]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/BoundingVolumeBuildVisitor.hxx
Add preliminary spot light animation
[simgear.git] / simgear / scene / model / BoundingVolumeBuildVisitor.hxx
index 80587ff02d105fe32fafe138c56928e547d7c5a9..9155bcece2920c62405ee3af31fd675afacd1d55 100644 (file)
@@ -384,10 +384,10 @@ public:
     {
     }
 
-    const SGMaterial* pushMaterial(osg::StateSet* stateSet)
+    const SGMaterial* pushMaterial(osg::Geode* geode)
     {
         const SGMaterial* oldMaterial = _primitiveFunctor.getCurrentMaterial();
-        const SGMaterial* material = SGMaterialLib::findMaterial(stateSet);
+        const SGMaterial* material = SGMaterialLib::findMaterial(geode);
         if (material)
             _primitiveFunctor.setCurrentMaterial(material);
         return oldMaterial;
@@ -395,9 +395,7 @@ public:
 
     void fillWith(osg::Drawable* drawable)
     {
-        const SGMaterial* oldMaterial = pushMaterial(drawable->getStateSet());
         drawable->accept(_primitiveFunctor);
-        _primitiveFunctor.setCurrentMaterial(oldMaterial);
     }
 
     virtual void apply(osg::Geode& geode)
@@ -405,7 +403,7 @@ public:
         if (hasBoundingVolumeTree(geode))
             return;
 
-        const SGMaterial* oldMaterial = pushMaterial(geode.getStateSet());
+        const SGMaterial* oldMaterial = pushMaterial(&geode);
 
         bool flushHere = getNodePath().size() <= 1 || _dumpIntoLeafs;
         if (flushHere) {
@@ -413,6 +411,9 @@ public:
             PFunctor previousPrimitives;
             _primitiveFunctor.swap(previousPrimitives);
 
+            const SGMaterial* mat = previousPrimitives.getCurrentMaterial();
+            _primitiveFunctor.setCurrentMaterial(mat);
+
             // walk the children
             for(unsigned i = 0; i < geode.getNumDrawables(); ++i)
                 fillWith(geode.getDrawable(i));
@@ -453,12 +454,13 @@ public:
         if (hasBoundingVolumeTree(node))
             return;
 
-        const SGMaterial* oldMaterial = pushMaterial(node.getStateSet());
-
         // push the current active primitive list
         PFunctor previousPrimitives;
         _primitiveFunctor.swap(previousPrimitives);
 
+        const SGMaterial* mat = previousPrimitives.getCurrentMaterial();
+        _primitiveFunctor.setCurrentMaterial(mat);
+
         // walk the children
         traverse(node);
 
@@ -469,8 +471,6 @@ public:
 
         // pop the current active primitive list
         _primitiveFunctor.swap(previousPrimitives);
-
-        _primitiveFunctor.setCurrentMaterial(oldMaterial);
     }
 
     void traverseAndCollect(osg::Node& node)
@@ -488,12 +488,8 @@ public:
         // Note that we do not need to push the already collected list of
         // primitives, since we are now in the topmost node ...
 
-        const SGMaterial* oldMaterial = pushMaterial(node.getStateSet());
-
         // walk the children
         traverse(node);
-
-        _primitiveFunctor.setCurrentMaterial(oldMaterial);
     }
 
     void addBoundingVolumeTreeToNode(osg::Node& node)