00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <osgDB/FileNameUtils>
00019 #include <osgDB/Registry>
00020
00021 #include <simgear/scene/model/ModelRegistry.hxx>
00022
00023 #include "SGReaderWriterBTGOptions.hxx"
00024 #include "SGReaderWriterBTG.hxx"
00025 #include "obj.hxx"
00026
00027 using namespace simgear;
00028
00029 SGReaderWriterBTG::SGReaderWriterBTG()
00030 {
00031 supportsExtension("btg", "SimGear btg database format");
00032 }
00033
00034 SGReaderWriterBTG::~SGReaderWriterBTG()
00035 {
00036 }
00037
00038 const char* SGReaderWriterBTG::className() const
00039 {
00040 return "BTG Database reader";
00041 }
00042
00043 bool
00044 SGReaderWriterBTG::acceptsExtension(const std::string& extension) const
00045 {
00046 std::string lowercase_ext = osgDB::convertToLowerCase(extension);
00047 if (lowercase_ext == "gz")
00048 return true;
00049 return osgDB::ReaderWriter::acceptsExtension(extension);
00050 }
00051
00052 osgDB::ReaderWriter::ReadResult
00053 SGReaderWriterBTG::readNode(const std::string& fileName,
00054 const osgDB::ReaderWriter::Options* options) const
00055 {
00056 SGMaterialLib* matlib = 0;
00057 bool calcLights = false;
00058 bool useRandomObjects = false;
00059 bool useRandomVegetation = false;
00060 const SGReaderWriterBTGOptions* btgOptions
00061 = dynamic_cast<const SGReaderWriterBTGOptions*>(options);
00062 if (btgOptions) {
00063 matlib = btgOptions->getMatlib();
00064 calcLights = btgOptions->getCalcLights();
00065 useRandomObjects = btgOptions->getUseRandomObjects();
00066 useRandomVegetation = btgOptions->getUseRandomVegetation();
00067 }
00068 osg::Node* result = SGLoadBTG(fileName, matlib, calcLights,
00069 useRandomObjects,
00070 useRandomVegetation);
00071 if (result)
00072 return result;
00073 else
00074 return ReadResult::FILE_NOT_HANDLED;
00075 }
00076
00077
00078 typedef ModelRegistryCallback<DefaultProcessPolicy, NoCachePolicy,
00079 NoOptimizePolicy,
00080 NoSubstitutePolicy, BuildGroupBVHPolicy>
00081 BTGCallback;
00082
00083 namespace
00084 {
00085 ModelRegistryCallbackProxy<BTGCallback> g_btgCallbackProxy("btg");
00086 }