]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/SGPagedLOD.cxx
Merge branch 'releases/2.2.0' into next
[simgear.git] / simgear / scene / model / SGPagedLOD.cxx
1 // Copyright (C) 2008 Till Busch buti@bux.at
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License as
5 // published by the Free Software Foundation; either version 2 of the
6 // License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful, but
9 // WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16
17 #ifdef HAVE_CONFIG_H
18 #  include <simgear_config.h>
19 #endif
20
21 #include <osgDB/ReadFile>
22 #include <osgDB/Input>
23 #include <osgDB/ParameterOutput>
24 #include <osgDB/DatabasePager>
25
26 #include <simgear/debug/logstream.hxx>
27 #include <simgear/structure/OSGVersion.hxx>
28
29 #include "modellib.hxx"
30 #include "SGReaderWriterXMLOptions.hxx"
31 #include "SGPagedLOD.hxx"
32
33 #include <simgear/math/SGMath.hxx>
34
35 using namespace osg;
36 using namespace simgear;
37
38 SGPagedLOD::SGPagedLOD()
39         : PagedLOD()
40 {
41 }
42
43 SGPagedLOD::~SGPagedLOD()
44 {
45     //SG_LOG(SG_GENERAL, SG_ALERT, "SGPagedLOD::~SGPagedLOD(" << getFileName(0) << ")");
46 }
47
48 SGPagedLOD::SGPagedLOD(const SGPagedLOD& plod,const CopyOp& copyop)
49         : osg::PagedLOD(plod, copyop)
50 #if !SG_PAGEDLOD_HAS_OPTIONS
51         ,  _readerWriterOptions(plod._readerWriterOptions)
52 #endif
53 {
54 }
55
56 bool SGPagedLOD::addChild(osg::Node *child)
57 {
58     if (!PagedLOD::addChild(child))
59         return false;
60
61     setRadius(getBound().radius());
62     setCenter(getBound().center());
63     return true;
64 }
65
66 // Work around interface change in osgDB::DatabasePager::requestNodeFile
67 struct NodePathProxy
68 {
69     NodePathProxy(NodePath& nodePath)
70         : _nodePath(nodePath)
71     {
72     }
73     operator Group* () { return static_cast<Group*>(_nodePath.back()); }
74     operator NodePath& () { return _nodePath; }
75     NodePath& _nodePath;
76 };
77
78 void SGPagedLOD::forceLoad(osgDB::DatabasePager *dbp, FrameStamp* framestamp,
79                            NodePath& path)
80 {
81     //SG_LOG(SG_GENERAL, SG_ALERT, "SGPagedLOD::forceLoad(" <<
82     //getFileName(getNumChildren()) << ")");
83     unsigned childNum = getNumChildren();
84     setTimeStamp(childNum, 0);
85     double priority=1.0;
86     dbp->requestNodeFile(getFileName(childNum), NodePathProxy(path),
87                          priority, framestamp,
88                          getDatabaseRequest(childNum),
89                          getReaderWriterOptions());
90 }
91
92 bool SGPagedLOD_writeLocalData(const Object& obj, osgDB::Output& fw)
93 {
94     return true;
95 }
96
97 namespace
98 {
99 osgDB::RegisterDotOsgWrapperProxy sgPagedLODProxy
100 (
101     new SGPagedLOD,
102     "simgear::SGPagedLOD",
103     "Object Node LOD PagedLOD SGPagedLOD Group",
104     0,
105     &SGPagedLOD_writeLocalData
106     );
107 }