From f76df2b2220fe8e0bebe4730720e01a50703c09e Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Thu, 11 Jan 2024 21:45:30 -0700 Subject: [PATCH] More cleanup --- include/ply.h | 23 ++++++++++++++++++++++- src/main.c | 2 +- src/ply.c | 26 +++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/include/ply.h b/include/ply.h index 4c0c9c0..0ec54c0 100644 --- a/include/ply.h +++ b/include/ply.h @@ -61,12 +61,33 @@ typedef struct PlyMeshStruct { uint16_t* index; } PlyMesh; +typedef struct PlyMappingsStruct { + char* vertex_element; + char* x; + char* y; + char* z; + char* nx; + char* ny; + char* nz; + char* r; + char* g; + char* b; + char* a; + char* u; + char* v; + + char* face_element; + char* index; +} PlyMappings; + +extern PlyMappings default_ply_mappings; + extern const char* const ply_formats[]; extern const char* const ply_header_items[]; extern const char* const ply_type_strings[]; extern const size_t ply_type_sizes[]; -PlyMesh ply_load_mesh(char* filename); +PlyMesh ply_load_mesh(char* filename, PlyMappings mappings); void ply_free_elements(PlyElement* elements_head); #endif diff --git a/src/main.c b/src/main.c index a727609..a997216 100644 --- a/src/main.c +++ b/src/main.c @@ -3372,7 +3372,7 @@ void cleanup(GLFWwindow* window, VulkanContext* context) { } int main() { - PlyMesh monkey = ply_load_mesh("monkey.ply"); + PlyMesh monkey = ply_load_mesh("monkey.ply", default_ply_mappings); if(monkey.position == 0) { fprintf(stderr, "failed to load %s\n", "monkey.ply"); } diff --git a/src/ply.c b/src/ply.c index fab3e85..90c612e 100644 --- a/src/ply.c +++ b/src/ply.c @@ -90,7 +90,25 @@ void ply_free_elements(PlyElement* elements_head) { } } -PlyMesh ply_load_mesh(char* filename) { +PlyMappings default_ply_mappings = { + .vertex_element = "vertex", + .x = "x", + .y = "y", + .z = "z", + .nx = "nx", + .ny = "ny", + .nz = "nz", + .r = "red", + .g = "green", + .b = "blue", + .a = "alpha", + .u = "s", + .v = "t", + .face_element = "face", + .index = "vetex_indices", +}; + +PlyMesh ply_load_mesh(char* filename, PlyMappings mappings) { PlyMesh mesh = { .vertex_count = 0, .position = NULL, @@ -245,6 +263,12 @@ PlyMesh ply_load_mesh(char* filename) { PlyElement* elem = elements_head; while(elem != NULL) { + if(strcmp(elem->name, mappings.vertex_element) == 0) { + + } else if(strcmp(elem->name, mappings.face_element) == 0) { + + } + PlyProperty* prop = elem->properties; while(prop != NULL) { if(prop->count == PLY_TYPE_INVALID) {