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/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 }