From: Mathias Froehlich Date: Sat, 3 Mar 2012 09:37:54 +0000 (+0100) Subject: scenery: Route loader options through the btg loader. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9e46820c57e286167732875c6d526549a2b2512b;p=simgear.git scenery: Route loader options through the btg loader. --- diff --git a/simgear/scene/tgdb/SGReaderWriterBTG.cxx b/simgear/scene/tgdb/SGReaderWriterBTG.cxx index 71d2a00d..753720d2 100644 --- a/simgear/scene/tgdb/SGReaderWriterBTG.cxx +++ b/simgear/scene/tgdb/SGReaderWriterBTG.cxx @@ -59,36 +59,13 @@ osgDB::ReaderWriter::ReadResult SGReaderWriterBTG::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { - SGMaterialLib* matlib = 0; - bool useRandomObjects = false; - bool useRandomVegetation = false; - float vegetation_density = 1.0f; const SGReaderWriterOptions* sgOptions; sgOptions = dynamic_cast(options); - if (sgOptions) { - matlib = sgOptions->getMaterialLib(); - SGPropertyNode* propertyNode = sgOptions->getPropertyNode().get(); - if (propertyNode) { - useRandomObjects - = propertyNode->getBoolValue("/sim/rendering/random-objects", - useRandomObjects); - useRandomVegetation - = propertyNode->getBoolValue("/sim/rendering/random-vegetation", - useRandomVegetation); - vegetation_density - = propertyNode->getFloatValue("/sim/rendering/vegetation-density", - vegetation_density); - } - } - - osg::Node* result = SGLoadBTG(fileName, matlib, - useRandomObjects, - useRandomVegetation, - vegetation_density); - if (result) - return result; - else + osg::Node* result = SGLoadBTG(fileName, sgOptions); + if (!result) return ReadResult::FILE_NOT_HANDLED; + + return result; } diff --git a/simgear/scene/tgdb/TreeBin.cxx b/simgear/scene/tgdb/TreeBin.cxx index 17da8374..f8980c6d 100644 --- a/simgear/scene/tgdb/TreeBin.cxx +++ b/simgear/scene/tgdb/TreeBin.cxx @@ -285,7 +285,8 @@ struct TreeTransformer // forest into the local Z-up coordinate system we can reuse the // primitive tree geometry for all the forests of the same type. -osg::Group* createForest(SGTreeBinList& forestList, const osg::Matrix& transform) +osg::Group* createForest(SGTreeBinList& forestList, const osg::Matrix& transform, + const SGReaderWriterOptions* options) { Matrix transInv = Matrix::inverse(transform); static Matrix ident; @@ -307,7 +308,7 @@ osg::Group* createForest(SGTreeBinList& forestList, const osg::Matrix& transform // emphasize n = 0 params->getChild("texture", 0, true)->getChild("image", 0, true) ->setStringValue(forest->texture); - effect = makeEffect(effectProp, true); + effect = makeEffect(effectProp, true, options); treeEffectMap.insert(EffectMap::value_type(forest->texture, effect)); } else { effect = iter->second.get(); diff --git a/simgear/scene/tgdb/TreeBin.hxx b/simgear/scene/tgdb/TreeBin.hxx index a9c42198..254c8812 100644 --- a/simgear/scene/tgdb/TreeBin.hxx +++ b/simgear/scene/tgdb/TreeBin.hxx @@ -65,6 +65,7 @@ public: typedef std::list SGTreeBinList; -osg::Group* createForest(SGTreeBinList& forestList, const osg::Matrix& transform); +osg::Group* createForest(SGTreeBinList& forestList, const osg::Matrix& transform, + const SGReaderWriterOptions* options); } #endif diff --git a/simgear/scene/tgdb/obj.cxx b/simgear/scene/tgdb/obj.cxx index 7ac2c4ca..a7286cb9 100644 --- a/simgear/scene/tgdb/obj.cxx +++ b/simgear/scene/tgdb/obj.cxx @@ -600,12 +600,32 @@ typedef QuadTreeBuilder RandomObjectsQuadtree; osg::Node* -SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool use_random_objects, bool use_random_vegetation, float vegetation_density) +SGLoadBTG(const std::string& path, const simgear::SGReaderWriterOptions* options) { SGBinObject tile; if (!tile.read_bin(path)) return NULL; + SGMaterialLib* matlib = 0; + bool use_random_objects = false; + bool use_random_vegetation = false; + float vegetation_density = 1.0f; + if (options) { + matlib = options->getMaterialLib(); + SGPropertyNode* propertyNode = options->getPropertyNode().get(); + if (propertyNode) { + use_random_objects + = propertyNode->getBoolValue("/sim/rendering/random-objects", + use_random_objects); + use_random_vegetation + = propertyNode->getBoolValue("/sim/rendering/random-vegetation", + use_random_vegetation); + vegetation_density + = propertyNode->getFloatValue("/sim/rendering/vegetation-density", + vegetation_density); + } + } + SGVec3d center = tile.get_gbs_center(); SGGeod geodPos = SGGeod::fromCart(center); SGQuatd hlOr = SGQuatd::fromLonLat(geodPos)*SGQuatd::fromEulerDeg(0, 0, 180); @@ -654,8 +674,9 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool use_random_object i < tileGeometryBin.randomModels.getNumModels(); i++) { SGMatModelBin::MatModel obj = tileGeometryBin.randomModels.getMatModel(i); - - osg::Node* node = sgGetRandomModel(obj.model, &seed); + + SGPropertyNode* root = options->getPropertyNode()->getRootNode(); + osg::Node* node = obj.model->get_random_model(root, &seed); // Create a matrix to place the object in the correct // location, and then apply the rotation matrix created @@ -694,7 +715,8 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool use_random_object tileGeometryBin.computeRandomForest(matlib, vegetation_density); if (tileGeometryBin.randomForest.size() > 0) { - forestNode = createForest(tileGeometryBin.randomForest, osg::Matrix::identity()); + forestNode = createForest(tileGeometryBin.randomForest, osg::Matrix::identity(), + options); forestNode->setName("Random trees"); } } diff --git a/simgear/scene/tgdb/obj.hxx b/simgear/scene/tgdb/obj.hxx index 66054a19..b84f21d9 100644 --- a/simgear/scene/tgdb/obj.hxx +++ b/simgear/scene/tgdb/obj.hxx @@ -42,6 +42,9 @@ using std::string; class SGBucket; class SGMaterialLib; +namespace simgear { +class SGReaderWriterOptions; +} // Generate an ocean tile inline bool SGGenTile( const std::string&, const SGBucket& b, @@ -57,9 +60,6 @@ inline bool SGGenTile( const std::string&, const SGBucket& b, osg::Node* SGLoadBTG(const std::string& path, - SGMaterialLib *matlib, - bool use_random_objects, - bool use_random_vegetation, - float vegetation_density); + const simgear::SGReaderWriterOptions* options); #endif // _SG_OBJ_HXX diff --git a/simgear/scene/tgdb/userdata.cxx b/simgear/scene/tgdb/userdata.cxx index 10fa8f7e..61c46b1e 100644 --- a/simgear/scene/tgdb/userdata.cxx +++ b/simgear/scene/tgdb/userdata.cxx @@ -59,10 +59,6 @@ void sgUserDataInit( SGPropertyNode *p ) { root_props = p; } -osg::Node* sgGetRandomModel(SGMatModel *obj, mt *seed) { - return obj->get_random_model( root_props, seed ); - } - namespace simgear { SGPropertyNode* getPropertyRoot() diff --git a/simgear/scene/tgdb/userdata.hxx b/simgear/scene/tgdb/userdata.hxx index 553a8c59..da1cc3d1 100644 --- a/simgear/scene/tgdb/userdata.hxx +++ b/simgear/scene/tgdb/userdata.hxx @@ -26,7 +26,6 @@ #define _SG_USERDATA_HXX #include -#include #include @@ -40,11 +39,6 @@ class SGPropertyNode; */ void sgUserDataInit(SGPropertyNode *p); -/** - * Get a random model. - */ -osg::Node* sgGetRandomModel(SGMatModel *obj, mt *seed); - namespace simgear { /**