root/OpenSceneGraph/trunk/include/osgUtil/UpdateVisitor @ 13041

Revision 13041, 4.0 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGUTIL_UPDATEVISITOR
15#define OSGUTIL_UPDATEVISITOR 1
16
17#include <osg/NodeVisitor>
18#include <osg/Node>
19#include <osg/Geode>
20#include <osg/Billboard>
21#include <osg/LOD>
22#include <osg/Switch>
23#include <osg/LightSource>
24#include <osg/Transform>
25#include <osg/Projection>
26#include <osg/OccluderNode>
27
28#include <osgUtil/Export>
29
30namespace osgUtil {
31
32/**
33 * Basic UpdateVisitor implementation for animating a scene.
34 * This visitor traverses the scene graph, calling each nodes appCallback if
35 * it exists.
36 */
37class OSGUTIL_EXPORT UpdateVisitor : public osg::NodeVisitor
38{
39    public:
40
41        UpdateVisitor();
42        virtual ~UpdateVisitor();
43
44        META_NodeVisitor("osgUtil","UpdateVisitor")
45
46        virtual void reset();
47
48        /** During traversal each type of node calls its callbacks and its children traversed. */
49        virtual void apply(osg::Node& node)         { handle_callbacks_and_traverse(node); }
50
51        virtual void apply(osg::Geode& node)        { handle_geode_callbacks(node); }
52        virtual void apply(osg::Billboard& node)    { handle_geode_callbacks(node); }
53
54        virtual void apply(osg::LightSource& node)  { handle_callbacks_and_traverse(node); }
55
56        virtual void apply(osg::Group& node)        { handle_callbacks_and_traverse(node); }
57        virtual void apply(osg::Transform& node)    { handle_callbacks_and_traverse(node); }
58        virtual void apply(osg::Projection& node)   { handle_callbacks_and_traverse(node); }
59        virtual void apply(osg::Switch& node)       { handle_callbacks_and_traverse(node); }
60        virtual void apply(osg::LOD& node)          { handle_callbacks_and_traverse(node); }
61        virtual void apply(osg::OccluderNode& node) { handle_callbacks_and_traverse(node); }
62
63
64    protected:
65
66//         /** Prevent unwanted copy construction.*/
67//         UpdateVisitor(const UpdateVisitor&):osg::NodeVisitor() {}
68
69        /** Prevent unwanted copy operator.*/
70        UpdateVisitor& operator = (const UpdateVisitor&) { return *this; }
71
72        inline void handle_callbacks(osg::StateSet* stateset)
73        {
74            if (stateset && stateset->requiresUpdateTraversal())
75            {
76                stateset->runUpdateCallbacks(this);
77            }
78        }
79
80        inline void handle_callbacks_and_traverse(osg::Node& node)
81        {
82            handle_callbacks(node.getStateSet());
83
84            osg::NodeCallback* callback = node.getUpdateCallback();
85            if (callback) (*callback)(&node,this);
86            else if (node.getNumChildrenRequiringUpdateTraversal()>0) traverse(node);
87        }
88
89        inline void handle_geode_callbacks(osg::Geode& geode)
90        {
91            handle_callbacks(geode.getStateSet());
92
93            osg::NodeCallback* callback = geode.getUpdateCallback();
94            if (callback) (*callback)(&geode,this);
95
96            // Call the app callbacks on the drawables.
97            for(unsigned int i=0;i<geode.getNumDrawables();++i)
98            {
99                osg::Drawable::UpdateCallback* callback = geode.getDrawable(i)->getUpdateCallback();
100                if (callback) callback->update(this,geode.getDrawable(i));
101
102                handle_callbacks(geode.getDrawable(i)->getStateSet());
103            }
104
105            // should we traverse just in case a subclass of Geode adds children??  Won't for now as
106            // Geode's arn't designed to have children.
107            // traverse(geode);
108        }
109};
110
111}
112
113#endif
114
Note: See TracBrowser for help on using the browser.