Browse Source

Review LoadGLTF() to read from memory buffer

pull/1233/head
raysan5 4 years ago
parent
commit
4ca4326bf9
1 changed files with 5 additions and 17 deletions
  1. +5
    -17
      src/models.c

+ 5
- 17
src/models.c View File

@ -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;
}

Loading…
Cancel
Save