Changeset 10693

Show
Ignore:
Timestamp:
10/27/09 16:37:13 (4 years ago)
Author:
cedricpinson
Message:

From Cedric Pinson, The following commit include:
* Refactore of RigGeometry? to support hardware skinning
* Refactore of Timeline to split Action in differents files
* Add example how to use hardware skinning

Location:
OpenSceneGraph/trunk
Files:
13 added
13 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osgAnimation/Action

    r10561 r10693  
    5858            } 
    5959 
     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 
    6071        protected: 
    6172            osg::ref_ptr<Callback> _nestedCallback; 
     
    8899            return _framesCallback[frame].get(); 
    89100        } 
    90          
     101 
     102        void removeCallback(Callback*); 
     103 
    91104        Callback* getFrameCallback(unsigned int frame); 
    92105        Callback* getFrameCallback(double time); 
     
    128141 
    129142 
    130     // blend in from 0 to weight in duration 
    131     class OSGANIMATION_EXPORT BlendIn : public Action 
    132     { 
    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 duration 
    147     class OSGANIMATION_EXPORT BlendOut : public Action 
    148     { 
    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 Action 
    163     { 
    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 usage 
    178     class OSGANIMATION_EXPORT StripAnimation : public Action 
    179     { 
    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  
    206143} 
    207144 
  • OpenSceneGraph/trunk/include/osgAnimation/ActionVisitor

    r10561 r10693  
    2626    class Timeline; 
    2727    class Action; 
    28     class BlendIn; 
    29     class BlendOut; 
     28    class ActionBlendIn; 
     29    class ActionBlendOut; 
    3030    class ActionAnimation; 
    31     class StripAnimation; 
     31    class ActionStripAnimation; 
    3232 
    3333#define META_ActionVisitor(library,name) \ 
     
    5757        virtual void apply(Action& action); 
    5858        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); 
    6161        virtual void apply(ActionAnimation& action); 
    62         virtual void apply(StripAnimation& action); 
     62        virtual void apply(ActionStripAnimation& action); 
    6363 
    6464    protected: 
     
    7373    protected: 
    7474        unsigned int _frame; 
    75  
     75        unsigned int _currentAnimationPriority; 
    7676    public: 
    7777        META_ActionVisitor(osgAnimation, UpdateActionVisitor); 
     
    8484        void apply(Timeline& action); 
    8585        void apply(Action& action); 
    86         void apply(BlendIn& action); 
    87         void apply(BlendOut& action); 
     86        void apply(ActionBlendIn& action); 
     87        void apply(ActionBlendOut& action); 
    8888        void apply(ActionAnimation& action); 
    89         void apply(StripAnimation& action); 
     89        void apply(ActionStripAnimation& action); 
    9090 
    9191    }; 
  • OpenSceneGraph/trunk/include/osgAnimation/RigGeometry

    r10344 r10693  
    11/*  -*-c++-*-  
    2  *  Copyright (C) 2008 Cedric Pinson <mornifle@plopbyte.net> 
     2 *  Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> 
    33 * 
    44 * This library is open source and may be redistributed and/or modified under   
     
    1717 
    1818#include <osgAnimation/Export> 
    19 #include <osgAnimation/Skinning> 
    2019#include <osgAnimation/Skeleton> 
     20#include <osgAnimation/RigTransform> 
    2121#include <osg/Geometry> 
    2222 
     
    3434        META_Object(osgAnimation, RigGeometry); 
    3535 
    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();} 
    3939  
    4040        const Skeleton* getSkeleton() const; 
    4141        Skeleton* getSkeleton(); 
     42        // will be used by the update callback to init correctly the rig mesh 
     43        void setSkeleton(Skeleton*); 
    4244         
    4345        void setNeedToComputeMatrix(bool state) { _needToComputeMatrix = state;} 
    4446        bool getNeedToComputeMatrix() const { return _needToComputeMatrix;} 
    4547         
    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 
    4853        void computeMatrixFromRootSkeleton(); 
    4954 
    50         virtual void transformSoftwareMethod(); 
    51         const osgAnimation::VertexInfluenceSet& getVertexInfluenceSet() const { return _vertexInfluenceSet;} 
    5255 
    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; 
    5565 
    5666    protected: 
    5767 
    58         std::vector<osg::Vec3> _positionSource; 
    59         std::vector<osg::Vec3> _normalSource; 
     68        osg::ref_ptr<RigTransform> _rigTransformImplementation; 
    6069 
    61         osgAnimation::VertexInfluenceSet _vertexInfluenceSet; 
    62         osg::ref_ptr<osgAnimation::VertexInfluenceMap> _vertexInfluenceMap; 
    63         osgAnimation::TransformVertexFunctor _transformVertexes; 
     70        VertexInfluenceSet _vertexInfluenceSet; 
     71        osg::ref_ptr<VertexInfluenceMap> _vertexInfluenceMap; 
    6472 
    6573        osg::Matrix _matrixFromSkeletonToGeometry; 
     
    6775        osg::observer_ptr<Skeleton> _root; 
    6876        bool _needToComputeMatrix; 
    69  
    7077  
    7178        struct FindNearestParentSkeleton : public osg::NodeVisitor 
    7279        { 
    73             osg::ref_ptr<osgAnimation::Skeleton> _root; 
     80            osg::ref_ptr<Skeleton> _root; 
    7481            FindNearestParentSkeleton() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_PARENTS) {} 
    7582            void apply(osg::Transform& node)  
     
    99106                    if (!finder._root.valid()) 
    100107                        return; 
    101                     geom->buildVertexSet(); 
    102                     geom->buildTransformer(finder._root.get()); 
     108                    geom->buildVertexInfluenceSet(); 
     109                    geom->setSkeleton(finder._root.get()); 
    103110                } 
    104111 
     
    108115                if (geom->getNeedToComputeMatrix()) 
    109116                    geom->computeMatrixFromRootSkeleton(); 
    110                 geom->transformSoftwareMethod(); 
     117 
     118                geom->update(); 
    111119            } 
    112120        }; 
    113  
    114         /** BuildVertexTransformerVisitor is used to setup RigGeometry drawable 
    115          *  throw a subgraph.  
    116          */ 
    117         struct BuildVertexTransformerVisitor : public osg::NodeVisitor 
    118         { 
    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  
    138121   }; 
    139122 
  • OpenSceneGraph/trunk/include/osgAnimation/StatsVisitor

    r10351 r10693  
    4242        void apply(Timeline& action); 
    4343        void apply(Action& action); 
    44         void apply(BlendIn& action); 
    45         void apply(BlendOut& action); 
     44        void apply(ActionBlendIn& action); 
     45        void apply(ActionBlendOut& action); 
    4646        void apply(ActionAnimation& action); 
    47         void apply(StripAnimation& action); 
     47        void apply(ActionStripAnimation& action); 
    4848 
    4949    }; 
  • OpenSceneGraph/trunk/include/osgAnimation/Timeline

    r10357 r10693  
    6363        virtual void addActionAt(double t, Action* action, int priority = 0); 
    6464        void addActionNow(Action* action, int priority = 0); 
    65  
     65         
    6666        void clearActions(); 
    6767 
  • OpenSceneGraph/trunk/include/osgAnimation/VertexInfluence

    r10656 r10693  
    1313*/ 
    1414 
    15 #ifndef OSGANIMATION_VERTEX_INFLUENCES_H 
    16 #define OSGANIMATION_VERTEX_INFLUENCES_H 
     15#ifndef OSGANIMATION_VERTEX_INFLUENCE_H 
     16#define OSGANIMATION_VERTEX_INFLUENCE_H 1 
    1717 
    1818#include <osg/Object> 
     
    3838        std::string _name; 
    3939    }; 
    40  
    41     //  typedef std::map<std::string, VertexInfluence> VertexInfluenceMap; 
    4240 
    4341    class VertexInfluenceMap : public std::map<std::string, VertexInfluence> , public osg::Object 
     
    7472        typedef std::map<int,BoneWeightList> VertexIndexToBoneWeightMap; 
    7573     
    76         class UniqVertexSetToBoneSet  
     74        class UniqVertexSetToBoneSet 
    7775        { 
    7876        public: 
     
    8987 
    9088        const UniqVertexSetToBoneSetList& getUniqVertexSetToBoneSetList() const { return _uniqVertexSetToBoneSet;} 
    91         void addVertexInfluence(const VertexInfluence& v) { _bone2Vertexes.push_back(v); } 
     89        void addVertexInfluence(const VertexInfluence& v); 
    9290        void buildVertex2BoneList(); 
    9391        void buildUniqVertexSetToBoneSetList(); 
    94         void clear()  
    95         { 
    96             _bone2Vertexes.clear();  
    97             _uniqVertexSetToBoneSet.clear(); 
    98         } 
     92        void clear(); 
    9993 
    10094        const VertexIndexToBoneWeightMap& getVertexToBoneList() const; 
  • OpenSceneGraph/trunk/src/osgAnimation/Action.cpp

    r10561 r10693  
    1515#include <osgAnimation/Action> 
    1616 
    17 osgAnimation::Action::Action() 
     17using namespace osgAnimation; 
     18 
     19Action::Action() 
    1820{ 
    1921    _numberFrame = 25; 
     
    2224    _loop = 1; 
    2325} 
    24 osgAnimation::Action::Action(const Action&,const osg::CopyOp&) {} 
    25 osgAnimation::Action::Callback* osgAnimation::Action::getFrameCallback(unsigned int frame) 
     26Action::Action(const Action&,const osg::CopyOp&) {} 
     27Action::Callback* Action::getFrameCallback(unsigned int frame) 
    2628{ 
    2729    if (_framesCallback.find(frame) != _framesCallback.end()) 
     
    3234} 
    3335 
    34 osgAnimation::Action::Callback* osgAnimation::Action::getFrameCallback(double time) 
     36void 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 
     59Action::Callback* Action::getFrameCallback(double time) 
    3560{ 
    3661    unsigned int frame = static_cast<unsigned int>(floor(time * _fps)); 
     
    5782    return true; 
    5883} 
    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 first 
    74     // 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     else 
    141         setDuration(loop * _animation->getDuration()); 
    142  
    143     // duration changed re evaluate the blendout duration 
    144     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  
    1414 
    1515#include <osgAnimation/Action> 
     16#include <osgAnimation/ActionBlendIn> 
     17#include <osgAnimation/ActionBlendOut> 
     18#include <osgAnimation/ActionStripAnimation> 
     19#include <osgAnimation/ActionAnimation> 
    1620#include <osgAnimation/ActionVisitor> 
    1721#include <osgAnimation/Timeline> 
    1822 
    19 osgAnimation::ActionVisitor::ActionVisitor() 
     23using namespace osgAnimation; 
     24 
     25ActionVisitor::ActionVisitor() 
    2026{ 
    2127    _currentLayer = 0; 
    2228} 
    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) 
     29void ActionVisitor::pushFrameActionOnStack(const FrameAction& fa) { _stackFrameAction.push_back(fa); } 
     30void ActionVisitor::popFrameAction() { _stackFrameAction.pop_back(); } 
     31void ActionVisitor::pushTimelineOnStack(Timeline* tm) { _stackTimeline.push_back(tm); } 
     32void ActionVisitor::popTimeline() { _stackTimeline.pop_back(); } 
     33void ActionVisitor::apply(Action& action) { traverse(action); } 
     34void ActionVisitor::apply(Timeline& tm) { tm.traverse(*this); } 
     35void ActionVisitor::apply(ActionBlendIn& action) { apply(static_cast<Action&>(action));} 
     36void ActionVisitor::apply(ActionBlendOut& action) { apply(static_cast<Action&>(action)); } 
     37void ActionVisitor::apply(ActionAnimation& action) { apply(static_cast<Action&>(action)); } 
     38void ActionVisitor::apply(ActionStripAnimation& action) { apply(static_cast<Action&>(action)); } 
     39void ActionVisitor::traverse(Action& action) 
    3440{ 
    3541    action.traverse(*this); 
    3642} 
    3743 
    38 osgAnimation::Timeline* osgAnimation::ActionVisitor::getCurrentTimeline() 
     44Timeline* ActionVisitor::getCurrentTimeline() 
    3945{ 
    4046    if (_stackTimeline.empty()) 
     
    4349} 
    4450 
    45 osgAnimation::UpdateActionVisitor::UpdateActionVisitor() { _frame = 0; } 
     51UpdateActionVisitor::UpdateActionVisitor()  
     52{ 
     53    _frame = 0;  
     54    _currentAnimationPriority = 0; 
     55} 
    4656 
    4757 
    48 void osgAnimation::UpdateActionVisitor::apply(Timeline& tm) 
     58void UpdateActionVisitor::apply(Timeline& tm) 
    4959{ 
     60    _currentAnimationPriority = 0; 
     61 
    5062    tm.setEvaluating(true); 
    5163 
     
    5769} 
    5870 
    59 bool osgAnimation::UpdateActionVisitor::isActive(Action& action) const 
     71bool UpdateActionVisitor::isActive(Action& action) const 
    6072{ 
    6173    FrameAction fa = _stackFrameAction.back(); 
     
    7183} 
    7284 
    73 unsigned int osgAnimation::UpdateActionVisitor::getLocalFrame() const 
     85unsigned int UpdateActionVisitor::getLocalFrame() const 
    7486{ 
    7587    return _frame - _stackFrameAction.back().first; 
    7688} 
    7789 
    78 void osgAnimation::UpdateActionVisitor::apply(Action& action) 
     90void UpdateActionVisitor::apply(Action& action) 
    7991{ 
    8092    if (isActive(action)) 
     
    103115} 
    104116 
    105 void osgAnimation::UpdateActionVisitor::apply(BlendIn& action) 
     117void UpdateActionVisitor::apply(ActionBlendIn& action) 
    106118{ 
    107119    if (isActive(action))  
     
    113125} 
    114126 
    115 void osgAnimation::UpdateActionVisitor::apply(BlendOut& action) 
     127void UpdateActionVisitor::apply(ActionBlendOut& action) 
    116128{ 
    117129    if (isActive(action))  
     
    123135} 
    124136 
    125 void osgAnimation::UpdateActionVisitor::apply(ActionAnimation& action) 
     137void UpdateActionVisitor::apply(ActionAnimation& action) 
    126138{ 
    127     if (isActive(action))  
     139    if (isActive(action)) 
    128140    { 
    129141        unsigned int frame = getLocalFrame(); 
    130142        apply(static_cast<Action&>(action)); 
    131         action.updateAnimation(frame, getCurrentLayer()); 
     143//        action.updateAnimation(frame, getCurrentLayer()); 
     144        action.updateAnimation(frame, -_currentAnimationPriority++); 
    132145    } 
    133146} 
    134147 
    135 void osgAnimation::UpdateActionVisitor::apply(StripAnimation& action) 
     148void UpdateActionVisitor::apply(ActionStripAnimation& action) 
    136149{ 
    137150    if (isActive(action)) 
     
    144157 
    145158 
    146 osgAnimation::ClearActionVisitor::ClearActionVisitor(ClearType type) : _clearType(type) 
     159ClearActionVisitor::ClearActionVisitor(ClearType type) : _clearType(type) 
    147160{ 
    148161} 
    149162 
    150 void osgAnimation::ClearActionVisitor::apply(Timeline& tm) 
     163void ClearActionVisitor::apply(Timeline& tm) 
    151164{ 
    152165    _remove.clear(); 
     
    155168        tm.removeAction(_remove[i].get()); 
    156169} 
    157 void osgAnimation::ClearActionVisitor::apply(Action& action) 
     170void ClearActionVisitor::apply(Action& action) 
    158171{ 
    159172    FrameAction fa = _stackFrameAction.back(); 
  • OpenSceneGraph/trunk/src/osgAnimation/Bone.cpp

    r10656 r10693  
    1313*/ 
    1414 
    15 #include <osgAnimation/Skinning> 
    1615#include <osgAnimation/Bone> 
    1716#include <osgAnimation/Skeleton> 
  • OpenSceneGraph/trunk/src/osgAnimation/CMakeLists.txt

    r10576 r10693  
    1212SET(LIB_PUBLIC_HEADERS 
    1313    ${HEADER_PATH}/Action 
     14    ${HEADER_PATH}/ActionAnimation 
     15    ${HEADER_PATH}/ActionBlendIn 
     16    ${HEADER_PATH}/ActionBlendOut 
    1417    ${HEADER_PATH}/ActionCallback 
     18    ${HEADER_PATH}/ActionStripAnimation 
    1519    ${HEADER_PATH}/ActionVisitor 
    1620    ${HEADER_PATH}/Animation 
     
    3236    ${HEADER_PATH}/MorphGeometry 
    3337    ${HEADER_PATH}/RigGeometry 
     38    ${HEADER_PATH}/RigTransform 
     39    ${HEADER_PATH}/RigTransformHardware 
     40    ${HEADER_PATH}/RigTransformSoftware 
    3441    ${HEADER_PATH}/Sampler 
    3542    ${HEADER_PATH}/Skeleton 
    36     ${HEADER_PATH}/Skinning 
    3743    ${HEADER_PATH}/StatsVisitor 
    3844    ${HEADER_PATH}/StatsHandler 
     
    5056    ${LIB_PUBLIC_HEADERS} 
    5157    Action.cpp 
     58    ActionAnimation.cpp 
     59    ActionBlendIn.cpp 
     60    ActionBlendOut.cpp 
    5261    ActionCallback.cpp 
     62    ActionStripAnimation.cpp 
    5363    ActionVisitor.cpp 
    5464    Animation.cpp 
     
    6272    MorphGeometry.cpp 
    6373    RigGeometry.cpp 
     74    RigTransformHardware.cpp 
     75    RigTransformSoftware.cpp 
    6476    Skeleton.cpp 
    6577    StatsVisitor.cpp 
  • OpenSceneGraph/trunk/src/osgAnimation/RigGeometry.cpp

    r9531 r10693  
    11/*  -*-c++-*-  
    2  *  Copyright (C) 2008 Cedric Pinson <mornifle@plopbyte.net> 
     2 *  Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> 
    33 * 
    4  * This program is free software; you can redistribute it and/or modify 
    5  * it under the terms of the GNU General Public License as published by 
    6  * the Free Software Foundation; either version 2 of the License, or 
    7  * (at your option) any later version. 
    8  * 
    9  * This program is 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, 
    1010 * 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. 
    2213 */ 
     14 
    2315#include <osgAnimation/RigGeometry> 
     16#include <osgAnimation/RigTransformSoftware> 
     17#include <sstream> 
     18#include <osg/GL2Extensions> 
    2419 
    2520using namespace osgAnimation; 
     
    2722RigGeometry::RigGeometry() 
    2823{ 
    29     setUseDisplayList(false); 
     24    _supportsDisplayList = false; 
     25    setUseVertexBufferObjects(true); 
    3026    setUpdateCallback(new UpdateVertex); 
    3127    setDataVariance(osg::Object::DYNAMIC); 
    3228    _needToComputeMatrix = true; 
    3329    _matrixFromSkeletonToGeometry = _invMatrixFromSkeletonToGeometry = osg::Matrix::identity(); 
     30 
     31    // disable the computation of boundingbox for the rig mesh 
     32    setComputeBoundingBoxCallback(new ComputeBoundingBoxCallback); 
    3433} 
    3534 
    3635RigGeometry::RigGeometry(const osg::Geometry& b) : osg::Geometry(b, osg::CopyOp::SHALLOW_COPY) 
    3736{ 
    38     setUseDisplayList(false); 
     37    _supportsDisplayList = false; 
     38    setUseVertexBufferObjects(true); 
    3939    setUpdateCallback(new UpdateVertex); 
    4040    setDataVariance(osg::Object::DYNAMIC); 
    4141    _needToComputeMatrix = true; 
    4242    _matrixFromSkeletonToGeometry = _invMatrixFromSkeletonToGeometry = osg::Matrix::identity(); 
     43 
     44    // disable the computation of boundingbox for the rig mesh 
     45    setComputeBoundingBoxCallback(new ComputeBoundingBoxCallback); 
    4346} 
    4447 
    45 RigGeometry::RigGeometry(const RigGeometry& b, const osg::CopyOp& copyop) :  
     48RigGeometry::RigGeometry(const RigGeometry& b, const osg::CopyOp& copyop) : 
    4649    osg::Geometry(b,copyop), 
    47     _positionSource(b._positionSource), 
    48     _normalSource(b._normalSource), 
    4950    _vertexInfluenceSet(b._vertexInfluenceSet), 
    5051    _vertexInfluenceMap(b._vertexInfluenceMap), 
    51     _transformVertexes(b._transformVertexes), 
    52     _needToComputeMatrix(b._needToComputeMatrix)  
     52    _needToComputeMatrix(b._needToComputeMatrix) 
    5353{ 
     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 
    5456} 
    5557 
    56 void RigGeometry::buildTransformer(Skeleton* root) 
     58 
     59const osg::Matrix& RigGeometry::getMatrixFromSkeletonToGeometry() const { return _matrixFromSkeletonToGeometry; } 
     60const osg::Matrix& RigGeometry::getInvMatrixFromSkeletonToGeometry() const { return _invMatrixFromSkeletonToGeometry;} 
     61 
     62 
     63void RigGeometry::drawImplementation(osg::RenderInfo& renderInfo) const 
    5764{ 
    58     Bone::BoneMap bm = root->getBoneMap(); 
    59     _transformVertexes.init(bm, _vertexInfluenceSet.getUniqVertexSetToBoneSetList()); 
    60     _root = root; 
     65    osg::Geometry::drawImplementation(renderInfo); 
    6166} 
    6267 
    63 void RigGeometry::buildVertexSet()  
     68void RigGeometry::buildVertexInfluenceSet() 
    6469{ 
    65     if (!_vertexInfluenceMap.valid())  
     70    if (!_vertexInfluenceMap.valid()) 
    6671    { 
    67         osg::notify(osg::WARN) << "buildVertexSet 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; 
    6873        return; 
    6974    } 
     
    7681    _vertexInfluenceSet.buildVertex2BoneList(); 
    7782    _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; 
    7984} 
    8085 
    81 void RigGeometry::computeMatrixFromRootSkeleton()  
     86void RigGeometry::computeMatrixFromRootSkeleton() 
    8287{ 
    83     if (!_root.valid())  
     88    if (!_root.valid()) 
    8489    { 
    8590        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; 
     
    9297} 
    9398 
    94 void RigGeometry::transformSoftwareMethod() 
     99void RigGeometry::update() 
    95100{ 
    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()) 
    102102    { 
    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; 
    111104    } 
    112105 
    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); 
    126110} 
    127111 
    128 const osgAnimation::Skeleton* RigGeometry::getSkeleton() const { return _root.get(); } 
    129 osgAnimation::Skeleton* RigGeometry::getSkeleton() { return _root.get(); } 
     112const VertexInfluenceSet& RigGeometry::getVertexInfluenceSet() const { return _vertexInfluenceSet;} 
     113 
     114const Skeleton* RigGeometry::getSkeleton() const { return _root.get(); } 
     115Skeleton* RigGeometry::getSkeleton() { return _root.get(); } 
     116void RigGeometry::setSkeleton(Skeleton* root) { _root = root;} 
     117RigTransform* RigGeometry::getRigTransformImplementation() { return _rigTransformImplementation.get(); } 
     118void RigGeometry::setRigTransformImplementation(RigTransform* rig) { _rigTransformImplementation = rig; } 
  • OpenSceneGraph/trunk/src/osgAnimation/StatsVisitor.cpp

    r10432 r10693  
    1515#include <osgAnimation/StatsVisitor> 
    1616#include <osgAnimation/Timeline> 
     17#include <osgAnimation/ActionBlendIn> 
     18#include <osgAnimation/ActionBlendOut> 
     19#include <osgAnimation/ActionStripAnimation> 
     20#include <osgAnimation/ActionAnimation> 
    1721 
    18 osgAnimation::StatsActionVisitor::StatsActionVisitor() {} 
    19 void osgAnimation::StatsActionVisitor::reset() { _channels.clear(); } 
     22using namespace osgAnimation; 
    2023 
    21 osgAnimation::StatsActionVisitor::StatsActionVisitor(osg::Stats* stats,unsigned int frame) 
     24StatsActionVisitor::StatsActionVisitor() {} 
     25void StatsActionVisitor::reset() { _channels.clear(); } 
     26 
     27StatsActionVisitor::StatsActionVisitor(osg::Stats* stats,unsigned int frame) 
    2228{ 
    2329    _frame = frame; 
     
    2531} 
    2632 
    27 void osgAnimation::StatsActionVisitor::apply(Timeline& tm) 
     33void StatsActionVisitor::apply(Timeline& tm) 
    2834{ 
    2935    _stats->setAttribute(_frame,"Timeline", tm.getCurrentTime()); 
     
    3137} 
    3238 
    33 void osgAnimation::StatsActionVisitor::apply(Action& action) 
     39void StatsActionVisitor::apply(Action& action) 
    3440{ 
    3541    if (isActive(action)) 
     
    4046} 
    4147 
    42 void osgAnimation::StatsActionVisitor::apply(BlendIn& action) 
     48void StatsActionVisitor::apply(ActionBlendIn& action) 
    4349{ 
    4450    if (isActive(action))  
     
    4955} 
    5056 
    51 void osgAnimation::StatsActionVisitor::apply(BlendOut& action) 
     57void StatsActionVisitor::apply(ActionBlendOut& action) 
    5258{ 
    5359    if (isActive(action))  
     
    5864} 
    5965 
    60 void osgAnimation::StatsActionVisitor::apply(ActionAnimation& action) 
     66void StatsActionVisitor::apply(ActionAnimation& action) 
    6167{ 
    6268    if (isActive(action))  
     
    6773} 
    6874 
    69 void osgAnimation::StatsActionVisitor::apply(StripAnimation& action) 
     75void StatsActionVisitor::apply(ActionStripAnimation& action) 
    7076{ 
    7177    if (isActive(action)) 
    7278    { 
    7379        _channels.push_back(action.getName()); 
    74         _stats->setAttribute(_frame,action.getName(), action.getActionAnimation()->getAnimation()->getWeight()); 
     80        _stats->setAttribute(_frame,action.getName(), action.getAnimation()->getAnimation()->getWeight()); 
    7581    } 
    7682} 
  • OpenSceneGraph/trunk/src/osgAnimation/VertexInfluence.cpp

    r10656 r10693  
    11/*  -*-c++-*-  
    2  *  Copyright (C) 2008 Cedric Pinson <mornifle@plopbyte.net> 
     2 *  Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> 
    33 * 
    44 * This library is open source and may be redistributed and/or modified under   
     
    1111 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
    1212 * OpenSceneGraph Public License for more details. 
    13 */ 
     13 */ 
    1414 
    1515#include <osgAnimation/VertexInfluence> 
     
    2020using namespace osgAnimation; 
    2121 
    22 const osgAnimation::VertexInfluenceSet::VertexIndexToBoneWeightMap& osgAnimation::VertexInfluenceSet::getVertexToBoneList() const { return _vertex2Bones;} 
     22void VertexInfluenceSet::addVertexInfluence(const VertexInfluence& v) { _bone2Vertexes.push_back(v); } 
     23const VertexInfluenceSet::VertexIndexToBoneWeightMap& VertexInfluenceSet::getVertexToBoneList() const { return _vertex2Bones;} 
    2324// this class manage VertexInfluence database by mesh 
    2425// reference bones per vertex ... 
    25 void osgAnimation::VertexInfluenceSet::buildVertex2BoneList() 
     26void VertexInfluenceSet::buildVertex2BoneList() 
    2627{ 
    2728    _vertex2Bones.clear(); 
     
    3637            float weight = viw.second; 
    3738            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; 
    3940            _vertex2Bones[index].push_back(BoneWeight(vi.getName(), weight)); 
    4041        } 
     
    6566 
    6667// sort by name and weight 
    67 struct SortByNameAndWeight : public std::less<osgAnimation::VertexInfluenceSet::BoneWeight> 
     68struct SortByNameAndWeight : public std::less<VertexInfluenceSet::BoneWeight> 
    6869{ 
    69     bool operator()(const osgAnimation::VertexInfluenceSet::BoneWeight& b0,  
    70                     const osgAnimation::VertexInfluenceSet::BoneWeight& b1) const  
     70    bool operator()(const VertexInfluenceSet::BoneWeight& b0,  
     71                    const VertexInfluenceSet::BoneWeight& b1) const  
    7172    { 
    7273        if (b0.getBoneName() < b1.getBoneName()) 
     
    8081}; 
    8182 
    82 struct SortByBoneWeightList : public std::less<osgAnimation::VertexInfluenceSet::BoneWeightList> 
     83struct SortByBoneWeightList : public std::less<VertexInfluenceSet::BoneWeightList> 
    8384{ 
    84     bool operator()(const osgAnimation::VertexInfluenceSet::BoneWeightList& b0,  
    85                     const osgAnimation::VertexInfluenceSet::BoneWeightList& b1) const  
     85    bool operator()(const VertexInfluenceSet::BoneWeightList& b0,  
     86                    const VertexInfluenceSet::BoneWeightList& b1) const  
    8687    { 
    8788        if (b0.size() < b1.size()) 
     
    103104}; 
    104105 
    105 void osgAnimation::VertexInfluenceSet::buildUniqVertexSetToBoneSetList() 
     106void VertexInfluenceSet::clear() 
     107{ 
     108    _bone2Vertexes.clear();  
     109    _uniqVertexSetToBoneSet.clear(); 
     110} 
     111 
     112void VertexInfluenceSet::buildUniqVertexSetToBoneSetList() 
    106113{ 
    107114    _uniqVertexSetToBoneSet.clear(); 
     
    131138    } 
    132139} 
     140