]> git.mxchange.org Git - simgear.git/commitdiff
scenery: Route loader options through the btg loader.
authorMathias Froehlich <Mathias.Froehlich@web.de>
Sat, 3 Mar 2012 09:37:54 +0000 (10:37 +0100)
committerMathias Froehlich <Mathias.Froehlich@web.de>
Sat, 3 Mar 2012 11:03:09 +0000 (12:03 +0100)
simgear/scene/tgdb/SGReaderWriterBTG.cxx
simgear/scene/tgdb/TreeBin.cxx
simgear/scene/tgdb/TreeBin.hxx
simgear/scene/tgdb/obj.cxx
simgear/scene/tgdb/obj.hxx
simgear/scene/tgdb/userdata.cxx
simgear/scene/tgdb/userdata.hxx

index 71d2a00dd405ef0e1ba2c8cb45c36a3c340f9f9d..753720d25c612cb3a6c11c56941a4e1bfad954d6 100644 (file)
@@ -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<const SGReaderWriterOptions*>(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;
 }
 
 
index 17da8374231b5d06fe559edf76808dc8adb3d1ca..f8980c6d552f9586169ae3cfdcf130969640c576 100644 (file)
@@ -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();
index a9c421987f1012eb5bc7078e81b05985a9565ffe..254c88128e3dda79cf5df005fcfd4753cde4ce7b 100644 (file)
@@ -65,6 +65,7 @@ public:
 
 typedef std::list<TreeBin*> SGTreeBinList;
 
-osg::Group* createForest(SGTreeBinList& forestList, const osg::Matrix& transform);
+osg::Group* createForest(SGTreeBinList& forestList, const osg::Matrix& transform,
+                         const SGReaderWriterOptions* options);
 }
 #endif
index 7ac2c4cab3013bcaef69e56dd7355c8bec936af9..a7286cb9e48c36887670a989e553afc044866531 100644 (file)
@@ -600,12 +600,32 @@ typedef QuadTreeBuilder<osg::LOD*, ModelLOD, MakeQuadLeaf, AddModelLOD,
                         GetModelLODCoord>  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");
       }
     } 
index 66054a195ed47caaa706c90bbe666b82e2ca2a6c..b84f21d990e9cea9e5fc693b43c258956701e439 100644 (file)
@@ -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
index 10fa8f7e7763d5cee644bf670b641325fc8e65db..61c46b1e77da2dfcd64014b6a3c65d4259f1c7b3 100644 (file)
@@ -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()
index 553a8c593fe591c7e0d07c77c94b40fcc48f5b98..da1cc3d1908d66b0e0895816802d51e7b742026f 100644 (file)
@@ -26,7 +26,6 @@
 #define _SG_USERDATA_HXX
 
 #include <simgear/compiler.h>
-#include <simgear/math/sg_random.h>
 
 #include <osg/Node>
 
@@ -40,11 +39,6 @@ class SGPropertyNode;
  */
 void sgUserDataInit(SGPropertyNode *p);
 
-/**
- * Get a random model.
- */
-osg::Node* sgGetRandomModel(SGMatModel *obj, mt *seed);
-
 namespace simgear
 {
 /**