More cleanup

main
noah metz 2024-01-11 21:45:30 -07:00
parent 69ad926976
commit f76df2b222
3 changed files with 48 additions and 3 deletions

@ -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

@ -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");
}

@ -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) {