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*
|
const SGMaterial*
|
||||||
SGMaterialLib::findMaterial(const simgear::Effect* effect)
|
SGMaterialLib::findMaterial(const osg::Geode* geode)
|
||||||
{
|
{
|
||||||
if (!effect)
|
if (!geode)
|
||||||
return 0;
|
return 0;
|
||||||
|
const simgear::EffectGeode* effectGeode;
|
||||||
const SGMaterialUserData* matUserData
|
effectGeode = dynamic_cast<const simgear::EffectGeode*>(geode);
|
||||||
= dynamic_cast<const SGMaterialUserData*>(effect->getUserData());
|
if (!effectGeode)
|
||||||
if (!matUserData)
|
return 0;
|
||||||
return 0;
|
const simgear::Effect* effect = effectGeode->getEffect();
|
||||||
else
|
if (!effect)
|
||||||
return matUserData->getMaterial();
|
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 <map> // STL associative "array"
|
||||||
#include <vector> // STL "array"
|
#include <vector> // STL "array"
|
||||||
|
|
||||||
#include <osg/Node>
|
#include <osg/Geode>
|
||||||
#include <osg/StateSet>
|
|
||||||
|
|
||||||
class SGMaterial;
|
class SGMaterial;
|
||||||
class SGPropertyNode;
|
class SGPropertyNode;
|
||||||
@@ -82,7 +81,7 @@ public:
|
|||||||
material_map_iterator end() { return matlib.end(); }
|
material_map_iterator end() { return matlib.end(); }
|
||||||
const_material_map_iterator end() const { 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
|
// Destructor
|
||||||
~SGMaterialLib ( void );
|
~SGMaterialLib ( void );
|
||||||
|
|||||||
@@ -27,8 +27,6 @@
|
|||||||
#include <osg/Transform>
|
#include <osg/Transform>
|
||||||
#include <osg/TriangleFunctor>
|
#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/mat.hxx>
|
||||||
#include <simgear/scene/material/matlib.hxx>
|
#include <simgear/scene/material/matlib.hxx>
|
||||||
#include <simgear/scene/util/SGNodeMasks.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* oldMaterial = _primitiveFunctor.getCurrentMaterial();
|
||||||
const SGMaterial* material = SGMaterialLib::findMaterial(effect);
|
const SGMaterial* material = SGMaterialLib::findMaterial(geode);
|
||||||
if (material)
|
if (material)
|
||||||
_primitiveFunctor.setCurrentMaterial(material);
|
_primitiveFunctor.setCurrentMaterial(material);
|
||||||
return oldMaterial;
|
return oldMaterial;
|
||||||
@@ -405,11 +403,7 @@ public:
|
|||||||
if (hasBoundingVolumeTree(geode))
|
if (hasBoundingVolumeTree(geode))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const SGMaterial* oldMaterial = 0;
|
const SGMaterial* oldMaterial = pushMaterial(&geode);
|
||||||
|
|
||||||
EffectGeode *eg = dynamic_cast<EffectGeode*>(&geode);
|
|
||||||
if (eg)
|
|
||||||
oldMaterial = pushMaterial(eg->getEffect());
|
|
||||||
|
|
||||||
bool flushHere = getNodePath().size() <= 1 || _dumpIntoLeafs;
|
bool flushHere = getNodePath().size() <= 1 || _dumpIntoLeafs;
|
||||||
if (flushHere) {
|
if (flushHere) {
|
||||||
@@ -417,6 +411,9 @@ public:
|
|||||||
PFunctor previousPrimitives;
|
PFunctor previousPrimitives;
|
||||||
_primitiveFunctor.swap(previousPrimitives);
|
_primitiveFunctor.swap(previousPrimitives);
|
||||||
|
|
||||||
|
const SGMaterial* mat = previousPrimitives.getCurrentMaterial();
|
||||||
|
_primitiveFunctor.setCurrentMaterial(mat);
|
||||||
|
|
||||||
// walk the children
|
// walk the children
|
||||||
for(unsigned i = 0; i < geode.getNumDrawables(); ++i)
|
for(unsigned i = 0; i < geode.getNumDrawables(); ++i)
|
||||||
fillWith(geode.getDrawable(i));
|
fillWith(geode.getDrawable(i));
|
||||||
@@ -430,8 +427,8 @@ public:
|
|||||||
for(unsigned i = 0; i < geode.getNumDrawables(); ++i)
|
for(unsigned i = 0; i < geode.getNumDrawables(); ++i)
|
||||||
fillWith(geode.getDrawable(i));
|
fillWith(geode.getDrawable(i));
|
||||||
}
|
}
|
||||||
if (eg)
|
|
||||||
_primitiveFunctor.setCurrentMaterial(oldMaterial);
|
_primitiveFunctor.setCurrentMaterial(oldMaterial);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void apply(osg::Group& group)
|
virtual void apply(osg::Group& group)
|
||||||
@@ -461,6 +458,9 @@ public:
|
|||||||
PFunctor previousPrimitives;
|
PFunctor previousPrimitives;
|
||||||
_primitiveFunctor.swap(previousPrimitives);
|
_primitiveFunctor.swap(previousPrimitives);
|
||||||
|
|
||||||
|
const SGMaterial* mat = previousPrimitives.getCurrentMaterial();
|
||||||
|
_primitiveFunctor.setCurrentMaterial(mat);
|
||||||
|
|
||||||
// walk the children
|
// walk the children
|
||||||
traverse(node);
|
traverse(node);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user