]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/modellib.cxx
Construct effects from property lists
[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 (n && n->getName().empty())
70         n->setName("Direct loaded model \"" + path + "\"");
71     return n;
72
73 }
74
75 osg::Node*
76 SGModelLib::loadModel(const string &path,
77                                 SGPropertyNode *prop_root,
78                                 panel_func pf)
79 {
80     osg::ref_ptr<SGReaderWriterXMLOptions> opt = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()->getOptions()));
81     opt->setPropRoot(prop_root);
82     opt->setLoadPanel(pf);
83     return readNodeFile(path, opt.get());
84 }
85
86 osg::Node*
87 SGModelLib::loadPagedModel(const string &path,
88                            SGPropertyNode *prop_root,
89                            SGModelData *data)
90 {
91     SGPagedLOD *plod = new SGPagedLOD;
92     plod->setName("Paged LOD for \"" + path + "\"");
93     plod->setFileName(0, path);
94     plod->setRange(0, 0.0, 50.0*SG_NM_TO_METER);
95
96     osg::ref_ptr<SGReaderWriterXMLOptions> opt = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()->getOptions()));
97     opt->setPropRoot(prop_root);
98     opt->setModelData(data);
99     plod->setReaderWriterOptions(opt.get());
100     return plod;
101 }
102
103 // end of modellib.cxx