From d38deeef3af2316a666f8fc0173940bd769b748e Mon Sep 17 00:00:00 2001 From: onelin Date: Sat, 1 Nov 2025 00:55:42 +0100 Subject: 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. --- src/model.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/model.c (limited to 'src/model.c') 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 +#include +#include +#include +#include +#include + +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; + } +} -- cgit v1.3