Show
Ignore:
Timestamp:
01/27/10 13:24:55 (3 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.
"

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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