Changeset 10561

Show
Ignore:
Timestamp:
08/31/09 11:40:56 (5 years ago)
Author:
cedricpinson
Message:

From Cedric Pinson, The following modification are
Update Timeline.cpp to add current layer to the ActionVisitor?, use correctly the priority
Add accessors in Action.cpp to retrieve protected data
Split files and rename them to classname
Change de default color of UpdateMaterial? to FFOOFF to detect unset value
Add accessors in LinkVisitor? instead of accessing data directly
Update osganimationtimeline example to fit the api callback

Location:
OpenSceneGraph/trunk
Files:
12 modified

Legend:

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

    r10432 r10561  
    167167        ActionAnimation(const ActionAnimation& a, const osg::CopyOp& c) : Action(a,c) { _animation = a._animation;} 
    168168        ActionAnimation(Animation* animation); 
    169         void updateAnimation(unsigned int frame); 
     169        void updateAnimation(unsigned int frame, int priority); 
    170170        Animation* getAnimation() { return _animation.get(); } 
    171171 
     
    193193        unsigned int getLoop() const { return _animation->getLoop(); } 
    194194        void setLoop(unsigned int loop); 
    195         void computeWeightAndUpdateAnimation(unsigned int frame); 
    196  
    197195        void traverse(ActionVisitor& visitor); 
    198196 
  • OpenSceneGraph/trunk/include/osgAnimation/ActionVisitor

    r10432 r10561  
    3939    { 
    4040    public: 
    41         std::vector<FrameAction> _stackFrameAction; 
    42         std::vector<Timeline*> _stackTimeline; 
    43  
    4441        META_ActionVisitor(osgAnimation, ActionVisitor); 
     42        ActionVisitor(); 
    4543        void traverse(Action& visitor); 
    4644 
     
    5250 
    5351        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; } 
    5456 
    5557        virtual void apply(Action& action); 
     
    5961        virtual void apply(ActionAnimation& action); 
    6062        virtual void apply(StripAnimation& action); 
     63 
     64    protected: 
     65        std::vector<FrameAction> _stackFrameAction; 
     66        std::vector<Timeline*> _stackTimeline; 
     67        int _currentLayer; 
    6168    }; 
    6269 
  • OpenSceneGraph/trunk/include/osgAnimation/Bone

    r10558 r10561  
    5757        void setDefaultUpdateCallback(const std::string& name = ""); 
    5858 
    59         struct BoneMapVisitor : public osg::NodeVisitor 
    60         { 
    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  
    7859        class OSGANIMATION_EXPORT UpdateBone : public AnimationUpdateCallback <osg::NodeCallback> 
    7960        { 
     
    132113        const osg::Vec3& getTranslation() const { return _position;} 
    133114        const osg::Quat& getRotation() const { return _rotation;} 
     115        const osg::Vec3& getScale() const { return _scale;} 
     116 
    134117        osg::Matrix getMatrixInBoneSpace() const { return (osg::Matrix(getRotation())) * osg::Matrix::translate(getTranslation()) * _bindInBoneSpace;} 
    135118        const osg::Matrix& getBindMatrixInBoneSpace() const { return _bindInBoneSpace; } 
  • OpenSceneGraph/trunk/include/osgAnimation/LinkVisitor

    r10518 r10561  
    3838        AnimationList& getAnimationList(); 
    3939        void reset(); 
     40        unsigned int getNbLinkedTarget() const { return _nbLinkedTarget; } 
    4041 
    4142    protected: 
  • OpenSceneGraph/trunk/include/osgAnimation/Target

    r10556 r10561  
    3535             
    3636        Target(); 
    37         virtual ~Target(); 
     37        virtual ~Target() {} 
    3838        virtual void normalize() = 0; 
    3939        void reset() { _weight = 0; _priorityWeight = 0; } 
  • OpenSceneGraph/trunk/src/osgAnimation/Action.cpp

    r10435 r10561  
    104104    setName(animation->getName()); 
    105105} 
    106 void osgAnimation::ActionAnimation::updateAnimation(unsigned int frame) 
     106void osgAnimation::ActionAnimation::updateAnimation(unsigned int frame, int priority) 
    107107{ 
    108     _animation->update(frame * 1.0/_fps); 
     108    _animation->update(frame * 1.0/_fps, priority); 
    109109} 
    110110 
     
    150150    if (_blendIn.valid()) 
    151151    { 
    152         unsigned int f = visitor._stackFrameAction.back().first; 
     152        unsigned int f = visitor.getStackedFrameAction().back().first; 
    153153        visitor.pushFrameActionOnStack(FrameAction(f,_blendIn.get())); 
    154154        _blendIn->accept(visitor); 
     
    157157    if (_blendOut.second.valid()) 
    158158    { 
    159         unsigned int f = visitor._stackFrameAction.back().first; 
     159        unsigned int f = visitor.getStackedFrameAction().back().first; 
    160160        visitor.pushFrameActionOnStack(FrameAction(f + _blendOut.first,_blendOut.second.get())); 
    161161        _blendOut.second.get()->accept(visitor); 
     
    165165    if (_animation.valid()) 
    166166    { 
    167         unsigned int f = visitor._stackFrameAction.back().first; 
     167        unsigned int f = visitor.getStackedFrameAction().back().first; 
    168168        visitor.pushFrameActionOnStack(FrameAction(f,_animation.get())); 
    169169        _animation->accept(visitor); 
     
    171171    } 
    172172} 
    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  
    1717#include <osgAnimation/Timeline> 
    1818 
     19osgAnimation::ActionVisitor::ActionVisitor() 
     20{ 
     21    _currentLayer = 0; 
     22} 
    1923void osgAnimation::ActionVisitor::pushFrameActionOnStack(const FrameAction& fa) { _stackFrameAction.push_back(fa); } 
    2024void osgAnimation::ActionVisitor::popFrameAction() { _stackFrameAction.pop_back(); } 
     
    125129        unsigned int frame = getLocalFrame(); 
    126130        apply(static_cast<Action&>(action)); 
    127         action.updateAnimation(frame); 
     131        action.updateAnimation(frame, getCurrentLayer()); 
    128132    } 
    129133} 
     
    134138    { 
    135139        apply(static_cast<Action&>(action)); 
    136  
    137 #if 0 
    138         unsigned int frame = getLocalFrame(); 
    139         // evaluate callback in blendin/blendout/animation 
    140         { 
    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 #else 
    157140        action.traverse(*this); 
    158 #endif 
    159141    } 
    160142} 
  • OpenSceneGraph/trunk/src/osgAnimation/Bone.cpp

    r10558 r10561  
    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   
     
    1616#include <osgAnimation/Bone> 
    1717#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> 
    5721 
    5822 
     
    10872        if (!_manager.valid()) 
    10973        { 
    110             FindNearestParentAnimationManager finder; 
     74            FindParentAnimationManagerVisitor finder; 
    11175 
    11276            if (b->getParents().size() > 1) 
     
    12185            b->getParents()[0]->accept(finder); 
    12286 
    123             if (!finder._manager.valid()) 
     87            if (!finder.getAnimationManager()) 
    12488            { 
    12589                osg::notify(osg::WARN) << "Warning can't update Bone, path to parent AnimationManagerBase not found" << std::endl; 
     
    12791            } 
    12892 
    129             _manager = finder._manager.get(); 
     93            _manager = finder.getAnimationManager(); 
    13094        } 
    13195 
     
    154118    _boneInSkeletonSpace(b._boneInSkeletonSpace) 
    155119{ 
     120#if 0 
    156121    osg::ref_ptr<osg::NodeCallback> updatecallback = getUpdateCallback(); 
    157122    setUpdateCallback(0); 
     
    162127        updatecallback = updatecallback->getNestedCallback(); 
    163128    } 
     129#endif 
    164130} 
    165131 
     
    193159} 
    194160 
    195 osgAnimation::Bone* osgAnimation::Bone::getBoneParent()  
     161osgAnimation::Bone* osgAnimation::Bone::getBoneParent() 
    196162{ 
    197163    if (getParents().empty()) 
     
    239205    BoneMapVisitor mapVisitor; 
    240206    this->accept(mapVisitor); 
    241     return mapVisitor._map; 
    242 } 
     207    return mapVisitor.getBoneMap(); 
     208} 
  • OpenSceneGraph/trunk/src/osgAnimation/CMakeLists.txt

    r10498 r10561  
    1919    ${HEADER_PATH}/BasicAnimationManager 
    2020    ${HEADER_PATH}/Bone 
     21    ${HEADER_PATH}/BoneMapVisitor 
    2122    ${HEADER_PATH}/Channel 
    2223    ${HEADER_PATH}/CubicBezier 
     24    ${HEADER_PATH}/ComputeBindMatrixVisitor 
    2325    ${HEADER_PATH}/EaseMotion 
    2426    ${HEADER_PATH}/Export 
     27    ${HEADER_PATH}/FindParentAnimationManagerVisitor 
    2528    ${HEADER_PATH}/FrameAction 
    2629    ${HEADER_PATH}/Interpolator 
     
    5457    BasicAnimationManager.cpp 
    5558    Bone.cpp 
     59    BoneMapVisitor.cpp 
    5660    Channel.cpp 
     61    FindParentAnimationManagerVisitor.cpp 
    5762    LinkVisitor.cpp 
    5863    MorphGeometry.cpp 
  • OpenSceneGraph/trunk/src/osgAnimation/Target.cpp

    r10556 r10561  
    2020 
    2121Target::Target() : _weight(0), _priorityWeight(0), _lastPriority(0) {} 
    22 Target::~Target() {} 
  • OpenSceneGraph/trunk/src/osgAnimation/Timeline.cpp

    r10394 r10561  
    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   
     
    5656void osgAnimation::Timeline::traverse(ActionVisitor& visitor) 
    5757{ 
     58    int layer = visitor.getCurrentLayer(); 
    5859    visitor.pushTimelineOnStack(this); 
    5960    // update from high priority to low priority 
    6061    for( ActionLayers::reverse_iterator iterAnim = _actions.rbegin(); iterAnim != _actions.rend(); ++iterAnim ) 
    6162    { 
     63        visitor.setCurrentLayer(iterAnim->first); 
    6264        ActionList& list = iterAnim->second; 
    6365        for (unsigned int i = 0; i < list.size(); i++) 
     
    6971    } 
    7072    visitor.popTimeline(); 
     73    visitor.setCurrentLayer(layer); 
    7174} 
    7275 
  • OpenSceneGraph/trunk/src/osgAnimation/UpdateCallback.cpp

    r10527 r10561  
    131131    AnimationUpdateCallback<osg::StateAttribute::Callback>(name) 
    132132{ 
    133     _diffuse = new osgAnimation::Vec4Target(osg::Vec4(1,1,1,1)); 
     133    _diffuse = new osgAnimation::Vec4Target(osg::Vec4(1,0,1,1)); 
    134134} 
    135135