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
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user