void RemoveOcclusionQueryVisitor::apply( osg::OcclusionQueryNode& oqn ) { if (oqn.getNumParents() == 0) { // Even if this is an OQN, can't delete it because it's the root. traverse( oqn ); return; } osg::ref_ptr<osg::OcclusionQueryNode> oqnPtr = &oqn; unsigned int np = oqn.getNumParents(); while (np--) { osg::Group* parent = dynamic_cast<osg::Group*>( oqn.getParent( np ) ); if (parent != NULL) { // Remove OQN from parent. parent->removeChild( oqnPtr.get() ); // Add OQN's children to parent. unsigned int nc = oqn.getNumChildren(); while (nc--) parent->addChild( oqn.getChild( nc ) ); } } }