merge with 2.5 (not trunk, last merge message said that on accident) at r22252
[blender.git] / source / blender / blenkernel / intern / modifier.c
index f8795edc87828b7c1c5407bf2a79de4e6f0c6be9..2149632d189c90165cb71cdf4d9884003f7e7d32 100644 (file)
@@ -24,7 +24,8 @@
 *                 Ton Roosendaal,
 *                 Ben Batt,
 *                 Brecht Van Lommel,
-*                 Campbell Barton
+*                 Campbell Barton,
+*                 Joseph Eagar
 *
 * ***** END GPL LICENSE BLOCK *****
 *
 #include "BKE_subsurf.h"
 #include "BKE_texture.h"
 #include "BKE_utildefines.h"
+#include "BKE_tessmesh.h"
 
 #include "depsgraph_private.h"
 #include "BKE_deform.h"
@@ -266,12 +268,12 @@ static void curveModifier_deformVerts(
 }
 
 static void curveModifier_deformVertsEM(
-                                       ModifierData *md, Object *ob, EditMesh *editData,
+                                       ModifierData *md, Object *ob, BMEditMesh *editData,
      DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
 {
        DerivedMesh *dm = derivedData;
 
-       if(!derivedData) dm = CDDM_from_editmesh(editData, ob->data);
+       if(!derivedData) dm = CDDM_from_BMEditMesh(editData, ob->data);
 
        curveModifier_deformVerts(md, ob, dm, vertexCos, numVerts, 0, 0);
 
@@ -358,12 +360,12 @@ static void latticeModifier_deformVerts(
 }
 
 static void latticeModifier_deformVertsEM(
-                                         ModifierData *md, Object *ob, EditMesh *editData,
+                                         ModifierData *md, Object *ob, BMEditMesh *editData,
        DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
 {
        DerivedMesh *dm = derivedData;
 
-       if(!derivedData) dm = CDDM_from_editmesh(editData, ob->data);
+       if(!derivedData) dm = CDDM_from_BMEditMesh(editData, ob->data);
 
        latticeModifier_deformVerts(md, ob, dm, vertexCos, numVerts, 0, 0);
 
@@ -419,7 +421,7 @@ static DerivedMesh *subsurfModifier_applyModifier(
 }
 
 static DerivedMesh *subsurfModifier_applyModifierEM(
-               ModifierData *md, Object *ob, EditMesh *editData,
+               ModifierData *md, Object *ob, BMEditMesh *editData,
   DerivedMesh *derivedData)
 {
        SubsurfModifierData *smd = (SubsurfModifierData*) md;
@@ -487,7 +489,7 @@ static DerivedMesh *buildModifier_applyModifier(ModifierData *md, Object *ob,
                              "build modifier edgeMap");
        for(i = 0; i < maxEdges; ++i) edgeMap[i] = i;
 
-       maxFaces = dm->getNumFaces(dm);
+       maxFaces = dm->getNumTessFaces(dm);
        faceMap = MEM_callocN(sizeof(*faceMap) * maxFaces,
                              "build modifier faceMap");
        for(i = 0; i < maxFaces; ++i) faceMap[i] = i;
@@ -500,7 +502,7 @@ static DerivedMesh *buildModifier_applyModifier(ModifierData *md, Object *ob,
        }
        CLAMP(frac, 0.0, 1.0);
 
-       numFaces = dm->getNumFaces(dm) * frac;
+       numFaces = dm->getNumTessFaces(dm) * frac;
        numEdges = dm->getNumEdges(dm) * frac;
 
        /* if there's at least one face, build based on faces */
@@ -516,7 +518,7 @@ static DerivedMesh *buildModifier_applyModifier(ModifierData *md, Object *ob,
                */
                for(i = 0; i < numFaces; ++i) {
                        MFace mf;
-                       dm->getFace(dm, faceMap[i], &mf);
+                       dm->getTessFace(dm, faceMap[i], &mf);
 
                        if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v1)))
                                BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(mf.v1),
@@ -592,7 +594,7 @@ static DerivedMesh *buildModifier_applyModifier(ModifierData *md, Object *ob,
        * the mesh
        */
        result = CDDM_from_template(dm, BLI_ghash_size(vertHash),
-                                   BLI_ghash_size(edgeHash), numFaces);
+                                   BLI_ghash_size(edgeHash), numFaces, 0, 0);
 
        /* copy the vertices across */
        for(hashIter = BLI_ghashIterator_new(vertHash);
@@ -633,8 +635,8 @@ static DerivedMesh *buildModifier_applyModifier(ModifierData *md, Object *ob,
                           MFace *dest;
                           int orig_v4;
 
-                          dm->getFace(dm, faceMap[i], &source);
-                          dest = CDDM_get_face(result, i);
+                          dm->getTessFace(dm, faceMap[i], &source);
+                          dest = CDDM_get_tessface(result, i);
 
                           orig_v4 = source.v4;
 
@@ -644,13 +646,14 @@ static DerivedMesh *buildModifier_applyModifier(ModifierData *md, Object *ob,
                           if(source.v4)
                                   source.v4 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v4)));
 
-                          DM_copy_face_data(dm, result, faceMap[i], i, 1);
+                          DM_copy_tessface_data(dm, result, faceMap[i], i, 1);
                           *dest = source;
 
                           test_index_face(dest, &result->faceData, i, (orig_v4 ? 4 : 3));
                   }
 
                   CDDM_calc_normals(result);
+                  CDDM_tessfaces_to_faces(result);
 
                   BLI_ghash_free(vertHash, NULL, NULL);
                   BLI_ghash_free(edgeHash, NULL, NULL);
@@ -658,7 +661,7 @@ static DerivedMesh *buildModifier_applyModifier(ModifierData *md, Object *ob,
                   MEM_freeN(vertMap);
                   MEM_freeN(edgeMap);
                   MEM_freeN(faceMap);
-
+                       
                   return result;
 }
 
@@ -722,7 +725,7 @@ static DerivedMesh *maskModifier_applyModifier(ModifierData *md, Object *ob,
        /* get original number of verts, edges, and faces */
        maxVerts= dm->getNumVerts(dm);
        maxEdges= dm->getNumEdges(dm);
-       maxFaces= dm->getNumFaces(dm);
+       maxFaces= dm->getNumTessFaces(dm);
        
        /* check if we can just return the original mesh 
         *      - must have verts and therefore verts assigned to vgroups to do anything useful
@@ -916,7 +919,7 @@ static DerivedMesh *maskModifier_applyModifier(ModifierData *md, Object *ob,
        for (i = 0; i < maxFaces; i++) 
        {
                MFace mf;
-               dm->getFace(dm, i, &mf);
+               dm->getTessFace(dm, i, &mf);
                
                /* all verts must be available */
                if ( BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v1)) &&
@@ -933,7 +936,7 @@ static DerivedMesh *maskModifier_applyModifier(ModifierData *md, Object *ob,
        /* now we know the number of verts, edges and faces, 
         * we can create the new (reduced) mesh
         */
-       result = CDDM_from_template(dm, numVerts, numEdges, numFaces);
+       result = CDDM_from_template(dm, numVerts, numEdges, numFaces, 0, 0);
        
        
        /* using ghash-iterators, map data into new mesh */
@@ -987,8 +990,8 @@ static DerivedMesh *maskModifier_applyModifier(ModifierData *md, Object *ob,
                int newIndex = GET_INT_FROM_POINTER(BLI_ghashIterator_getValue(hashIter));
                int orig_v4;
                
-               dm->getFace(dm, oldIndex, &source);
-               dest = CDDM_get_face(result, newIndex);
+               dm->getTessFace(dm, oldIndex, &source);
+               dest = CDDM_get_tessface(result, newIndex);
                
                orig_v4 = source.v4;
                
@@ -998,7 +1001,7 @@ static DerivedMesh *maskModifier_applyModifier(ModifierData *md, Object *ob,
                if (source.v4)
                   source.v4 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v4)));
                
-               DM_copy_face_data(dm, result, oldIndex, newIndex, 1);
+               DM_copy_tessface_data(dm, result, oldIndex, newIndex, 1);
                *dest = source;
                
                test_index_face(dest, &result->faceData, newIndex, (orig_v4 ? 4 : 3));
@@ -1013,6 +1016,8 @@ static DerivedMesh *maskModifier_applyModifier(ModifierData *md, Object *ob,
        BLI_ghash_free(edgeHash, NULL, NULL);
        BLI_ghash_free(faceHash, NULL, NULL);
        
+       CDDM_tessfaces_to_faces(result);
+
        /* return the new mesh */
        return result;
 }
@@ -1160,6 +1165,7 @@ static int calc_mapping(IndexMapEntry *indexMap, int oldIndex, int copyNum)
        }
 }
 
+#if 0
 static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
                                          Scene *scene, Object *ob, DerivedMesh *dm,
        int initFlags)
@@ -1262,18 +1268,18 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
        */
                  finalVerts = dm->getNumVerts(dm) * count;
                  finalEdges = dm->getNumEdges(dm) * count;
-                 finalFaces = dm->getNumFaces(dm) * count;
+                 finalFaces = dm->getNumTessFaces(dm) * count;
                  if(start_cap) {
                          finalVerts += start_cap->getNumVerts(start_cap);
                          finalEdges += start_cap->getNumEdges(start_cap);
-                         finalFaces += start_cap->getNumFaces(start_cap);
+                         finalFaces += start_cap->getNumTessFaces(start_cap);
                  }
                  if(end_cap) {
                          finalVerts += end_cap->getNumVerts(end_cap);
                          finalEdges += end_cap->getNumEdges(end_cap);
-                         finalFaces += end_cap->getNumFaces(end_cap);
+                         finalFaces += end_cap->getNumTessFaces(end_cap);
                  }
-                 result = CDDM_from_template(dm, finalVerts, finalEdges, finalFaces);
+                 result = CDDM_from_template(dm, finalVerts, finalEdges, finalFaces, 0, 0);
 
                  /* calculate the offset matrix of the final copy (for merging) */ 
                  MTC_Mat4One(final_offset);
@@ -1424,15 +1430,15 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
                          }
                  }
 
-                 maxFaces = dm->getNumFaces(dm);
-                 mface = CDDM_get_faces(result);
+                 maxFaces = dm->getNumTessFaces(dm);
+                 mface = CDDM_get_tessfaces(result);
                  for (i=0; i < maxFaces; i++) {
                          MFace inMF;
                          MFace *mf = &mface[numFaces];
 
-                         dm->getFace(dm, i, &inMF);
+                         dm->getTessFace(dm, i, &inMF);
 
-                         DM_copy_face_data(dm, result, i, numFaces, 1);
+                         DM_copy_tessface_data(dm, result, i, numFaces, 1);
                          *mf = inMF;
 
                          mf->v1 = indexMap[inMF.v1].new;
@@ -1468,7 +1474,7 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
                          {
                                  MFace *mf2 = &mface[numFaces];
 
-                                 DM_copy_face_data(dm, result, i, numFaces, 1);
+                                 DM_copy_tessface_data(dm, result, i, numFaces, 1);
                                  *mf2 = *mf;
 
                                  mf2->v1 = calc_mapping(indexMap, inMF.v1, j);
@@ -1501,10 +1507,10 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
 
                          capVerts = start_cap->getNumVerts(start_cap);
                          capEdges = start_cap->getNumEdges(start_cap);
-                         capFaces = start_cap->getNumFaces(start_cap);
+                         capFaces = start_cap->getNumTessFaces(start_cap);
                          cap_mvert = start_cap->getVertArray(start_cap);
                          cap_medge = start_cap->getEdgeArray(start_cap);
-                         cap_mface = start_cap->getFaceArray(start_cap);
+                         cap_mface = start_cap->getTessFaceArray(start_cap);
 
                          Mat4Invert(startoffset, offset);
 
@@ -1563,9 +1569,9 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
                                          numEdges++;
                                  }
                          }
-                         origindex = result->getFaceDataArray(result, CD_ORIGINDEX);
+                         origindex = result->getTessFaceDataArray(result, CD_ORIGINDEX);
                          for(i = 0; i < capFaces; i++) {
-                                 DM_copy_face_data(start_cap, result, i, numFaces, 1);
+                                 DM_copy_tessface_data(start_cap, result, i, numFaces, 1);
                                  mface[numFaces] = cap_mface[i];
                                  mface[numFaces].v1 = vert_map[mface[numFaces].v1];
                                  mface[numFaces].v2 = vert_map[mface[numFaces].v2];
@@ -1602,10 +1608,10 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
 
                          capVerts = end_cap->getNumVerts(end_cap);
                          capEdges = end_cap->getNumEdges(end_cap);
-                         capFaces = end_cap->getNumFaces(end_cap);
+                         capFaces = end_cap->getNumTessFaces(end_cap);
                          cap_mvert = end_cap->getVertArray(end_cap);
                          cap_medge = end_cap->getEdgeArray(end_cap);
-                         cap_mface = end_cap->getFaceArray(end_cap);
+                         cap_mface = end_cap->getTessFaceArray(end_cap);
 
                          Mat4MulMat4(endoffset, final_offset, offset);
 
@@ -1664,9 +1670,9 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
                                          numEdges++;
                                  }
                          }
-                         origindex = result->getFaceDataArray(result, CD_ORIGINDEX);
+                         origindex = result->getTessFaceDataArray(result, CD_ORIGINDEX);
                          for(i = 0; i < capFaces; i++) {
-                                 DM_copy_face_data(end_cap, result, i, numFaces, 1);
+                                 DM_copy_tessface_data(end_cap, result, i, numFaces, 1);
                                  mface[numFaces] = cap_mface[i];
                                  mface[numFaces].v1 = vert_map[mface[numFaces].v1];
                                  mface[numFaces].v2 = vert_map[mface[numFaces].v2];
@@ -1697,6 +1703,8 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
                  CDDM_lower_num_verts(result, numVerts);
                  CDDM_lower_num_edges(result, numEdges);
                  CDDM_lower_num_faces(result, numFaces);
+               
+                 CDDM_tessfaces_to_faces(result);
 
                  return result;
 }
@@ -1717,11 +1725,19 @@ static DerivedMesh *arrayModifier_applyModifier(
 }
 
 static DerivedMesh *arrayModifier_applyModifierEM(
-               ModifierData *md, Object *ob, EditMesh *editData,
+               ModifierData *md, Object *ob, BMEditMesh *editData,
   DerivedMesh *derivedData)
 {
        return arrayModifier_applyModifier(md, ob, derivedData, 0, 1);
 }
+#endif
+
+DerivedMesh *arrayModifier_applyModifier(ModifierData *md, Object *ob, 
+                                        DerivedMesh *derivedData,
+                                         int useRenderParams, int isFinalCalc);
+DerivedMesh *arrayModifier_applyModifierEM(ModifierData *md, Object *ob,
+                                           BMEditMesh *editData, 
+                                           DerivedMesh *derivedData);
 
 /* Mirror */
 
@@ -1880,6 +1896,7 @@ void vertgroup_flip_name (char *name, int strip_number)
        sprintf (name, "%s%s%s%s", prefix, replace, suffix, number);
 }
 
+#if 0
 static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
                Object *ob,
                DerivedMesh *dm,
@@ -1892,7 +1909,7 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
        int numVerts, numEdges, numFaces;
        int maxVerts = dm->getNumVerts(dm);
        int maxEdges = dm->getNumEdges(dm);
-       int maxFaces = dm->getNumFaces(dm);
+       int maxFaces = dm->getNumTessFaces(dm);
        int vector_size=0, j, a, b;
        bDeformGroup *def, *defb;
        bDeformGroup **vector_def = NULL;
@@ -1903,7 +1920,7 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
 
        indexMap = MEM_mallocN(sizeof(*indexMap) * maxVerts, "indexmap");
 
-       result = CDDM_from_template(dm, maxVerts * 2, maxEdges * 2, maxFaces * 2);
+       result = CDDM_from_template(dm, maxVerts * 2, maxEdges * 2, maxFaces * 2, 0, 0);
 
 
        if (mmd->flag & MOD_MIR_VGROUP) {
@@ -2038,11 +2055,11 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
 
        for(i = 0; i < maxFaces; i++) {
                MFace inMF;
-               MFace *mf = CDDM_get_face(result, numFaces);
+               MFace *mf = CDDM_get_tessface(result, numFaces);
                
-               dm->getFace(dm, i, &inMF);
+               dm->getTessFace(dm, i, &inMF);
                
-               DM_copy_face_data(dm, result, i, numFaces, 1);
+               DM_copy_tessface_data(dm, result, i, numFaces, 1);
                *mf = inMF;
                numFaces++;
                
@@ -2055,10 +2072,10 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
                                 || indexMap[inMF.v2][1]
                                 || indexMap[inMF.v3][1]
                                 || (mf->v4 && indexMap[inMF.v4][1])) {
-                       MFace *mf2 = CDDM_get_face(result, numFaces);
+                       MFace *mf2 = CDDM_get_tessface(result, numFaces);
                        static int corner_indices[4] = {2, 1, 0, 3};
                        
-                       DM_copy_face_data(dm, result, i, numFaces, 1);
+                       DM_copy_tessface_data(dm, result, i, numFaces, 1);
                        *mf2 = *mf;
                        
                        mf2->v1 += indexMap[inMF.v1][1];
@@ -2068,7 +2085,7 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
                        
                        /* mirror UVs if enabled */
                        if(mmd->flag & (MOD_MIR_MIRROR_U | MOD_MIR_MIRROR_V)) {
-                               MTFace *tf = result->getFaceData(result, numFaces, CD_MTFACE);
+                               MTFace *tf = result->getTessFaceData(result, numFaces, CD_MTFACE);
                                if(tf) {
                                        int j;
                                        for(j = 0; j < 4; ++j) {
@@ -2082,7 +2099,7 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
                        
                        /* Flip face normal */
                        SWAP(int, mf2->v1, mf2->v3);
-                       DM_swap_face_data(result, numFaces, corner_indices);
+                       DM_swap_tessface_data(result, numFaces, corner_indices);
                        
                        test_index_face(mf2, &result->faceData, numFaces, inMF.v4?4:3);
                        numFaces++;
@@ -2097,8 +2114,11 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
        CDDM_lower_num_edges(result, numEdges);
        CDDM_lower_num_faces(result, numFaces);
 
+       CDDM_tessfaces_to_faces(result);
+
        return result;
 }
+#endif
 
 static DerivedMesh *mirrorModifier__doMirror(MirrorModifierData *mmd,
                                            Object *ob, DerivedMesh *dm,
@@ -2140,7 +2160,7 @@ static DerivedMesh *mirrorModifier_applyModifier(
 }
 
 static DerivedMesh *mirrorModifier_applyModifierEM(
-               ModifierData *md, Object *ob, EditMesh *editData,
+               ModifierData *md, Object *ob, BMEditMesh *editData,
   DerivedMesh *derivedData)
 {
        return mirrorModifier_applyModifier(md, ob, derivedData, 0, 1);
@@ -2431,7 +2451,7 @@ static SmoothMesh *smoothmesh_from_derivedmesh(DerivedMesh *dm)
 
        totvert = dm->getNumVerts(dm);
        totedge = dm->getNumEdges(dm);
-       totface = dm->getNumFaces(dm);
+       totface = dm->getNumTessFaces(dm);
 
        mesh = smoothmesh_new(totvert, totedge, totface,
                              totvert, totedge, totface);
@@ -2463,7 +2483,7 @@ static SmoothMesh *smoothmesh_from_derivedmesh(DerivedMesh *dm)
                MVert v1, v2, v3;
                int j;
 
-               dm->getFace(dm, i, &mf);
+               dm->getTessFace(dm, i, &mf);
 
                dm->getVert(dm, mf.v1, &v1);
                dm->getVert(dm, mf.v2, &v2);
@@ -2505,11 +2525,12 @@ static DerivedMesh *CDDM_from_smoothmesh(SmoothMesh *mesh)
 {
        DerivedMesh *result = CDDM_from_template(mesh->dm,
                        mesh->num_verts,
-   mesh->num_edges,
-   mesh->num_faces);
+                       mesh->num_edges,
+                       mesh->num_faces,
+                       0, 0);
        MVert *new_verts = CDDM_get_verts(result);
        MEdge *new_edges = CDDM_get_edges(result);
-       MFace *new_faces = CDDM_get_faces(result);
+       MFace *new_faces = CDDM_get_tessfaces(result);
        int i;
 
        for(i = 0; i < mesh->num_verts; ++i) {
@@ -2536,9 +2557,9 @@ static DerivedMesh *CDDM_from_smoothmesh(SmoothMesh *mesh)
                SmoothFace *face = &mesh->faces[i];
                MFace *newMF = &new_faces[face->newIndex];
 
-               DM_copy_face_data(mesh->dm, result,
+               DM_copy_tessface_data(mesh->dm, result,
                                  face->oldIndex, face->newIndex, 1);
-               mesh->dm->getFace(mesh->dm, face->oldIndex, newMF);
+               mesh->dm->getTessFace(mesh->dm, face->oldIndex, newMF);
 
                newMF->v1 = face->edges[0]->verts[face->flip[0]]->newIndex;
                newMF->v2 = face->edges[1]->verts[face->flip[1]]->newIndex;
@@ -2551,6 +2572,8 @@ static DerivedMesh *CDDM_from_smoothmesh(SmoothMesh *mesh)
                }
        }
 
+       CDDM_tessfaces_to_faces(result);
+
        return result;
 }
 
@@ -2609,18 +2632,17 @@ static void linklist_copy(LinkNode **target, LinkNode *source)
        for(; source; source = source->next) {
                if(node) {
                        node->next = MEM_mallocN(sizeof(*node->next), "nlink_copy");
-                                                                               node = node->next;
-} else {
-                                                                               node = *target = MEM_mallocN(sizeof(**target), "nlink_copy");
-}
-                                                                               node->link = source->link;
-                                                                               node->next = NULL;
-}
+                       node = node->next;
+               } else {
+                       node = *target = MEM_mallocN(sizeof(**target), "nlink_copy");
+               }       node->link = source->link;
+                       node->next = NULL;
+       }
 }
 #endif
 
-                                                                               /* appends source to target if it's not already in target */
-                                                                               static void linklist_append_unique(LinkNode **target, void *source) 
+/* appends source to target if it's not already in target */
+static void linklist_append_unique(LinkNode **target, void *source) 
 {
        LinkNode *node;
        LinkNode *prev = NULL;
@@ -3363,7 +3385,7 @@ static DerivedMesh *edgesplitModifier_applyModifier(
 }
 
 static DerivedMesh *edgesplitModifier_applyModifierEM(
-               ModifierData *md, Object *ob, EditMesh *editData,
+               ModifierData *md, Object *ob, BMEditMesh *editData,
   DerivedMesh *derivedData)
 {
        return edgesplitModifier_applyModifier(md, ob, derivedData, 0, 1);
@@ -3447,7 +3469,7 @@ static DerivedMesh *bevelModifier_applyModifier(
 }
 
 static DerivedMesh *bevelModifier_applyModifierEM(
-               ModifierData *md, Object *ob, EditMesh *editData,
+               ModifierData *md, Object *ob, BMEditMesh *editData,
   DerivedMesh *derivedData)
 {
        return bevelModifier_applyModifier(md, ob, derivedData, 0, 1);
@@ -3583,12 +3605,12 @@ static void get_texture_coords(DisplaceModifierData *dmd, Object *ob,
 
        /* UVs need special handling, since they come from faces */
        if(texmapping == MOD_DISP_MAP_UV) {
-               if(dm->getFaceDataArray(dm, CD_MTFACE)) {
-                       MFace *mface = dm->getFaceArray(dm);
+               if(dm->getTessFaceDataArray(dm, CD_MTFACE)) {
+                       MFace *mface = dm->getTessFaceArray(dm);
                        MFace *mf;
                        char *done = MEM_callocN(sizeof(*done) * numVerts,
                                        "get_texture_coords done");
-                       int numFaces = dm->getNumFaces(dm);
+                       int numFaces = dm->getNumTessFaces(dm);
                        char uvname[32];
                        MTFace *tf;
 
@@ -3775,13 +3797,13 @@ static void displaceModifier_deformVerts(
 }
 
 static void displaceModifier_deformVertsEM(
-                                          ModifierData *md, Object *ob, EditMesh *editData,
+                                          ModifierData *md, Object *ob, BMEditMesh *editData,
        DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
 {
        DerivedMesh *dm;
 
        if(derivedData) dm = CDDM_copy(derivedData);
-       else dm = CDDM_from_editmesh(editData, ob->data);
+       else dm = CDDM_from_BMEditMesh(editData, ob->data);
 
        CDDM_apply_vert_coords(dm, vertexCos);
        CDDM_calc_normals(dm);
@@ -3901,7 +3923,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
        if(num_projectors == 0) return dm;
 
        /* make sure there are UV layers available */
-       if(!dm->getFaceDataArray(dm, CD_MTFACE)) return dm;
+       if(!dm->getTessFaceDataArray(dm, CD_MTFACE)) return dm;
 
        /* make sure we're using an existing layer */
        validate_layer_name(&dm->faceData, CD_MTFACE, umd->uvlayer_name, uvname);
@@ -4007,8 +4029,8 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
                for(i = 0, co = coords; i < numVerts; ++i, ++co)
                        Mat4MulVec3Project(projectors[0].projmat, *co);
 
-       mface = dm->getFaceArray(dm);
-       numFaces = dm->getNumFaces(dm);
+       mface = dm->getTessFaceArray(dm);
+       numFaces = dm->getNumTessFaces(dm);
 
        /* apply coords as UVs, and apply image if tfaces are new */
        for(i = 0, mf = mface; i < numFaces; ++i, ++mf, ++tface) {
@@ -4106,7 +4128,7 @@ static DerivedMesh *uvprojectModifier_applyModifier(
 }
 
 static DerivedMesh *uvprojectModifier_applyModifierEM(
-               ModifierData *md, Object *ob, EditMesh *editData,
+               ModifierData *md, Object *ob, BMEditMesh *editData,
   DerivedMesh *derivedData)
 {
        return uvprojectModifier_applyModifier(md, ob, derivedData, 0, 1);
@@ -4142,9 +4164,9 @@ static DerivedMesh *decimateModifier_applyModifier(
        int a, numTris;
 
        mvert = dm->getVertArray(dm);
-       mface = dm->getFaceArray(dm);
+       mface = dm->getTessFaceArray(dm);
        totvert = dm->getNumVerts(dm);
-       totface = dm->getNumFaces(dm);
+       totface = dm->getNumTessFaces(dm);
 
        numTris = 0;
        for (a=0; a<totface; a++) {
@@ -4220,7 +4242,7 @@ static DerivedMesh *decimateModifier_applyModifier(
                        }
 
                        if(lod.vertex_num>2) {
-                               mface = CDDM_get_faces(result);
+                               mface = CDDM_get_tessfaces(result);
                                for(a=0; a<lod.face_num; a++) {
                                        MFace *mf = &mface[a];
                                        int *tri = &lod.triangle_index_buffer[a*3];
@@ -4459,13 +4481,13 @@ static void smoothModifier_deformVerts(
 }
 
 static void smoothModifier_deformVertsEM(
-                                        ModifierData *md, Object *ob, EditMesh *editData,
+                                        ModifierData *md, Object *ob, BMEditMesh *editData,
       DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
 {
        DerivedMesh *dm;
 
        if(derivedData) dm = CDDM_copy(derivedData);
-       else dm = CDDM_from_editmesh(editData, ob->data);
+       else dm = CDDM_from_BMEditMesh(editData, ob->data);
 
        CDDM_apply_vert_coords(dm, vertexCos);
        CDDM_calc_normals(dm);
@@ -5040,14 +5062,14 @@ static void castModifier_deformVerts(
 }
 
 static void castModifier_deformVertsEM(
-                                      ModifierData *md, Object *ob, EditMesh *editData,
+                                      ModifierData *md, Object *ob, BMEditMesh *editData,
           DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
 {
        DerivedMesh *dm = derivedData;
        CastModifierData *cmd = (CastModifierData *)md;
 
        if (!dm && ob->type == OB_MESH)
-               dm = CDDM_from_editmesh(editData, ob->data);
+               dm = CDDM_from_BMEditMesh(editData, ob->data);
 
        if (cmd->type == MOD_CAST_TYPE_CUBOID) {
                castModifier_cuboid_do(cmd, ob, dm, vertexCos, numVerts);
@@ -5184,12 +5206,12 @@ static void wavemod_get_texture_coords(WaveModifierData *wmd, Object *ob,
 
        /* UVs need special handling, since they come from faces */
        if(texmapping == MOD_WAV_MAP_UV) {
-               if(dm->getFaceDataArray(dm, CD_MTFACE)) {
-                       MFace *mface = dm->getFaceArray(dm);
+               if(dm->getTessFaceDataArray(dm, CD_MTFACE)) {
+                       MFace *mface = dm->getTessFaceArray(dm);
                        MFace *mf;
                        char *done = MEM_callocN(sizeof(*done) * numVerts,
                                        "get_texture_coords done");
-                       int numFaces = dm->getNumFaces(dm);
+                       int numFaces = dm->getNumTessFaces(dm);
                        char uvname[32];
                        MTFace *tf;
 
@@ -5446,7 +5468,7 @@ static void waveModifier_deformVerts(
 }
 
 static void waveModifier_deformVertsEM(
-                                      ModifierData *md, Object *ob, EditMesh *editData,
+                                      ModifierData *md, Object *ob, BMEditMesh *editData,
           DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
 {
        DerivedMesh *dm;
@@ -5455,7 +5477,7 @@ static void waveModifier_deformVertsEM(
        if(!wmd->texture && !wmd->defgrp_name[0] && !(wmd->flag & MOD_WAVE_NORM))
                dm = derivedData;
        else if(derivedData) dm = CDDM_copy(derivedData);
-       else dm = CDDM_from_editmesh(editData, ob->data);
+       else dm = CDDM_from_BMEditMesh(editData, ob->data);
 
        if(wmd->flag & MOD_WAVE_NORM) {
                CDDM_apply_vert_coords(dm, vertexCos);
@@ -5546,13 +5568,13 @@ static void armatureModifier_deformVerts(
 }
 
 static void armatureModifier_deformVertsEM(
-                                          ModifierData *md, Object *ob, EditMesh *editData,
+                                          ModifierData *md, Object *ob, BMEditMesh *editData,
        DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
 {
        ArmatureModifierData *amd = (ArmatureModifierData*) md;
        DerivedMesh *dm = derivedData;
 
-       if(!derivedData) dm = CDDM_from_editmesh(editData, ob->data);
+       if(!derivedData) dm = CDDM_from_BMEditMesh(editData, ob->data);
 
        armature_deform_verts(amd->object, ob, dm, vertexCos, NULL, numVerts,
                              amd->deformflag, NULL, amd->defgrp_name);
@@ -5561,14 +5583,14 @@ static void armatureModifier_deformVertsEM(
 }
 
 static void armatureModifier_deformMatricesEM(
-                                             ModifierData *md, Object *ob, EditMesh *editData,
+                                             ModifierData *md, Object *ob, BMEditMesh *editData,
           DerivedMesh *derivedData, float (*vertexCos)[3],
                                             float (*defMats)[3][3], int numVerts)
 {
        ArmatureModifierData *amd = (ArmatureModifierData*) md;
        DerivedMesh *dm = derivedData;
 
-       if(!derivedData) dm = CDDM_from_editmesh(editData, ob->data);
+       if(!derivedData) dm = CDDM_from_BMEditMesh(editData, ob->data);
 
        armature_deform_verts(amd->object, ob, dm, vertexCos, defMats, numVerts,
                              amd->deformflag, NULL, amd->defgrp_name);
@@ -5764,12 +5786,12 @@ static void hookModifier_deformVerts(
 }
 
 static void hookModifier_deformVertsEM(
-                                      ModifierData *md, Object *ob, EditMesh *editData,
+                                      ModifierData *md, Object *ob, BMEditMesh *editData,
           DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
 {
        DerivedMesh *dm = derivedData;
 
-       if(!derivedData) dm = CDDM_from_editmesh(editData, ob->data);
+       if(!derivedData) dm = CDDM_from_BMEditMesh(editData, ob->data);
 
        hookModifier_deformVerts(md, ob, derivedData, vertexCos, numVerts, 0, 0);
 
@@ -6115,8 +6137,8 @@ static void collisionModifier_deformVerts(
 
                                collmd->numverts = numverts;
                                
-                               collmd->mfaces = dm->dupFaceArray(dm);
-                               collmd->numfaces = dm->getNumFaces(dm);
+                               collmd->mfaces = dm->dupTessFaceArray(dm);
+                               collmd->numfaces = dm->getNumTessFaces(dm);
                                
                                // create bounding box hierarchy
                                collmd->bvhtree = bvhtree_build_from_mvert(collmd->mfaces, collmd->numfaces, collmd->x, numverts, ob->pd->pdef_sboft);
@@ -6353,8 +6375,8 @@ static DerivedMesh *booleanModifier_applyModifier(
        DerivedMesh *dm = mesh_get_derived_final(md->scene, bmd->object, CD_MASK_BAREMESH);
 
        /* we do a quick sanity check */
-       if(dm && (derivedData->getNumFaces(derivedData) > 3)
-                   && bmd->object && dm->getNumFaces(dm) > 3) {
+       if(dm && (derivedData->getNumTessFaces(derivedData) > 3)
+                   && bmd->object && dm->getNumTessFaces(dm) > 3) {
                DerivedMesh *result = NewBooleanDerivedMesh(dm, bmd->object, derivedData, ob,
                                1 + bmd->operation);
 
@@ -6513,7 +6535,7 @@ static void particleSystemModifier_deformVerts(
        /* report change in mesh structure */
        if(psmd->dm->getNumVerts(psmd->dm)!=psmd->totdmvert ||
                  psmd->dm->getNumEdges(psmd->dm)!=psmd->totdmedge ||
-                 psmd->dm->getNumFaces(psmd->dm)!=psmd->totdmface){
+                 psmd->dm->getNumTessFaces(psmd->dm)!=psmd->totdmface){
                /* in file read dm hasn't really changed but just wasn't saved in file */
 
                psys->recalc |= PSYS_RECALC_RESET;
@@ -6521,7 +6543,7 @@ static void particleSystemModifier_deformVerts(
 
                psmd->totdmvert= psmd->dm->getNumVerts(psmd->dm);
                psmd->totdmedge= psmd->dm->getNumEdges(psmd->dm);
-               psmd->totdmface= psmd->dm->getNumFaces(psmd->dm);
+               psmd->totdmface= psmd->dm->getNumTessFaces(psmd->dm);
                  }
 
                  if(psys){
@@ -6536,12 +6558,12 @@ static void particleSystemModifier_deformVerts(
  * updates is coded */
 #if 0
 static void particleSystemModifier_deformVertsEM(
-                ModifierData *md, Object *ob, EditMesh *editData,
+                ModifierData *md, Object *ob, BMEditMesh *editData,
                 DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
 {
        DerivedMesh *dm = derivedData;
 
-       if(!derivedData) dm = CDDM_from_editmesh(editData, ob->data);
+       if(!derivedData) dm = CDDM_from_BMEditMesh(editData, ob->data);
 
        particleSystemModifier_deformVerts(md, ob, dm, vertexCos, numVerts);
 
@@ -6661,7 +6683,7 @@ static DerivedMesh * particleInstanceModifier_applyModifier(
        pars=psys->particles;
 
        totvert=dm->getNumVerts(dm);
-       totface=dm->getNumFaces(dm);
+       totface=dm->getNumTessFaces(dm);
 
        maxvert=totvert*totpart;
        maxface=totface*totpart;
@@ -6677,7 +6699,7 @@ static DerivedMesh * particleInstanceModifier_applyModifier(
                max_co=max_r[track];
        }
 
-       result = CDDM_from_template(dm, maxvert,dm->getNumEdges(dm)*totpart,maxface);
+       result = CDDM_from_template(dm, maxvert,dm->getNumEdges(dm)*totpart,maxface, 0, 0);
 
        mvert=result->getVertArray(result);
        orig_mvert=dm->getVertArray(dm);
@@ -6749,8 +6771,8 @@ static DerivedMesh * particleInstanceModifier_applyModifier(
                VECADD(mv->co,mv->co,state.co);
        }
 
-       mface=result->getFaceArray(result);
-       orig_mface=dm->getFaceArray(dm);
+       mface=result->getTessFaceArray(result);
+       orig_mface=dm->getTessFaceArray(dm);
 
        for(i=0; i<maxface; i++){
                MFace *inMF;
@@ -6780,7 +6802,7 @@ static DerivedMesh * particleInstanceModifier_applyModifier(
                }
 
                inMF = orig_mface + i%totface;
-               DM_copy_face_data(dm, result, i%totface, i, 1);
+               DM_copy_tessface_data(dm, result, i%totface, i, 1);
                *mf = *inMF;
 
                mf->v1+=(i/totface)*totvert;
@@ -6797,14 +6819,15 @@ static DerivedMesh * particleInstanceModifier_applyModifier(
                end_latt_deform(psys->lattice);
                psys->lattice= NULL;
        }
-
+       
+       CDDM_tessfaces_to_faces(result);
        if(size)
                MEM_freeN(size);
 
        return result;
 }
 static DerivedMesh *particleInstanceModifier_applyModifierEM(
-               ModifierData *md, Object *ob, EditMesh *editData,
+               ModifierData *md, Object *ob, BMEditMesh *editData,
   DerivedMesh *derivedData)
 {
        return particleInstanceModifier_applyModifier(md, ob, derivedData, 0, 1);
@@ -6863,8 +6886,8 @@ static void explodeModifier_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;
 
@@ -6946,12 +6969,12 @@ static int edgesplit_get(EdgeHash *edgehash, int v1, int v2)
 static DerivedMesh * explodeModifier_splitEdges(ExplodeModifierData *emd, DerivedMesh *dm){
        DerivedMesh *splitdm;
        MFace *mf=0,*df1=0,*df2=0,*df3=0;
-       MFace *mface=CDDM_get_faces(dm);
+       MFace *mface=CDDM_get_tessfaces(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");
@@ -7037,14 +7060,14 @@ static DerivedMesh * explodeModifier_splitEdges(ExplodeModifierData *emd, Derive
                else if(*fs==4){
                        totfsplit+=3;
 
-                       mf=dm->getFaceData(dm,i,CD_MFACE);//CDDM_get_face(dm,i);
+                       mf=dm->getTessFaceData(dm,i,CD_MFACE);//CDDM_get_tessface(dm,i);
 
                        if(vertpa[mf->v1]!=vertpa[mf->v2] && vertpa[mf->v2]!=vertpa[mf->v3])
                                totin++;
                }
        }
        
-       splitdm= CDDM_from_template(dm, totesplit+totin, dm->getNumEdges(dm),totface+totfsplit);
+       splitdm= CDDM_from_template(dm, totesplit+totin, dm->getNumEdges(dm),totface+totfsplit, 0, 0);
 
        /* copy new faces & verts (is it really this painful with custom data??) */
        for(i=0; i<totvert; i++){
@@ -7059,10 +7082,10 @@ static DerivedMesh * explodeModifier_splitEdges(ExplodeModifierData *emd, Derive
        for(i=0; i<totface; i++){
                MFace source;
                MFace *dest;
-               dm->getFace(dm, i, &source);
-               dest = CDDM_get_face(splitdm, i);
+               dm->getTessFace(dm, i, &source);
+               dest = CDDM_get_tessface(splitdm, i);
 
-               DM_copy_face_data(dm, splitdm, i, i, 1);
+               DM_copy_tessface_data(dm, splitdm, i, i, 1);
                *dest = source;
        }
 
@@ -7096,7 +7119,7 @@ static DerivedMesh * explodeModifier_splitEdges(ExplodeModifierData *emd, Derive
        curdupin=totesplit;
        for(i=0,fs=facesplit; i<totface; i++,fs++){
                if(*fs){
-                       mf=CDDM_get_face(splitdm,i);
+                       mf=CDDM_get_tessface(splitdm,i);
 
                        v1=vertpa[mf->v1];
                        v2=vertpa[mf->v2];
@@ -7104,8 +7127,8 @@ static DerivedMesh * explodeModifier_splitEdges(ExplodeModifierData *emd, Derive
                        v4=vertpa[mf->v4];
                        /* ouch! creating new faces & remapping them to new verts is no fun */
                        if(*fs==1){
-                               df1=CDDM_get_face(splitdm,curdupface);
-                               DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
+                               df1=CDDM_get_tessface(splitdm,curdupface);
+                               DM_copy_tessface_data(splitdm,splitdm,i,curdupface,1);
                                *df1=*mf;
                                curdupface++;
                                
@@ -7128,13 +7151,13 @@ static DerivedMesh * explodeModifier_splitEdges(ExplodeModifierData *emd, Derive
                                test_index_face(df1, &splitdm->faceData, curdupface, (df1->v4 ? 4 : 3));
                        }
                        if(*fs==2){
-                               df1=CDDM_get_face(splitdm,curdupface);
-                               DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
+                               df1=CDDM_get_tessface(splitdm,curdupface);
+                               DM_copy_tessface_data(splitdm,splitdm,i,curdupface,1);
                                *df1=*mf;
                                curdupface++;
 
-                               df2=CDDM_get_face(splitdm,curdupface);
-                               DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
+                               df2=CDDM_get_tessface(splitdm,curdupface);
+                               DM_copy_tessface_data(splitdm,splitdm,i,curdupface,1);
                                *df2=*mf;
                                curdupface++;
 
@@ -7205,18 +7228,18 @@ static DerivedMesh * explodeModifier_splitEdges(ExplodeModifierData *emd, Derive
                                test_index_face(df1, &splitdm->faceData, curdupface-1, (df1->v4 ? 4 : 3));
                        }
                        else if(*fs==3){
-                               df1=CDDM_get_face(splitdm,curdupface);
-                               DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
+                               df1=CDDM_get_tessface(splitdm,curdupface);
+                               DM_copy_tessface_data(splitdm,splitdm,i,curdupface,1);
                                *df1=*mf;
                                curdupface++;
 
-                               df2=CDDM_get_face(splitdm,curdupface);
-                               DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
+                               df2=CDDM_get_tessface(splitdm,curdupface);
+                               DM_copy_tessface_data(splitdm,splitdm,i,curdupface,1);
                                *df2=*mf;
                                curdupface++;
 
-                               df3=CDDM_get_face(splitdm,curdupface);
-                               DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
+                               df3=CDDM_get_tessface(splitdm,curdupface);
+                               DM_copy_tessface_data(splitdm,splitdm,i,curdupface,1);
                                *df3=*mf;
                                curdupface++;
 
@@ -7306,18 +7329,18 @@ static DerivedMesh * explodeModifier_splitEdges(ExplodeModifierData *emd, Derive
                                        VecMulf(dupve->co,0.25);
 
 
-                                       df1=CDDM_get_face(splitdm,curdupface);
-                                       DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
+                                       df1=CDDM_get_tessface(splitdm,curdupface);
+                                       DM_copy_tessface_data(splitdm,splitdm,i,curdupface,1);
                                        *df1=*mf;
                                        curdupface++;
 
-                                       df2=CDDM_get_face(splitdm,curdupface);
-                                       DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
+                                       df2=CDDM_get_tessface(splitdm,curdupface);
+                                       DM_copy_tessface_data(splitdm,splitdm,i,curdupface,1);
                                        *df2=*mf;
                                        curdupface++;
 
-                                       df3=CDDM_get_face(splitdm,curdupface);
-                                       DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
+                                       df3=CDDM_get_tessface(splitdm,curdupface);
+                                       DM_copy_tessface_data(splitdm,splitdm,i,curdupface,1);
                                        *df3=*mf;
                                        curdupface++;
 
@@ -7346,18 +7369,18 @@ static DerivedMesh * explodeModifier_splitEdges(ExplodeModifierData *emd, Derive
                                        test_index_face(df1, &splitdm->faceData, curdupface-1, (df1->v4 ? 4 : 3));
                                }
                                else{
-                                       df1=CDDM_get_face(splitdm,curdupface);
-                                       DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
+                                       df1=CDDM_get_tessface(splitdm,curdupface);
+                                       DM_copy_tessface_data(splitdm,splitdm,i,curdupface,1);
                                        *df1=*mf;
                                        curdupface++;
 
-                                       df2=CDDM_get_face(splitdm,curdupface);
-                                       DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
+                                       df2=CDDM_get_tessface(splitdm,curdupface);
+                                       DM_copy_tessface_data(splitdm,splitdm,i,curdupface,1);
                                        *df2=*mf;
                                        curdupface++;
 
-                                       df3=CDDM_get_face(splitdm,curdupface);
-                                       DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
+                                       df3=CDDM_get_tessface(splitdm,curdupface);
+                                       DM_copy_tessface_data(splitdm,splitdm,i,curdupface,1);
                                        *df3=*mf;
                                        curdupface++;
 
@@ -7411,7 +7434,8 @@ static DerivedMesh * explodeModifier_splitEdges(ExplodeModifierData *emd, Derive
        BLI_edgehash_free(edgehash, NULL);
        MEM_freeN(facesplit);
        MEM_freeN(vertpa);
-
+       
+       CDDM_tessfaces_to_faces(splitdm);
        return splitdm;
 
 }
@@ -7433,7 +7457,7 @@ static DerivedMesh * explodeModifier_explodeMesh(ExplodeModifierData *emd,
        int totdup=0,totvert=0,totface=0,totpart=0;
        int i, j, v, mindex=0;
 
-       totface= dm->getNumFaces(dm);
+       totface= dm->getNumTessFaces(dm);
        totvert= dm->getNumVerts(dm);
        totpart= psmd->psys->totpart;
 
@@ -7455,7 +7479,7 @@ static DerivedMesh * explodeModifier_explodeMesh(ExplodeModifierData *emd,
                else 
                        mindex = totvert+facepa[i];
 
-               mf=CDDM_get_face(dm,i);
+               mf=CDDM_get_tessface(dm,i);
 
                /* set face vertices to exist in particle group */
                BLI_edgehash_insert(vertpahash, mf->v1, mindex, NULL);
@@ -7474,7 +7498,7 @@ static DerivedMesh * explodeModifier_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);
        /*dupvert= CDDM_get_verts(explode);*/
 
        /* getting back to object space */
@@ -7540,8 +7564,8 @@ static DerivedMesh * explodeModifier_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;
 
@@ -7556,7 +7580,7 @@ static DerivedMesh * explodeModifier_explodeMesh(ExplodeModifierData *emd,
                if(source.v4)
                        source.v4 = edgesplit_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;
 
@@ -7577,6 +7601,7 @@ static DerivedMesh * explodeModifier_explodeMesh(ExplodeModifierData *emd,
                psmd->psys->lattice= NULL;
        }
 
+       CDDM_tessfaces_to_faces(explode);
        return explode;
 }
 
@@ -7610,7 +7635,7 @@ static DerivedMesh * explodeModifier_applyModifier(
                if(emd->facepa==0
                                 || 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;
                        
@@ -7853,10 +7878,10 @@ static void meshdeformModifier_do(
 {
        MeshDeformModifierData *mmd = (MeshDeformModifierData*) md;
        Mesh *me= ob->data;
+       BMEditMesh *bem = me->edit_btmesh;
        DerivedMesh *tmpdm, *cagedm;
        MDeformVert *dvert = NULL;
        MDeformWeight *dw;
-       EditMesh *em = BKE_mesh_get_editmesh(me);
        MVert *cagemvert;
        float imat[4][4], cagemat[4][4], iobmat[4][4], icagemat[3][3], cmat[4][4];
        float weight, totweight, fac, co[3], *weights, (*dco)[3], (*bindcos)[3];
@@ -7866,11 +7891,10 @@ static void meshdeformModifier_do(
                return;
        
        /* get cage derivedmesh */
-       if(em) {
-               tmpdm= editmesh_get_derived_cage_and_final(md->scene, ob, em, &cagedm, 0);
+       if(bem) {
+               tmpdm= editbmesh_get_derived_cage_and_final(md->scene, ob, bem, &cagedm, 0);
                if(tmpdm)
                        tmpdm->release(tmpdm);
-               BKE_mesh_end_editmesh(me, em);
        }
        else
                cagedm= mmd->object->derivedFinal;
@@ -8032,13 +8056,13 @@ static void meshdeformModifier_deformVerts(
 }
 
 static void meshdeformModifier_deformVertsEM(
-                                            ModifierData *md, Object *ob, EditMesh *editData,
+                                            ModifierData *md, Object *ob, BMEditMesh *editData,
          DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
 {
        DerivedMesh *dm;
 
        if(!derivedData && ob->type == OB_MESH)
-               dm = CDDM_from_editmesh(editData, ob->data);
+               dm = CDDM_from_BMEditMesh(editData, ob->data);
        else
                dm = derivedData;
 
@@ -8190,7 +8214,7 @@ static void shrinkwrapModifier_deformVerts(ModifierData *md, Object *ob, Derived
                dm->release(dm);
 }
 
-static void shrinkwrapModifier_deformVertsEM(ModifierData *md, Object *ob, EditMesh *editData, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
+static void shrinkwrapModifier_deformVertsEM(ModifierData *md, Object *ob, BMEditMesh *editData, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
 {
        DerivedMesh *dm = NULL;
        CustomDataMask dataMask = shrinkwrapModifier_requiredDataMask(ob, md);
@@ -8198,7 +8222,7 @@ static void shrinkwrapModifier_deformVertsEM(ModifierData *md, Object *ob, EditM
        if(dataMask)
        {
                if(derivedData) dm = CDDM_copy(derivedData);
-               else if(ob->type==OB_MESH) dm = CDDM_from_editmesh(editData, ob->data);
+               else if(ob->type==OB_MESH) dm = CDDM_from_BMEditMesh(editData, ob->data);
                else if(ob->type==OB_LATTICE) dm = NULL;
                else return;
 
@@ -8305,7 +8329,7 @@ static void simpledeformModifier_deformVerts(ModifierData *md, Object *ob, Deriv
 
 }
 
-static void simpledeformModifier_deformVertsEM(ModifierData *md, Object *ob, EditMesh *editData, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
+static void simpledeformModifier_deformVertsEM(ModifierData *md, Object *ob, BMEditMesh *editData, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
 {
        DerivedMesh *dm = NULL;
        CustomDataMask dataMask = simpledeformModifier_requiredDataMask(ob, md);
@@ -8314,7 +8338,7 @@ static void simpledeformModifier_deformVertsEM(ModifierData *md, Object *ob, Edi
        if(dataMask)
        {
                if(derivedData) dm = CDDM_copy(derivedData);
-               else if(ob->type==OB_MESH) dm = CDDM_from_editmesh(editData, ob->data);
+               else if(ob->type==OB_MESH) dm = CDDM_from_BMEditMesh(editData, ob->data);
                else if(ob->type==OB_LATTICE) dm = NULL;
                else return;