commit 17718c31beb6c6872c03ba59b54e3ceda7eade08
parent 78211c56742c8117f183c745b08db73933da329b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 3 Jul 2025 14:16:51 +0200
Add desc API to facilitate access to mesh data
Diffstat:
| M | src/sstl.h | | | 50 | ++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 50 insertions(+), 0 deletions(-)
diff --git a/src/sstl.h b/src/sstl.h
@@ -162,6 +162,56 @@ sstl_get_desc
struct sstl_desc* desc);
/*******************************************************************************
+ * Descriptor API. This is a set of help functions for retrieving mesh data from
+ * their raw representation.
+ ******************************************************************************/
+static INLINE res_T
+sstl_desc_get_triangle_ids
+ (const struct sstl_desc* desc,
+ const size_t itri,
+ unsigned ids[3])
+{
+ if(!desc || !ids || itri >= desc->triangles_count) return RES_BAD_ARG;
+ ids[0] = desc->indices[itri*3/*#ids per triangle*/ + 0];
+ ids[1] = desc->indices[itri*3/*#ids per triangle*/ + 1];
+ ids[2] = desc->indices[itri*3/*#ids per triangle*/ + 2];
+ return RES_OK;
+}
+
+static INLINE res_T
+sstl_desc_get_vertex_coords
+ (const struct sstl_desc* desc,
+ const size_t ivtx,
+ float coords[3])
+{
+ if(!desc || !coords || ivtx >= desc->vertices_count) return RES_BAD_ARG;
+ coords[0] = desc->vertices[ivtx*3/*#coords per vertex*/ + 0];
+ coords[1] = desc->vertices[ivtx*3/*#coords per vertex*/ + 1];
+ coords[2] = desc->vertices[ivtx*3/*#coords per vertex*/ + 2];
+ return RES_OK;
+}
+
+static INLINE res_T
+sstl_desc_get_facet
+ (const struct sstl_desc* desc,
+ const size_t itri,
+ struct sstl_facet* facet)
+{
+ unsigned ids[3] = {0,0,0};
+
+ if(!desc || !facet || itri >= desc->triangles_count) return RES_BAD_ARG;
+
+ #define CALL(Func) {res_T res; if((res = Func) != RES_OK) return res;} (void)0
+ CALL(sstl_desc_get_triangle_ids(desc, itri, ids));
+ CALL(sstl_desc_get_vertex_coords(desc, ids[0], facet->vertices[0]));
+ CALL(sstl_desc_get_vertex_coords(desc, ids[1], facet->vertices[1]));
+ CALL(sstl_desc_get_vertex_coords(desc, ids[2], facet->vertices[2]));
+ #undef CALL
+
+ return RES_OK;
+}
+
+/*******************************************************************************
* Writer API
******************************************************************************/
SSTL_API res_T