diff --git a/include/osgAnimation/Action b/include/osgAnimation/Action index 7c5ce68a2..a39723855 100644 --- a/include/osgAnimation/Action +++ b/include/osgAnimation/Action @@ -166,7 +166,7 @@ namespace osgAnimation ActionAnimation() {} ActionAnimation(const ActionAnimation& a, const osg::CopyOp& c) : Action(a,c) { _animation = a._animation;} ActionAnimation(Animation* animation); - void updateAnimation(unsigned int frame); + void updateAnimation(unsigned int frame, int priority); Animation* getAnimation() { return _animation.get(); } protected: @@ -192,8 +192,6 @@ namespace osgAnimation unsigned int getLoop() const { return _animation->getLoop(); } void setLoop(unsigned int loop); - void computeWeightAndUpdateAnimation(unsigned int frame); - void traverse(ActionVisitor& visitor); protected: diff --git a/include/osgAnimation/ActionVisitor b/include/osgAnimation/ActionVisitor index 160c21af0..91a5dd242 100644 --- a/include/osgAnimation/ActionVisitor +++ b/include/osgAnimation/ActionVisitor @@ -38,10 +38,8 @@ namespace osgAnimation class OSGANIMATION_EXPORT ActionVisitor : public osg::Referenced { public: - std::vector _stackFrameAction; - std::vector _stackTimeline; - META_ActionVisitor(osgAnimation, ActionVisitor); + ActionVisitor(); void traverse(Action& visitor); void pushFrameActionOnStack(const FrameAction& fa); @@ -51,6 +49,10 @@ namespace osgAnimation void popTimeline(); Timeline* getCurrentTimeline(); + void setCurrentLayer(int layer) { _currentLayer = layer;} + int getCurrentLayer() const { return _currentLayer; } + + const std::vector& getStackedFrameAction() const { return _stackFrameAction; } virtual void apply(Action& action); virtual void apply(Timeline& tm); @@ -58,6 +60,11 @@ namespace osgAnimation virtual void apply(BlendOut& action); virtual void apply(ActionAnimation& action); virtual void apply(StripAnimation& action); + + protected: + std::vector _stackFrameAction; + std::vector _stackTimeline; + int _currentLayer; }; diff --git a/include/osgAnimation/Bone b/include/osgAnimation/Bone index 2b4255ebb..ae98d2385 100644 --- a/include/osgAnimation/Bone +++ b/include/osgAnimation/Bone @@ -56,25 +56,6 @@ namespace osgAnimation void setDefaultUpdateCallback(const std::string& name = ""); - struct BoneMapVisitor : public osg::NodeVisitor - { - BoneMap _map; - BoneMapVisitor(): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} - - META_NodeVisitor("osgAnimation","BoneMapVisitor") - - void apply(osg::Node&) { return; } - void apply(osg::Transform& node) - { - Bone* bone = dynamic_cast(&node); - if (bone) - { - _map[bone->getName()] = bone; - traverse(node); - } - } - }; - class OSGANIMATION_EXPORT UpdateBone : public AnimationUpdateCallback { protected: @@ -131,6 +112,8 @@ namespace osgAnimation const osg::Vec3& getTranslation() const { return _position;} const osg::Quat& getRotation() const { return _rotation;} + const osg::Vec3& getScale() const { return _scale;} + osg::Matrix getMatrixInBoneSpace() const { return (osg::Matrix(getRotation())) * osg::Matrix::translate(getTranslation()) * _bindInBoneSpace;} const osg::Matrix& getBindMatrixInBoneSpace() const { return _bindInBoneSpace; } const osg::Matrix& getMatrixInSkeletonSpace() const { return _boneInSkeletonSpace; } diff --git a/include/osgAnimation/LinkVisitor b/include/osgAnimation/LinkVisitor index 3f0789a33..de61a229f 100644 --- a/include/osgAnimation/LinkVisitor +++ b/include/osgAnimation/LinkVisitor @@ -37,6 +37,7 @@ namespace osgAnimation AnimationList& getAnimationList(); void reset(); + unsigned int getNbLinkedTarget() const { return _nbLinkedTarget; } protected: diff --git a/include/osgAnimation/Target b/include/osgAnimation/Target index 832277de7..e811a5606 100644 --- a/include/osgAnimation/Target +++ b/include/osgAnimation/Target @@ -34,7 +34,7 @@ namespace osgAnimation public: Target(); - virtual ~Target(); + virtual ~Target() {} virtual void normalize() = 0; void reset() { _weight = 0; _priorityWeight = 0; } int getCount() const { return referenceCount(); } diff --git a/src/osgAnimation/Action.cpp b/src/osgAnimation/Action.cpp index 56c50e86e..62e89c6ac 100644 --- a/src/osgAnimation/Action.cpp +++ b/src/osgAnimation/Action.cpp @@ -103,9 +103,9 @@ osgAnimation::ActionAnimation::ActionAnimation(Animation* animation) : _animatio Action::setDuration(animation->getDuration()); setName(animation->getName()); } -void osgAnimation::ActionAnimation::updateAnimation(unsigned int frame) +void osgAnimation::ActionAnimation::updateAnimation(unsigned int frame, int priority) { - _animation->update(frame * 1.0/_fps); + _animation->update(frame * 1.0/_fps, priority); } @@ -149,14 +149,14 @@ void osgAnimation::StripAnimation::traverse(ActionVisitor& visitor) { if (_blendIn.valid()) { - unsigned int f = visitor._stackFrameAction.back().first; + unsigned int f = visitor.getStackedFrameAction().back().first; visitor.pushFrameActionOnStack(FrameAction(f,_blendIn.get())); _blendIn->accept(visitor); visitor.popFrameAction(); } if (_blendOut.second.valid()) { - unsigned int f = visitor._stackFrameAction.back().first; + unsigned int f = visitor.getStackedFrameAction().back().first; visitor.pushFrameActionOnStack(FrameAction(f + _blendOut.first,_blendOut.second.get())); _blendOut.second.get()->accept(visitor); visitor.popFrameAction(); @@ -164,18 +164,9 @@ void osgAnimation::StripAnimation::traverse(ActionVisitor& visitor) if (_animation.valid()) { - unsigned int f = visitor._stackFrameAction.back().first; + unsigned int f = visitor.getStackedFrameAction().back().first; visitor.pushFrameActionOnStack(FrameAction(f,_animation.get())); _animation->accept(visitor); visitor.popFrameAction(); } } - -void osgAnimation::StripAnimation::computeWeightAndUpdateAnimation(unsigned int frame) -{ - if (frame < _blendIn->getNumFrames()) - _blendIn->computeWeight(frame); - if (frame >= _blendOut.first) - _blendOut.second->computeWeight(frame - _blendOut.first); - _animation->updateAnimation(frame); -} diff --git a/src/osgAnimation/ActionVisitor.cpp b/src/osgAnimation/ActionVisitor.cpp index 0eb43b776..dd6395785 100644 --- a/src/osgAnimation/ActionVisitor.cpp +++ b/src/osgAnimation/ActionVisitor.cpp @@ -16,6 +16,10 @@ #include #include +osgAnimation::ActionVisitor::ActionVisitor() +{ + _currentLayer = 0; +} void osgAnimation::ActionVisitor::pushFrameActionOnStack(const FrameAction& fa) { _stackFrameAction.push_back(fa); } void osgAnimation::ActionVisitor::popFrameAction() { _stackFrameAction.pop_back(); } void osgAnimation::ActionVisitor::pushTimelineOnStack(Timeline* tm) { _stackTimeline.push_back(tm); } @@ -124,7 +128,7 @@ void osgAnimation::UpdateActionVisitor::apply(ActionAnimation& action) { unsigned int frame = getLocalFrame(); apply(static_cast(action)); - action.updateAnimation(frame); + action.updateAnimation(frame, getCurrentLayer()); } } @@ -133,29 +137,7 @@ void osgAnimation::UpdateActionVisitor::apply(StripAnimation& action) if (isActive(action)) { apply(static_cast(action)); - -#if 0 - unsigned int frame = getLocalFrame(); - // evaluate callback in blendin/blendout/animation - { - BlendIn* subAction = action.getBlendIn(); - if (subAction) - apply(static_cast(*subAction)); - } - { - BlendOut* subAction = action.getBlendOut(); - if (subAction) - apply(static_cast(*subAction)); - } - { - ActionAnimation* subAction = action.getActionAnimation(); - if (subAction) - apply(static_cast(*subAction)); - } - action.computeWeightAndUpdateAnimation(frame); -#else action.traverse(*this); -#endif } } diff --git a/src/osgAnimation/Bone.cpp b/src/osgAnimation/Bone.cpp index ea664092c..ae01dd49b 100644 --- a/src/osgAnimation/Bone.cpp +++ b/src/osgAnimation/Bone.cpp @@ -1,5 +1,5 @@ /* -*-c++-*- - * Copyright (C) 2008 Cedric Pinson + * Copyright (C) 2008 Cedric Pinson * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or @@ -15,45 +15,9 @@ #include #include #include - - -struct FindNearestParentAnimationManager : public osg::NodeVisitor -{ - osg::ref_ptr _manager; - FindNearestParentAnimationManager() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_PARENTS) {} - void apply(osg::Node& node) - { - if (_manager.valid()) - return; - osg::NodeCallback* callback = node.getUpdateCallback(); - while (callback) - { - _manager = dynamic_cast(callback); - if (_manager.valid()) - return; - callback = callback->getNestedCallback(); - } - traverse(node); - } -}; - - -struct ComputeBindMatrixVisitor : public osg::NodeVisitor -{ - ComputeBindMatrixVisitor(): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} - void apply(osg::Node& node) { return; } - void apply(osg::Transform& node) - { - osgAnimation::Bone* bone = dynamic_cast(&node); - if (!bone) - return; - if (bone->needToComputeBindMatrix()) - bone->computeBindMatrix(); - - traverse(node); - } -}; - +#include +#include +#include osgAnimation::Bone::UpdateBone::UpdateBone(const osgAnimation::Bone::UpdateBone& apc,const osg::CopyOp& copyop) : @@ -107,7 +71,7 @@ void osgAnimation::Bone::UpdateBone::operator()(osg::Node* node, osg::NodeVisito if (!_manager.valid()) { - FindNearestParentAnimationManager finder; + FindParentAnimationManagerVisitor finder; if (b->getParents().size() > 1) { @@ -120,13 +84,13 @@ void osgAnimation::Bone::UpdateBone::operator()(osg::Node* node, osg::NodeVisito } b->getParents()[0]->accept(finder); - if (!finder._manager.valid()) + if (!finder.getAnimationManager()) { osg::notify(osg::WARN) << "Warning can't update Bone, path to parent AnimationManagerBase not found" << std::endl; return; } - _manager = finder._manager.get(); + _manager = finder.getAnimationManager(); } updateLink(); @@ -153,6 +117,7 @@ osgAnimation::Bone::Bone(const Bone& b, const osg::CopyOp& copyop) : _invBindInSkeletonSpace(b._invBindInSkeletonSpace), _boneInSkeletonSpace(b._boneInSkeletonSpace) { +#if 0 osg::ref_ptr updatecallback = getUpdateCallback(); setUpdateCallback(0); while (updatecallback.valid()) { @@ -161,6 +126,7 @@ osgAnimation::Bone::Bone(const Bone& b, const osg::CopyOp& copyop) : addUpdateCallback(ucb); updatecallback = updatecallback->getNestedCallback(); } +#endif } osgAnimation::Bone::Bone(const std::string& name) @@ -192,7 +158,7 @@ void osgAnimation::Bone::computeBindMatrix() _invBindInSkeletonSpace = parent->getInvBindMatrixInSkeletonSpace() * _invBindInSkeletonSpace; } -osgAnimation::Bone* osgAnimation::Bone::getBoneParent() +osgAnimation::Bone* osgAnimation::Bone::getBoneParent() { if (getParents().empty()) return 0; @@ -238,5 +204,5 @@ osgAnimation::Bone::BoneMap osgAnimation::Bone::getBoneMap() { BoneMapVisitor mapVisitor; this->accept(mapVisitor); - return mapVisitor._map; + return mapVisitor.getBoneMap(); } diff --git a/src/osgAnimation/CMakeLists.txt b/src/osgAnimation/CMakeLists.txt index 80caf9e79..04a17889c 100644 --- a/src/osgAnimation/CMakeLists.txt +++ b/src/osgAnimation/CMakeLists.txt @@ -18,10 +18,13 @@ SET(LIB_PUBLIC_HEADERS ${HEADER_PATH}/Assert ${HEADER_PATH}/BasicAnimationManager ${HEADER_PATH}/Bone + ${HEADER_PATH}/BoneMapVisitor ${HEADER_PATH}/Channel ${HEADER_PATH}/CubicBezier + ${HEADER_PATH}/ComputeBindMatrixVisitor ${HEADER_PATH}/EaseMotion ${HEADER_PATH}/Export + ${HEADER_PATH}/FindParentAnimationManagerVisitor ${HEADER_PATH}/FrameAction ${HEADER_PATH}/Interpolator ${HEADER_PATH}/Keyframe @@ -53,7 +56,9 @@ ADD_LIBRARY(${LIB_NAME} AnimationManager.cpp BasicAnimationManager.cpp Bone.cpp + BoneMapVisitor.cpp Channel.cpp + FindParentAnimationManagerVisitor.cpp LinkVisitor.cpp MorphGeometry.cpp RigGeometry.cpp diff --git a/src/osgAnimation/Target.cpp b/src/osgAnimation/Target.cpp index 8afb99ff0..b05775611 100644 --- a/src/osgAnimation/Target.cpp +++ b/src/osgAnimation/Target.cpp @@ -19,4 +19,3 @@ using namespace osgAnimation; Target::Target() : _weight(0), _priorityWeight(0), _lastPriority(0) {} -Target::~Target() {} diff --git a/src/osgAnimation/Timeline.cpp b/src/osgAnimation/Timeline.cpp index 43367086e..8713a9b73 100644 --- a/src/osgAnimation/Timeline.cpp +++ b/src/osgAnimation/Timeline.cpp @@ -1,5 +1,5 @@ /* -*-c++-*- - * Copyright (C) 2008 Cedric Pinson + * Copyright (C) 2008 Cedric Pinson * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or @@ -55,10 +55,12 @@ osgAnimation::Timeline::Timeline(const Timeline& nc,const osg::CopyOp& op) void osgAnimation::Timeline::traverse(ActionVisitor& visitor) { + int layer = visitor.getCurrentLayer(); visitor.pushTimelineOnStack(this); // update from high priority to low priority for( ActionLayers::reverse_iterator iterAnim = _actions.rbegin(); iterAnim != _actions.rend(); ++iterAnim ) { + visitor.setCurrentLayer(iterAnim->first); ActionList& list = iterAnim->second; for (unsigned int i = 0; i < list.size(); i++) { @@ -68,6 +70,7 @@ void osgAnimation::Timeline::traverse(ActionVisitor& visitor) } } visitor.popTimeline(); + visitor.setCurrentLayer(layer); } diff --git a/src/osgAnimation/UpdateCallback.cpp b/src/osgAnimation/UpdateCallback.cpp index 411c6814c..94098a6cc 100644 --- a/src/osgAnimation/UpdateCallback.cpp +++ b/src/osgAnimation/UpdateCallback.cpp @@ -130,7 +130,7 @@ UpdateMaterial::UpdateMaterial(const UpdateMaterial& apc,const osg::CopyOp& copy UpdateMaterial::UpdateMaterial(const std::string& name): AnimationUpdateCallback(name) { - _diffuse = new osgAnimation::Vec4Target(osg::Vec4(1,1,1,1)); + _diffuse = new osgAnimation::Vec4Target(osg::Vec4(1,0,1,1)); } /** Callback method called by the NodeVisitor when visiting a node.*/