]> git.mxchange.org Git - simgear.git/blob - simgear/scene/tgdb/SGReaderWriterBTG.cxx
ocean state set in osg::Geometry
[simgear.git] / simgear / scene / tgdb / SGReaderWriterBTG.cxx
1 // Copyright (C) 2007 Tim Moore timoore@redhat.com
2 //
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.
7 //
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.
12 //
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.
16 //
17
18 #include <osgDB/FileNameUtils>
19 #include <osgDB/Registry>
20 #include "SGReaderWriterBTGOptions.hxx"
21 #include "SGReaderWriterBTG.hxx"
22 #include "obj.hxx"
23
24 const char* SGReaderWriterBTG::className() const
25 {
26     return "BTG Database reader";
27 }
28
29 bool SGReaderWriterBTG::acceptsExtension(const std::string& extension) const
30 {
31     return (osgDB::equalCaseInsensitive(extension, "gz")
32             || osgDB::equalCaseInsensitive(extension, "btg"));
33 }
34
35 osgDB::ReaderWriter::ReadResult
36 SGReaderWriterBTG::readNode(const std::string& fileName,
37                             const osgDB::ReaderWriter::Options* options) const
38 {
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;
47         }
48     }
49     SGMaterialLib* matlib = 0;
50     bool calcLights = false;
51     bool useRandomObjects = false;
52     const SGReaderWriterBTGOptions* btgOptions
53         = dynamic_cast<const SGReaderWriterBTGOptions*>(options);
54     if (btgOptions) {
55         matlib = btgOptions->getMatlib();
56         calcLights = btgOptions->getCalcLights();
57         useRandomObjects = btgOptions->getUseRandomObjects();
58     }
59     osg::Node* result = SGLoadBTG(fileName, matlib, calcLights,
60                                   useRandomObjects);
61     if (result)
62         return result;
63     else
64         return ReadResult::FILE_NOT_HANDLED;
65 }
66
67