]> 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         _readerWriterOptions(plod._readerWriterOptions)
51 {
52 }
53
54 bool SGPagedLOD::addChild(osg::Node *child)
55 {
56     if (!PagedLOD::addChild(child))
57         return false;
58
59     setRadius(getBound().radius());
60     setCenter(getBound().center());
61     return true;
62 }
63
64 // Work around interface change in osgDB::DatabasePager::requestNodeFile
65 struct NodePathProxy
66 {
67     NodePathProxy(NodePath& nodePath)
68         : _nodePath(nodePath)
69     {
70     }
71     operator Group* () { return static_cast<Group*>(_nodePath.back()); }
72     operator NodePath& () { return _nodePath; }
73     NodePath& _nodePath;
74 };
75
76 void SGPagedLOD::forceLoad(osgDB::DatabasePager *dbp, FrameStamp* framestamp,
77                            NodePath& path)
78 {
79     //SG_LOG(SG_GENERAL, SG_ALERT, "SGPagedLOD::forceLoad(" <<
80     //getFileName(getNumChildren()) << ")");
81     unsigned childNum = getNumChildren();
82     setTimeStamp(childNum, 0);
83     double priority=1.0;
84     dbp->requestNodeFile(getFileName(childNum), NodePathProxy(path),
85                          priority, framestamp,
86                          getDatabaseRequest(childNum),
87                          _readerWriterOptions.get());
88 }
89
90 bool SGPagedLOD_writeLocalData(const Object& obj, osgDB::Output& fw)
91 {
92     return true;
93 }
94
95 namespace
96 {
97 osgDB::RegisterDotOsgWrapperProxy sgPagedLODProxy
98 (
99     new SGPagedLOD,
100     "simgear::SGPagedLOD",
101     "Object Node LOD PagedLOD SGPagedLOD Group",
102     0,
103     &SGPagedLOD_writeLocalData
104     );
105 }