]> git.mxchange.org Git - simgear.git/blob - simgear/scene/tgdb/SGReaderWriterBTG.cxx
Make tsync part of libSimGearCore when building shared libraries
[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 #ifdef HAVE_CONFIG_H
19 #  include <simgear_config.h>
20 #endif
21
22 #include <osgDB/FileNameUtils>
23 #include <osgDB/Registry>
24
25 #include <simgear/scene/model/ModelRegistry.hxx>
26 #include <simgear/scene/util/SGReaderWriterOptions.hxx>
27 #include <simgear/math/SGMath.hxx>
28
29 #include "SGReaderWriterBTG.hxx"
30 #include "obj.hxx"
31
32 using namespace simgear;
33
34 SGReaderWriterBTG::SGReaderWriterBTG()
35 {
36     supportsExtension("btg", "SimGear btg database format");
37     // supportsExtension("btg.gz", "SimGear btg database format");
38 }
39
40 SGReaderWriterBTG::~SGReaderWriterBTG()
41 {
42 }
43
44 const char* SGReaderWriterBTG::className() const
45 {
46     return "BTG Database reader";
47 }
48
49 bool
50 SGReaderWriterBTG::acceptsExtension(const std::string& extension) const
51 {
52     // trick the osg extensions match algorithm to accept btg.gz files.
53     if (osgDB::convertToLowerCase(extension) == "gz")
54         return true;
55     return osgDB::ReaderWriter::acceptsExtension(extension);
56 }
57
58 osgDB::ReaderWriter::ReadResult
59 SGReaderWriterBTG::readNode(const std::string& fileName,
60                             const osgDB::ReaderWriter::Options* options) const
61 {
62     SGMaterialLib* matlib = 0;
63     bool useRandomObjects = false;
64     bool useRandomVegetation = false;
65     float vegetation_density = 1.0f;
66     const SGReaderWriterOptions* sgOptions;
67     sgOptions = dynamic_cast<const SGReaderWriterOptions*>(options);
68     if (sgOptions) {
69         matlib = sgOptions->getMaterialLib();
70         SGPropertyNode* propertyNode = sgOptions->getPropertyNode().get();
71         if (propertyNode) {
72             useRandomObjects
73                 = propertyNode->getBoolValue("/sim/rendering/random-objects",
74                                              useRandomObjects);
75             useRandomVegetation
76                 = propertyNode->getBoolValue("/sim/rendering/random-vegetation",
77                                              useRandomVegetation);
78             vegetation_density
79                 = propertyNode->getFloatValue("/sim/rendering/vegetation-density",
80                                               vegetation_density);
81         }
82     }
83
84     osg::Node* result = SGLoadBTG(fileName, matlib,
85                                   useRandomObjects,
86                                   useRandomVegetation,
87                                   vegetation_density);
88     if (result)
89         return result;
90     else
91         return ReadResult::FILE_NOT_HANDLED;
92 }
93
94
95 typedef ModelRegistryCallback<DefaultProcessPolicy, NoCachePolicy,
96                               NoOptimizePolicy,
97                               NoSubstitutePolicy, BuildGroupBVHPolicy>
98 BTGCallback;
99
100 namespace
101 {
102 ModelRegistryCallbackProxy<BTGCallback> g_btgCallbackProxy("btg");
103 }