diff options
| author | onelin <oscar@nelin.dk> | 2025-10-31 23:55:42 +0000 |
|---|---|---|
| committer | onelin <oscar@nelin.dk> | 2025-11-02 22:07:17 +0000 |
| commit | d38deeef3af2316a666f8fc0173940bd769b748e (patch) | |
| tree | 6e30d4a9eea18daa5705c894f28cd99ff047e8f9 /src/model.c | |
| parent | 6c077751982ea2c7bd2d9262b01b9f8602f80dc8 (diff) | |
Flatten project structure
This will make it easier to break up the code into smaller chunks again
later.
One would think doing this seems fun to me at this point.
Diffstat (limited to 'src/model.c')
| -rw-r--r-- | src/model.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/model.c b/src/model.c new file mode 100644 index 0000000..172c409 --- /dev/null +++ b/src/model.c @@ -0,0 +1,68 @@ +#include <daw/daw.h> +#include <daw/logging.h> +#include <daw/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; + + /* + isize vertices_len = 0; + vec3 *vertices = malloc(sizeof(vec3) * 512); + usize *vertices_idx = malloc(sizeof(usize) * 512); + + isize uvs_len = 0; + vec2 *uvs = malloc(sizeof(vec2) * 512); + usize *uvs_idx = malloc(sizeof(usize) * 512); + + isize normals_len = 0; + vec3 *normals = malloc(sizeof(vec3) * 512); + usize *normals_idx = malloc(sizeof(usize) * 512); + */ + + // 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}; + } + const usize 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); + + //// We're done. Release all resources associated with this import + aiReleaseImport(scene); + + { + Model m = {0}; + m.format = format; + + // TODO add index array + + return m; + } +} |
