| [9150] | 1 | |
|---|
| [10557] | 2 | |
|---|
| [9150] | 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #include <osgAnimation/AnimationManagerBase> |
|---|
| 16 | #include <osgAnimation/LinkVisitor> |
|---|
| [10557] | 17 | #include <algorithm> |
|---|
| [9150] | 18 | |
|---|
| 19 | using namespace osgAnimation; |
|---|
| 20 | |
|---|
| 21 | AnimationManagerBase::~AnimationManagerBase() {} |
|---|
| 22 | |
|---|
| 23 | AnimationManagerBase::AnimationManagerBase() |
|---|
| 24 | { |
|---|
| [10498] | 25 | _needToLink = false; |
|---|
| [10656] | 26 | _automaticLink = true; |
|---|
| [9150] | 27 | } |
|---|
| 28 | |
|---|
| [9370] | 29 | void AnimationManagerBase::clearTargets() |
|---|
| 30 | { |
|---|
| 31 | for (TargetSet::iterator it = _targets.begin(); it != _targets.end(); it++) |
|---|
| 32 | (*it).get()->reset(); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| [10656] | 35 | void AnimationManagerBase::dirty() |
|---|
| 36 | { |
|---|
| 37 | _needToLink = true; |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | void AnimationManagerBase::setAutomaticLink(bool state) { _automaticLink = state; } |
|---|
| 41 | bool AnimationManagerBase::isAutomaticLink() const { return _automaticLink; } |
|---|
| 42 | |
|---|
| [9370] | 43 | void 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 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 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] | 65 | AnimationManagerBase::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] | 80 | void 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 | |
|---|
| 94 | void AnimationManagerBase::registerAnimation (Animation* animation) |
|---|
| 95 | { |
|---|
| 96 | _needToLink = true; |
|---|
| 97 | _animations.push_back(animation); |
|---|
| 98 | buildTargetReference(); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| [10557] | 101 | void 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] | 111 | bool AnimationManagerBase::needToLink() const { return _needToLink && isAutomaticLink(); } |
|---|
| [9150] | 112 | |
|---|
| 113 | |
|---|
| [10498] | 114 | void AnimationManagerBase::setLinkVisitor(LinkVisitor* visitor) |
|---|
| 115 | { |
|---|
| 116 | _linker = visitor; |
|---|
| 117 | } |
|---|
| [9150] | 118 | |
|---|
| [10498] | 119 | LinkVisitor* AnimationManagerBase::getOrCreateLinkVisitor() |
|---|
| 120 | { |
|---|
| 121 | if (!_linker.valid()) |
|---|
| 122 | _linker = new LinkVisitor; |
|---|
| 123 | return _linker.get(); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| [9370] | 126 | void 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 | } |
|---|