]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/modellib.cxx
Doing the compilers job: constant propagation.
[simgear.git] / simgear / scene / model / modellib.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
18 #ifdef HAVE_CONFIG_H
19 #  include <simgear_config.h>
20 #endif
21
22 #include <osgDB/ReadFile>
23 #include <osgDB/WriteFile>
24 #include <osgDB/Registry>
25
26 #include <simgear/constants.h>
27 #include <simgear/props/props.hxx>
28 #include <simgear/props/props_io.hxx>
29 #include <simgear/scene/model/ModelRegistry.hxx>
30
31 #include "SGPagedLOD.hxx"
32 #include "SGReaderWriterXML.hxx"
33 #include "SGReaderWriterXMLOptions.hxx"
34
35 #include "modellib.hxx"
36
37
38 using namespace simgear;
39
40 osgDB::RegisterReaderWriterProxy<SGReaderWriterXML> g_readerWriter_XML_Proxy;
41 ModelRegistryCallbackProxy<LoadOnlyCallback> g_xmlCallbackProxy("xml");
42
43 \f
44 ////////////////////////////////////////////////////////////////////////
45 // Implementation of SGModelLib.
46 ////////////////////////////////////////////////////////////////////////
47 void SGModelLib::init(const string &root_dir)
48 {
49     osgDB::Registry::instance()->getDataFilePathList().push_front(root_dir);
50 }
51
52 SGModelLib::SGModelLib()
53 {
54 }
55
56 SGModelLib::~SGModelLib()
57 {
58 }
59
60 osg::Node*
61 SGModelLib::loadModel(const string &path,
62                        SGPropertyNode *prop_root,
63                        SGModelData *data)
64 {
65     osg::ref_ptr<SGReaderWriterXMLOptions> opt = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()->getOptions()));
66     opt->setPropRoot(prop_root);
67     opt->setModelData(data);
68     osg::Node *n = readNodeFile(path, opt.get());
69     if(data)
70         data->modelLoaded(path, 0, n);
71     if (n && n->getName().empty())
72         n->setName("Direct loaded model \"" + path + "\"");
73     return n;
74
75 }
76
77 osg::Node*
78 SGModelLib::loadModel(const string &path,
79                                 SGPropertyNode *prop_root,
80                                 panel_func pf)
81 {
82     osg::ref_ptr<SGReaderWriterXMLOptions> opt = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()->getOptions()));
83     opt->setPropRoot(prop_root);
84     opt->setLoadPanel(pf);
85     return readNodeFile(path, opt.get());
86 }
87
88 osg::Node*
89 SGModelLib::loadPagedModel(const string &path,
90                            SGPropertyNode *prop_root,
91                            SGModelData *data)
92 {
93     SGPagedLOD *plod = new SGPagedLOD;
94     plod->setName("Paged LOD for \"" + path + "\"");
95     plod->setFileName(0, path);
96     plod->setRange(0, 0.0, 50.0*SG_NM_TO_METER);
97
98     osg::ref_ptr<SGReaderWriterXMLOptions> opt = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()->getOptions()));
99     opt->setPropRoot(prop_root);
100     opt->setModelData(data);
101     plod->setReaderWriterOptions(opt.get());
102     return plod;
103 }
104
105 // end of modellib.cxx