]> git.mxchange.org Git - simgear.git/blob - simgear/scene/tgdb/SGReaderWriterBTG.cxx
Merge branch 'jmt/ref_ptr-conv'
[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 SGReaderWriterBTG::SGReaderWriterBTG()
30 {
31     supportsExtension("btg", "SimGear btg database format");
32 }
33
34 SGReaderWriterBTG::~SGReaderWriterBTG()
35 {
36 }
37
38 const char* SGReaderWriterBTG::className() const
39 {
40     return "BTG Database reader";
41 }
42
43 bool
44 SGReaderWriterBTG::acceptsExtension(const std::string& extension) const
45 {
46     std::string lowercase_ext = osgDB::convertToLowerCase(extension);
47     if (lowercase_ext == "gz")
48         return true;
49     return osgDB::ReaderWriter::acceptsExtension(extension);
50 }
51
52 osgDB::ReaderWriter::ReadResult
53 SGReaderWriterBTG::readNode(const std::string& fileName,
54                             const osgDB::ReaderWriter::Options* options) const
55 {
56     SGMaterialLib* matlib = 0;
57     bool calcLights = false;
58     bool useRandomObjects = false;
59     bool useRandomVegetation = false;
60     const SGReaderWriterBTGOptions* btgOptions
61         = dynamic_cast<const SGReaderWriterBTGOptions*>(options);
62     if (btgOptions) {
63         matlib = btgOptions->getMatlib();
64         calcLights = btgOptions->getCalcLights();
65         useRandomObjects = btgOptions->getUseRandomObjects();
66         useRandomVegetation = btgOptions->getUseRandomVegetation();
67     }
68     osg::Node* result = SGLoadBTG(fileName, matlib, calcLights,
69                                   useRandomObjects,
70                                   useRandomVegetation);
71     if (result)
72         return result;
73     else
74         return ReadResult::FILE_NOT_HANDLED;
75 }
76
77
78 typedef ModelRegistryCallback<DefaultProcessPolicy, NoCachePolicy,
79                               NoOptimizePolicy,
80                               NoSubstitutePolicy, BuildGroupBVHPolicy>
81 BTGCallback;
82
83 namespace
84 {
85 ModelRegistryCallbackProxy<BTGCallback> g_btgCallbackProxy("btg");
86 }