From: Tim Moore Date: Mon, 16 Nov 2009 21:43:41 +0000 (+0100) Subject: descend into Effects to find default material animation values X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;ds=inline;h=3cd53224964afc3bb30a826cd4696867e782f1bf;p=simgear.git descend into Effects to find default material animation values --- diff --git a/simgear/scene/model/SGMaterialAnimation.cxx b/simgear/scene/model/SGMaterialAnimation.cxx index ca9ac364..d726a59c 100644 --- a/simgear/scene/model/SGMaterialAnimation.cxx +++ b/simgear/scene/model/SGMaterialAnimation.cxx @@ -22,8 +22,14 @@ #include #include +#include +#include +#include +#include #include +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(&node); + if (eg) { + const Effect* effect = eg->getEffect(); + if (effect) + for (vector >::const_iterator itr + = effect->techniques.begin(), end = effect->techniques.end(); + itr != end; + ++itr) { + const Technique* tniq = itr->get(); + for (vector >::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(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(stateSet->getAttribute(osg::StateAttribute::MATERIAL)); + const osg::Material* nodeMat + = dynamic_cast(stateSet + ->getAttribute(osg::StateAttribute + ::MATERIAL)); if (!nodeMat) return; material = nodeMat; } - osg::ref_ptr material; + osg::ref_ptr material; osg::Vec4 ambientDiffuse; };