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