2
2
#include "dbg.h"
3
3
4
4
#include "commands.h"
5
- #include "stl .h"
5
+ #include "mesh .h"
6
6
#include "bsp.h"
7
7
#include "export.h"
8
8
@@ -12,39 +12,39 @@ typedef bsp_node_t* (*bsp_binary_op)(bsp_node_t *, bsp_node_t *);
12
12
// in `path1` and `path1` defined by an operation `op` from` bsp.h
13
13
// Result is freshly allocated, and needs to be freed with `free_bsp_tree()`
14
14
bsp_node_t * bsp_binary_operation (char * path1 , char * path2 , bsp_binary_op op ) {
15
- stl_object * file1 = NULL ;
15
+ mesh_t * file1 = NULL ;
16
16
bsp_node_t * bsp1 = NULL ;
17
17
18
- stl_object * file2 = NULL ;
18
+ mesh_t * file2 = NULL ;
19
19
bsp_node_t * bsp2 = NULL ;
20
20
21
21
bsp_node_t * result = NULL ;
22
22
23
23
// Read 1
24
- file1 = stl_read_file (path1 , 1 );
25
- check (file1 != NULL , "Failed to read .stl from '%s'" , path1 );
26
- log_info ("Loaded file: %s %d facets" , path1 , file1 -> facet_count );
27
- bsp1 = stl_to_bsp (file1 );
24
+ file1 = mesh_read_file (path1 );
25
+ check (file1 != NULL , "Failed to read mesh from '%s'" , path1 );
26
+ log_info ("Loaded file: %s %d facets" , path1 , file1 -> poly_count ( file1 ) );
27
+ bsp1 = mesh_to_bsp (file1 );
28
28
check_mem (bsp1 );
29
29
30
30
// Read 2
31
- file2 = stl_read_file (path2 , 1 );
32
- check (file2 != NULL , "Failed to read .stl from '%s'" , path2 );
33
- log_info ("Loaded file: %s %d facets" , path2 , file2 -> facet_count );
34
- bsp2 = stl_to_bsp (file2 );
31
+ file2 = mesh_read_file (path2 );
32
+ check (file2 != NULL , "Failed to read mesh from '%s'" , path2 );
33
+ log_info ("Loaded file: %s %d facets" , path2 , file2 -> poly_count ( file2 ) );
34
+ bsp2 = mesh_to_bsp (file2 );
35
35
check_mem (bsp2 );
36
36
37
37
// Operate
38
38
result = op (bsp1 , bsp2 );
39
39
40
- if (file1 != NULL ) stl_free (file1 );
41
- if (file2 != NULL ) stl_free (file2 );
40
+ if (file1 != NULL ) file1 -> destroy (file1 );
41
+ if (file2 != NULL ) file2 -> destroy (file2 );
42
42
if (bsp1 != NULL ) free_bsp_tree (bsp1 );
43
43
if (bsp2 != NULL ) free_bsp_tree (bsp2 );
44
44
return result ;
45
45
error :
46
- if (file1 != NULL ) stl_free (file1 );
47
- if (file2 != NULL ) stl_free (file2 );
46
+ if (file1 != NULL ) file1 -> destroy (file1 );
47
+ if (file2 != NULL ) file2 -> destroy (file2 );
48
48
if (bsp1 != NULL ) free_bsp_tree (bsp1 );
49
49
if (bsp2 != NULL ) free_bsp_tree (bsp2 );
50
50
if (result != NULL ) free_bsp_tree (result );
@@ -61,23 +61,23 @@ bsp_node_t* bsp_binary_operation(char *path1, char *path2, bsp_binary_op op) {
61
61
#define MAKE_CSG_COMMAND (name ) \
62
62
int cmd_##name(int argc, char **argv) { \
63
63
bsp_node_t *result = NULL; \
64
- stl_object *out = NULL; \
64
+ mesh_t *out = NULL; \
65
65
char *out_path = "./out.stl"; \
66
66
\
67
67
check(argc >= 2, "At least two input files required."); \
68
68
if(argc > 2) out_path = argv[2]; \
69
69
\
70
- result = bsp_binary_operation(argv[0], argv[1], bsp_##name); \
71
- out = bsp_to_stl(result); \
70
+ result = bsp_binary_operation(argv[0], argv[1], bsp_##name); \
71
+ check(result != NULL, "Binary operation" #name "failed."); \
72
+ out = NEW(bsp_mesh_t, "BSP", result); \
72
73
log_info("Writing output to %s", out_path); \
73
- check(stl_write_file (out, out_path) == 0, "Failed to write STL to %s", out_path); \
74
+ check(out->write (out, out_path) == 0, "Failed to write STL to %s", out_path); \
74
75
\
75
- if(result != NULL) free_bsp_tree(result); \
76
- if(out != NULL) stl_free(out); \
76
+ out->destroy(out); \
77
77
return 0; \
78
78
error: \
79
- if(result != NULL) free_bsp_tree(result); \
80
- if(out != NULL) stl_free(out); \
79
+ if(out != NULL) out->destroy(out); \
80
+ else if(result != NULL) free_bsp_tree(result); \
81
81
return -1; \
82
82
}
83
83
0 commit comments