Changeset 10693
- Timestamp:
- 10/27/09 16:37:13 (4 years ago)
- Location:
- OpenSceneGraph/trunk
- Files:
-
- 13 added
- 13 modified
-
include/osgAnimation/Action (modified) (3 diffs)
-
include/osgAnimation/ActionAnimation (added)
-
include/osgAnimation/ActionBlendIn (added)
-
include/osgAnimation/ActionBlendOut (added)
-
include/osgAnimation/ActionStripAnimation (added)
-
include/osgAnimation/ActionVisitor (modified) (4 diffs)
-
include/osgAnimation/RigGeometry (modified) (6 diffs)
-
include/osgAnimation/RigTransform (added)
-
include/osgAnimation/RigTransformHardware (added)
-
include/osgAnimation/RigTransformSoftware (added)
-
include/osgAnimation/StatsVisitor (modified) (1 diff)
-
include/osgAnimation/Timeline (modified) (1 diff)
-
include/osgAnimation/VertexInfluence (modified) (4 diffs)
-
src/osgAnimation/Action.cpp (modified) (4 diffs)
-
src/osgAnimation/ActionAnimation.cpp (added)
-
src/osgAnimation/ActionBlendIn.cpp (added)
-
src/osgAnimation/ActionBlendOut.cpp (added)
-
src/osgAnimation/ActionStripAnimation.cpp (added)
-
src/osgAnimation/ActionVisitor.cpp (modified) (9 diffs)
-
src/osgAnimation/Bone.cpp (modified) (1 diff)
-
src/osgAnimation/CMakeLists.txt (modified) (4 diffs)
-
src/osgAnimation/RigGeometry.cpp (modified) (4 diffs)
-
src/osgAnimation/RigTransformHardware.cpp (added)
-
src/osgAnimation/RigTransformSoftware.cpp (added)
-
src/osgAnimation/StatsVisitor.cpp (modified) (7 diffs)
-
src/osgAnimation/VertexInfluence.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgAnimation/Action
r10561 r10693 58 58 } 59 59 60 void removeCallback(Callback* cb) 61 { 62 if (!cb) 63 return; 64 65 if (_nestedCallback.get() == cb) 66 _nestedCallback = _nestedCallback->getNestedCallback(); 67 else 68 _nestedCallback->removeCallback(cb); 69 } 70 60 71 protected: 61 72 osg::ref_ptr<Callback> _nestedCallback; … … 88 99 return _framesCallback[frame].get(); 89 100 } 90 101 102 void removeCallback(Callback*); 103 91 104 Callback* getFrameCallback(unsigned int frame); 92 105 Callback* getFrameCallback(double time); … … 128 141 129 142 130 // blend in from 0 to weight in duration131 class OSGANIMATION_EXPORT BlendIn : public Action132 {133 double _weight;134 osg::ref_ptr<Animation> _animation;135 136 public:137 META_Action(osgAnimation, BlendIn);138 BlendIn() : _weight(0) {}139 BlendIn(const BlendIn& a, const osg::CopyOp& c) : Action(a,c) { _weight = a._weight; _animation = a._animation;}140 BlendIn(Animation* animation, double duration, double weight);141 double getWeight() const { return _weight;}142 Animation* getAnimation() { return _animation.get(); }143 void computeWeight(unsigned int frame);144 };145 146 // blend in from 0 to weight in duration147 class OSGANIMATION_EXPORT BlendOut : public Action148 {149 double _weight;150 osg::ref_ptr<Animation> _animation;151 public:152 META_Action(osgAnimation, BlendOut);153 BlendOut() : _weight(0) {}154 BlendOut(const BlendOut& a, const osg::CopyOp& c) : Action(a,c) { _weight = a._weight; _animation = a._animation;}155 BlendOut(Animation* animation, double duration);156 Animation* getAnimation() { return _animation.get(); }157 double getWeight() const { return _weight;}158 void computeWeight(unsigned int frame);159 };160 161 162 class OSGANIMATION_EXPORT ActionAnimation : public Action163 {164 public:165 META_Action(osgAnimation, ActionAnimation);166 ActionAnimation() {}167 ActionAnimation(const ActionAnimation& a, const osg::CopyOp& c) : Action(a,c) { _animation = a._animation;}168 ActionAnimation(Animation* animation);169 void updateAnimation(unsigned int frame, int priority);170 Animation* getAnimation() { return _animation.get(); }171 172 protected:173 osg::ref_ptr<Animation> _animation;174 };175 176 177 // encapsulate animation with blend in blend out for classic usage178 class OSGANIMATION_EXPORT StripAnimation : public Action179 {180 public:181 META_Action(osgAnimation, StripAnimation);182 StripAnimation() {}183 StripAnimation(const StripAnimation& a, const osg::CopyOp& c);184 StripAnimation(Animation* animation, double blendInDuration = 0.0, double blendOutDuration = 0.0, double blendInWeightTarget = 1.0 );185 ActionAnimation* getActionAnimation() { return _animation.get(); }186 BlendIn* getBlendIn() { return _blendIn.get(); }187 BlendOut* getBlendOut() { return _blendOut.second.get(); }188 const ActionAnimation* getActionAnimation() const { return _animation.get(); }189 const BlendIn* getBlendIn() const { return _blendIn.get(); }190 const BlendOut* getBlendOut() const { return _blendOut.second.get(); }191 unsigned int getBlendOutStartFrame() const { return _blendOut.first; }192 193 unsigned int getLoop() const { return _animation->getLoop(); }194 void setLoop(unsigned int loop);195 void traverse(ActionVisitor& visitor);196 197 protected:198 typedef std::pair<unsigned int, osg::ref_ptr<BlendOut> > FrameBlendOut;199 osg::ref_ptr<BlendIn> _blendIn;200 FrameBlendOut _blendOut;201 osg::ref_ptr<ActionAnimation> _animation;202 };203 204 205 206 143 } 207 144 -
OpenSceneGraph/trunk/include/osgAnimation/ActionVisitor
r10561 r10693 26 26 class Timeline; 27 27 class Action; 28 class BlendIn;29 class BlendOut;28 class ActionBlendIn; 29 class ActionBlendOut; 30 30 class ActionAnimation; 31 class StripAnimation;31 class ActionStripAnimation; 32 32 33 33 #define META_ActionVisitor(library,name) \ … … 57 57 virtual void apply(Action& action); 58 58 virtual void apply(Timeline& tm); 59 virtual void apply( BlendIn& action);60 virtual void apply( BlendOut& action);59 virtual void apply(ActionBlendIn& action); 60 virtual void apply(ActionBlendOut& action); 61 61 virtual void apply(ActionAnimation& action); 62 virtual void apply( StripAnimation& action);62 virtual void apply(ActionStripAnimation& action); 63 63 64 64 protected: … … 73 73 protected: 74 74 unsigned int _frame; 75 75 unsigned int _currentAnimationPriority; 76 76 public: 77 77 META_ActionVisitor(osgAnimation, UpdateActionVisitor); … … 84 84 void apply(Timeline& action); 85 85 void apply(Action& action); 86 void apply( BlendIn& action);87 void apply( BlendOut& action);86 void apply(ActionBlendIn& action); 87 void apply(ActionBlendOut& action); 88 88 void apply(ActionAnimation& action); 89 void apply( StripAnimation& action);89 void apply(ActionStripAnimation& action); 90 90 91 91 }; -
OpenSceneGraph/trunk/include/osgAnimation/RigGeometry
r10344 r10693 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 … … 17 17 18 18 #include <osgAnimation/Export> 19 #include <osgAnimation/Skinning>20 19 #include <osgAnimation/Skeleton> 20 #include <osgAnimation/RigTransform> 21 21 #include <osg/Geometry> 22 22 … … 34 34 META_Object(osgAnimation, RigGeometry); 35 35 36 void setInfluenceMap( osgAnimation::VertexInfluenceMap* vertexInfluenceMap) { _vertexInfluenceMap = vertexInfluenceMap; }37 const osgAnimation::VertexInfluenceMap* getInfluenceMap() const { return _vertexInfluenceMap.get();}38 osgAnimation::VertexInfluenceMap* getInfluenceMap() { return _vertexInfluenceMap.get();}36 void setInfluenceMap(VertexInfluenceMap* vertexInfluenceMap) { _vertexInfluenceMap = vertexInfluenceMap; } 37 const VertexInfluenceMap* getInfluenceMap() const { return _vertexInfluenceMap.get();} 38 VertexInfluenceMap* getInfluenceMap() { return _vertexInfluenceMap.get();} 39 39 40 40 const Skeleton* getSkeleton() const; 41 41 Skeleton* getSkeleton(); 42 // will be used by the update callback to init correctly the rig mesh 43 void setSkeleton(Skeleton*); 42 44 43 45 void setNeedToComputeMatrix(bool state) { _needToComputeMatrix = state;} 44 46 bool getNeedToComputeMatrix() const { return _needToComputeMatrix;} 45 47 46 void buildVertexSet(); 47 void buildTransformer(Skeleton* root); 48 49 // this build the internal database about vertex influence and bones 50 void buildVertexInfluenceSet(); 51 const VertexInfluenceSet& getVertexInfluenceSet() const; 52 48 53 void computeMatrixFromRootSkeleton(); 49 54 50 virtual void transformSoftwareMethod();51 const osgAnimation::VertexInfluenceSet& getVertexInfluenceSet() const { return _vertexInfluenceSet;}52 55 53 const std::vector<osg::Vec3>& getPositionSource() const { return _positionSource;} 54 const std::vector<osg::Vec3>& getNormalSource() const { return _normalSource;} 56 // set implementation of rig method 57 void setRigTransformImplementation(RigTransform*); 58 RigTransform* getRigTransformImplementation(); 59 60 virtual void drawImplementation(osg::RenderInfo& renderInfo) const; 61 void update(); 62 63 const osg::Matrix& getMatrixFromSkeletonToGeometry() const; 64 const osg::Matrix& getInvMatrixFromSkeletonToGeometry() const; 55 65 56 66 protected: 57 67 58 std::vector<osg::Vec3> _positionSource; 59 std::vector<osg::Vec3> _normalSource; 68 osg::ref_ptr<RigTransform> _rigTransformImplementation; 60 69 61 osgAnimation::VertexInfluenceSet _vertexInfluenceSet; 62 osg::ref_ptr<osgAnimation::VertexInfluenceMap> _vertexInfluenceMap; 63 osgAnimation::TransformVertexFunctor _transformVertexes; 70 VertexInfluenceSet _vertexInfluenceSet; 71 osg::ref_ptr<VertexInfluenceMap> _vertexInfluenceMap; 64 72 65 73 osg::Matrix _matrixFromSkeletonToGeometry; … … 67 75 osg::observer_ptr<Skeleton> _root; 68 76 bool _needToComputeMatrix; 69 70 77 71 78 struct FindNearestParentSkeleton : public osg::NodeVisitor 72 79 { 73 osg::ref_ptr< osgAnimation::Skeleton> _root;80 osg::ref_ptr<Skeleton> _root; 74 81 FindNearestParentSkeleton() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_PARENTS) {} 75 82 void apply(osg::Transform& node) … … 99 106 if (!finder._root.valid()) 100 107 return; 101 geom->buildVertex Set();102 geom-> buildTransformer(finder._root.get());108 geom->buildVertexInfluenceSet(); 109 geom->setSkeleton(finder._root.get()); 103 110 } 104 111 … … 108 115 if (geom->getNeedToComputeMatrix()) 109 116 geom->computeMatrixFromRootSkeleton(); 110 geom->transformSoftwareMethod(); 117 118 geom->update(); 111 119 } 112 120 }; 113 114 /** BuildVertexTransformerVisitor is used to setup RigGeometry drawable115 * throw a subgraph.116 */117 struct BuildVertexTransformerVisitor : public osg::NodeVisitor118 {119 osg::ref_ptr<Skeleton> _root;120 BuildVertexTransformerVisitor(Skeleton* root): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { _root = root;}121 122 META_NodeVisitor("osgAnimation","BuildVertexTransformerVisitor")123 124 void apply(osg::Geode& node)125 {126 int num = node.getNumDrawables();127 for (int i = 0; i < num; i++) {128 RigGeometry* geom = dynamic_cast<RigGeometry*>(node.getDrawable(i));129 if (geom)130 {131 geom->buildVertexSet();132 geom->buildTransformer(_root.get());133 }134 }135 }136 };137 138 121 }; 139 122 -
OpenSceneGraph/trunk/include/osgAnimation/StatsVisitor
r10351 r10693 42 42 void apply(Timeline& action); 43 43 void apply(Action& action); 44 void apply( BlendIn& action);45 void apply( BlendOut& action);44 void apply(ActionBlendIn& action); 45 void apply(ActionBlendOut& action); 46 46 void apply(ActionAnimation& action); 47 void apply( StripAnimation& action);47 void apply(ActionStripAnimation& action); 48 48 49 49 }; -
OpenSceneGraph/trunk/include/osgAnimation/Timeline
r10357 r10693 63 63 virtual void addActionAt(double t, Action* action, int priority = 0); 64 64 void addActionNow(Action* action, int priority = 0); 65 65 66 66 void clearActions(); 67 67 -
OpenSceneGraph/trunk/include/osgAnimation/VertexInfluence
r10656 r10693 13 13 */ 14 14 15 #ifndef OSGANIMATION_VERTEX_INFLUENCE S_H16 #define OSGANIMATION_VERTEX_INFLUENCE S_H15 #ifndef OSGANIMATION_VERTEX_INFLUENCE_H 16 #define OSGANIMATION_VERTEX_INFLUENCE_H 1 17 17 18 18 #include <osg/Object> … … 38 38 std::string _name; 39 39 }; 40 41 // typedef std::map<std::string, VertexInfluence> VertexInfluenceMap;42 40 43 41 class VertexInfluenceMap : public std::map<std::string, VertexInfluence> , public osg::Object … … 74 72 typedef std::map<int,BoneWeightList> VertexIndexToBoneWeightMap; 75 73 76 class UniqVertexSetToBoneSet 74 class UniqVertexSetToBoneSet 77 75 { 78 76 public: … … 89 87 90 88 const UniqVertexSetToBoneSetList& getUniqVertexSetToBoneSetList() const { return _uniqVertexSetToBoneSet;} 91 void addVertexInfluence(const VertexInfluence& v) { _bone2Vertexes.push_back(v); }89 void addVertexInfluence(const VertexInfluence& v); 92 90 void buildVertex2BoneList(); 93 91 void buildUniqVertexSetToBoneSetList(); 94 void clear() 95 { 96 _bone2Vertexes.clear(); 97 _uniqVertexSetToBoneSet.clear(); 98 } 92 void clear(); 99 93 100 94 const VertexIndexToBoneWeightMap& getVertexToBoneList() const; -
OpenSceneGraph/trunk/src/osgAnimation/Action.cpp
r10561 r10693 15 15 #include <osgAnimation/Action> 16 16 17 osgAnimation::Action::Action() 17 using namespace osgAnimation; 18 19 Action::Action() 18 20 { 19 21 _numberFrame = 25; … … 22 24 _loop = 1; 23 25 } 24 osgAnimation::Action::Action(const Action&,const osg::CopyOp&) {}25 osgAnimation::Action::Callback* osgAnimation::Action::getFrameCallback(unsigned int frame)26 Action::Action(const Action&,const osg::CopyOp&) {} 27 Action::Callback* Action::getFrameCallback(unsigned int frame) 26 28 { 27 29 if (_framesCallback.find(frame) != _framesCallback.end()) … … 32 34 } 33 35 34 osgAnimation::Action::Callback* osgAnimation::Action::getFrameCallback(double time) 36 void Action::removeCallback(Callback* cb) 37 { 38 std::vector<unsigned int> keyToRemove; 39 for (FrameCallback::iterator it = _framesCallback.begin(); it != _framesCallback.end(); it++) 40 { 41 if (it->second.get()) 42 { 43 if (it->second.get() == cb) 44 { 45 it->second = it->second->getNestedCallback(); 46 if (!it->second.valid()) 47 keyToRemove.push_back(it->first); 48 } 49 else 50 { 51 it->second->removeCallback(cb); 52 } 53 } 54 } 55 for (std::vector<unsigned int>::iterator it = keyToRemove.begin(); it != keyToRemove.end(); it++) 56 _framesCallback.erase(*it); 57 } 58 59 Action::Callback* Action::getFrameCallback(double time) 35 60 { 36 61 unsigned int frame = static_cast<unsigned int>(floor(time * _fps)); … … 57 82 return true; 58 83 } 59 60 61 osgAnimation::BlendIn::BlendIn(Animation* animation, double duration, double weight)62 {63 _animation = animation;64 _weight = weight;65 float d = duration * _fps;66 setNumFrames(static_cast<unsigned int>(floor(d)) + 1);67 setName("BlendIn");68 }69 70 void osgAnimation::BlendIn::computeWeight(unsigned int frame)71 {72 73 // frame + 1 because the start is 0 and we want to start the blend in at the first74 // frame.75 double ratio = ( (frame+1) * 1.0 / (getNumFrames()) );76 double w = _weight * ratio;77 78 osg::notify(osg::DEBUG_INFO) << getName() << " BlendIn frame " << frame << " weight " << w << std::endl;79 _animation->setWeight(w);80 }81 82 83 osgAnimation::BlendOut::BlendOut(Animation* animation, double duration)84 {85 _animation = animation;86 float d = duration * _fps;87 setNumFrames(static_cast<unsigned int>(floor(d) + 1));88 _weight = 1.0;89 setName("BlendOut");90 }91 92 void osgAnimation::BlendOut::computeWeight(unsigned int frame)93 {94 double ratio = ( (frame+1) * 1.0 / (getNumFrames()) );95 double w = _weight * (1.0-ratio);96 osg::notify(osg::DEBUG_INFO) << getName() << " BlendOut frame " << frame << " weight " << w << std::endl;97 _animation->setWeight(w);98 }99 100 101 osgAnimation::ActionAnimation::ActionAnimation(Animation* animation) : _animation(animation)102 {103 Action::setDuration(animation->getDuration());104 setName(animation->getName());105 }106 void osgAnimation::ActionAnimation::updateAnimation(unsigned int frame, int priority)107 {108 _animation->update(frame * 1.0/_fps, priority);109 }110 111 112 113 114 115 osgAnimation::StripAnimation::StripAnimation(const StripAnimation& a, const osg::CopyOp& c) : Action(a,c)116 {117 _animation = a._animation;118 _blendIn = a._blendIn;119 _blendOut = a._blendOut;120 }121 122 osgAnimation::StripAnimation::StripAnimation(Animation* animation, double blendInDuration, double blendOutDuration, double blendInWeightTarget)123 {124 _blendIn = new BlendIn(animation, blendInDuration, blendInWeightTarget);125 _animation = new ActionAnimation(animation);126 unsigned int start = static_cast<unsigned int>(floor((_animation->getDuration() - blendOutDuration) * _fps));127 _blendOut = FrameBlendOut(start, new BlendOut(animation, blendOutDuration));128 setName(animation->getName() + "_Strip");129 _blendIn->setName(_animation->getName() + "_" + _blendIn->getName());130 _blendOut.second->setName(_animation->getName() + "_" + _blendOut.second->getName());131 setDuration(animation->getDuration());132 }133 134 135 void osgAnimation::StripAnimation::setLoop(unsigned int loop)136 {137 _animation->setLoop(loop);138 if (!loop)139 setDuration(-1);140 else141 setDuration(loop * _animation->getDuration());142 143 // duration changed re evaluate the blendout duration144 unsigned int start = static_cast<unsigned int>(floor((getDuration() - _blendOut.second->getDuration()) * _fps));145 _blendOut = FrameBlendOut(start, _blendOut.second);146 }147 148 void osgAnimation::StripAnimation::traverse(ActionVisitor& visitor)149 {150 if (_blendIn.valid())151 {152 unsigned int f = visitor.getStackedFrameAction().back().first;153 visitor.pushFrameActionOnStack(FrameAction(f,_blendIn.get()));154 _blendIn->accept(visitor);155 visitor.popFrameAction();156 }157 if (_blendOut.second.valid())158 {159 unsigned int f = visitor.getStackedFrameAction().back().first;160 visitor.pushFrameActionOnStack(FrameAction(f + _blendOut.first,_blendOut.second.get()));161 _blendOut.second.get()->accept(visitor);162 visitor.popFrameAction();163 }164 165 if (_animation.valid())166 {167 unsigned int f = visitor.getStackedFrameAction().back().first;168 visitor.pushFrameActionOnStack(FrameAction(f,_animation.get()));169 _animation->accept(visitor);170 visitor.popFrameAction();171 }172 } -
OpenSceneGraph/trunk/src/osgAnimation/ActionVisitor.cpp
r10561 r10693 14 14 15 15 #include <osgAnimation/Action> 16 #include <osgAnimation/ActionBlendIn> 17 #include <osgAnimation/ActionBlendOut> 18 #include <osgAnimation/ActionStripAnimation> 19 #include <osgAnimation/ActionAnimation> 16 20 #include <osgAnimation/ActionVisitor> 17 21 #include <osgAnimation/Timeline> 18 22 19 osgAnimation::ActionVisitor::ActionVisitor() 23 using namespace osgAnimation; 24 25 ActionVisitor::ActionVisitor() 20 26 { 21 27 _currentLayer = 0; 22 28 } 23 void osgAnimation::ActionVisitor::pushFrameActionOnStack(const FrameAction& fa) { _stackFrameAction.push_back(fa); }24 void osgAnimation::ActionVisitor::popFrameAction() { _stackFrameAction.pop_back(); }25 void osgAnimation::ActionVisitor::pushTimelineOnStack(Timeline* tm) { _stackTimeline.push_back(tm); }26 void osgAnimation::ActionVisitor::popTimeline() { _stackTimeline.pop_back(); }27 void osgAnimation::ActionVisitor::apply(Action& action) { traverse(action); }28 void osgAnimation::ActionVisitor::apply(Timeline& tm) { tm.traverse(*this); }29 void osgAnimation::ActionVisitor::apply(BlendIn& action) { apply(static_cast<Action&>(action));}30 void osgAnimation::ActionVisitor::apply(BlendOut& action) { apply(static_cast<Action&>(action)); }31 void osgAnimation::ActionVisitor::apply(ActionAnimation& action) { apply(static_cast<Action&>(action)); }32 void osgAnimation::ActionVisitor::apply(StripAnimation& action) { apply(static_cast<Action&>(action)); }33 void osgAnimation::ActionVisitor::traverse(Action& action)29 void ActionVisitor::pushFrameActionOnStack(const FrameAction& fa) { _stackFrameAction.push_back(fa); } 30 void ActionVisitor::popFrameAction() { _stackFrameAction.pop_back(); } 31 void ActionVisitor::pushTimelineOnStack(Timeline* tm) { _stackTimeline.push_back(tm); } 32 void ActionVisitor::popTimeline() { _stackTimeline.pop_back(); } 33 void ActionVisitor::apply(Action& action) { traverse(action); } 34 void ActionVisitor::apply(Timeline& tm) { tm.traverse(*this); } 35 void ActionVisitor::apply(ActionBlendIn& action) { apply(static_cast<Action&>(action));} 36 void ActionVisitor::apply(ActionBlendOut& action) { apply(static_cast<Action&>(action)); } 37 void ActionVisitor::apply(ActionAnimation& action) { apply(static_cast<Action&>(action)); } 38 void ActionVisitor::apply(ActionStripAnimation& action) { apply(static_cast<Action&>(action)); } 39 void ActionVisitor::traverse(Action& action) 34 40 { 35 41 action.traverse(*this); 36 42 } 37 43 38 osgAnimation::Timeline* osgAnimation::ActionVisitor::getCurrentTimeline()44 Timeline* ActionVisitor::getCurrentTimeline() 39 45 { 40 46 if (_stackTimeline.empty()) … … 43 49 } 44 50 45 osgAnimation::UpdateActionVisitor::UpdateActionVisitor() { _frame = 0; } 51 UpdateActionVisitor::UpdateActionVisitor() 52 { 53 _frame = 0; 54 _currentAnimationPriority = 0; 55 } 46 56 47 57 48 void osgAnimation::UpdateActionVisitor::apply(Timeline& tm)58 void UpdateActionVisitor::apply(Timeline& tm) 49 59 { 60 _currentAnimationPriority = 0; 61 50 62 tm.setEvaluating(true); 51 63 … … 57 69 } 58 70 59 bool osgAnimation::UpdateActionVisitor::isActive(Action& action) const71 bool UpdateActionVisitor::isActive(Action& action) const 60 72 { 61 73 FrameAction fa = _stackFrameAction.back(); … … 71 83 } 72 84 73 unsigned int osgAnimation::UpdateActionVisitor::getLocalFrame() const85 unsigned int UpdateActionVisitor::getLocalFrame() const 74 86 { 75 87 return _frame - _stackFrameAction.back().first; 76 88 } 77 89 78 void osgAnimation::UpdateActionVisitor::apply(Action& action)90 void UpdateActionVisitor::apply(Action& action) 79 91 { 80 92 if (isActive(action)) … … 103 115 } 104 116 105 void osgAnimation::UpdateActionVisitor::apply(BlendIn& action)117 void UpdateActionVisitor::apply(ActionBlendIn& action) 106 118 { 107 119 if (isActive(action)) … … 113 125 } 114 126 115 void osgAnimation::UpdateActionVisitor::apply(BlendOut& action)127 void UpdateActionVisitor::apply(ActionBlendOut& action) 116 128 { 117 129 if (isActive(action)) … … 123 135 } 124 136 125 void osgAnimation::UpdateActionVisitor::apply(ActionAnimation& action)137 void UpdateActionVisitor::apply(ActionAnimation& action) 126 138 { 127 if (isActive(action)) 139 if (isActive(action)) 128 140 { 129 141 unsigned int frame = getLocalFrame(); 130 142 apply(static_cast<Action&>(action)); 131 action.updateAnimation(frame, getCurrentLayer()); 143 // action.updateAnimation(frame, getCurrentLayer()); 144 action.updateAnimation(frame, -_currentAnimationPriority++); 132 145 } 133 146 } 134 147 135 void osgAnimation::UpdateActionVisitor::apply(StripAnimation& action)148 void UpdateActionVisitor::apply(ActionStripAnimation& action) 136 149 { 137 150 if (isActive(action)) … … 144 157 145 158 146 osgAnimation::ClearActionVisitor::ClearActionVisitor(ClearType type) : _clearType(type)159 ClearActionVisitor::ClearActionVisitor(ClearType type) : _clearType(type) 147 160 { 148 161 } 149 162 150 void osgAnimation::ClearActionVisitor::apply(Timeline& tm)163 void ClearActionVisitor::apply(Timeline& tm) 151 164 { 152 165 _remove.clear(); … … 155 168 tm.removeAction(_remove[i].get()); 156 169 } 157 void osgAnimation::ClearActionVisitor::apply(Action& action)170 void ClearActionVisitor::apply(Action& action) 158 171 { 159 172 FrameAction fa = _stackFrameAction.back(); -
OpenSceneGraph/trunk/src/osgAnimation/Bone.cpp
r10656 r10693 13 13 */ 14 14 15 #include <osgAnimation/Skinning>16 15 #include <osgAnimation/Bone> 17 16 #include <osgAnimation/Skeleton> -
OpenSceneGraph/trunk/src/osgAnimation/CMakeLists.txt
r10576 r10693 12 12 SET(LIB_PUBLIC_HEADERS 13 13 ${HEADER_PATH}/Action 14 ${HEADER_PATH}/ActionAnimation 15 ${HEADER_PATH}/ActionBlendIn 16 ${HEADER_PATH}/ActionBlendOut 14 17 ${HEADER_PATH}/ActionCallback 18 ${HEADER_PATH}/ActionStripAnimation 15 19 ${HEADER_PATH}/ActionVisitor 16 20 ${HEADER_PATH}/Animation … … 32 36 ${HEADER_PATH}/MorphGeometry 33 37 ${HEADER_PATH}/RigGeometry 38 ${HEADER_PATH}/RigTransform 39 ${HEADER_PATH}/RigTransformHardware 40 ${HEADER_PATH}/RigTransformSoftware 34 41 ${HEADER_PATH}/Sampler 35 42 ${HEADER_PATH}/Skeleton 36 ${HEADER_PATH}/Skinning37 43 ${HEADER_PATH}/StatsVisitor 38 44 ${HEADER_PATH}/StatsHandler … … 50 56 ${LIB_PUBLIC_HEADERS} 51 57 Action.cpp 58 ActionAnimation.cpp 59 ActionBlendIn.cpp 60 ActionBlendOut.cpp 52 61 ActionCallback.cpp 62 ActionStripAnimation.cpp 53 63 ActionVisitor.cpp 54 64 Animation.cpp … … 62 72 MorphGeometry.cpp 63 73 RigGeometry.cpp 74 RigTransformHardware.cpp 75 RigTransformSoftware.cpp 64 76 Skeleton.cpp 65 77 StatsVisitor.cpp -
OpenSceneGraph/trunk/src/osgAnimation/RigGeometry.cpp
r9531 r10693 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 * This program is free software; you can redistribute it and/or modify5 * it under the terms of the GNU General Public License as published by6 * the Free Software Foundation; either version 2 of the License, or7 * (at your option) any later version.8 * 9 * This programis distributed in the hope that it will be useful,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 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * 18 * Authors: 19 * 20 * Cedric Pinson <mornifle@plopbyte.net> 21 * 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * OpenSceneGraph Public License for more details. 22 13 */ 14 23 15 #include <osgAnimation/RigGeometry> 16 #include <osgAnimation/RigTransformSoftware> 17 #include <sstream> 18 #include <osg/GL2Extensions> 24 19 25 20 using namespace osgAnimation; … … 27 22 RigGeometry::RigGeometry() 28 23 { 29 setUseDisplayList(false); 24 _supportsDisplayList = false; 25 setUseVertexBufferObjects(true); 30 26 setUpdateCallback(new UpdateVertex); 31 27 setDataVariance(osg::Object::DYNAMIC); 32 28 _needToComputeMatrix = true; 33 29 _matrixFromSkeletonToGeometry = _invMatrixFromSkeletonToGeometry = osg::Matrix::identity(); 30 31 // disable the computation of boundingbox for the rig mesh 32 setComputeBoundingBoxCallback(new ComputeBoundingBoxCallback); 34 33 } 35 34 36 35 RigGeometry::RigGeometry(const osg::Geometry& b) : osg::Geometry(b, osg::CopyOp::SHALLOW_COPY) 37 36 { 38 setUseDisplayList(false); 37 _supportsDisplayList = false; 38 setUseVertexBufferObjects(true); 39 39 setUpdateCallback(new UpdateVertex); 40 40 setDataVariance(osg::Object::DYNAMIC); 41 41 _needToComputeMatrix = true; 42 42 _matrixFromSkeletonToGeometry = _invMatrixFromSkeletonToGeometry = osg::Matrix::identity(); 43 44 // disable the computation of boundingbox for the rig mesh 45 setComputeBoundingBoxCallback(new ComputeBoundingBoxCallback); 43 46 } 44 47 45 RigGeometry::RigGeometry(const RigGeometry& b, const osg::CopyOp& copyop) : 48 RigGeometry::RigGeometry(const RigGeometry& b, const osg::CopyOp& copyop) : 46 49 osg::Geometry(b,copyop), 47 _positionSource(b._positionSource),48 _normalSource(b._normalSource),49 50 _vertexInfluenceSet(b._vertexInfluenceSet), 50 51 _vertexInfluenceMap(b._vertexInfluenceMap), 51 _transformVertexes(b._transformVertexes), 52 _needToComputeMatrix(b._needToComputeMatrix) 52 _needToComputeMatrix(b._needToComputeMatrix) 53 53 { 54 // we dont copy the RigImplementation yet. because the RigImplementation need to be initialized in a valid graph, with a skeleton ... 55 // dont know yet what to do with a clone of a RigGeometry 54 56 } 55 57 56 void RigGeometry::buildTransformer(Skeleton* root) 58 59 const osg::Matrix& RigGeometry::getMatrixFromSkeletonToGeometry() const { return _matrixFromSkeletonToGeometry; } 60 const osg::Matrix& RigGeometry::getInvMatrixFromSkeletonToGeometry() const { return _invMatrixFromSkeletonToGeometry;} 61 62 63 void RigGeometry::drawImplementation(osg::RenderInfo& renderInfo) const 57 64 { 58 Bone::BoneMap bm = root->getBoneMap(); 59 _transformVertexes.init(bm, _vertexInfluenceSet.getUniqVertexSetToBoneSetList()); 60 _root = root; 65 osg::Geometry::drawImplementation(renderInfo); 61 66 } 62 67 63 void RigGeometry::buildVertex Set()68 void RigGeometry::buildVertexInfluenceSet() 64 69 { 65 if (!_vertexInfluenceMap.valid()) 70 if (!_vertexInfluenceMap.valid()) 66 71 { 67 osg::notify(osg::WARN) << "buildVertex Set can't be called without VertexInfluence already set to the RigGeometry ( " << getName() << " ) " << std::endl;72 osg::notify(osg::WARN) << "buildVertexInfluenceSet can't be called without VertexInfluence already set to the RigGeometry ( " << getName() << " ) " << std::endl; 68 73 return; 69 74 } … … 76 81 _vertexInfluenceSet.buildVertex2BoneList(); 77 82 _vertexInfluenceSet.buildUniqVertexSetToBoneSetList(); 78 std::cout<< "uniq groups " << _vertexInfluenceSet.getUniqVertexSetToBoneSetList().size() << " for " << getName() << std::endl;83 osg::notify(osg::NOTICE) << "uniq groups " << _vertexInfluenceSet.getUniqVertexSetToBoneSetList().size() << " for " << getName() << std::endl; 79 84 } 80 85 81 void RigGeometry::computeMatrixFromRootSkeleton() 86 void RigGeometry::computeMatrixFromRootSkeleton() 82 87 { 83 if (!_root.valid()) 88 if (!_root.valid()) 84 89 { 85 90 osg::notify(osg::WARN) << "Warning " << className() <<"::computeMatrixFromRootSkeleton if you have this message it means you miss to call buildTransformer(Skeleton* root), or your RigGeometry (" << getName() <<") is not attached to a Skeleton subgraph" << std::endl; … … 92 97 } 93 98 94 void RigGeometry:: transformSoftwareMethod()99 void RigGeometry::update() 95 100 { 96 setUseDisplayList(false); 97 setUseVertexBufferObjects(true); 98 99 // std::cout << getName() << " _matrixFromSkeletonToGeometry" << _matrixFromSkeletonToGeometry << std::endl; 100 osg::Vec3Array* pos = dynamic_cast<osg::Vec3Array*>(getVertexArray()); 101 if (pos && _positionSource.size() != pos->size()) 101 if (!getRigTransformImplementation()) 102 102 { 103 _positionSource = std::vector<osg::Vec3>(pos->begin(),pos->end()); 104 getVertexArray()->setDataVariance(osg::Object::DYNAMIC); 105 } 106 osg::Vec3Array* normal = dynamic_cast<osg::Vec3Array*>(getNormalArray()); 107 if (normal && _normalSource.size() != normal->size()) 108 { 109 _normalSource = std::vector<osg::Vec3>(normal->begin(),normal->end()); 110 getNormalArray()->setDataVariance(osg::Object::DYNAMIC); 103 _rigTransformImplementation = new RigTransformSoftware; 111 104 } 112 105 113 if (!_positionSource.empty()) 114 { 115 _transformVertexes.compute<osg::Vec3>(_matrixFromSkeletonToGeometry, _invMatrixFromSkeletonToGeometry, &_positionSource.front(), &pos->front()); 116 pos->dirty(); 117 } 118 if (!_normalSource.empty()) 119 { 120 _transformVertexes.computeNormal<osg::Vec3>(_matrixFromSkeletonToGeometry, _invMatrixFromSkeletonToGeometry, &_normalSource.front(), &normal->front()); 121 normal->dirty(); 122 } 123 if (getUseDisplayList()) 124 dirtyDisplayList(); 125 dirtyBound(); 106 if (getRigTransformImplementation()->needInit()) 107 if (!getRigTransformImplementation()->init(*this)) 108 return; 109 getRigTransformImplementation()->update(*this); 126 110 } 127 111 128 const osgAnimation::Skeleton* RigGeometry::getSkeleton() const { return _root.get(); } 129 osgAnimation::Skeleton* RigGeometry::getSkeleton() { return _root.get(); } 112 const VertexInfluenceSet& RigGeometry::getVertexInfluenceSet() const { return _vertexInfluenceSet;} 113 114 const Skeleton* RigGeometry::getSkeleton() const { return _root.get(); } 115 Skeleton* RigGeometry::getSkeleton() { return _root.get(); } 116 void RigGeometry::setSkeleton(Skeleton* root) { _root = root;} 117 RigTransform* RigGeometry::getRigTransformImplementation() { return _rigTransformImplementation.get(); } 118 void RigGeometry::setRigTransformImplementation(RigTransform* rig) { _rigTransformImplementation = rig; } -
OpenSceneGraph/trunk/src/osgAnimation/StatsVisitor.cpp
r10432 r10693 15 15 #include <osgAnimation/StatsVisitor> 16 16 #include <osgAnimation/Timeline> 17 #include <osgAnimation/ActionBlendIn> 18 #include <osgAnimation/ActionBlendOut> 19 #include <osgAnimation/ActionStripAnimation> 20 #include <osgAnimation/ActionAnimation> 17 21 18 osgAnimation::StatsActionVisitor::StatsActionVisitor() {} 19 void osgAnimation::StatsActionVisitor::reset() { _channels.clear(); } 22 using namespace osgAnimation; 20 23 21 osgAnimation::StatsActionVisitor::StatsActionVisitor(osg::Stats* stats,unsigned int frame) 24 StatsActionVisitor::StatsActionVisitor() {} 25 void StatsActionVisitor::reset() { _channels.clear(); } 26 27 StatsActionVisitor::StatsActionVisitor(osg::Stats* stats,unsigned int frame) 22 28 { 23 29 _frame = frame; … … 25 31 } 26 32 27 void osgAnimation::StatsActionVisitor::apply(Timeline& tm)33 void StatsActionVisitor::apply(Timeline& tm) 28 34 { 29 35 _stats->setAttribute(_frame,"Timeline", tm.getCurrentTime()); … … 31 37 } 32 38 33 void osgAnimation::StatsActionVisitor::apply(Action& action)39 void StatsActionVisitor::apply(Action& action) 34 40 { 35 41 if (isActive(action)) … … 40 46 } 41 47 42 void osgAnimation::StatsActionVisitor::apply(BlendIn& action)48 void StatsActionVisitor::apply(ActionBlendIn& action) 43 49 { 44 50 if (isActive(action)) … … 49 55 } 50 56 51 void osgAnimation::StatsActionVisitor::apply(BlendOut& action)57 void StatsActionVisitor::apply(ActionBlendOut& action) 52 58 { 53 59 if (isActive(action)) … … 58 64 } 59 65 60 void osgAnimation::StatsActionVisitor::apply(ActionAnimation& action)66 void StatsActionVisitor::apply(ActionAnimation& action) 61 67 { 62 68 if (isActive(action)) … … 67 73 } 68 74 69 void osgAnimation::StatsActionVisitor::apply(StripAnimation& action)75 void StatsActionVisitor::apply(ActionStripAnimation& action) 70 76 { 71 77 if (isActive(action)) 72 78 { 73 79 _channels.push_back(action.getName()); 74 _stats->setAttribute(_frame,action.getName(), action.getA ctionAnimation()->getAnimation()->getWeight());80 _stats->setAttribute(_frame,action.getName(), action.getAnimation()->getAnimation()->getWeight()); 75 81 } 76 82 } -
OpenSceneGraph/trunk/src/osgAnimation/VertexInfluence.cpp
r10656 r10693 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 … … 11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 12 * OpenSceneGraph Public License for more details. 13 */13 */ 14 14 15 15 #include <osgAnimation/VertexInfluence> … … 20 20 using namespace osgAnimation; 21 21 22 const osgAnimation::VertexInfluenceSet::VertexIndexToBoneWeightMap& osgAnimation::VertexInfluenceSet::getVertexToBoneList() const { return _vertex2Bones;} 22 void VertexInfluenceSet::addVertexInfluence(const VertexInfluence& v) { _bone2Vertexes.push_back(v); } 23 const VertexInfluenceSet::VertexIndexToBoneWeightMap& VertexInfluenceSet::getVertexToBoneList() const { return _vertex2Bones;} 23 24 // this class manage VertexInfluence database by mesh 24 25 // reference bones per vertex ... 25 void osgAnimation::VertexInfluenceSet::buildVertex2BoneList()26 void VertexInfluenceSet::buildVertex2BoneList() 26 27 { 27 28 _vertex2Bones.clear(); … … 36 37 float weight = viw.second; 37 38 if (vi.getName().empty()) 38 osg::notify(osg::WARN) << " osgAnimation::VertexInfluenceSet::buildVertex2BoneList warning vertex " << index << " is not assigned to a bone" << std::endl;39 osg::notify(osg::WARN) << "VertexInfluenceSet::buildVertex2BoneList warning vertex " << index << " is not assigned to a bone" << std::endl; 39 40 _vertex2Bones[index].push_back(BoneWeight(vi.getName(), weight)); 40 41 } … … 65 66 66 67 // sort by name and weight 67 struct SortByNameAndWeight : public std::less< osgAnimation::VertexInfluenceSet::BoneWeight>68 struct SortByNameAndWeight : public std::less<VertexInfluenceSet::BoneWeight> 68 69 { 69 bool operator()(const osgAnimation::VertexInfluenceSet::BoneWeight& b0,70 const osgAnimation::VertexInfluenceSet::BoneWeight& b1) const70 bool operator()(const VertexInfluenceSet::BoneWeight& b0, 71 const VertexInfluenceSet::BoneWeight& b1) const 71 72 { 72 73 if (b0.getBoneName() < b1.getBoneName()) … … 80 81 }; 81 82 82 struct SortByBoneWeightList : public std::less< osgAnimation::VertexInfluenceSet::BoneWeightList>83 struct SortByBoneWeightList : public std::less<VertexInfluenceSet::BoneWeightList> 83 84 { 84 bool operator()(const osgAnimation::VertexInfluenceSet::BoneWeightList& b0,85 const osgAnimation::VertexInfluenceSet::BoneWeightList& b1) const85 bool operator()(const VertexInfluenceSet::BoneWeightList& b0, 86 const VertexInfluenceSet::BoneWeightList& b1) const 86 87 { 87 88 if (b0.size() < b1.size()) … … 103 104 }; 104 105 105 void osgAnimation::VertexInfluenceSet::buildUniqVertexSetToBoneSetList() 106 void VertexInfluenceSet::clear() 107 { 108 _bone2Vertexes.clear(); 109 _uniqVertexSetToBoneSet.clear(); 110 } 111 112 void VertexInfluenceSet::buildUniqVertexSetToBoneSetList() 106 113 { 107 114 _uniqVertexSetToBoneSet.clear(); … … 131 138 } 132 139 } 140
