/** Method for handling traversal of a nodes.
If you intend to use the visitor for actively traversing
the scene graph then make sure the accept() methods call
this method unless they handle traversal directly.*/
inline void traverse(Node& node)
{
if (_traversalMode==TRAVERSE_PARENTS) node.ascend(*this);
else if (_traversalMode!=TRAVERSE_NONE) node.traverse(*this);
}
void CullVisitor::apply(Node& node)
{
if (isCulled(node)) return;
// push the culling mode.
pushCurrentMask();
// push the node's state.
StateSet* node_state = node.getStateSet();
if (node_state) pushStateSet(node_state);
handle_cull_callbacks_and_traverse(node);
// pop the node's state off the geostate stack.
if (node_state) popStateSet();
// pop the culling mode.
popCurrentMask();
}
inline void handle_cull_callbacks_and_traverse(osg::Node& node)
{
osg::Callback* callback = node.getCullCallback();
if (callback) callback->run(&node,this);
else traverse(node);
}