Blender  V2.93
BKE_DerivedMesh.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
20 #pragma once
21 
57 /*
58  * Note: This structure is read-only, for all practical purposes.
59  * At some point in the future, we may want to consider
60  * creating a replacement structure that implements a proper
61  * abstract mesh kernel interface. Or, we can leave this
62  * as it is and stick with using BMesh and CDDM.
63  */
64 
65 #include "DNA_customdata_types.h"
66 #include "DNA_defs.h"
67 #include "DNA_meshdata_types.h"
68 
69 #include "BLI_compiler_attrs.h"
70 
71 #include "BKE_bvhutils.h"
72 #include "BKE_customdata.h"
73 
74 #ifdef __cplusplus
75 extern "C" {
76 #endif
77 
78 struct BMEditMesh;
79 struct CCGElem;
80 struct CCGKey;
82 struct Depsgraph;
83 struct MEdge;
84 struct MFace;
85 struct MVert;
86 struct Mesh;
87 struct ModifierData;
88 struct Object;
89 struct Scene;
90 
91 /*
92  * Note: all mface interfaces now officially operate on tessellated data.
93  * Also, the mface origindex layer indexes mpolys, not mfaces.
94  */
95 
96 /* keep in sync with MFace/MPoly types */
97 typedef struct DMFlagMat {
98  short mat_nr;
99  char flag;
101 
102 typedef enum DerivedMeshType {
106 
107 typedef enum DMDirtyFlag {
108  /* dm has valid tessellated faces, but tessellated CDDATA need to be updated. */
110 
111  /* check this with modifier dependsOnNormals callback to see if normals need recalculation */
114 
115 typedef struct DerivedMesh DerivedMesh;
116 struct DerivedMesh {
120  int needsFree; /* checked on ->release, is set to 0 for cached results */
121  int deformedOnly; /* set by modifier stack if only deformed from original */
124 
128  struct {
129  /* WARNING! swapping between array (ready-to-be-used data) and array_wip
130  * (where data is actually computed) shall always be protected by same
131  * lock as one used for looptris computing. */
133  int num;
136 
137  /* use for converting to BMesh which doesn't store bevel weight and edge crease by default */
138  char cd_flag;
139 
140  short tangent_mask; /* which tangent layers are calculated */
141 
143  void (*calcNormals)(DerivedMesh *dm);
144 
148  const struct MLoopTri *(*getLoopTriArray)(DerivedMesh *dm);
150 
151  /* Misc. Queries */
152 
153  /* Also called in Editmode */
159 
165  void (*getVert)(DerivedMesh *dm, int index, struct MVert *r_vert);
166  void (*getEdge)(DerivedMesh *dm, int index, struct MEdge *r_edge);
167  void (*getTessFace)(DerivedMesh *dm, int index, struct MFace *r_face);
168 
174  struct MVert *(*getVertArray)(DerivedMesh *dm);
175  struct MEdge *(*getEdgeArray)(DerivedMesh *dm);
176  struct MFace *(*getTessFaceArray)(DerivedMesh *dm);
177  struct MLoop *(*getLoopArray)(DerivedMesh *dm);
178  struct MPoly *(*getPolyArray)(DerivedMesh *dm);
179 
183  void (*copyVertArray)(DerivedMesh *dm, struct MVert *r_vert);
184  void (*copyEdgeArray)(DerivedMesh *dm, struct MEdge *r_edge);
185  void (*copyTessFaceArray)(DerivedMesh *dm, struct MFace *r_face);
186  void (*copyLoopArray)(DerivedMesh *dm, struct MLoop *r_loop);
187  void (*copyPolyArray)(DerivedMesh *dm, struct MPoly *r_poly);
188 
192  struct MVert *(*dupVertArray)(DerivedMesh *dm);
193  struct MEdge *(*dupEdgeArray)(DerivedMesh *dm);
194  struct MFace *(*dupTessFaceArray)(DerivedMesh *dm);
195  struct MLoop *(*dupLoopArray)(DerivedMesh *dm);
196  struct MPoly *(*dupPolyArray)(DerivedMesh *dm);
197 
202  void *(*getVertData)(DerivedMesh *dm, int index, int type);
203  void *(*getEdgeData)(DerivedMesh *dm, int index, int type);
204  void *(*getTessFaceData)(DerivedMesh *dm, int index, int type);
205  void *(*getPolyData)(DerivedMesh *dm, int index, int type);
206 
211  void *(*getVertDataArray)(DerivedMesh *dm, int type);
212  void *(*getEdgeDataArray)(DerivedMesh *dm, int type);
213  void *(*getTessFaceDataArray)(DerivedMesh *dm, int type);
214  void *(*getLoopDataArray)(DerivedMesh *dm, int type);
215  void *(*getPolyDataArray)(DerivedMesh *dm, int type);
216 
219  CustomData *(*getVertDataLayout)(DerivedMesh *dm);
220  CustomData *(*getEdgeDataLayout)(DerivedMesh *dm);
221  CustomData *(*getTessFaceDataLayout)(DerivedMesh *dm);
222  CustomData *(*getLoopDataLayout)(DerivedMesh *dm);
223  CustomData *(*getPolyDataLayout)(DerivedMesh *dm);
224 
228  struct CCGElem **(*getGridData)(DerivedMesh *dm);
229  int *(*getGridOffset)(DerivedMesh *dm);
230  void (*getGridKey)(DerivedMesh *dm, struct CCGKey *key);
231  DMFlagMat *(*getGridFlagMats)(DerivedMesh *dm);
232  unsigned int **(*getGridHidden)(DerivedMesh *dm);
233 
239  void (*getVertCo)(DerivedMesh *dm, int index, float r_co[3]);
240 
242  void (*getVertNo)(DerivedMesh *dm, int index, float r_no[3]);
243  void (*getPolyNo)(DerivedMesh *dm, int index, float r_no[3]);
244 
247  const struct MeshElemMap *(*getPolyMap)(struct Object *ob, DerivedMesh *dm);
248 
251  void (*release)(DerivedMesh *dm);
252 };
253 
254 void DM_init_funcs(DerivedMesh *dm);
255 
256 void DM_init(DerivedMesh *dm,
258  int numVerts,
259  int numEdges,
260  int numTessFaces,
261  int numLoops,
262  int numPolys);
263 
265  DerivedMesh *source,
267  int numVerts,
268  int numEdges,
269  int numTessFaces,
270  int numLoops,
271  int numPolys,
272  const struct CustomData_MeshMasks *mask);
274  DerivedMesh *source,
276  int numVerts,
277  int numEdges,
278  int numTessFaces,
279  int numLoops,
280  int numPolys);
281 
286 bool DM_release(DerivedMesh *dm);
287 
289 
290 /* adds a vertex/edge/face custom data layer to a DerivedMesh, optionally
291  * backed by an external data array
292  * alloctype defines how the layer is allocated or copied, and how it is
293  * freed, see BKE_customdata.h for the different options
294  */
295 void DM_add_vert_layer(struct DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer);
296 void DM_add_edge_layer(struct DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer);
297 void DM_add_tessface_layer(struct DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer);
298 void DM_add_loop_layer(DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer);
299 void DM_add_poly_layer(struct DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer);
300 
301 /* custom data access functions
302  * return pointer to data from first layer which matches type
303  * if they return NULL for valid indices, data doesn't exist
304  * note these return pointers - any change modifies the internals of the mesh
305  */
306 void *DM_get_vert_data(struct DerivedMesh *dm, int index, int type);
307 void *DM_get_edge_data(struct DerivedMesh *dm, int index, int type);
308 void *DM_get_tessface_data(struct DerivedMesh *dm, int index, int type);
309 void *DM_get_poly_data(struct DerivedMesh *dm, int index, int type);
310 
311 /* custom data layer access functions
312  * return pointer to first data layer which matches type (a flat array)
313  * if they return NULL, data doesn't exist
314  * note these return pointers - any change modifies the internals of the mesh
315  */
316 void *DM_get_vert_data_layer(struct DerivedMesh *dm, int type);
317 void *DM_get_edge_data_layer(struct DerivedMesh *dm, int type);
318 void *DM_get_tessface_data_layer(struct DerivedMesh *dm, int type);
319 void *DM_get_poly_data_layer(struct DerivedMesh *dm, int type);
320 void *DM_get_loop_data_layer(struct DerivedMesh *dm, int type);
321 
322 /* custom data copy functions
323  * copy count elements from source_index in source to dest_index in dest
324  * these copy all layers for which the CD_FLAG_NOCOPY flag is not set
325  */
326 void DM_copy_vert_data(struct DerivedMesh *source,
327  struct DerivedMesh *dest,
328  int source_index,
329  int dest_index,
330  int count);
331 
332 /*sets up mpolys for a DM based on face iterators in source*/
333 void DM_DupPolys(DerivedMesh *source, DerivedMesh *target);
334 
336 
338 
339 void DM_interp_vert_data(struct DerivedMesh *source,
340  struct DerivedMesh *dest,
341  int *src_indices,
342  float *weights,
343  int count,
344  int dest_index);
345 
346 void mesh_get_mapped_verts_coords(struct Mesh *me_eval, float (*r_cos)[3], const int totcos);
347 
348 /* same as above but wont use render settings */
350  struct Scene *scene,
351  struct Object *,
352  struct BMEditMesh *em,
353  const struct CustomData_MeshMasks *dataMask);
355  struct Scene *scene,
356  struct Object *obedit,
357  const struct CustomData_MeshMasks *dataMask);
359  struct Scene *scene,
360  struct Object *,
361  struct BMEditMesh *em,
362  const struct CustomData_MeshMasks *dataMask,
363  struct Mesh **r_final);
364 
365 float (*editbmesh_vert_coords_alloc(struct BMEditMesh *em, int *r_vert_len))[3];
367  const struct Object *ob,
368  struct ModifierData *md,
369  bool has_prev_mesh);
371  struct Scene *scene,
372  struct Object *ob,
373  struct BMEditMesh *em,
374  const struct CustomData_MeshMasks *dataMask);
375 
377  bool calc_active_tangent,
378  const char (*tangent_names)[MAX_NAME],
379  int tangent_names_len);
380 
381 /* debug only */
382 #ifndef NDEBUG
383 char *DM_debug_info(DerivedMesh *dm);
384 void DM_debug_print(DerivedMesh *dm);
385 
386 bool DM_is_valid(DerivedMesh *dm);
387 #endif
388 
389 #ifdef __cplusplus
390 }
391 #endif
typedef float(TangentPoint)[2]
void * DM_get_edge_data_layer(struct DerivedMesh *dm, int type)
Definition: DerivedMesh.cc:626
void DM_interp_vert_data(struct DerivedMesh *source, struct DerivedMesh *dest, int *src_indices, float *weights, int count, int dest_index)
Definition: DerivedMesh.cc:665
void DM_copy_vert_data(struct DerivedMesh *source, struct DerivedMesh *dest, int source_index, int dest_index, int count)
Definition: DerivedMesh.cc:654
void DM_ensure_normals(DerivedMesh *dm)
Definition: DerivedMesh.cc:479
void * DM_get_poly_data_layer(struct DerivedMesh *dm, int type)
Definition: DerivedMesh.cc:644
void DM_add_vert_layer(struct DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
Definition: DerivedMesh.cc:568
bool DM_is_valid(DerivedMesh *dm)
void * DM_get_edge_data(struct DerivedMesh *dm, int index, int type)
Definition: DerivedMesh.cc:599
void * DM_get_vert_data(struct DerivedMesh *dm, int index, int type)
Definition: DerivedMesh.cc:593
void DM_calc_loop_tangents(DerivedMesh *dm, bool calc_active_tangent, const char(*tangent_names)[MAX_NAME], int tangent_names_len)
void DM_debug_print(DerivedMesh *dm)
void DM_set_only_copy(DerivedMesh *dm, const struct CustomData_MeshMasks *mask)
char * DM_debug_info(DerivedMesh *dm)
void * DM_get_poly_data(struct DerivedMesh *dm, int index, int type)
Definition: DerivedMesh.cc:611
struct Mesh * editbmesh_get_eval_cage_and_final(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *, struct BMEditMesh *em, const struct CustomData_MeshMasks *dataMask, struct Mesh **r_final)
void DM_init(DerivedMesh *dm, DerivedMeshType type, int numVerts, int numEdges, int numTessFaces, int numLoops, int numPolys)
Definition: DerivedMesh.cc:342
void makeDerivedMesh(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct BMEditMesh *em, const struct CustomData_MeshMasks *dataMask)
void DM_from_template_ex(DerivedMesh *dm, DerivedMesh *source, DerivedMeshType type, int numVerts, int numEdges, int numTessFaces, int numLoops, int numPolys, const struct CustomData_MeshMasks *mask)
void * DM_get_tessface_data_layer(struct DerivedMesh *dm, int type)
Definition: DerivedMesh.cc:635
bool DM_release(DerivedMesh *dm)
Definition: DerivedMesh.cc:424
void DM_from_template(DerivedMesh *dm, DerivedMesh *source, DerivedMeshType type, int numVerts, int numEdges, int numTessFaces, int numLoops, int numPolys)
Definition: DerivedMesh.cc:404
void DM_ensure_looptri_data(DerivedMesh *dm)
Definition: DerivedMesh.cc:493
struct Mesh * editbmesh_get_eval_cage_from_orig(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *obedit, const struct CustomData_MeshMasks *dataMask)
void * DM_get_tessface_data(struct DerivedMesh *dm, int index, int type)
Definition: DerivedMesh.cc:605
void * DM_get_vert_data_layer(struct DerivedMesh *dm, int type)
Definition: DerivedMesh.cc:617
struct Mesh * editbmesh_get_eval_cage(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *, struct BMEditMesh *em, const struct CustomData_MeshMasks *dataMask)
bool editbmesh_modifier_is_enabled(struct Scene *scene, const struct Object *ob, struct ModifierData *md, bool has_prev_mesh)
void DM_DupPolys(DerivedMesh *source, DerivedMesh *target)
Definition: DerivedMesh.cc:449
void mesh_get_mapped_verts_coords(struct Mesh *me_eval, float(*r_cos)[3], const int totcos)
struct DMFlagMat DMFlagMat
void * DM_get_loop_data_layer(struct DerivedMesh *dm, int type)
Definition: DerivedMesh.cc:649
void DM_init_funcs(DerivedMesh *dm)
Definition: DerivedMesh.cc:301
void DM_add_tessface_layer(struct DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
Definition: DerivedMesh.cc:578
void DM_add_loop_layer(DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
Definition: DerivedMesh.cc:583
float(* editbmesh_vert_coords_alloc(struct BMEditMesh *em, int *r_vert_len))[3]
void DM_add_edge_layer(struct DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
Definition: DerivedMesh.cc:573
DerivedMeshType
@ DM_TYPE_CDDM
@ DM_TYPE_CCGDM
void DM_add_poly_layer(struct DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
Definition: DerivedMesh.cc:588
DMDirtyFlag
@ DM_DIRTY_TESS_CDLAYERS
@ DM_DIRTY_NORMALS
struct CCGElem CCGElem
Definition: BKE_ccg.h:46
CustomData interface, see also DNA_customdata_types.h.
eCDAllocType
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
#define MAX_NAME
Definition: DNA_defs.h:62
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Scene scene
const Depsgraph * depsgraph
int count
Definition: BKE_ccg.h:48
struct DerivedMesh::@15 looptris
int(* getGridSize)(DerivedMesh *dm)
CustomData faceData
void(* getVertNo)(DerivedMesh *dm, int index, float r_no[3])
CustomData vertData
void(* copyLoopArray)(DerivedMesh *dm, struct MLoop *r_loop)
void(* copyEdgeArray)(DerivedMesh *dm, struct MEdge *r_edge)
int(* getNumVerts)(DerivedMesh *dm)
int(* getNumLoopTri)(DerivedMesh *dm)
void(* copyPolyArray)(DerivedMesh *dm, struct MPoly *r_poly)
int(* getNumPolys)(DerivedMesh *dm)
int(* getNumEdges)(DerivedMesh *dm)
int(* getNumGrids)(DerivedMesh *dm)
CustomData polyData
int(* getNumTessFaces)(DerivedMesh *dm)
struct MLoopTri * array_wip
void(* copyVertArray)(DerivedMesh *dm, struct MVert *r_vert)
void(* getVert)(DerivedMesh *dm, int index, struct MVert *r_vert)
void(* calcNormals)(DerivedMesh *dm)
void(* getGridKey)(DerivedMesh *dm, struct CCGKey *key)
CustomData edgeData
void(* copyTessFaceArray)(DerivedMesh *dm, struct MFace *r_face)
void(* getEdge)(DerivedMesh *dm, int index, struct MEdge *r_edge)
CustomData loopData
void(* recalcLoopTri)(DerivedMesh *dm)
struct MLoopTri * array
void(* getTessFace)(DerivedMesh *dm, int index, struct MFace *r_face)
void(* release)(DerivedMesh *dm)
void(* getVertCo)(DerivedMesh *dm, int index, float r_co[3])
void(* getPolyNo)(DerivedMesh *dm, int index, float r_no[3])
DMDirtyFlag dirty
int(* getNumLoops)(DerivedMesh *dm)
DerivedMeshType type
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)