Changeset 10561
- Timestamp:
- 08/31/09 11:40:56 (4 years ago)
- Location:
- OpenSceneGraph/trunk
- Files:
-
- 12 modified
-
include/osgAnimation/Action (modified) (2 diffs)
-
include/osgAnimation/ActionVisitor (modified) (3 diffs)
-
include/osgAnimation/Bone (modified) (2 diffs)
-
include/osgAnimation/LinkVisitor (modified) (1 diff)
-
include/osgAnimation/Target (modified) (1 diff)
-
src/osgAnimation/Action.cpp (modified) (5 diffs)
-
src/osgAnimation/ActionVisitor.cpp (modified) (3 diffs)
-
src/osgAnimation/Bone.cpp (modified) (9 diffs)
-
src/osgAnimation/CMakeLists.txt (modified) (2 diffs)
-
src/osgAnimation/Target.cpp (modified) (1 diff)
-
src/osgAnimation/Timeline.cpp (modified) (3 diffs)
-
src/osgAnimation/UpdateCallback.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgAnimation/Action
r10432 r10561 167 167 ActionAnimation(const ActionAnimation& a, const osg::CopyOp& c) : Action(a,c) { _animation = a._animation;} 168 168 ActionAnimation(Animation* animation); 169 void updateAnimation(unsigned int frame );169 void updateAnimation(unsigned int frame, int priority); 170 170 Animation* getAnimation() { return _animation.get(); } 171 171 … … 193 193 unsigned int getLoop() const { return _animation->getLoop(); } 194 194 void setLoop(unsigned int loop); 195 void computeWeightAndUpdateAnimation(unsigned int frame);196 197 195 void traverse(ActionVisitor& visitor); 198 196 -
OpenSceneGraph/trunk/include/osgAnimation/ActionVisitor
r10432 r10561 39 39 { 40 40 public: 41 std::vector<FrameAction> _stackFrameAction;42 std::vector<Timeline*> _stackTimeline;43 44 41 META_ActionVisitor(osgAnimation, ActionVisitor); 42 ActionVisitor(); 45 43 void traverse(Action& visitor); 46 44 … … 52 50 53 51 Timeline* getCurrentTimeline(); 52 void setCurrentLayer(int layer) { _currentLayer = layer;} 53 int getCurrentLayer() const { return _currentLayer; } 54 55 const std::vector<FrameAction>& getStackedFrameAction() const { return _stackFrameAction; } 54 56 55 57 virtual void apply(Action& action); … … 59 61 virtual void apply(ActionAnimation& action); 60 62 virtual void apply(StripAnimation& action); 63 64 protected: 65 std::vector<FrameAction> _stackFrameAction; 66 std::vector<Timeline*> _stackTimeline; 67 int _currentLayer; 61 68 }; 62 69 -
OpenSceneGraph/trunk/include/osgAnimation/Bone
r10558 r10561 57 57 void setDefaultUpdateCallback(const std::string& name = ""); 58 58 59 struct BoneMapVisitor : public osg::NodeVisitor60 {61 BoneMap _map;62 BoneMapVisitor(): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}63 64 META_NodeVisitor("osgAnimation","BoneMapVisitor")65 66 void apply(osg::Node&) { return; }67 void apply(osg::Transform& node)68 {69 Bone* bone = dynamic_cast<Bone*>(&node);70 if (bone)71 {72 _map[bone->getName()] = bone;73 traverse(node);74 }75 }76 };77 78 59 class OSGANIMATION_EXPORT UpdateBone : public AnimationUpdateCallback <osg::NodeCallback> 79 60 { … … 132 113 const osg::Vec3& getTranslation() const { return _position;} 133 114 const osg::Quat& getRotation() const { return _rotation;} 115 const osg::Vec3& getScale() const { return _scale;} 116 134 117 osg::Matrix getMatrixInBoneSpace() const { return (osg::Matrix(getRotation())) * osg::Matrix::translate(getTranslation()) * _bindInBoneSpace;} 135 118 const osg::Matrix& getBindMatrixInBoneSpace() const { return _bindInBoneSpace; } -
OpenSceneGraph/trunk/include/osgAnimation/LinkVisitor
r10518 r10561 38 38 AnimationList& getAnimationList(); 39 39 void reset(); 40 unsigned int getNbLinkedTarget() const { return _nbLinkedTarget; } 40 41 41 42 protected: -
OpenSceneGraph/trunk/include/osgAnimation/Target
r10556 r10561 35 35 36 36 Target(); 37 virtual ~Target() ;37 virtual ~Target() {} 38 38 virtual void normalize() = 0; 39 39 void reset() { _weight = 0; _priorityWeight = 0; } -
OpenSceneGraph/trunk/src/osgAnimation/Action.cpp
r10435 r10561 104 104 setName(animation->getName()); 105 105 } 106 void osgAnimation::ActionAnimation::updateAnimation(unsigned int frame )106 void osgAnimation::ActionAnimation::updateAnimation(unsigned int frame, int priority) 107 107 { 108 _animation->update(frame * 1.0/_fps );108 _animation->update(frame * 1.0/_fps, priority); 109 109 } 110 110 … … 150 150 if (_blendIn.valid()) 151 151 { 152 unsigned int f = visitor. _stackFrameAction.back().first;152 unsigned int f = visitor.getStackedFrameAction().back().first; 153 153 visitor.pushFrameActionOnStack(FrameAction(f,_blendIn.get())); 154 154 _blendIn->accept(visitor); … … 157 157 if (_blendOut.second.valid()) 158 158 { 159 unsigned int f = visitor. _stackFrameAction.back().first;159 unsigned int f = visitor.getStackedFrameAction().back().first; 160 160 visitor.pushFrameActionOnStack(FrameAction(f + _blendOut.first,_blendOut.second.get())); 161 161 _blendOut.second.get()->accept(visitor); … … 165 165 if (_animation.valid()) 166 166 { 167 unsigned int f = visitor. _stackFrameAction.back().first;167 unsigned int f = visitor.getStackedFrameAction().back().first; 168 168 visitor.pushFrameActionOnStack(FrameAction(f,_animation.get())); 169 169 _animation->accept(visitor); … … 171 171 } 172 172 } 173 174 void osgAnimation::StripAnimation::computeWeightAndUpdateAnimation(unsigned int frame)175 {176 if (frame < _blendIn->getNumFrames())177 _blendIn->computeWeight(frame);178 if (frame >= _blendOut.first)179 _blendOut.second->computeWeight(frame - _blendOut.first);180 _animation->updateAnimation(frame);181 } -
OpenSceneGraph/trunk/src/osgAnimation/ActionVisitor.cpp
r10432 r10561 17 17 #include <osgAnimation/Timeline> 18 18 19 osgAnimation::ActionVisitor::ActionVisitor() 20 { 21 _currentLayer = 0; 22 } 19 23 void osgAnimation::ActionVisitor::pushFrameActionOnStack(const FrameAction& fa) { _stackFrameAction.push_back(fa); } 20 24 void osgAnimation::ActionVisitor::popFrameAction() { _stackFrameAction.pop_back(); } … … 125 129 unsigned int frame = getLocalFrame(); 126 130 apply(static_cast<Action&>(action)); 127 action.updateAnimation(frame );131 action.updateAnimation(frame, getCurrentLayer()); 128 132 } 129 133 } … … 134 138 { 135 139 apply(static_cast<Action&>(action)); 136 137 #if 0138 unsigned int frame = getLocalFrame();139 // evaluate callback in blendin/blendout/animation140 {141 BlendIn* subAction = action.getBlendIn();142 if (subAction)143 apply(static_cast<Action&>(*subAction));144 }145 {146 BlendOut* subAction = action.getBlendOut();147 if (subAction)148 apply(static_cast<Action&>(*subAction));149 }150 {151 ActionAnimation* subAction = action.getActionAnimation();152 if (subAction)153 apply(static_cast<Action&>(*subAction));154 }155 action.computeWeightAndUpdateAnimation(frame);156 #else157 140 action.traverse(*this); 158 #endif159 141 } 160 142 } -
OpenSceneGraph/trunk/src/osgAnimation/Bone.cpp
r10558 r10561 1 1 /* -*-c++-*- 2 * Copyright (C) 2008 Cedric Pinson < mornifle@plopbyte.net>2 * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> 3 3 * 4 4 * This library is open source and may be redistributed and/or modified under … … 16 16 #include <osgAnimation/Bone> 17 17 #include <osgAnimation/Skeleton> 18 19 20 struct FindNearestParentAnimationManager : public osg::NodeVisitor 21 { 22 osg::ref_ptr<osgAnimation::AnimationManagerBase> _manager; 23 FindNearestParentAnimationManager() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_PARENTS) {} 24 void apply(osg::Node& node) 25 { 26 if (_manager.valid()) 27 return; 28 osg::NodeCallback* callback = node.getUpdateCallback(); 29 while (callback) 30 { 31 _manager = dynamic_cast<osgAnimation::AnimationManagerBase*>(callback); 32 if (_manager.valid()) 33 return; 34 callback = callback->getNestedCallback(); 35 } 36 traverse(node); 37 } 38 }; 39 40 41 struct ComputeBindMatrixVisitor : public osg::NodeVisitor 42 { 43 ComputeBindMatrixVisitor(): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} 44 void apply(osg::Node& node) { return; } 45 void apply(osg::Transform& node) 46 { 47 osgAnimation::Bone* bone = dynamic_cast<osgAnimation::Bone*>(&node); 48 if (!bone) 49 return; 50 if (bone->needToComputeBindMatrix()) 51 bone->computeBindMatrix(); 52 53 traverse(node); 54 } 55 }; 56 18 #include <osgAnimation/FindParentAnimationManagerVisitor> 19 #include <osgAnimation/BoneMapVisitor> 20 #include <osgAnimation/ComputeBindMatrixVisitor> 57 21 58 22 … … 108 72 if (!_manager.valid()) 109 73 { 110 Find NearestParentAnimationManager finder;74 FindParentAnimationManagerVisitor finder; 111 75 112 76 if (b->getParents().size() > 1) … … 121 85 b->getParents()[0]->accept(finder); 122 86 123 if (!finder. _manager.valid())87 if (!finder.getAnimationManager()) 124 88 { 125 89 osg::notify(osg::WARN) << "Warning can't update Bone, path to parent AnimationManagerBase not found" << std::endl; … … 127 91 } 128 92 129 _manager = finder. _manager.get();93 _manager = finder.getAnimationManager(); 130 94 } 131 95 … … 154 118 _boneInSkeletonSpace(b._boneInSkeletonSpace) 155 119 { 120 #if 0 156 121 osg::ref_ptr<osg::NodeCallback> updatecallback = getUpdateCallback(); 157 122 setUpdateCallback(0); … … 162 127 updatecallback = updatecallback->getNestedCallback(); 163 128 } 129 #endif 164 130 } 165 131 … … 193 159 } 194 160 195 osgAnimation::Bone* osgAnimation::Bone::getBoneParent() 161 osgAnimation::Bone* osgAnimation::Bone::getBoneParent() 196 162 { 197 163 if (getParents().empty()) … … 239 205 BoneMapVisitor mapVisitor; 240 206 this->accept(mapVisitor); 241 return mapVisitor. _map;242 } 207 return mapVisitor.getBoneMap(); 208 } -
OpenSceneGraph/trunk/src/osgAnimation/CMakeLists.txt
r10498 r10561 19 19 ${HEADER_PATH}/BasicAnimationManager 20 20 ${HEADER_PATH}/Bone 21 ${HEADER_PATH}/BoneMapVisitor 21 22 ${HEADER_PATH}/Channel 22 23 ${HEADER_PATH}/CubicBezier 24 ${HEADER_PATH}/ComputeBindMatrixVisitor 23 25 ${HEADER_PATH}/EaseMotion 24 26 ${HEADER_PATH}/Export 27 ${HEADER_PATH}/FindParentAnimationManagerVisitor 25 28 ${HEADER_PATH}/FrameAction 26 29 ${HEADER_PATH}/Interpolator … … 54 57 BasicAnimationManager.cpp 55 58 Bone.cpp 59 BoneMapVisitor.cpp 56 60 Channel.cpp 61 FindParentAnimationManagerVisitor.cpp 57 62 LinkVisitor.cpp 58 63 MorphGeometry.cpp -
OpenSceneGraph/trunk/src/osgAnimation/Target.cpp
r10556 r10561 20 20 21 21 Target::Target() : _weight(0), _priorityWeight(0), _lastPriority(0) {} 22 Target::~Target() {} -
OpenSceneGraph/trunk/src/osgAnimation/Timeline.cpp
r10394 r10561 1 1 /* -*-c++-*- 2 * Copyright (C) 2008 Cedric Pinson < mornifle@plopbyte.net>2 * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> 3 3 * 4 4 * This library is open source and may be redistributed and/or modified under … … 56 56 void osgAnimation::Timeline::traverse(ActionVisitor& visitor) 57 57 { 58 int layer = visitor.getCurrentLayer(); 58 59 visitor.pushTimelineOnStack(this); 59 60 // update from high priority to low priority 60 61 for( ActionLayers::reverse_iterator iterAnim = _actions.rbegin(); iterAnim != _actions.rend(); ++iterAnim ) 61 62 { 63 visitor.setCurrentLayer(iterAnim->first); 62 64 ActionList& list = iterAnim->second; 63 65 for (unsigned int i = 0; i < list.size(); i++) … … 69 71 } 70 72 visitor.popTimeline(); 73 visitor.setCurrentLayer(layer); 71 74 } 72 75 -
OpenSceneGraph/trunk/src/osgAnimation/UpdateCallback.cpp
r10527 r10561 131 131 AnimationUpdateCallback<osg::StateAttribute::Callback>(name) 132 132 { 133 _diffuse = new osgAnimation::Vec4Target(osg::Vec4(1, 1,1,1));133 _diffuse = new osgAnimation::Vec4Target(osg::Vec4(1,0,1,1)); 134 134 } 135 135
