1 // Copyright (C) 2008 Till Busch buti@bux.at
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.
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.
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.
19 # include <simgear_config.h>
22 #include <osgDB/ReadFile>
23 #include <osgDB/WriteFile>
24 #include <osgDB/Registry>
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>
31 #include "SGPagedLOD.hxx"
32 #include "SGReaderWriterXML.hxx"
33 #include "SGReaderWriterXMLOptions.hxx"
35 #include "modellib.hxx"
38 using namespace simgear;
40 osgDB::RegisterReaderWriterProxy<SGReaderWriterXML> g_readerWriter_XML_Proxy;
41 ModelRegistryCallbackProxy<LoadOnlyCallback> g_xmlCallbackProxy("xml");
44 ////////////////////////////////////////////////////////////////////////
45 // Implementation of SGModelLib.
46 ////////////////////////////////////////////////////////////////////////
47 void SGModelLib::init(const string &root_dir)
49 osgDB::Registry::instance()->getDataFilePathList().push_front(root_dir);
52 SGModelLib::SGModelLib()
56 SGModelLib::~SGModelLib()
61 SGModelLib::loadModel(const string &path,
62 SGPropertyNode *prop_root,
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 + "\"");
76 SGModelLib::loadModel(const string &path,
77 SGPropertyNode *prop_root,
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());
87 SGModelLib::loadPagedModel(const string &path,
88 SGPropertyNode *prop_root,
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);
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());
103 // end of modellib.cxx