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