From 5685312fe06b94db40d78bd2c8167eb7c5e5e99f Mon Sep 17 00:00:00 2001 From: jonathanklein Date: Fri, 16 Apr 2010 19:10:09 +0000 Subject: [PATCH] - PoseToKey Matrix is computed just computed when it changes - VertexWeights will be normalized to 1 git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@686 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/OgreImporter.cpp | 50 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/code/OgreImporter.cpp b/code/OgreImporter.cpp index 66883ae01..0b6d025d8 100644 --- a/code/OgreImporter.cpp +++ b/code/OgreImporter.cpp @@ -230,6 +230,8 @@ void OgreImporter::ReadSubMesh(SubMesh &theSubMesh, XmlReader *Reader) } }//end of "geometry + + else if(string(Reader->getNodeName())=="boneassignments") { theSubMesh.Weights.resize(theSubMesh.Positions.size()); @@ -303,6 +305,29 @@ void OgreImporter::ReadSubMesh(SubMesh &theSubMesh, XmlReader *Reader) theSubMesh.Normals.swap(UniqueNormals); theSubMesh.Uvs.swap(UniqueUvs); theSubMesh.Weights.swap(UniqueWeights); + + //------------- normalize weights ----------------------------- + //The Blender exporter doesn't care about whether the sum of all boneweights for a single vertex equals 1 or not, + //so we have to make this sure: + for(unsigned int VertexId=0; VertexId1.0f+0.05f) + { + //normalize all weights: + for(unsigned int BoneId=0; BoneId > aiWeights(theSubMesh.BonesUsed);//now the outer list are the bones, and the inner vector the vertices for(unsigned int VertexId=0; VertexId aiBones; aiBones.reserve(theSubMesh.BonesUsed);//the vector might be smaller, because there might be empty bones (bones that are not attached to any vertex) @@ -653,6 +681,10 @@ void OgreImporter::CreateAssimpSkeleton(const std::vector &Bones, const st //we need this, to acces the bones default pose, which we need to make keys absolute vector::const_iterator CurBone=find(Bones.begin(), Bones.end(), NewNodeAnim->mNodeName); + aiMatrix4x4 t0, t1; + aiMatrix4x4 DefBonePose=//The default bone pose doesnt have a scaling value + aiMatrix4x4::Rotation(CurBone->RotationAngle, CurBone->RotationAxis, t0) + * aiMatrix4x4::Translation(CurBone->Position, t1); //Create the keyframe arrays... unsigned int KeyframeCount=Animations[i].Tracks[j].Keyframes.size(); @@ -666,15 +698,13 @@ void OgreImporter::CreateAssimpSkeleton(const std::vector &Bones, const st //...and fill them for(unsigned int k=0; kRotationAngle, CurBone->RotationAxis, t3) - * aiMatrix4x4::Translation(CurBone->Position, t2); - //The defautl bone pose doesnt have a scaling value + //Create a matrix to transfrom a vector from the bones default pose to the bone bones in this animation key + aiMatrix4x4 PoseToKey=aiMatrix4x4::Scaling(Animations[i].Tracks[j].Keyframes[k].Scaling, t2) //scale + * aiMatrix4x4(Animations[i].Tracks[j].Keyframes[k].Rotation.GetMatrix()) //rot + * aiMatrix4x4::Translation(Animations[i].Tracks[j].Keyframes[k].Position, t3); //pos + //calculate the complete transformation from world space to bone space aiMatrix4x4 CompleteTransform=DefBonePose * PoseToKey; @@ -702,6 +732,8 @@ void OgreImporter::CreateAssimpSkeleton(const std::vector &Bones, const st m_CurrentScene->mAnimations[i]=NewAnimation; } } +//TODO: Auf nicht vorhandene Animationskeys achten! +#pragma warning (s.o.) //__________________________________________________________________ }