1 // Copyright (C) 2007 Tim Moore timoore@redhat.com
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.
18 #include <osgDB/FileNameUtils>
19 #include <osgDB/Registry>
21 #include <simgear/scene/model/ModelRegistry.hxx>
23 #include "SGReaderWriterBTGOptions.hxx"
24 #include "SGReaderWriterBTG.hxx"
27 using namespace simgear;
29 const char* SGReaderWriterBTG::className() const
31 return "BTG Database reader";
34 bool SGReaderWriterBTG::acceptsExtension(const std::string& extension) const
36 return (osgDB::equalCaseInsensitive(extension, "gz")
37 || osgDB::equalCaseInsensitive(extension, "btg"));
40 osgDB::ReaderWriter::ReadResult
41 SGReaderWriterBTG::readNode(const std::string& fileName,
42 const osgDB::ReaderWriter::Options* options) const
44 std::string ext = osgDB::getLowerCaseFileExtension(fileName);
45 if(!acceptsExtension(ext))
46 return ReadResult::FILE_NOT_HANDLED;
47 if (osgDB::equalCaseInsensitive(ext, "gz")) {
48 std::string btgFileName = osgDB::getNameLessExtension(fileName);
49 if (!acceptsExtension(
50 osgDB::getLowerCaseFileExtension(btgFileName))) {
51 return ReadResult::FILE_NOT_HANDLED;
54 SGMaterialLib* matlib = 0;
55 bool calcLights = false;
56 bool useRandomObjects = false;
57 const SGReaderWriterBTGOptions* btgOptions
58 = dynamic_cast<const SGReaderWriterBTGOptions*>(options);
60 matlib = btgOptions->getMatlib();
61 calcLights = btgOptions->getCalcLights();
62 useRandomObjects = btgOptions->getUseRandomObjects();
64 osg::Node* result = SGLoadBTG(fileName, matlib, calcLights,
69 return ReadResult::FILE_NOT_HANDLED;
74 ModelRegistryCallbackProxy<OSGFileCallback> g_btgCallbackProxy("btg");