~ubuntu-branches/ubuntu/saucy/blender/saucy-proposed

« back to all changes in this revision

Viewing changes to source/blender/modifiers/intern/MOD_explode.c

  • 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:
35
35
 
36
36
#include "DNA_meshdata_types.h"
37
37
#include "DNA_scene_types.h"
 
38
#include "DNA_object_types.h"
38
39
 
39
40
#include "BLI_kdtree.h"
40
41
#include "BLI_rand.h"
58
59
 
59
60
static void initData(ModifierData *md)
60
61
{
61
 
        ExplodeModifierData *emd= (ExplodeModifierData*) md;
 
62
        ExplodeModifierData *emd = (ExplodeModifierData *) md;
62
63
 
63
 
        emd->facepa= NULL;
64
 
        emd->flag |= eExplodeFlag_Unborn+eExplodeFlag_Alive+eExplodeFlag_Dead;
 
64
        emd->facepa = NULL;
 
65
        emd->flag |= eExplodeFlag_Unborn + eExplodeFlag_Alive + eExplodeFlag_Dead;
65
66
}
66
67
static void freeData(ModifierData *md)
67
68
{
68
 
        ExplodeModifierData *emd= (ExplodeModifierData*) md;
 
69
        ExplodeModifierData *emd = (ExplodeModifierData *) md;
69
70
        
70
71
        if (emd->facepa) MEM_freeN(emd->facepa);
71
72
}
72
73
static void copyData(ModifierData *md, ModifierData *target)
73
74
{
74
 
        ExplodeModifierData *emd= (ExplodeModifierData*) md;
75
 
        ExplodeModifierData *temd= (ExplodeModifierData*) target;
 
75
        ExplodeModifierData *emd = (ExplodeModifierData *) md;
 
76
        ExplodeModifierData *temd = (ExplodeModifierData *) target;
76
77
 
77
78
        temd->facepa = NULL;
78
79
        temd->flag = emd->flag;
85
86
}
86
87
static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
87
88
{
88
 
        ExplodeModifierData *emd= (ExplodeModifierData*) md;
 
89
        ExplodeModifierData *emd = (ExplodeModifierData *) md;
89
90
        CustomDataMask dataMask = 0;
90
91
 
91
92
        if (emd->vgroup)
95
96
}
96
97
 
97
98
static void createFacepa(ExplodeModifierData *emd,
98
 
                                                ParticleSystemModifierData *psmd,
99
 
                                                DerivedMesh *dm)
 
99
                         ParticleSystemModifierData *psmd,
 
100
                         DerivedMesh *dm)
100
101
{
101
 
        ParticleSystem *psys=psmd->psys;
102
 
        MFace *fa=NULL, *mface=NULL;
 
102
        ParticleSystem *psys = psmd->psys;
 
103
        MFace *fa = NULL, *mface = NULL;
103
104
        MVert *mvert = NULL;
104
105
        ParticleData *pa;
105
106
        KDTree *tree;
106
107
        float center[3], co[3];
107
 
        int *facepa=NULL,*vertpa=NULL,totvert=0,totface=0,totpart=0;
108
 
        int i,p,v1,v2,v3,v4=0;
 
108
        int *facepa = NULL, *vertpa = NULL, totvert = 0, totface = 0, totpart = 0;
 
109
        int i, p, v1, v2, v3, v4 = 0;
109
110
 
110
111
        mvert = dm->getVertArray(dm);
111
112
        mface = dm->getTessFaceArray(dm);
112
 
        totface= dm->getNumTessFaces(dm);
113
 
        totvert= dm->getNumVerts(dm);
114
 
        totpart= psmd->psys->totpart;
 
113
        totface = dm->getNumTessFaces(dm);
 
114
        totvert = dm->getNumVerts(dm);
 
115
        totpart = psmd->psys->totpart;
115
116
 
116
117
        BLI_srandom(psys->seed);
117
118
 
118
119
        if (emd->facepa)
119
120
                MEM_freeN(emd->facepa);
120
121
 
121
 
        facepa = emd->facepa = MEM_callocN(sizeof(int)*totface, "explode_facepa");
 
122
        facepa = emd->facepa = MEM_callocN(sizeof(int) * totface, "explode_facepa");
122
123
 
123
 
        vertpa = MEM_callocN(sizeof(int)*totvert, "explode_vertpa");
 
124
        vertpa = MEM_callocN(sizeof(int) * totvert, "explode_vertpa");
124
125
 
125
126
        /* initialize all faces & verts to no particle */
126
 
        for (i=0; i<totface; i++)
127
 
                facepa[i]=totpart;
 
127
        for (i = 0; i < totface; i++)
 
128
                facepa[i] = totpart;
128
129
 
129
 
        for (i=0; i<totvert; i++)
130
 
                vertpa[i]=totpart;
 
130
        for (i = 0; i < totvert; i++)
 
131
                vertpa[i] = totpart;
131
132
 
132
133
        /* set protected verts */
133
134
        if (emd->vgroup) {
134
135
                MDeformVert *dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
135
136
                if (dvert) {
136
 
                        const int defgrp_index= emd->vgroup-1;
137
 
                        for (i=0; i<totvert; i++, dvert++) {
 
137
                        const int defgrp_index = emd->vgroup - 1;
 
138
                        for (i = 0; i < totvert; i++, dvert++) {
138
139
                                float val = BLI_frand();
139
 
                                val = (1.0f-emd->protect)*val + emd->protect*0.5f;
 
140
                                val = (1.0f - emd->protect) * val + emd->protect * 0.5f;
140
141
                                if (val < defvert_find_weight(dvert, defgrp_index))
141
142
                                        vertpa[i] = -1;
142
143
                        }
144
145
        }
145
146
 
146
147
        /* make tree of emitter locations */
147
 
        tree=BLI_kdtree_new(totpart);
148
 
        for (p=0,pa=psys->particles; p<totpart; p++,pa++) {
149
 
                psys_particle_on_emitter(psmd,psys->part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co,NULL,NULL,NULL,NULL,NULL);
 
148
        tree = BLI_kdtree_new(totpart);
 
149
        for (p = 0, pa = psys->particles; p < totpart; p++, pa++) {
 
150
                psys_particle_on_emitter(psmd, psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co, NULL, NULL, NULL, NULL, NULL);
150
151
                BLI_kdtree_insert(tree, p, co, NULL);
151
152
        }
152
153
        BLI_kdtree_balance(tree);
153
154
 
154
155
        /* set face-particle-indexes to nearest particle to face center */
155
 
        for (i=0,fa=mface; i<totface; i++,fa++) {
156
 
                add_v3_v3v3(center,mvert[fa->v1].co,mvert[fa->v2].co);
 
156
        for (i = 0, fa = mface; i < totface; i++, fa++) {
 
157
                add_v3_v3v3(center, mvert[fa->v1].co, mvert[fa->v2].co);
157
158
                add_v3_v3(center, mvert[fa->v3].co);
158
159
                if (fa->v4) {
159
160
                        add_v3_v3(center, mvert[fa->v4].co);
160
 
                        mul_v3_fl(center,0.25);
 
161
                        mul_v3_fl(center, 0.25);
161
162
                }
162
163
                else
163
 
                        mul_v3_fl(center,0.3333f);
164
 
 
165
 
                p= BLI_kdtree_find_nearest(tree,center,NULL,NULL);
166
 
 
167
 
                v1=vertpa[fa->v1];
168
 
                v2=vertpa[fa->v2];
169
 
                v3=vertpa[fa->v3];
 
164
                        mul_v3_fl(center, 1.0f / 3.0f);
 
165
 
 
166
                p = BLI_kdtree_find_nearest(tree, center, NULL, NULL);
 
167
 
 
168
                v1 = vertpa[fa->v1];
 
169
                v2 = vertpa[fa->v2];
 
170
                v3 = vertpa[fa->v3];
170
171
                if (fa->v4)
171
 
                        v4=vertpa[fa->v4];
172
 
 
173
 
                if (v1>=0 && v2>=0 && v3>=0 && (fa->v4==0 || v4>=0))
174
 
                        facepa[i]=p;
175
 
 
176
 
                if (v1>=0) vertpa[fa->v1]=p;
177
 
                if (v2>=0) vertpa[fa->v2]=p;
178
 
                if (v3>=0) vertpa[fa->v3]=p;
179
 
                if (fa->v4 && v4>=0) vertpa[fa->v4]=p;
 
172
                        v4 = vertpa[fa->v4];
 
173
 
 
174
                if (v1 >= 0 && v2 >= 0 && v3 >= 0 && (fa->v4 == 0 || v4 >= 0))
 
175
                        facepa[i] = p;
 
176
 
 
177
                if (v1 >= 0) vertpa[fa->v1] = p;
 
178
                if (v2 >= 0) vertpa[fa->v2] = p;
 
179
                if (v3 >= 0) vertpa[fa->v3] = p;
 
180
                if (fa->v4 && v4 >= 0) vertpa[fa->v4] = p;
180
181
        }
181
182
 
182
183
        if (vertpa) MEM_freeN(vertpa);
194
195
        0, 0, 2, 0, 1, 2, 2, 0, 2, 1,
195
196
        2, 2, 2, 2, 3, 0, 0, 0, 1, 0,
196
197
        1, 1, 2
197
 
 };
 
198
};
198
199
 
199
200
static MFace *get_dface(DerivedMesh *dm, DerivedMesh *split, int cur, int i, MFace *mf)
200
201
{
204
205
        return df;
205
206
}
206
207
 
207
 
#define SET_VERTS(a, b, c, d) \
208
 
                v[0] = mf->v##a; uv[0]=a-1; \
209
 
                v[1] = mf->v##b; uv[1]=b-1; \
210
 
                v[2] = mf->v##c; uv[2]=c-1; \
211
 
                v[3] = mf->v##d; uv[3]=d-1; \
212
 
                (void)0
 
208
#define SET_VERTS(a, b, c, d)           \
 
209
        {                                   \
 
210
                v[0] = mf->v##a; uv[0] = a - 1; \
 
211
                v[1] = mf->v##b; uv[1] = b - 1; \
 
212
                v[2] = mf->v##c; uv[2] = c - 1; \
 
213
                v[3] = mf->v##d; uv[3] = d - 1; \
 
214
        } (void)0
213
215
 
214
216
#define GET_ES(v1, v2) edgecut_get(eh, v1, v2)
215
217
#define INT_UV(uvf, c0, c1) interp_v2_v2v2(uvf, mf->uv[c0], mf->uv[c1], 0.5f)
217
219
static void remap_faces_3_6_9_12(DerivedMesh *dm, DerivedMesh *split, MFace *mf, int *facepa, int *vertpa, int i, EdgeHash *eh, int cur, int v1, int v2, int v3, int v4)
218
220
{
219
221
        MFace *df1 = get_dface(dm, split, cur, i, mf);
220
 
        MFace *df2 = get_dface(dm, split, cur+1, i, mf);
221
 
        MFace *df3 = get_dface(dm, split, cur+2, i, mf);
 
222
        MFace *df2 = get_dface(dm, split, cur + 1, i, mf);
 
223
        MFace *df3 = get_dface(dm, split, cur + 2, i, mf);
222
224
 
223
225
        facepa[cur] = vertpa[v1];
224
226
        df1->v1 = v1;
227
229
        df1->v4 = v3;
228
230
        df1->flag |= ME_FACE_SEL;
229
231
 
230
 
        facepa[cur+1] = vertpa[v2];
 
232
        facepa[cur + 1] = vertpa[v2];
231
233
        df2->v1 = GET_ES(v1, v2);
232
234
        df2->v2 = v2;
233
235
        df2->v3 = GET_ES(v2, v3);
234
236
        df2->v4 = 0;
235
237
        df2->flag &= ~ME_FACE_SEL;
236
238
 
237
 
        facepa[cur+2] = vertpa[v1];
 
239
        facepa[cur + 2] = vertpa[v1];
238
240
        df3->v1 = v1;
239
241
        df3->v2 = v3;
240
242
        df3->v3 = v4;
247
249
        MTFace *mf, *df1, *df2, *df3;
248
250
        int l;
249
251
 
250
 
        for (l=0; l<numlayer; l++) {
 
252
        for (l = 0; l < numlayer; l++) {
251
253
                mf = CustomData_get_layer_n(&split->faceData, CD_MTFACE, l);
252
 
                df1 = mf+cur;
 
254
                df1 = mf + cur;
253
255
                df2 = df1 + 1;
254
256
                df3 = df1 + 2;
255
257
                mf = CustomData_get_layer_n(&dm->faceData, CD_MTFACE, l);
273
275
static void remap_faces_5_10(DerivedMesh *dm, DerivedMesh *split, MFace *mf, int *facepa, int *vertpa, int i, EdgeHash *eh, int cur, int v1, int v2, int v3, int v4)
274
276
{
275
277
        MFace *df1 = get_dface(dm, split, cur, i, mf);
276
 
        MFace *df2 = get_dface(dm, split, cur+1, i, mf);
 
278
        MFace *df2 = get_dface(dm, split, cur + 1, i, mf);
277
279
 
278
280
        facepa[cur] = vertpa[v1];
279
281
        df1->v1 = v1;
282
284
        df1->v4 = GET_ES(v1, v4);
283
285
        df1->flag |= ME_FACE_SEL;
284
286
 
285
 
        facepa[cur+1] = vertpa[v3];
 
287
        facepa[cur + 1] = vertpa[v3];
286
288
        df2->v1 = GET_ES(v1, v4);
287
289
        df2->v2 = GET_ES(v2, v3);
288
290
        df2->v3 = v3;
295
297
        MTFace *mf, *df1, *df2;
296
298
        int l;
297
299
 
298
 
        for (l=0; l<numlayer; l++) {
 
300
        for (l = 0; l < numlayer; l++) {
299
301
                mf = CustomData_get_layer_n(&split->faceData, CD_MTFACE, l);
300
 
                df1 = mf+cur;
 
302
                df1 = mf + cur;
301
303
                df2 = df1 + 1;
302
304
                mf = CustomData_get_layer_n(&dm->faceData, CD_MTFACE, l);
303
305
                mf += i;
318
320
static void remap_faces_15(DerivedMesh *dm, DerivedMesh *split, MFace *mf, int *facepa, int *vertpa, int i, EdgeHash *eh, int cur, int v1, int v2, int v3, int v4)
319
321
{
320
322
        MFace *df1 = get_dface(dm, split, cur, i, mf);
321
 
        MFace *df2 = get_dface(dm, split, cur+1, i, mf);
322
 
        MFace *df3 = get_dface(dm, split, cur+2, i, mf);
323
 
        MFace *df4 = get_dface(dm, split, cur+3, i, mf);
 
323
        MFace *df2 = get_dface(dm, split, cur + 1, i, mf);
 
324
        MFace *df3 = get_dface(dm, split, cur + 2, i, mf);
 
325
        MFace *df4 = get_dface(dm, split, cur + 3, i, mf);
324
326
 
325
327
        facepa[cur] = vertpa[v1];
326
328
        df1->v1 = v1;
329
331
        df1->v4 = GET_ES(v1, v4);
330
332
        df1->flag |= ME_FACE_SEL;
331
333
 
332
 
        facepa[cur+1] = vertpa[v2];
 
334
        facepa[cur + 1] = vertpa[v2];
333
335
        df2->v1 = GET_ES(v1, v2);
334
336
        df2->v2 = v2;
335
337
        df2->v3 = GET_ES(v2, v3);
336
338
        df2->v4 = GET_ES(v1, v3);
337
339
        df2->flag |= ME_FACE_SEL;
338
340
 
339
 
        facepa[cur+2] = vertpa[v3];
 
341
        facepa[cur + 2] = vertpa[v3];
340
342
        df3->v1 = GET_ES(v1, v3);
341
343
        df3->v2 = GET_ES(v2, v3);
342
344
        df3->v3 = v3;
343
345
        df3->v4 = GET_ES(v3, v4);
344
346
        df3->flag |= ME_FACE_SEL;
345
347
 
346
 
        facepa[cur+3] = vertpa[v4];
 
348
        facepa[cur + 3] = vertpa[v4];
347
349
        df4->v1 = GET_ES(v1, v4);
348
350
        df4->v2 = GET_ES(v1, v3);
349
351
        df4->v3 = GET_ES(v3, v4);
356
358
        MTFace *mf, *df1, *df2, *df3, *df4;
357
359
        int l;
358
360
 
359
 
        for (l=0; l<numlayer; l++) {
 
361
        for (l = 0; l < numlayer; l++) {
360
362
                mf = CustomData_get_layer_n(&split->faceData, CD_MTFACE, l);
361
 
                df1 = mf+cur;
 
363
                df1 = mf + cur;
362
364
                df2 = df1 + 1;
363
365
                df3 = df1 + 2;
364
366
                df4 = df1 + 3;
390
392
static void remap_faces_7_11_13_14(DerivedMesh *dm, DerivedMesh *split, MFace *mf, int *facepa, int *vertpa, int i, EdgeHash *eh, int cur, int v1, int v2, int v3, int v4)
391
393
{
392
394
        MFace *df1 = get_dface(dm, split, cur, i, mf);
393
 
        MFace *df2 = get_dface(dm, split, cur+1, i, mf);
394
 
        MFace *df3 = get_dface(dm, split, cur+2, i, mf);
 
395
        MFace *df2 = get_dface(dm, split, cur + 1, i, mf);
 
396
        MFace *df3 = get_dface(dm, split, cur + 2, i, mf);
395
397
 
396
398
        facepa[cur] = vertpa[v1];
397
399
        df1->v1 = v1;
400
402
        df1->v4 = GET_ES(v1, v4);
401
403
        df1->flag |= ME_FACE_SEL;
402
404
 
403
 
        facepa[cur+1] = vertpa[v2];
 
405
        facepa[cur + 1] = vertpa[v2];
404
406
        df2->v1 = GET_ES(v1, v2);
405
407
        df2->v2 = v2;
406
408
        df2->v3 = GET_ES(v2, v3);
407
409
        df2->v4 = 0;
408
410
        df2->flag &= ~ME_FACE_SEL;
409
411
 
410
 
        facepa[cur+2] = vertpa[v4];
 
412
        facepa[cur + 2] = vertpa[v4];
411
413
        df3->v1 = GET_ES(v1, v4);
412
414
        df3->v2 = GET_ES(v2, v3);
413
415
        df3->v3 = v3;
420
422
        MTFace *mf, *df1, *df2, *df3;
421
423
        int l;
422
424
 
423
 
        for (l=0; l<numlayer; l++) {
 
425
        for (l = 0; l < numlayer; l++) {
424
426
                mf = CustomData_get_layer_n(&split->faceData, CD_MTFACE, l);
425
 
                df1 = mf+cur;
 
427
                df1 = mf + cur;
426
428
                df2 = df1 + 1;
427
429
                df3 = df1 + 2;
428
430
                mf = CustomData_get_layer_n(&dm->faceData, CD_MTFACE, l);
447
449
static void remap_faces_19_21_22(DerivedMesh *dm, DerivedMesh *split, MFace *mf, int *facepa, int *vertpa, int i, EdgeHash *eh, int cur, int v1, int v2, int v3)
448
450
{
449
451
        MFace *df1 = get_dface(dm, split, cur, i, mf);
450
 
        MFace *df2 = get_dface(dm, split, cur+1, i, mf);
 
452
        MFace *df2 = get_dface(dm, split, cur + 1, i, mf);
451
453
 
452
454
        facepa[cur] = vertpa[v1];
453
455
        df1->v1 = v1;
456
458
        df1->v4 = 0;
457
459
        df1->flag &= ~ME_FACE_SEL;
458
460
 
459
 
        facepa[cur+1] = vertpa[v2];
 
461
        facepa[cur + 1] = vertpa[v2];
460
462
        df2->v1 = GET_ES(v1, v2);
461
463
        df2->v2 = v2;
462
464
        df2->v3 = v3;
469
471
        MTFace *mf, *df1, *df2;
470
472
        int l;
471
473
 
472
 
        for (l=0; l<numlayer; l++) {
 
474
        for (l = 0; l < numlayer; l++) {
473
475
                mf = CustomData_get_layer_n(&split->faceData, CD_MTFACE, l);
474
 
                df1 = mf+cur;
 
476
                df1 = mf + cur;
475
477
                df2 = df1 + 1;
476
478
                mf = CustomData_get_layer_n(&dm->faceData, CD_MTFACE, l);
477
479
                mf += i;
490
492
static void remap_faces_23(DerivedMesh *dm, DerivedMesh *split, MFace *mf, int *facepa, int *vertpa, int i, EdgeHash *eh, int cur, int v1, int v2, int v3)
491
493
{
492
494
        MFace *df1 = get_dface(dm, split, cur, i, mf);
493
 
        MFace *df2 = get_dface(dm, split, cur+1, i, mf);
494
 
        MFace *df3 = get_dface(dm, split, cur+2, i, mf);
 
495
        MFace *df2 = get_dface(dm, split, cur + 1, i, mf);
 
496
        MFace *df3 = get_dface(dm, split, cur + 2, i, mf);
495
497
 
496
498
        facepa[cur] = vertpa[v1];
497
499
        df1->v1 = v1;
500
502
        df1->v4 = GET_ES(v1, v3);
501
503
        df1->flag |= ME_FACE_SEL;
502
504
 
503
 
        facepa[cur+1] = vertpa[v2];
 
505
        facepa[cur + 1] = vertpa[v2];
504
506
        df2->v1 = GET_ES(v1, v2);
505
507
        df2->v2 = v2;
506
508
        df2->v3 = GET_ES(v2, v3);
507
509
        df2->v4 = 0;
508
510
        df2->flag &= ~ME_FACE_SEL;
509
511
 
510
 
        facepa[cur+2] = vertpa[v3];
 
512
        facepa[cur + 2] = vertpa[v3];
511
513
        df3->v1 = GET_ES(v1, v3);
512
514
        df3->v2 = GET_ES(v2, v3);
513
515
        df3->v3 = v3;
520
522
        MTFace *mf, *df1, *df2;
521
523
        int l;
522
524
 
523
 
        for (l=0; l<numlayer; l++) {
 
525
        for (l = 0; l < numlayer; l++) {
524
526
                mf = CustomData_get_layer_n(&split->faceData, CD_MTFACE, l);
525
 
                df1 = mf+cur;
 
527
                df1 = mf + cur;
526
528
                df2 = df1 + 1;
527
529
                mf = CustomData_get_layer_n(&dm->faceData, CD_MTFACE, l);
528
530
                mf += i;
542
544
        }
543
545
}
544
546
 
545
 
static DerivedMesh * cutEdges(ExplodeModifierData *emd, DerivedMesh *dm)
 
547
static DerivedMesh *cutEdges(ExplodeModifierData *emd, DerivedMesh *dm)
546
548
{
547
549
        DerivedMesh *splitdm;
548
 
        MFace *mf=NULL,*df1=NULL;
549
 
        MFace *mface=dm->getTessFaceArray(dm);
 
550
        MFace *mf = NULL, *df1 = NULL;
 
551
        MFace *mface = dm->getTessFaceArray(dm);
550
552
        MVert *dupve, *mv;
551
553
        EdgeHash *edgehash;
552
554
        EdgeHashIterator *ehi;
553
 
        int totvert=dm->getNumVerts(dm);
554
 
        int totface=dm->getNumTessFaces(dm);
 
555
        int totvert = dm->getNumVerts(dm);
 
556
        int totface = dm->getNumTessFaces(dm);
555
557
 
556
 
        int *facesplit = MEM_callocN(sizeof(int)*totface,"explode_facesplit");
557
 
        int *vertpa = MEM_callocN(sizeof(int)*totvert,"explode_vertpa2");
 
558
        int *facesplit = MEM_callocN(sizeof(int) * totface, "explode_facesplit");
 
559
        int *vertpa = MEM_callocN(sizeof(int) * totvert, "explode_vertpa2");
558
560
        int *facepa = emd->facepa;
559
 
        int *fs, totesplit=0,totfsplit=0,curdupface=0;
 
561
        int *fs, totesplit = 0, totfsplit = 0, curdupface = 0;
560
562
        int i, v1, v2, v3, v4, esplit,
561
563
            v[4]  = {0, 0, 0, 0}, /* To quite gcc barking... */
562
564
            uv[4] = {0, 0, 0, 0}; /* To quite gcc barking... */
563
565
        int numlayer;
564
566
        unsigned int ed_v1, ed_v2;
565
567
 
566
 
        edgehash= BLI_edgehash_new();
 
568
        edgehash = BLI_edgehash_new();
567
569
 
568
570
        /* recreate vertpa from facepa calculation */
569
 
        for (i=0,mf=mface; i<totface; i++,mf++) {
570
 
                vertpa[mf->v1]=facepa[i];
571
 
                vertpa[mf->v2]=facepa[i];
572
 
                vertpa[mf->v3]=facepa[i];
 
571
        for (i = 0, mf = mface; i < totface; i++, mf++) {
 
572
                vertpa[mf->v1] = facepa[i];
 
573
                vertpa[mf->v2] = facepa[i];
 
574
                vertpa[mf->v3] = facepa[i];
573
575
                if (mf->v4)
574
 
                        vertpa[mf->v4]=facepa[i];
 
576
                        vertpa[mf->v4] = facepa[i];
575
577
        }
576
578
 
577
579
        /* mark edges for splitting and how to split faces */
578
 
        for (i=0,mf=mface,fs=facesplit; i<totface; i++,mf++,fs++) {
579
 
                v1=vertpa[mf->v1];
580
 
                v2=vertpa[mf->v2];
581
 
                v3=vertpa[mf->v3];
 
580
        for (i = 0, mf = mface, fs = facesplit; i < totface; i++, mf++, fs++) {
 
581
                v1 = vertpa[mf->v1];
 
582
                v2 = vertpa[mf->v2];
 
583
                v3 = vertpa[mf->v3];
582
584
 
583
 
                if (v1!=v2) {
 
585
                if (v1 != v2) {
584
586
                        BLI_edgehash_insert(edgehash, mf->v1, mf->v2, NULL);
585
587
                        (*fs) |= 1;
586
588
                }
587
589
 
588
 
                if (v2!=v3) {
 
590
                if (v2 != v3) {
589
591
                        BLI_edgehash_insert(edgehash, mf->v2, mf->v3, NULL);
590
592
                        (*fs) |= 2;
591
593
                }
592
594
 
593
595
                if (mf->v4) {
594
 
                        v4=vertpa[mf->v4];
 
596
                        v4 = vertpa[mf->v4];
595
597
 
596
 
                        if (v3!=v4) {
 
598
                        if (v3 != v4) {
597
599
                                BLI_edgehash_insert(edgehash, mf->v3, mf->v4, NULL);
598
600
                                (*fs) |= 4;
599
601
                        }
600
602
 
601
 
                        if (v1!=v4) {
 
603
                        if (v1 != v4) {
602
604
                                BLI_edgehash_insert(edgehash, mf->v1, mf->v4, NULL);
603
605
                                (*fs) |= 8;
604
606
                        }
610
612
                else {
611
613
                        (*fs) |= 16; /* mark face as tri */
612
614
 
613
 
                        if (v1!=v3) {
 
615
                        if (v1 != v3) {
614
616
                                BLI_edgehash_insert(edgehash, mf->v1, mf->v3, NULL);
615
617
                                (*fs) |= 4;
616
618
                        }
618
620
        }
619
621
 
620
622
        /* count splits & create indexes for new verts */
621
 
        ehi= BLI_edgehashIterator_new(edgehash);
622
 
        totesplit=totvert;
 
623
        ehi = BLI_edgehashIterator_new(edgehash);
 
624
        totesplit = totvert;
623
625
        for (; !BLI_edgehashIterator_isDone(ehi); BLI_edgehashIterator_step(ehi)) {
624
626
                BLI_edgehashIterator_setValue(ehi, SET_INT_IN_POINTER(totesplit));
625
627
                totesplit++;
627
629
        BLI_edgehashIterator_free(ehi);
628
630
 
629
631
        /* count new faces due to splitting */
630
 
        for (i=0,fs=facesplit; i<totface; i++,fs++)
 
632
        for (i = 0, fs = facesplit; i < totface; i++, fs++)
631
633
                totfsplit += add_faces[*fs];
632
634
        
633
 
        splitdm= CDDM_from_template(dm, totesplit, 0, totface+totfsplit, 0, 0);
 
635
        splitdm = CDDM_from_template(dm, totesplit, 0, totface + totfsplit, 0, 0);
634
636
        numlayer = CustomData_number_of_layers(&splitdm->faceData, CD_MTFACE);
635
637
 
636
638
        /* copy new faces & verts (is it really this painful with custom data??) */
637
 
        for (i=0; i<totvert; i++) {
 
639
        for (i = 0; i < totvert; i++) {
638
640
                MVert source;
639
641
                MVert *dest;
640
642
                dm->getVert(dm, i, &source);
650
652
         * later interpreted as tri's, for this to work right I think we probably
651
653
         * have to stop using tessface - campbell */
652
654
 
653
 
        facepa= MEM_callocN(sizeof(int)*(totface+(totfsplit * 2)),"explode_facepa");
654
 
        //memcpy(facepa,emd->facepa,totface*sizeof(int));
655
 
        emd->facepa=facepa;
 
655
        facepa = MEM_callocN(sizeof(int) * (totface + (totfsplit * 2)), "explode_facepa");
 
656
        //memcpy(facepa, emd->facepa, totface*sizeof(int));
 
657
        emd->facepa = facepa;
656
658
 
657
659
        /* create new verts */
658
 
        ehi= BLI_edgehashIterator_new(edgehash);
 
660
        ehi = BLI_edgehashIterator_new(edgehash);
659
661
        for (; !BLI_edgehashIterator_isDone(ehi); BLI_edgehashIterator_step(ehi)) {
660
662
                BLI_edgehashIterator_getKey(ehi, &ed_v1, &ed_v2);
661
 
                esplit= GET_INT_FROM_POINTER(BLI_edgehashIterator_getValue(ehi));
662
 
                mv=CDDM_get_vert(splitdm, ed_v2);
663
 
                dupve=CDDM_get_vert(splitdm,esplit);
664
 
 
665
 
                DM_copy_vert_data(splitdm,splitdm, ed_v2, esplit,1);
666
 
 
667
 
                *dupve=*mv;
668
 
 
669
 
                mv=CDDM_get_vert(splitdm, ed_v1);
670
 
 
671
 
                add_v3_v3(dupve->co, mv->co);
672
 
                mul_v3_fl(dupve->co, 0.5f);
 
663
                esplit = GET_INT_FROM_POINTER(BLI_edgehashIterator_getValue(ehi));
 
664
                mv = CDDM_get_vert(splitdm, ed_v2);
 
665
                dupve = CDDM_get_vert(splitdm, esplit);
 
666
 
 
667
                DM_copy_vert_data(splitdm, splitdm, ed_v2, esplit, 1);
 
668
 
 
669
                *dupve = *mv;
 
670
 
 
671
                mv = CDDM_get_vert(splitdm, ed_v1);
 
672
 
 
673
                mid_v3_v3v3(dupve->co, dupve->co, mv->co);
673
674
        }
674
675
        BLI_edgehashIterator_free(ehi);
675
676
 
676
677
        /* create new faces */
677
 
        curdupface=0;//=totface;
 
678
        curdupface = 0; //=totface;
678
679
        //curdupin=totesplit;
679
 
        for (i=0,fs=facesplit; i<totface; i++,fs++) {
 
680
        for (i = 0, fs = facesplit; i < totface; i++, fs++) {
680
681
                mf = dm->getTessFaceData(dm, i, CD_MFACE);
681
682
 
682
 
                switch(*fs) {
683
 
                case 3:
684
 
                case 10:
685
 
                case 11:
686
 
                case 15:
687
 
                        SET_VERTS(1, 2, 3, 4);
688
 
                        break;
689
 
                case 5:
690
 
                case 6:
691
 
                case 7:
692
 
                        SET_VERTS(2, 3, 4, 1);
693
 
                        break;
694
 
                case 9:
695
 
                case 13:
696
 
                        SET_VERTS(4, 1, 2, 3);
697
 
                        break;
698
 
                case 12:
699
 
                case 14:
700
 
                        SET_VERTS(3, 4, 1, 2);
701
 
                        break;
702
 
                case 21:
703
 
                case 23:
704
 
                        SET_VERTS(1, 2, 3, 4);
705
 
                        break;
706
 
                case 19:
707
 
                        SET_VERTS(2, 3, 1, 4);
708
 
                        break;
709
 
                case 22:
710
 
                        SET_VERTS(3, 1, 2, 4);
711
 
                        break;
712
 
                }
713
 
 
714
 
                switch(*fs) {
715
 
                case 3:
716
 
                case 6:
717
 
                case 9:
718
 
                case 12:
719
 
                        remap_faces_3_6_9_12(dm, splitdm, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2], v[3]);
720
 
                        if (numlayer)
721
 
                                remap_uvs_3_6_9_12(dm, splitdm, numlayer, i, curdupface, uv[0], uv[1], uv[2], uv[3]);
722
 
                        break;
723
 
                case 5:
724
 
                case 10:
725
 
                        remap_faces_5_10(dm, splitdm, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2], v[3]);
726
 
                        if (numlayer)
727
 
                                remap_uvs_5_10(dm, splitdm, numlayer, i, curdupface, uv[0], uv[1], uv[2], uv[3]);
728
 
                        break;
729
 
                case 15:
730
 
                        remap_faces_15(dm, splitdm, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2], v[3]);
731
 
                        if (numlayer)
732
 
                                remap_uvs_15(dm, splitdm, numlayer, i, curdupface, uv[0], uv[1], uv[2], uv[3]);
733
 
                        break;
734
 
                case 7:
735
 
                case 11:
736
 
                case 13:
737
 
                case 14:
738
 
                        remap_faces_7_11_13_14(dm, splitdm, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2], v[3]);
739
 
                        if (numlayer)
740
 
                                remap_uvs_7_11_13_14(dm, splitdm, numlayer, i, curdupface, uv[0], uv[1], uv[2], uv[3]);
741
 
                        break;
742
 
                case 19:
743
 
                case 21:
744
 
                case 22:
745
 
                        remap_faces_19_21_22(dm, splitdm, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2]);
746
 
                        if (numlayer)
747
 
                                remap_uvs_19_21_22(dm, splitdm, numlayer, i, curdupface, uv[0], uv[1], uv[2]);
748
 
                        break;
749
 
                case 23:
750
 
                        remap_faces_23(dm, splitdm, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2]);
751
 
                        if (numlayer)
752
 
                                remap_uvs_23(dm, splitdm, numlayer, i, curdupface, uv[0], uv[1], uv[2]);
753
 
                        break;
754
 
                case 0:
755
 
                case 16:
756
 
                        df1 = get_dface(dm, splitdm, curdupface, i, mf);
757
 
                        facepa[curdupface] = vertpa[mf->v1];
758
 
 
759
 
                        if (df1->v4)
760
 
                                df1->flag |= ME_FACE_SEL;
761
 
                        else
762
 
                                df1->flag &= ~ME_FACE_SEL;
763
 
                        break;
764
 
                }
765
 
 
766
 
                curdupface += add_faces[*fs]+1;
 
683
                switch (*fs) {
 
684
                        case 3:
 
685
                        case 10:
 
686
                        case 11:
 
687
                        case 15:
 
688
                                SET_VERTS(1, 2, 3, 4);
 
689
                                break;
 
690
                        case 5:
 
691
                        case 6:
 
692
                        case 7:
 
693
                                SET_VERTS(2, 3, 4, 1);
 
694
                                break;
 
695
                        case 9:
 
696
                        case 13:
 
697
                                SET_VERTS(4, 1, 2, 3);
 
698
                                break;
 
699
                        case 12:
 
700
                        case 14:
 
701
                                SET_VERTS(3, 4, 1, 2);
 
702
                                break;
 
703
                        case 21:
 
704
                        case 23:
 
705
                                SET_VERTS(1, 2, 3, 4);
 
706
                                break;
 
707
                        case 19:
 
708
                                SET_VERTS(2, 3, 1, 4);
 
709
                                break;
 
710
                        case 22:
 
711
                                SET_VERTS(3, 1, 2, 4);
 
712
                                break;
 
713
                }
 
714
 
 
715
                switch (*fs) {
 
716
                        case 3:
 
717
                        case 6:
 
718
                        case 9:
 
719
                        case 12:
 
720
                                remap_faces_3_6_9_12(dm, splitdm, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2], v[3]);
 
721
                                if (numlayer)
 
722
                                        remap_uvs_3_6_9_12(dm, splitdm, numlayer, i, curdupface, uv[0], uv[1], uv[2], uv[3]);
 
723
                                break;
 
724
                        case 5:
 
725
                        case 10:
 
726
                                remap_faces_5_10(dm, splitdm, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2], v[3]);
 
727
                                if (numlayer)
 
728
                                        remap_uvs_5_10(dm, splitdm, numlayer, i, curdupface, uv[0], uv[1], uv[2], uv[3]);
 
729
                                break;
 
730
                        case 15:
 
731
                                remap_faces_15(dm, splitdm, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2], v[3]);
 
732
                                if (numlayer)
 
733
                                        remap_uvs_15(dm, splitdm, numlayer, i, curdupface, uv[0], uv[1], uv[2], uv[3]);
 
734
                                break;
 
735
                        case 7:
 
736
                        case 11:
 
737
                        case 13:
 
738
                        case 14:
 
739
                                remap_faces_7_11_13_14(dm, splitdm, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2], v[3]);
 
740
                                if (numlayer)
 
741
                                        remap_uvs_7_11_13_14(dm, splitdm, numlayer, i, curdupface, uv[0], uv[1], uv[2], uv[3]);
 
742
                                break;
 
743
                        case 19:
 
744
                        case 21:
 
745
                        case 22:
 
746
                                remap_faces_19_21_22(dm, splitdm, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2]);
 
747
                                if (numlayer)
 
748
                                        remap_uvs_19_21_22(dm, splitdm, numlayer, i, curdupface, uv[0], uv[1], uv[2]);
 
749
                                break;
 
750
                        case 23:
 
751
                                remap_faces_23(dm, splitdm, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2]);
 
752
                                if (numlayer)
 
753
                                        remap_uvs_23(dm, splitdm, numlayer, i, curdupface, uv[0], uv[1], uv[2]);
 
754
                                break;
 
755
                        case 0:
 
756
                        case 16:
 
757
                                df1 = get_dface(dm, splitdm, curdupface, i, mf);
 
758
                                facepa[curdupface] = vertpa[mf->v1];
 
759
 
 
760
                                if (df1->v4)
 
761
                                        df1->flag |= ME_FACE_SEL;
 
762
                                else
 
763
                                        df1->flag &= ~ME_FACE_SEL;
 
764
                                break;
 
765
                }
 
766
 
 
767
                curdupface += add_faces[*fs] + 1;
767
768
        }
768
769
 
769
 
        for (i=0; i<curdupface; i++) {
 
770
        for (i = 0; i < curdupface; i++) {
770
771
                mf = CDDM_get_tessface(splitdm, i);
771
772
                test_index_face(mf, &splitdm->faceData, i, (mf->flag & ME_FACE_SEL ? 4 : 3));
772
773
        }
780
781
 
781
782
        return splitdm;
782
783
}
783
 
static DerivedMesh * explodeMesh(ExplodeModifierData *emd, 
784
 
                ParticleSystemModifierData *psmd, Scene *scene, Object *ob, 
785
 
  DerivedMesh *to_explode)
 
784
static DerivedMesh *explodeMesh(ExplodeModifierData *emd,
 
785
                                ParticleSystemModifierData *psmd, Scene *scene, Object *ob,
 
786
                                DerivedMesh *to_explode)
786
787
{
787
 
        DerivedMesh *explode, *dm=to_explode;
788
 
        MFace *mf= NULL, *mface;
 
788
        DerivedMesh *explode, *dm = to_explode;
 
789
        MFace *mf = NULL, *mface;
789
790
        /* ParticleSettings *part=psmd->psys->part; */ /* UNUSED */
790
 
        ParticleSimulationData sim= {NULL};
791
 
        ParticleData *pa=NULL, *pars=psmd->psys->particles;
 
791
        ParticleSimulationData sim = {NULL};
 
792
        ParticleData *pa = NULL, *pars = psmd->psys->particles;
792
793
        ParticleKey state, birth;
793
794
        EdgeHash *vertpahash;
794
795
        EdgeHashIterator *ehi;
795
 
        float *vertco= NULL, imat[4][4];
 
796
        float *vertco = NULL, imat[4][4];
796
797
        float rot[4];
797
798
        float cfra;
798
799
        /* float timestep; */
799
 
        int *facepa=emd->facepa;
800
 
        int totdup=0,totvert=0,totface=0,totpart=0,delface=0;
 
800
        int *facepa = emd->facepa;
 
801
        int totdup = 0, totvert = 0, totface = 0, totpart = 0, delface = 0;
801
802
        int i, v, u;
802
 
        unsigned int ed_v1, ed_v2, mindex=0;
 
803
        unsigned int ed_v1, ed_v2, mindex = 0;
803
804
        MTFace *mtface = NULL, *mtf;
804
805
 
805
 
        totface= dm->getNumTessFaces(dm);
806
 
        totvert= dm->getNumVerts(dm);
807
 
        mface= dm->getTessFaceArray(dm);
808
 
        totpart= psmd->psys->totpart;
809
 
 
810
 
        sim.scene= scene;
811
 
        sim.ob= ob;
812
 
        sim.psys= psmd->psys;
813
 
        sim.psmd= psmd;
814
 
 
815
 
        /* timestep= psys_get_timestep(&sim); */
816
 
 
817
 
        cfra= BKE_curframe(scene);
 
806
        totface = dm->getNumTessFaces(dm);
 
807
        totvert = dm->getNumVerts(dm);
 
808
        mface = dm->getTessFaceArray(dm);
 
809
        totpart = psmd->psys->totpart;
 
810
 
 
811
        sim.scene = scene;
 
812
        sim.ob = ob;
 
813
        sim.psys = psmd->psys;
 
814
        sim.psmd = psmd;
 
815
 
 
816
        /* timestep = psys_get_timestep(&sim); */
 
817
 
 
818
        cfra = BKE_scene_frame_get(scene);
818
819
 
819
820
        /* hash table for vertice <-> particle relations */
820
 
        vertpahash= BLI_edgehash_new();
 
821
        vertpahash = BLI_edgehash_new();
821
822
 
822
 
        for (i=0; i<totface; i++) {
 
823
        for (i = 0; i < totface; i++) {
823
824
                if (facepa[i] != totpart) {
824
825
                        pa = pars + facepa[i];
825
826
 
834
835
 
835
836
                /* do mindex + totvert to ensure the vertex index to be the first
836
837
                 * with BLI_edgehashIterator_getKey */
837
 
                if (facepa[i]==totpart || cfra < (pars+facepa[i])->time)
838
 
                        mindex = totvert+totpart;
 
838
                if (facepa[i] == totpart || cfra < (pars + facepa[i])->time)
 
839
                        mindex = totvert + totpart;
839
840
                else 
840
 
                        mindex = totvert+facepa[i];
 
841
                        mindex = totvert + facepa[i];
841
842
 
842
 
                mf= &mface[i];
 
843
                mf = &mface[i];
843
844
 
844
845
                /* set face vertices to exist in particle group */
845
846
                BLI_edgehash_insert(vertpahash, mf->v1, mindex, NULL);
850
851
        }
851
852
 
852
853
        /* make new vertice indexes & count total vertices after duplication */
853
 
        ehi= BLI_edgehashIterator_new(vertpahash);
 
854
        ehi = BLI_edgehashIterator_new(vertpahash);
854
855
        for (; !BLI_edgehashIterator_isDone(ehi); BLI_edgehashIterator_step(ehi)) {
855
856
                BLI_edgehashIterator_setValue(ehi, SET_INT_IN_POINTER(totdup));
856
857
                totdup++;
858
859
        BLI_edgehashIterator_free(ehi);
859
860
 
860
861
        /* the final duplicated vertices */
861
 
        explode= CDDM_from_template(dm, totdup, 0,totface-delface, 0, 0);
 
862
        explode = CDDM_from_template(dm, totdup, 0, totface - delface, 0, 0);
862
863
        mtface = CustomData_get_layer_named(&explode->faceData, CD_MTFACE, emd->uvname);
863
 
        /*dupvert= CDDM_get_verts(explode);*/
 
864
        /*dupvert = CDDM_get_verts(explode);*/
864
865
 
865
866
        /* getting back to object space */
866
 
        invert_m4_m4(imat,ob->obmat);
 
867
        invert_m4_m4(imat, ob->obmat);
867
868
 
868
869
        psmd->psys->lattice = psys_get_lattice(&sim);
869
870
 
870
871
        /* duplicate & displace vertices */
871
 
        ehi= BLI_edgehashIterator_new(vertpahash);
 
872
        ehi = BLI_edgehashIterator_new(vertpahash);
872
873
        for (; !BLI_edgehashIterator_isDone(ehi); BLI_edgehashIterator_step(ehi)) {
873
874
                MVert source;
874
875
                MVert *dest;
876
877
                /* get particle + vertex from hash */
877
878
                BLI_edgehashIterator_getKey(ehi, &ed_v1, &ed_v2);
878
879
                ed_v2 -= totvert;
879
 
                v= GET_INT_FROM_POINTER(BLI_edgehashIterator_getValue(ehi));
 
880
                v = GET_INT_FROM_POINTER(BLI_edgehashIterator_getValue(ehi));
880
881
 
881
882
                dm->getVert(dm, ed_v1, &source);
882
 
                dest = CDDM_get_vert(explode,v);
 
883
                dest = CDDM_get_vert(explode, v);
883
884
 
884
885
                DM_copy_vert_data(dm, explode, ed_v1, v, 1);
885
886
                *dest = source;
886
887
 
887
888
                if (ed_v2 != totpart) {
888
889
                        /* get particle */
889
 
                        pa= pars + ed_v2;
 
890
                        pa = pars + ed_v2;
890
891
 
891
892
                        psys_get_birth_coordinates(&sim, pa, &birth, 0, 0);
892
893
 
893
 
                        state.time=cfra;
 
894
                        state.time = cfra;
894
895
                        psys_get_particle_state(&sim, ed_v2, &state, 1);
895
896
 
896
 
                        vertco=CDDM_get_vert(explode,v)->co;
897
 
                        mul_m4_v3(ob->obmat,vertco);
 
897
                        vertco = CDDM_get_vert(explode, v)->co;
 
898
                        mul_m4_v3(ob->obmat, vertco);
898
899
 
899
900
                        sub_v3_v3(vertco, birth.co);
900
901
 
903
904
                        mul_qt_v3(rot, vertco);
904
905
 
905
906
                        if (emd->flag & eExplodeFlag_PaSize)
906
 
                                mul_v3_fl(vertco,pa->size);
 
907
                                mul_v3_fl(vertco, pa->size);
907
908
 
908
909
                        add_v3_v3(vertco, state.co);
909
910
 
913
914
        BLI_edgehashIterator_free(ehi);
914
915
 
915
916
        /*map new vertices to faces*/
916
 
        for (i=0,u=0; i<totface; i++) {
 
917
        for (i = 0, u = 0; i < totface; i++) {
917
918
                MFace source;
918
919
                int orig_v4;
919
920
 
920
 
                if (facepa[i]!=totpart) {
921
 
                        pa=pars+facepa[i];
 
921
                if (facepa[i] != totpart) {
 
922
                        pa = pars + facepa[i];
922
923
 
923
 
                        if (pa->alive==PARS_UNBORN && (emd->flag&eExplodeFlag_Unborn)==0) continue;
924
 
                        if (pa->alive==PARS_ALIVE && (emd->flag&eExplodeFlag_Alive)==0) continue;
925
 
                        if (pa->alive==PARS_DEAD && (emd->flag&eExplodeFlag_Dead)==0) continue;
 
924
                        if (pa->alive == PARS_UNBORN && (emd->flag & eExplodeFlag_Unborn) == 0) continue;
 
925
                        if (pa->alive == PARS_ALIVE && (emd->flag & eExplodeFlag_Alive) == 0) continue;
 
926
                        if (pa->alive == PARS_DEAD && (emd->flag & eExplodeFlag_Dead) == 0) continue;
926
927
                }
927
928
 
928
 
                dm->getTessFace(dm,i,&source);
929
 
                mf=CDDM_get_tessface(explode,u);
 
929
                dm->getTessFace(dm, i, &source);
 
930
                mf = CDDM_get_tessface(explode, u);
930
931
                
931
932
                orig_v4 = source.v4;
932
933
 
933
 
                if (facepa[i]!=totpart && cfra < pa->time)
934
 
                        mindex = totvert+totpart;
 
934
                if (facepa[i] != totpart && cfra < pa->time)
 
935
                        mindex = totvert + totpart;
935
936
                else 
936
 
                        mindex = totvert+facepa[i];
 
937
                        mindex = totvert + facepa[i];
937
938
 
938
939
                source.v1 = edgecut_get(vertpahash, source.v1, mindex);
939
940
                source.v2 = edgecut_get(vertpahash, source.v2, mindex);
941
942
                if (source.v4)
942
943
                        source.v4 = edgecut_get(vertpahash, source.v4, mindex);
943
944
 
944
 
                DM_copy_tessface_data(dm,explode,i,u,1);
 
945
                DM_copy_tessface_data(dm, explode, i, u, 1);
945
946
 
946
947
                *mf = source;
947
948
 
948
949
                /* override uv channel for particle age */
949
950
                if (mtface) {
950
 
                        float age = (cfra - pa->time)/pa->lifetime;
 
951
                        float age = (cfra - pa->time) / pa->lifetime;
951
952
                        /* Clamp to this range to avoid flipping to the other side of the coordinates. */
952
953
                        CLAMP(age, 0.001f, 0.999f);
953
954
 
971
972
 
972
973
        if (psmd->psys->lattice) {
973
974
                end_latt_deform(psmd->psys->lattice);
974
 
                psmd->psys->lattice= NULL;
 
975
                psmd->psys->lattice = NULL;
975
976
        }
976
977
 
977
978
        return explode;
978
979
}
979
980
 
980
 
static ParticleSystemModifierData * findPrecedingParticlesystem(Object *ob, ModifierData *emd)
 
981
static ParticleSystemModifierData *findPrecedingParticlesystem(Object *ob, ModifierData *emd)
981
982
{
982
983
        ModifierData *md;
983
 
        ParticleSystemModifierData *psmd= NULL;
 
984
        ParticleSystemModifierData *psmd = NULL;
984
985
 
985
 
        for (md=ob->modifiers.first; emd!=md; md=md->next) {
986
 
                if (md->type==eModifierType_ParticleSystem)
987
 
                        psmd= (ParticleSystemModifierData*) md;
 
986
        for (md = ob->modifiers.first; emd != md; md = md->next) {
 
987
                if (md->type == eModifierType_ParticleSystem)
 
988
                        psmd = (ParticleSystemModifierData *) md;
988
989
        }
989
990
        return psmd;
990
991
}
991
 
static DerivedMesh * applyModifier(ModifierData *md, Object *ob,
992
 
                                                DerivedMesh *derivedData,
993
 
                                                int UNUSED(useRenderParams),
994
 
                                                int UNUSED(isFinalCalc))
 
992
static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
 
993
                                  DerivedMesh *derivedData,
 
994
                                  ModifierApplyFlag UNUSED(flag))
995
995
{
996
996
        DerivedMesh *dm = derivedData;
997
 
        ExplodeModifierData *emd= (ExplodeModifierData*) md;
998
 
        ParticleSystemModifierData *psmd=findPrecedingParticlesystem(ob,md);
 
997
        ExplodeModifierData *emd = (ExplodeModifierData *) md;
 
998
        ParticleSystemModifierData *psmd = findPrecedingParticlesystem(ob, md);
999
999
 
1000
1000
        DM_ensure_tessface(dm); /* BMESH - UNTIL MODIFIER IS UPDATED FOR MPoly */
1001
1001
 
1002
1002
        if (psmd) {
1003
 
                ParticleSystem * psys=psmd->psys;
 
1003
                ParticleSystem *psys = psmd->psys;
1004
1004
 
1005
 
                if (psys==NULL || psys->totpart==0) return derivedData;
1006
 
                if (psys->part==NULL || psys->particles==NULL) return derivedData;
1007
 
                if (psmd->dm==NULL) return derivedData;
 
1005
                if (psys == NULL || psys->totpart == 0) return derivedData;
 
1006
                if (psys->part == NULL || psys->particles == NULL) return derivedData;
 
1007
                if (psmd->dm == NULL) return derivedData;
1008
1008
 
1009
1009
                /* 1. find faces to be exploded if needed */
1010
1010
                if (emd->facepa == NULL ||
1011
 
                    psmd->flag&eParticleSystemFlag_Pars ||
1012
 
                    emd->flag&eExplodeFlag_CalcFaces ||
 
1011
                    psmd->flag & eParticleSystemFlag_Pars ||
 
1012
                    emd->flag & eExplodeFlag_CalcFaces ||
1013
1013
                    MEM_allocN_len(emd->facepa) / sizeof(int) != dm->getNumTessFaces(dm))
1014
1014
                {
1015
1015
                        if (psmd->flag & eParticleSystemFlag_Pars)
1018
1018
                        if (emd->flag & eExplodeFlag_CalcFaces)
1019
1019
                                emd->flag &= ~eExplodeFlag_CalcFaces;
1020
1020
 
1021
 
                        createFacepa(emd,psmd,derivedData);
 
1021
                        createFacepa(emd, psmd, derivedData);
1022
1022
                }
1023
1023
                /* 2. create new mesh */
1024
1024
                if (emd->flag & eExplodeFlag_EdgeCut) {
1025
1025
                        int *facepa = emd->facepa;
1026
 
                        DerivedMesh *splitdm=cutEdges(emd,dm);
1027
 
                        DerivedMesh *explode=explodeMesh(emd, psmd, md->scene, ob, splitdm);
 
1026
                        DerivedMesh *splitdm = cutEdges(emd, dm);
 
1027
                        DerivedMesh *explode = explodeMesh(emd, psmd, md->scene, ob, splitdm);
1028
1028
 
1029
1029
                        MEM_freeN(emd->facepa);
1030
 
                        emd->facepa=facepa;
 
1030
                        emd->facepa = facepa;
1031
1031
                        splitdm->release(splitdm);
1032
1032
                        return explode;
1033
1033
                }
1057
1057
        /* isDisabled */        NULL,
1058
1058
        /* updateDepgraph */    NULL,
1059
1059
        /* dependsOnTime */     dependsOnTime,
1060
 
        /* dependsOnNormals */  NULL,
 
1060
        /* dependsOnNormals */  NULL,
1061
1061
        /* foreachObjectLink */ NULL,
1062
1062
        /* foreachIDLink */     NULL,
1063
1063
        /* foreachTexLink */    NULL,