From 5734711ff991c9ee8742925f75c11aeb108e0b5e Mon Sep 17 00:00:00 2001 From: 0scar Date: Fri, 1 Mar 2024 08:17:34 +0100 Subject: Tidy up model loading --- src/resources/src/model.c | 53 +++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 23 deletions(-) (limited to 'src/resources') diff --git a/src/resources/src/model.c b/src/resources/src/model.c index 893036a..3c3ee83 100644 --- a/src/resources/src/model.c +++ b/src/resources/src/model.c @@ -1,5 +1,9 @@ +#include #include #include +#include +#include +#include Model load_model(const Asset_ModelSpec *restrict ms) { ModelType format = Model_error; @@ -19,33 +23,36 @@ Model load_model(const Asset_ModelSpec *restrict ms) { // For now, just default to obj format = Model_obj; - //FILE* f = fopen(ms->path, "r"); - //if (f == NULL) { - // ERROR("Failed to load file " TERM_COLOR_YELLOW "%s" TERM_COLOR_RESET, ms->path); - // return (Model){.format = format}; - //} - - //// Start the import on the given file with some example postprocessing - //// Usually - if speed is not the most important aspect for you - you'll t - //// probably to request more postprocessing than we do in this example. - //const struct aiScene* scene = aiImportFile( pFile, - // aiProcess_CalcTangentSpace | - // aiProcess_Triangulate | - // aiProcess_JoinIdenticalVertices | - // aiProcess_SortByPType); - - //// If the import failed, report it - //if( NULL == scene) { - // DoTheErrorLogging( aiGetErrorString()); - // return false; - //} + FILE* f = fopen(ms->path, "r"); + if (f == NULL) { + ERROR("Failed to load file " TERM_COLOR_YELLOW "%s" TERM_COLOR_RESET, ms->path); + return (Model){.format = format}; + } + const isize filesz = f_get_sz(f); + char* filecontets = calloc(filesz, sizeof(char)); + fread(filecontets, sizeof(char), filesz, f); + + // Start the import on the given file with some example postprocessing + // Usually - if speed is not the most important aspect for you - you'll t + // probably to request more postprocessing than we do in this example. + const struct aiScene* scene = aiImportFile( filecontets, + aiProcess_CalcTangentSpace | + aiProcess_Triangulate | + aiProcess_JoinIdenticalVertices | + aiProcess_SortByPType); + + free(filecontets); + // If the import failed, report it + if( NULL == scene) { + ERROR("Failed to import %s: %s", ms->path, aiGetErrorString()); + return (Model){.format = format}; + } //// Now we can access the file's contents - //DoTheSceneProcessing( scene); + //DoTheSceneProcessing(scene); //// We're done. Release all resources associated with this import - //aiReleaseImport( scene); - //return true; + aiReleaseImport(scene); { Model m = {}; -- cgit v1.3