svn merge ^/trunk/blender -r40644:40720
[blender-staging.git] / source / blender / modifiers / intern / MOD_explode.c
index 0f3822f8cb6b020237503c7061b03d9488fd0761..59461d18f8f138b85244fcc86cd58dcda16ec655 100644 (file)
 #include "DNA_meshdata_types.h"
 #include "DNA_scene_types.h"
 
+#include "BLI_utildefines.h"
 #include "BLI_kdtree.h"
 #include "BLI_rand.h"
 #include "BLI_math.h"
 #include "BLI_edgehash.h"
-#include "BLI_utildefines.h"
 
 #include "BKE_cdderivedmesh.h"
 #include "BKE_deform.h"
@@ -110,8 +110,8 @@ static void createFacepa(ExplodeModifierData *emd,
        int i,p,v1,v2,v3,v4=0;
 
        mvert = dm->getVertArray(dm);
-       mface = dm->getFaceArray(dm);
-       totface= dm->getNumFaces(dm);
+       mface = dm->getTessFaceArray(dm);
+       totface= dm->getNumTessFaces(dm);
        totvert= dm->getNumVerts(dm);
        totpart= psmd->psys->totpart;
 
@@ -200,8 +200,8 @@ static const short add_faces[24] = {
 
 static MFace *get_dface(DerivedMesh *dm, DerivedMesh *split, int cur, int i, MFace *mf)
 {
-       MFace *df = CDDM_get_face(split, cur);
-       DM_copy_face_data(dm, split, i, cur, 1);
+       MFace *df = CDDM_get_tessface(split, cur);
+       DM_copy_tessface_data(dm, split, i, cur, 1);
        *df = *mf;
        return df;
 }
@@ -547,12 +547,12 @@ static DerivedMesh * cutEdges(ExplodeModifierData *emd, DerivedMesh *dm)
 {
        DerivedMesh *splitdm;
        MFace *mf=NULL,*df1=NULL;
-       MFace *mface=dm->getFaceArray(dm);
+       MFace *mface=dm->getTessFaceArray(dm);
        MVert *dupve, *mv;
        EdgeHash *edgehash;
        EdgeHashIterator *ehi;
        int totvert=dm->getNumVerts(dm);
-       int totface=dm->getNumFaces(dm);
+       int totface=dm->getNumTessFaces(dm);
 
        int *facesplit = MEM_callocN(sizeof(int)*totface,"explode_facesplit");
        int *vertpa = MEM_callocN(sizeof(int)*totvert,"explode_vertpa2");
@@ -630,7 +630,7 @@ static DerivedMesh * cutEdges(ExplodeModifierData *emd, DerivedMesh *dm)
        for(i=0,fs=facesplit; i<totface; i++,fs++)
                totfsplit += add_faces[*fs];
        
-       splitdm= CDDM_from_template(dm, totesplit, 0, totface+totfsplit);
+       splitdm= CDDM_from_template(dm, totesplit, 0, totface+totfsplit, 0, 0);
        numlayer = CustomData_number_of_layers(&splitdm->faceData, CD_MTFACE);
 
        /* copy new faces & verts (is it really this painful with custom data??) */
@@ -672,7 +672,7 @@ static DerivedMesh * cutEdges(ExplodeModifierData *emd, DerivedMesh *dm)
        curdupface=0;//=totface;
        //curdupin=totesplit;
        for(i=0,fs=facesplit; i<totface; i++,fs++){
-               mf = dm->getFaceData(dm, i, CD_MFACE);
+               mf = dm->getTessFaceData(dm, i, CD_MFACE);
 
                switch(*fs) {
                case 3:
@@ -762,7 +762,7 @@ static DerivedMesh * cutEdges(ExplodeModifierData *emd, DerivedMesh *dm)
        }
 
        for(i=0; i<curdupface; i++) {
-               mf = CDDM_get_face(splitdm, i);
+               mf = CDDM_get_tessface(splitdm, i);
                test_index_face(mf, &splitdm->faceData, i, (mf->flag & ME_FACE_SEL ? 4 : 3));
        }
 
@@ -770,8 +770,11 @@ static DerivedMesh * cutEdges(ExplodeModifierData *emd, DerivedMesh *dm)
        MEM_freeN(facesplit);
        MEM_freeN(vertpa);
 
-       return splitdm;
+       dm = CDDM_copy(splitdm, 1); /*builds ngon faces from tess (mface) faces*/
+       splitdm->needsFree = 1;
+       splitdm->release(splitdm);
 
+       return dm;
 }
 static DerivedMesh * explodeMesh(ExplodeModifierData *emd, 
                ParticleSystemModifierData *psmd, Scene *scene, Object *ob, 
@@ -794,9 +797,9 @@ static DerivedMesh * explodeMesh(ExplodeModifierData *emd,
        int i, j, v, mindex=0;
        MTFace *mtface = NULL, *mtf;
 
-       totface= dm->getNumFaces(dm);
+       totface= dm->getNumTessFaces(dm);
        totvert= dm->getNumVerts(dm);
-       mface= dm->getFaceArray(dm);
+       mface= dm->getTessFaceArray(dm);
        totpart= psmd->psys->totpart;
 
        sim.scene= scene;
@@ -841,7 +844,7 @@ static DerivedMesh * explodeMesh(ExplodeModifierData *emd,
        BLI_edgehashIterator_free(ehi);
 
        /* the final duplicated vertices */
-       explode= CDDM_from_template(dm, totdup, 0,totface);
+       explode= CDDM_from_template(dm, totdup, 0,totface, 0, 0);
        mtface = CustomData_get_layer_named(&explode->faceData, CD_MTFACE, emd->uvname);
        /*dupvert= CDDM_get_verts(explode);*/
 
@@ -909,8 +912,8 @@ static DerivedMesh * explodeMesh(ExplodeModifierData *emd,
                        if(pa->alive==PARS_DEAD && (emd->flag&eExplodeFlag_Dead)==0) continue;
                }
 
-               dm->getFace(dm,i,&source);
-               mf=CDDM_get_face(explode,i);
+               dm->getTessFace(dm,i,&source);
+               mf=CDDM_get_tessface(explode,i);
                
                orig_v4 = source.v4;
 
@@ -925,7 +928,7 @@ static DerivedMesh * explodeMesh(ExplodeModifierData *emd,
                if(source.v4)
                        source.v4 = edgecut_get(vertpahash, source.v4, mindex);
 
-               DM_copy_face_data(dm,explode,i,i,1);
+               DM_copy_tessface_data(dm,explode,i,i,1);
 
                *mf = source;
 
@@ -949,6 +952,7 @@ static DerivedMesh * explodeMesh(ExplodeModifierData *emd,
 
        /* finalization */
        CDDM_calc_edges(explode);
+       CDDM_tessfaces_to_faces(explode);
        CDDM_calc_normals(explode);
 
        if(psmd->psys->lattice){
@@ -990,7 +994,7 @@ static DerivedMesh * applyModifier(ModifierData *md, Object *ob,
                if(emd->facepa == NULL
                                 || psmd->flag&eParticleSystemFlag_Pars
                                 || emd->flag&eExplodeFlag_CalcFaces
-                                || MEM_allocN_len(emd->facepa)/sizeof(int) != dm->getNumFaces(dm))
+                                || MEM_allocN_len(emd->facepa)/sizeof(int) != dm->getNumTessFaces(dm))
                {
                        if(psmd->flag & eParticleSystemFlag_Pars)
                                psmd->flag &= ~eParticleSystemFlag_Pars;