2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): (mar-2001 nzc)
25 * ***** END GPL LICENSE BLOCK *****
27 #ifndef __BKE_MESH_H__
28 #define __BKE_MESH_H__
61 /* setting zero so we can catch bugs in OpenMP/BMesh */
63 # define BKE_MESH_OMP_LIMIT 0
65 # define BKE_MESH_OMP_LIMIT 10000
70 struct BMesh *BKE_mesh_to_bmesh(struct Mesh *me, struct Object *ob);
72 int poly_find_loop_from_vert(
73 const struct MPoly *poly,
74 const struct MLoop *loopstart,
76 int poly_get_adj_loops_from_vert(
77 unsigned r_adj[2], const struct MPoly *poly,
78 const struct MLoop *mloop, unsigned vert);
80 int BKE_mesh_edge_other_vert(const struct MEdge *e, int v);
82 void BKE_mesh_unlink(struct Mesh *me);
83 void BKE_mesh_free(struct Mesh *me, int unlink);
84 struct Mesh *BKE_mesh_add(struct Main *bmain, const char *name);
85 struct Mesh *BKE_mesh_copy_ex(struct Main *bmain, struct Mesh *me);
86 struct Mesh *BKE_mesh_copy(struct Mesh *me);
87 void BKE_mesh_update_customdata_pointers(struct Mesh *me, const bool do_ensure_tess_cd);
88 void BKE_mesh_ensure_skin_customdata(struct Mesh *me);
90 void BKE_mesh_make_local(struct Mesh *me);
91 void BKE_mesh_boundbox_calc(struct Mesh *me, float r_loc[3], float r_size[3]);
92 void BKE_mesh_texspace_calc(struct Mesh *me);
93 float (*BKE_mesh_orco_verts_get(struct Object *ob))[3];
94 void BKE_mesh_orco_verts_transform(struct Mesh *me, float (*orco)[3], int totvert, int invert);
95 int test_index_face(struct MFace *mface, struct CustomData *mfdata, int mfindex, int nr);
96 struct Mesh *BKE_mesh_from_object(struct Object *ob);
97 void BKE_mesh_assign_object(struct Object *ob, struct Mesh *me);
98 void BKE_mesh_from_metaball(struct ListBase *lb, struct Mesh *me);
99 int BKE_mesh_nurbs_to_mdata(struct Object *ob, struct MVert **allvert, int *totvert,
100 struct MEdge **alledge, int *totedge, struct MLoop **allloop, struct MPoly **allpoly,
101 int *totloop, int *totpoly);
102 int BKE_mesh_nurbs_displist_to_mdata(struct Object *ob, struct ListBase *dispbase, struct MVert **allvert, int *_totvert,
103 struct MEdge **alledge, int *_totedge, struct MLoop **allloop, struct MPoly **allpoly,
104 struct MLoopUV **alluv, int *_totloop, int *_totpoly);
105 void BKE_mesh_from_nurbs_displist(struct Object *ob, struct ListBase *dispbase, const bool use_orco_uv);
106 void BKE_mesh_from_nurbs(struct Object *ob);
107 void BKE_mesh_to_curve_nurblist(struct DerivedMesh *dm, struct ListBase *nurblist, const int edge_users_test);
108 void BKE_mesh_to_curve(struct Scene *scene, struct Object *ob);
109 void BKE_mesh_material_index_remove(struct Mesh *me, short index);
110 void BKE_mesh_material_index_clear(struct Mesh *me);
111 void BKE_mesh_smooth_flag_set(struct Object *meshOb, int enableSmooth);
113 const char *BKE_mesh_cmp(struct Mesh *me1, struct Mesh *me2, float thresh);
115 struct BoundBox *BKE_mesh_boundbox_get(struct Object *ob);
116 void BKE_mesh_texspace_get(struct Mesh *me, float r_loc[3], float r_rot[3], float r_size[3]);
117 void BKE_mesh_texspace_copy_from_object(struct Mesh *me, struct Object *ob);
119 bool BKE_mesh_uv_cdlayer_rename_index(struct Mesh *me, const int poly_index, const int loop_index, const int face_index,
120 const char *new_name, const bool do_tessface);
121 bool BKE_mesh_uv_cdlayer_rename(struct Mesh *me, const char *old_name, const char *new_name, bool do_tessface);
123 float (*BKE_mesh_vertexCos_get(const struct Mesh *me, int *r_numVerts))[3];
125 void BKE_mesh_calc_normals_split(struct Mesh *mesh);
126 void BKE_mesh_split_faces(struct Mesh *mesh);
128 struct Mesh *BKE_mesh_new_from_object(struct Main *bmain, struct Scene *sce, struct Object *ob,
129 int apply_modifiers, int settings, int calc_tessface, int calc_undeformed);
131 /* vertex level transformations & checks (no derived mesh) */
133 bool BKE_mesh_minmax(struct Mesh *me, float r_min[3], float r_max[3]);
134 void BKE_mesh_transform(struct Mesh *me, float mat[4][4], bool do_keys);
135 void BKE_mesh_translate(struct Mesh *me, const float offset[3], const bool do_keys);
137 void BKE_mesh_ensure_navmesh(struct Mesh *me);
139 void BKE_mesh_tessface_calc(struct Mesh *mesh);
140 void BKE_mesh_tessface_ensure(struct Mesh *mesh);
141 void BKE_mesh_tessface_clear(struct Mesh *mesh);
143 void BKE_mesh_do_versions_cd_flag_init(struct Mesh *mesh);
146 void BKE_mesh_mselect_clear(struct Mesh *me);
147 void BKE_mesh_mselect_validate(struct Mesh *me);
148 int BKE_mesh_mselect_find(struct Mesh *me, int index, int type);
149 int BKE_mesh_mselect_active_get(struct Mesh *me, int type);
150 void BKE_mesh_mselect_active_set(struct Mesh *me, int index, int type);
154 /* *** mesh_evaluate.c *** */
156 void BKE_mesh_calc_normals_mapping(
157 struct MVert *mverts, int numVerts,
158 struct MLoop *mloop, struct MPoly *mpolys, int numLoops, int numPolys, float (*r_polyNors)[3],
159 struct MFace *mfaces, int numFaces, const int *origIndexFace, float (*r_faceNors)[3]);
160 void BKE_mesh_calc_normals_mapping_ex(
161 struct MVert *mverts, int numVerts,
162 struct MLoop *mloop, struct MPoly *mpolys, int numLoops, int numPolys, float (*r_polyNors)[3],
163 struct MFace *mfaces, int numFaces, const int *origIndexFace, float (*r_faceNors)[3],
164 const bool only_face_normals);
165 void BKE_mesh_calc_normals_poly(
166 struct MVert *mverts, int numVerts,
167 struct MLoop *mloop, struct MPoly *mpolys,
168 int numLoops, int numPolys, float (*r_polyNors)[3],
169 const bool only_face_normals);
170 void BKE_mesh_calc_normals(struct Mesh *me);
171 void BKE_mesh_calc_normals_tessface(
172 struct MVert *mverts, int numVerts,
173 struct MFace *mfaces, int numFaces,
174 float (*r_faceNors)[3]);
175 void BKE_mesh_loop_tangents_ex(
176 struct MVert *mverts, const int numVerts, struct MLoop *mloops, float (*r_looptangent)[4], float (*loopnors)[3],
177 struct MLoopUV *loopuv, const int numLoops, struct MPoly *mpolys, const int numPolys,
178 struct ReportList *reports);
179 void BKE_mesh_loop_tangents(
180 struct Mesh *mesh, const char *uvmap, float (*r_looptangents)[4], struct ReportList *reports);
183 * References a contiguous loop-fan with normal offset vars.
185 typedef struct MLoopNorSpace {
186 float vec_lnor[3]; /* Automatically computed loop normal. */
187 float vec_ref[3]; /* Reference vector, orthogonal to vec_lnor. */
188 float vec_ortho[3]; /* Third vector, orthogonal to vec_lnor and vec_ref. */
189 float ref_alpha; /* Reference angle, around vec_ortho, in ]0, pi] range (0.0 marks that space as invalid). */
190 float ref_beta; /* Reference angle, around vec_lnor, in ]0, 2pi] range (0.0 marks that space as invalid). */
191 struct LinkNode *loops; /* All indices (uint_in_ptr) of loops using this lnor space (i.e. smooth fan of loops). */
194 * Collection of #MLoopNorSpace basic storage & pre-allocation.
196 typedef struct MLoopNorSpaceArray {
197 MLoopNorSpace **lspacearr; /* MLoop aligned array */
198 struct LinkNode *loops_pool; /* Allocated once, avoids to call BLI_linklist_prepend_arena() for each loop! */
199 struct MemArena *mem;
200 } MLoopNorSpaceArray;
201 void BKE_lnor_spacearr_init(MLoopNorSpaceArray *lnors_spacearr, const int numLoops);
202 void BKE_lnor_spacearr_clear(MLoopNorSpaceArray *lnors_spacearr);
203 void BKE_lnor_spacearr_free(MLoopNorSpaceArray *lnors_spacearr);
204 MLoopNorSpace *BKE_lnor_space_create(MLoopNorSpaceArray *lnors_spacearr);
205 void BKE_lnor_space_define(
206 MLoopNorSpace *lnor_space, const float lnor[3], float vec_ref[3], float vec_other[3],
207 struct BLI_Stack *edge_vectors);
208 void BKE_lnor_space_add_loop(
209 MLoopNorSpaceArray *lnors_spacearr, MLoopNorSpace *lnor_space, const int ml_index, const bool add_to_list);
210 void BKE_lnor_space_custom_data_to_normal(MLoopNorSpace *lnor_space, const short clnor_data[2], float r_custom_lnor[3]);
211 void BKE_lnor_space_custom_normal_to_data(MLoopNorSpace *lnor_space, const float custom_lnor[3], short r_clnor_data[2]);
213 bool BKE_mesh_has_custom_loop_normals(struct Mesh *me);
215 void BKE_mesh_normals_loop_split(struct MVert *mverts, const int numVerts, struct MEdge *medges, const int numEdges,
216 struct MLoop *mloops, float (*r_loopnors)[3], const int numLoops,
217 struct MPoly *mpolys, const float (*polynors)[3], const int numPolys,
218 const bool use_split_normals, float split_angle,
219 MLoopNorSpaceArray *r_lnors_spacearr, short (*clnors_data)[2], int *r_loop_to_poly);
221 void BKE_mesh_normals_loop_custom_set(
222 struct MVert *mverts, const int numVerts, struct MEdge *medges, const int numEdges,
223 struct MLoop *mloops, float (*custom_loopnors)[3], const int numLoops,
224 struct MPoly *mpolys, const float (*polynors)[3], const int numPolys,
225 short (*r_clnors_data)[2]);
226 void BKE_mesh_normals_loop_custom_from_vertices_set(
227 struct MVert *mverts, float (*custom_vertnors)[3], const int numVerts,
228 struct MEdge *medges, const int numEdges, struct MLoop *mloops, const int numLoops,
229 struct MPoly *mpolys, const float (*polynors)[3], const int numPolys,
230 short (*r_clnors_data)[2]);
232 void BKE_mesh_calc_poly_normal(
233 struct MPoly *mpoly, struct MLoop *loopstart,
234 struct MVert *mvarray, float no[3]);
235 void BKE_mesh_calc_poly_normal_coords(
236 struct MPoly *mpoly, struct MLoop *loopstart,
237 const float (*vertex_coords)[3], float no[3]);
238 void BKE_mesh_calc_poly_center(
239 struct MPoly *mpoly, struct MLoop *loopstart,
240 struct MVert *mvarray, float cent[3]);
241 float BKE_mesh_calc_poly_area(
242 struct MPoly *mpoly, struct MLoop *loopstart,
243 struct MVert *mvarray);
244 void BKE_mesh_calc_poly_angles(
245 struct MPoly *mpoly, struct MLoop *loopstart,
246 struct MVert *mvarray, float angles[]);
248 void BKE_mesh_poly_edgehash_insert(
249 struct EdgeHash *ehash,
250 const struct MPoly *mp, const struct MLoop *mloop);
251 void BKE_mesh_poly_edgebitmap_insert(
252 unsigned int *edge_bitmap,
253 const struct MPoly *mp, const struct MLoop *mloop);
256 bool BKE_mesh_center_median(struct Mesh *me, float cent[3]);
257 bool BKE_mesh_center_bounds(struct Mesh *me, float cent[3]);
258 bool BKE_mesh_center_centroid(struct Mesh *me, float cent[3]);
260 void BKE_mesh_calc_volume(struct MVert *mverts, int numVerts,
261 struct MFace *mfaces, int numFaces,
262 float *r_vol, float *r_com);
265 void BKE_mesh_loops_to_mface_corners(
266 struct CustomData *fdata, struct CustomData *ldata,
267 struct CustomData *pdata, unsigned int lindex[4], int findex,
268 const int polyindex, const int mf_len,
269 const int numTex, const int numCol,
270 const bool hasPCol, const bool hasOrigSpace, const bool hasLNor);
271 void BKE_mesh_loops_to_tessdata(
272 struct CustomData *fdata, struct CustomData *ldata, struct CustomData *pdata, struct MFace *mface,
273 int *polyindices, unsigned int (*loopindices)[4], const int num_faces);
274 int BKE_mesh_recalc_tessellation(
275 struct CustomData *fdata, struct CustomData *ldata, struct CustomData *pdata,
277 int totface, int totloop, int totpoly,
278 const bool do_face_normals);
279 int BKE_mesh_mpoly_to_mface(
280 struct CustomData *fdata, struct CustomData *ldata,
281 struct CustomData *pdata, int totface, int totloop, int totpoly);
282 void BKE_mesh_convert_mfaces_to_mpolys(struct Mesh *mesh);
283 void BKE_mesh_do_versions_convert_mfaces_to_mpolys(struct Mesh *mesh);
284 void BKE_mesh_convert_mfaces_to_mpolys_ex(
286 struct CustomData *fdata, struct CustomData *ldata, struct CustomData *pdata,
287 int totedge_i, int totface_i, int totloop_i, int totpoly_i,
288 struct MEdge *medge, struct MFace *mface,
289 int *r_totloop, int *r_totpoly,
290 struct MLoop **r_mloop, struct MPoly **r_mpoly);
293 void BKE_mesh_flush_hidden_from_verts_ex(
294 const struct MVert *mvert,
295 const struct MLoop *mloop,
296 struct MEdge *medge, const int totedge,
297 struct MPoly *mpoly, const int totpoly);
298 void BKE_mesh_flush_hidden_from_verts(struct Mesh *me);
299 void BKE_mesh_flush_hidden_from_polys_ex(
301 const struct MLoop *mloop,
302 struct MEdge *medge, const int totedge,
303 const struct MPoly *mpoly, const int totpoly);
304 void BKE_mesh_flush_hidden_from_polys(struct Mesh *me);
305 void BKE_mesh_flush_select_from_polys_ex(
306 struct MVert *mvert, const int totvert,
307 const struct MLoop *mloop,
308 struct MEdge *medge, const int totedge,
309 const struct MPoly *mpoly, const int totpoly);
310 void BKE_mesh_flush_select_from_polys(struct Mesh *me);
311 void BKE_mesh_flush_select_from_verts_ex(
312 const struct MVert *mvert, const int totvert,
313 const struct MLoop *mloop,
314 struct MEdge *medge, const int totedge,
315 struct MPoly *mpoly, const int totpoly);
316 void BKE_mesh_flush_select_from_verts(struct Mesh *me);
318 /* spatial evaluation */
319 void BKE_mesh_calc_relative_deform(
320 const struct MPoly *mpoly, const int totpoly,
321 const struct MLoop *mloop, const int totvert,
323 const float (*vert_cos_src)[3],
324 const float (*vert_cos_dst)[3],
326 const float (*vert_cos_org)[3],
327 float (*vert_cos_new)[3]);
331 /* *** mesh_validate.c *** */
333 int BKE_mesh_validate(struct Mesh *me, const int do_verbose, const int cddata_check_mask);
334 void BKE_mesh_cd_validate(struct Mesh *me);
335 int BKE_mesh_validate_material_indices(struct Mesh *me);
337 bool BKE_mesh_validate_arrays(
339 struct MVert *mverts, unsigned int totvert,
340 struct MEdge *medges, unsigned int totedge,
341 struct MFace *mfaces, unsigned int totface,
342 struct MLoop *mloops, unsigned int totloop,
343 struct MPoly *mpolys, unsigned int totpoly,
344 struct MDeformVert *dverts, /* assume totvert length */
345 const bool do_verbose, const bool do_fixes,
348 bool BKE_mesh_validate_all_customdata(
349 struct CustomData *vdata, struct CustomData *edata,
350 struct CustomData *ldata, struct CustomData *pdata,
351 const bool check_meshmask,
352 const bool do_verbose, const bool do_fixes,
355 void BKE_mesh_strip_loose_faces(struct Mesh *me);
356 void BKE_mesh_strip_loose_polysloops(struct Mesh *me);
357 void BKE_mesh_strip_loose_edges(struct Mesh *me);
359 void BKE_mesh_calc_edges_legacy(struct Mesh *me, const bool use_old);
360 void BKE_mesh_calc_edges(struct Mesh *mesh, bool update, const bool select);
366 #endif /* __BKE_MESH_H__ */