diff options
Diffstat (limited to 'include/stl.h')
| -rw-r--r-- | include/stl.h | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/include/stl.h b/include/stl.h new file mode 100644 index 0000000..14ec11a --- /dev/null +++ b/include/stl.h @@ -0,0 +1,92 @@ +#pragma once + +#include <stdbool.h> +#include <stdlib.h> + +#define STL_BUFMAX 256 + +#define STL_STRERROR_INIT \ + [STL_OK] = "Success", \ + [STL_DONE] = "Done processing", \ + [STL_INVALID] = "Invalid stl file", \ + [STL_INVALID_ARG] = "Invalid argument", \ + [STL_INCOMPLETE] = "Unexpected end of file" \ + +enum { + STL_OK, + STL_DONE, + STL_INVALID, + STL_INVALID_ARG, + STL_INCOMPLETE, +}; + +enum { + STL_TYPE_DETECT, + STL_TYPE_ASCII, + STL_TYPE_BINARY, +}; + +enum { + STL_RES_SOLID_NAME, + STL_RES_HEADER, + STL_RES_TRIANGLE, + STL_RES_FILETYPE +}; + +struct stl_vertex { + union { + struct { + float x, y, z; + }; + struct { + float dim[3]; + }; + }; +}; + +struct stl_triangle { + struct stl_vertex vtx[3]; + struct stl_vertex normal; +}; + +struct stl_span { + const char *str; + size_t len; +}; + +struct stl_result { + int type; + union { + struct stl_span solid_name; + struct stl_span header; + struct stl_triangle tri; + int filetype; + }; +}; + +struct stl { + char buf[STL_BUFMAX]; + size_t buflen; + + const void *chunk; + const void *pos; + size_t nleft; + + struct stl_triangle tri; + + int type; + union { + struct { + int state; + } ascii; + struct { + int state; + size_t index; + size_t count; + } bin; + }; +}; + +void stl_init(struct stl *stl, int type); +int stl_feed(struct stl *stl, struct stl_result *res, + const void *chunk, size_t size); |
