From 8058d66a68327055e409abc3544476acafb974ea Mon Sep 17 00:00:00 2001 From: Paul Melis Date: Tue, 4 Jun 2024 21:59:57 +0200 Subject: [PATCH] Update processing of gltf mesh animation data, to match earlier changes to vertex/normal/tangent data --- src/rmodels.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/rmodels.c b/src/rmodels.c index 18a7e1ac2..492320e58 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -5465,22 +5465,27 @@ static Model LoadGLTF(const char *fileName) TRACELOG(LOG_ERROR, "MODEL: [%s] can only load one skin (armature) per model, but gltf skins_count == %i", fileName, data->skins_count); } - // XXX this is currently broken, due to the changes above - - for (unsigned int i = 0, meshIndex = 0; i < data->meshes_count; i++) + meshIndex = 0; + for (unsigned int i = 0; i < data->nodes_count; i++) { - for (unsigned int p = 0; p < data->meshes[i].primitives_count; p++) + cgltf_node *node = &(data->nodes[i]); + + cgltf_mesh *mesh = node->mesh; + if (!mesh) + continue; + + for (unsigned int p = 0; p < mesh->primitives_count; p++) { // NOTE: We only support primitives defined by triangles - if (data->meshes[i].primitives[p].type != cgltf_primitive_type_triangles) continue; + if (mesh->primitives[p].type != cgltf_primitive_type_triangles) continue; - for (unsigned int j = 0; j < data->meshes[i].primitives[p].attributes_count; j++) + for (unsigned int j = 0; j < mesh->primitives[p].attributes_count; j++) { // NOTE: JOINTS_1 + WEIGHT_1 will be used for +4 joints influencing a vertex -> Not supported by raylib - if (data->meshes[i].primitives[p].attributes[j].type == cgltf_attribute_type_joints) // JOINTS_n (vec4: 4 bones max per vertex / u8, u16) + if (mesh->primitives[p].attributes[j].type == cgltf_attribute_type_joints) // JOINTS_n (vec4: 4 bones max per vertex / u8, u16) { - cgltf_accessor *attribute = data->meshes[i].primitives[p].attributes[j].data; + cgltf_accessor *attribute = mesh->primitives[p].attributes[j].data; // NOTE: JOINTS_n can only be vec4 and u8/u16 // SPECS: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes-overview @@ -5528,9 +5533,9 @@ static Model LoadGLTF(const char *fileName) } else TRACELOG(LOG_WARNING, "MODEL: [%s] Joint attribute data format not supported", fileName); } - else if (data->meshes[i].primitives[p].attributes[j].type == cgltf_attribute_type_weights) // WEIGHTS_n (vec4, u8n/u16n/f32) + else if (mesh->primitives[p].attributes[j].type == cgltf_attribute_type_weights) // WEIGHTS_n (vec4, u8n/u16n/f32) { - cgltf_accessor *attribute = data->meshes[i].primitives[p].attributes[j].data; + cgltf_accessor *attribute = mesh->primitives[p].attributes[j].data; if (attribute->type == cgltf_type_vec4) {