osg::Node::accept()
void Node::accept(NodeVisitor& nv)
{
if (nv.validNodeMask(*this))
{
nv.pushOntoNodePath(this);
nv.apply(*this);
nv.popFromNodePath();
}
}
osg::NodeVisitor::apply()
virtual void apply(Drawable& drawable);
virtual void apply(Geometry& geometry);
virtual void apply(Node& node);
virtual void apply(Geode& node);
virtual void apply(Billboard& node);
virtual void apply(Group& node);
osg::NodeVisitor::traverse()
/** 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);
}
osg::Node::traverse()
/** Traverse downwards : calls children's accept method with NodeVisitor.*/
virtual void traverse(NodeVisitor& /*nv*/) {}
osg::Group::traverse()
void Group::traverse(NodeVisitor& nv)
{
for(NodeList::iterator itr=_children.begin();
itr!=_children.end();
++itr)
{
(*itr)->accept(nv);
}
}
CullVisitor::apply()
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);
}