root/OpenSceneGraph/trunk/src/osgAnimation/LinkVisitor.cpp @ 13041

Revision 13041, 2.6 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1/*  -*-c++-*-
2 *  Copyright (C) 2009 Cedric Pinson <cedric.pinson@plopbyte.net>
3 *
4 * This library is open source and may be redistributed and/or modified under
5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6 * (at your option) any later version.  The full license is in LICENSE file
7 * included with this distribution, and on the openscenegraph.org website.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * OpenSceneGraph Public License for more details.
13*/
14
15#include <osgAnimation/LinkVisitor>
16#include <osgAnimation/AnimationUpdateCallback>
17#include <osg/Notify>
18#include <osg/Geode>
19
20using namespace osgAnimation;
21
22LinkVisitor::LinkVisitor() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
23{
24    _nbLinkedTarget = 0;
25}
26
27void LinkVisitor::reset()
28{
29    _nbLinkedTarget = 0;
30}
31
32AnimationList& LinkVisitor::getAnimationList()
33{
34    return _animations;
35}
36void LinkVisitor::link(AnimationUpdateCallbackBase* cb)
37{
38    int result = 0;
39    for (int i = 0; i < (int)_animations.size(); i++)
40    {
41        result += cb->link(_animations[i].get());
42        _nbLinkedTarget += result;
43    }
44    OSG_NOTICE << "LinkVisitor links " << result << " for \"" << cb->getName() << '"' << std::endl;
45}
46
47void LinkVisitor::handle_stateset(osg::StateSet* stateset)
48{
49    if (!stateset)
50        return;
51    osg::StateSet::AttributeList& attr = stateset->getAttributeList();
52    for (osg::StateSet::AttributeList::iterator it = attr.begin(); it != attr.end(); ++it)
53    {
54        osg::StateAttribute* sattr = it->second.first.get();
55        osgAnimation::AnimationUpdateCallbackBase* cb = dynamic_cast<osgAnimation::AnimationUpdateCallbackBase*>(sattr->getUpdateCallback());
56        if (cb)
57            link(cb);
58    }
59}
60
61void LinkVisitor::apply(osg::Node& node)
62{
63    osg::StateSet* st = node.getStateSet();
64    if (st)
65        handle_stateset(st);
66
67    osg::NodeCallback* cb = node.getUpdateCallback();
68    while (cb)
69    {
70        osgAnimation::AnimationUpdateCallbackBase* cba = dynamic_cast<osgAnimation::AnimationUpdateCallbackBase*>(cb);
71        if (cba)
72            link(cba);
73        cb = cb->getNestedCallback();
74    }
75    traverse(node);
76}
77
78void LinkVisitor::apply(osg::Geode& node)
79{
80    for (unsigned int i = 0; i < node.getNumDrawables(); i++)
81    {
82        osg::Drawable* drawable = node.getDrawable(i);
83        if (drawable && drawable->getStateSet())
84            handle_stateset(drawable->getStateSet());
85    }
86    apply(static_cast<osg::Node&>(node));
87}
Note: See TracBrowser for help on using the browser.