91 lines
3.0 KiB
Plaintext
91 lines
3.0 KiB
Plaintext
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
//as published by the Free Software Foundation.
|
|
|
|
#ifndef OSGUTIL_APPVISITOR
|
|
#define OSGUTIL_APPVISITOR 1
|
|
|
|
#include <osg/NodeVisitor>
|
|
#include <osg/Node>
|
|
#include <osg/Geode>
|
|
#include <osg/Billboard>
|
|
#include <osg/LOD>
|
|
#include <osg/Switch>
|
|
#include <osg/LightSource>
|
|
#include <osg/Transform>
|
|
#include <osg/Projection>
|
|
#include <osg/Impostor>
|
|
#include <osg/OccluderNode>
|
|
|
|
#include <osgUtil/Export>
|
|
|
|
namespace osgUtil {
|
|
|
|
/**
|
|
* Basic AppVisitor implementation for animating a scene.
|
|
* This visitor traverses the scene graph, call each nodes appCallback if
|
|
* it exists.
|
|
*/
|
|
class OSGUTIL_EXPORT AppVisitor : public osg::NodeVisitor
|
|
{
|
|
public:
|
|
|
|
AppVisitor();
|
|
virtual ~AppVisitor();
|
|
|
|
virtual void reset();
|
|
|
|
virtual void apply(osg::Node& node) { handle_callbacks_and_traverse(node); }
|
|
|
|
virtual void apply(osg::Geode& node) { handle_geode_callbacks(node); }
|
|
virtual void apply(osg::Billboard& node) { handle_geode_callbacks(node); }
|
|
|
|
virtual void apply(osg::LightSource& node) { handle_callbacks_and_traverse(node); }
|
|
|
|
virtual void apply(osg::Group& node) { handle_callbacks_and_traverse(node); }
|
|
virtual void apply(osg::Transform& node) { handle_callbacks_and_traverse(node); }
|
|
virtual void apply(osg::Projection& node) { handle_callbacks_and_traverse(node); }
|
|
virtual void apply(osg::Switch& node) { handle_callbacks_and_traverse(node); }
|
|
virtual void apply(osg::LOD& node) { handle_callbacks_and_traverse(node); }
|
|
virtual void apply(osg::Impostor& node) { handle_callbacks_and_traverse(node); }
|
|
virtual void apply(osg::OccluderNode& node) { handle_callbacks_and_traverse(node); }
|
|
|
|
|
|
protected:
|
|
|
|
/** prevent unwanted copy construction.*/
|
|
AppVisitor(const AppVisitor&):osg::NodeVisitor() {}
|
|
|
|
/** prevent unwanted copy operator.*/
|
|
AppVisitor& operator = (const AppVisitor&) { return *this; }
|
|
|
|
inline void handle_callbacks_and_traverse(osg::Node& node)
|
|
{
|
|
osg::NodeCallback* callback = node.getAppCallback();
|
|
if (callback) (*callback)(&node,this);
|
|
else if (node.getNumChildrenRequiringAppTraversal()>0) traverse(node);
|
|
}
|
|
|
|
inline void handle_geode_callbacks(osg::Geode& node)
|
|
{
|
|
osg::NodeCallback* callback = node.getAppCallback();
|
|
if (callback) (*callback)(&node,this);
|
|
else if (node.getNumChildrenRequiringAppTraversal()>0) traverse(node);
|
|
|
|
// call the app callbacks on the drawables.
|
|
for(int i=0;i<node.getNumDrawables();++i)
|
|
{
|
|
osg::Drawable::AppCallback* callback = node.getDrawable(i)->getAppCallback();
|
|
if (callback) callback->app(this,node.getDrawable(i));
|
|
}
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|
|
|