2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2002-12-19 23:55:40 +08:00
|
|
|
#ifndef OSGUTIL_UPDATEVISITOR
|
|
|
|
#define OSGUTIL_UPDATEVISITOR 1
|
2001-09-20 07:41:39 +08:00
|
|
|
|
|
|
|
#include <osg/NodeVisitor>
|
|
|
|
#include <osg/Geode>
|
|
|
|
#include <osg/Billboard>
|
|
|
|
#include <osg/LOD>
|
|
|
|
#include <osg/Switch>
|
|
|
|
#include <osg/LightSource>
|
|
|
|
#include <osg/Transform>
|
2002-04-15 21:15:48 +08:00
|
|
|
#include <osg/Projection>
|
2002-06-12 02:41:57 +08:00
|
|
|
#include <osg/OccluderNode>
|
2014-06-06 00:26:13 +08:00
|
|
|
#include <osg/ScriptEngine>
|
2001-09-20 07:41:39 +08:00
|
|
|
|
|
|
|
#include <osgUtil/Export>
|
|
|
|
|
|
|
|
namespace osgUtil {
|
|
|
|
|
|
|
|
/**
|
2002-12-19 23:55:40 +08:00
|
|
|
* Basic UpdateVisitor implementation for animating a scene.
|
2004-10-24 22:42:40 +08:00
|
|
|
* This visitor traverses the scene graph, calling each nodes appCallback if
|
2012-03-22 01:36:20 +08:00
|
|
|
* it exists.
|
2001-09-20 07:41:39 +08:00
|
|
|
*/
|
2002-12-19 23:55:40 +08:00
|
|
|
class OSGUTIL_EXPORT UpdateVisitor : public osg::NodeVisitor
|
2001-09-20 07:41:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2002-12-19 23:55:40 +08:00
|
|
|
UpdateVisitor();
|
|
|
|
virtual ~UpdateVisitor();
|
2001-09-20 07:41:39 +08:00
|
|
|
|
2013-01-25 02:48:34 +08:00
|
|
|
META_NodeVisitor(osgUtil, UpdateVisitor)
|
2008-12-17 20:13:15 +08:00
|
|
|
|
2001-09-20 07:41:39 +08:00
|
|
|
virtual void reset();
|
|
|
|
|
2008-12-17 20:13:15 +08:00
|
|
|
/** During traversal each type of node calls its callbacks and its children traversed. */
|
2014-05-21 00:09:34 +08:00
|
|
|
virtual void apply(osg::Node& node) { handle_callbacks_and_traverse(node); }
|
|
|
|
|
|
|
|
virtual void apply(osg::Drawable& drawable)
|
|
|
|
{
|
2014-06-06 00:26:13 +08:00
|
|
|
osg::Callback* callback = drawable.getUpdateCallback();
|
|
|
|
if (callback)
|
|
|
|
{
|
|
|
|
osg::Drawable::UpdateCallback* drawable_callback = dynamic_cast<osg::Drawable::UpdateCallback*>(callback);
|
|
|
|
osg::NodeCallback* node_callback = dynamic_cast<osg::NodeCallback*>(callback);
|
|
|
|
|
|
|
|
if (drawable_callback) drawable_callback->update(this,&drawable);
|
|
|
|
if (node_callback) (*node_callback)(&drawable, this);
|
2014-05-21 00:09:34 +08:00
|
|
|
|
2016-11-24 03:18:14 +08:00
|
|
|
if (!drawable_callback && !node_callback) callback->run(&drawable, this);
|
2014-06-06 00:26:13 +08:00
|
|
|
}
|
2014-05-21 00:09:34 +08:00
|
|
|
|
|
|
|
handle_callbacks(drawable.getStateSet());
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2014-06-06 00:26:13 +08:00
|
|
|
virtual void apply(osg::Geode& node) { handle_callbacks_and_traverse(node); }
|
|
|
|
virtual void apply(osg::Billboard& node) { handle_callbacks_and_traverse(node); }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-06-12 02:41:57 +08:00
|
|
|
virtual void apply(osg::LightSource& node) { handle_callbacks_and_traverse(node); }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-06-12 02:41:57 +08:00
|
|
|
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::OccluderNode& node) { handle_callbacks_and_traverse(node); }
|
2001-09-20 07:41:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2004-10-24 22:42:40 +08:00
|
|
|
// /** Prevent unwanted copy construction.*/
|
2003-06-24 23:40:09 +08:00
|
|
|
// UpdateVisitor(const UpdateVisitor&):osg::NodeVisitor() {}
|
2001-09-20 07:41:39 +08:00
|
|
|
|
2004-10-24 22:42:40 +08:00
|
|
|
/** Prevent unwanted copy operator.*/
|
2002-12-19 23:55:40 +08:00
|
|
|
UpdateVisitor& operator = (const UpdateVisitor&) { return *this; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-04-25 19:05:02 +08:00
|
|
|
inline void handle_callbacks(osg::StateSet* stateset)
|
|
|
|
{
|
|
|
|
if (stateset && stateset->requiresUpdateTraversal())
|
|
|
|
{
|
|
|
|
stateset->runUpdateCallbacks(this);
|
|
|
|
}
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-04-15 21:15:48 +08:00
|
|
|
inline void handle_callbacks_and_traverse(osg::Node& node)
|
2001-09-20 07:41:39 +08:00
|
|
|
{
|
2005-04-25 19:05:02 +08:00
|
|
|
handle_callbacks(node.getStateSet());
|
|
|
|
|
2014-06-06 00:26:13 +08:00
|
|
|
osg::Callback* callback = node.getUpdateCallback();
|
|
|
|
if (callback) callback->run(&node,this);
|
2002-12-19 23:55:40 +08:00
|
|
|
else if (node.getNumChildrenRequiringUpdateTraversal()>0) traverse(node);
|
2001-09-20 07:41:39 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-09-20 07:41:39 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|