From 6147cb3f813588f9ce547d5446aaa49243ce65cf Mon Sep 17 00:00:00 2001 From: gered Date: Tue, 3 May 2011 23:06:36 -0400 Subject: [PATCH] write index of parent joint instead of just the parent joint name. some MeshJoint member naming changes for clarity --- AssimpToMesh/src/convert/meshjoint.h | 8 +++-- AssimpToMesh/src/convert/meshutils.cpp | 32 ++++++++++++------- AssimpToMesh/src/convert/skeletalanimated.cpp | 5 ++- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/AssimpToMesh/src/convert/meshjoint.h b/AssimpToMesh/src/convert/meshjoint.h index 194ca82..a77101a 100644 --- a/AssimpToMesh/src/convert/meshjoint.h +++ b/AssimpToMesh/src/convert/meshjoint.h @@ -11,8 +11,10 @@ struct MeshJoint { std::string name; std::string parentName; - aiVector3D position; - aiQuaternion rotation; + aiVector3D localPosition; + aiQuaternion localRotation; + aiVector3D offsetPosition; + aiQuaternion offsetRotation; }; struct MeshJointKeyFrame @@ -23,4 +25,6 @@ struct MeshJointKeyFrame typedef std::vector JointKeyFrames; +int32_t GetIndexOf(const std::vector &joints, const std::string &name); + #endif diff --git a/AssimpToMesh/src/convert/meshutils.cpp b/AssimpToMesh/src/convert/meshutils.cpp index 151e0f6..bc1cfca 100644 --- a/AssimpToMesh/src/convert/meshutils.cpp +++ b/AssimpToMesh/src/convert/meshutils.cpp @@ -229,19 +229,17 @@ void WriteJoints(const std::vector &joints, FILE *fp) char c = '\0'; fwrite(&c, 1, 1, fp); - // haven't tried, but i have a feeling fwrite() won't like passing a length of 0 to be written - if (j->parentName.length() > 0) - fwrite(j->parentName.c_str(), j->parentName.length(), 1, fp); - fwrite(&c, 1, 1, fp); + int32_t parentIndex = GetIndexOf(joints, j->parentName); + fwrite(&parentIndex, 4, 1, fp); - fwrite(&j->position.x, sizeof(float), 1, fp); - fwrite(&j->position.y, sizeof(float), 1, fp); - fwrite(&j->position.z, sizeof(float), 1, fp); + fwrite(&j->localPosition.x, sizeof(float), 1, fp); + fwrite(&j->localPosition.y, sizeof(float), 1, fp); + fwrite(&j->localPosition.z, sizeof(float), 1, fp); - fwrite(&j->rotation.x, sizeof(float), 1, fp); - fwrite(&j->rotation.y, sizeof(float), 1, fp); - fwrite(&j->rotation.z, sizeof(float), 1, fp); - fwrite(&j->rotation.w, sizeof(float), 1, fp); + fwrite(&j->localRotation.x, sizeof(float), 1, fp); + fwrite(&j->localRotation.y, sizeof(float), 1, fp); + fwrite(&j->localRotation.z, sizeof(float), 1, fp); + fwrite(&j->localRotation.w, sizeof(float), 1, fp); } } @@ -300,3 +298,15 @@ void WriteJointKeyFrames(const std::vector &jointKeyFrames, FILE } } } + + +int32_t GetIndexOf(const std::vector &joints, const std::string &name) +{ + for (uint32_t i = 0; i < joints.size(); ++i) + { + if (joints[i].name == name) + return i; + } + + return -1; +} diff --git a/AssimpToMesh/src/convert/skeletalanimated.cpp b/AssimpToMesh/src/convert/skeletalanimated.cpp index 6a7b98d..aa4dbcc 100644 --- a/AssimpToMesh/src/convert/skeletalanimated.cpp +++ b/AssimpToMesh/src/convert/skeletalanimated.cpp @@ -95,7 +95,10 @@ void ConvertSkeletalAnimated(const std::string &outfile, const aiScene *scene) joint.parentName = ""; else joint.parentName = std::string(parentNode->mName.data, parentNode->mName.length); - node->mTransformation.DecomposeNoScaling(joint.rotation, joint.position); + + aiMatrix4x4 transform = node->mTransformation * bone->mOffsetMatrix; + node->mTransformation.DecomposeNoScaling(joint.localRotation, joint.localPosition); + bone->mOffsetMatrix.DecomposeNoScaling(joint.offsetRotation, joint.offsetPosition); // assumption: sum of all bone->mNumWeights is always == vertices.size() for (unsigned int k = 0; k < bone->mNumWeights; ++k)