From 4ca4326bf94cfbeb5c87fa0eb71c4d4a6646c8fe Mon Sep 17 00:00:00 2001 From: raysan5 Date: Thu, 30 Apr 2020 19:51:57 +0200 Subject: [PATCH] Review LoadGLTF() to read from memory buffer --- src/models.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/models.c b/src/models.c index 2629ea70..8b013ea5 100644 --- a/src/models.c +++ b/src/models.c @@ -3521,27 +3521,15 @@ static Model LoadGLTF(const char *fileName) Model model = { 0 }; // glTF file loading - FILE *gltfFile = fopen(fileName, "rb"); + unsigned int dataSize = 0; + unsigned char *fileData = LoadFileData(fileName, &dataSize); - if (gltfFile == NULL) - { - TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to open glTF file", fileName); - return model; - } - - fseek(gltfFile, 0, SEEK_END); - int size = ftell(gltfFile); - fseek(gltfFile, 0, SEEK_SET); - - void *buffer = RL_MALLOC(size); - fread(buffer, size, 1, gltfFile); - - fclose(gltfFile); + if (fileData == NULL) return model; // glTF data loading cgltf_options options = { 0 }; cgltf_data *data = NULL; - cgltf_result result = cgltf_parse(&options, buffer, size, &data); + cgltf_result result = cgltf_parse(&options, fileData, dataSize, &data); if (result == cgltf_result_success) { @@ -3713,7 +3701,7 @@ static Model LoadGLTF(const char *fileName) } else TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to load glTF data", fileName); - RL_FREE(buffer); + RL_FREE(fileData); return model; }