diff options
| author | 0scar <qgt268@alumni.ku.dk> | 2024-03-01 07:17:34 +0000 |
|---|---|---|
| committer | 0scar <qgt268@alumni.ku.dk> | 2024-03-01 07:17:34 +0000 |
| commit | 5734711ff991c9ee8742925f75c11aeb108e0b5e (patch) | |
| tree | 5086e6780f2260b9de93d9b9554a284e8551becf /src/resources | |
| parent | 424d21e100af255e51e9f2d8442e80df2f701391 (diff) | |
Tidy up model loading
Diffstat (limited to 'src/resources')
| -rw-r--r-- | src/resources/src/model.c | 49 |
1 files changed, 28 insertions, 21 deletions
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 <engine/engine.h> #include <engine/core/logging.h> #include <engine/resources/model.h> +#include <assimp/cimport.h> +#include <assimp/scene.h> +#include <assimp/postprocess.h> 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}; - //} + 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( pFile, - // aiProcess_CalcTangentSpace | - // aiProcess_Triangulate | - // aiProcess_JoinIdenticalVertices | - // aiProcess_SortByPType); + // 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); - //// If the import failed, report it - //if( NULL == scene) { - // DoTheErrorLogging( aiGetErrorString()); - // return false; - //} + 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 = {}; |
