#ifndef EZ3D_TRIMESH_H #define EZ3D_TRIMESH_H #include #include #include "triangle.h" /* An indexed triangle mesh in memory. Vertices are deduplicated by exact * float32 equality -- legitimate because the mesher generates every copy * of a shared corner from the same vertex grid, so coordinates that should * match match bit-for-bit. Vertex ids are stable for the mesh's lifetime * (append-only array), which the decimator relies on. */ typedef struct { vertex_t *v; /* nv structs, which is nv * 3 floats */ triangle_t *tri; /* ntri structs, which is ntri * 3 vertex ids */ size_t nv, ntri; size_t capv, captri; /* dedup hash: bucket chains over stable vertex ids */ uint32_t *buckets; uint32_t *next; size_t nbuckets; } trimesh_t; void tm_init(trimesh_t *m); void tm_free(trimesh_t *m); /* * Return the id of the vertex at (v->x, v->y, v->z), appending it if new. */ uint32_t tm_vertex(trimesh_t *m, const vertex_t *v); /* Append a vertex unconditionally, no dedup, and return its id. Used by * the decimator's compaction: survivors must keep distinct ids even when * two of them happened to land on identical coordinates, otherwise two * triangle fans get glued into a non-manifold point. */ uint32_t tm_append(trimesh_t *m, const vertex_t *v); /* Append a triangle by vertex ids (no dedup -- ids must be valid). */ void tm_tri(trimesh_t *m, const triangle_t *t); #endif /* EZ3D_TRIMESH_H */