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__
65 struct BMesh *BKE_mesh_to_bmesh(struct Mesh *me, struct Object *ob);
68 * this function recreates a tessellation.
69 * returns number of tessellation faces.
71 * use_poly_origindex sets whether or not the tessellation faces' origindex
72 * layer should point to original poly indices or real poly indices.
74 * use_face_origindex sets the tessellation faces' origindex layer
75 * to point to the tessellation faces themselves, not the polys.
77 * if both of the above are 0, it'll use the indices of the mpolys of the MPoly
78 * data in pdata, and ignore the origindex layer altogether.
80 int BKE_mesh_recalc_tessellation(struct CustomData *fdata, struct CustomData *ldata, struct CustomData *pdata,
82 int totface, int totloop, int totpoly,
83 const int do_face_normals);
85 /* for forwards compat only quad->tri polys to mface, skip ngons.
87 int BKE_mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata,
88 struct CustomData *pdata, int totface, int totloop, int totpoly);
90 /*calculates a face normal.*/
91 void BKE_mesh_calc_poly_normal(struct MPoly *mpoly, struct MLoop *loopstart,
92 struct MVert *mvarray, float no[3]);
94 void BKE_mesh_calc_poly_normal_coords(struct MPoly *mpoly, struct MLoop *loopstart,
95 const float (*vertex_coords)[3], float no[3]);
97 void BKE_mesh_calc_poly_center(struct MPoly *mpoly, struct MLoop *loopstart,
98 struct MVert *mvarray, float cent[3]);
100 float BKE_mesh_calc_poly_area(struct MPoly *mpoly, struct MLoop *loopstart,
101 struct MVert *mvarray, const float polynormal[3]);
103 /* Find the index of the loop in 'poly' which references vertex,
104 * returns -1 if not found */
105 int poly_find_loop_from_vert(const struct MPoly *poly,
106 const struct MLoop *loopstart,
109 /* Fill 'adj_r' with the loop indices in 'poly' adjacent to the
110 * vertex. Returns the index of the loop matching vertex, or -1 if the
111 * vertex is not in 'poly' */
112 int poly_get_adj_loops_from_vert(unsigned adj_r[3], const struct MPoly *poly,
113 const struct MLoop *mloop, unsigned vert);
115 /* Return the index of the edge vert that is not equal to 'v'. If
116 * neither edge vertex is equal to 'v', returns -1. */
117 int BKE_mesh_edge_other_vert(const struct MEdge *e, int v);
119 /* update the hide flag for edges and polys from the corresponding
121 void BKE_mesh_flush_hidden_from_verts(const struct MVert *mvert,
122 const struct MLoop *mloop,
123 struct MEdge *medge, int totedge,
124 struct MPoly *mpoly, int totpoly);
126 void BKE_mesh_unlink(struct Mesh *me);
127 void BKE_mesh_free(struct Mesh *me, int unlink);
128 struct Mesh *BKE_mesh_add(const char *name);
129 struct Mesh *BKE_mesh_copy(struct Mesh *me);
130 void mesh_update_customdata_pointers(struct Mesh *me, const short do_ensure_tess_cd);
132 void BKE_mesh_make_local(struct Mesh *me);
133 void BKE_mesh_boundbox_calc(struct Mesh *me, float r_loc[3], float r_size[3]);
134 void BKE_mesh_texspace_calc(struct Mesh *me);
135 float *BKE_mesh_orco_verts_get(struct Object *ob);
136 void BKE_mesh_orco_verts_transform(struct Mesh *me, float (*orco)[3], int totvert, int invert);
137 int test_index_face(struct MFace *mface, struct CustomData *mfdata, int mfindex, int nr);
138 struct Mesh *BKE_mesh_from_object(struct Object *ob);
139 void set_mesh(struct Object *ob, struct Mesh *me);
140 void BKE_mesh_from_metaball(struct ListBase *lb, struct Mesh *me);
141 int BKE_mesh_nurbs_to_mdata(struct Object *ob, struct MVert **allvert, int *totvert,
142 struct MEdge **alledge, int *totedge, struct MLoop **allloop, struct MPoly **allpoly,
143 int *totloop, int *totpoly);
144 int BKE_mesh_nurbs_displist_to_mdata(struct Object *ob, struct ListBase *dispbase, struct MVert **allvert, int *_totvert,
145 struct MEdge **alledge, int *_totedge, struct MLoop **allloop, struct MPoly **allpoly,
146 int *_totloop, int *_totpoly, int **orco_index_ptr);
147 void BKE_mesh_nurbs_to_mdata_orco(struct MPoly *mpoly, int totpoly,
148 struct MLoop *mloops, struct MLoopUV *mloopuvs,
149 float (*orco)[3], int (*orco_index)[4]);
150 void BKE_mesh_from_nurbs(struct Object *ob);
151 void BKE_mesh_from_nurbs_displist(struct Object *ob, struct ListBase *dispbase,
152 int **orco_index_ptr);
153 void BKE_mesh_from_curve(struct Scene *scene, struct Object *ob);
154 void free_dverts(struct MDeformVert *dvert, int totvert);
155 void copy_dverts(struct MDeformVert *dst, struct MDeformVert *src, int totvert); /* __NLA */
156 void BKE_mesh_delete_material_index(struct Mesh *me, short index);
157 void BKE_mesh_smooth_flag_set(struct Object *meshOb, int enableSmooth);
158 void BKE_mesh_convert_mfaces_to_mpolys(struct Mesh *mesh);
159 void BKE_mesh_do_versions_convert_mfaces_to_mpolys(struct Mesh *mesh);
160 void BKE_mesh_convert_mfaces_to_mpolys_ex(struct ID *id,
161 struct CustomData *fdata, struct CustomData *ldata, struct CustomData *pdata,
162 int totedge_i, int totface_i, int totloop_i, int totpoly_i,
163 struct MEdge *medge, struct MFace *mface,
164 int *totloop_r, int *totpoly_r,
165 struct MLoop **mloop_r, struct MPoly **mpoly_r);
167 void BKE_mesh_calc_normals_tessface(struct MVert *mverts, int numVerts, struct MFace *mfaces, int numFaces, float (*faceNors_r)[3]);
169 /* used for unit testing; compares two meshes, checking only
170 * differences we care about. should be usable with leaf's
171 * testing framework I get RNA work done, will use hackish
172 * testing code for now.*/
173 const char *BKE_mesh_cmp(struct Mesh *me1, struct Mesh *me2, float thresh);
175 struct BoundBox *BKE_mesh_boundbox_get(struct Object *ob);
176 void BKE_mesh_texspace_get(struct Mesh *me, float r_loc[3], float r_rot[3], float r_size[3]);
178 /* if old, it converts mface->edcode to edge drawflags */
179 void BKE_mesh_make_edges(struct Mesh *me, int old);
181 void BKE_mesh_strip_loose_faces(struct Mesh *me); /* Needed for compatibility (some old read code). */
182 void BKE_mesh_strip_loose_polysloops(struct Mesh *me);
183 void BKE_mesh_strip_loose_edges(struct Mesh *me);
185 /* Calculate vertex and face normals, face normals are returned in *faceNors_r if non-NULL
186 * and vertex normals are stored in actual mverts.
188 void BKE_mesh_calc_normals_mapping(
189 struct MVert *mverts, int numVerts,
190 struct MLoop *mloop, struct MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3],
191 struct MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3]);
192 /* extended version of 'BKE_mesh_calc_normals' with option not to calc vertex normals */
193 void BKE_mesh_calc_normals_mapping_ex(
194 struct MVert *mverts, int numVerts,
195 struct MLoop *mloop, struct MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3],
196 struct MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3],
197 const short only_face_normals);
199 void BKE_mesh_calc_normals(
200 struct MVert *mverts, int numVerts,
201 struct MLoop *mloop, struct MPoly *mpolys,
202 int numLoops, int numPolys, float (*polyNors_r)[3]);
204 /* Return a newly MEM_malloc'd array of all the mesh vertex locations
205 * (_numVerts_r_ may be NULL) */
206 float (*mesh_getVertexCos(struct Mesh *me, int *numVerts_r))[3];
208 /* map from uv vertex to face (for select linked, stitch, uv suburf) */
212 #define STD_UV_CONNECT_LIMIT 0.0001f
214 typedef struct UvVertMap {
215 struct UvMapVert **vert;
216 struct UvMapVert *buf;
219 typedef struct UvMapVert {
220 struct UvMapVert *next;
222 unsigned char tfindex, separate, flag;
225 /* UvElement stores per uv information so that we can quickly access information for a uv.
226 * it is actually an improved UvMapVert, including an island and a direct pointer to the face
227 * to avoid initializing face arrays */
228 typedef struct UvElement {
229 /* Next UvElement corresponding to same vertex */
230 struct UvElement *next;
231 /* Face the element belongs to */
233 /* Index in the editFace of the uv */
236 unsigned short tfindex;
237 /* Whether this element is the first of coincident elements */
238 unsigned char separate;
239 /* general use flag */
241 /* If generating element map with island sorting, this stores the island index */
242 unsigned short island;
246 /* UvElementMap is a container for UvElements of a mesh. It stores some UvElements belonging to the
247 * same uv island in sequence and the number of uvs per island so it is possible to access all uvs
248 * belonging to an island directly by iterating through the buffer.
250 typedef struct UvElementMap {
251 /* address UvElements by their vertex */
252 struct UvElement **vert;
253 /* UvElement Store */
254 struct UvElement *buf;
255 /* Total number of UVs in the layer. Useful to know */
257 /* Number of Islands in the mesh */
259 /* Stores the starting index in buf where each island begins */
263 /* invalid island index is max short. If any one has the patience
264 * to make that many islands, he can bite me :p */
265 #define INVALID_ISLAND 0xFFFF
267 UvVertMap *BKE_mesh_uv_vert_map_make(struct MPoly *mpoly, struct MLoop *mloop, struct MLoopUV *mloopuv,
268 unsigned int totpoly, unsigned int totvert, int selected, float *limit);
269 UvMapVert *BKE_mesh_uv_vert_map_get_vert(UvVertMap *vmap, unsigned int v);
270 void BKE_mesh_uv_vert_map_free(UvVertMap *vmap);
272 /* Connectivity data */
273 typedef struct MeshElemMap {
278 typedef struct IndexNode {
279 struct IndexNode *next, *prev;
283 void create_vert_poly_map(MeshElemMap **map, int **mem,
284 const struct MPoly *mface, const struct MLoop *mloop,
285 int totvert, int totface, int totloop);
287 void create_vert_edge_map(MeshElemMap **map, int **mem,
288 const struct MEdge *medge, int totvert, int totedge);
290 /* vertex level transformations & checks (no derived mesh) */
292 int BKE_mesh_minmax(struct Mesh *me, float r_min[3], float r_max[3]);
293 int BKE_mesh_center_median(struct Mesh *me, float cent[3]);
294 int BKE_mesh_center_bounds(struct Mesh *me, float cent[3]);
295 int BKE_mesh_center_centroid(struct Mesh *me, float cent[3]);
296 void BKE_mesh_translate(struct Mesh *me, float offset[3], int do_keys);
298 /* mesh_validate.c */
299 /* XXX Loop v/e are unsigned, so using max uint_32 value as invalid marker... */
300 #define INVALID_LOOP_EDGE_MARKER 4294967295u
301 int BKE_mesh_validate_arrays(
303 struct MVert *mverts, unsigned int totvert,
304 struct MEdge *medges, unsigned int totedge,
305 struct MFace *mfaces, unsigned int totface,
306 struct MLoop *mloops, unsigned int totloop,
307 struct MPoly *mpolys, unsigned int totpoly,
308 struct MDeformVert *dverts, /* assume totvert length */
309 const short do_verbose, const short do_fixes);
310 int BKE_mesh_validate(struct Mesh *me, int do_verbose);
311 int BKE_mesh_validate_dm(struct DerivedMesh *dm);
313 void BKE_mesh_calc_edges(struct Mesh *mesh, int update);
315 void BKE_mesh_ensure_navmesh(struct Mesh *me);
317 void BKE_mesh_tessface_calc(struct Mesh *mesh);
318 void BKE_mesh_tessface_ensure(struct Mesh *mesh);
319 void BKE_mesh_tessface_clear(struct Mesh *mesh);
321 /* Convert a triangle or quadrangle of loop/poly data to tessface data */
322 void BKE_mesh_loops_to_mface_corners(struct CustomData *fdata, struct CustomData *ldata,
323 struct CustomData *pdata, int lindex[4], int findex,
324 const int polyindex, const int mf_len,
325 const int numTex, const int numCol, const int hasPCol, const int hasOrigSpace);
327 void BKE_mesh_poly_calc_angles(struct MVert *mvert, struct MLoop *mloop,
328 struct MPoly *mp, float angles[]);
334 #endif /* __BKE_MESH_H__ */