diff --git a/include/osg/Geometry b/include/osg/Geometry index a8c0a43cf..de819fe23 100644 --- a/include/osg/Geometry +++ b/include/osg/Geometry @@ -42,6 +42,8 @@ class SG_EXPORT Geometry : public Drawable virtual Geometry* asGeometry() { return this; } virtual const Geometry* asGeometry() const { return this; } + bool empty() const; + enum AttributeBinding { BIND_OFF=0, @@ -83,6 +85,8 @@ class SG_EXPORT Geometry : public Drawable offset = rhs.offset; return *this; } + + inline bool empty() const { return !array.valid(); } ref_ptr array; ref_ptr indices; @@ -124,6 +128,8 @@ class SG_EXPORT Geometry : public Drawable return *this; } + inline bool empty() const { return !array.valid(); } + ref_ptr array; ref_ptr indices; AttributeBinding binding; diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index 63b8fbcbd..117e30a3d 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -420,6 +420,19 @@ Geometry::~Geometry() // 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) { if (_texCoordList.size()<=unit) diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index b92b4b3f5..0065b7524 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -1018,6 +1018,16 @@ bool Optimizer::CombineStaticTransformsVisitor::removeTransforms(osg::Node* node 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.getNumDrawables()==0 && isNodeEmpty(geode)) _redundantNodeList.insert(&geode);