-
Notifications
You must be signed in to change notification settings - Fork 1
/
carve-capi.h
164 lines (131 loc) · 6.14 KB
/
carve-capi.h
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2014 Blender Foundation.
* All rights reserved.
*
* Contributor(s): Blender Foundation,
* Sergey Sharybin
*
* ***** END GPL LICENSE BLOCK *****
*/
#ifndef __CARVE_CAPI_H__
#define __CARVE_CAPI_H__
#ifdef __cplusplus
extern "C" {
#endif
struct CarveMeshDescr;
//
// Importer from external storage to Carve module
//
struct ImportMeshData;
// Get number of vertices.
typedef int (*CarveImporter_GetNumVerts) (struct ImportMeshData *import_data);
// Get number of edges.
typedef int (*CarveImporter_GetNumEdges) (struct ImportMeshData *import_data);
// Get number of loops.
typedef int (*CarveImporter_GetNumLoops) (struct ImportMeshData *import_data);
// Get number of polys.
typedef int (*CarveImporter_GetNumPolys) (struct ImportMeshData *import_data);
// Get 3D coordinate of vertex with given index.
typedef void (*CarveImporter_GetVertCoord) (struct ImportMeshData *import_data, int vert_index, float coord[3]);
// Get index of vertices which are adjacent to edge specified by its index.
typedef void (*CarveImporter_GetEdgeVerts) (struct ImportMeshData *import_data, int edge_index, int *v1, int *v2);
// Get number of adjacent vertices to the poly specified by its index.
typedef int (*CarveImporter_GetPolyNumVerts) (struct ImportMeshData *import_data, int poly_index);
// Get list of adjacent vertices to the poly specified by its index.
typedef void (*CarveImporter_GetPolyVerts) (struct ImportMeshData *import_data, int poly_index, int *verts);
// Triangulate 2D polygon.
typedef int (*CarveImporter_Triangulate2DPoly) (struct ImportMeshData *import_data,
const float (*vertices)[2], int num_vertices,
unsigned int (*triangles)[3]);
typedef struct CarveMeshImporter {
CarveImporter_GetNumVerts getNumVerts;
CarveImporter_GetNumEdges getNumEdges;
CarveImporter_GetNumLoops getNumLoops;
CarveImporter_GetNumPolys getNumPolys;
CarveImporter_GetVertCoord getVertCoord;
CarveImporter_GetEdgeVerts getEdgeVerts;
CarveImporter_GetPolyNumVerts getNumPolyVerts;
CarveImporter_GetPolyVerts getPolyVerts;
CarveImporter_Triangulate2DPoly triangulate2DPoly;
} CarveMeshImporter;
//
// Exporter from Carve module to external storage
//
struct ExportMeshData;
// Initialize arrays for geometry.
typedef void (*CarveExporter_InitGeomArrays) (struct ExportMeshData *export_data,
int num_verts, int num_edges,
int num_loops, int num_polys);
// Set coordinate of vertex with given index.
typedef void (*CarveExporter_SetVert) (struct ExportMeshData *export_data,
int vert_index, float coord[3],
int which_orig_mesh, int orig_vert_index);
// Set vertices which are adjacent to the edge specified by its index.
typedef void (*CarveExporter_SetEdge) (struct ExportMeshData *export_data,
int edge_index, int v1, int v2,
int which_orig_mesh, int orig_edge_index);
// Set adjacent loops to the poly specified by its index.
typedef void (*CarveExporter_SetPoly) (struct ExportMeshData *export_data,
int poly_index, int start_loop, int num_loops,
int which_orig_mesh, int orig_poly_index);
// Set list vertex and edge which are adjacent to loop with given index.
typedef void (*CarveExporter_SetLoop) (struct ExportMeshData *export_data,
int loop_index, int vertex, int edge,
int which_orig_mesh, int orig_loop_index);
// Get edge index from a loop index for a given original mesh.
//
// A bit of a bummer to access original operands data on export stage,
// but Blender side still does have this information in derived meshes
// and we use API to get this data instead of duplicating it in Carve
// API side. This is because of optimizations reasons.
typedef int (*CarveExporter_MapLoopToEdge) (struct ExportMeshData *export_data,
int which_mesh, int loop_index);
typedef struct CarveMeshExporter {
CarveExporter_InitGeomArrays initGeomArrays;
CarveExporter_SetVert setVert;
CarveExporter_SetEdge setEdge;
CarveExporter_SetPoly setPoly;
CarveExporter_SetLoop setLoop;
CarveExporter_MapLoopToEdge mapLoopToEdge;
} CarveMeshExporter;
enum {
CARVE_OP_UNION,
CARVE_OP_INTERSECTION,
CARVE_OP_A_MINUS_B,
};
enum {
CARVE_MESH_NONE,
CARVE_MESH_LEFT,
CARVE_MESH_RIGHT
};
struct CarveMeshDescr *carve_addMesh(struct ImportMeshData *import_data,
CarveMeshImporter *mesh_importer);
void carve_deleteMesh(struct CarveMeshDescr *mesh_descr);
bool carve_performBooleanOperation(struct CarveMeshDescr *left_mesh,
struct CarveMeshDescr *right_mesh,
int operation,
struct CarveMeshDescr **output_mesh);
void carve_exportMesh(struct CarveMeshDescr *mesh_descr,
CarveMeshExporter *mesh_exporter,
struct ExportMeshData *export_data);
void carve_unionIntersections(struct CarveMeshDescr **left_mesh_r, struct CarveMeshDescr **right_mesh_r);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // __CARVE_CAPI_H__