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/Node>
|
|
|
|
#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>
|
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. */
|
2002-06-12 02:41:57 +08:00
|
|
|
virtual void apply(osg::Node& node) { handle_callbacks_and_traverse(node); }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-07-10 23:35:47 +08:00
|
|
|
virtual void apply(osg::Geode& node) { handle_geode_callbacks(node); }
|
|
|
|
virtual void apply(osg::Billboard& node) { handle_geode_callbacks(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());
|
|
|
|
|
2002-12-19 23:55:40 +08:00
|
|
|
osg::NodeCallback* callback = node.getUpdateCallback();
|
2001-09-20 07:41:39 +08:00
|
|
|
if (callback) (*callback)(&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
|
|
|
}
|
|
|
|
|
2005-04-25 19:05:02 +08:00
|
|
|
inline void handle_geode_callbacks(osg::Geode& geode)
|
2003-03-22 17:48:43 +08:00
|
|
|
{
|
2005-04-25 19:05:02 +08:00
|
|
|
handle_callbacks(geode.getStateSet());
|
|
|
|
|
|
|
|
osg::NodeCallback* callback = geode.getUpdateCallback();
|
|
|
|
if (callback) (*callback)(&geode,this);
|
|
|
|
|
2004-10-24 22:42:40 +08:00
|
|
|
// Call the app callbacks on the drawables.
|
2003-03-22 17:48:43 +08:00
|
|
|
for(unsigned int i=0;i<geode.getNumDrawables();++i)
|
2002-07-10 23:35:47 +08:00
|
|
|
{
|
2003-03-22 17:48:43 +08:00
|
|
|
osg::Drawable::UpdateCallback* callback = geode.getDrawable(i)->getUpdateCallback();
|
|
|
|
if (callback) callback->update(this,geode.getDrawable(i));
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-04-25 19:05:02 +08:00
|
|
|
handle_callbacks(geode.getDrawable(i)->getStateSet());
|
2002-07-10 23:35:47 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-04-25 19:05:02 +08:00
|
|
|
// should we traverse just in case a subclass of Geode adds children?? Won't for now as
|
|
|
|
// Geode's arn't designed to have children.
|
|
|
|
// traverse(geode);
|
2012-03-22 01:36:20 +08:00
|
|
|
}
|
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
|
|
|
|
|