From 6c67ef3da0e5e9fb45b2166ce90655e14530c1a0 Mon Sep 17 00:00:00 2001 From: Chris Sinclair Date: Tue, 23 Feb 2021 17:10:30 +0000 Subject: [PATCH] Add support for u8 bone indicies when loading glTF --- src/models.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/models.c b/src/models.c index 5c54902a9..695935cea 100644 --- a/src/models.c +++ b/src/models.c @@ -3879,7 +3879,28 @@ static Model LoadGLTF(const char *fileName) short* bones = RL_MALLOC(sizeof(short) * acc->count * 4); LOAD_ACCESSOR(short, 4, acc, bones); - for (unsigned int a = 0; a < acc->count * 4; a ++) + for (unsigned int a = 0; a < acc->count * 4; a++) + { + cgltf_node* skinJoint = data->skins->joints[bones[a]]; + + for (unsigned int k = 0; k < data->nodes_count; k++) + { + if (&(data->nodes[k]) == skinJoint) + { + model.meshes[primitiveIndex].boneIds[a] = k; + break; + } + } + } + RL_FREE(bones); + } + else if (acc->component_type == cgltf_component_type_r_8u) + { + model.meshes[primitiveIndex].boneIds = RL_MALLOC(sizeof(int) * acc->count * 4); + unsigned char* bones = RL_MALLOC(sizeof(unsigned char) * acc->count * 4); + + LOAD_ACCESSOR(unsigned char, 4, acc, bones); + for (unsigned int a = 0; a < acc->count * 4; a++) { cgltf_node* skinJoint = data->skins->joints[bones[a]];