From 658d96aa6433b97d144c7f7e632c320313217125 Mon Sep 17 00:00:00 2001 From: Cedric Pinson Date: Mon, 22 Jun 2009 14:24:59 +0000 Subject: [PATCH] From Cedric Pinson, fix constructors for cloning osgAnimation objects --- include/osgAnimation/Animation | 2 +- include/osgAnimation/AnimationManagerBase | 1 - include/osgAnimation/Channel | 12 +++++++++++- include/osgAnimation/Skeleton | 2 +- src/osgAnimation/Animation.cpp | 17 +++++++++++------ src/osgAnimation/AnimationManagerBase.cpp | 15 +++++++++++---- src/osgAnimation/Bone.cpp | 2 +- src/osgAnimation/Channel.cpp | 6 ++++++ src/osgAnimation/Timeline.cpp | 5 +++-- src/osgAnimation/UpdateCallback.cpp | 9 +++++---- 10 files changed, 50 insertions(+), 21 deletions(-) diff --git a/include/osgAnimation/Animation b/include/osgAnimation/Animation index 9e5476da9..01e25a233 100644 --- a/include/osgAnimation/Animation +++ b/include/osgAnimation/Animation @@ -31,7 +31,7 @@ namespace osgAnimation META_Object(osgAnimation, Animation) Animation() : _duration(0), _weight(0), _startTime(0), _playmode(LOOP) {} - Animation(const osgAnimation::Animation& anim, const osg::CopyOp&); + Animation(const osgAnimation::Animation&, const osg::CopyOp&); enum PlayMode { diff --git a/include/osgAnimation/AnimationManagerBase b/include/osgAnimation/AnimationManagerBase index e5b900204..55cd7e48a 100644 --- a/include/osgAnimation/AnimationManagerBase +++ b/include/osgAnimation/AnimationManagerBase @@ -46,7 +46,6 @@ namespace osgAnimation void clearTargets(); void normalizeTargets(); - protected: AnimationList _animations; diff --git a/include/osgAnimation/Channel b/include/osgAnimation/Channel index c2ebf79d4..60062d59f 100644 --- a/include/osgAnimation/Channel +++ b/include/osgAnimation/Channel @@ -29,7 +29,9 @@ namespace osgAnimation public: Channel(); + Channel(const Channel& channel); virtual ~Channel(); + virtual Channel* clone() const = 0; virtual void update(float time) = 0; virtual void reset() = 0; @@ -66,8 +68,16 @@ namespace osgAnimation typedef typename SamplerType::UsingType UsingType; typedef TemplateTarget TargetType; typedef TemplateKeyframeContainer KeyframeContainerType; + Channel* clone() const { return new TemplateChannel(*this); } - TemplateChannel (SamplerType* s = 0,TargetType* target = 0) + TemplateChannel (const TemplateChannel& channel) : + Channel(channel), + _target(new TargetType), + _sampler(channel._sampler.get()) + { + } + + TemplateChannel (SamplerType* s = 0,TargetType* target = 0) { if (target) _target = target; diff --git a/include/osgAnimation/Skeleton b/include/osgAnimation/Skeleton index 5a1b0de77..0bf732fe5 100644 --- a/include/osgAnimation/Skeleton +++ b/include/osgAnimation/Skeleton @@ -31,7 +31,7 @@ namespace osgAnimation { META_Object(osgAnimation, UpdateSkeleton); UpdateSkeleton() {} - UpdateSkeleton(const UpdateSkeleton& us, const osg::CopyOp& copyop= osg::CopyOp::SHALLOW_COPY) : osg::NodeCallback(us, copyop) {} + UpdateSkeleton(const UpdateSkeleton& us, const osg::CopyOp& copyop= osg::CopyOp::SHALLOW_COPY) : osg::Object(us, copyop), osg::NodeCallback(us, copyop) {} virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); }; diff --git a/src/osgAnimation/Animation.cpp b/src/osgAnimation/Animation.cpp index f513492eb..bd360cf67 100644 --- a/src/osgAnimation/Animation.cpp +++ b/src/osgAnimation/Animation.cpp @@ -16,13 +16,18 @@ using namespace osgAnimation; -Animation::Animation(const osgAnimation::Animation& anim, const osg::CopyOp& c) +Animation::Animation(const osgAnimation::Animation& anim, const osg::CopyOp& copyop): + _duration(anim._duration), + _originalDuration(anim._originalDuration), + _weight(anim._weight), + _startTime(anim._startTime), + _playmode(anim._playmode) { - _duration = anim._duration; - _originalDuration = anim._originalDuration; - _weight = anim._weight; - _startTime = anim._startTime; - _playmode = anim._playmode; + const ChannelList& cl = anim.getChannels(); + for (ChannelList::const_iterator it = cl.begin(); it != cl.end(); it++) + { + addChannel(it->get()->clone()); + } } diff --git a/src/osgAnimation/AnimationManagerBase.cpp b/src/osgAnimation/AnimationManagerBase.cpp index f5dedf168..a289e0816 100644 --- a/src/osgAnimation/AnimationManagerBase.cpp +++ b/src/osgAnimation/AnimationManagerBase.cpp @@ -57,11 +57,18 @@ void AnimationManagerBase::operator()(osg::Node* node, osg::NodeVisitor* nv) } -AnimationManagerBase::AnimationManagerBase(const AnimationManagerBase& b, const osg::CopyOp& copyop) : osg::NodeCallback(b,copyop) +AnimationManagerBase::AnimationManagerBase(const AnimationManagerBase& b, const osg::CopyOp& copyop) : osg::NodeCallback(b,copyop) { - _animations = b._animations; - _targets = b._targets; - _needToLink = b._needToLink; + const AnimationList& animationList = b.getAnimationList(); + for (AnimationList::const_iterator it = animationList.begin(); + it != animationList.end(); + it++) + { + Animation* animation = dynamic_cast(it->get()->clone(copyop)); + _animations.push_back(animation); + } + _needToLink = true; + buildTargetReference(); } void AnimationManagerBase::buildTargetReference() diff --git a/src/osgAnimation/Bone.cpp b/src/osgAnimation/Bone.cpp index 245c250bb..2b1c5a188 100644 --- a/src/osgAnimation/Bone.cpp +++ b/src/osgAnimation/Bone.cpp @@ -17,6 +17,7 @@ #include osgAnimation::Bone::UpdateBone::UpdateBone(const osgAnimation::Bone::UpdateBone& apc,const osg::CopyOp& copyop) : + osg::Object(apc, copyop), osgAnimation::AnimationUpdateCallback(apc, copyop) { _quaternion = new osgAnimation::QuatTarget(apc._quaternion->getValue()); @@ -40,7 +41,6 @@ osgAnimation::Bone::Bone(const Bone& b, const osg::CopyOp& copyop) : while (updatecallback.valid()) { osg::NodeCallback* ucb = dynamic_cast(updatecallback->clone(copyop)); ucb->setNestedCallback(0); - ucb->setName(updatecallback->getName()); addUpdateCallback(ucb); updatecallback = updatecallback->getNestedCallback(); } diff --git a/src/osgAnimation/Channel.cpp b/src/osgAnimation/Channel.cpp index 559d83573..cdfb80577 100644 --- a/src/osgAnimation/Channel.cpp +++ b/src/osgAnimation/Channel.cpp @@ -17,6 +17,12 @@ using namespace osgAnimation; Channel::Channel() { _weight=1; } Channel::~Channel() {} +Channel::Channel(const Channel& channel) : osg::Referenced(channel), + _targetName(channel._targetName), + _name(channel._name), + _weight(channel._weight) +{ +} const std::string& Channel::getName() const { return _name; } void Channel::setName (const std::string& name) { _name = name; } diff --git a/src/osgAnimation/Timeline.cpp b/src/osgAnimation/Timeline.cpp index 2248adeb7..6027b176d 100644 --- a/src/osgAnimation/Timeline.cpp +++ b/src/osgAnimation/Timeline.cpp @@ -35,8 +35,9 @@ osgAnimation::Timeline::Timeline() setName("Timeline"); } -osgAnimation::Timeline::Timeline(const Timeline& nc,const osg::CopyOp& op) : Action(nc, op), - _actions(nc._actions) +osgAnimation::Timeline::Timeline(const Timeline& nc,const osg::CopyOp& op) + : Action(nc, op), + _actions(nc._actions) { _lastUpdate = 0; _currentFrame = 0; diff --git a/src/osgAnimation/UpdateCallback.cpp b/src/osgAnimation/UpdateCallback.cpp index a4fc0b65c..a9c3ef460 100644 --- a/src/osgAnimation/UpdateCallback.cpp +++ b/src/osgAnimation/UpdateCallback.cpp @@ -66,11 +66,12 @@ void AnimationUpdateCallback::updateLink() UpdateTransform::UpdateTransform(const UpdateTransform& apc,const osg::CopyOp& copyop) - : AnimationUpdateCallback(apc, copyop), - _euler(apc._euler), - _position(apc._position), - _scale(apc._scale) + : osg::Object(apc, copyop), + AnimationUpdateCallback(apc, copyop) { + _euler = new osgAnimation::Vec3Target(apc._euler->getValue()); + _position = new osgAnimation::Vec3Target(apc._euler->getValue()); + _scale = new osgAnimation::Vec3Target(apc._euler->getValue()); } UpdateTransform::UpdateTransform(const std::string& name) : AnimationUpdateCallback(name)