~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/blenkernel/BKE_DerivedMesh.h

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#ifndef __BKE_DERIVEDMESH_H__
29
29
#define __BKE_DERIVEDMESH_H__
30
30
 
31
 
/*
 
31
/**
32
32
 * Basic design of the DerivedMesh system:
33
33
 *
34
34
 * DerivedMesh is a common set of interfaces for mesh systems.
35
35
 *
36
 
 * There are three main mesh data structures in Blender: Mesh, CDDM, and BMesh.
 
36
 * There are three main mesh data structures in Blender:
 
37
 * #Mesh, #CDDerivedMesh and #BMesh.
 
38
 *
37
39
 * These, and a few others, all implement DerivedMesh interfaces, 
38
40
 * which contains unified drawing interfaces, a few utility interfaces, 
39
41
 * and a bunch of read-only interfaces intended mostly for conversion from 
67
69
 *       as it is and stick with using BMesh and CDDM.
68
70
 */
69
71
 
70
 
 
71
72
#include "DNA_customdata_types.h"
72
73
#include "DNA_meshdata_types.h"
73
74
 
74
75
#include "BKE_customdata.h"
75
76
#include "BKE_bvhutils.h"
76
77
 
 
78
struct CCGElem;
 
79
struct CCGKey;
77
80
struct MVert;
78
81
struct MEdge;
79
82
struct MFace;
92
95
struct ListBase;
93
96
struct PBVH;
94
97
 
 
98
#define DM_OMP_LIMIT 10000  /* setting zero so we can catch bugs in OpenMP/BMesh */
 
99
 
95
100
/* number of sub-elements each mesh element has (for interpolation) */
96
101
#define SUB_ELEMS_VERT 0
97
102
#define SUB_ELEMS_EDGE 2
102
107
 *       Also, the mface origindex layer indexes mpolys, not mfaces.
103
108
 */
104
109
 
105
 
typedef struct DMGridData {
 
110
typedef struct DMCoNo {
106
111
        float co[3];
107
112
        float no[3];
108
 
} DMGridData;
 
113
} DMCoNo;
109
114
 
110
115
typedef struct DMGridAdjacency {
111
116
        int index[4];
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,
153
163
} DMDirtyFlag;
154
164
 
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 */
165
175
        float auto_bump_scale;
166
176
        DMDirtyFlag dirty;
167
177
 
168
 
        /* calculate vert and face normals */
 
178
        /* use for converting to BMesh which doesn't store bevel weight and edge crease by default */
 
179
        char cd_flag;
 
180
 
 
181
        /** Calculate vert and face normals */
169
182
        void (*calcNormals)(DerivedMesh *dm);
170
183
 
171
 
        /* recalculates mesh tessellation */
 
184
        /** Recalculates mesh tessellation */
172
185
        void (*recalcTessellation)(DerivedMesh *dm);
173
186
 
174
187
        /* Misc. Queries */
180
193
        int (*getNumLoops)(DerivedMesh *dm);
181
194
        int (*getNumPolys)(DerivedMesh *dm);
182
195
 
183
 
        /* copy a single vert/edge/tessellated face from the derived mesh into
 
196
        /** Copy a single vert/edge/tessellated face from the derived mesh into
184
197
         * *{vert/edge/face}_r. note that the current implementation
185
198
         * of this function can be quite slow, iterating over all
186
199
         * elements (editmesh)
189
202
        void (*getEdge)(DerivedMesh *dm, int index, struct MEdge *edge_r);
190
203
        void (*getTessFace)(DerivedMesh *dm, int index, struct MFace *face_r);
191
204
 
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.
196
209
         */
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);
202
215
 
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)
205
218
         */
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);
211
224
 
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
214
227
         */
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);
220
 
 
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
223
 
         * a copy)
224
 
         */
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);
228
 
 
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
231
 
         * a copy)
232
 
         */
233
 
        void *(*getVertDataArray)(DerivedMesh *dm, int type);
234
 
        void *(*getEdgeDataArray)(DerivedMesh *dm, int type);
235
 
        void *(*getTessFaceDataArray)(DerivedMesh *dm, int type);
236
 
        
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);
 
233
 
 
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
 
236
         * a copy)
 
237
         */
 
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);
 
242
 
 
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
 
245
         * a copy)
 
246
         */
 
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);
 
251
 
 
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);
244
259
        
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);
249
264
        
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);
258
274
        
259
275
 
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.
267
283
                                               const float no_f[3], const short no_s[3]),
268
284
                                  void *userData);
269
285
 
270
 
        /* Iterate over each mapped edge in the derived mesh, calling the
 
286
        /** Iterate over each mapped edge in the derived mesh, calling the
271
287
         * given function with the original edge and the mapped edge's new
272
288
         * coordinates.
273
289
         */
276
292
                                               const float v0co[3], const float v1co[3]),
277
293
                                  void *userData);
278
294
 
279
 
        /* Iterate over each mapped face in the derived mesh, calling the
 
295
        /** Iterate over each mapped face in the derived mesh, calling the
280
296
         * given function with the original face and the mapped face's (or
281
297
         * faces') center and normal.
282
298
         */
285
301
                                                     const float cent[3], const float no[3]),
286
302
                                        void *userData);
287
303
 
288
 
        /* Iterate over all vertex points, calling DO_MINMAX with given args.
 
304
        /** Iterate over all vertex points, calling DO_MINMAX with given args.
289
305
         *
290
306
         * Also called in Editmode
291
307
         */
292
308
        void (*getMinMax)(DerivedMesh *dm, float min_r[3], float max_r[3]);
293
309
 
294
 
        /* Direct Access Operations */
295
 
        /*  o Can be undefined */
296
 
        /*  o Must be defined for modifiers that only deform however */
 
310
        /** Direct Access Operations
 
311
         * - Can be undefined
 
312
         * - Must be defined for modifiers that only deform however */
297
313
 
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]);
300
316
 
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]);
303
319
 
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]);
306
322
 
307
 
        /* Get a map of vertices to faces
 
323
        /** Get a map of vertices to faces
308
324
         */
309
325
        const struct MeshElemMap *(*getPolyMap)(struct Object *ob, DerivedMesh *dm);
310
326
 
311
 
        /* Get the BVH used for paint modes
 
327
        /** Get the BVH used for paint modes
312
328
         */
313
329
        struct PBVH *(*getPBVH)(struct Object *ob, DerivedMesh *dm);
314
330
 
315
331
        /* Drawing Operations */
316
332
 
317
 
        /* Draw all vertices as bgl points (no options) */
 
333
        /** Draw all vertices as bgl points (no options) */
318
334
        void (*drawVerts)(DerivedMesh *dm);
319
335
 
320
 
        /* Draw edges in the UV mesh (if exists) */
 
336
        /** Draw edges in the UV mesh (if exists) */
321
337
        void (*drawUVEdges)(DerivedMesh *dm);
322
338
 
323
 
        /* Draw all edges as lines (no options) 
 
339
        /** Draw all edges as lines (no options)
324
340
         *
325
341
         * Also called for *final* editmode DerivedMeshes
326
342
         */
327
343
        void (*drawEdges)(DerivedMesh *dm, int drawLooseEdges, int drawAllEdges);
328
344
        
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);
331
347
 
332
 
        /* Draw all faces
 
348
        /** Draw all faces
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
338
354
         */
339
355
        void (*drawFacesSolid)(DerivedMesh *dm, float (*partial_redraw_planes)[4],
340
 
                                                   int fast, DMSetMaterial setMaterial);
 
356
                               int fast, DMSetMaterial setMaterial);
341
357
 
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.
344
360
         */
345
361
        void (*drawFacesTex)(DerivedMesh *dm,
346
362
                             DMSetDrawOptionsTex setDrawOptions,
347
 
                                                 DMCompareDrawOptions compareDrawOptions,
348
 
                                                 void *userData);
 
363
                             DMCompareDrawOptions compareDrawOptions,
 
364
                             void *userData);
349
365
 
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
353
369
         */
354
370
        void (*drawFacesGLSL)(DerivedMesh *dm, DMSetMaterial setMaterial);
355
371
 
356
 
        /* Draw mapped faces (no color, or texture)
357
 
         *  o Only if !setDrawOptions or
358
 
         *    setDrawOptions(userData, mapped-face-index, drawSmooth_r)
359
 
         *    returns true
 
372
        /** Draw mapped faces (no color, or texture)
 
373
         * - Only if !setDrawOptions or
 
374
         *   setDrawOptions(userData, mapped-face-index, drawSmooth_r)
 
375
         *   returns true
360
376
         *
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
367
383
         * smooth shaded.
368
384
         */
369
385
        void (*drawMappedFaces)(DerivedMesh *dm,
370
 
                                                        DMSetDrawOptions setDrawOptions,
371
 
                                                        DMSetMaterial setMaterial,
372
 
                                                        DMCompareDrawOptions compareDrawOptions,
373
 
                                                        void *userData,
374
 
                                                        DMDrawFlag flag);
 
386
                                DMSetDrawOptions setDrawOptions,
 
387
                                DMSetMaterial setMaterial,
 
388
                                DMCompareDrawOptions compareDrawOptions,
 
389
                                void *userData,
 
390
                                DMDrawFlag flag);
375
391
 
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.
378
394
         */
379
395
        void (*drawMappedFacesTex)(DerivedMesh *dm,
380
 
                                                           DMSetDrawOptions setDrawOptions,
381
 
                                                           DMCompareDrawOptions compareDrawOptions,
382
 
                                                           void *userData);
 
396
                                   DMSetDrawOptions setDrawOptions,
 
397
                                   DMCompareDrawOptions compareDrawOptions,
 
398
                                   void *userData);
383
399
 
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
388
404
         */
389
405
        void (*drawMappedFacesGLSL)(DerivedMesh *dm,
390
 
                DMSetMaterial setMaterial,
391
 
                DMSetDrawOptions setDrawOptions,
392
 
                void *userData);
 
406
                                    DMSetMaterial setMaterial,
 
407
                                    DMSetDrawOptions setDrawOptions,
 
408
                                    void *userData);
393
409
 
394
 
        /* Draw mapped edges as lines
395
 
         *  o Only if !setDrawOptions or setDrawOptions(userData, mapped-edge)
396
 
         *    returns true
 
410
        /** Draw mapped edges as lines
 
411
         * - Only if !setDrawOptions or setDrawOptions(userData, mapped-edge)
 
412
         *   returns true
397
413
         */
398
414
        void (*drawMappedEdges)(DerivedMesh *dm,
399
 
                                                        DMSetDrawOptions setDrawOptions,
400
 
                                                        void *userData);
 
415
                                DMSetDrawOptions setDrawOptions,
 
416
                                void *userData);
401
417
 
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)
405
 
         *    returns true
 
418
        /** Draw mapped edges as lines with interpolation values
 
419
         * - Only if !setDrawOptions or
 
420
         *   setDrawOptions(userData, mapped-edge, mapped-v0, mapped-v1, t)
 
421
         *   returns true
406
422
         *
407
423
         * NOTE: This routine is optional!
408
424
         */
409
425
        void (*drawMappedEdgesInterp)(DerivedMesh *dm, 
410
 
                                                                  DMSetDrawOptions setDrawOptions,
411
 
                                                                  DMSetDrawInterpOptions setDrawInterpOptions,
412
 
                                                                  void *userData);
 
426
                                      DMSetDrawOptions setDrawOptions,
 
427
                                      DMSetDrawInterpOptions setDrawInterpOptions,
 
428
                                      void *userData);
413
429
 
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
417
433
         */
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);
421
437
 
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);
425
441
};
426
442
 
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)
429
445
 */
430
446
void DM_init_funcs(DerivedMesh *dm);
431
447
 
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)
435
451
 */
436
452
void DM_init(DerivedMesh *dm, DerivedMeshType type, int numVerts, int numEdges, 
437
453
             int numFaces, int numLoops, int numPolys);
438
454
 
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
441
457
 */
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);
446
462
 
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
449
465
 */
450
466
int DM_release(DerivedMesh *dm);
451
467
 
452
 
/* utility function to convert a DerivedMesh to a Mesh
 
468
/** utility function to convert a DerivedMesh to a Mesh
453
469
 */
454
470
void DM_to_mesh(DerivedMesh *dm, struct Mesh *me, struct Object *ob);
455
471
 
461
477
struct BMesh *DM_to_bmesh(struct DerivedMesh *dm);
462
478
 
463
479
 
464
 
/* utility function to convert a DerivedMesh to a shape key block 
465
 
 */
 
480
/** Utility function to convert a DerivedMesh to a shape key block */
466
481
void DM_to_meshkey(DerivedMesh *dm, struct Mesh *me, struct KeyBlock *kb);
467
482
 
468
 
/* set the CD_FLAG_NOCOPY flag in custom data layers where the mask is
 
483
/** set the CD_FLAG_NOCOPY flag in custom data layers where the mask is
469
484
 * zero for the layer type, so only layer types specified by the mask
470
485
 * will be copied
471
486
 */
495
510
void *DM_get_vert_data(struct DerivedMesh *dm, int index, int type);
496
511
void *DM_get_edge_data(struct DerivedMesh *dm, int index, int type);
497
512
void *DM_get_tessface_data(struct DerivedMesh *dm, int index, int type);
 
513
void *DM_get_poly_data(struct DerivedMesh *dm, int index, int type);
498
514
 
499
515
/* custom data layer access functions
500
516
 * return pointer to first data layer which matches type (a flat array)
520
536
 * these copy all layers for which the CD_FLAG_NOCOPY flag is not set
521
537
 */
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);
532
548
 
533
549
/* custom data free functions
534
550
 * free count elements, starting at index
547
563
 
548
564
void DM_update_tessface_data(DerivedMesh *dm);
549
565
 
550
 
/* interpolates vertex data from the vertices indexed by src_indices in the
 
566
/** interpolates vertex data from the vertices indexed by src_indices in the
551
567
 * source mesh using the given weights and stores the result in the vertex
552
568
 * indexed by dest_index in the dest mesh
553
569
 */
554
570
void DM_interp_vert_data(struct DerivedMesh *source, struct DerivedMesh *dest,
555
 
                                                 int *src_indices, float *weights,
556
 
                                                 int count, int dest_index);
 
571
                         int *src_indices, float *weights,
 
572
                         int count, int dest_index);
557
573
 
558
 
/* interpolates edge data from the edges indexed by src_indices in the
 
574
/** interpolates edge data from the edges indexed by src_indices in the
559
575
 * source mesh using the given weights and stores the result in the edge indexed
560
576
 * by dest_index in the dest mesh.
561
577
 * if weights is NULL, all weights default to 1.
564
580
 */
565
581
typedef float EdgeVertWeight[SUB_ELEMS_EDGE][SUB_ELEMS_EDGE];
566
582
void DM_interp_edge_data(struct DerivedMesh *source, struct DerivedMesh *dest,
567
 
                                                 int *src_indices,
568
 
                                                 float *weights, EdgeVertWeight *vert_weights,
569
 
                                                 int count, int dest_index);
 
583
                         int *src_indices,
 
584
                         float *weights, EdgeVertWeight *vert_weights,
 
585
                         int count, int dest_index);
570
586
 
571
 
/* interpolates face data from the faces indexed by src_indices in the
 
587
/** interpolates face data from the faces indexed by src_indices in the
572
588
 * source mesh using the given weights and stores the result in the face indexed
573
589
 * by dest_index in the dest mesh.
574
590
 * if weights is NULL, all weights default to 1.
577
593
 */
578
594
typedef float FaceVertWeight[SUB_ELEMS_FACE][SUB_ELEMS_FACE];
579
595
void DM_interp_tessface_data(struct DerivedMesh *source, struct DerivedMesh *dest,
580
 
                                                 int *src_indices,
581
 
                                                 float *weights, FaceVertWeight *vert_weights,
582
 
                                                 int count, int dest_index);
 
596
                             int *src_indices,
 
597
                             float *weights, FaceVertWeight *vert_weights,
 
598
                             int count, int dest_index);
583
599
 
584
600
void DM_swap_tessface_data(struct DerivedMesh *dm, int index, const int *corner_indices);
585
601
 
594
610
/* Temporary? A function to give a colorband to derivedmesh for vertexcolor ranges */
595
611
void vDM_ColorBand_store(struct ColorBand *coba);
596
612
 
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);
601
617
 
602
 
        /* */
 
618
/* */
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);
607
623
 
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);
610
626
 
611
627
DerivedMesh *mesh_create_derived_render(struct Scene *scene, struct Object *ob,
612
 
                                                                                CustomDataMask dataMask);
 
628
                                        CustomDataMask dataMask);
613
629
 
614
630
DerivedMesh *getEditDerivedBMesh(struct BMEditMesh *em, struct Object *ob,
615
 
                                           float (*vertexCos)[3]);
 
631
                                 float (*vertexCos)[3]);
616
632
 
617
633
DerivedMesh *mesh_create_derived_index_render(struct Scene *scene, struct Object *ob, CustomDataMask dataMask, int index);
618
634
 
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,
624
 
                                                                                   float (*vertCos)[3],
625
 
                                                                                   CustomDataMask dataMask);
 
640
                                           float (*vertCos)[3],
 
641
                                           CustomDataMask dataMask);
626
642
DerivedMesh *mesh_create_derived_no_deform_render(struct Scene *scene, struct Object *ob,
627
 
                                                                                                  float (*vertCos)[3],
628
 
                                                                                                  CustomDataMask dataMask);
 
643
                                                  float (*vertCos)[3],
 
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);
634
650
 
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);
645
661
 
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]);
650
666
 
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);
661
677
 
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 {
665
681
        struct {
666
682
                struct MTFace *array;
667
 
                int emOffset, glIndex, glTexco;
 
683
                int em_offset, gl_index, gl_texco;
668
684
        } tface[MAX_MTFACE];
669
685
 
670
686
        struct {
671
687
                struct MCol *array;
672
 
                int emOffset, glIndex;
 
688
                int em_offset, gl_index;
673
689
        } mcol[MAX_MCOL];
674
690
 
675
691
        struct {
676
692
                float (*array)[4];
677
 
                int emOffset, glIndex;
 
693
                int em_offset, gl_index;
678
694
        } tang;
679
695
 
680
696
        struct {
681
697
                float (*array)[3];
682
 
                int emOffset, glIndex, glTexco;
 
698
                int em_offset, gl_index, gl_texco;
683
699
        } orco;
684
700
 
685
701
        int tottface, totmcol, tottang, totorco;
686
702
} DMVertexAttribs;
687
703
 
688
704
void DM_vertex_attributes_from_gpu(DerivedMesh *dm,
689
 
        struct GPUVertexAttribs *gattribs, DMVertexAttribs *attribs);
 
705
                                   struct GPUVertexAttribs *gattribs, DMVertexAttribs *attribs);
690
706
 
691
707
void DM_add_tangent_layer(DerivedMesh *dm);
692
708
void DM_calc_auto_bump_scale(DerivedMesh *dm);
693
709
 
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);
696
712
 
697
713
void DM_init_origspace(DerivedMesh *dm);
700
716
#ifndef NDEBUG
701
717
char *DM_debug_info(DerivedMesh *dm);
702
718
void DM_debug_print(DerivedMesh *dm);
703
 
#endif
704
 
 
705
 
#endif
 
719
void DM_debug_print_cdlayers(CustomData *cdata);
 
720
#endif
 
721
 
 
722
#ifdef __GNUC__
 
723
BLI_INLINE int DM_origindex_mface_mpoly(const int *index_mf_to_mpoly, const int *index_mp_to_orig, const int i)
 
724
        __attribute__((nonnull(1)))
 
725
;
 
726
#endif
 
727
 
 
728
BLI_INLINE int DM_origindex_mface_mpoly(const int *index_mf_to_mpoly, const int *index_mp_to_orig, const int i)
 
729
{
 
730
        const int j = index_mf_to_mpoly[i];
 
731
        return (j != ORIGINDEX_NONE) ? (index_mp_to_orig ? index_mp_to_orig[j] : j) : ORIGINDEX_NONE;
 
732
}
 
733
 
 
734
#endif  /* __BKE_DERIVEDMESH_H__ */