]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/modellib.cxx
model paging patch from Till Busch
[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 "model.hxx"
36 #include "modellib.hxx"
37
38
39 using namespace simgear;
40
41 osgDB::RegisterReaderWriterProxy<SGReaderWriterXML> g_readerWriter_XML_Proxy;
42 ModelRegistryCallbackProxy<LoadOnlyCallback> g_xmlCallbackProxy("xml");
43
44 \f
45 ////////////////////////////////////////////////////////////////////////
46 // Implementation of SGModelLib.
47 ////////////////////////////////////////////////////////////////////////
48 void SGModelLib::init(const string &root_dir)
49 {
50     osgDB::Registry::instance()->getDataFilePathList().push_front(root_dir);
51 }
52
53 SGModelLib::SGModelLib()
54 {
55 }
56
57 SGModelLib::~SGModelLib()
58 {
59 }
60
61 osg::Node*
62 SGModelLib::loadModel(const string &path,
63                        SGPropertyNode *prop_root,
64                        SGModelData *data)
65 {
66     osg::ref_ptr<SGReaderWriterXMLOptions> opt = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()->getOptions()));
67     opt->setPropRoot(prop_root);
68     opt->setModelData(data);
69     osg::Node *n = readNodeFile(path, opt.get());
70     if(data)
71         data->modelLoaded(path, data->getProperties(), n);
72     return n;
73
74 }
75
76 osg::Node*
77 SGModelLib::loadModel(const string &path,
78                                 SGPropertyNode *prop_root,
79                                 panel_func pf)
80 {
81     osg::ref_ptr<SGReaderWriterXMLOptions> opt = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()->getOptions()));
82     opt->setPropRoot(prop_root);
83     opt->setLoadPanel(pf);
84     return readNodeFile(path, opt.get());
85 }
86
87 osg::Node*
88 SGModelLib::loadPagedModel(const string &path,
89                            SGPropertyNode *prop_root,
90                            SGModelData *data)
91 {
92     SGPagedLOD *plod = new SGPagedLOD;
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