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__
62 /* setting zero so we can catch bugs in OpenMP/BMesh */
64 # define BKE_MESH_OMP_LIMIT 0
66 # define BKE_MESH_OMP_LIMIT 10000
71 struct BMesh *BKE_mesh_to_bmesh(struct Mesh *me, struct Object *ob);
73 int poly_find_loop_from_vert(
74 const struct MPoly *poly,
75 const struct MLoop *loopstart, unsigned vert);
76 int poly_get_adj_loops_from_vert(
77 const struct MPoly *poly,
78 const struct MLoop *mloop, unsigned int vert,
79 unsigned int r_adj[2]);
81 int BKE_mesh_edge_other_vert(const struct MEdge *e, int v);
83 void BKE_mesh_unlink(struct Mesh *me);
84 void BKE_mesh_free(struct Mesh *me, int unlink);
85 struct Mesh *BKE_mesh_add(struct Main *bmain, const char *name);
86 struct Mesh *BKE_mesh_copy_ex(struct Main *bmain, struct Mesh *me);
87 struct Mesh *BKE_mesh_copy(struct Mesh *me);
88 void BKE_mesh_update_customdata_pointers(struct Mesh *me, const bool do_ensure_tess_cd);
89 void BKE_mesh_ensure_skin_customdata(struct Mesh *me);
91 void BKE_mesh_make_local(struct Mesh *me);
92 void BKE_mesh_boundbox_calc(struct Mesh *me, float r_loc[3], float r_size[3]);
93 void BKE_mesh_texspace_calc(struct Mesh *me);
94 float (*BKE_mesh_orco_verts_get(struct Object *ob))[3];
95 void BKE_mesh_orco_verts_transform(struct Mesh *me, float (*orco)[3], int totvert, int invert);
96 int test_index_face(struct MFace *mface, struct CustomData *mfdata, int mfindex, int nr);
97 struct Mesh *BKE_mesh_from_object(struct Object *ob);
98 void BKE_mesh_assign_object(struct Object *ob, struct Mesh *me);
99 void BKE_mesh_from_metaball(struct ListBase *lb, struct Mesh *me);
100 int BKE_mesh_nurbs_to_mdata(
101 struct Object *ob, struct MVert **r_allvert, int *r_totvert,
102 struct MEdge **r_alledge, int *r_totedge, struct MLoop **r_allloop, struct MPoly **r_allpoly,
103 int *r_totloop, int *r_totpoly);
104 int BKE_mesh_nurbs_displist_to_mdata(
105 struct Object *ob, const struct ListBase *dispbase,
106 struct MVert **r_allvert, int *r_totvert,
107 struct MEdge **r_alledge, int *r_totedge,
108 struct MLoop **r_allloop, struct MPoly **r_allpoly,
109 struct MLoopUV **r_alluv, int *r_totloop, int *r_totpoly);
110 void BKE_mesh_from_nurbs_displist(struct Object *ob, struct ListBase *dispbase, const bool use_orco_uv);
111 void BKE_mesh_from_nurbs(struct Object *ob);
112 void BKE_mesh_to_curve_nurblist(struct DerivedMesh *dm, struct ListBase *nurblist, const int edge_users_test);
113 void BKE_mesh_to_curve(struct Scene *scene, struct Object *ob);
114 void BKE_mesh_material_index_remove(struct Mesh *me, short index);
115 void BKE_mesh_material_index_clear(struct Mesh *me);
116 void BKE_mesh_material_remap(struct Mesh *me, const unsigned int *remap, unsigned int remap_len);
117 void BKE_mesh_smooth_flag_set(struct Object *meshOb, int enableSmooth);
119 const char *BKE_mesh_cmp(struct Mesh *me1, struct Mesh *me2, float thresh);
121 struct BoundBox *BKE_mesh_boundbox_get(struct Object *ob);
122 void BKE_mesh_texspace_get(struct Mesh *me, float r_loc[3], float r_rot[3], float r_size[3]);
123 void BKE_mesh_texspace_copy_from_object(struct Mesh *me, struct Object *ob);
125 bool BKE_mesh_uv_cdlayer_rename_index(struct Mesh *me, const int poly_index, const int loop_index, const int face_index,
126 const char *new_name, const bool do_tessface);
127 bool BKE_mesh_uv_cdlayer_rename(struct Mesh *me, const char *old_name, const char *new_name, bool do_tessface);
129 float (*BKE_mesh_vertexCos_get(const struct Mesh *me, int *r_numVerts))[3];
131 void BKE_mesh_calc_normals_split(struct Mesh *mesh);
132 void BKE_mesh_split_faces(struct Mesh *mesh);
134 struct Mesh *BKE_mesh_new_from_object(struct Main *bmain, struct Scene *sce, struct Object *ob,
135 int apply_modifiers, int settings, int calc_tessface, int calc_undeformed);
137 /* vertex level transformations & checks (no derived mesh) */
139 bool BKE_mesh_minmax(const struct Mesh *me, float r_min[3], float r_max[3]);
140 void BKE_mesh_transform(struct Mesh *me, float mat[4][4], bool do_keys);
141 void BKE_mesh_translate(struct Mesh *me, const float offset[3], const bool do_keys);
143 void BKE_mesh_ensure_navmesh(struct Mesh *me);
145 void BKE_mesh_tessface_calc(struct Mesh *mesh);
146 void BKE_mesh_tessface_ensure(struct Mesh *mesh);
147 void BKE_mesh_tessface_clear(struct Mesh *mesh);
149 void BKE_mesh_do_versions_cd_flag_init(struct Mesh *mesh);
152 void BKE_mesh_mselect_clear(struct Mesh *me);
153 void BKE_mesh_mselect_validate(struct Mesh *me);
154 int BKE_mesh_mselect_find(struct Mesh *me, int index, int type);
155 int BKE_mesh_mselect_active_get(struct Mesh *me, int type);
156 void BKE_mesh_mselect_active_set(struct Mesh *me, int index, int type);
160 /* *** mesh_evaluate.c *** */
162 void BKE_mesh_calc_normals_mapping(
163 struct MVert *mverts, int numVerts,
164 const struct MLoop *mloop, const struct MPoly *mpolys, int numLoops, int numPolys, float (*r_polyNors)[3],
165 const struct MFace *mfaces, int numFaces, const int *origIndexFace, float (*r_faceNors)[3]);
166 void BKE_mesh_calc_normals_mapping_ex(
167 struct MVert *mverts, int numVerts,
168 const struct MLoop *mloop, const struct MPoly *mpolys,
169 int numLoops, int numPolys, float (*r_polyNors)[3],
170 const struct MFace *mfaces, int numFaces, const int *origIndexFace, float (*r_faceNors)[3],
171 const bool only_face_normals);
172 void BKE_mesh_calc_normals_poly(
173 struct MVert *mverts, int numVerts,
174 const struct MLoop *mloop, const struct MPoly *mpolys,
175 int numLoops, int numPolys, float (*r_polyNors)[3],
176 const bool only_face_normals);
177 void BKE_mesh_calc_normals(struct Mesh *me);
178 void BKE_mesh_calc_normals_tessface(
179 struct MVert *mverts, int numVerts,
180 const struct MFace *mfaces, int numFaces,
181 float (*r_faceNors)[3]);
182 void BKE_mesh_calc_normals_looptri(
183 struct MVert *mverts, int numVerts,
184 const struct MLoop *mloop,
185 const struct MLoopTri *looptri, int looptri_num,
186 float (*r_tri_nors)[3]);
187 void BKE_mesh_loop_tangents_ex(
188 const struct MVert *mverts, const int numVerts, const struct MLoop *mloops,
189 float (*r_looptangent)[4], float (*loopnors)[3], const struct MLoopUV *loopuv,
190 const int numLoops, const struct MPoly *mpolys, const int numPolys,
191 struct ReportList *reports);
192 void BKE_mesh_loop_tangents(
193 struct Mesh *mesh, const char *uvmap, float (*r_looptangents)[4], struct ReportList *reports);
196 * References a contiguous loop-fan with normal offset vars.
198 typedef struct MLoopNorSpace {
199 float vec_lnor[3]; /* Automatically computed loop normal. */
200 float vec_ref[3]; /* Reference vector, orthogonal to vec_lnor. */
201 float vec_ortho[3]; /* Third vector, orthogonal to vec_lnor and vec_ref. */
202 float ref_alpha; /* Reference angle, around vec_ortho, in ]0, pi] range (0.0 marks that space as invalid). */
203 float ref_beta; /* Reference angle, around vec_lnor, in ]0, 2pi] range (0.0 marks that space as invalid). */
204 struct LinkNode *loops; /* All indices (uint_in_ptr) of loops using this lnor space (i.e. smooth fan of loops). */
207 * Collection of #MLoopNorSpace basic storage & pre-allocation.
209 typedef struct MLoopNorSpaceArray {
210 MLoopNorSpace **lspacearr; /* MLoop aligned array */
211 struct LinkNode *loops_pool; /* Allocated once, avoids to call BLI_linklist_prepend_arena() for each loop! */
212 struct MemArena *mem;
213 } MLoopNorSpaceArray;
214 void BKE_lnor_spacearr_init(MLoopNorSpaceArray *lnors_spacearr, const int numLoops);
215 void BKE_lnor_spacearr_clear(MLoopNorSpaceArray *lnors_spacearr);
216 void BKE_lnor_spacearr_free(MLoopNorSpaceArray *lnors_spacearr);
217 MLoopNorSpace *BKE_lnor_space_create(MLoopNorSpaceArray *lnors_spacearr);
218 void BKE_lnor_space_define(
219 MLoopNorSpace *lnor_space, const float lnor[3], float vec_ref[3], float vec_other[3],
220 struct BLI_Stack *edge_vectors);
221 void BKE_lnor_space_add_loop(
222 MLoopNorSpaceArray *lnors_spacearr, MLoopNorSpace *lnor_space, const int ml_index, const bool add_to_list);
223 void BKE_lnor_space_custom_data_to_normal(MLoopNorSpace *lnor_space, const short clnor_data[2], float r_custom_lnor[3]);
224 void BKE_lnor_space_custom_normal_to_data(MLoopNorSpace *lnor_space, const float custom_lnor[3], short r_clnor_data[2]);
226 bool BKE_mesh_has_custom_loop_normals(struct Mesh *me);
228 void BKE_mesh_normals_loop_split(
229 const struct MVert *mverts, const int numVerts, struct MEdge *medges, const int numEdges,
230 struct MLoop *mloops, float (*r_loopnors)[3], const int numLoops,
231 struct MPoly *mpolys, const float (*polynors)[3], const int numPolys,
232 const bool use_split_normals, float split_angle,
233 MLoopNorSpaceArray *r_lnors_spacearr, short (*clnors_data)[2], int *r_loop_to_poly);
235 void BKE_mesh_normals_loop_custom_set(
236 const struct MVert *mverts, const int numVerts, struct MEdge *medges, const int numEdges,
237 struct MLoop *mloops, float (*custom_loopnors)[3], const int numLoops,
238 struct MPoly *mpolys, const float (*polynors)[3], const int numPolys,
239 short (*r_clnors_data)[2]);
240 void BKE_mesh_normals_loop_custom_from_vertices_set(
241 const struct MVert *mverts, float (*custom_vertnors)[3], const int numVerts,
242 struct MEdge *medges, const int numEdges, struct MLoop *mloops, const int numLoops,
243 struct MPoly *mpolys, const float (*polynors)[3], const int numPolys,
244 short (*r_clnors_data)[2]);
246 void BKE_mesh_calc_poly_normal(
247 const struct MPoly *mpoly, const struct MLoop *loopstart,
248 const struct MVert *mvarray, float r_no[3]);
249 void BKE_mesh_calc_poly_normal_coords(
250 const struct MPoly *mpoly, const struct MLoop *loopstart,
251 const float (*vertex_coords)[3], float r_no[3]);
252 void BKE_mesh_calc_poly_center(
253 const struct MPoly *mpoly, const struct MLoop *loopstart,
254 const struct MVert *mvarray, float r_cent[3]);
255 float BKE_mesh_calc_poly_area(
256 const struct MPoly *mpoly, const struct MLoop *loopstart,
257 const struct MVert *mvarray);
258 void BKE_mesh_calc_poly_angles(
259 const struct MPoly *mpoly, const struct MLoop *loopstart,
260 const struct MVert *mvarray, float angles[]);
262 void BKE_mesh_poly_edgehash_insert(
263 struct EdgeHash *ehash,
264 const struct MPoly *mp, const struct MLoop *mloop);
265 void BKE_mesh_poly_edgebitmap_insert(
266 unsigned int *edge_bitmap,
267 const struct MPoly *mp, const struct MLoop *mloop);
270 bool BKE_mesh_center_median(const struct Mesh *me, float r_cent[3]);
271 bool BKE_mesh_center_bounds(const struct Mesh *me, float r_cent[3]);
272 bool BKE_mesh_center_centroid(const struct Mesh *me, float r_cent[3]);
274 void BKE_mesh_calc_volume(
275 const struct MVert *mverts, const int numVerts,
276 const struct MLoopTri *mlooptri, const int numTris,
277 const struct MLoop *mloop, float *r_vol, float *r_com);
280 void BKE_mesh_loops_to_mface_corners(
281 struct CustomData *fdata, struct CustomData *ldata,
282 struct CustomData *pdata, unsigned int lindex[4], int findex,
283 const int polyindex, const int mf_len,
284 const int numTex, const int numCol,
285 const bool hasPCol, const bool hasOrigSpace, const bool hasLNor);
286 void BKE_mesh_loops_to_tessdata(
287 struct CustomData *fdata, struct CustomData *ldata, struct CustomData *pdata, struct MFace *mface,
288 int *polyindices, unsigned int (*loopindices)[4], const int num_faces);
289 int BKE_mesh_recalc_tessellation(
290 struct CustomData *fdata, struct CustomData *ldata, struct CustomData *pdata,
292 int totface, int totloop, int totpoly,
293 const bool do_face_nor_copy);
294 void BKE_mesh_recalc_looptri(
295 const struct MLoop *mloop, const struct MPoly *mpoly,
296 const struct MVert *mvert,
297 int totloop, int totpoly,
298 struct MLoopTri *mlooptri);
299 int BKE_mesh_mpoly_to_mface(
300 struct CustomData *fdata, struct CustomData *ldata,
301 struct CustomData *pdata, int totface, int totloop, int totpoly);
302 void BKE_mesh_convert_mfaces_to_mpolys(struct Mesh *mesh);
303 void BKE_mesh_do_versions_convert_mfaces_to_mpolys(struct Mesh *mesh);
304 void BKE_mesh_convert_mfaces_to_mpolys_ex(
306 struct CustomData *fdata, struct CustomData *ldata, struct CustomData *pdata,
307 int totedge_i, int totface_i, int totloop_i, int totpoly_i,
308 struct MEdge *medge, struct MFace *mface,
309 int *r_totloop, int *r_totpoly,
310 struct MLoop **r_mloop, struct MPoly **r_mpoly);
313 void BKE_mesh_flush_hidden_from_verts_ex(
314 const struct MVert *mvert,
315 const struct MLoop *mloop,
316 struct MEdge *medge, const int totedge,
317 struct MPoly *mpoly, const int totpoly);
318 void BKE_mesh_flush_hidden_from_verts(struct Mesh *me);
319 void BKE_mesh_flush_hidden_from_polys_ex(
321 const struct MLoop *mloop,
322 struct MEdge *medge, const int totedge,
323 const struct MPoly *mpoly, const int totpoly);
324 void BKE_mesh_flush_hidden_from_polys(struct Mesh *me);
325 void BKE_mesh_flush_select_from_polys_ex(
326 struct MVert *mvert, const int totvert,
327 const struct MLoop *mloop,
328 struct MEdge *medge, const int totedge,
329 const struct MPoly *mpoly, const int totpoly);
330 void BKE_mesh_flush_select_from_polys(struct Mesh *me);
331 void BKE_mesh_flush_select_from_verts_ex(
332 const struct MVert *mvert, const int totvert,
333 const struct MLoop *mloop,
334 struct MEdge *medge, const int totedge,
335 struct MPoly *mpoly, const int totpoly);
336 void BKE_mesh_flush_select_from_verts(struct Mesh *me);
338 /* spatial evaluation */
339 void BKE_mesh_calc_relative_deform(
340 const struct MPoly *mpoly, const int totpoly,
341 const struct MLoop *mloop, const int totvert,
343 const float (*vert_cos_src)[3],
344 const float (*vert_cos_dst)[3],
346 const float (*vert_cos_org)[3],
347 float (*vert_cos_new)[3]);
351 /* *** mesh_validate.c *** */
353 int BKE_mesh_validate(struct Mesh *me, const int do_verbose, const int cddata_check_mask);
354 void BKE_mesh_cd_validate(struct Mesh *me);
355 int BKE_mesh_validate_material_indices(struct Mesh *me);
357 bool BKE_mesh_validate_arrays(
359 struct MVert *mverts, unsigned int totvert,
360 struct MEdge *medges, unsigned int totedge,
361 struct MFace *mfaces, unsigned int totface,
362 struct MLoop *mloops, unsigned int totloop,
363 struct MPoly *mpolys, unsigned int totpoly,
364 struct MDeformVert *dverts, /* assume totvert length */
365 const bool do_verbose, const bool do_fixes,
368 bool BKE_mesh_validate_all_customdata(
369 struct CustomData *vdata, struct CustomData *edata,
370 struct CustomData *ldata, struct CustomData *pdata,
371 const bool check_meshmask,
372 const bool do_verbose, const bool do_fixes,
375 void BKE_mesh_strip_loose_faces(struct Mesh *me);
376 void BKE_mesh_strip_loose_polysloops(struct Mesh *me);
377 void BKE_mesh_strip_loose_edges(struct Mesh *me);
379 void BKE_mesh_calc_edges_legacy(struct Mesh *me, const bool use_old);
380 void BKE_mesh_calc_edges(struct Mesh *mesh, bool update, const bool select);
382 /* **** Depsgraph evaluation **** */
384 struct EvaluationContext;
386 void BKE_mesh_eval_geometry(struct EvaluationContext *eval_ctx,
393 #endif /* __BKE_MESH_H__ */