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