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>
20 #include "SGReaderWriterBTGOptions.hxx"
21 #include "SGReaderWriterBTG.hxx"
24 const char* SGReaderWriterBTG::className() const
26 return "BTG Database reader";
29 bool SGReaderWriterBTG::acceptsExtension(const std::string& extension) const
31 return (osgDB::equalCaseInsensitive(extension, "gz")
32 || osgDB::equalCaseInsensitive(extension, "btg"));
35 osgDB::ReaderWriter::ReadResult
36 SGReaderWriterBTG::readNode(const std::string& fileName,
37 const osgDB::ReaderWriter::Options* options) const
39 std::string ext = osgDB::getLowerCaseFileExtension(fileName);
40 if(!acceptsExtension(ext))
41 return ReadResult::FILE_NOT_HANDLED;
42 if (osgDB::equalCaseInsensitive(ext, "gz")) {
43 std::string btgFileName = osgDB::getNameLessExtension(fileName);
44 if (!acceptsExtension(
45 osgDB::getLowerCaseFileExtension(btgFileName))) {
46 return ReadResult::FILE_NOT_HANDLED;
49 SGMaterialLib* matlib = 0;
50 bool calcLights = false;
51 bool useRandomObjects = false;
52 const SGReaderWriterBTGOptions* btgOptions
53 = dynamic_cast<const SGReaderWriterBTGOptions*>(options);
55 matlib = btgOptions->getMatlib();
56 calcLights = btgOptions->getCalcLights();
57 useRandomObjects = btgOptions->getUseRandomObjects();
59 osg::Node* result = SGLoadBTG(fileName, matlib, calcLights,
64 return ReadResult::FILE_NOT_HANDLED;