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:
parent
74ef590992
commit
aa52005b87
@ -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> array;
|
||||
ref_ptr<IndexArray> indices;
|
||||
@ -124,6 +128,8 @@ class SG_EXPORT Geometry : public Drawable
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool empty() const { return !array.valid(); }
|
||||
|
||||
ref_ptr<Vec3Array> array;
|
||||
ref_ptr<IndexArray> indices;
|
||||
AttributeBinding binding;
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user