work save : glTF scene support

This commit is contained in:
royqh1979@gmail.com 2022-01-21 12:09:11 +08:00
parent 3c359ff4bc
commit b265ded584
4 changed files with 5872 additions and 547 deletions

File diff suppressed because it is too large Load Diff

View File

@ -732,6 +732,7 @@ typedef struct cgltf_data
cgltf_scene* scenes; cgltf_scene* scenes;
cgltf_size scenes_count; cgltf_size scenes_count;
unsigned int scene_id;
cgltf_scene* scene; cgltf_scene* scene;
cgltf_animation* animations; cgltf_animation* animations;
@ -5758,7 +5759,8 @@ static int cgltf_parse_json_root(cgltf_options* options, jsmntok_t const* tokens
else if (cgltf_json_strcmp(tokens + i, json_chunk, "scene") == 0) else if (cgltf_json_strcmp(tokens + i, json_chunk, "scene") == 0)
{ {
++i; ++i;
out_data->scene = CGLTF_PTRINDEX(cgltf_scene, cgltf_json_to_int(tokens + i, json_chunk)); out_data->scene_id = cgltf_json_to_int(tokens + i, json_chunk);
out_data->scene = CGLTF_PTRINDEX(cgltf_scene, out_data->scene_id);
++i; ++i;
} }
else if (cgltf_json_strcmp(tokens + i, json_chunk, "animations") == 0) else if (cgltf_json_strcmp(tokens + i, json_chunk, "animations") == 0)

View File

@ -366,6 +366,13 @@ typedef struct Transform {
Vector3 scale; // Scale Vector3 scale; // Scale
} Transform; } Transform;
//Scene
typedef struct Scene {
int meshCount; // Number of meshes
int *meshes; // Scene meshes array
Transform *meshTransforms; // transform matrices for meshes
} Scene;
// Bone, skeletal animation bone // Bone, skeletal animation bone
typedef struct BoneInfo { typedef struct BoneInfo {
char name[32]; // Bone name char name[32]; // Bone name
@ -382,6 +389,11 @@ typedef struct Model {
Material *materials; // Materials array Material *materials; // Materials array
int *meshMaterial; // Mesh material number int *meshMaterial; // Mesh material number
// Scene data
int sceneCount; // Number of scenes
Scene *scenes; // Scenes array
int scene; // Scene should be displayed
// Animation data // Animation data
int boneCount; // Number of bones int boneCount; // Number of bones
BoneInfo *bones; // Bones information (skeleton) BoneInfo *bones; // Bones information (skeleton)

View File

@ -4649,6 +4649,7 @@ static Model LoadGLTF(const char *fileName)
TRACELOG(LOG_DEBUG, " > Buffers count: %i", data->buffers_count); TRACELOG(LOG_DEBUG, " > Buffers count: %i", data->buffers_count);
TRACELOG(LOG_DEBUG, " > Images count: %i", data->images_count); TRACELOG(LOG_DEBUG, " > Images count: %i", data->images_count);
TRACELOG(LOG_DEBUG, " > Textures count: %i", data->textures_count); TRACELOG(LOG_DEBUG, " > Textures count: %i", data->textures_count);
TRACELOG(LOG_DEBUG, " > Scenes count: %1", data->scenes_count);
// Force reading data buffers (fills buffer_view->buffer->data) // Force reading data buffers (fills buffer_view->buffer->data)
// NOTE: If an uri is defined to base64 data or external path, it's automatically loaded -> TODO: Verify this assumption // NOTE: If an uri is defined to base64 data or external path, it's automatically loaded -> TODO: Verify this assumption
@ -4943,6 +4944,22 @@ static Model LoadGLTF(const char *fileName)
} }
} }
// Load scene data
if (data->scenes_count > 0) {
model.scene = data->scene_id;
model.scenes = (Scene *)malloc(sizeof(Scene) * data->scenes_count);
memset(model.scenes, 0, sizeof(Scene) * data->scenes_count);
for (unsigned int i = 0; i < data->scenes_count; i++) {
// TODO: for each nodes, find
if (data->scenes[i].nodes_count>0) {
for (unsigned int j = 0; j < data->scenes[i].nodes_count; j++) {
scenes
}
}
}
}
/* /*
// TODO: Load glTF meshes animation data // TODO: Load glTF meshes animation data
// REF: https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#skins // REF: https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#skins