]> git.mxchange.org Git - simgear.git/blob - simgear/scene/tgdb/SGReaderWriterBTG.cxx
Make sure the boundingvolumes for the btg files are as high as possible
[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
21 #include <simgear/scene/model/ModelRegistry.hxx>
22
23 #include "SGReaderWriterBTGOptions.hxx"
24 #include "SGReaderWriterBTG.hxx"
25 #include "obj.hxx"
26
27 using namespace simgear;
28
29 // SGReaderWriterBTGOptions static value here to avoid an additional,
30 // tiny source file.
31
32 std::string SGReaderWriterBTGOptions::defaultOptions;
33
34 const char* SGReaderWriterBTG::className() const
35 {
36     return "BTG Database reader";
37 }
38
39 bool SGReaderWriterBTG::acceptsExtension(const std::string& extension) const
40 {
41     return (osgDB::equalCaseInsensitive(extension, "gz")
42             || osgDB::equalCaseInsensitive(extension, "btg"));
43 }
44
45 osgDB::ReaderWriter::ReadResult
46 SGReaderWriterBTG::readNode(const std::string& fileName,
47                             const osgDB::ReaderWriter::Options* options) const
48 {
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;
57         }
58     }
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);
65     if (btgOptions) {
66         matlib = btgOptions->getMatlib();
67         calcLights = btgOptions->getCalcLights();
68         useRandomObjects = btgOptions->getUseRandomObjects();
69         useRandomVegetation = btgOptions->getUseRandomVegetation();
70     }
71     osg::Node* result = SGLoadBTG(fileName, matlib, calcLights,
72                                   useRandomObjects,
73                                   useRandomVegetation);
74     if (result)
75         return result;
76     else
77         return ReadResult::FILE_NOT_HANDLED;
78 }
79
80
81 typedef ModelRegistryCallback<DefaultProcessPolicy, NoCachePolicy,
82                               NoOptimizePolicy, NoCopyPolicy,
83                               NoSubstitutePolicy, BuildGroupBVHPolicy>
84 BTGCallback;
85
86 namespace
87 {
88 ModelRegistryCallbackProxy<BTGCallback> g_btgCallbackProxy("btg");
89 }