]> git.mxchange.org Git - simgear.git/commitdiff
Fix problem with ocean files not recognized as water.
authorfrohlich <frohlich>
Mon, 7 Sep 2009 20:37:19 +0000 (20:37 +0000)
committerTim Moore <timoore@redhat.com>
Wed, 9 Sep 2009 06:39:55 +0000 (08:39 +0200)
Move dynamic casts to EffectGeode into the findMaterial method.

Modified Files:
simgear/scene/material/matlib.cxx
simgear/scene/material/matlib.hxx
simgear/scene/model/BoundingVolumeBuildVisitor.hxx

simgear/scene/material/matlib.cxx
simgear/scene/material/matlib.hxx
simgear/scene/model/BoundingVolumeBuildVisitor.hxx

index 36c95bdf07bb6796f23c969ed5a0e1751e2f0165..249977128f229a830ddec4145b1d0f53ebe43c7b 100644 (file)
@@ -127,15 +127,20 @@ SGMaterialLib::~SGMaterialLib ( void ) {
 }
 
 const SGMaterial*
-SGMaterialLib::findMaterial(const simgear::Effect* effect)
+SGMaterialLib::findMaterial(const osg::Geode* geode)
 {
-  if (!effect)
-    return 0;
-
-  const SGMaterialUserData* matUserData
-    = dynamic_cast<const SGMaterialUserData*>(effect->getUserData());
-  if (!matUserData)
-    return 0;
-  else
-    return matUserData->getMaterial();
+    if (!geode)
+        return 0;
+    const simgear::EffectGeode* effectGeode;
+    effectGeode = dynamic_cast<const simgear::EffectGeode*>(geode);
+    if (!effectGeode)
+        return 0;
+    const simgear::Effect* effect = effectGeode->getEffect();
+    if (!effect)
+        return 0;
+    const SGMaterialUserData* userData;
+    userData = dynamic_cast<const SGMaterialUserData*>(effect->getUserData());
+    if (!userData)
+        return 0;
+    return userData->getMaterial();
 }
index 373ae83d81bc2c0ec93fae467e8a795e59f4f2c9..b3e8c9005427f3419f1ebb3eb24772f7edb24531 100644 (file)
@@ -37,8 +37,7 @@
 #include <map>                 // STL associative "array"
 #include <vector>              // STL "array"
 
-#include <osg/Node>
-#include <osg/StateSet>
+#include <osg/Geode>
 
 class SGMaterial;
 class SGPropertyNode;
@@ -82,7 +81,7 @@ public:
     material_map_iterator end() { return matlib.end(); }
     const_material_map_iterator end() const { return matlib.end(); }
 
-    static const SGMaterial* findMaterial(const simgear::Effect* effect);
+    static const SGMaterial* findMaterial(const osg::Geode* geode);
 
     // Destructor
     ~SGMaterialLib ( void );
index 0489f82793f6810d3f5de1903d644fd220b79338..9155bcece2920c62405ee3af31fd675afacd1d55 100644 (file)
@@ -27,8 +27,6 @@
 #include <osg/Transform>
 #include <osg/TriangleFunctor>
 
-#include <simgear/scene/material/Effect.hxx>
-#include <simgear/scene/material/EffectGeode.hxx>
 #include <simgear/scene/material/mat.hxx>
 #include <simgear/scene/material/matlib.hxx>
 #include <simgear/scene/util/SGNodeMasks.hxx>
@@ -386,10 +384,10 @@ public:
     {
     }
 
-    const SGMaterial* pushMaterial(Effect* effect)
+    const SGMaterial* pushMaterial(osg::Geode* geode)
     {
         const SGMaterial* oldMaterial = _primitiveFunctor.getCurrentMaterial();
-        const SGMaterial* material = SGMaterialLib::findMaterial(effect);
+        const SGMaterial* material = SGMaterialLib::findMaterial(geode);
         if (material)
             _primitiveFunctor.setCurrentMaterial(material);
         return oldMaterial;
@@ -405,11 +403,7 @@ public:
         if (hasBoundingVolumeTree(geode))
             return;
 
-        const SGMaterial* oldMaterial = 0;
-
-        EffectGeode *eg = dynamic_cast<EffectGeode*>(&geode);
-        if (eg)
-            oldMaterial = pushMaterial(eg->getEffect());
+        const SGMaterial* oldMaterial = pushMaterial(&geode);
 
         bool flushHere = getNodePath().size() <= 1 || _dumpIntoLeafs;
         if (flushHere) {
@@ -417,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));
@@ -430,8 +427,8 @@ public:
             for(unsigned i = 0; i < geode.getNumDrawables(); ++i)
                 fillWith(geode.getDrawable(i));
         }
-        if (eg)
-            _primitiveFunctor.setCurrentMaterial(oldMaterial);
+
+        _primitiveFunctor.setCurrentMaterial(oldMaterial);
     }
 
     virtual void apply(osg::Group& group)
@@ -461,6 +458,9 @@ public:
         PFunctor previousPrimitives;
         _primitiveFunctor.swap(previousPrimitives);
 
+        const SGMaterial* mat = previousPrimitives.getCurrentMaterial();
+        _primitiveFunctor.setCurrentMaterial(mat);
+
         // walk the children
         traverse(node);