}
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();
}
#include <map> // STL associative "array"
#include <vector> // STL "array"
-#include <osg/Node>
-#include <osg/StateSet>
+#include <osg/Geode>
class SGMaterial;
class SGPropertyNode;
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 );
#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>
{
}
- 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;
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) {
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));
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)
PFunctor previousPrimitives;
_primitiveFunctor.swap(previousPrimitives);
+ const SGMaterial* mat = previousPrimitives.getCurrentMaterial();
+ _primitiveFunctor.setCurrentMaterial(mat);
+
// walk the children
traverse(node);