150
155
typedef enum DMDirtyFlag {
151
156
/* dm has valid tessellated faces, but tessellated CDDATA need to be updated. */
152
157
DM_DIRTY_TESS_CDLAYERS = 1 << 0,
158
/* One of the MCOL layers have been updated, force updating of GPUDrawObject's colors buffer.
159
* This is necessary with modern, VBO draw code, as e.g. in vpaint mode me->mcol may be updated
160
* without actually rebuilding dm (hence by defautl keeping same GPUDrawObject, and same colors
161
* buffer, which prevents update during a stroke!). */
162
DM_DIRTY_MCOL_UPDATE_DRAW = 1 << 1,
155
165
typedef struct DerivedMesh DerivedMesh;
156
166
struct DerivedMesh {
157
/* Private DerivedMesh data, only for internal DerivedMesh use */
167
/** Private DerivedMesh data, only for internal DerivedMesh use */
158
168
CustomData vertData, edgeData, faceData, loopData, polyData;
159
169
int numVertData, numEdgeData, numTessFaceData, numLoopData, numPolyData;
160
170
int needsFree; /* checked on ->release, is set to 0 for cached results */
189
202
void (*getEdge)(DerivedMesh *dm, int index, struct MEdge *edge_r);
190
203
void (*getTessFace)(DerivedMesh *dm, int index, struct MFace *face_r);
192
/* return a pointer to the entire array of verts/edges/face from the
205
/** Return a pointer to the entire array of verts/edges/face from the
193
206
* derived mesh. if such an array does not exist yet, it will be created,
194
207
* and freed on the next ->release(). consider using getVert/Edge/Face if
195
208
* you are only interested in a few verts/edges/faces.
197
struct MVert *(*getVertArray)(DerivedMesh *dm);
198
struct MEdge *(*getEdgeArray)(DerivedMesh *dm);
199
struct MFace *(*getTessFaceArray)(DerivedMesh *dm);
200
struct MLoop *(*getLoopArray)(DerivedMesh *dm);
201
struct MPoly *(*getPolyArray)(DerivedMesh *dm);
210
struct MVert *(*getVertArray)(DerivedMesh * dm);
211
struct MEdge *(*getEdgeArray)(DerivedMesh * dm);
212
struct MFace *(*getTessFaceArray)(DerivedMesh * dm);
213
struct MLoop *(*getLoopArray)(DerivedMesh * dm);
214
struct MPoly *(*getPolyArray)(DerivedMesh * dm);
203
/* copy all verts/edges/faces from the derived mesh into
216
/** Copy all verts/edges/faces from the derived mesh into
204
217
* *{vert/edge/face}_r (must point to a buffer large enough)
206
219
void (*copyVertArray)(DerivedMesh *dm, struct MVert *vert_r);
209
222
void (*copyLoopArray)(DerivedMesh *dm, struct MLoop *loop_r);
210
223
void (*copyPolyArray)(DerivedMesh *dm, struct MPoly *poly_r);
212
/* return a copy of all verts/edges/faces from the derived mesh
225
/** Return a copy of all verts/edges/faces from the derived mesh
213
226
* it is the caller's responsibility to free the returned pointer
215
struct MVert *(*dupVertArray)(DerivedMesh *dm);
216
struct MEdge *(*dupEdgeArray)(DerivedMesh *dm);
217
struct MFace *(*dupTessFaceArray)(DerivedMesh *dm);
218
struct MLoop *(*dupLoopArray)(DerivedMesh *dm);
219
struct MPoly *(*dupPolyArray)(DerivedMesh *dm);
221
/* return a pointer to a single element of vert/edge/face custom data
222
* from the derived mesh (this gives a pointer to the actual data, not
225
void *(*getVertData)(DerivedMesh *dm, int index, int type);
226
void *(*getEdgeData)(DerivedMesh *dm, int index, int type);
227
void *(*getTessFaceData)(DerivedMesh *dm, int index, int type);
229
/* return a pointer to the entire array of vert/edge/face custom data
230
* from the derived mesh (this gives a pointer to the actual data, not
233
void *(*getVertDataArray)(DerivedMesh *dm, int type);
234
void *(*getEdgeDataArray)(DerivedMesh *dm, int type);
235
void *(*getTessFaceDataArray)(DerivedMesh *dm, int type);
237
/* retrieves the base CustomData structures for
228
struct MVert *(*dupVertArray)(DerivedMesh * dm);
229
struct MEdge *(*dupEdgeArray)(DerivedMesh * dm);
230
struct MFace *(*dupTessFaceArray)(DerivedMesh * dm);
231
struct MLoop *(*dupLoopArray)(DerivedMesh * dm);
232
struct MPoly *(*dupPolyArray)(DerivedMesh * dm);
234
/** Return a pointer to a single element of vert/edge/face custom data
235
* from the derived mesh (this gives a pointer to the actual data, not
238
void *(*getVertData)(DerivedMesh * dm, int index, int type);
239
void *(*getEdgeData)(DerivedMesh * dm, int index, int type);
240
void *(*getTessFaceData)(DerivedMesh * dm, int index, int type);
241
void *(*getPolyData)(DerivedMesh * dm, int index, int type);
243
/** Return a pointer to the entire array of vert/edge/face custom data
244
* from the derived mesh (this gives a pointer to the actual data, not
247
void *(*getVertDataArray)(DerivedMesh * dm, int type);
248
void *(*getEdgeDataArray)(DerivedMesh * dm, int type);
249
void *(*getTessFaceDataArray)(DerivedMesh * dm, int type);
250
void *(*getPolyDataArray)(DerivedMesh * dm, int type);
252
/** Retrieves the base CustomData structures for
238
253
* verts/edges/tessfaces/loops/facdes*/
239
CustomData *(*getVertDataLayout)(DerivedMesh *dm);
240
CustomData *(*getEdgeDataLayout)(DerivedMesh *dm);
241
CustomData *(*getTessFaceDataLayout)(DerivedMesh *dm);
242
CustomData *(*getLoopDataLayout)(DerivedMesh *dm);
243
CustomData *(*getPolyDataLayout)(DerivedMesh *dm);
254
CustomData *(*getVertDataLayout)(DerivedMesh * dm);
255
CustomData *(*getEdgeDataLayout)(DerivedMesh * dm);
256
CustomData *(*getTessFaceDataLayout)(DerivedMesh * dm);
257
CustomData *(*getLoopDataLayout)(DerivedMesh * dm);
258
CustomData *(*getPolyDataLayout)(DerivedMesh * dm);
245
/*copies all customdata for an element source into dst at index dest*/
260
/** Copies all customdata for an element source into dst at index dest */
246
261
void (*copyFromVertCData)(DerivedMesh *dm, int source, CustomData *dst, int dest);
247
262
void (*copyFromEdgeCData)(DerivedMesh *dm, int source, CustomData *dst, int dest);
248
263
void (*copyFromFaceCData)(DerivedMesh *dm, int source, CustomData *dst, int dest);
250
/* optional grid access for subsurf */
265
/** Optional grid access for subsurf */
251
266
int (*getNumGrids)(DerivedMesh *dm);
252
267
int (*getGridSize)(DerivedMesh *dm);
253
DMGridData **(*getGridData)(DerivedMesh *dm);
254
DMGridAdjacency *(*getGridAdjacency)(DerivedMesh *dm);
255
int *(*getGridOffset)(DerivedMesh *dm);
256
DMFlagMat *(*getGridFlagMats)(DerivedMesh *dm);
257
unsigned int **(*getGridHidden)(DerivedMesh *dm);
268
struct CCGElem **(*getGridData)(DerivedMesh * dm);
269
DMGridAdjacency *(*getGridAdjacency)(DerivedMesh * dm);
270
int *(*getGridOffset)(DerivedMesh * dm);
271
void (*getGridKey)(DerivedMesh *dm, struct CCGKey *key);
272
DMFlagMat *(*getGridFlagMats)(DerivedMesh * dm);
273
unsigned int **(*getGridHidden)(DerivedMesh * dm);
260
/* Iterate over each mapped vertex in the derived mesh, calling the
276
/** Iterate over each mapped vertex in the derived mesh, calling the
261
277
* given function with the original vert and the mapped vert's new
262
278
* coordinate and normal. For historical reasons the normal can be
263
279
* passed as a float or short array, only one should be non-NULL.
285
301
const float cent[3], const float no[3]),
288
/* Iterate over all vertex points, calling DO_MINMAX with given args.
304
/** Iterate over all vertex points, calling DO_MINMAX with given args.
290
306
* Also called in Editmode
292
308
void (*getMinMax)(DerivedMesh *dm, float min_r[3], float max_r[3]);
294
/* Direct Access Operations */
295
/* o Can be undefined */
296
/* o Must be defined for modifiers that only deform however */
310
/** Direct Access Operations
312
* - Must be defined for modifiers that only deform however */
298
/* Get vertex location, undefined if index is not valid */
314
/** Get vertex location, undefined if index is not valid */
299
315
void (*getVertCo)(DerivedMesh *dm, int index, float co_r[3]);
301
/* Fill the array (of length .getNumVerts()) with all vertex locations */
317
/** Fill the array (of length .getNumVerts()) with all vertex locations */
302
318
void (*getVertCos)(DerivedMesh *dm, float (*cos_r)[3]);
304
/* Get smooth vertex normal, undefined if index is not valid */
320
/** Get smooth vertex normal, undefined if index is not valid */
305
321
void (*getVertNo)(DerivedMesh *dm, int index, float no_r[3]);
307
/* Get a map of vertices to faces
323
/** Get a map of vertices to faces
309
325
const struct MeshElemMap *(*getPolyMap)(struct Object *ob, DerivedMesh *dm);
311
/* Get the BVH used for paint modes
327
/** Get the BVH used for paint modes
313
329
struct PBVH *(*getPBVH)(struct Object *ob, DerivedMesh *dm);
315
331
/* Drawing Operations */
317
/* Draw all vertices as bgl points (no options) */
333
/** Draw all vertices as bgl points (no options) */
318
334
void (*drawVerts)(DerivedMesh *dm);
320
/* Draw edges in the UV mesh (if exists) */
336
/** Draw edges in the UV mesh (if exists) */
321
337
void (*drawUVEdges)(DerivedMesh *dm);
323
/* Draw all edges as lines (no options)
339
/** Draw all edges as lines (no options)
325
341
* Also called for *final* editmode DerivedMeshes
327
343
void (*drawEdges)(DerivedMesh *dm, int drawLooseEdges, int drawAllEdges);
329
/* Draw all loose edges (edges w/ no adjoining faces) */
345
/** Draw all loose edges (edges w/ no adjoining faces) */
330
346
void (*drawLooseEdges)(DerivedMesh *dm);
333
349
* o Set face normal or vertex normal based on inherited face flag
334
350
* o Use inherited face material index to call setMaterial
335
351
* o Only if setMaterial returns true
337
353
* Also called for *final* editmode DerivedMeshes
339
355
void (*drawFacesSolid)(DerivedMesh *dm, float (*partial_redraw_planes)[4],
340
int fast, DMSetMaterial setMaterial);
356
int fast, DMSetMaterial setMaterial);
342
/* Draw all faces using MTFace
343
* o Drawing options too complicated to enumerate, look at code.
358
/** Draw all faces using MTFace
359
* - Drawing options too complicated to enumerate, look at code.
345
361
void (*drawFacesTex)(DerivedMesh *dm,
346
362
DMSetDrawOptionsTex setDrawOptions,
347
DMCompareDrawOptions compareDrawOptions,
363
DMCompareDrawOptions compareDrawOptions,
350
/* Draw all faces with GLSL materials
366
/** Draw all faces with GLSL materials
351
367
* o setMaterial is called for every different material nr
352
368
* o Only if setMaterial returns true
354
370
void (*drawFacesGLSL)(DerivedMesh *dm, DMSetMaterial setMaterial);
356
/* Draw mapped faces (no color, or texture)
357
* o Only if !setDrawOptions or
358
* setDrawOptions(userData, mapped-face-index, drawSmooth_r)
372
/** Draw mapped faces (no color, or texture)
373
* - Only if !setDrawOptions or
374
* setDrawOptions(userData, mapped-face-index, drawSmooth_r)
361
377
* If drawSmooth is set to true then vertex normals should be set and
362
378
* glShadeModel called with GL_SMOOTH. Otherwise the face normal should
369
385
void (*drawMappedFaces)(DerivedMesh *dm,
370
DMSetDrawOptions setDrawOptions,
371
DMSetMaterial setMaterial,
372
DMCompareDrawOptions compareDrawOptions,
386
DMSetDrawOptions setDrawOptions,
387
DMSetMaterial setMaterial,
388
DMCompareDrawOptions compareDrawOptions,
376
/* Draw mapped faces using MTFace
377
* o Drawing options too complicated to enumerate, look at code.
392
/** Draw mapped faces using MTFace
393
* - Drawing options too complicated to enumerate, look at code.
379
395
void (*drawMappedFacesTex)(DerivedMesh *dm,
380
DMSetDrawOptions setDrawOptions,
381
DMCompareDrawOptions compareDrawOptions,
396
DMSetDrawOptions setDrawOptions,
397
DMCompareDrawOptions compareDrawOptions,
384
/* Draw mapped faces with GLSL materials
385
* o setMaterial is called for every different material nr
386
* o setDrawOptions is called for every face
387
* o Only if setMaterial and setDrawOptions return true
400
/** Draw mapped faces with GLSL materials
401
* - setMaterial is called for every different material nr
402
* - setDrawOptions is called for every face
403
* - Only if setMaterial and setDrawOptions return true
389
405
void (*drawMappedFacesGLSL)(DerivedMesh *dm,
390
DMSetMaterial setMaterial,
391
DMSetDrawOptions setDrawOptions,
406
DMSetMaterial setMaterial,
407
DMSetDrawOptions setDrawOptions,
394
/* Draw mapped edges as lines
395
* o Only if !setDrawOptions or setDrawOptions(userData, mapped-edge)
410
/** Draw mapped edges as lines
411
* - Only if !setDrawOptions or setDrawOptions(userData, mapped-edge)
398
414
void (*drawMappedEdges)(DerivedMesh *dm,
399
DMSetDrawOptions setDrawOptions,
415
DMSetDrawOptions setDrawOptions,
402
/* Draw mapped edges as lines with interpolation values
403
* o Only if !setDrawOptions or
404
* setDrawOptions(userData, mapped-edge, mapped-v0, mapped-v1, t)
418
/** Draw mapped edges as lines with interpolation values
419
* - Only if !setDrawOptions or
420
* setDrawOptions(userData, mapped-edge, mapped-v0, mapped-v1, t)
407
423
* NOTE: This routine is optional!
409
425
void (*drawMappedEdgesInterp)(DerivedMesh *dm,
410
DMSetDrawOptions setDrawOptions,
411
DMSetDrawInterpOptions setDrawInterpOptions,
426
DMSetDrawOptions setDrawOptions,
427
DMSetDrawInterpOptions setDrawInterpOptions,
414
/* Draw all faces with materials
415
* o setMaterial is called for every different material nr
416
* o setFace is called to verify if a face must be hidden
430
/** Draw all faces with materials
431
* - setMaterial is called for every different material nr
432
* - setFace is called to verify if a face must be hidden
418
434
void (*drawMappedFacesMat)(DerivedMesh *dm,
419
void (*setMaterial)(void *userData, int, void *attribs),
420
int (*setFace)(void *userData, int index), void *userData);
435
void (*setMaterial)(void *userData, int, void *attribs),
436
int (*setFace)(void *userData, int index), void *userData);
422
/* Release reference to the DerivedMesh. This function decides internally
438
/** Release reference to the DerivedMesh. This function decides internally
423
439
* if the DerivedMesh will be freed, or cached for later use. */
424
440
void (*release)(DerivedMesh *dm);
427
/* utility function to initialize a DerivedMesh's function pointers to
443
/** utility function to initialize a DerivedMesh's function pointers to
428
444
* the default implementation (for those functions which have a default)
430
446
void DM_init_funcs(DerivedMesh *dm);
432
/* utility function to initialize a DerivedMesh for the desired number
448
/** utility function to initialize a DerivedMesh for the desired number
433
449
* of vertices, edges and faces (doesn't allocate memory for them, just
434
450
* sets up the custom data layers)
436
452
void DM_init(DerivedMesh *dm, DerivedMeshType type, int numVerts, int numEdges,
437
453
int numFaces, int numLoops, int numPolys);
439
/* utility function to initialize a DerivedMesh for the desired number
455
/** utility function to initialize a DerivedMesh for the desired number
440
456
* of vertices, edges and faces, with a layer setup copied from source
442
458
void DM_from_template(DerivedMesh *dm, DerivedMesh *source,
443
DerivedMeshType type,
444
int numVerts, int numEdges, int numFaces,
445
int numLoops, int numPolys);
459
DerivedMeshType type,
460
int numVerts, int numEdges, int numFaces,
461
int numLoops, int numPolys);
447
/* utility function to release a DerivedMesh's layers
463
/** utility function to release a DerivedMesh's layers
448
464
* returns 1 if DerivedMesh has to be released by the backend, 0 otherwise
450
466
int DM_release(DerivedMesh *dm);
452
/* utility function to convert a DerivedMesh to a Mesh
468
/** utility function to convert a DerivedMesh to a Mesh
454
470
void DM_to_mesh(DerivedMesh *dm, struct Mesh *me, struct Object *ob);
520
536
* these copy all layers for which the CD_FLAG_NOCOPY flag is not set
522
538
void DM_copy_vert_data(struct DerivedMesh *source, struct DerivedMesh *dest,
523
int source_index, int dest_index, int count);
539
int source_index, int dest_index, int count);
524
540
void DM_copy_edge_data(struct DerivedMesh *source, struct DerivedMesh *dest,
525
int source_index, int dest_index, int count);
541
int source_index, int dest_index, int count);
526
542
void DM_copy_tessface_data(struct DerivedMesh *source, struct DerivedMesh *dest,
527
int source_index, int dest_index, int count);
543
int source_index, int dest_index, int count);
528
544
void DM_copy_loop_data(struct DerivedMesh *source, struct DerivedMesh *dest,
529
545
int source_index, int dest_index, int count);
530
546
void DM_copy_poly_data(struct DerivedMesh *source, struct DerivedMesh *dest,
531
int source_index, int dest_index, int count);
547
int source_index, int dest_index, int count);
533
549
/* custom data free functions
534
550
* free count elements, starting at index
594
610
/* Temporary? A function to give a colorband to derivedmesh for vertexcolor ranges */
595
611
void vDM_ColorBand_store(struct ColorBand *coba);
597
/* Simple function to get me->totvert amount of vertices/normals,
613
/** Simple function to get me->totvert amount of vertices/normals,
598
614
* correctly deformed and subsurfered. Needed especially when vertexgroups are involved.
599
615
* In use now by vertex/weight paint and particles */
600
float *mesh_get_mapped_verts_nors(struct Scene *scene, struct Object *ob);
616
DMCoNo *mesh_get_mapped_verts_nors(struct Scene *scene, struct Object *ob);
603
619
DerivedMesh *mesh_get_derived_final(struct Scene *scene, struct Object *ob,
604
CustomDataMask dataMask);
620
CustomDataMask dataMask);
605
621
DerivedMesh *mesh_get_derived_deform(struct Scene *scene, struct Object *ob,
606
CustomDataMask dataMask);
622
CustomDataMask dataMask);
608
624
DerivedMesh *mesh_create_derived_for_modifier(struct Scene *scene, struct Object *ob,
609
struct ModifierData *md, int build_shapekey_layers);
625
struct ModifierData *md, int build_shapekey_layers);
611
627
DerivedMesh *mesh_create_derived_render(struct Scene *scene, struct Object *ob,
612
CustomDataMask dataMask);
628
CustomDataMask dataMask);
614
630
DerivedMesh *getEditDerivedBMesh(struct BMEditMesh *em, struct Object *ob,
615
float (*vertexCos)[3]);
631
float (*vertexCos)[3]);
617
633
DerivedMesh *mesh_create_derived_index_render(struct Scene *scene, struct Object *ob, CustomDataMask dataMask, int index);
619
/* same as above but wont use render settings */
635
/* same as above but wont use render settings */
620
636
DerivedMesh *mesh_create_derived(struct Mesh *me, struct Object *ob, float (*vertCos)[3]);
621
637
DerivedMesh *mesh_create_derived_view(struct Scene *scene, struct Object *ob,
622
CustomDataMask dataMask);
638
CustomDataMask dataMask);
623
639
DerivedMesh *mesh_create_derived_no_deform(struct Scene *scene, struct Object *ob,
625
CustomDataMask dataMask);
641
CustomDataMask dataMask);
626
642
DerivedMesh *mesh_create_derived_no_deform_render(struct Scene *scene, struct Object *ob,
628
CustomDataMask dataMask);
644
CustomDataMask dataMask);
629
645
/* for gameengine */
630
646
DerivedMesh *mesh_create_derived_no_virtual(struct Scene *scene, struct Object *ob, float (*vertCos)[3],
631
CustomDataMask dataMask);
647
CustomDataMask dataMask);
632
648
DerivedMesh *mesh_create_derived_physics(struct Scene *scene, struct Object *ob, float (*vertCos)[3],
633
CustomDataMask dataMask);
649
CustomDataMask dataMask);
635
651
DerivedMesh *editbmesh_get_derived_base(struct Object *, struct BMEditMesh *em);
636
652
DerivedMesh *editbmesh_get_derived_cage(struct Scene *scene, struct Object *,
637
struct BMEditMesh *em, CustomDataMask dataMask);
653
struct BMEditMesh *em, CustomDataMask dataMask);
638
654
DerivedMesh *editbmesh_get_derived_cage_and_final(struct Scene *scene, struct Object *,
639
struct BMEditMesh *em, DerivedMesh **final_r,
640
CustomDataMask dataMask);
655
struct BMEditMesh *em, DerivedMesh **final_r,
656
CustomDataMask dataMask);
641
657
float (*editbmesh_get_vertex_cos(struct BMEditMesh *em, int *numVerts_r))[3];
642
658
int editbmesh_modifier_is_enabled(struct Scene *scene, struct ModifierData *md, DerivedMesh *dm);
643
659
void makeDerivedMesh(struct Scene *scene, struct Object *ob, struct BMEditMesh *em,
644
CustomDataMask dataMask, int build_shapekey_layers);
660
CustomDataMask dataMask, int build_shapekey_layers);
646
/* returns an array of deform matrices for crazyspace correction, and the
662
/** returns an array of deform matrices for crazyspace correction, and the
647
663
* number of modifiers left */
648
664
int editbmesh_get_first_deform_matrices(struct Scene *, struct Object *, struct BMEditMesh *em,
649
float (**deformmats)[3][3], float (**deformcos)[3]);
665
float (**deformmats)[3][3], float (**deformcos)[3]);
651
667
void weight_to_rgb(float r_rgb[3], const float weight);
652
/* Update the weight MCOL preview layer.
668
/** Update the weight MCOL preview layer.
653
669
* If weights are NULL, use object's active vgroup(s).
654
670
* Else, weights must be an array of weight float values.
655
671
* If indices is NULL, it must be of numVerts length.
659
675
void DM_update_weight_mcol(struct Object *ob, struct DerivedMesh *dm, int const draw_flag,
660
676
float *weights, int num, const int *indices);
662
/* convert layers requested by a GLSL material to actually available layers in
678
/** convert layers requested by a GLSL material to actually available layers in
663
679
* the DerivedMesh, with both a pointer for arrays and an offset for editmesh */
664
680
typedef struct DMVertexAttribs {
666
682
struct MTFace *array;
667
int emOffset, glIndex, glTexco;
683
int em_offset, gl_index, gl_texco;
668
684
} tface[MAX_MTFACE];
671
687
struct MCol *array;
672
int emOffset, glIndex;
688
int em_offset, gl_index;
673
689
} mcol[MAX_MCOL];
676
692
float (*array)[4];
677
int emOffset, glIndex;
693
int em_offset, gl_index;
681
697
float (*array)[3];
682
int emOffset, glIndex, glTexco;
698
int em_offset, gl_index, gl_texco;
685
701
int tottface, totmcol, tottang, totorco;
686
702
} DMVertexAttribs;
688
704
void DM_vertex_attributes_from_gpu(DerivedMesh *dm,
689
struct GPUVertexAttribs *gattribs, DMVertexAttribs *attribs);
705
struct GPUVertexAttribs *gattribs, DMVertexAttribs *attribs);
691
707
void DM_add_tangent_layer(DerivedMesh *dm);
692
708
void DM_calc_auto_bump_scale(DerivedMesh *dm);
694
/* Set object's bounding box based on DerivedMesh min/max data */
710
/** Set object's bounding box based on DerivedMesh min/max data */
695
711
void DM_set_object_boundbox(struct Object *ob, DerivedMesh *dm);
697
713
void DM_init_origspace(DerivedMesh *dm);