write index of parent joint instead of just the parent joint name. some MeshJoint member naming changes for clarity
This commit is contained in:
parent
646092676a
commit
6147cb3f81
|
@ -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<MeshJointKeyFrame> JointKeyFrames;
|
||||
|
||||
int32_t GetIndexOf(const std::vector<MeshJoint> &joints, const std::string &name);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -229,19 +229,17 @@ void WriteJoints(const std::vector<MeshJoint> &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> &jointKeyFrames, FILE
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int32_t GetIndexOf(const std::vector<MeshJoint> &joints, const std::string &name)
|
||||
{
|
||||
for (uint32_t i = 0; i < joints.size(); ++i)
|
||||
{
|
||||
if (joints[i].name == name)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Reference in a new issue