Added detection and disabling of flattening of static transforms which a

LightPointNode exists in the scene graph.
This commit is contained in:
Robert Osfield 2004-07-29 10:13:02 +00:00
parent 3d61e25cce
commit 9b9cb9cdb0
2 changed files with 32 additions and 1 deletions

View File

@ -125,6 +125,7 @@ class OSGUTIL_EXPORT Optimizer
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
_optimizer(optimizer) {}
virtual void apply(osg::Node& geode);
virtual void apply(osg::Geode& geode);
virtual void apply(osg::Billboard& geode);
virtual void apply(osg::Transform& transform);
@ -142,10 +143,12 @@ class OSGUTIL_EXPORT Optimizer
typedef std::vector<osg::Transform*> TransformStack;
typedef std::set<osg::Drawable*> DrawableSet;
typedef std::set<osg::Billboard*> BillboardSet;
typedef std::set<osg::Node* > NodeSet;
typedef std::set<osg::Transform*> TransformSet;
Optimizer* _optimizer;
TransformStack _transformStack;
NodeSet _excludedNodeSet;
DrawableSet _drawableSet;
BillboardSet _billboardSet;
TransformSet _transformSet;

View File

@ -548,6 +548,15 @@ class CollectLowestTransformsVisitor : public osg::NodeVisitor
}
void collectDataFor(osg::Node* node)
{
_currentObjectList.push_back(node);
node->accept(*this);
_currentObjectList.pop_back();
}
void collectDataFor(osg::Billboard* billboard)
{
_currentObjectList.push_back(billboard);
@ -578,9 +587,13 @@ class CollectLowestTransformsVisitor : public osg::NodeVisitor
inline bool isOperationPermissableForObject(const osg::Object* object)
{
// disable if cannot apply transform functor.
const osg::Drawable* drawable = dynamic_cast<const osg::Drawable*>(object);
if (drawable && !drawable->supports(_transformFunctor)) return false;
// disable if object is a light point node.
if (strcmp(object->className(),"LightPointNode")==0) return false;
return _optimizer ? _optimizer->isOperationPermissableForObject(object,Optimizer::FLATTEN_STATIC_TRANSFORMS) : true;
}
@ -903,9 +916,17 @@ bool CollectLowestTransformsVisitor::removeTransforms(osg::Node* nodeWeCannotRem
return transformRemoved;
}
void Optimizer::FlattenStaticTransformsVisitor::apply(osg::Node& node)
{
if (strcmp(node.className(),"LightPointNode")==0)
{
_excludedNodeSet.insert(&node);
}
traverse(node);
}
void Optimizer::FlattenStaticTransformsVisitor::apply(osg::Geode& geode)
{
if (!_transformStack.empty())
{
for(unsigned int i=0;i<geode.getNumDrawables();++i)
@ -945,6 +966,13 @@ bool Optimizer::FlattenStaticTransformsVisitor::removeTransforms(osg::Node* node
{
CollectLowestTransformsVisitor cltv(_optimizer);
for(NodeSet::iterator nitr=_excludedNodeSet.begin();
nitr!=_excludedNodeSet.end();
++nitr)
{
cltv.collectDataFor(*nitr);
}
for(DrawableSet::iterator ditr=_drawableSet.begin();
ditr!=_drawableSet.end();
++ditr)