From 5947b97cde31a8b600ddda7c6ee7a3caf34210fd Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 17 May 2005 14:25:11 +0000 Subject: [PATCH] Improved the handling of data attached to proxy nodes --- src/osgUtil/Optimizer.cpp | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index cd9e405b0..89814f35e 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -1326,21 +1326,50 @@ void Optimizer::RemoveLoadedProxyNodesVisitor::removeRedundantNodes() osg::ref_ptr group = dynamic_cast(*itr); if (group.valid()) { - // take a copy of parents list since subsequent removes will modify the original one. - osg::Node::ParentList parents = group->getParents(); + + // first check to see if data was attached to the ProxyNode that we need to keep. + bool keepData = false; + if (!group->getName().empty()) keepData = true; + if (!group->getDescriptions().empty()) keepData = true; + if (group->getNodeMask()) keepData = true; + if (group->getUpdateCallback()) keepData = true; + if (group->getEventCallback()) keepData = true; + if (group->getCullCallback()) keepData = true; - for(unsigned int i=0;igetNumChildren();++i) + if (keepData) { - osg::Node* child = group->getChild(i); + // create a group to store all proxy's children and data. + osg::ref_ptr newGroup = new osg::Group(*group,osg::CopyOp::SHALLOW_COPY); + + + // take a copy of parents list since subsequent removes will modify the original one. + osg::Node::ParentList parents = group->getParents(); + for(osg::Node::ParentList::iterator pitr=parents.begin(); pitr!=parents.end(); ++pitr) { - (*pitr)->replaceChild(group.get(),child); + (*pitr)->replaceChild(group.get(),newGroup.get()); } } + else + { + // take a copy of parents list since subsequent removes will modify the original one. + osg::Node::ParentList parents = group->getParents(); + for(unsigned int i=0;igetNumChildren();++i) + { + osg::Node* child = group->getChild(i); + for(osg::Node::ParentList::iterator pitr=parents.begin(); + pitr!=parents.end(); + ++pitr) + { + (*pitr)->replaceChild(group.get(),child); + } + + } + } } else {