summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/resources/src/model.c49
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 = {};