root/OpenSceneGraph/trunk/src/osgAnimation/AnimationManagerBase.cpp @ 10656

Revision 10656, 4.0 kB (checked in by cedricpinson, 5 years ago)

From Cedric Pinson, this commit contains the following change:
* Change ref_ptr to observer_ptr to avoid cross reference and leak in Skinning
* Set invalidate to true to re run the check visitor in Skeleton
* Shallow copy Sampler in channel copy constructor
* Add accessor in VertexInfluence?
* Remove dead code in Timeline.cpp
* Dont force linking in Bone::UpdateBone?, the decision is done by the user or the manager
* Add offset in timeline stats to display each manager on the screen
* Add a flag in animation manager base to enable or not automatic link when modifying the manager

RevLine 
[9150]1/*  -*-c++-*-
[10557]2 *  Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
[9150]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/AnimationManagerBase>
16#include <osgAnimation/LinkVisitor>
[10557]17#include <algorithm>
[9150]18
19using namespace osgAnimation;
20
21AnimationManagerBase::~AnimationManagerBase() {}
22
23AnimationManagerBase::AnimationManagerBase()
24{
[10498]25    _needToLink = false;
[10656]26    _automaticLink = true;
[9150]27}
28
[9370]29void AnimationManagerBase::clearTargets()
30{
31    for (TargetSet::iterator it = _targets.begin(); it != _targets.end(); it++)
32        (*it).get()->reset();
33}
34
[10656]35void AnimationManagerBase::dirty()
36{
37    _needToLink = true;
38}
39
40void AnimationManagerBase::setAutomaticLink(bool state) { _automaticLink = state; }
41bool AnimationManagerBase::isAutomaticLink() const { return _automaticLink; }
42
[9370]43void AnimationManagerBase::operator()(osg::Node* node, osg::NodeVisitor* nv)
44{
[9877]45    if (nv && nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
[9370]46    {
47        if (needToLink())
48        {
49            /** manager need to link, it means that an animation has been added
50                so we need to relink all item animated with all animations.
51                We apply the linker visitor on the manager node to affect
52                all its children.
53                But it should not be done here, it should be done in the
54                update of AnimationManager
55            */
56            link(node);
57        }
58        const osg::FrameStamp* fs = nv->getFrameStamp();
59        update(fs->getSimulationTime());
60    }
61    traverse(node,nv);
62}
63
64
[10386]65AnimationManagerBase::AnimationManagerBase(const AnimationManagerBase& b, const osg::CopyOp& copyop) : osg::NodeCallback(b,copyop)
[9370]66{
[10386]67    const AnimationList& animationList = b.getAnimationList();
68    for (AnimationList::const_iterator it = animationList.begin();
69         it != animationList.end();
70         it++)
71    {
72        Animation* animation = dynamic_cast<osgAnimation::Animation*>(it->get()->clone(copyop));
73        _animations.push_back(animation);
74    }
75    _needToLink = true;
[10656]76    _automaticLink = b._automaticLink;
[10386]77    buildTargetReference();
[9370]78}
79
[9150]80void AnimationManagerBase::buildTargetReference()
81{
82    _targets.clear();
[10656]83    for( AnimationList::iterator iterAnim = _animations.begin(); iterAnim != _animations.end(); ++iterAnim )
[9150]84    {
85        Animation* anim = (*iterAnim).get();
86        for (ChannelList::iterator it = anim->getChannels().begin();
87             it != anim->getChannels().end();
88             it++)
89            _targets.insert((*it)->getTarget());
90    }
91}
92
93
94void AnimationManagerBase::registerAnimation (Animation* animation)
95{
96    _needToLink = true;
97    _animations.push_back(animation);
98    buildTargetReference();
99}
100
[10557]101void AnimationManagerBase::unregisterAnimation (Animation* animation)
102{
103    AnimationList::iterator it = std::find(_animations.begin(), _animations.end(), animation);
104    if (it != _animations.end())
105    {
106        _animations.erase(it);
107    }
108    buildTargetReference();
109}
110
[10656]111bool AnimationManagerBase::needToLink() const { return _needToLink && isAutomaticLink(); }
[9150]112
113
[10498]114void AnimationManagerBase::setLinkVisitor(LinkVisitor* visitor)
115{
116    _linker = visitor;
117}
[9150]118
[10498]119LinkVisitor* AnimationManagerBase::getOrCreateLinkVisitor()
120{
121    if (!_linker.valid())
122        _linker = new LinkVisitor;
123    return _linker.get();
124}
125
[9370]126void AnimationManagerBase::link(osg::Node* subgraph)
[9150]127{
[10498]128    LinkVisitor* linker = getOrCreateLinkVisitor();
129    linker->getAnimationList().clear();
130    linker->getAnimationList() = _animations;
131
132    subgraph->accept(*linker);
[9150]133    _needToLink = false;
134    buildTargetReference();
135}
Note: See TracBrowser for help on using the browser.