From: frohlich Date: Mon, 7 Sep 2009 20:37:19 +0000 (+0000) Subject: Fix problem with ocean files not recognized as water. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1b936b9af8a86bdc02fb4365ff488c492555b59f;p=simgear.git Fix problem with ocean files not recognized as water. 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 --- diff --git a/simgear/scene/material/matlib.cxx b/simgear/scene/material/matlib.cxx index 36c95bdf..24997712 100644 --- a/simgear/scene/material/matlib.cxx +++ b/simgear/scene/material/matlib.cxx @@ -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(effect->getUserData()); - if (!matUserData) - return 0; - else - return matUserData->getMaterial(); + if (!geode) + return 0; + const simgear::EffectGeode* effectGeode; + effectGeode = dynamic_cast(geode); + if (!effectGeode) + return 0; + const simgear::Effect* effect = effectGeode->getEffect(); + if (!effect) + return 0; + const SGMaterialUserData* userData; + userData = dynamic_cast(effect->getUserData()); + if (!userData) + return 0; + return userData->getMaterial(); } diff --git a/simgear/scene/material/matlib.hxx b/simgear/scene/material/matlib.hxx index 373ae83d..b3e8c900 100644 --- a/simgear/scene/material/matlib.hxx +++ b/simgear/scene/material/matlib.hxx @@ -37,8 +37,7 @@ #include // STL associative "array" #include // STL "array" -#include -#include +#include 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 ); diff --git a/simgear/scene/model/BoundingVolumeBuildVisitor.hxx b/simgear/scene/model/BoundingVolumeBuildVisitor.hxx index 0489f827..9155bcec 100644 --- a/simgear/scene/model/BoundingVolumeBuildVisitor.hxx +++ b/simgear/scene/model/BoundingVolumeBuildVisitor.hxx @@ -27,8 +27,6 @@ #include #include -#include -#include #include #include #include @@ -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(&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);