stl/stl.h
josh ffe4f07ace stl: added the beginning of a viewer
git-svn-id: svn://anubis/misc/stl@5 bd8a9e45-a331-0410-811e-c64571078777
2007-06-03 02:38:40 +00:00

45 lines
915 B
C

/*
* stl.h
* Author: Josh Holtrop
* Date: 2007-06-02
* From information at http://en.wikipedia.org/wiki/STL_(file_format)
*/
#ifdef __cplusplus
extern "C" {
#endif
/* macros */
#define STL_HEADER_LENGTH 80
#define stl_num_faces(stlp) ((stlp)->n_faces)
#define stl_face(stlp,facenum) ((stlp)->faces[(facenum)])
#define stl_attr_color_valid(attr) ((attr) & 0x8000)
#define stl_attr_color_r(attr) (((attr) & 0x7C00) >> 7)
#define stl_attr_color_g(attr) (((attr) & 0x03E0) >> 2)
#define stl_attr_color_b(attr) (((attr) & 0x001F) << 3)
/* types */
typedef struct stl_face_s
{
float normal[3];
float vertices[3][3];
unsigned short attribute;
} __attribute__ ((packed)) stl_face_t;
typedef struct stl_s
{
char header[STL_HEADER_LENGTH];
unsigned int n_faces;
stl_face_t faces[1];
} __attribute__ ((packed)) stl_t;
/* functions */
stl_t * stl_load(const char * filename);
#ifdef __cplusplus
}
#endif