Changeset 11009

Show
Ignore:
Timestamp:
01/27/10 13:24:55 (5 years ago)
Author:
robert
Message:

From Cedric Pinson, "Here a list of changes:
Bone now inherit from MatrixTransform?. It simplify a lot the update of
Bone matrix. It helps to have the bone system more generic. eg it's now
possible to have animation data with precomputed bind matrix. The other
benefit, is now the collada plugin will be able to use osgAnimation to
display skinned mesh. Michael Plating did a great work to improve this
aspect, he is working on the collada plugin and should be able to submit
a new version soon.
The RigGeometry? has been refactored so now it works when you save and
reload RigGeometry? because the source is not touched anymore. The
benefit with this update is that it should be now possible to use a
MorphGeometry? as source for a RigGeometry?.

The bad news is that the format has changed, so i have rebuild osg-data
related to osgAnimation data, updated the blender exporter to export to
the new format.
The fbx plugin could be touched about this commit, i dont compile it so
i can't give more information about it.
The bvh plugin has been updated by Wang rui so this one is fixed with
the new code of osgAnimation.
The examples has been updated to work with the new code too...

The example osg-data/example.osg should be remove, it's an old example
that does not work.

For people using blender the blender exporter up to date is here:
http://hg.plopbyte.net/osgexport2/
it will be merge to http://hg.plopbyte.net/osgexport/ as soon as the
modification will be push in the trunk.
"

Location:
OpenSceneGraph/trunk
Files:
25 added
3 removed
37 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osganimationhardware/osganimationhardware.cpp

    r10923 r11009  
    3030#include <osgAnimation/RigTransformHardware> 
    3131#include <osgAnimation/AnimationManagerBase> 
     32#include <osgAnimation/BoneMapVisitor> 
    3233 
    3334#include <sstream> 
     
    4445struct MyRigTransformHardware : public osgAnimation::RigTransformHardware 
    4546{ 
     47 
     48    void operator()(osgAnimation::RigGeometry& geom) 
     49    { 
     50        if (_needInit) 
     51            if (!init(geom)) 
     52                return; 
     53        computeMatrixPaletteUniform(geom.getMatrixFromSkeletonToGeometry(), geom.getInvMatrixFromSkeletonToGeometry()); 
     54    } 
     55 
    4656    bool init(osgAnimation::RigGeometry& geom) 
    4757    { 
     
    5767        } 
    5868 
    59         osgAnimation::Bone::BoneMap bm = geom.getSkeleton()->getBoneMap(); 
     69        osgAnimation::BoneMapVisitor mapVisitor; 
     70        geom.getSkeleton()->accept(mapVisitor); 
     71        osgAnimation::BoneMap bm = mapVisitor.getBoneMap(); 
    6072 
    6173        if (!createPalette(pos->size(),bm, geom.getVertexInfluenceSet().getVertexToBoneList())) 
     
    137149        } 
    138150 
     151#if 0 
    139152        if (geom.getName() != std::string("BoundingBox")) // we disable compute of bounding box for all geometry except our bounding box 
    140153            geom.setComputeBoundingBoxCallback(new osg::Drawable::ComputeBoundingBoxCallback); 
     154//            geom.setInitialBound(new osg::Drawable::ComputeBoundingBoxCallback); 
     155#endif 
    141156    } 
    142157}; 
  • OpenSceneGraph/trunk/examples/osganimationskinning/osganimationskinning.cpp

    r10697 r11009  
    1919#include <osgViewer/Viewer> 
    2020#include <osgGA/TrackballManipulator> 
     21#include <osgDB/WriteFile> 
    2122#include <osgUtil/SmoothingVisitor> 
    2223#include <osg/io_utils> 
     
    2627#include <osgAnimation/RigGeometry> 
    2728#include <osgAnimation/BasicAnimationManager> 
     29#include <osgAnimation/UpdateMatrixTransform> 
     30#include <osgAnimation/UpdateBone> 
     31#include <osgAnimation/StackedTransform> 
     32#include <osgAnimation/StackedTranslateElement> 
     33#include <osgAnimation/StackedRotateAxisElement> 
    2834 
    2935osg::Geode* createAxis() 
     
    5965osgAnimation::RigGeometry* createTesselatedBox(int nsplit, float size) 
    6066{ 
    61     osgAnimation::RigGeometry* geometry = new osgAnimation::RigGeometry; 
    62  
     67    osgAnimation::RigGeometry* riggeometry = new osgAnimation::RigGeometry; 
     68 
     69    osg::Geometry* geometry = new osg::Geometry; 
    6370    osg::ref_ptr<osg::Vec3Array> vertices (new osg::Vec3Array()); 
    6471    osg::ref_ptr<osg::Vec3Array> colors (new osg::Vec3Array()); 
     
    120127    geometry->addPrimitiveSet(new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, array->size(), &array->front())); 
    121128    geometry->setUseDisplayList( false ); 
    122     return geometry; 
     129    riggeometry->setSourceGeometry(geometry); 
     130    return riggeometry; 
    123131} 
    124132 
     
    164172    skelroot->setDefaultUpdateCallback(); 
    165173    osg::ref_ptr<osgAnimation::Bone> root = new osgAnimation::Bone; 
    166     { 
    167         root->setBindMatrixInBoneSpace(osg::Matrix::identity()); 
    168         root->setBindMatrixInBoneSpace(osg::Matrix::translate(-1,0,0)); 
    169         root->setName("root"); 
    170         root->setDefaultUpdateCallback(); 
    171     } 
     174    root->setInvBindMatrixInSkeletonSpace(osg::Matrix::inverse(osg::Matrix::translate(-1,0,0))); 
     175    root->setName("root"); 
     176    osgAnimation::UpdateBone* pRootUpdate = new osgAnimation::UpdateBone("root"); 
     177    pRootUpdate->getStackedTransforms().push_back(new osgAnimation::StackedTranslateElement("translate",osg::Vec3(-1,0,0))); 
     178    root->setUpdateCallback(pRootUpdate); 
    172179 
    173180    osg::ref_ptr<osgAnimation::Bone> right0 = new osgAnimation::Bone; 
    174     right0->setBindMatrixInBoneSpace(osg::Matrix::translate(1,0,0)); 
     181    right0->setInvBindMatrixInSkeletonSpace(osg::Matrix::inverse(osg::Matrix::translate(0,0,0))); 
    175182    right0->setName("right0"); 
    176     right0->setDefaultUpdateCallback("right0"); 
     183    osgAnimation::UpdateBone* pRight0Update = new osgAnimation::UpdateBone("right0"); 
     184    pRight0Update->getStackedTransforms().push_back(new osgAnimation::StackedTranslateElement("translate", osg::Vec3(1,0,0))); 
     185    pRight0Update->getStackedTransforms().push_back(new osgAnimation::StackedRotateAxisElement("rotate", osg::Vec3(0,0,1), 0)); 
     186    right0->setUpdateCallback(pRight0Update); 
    177187 
    178188    osg::ref_ptr<osgAnimation::Bone> right1 = new osgAnimation::Bone; 
    179     right1->setBindMatrixInBoneSpace(osg::Matrix::translate(1,0,0)); 
     189    right1->setInvBindMatrixInSkeletonSpace(osg::Matrix::inverse(osg::Matrix::translate(1,0,0))); 
    180190    right1->setName("right1"); 
    181     right1->setDefaultUpdateCallback("right1"); 
     191    osgAnimation::UpdateBone* pRight1Update = new osgAnimation::UpdateBone("right1"); 
     192    pRight1Update->getStackedTransforms().push_back(new osgAnimation::StackedTranslateElement("translate", osg::Vec3(1,0,0))); 
     193    pRight1Update->getStackedTransforms().push_back(new osgAnimation::StackedRotateAxisElement("rotate", osg::Vec3(0,0,1), 0)); 
     194    right1->setUpdateCallback(pRight1Update); 
    182195 
    183196    root->addChild(right0.get()); 
     
    191204    osgAnimation::Animation* anim = new osgAnimation::Animation; 
    192205    { 
    193         osgAnimation::QuatKeyframeContainer* keys0 = new osgAnimation::QuatKeyframeContainer; 
    194         osg::Quat rotate; 
    195         rotate.makeRotate(osg::PI_2, osg::Vec3(0,0,1)); 
    196         keys0->push_back(osgAnimation::QuatKeyframe(0,osg::Quat(0,0,0,1))); 
    197         keys0->push_back(osgAnimation::QuatKeyframe(3,rotate)); 
    198         keys0->push_back(osgAnimation::QuatKeyframe(6,rotate)); 
    199         osgAnimation::QuatSphericalLinearSampler* sampler = new osgAnimation::QuatSphericalLinearSampler; 
     206        osgAnimation::FloatKeyframeContainer* keys0 = new osgAnimation::FloatKeyframeContainer; 
     207        keys0->push_back(osgAnimation::FloatKeyframe(0,0)); 
     208        keys0->push_back(osgAnimation::FloatKeyframe(3,osg::PI_2)); 
     209        keys0->push_back(osgAnimation::FloatKeyframe(6,osg::PI_2)); 
     210        osgAnimation::FloatLinearSampler* sampler = new osgAnimation::FloatLinearSampler; 
    200211        sampler->setKeyframeContainer(keys0); 
    201         // osgAnimation::AnimationUpdateCallback* cb = dynamic_cast<osgAnimation::AnimationUpdateCallback*>(right0->getUpdateCallback()); 
    202         osgAnimation::QuatSphericalLinearChannel* channel = new osgAnimation::QuatSphericalLinearChannel(sampler); 
    203         channel->setName("quaternion"); 
     212        osgAnimation::FloatLinearChannel* channel = new osgAnimation::FloatLinearChannel(sampler); 
     213        channel->setName("rotate"); 
    204214        channel->setTargetName("right0"); 
    205215        anim->addChannel(channel); 
     
    207217 
    208218    { 
    209         osgAnimation::QuatKeyframeContainer* keys1 = new osgAnimation::QuatKeyframeContainer; 
    210         osg::Quat rotate; 
    211         rotate.makeRotate(osg::PI_2, osg::Vec3(0,0,1)); 
    212         keys1->push_back(osgAnimation::QuatKeyframe(0,osg::Quat(0,0,0,1))); 
    213         keys1->push_back(osgAnimation::QuatKeyframe(3,osg::Quat(0,0,0,1))); 
    214         keys1->push_back(osgAnimation::QuatKeyframe(6,rotate)); 
    215         osgAnimation::QuatSphericalLinearSampler* sampler = new osgAnimation::QuatSphericalLinearSampler; 
     219        osgAnimation::FloatKeyframeContainer* keys1 = new osgAnimation::FloatKeyframeContainer; 
     220        keys1->push_back(osgAnimation::FloatKeyframe(0,0)); 
     221        keys1->push_back(osgAnimation::FloatKeyframe(3,0)); 
     222        keys1->push_back(osgAnimation::FloatKeyframe(6,osg::PI_2)); 
     223        osgAnimation::FloatLinearSampler* sampler = new osgAnimation::FloatLinearSampler; 
    216224        sampler->setKeyframeContainer(keys1); 
    217         osgAnimation::QuatSphericalLinearChannel* channel = new osgAnimation::QuatSphericalLinearChannel(sampler); 
    218         //osgAnimation::AnimationUpdateCallback* cb = dynamic_cast<osgAnimation::AnimationUpdateCallback*>(right1->getUpdateCallback()); 
    219         channel->setName("quaternion"); 
     225        osgAnimation::FloatLinearChannel* channel = new osgAnimation::FloatLinearChannel(sampler); 
     226        channel->setName("rotate"); 
    220227        channel->setTargetName("right1"); 
    221228        anim->addChannel(channel); 
     
    246253    geode->addDrawable(geom); 
    247254    skelroot->addChild(geode); 
    248     osg::ref_ptr<osg::Vec3Array> src = dynamic_cast<osg::Vec3Array*>(geom->getVertexArray()); 
     255    osg::ref_ptr<osg::Vec3Array> src = dynamic_cast<osg::Vec3Array*>(geom->getSourceGeometry()->getVertexArray()); 
    249256    geom->getOrCreateStateSet()->setMode(GL_LIGHTING, false); 
    250257    geom->setDataVariance(osg::Object::DYNAMIC); 
     
    261268    } 
    262269 
     270    osgDB::writeNodeFile(*scene, "skinning.osg"); 
    263271    return 0; 
    264272} 
  • OpenSceneGraph/trunk/examples/osganimationsolid/osganimationsolid.cpp

    r9459 r11009  
    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   
     
    2323#include <osgAnimation/BasicAnimationManager> 
    2424#include <osgAnimation/Channel> 
    25 #include <osgAnimation/UpdateCallback> 
     25#include <osgAnimation/UpdateMatrixTransform> 
     26#include <osgAnimation/StackedTranslateElement> 
    2627 
    2728using namespace osgAnimation; 
     
    7576    trans->setName("AnimatedNode"); 
    7677    trans->setDataVariance(osg::Object::DYNAMIC); 
    77     trans->setUpdateCallback(new osgAnimation::UpdateTransform("AnimatedCallback")); 
     78    osgAnimation::UpdateMatrixTransform* updatecb = new osgAnimation::UpdateMatrixTransform("AnimatedCallback"); 
     79    updatecb->getStackedTransforms().push_back(new osgAnimation::StackedTranslateElement("position")); 
     80    trans->setUpdateCallback(updatecb); 
    7881    trans->setMatrix(osg::Matrix::identity()); 
    7982    trans->addChild (geode.get()); 
  • OpenSceneGraph/trunk/include/osgAnimation/Bone

    r10561 r11009  
    1717 */ 
    1818 
    19 #ifndef OSGANIMATION_BONE_H 
    20 #define OSGANIMATION_BONE_H 
     19#ifndef OSGANIMATION_BONE 
     20#define OSGANIMATION_BONE 1 
    2121 
    22 #include <osg/Transform> 
    23 #include <osg/Quat> 
    24 #include <osg/Vec3> 
    25 #include <osg/Node> 
    26 #include <osg/Geode> 
    27 #include <osg/Geometry> 
    28 #include <osg/Notify> 
    29 #include <osg/io_utils> 
    30 #include <osg/NodeVisitor> 
     22#include <osg/MatrixTransform> 
    3123#include <osgAnimation/Export> 
    32 #include <osgAnimation/Target> 
    33 #include <osgAnimation/Sampler> 
    34 #include <osgAnimation/Channel> 
    35 #include <osgAnimation/Keyframe> 
    36 #include <osgAnimation/UpdateCallback> 
    37 #include <osgAnimation/Animation> 
    38 #include <osgAnimation/AnimationManagerBase> 
    39 #include <osgAnimation/VertexInfluence> 
    4024 
    4125namespace osgAnimation  
     
    4428    // A bone can't have more than one parent Bone, so sharing a part of Bone's hierarchy 
    4529    // makes no sense. You can share the entire hierarchy but not only a part of it. 
    46     class OSGANIMATION_EXPORT Bone : public osg::Transform 
     30    class OSGANIMATION_EXPORT Bone : public osg::MatrixTransform 
    4731    { 
    4832    public: 
    49         typedef osg::ref_ptr<Bone> PointerType; 
    50         typedef std::map<std::string, PointerType > BoneMap; 
    5133        typedef osg::Matrix MatrixType; 
    5234 
     
    5739        void setDefaultUpdateCallback(const std::string& name = ""); 
    5840 
    59         class OSGANIMATION_EXPORT UpdateBone : public AnimationUpdateCallback <osg::NodeCallback> 
    60         { 
    61         protected: 
    62             osg::ref_ptr<osgAnimation::Vec3Target> _position; 
    63             osg::ref_ptr<osgAnimation::QuatTarget> _quaternion; 
    64             osg::ref_ptr<osgAnimation::Vec3Target> _scale; 
    65      
    66         public: 
    67             META_Object(osgAnimation, UpdateBone); 
    68             UpdateBone(const UpdateBone& apc,const osg::CopyOp& copyop); 
    69  
    70             UpdateBone(const std::string& name = "") : AnimationUpdateCallback <osg::NodeCallback>(name) 
    71             { 
    72                 setName(name); 
    73                 _quaternion = new osgAnimation::QuatTarget; 
    74                 _position = new osgAnimation::Vec3Target; 
    75                 _scale = new osgAnimation::Vec3Target; 
    76             } 
    77  
    78             void update(osgAnimation::Bone& bone) 
    79             { 
    80                 bone.setTranslation(_position->getValue()); 
    81                 bone.setRotation(_quaternion->getValue()); 
    82                 bone.setScale(_scale->getValue()); 
    83                 bone.dirtyBound(); 
    84             } 
    85  
    86             osgAnimation::QuatTarget* getQuaternion() {return _quaternion.get();} 
    87             osgAnimation::Vec3Target* getPosition() {return _position.get();} 
    88             osgAnimation::Vec3Target* getScale() {return _scale.get();} 
    89  
    90             bool needLink() const 
    91             { 
    92                 // the idea is to return true if nothing is linked 
    93                 return !((_position->getCount() + _quaternion->getCount() + _scale->getCount()) > 3); 
    94             } 
    95  
    96             /** Link channel*/ 
    97             bool link(osgAnimation::Channel* channel); 
    98  
    99             /** Callback method called by the NodeVisitor when visiting a node.*/ 
    100             virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); 
    101         }; 
    102  
    103         virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const; 
    104         virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const; 
    105  
    10641        Bone* getBoneParent(); 
    10742        const Bone* getBoneParent() const; 
    10843 
    109         void setTranslation(const osg::Vec3& trans) { _position = trans;} 
    110         void setRotation(const osg::Quat& quat) { _rotation = quat;} 
    111         void setScale(const osg::Vec3& scale) { _scale = scale;} 
    112  
    113         const osg::Vec3& getTranslation() const { return _position;} 
    114         const osg::Quat& getRotation() const { return _rotation;} 
    115         const osg::Vec3& getScale() const { return _scale;} 
    116  
    117         osg::Matrix getMatrixInBoneSpace() const { return (osg::Matrix(getRotation())) * osg::Matrix::translate(getTranslation()) * _bindInBoneSpace;} 
    118         const osg::Matrix& getBindMatrixInBoneSpace() const { return _bindInBoneSpace; } 
     44        const osg::Matrix& getMatrixInBoneSpace() const { return getMatrix();} 
    11945        const osg::Matrix& getMatrixInSkeletonSpace() const { return _boneInSkeletonSpace; } 
    12046        const osg::Matrix& getInvBindMatrixInSkeletonSpace() const { return _invBindInSkeletonSpace;} 
    12147        void setMatrixInSkeletonSpace(const osg::Matrix& matrix) { _boneInSkeletonSpace = matrix; } 
    122         void setBindMatrixInBoneSpace(const osg::Matrix& matrix)  
    123         { 
    124             _bindInBoneSpace = matrix; 
    125             _needToRecomputeBindMatrix = true; 
    126         } 
    127  
    128         inline bool needToComputeBindMatrix() { return _needToRecomputeBindMatrix;} 
    129         virtual void computeBindMatrix(); 
    130  
    131         void setNeedToComputeBindMatrix(bool state) { _needToRecomputeBindMatrix = state; } 
    132  
    133         /** Add Node to Group. 
    134          * If node is not NULL and is not contained in Group then increment its 
    135          * reference count, add it to the child list and dirty the bounding 
    136          * sphere to force it to recompute on next getBound() and return true for success. 
    137          * Otherwise return false. Scene nodes can't be added as child nodes. 
    138          */ 
    139         virtual bool addChild( Node *child ); 
    140         BoneMap getBoneMap(); 
    141  
     48        void setInvBindMatrixInSkeletonSpace(const osg::Matrix& matrix) { _invBindInSkeletonSpace = matrix; } 
    14249 
    14350    protected: 
    14451 
    145         osg::Vec3 _position; 
    146         osg::Quat _rotation; 
    147         osg::Vec3 _scale; 
    148  
    149  
    150         // flag to recompute bind pose 
    151         bool _needToRecomputeBindMatrix; 
    152  
    15352        // bind data 
    154         osg::Matrix _bindInBoneSpace; 
    15553        osg::Matrix _invBindInSkeletonSpace; 
    15654 
    15755        // bone updated 
    15856        osg::Matrix _boneInSkeletonSpace; 
    159      
    16057    }; 
    16158 
    162  
    163     inline bool Bone::computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const 
    164     { 
    165         if (_referenceFrame==RELATIVE_RF)  
    166             matrix.preMult(getMatrixInBoneSpace()); 
    167         else  
    168             matrix = getMatrixInBoneSpace(); 
    169         return true; 
    170     } 
    171  
    172  
    173     inline bool Bone::computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const 
    174     { 
    175         if (_referenceFrame==RELATIVE_RF)  
    176             matrix.postMult(osg::Matrix::inverse(getMatrixInBoneSpace())); 
    177         else 
    178             matrix = osg::Matrix::inverse(getMatrixInBoneSpace()); 
    179         return true; 
    180     } 
    181  
     59    typedef std::map<std::string, osg::ref_ptr<Bone> > BoneMap; 
    18260} 
    18361#endif 
  • OpenSceneGraph/trunk/include/osgAnimation/BoneMapVisitor

    r10562 r11009  
    1616 */ 
    1717 
    18 #ifndef OSGANIMATION_BONEMAP_VISITOR_H 
    19 #define OSGANIMATION_BONEMAP_VISITOR_H 1 
     18#ifndef OSGANIMATION_BONEMAP_VISITOR 
     19#define OSGANIMATION_BONEMAP_VISITOR 1 
    2020 
    2121#include <osgAnimation/Export> 
     
    3333        void apply(osg::Node&); 
    3434        void apply(osg::Transform& node); 
    35         const Bone::BoneMap& getBoneMap() const; 
     35        const BoneMap& getBoneMap() const; 
    3636 
    3737    protected: 
    38         Bone::BoneMap _map; 
     38        BoneMap _map; 
    3939    }; 
    4040} 
  • OpenSceneGraph/trunk/include/osgAnimation/Channel

    r10656 r11009  
    173173    typedef TemplateChannel<Vec4LinearSampler> Vec4LinearChannel; 
    174174    typedef TemplateChannel<QuatSphericalLinearSampler> QuatSphericalLinearChannel; 
     175    typedef TemplateChannel<MatrixLinearSampler> MatrixLinearChannel; 
    175176 
    176177    typedef TemplateChannel<FloatCubicBezierSampler> FloatCubicBezierChannel; 
  • OpenSceneGraph/trunk/include/osgAnimation/CubicBezier

    r10576 r11009  
    1313*/ 
    1414 
    15 #ifndef OSGANIMATION_CUBIC_BEZIER_H 
    16 #define OSGANIMATION_CUBIC_BEZIER_H 
     15#ifndef OSGANIMATION_CUBIC_BEZIER 
     16#define OSGANIMATION_CUBIC_BEZIER 1 
    1717 
    1818#include <osg/Vec2> 
    1919#include <osg/Vec3> 
    2020#include <osg/Vec4> 
    21 #include <osg/Quat> 
    2221 
    2322namespace osgAnimation 
     
    2524 
    2625    template <class T> 
    27     struct TemplateCubicBezier 
     26    class TemplateCubicBezier 
    2827    { 
    29         T mPoint[3]; 
    30         const T& getP0() const { return mPoint[0];} 
    31         const T& getP1() const { return mPoint[1];} 
    32         const T& getP2() const { return mPoint[2];} 
    33         TemplateCubicBezier(const T& v0, const T& v1, const T& v2)  
     28    public: 
     29        TemplateCubicBezier() {} 
     30 
     31        TemplateCubicBezier(const T& p, const T& i, const T& o) : _position(p), _controlPointIn(i), _controlPointOut(o) 
    3432        { 
    35             mPoint[0] = v0; 
    36             mPoint[1] = v1; 
    37             mPoint[2] = v2; 
    38         } 
    39         // Constructor with value only 
    40         TemplateCubicBezier(const T& v0)  
    41         { 
    42             mPoint[0] = v0; 
    43             mPoint[1] = v0; 
    44             mPoint[2] = v0; 
    4533        } 
    4634 
    47         TemplateCubicBezier() {} 
     35        // Constructor with value only 
     36        TemplateCubicBezier(const T& p) : _position(p), _controlPointIn(p), _controlPointOut(p) 
     37        { 
     38        } 
    4839 
    49         const T& getPosition() const { return mPoint[0];} 
    50         const T& getTangentPoint1() const { return mPoint[1];} 
    51         const T& getTangentPoint2() const { return mPoint[2];} 
    52          
     40        const T& getPosition() const { return _position;} 
     41        const T& getControlPointIn() const { return _controlPointIn;} 
     42        const T& getControlPointOut() const { return _controlPointOut;} 
     43 
     44        T& getPosition() { return _position;} 
     45        T& getControlPointIn() { return _controlPointIn;} 
     46        T& getControlPointOut() { return _controlPointOut;} 
     47 
     48        void setPosition(const T& v) {_position = v;} 
     49        void setControlPointIn(const T& v) {_controlPointIn = v;} 
     50        void setControlPointOut(const T& v) {_controlPointOut = v;} 
     51 
    5352        // steaming operators. 
    54         friend std::ostream& operator << (std::ostream& output, const TemplateCubicBezier<T>& vec) 
     53        friend std::ostream& operator << (std::ostream& output, const TemplateCubicBezier<T>& tcb) 
    5554        { 
    56             output << vec.mPoint[0] << " " 
    57                    << vec.mPoint[1] << " " 
    58                    << vec.mPoint[2]; 
     55            output << tcb._position << " " 
     56                   << tcb._controlPointIn << " " 
     57                   << tcb._controlPointOut; 
    5958            return output; // to enable cascading 
    6059        } 
    6160 
    62         friend std::istream& operator >> (std::istream& input, TemplateCubicBezier<T>& vec) 
     61        friend std::istream& operator >> (std::istream& input, TemplateCubicBezier<T>& tcb) 
    6362        { 
    64             input >> vec.mPoint[0] >> vec.mPoint[1] >> vec.mPoint[2]; 
     63            input >> tcb._position >> tcb._controlPointIn >> tcb._controlPointOut; 
    6564            return input; 
    6665        } 
     66 
     67    protected: 
     68        T _position, _controlPointIn, _controlPointOut; 
    6769    }; 
    68  
    6970 
    7071    typedef TemplateCubicBezier<float> FloatCubicBezier; 
  • OpenSceneGraph/trunk/include/osgAnimation/EaseMotion

    r9981 r11009  
    314314                return; 
    315315            } 
    316             for (MotionList::const_iterator it = _motions.begin(); it != _motions.end(); it++) 
     316            for (MotionList::const_iterator it = _motions.begin(); it != _motions.end(); ++it) 
    317317            { 
    318318                const Motion* motion = static_cast<const Motion*>(it->get()); 
  • OpenSceneGraph/trunk/include/osgAnimation/Interpolator

    r10877 r11009  
    206206 
    207207            TYPE v0 = keyframes[i].getValue().getPosition() * one_minus_t3; 
    208             TYPE v1 = keyframes[i].getValue().getTangentPoint1() * (3.0 * t * one_minus_t2); 
    209             TYPE v2 = keyframes[i].getValue().getTangentPoint2() * (3.0 * t2 * one_minus_t); 
     208            TYPE v1 = keyframes[i].getValue().getControlPointIn() * (3.0 * t * one_minus_t2); 
     209            TYPE v2 = keyframes[i].getValue().getControlPointOut() * (3.0 * t2 * one_minus_t); 
    210210            TYPE v3 = keyframes[i+1].getValue().getPosition() * (t2 * t); 
    211211 
     
    229229    typedef TemplateLinearInterpolator<osg::Vec4, osg::Vec4> Vec4LinearInterpolator; 
    230230    typedef TemplateSphericalLinearInterpolator<osg::Quat, osg::Quat> QuatSphericalLinearInterpolator; 
     231    typedef TemplateLinearInterpolator<osg::Matrixf, osg::Matrixf> MatrixLinearInterpolator; 
    231232 
    232233    typedef TemplateCubicBezierInterpolator<float, FloatCubicBezier > FloatCubicBezierInterpolator; 
  • OpenSceneGraph/trunk/include/osgAnimation/Keyframe

    r9877 r11009  
    2424#include <osg/Vec3> 
    2525#include <osg/Vec2> 
     26#include <osg/Matrixf> 
    2627 
    2728namespace osgAnimation  
     
    115116    typedef TemplateKeyframeContainer<osg::Quat> QuatKeyframeContainer; 
    116117 
     118    typedef TemplateKeyframe<osg::Matrixf> MatrixKeyframe; 
     119    typedef TemplateKeyframeContainer<osg::Matrixf> MatrixKeyframeContainer; 
     120 
    117121    typedef TemplateKeyframe<Vec3Packed> Vec3PackedKeyframe; 
    118122    typedef TemplateKeyframeContainer<Vec3Packed> Vec3PackedKeyframeContainer; 
  • OpenSceneGraph/trunk/include/osgAnimation/MorphGeometry

    r10518 r11009  
    1717 
    1818#include <osgAnimation/Export> 
     19#include <osgAnimation/AnimationUpdateCallback> 
    1920#include <osg/Geometry> 
    20 #include <osgAnimation/UpdateCallback> 
    2121 
    2222namespace osgAnimation  
  • OpenSceneGraph/trunk/include/osgAnimation/RigGeometry

    r10693 r11009  
    1919#include <osgAnimation/Skeleton> 
    2020#include <osgAnimation/RigTransform> 
     21#include <osgAnimation/VertexInfluence> 
    2122#include <osg/Geometry> 
    2223 
     
    2930 
    3031        RigGeometry(); 
    31         RigGeometry(const osg::Geometry& b); 
     32//        RigGeometry(const osg::Geometry& b); 
    3233        RigGeometry(const RigGeometry& b, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY); 
    3334 
     
    6465        const osg::Matrix& getInvMatrixFromSkeletonToGeometry() const; 
    6566 
     67        osg::Geometry* getSourceGeometry(); 
     68        const osg::Geometry* getSourceGeometry() const; 
     69        void setSourceGeometry(osg::Geometry* geometry); 
     70 
     71        void copyFrom(osg::Geometry& from); 
     72 
    6673    protected: 
    67  
     74         
     75        osg::ref_ptr<osg::Geometry> _geometry; 
    6876        osg::ref_ptr<RigTransform> _rigTransformImplementation; 
    6977 
     
    105113 
    106114                    if (!finder._root.valid()) 
     115                    { 
     116                        osg::notify(osg::WARN) << "A RigGeometry did not find a parent skeleton for RigGeomtry ( " << geom->getName() << " )" << std::endl; 
    107117                        return; 
     118                    } 
    108119                    geom->buildVertexInfluenceSet(); 
    109120                    geom->setSkeleton(finder._root.get()); 
  • OpenSceneGraph/trunk/include/osgAnimation/RigTransform

    r10693 r11009  
    1313*/ 
    1414 
    15 #ifndef OSGANIMATION_RIGTRANSFORM_H 
    16 #define OSGANIMATION_RIGTRANSFORM_H 
     15#ifndef OSGANIMATION_RIGTRANSFORM 
     16#define OSGANIMATION_RIGTRANSFORM 1 
    1717 
    1818#include <osg/Referenced> 
     
    2626    { 
    2727    public: 
    28         RigTransform() : _needInit(true) {} 
     28        RigTransform() {} 
    2929        virtual ~RigTransform() {} 
    30         bool needInit() const { return _needInit; } 
    31         virtual bool init(RigGeometry&) = 0; 
    32         virtual void update(RigGeometry&) = 0; 
     30        virtual void operator()(RigGeometry& geometry) {} 
    3331 
    34     protected: 
    35         bool _needInit; 
    3632    }; 
    3733 
  • OpenSceneGraph/trunk/include/osgAnimation/RigTransformHardware

    r10918 r11009  
    1313 */ 
    1414 
    15 #ifndef OSGANIMATION_RIG_TRANSFORM_HARDWARE_H 
    16 #define OSGANIMATION_RIG_TRANSFORM_HARDWARE_H 1 
     15#ifndef OSGANIMATION_RIG_TRANSFORM_HARDWARE 
     16#define OSGANIMATION_RIG_TRANSFORM_HARDWARE 1 
    1717 
    1818#include <osgAnimation/Export> 
     
    3333        typedef osg::Matrix MatrixType; 
    3434        typedef osgAnimation::Bone BoneType; 
    35         typedef Bone::BoneMap BoneMap; 
    3635        typedef std::vector<osg::ref_ptr<osg::Vec4Array> > BoneWeightAttribList; 
    3736        typedef std::vector<osg::ref_ptr<BoneType> > BonePalette; 
     
    4948        typedef std::vector<std::vector<IndexWeightEntry> > VertexIndexWeightList; 
    5049 
     50        RigTransformHardware(); 
     51 
    5152        osg::Vec4Array* getVertexAttrib(int index); 
    5253        int getNumVertexAttrib(); 
     
    6061        bool createPalette(int nbVertexes, BoneMap boneMap, const VertexInfluenceSet::VertexIndexToBoneWeightMap& vertexIndexToBoneWeightMap); 
    6162 
     63        virtual void operator()(RigGeometry&); 
     64        void setShader(osg::Shader*); 
    6265 
    63         virtual bool init(RigGeometry&); 
    64         virtual void update(RigGeometry&); 
     66    protected: 
    6567 
    66         void setShader(osg::Shader*); 
    67     protected: 
     68        bool init(RigGeometry&); 
    6869 
    6970        BoneWeightAttribList createVertexAttribList(); 
     
    7778        osg::ref_ptr<osg::Uniform> _uniformMatrixPalette; 
    7879        osg::ref_ptr<osg::Shader> _shader; 
     80 
     81        bool _needInit; 
    7982    }; 
    8083} 
  • OpenSceneGraph/trunk/include/osgAnimation/RigTransformSoftware

    r10877 r11009  
    1313 */ 
    1414 
    15 #ifndef OSGANIMATION_RIG_TRANSFORM_SOFTWARE_H 
    16 #define OSGANIMATION_RIG_TRANSFORM_SOFTWARE_H 1 
     15#ifndef OSGANIMATION_RIGTRANSFORM_SOFTWARE 
     16#define OSGANIMATION_RIGTRANSFORM_SOFTWARE 1 
    1717 
    1818#include <osgAnimation/Export> 
    1919#include <osgAnimation/RigTransform> 
    2020#include <osgAnimation/Bone> 
     21#include <osgAnimation/VertexInfluence> 
     22#include <osg/observer_ptr> 
    2123 
    2224namespace osgAnimation  
     
    3032    public: 
    3133 
    32         virtual bool init(RigGeometry&); 
    33         virtual void update(RigGeometry&); 
     34        RigTransformSoftware(); 
     35        virtual void operator()(RigGeometry&); 
    3436     
    3537 
     
    157159        } 
    158160 
    159         const std::vector<osg::Vec3>& getPositionSource() const { return _positionSource;} 
    160         const std::vector<osg::Vec3>& getNormalSource() const { return _normalSource;} 
    161  
    162161    protected: 
    163162 
    164         void initVertexSetFromBones(const Bone::BoneMap& map, const VertexInfluenceSet::UniqVertexSetToBoneSetList& influence); 
     163        bool init(RigGeometry&); 
     164        void initVertexSetFromBones(const BoneMap& map, const VertexInfluenceSet::UniqVertexSetToBoneSetList& influence); 
     165        std::vector<UniqBoneSetVertexSet> _boneSetVertexSet; 
    165166 
    166         std::vector<UniqBoneSetVertexSet> _boneSetVertexSet; 
    167         std::vector<osg::Vec3> _positionSource; 
    168         std::vector<osg::Vec3> _normalSource; 
     167        bool _needInit; 
    169168 
    170169    }; 
  • OpenSceneGraph/trunk/include/osgAnimation/Sampler

    r10527 r11009  
    126126    typedef TemplateSampler<Vec4LinearInterpolator> Vec4LinearSampler; 
    127127    typedef TemplateSampler<QuatSphericalLinearInterpolator> QuatSphericalLinearSampler; 
     128    typedef TemplateSampler<MatrixLinearInterpolator> MatrixLinearSampler; 
    128129 
    129130    typedef TemplateSampler<FloatCubicBezierInterpolator> FloatCubicBezierSampler; 
  • OpenSceneGraph/trunk/include/osgAnimation/Skeleton

    r10751 r11009  
    1717 
    1818#include <osgAnimation/Export> 
    19 #include <osgAnimation/Bone> 
     19#include <osg/MatrixTransform> 
    2020 
    2121namespace osgAnimation  
    2222{ 
    2323 
    24     class OSGANIMATION_EXPORT Skeleton : public Bone 
     24    class OSGANIMATION_EXPORT Skeleton : public osg::MatrixTransform 
    2525    { 
    2626    public: 
     
    4141        Skeleton(); 
    4242        Skeleton(const Skeleton&, const osg::CopyOp&); 
     43        void setDefaultUpdateCallback(); 
    4344 
    44         void setDefaultUpdateCallback(); 
    45         void computeBindMatrix(); 
    4645    }; 
    4746 
  • OpenSceneGraph/trunk/include/osgAnimation/Target

    r10599 r11009  
    122122    } 
    123123 
     124    typedef TemplateTarget<osg::Matrixf> MatrixTarget; 
    124125    typedef TemplateTarget<osg::Quat> QuatTarget; 
    125126    typedef TemplateTarget<osg::Vec3> Vec3Target; 
  • OpenSceneGraph/trunk/src/osgAnimation/Action.cpp

    r10693 r11009  
    3737{ 
    3838    std::vector<unsigned int> keyToRemove; 
    39     for (FrameCallback::iterator it = _framesCallback.begin(); it != _framesCallback.end(); it++)  
     39    for (FrameCallback::iterator it = _framesCallback.begin(); it != _framesCallback.end(); ++it)  
    4040    { 
    4141        if (it->second.get()) 
     
    5353        } 
    5454    } 
    55     for (std::vector<unsigned int>::iterator it = keyToRemove.begin(); it != keyToRemove.end(); it++) 
     55    for (std::vector<unsigned int>::iterator it = keyToRemove.begin(); it != keyToRemove.end(); ++it) 
    5656        _framesCallback.erase(*it); 
    5757} 
  • OpenSceneGraph/trunk/src/osgAnimation/Animation.cpp

    r10656 r11009  
    2525{ 
    2626    const ChannelList& cl = anim.getChannels(); 
    27     for (ChannelList::const_iterator it = cl.begin(); it != cl.end(); it++) 
     27    for (ChannelList::const_iterator it = cl.begin(); it != cl.end(); ++it) 
    2828    { 
    2929        addChannel(it->get()->clone()); 
  • OpenSceneGraph/trunk/src/osgAnimation/AnimationManagerBase.cpp

    r10656 r11009  
    2929void AnimationManagerBase::clearTargets() 
    3030{ 
    31     for (TargetSet::iterator it = _targets.begin(); it != _targets.end(); it++) 
     31    for (TargetSet::iterator it = _targets.begin(); it != _targets.end(); ++it) 
    3232        (*it).get()->reset(); 
    3333} 
     
    6868    for (AnimationList::const_iterator it = animationList.begin(); 
    6969         it != animationList.end(); 
    70          it++) 
     70         ++it) 
    7171    { 
    7272        Animation* animation = dynamic_cast<osgAnimation::Animation*>(it->get()->clone(copyop)); 
     
    8686        for (ChannelList::iterator it = anim->getChannels().begin(); 
    8787             it != anim->getChannels().end(); 
    88              it++) 
     88             ++it) 
    8989            _targets.insert((*it)->getTarget()); 
    9090    } 
  • OpenSceneGraph/trunk/src/osgAnimation/BasicAnimationManager.cpp

    r10576 r11009  
    3939    { 
    4040        AnimationList& list = iterAnim->second; 
    41         for (AnimationList::iterator it = list.begin(); it != list.end(); it++) 
     41        for (AnimationList::iterator it = list.begin(); it != list.end(); ++it) 
    4242            (*it)->resetTargets(); 
    4343    } 
     
    6666    { 
    6767        AnimationList& list = iterAnim->second; 
    68         for (AnimationList::iterator it = list.begin(); it != list.end(); it++) 
     68        for (AnimationList::iterator it = list.begin(); it != list.end(); ++it) 
    6969            if( (*it) == pAnimation ) 
    7070            { 
     
    8383 
    8484    // could filtered with an active flag 
    85     for (TargetSet::iterator it = _targets.begin(); it != _targets.end(); it++) 
     85    for (TargetSet::iterator it = _targets.begin(); it != _targets.end(); ++it) 
    8686        (*it).get()->reset(); 
    8787 
     
    133133    { 
    134134        AnimationList& list = iterAnim->second; 
    135         for (AnimationList::iterator it = list.begin(); it != list.end(); it++) 
     135        for (AnimationList::iterator it = list.begin(); it != list.end(); ++it) 
    136136            if ( (*it) == pAnimation ) 
    137137                return true; 
     
    146146    { 
    147147        AnimationList& list = iterAnim->second; 
    148         for (AnimationList::iterator it = list.begin(); it != list.end(); it++) 
     148        for (AnimationList::iterator it = list.begin(); it != list.end(); ++it) 
    149149            if ( (*it)->getName() == name ) 
    150150                return true; 
  • OpenSceneGraph/trunk/src/osgAnimation/Bone.cpp

    r10693 r11009  
    1515#include <osgAnimation/Bone> 
    1616#include <osgAnimation/Skeleton> 
    17 #include <osgAnimation/FindParentAnimationManagerVisitor> 
     17#include <osgAnimation/UpdateBone> 
    1818#include <osgAnimation/BoneMapVisitor> 
    19 #include <osgAnimation/ComputeBindMatrixVisitor> 
    2019 
     20using namespace osgAnimation; 
    2121 
    22 osgAnimation::Bone::UpdateBone::UpdateBone(const osgAnimation::Bone::UpdateBone& apc,const osg::CopyOp& copyop) : 
    23     osg::Object(apc, copyop), 
    24     osgAnimation::AnimationUpdateCallback<osg::NodeCallback>(apc, copyop) 
     22Bone::Bone(const Bone& b, const osg::CopyOp& copyop) : osg::MatrixTransform(b,copyop), _invBindInSkeletonSpace(b._invBindInSkeletonSpace), _boneInSkeletonSpace(b._boneInSkeletonSpace) 
    2523{ 
    26     _quaternion = new osgAnimation::QuatTarget(apc._quaternion->getValue()); 
    27     _position = new osgAnimation::Vec3Target(apc._position->getValue()); 
    28     _scale = new osgAnimation::Vec3Target(apc._scale->getValue()); 
    2924} 
    3025 
    31 bool osgAnimation::Bone::UpdateBone::link(osgAnimation::Channel* channel) 
     26Bone::Bone(const std::string& name) 
    3227{ 
    33     if (channel->getName().find("quaternion") != std::string::npos) 
    34     { 
    35         return channel->setTarget(_quaternion.get()); 
    36     } 
    37     else if (channel->getName().find("position") != std::string::npos) 
    38     { 
    39         return channel->setTarget(_position.get()); 
    40     } 
    41     else if (channel->getName().find("scale") != std::string::npos) 
    42     { 
    43         return channel->setTarget(_scale.get()); 
    44     } 
    45     else  
    46     { 
    47         osg::notify(osg::WARN) << "Channel " << channel->getName() << " does not contain a valid symbolic name for this class" << className() << std::endl; 
    48     } 
    49     return false; 
     28    if (!name.empty()) 
     29        setName(name); 
    5030} 
    5131 
    5232 
    53 /** Callback method called by the NodeVisitor when visiting a node.*/ 
    54 void osgAnimation::Bone::UpdateBone::operator()(osg::Node* node, osg::NodeVisitor* nv) 
    55 { 
    56     if (nv && nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR) 
    57     { 
    58         Bone* b = dynamic_cast<Bone*>(node); 
    59         if (!b) 
    60         { 
    61             osg::notify(osg::WARN) << "Warning: UpdateBone set on non-Bone object." << std::endl; 
    62             return; 
    63         } 
    64  
    65         if (b->needToComputeBindMatrix()) 
    66         { 
    67             ComputeBindMatrixVisitor visitor; 
    68             b->accept(visitor); 
    69         } 
    70  
    71         update(*b); 
    72  
    73         Bone* parent = b->getBoneParent(); 
    74         if (parent) 
    75             b->setMatrixInSkeletonSpace(b->getMatrixInBoneSpace() * parent->getMatrixInSkeletonSpace()); 
    76         else 
    77             b->setMatrixInSkeletonSpace(b->getMatrixInBoneSpace()); 
    78  
    79     } 
    80     traverse(node,nv); 
    81 } 
    82  
    83  
    84 osgAnimation::Bone::Bone(const Bone& b, const osg::CopyOp& copyop) : 
    85     osg::Transform(b,copyop), 
    86     _position(b._position), 
    87     _rotation(b._rotation), 
    88     _scale(b._scale), 
    89     _needToRecomputeBindMatrix(true), 
    90     _bindInBoneSpace(b._bindInBoneSpace), 
    91     _invBindInSkeletonSpace(b._invBindInSkeletonSpace), 
    92     _boneInSkeletonSpace(b._boneInSkeletonSpace) 
    93 { 
    94 } 
    95  
    96 osgAnimation::Bone::Bone(const std::string& name) 
    97 { 
    98     if (!name.empty()) 
    99         setName(name); 
    100     _needToRecomputeBindMatrix = false; 
    101 } 
    102  
    103  
    104 void osgAnimation::Bone::setDefaultUpdateCallback(const std::string& name) 
     33void Bone::setDefaultUpdateCallback(const std::string& name) 
    10534{ 
    10635    std::string cbName = name; 
     
    11039} 
    11140 
    112 void osgAnimation::Bone::computeBindMatrix() 
    113 { 
    114     _invBindInSkeletonSpace = osg::Matrix::inverse(_bindInBoneSpace); 
    115     const Bone* parent = getBoneParent(); 
    116     _needToRecomputeBindMatrix = false; 
    117     if (!parent) 
    118     { 
    119         osg::notify(osg::WARN) << "Warning " << className() <<"::computeBindMatrix you should not have this message, it means you miss to attach this bone(" << getName() <<") to a Skeleton node" << std::endl; 
    120         return; 
    121     } 
    122     _invBindInSkeletonSpace = parent->getInvBindMatrixInSkeletonSpace() * _invBindInSkeletonSpace; 
    123 } 
    124  
    125 osgAnimation::Bone* osgAnimation::Bone::getBoneParent() 
     41Bone* Bone::getBoneParent() 
    12642{ 
    12743    if (getParents().empty()) 
    12844        return 0; 
    12945    osg::Node::ParentList parents = getParents(); 
    130     for (osg::Node::ParentList::iterator it = parents.begin(); it != parents.end(); it++)  
     46    for (osg::Node::ParentList::iterator it = parents.begin(); it != parents.end(); ++it) 
    13147    { 
    13248        Bone* pb = dynamic_cast<Bone*>(*it); 
     
    13652    return 0; 
    13753} 
    138 const osgAnimation::Bone* osgAnimation::Bone::getBoneParent() const 
     54const Bone* Bone::getBoneParent() const 
    13955{ 
    14056    if (getParents().empty()) 
    14157        return 0; 
    14258    const osg::Node::ParentList& parents = getParents(); 
    143     for (osg::Node::ParentList::const_iterator it = parents.begin(); it != parents.end(); it++)  
     59    for (osg::Node::ParentList::const_iterator it = parents.begin(); it != parents.end(); ++it)  
    14460    { 
    14561        const Bone* pb = dynamic_cast<const Bone*>(*it); 
     
    14965    return 0; 
    15066} 
    151  
    152  
    153 /** Add Node to Group. 
    154  * If node is not NULL and is not contained in Group then increment its 
    155  * reference count, add it to the child list and dirty the bounding 
    156  * sphere to force it to recompute on next getBound() and return true for success. 
    157  * Otherwise return false. Scene nodes can't be added as child nodes. 
    158  */ 
    159 bool osgAnimation::Bone::addChild( Node *child )  
    160 { 
    161     Bone* bone = dynamic_cast<Bone*>(child); 
    162     if (bone) 
    163         bone->setNeedToComputeBindMatrix(true); 
    164     return osg::Group::addChild(child); 
    165 } 
    166  
    167 osgAnimation::Bone::BoneMap osgAnimation::Bone::getBoneMap() 
    168 { 
    169     BoneMapVisitor mapVisitor; 
    170     this->accept(mapVisitor); 
    171     return mapVisitor.getBoneMap(); 
    172 } 
  • OpenSceneGraph/trunk/src/osgAnimation/BoneMapVisitor.cpp

    r10562 r11009  
    1717 
    1818#include <osgAnimation/BoneMapVisitor> 
     19#include <osgAnimation/Skeleton> 
    1920 
    20 osgAnimation::BoneMapVisitor::BoneMapVisitor() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} 
     21using namespace osgAnimation; 
    2122 
    22 void osgAnimation::BoneMapVisitor::apply(osg::Node&) { return; } 
    23 void osgAnimation::BoneMapVisitor::apply(osg::Transform& node) 
     23BoneMapVisitor::BoneMapVisitor() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} 
     24 
     25void BoneMapVisitor::apply(osg::Node&) { return; } 
     26void BoneMapVisitor::apply(osg::Transform& node) 
    2427{ 
    2528    Bone* bone = dynamic_cast<Bone*>(&node); 
    26     if (bone)  
     29    if (bone) 
    2730    { 
    2831        _map[bone->getName()] = bone; 
    2932        traverse(node); 
    3033    } 
     34    Skeleton* skeleton = dynamic_cast<Skeleton*>(&node); 
     35    if (skeleton) 
     36        traverse(node); 
    3137} 
    32 const osgAnimation::Bone::BoneMap& osgAnimation::BoneMapVisitor::getBoneMap() const 
     38 
     39const BoneMap& BoneMapVisitor::getBoneMap() const 
    3340{ 
    3441    return _map; 
  • OpenSceneGraph/trunk/src/osgAnimation/CMakeLists.txt

    r10693 r11009  
    2020    ${HEADER_PATH}/Animation 
    2121    ${HEADER_PATH}/AnimationManagerBase 
     22    ${HEADER_PATH}/AnimationUpdateCallback 
    2223    ${HEADER_PATH}/Assert 
    2324    ${HEADER_PATH}/BasicAnimationManager 
     
    2627    ${HEADER_PATH}/Channel 
    2728    ${HEADER_PATH}/CubicBezier 
    28     ${HEADER_PATH}/ComputeBindMatrixVisitor 
    2929    ${HEADER_PATH}/EaseMotion 
    3030    ${HEADER_PATH}/Export 
     
    4141    ${HEADER_PATH}/Sampler 
    4242    ${HEADER_PATH}/Skeleton 
     43    ${HEADER_PATH}/StackedMatrixElement 
     44    ${HEADER_PATH}/StackedQuaternionElement 
     45    ${HEADER_PATH}/StackedRotateAxisElement 
     46    ${HEADER_PATH}/StackedScaleElement 
     47    ${HEADER_PATH}/StackedTransformElement 
     48    ${HEADER_PATH}/StackedTranslateElement 
     49    ${HEADER_PATH}/StackedTransform 
    4350    ${HEADER_PATH}/StatsVisitor 
    4451    ${HEADER_PATH}/StatsHandler 
     
    4653    ${HEADER_PATH}/Timeline 
    4754    ${HEADER_PATH}/TimelineAnimationManager 
    48     ${HEADER_PATH}/UpdateCallback 
     55    ${HEADER_PATH}/UpdateBone 
     56    ${HEADER_PATH}/UpdateMaterial 
     57    ${HEADER_PATH}/UpdateMatrixTransform 
    4958    ${HEADER_PATH}/Vec3Packed 
    5059    ${HEADER_PATH}/VertexInfluence 
     
    7584    RigTransformSoftware.cpp 
    7685    Skeleton.cpp 
     86    StackedMatrixElement.cpp 
     87    StackedQuaternionElement.cpp 
     88    StackedRotateAxisElement.cpp 
     89    StackedScaleElement.cpp 
     90    StackedTransform.cpp 
     91    StackedTranslateElement.cpp 
    7792    StatsVisitor.cpp 
    7893    StatsHandler.cpp 
     
    8095    TimelineAnimationManager.cpp 
    8196    Timeline.cpp 
    82     UpdateCallback.cpp 
     97    UpdateBone.cpp 
     98    UpdateMaterial.cpp 
     99    UpdateMatrixTransform.cpp 
    83100    VertexInfluence.cpp 
    84101    ${OPENSCENEGRAPH_VERSIONINFO_RC} 
  • OpenSceneGraph/trunk/src/osgAnimation/LinkVisitor.cpp

    r10518 r11009  
    1414 
    1515#include <osgAnimation/LinkVisitor> 
    16 #include <osgAnimation/UpdateCallback> 
     16#include <osgAnimation/AnimationUpdateCallback> 
    1717#include <osg/Notify> 
    1818#include <osg/Geode> 
     
    3434    return _animations; 
    3535} 
    36 void LinkVisitor::link(osgAnimation::AnimationUpdateCallbackBase* cb) 
     36void LinkVisitor::link(AnimationUpdateCallbackBase* cb) 
    3737{ 
    3838    int result = 0; 
     
    5050        return; 
    5151    osg::StateSet::AttributeList& attr = stateset->getAttributeList(); 
    52     for (osg::StateSet::AttributeList::iterator it = attr.begin(); it != attr.end(); it++) 
     52    for (osg::StateSet::AttributeList::iterator it = attr.begin(); it != attr.end(); ++it) 
    5353    { 
    5454        osg::StateAttribute* sattr = it->second.first.get(); 
  • OpenSceneGraph/trunk/src/osgAnimation/MorphGeometry.cpp

    r10599 r11009  
    262262    if (weightIndex >= 0) 
    263263    { 
    264         osgAnimation::FloatLinearChannel* fc = dynamic_cast<osgAnimation::FloatLinearChannel*>(channel); 
    265         if (fc) 
    266         { 
    267             osgAnimation::FloatTarget* ft = _weightTargets[weightIndex].get(); 
    268             if (ft == 0) 
    269             { 
    270                 ft = new osgAnimation::FloatTarget; 
    271                 _weightTargets[weightIndex] = ft; 
    272             } 
    273             fc->setTarget(ft); 
    274             return true; 
    275         } 
     264        osgAnimation::FloatTarget* ft = _weightTargets[weightIndex].get(); 
     265        if (!ft) 
     266        { 
     267            ft = new osgAnimation::FloatTarget; 
     268            _weightTargets[weightIndex] = ft; 
     269        } 
     270        return channel->setTarget(ft); 
    276271    } 
    277272    else 
  • OpenSceneGraph/trunk/src/osgAnimation/RigGeometry.cpp

    r10877 r11009  
    1313 */ 
    1414 
     15#include <osgAnimation/VertexInfluence> 
    1516#include <osgAnimation/RigGeometry> 
    1617#include <osgAnimation/RigTransformSoftware> 
     
    7273} 
    7374 
    74 RigGeometry::RigGeometry(const osg::Geometry& b) : osg::Geometry(b, osg::CopyOp::SHALLOW_COPY) 
    75 { 
    76     _supportsDisplayList = false; 
    77     setUseVertexBufferObjects(true); 
    78     setUpdateCallback(new UpdateVertex); 
    79     setDataVariance(osg::Object::DYNAMIC); 
    80     _needToComputeMatrix = true; 
    81     _matrixFromSkeletonToGeometry = _invMatrixFromSkeletonToGeometry = osg::Matrix::identity(); 
    82  
    83     // disable the computation of boundingbox for the rig mesh 
    84     setComputeBoundingBoxCallback(new RigComputeBoundingBoxCallback); 
    85 } 
    8675 
    8776RigGeometry::RigGeometry(const RigGeometry& b, const osg::CopyOp& copyop) : 
    8877    osg::Geometry(b,copyop), 
     78    _geometry(b._geometry), 
    8979    _vertexInfluenceSet(b._vertexInfluenceSet), 
    9080    _vertexInfluenceMap(b._vertexInfluenceMap), 
     
    115105    for (osgAnimation::VertexInfluenceMap::iterator it = _vertexInfluenceMap->begin();  
    116106         it != _vertexInfluenceMap->end();  
    117          it++) 
     107         ++it) 
    118108        _vertexInfluenceSet.addVertexInfluence(it->second); 
    119109 
     
    131121    } 
    132122    osg::MatrixList mtxList = getParent(0)->getWorldMatrices(_root.get()); 
    133     _matrixFromSkeletonToGeometry = mtxList[0]; 
     123    osg::Matrix notRoot = _root->getMatrix(); 
     124    _matrixFromSkeletonToGeometry = mtxList[0] * osg::Matrix::inverse(notRoot); 
    134125    _invMatrixFromSkeletonToGeometry = osg::Matrix::inverse(_matrixFromSkeletonToGeometry); 
    135126    _needToComputeMatrix = false; 
     
    143134    } 
    144135 
    145     if (getRigTransformImplementation()->needInit()) 
    146         if (!getRigTransformImplementation()->init(*this)) 
    147             return; 
    148     getRigTransformImplementation()->update(*this); 
     136    RigTransform& implementation = *getRigTransformImplementation(); 
     137    (implementation)(*this); 
     138} 
     139 
     140void RigGeometry::copyFrom(osg::Geometry& from) 
     141{ 
     142    bool copyToSelf = (this==&from); 
     143 
     144    osg::Geometry& target = *this; 
     145 
     146    if (!copyToSelf) target.setStateSet(from.getStateSet()); 
     147 
     148    // copy over primitive sets. 
     149    if (!copyToSelf) target.getPrimitiveSetList() = from.getPrimitiveSetList(); 
     150 
     151    if (from.getVertexArray()) 
     152    { 
     153        if (!copyToSelf) target.setVertexArray(from.getVertexArray()); 
     154    } 
     155 
     156    target.setNormalBinding(from.getNormalBinding()); 
     157    if (from.getNormalArray()) 
     158    { 
     159        if (!copyToSelf) target.setNormalArray(from.getNormalArray()); 
     160    } 
     161 
     162    target.setColorBinding(from.getColorBinding()); 
     163    if (from.getColorArray()) 
     164    { 
     165        if (!copyToSelf) target.setColorArray(from.getColorArray()); 
     166    } 
     167 
     168    target.setSecondaryColorBinding(from.getSecondaryColorBinding()); 
     169    if (from.getSecondaryColorArray()) 
     170    { 
     171        if (!copyToSelf) target.setSecondaryColorArray(from.getSecondaryColorArray()); 
     172    } 
     173 
     174    target.setFogCoordBinding(from.getFogCoordBinding()); 
     175    if (from.getFogCoordArray()) 
     176    { 
     177        if (!copyToSelf) target.setFogCoordArray(from.getFogCoordArray()); 
     178    } 
     179 
     180    for(unsigned int ti=0;ti<from.getNumTexCoordArrays();++ti) 
     181    { 
     182        if (from.getTexCoordArray(ti))  
     183        { 
     184            if (!copyToSelf) target.setTexCoordArray(ti,from.getTexCoordArray(ti)); 
     185        } 
     186    } 
     187     
     188    ArrayDataList& arrayList = from.getVertexAttribArrayList(); 
     189    for(unsigned int vi=0;vi< arrayList.size();++vi) 
     190    { 
     191        ArrayData& arrayData = arrayList[vi]; 
     192        if (arrayData.array.valid()) 
     193        { 
     194            if (!copyToSelf) target.setVertexAttribData(vi,arrayData); 
     195        } 
     196    } 
    149197} 
    150198 
     
    156204RigTransform* RigGeometry::getRigTransformImplementation() { return _rigTransformImplementation.get(); } 
    157205void RigGeometry::setRigTransformImplementation(RigTransform* rig) { _rigTransformImplementation = rig; } 
     206 
     207osg::Geometry* RigGeometry::getSourceGeometry() { return _geometry.get(); } 
     208const osg::Geometry* RigGeometry::getSourceGeometry() const { return _geometry.get(); } 
     209void RigGeometry::setSourceGeometry(osg::Geometry* geometry) { _geometry = geometry; } 
  • OpenSceneGraph/trunk/src/osgAnimation/RigTransformHardware.cpp

    r10693 r11009  
    1515#include <osgAnimation/RigTransformHardware> 
    1616#include <osgAnimation/RigGeometry> 
     17#include <osgAnimation/BoneMapVisitor> 
    1718#include <sstream> 
    1819 
    1920using namespace osgAnimation; 
     21 
     22 
     23RigTransformHardware::RigTransformHardware() 
     24{ 
     25    _needInit = true; 
     26    _bonesPerVertex = 0; 
     27    _nbVertexes = 0; 
     28} 
    2029 
    2130osg::Vec4Array* RigTransformHardware::getVertexAttrib(int index) 
     
    6877 
    6978    int maxBonePerVertex = 0; 
    70     for (VertexInfluenceSet::VertexIndexToBoneWeightMap::const_iterator it = vertexIndexToBoneWeightMap.begin(); it != vertexIndexToBoneWeightMap.end(); it++) 
     79    for (VertexInfluenceSet::VertexIndexToBoneWeightMap::const_iterator it = vertexIndexToBoneWeightMap.begin(); it != vertexIndexToBoneWeightMap.end(); ++it) 
    7180    { 
    7281        int vertexIndex = it->first; 
    7382        const VertexInfluenceSet::BoneWeightList& boneWeightList = it->second; 
    7483        int bonesForThisVertex = 0; 
    75         for (VertexInfluenceSet::BoneWeightList::const_iterator it = boneWeightList.begin(); it != boneWeightList.end(); it++) 
     84        for (VertexInfluenceSet::BoneWeightList::const_iterator it = boneWeightList.begin(); it != boneWeightList.end(); ++it) 
    7685        { 
    7786            const VertexInfluenceSet::BoneWeight& bw = *it; 
     
    8695                if (boneMap.find(bw.getBoneName()) == boneMap.end()) 
    8796                { 
    88                     osg::notify(osg::WARN) << "RigTransformHardware::createPalette can't find bone " << bw.getBoneName() << " skip this influence" << std::endl; 
     97                    osg::notify(osg::INFO) << "RigTransformHardware::createPalette can't find bone " << bw.getBoneName() << " skip this influence" << std::endl; 
    8998                    continue; 
    9099                } 
     
    105114    osg::notify(osg::INFO) << "RigTransformHardware::createPalette matrix palette has " << boneNameCountMap.size() << " entries" << std::endl; 
    106115 
    107     for (BoneNameCountMap::iterator it = boneNameCountMap.begin(); it != boneNameCountMap.end(); it++) 
     116    for (BoneNameCountMap::iterator it = boneNameCountMap.begin(); it != boneNameCountMap.end(); ++it) 
    108117    { 
    109118        osg::notify(osg::INFO) << "RigTransformHardware::createPalette Bone " << it->first << " is used " << it->second << " times" << std::endl; 
     
    187196bool RigTransformHardware::init(RigGeometry& geom) 
    188197{ 
    189     osg::Vec3Array* pos = dynamic_cast<osg::Vec3Array*>(geom.getVertexArray()); 
    190     if (!pos) { 
     198    osg::Geometry& source = *geom.getSourceGeometry(); 
     199    osg::Vec3Array* positionSrc = dynamic_cast<osg::Vec3Array*>(source.getVertexArray()); 
     200    if (!positionSrc)  
     201    { 
    191202        osg::notify(osg::WARN) << "RigTransformHardware no vertex array in the geometry " << geom.getName() << std::endl; 
    192203        return false; 
    193204    } 
    194205 
    195     if (!geom.getSkeleton()) { 
    196         osg::notify(osg::WARN) << "RigTransformHardware no skeleting set in geometry " << geom.getName() << std::endl; 
    197         return false; 
    198     } 
    199  
    200     Bone::BoneMap bm = geom.getSkeleton()->getBoneMap(); 
    201  
    202     if (!createPalette(pos->size(),bm, geom.getVertexInfluenceSet().getVertexToBoneList())) 
     206    if (!geom.getSkeleton())  
     207    { 
     208        osg::notify(osg::WARN) << "RigTransformHardware no skeleton set in geometry " << geom.getName() << std::endl; 
     209        return false; 
     210    } 
     211 
     212 
     213    // copy shallow from source geometry to rig 
     214    geom.copyFrom(source); 
     215 
     216 
     217    BoneMapVisitor mapVisitor; 
     218    geom.getSkeleton()->accept(mapVisitor); 
     219    BoneMap bm = mapVisitor.getBoneMap(); 
     220 
     221    if (!createPalette(positionSrc->size(),bm, geom.getVertexInfluenceSet().getVertexToBoneList())) 
    203222        return false; 
    204223 
     
    245264    return true; 
    246265} 
    247 void RigTransformHardware::update(RigGeometry& geom) 
    248 { 
     266void RigTransformHardware::operator()(RigGeometry& geom) 
     267{ 
     268    if (_needInit) 
     269        if (!init(geom)) 
     270            return; 
    249271    computeMatrixPaletteUniform(geom.getMatrixFromSkeletonToGeometry(), geom.getInvMatrixFromSkeletonToGeometry()); 
    250272} 
  • OpenSceneGraph/trunk/src/osgAnimation/RigTransformSoftware.cpp

    r10693 r11009  
    1414 
    1515 
     16#include <osgAnimation/VertexInfluence> 
    1617#include <osgAnimation/RigTransformSoftware> 
     18#include <osgAnimation/BoneMapVisitor> 
    1719#include <osgAnimation/RigGeometry> 
    1820 
    1921using namespace osgAnimation; 
     22 
     23RigTransformSoftware::RigTransformSoftware() 
     24{ 
     25    _needInit = true; 
     26} 
    2027 
    2128bool RigTransformSoftware::init(RigGeometry& geom) 
     
    2330    if (!geom.getSkeleton()) 
    2431        return false; 
    25     Bone::BoneMap bm = geom.getSkeleton()->getBoneMap(); 
     32 
     33    BoneMapVisitor mapVisitor; 
     34    geom.getSkeleton()->accept(mapVisitor); 
     35    BoneMap bm = mapVisitor.getBoneMap(); 
    2636    initVertexSetFromBones(bm, geom.getVertexInfluenceSet().getUniqVertexSetToBoneSetList()); 
     37 
     38    geom.copyFrom(*geom.getSourceGeometry()); 
     39    geom.setVertexArray(0); 
     40    geom.setNormalArray(0); 
     41 
    2742    _needInit = false; 
    2843    return true; 
    2944} 
    3045 
    31 void RigTransformSoftware::update(RigGeometry& geom) 
     46void RigTransformSoftware::operator()(RigGeometry& geom) 
    3247{ 
    33     osg::Vec3Array* pos = dynamic_cast<osg::Vec3Array*>(geom.getVertexArray()); 
    34     if (pos && _positionSource.size() != pos->size())  
     48    if (_needInit) 
     49        if (!init(geom)) 
     50            return; 
     51 
     52    osg::Geometry& source = *geom.getSourceGeometry(); 
     53    osg::Geometry& destination = geom; 
     54 
     55    osg::Vec3Array* positionSrc = dynamic_cast<osg::Vec3Array*>(source.getVertexArray()); 
     56    osg::Vec3Array* positionDst = dynamic_cast<osg::Vec3Array*>(destination.getVertexArray()); 
     57    if (positionSrc && (!positionDst || (positionDst->size() != positionSrc->size()) ) ) 
    3558    { 
    36         _positionSource = std::vector<osg::Vec3>(pos->begin(),pos->end()); 
    37         geom.getVertexArray()->setDataVariance(osg::Object::DYNAMIC); 
     59        if (!positionDst) 
     60        { 
     61            positionDst = new osg::Vec3Array; 
     62            positionDst->setDataVariance(osg::Object::DYNAMIC); 
     63            destination.setVertexArray(positionDst); 
     64        } 
     65        *positionDst = *positionSrc; 
    3866    } 
    39     osg::Vec3Array* normal = dynamic_cast<osg::Vec3Array*>(geom.getNormalArray()); 
    40     if (normal && _normalSource.size() != normal->size())  
     67     
     68    osg::Vec3Array* normalSrc = dynamic_cast<osg::Vec3Array*>(source.getNormalArray()); 
     69    osg::Vec3Array* normalDst = dynamic_cast<osg::Vec3Array*>(destination.getNormalArray()); 
     70    if (normalSrc && (!normalDst || (normalDst->size() != normalSrc->size()) ) ) 
    4171    { 
    42         _normalSource = std::vector<osg::Vec3>(normal->begin(),normal->end()); 
    43         geom.getNormalArray()->setDataVariance(osg::Object::DYNAMIC); 
     72        if (!normalDst) 
     73        { 
     74            normalDst = new osg::Vec3Array; 
     75            normalDst->setDataVariance(osg::Object::DYNAMIC); 
     76            destination.setNormalArray(normalDst); 
     77            destination.setNormalBinding(osg::Geometry::BIND_PER_VERTEX); 
     78        } 
     79        *normalDst = *normalSrc; 
    4480    } 
    4581 
    46     if (!_positionSource.empty())  
     82    if (positionDst && !positionDst->empty()) 
    4783    { 
    48         compute<osg::Vec3>(geom.getMatrixFromSkeletonToGeometry(), geom.getInvMatrixFromSkeletonToGeometry(),  &_positionSource.front(), &pos->front()); 
    49         pos->dirty(); 
     84        compute<osg::Vec3>(geom.getMatrixFromSkeletonToGeometry(),  
     85                           geom.getInvMatrixFromSkeletonToGeometry(),   
     86                           &positionSrc->front(), 
     87                           &positionDst->front()); 
     88        positionDst->dirty(); 
    5089    } 
    51     if (!_normalSource.empty())  
     90 
     91    if (normalDst && !normalDst->empty()) 
    5292    { 
    53         computeNormal<osg::Vec3>(geom.getMatrixFromSkeletonToGeometry(), geom.getInvMatrixFromSkeletonToGeometry(), &_normalSource.front(), &normal->front()); 
    54         normal->dirty(); 
     93        computeNormal<osg::Vec3>(geom.getMatrixFromSkeletonToGeometry(),  
     94                           geom.getInvMatrixFromSkeletonToGeometry(),   
     95                           &normalSrc->front(), 
     96                           &normalDst->front()); 
     97        normalDst->dirty(); 
    5598    } 
    5699} 
    57100 
    58 void RigTransformSoftware::initVertexSetFromBones(const Bone::BoneMap& map, const VertexInfluenceSet::UniqVertexSetToBoneSetList& influence) 
     101void RigTransformSoftware::initVertexSetFromBones(const BoneMap& map, const VertexInfluenceSet::UniqVertexSetToBoneSetList& influence) 
    59102{ 
    60103    _boneSetVertexSet.clear(); 
     
    73116            const std::string& bname = inf.getBones()[b].getBoneName(); 
    74117            float weight = inf.getBones()[b].getWeight(); 
    75             Bone::BoneMap::const_iterator it = map.find(bname); 
     118            BoneMap::const_iterator it = map.find(bname); 
    76119            if (it == map.end())  
    77120            { 
  • OpenSceneGraph/trunk/src/osgAnimation/Skeleton.cpp

    r10751 r11009  
    1515#include <osgAnimation/Skeleton> 
    1616#include <osgAnimation/Bone> 
     17#include <osg/Notify> 
    1718 
    1819using namespace osgAnimation; 
    1920 
    2021Skeleton::Skeleton() {} 
    21 Skeleton::Skeleton(const Skeleton& b, const osg::CopyOp& copyop) : Bone(b,copyop) {} 
     22Skeleton::Skeleton(const Skeleton& b, const osg::CopyOp& copyop) : osg::MatrixTransform(b,copyop) {} 
    2223 
    2324Skeleton::UpdateSkeleton::UpdateSkeleton() : _needValidate(true) {} 
    24 Skeleton::UpdateSkeleton::UpdateSkeleton(const UpdateSkeleton& us, const osg::CopyOp& copyop= osg::CopyOp::SHALLOW_COPY) : osg::Object(us, copyop), osg::NodeCallback(us, copyop)  
     25Skeleton::UpdateSkeleton::UpdateSkeleton(const UpdateSkeleton& us, const osg::CopyOp& copyop= osg::CopyOp::SHALLOW_COPY) : osg::Object(us, copyop), osg::NodeCallback(us, copyop) 
    2526{ 
    2627    _needValidate = true; 
     
    4647        bool foundNonBone = false; 
    4748 
    48         for (unsigned i = 0; i < bone->getNumChildren(); ++i) 
     49        for (unsigned int i = 0; i < bone->getNumChildren(); ++i) 
    4950        { 
    5051            if (dynamic_cast<Bone*>(bone->getChild(i))) 
     
    7778        { 
    7879            ValidateSkeletonVisitor visitor; 
    79             node->accept(visitor); 
     80            for (unsigned int i = 0; i < skeleton->getNumChildren(); ++i) 
     81            { 
     82                osg::Node* child = skeleton->getChild(i); 
     83                child->accept(visitor); 
     84            } 
    8085            _needValidate = false; 
    8186        } 
    82         if (skeleton->needToComputeBindMatrix()) 
    83             skeleton->computeBindMatrix(); 
    8487    } 
    8588    traverse(node,nv); 
     
    9093    setUpdateCallback(new Skeleton::UpdateSkeleton ); 
    9194} 
    92  
    93 void Skeleton::computeBindMatrix()  
    94 { 
    95     _invBindInSkeletonSpace = osg::Matrix::inverse(_bindInBoneSpace);  
    96     _needToRecomputeBindMatrix = false;  
    97 } 
  • OpenSceneGraph/trunk/src/osgAnimation/StatsHandler.cpp

    r10764 r11009  
    425425            pos.y() -= characterSize *2 + backgroundMargin; 
    426426 
    427              for (std::map<std::string, StatAction >::iterator it = _actions.begin(); it != _actions.end(); it++) { 
     427             for (std::map<std::string, StatAction >::iterator it = _actions.begin(); it != _actions.end(); ++it) { 
    428428                 (*it).second._group->setNodeMask(~osg::Node::NodeMask(1)); 
    429429             } 
  • OpenSceneGraph/trunk/src/osgAnimation/Timeline.cpp

    r10904 r11009  
    211211void Timeline::internalRemoveAction(Action* action) 
    212212{ 
    213     for (ActionLayers::iterator it = _actions.begin(); it != _actions.end(); it++) 
     213    for (ActionLayers::iterator it = _actions.begin(); it != _actions.end(); ++it) 
    214214    { 
    215215        ActionList& fa = it->second; 
  • OpenSceneGraph/trunk/src/osgAnimation/VertexInfluence.cpp

    r10693 r11009  
    2727{ 
    2828    _vertex2Bones.clear(); 
    29     for (BoneToVertexList::const_iterator it = _bone2Vertexes.begin(); it != _bone2Vertexes.end(); it++)  
     29    for (BoneToVertexList::const_iterator it = _bone2Vertexes.begin(); it != _bone2Vertexes.end(); ++it)  
    3030    { 
    3131        const VertexInfluence& vi = (*it); 
     
    4343 
    4444    // normalize weight per vertex 
    45     for (VertexIndexToBoneWeightMap::iterator it = _vertex2Bones.begin(); it != _vertex2Bones.end(); it++) 
     45    for (VertexIndexToBoneWeightMap::iterator it = _vertex2Bones.begin(); it != _vertex2Bones.end(); ++it) 
    4646    { 
    4747        BoneWeightList& bones = it->second; 
     
    117117    UnifyBoneGroup unifyBuffer; 
    118118 
    119     for (VertexIndexToBoneWeightMap::iterator it = _vertex2Bones.begin(); it != _vertex2Bones.end(); it++)  
     119    for (VertexIndexToBoneWeightMap::iterator it = _vertex2Bones.begin(); it != _vertex2Bones.end(); ++it)  
    120120    { 
    121121        BoneWeightList bones = it->second; 
     
    133133 
    134134    _uniqVertexSetToBoneSet.reserve(unifyBuffer.size()); 
    135     for (UnifyBoneGroup::iterator it = unifyBuffer.begin(); it != unifyBuffer.end(); it++)  
     135    for (UnifyBoneGroup::iterator it = unifyBuffer.begin(); it != unifyBuffer.end(); ++it)  
    136136    { 
    137137        _uniqVertexSetToBoneSet.push_back(it->second); 
  • OpenSceneGraph/trunk/src/osgPlugins/bvh/ReaderWriterBVH.cpp

    r9371 r11009  
    99#include <osgAnimation/Bone> 
    1010#include <osgAnimation/Skeleton> 
     11#include <osgAnimation/UpdateBone> 
     12#include <osgAnimation/StackedTransform> 
     13#include <osgAnimation/StackedTranslateElement> 
     14#include <osgAnimation/StackedQuaternionElement> 
    1115#include <osgAnimation/BasicAnimationManager> 
    1216 
     
    4044            { 
    4145                // Process OFFSET section 
    42                 parent->setBindMatrixInBoneSpace( osg::Matrix::translate(offset) ); 
     46                parent->setMatrixInSkeletonSpace( osg::Matrix::translate(offset) * 
     47                                                  parent->getMatrixInSkeletonSpace() ); 
     48                osgAnimation::UpdateBone* updateBone = 
     49                    static_cast<osgAnimation::UpdateBone*>( parent->getUpdateCallback() ); 
     50                if ( updateBone ) 
     51                { 
     52                    osgAnimation::StackedTransform& stack = updateBone->getStackedTransforms(); 
     53                    stack.push_back( new osgAnimation::StackedTranslateElement("position", offset) ); 
     54                    stack.push_back( new osgAnimation::StackedQuaternionElement("quaternion", osg::Quat()) ); 
     55                } 
     56                 
    4357                if ( _drawingFlag && parent->getNumParents() && level>0 ) 
    4458                    parent->getParent(0)->addChild( createRefGeometry(offset, 0.5).get() ); 
     
    7892                    // Process End Site section 
    7993                    osg::ref_ptr<osgAnimation::Bone> bone = new osgAnimation::Bone( parent->getName()+"End" ); 
    80                     bone->setBindMatrixInBoneSpace( osg::Matrix::translate(offsetEndSite) ); 
     94                    bone->setMatrixInSkeletonSpace( osg::Matrix::translate(offsetEndSite) * 
     95                                                    bone->getMatrixInSkeletonSpace() ); 
    8196                    bone->setDataVariance( osg::Object::DYNAMIC ); 
    82                     parent->addChild( bone.get() ); 
     97                    parent->insertChild( 0, bone.get() ); 
    8398 
    8499                    if ( _drawingFlag ) 
     
    95110            // Process JOINT section 
    96111            osg::ref_ptr<osgAnimation::Bone> bone = new osgAnimation::Bone( fr[1].getStr() ); 
     112            bone->setDataVariance( osg::Object::DYNAMIC ); 
    97113            bone->setDefaultUpdateCallback(); 
    98             bone->setDataVariance( osg::Object::DYNAMIC ); 
    99             parent->addChild( bone.get() ); 
     114            parent->insertChild( 0, bone.get() ); 
    100115            _joints.push_back( JointNode(bone, 0) ); 
    101116 
     
    195210        fr.attach( &stream ); 
    196211 
     212        osg::ref_ptr<osgAnimation::Bone> boneroot = new osgAnimation::Bone( "Root" ); 
     213        boneroot->setDefaultUpdateCallback(); 
     214 
    197215        osg::ref_ptr<osgAnimation::Skeleton> skelroot = new osgAnimation::Skeleton; 
    198216        skelroot->setDefaultUpdateCallback(); 
     217        skelroot->insertChild( 0, boneroot.get() ); 
     218 
    199219        osg::ref_ptr<osgAnimation::Animation> anim = new osgAnimation::Animation; 
    200220 
     
    204224            { 
    205225                ++fr; 
    206                 buildHierarchy( fr, 0, skelroot.get() ); 
     226                buildHierarchy( fr, 0, boneroot.get() ); 
    207227            } 
    208228            else if ( fr.matchSequence("MOTION") ) 
  • OpenSceneGraph/trunk/src/osgWrappers/deprecated-dotosg/osgAnimation/CMakeLists.txt

    r10975 r11009  
    66#### end var setup  ### 
    77SETUP_PLUGIN(osganimation) 
    8  
    9  
  • OpenSceneGraph/trunk/src/osgWrappers/deprecated-dotosg/osgAnimation/ReaderWriter.cpp

    r10556 r11009  
    1111 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
    1212 * OpenSceneGraph Public License for more details. 
    13 */ 
    14  
    15  
    16 #include <osgDB/Registry> 
     13 */ 
     14 
     15 
    1716#include <osgDB/FileNameUtils> 
    1817#include <osgDB/FileUtils> 
    1918#include <osgDB/ReaderWriter> 
    20  
     19#include <osg/io_utils> 
    2120#include <osgAnimation/AnimationManagerBase> 
    2221#include <osgAnimation/BasicAnimationManager> 
     
    2524#include <osgAnimation/Animation> 
    2625#include <osgAnimation/Bone> 
     26#include <osgAnimation/UpdateBone> 
     27#include <osgAnimation/UpdateMatrixTransform> 
    2728#include <osgAnimation/Skeleton> 
    2829#include <osgAnimation/RigGeometry> 
    2930#include <osgAnimation/MorphGeometry> 
    30 #include <osgAnimation/UpdateCallback> 
     31#include <osgAnimation/StackedTransform> 
     32#include <osgAnimation/StackedTranslateElement> 
     33#include <osgAnimation/StackedRotateAxisElement> 
     34#include <osgAnimation/StackedMatrixElement> 
     35#include <osgAnimation/StackedScaleElement> 
     36#include "Matrix.h" 
    3137 
    3238#include <osgDB/Registry> 
     
    4349    osg::Quat att; 
    4450    bool iteratorAdvanced = false; 
    45     if (fr.matchSequence("bindQuaternion %f %f %f %f"))  
     51    if (fr.matchSequence("bindQuaternion %f %f %f %f")) 
    4652    { 
    4753        fr[1].getFloat(att[0]); 
     
    5258        fr += 5; 
    5359        iteratorAdvanced = true; 
     60        osg::notify(osg::WARN) << "Old osgAnimation file format update your data file" << std::endl; 
    5461    } 
    5562 
    5663    osg::Vec3d pos(0,0,0); 
    57     if (fr.matchSequence("bindPosition %f %f %f"))  
     64    if (fr.matchSequence("bindPosition %f %f %f")) 
    5865    { 
    5966        fr[1].getFloat(pos[0]); 
     
    6370        fr += 4; 
    6471        iteratorAdvanced = true; 
     72        osg::notify(osg::WARN) << "Old osgAnimation file format update your data file" << std::endl; 
    6573    } 
    6674 
    6775    osg::Vec3d scale(1,1,1); 
    68     if (fr.matchSequence("bindScale %f %f %f"))  
     76    if (fr.matchSequence("bindScale %f %f %f")) 
    6977    { 
    7078        fr[1].getFloat(scale[0]); 
     
    7482        fr += 4; 
    7583        iteratorAdvanced = true; 
    76     } 
    77  
    78     bone.setBindMatrixInBoneSpace( osg::Matrix(att) * osg::Matrix::translate(pos)); 
     84        osg::notify(osg::WARN) << "Old osgAnimation file format update your data file" << std::endl; 
     85    } 
     86 
     87    if (fr.matchSequence("InvBindMatrixInSkeletonSpace {")) 
     88    { 
     89        Matrix matrix;  
     90        if (readMatrix(matrix,fr, "InvBindMatrixInSkeletonSpace")) 
     91        { 
     92            bone.setInvBindMatrixInSkeletonSpace(matrix); 
     93            iteratorAdvanced = true; 
     94        } 
     95    } 
     96    if (fr.matchSequence("MatrixInSkeletonSpace {")) 
     97    { 
     98        Matrix matrix;  
     99        if (readMatrix(matrix,fr, "MatrixInSkeletonSpace")) 
     100        { 
     101            bone.setMatrixInSkeletonSpace(matrix); 
     102            iteratorAdvanced = true; 
     103        } 
     104    } 
    79105    return iteratorAdvanced; 
    80106} 
    81107 
    82 bool Bone_writeLocalData(const Object& obj, Output& fw)  
     108bool Bone_writeLocalData(const Object& obj, Output& fw) 
    83109{ 
    84110    const osgAnimation::Bone& bone = dynamic_cast<const osgAnimation::Bone&>(obj); 
    85     osg::Vec3 t; 
    86     osg::Quat r; 
    87     osg::Vec3 s; 
    88     osg::Quat rs; 
    89     bone.getBindMatrixInBoneSpace().decompose(t,r,s,rs); 
    90     fw.indent() << "bindQuaternion "  << r << std::endl; 
    91     fw.indent() << "bindPosition "  << t << std::endl; 
    92     fw.indent() << "bindScale "  << s << std::endl; 
    93     return true; 
    94 } 
    95  
    96 RegisterDotOsgWrapperProxy g_atkBoneProxy 
     111    bool res1 = writeMatrix(bone.getInvBindMatrixInSkeletonSpace(), fw, "InvBindMatrixInSkeletonSpace"); 
     112    // write this field for debug only 
     113    // because it's recompute at each update 
     114    bool res2 = writeMatrix(bone.getMatrixInSkeletonSpace(), fw, "MatrixInSkeletonSpace"); 
     115    return (res1 || res2); 
     116} 
     117 
     118RegisterDotOsgWrapperProxy g_BoneProxy 
    97119( 
    98120    new osgAnimation::Bone, 
    99121    "osgAnimation::Bone", 
    100     "Object Node Transform osgAnimation::Bone Group", 
     122    "Object Node MatrixTransform osgAnimation::Bone Group", 
    101123    &Bone_readLocalData, 
    102124    &Bone_writeLocalData 
     
    113135    return true;  
    114136} 
    115 RegisterDotOsgWrapperProxy g_atkRootSkeletonProxy 
     137RegisterDotOsgWrapperProxy g_SkeletonProxy 
    116138( 
    117139    new osgAnimation::Skeleton, 
    118140    "osgAnimation::Skeleton", 
    119     "Object Node  Transform osgAnimation::Bone osgAnimation::Skeleton Group", 
     141    "Object Node MatrixTransform osgAnimation::Skeleton Group", 
    120142    &Skeleton_readLocalData, 
    121143    &Skeleton_writeLocalData, 
     
    724746 
    725747    fw.indent() << "num_animations " << animList.size()  << std::endl; 
    726     for (osgAnimation::AnimationList::const_iterator it = animList.begin(); it != animList.end(); it++) 
     748    for (osgAnimation::AnimationList::const_iterator it = animList.begin(); it != animList.end(); ++it) 
    727749    { 
    728750        if (!fw.writeObject(**it)) 
     
    817839        geom.setInfluenceMap(vmap.get()); 
    818840 
     841    if (fr.matchSequence("Geometry {")) 
     842    { 
     843        osg::Geometry* source = dynamic_cast<osg::Geometry*>(fr.readObject()); 
     844        geom.setSourceGeometry(source); 
     845        iteratorAdvanced = true; 
     846    } 
     847 
    819848    return iteratorAdvanced; 
    820849} 
     
    828857    fw.indent() << "num_influences "  << vm->size() << std::endl; 
    829858    fw.moveIn(); 
    830     for (osgAnimation::VertexInfluenceMap::const_iterator it = vm->begin(); it != vm->end(); it++)  
     859    for (osgAnimation::VertexInfluenceMap::const_iterator it = vm->begin(); it != vm->end(); ++it)  
    831860    { 
    832861        std::string name = it->first; 
     
    844873    } 
    845874    fw.moveOut(); 
     875 
     876    fw.writeObject(*geom.getSourceGeometry()); 
    846877    return true; 
    847878} 
     
    851882    new osgAnimation::RigGeometry, 
    852883    "osgAnimation::RigGeometry", 
    853     "Object Drawable osgAnimation::RigGeometry Geometry", 
     884    "Object osgAnimation::RigGeometry Drawable Geometry", 
    854885    &RigGeometry_readLocalData, 
    855886    &RigGeometry_writeLocalData, 
     
    9761007 
    9771008 
    978 bool UpdateBone_readLocalData(Object& obj, Input& fr)  
     1009 
     1010 
     1011 
     1012bool UpdateBone_readLocalData(Object& obj, Input& fr) 
    9791013{ 
    9801014    bool iteratorAdvanced = false; 
     
    9871021} 
    9881022 
    989 RegisterDotOsgWrapperProxy g_atkUpdateBoneProxy 
     1023RegisterDotOsgWrapperProxy g_UpdateBoneProxy 
    9901024( 
    991     new osgAnimation::Bone::UpdateBone, 
     1025    new osgAnimation::UpdateBone, 
    9921026    "osgAnimation::UpdateBone", 
    993     "Object NodeCallback osgAnimation::UpdateBone", 
     1027    "Object NodeCallback osgAnimation::UpdateMatrixTransform osgAnimation::UpdateBone", 
    9941028    &UpdateBone_readLocalData, 
    9951029    &UpdateBone_writeLocalData, 
     
    10101044} 
    10111045 
    1012 RegisterDotOsgWrapperProxy g_atkUpdateSkeletonProxy 
     1046RegisterDotOsgWrapperProxy g_UpdateSkeletonProxy 
    10131047( 
    10141048    new osgAnimation::Skeleton::UpdateSkeleton, 
     
    10211055 
    10221056 
    1023  
    1024 bool UpdateTransform_readLocalData(Object& obj, Input& fr)  
     1057bool UpdateMorph_readLocalData(Object& obj, Input& fr)  
    10251058{ 
    10261059    bool iteratorAdvanced = false; 
     
    10281061} 
    10291062 
    1030 bool UpdateTransform_writeLocalData(const Object& obj, Output& fw) 
     1063bool UpdateMorph_writeLocalData(const Object& obj, Output& fw) 
    10311064{ 
    10321065    return true; 
    10331066} 
    10341067 
    1035 RegisterDotOsgWrapperProxy g_atkUpdateTransformProxy 
    1036 ( 
    1037     new osgAnimation::UpdateTransform, 
    1038     "osgAnimation::UpdateTransform", 
    1039     "Object NodeCallback osgAnimation::UpdateTransform", 
    1040     &UpdateTransform_readLocalData, 
    1041     &UpdateTransform_writeLocalData, 
    1042     DotOsgWrapper::READ_AND_WRITE 
    1043 ); 
    1044  
    1045  
    1046  
    1047 bool UpdateMaterial_readLocalData(Object& obj, Input& fr)  
    1048 { 
    1049     bool iteratorAdvanced = false; 
    1050     return iteratorAdvanced; 
    1051 } 
    1052  
    1053 bool UpdateMaterial_writeLocalData(const Object& obj, Output& fw) 
    1054 { 
    1055     return true; 
    1056 } 
    1057  
    1058 RegisterDotOsgWrapperProxy g_UpdateMaterialProxy 
    1059 ( 
    1060     new osgAnimation::UpdateMaterial, 
    1061     "osgAnimation::UpdateMaterial", 
    1062     "Object StateAttribute::Callback osgAnimation::UpdateMaterial", 
    1063     &UpdateMaterial_readLocalData, 
    1064     &UpdateMaterial_writeLocalData, 
    1065     DotOsgWrapper::READ_AND_WRITE 
    1066 ); 
    1067  
    1068 bool UpdateMorph_readLocalData(Object& obj, Input& fr)  
    1069 { 
    1070     bool iteratorAdvanced = false; 
    1071     return iteratorAdvanced; 
    1072 } 
    1073  
    1074 bool UpdateMorph_writeLocalData(const Object& obj, Output& fw) 
    1075 { 
    1076     return true; 
    1077 } 
    1078  
    1079 RegisterDotOsgWrapperProxy g_atkUpdateMorphProxy 
     1068RegisterDotOsgWrapperProxy g_UpdateMorphProxy 
    10801069( 
    10811070 new osgAnimation::UpdateMorph,