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 // SGReaderWriterBTGOptions static value here to avoid an additional,
32 std::string SGReaderWriterBTGOptions::defaultOptions;
34 const char* SGReaderWriterBTG::className() const
36 return "BTG Database reader";
39 bool SGReaderWriterBTG::acceptsExtension(const std::string& extension) const
41 return (osgDB::equalCaseInsensitive(extension, "gz")
42 || osgDB::equalCaseInsensitive(extension, "btg"));
45 osgDB::ReaderWriter::ReadResult
46 SGReaderWriterBTG::readNode(const std::string& fileName,
47 const osgDB::ReaderWriter::Options* options) const
49 std::string ext = osgDB::getLowerCaseFileExtension(fileName);
50 if(!acceptsExtension(ext))
51 return ReadResult::FILE_NOT_HANDLED;
52 if (osgDB::equalCaseInsensitive(ext, "gz")) {
53 std::string btgFileName = osgDB::getNameLessExtension(fileName);
54 if (!acceptsExtension(
55 osgDB::getLowerCaseFileExtension(btgFileName))) {
56 return ReadResult::FILE_NOT_HANDLED;
59 SGMaterialLib* matlib = 0;
60 bool calcLights = false;
61 bool useRandomObjects = false;
62 bool useRandomVegetation = false;
63 const SGReaderWriterBTGOptions* btgOptions
64 = dynamic_cast<const SGReaderWriterBTGOptions*>(options);
66 matlib = btgOptions->getMatlib();
67 calcLights = btgOptions->getCalcLights();
68 useRandomObjects = btgOptions->getUseRandomObjects();
69 useRandomVegetation = btgOptions->getUseRandomVegetation();
71 osg::Node* result = SGLoadBTG(fileName, matlib, calcLights,
77 return ReadResult::FILE_NOT_HANDLED;
82 ModelRegistryCallbackProxy<LoadOnlyCallback> g_btgCallbackProxy("btg");