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"
37 #include <simgear/math/SGMath.hxx>
40 using namespace simgear;
42 osgDB::RegisterReaderWriterProxy<SGReaderWriterXML> g_readerWriter_XML_Proxy;
43 ModelRegistryCallbackProxy<LoadOnlyCallback> g_xmlCallbackProxy("xml");
46 ////////////////////////////////////////////////////////////////////////
47 // Implementation of SGModelLib.
48 ////////////////////////////////////////////////////////////////////////
49 void SGModelLib::init(const string &root_dir)
51 osgDB::Registry::instance()->getDataFilePathList().push_front(root_dir);
54 SGModelLib::SGModelLib()
58 SGModelLib::~SGModelLib()
63 SGModelLib::loadModel(const string &path,
64 SGPropertyNode *prop_root,
67 osg::ref_ptr<SGReaderWriterXMLOptions> opt = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()->getOptions()));
68 opt->setPropRoot(prop_root);
69 opt->setModelData(data);
70 osg::Node *n = readNodeFile(path, opt.get());
71 if (n && n->getName().empty())
72 n->setName("Direct loaded model \"" + path + "\"");
78 SGModelLib::loadModel(const string &path,
79 SGPropertyNode *prop_root,
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());
89 SGModelLib::loadPagedModel(const string &path,
90 SGPropertyNode *prop_root,
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);
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());
105 // end of modellib.cxx