Changeset 11009 for OpenSceneGraph/trunk/src/osgWrappers/deprecated-dotosg/osgAnimation/ReaderWriter.cpp
- Timestamp:
- 01/27/10 13:24:55 (3 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgWrappers/deprecated-dotosg/osgAnimation/ReaderWriter.cpp
r10556 r11009 11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 12 * OpenSceneGraph Public License for more details. 13 */ 14 15 16 #include <osgDB/Registry> 13 */ 14 15 17 16 #include <osgDB/FileNameUtils> 18 17 #include <osgDB/FileUtils> 19 18 #include <osgDB/ReaderWriter> 20 19 #include <osg/io_utils> 21 20 #include <osgAnimation/AnimationManagerBase> 22 21 #include <osgAnimation/BasicAnimationManager> … … 25 24 #include <osgAnimation/Animation> 26 25 #include <osgAnimation/Bone> 26 #include <osgAnimation/UpdateBone> 27 #include <osgAnimation/UpdateMatrixTransform> 27 28 #include <osgAnimation/Skeleton> 28 29 #include <osgAnimation/RigGeometry> 29 30 #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" 31 37 32 38 #include <osgDB/Registry> … … 43 49 osg::Quat att; 44 50 bool iteratorAdvanced = false; 45 if (fr.matchSequence("bindQuaternion %f %f %f %f")) 51 if (fr.matchSequence("bindQuaternion %f %f %f %f")) 46 52 { 47 53 fr[1].getFloat(att[0]); … … 52 58 fr += 5; 53 59 iteratorAdvanced = true; 60 osg::notify(osg::WARN) << "Old osgAnimation file format update your data file" << std::endl; 54 61 } 55 62 56 63 osg::Vec3d pos(0,0,0); 57 if (fr.matchSequence("bindPosition %f %f %f")) 64 if (fr.matchSequence("bindPosition %f %f %f")) 58 65 { 59 66 fr[1].getFloat(pos[0]); … … 63 70 fr += 4; 64 71 iteratorAdvanced = true; 72 osg::notify(osg::WARN) << "Old osgAnimation file format update your data file" << std::endl; 65 73 } 66 74 67 75 osg::Vec3d scale(1,1,1); 68 if (fr.matchSequence("bindScale %f %f %f")) 76 if (fr.matchSequence("bindScale %f %f %f")) 69 77 { 70 78 fr[1].getFloat(scale[0]); … … 74 82 fr += 4; 75 83 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 } 79 105 return iteratorAdvanced; 80 106 } 81 107 82 bool Bone_writeLocalData(const Object& obj, Output& fw) 108 bool Bone_writeLocalData(const Object& obj, Output& fw) 83 109 { 84 110 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 118 RegisterDotOsgWrapperProxy g_BoneProxy 97 119 ( 98 120 new osgAnimation::Bone, 99 121 "osgAnimation::Bone", 100 "Object Node Transform osgAnimation::Bone Group",122 "Object Node MatrixTransform osgAnimation::Bone Group", 101 123 &Bone_readLocalData, 102 124 &Bone_writeLocalData … … 113 135 return true; 114 136 } 115 RegisterDotOsgWrapperProxy g_ atkRootSkeletonProxy137 RegisterDotOsgWrapperProxy g_SkeletonProxy 116 138 ( 117 139 new osgAnimation::Skeleton, 118 140 "osgAnimation::Skeleton", 119 "Object Node Transform osgAnimation::BoneosgAnimation::Skeleton Group",141 "Object Node MatrixTransform osgAnimation::Skeleton Group", 120 142 &Skeleton_readLocalData, 121 143 &Skeleton_writeLocalData, … … 724 746 725 747 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) 727 749 { 728 750 if (!fw.writeObject(**it)) … … 817 839 geom.setInfluenceMap(vmap.get()); 818 840 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 819 848 return iteratorAdvanced; 820 849 } … … 828 857 fw.indent() << "num_influences " << vm->size() << std::endl; 829 858 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) 831 860 { 832 861 std::string name = it->first; … … 844 873 } 845 874 fw.moveOut(); 875 876 fw.writeObject(*geom.getSourceGeometry()); 846 877 return true; 847 878 } … … 851 882 new osgAnimation::RigGeometry, 852 883 "osgAnimation::RigGeometry", 853 "Object Drawable osgAnimation::RigGeometryGeometry",884 "Object osgAnimation::RigGeometry Drawable Geometry", 854 885 &RigGeometry_readLocalData, 855 886 &RigGeometry_writeLocalData, … … 976 1007 977 1008 978 bool UpdateBone_readLocalData(Object& obj, Input& fr) 1009 1010 1011 1012 bool UpdateBone_readLocalData(Object& obj, Input& fr) 979 1013 { 980 1014 bool iteratorAdvanced = false; … … 987 1021 } 988 1022 989 RegisterDotOsgWrapperProxy g_ atkUpdateBoneProxy1023 RegisterDotOsgWrapperProxy g_UpdateBoneProxy 990 1024 ( 991 new osgAnimation:: Bone::UpdateBone,1025 new osgAnimation::UpdateBone, 992 1026 "osgAnimation::UpdateBone", 993 "Object NodeCallback osgAnimation::Update Bone",1027 "Object NodeCallback osgAnimation::UpdateMatrixTransform osgAnimation::UpdateBone", 994 1028 &UpdateBone_readLocalData, 995 1029 &UpdateBone_writeLocalData, … … 1010 1044 } 1011 1045 1012 RegisterDotOsgWrapperProxy g_ atkUpdateSkeletonProxy1046 RegisterDotOsgWrapperProxy g_UpdateSkeletonProxy 1013 1047 ( 1014 1048 new osgAnimation::Skeleton::UpdateSkeleton, … … 1021 1055 1022 1056 1023 1024 bool UpdateTransform_readLocalData(Object& obj, Input& fr) 1057 bool UpdateMorph_readLocalData(Object& obj, Input& fr) 1025 1058 { 1026 1059 bool iteratorAdvanced = false; … … 1028 1061 } 1029 1062 1030 bool Update Transform_writeLocalData(const Object& obj, Output& fw)1063 bool UpdateMorph_writeLocalData(const Object& obj, Output& fw) 1031 1064 { 1032 1065 return true; 1033 1066 } 1034 1067 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 1068 RegisterDotOsgWrapperProxy g_UpdateMorphProxy 1080 1069 ( 1081 1070 new osgAnimation::UpdateMorph,
