-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstl.c
65 lines (50 loc) · 1 KB
/
stl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// stl.c - stereolithography mesh stuff
#include <stdio.h>
#include "math.h"
#include "stl.h"
//
typedef struct
{
vec3 normal, p1, p2, p3;
unsigned short aux;
} stlface_t;
//
unsigned int stl_datasize, num_stlfaces;
unsigned char stl_data[MAX_STLDATASIZE];
unsigned int *stl_numtrisptr = (unsigned int *)&stl_data[80];
//
void stl_new(char *header)
{
sprintf((char *)stl_data, "[ %s ]", header);
stl_datasize = 84;
num_stlfaces = 0;
}
//
// generate face normal, write face data to stl_data
void stl_face(vec3 p1, vec3 p2, vec3 p3)
{
stlface_t *face;
if(stl_datasize + 50 > MAX_STLDATASIZE)
{
print("stl_face: STL buffer overflow!");
return;
}
face = (stlface_t *)&stl_data[stl_datasize];
stl_datasize += 50; // unpadded size of stlface_t
// calculate normal
face->normal = vnormp(vcross(vsub(p1, p2), vsub(p3, p2)));
// write vertices
face->p1 = p1;
face->p2 = p2;
face->p3 = p3;
// etc..
face->aux = 0;
num_stlfaces++;
}
//
//
void stl_end()
{
*stl_numtrisptr = num_stlfaces;
}
//