aboutsummaryrefslogtreecommitdiffstats
path: root/src/stlfile.h
blob: ae4bf363f8fb932f2ace3dcb0c42ab4516f4155c (plain) (blame)
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
#ifndef STLFILE_H
#define STLFILE_H

#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <endian.h>
#include <math.h>

#include "util.h"

#define FMT_ERR(...) ERR("FORMAT " __VA_ARGS__)

enum {
	KW_INVALID = -1,
	KW_UNKNOWN,
	KW_SOLID_BEGIN,
	KW_SOLID_END,
	KW_FACET_BEGIN,
	KW_FACET_END,
	KW_LOOP_BEGIN,
	KW_LOOP_END,
	KW_VERTEX
};

enum {
	STATE_SOLID,
	STATE_FACET,
	STATE_LOOP
};

enum {
	TYPE_ASCII,
	TYPE_BIN
};

struct stack {
	int *data;
	size_t count, cap;
};

struct parseinfo {
	char header[80], *hash, *modelname, *solidname;
	uint32_t loopcount;
	unsigned filesize;
	float bbmin[3], bbmax[3];
	int type, valid;
};

int parse_file(struct parseinfo *info, char *buf, size_t len);
int save_info(struct parseinfo *info, FILE *f);
int load_info(struct parseinfo *info, FILE *f);
void print_info(struct parseinfo *info);
void free_info(struct parseinfo *info);

#endif /* STLFILE_H */