Added empty() method to Geometry to facilitate tests for removing empty

geometry from the scene graph.

Added removal of empty geometry leaves from within the RemoveEmptyNodeVisitor
This commit is contained in:
Robert Osfield 2004-03-29 10:24:16 +00:00
parent 74ef590992
commit aa52005b87
3 changed files with 29 additions and 0 deletions

View File

@ -42,6 +42,8 @@ class SG_EXPORT Geometry : public Drawable
virtual Geometry* asGeometry() { return this; } virtual Geometry* asGeometry() { return this; }
virtual const Geometry* asGeometry() const { return this; } virtual const Geometry* asGeometry() const { return this; }
bool empty() const;
enum AttributeBinding enum AttributeBinding
{ {
BIND_OFF=0, BIND_OFF=0,
@ -83,6 +85,8 @@ class SG_EXPORT Geometry : public Drawable
offset = rhs.offset; offset = rhs.offset;
return *this; return *this;
} }
inline bool empty() const { return !array.valid(); }
ref_ptr<Array> array; ref_ptr<Array> array;
ref_ptr<IndexArray> indices; ref_ptr<IndexArray> indices;
@ -124,6 +128,8 @@ class SG_EXPORT Geometry : public Drawable
return *this; return *this;
} }
inline bool empty() const { return !array.valid(); }
ref_ptr<Vec3Array> array; ref_ptr<Vec3Array> array;
ref_ptr<IndexArray> indices; ref_ptr<IndexArray> indices;
AttributeBinding binding; AttributeBinding binding;

View File

@ -420,6 +420,19 @@ Geometry::~Geometry()
// no need to delete, all automatically handled by ref_ptr :-) // no need to delete, all automatically handled by ref_ptr :-)
} }
bool Geometry::empty() const
{
if (!_primitives.empty()) return false;
if (!_vertexData.empty()) return false;
if (!_normalData.empty()) return false;
if (!_colorData.empty()) return false;
if (!_secondaryColorData.empty()) return false;
if (!_fogCoordData.empty()) return false;
if (!_texCoordList.empty()) return false;
if (!_vertexAttribList.empty()) return false;
return true;
}
void Geometry::setTexCoordData(unsigned int unit,const ArrayData& arrayData) void Geometry::setTexCoordData(unsigned int unit,const ArrayData& arrayData)
{ {
if (_texCoordList.size()<=unit) if (_texCoordList.size()<=unit)

View File

@ -1018,6 +1018,16 @@ bool Optimizer::CombineStaticTransformsVisitor::removeTransforms(osg::Node* node
void Optimizer::RemoveEmptyNodesVisitor::apply(osg::Geode& geode) void Optimizer::RemoveEmptyNodesVisitor::apply(osg::Geode& geode)
{ {
for(int i=geode.getNumDrawables()-1;i>=0;--i)
{
osg::Geometry* geom = geode.getDrawable(i)->asGeometry();
if (geom && geom->empty())
{
geode.removeDrawable(i);
}
}
if (geode.getNumParents()>0) if (geode.getNumParents()>0)
{ {
if (geode.getNumDrawables()==0 && isNodeEmpty(geode)) _redundantNodeList.insert(&geode); if (geode.getNumDrawables()==0 && isNodeEmpty(geode)) _redundantNodeList.insert(&geode);