]> git.mxchange.org Git - simgear.git/commitdiff
descend into Effects to find default material animation values
authorTim Moore <timoore@redhat.com>
Mon, 16 Nov 2009 21:43:41 +0000 (22:43 +0100)
committerTim Moore <timoore@redhat.com>
Mon, 16 Nov 2009 21:43:41 +0000 (22:43 +0100)
simgear/scene/model/SGMaterialAnimation.cxx

index ca9ac364d27c42e36a5bcd00cf4590a406ecd23c..d726a59c5a6a4a0abb628f9e21a0b4596c8af7b4 100644 (file)
 
 #include <simgear/props/condition.hxx>
 #include <simgear/props/props.hxx>
+#include <simgear/scene/material/Effect.hxx>
+#include <simgear/scene/material/EffectGeode.hxx>
+#include <simgear/scene/material/Pass.hxx>
+#include <simgear/scene/material/Technique.hxx>
 #include <simgear/scene/model/model.hxx>
 
+using namespace std;
+
 namespace {
 /**
  * Get a color from properties.
@@ -209,7 +215,25 @@ public:
 
   virtual void apply(osg::Geode& node)
   {
-    maybeGetMaterialValues(node.getStateSet());
+    using namespace simgear;
+    EffectGeode* eg = dynamic_cast<EffectGeode*>(&node);
+    if (eg) {
+      const Effect* effect = eg->getEffect();
+      if (effect)
+        for (vector<osg::ref_ptr<Technique> >::const_iterator itr
+               = effect->techniques.begin(), end = effect->techniques.end();
+             itr != end;
+             ++itr) {
+          const Technique* tniq = itr->get();
+          for (vector<osg::ref_ptr<Pass> >::const_iterator pitr
+                 = tniq->passes.begin(), pend = tniq->passes.end();
+               pitr != pend;
+               ++pitr)
+            maybeGetMaterialValues(pitr->get());
+        }
+    } else {
+      maybeGetMaterialValues(node.getStateSet());
+    }
     int numDrawables = node.getNumDrawables();
     for (int i = 0; i < numDrawables; i++) {
       osg::Geometry* geom = dynamic_cast<osg::Geometry*>(node.getDrawable(i));
@@ -230,18 +254,20 @@ public:
     }
   }
   
-  void maybeGetMaterialValues(osg::StateSet* stateSet)
+  void maybeGetMaterialValues(const osg::StateSet* stateSet)
   {
     if (!stateSet)
       return;
-    osg::Material* nodeMat
-      = dynamic_cast<osg::Material*>(stateSet->getAttribute(osg::StateAttribute::MATERIAL));
+    const osg::Material* nodeMat
+      = dynamic_cast<const osg::Material*>(stateSet
+                                           ->getAttribute(osg::StateAttribute
+                                                          ::MATERIAL));
     if (!nodeMat)
       return;
     material = nodeMat;
   }
 
-  osg::ref_ptr<osg::Material> material;
+  osg::ref_ptr<const osg::Material> material;
   osg::Vec4 ambientDiffuse;
 };