Prune empty nodes in RemoveDrawableVisitor

Gets rid of 28 useless transform nodes in base_anim.1st.nif.
c++11
scrawl 10 years ago
parent f017fd6860
commit a5b72a358b

@ -182,7 +182,12 @@ namespace
virtual void apply(osg::Geode &node)
{
// Not safe to remove in apply(), since the visitor is still iterating the child list
mToRemove.push_back(&node);
osg::Group* parent = node.getParent(0);
// prune nodes that would be empty after the removal
if (parent->getNumChildren() == 1 && parent->getDataVariance() == osg::Object::STATIC)
mToRemove.push_back(parent);
else
mToRemove.push_back(&node);
traverse(node);
}

@ -451,6 +451,22 @@ namespace NifOsg
transformNode->addCullCallback(new BillboardCallback);
}
// Set a default DataVariance (used as hint by optimization routines).
switch (nifNode->recType)
{
case Nif::RC_NiTriShape:
case Nif::RC_NiAutoNormalParticles:
case Nif::RC_NiRotatingParticles:
// Leaf nodes in the NIF hierarchy, so won't be able to dynamically attach children.
// No support for keyframe controllers (just crashes in the original engine).
transformNode->setDataVariance(osg::Object::STATIC);
break;
default:
// could have new children attached at any time, or added external keyframe controllers from .kf files
transformNode->setDataVariance(osg::Object::DYNAMIC);
break;
}
transformNode->setName(nifNode->name);
if (parentNode)

Loading…
Cancel
Save