star-stl

Load STereo Lithography (StL) file format
git clone git://git.meso-star.fr/star-stl.git
Log | Files | Refs | README | LICENSE

commit 02e464ffbac121460de72b4984b0bd0e85e58705
parent 03c2c7eb393ce5f14445e2f7ff10cd0e91d20154
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Fri, 21 Feb 2025 15:57:39 +0100

Add information of the read data format in data descriptor

Diffstat:
Msrc/sstl.c | 11+++++++----
Msrc/sstl.h | 15+++++++++++----
2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/sstl.c b/src/sstl.c @@ -49,8 +49,9 @@ struct solid { unsigned* indices; float* vertices; float* normals; + enum sstl_read_type read_type; }; -static const struct solid SOLID_NULL = { NULL, NULL, NULL, NULL }; +static const struct solid SOLID_NULL = { NULL, NULL, NULL, NULL, 0 }; struct streamer { FILE* stream; @@ -535,6 +536,7 @@ load_ascii_stream } /* Register the solid */ + solid.read_type = SSTL_ASCII; sstl->solid = solid; exit: @@ -615,6 +617,7 @@ load_binary_stream } /* Register the solid */ + solid.read_type = SSTL_BINARY; sstl->solid = solid; exit: @@ -710,7 +713,7 @@ get_sstl_triangle_normal float normal[3]) { res_T res = RES_OK; - const struct sstl* sstl = (struct sstl*)data; + struct sstl* sstl = (struct sstl*)data; struct sstl_desc desc; if(!sstl || !normal) { @@ -740,7 +743,7 @@ get_sstl_triangle_vertices float vtx[3][3]) { res_T res = RES_OK; - const struct sstl* sstl = (struct sstl*)data; + struct sstl* sstl = (struct sstl*)data; struct sstl_desc desc; unsigned n; @@ -1008,7 +1011,7 @@ sstl_load_stream(struct sstl* sstl, FILE* stream) } res_T -sstl_get_desc(const struct sstl* sstl, struct sstl_desc* desc) +sstl_get_desc(struct sstl* sstl, struct sstl_desc* desc) { if(!sstl || !desc) return RES_BAD_ARG; desc->solid_name = sstl->solid.name; diff --git a/src/sstl.h b/src/sstl.h @@ -36,14 +36,21 @@ #define SSTL(Func) sstl_ ## Func #endif +/* The type of a read file */ +enum sstl_read_type { + SSTL_ASCII = 1, + SSTL_BINARY = 2 +}; + /* Descriptor of a loaded STL */ struct sstl_desc { const char* solid_name; /* May be NULL <=> no name */ + enum sstl_read_type read_type; /* The type of the file */ /* Front faces are CCW ordered and the normals follow the right handed rule */ - const float* vertices; /* triangles_count * 3 coordinates */ - const unsigned* indices; /* triangles_count * 3 indices */ - const float* normals; /* Per triangle normalized normal */ + float* vertices; /* triangles_count * 3 coordinates */ + unsigned* indices; /* triangles_count * 3 indices */ + float* normals; /* Per triangle normalized normal */ size_t triangles_count; size_t vertices_count; @@ -152,7 +159,7 @@ sstl_write_stream /* The returned descriptor is valid until a new load process */ SSTL_API res_T sstl_get_desc - (const struct sstl* sstl, + (struct sstl* sstl, struct sstl_desc* desc); END_DECLS