summaryrefslogtreecommitdiffhomepage
path: root/src/rmodels.c
diff options
context:
space:
mode:
authorPencilAmazing <[email protected]>2023-01-23 13:55:02 -0500
committerGitHub <[email protected]>2023-01-23 19:55:02 +0100
commit542ef8904a2ce9d87ab53289026da7a715907b87 (patch)
treea8b059458d047621189a09ae4bffac72c1fd5a81 /src/rmodels.c
parent393a03a46eec038d49606ef5f3459621decb27b9 (diff)
downloadraylib-542ef8904a2ce9d87ab53289026da7a715907b87.tar.gz
raylib-542ef8904a2ce9d87ab53289026da7a715907b87.zip
[models] Load bone names from IQM file if available (#2882)
* Load bone names from IQM file if available * Formatting and default bone name
Diffstat (limited to 'src/rmodels.c')
-rw-r--r--src/rmodels.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/rmodels.c b/src/rmodels.c
index 80ea9164..78219a70 100644
--- a/src/rmodels.c
+++ b/src/rmodels.c
@@ -4450,6 +4450,12 @@ static ModelAnimation *LoadModelAnimationsIQM(const char *fileName, unsigned int
unsigned int num_extensions, ofs_extensions;
} IQMHeader;
+ typedef struct IQMJoint {
+ unsigned int name;
+ int parent;
+ float translate[3], rotate[4], scale[3];
+ } IQMJoint;
+
typedef struct IQMPose {
int parent;
unsigned int mask;
@@ -4503,6 +4509,10 @@ static ModelAnimation *LoadModelAnimationsIQM(const char *fileName, unsigned int
//fread(framedata, iqmHeader->num_frames*iqmHeader->num_framechannels*sizeof(unsigned short), 1, iqmFile);
memcpy(framedata, fileDataPtr + iqmHeader->ofs_frames, iqmHeader->num_frames*iqmHeader->num_framechannels*sizeof(unsigned short));
+ // joints
+ IQMJoint *joints = RL_MALLOC(iqmHeader->num_joints*sizeof(IQMJoint));
+ memcpy(joints, fileDataPtr + iqmHeader->ofs_joints, iqmHeader->num_joints*sizeof(IQMJoint));
+
for (unsigned int a = 0; a < iqmHeader->num_anims; a++)
{
animations[a].frameCount = anim[a].num_frames;
@@ -4513,7 +4523,11 @@ static ModelAnimation *LoadModelAnimationsIQM(const char *fileName, unsigned int
for (unsigned int j = 0; j < iqmHeader->num_poses; j++)
{
- strcpy(animations[a].bones[j].name, "ANIMJOINTNAME");
+ // If animations and skeleton are in the same file, copy bone names to anim
+ if (iqmHeader->num_joints > 0)
+ memcpy(animations[a].bones[j].name, fileDataPtr + iqmHeader->ofs_text + joints[j].name, BONE_NAME_LENGTH*sizeof(char));
+ else
+ strcpy(animations[a].bones[j].name, "ANIMJOINTNAME"); // default bone name otherwise
animations[a].bones[j].parent = poses[j].parent;
}
@@ -4627,6 +4641,7 @@ static ModelAnimation *LoadModelAnimationsIQM(const char *fileName, unsigned int
RL_FREE(fileData);
+ RL_FREE(joints);
RL_FREE(framedata);
RL_FREE(poses);
RL_FREE(anim);