(NOTE: DO NOT TEST)
authorJoseph Eagar <joeedh@gmail.com>
Wed, 10 Jun 2009 10:06:25 +0000 (10:06 +0000)
committerJoseph Eagar <joeedh@gmail.com>
Wed, 10 Jun 2009 10:06:25 +0000 (10:06 +0000)
Start of planned DerivedMesh refactoring.  The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).

short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles).  mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.

I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh.  Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).

I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.

I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.

35 files changed:
source/blender/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/BKE_cdderivedmesh.h
source/blender/blenkernel/BKE_multires.h
source/blender/blenkernel/intern/BME_conversions.c
source/blender/blenkernel/intern/CCGSubSurf.c
source/blender/blenkernel/intern/CCGSubSurf.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/anim.c
source/blender/blenkernel/intern/booleanops.c
source/blender/blenkernel/intern/bvhutils.c
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/cloth.c
source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/editderivedbmesh.c
source/blender/blenkernel/intern/exotic.c
source/blender/blenkernel/intern/fluidsim.c
source/blender/blenkernel/intern/modifier.c
source/blender/blenkernel/intern/multires.c
source/blender/blenkernel/intern/particle.c
source/blender/blenkernel/intern/particle_system.c
source/blender/blenkernel/intern/softbody.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/bmesh/bmesh.h
source/blender/bmesh/intern/bmesh_construct.c
source/blender/editors/armature/meshlaplacian.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/physics/editparticle.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/sculpt_paint/paint_utils.c
source/blender/editors/sculpt_paint/sculpt.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/transform/transform_snap.c
source/blender/render/intern/source/convertblender.c
source/blender/render/intern/source/strand.c
source/gameengine/Converter/BL_BlenderDataConversion.cpp

index 42904014ea8aa7f65211088049d7a21c459a1658..707b8f143dac21d56b5a1adb423e133b96a22c9f 100644 (file)
@@ -43,6 +43,8 @@
  */
 
 #include "DNA_customdata_types.h"
+#include "DNA_meshdata_types.h"
+
 #include "BKE_customdata.h"
 #include "BKE_bvhutils.h"
 
@@ -65,32 +67,75 @@ struct BMEditMesh;
 #define SUB_ELEMS_EDGE 2
 #define SUB_ELEMS_FACE 4
 
+/*
+note: all mface interfaces now officially operate on tesselated data.
+*/
+
+/*DM Iterators.  For now, first implement face iterators.
+  These are read-only, at least for now.*/
+
+typedef struct DMLoopIter {
+       void (*step)(void *self);
+       int done;
+
+       int index, vindex, eindex;
+       MVert v; /*copy of the associated vert's data*/ 
+
+       /*note: if layer is -1, then the active layer is retrieved.
+         loop refers to per-face-vertex data.*/
+       void *(*getLoopCDData)(void *self, int type, int layer);
+       void *(*getVertCDData)(void *self, int type, int layer);
+} DMLoopIter;
+
+typedef struct DMFaceIter {
+       void (*step)(void *self);
+       void (*free)(void *self);
+       int done;
+
+       int index;
+       int len;
+       int mat_nr;
+       int flags;
+
+       /*note: you may only use one
+         loop iterator at a time.*/
+       DMLoopIter *(*getLoopsIter)(void *self);
+
+       /*if layer is -1, returns active layer*/
+       void *(*getCDData)(void *self, int type, int layer);
+} DMFaceIter;
+
 typedef struct DerivedMesh DerivedMesh;
 struct DerivedMesh {
        /* Private DerivedMesh data, only for internal DerivedMesh use */
-       CustomData vertData, edgeData, faceData;
-       int numVertData, numEdgeData, numFaceData;
+       CustomData vertData, edgeData, faceData, loopData, polyData;
+       int numVertData, numEdgeData, numFaceData, numLoopData, numPolyData;
        int needsFree; /* checked on ->release, is set to 0 for cached results */
        int deformedOnly; /* set by modifier stack if only deformed from original */
        BVHCache bvhCache;
 
        /* Misc. Queries */
+       
+       /*face iterator.  initializes iter.*/
+       DMFaceIter *(*newFaceIter)(DerivedMesh *dm);
+
+       /*recalculates mesh tesselation*/
+       void (*recalcTesselation)(DerivedMesh *dm);
 
        /* Also called in Editmode */
        int (*getNumVerts)(DerivedMesh *dm);
-       /* Also called in Editmode */
-       int (*getNumFaces)(DerivedMesh *dm);
-
        int (*getNumEdges)(DerivedMesh *dm);
+       int (*getNumTessFaces)(DerivedMesh *dm);
+       int (*getNumFaces) (DerivedMesh *dm);
 
-       /* copy a single vert/edge/face from the derived mesh into
+       /* copy a single vert/edge/tesselated face from the derived mesh into
         * *{vert/edge/face}_r. note that the current implementation
         * of this function can be quite slow, iterating over all
         * elements (editmesh)
         */
        void (*getVert)(DerivedMesh *dm, int index, struct MVert *vert_r);
        void (*getEdge)(DerivedMesh *dm, int index, struct MEdge *edge_r);
-       void (*getFace)(DerivedMesh *dm, int index, struct MFace *face_r);
+       void (*getTessFace)(DerivedMesh *dm, int index, struct MFace *face_r);
 
        /* return a pointer to the entire array of verts/edges/face from the
         * derived mesh. if such an array does not exist yet, it will be created,
@@ -99,21 +144,21 @@ struct DerivedMesh {
         */
        struct MVert *(*getVertArray)(DerivedMesh *dm);
        struct MEdge *(*getEdgeArray)(DerivedMesh *dm);
-       struct MFace *(*getFaceArray)(DerivedMesh *dm);
+       struct MFace *(*getTessFaceArray)(DerivedMesh *dm);
 
        /* copy all verts/edges/faces from the derived mesh into
         * *{vert/edge/face}_r (must point to a buffer large enough)
         */
        void (*copyVertArray)(DerivedMesh *dm, struct MVert *vert_r);
        void (*copyEdgeArray)(DerivedMesh *dm, struct MEdge *edge_r);
-       void (*copyFaceArray)(DerivedMesh *dm, struct MFace *face_r);
+       void (*copyTessFaceArray)(DerivedMesh *dm, struct MFace *face_r);
 
        /* return a copy of all verts/edges/faces from the derived mesh
         * it is the caller's responsibility to free the returned pointer
         */
        struct MVert *(*dupVertArray)(DerivedMesh *dm);
        struct MEdge *(*dupEdgeArray)(DerivedMesh *dm);
-       struct MFace *(*dupFaceArray)(DerivedMesh *dm);
+       struct MFace *(*dupTessFaceArray)(DerivedMesh *dm);
 
        /* return a pointer to a single element of vert/edge/face custom data
         * from the derived mesh (this gives a pointer to the actual data, not
@@ -121,7 +166,7 @@ struct DerivedMesh {
         */
        void *(*getVertData)(DerivedMesh *dm, int index, int type);
        void *(*getEdgeData)(DerivedMesh *dm, int index, int type);
-       void *(*getFaceData)(DerivedMesh *dm, int index, int type);
+       void *(*getTessFaceData)(DerivedMesh *dm, int index, int type);
 
        /* return a pointer to the entire array of vert/edge/face custom data
         * from the derived mesh (this gives a pointer to the actual data, not
@@ -129,7 +174,7 @@ struct DerivedMesh {
         */
        void *(*getVertDataArray)(DerivedMesh *dm, int type);
        void *(*getEdgeDataArray)(DerivedMesh *dm, int type);
-       void *(*getFaceDataArray)(DerivedMesh *dm, int type);
+       void *(*getTessFaceDataArray)(DerivedMesh *dm, int type);
 
        /* Iterate over each mapped vertex in the derived mesh, calling the
         * given function with the original vert and the mapped vert's new
@@ -300,13 +345,15 @@ void DM_init_funcs(DerivedMesh *dm);
  * of vertices, edges and faces (doesn't allocate memory for them, just
  * sets up the custom data layers)
  */
-void DM_init(DerivedMesh *dm, int numVerts, int numEdges, int numFaces);
+void DM_init(DerivedMesh *dm, int numVerts, int numEdges, int numFaces,
+            int numLoops, int numPolys);
 
 /* utility function to initialise a DerivedMesh for the desired number
  * of vertices, edges and faces, with a layer setup copied from source
  */
 void DM_from_template(DerivedMesh *dm, DerivedMesh *source,
-                      int numVerts, int numEdges, int numFaces);
+                      int numVerts, int numEdges, int numFaces,
+                     int numLoops, int numPolys);
 
 /* utility function to release a DerivedMesh's layers
  * returns 1 if DerivedMesh has to be released by the backend, 0 otherwise
@@ -369,6 +416,10 @@ void DM_copy_vert_data(struct DerivedMesh *source, struct DerivedMesh *dest,
                        int source_index, int dest_index, int count);
 void DM_copy_edge_data(struct DerivedMesh *source, struct DerivedMesh *dest,
                        int source_index, int dest_index, int count);
+void DM_copy_tessface_data(struct DerivedMesh *source, struct DerivedMesh *dest,
+                       int source_index, int dest_index, int count);
+void DM_copy_loop_data(struct DerivedMesh *source, struct DerivedMesh *dest,
+                       int source_index, int dest_index, int count);
 void DM_copy_face_data(struct DerivedMesh *source, struct DerivedMesh *dest,
                        int source_index, int dest_index, int count);
 
@@ -378,8 +429,13 @@ void DM_copy_face_data(struct DerivedMesh *source, struct DerivedMesh *dest,
  */
 void DM_free_vert_data(struct DerivedMesh *dm, int index, int count);
 void DM_free_edge_data(struct DerivedMesh *dm, int index, int count);
+void DM_free_tessface_data(struct DerivedMesh *dm, int index, int count);
+void DM_free_loop_data(struct DerivedMesh *dm, int index, int count);
 void DM_free_face_data(struct DerivedMesh *dm, int index, int count);
 
+/*sets up mpolys for a DM based on face iterators in source*/
+void DM_DupPolys(DerivedMesh *source, DerivedMesh *target);
+
 /* interpolates vertex data from the vertices indexed by src_indices in the
  * source mesh using the given weights and stores the result in the vertex
  * indexed by dest_index in the dest mesh
@@ -409,12 +465,20 @@ void DM_interp_edge_data(struct DerivedMesh *source, struct DerivedMesh *dest,
  * vert_weights[i] multiplied by weights[i].
  */
 typedef float FaceVertWeight[SUB_ELEMS_FACE][SUB_ELEMS_FACE];
-void DM_interp_face_data(struct DerivedMesh *source, struct DerivedMesh *dest,
+void DM_interp_tessface_data(struct DerivedMesh *source, struct DerivedMesh *dest,
                          int *src_indices,
                          float *weights, FaceVertWeight *vert_weights,
                          int count, int dest_index);
 
-void DM_swap_face_data(struct DerivedMesh *dm, int index, int *corner_indices);
+void DM_swap_tessface_data(struct DerivedMesh *dm, int index, int *corner_indices);
+
+void DM_interp_loop_data(struct DerivedMesh *source, struct DerivedMesh *dest,
+                         int *src_indices,
+                         float *weights, int count, int dest_index);
+
+void DM_interp_face_data(struct DerivedMesh *source, struct DerivedMesh *dest,
+                         int *src_indices,
+                         float *weights, int count, int dest_index);
 
 /* Temporary? A function to give a colorband to derivedmesh for vertexcolor ranges */
 void vDM_ColorBand_store(struct ColorBand *coba);
index d4fee61f9c601c5ed41ed1699c8adb7bc9bc11cb..36db9553c595a1f7e74312f11d9824fd3c53d096 100644 (file)
@@ -44,7 +44,8 @@ struct Mesh;
 struct Object;
 
 /* creates a new CDDerivedMesh */
-struct DerivedMesh *CDDM_new(int numVerts, int numEdges, int numFaces);
+struct DerivedMesh *CDDM_new(int numVerts, int numEdges, int numFaces,
+                             int numLoops, int numPolys);
 
 /* creates a CDDerivedMesh from the given Mesh, this will reference the
    original data in Mesh, but it is safe to apply vertex coordinates or
@@ -68,7 +69,13 @@ struct DerivedMesh *CDDM_copy(struct DerivedMesh *dm);
  * elements are initialised to all zeros
  */
 struct DerivedMesh *CDDM_from_template(struct DerivedMesh *source,
-                                  int numVerts, int numEdges, int numFaces);
+                                  int numVerts, int numEdges, int numFaces,
+                                  int numLoops, int numPolys);
+
+/*converts mfaces to mpolys.  note things may break if there are not valid
+ *medges surrounding each mface.
+ */
+void CDDM_tessfaces_to_faces(struct DerivedMesh *dm);
 
 /* applies vertex coordinates or normals to a CDDerivedMesh. if the MVert
  * layer is a referenced layer, it will be duplicate to not overwrite the
@@ -99,7 +106,9 @@ void CDDM_lower_num_faces(struct DerivedMesh *dm, int numFaces);
  */
 struct MVert *CDDM_get_vert(struct DerivedMesh *dm, int index);
 struct MEdge *CDDM_get_edge(struct DerivedMesh *dm, int index);
-struct MFace *CDDM_get_face(struct DerivedMesh *dm, int index);
+struct MFace *CDDM_get_tessface(struct DerivedMesh *dm, int index);
+struct MLoop *CDDM_get_loop(struct DerivedMesh *dm, int index);
+struct MPoly *CDDM_get_face(struct DerivedMesh *dm, int index);
 
 /* vertex/edge/face array access functions - return the array holding the
  * desired data
@@ -108,6 +117,9 @@ struct MFace *CDDM_get_face(struct DerivedMesh *dm, int index);
  */
 struct MVert *CDDM_get_verts(struct DerivedMesh *dm);
 struct MEdge *CDDM_get_edges(struct DerivedMesh *dm);
-struct MFace *CDDM_get_faces(struct DerivedMesh *dm);
+struct MFace *CDDM_get_tessfaces(struct DerivedMesh *dm);
+struct MLoop *CDDM_get_loops(struct DerivedMesh *dm);
+struct MPoly *CDDM_get_faces(struct DerivedMesh *dm);
+
 #endif
 
index 3b0ff2db6f46292bfd328c3f06558db5c972dbd9..8835a7127f178a99479e6706f4fe1f2ef06315be 100644 (file)
@@ -40,7 +40,8 @@ typedef struct MultiresSubsurf {
 
 /* MultiresDM */
 struct Mesh *MultiresDM_get_mesh(struct DerivedMesh *dm);
-struct DerivedMesh *MultiresDM_new(struct MultiresSubsurf *, struct DerivedMesh*, int, int, int);
+struct DerivedMesh *MultiresDM_new(struct MultiresSubsurf *, struct DerivedMesh*, 
+                                   int, int, int, int, int);
 void *MultiresDM_get_vertnorm(struct DerivedMesh *);
 void *MultiresDM_get_orco(struct DerivedMesh *);
 struct MVert *MultiresDM_get_subco(struct DerivedMesh *);
index 177bb4a136b231b694599f3ae4e29bea5e93b507..dcfe4e6fa362f85f49ec05285a74443a271013e9 100644 (file)
@@ -475,10 +475,10 @@ BME_Mesh *BME_derivedmesh_to_bmesh(DerivedMesh *dm)
 
        totvert = dm->getNumVerts(dm);
        totedge = dm->getNumEdges(dm);
-       totface = dm->getNumFaces(dm);
+       totface = dm->getNumTessFaces(dm);
        mvert = dm->getVertArray(dm);
        medge = dm->getEdgeArray(dm);
-       mface = dm->getFaceArray(dm);
+       mface = dm->getTessFaceArray(dm);
 
        vert_array = MEM_mallocN(sizeof(*vert_array)*totvert,"BME_derivedmesh_to_bmesh BME_Vert* array");
 
@@ -574,7 +574,8 @@ DerivedMesh *BME_bmesh_to_derivedmesh(BME_Mesh *bm, DerivedMesh *dm)
        }
        
        /*convert back to mesh*/
-       result = CDDM_from_template(dm,totvert,totedge,totface);
+       /*BMESH_TODO this should add in mloops and mpolys as well*/
+       result = CDDM_from_template(dm,totvert,totedge,totface, 0, 0);
        CustomData_merge(&bm->vdata, &result->vertData, CD_MASK_BMESH, CD_CALLOC, totvert);
        CustomData_merge(&bm->edata, &result->edgeData, CD_MASK_BMESH, CD_CALLOC, totedge);
        CustomData_merge(&bm->pdata, &result->faceData, CD_MASK_BMESH, CD_CALLOC, totface);
@@ -613,7 +614,7 @@ DerivedMesh *BME_bmesh_to_derivedmesh(BME_Mesh *bm, DerivedMesh *dm)
                }
        }
        if(totface){
-               mface = CDDM_get_faces(result);
+               mface = CDDM_get_tessfaces(result);
                /*make faces*/
                for(i=0,f=bm->polys.first;f;f=f->next){
                        mf = &mface[i];
index cee032f364eb74c78a70b84f40ffe057c306b2f0..c2fc626b8e14d87526f2a2f3d1d302bab010b765 100644 (file)
@@ -2035,7 +2035,7 @@ int ccgSubSurf_getNumVerts(CCGSubSurf *ss) {
 int ccgSubSurf_getNumEdges(CCGSubSurf *ss) {
        return ss->eMap->numEntries;
 }
-int ccgSubSurf_getNumFaces(CCGSubSurf *ss) {
+int ccgSubSurf_getNumTessFaces(CCGSubSurf *ss) {
        return ss->fMap->numEntries;
 }
 
index fbd0aecc0a515c5d2b259dd174fae252c5fb22ab..c77163148999ce0eb22f4dd5b5c14a43861ea556 100644 (file)
@@ -73,7 +73,7 @@ CCGError      ccgSubSurf_setCalcVertexNormals         (CCGSubSurf *ss, int useVertNormals, i
 
 int                    ccgSubSurf_getNumVerts                          (CCGSubSurf *ss);
 int                    ccgSubSurf_getNumEdges                          (CCGSubSurf *ss);
-int                    ccgSubSurf_getNumFaces                          (CCGSubSurf *ss);
+int                    ccgSubSurf_getNumTessFaces                              (CCGSubSurf *ss);
 
 int                    ccgSubSurf_getSubdivisionLevels         (CCGSubSurf *ss);
 int                    ccgSubSurf_getEdgeSize                          (CCGSubSurf *ss);
index 2eed104f43bb4ad166608e48903dc02408b8a342..63b3152ae95bf94f9e0f5a1d008b26d08492d468 100644 (file)
@@ -125,9 +125,9 @@ static MFace *dm_getFaceArray(DerivedMesh *dm)
 
        if (!mface) {
                mface = CustomData_add_layer(&dm->faceData, CD_MFACE, CD_CALLOC, NULL,
-                       dm->getNumFaces(dm));
+                       dm->getNumTessFaces(dm));
                CustomData_set_layer_flag(&dm->faceData, CD_MFACE, CD_FLAG_TEMPORARY);
-               dm->copyFaceArray(dm, mface);
+               dm->copyTessFaceArray(dm, mface);
        }
 
        return mface;
@@ -155,10 +155,10 @@ static MEdge *dm_dupEdgeArray(DerivedMesh *dm)
 
 static MFace *dm_dupFaceArray(DerivedMesh *dm)
 {
-       MFace *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumFaces(dm),
+       MFace *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumTessFaces(dm),
                                 "dm_dupFaceArray tmp");
 
-       if(tmp) dm->copyFaceArray(dm, tmp);
+       if(tmp) dm->copyTessFaceArray(dm, tmp);
 
        return tmp;
 }
@@ -168,27 +168,29 @@ void DM_init_funcs(DerivedMesh *dm)
        /* default function implementations */
        dm->getVertArray = dm_getVertArray;
        dm->getEdgeArray = dm_getEdgeArray;
-       dm->getFaceArray = dm_getFaceArray;
+       dm->getTessFaceArray = dm_getFaceArray;
        dm->dupVertArray = dm_dupVertArray;
        dm->dupEdgeArray = dm_dupEdgeArray;
-       dm->dupFaceArray = dm_dupFaceArray;
+       dm->dupTessFaceArray = dm_dupFaceArray;
 
        dm->getVertData = DM_get_vert_data;
        dm->getEdgeData = DM_get_edge_data;
-       dm->getFaceData = DM_get_face_data;
+       dm->getTessFaceData = DM_get_face_data;
        dm->getVertDataArray = DM_get_vert_data_layer;
        dm->getEdgeDataArray = DM_get_edge_data_layer;
-       dm->getFaceDataArray = DM_get_face_data_layer;
+       dm->getTessFaceDataArray = DM_get_face_data_layer;
 
        bvhcache_init(&dm->bvhCache);
 }
 
-void DM_init(DerivedMesh *dm,
-             int numVerts, int numEdges, int numFaces)
+void DM_init(DerivedMesh *dm, int numVerts, int numEdges, int numFaces,
+            int numLoops, int numPoly)
 {
        dm->numVertData = numVerts;
        dm->numEdgeData = numEdges;
        dm->numFaceData = numFaces;
+       dm->numLoopData = numLoops;
+       dm->numPolyData = numPoly;
 
        DM_init_funcs(dm);
        
@@ -196,7 +198,8 @@ void DM_init(DerivedMesh *dm,
 }
 
 void DM_from_template(DerivedMesh *dm, DerivedMesh *source,
-                      int numVerts, int numEdges, int numFaces)
+                      int numVerts, int numEdges, int numFaces,
+                     int numLoops, int numPolys)
 {
        CustomData_copy(&source->vertData, &dm->vertData, CD_MASK_DERIVEDMESH,
                        CD_CALLOC, numVerts);
@@ -204,10 +207,16 @@ void DM_from_template(DerivedMesh *dm, DerivedMesh *source,
                        CD_CALLOC, numEdges);
        CustomData_copy(&source->faceData, &dm->faceData, CD_MASK_DERIVEDMESH,
                        CD_CALLOC, numFaces);
+       CustomData_copy(&source->loopData, &dm->loopData, CD_MASK_DERIVEDMESH,
+                       CD_CALLOC, numLoops);
+       CustomData_copy(&source->polyData, &dm->polyData, CD_MASK_DERIVEDMESH,
+                       CD_CALLOC, numPolys);
 
        dm->numVertData = numVerts;
        dm->numEdgeData = numEdges;
        dm->numFaceData = numFaces;
+       dm->numLoopData = numLoops;
+       dm->numPolyData = numPolys;
 
        DM_init_funcs(dm);
 
@@ -222,6 +231,8 @@ int DM_release(DerivedMesh *dm)
                CustomData_free(&dm->vertData, dm->numVertData);
                CustomData_free(&dm->edgeData, dm->numEdgeData);
                CustomData_free(&dm->faceData, dm->numFaceData);
+               CustomData_free(&dm->loopData, dm->numLoopData);
+               CustomData_free(&dm->polyData, dm->numPolyData);
 
                return 1;
        }
@@ -229,28 +240,105 @@ int DM_release(DerivedMesh *dm)
                CustomData_free_temporary(&dm->vertData, dm->numVertData);
                CustomData_free_temporary(&dm->edgeData, dm->numEdgeData);
                CustomData_free_temporary(&dm->faceData, dm->numFaceData);
+               CustomData_free(&dm->loopData, dm->numLoopData);
+               CustomData_free(&dm->polyData, dm->numPolyData);
 
                return 0;
        }
 }
 
+void dm_add_polys_from_iter(CustomData *ldata, CustomData *pdata, DerivedMesh *dm, int totloop)
+{
+       DMFaceIter *iter = dm->newFaceIter(dm);
+       DMLoopIter *liter;
+       MPoly *mpoly;
+       MLoop *mloop;
+       int i;
+
+       mloop = MEM_callocN(sizeof(MLoop)*totloop, "MLoop from dm_add_polys_from_iter");
+       mpoly = MEM_callocN(sizeof(MPoly)*dm->getNumFaces(dm), "MPoly from dm_add_polys_from_iter");
+       
+       CustomData_add_layer(ldata, CD_MLOOP, CD_ASSIGN, mloop, totloop);
+       CustomData_add_layer(pdata, CD_MPOLY, CD_ASSIGN, mpoly, dm->getNumFaces(dm));
+
+       i = 0;
+       for (; !iter->done; iter->step(iter), mpoly++) {
+               mpoly->flag = iter->flags;
+               mpoly->loopstart = i;
+               mpoly->totloop = iter->len;
+               mpoly->mat_nr = iter->mat_nr;
+               
+               liter = iter->getLoopsIter(iter);
+               for (; !liter->done; liter->step(liter), mloop++, i++) {
+                       mloop->v = liter->vindex;
+                       mloop->e = liter->eindex;
+               }
+       }
+       iter->free(iter);
+}
+
+void DM_DupPolys(DerivedMesh *source, DerivedMesh *target)
+{
+       DMFaceIter *iter = source->newFaceIter(source);
+       DMLoopIter *liter;
+       MPoly *mpoly;
+       MLoop *mloop;
+       int i;
+
+       mloop = MEM_callocN(sizeof(MLoop)*source->numLoopData, "MLoop from dm_add_polys_from_iter");
+       mpoly = MEM_callocN(sizeof(MPoly)*source->getNumFaces(source), "MPoly from dm_add_polys_from_iter");
+       
+       CustomData_add_layer(&target->loopData, CD_MLOOP, CD_ASSIGN, mloop, source->numLoopData);
+       CustomData_add_layer(&target->polyData, CD_MPOLY, CD_ASSIGN, mpoly, source->getNumFaces(source));
+       
+       target->numLoopData = source->numLoopData;
+       target->numPolyData = source->numPolyData;
+
+       i = 0;
+       for (; !iter->done; iter->step(iter), mpoly++) {
+               mpoly->flag = iter->flags;
+               mpoly->loopstart = i;
+               mpoly->totloop = iter->len;
+               mpoly->mat_nr = iter->mat_nr;
+               
+               liter = iter->getLoopsIter(iter);
+               for (; !liter->done; liter->step(liter), mloop++, i++) {
+                       mloop->v = liter->vindex;
+                       mloop->e = liter->eindex;
+               }
+       }
+       iter->free(iter);
+}
+
 void DM_to_mesh(DerivedMesh *dm, Mesh *me)
 {
        /* dm might depend on me, so we need to do everything with a local copy */
        Mesh tmp = *me;
-       int totvert, totedge, totface;
+       DMFaceIter *iter;
+       int totvert, totedge, totface, totloop, totpoly;
 
        memset(&tmp.vdata, 0, sizeof(tmp.vdata));
        memset(&tmp.edata, 0, sizeof(tmp.edata));
        memset(&tmp.fdata, 0, sizeof(tmp.fdata));
+       memset(&tmp.ldata, 0, sizeof(tmp.ldata));
+       memset(&tmp.pdata, 0, sizeof(tmp.pdata));
 
        totvert = tmp.totvert = dm->getNumVerts(dm);
        totedge = tmp.totedge = dm->getNumEdges(dm);
-       totface = tmp.totface = dm->getNumFaces(dm);
+       totface = tmp.totface = dm->getNumTessFaces(dm);
+       totpoly = tmp.totpoly = dm->getNumFaces(dm);
+       
+       totloop = 0;
+       for (iter=dm->newFaceIter(dm); !iter->done; iter->step(iter)) {
+               totloop += iter->len;
+       }
+       iter->free(iter);
 
        CustomData_copy(&dm->vertData, &tmp.vdata, CD_MASK_MESH, CD_DUPLICATE, totvert);
        CustomData_copy(&dm->edgeData, &tmp.edata, CD_MASK_MESH, CD_DUPLICATE, totedge);
        CustomData_copy(&dm->faceData, &tmp.fdata, CD_MASK_MESH, CD_DUPLICATE, totface);
+       CustomData_copy(&dm->loopData, &tmp.ldata, CD_MASK_MESH, CD_DUPLICATE, totloop);
+       CustomData_copy(&dm->polyData, &tmp.pdata, CD_MASK_MESH, CD_DUPLICATE, totpoly);
 
        /* not all DerivedMeshes store their verts/edges/faces in CustomData, so
           we set them here in case they are missing */
@@ -259,7 +347,10 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me)
        if(!CustomData_has_layer(&tmp.edata, CD_MEDGE))
                CustomData_add_layer(&tmp.edata, CD_MEDGE, CD_ASSIGN, dm->dupEdgeArray(dm), totedge);
        if(!CustomData_has_layer(&tmp.fdata, CD_MFACE))
-               CustomData_add_layer(&tmp.fdata, CD_MFACE, CD_ASSIGN, dm->dupFaceArray(dm), totface);
+               CustomData_add_layer(&tmp.fdata, CD_MFACE, CD_ASSIGN, dm->dupTessFaceArray(dm), totface);
+       
+       if(!CustomData_has_layer(&tmp.fdata, CD_MPOLY))
+               dm_add_polys_from_iter(&tmp.ldata, &tmp.pdata, dm, totloop);
 
        mesh_update_customdata_pointers(&tmp);
 
@@ -357,13 +448,27 @@ void DM_copy_edge_data(DerivedMesh *source, DerivedMesh *dest,
                             source_index, dest_index, count);
 }
 
-void DM_copy_face_data(DerivedMesh *source, DerivedMesh *dest,
+void DM_copy_tessface_data(DerivedMesh *source, DerivedMesh *dest,
                        int source_index, int dest_index, int count)
 {
        CustomData_copy_data(&source->faceData, &dest->faceData,
                             source_index, dest_index, count);
 }
 
+void DM_copy_loop_data(DerivedMesh *source, DerivedMesh *dest,
+                       int source_index, int dest_index, int count)
+{
+       CustomData_copy_data(&source->loopData, &dest->loopData,
+                            source_index, dest_index, count);
+}
+
+void DM_copy_face_data(DerivedMesh *source, DerivedMesh *dest,
+                       int source_index, int dest_index, int count)
+{
+       CustomData_copy_data(&source->polyData, &dest->polyData,
+                            source_index, dest_index, count);
+}
+
 void DM_free_vert_data(struct DerivedMesh *dm, int index, int count)
 {
        CustomData_free_elem(&dm->vertData, index, count);
@@ -374,11 +479,21 @@ void DM_free_edge_data(struct DerivedMesh *dm, int index, int count)
        CustomData_free_elem(&dm->edgeData, index, count);
 }
 
-void DM_free_face_data(struct DerivedMesh *dm, int index, int count)
+void DM_free_tessface_data(struct DerivedMesh *dm, int index, int count)
 {
        CustomData_free_elem(&dm->faceData, index, count);
 }
 
+void DM_free_loop_data(struct DerivedMesh *dm, int index, int count)
+{
+       CustomData_free_elem(&dm->loopData, index, count);
+}
+
+void DM_free_face_data(struct DerivedMesh *dm, int index, int count)
+{
+       CustomData_free_elem(&dm->polyData, index, count);
+}
+
 void DM_interp_vert_data(DerivedMesh *source, DerivedMesh *dest,
                          int *src_indices, float *weights,
                          int count, int dest_index)
@@ -396,7 +511,7 @@ void DM_interp_edge_data(DerivedMesh *source, DerivedMesh *dest,
                          weights, (float*)vert_weights, count, dest_index);
 }
 
-void DM_interp_face_data(DerivedMesh *source, DerivedMesh *dest,
+void DM_interp_tessface_data(DerivedMesh *source, DerivedMesh *dest,
                          int *src_indices,
                          float *weights, FaceVertWeight *vert_weights,
                          int count, int dest_index)
@@ -405,11 +520,28 @@ void DM_interp_face_data(DerivedMesh *source, DerivedMesh *dest,
                          weights, (float*)vert_weights, count, dest_index);
 }
 
-void DM_swap_face_data(DerivedMesh *dm, int index, int *corner_indices)
+
+void DM_swap_tessface_data(DerivedMesh *dm, int index, int *corner_indices)
 {
        CustomData_swap(&dm->faceData, index, corner_indices);
 }
 
+void DM_interp_loop_data(DerivedMesh *source, DerivedMesh *dest,
+                         int *src_indices,
+                         float *weights, int count, int dest_index)
+{
+       CustomData_interp(&source->loopData, &dest->loopData, src_indices,
+                         weights, NULL, count, dest_index);
+}
+
+void DM_interp_face_data(DerivedMesh *source, DerivedMesh *dest,
+                         int *src_indices,
+                         float *weights, int count, int dest_index)
+{
+       CustomData_interp(&source->polyData, &dest->polyData, src_indices,
+                         weights, NULL, count, dest_index);
+}
+
 ///
 
 static DerivedMesh *getMeshDerivedMesh(Mesh *me, Object *ob, float (*vertCos)[3])
@@ -438,9 +570,9 @@ typedef struct {
        float (*faceNos)[3];
 } EditMeshDerivedMesh;
 
-static void emDM_foreachMappedVert(DerivedMesh *dm, void (*func)(void *userData, int index, float *co, float *no_f, short *no_s), void *userData)
+static void emDM_foreachMappedVert(void *dm, void (*func)(void *userData, int index, float *co, float *no_f, short *no_s), void *userData)
 {
-       EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
+       EditMeshDerivedMesh *emdm= dm;
        EditVert *eve;
        int i;
 
@@ -452,9 +584,9 @@ static void emDM_foreachMappedVert(DerivedMesh *dm, void (*func)(void *userData,
                }
        }
 }
-static void emDM_foreachMappedEdge(DerivedMesh *dm, void (*func)(void *userData, int index, float *v0co, float *v1co), void *userData)
+static void emDM_foreachMappedEdge(void *dm, void (*func)(void *userData, int index, float *v0co, float *v1co), void *userData)
 {
-       EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
+       EditMeshDerivedMesh *emdm= dm;
        EditEdge *eed;
        int i;
 
@@ -470,9 +602,9 @@ static void emDM_foreachMappedEdge(DerivedMesh *dm, void (*func)(void *userData,
                        func(userData, i, eed->v1->co, eed->v2->co);
        }
 }
-static void emDM_drawMappedEdges(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index), void *userData) 
+static void emDM_drawMappedEdges(void *dm, int (*setDrawOptions)(void *userData, int index), void *userData) 
 {
-       EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
+       EditMeshDerivedMesh *emdm= dm;
        EditEdge *eed;
        int i;
 
@@ -501,13 +633,13 @@ static void emDM_drawMappedEdges(DerivedMesh *dm, int (*setDrawOptions)(void *us
                glEnd();
        }
 }
-static void emDM_drawEdges(DerivedMesh *dm, int drawLooseEdges)
+static void emDM_drawEdges(void *dm, int drawLooseEdges)
 {
        emDM_drawMappedEdges(dm, NULL, NULL);
 }
-static void emDM_drawMappedEdgesInterp(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index), void (*setDrawInterpOptions)(void *userData, int index, float t), void *userData) 
+static void emDM_drawMappedEdgesInterp(void *dm, int (*setDrawOptions)(void *userData, int index), void (*setDrawInterpOptions)(void *userData, int index, float t), void *userData) 
 {
-       EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
+       EditMeshDerivedMesh *emdm= dm;
        EditEdge *eed;
        int i;
 
@@ -541,9 +673,9 @@ static void emDM_drawMappedEdgesInterp(DerivedMesh *dm, int (*setDrawOptions)(vo
        }
 }
 
-static void emDM_drawUVEdges(DerivedMesh *dm)
+static void emDM_drawUVEdges(void *dm)
 {
-       EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
+       EditMeshDerivedMesh *emdm= dm;
        EditFace *efa;
        MTFace *tf;
 
@@ -592,9 +724,9 @@ static void emDM__calcFaceCent(EditFace *efa, float cent[3], float (*vertexCos)[
                VecMulf(cent, 0.33333333333f);
        }
 }
-static void emDM_foreachMappedFaceCenter(DerivedMesh *dm, void (*func)(void *userData, int index, float *co, float *no), void *userData)
+static void emDM_foreachMappedFaceCenter(void *dm, void (*func)(void *userData, int index, float *co, float *no), void *userData)
 {
-       EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
+       EditMeshDerivedMesh *emdm= dm;
        EditVert *eve;
        EditFace *efa;
        float cent[3];
@@ -610,9 +742,9 @@ static void emDM_foreachMappedFaceCenter(DerivedMesh *dm, void (*func)(void *use
                func(userData, i, cent, emdm->vertexCos?emdm->faceNos[i]:efa->n);
        }
 }
-static void emDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r), void *userData, int useColors)
+static void emDM_drawMappedFaces(void *dm, int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r), void *userData, int useColors)
 {
-       EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
+       EditMeshDerivedMesh *emdm= dm;
        EditFace *efa;
        int i, draw;
 
@@ -697,12 +829,12 @@ static void emDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *us
        }
 }
 
-static void emDM_drawFacesTex_common(DerivedMesh *dm,
+static void emDM_drawFacesTex_common(void *dm,
                int (*drawParams)(MTFace *tface, MCol *mcol, int matnr),
                int (*drawParamsMapped)(void *userData, int index),
                void *userData) 
 {
-       EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
+       EditMeshDerivedMesh *emdm= dm;
        EditMesh *em= emdm->em;
        float (*vertexCos)[3]= emdm->vertexCos;
        float (*vertexNos)[3]= emdm->vertexNos;
@@ -865,21 +997,21 @@ static void emDM_drawFacesTex_common(DerivedMesh *dm,
        }
 }
 
-static void emDM_drawFacesTex(DerivedMesh *dm, int (*setDrawOptions)(MTFace *tface, MCol *mcol, int matnr))
+static void emDM_drawFacesTex(void *dm, int (*setDrawOptions)(MTFace *tface, MCol *mcol, int matnr))
 {
        emDM_drawFacesTex_common(dm, setDrawOptions, NULL, NULL);
 }
 
-static void emDM_drawMappedFacesTex(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index), void *userData)
+static void emDM_drawMappedFacesTex(void *dm, int (*setDrawOptions)(void *userData, int index), void *userData)
 {
        emDM_drawFacesTex_common(dm, NULL, setDrawOptions, userData);
 }
 
-static void emDM_drawMappedFacesGLSL(DerivedMesh *dm,
+static void emDM_drawMappedFacesGLSL(void *dm,
                int (*setMaterial)(int, void *attribs),
                int (*setDrawOptions)(void *userData, int index), void *userData) 
 {
-       EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
+       EditMeshDerivedMesh *emdm= dm;
        EditMesh *em= emdm->em;
        float (*vertexCos)[3]= emdm->vertexCos;
        float (*vertexNos)[3]= emdm->vertexNos;
@@ -1025,15 +1157,15 @@ static void emDM_drawMappedFacesGLSL(DerivedMesh *dm,
        }
 }
 
-static void emDM_drawFacesGLSL(DerivedMesh *dm,
+static void emDM_drawFacesGLSL(void *dm,
                int (*setMaterial)(int, void *attribs))
 {
-       dm->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL);
+       ((DerivedMesh*)dm)->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL);
 }
 
-static void emDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3])
+static void emDM_getMinMax(void *dm, float min_r[3], float max_r[3])
 {
-       EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
+       EditMeshDerivedMesh *emdm= dm;
        EditVert *eve;
        int i;
 
@@ -1049,28 +1181,28 @@ static void emDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3])
                min_r[0] = min_r[1] = min_r[2] = max_r[0] = max_r[1] = max_r[2] = 0.0;
        }
 }
-static int emDM_getNumVerts(DerivedMesh *dm)
+static int emDM_getNumVerts(void *dm)
 {
-       EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
+       EditMeshDerivedMesh *emdm= dm;
 
        return BLI_countlist(&emdm->em->verts);
 }
 
-static int emDM_getNumEdges(DerivedMesh *dm)
+static int emDM_getNumEdges(void *dm)
 {
-       EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
+       EditMeshDerivedMesh *emdm= dm;
 
        return BLI_countlist(&emdm->em->edges);
 }
 
-static int emDM_getNumFaces(DerivedMesh *dm)
+static int emDM_getNumTessFaces(void *dm)
 {
-       EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
+       EditMeshDerivedMesh *emdm= dm;
 
        return BLI_countlist(&emdm->em->faces);
 }
 
-static void emDM_getVert(DerivedMesh *dm, int index, MVert *vert_r)
+static void emDM_getVert(void *dm, int index, MVert *vert_r)
 {
        EditVert *ev = ((EditMeshDerivedMesh *)dm)->em->verts.first;
        int i;
@@ -1088,7 +1220,7 @@ static void emDM_getVert(DerivedMesh *dm, int index, MVert *vert_r)
        vert_r->bweight = (unsigned char) (ev->bweight*255.0f);
 }
 
-static void emDM_getEdge(DerivedMesh *dm, int index, MEdge *edge_r)
+static void emDM_getEdge(void *dm, int index, MEdge *edge_r)
 {
        EditMesh *em = ((EditMeshDerivedMesh *)dm)->em;
        EditEdge *ee = em->edges.first;
@@ -1123,7 +1255,7 @@ static void emDM_getEdge(DerivedMesh *dm, int index, MEdge *edge_r)
        }
 }
 
-static void emDM_getFace(DerivedMesh *dm, int index, MFace *face_r)
+static void emDM_getFace(void *dm, int index, MFace *face_r)
 {
        EditMesh *em = ((EditMeshDerivedMesh *)dm)->em;
        EditFace *ef = em->faces.first;
@@ -1165,7 +1297,7 @@ static void emDM_getFace(DerivedMesh *dm, int index, MFace *face_r)
        test_index_face(face_r, NULL, 0, ef->v4?4:3);
 }
 
-static void emDM_copyVertArray(DerivedMesh *dm, MVert *vert_r)
+static void emDM_copyVertArray(void *dm, MVert *vert_r)
 {
        EditVert *ev = ((EditMeshDerivedMesh *)dm)->em->verts.first;
 
@@ -1183,7 +1315,7 @@ static void emDM_copyVertArray(DerivedMesh *dm, MVert *vert_r)
        }
 }
 
-static void emDM_copyEdgeArray(DerivedMesh *dm, MEdge *edge_r)
+static void emDM_copyEdgeArray(void *dm, MEdge *edge_r)
 {
        EditMesh *em = ((EditMeshDerivedMesh *)dm)->em;
        EditEdge *ee = em->edges.first;
@@ -1211,7 +1343,7 @@ static void emDM_copyEdgeArray(DerivedMesh *dm, MEdge *edge_r)
        }
 }
 
-static void emDM_copyFaceArray(DerivedMesh *dm, MFace *face_r)
+static void emDM_copyFaceArray(void *dm, MFace *face_r)
 {
        EditMesh *em = ((EditMeshDerivedMesh *)dm)->em;
        EditFace *ef = em->faces.first;
@@ -1236,9 +1368,9 @@ static void emDM_copyFaceArray(DerivedMesh *dm, MFace *face_r)
        }
 }
 
-static void *emDM_getFaceDataArray(DerivedMesh *dm, int type)
+static void *emDM_getFaceDataArray(void *dm, int type)
 {
-       EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
+       EditMeshDerivedMesh *emdm= dm;
        EditMesh *em= emdm->em;
        EditFace *efa;
        char *data, *emdata;
@@ -1259,8 +1391,8 @@ static void *emDM_getFaceDataArray(DerivedMesh *dm, int type)
                        size = CustomData_sizeof(type);
 
                        DM_add_face_layer(dm, type, CD_CALLOC, NULL);
-                       index = CustomData_get_layer_index(&dm->faceData, type);
-                       dm->faceData.layers[index].flag |= CD_FLAG_TEMPORARY;
+                       index = CustomData_get_layer_index(&emdm->dm.faceData, type);
+                       emdm->dm.faceData.layers[index].flag |= CD_FLAG_TEMPORARY;
 
                        data = datalayer = DM_get_face_data_layer(dm, type);
                        for(efa=em->faces.first; efa; efa=efa->next, data+=size) {
@@ -1273,9 +1405,9 @@ static void *emDM_getFaceDataArray(DerivedMesh *dm, int type)
        return datalayer;
 }
 
-static void emDM_release(DerivedMesh *dm)
+static void emDM_release(void *dm)
 {
-       EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
+       EditMeshDerivedMesh *emdm= dm;
 
        if (DM_release(dm)) {
                if (emdm->vertexCos) {
@@ -1294,21 +1426,22 @@ static DerivedMesh *getEditMeshDerivedMesh(EditMesh *em, Object *ob,
        EditMeshDerivedMesh *emdm = MEM_callocN(sizeof(*emdm), "emdm");
 
        DM_init(&emdm->dm, BLI_countlist(&em->verts),
-                        BLI_countlist(&em->edges), BLI_countlist(&em->faces));
+                        BLI_countlist(&em->edges), BLI_countlist(&em->faces),
+                        0, 0);
 
        emdm->dm.getMinMax = emDM_getMinMax;
 
        emdm->dm.getNumVerts = emDM_getNumVerts;
        emdm->dm.getNumEdges = emDM_getNumEdges;
-       emdm->dm.getNumFaces = emDM_getNumFaces;
+       emdm->dm.getNumTessFaces = emDM_getNumTessFaces;
 
        emdm->dm.getVert = emDM_getVert;
        emdm->dm.getEdge = emDM_getEdge;
-       emdm->dm.getFace = emDM_getFace;
+       emdm->dm.getTessFace = emDM_getFace;
        emdm->dm.copyVertArray = emDM_copyVertArray;
        emdm->dm.copyEdgeArray = emDM_copyEdgeArray;
-       emdm->dm.copyFaceArray = emDM_copyFaceArray;
-       emdm->dm.getFaceDataArray = emDM_getFaceDataArray;
+       emdm->dm.copyTessFaceArray = emDM_copyFaceArray;
+       emdm->dm.getTessFaceDataArray = emDM_getFaceDataArray;
 
        emdm->dm.foreachMappedVert = emDM_foreachMappedVert;
        emdm->dm.foreachMappedEdge = emDM_foreachMappedEdge;
@@ -2377,11 +2510,11 @@ void DM_add_tangent_layer(DerivedMesh *dm)
 
        /* check we have all the needed layers */
        totvert= dm->getNumVerts(dm);
-       totface= dm->getNumFaces(dm);
+       totface= dm->getNumTessFaces(dm);
 
        mvert= dm->getVertArray(dm);
-       mface= dm->getFaceArray(dm);
-       mtface= dm->getFaceDataArray(dm, CD_MTFACE);
+       mface= dm->getTessFaceArray(dm);
+       mtface= dm->getTessFaceDataArray(dm, CD_MTFACE);
 
        if(!mtface) {
                orco= dm->getVertDataArray(dm, CD_ORCO);
index b2cbd82cfc2c74123075e4acefe39838afc25852..7451e40cac72af72b0549a92f78b538f19629b09 100644 (file)
@@ -579,9 +579,9 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
                int totvert;
                dm= editbmesh_get_derived_cage(scene, par, em, CD_MASK_BAREMESH);
                
-               totface= dm->getNumFaces(dm);
+               totface= dm->getNumTessFaces(dm);
                mface= MEM_mallocN(sizeof(MFace)*totface, "mface temp");
-               dm->copyFaceArray(dm, mface);
+               dm->copyTessFaceArray(dm, mface);
                totvert= dm->getNumVerts(dm);
                mvert= MEM_mallocN(sizeof(MVert)*totvert, "mvert temp");
                dm->copyVertArray(dm, mvert);
@@ -589,8 +589,8 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
        else {
                dm = mesh_get_derived_deform(scene, par, CD_MASK_BAREMESH);
                
-               totface= dm->getNumFaces(dm);
-               mface= dm->getFaceArray(dm);
+               totface= dm->getNumTessFaces(dm);
+               mface= dm->getTessFaceArray(dm);
                mvert= dm->getVertArray(dm);
        }
 
index 27b78c6644c5c4ccda131c63207b3622b63ff4e8..ef3a99f5fd826677b150be88b1f0c03bf2b25a1e 100644 (file)
@@ -177,14 +177,14 @@ static int FaceIt_Done(CSG_IteratorPtr it)
 {
        // assume CSG_IteratorPtr is of the correct type.
        FaceIt * iterator = (FaceIt *)it;
-       return(iterator->pos >= iterator->dm->getNumFaces(iterator->dm));
+       return(iterator->pos >= iterator->dm->getNumTessFaces(iterator->dm));
 }
 
 static void FaceIt_Fill(CSG_IteratorPtr it, CSG_IFace *face)
 {
        // assume CSG_IteratorPtr is of the correct type.
        FaceIt *face_it = (FaceIt *)it;
-       MFace *mfaces = face_it->dm->getFaceArray(face_it->dm);
+       MFace *mfaces = face_it->dm->getTessFaceArray(face_it->dm);
        MFace *mface = &mfaces[face_it->pos];
 
        face->vertex_index[0] = mface->v1;
@@ -233,7 +233,7 @@ static void FaceIt_Construct(
        output->Fill = FaceIt_Fill;
        output->Done = FaceIt_Done;
        output->Reset = FaceIt_Reset;
-       output->num_elements = it->dm->getNumFaces(it->dm);
+       output->num_elements = it->dm->getNumTessFaces(it->dm);
        output->it = it;
 }
 
@@ -283,8 +283,8 @@ static void InterpCSGFace(
        MFace *mface, *orig_mface;
        int j;
 
-       mface = CDDM_get_face(dm, index);
-       orig_mface = orig_dm->getFaceArray(orig_dm) + orig_index;
+       mface = CDDM_get_tessface(dm, index);
+       orig_mface = orig_dm->getTessFaceArray(orig_dm) + orig_index;
 
        // get the vertex coordinates from the original mesh
        orig_co[0] = (orig_dm->getVertArray(orig_dm) + orig_mface->v1)->co;
@@ -332,7 +332,7 @@ static DerivedMesh *ConvertCSGDescriptorsToDerivedMesh(
        int i;
 
        // create a new DerivedMesh
-       result = CDDM_new(vertex_it->num_elements, 0, face_it->num_elements);
+       result = CDDM_new(vertex_it->num_elements, 0, face_it->num_elements, 0, 0);
        CustomData_merge(&dm1->faceData, &result->faceData, CD_MASK_DERIVEDMESH,
                          CD_DEFAULT, face_it->num_elements); 
        CustomData_merge(&dm2->faceData, &result->faceData, CD_MASK_DERIVEDMESH,
@@ -372,16 +372,16 @@ static DerivedMesh *ConvertCSGDescriptorsToDerivedMesh(
                face_it->Step(face_it->it);
 
                // find the original mesh and data
-               orig_ob = (csgface.orig_face < dm1->getNumFaces(dm1))? ob1: ob2;
-               orig_dm = (csgface.orig_face < dm1->getNumFaces(dm1))? dm1: dm2;
+               orig_ob = (csgface.orig_face < dm1->getNumTessFaces(dm1))? ob1: ob2;
+               orig_dm = (csgface.orig_face < dm1->getNumTessFaces(dm1))? dm1: dm2;
                orig_me = (orig_ob == ob1)? me1: me2;
-               orig_index = (orig_ob == ob1)? csgface.orig_face: csgface.orig_face - dm1->getNumFaces(dm1);
+               orig_index = (orig_ob == ob1)? csgface.orig_face: csgface.orig_face - dm1->getNumTessFaces(dm1);
 
                // copy all face layers, including mface
                CustomData_copy_data(&orig_dm->faceData, &result->faceData, orig_index, i, 1);
 
                // set mface
-               mface = CDDM_get_face(result, i);
+               mface = CDDM_get_tessface(result, i);
                mface->v1 = csgface.vertex_index[0];
                mface->v2 = csgface.vertex_index[1];
                mface->v3 = csgface.vertex_index[2];
@@ -414,6 +414,8 @@ static DerivedMesh *ConvertCSGDescriptorsToDerivedMesh(
        CDDM_calc_edges(result);
        CDDM_calc_normals(result);
 
+       CDDM_tessfaces_to_faces(result);
+
        return result;
 }
        
@@ -447,7 +449,7 @@ DerivedMesh *NewBooleanDerivedMesh_intern(
        DerivedMesh *result = NULL;
 
        if (dm == NULL || dm_select == NULL) return 0;
-       if (!dm->getNumFaces(dm) || !dm_select->getNumFaces(dm_select)) return 0;
+       if (!dm->getNumTessFaces(dm) || !dm_select->getNumTessFaces(dm_select)) return 0;
 
        // we map the final object back into ob's local coordinate space. For this
        // we need to compute the inverse transform from global to ob (inv_mat),
@@ -479,7 +481,7 @@ DerivedMesh *NewBooleanDerivedMesh_intern(
                }
                
                BuildMeshDescriptors(dm_select, ob_select, 0, &fd_1, &vd_1);
-               BuildMeshDescriptors(dm, ob, dm_select->getNumFaces(dm_select) , &fd_2, &vd_2);
+               BuildMeshDescriptors(dm, ob, dm_select->getNumTessFaces(dm_select) , &fd_2, &vd_2);
 
                bool_op = CSG_NewBooleanFunction();
 
@@ -533,7 +535,7 @@ int NewBooleanMesh(Scene *scene, Base *base, Base *base_select, int int_op_type)
        
        /* put some checks in for nice user feedback */
        if (dm == NULL || dm_select == NULL) return 0;
-       if (!dm->getNumFaces(dm) || !dm_select->getNumFaces(dm_select))
+       if (!dm->getNumTessFaces(dm) || !dm_select->getNumTessFaces(dm_select))
        {
                MEM_freeN(mat);
                return -1;
index d9e005811d0078e16ca68d75d86331c87566dbf3..08bcd9c2820a175675baf720dcb54aa1f3085915 100644 (file)
@@ -532,7 +532,7 @@ BVHTree* bvhtree_from_mesh_verts(BVHTreeFromMesh *data, DerivedMesh *mesh, float
 
                data->mesh = mesh;
                data->vert = mesh->getVertDataArray(mesh, CD_MVERT);
-               data->face = mesh->getFaceDataArray(mesh, CD_MFACE);
+               data->face = mesh->getTessFaceDataArray(mesh, CD_MFACE);
 
                data->sphere_radius = epsilon;
        }
@@ -549,9 +549,9 @@ BVHTree* bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *mesh, float
        if(tree == NULL)
        {
                int i;
-               int numFaces= mesh->getNumFaces(mesh);
+               int numFaces= mesh->getNumTessFaces(mesh);
                MVert *vert     = mesh->getVertDataArray(mesh, CD_MVERT);
-               MFace *face = mesh->getFaceDataArray(mesh, CD_MFACE);
+               MFace *face = mesh->getTessFaceDataArray(mesh, CD_MFACE);
 
                if(vert != NULL && face != NULL)
                {
@@ -597,7 +597,7 @@ BVHTree* bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *mesh, float
 
                data->mesh = mesh;
                data->vert = mesh->getVertDataArray(mesh, CD_MVERT);
-               data->face = mesh->getFaceDataArray(mesh, CD_MFACE);
+               data->face = mesh->getTessFaceDataArray(mesh, CD_MFACE);
 
                data->sphere_radius = epsilon;
        }
index ecdf0e78df230ae68b919fb0f8f88d2e3cf7ad05..4f6f3a5f93d3cf4c5eaac17c638e830195697f49 100644 (file)
@@ -77,8 +77,12 @@ typedef struct {
        MVert *mvert;
        MEdge *medge;
        MFace *mface;
+       MLoop *mloop;
+       MPoly *mpoly;
 } CDDerivedMesh;
 
+DMFaceIter *cdDM_newFaceIter(DerivedMesh *source);
+
 /**************** DerivedMesh interface functions ****************/
 static int cdDM_getNumVerts(DerivedMesh *dm)
 {
@@ -90,11 +94,16 @@ static int cdDM_getNumEdges(DerivedMesh *dm)
        return dm->numEdgeData;
 }
 
-static int cdDM_getNumFaces(DerivedMesh *dm)
+static int cdDM_getNumTessFaces(DerivedMesh *dm)
 {
        return dm->numFaceData;
 }
 
+static int cdDM_getNumFaces(DerivedMesh *dm)
+{
+       return dm->numPolyData;
+}
+
 static void cdDM_getVert(DerivedMesh *dm, int index, MVert *vert_r)
 {
        CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
@@ -256,7 +265,7 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm, int (*setMaterial)(int, void *a
        CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
        MVert *mvert = cddm->mvert;
        MFace *mface = cddm->mface;
-       float *nors= dm->getFaceDataArray(dm, CD_NORMAL);
+       float *nors= dm->getTessFaceDataArray(dm, CD_NORMAL);
        int a, glmode = -1, shademodel = -1, matnr = -1, drawCurrentMat = 1;
 
 #define PASSVERT(index) {                                              \
@@ -392,8 +401,8 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
        CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
        MVert *mv = cddm->mvert;
        MFace *mf = cddm->mface;
-       MCol *mcol = dm->getFaceDataArray(dm, CD_MCOL);
-       float *nors= dm->getFaceDataArray(dm, CD_NORMAL);
+       MCol *mcol = dm->getTessFaceDataArray(dm, CD_MCOL);
+       float *nors= dm->getTessFaceDataArray(dm, CD_NORMAL);
        MTFace *tf = DM_get_face_data_layer(dm, CD_MTFACE);
        int i, orig, *index = DM_get_face_data_layer(dm, CD_ORIGINDEX);
 
@@ -484,7 +493,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *us
        MVert *mv = cddm->mvert;
        MFace *mf = cddm->mface;
        MCol *mc;
-       float *nors= dm->getFaceDataArray(dm, CD_NORMAL);
+       float *nors= dm->getTessFaceDataArray(dm, CD_NORMAL);
        int i, orig, *index = DM_get_face_data_layer(dm, CD_ORIGINDEX);
 
        mc = DM_get_face_data_layer(dm, CD_WEIGHT_MCOL);
@@ -575,11 +584,11 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo
        DMVertexAttribs attribs;
        MVert *mvert = cddm->mvert;
        MFace *mface = cddm->mface;
-       MTFace *tf = dm->getFaceDataArray(dm, CD_MTFACE);
-       float (*nors)[3] = dm->getFaceDataArray(dm, CD_NORMAL);
+       MTFace *tf = dm->getTessFaceDataArray(dm, CD_MTFACE);
+       float (*nors)[3] = dm->getTessFaceDataArray(dm, CD_NORMAL);
        int a, b, dodraw, smoothnormal, matnr, new_matnr;
        int transp, new_transp, orig_transp;
-       int orig, *index = dm->getFaceDataArray(dm, CD_ORIGINDEX);
+       int orig, *index = dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
 
        matnr = -1;
        smoothnormal = 0;
@@ -770,10 +779,11 @@ static void cdDM_foreachMappedFaceCenter(
 {
        CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
        MVert *mv = cddm->mvert;
-       MFace *mf = cddm->mface;
-       int i, orig, *index = DM_get_face_data_layer(dm, CD_ORIGINDEX);
+       MPoly *mf = cddm->mpoly;
+       MLoop *ml = cddm->mloop;
+       int i, j, orig, *index = DM_get_face_data_layer(dm, CD_ORIGINDEX);
 
-       for(i = 0; i < dm->numFaceData; i++, mf++) {
+       for(i = 0; i < dm->numPolyData; i++, mf++) {
                float cent[3];
                float no[3];
 
@@ -783,20 +793,21 @@ static void cdDM_foreachMappedFaceCenter(
                }
                else
                        orig = i;
+               
+               ml = &cddm->mloop[mf->loopstart];
+               cent[0] = cent[1] = cent[2] = 0.0f;
+               for (j=0; j<mf->totloop; j++, ml++) {
+                       VecAddf(cent, cent, mv[ml->v].co);
+               }
+               VecMulf(cent, 1.0f / (float)j);
 
-               VECCOPY(cent, mv[mf->v1].co);
-               VecAddf(cent, cent, mv[mf->v2].co);
-               VecAddf(cent, cent, mv[mf->v3].co);
-
-               if (mf->v4) {
-                       CalcNormFloat4(mv[mf->v1].co, mv[mf->v2].co,
-                                      mv[mf->v3].co, mv[mf->v4].co, no);
-                       VecAddf(cent, cent, mv[mf->v4].co);
-                       VecMulf(cent, 0.25f);
+               ml = &cddm->mloop[mf->loopstart];
+               if (j > 3) {
+                       CalcNormFloat4(mv[ml->v].co, mv[(ml+1)->v].co,
+                                      mv[(ml+2)->v].co, mv[(ml+3)->v].co, no);
                } else {
-                       CalcNormFloat(mv[mf->v1].co, mv[mf->v2].co,
-                                     mv[mf->v3].co, no);
-                       VecMulf(cent, 0.33333333333f);
+                       CalcNormFloat(mv[ml->v].co, mv[(ml+1)->v].co,
+                                      mv[(ml+2)->v].co, no);
                }
 
                func(userData, orig, cent, no);
@@ -823,21 +834,24 @@ static CDDerivedMesh *cdDM_create(const char *desc)
        dm->getMinMax = cdDM_getMinMax;
 
        dm->getNumVerts = cdDM_getNumVerts;
-       dm->getNumFaces = cdDM_getNumFaces;
        dm->getNumEdges = cdDM_getNumEdges;
+       dm->getNumTessFaces = cdDM_getNumTessFaces;
+       dm->getNumFaces = cdDM_getNumFaces;
+
+       dm->newFaceIter = cdDM_newFaceIter;
 
        dm->getVert = cdDM_getVert;
        dm->getEdge = cdDM_getEdge;
-       dm->getFace = cdDM_getFace;
+       dm->getTessFace = cdDM_getFace;
        dm->copyVertArray = cdDM_copyVertArray;
        dm->copyEdgeArray = cdDM_copyEdgeArray;
-       dm->copyFaceArray = cdDM_copyFaceArray;
+       dm->copyTessFaceArray = cdDM_copyFaceArray;
        dm->getVertData = DM_get_vert_data;
        dm->getEdgeData = DM_get_edge_data;
-       dm->getFaceData = DM_get_face_data;
+       dm->getTessFaceData = DM_get_face_data;
        dm->getVertDataArray = DM_get_vert_data_layer;
        dm->getEdgeDataArray = DM_get_edge_data_layer;
-       dm->getFaceDataArray = DM_get_face_data_layer;
+       dm->getTessFaceDataArray = DM_get_face_data_layer;
 
        dm->getVertCos = cdDM_getVertCos;
        dm->getVertCo = cdDM_getVertCo;
@@ -867,24 +881,29 @@ static CDDerivedMesh *cdDM_create(const char *desc)
        return cddm;
 }
 
-DerivedMesh *CDDM_new(int numVerts, int numEdges, int numFaces)
+DerivedMesh *CDDM_new(int numVerts, int numEdges, int numFaces, int numLoops, int numPolys)
 {
        CDDerivedMesh *cddm = cdDM_create("CDDM_new dm");
        DerivedMesh *dm = &cddm->dm;
 
-       DM_init(dm, numVerts, numEdges, numFaces);
+       DM_init(dm, numVerts, numEdges, numFaces, numLoops, numPolys);
 
        CustomData_add_layer(&dm->vertData, CD_ORIGINDEX, CD_CALLOC, NULL, numVerts);
        CustomData_add_layer(&dm->edgeData, CD_ORIGINDEX, CD_CALLOC, NULL, numEdges);
        CustomData_add_layer(&dm->faceData, CD_ORIGINDEX, CD_CALLOC, NULL, numFaces);
+       CustomData_add_layer(&dm->polyData, CD_ORIGINDEX, CD_CALLOC, NULL, numPolys);
 
        CustomData_add_layer(&dm->vertData, CD_MVERT, CD_CALLOC, NULL, numVerts);
        CustomData_add_layer(&dm->edgeData, CD_MEDGE, CD_CALLOC, NULL, numEdges);
        CustomData_add_layer(&dm->faceData, CD_MFACE, CD_CALLOC, NULL, numFaces);
+       CustomData_add_layer(&dm->loopData, CD_MLOOP, CD_CALLOC, NULL, numLoops);
+       CustomData_add_layer(&dm->polyData, CD_MPOLY, CD_CALLOC, NULL, numPolys);
 
        cddm->mvert = CustomData_get_layer(&dm->vertData, CD_MVERT);
        cddm->medge = CustomData_get_layer(&dm->edgeData, CD_MEDGE);
        cddm->mface = CustomData_get_layer(&dm->faceData, CD_MFACE);
+       cddm->mloop = CustomData_get_layer(&dm->loopData, CD_MLOOP);
+       cddm->mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY);
 
        return dm;
 }
@@ -899,11 +918,13 @@ DerivedMesh *CDDM_from_mesh(Mesh *mesh, Object *ob)
        /* this does a referenced copy, the only new layers being ORIGINDEX,
         * with an exception for fluidsim */
 
-       DM_init(dm, mesh->totvert, mesh->totedge, mesh->totface);
+       DM_init(dm, mesh->totvert, mesh->totedge, mesh->totface,
+                   mesh->totloop, mesh->totpoly);
 
        CustomData_add_layer(&dm->vertData, CD_ORIGINDEX, CD_CALLOC, NULL, mesh->totvert);
        CustomData_add_layer(&dm->edgeData, CD_ORIGINDEX, CD_CALLOC, NULL, mesh->totedge);
        CustomData_add_layer(&dm->faceData, CD_ORIGINDEX, CD_CALLOC, NULL, mesh->totface);
+       CustomData_add_layer(&dm->polyData, CD_ORIGINDEX, CD_CALLOC, NULL, mesh->totpoly);
 
        dm->deformedOnly = 1;
 
@@ -915,10 +936,16 @@ DerivedMesh *CDDM_from_mesh(Mesh *mesh, Object *ob)
                         mesh->totedge);
        CustomData_merge(&mesh->fdata, &dm->faceData, mask, alloctype,
                         mesh->totface);
+       CustomData_merge(&mesh->ldata, &dm->loopData, mask, alloctype,
+                        mesh->totloop);
+       CustomData_merge(&mesh->pdata, &dm->polyData, mask, alloctype,
+                        mesh->totpoly);
 
        cddm->mvert = CustomData_get_layer(&dm->vertData, CD_MVERT);
        cddm->medge = CustomData_get_layer(&dm->edgeData, CD_MEDGE);
        cddm->mface = CustomData_get_layer(&dm->faceData, CD_MFACE);
+       cddm->mloop = CustomData_get_layer(&dm->loopData, CD_MLOOP);
+       cddm->mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY);
 
        index = CustomData_get_layer(&dm->vertData, CD_ORIGINDEX);
        for(i = 0; i < mesh->totvert; ++i, ++index)
@@ -932,6 +959,10 @@ DerivedMesh *CDDM_from_mesh(Mesh *mesh, Object *ob)
        for(i = 0; i < mesh->totface; ++i, ++index)
                *index = i;
 
+       index = CustomData_get_layer(&dm->polyData, CD_ORIGINDEX);
+       for(i = 0; i < mesh->totpoly; ++i, ++index)
+               *index = i;
+
        return dm;
 }
 
@@ -939,7 +970,7 @@ DerivedMesh *CDDM_from_editmesh(EditMesh *em, Mesh *me)
 {
        DerivedMesh *dm = CDDM_new(BLI_countlist(&em->verts),
                                   BLI_countlist(&em->edges),
-                                  BLI_countlist(&em->faces));
+                                  BLI_countlist(&em->faces), 0, 0);
        CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
        EditVert *eve;
        EditEdge *eed;
@@ -957,6 +988,8 @@ DerivedMesh *CDDM_from_editmesh(EditMesh *em, Mesh *me)
                         CD_CALLOC, dm->numEdgeData); */
        CustomData_merge(&em->fdata, &dm->faceData, CD_MASK_DERIVEDMESH,
                         CD_CALLOC, dm->numFaceData);
+       CustomData_merge(&em->fdata, &dm->faceData, CD_MASK_DERIVEDMESH,
+                        CD_CALLOC, dm->numFaceData);
 
        /* set eve->hash to vert index */
        for(i = 0, eve = em->verts.first; eve; eve = eve->next, ++i)
@@ -1013,7 +1046,7 @@ DerivedMesh *CDDM_from_editmesh(EditMesh *em, Mesh *me)
                /* CustomData_from_em_block(&em->edata, &dm->edgeData, eed->data, i); */
        }
 
-       index = dm->getFaceDataArray(dm, CD_ORIGINDEX);
+       index = dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
        for(i = 0, efa = em->faces.first; i < dm->numFaceData;
            i++, efa = efa->next, index++) {
                MFace *mf = &mface[i];
@@ -1083,19 +1116,22 @@ static void loops_to_customdata_corners(BMesh *bm, CustomData *facedata,
 
 DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *me)
 {
-       DerivedMesh *dm = CDDM_new(em->bm->totvert, em->bm->totedge, em->tottri);
+       DerivedMesh *dm = CDDM_new(em->bm->totvert, em->bm->totedge, 
+                              em->tottri, em->bm->totloop, em->bm->totface);
        CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
        BMesh *bm = em->bm;
-       BMIter iter;
+       BMIter iter, liter;
        BMVert *eve;
        BMEdge *eed;
        BMFace *efa;
        MVert *mvert = cddm->mvert;
        MEdge *medge = cddm->medge;
        MFace *mface = cddm->mface;
+       MLoop *mloop = cddm->mloop;
+       MPoly *mpoly = cddm->mpoly;
        int numCol = CustomData_number_of_layers(&em->bm->ldata, CD_MLOOPCOL);
        int numTex = CustomData_number_of_layers(&em->bm->pdata, CD_MTEXPOLY);
-       int i, *index;
+       int i, j, *index;
 
        dm->deformedOnly = 1;
 
@@ -1105,8 +1141,12 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *me)
                         CD_CALLOC, dm->numEdgeData); */
        CustomData_merge(&em->bm->pdata, &dm->faceData, CD_MASK_DERIVEDMESH,
                         CD_CALLOC, dm->numFaceData);
+       CustomData_merge(&em->bm->ldata, &dm->loopData, CD_MASK_DERIVEDMESH,
+                        CD_CALLOC, dm->numLoopData);
+       CustomData_merge(&em->bm->pdata, &dm->polyData, CD_MASK_DERIVEDMESH,
+                        CD_CALLOC, dm->numPolyData);
        
-       /*add mface and mcol layers as necassary*/
+       /*add tesselation mface and mcol layers as necassary*/
        for (i=0; i<numTex; i++) {
                CustomData_add_layer(&dm->faceData, CD_MTFACE, CD_CALLOC, NULL, em->tottri);
        }
@@ -1134,7 +1174,7 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *me)
                mv->bweight = (unsigned char) (eve->bweight * 255.0f);
 
                mv->mat_nr = 0;
-               mv->flag = 0;
+               mv->flag = BMFlags_To_MEFlags(eve);
 
                *index = i;
 
@@ -1152,16 +1192,19 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *me)
                med->bweight = (unsigned char) (eed->bweight * 255.0f);
                med->flag = ME_EDGEDRAW|ME_EDGERENDER;
                
-               if(BM_TestHFlag(eed, BM_SEAM)) med->flag |= ME_SEAM;
-               if(BM_TestHFlag(eed, BM_SHARP)) med->flag |= ME_SHARP;
-               if (BM_Wire_Edge(bm, eed)) med->flag |= ME_LOOSEEDGE;
+               med->flag = BMFlags_To_MEFlags(eed);
 
                *index = i;
 
                /* CustomData_from_em_block(&em->edata, &dm->edgeData, eed->data, i); */
        }
 
-       index = dm->getFaceDataArray(dm, CD_ORIGINDEX);
+       efa = BMIter_New(&iter, bm, BM_FACES_OF_MESH, NULL);
+       for (i=0; efa; i++, efa=BMIter_Step(&iter)) {
+               BMINDEX_SET(efa, i);
+       }
+
+       index = dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
        for(i = 0; i < dm->numFaceData; i++, index++) {
                MFace *mf = &mface[i];
                BMLoop **l = em->looptris[i];
@@ -1172,21 +1215,168 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *me)
                mf->v3 = BMINDEX_GET(l[2]->v);
                mf->v4 = 0;
                mf->mat_nr = efa->mat_nr;
+               mf->flag = BMFlags_To_MEFlags(efa);
 
-               if (BM_TestHFlag(efa, BM_SELECT)) mf->flag |= ME_FACE_SEL;
-               if (BM_TestHFlag(efa, BM_HIDDEN)) mf->flag |= ME_HIDE;
-               if (BM_TestHFlag(efa, BM_SMOOTH)) mf->flag |= ME_SMOOTH;
-
-               *index = i;
+               *index = BMINDEX_GET(efa);
 
                loops_to_customdata_corners(bm, &dm->faceData, i, l, numCol, numTex);
 
                test_index_face(mf, &dm->faceData, i, 3);
        }
+       
+       index = CustomData_get(&dm->polyData, 0, CD_ORIGINDEX);
+       j = 0;
+       efa = BMIter_New(&iter, bm, BM_FACES_OF_MESH, NULL);
+       for (i=0; efa; i++, efa=BMIter_Step(&iter)) {
+               BMLoop *l;
+               MPoly *mp = &mpoly[i];
+
+               mp->totloop = efa->len;
+               mp->flag = BMFlags_To_MEFlags(efa);
+               mp->loopstart = j;
+               mp->mat_nr = efa->mat_nr;
+               
+               BM_ITER(l, &liter, bm, BM_LOOPS_OF_FACE, efa) {
+                       mloop->v = BMINDEX_GET(l->v);
+                       mloop->e = BMINDEX_GET(l->e);
+                       CustomData_from_bmesh_block(&bm->ldata, &dm->loopData, l->data, j);
+
+                       j++;
+                       mloop++;
+               }
+
+               *(index++) = i;
+       }
 
        return dm;
 }
 
+typedef struct CDDM_LoopIter {
+       DMLoopIter head;
+       CDDerivedMesh *cddm;
+       int len, i;
+} CDDM_LoopIter;
+
+typedef struct CDDM_FaceIter {
+       DMFaceIter head;
+       CDDerivedMesh *cddm;
+       CDDM_LoopIter liter;
+} CDDM_FaceIter;
+
+void cddm_freeiter(void *self)
+{
+       MEM_freeN(self);
+}
+
+void cddm_stepiter(void *self)
+{
+       CDDM_FaceIter *iter = self;
+       MPoly *mp;
+       
+       iter->head.index++;
+       if (iter->head.index >= iter->cddm->dm.numPolyData) {
+               iter->head.done = 1;
+               return;
+       }
+
+       mp = iter->cddm->mpoly + iter->head.index;
+
+       iter->head.flags = mp->flag;
+       iter->head.mat_nr = mp->mat_nr;
+       iter->head.len = mp->totloop;
+}
+
+void *cddm_faceiter_getcddata(void *self, int type, int layer)
+{
+       CDDM_FaceIter *iter = self;
+
+       if (layer == -1) return CustomData_get(&iter->cddm->dm.polyData, 
+                                              iter->head.index, type);
+       else return CustomData_get_n(&iter->cddm->dm.polyData, type, 
+                                   iter->head.index, layer);
+}
+
+void *cddm_loopiter_getcddata(void *self, int type, int layer)
+{
+       CDDM_FaceIter *iter = self;
+
+       if (layer == -1) return CustomData_get(&iter->cddm->dm.loopData, 
+                                              iter->head.index, type);
+       else return CustomData_get_n(&iter->cddm->dm.loopData, type, 
+                                    iter->head.index, layer);
+}
+
+void *cddm_loopiter_getvertcddata(void *self, int type, int layer)
+{
+       CDDM_FaceIter *iter = self;
+
+       if (layer == -1) return CustomData_get(&iter->cddm->dm.vertData, 
+                                              iter->cddm->mloop[iter->head.index].v,
+                                              type);
+       else return CustomData_get_n(&iter->cddm->dm.vertData, type, 
+                                    iter->cddm->mloop[iter->head.index].v, layer);
+}
+
+DMLoopIter *cddmiter_get_loopiter(void *self)
+{
+       CDDM_FaceIter *iter = self;
+       CDDM_LoopIter *liter = &iter->liter;
+       MPoly *mp = iter->cddm->mpoly + iter->head.index;
+
+       liter->i = -1;
+       liter->len = iter->head.len;
+       liter->head.index = mp->loopstart-1;
+       liter->head.done = 0;
+
+       liter->head.step(liter);
+
+       return (DMLoopIter*) liter;
+}
+
+void cddm_loopiter_step(void *self)
+{
+       CDDM_LoopIter *liter = self;
+       MLoop *ml;
+
+       liter->i++;
+       liter->head.index++;
+
+       if (liter->i == liter->len) {
+               liter->head.done = 1;
+               return;
+       }
+
+       ml = liter->cddm->mloop + liter->head.index;
+
+       liter->head.eindex = ml->e;
+       liter->head.v = liter->cddm->mvert[ml->v];
+       liter->head.vindex = ml->v;
+
+       return;
+}
+
+DMFaceIter *cdDM_newFaceIter(DerivedMesh *source)
+{
+       CDDerivedMesh *cddm = (CDDerivedMesh*) source;
+       CDDM_FaceIter *iter = MEM_callocN(sizeof(CDDM_FaceIter), "DMFaceIter from cddm");
+
+       iter->head.free = cddm_freeiter;
+       iter->head.step = cddm_stepiter;
+       iter->head.getCDData = cddm_faceiter_getcddata;
+       iter->head.getLoopsIter = cddmiter_get_loopiter;
+
+       iter->liter.head.step = cddm_loopiter_step;
+       iter->liter.head.getLoopCDData = cddm_loopiter_getcddata;
+       iter->liter.head.getVertCDData = cddm_loopiter_getvertcddata;
+       iter->liter.cddm = cddm;
+
+       iter->cddm = cddm;
+       iter->head.index = -1;
+       iter->head.step(iter);
+
+       return (DMFaceIter*) iter;
+}
+
 DerivedMesh *CDDM_copy(DerivedMesh *source)
 {
        CDDerivedMesh *cddm = cdDM_create("CDDM_copy cddm");
@@ -1194,44 +1384,59 @@ DerivedMesh *CDDM_copy(DerivedMesh *source)
        int numVerts = source->numVertData;
        int numEdges = source->numEdgeData;
        int numFaces = source->numFaceData;
+       int numLoops = source->numLoopData;
+       int numPolys = source->numPolyData;
 
        /* this initializes dm, and copies all non mvert/medge/mface layers */
-       DM_from_template(dm, source, numVerts, numEdges, numFaces);
+       DM_from_template(dm, source, numVerts, numEdges, numFaces,
+               numLoops, numPolys);
        dm->deformedOnly = source->deformedOnly;
 
        CustomData_copy_data(&source->vertData, &dm->vertData, 0, 0, numVerts);
        CustomData_copy_data(&source->edgeData, &dm->edgeData, 0, 0, numEdges);
        CustomData_copy_data(&source->faceData, &dm->faceData, 0, 0, numFaces);
+       CustomData_copy_data(&source->loopData, &dm->loopData, 0, 0, numLoops);
+       CustomData_copy_data(&source->polyData, &dm->polyData, 0, 0, numPolys);
 
        /* now add mvert/medge/mface layers */
        cddm->mvert = source->dupVertArray(source);
        cddm->medge = source->dupEdgeArray(source);
-       cddm->mface = source->dupFaceArray(source);
+       cddm->mface = source->dupTessFaceArray(source);
 
        CustomData_add_layer(&dm->vertData, CD_MVERT, CD_ASSIGN, cddm->mvert, numVerts);
        CustomData_add_layer(&dm->edgeData, CD_MEDGE, CD_ASSIGN, cddm->medge, numEdges);
        CustomData_add_layer(&dm->faceData, CD_MFACE, CD_ASSIGN, cddm->mface, numFaces);
+       
+       DM_DupPolys(source, dm);
+
+       cddm->mloop = CustomData_get_layer(&dm->loopData, CD_MLOOP);
+       cddm->mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY);
 
        return dm;
 }
 
 DerivedMesh *CDDM_from_template(DerivedMesh *source,
-                                int numVerts, int numEdges, int numFaces)
+                                int numVerts, int numEdges, int numFaces,
+                               int numLoops, int numPolys)
 {
        CDDerivedMesh *cddm = cdDM_create("CDDM_from_template dest");
        DerivedMesh *dm = &cddm->dm;
 
        /* this does a copy of all non mvert/medge/mface layers */
-       DM_from_template(dm, source, numVerts, numEdges, numFaces);
+       DM_from_template(dm, source, numVerts, numEdges, numFaces, numLoops, numPolys);
 
        /* now add mvert/medge/mface layers */
        CustomData_add_layer(&dm->vertData, CD_MVERT, CD_CALLOC, NULL, numVerts);
        CustomData_add_layer(&dm->edgeData, CD_MEDGE, CD_CALLOC, NULL, numEdges);
        CustomData_add_layer(&dm->faceData, CD_MFACE, CD_CALLOC, NULL, numFaces);
+       CustomData_add_layer(&dm->loopData, CD_MLOOP, CD_CALLOC, NULL, numLoops);
+       CustomData_add_layer(&dm->polyData, CD_MPOLY, CD_CALLOC, NULL, numPolys);
 
        cddm->mvert = CustomData_get_layer(&dm->vertData, CD_MVERT);
        cddm->medge = CustomData_get_layer(&dm->edgeData, CD_MEDGE);
        cddm->mface = CustomData_get_layer(&dm->faceData, CD_MFACE);
+       cddm->mloop = CustomData_get_layer(&dm->loopData, CD_MLOOP);
+       cddm->mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY);
 
        return dm;
 }
@@ -1292,7 +1497,7 @@ void CDDM_calc_normals(DerivedMesh *dm)
                                                 NULL, dm->numFaceData);
 
        /* calculate face normals and add to vertex normals */
-       mf = CDDM_get_faces(dm);
+       mf = CDDM_get_tessfaces(dm);
        for(i = 0; i < numFaces; i++, mf++) {
                float *f_no = face_nors[i];
 
@@ -1417,7 +1622,7 @@ MEdge *CDDM_get_edge(DerivedMesh *dm, int index)
        return &((CDDerivedMesh*)dm)->medge[index];
 }
 
-MFace *CDDM_get_face(DerivedMesh *dm, int index)
+MFace *CDDM_get_tessface(DerivedMesh *dm, int index)
 {
        return &((CDDerivedMesh*)dm)->mface[index];
 }
@@ -1432,11 +1637,74 @@ MEdge *CDDM_get_edges(DerivedMesh *dm)
        return ((CDDerivedMesh*)dm)->medge;
 }
 
-MFace *CDDM_get_faces(DerivedMesh *dm)
+MFace *CDDM_get_tessfaces(DerivedMesh *dm)
 {
        return ((CDDerivedMesh*)dm)->mface;
 }
 
+void CDDM_tessfaces_to_faces(DerivedMesh *dm)
+{
+       /*converts mfaces to mpolys/mloops*/
+       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       MFace *mf;
+       MEdge *me;
+       MLoop *ml;
+       MPoly *mp;
+       EdgeHash *eh = BLI_edgehash_new();
+       int i, l, totloop;
+       
+       me = cddm->medge;
+       for (i=0; i<cddm->dm.numEdgeData; i++, me++) {
+               BLI_edgehash_insert(eh, me->v1, me->v2, SET_INT_IN_POINTER(i));
+       }
+
+       mf = cddm->mface;
+       totloop = 0;
+       for (i=0; i<cddm->dm.numFaceData; i++, mf++) {
+               totloop += mf->v4 ? 4 : 3;
+       }
+
+       cddm->mloop = MEM_callocN(sizeof(MLoop)*totloop, "cddm->mloop in CDDM_tessfaces_to_faces");
+       cddm->dm.numLoopData = totloop;
+       cddm->mpoly = MEM_callocN(sizeof(MPoly)*cddm->dm.numFaceData, "cddm->mpoly in CDDM_tessfaces_to_faces");
+       cddm->dm.numPolyData = cddm->dm.numFaceData;
+       
+       CustomData_add_layer(&cddm->dm.loopData, CD_MLOOP, CD_ASSIGN, cddm->mloop, totloop);
+       CustomData_add_layer(&cddm->dm.polyData, CD_MPOLY, CD_ASSIGN, cddm->mpoly, cddm->dm.numPolyData);
+       
+       mf = cddm->mface;
+       mp = cddm->mpoly;
+       ml = cddm->mloop;
+       l = 0;
+       for (i=0; i<cddm->dm.numFaceData; i++, mf++) {
+               mp->flag = mf->flag;
+               mp->loopstart = l;
+               mp->mat_nr = mf->mat_nr;
+               mp->totloop = mf->v4 ? 4 : 3;
+               
+               ml->v = mf->v1;
+               ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v1, mf->v2));
+               ml++, l++;
+
+               ml->v = mf->v2;
+               ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v2, mf->v3));
+               ml++, l++;
+
+               ml->v = mf->v3;
+               ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v3, mf->v4?mf->v4:mf->v1));
+               ml++, l++;
+
+               if (mf->v4) {
+                       ml->v = mf->v4;
+                       ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v4, mf->v1));
+                       ml++, l++;
+               }
+
+       }
+
+       BLI_edgehash_free(eh, NULL);
+}
+
 /* Multires DerivedMesh, extends CDDM */
 typedef struct MultiresDM {
        CDDerivedMesh cddm;
@@ -1491,7 +1759,9 @@ static void MultiresDM_release(DerivedMesh *dm)
        }
 }
 
-DerivedMesh *MultiresDM_new(MultiresSubsurf *ms, DerivedMesh *orig, int numVerts, int numEdges, int numFaces)
+DerivedMesh *MultiresDM_new(MultiresSubsurf *ms, DerivedMesh *orig, 
+                           int numVerts, int numEdges, int numFaces,
+                           int numLoops, int numPolys)
 {
        MultiresDM *mrdm = MEM_callocN(sizeof(MultiresDM), "MultiresDM");
        CDDerivedMesh *cddm = cdDM_create("MultiresDM CDDM");
@@ -1509,7 +1779,8 @@ DerivedMesh *MultiresDM_new(MultiresSubsurf *ms, DerivedMesh *orig, int numVerts
                MVert *mvert;
                int i;
 
-               DM_from_template(dm, orig, numVerts, numEdges, numFaces);
+               DM_from_template(dm, orig, numVerts, numEdges, numFaces, 
+                                numLoops, numPolys);
                CustomData_free_layers(&dm->faceData, CD_MDISPS, numFaces);
 
                disps = CustomData_get_layer(&orig->faceData, CD_MDISPS);
@@ -1523,7 +1794,7 @@ DerivedMesh *MultiresDM_new(MultiresSubsurf *ms, DerivedMesh *orig, int numVerts
                        VecCopyf(mrdm->orco[i], mvert[i].co);
        }
        else
-               DM_init(dm, numVerts, numEdges, numFaces);
+               DM_init(dm, numVerts, numEdges, numFaces, numLoops, numPolys);
 
        CustomData_add_layer(&dm->vertData, CD_MVERT, CD_CALLOC, NULL, numVerts);
        CustomData_add_layer(&dm->edgeData, CD_MEDGE, CD_CALLOC, NULL, numEdges);
@@ -1626,3 +1897,4 @@ int *MultiresDM_get_flags(DerivedMesh *dm)
 {
        return &((MultiresDM*)dm)->flags;
 }
+
index 6c9dfe4bf0a28aa8c1fa04e346fddaa7590c5d4b..b485a4266fb54e9a58b5ea8fa89dee15b1e80d00 100644 (file)
@@ -973,8 +973,8 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
 static void cloth_from_mesh ( Object *ob, ClothModifierData *clmd, DerivedMesh *dm )
 {
        unsigned int numverts = dm->getNumVerts ( dm );
-       unsigned int numfaces = dm->getNumFaces ( dm );
-       MFace *mface = CDDM_get_faces(dm);
+       unsigned int numfaces = dm->getNumTessFaces ( dm );
+       MFace *mface = CDDM_get_tessfaces(dm);
        unsigned int i = 0;
 
        /* Allocate our vertices. */
@@ -1086,9 +1086,9 @@ int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm )
        int i = 0;
        int numverts = dm->getNumVerts ( dm );
        int numedges = dm->getNumEdges ( dm );
-       int numfaces = dm->getNumFaces ( dm );
+       int numfaces = dm->getNumTessFaces ( dm );
        MEdge *medge = CDDM_get_edges ( dm );
-       MFace *mface = CDDM_get_faces ( dm );
+       MFace *mface = CDDM_get_tessfaces ( dm );
        int index2 = 0; // our second vertex index
        LinkNode **edgelist = NULL;
        EdgeHash *edgehash = NULL;
index 645f468d250f91af8df998bc52fec81ba5959664..4d06f8b72d90a780b7ec41756848483b6aa5c377 100644 (file)
@@ -520,10 +520,10 @@ static void mesh_create_shadedColors(Render *re, Object *ob, int onlyForMesh, un
                dm = mesh_get_derived_final(RE_GetScene(re), ob, dataMask);
        
        mvert = dm->getVertArray(dm);
-       mface = dm->getFaceArray(dm);
-       nors = dm->getFaceDataArray(dm, CD_NORMAL);
+       mface = dm->getTessFaceArray(dm);
+       nors = dm->getTessFaceDataArray(dm, CD_NORMAL);
        totvert = dm->getNumVerts(dm);
-       totface = dm->getNumFaces(dm);
+       totface = dm->getNumTessFaces(dm);
        orco= dm->getVertDataArray(dm, CD_ORCO);
 
        if (onlyForMesh) {
index 37bae53d3e81a4012b28bf4f16d78ad0e23c6680..34054557e34f32cabf89cf419f9d0b80f567e84d 100644 (file)
@@ -929,13 +929,27 @@ static int bmDM_getNumEdges(DerivedMesh *dm)
        return bmdm->tc->bm->totedge;
 }
 
-static int bmDM_getNumFaces(DerivedMesh *dm)
+static int bmDM_getNumTessFaces(DerivedMesh *dm)
 {
        EditDerivedBMesh *bmdm= (EditDerivedBMesh*) dm;
        
        return bmdm->tc->tottri;
 }
 
+static int bmvert_to_mvert(BMVert *ev, MVert *vert_r)
+{
+       VECCOPY(vert_r->co, ev->co);
+
+       vert_r->no[0] = (short)(ev->no[0] * 32767.0f);
+       vert_r->no[1] = (short)(ev->no[1] * 32767.0f);
+       vert_r->no[2] = (short)(ev->no[2] * 32767.0f);
+
+       /* TODO what to do with vert_r->flag and vert_r->mat_nr? */
+       vert_r->flag = BMFlags_To_MEFlags(ev);
+       vert_r->mat_nr = 0;
+       vert_r->bweight = (unsigned char) (ev->bweight*255.0f);
+}
+
 static void bmDM_getVert(DerivedMesh *dm, int index, MVert *vert_r)
 {
        BMVert *ev;
@@ -950,15 +964,7 @@ static void bmDM_getVert(DerivedMesh *dm, int index, MVert *vert_r)
                return;
        }
 
-       VECCOPY(vert_r->co, ev->co);
-
-       vert_r->no[0] = (short)(ev->no[0] * 32767.0f);
-       vert_r->no[1] = (short)(ev->no[1] * 32767.0f);
-       vert_r->no[2] = (short)(ev->no[2] * 32767.0f);
-
-       /* TODO what to do with vert_r->flag and vert_r->mat_nr? */
-       vert_r->mat_nr = 0;
-       vert_r->bweight = (unsigned char) (ev->bweight*255.0f);
+       bmvert_to_mvert(ev, vert_r);
 }
 
 static void bmDM_getEdge(DerivedMesh *dm, int index, MEdge *edge_r)
@@ -977,8 +983,7 @@ static void bmDM_getEdge(DerivedMesh *dm, int index, MEdge *edge_r)
        edge_r->bweight = (unsigned char) (e->bweight*255.0f);
        /* TODO what to do with edge_r->flag? */
        edge_r->flag = ME_EDGEDRAW|ME_EDGERENDER;
-       if (e->head.flag & BM_SEAM)  edge_r->flag |= ME_SEAM;
-       if (e->head.flag & BM_SHARP) edge_r->flag |= ME_SHARP;
+       edge_r->flag |= BMFlags_To_MEFlags(e);
 #if 0
        /* this needs setup of f2 field */
        if (!ee->f2) edge_r->flag |= ME_LOOSEEDGE;
@@ -1016,9 +1021,7 @@ static void bmDM_getFace(DerivedMesh *dm, int index, MFace *face_r)
 
        face_r->mat_nr = (unsigned char) ef->mat_nr;
        //need to convert flags here!
-       if (ef->head.flag & BM_SELECT) face_r->flag |= ME_FACE_SEL;
-       if (ef->head.flag & BM_HIDDEN) face_r->flag |= ME_HIDE;
-       //face_r->flag = ef->head.flag;
+       face_r->flag = BMFlags_To_MEFlags(ef);
 
        /*while it's possible to store a cache to lookup these indices faster,
          that would require going over the code and ensuring the cache is
@@ -1064,7 +1067,7 @@ static void bmDM_copyVertArray(DerivedMesh *dm, MVert *vert_r)
 
                /* TODO what to do with vert_r->flag and vert_r->mat_nr? */
                vert_r->mat_nr = 0;
-               vert_r->flag = 0;
+               vert_r->flag = BMFlags_To_MEFlags(ev);
                vert_r->bweight = (unsigned char) (ev->bweight*255.0f);
        }
 }
@@ -1173,9 +1176,153 @@ static void *bmDM_getFaceDataArray(DerivedMesh *dm, int type)
        return datalayer;
 }
 
-static void bmDM_release(DerivedMesh *dm)
+typedef struct bmDM_loopIter {
+       DMLoopIter head;
+
+       BMFace *f;
+       BMLoop *l, *nextl;
+       BMIter iter;
+       BMesh *bm;
+} bmDM_loopIter;
+
+typedef struct bmDM_faceIter {
+       DMFaceIter head;
+
+       BMFace *f, *nextf;
+       BMIter iter;
+       BMesh *bm;
+
+       bmDM_loopIter loopiter;
+} bmDM_faceIter;
+
+void bmDM_faceIterStep(void *self)
 {
-       EditDerivedBMesh *bmdm= (EditDerivedBMesh*) dm;
+       bmDM_faceIter *iter = self;
+       
+       iter->f = iter->nextf;
+
+       iter->head.mat_nr = iter->f->mat_nr;
+       iter->head.flags = BMFlags_To_MEFlags(iter->f);
+       iter->head.index++;
+
+       iter->nextf = BMIter_Step(&iter->iter);
+
+       if (!iter->nextf) iter->head.done = 1;
+}
+
+void *bmDM_getFaceCDData(void *self, int type, int layer)
+{
+       bmDM_faceIter *iter = self;
+
+       if (layer == -1) 
+               return CustomData_bmesh_get(&iter->bm->pdata, iter->f->data, type);
+       else return CustomData_bmesh_get_n(&iter->bm->pdata, iter->f->data, type, layer);
+}
+
+void bmDM_loopIterStep(void *self)
+{
+       bmDM_loopIter *iter = self;
+
+       iter->l = iter->nextl;
+
+       bmvert_to_mvert(iter->l->v, &iter->head.v);
+       iter->head.index++;
+       iter->head.vindex = BMINDEX_GET(iter->l->v);
+       iter->head.eindex = BMINDEX_GET(iter->l->e);
+
+       iter->nextl = BMIter_Step(&iter->iter);
+
+       if (!iter->nextl) iter->head.done = 1;
+}
+
+void *bmDM_getLoopCDData(void *self, int type, int layer)
+{
+       bmDM_loopIter *iter = self;
+
+       if (layer == -1) 
+               return CustomData_bmesh_get(&iter->bm->ldata, iter->l->data, type);
+       else return CustomData_bmesh_get_n(&iter->bm->ldata, iter->l->data, type, layer);
+}
+
+void *bmDM_getVertCDData(void *self, int type, int layer)
+{
+       bmDM_loopIter *iter = self;
+
+       if (layer == -1) 
+               return CustomData_bmesh_get(&iter->bm->vdata, iter->l->v->data, type);
+       else return CustomData_bmesh_get_n(&iter->bm->vdata, iter->l->v->data, type, layer);
+}
+
+void bmDM_iterFree(void *self)
+{
+       MEM_freeN(self);
+}
+
+void bmDM_nulliterFree(void *self)
+{
+}
+
+DMLoopIter *bmDM_newLoopsIter(void *faceiter)
+{
+       bmDM_faceIter *fiter = faceiter;
+       bmDM_loopIter *iter = &fiter->loopiter;
+
+       memset(&fiter->loopiter, 0, sizeof(bmDM_loopIter));
+
+       iter->bm = fiter->bm;
+       iter->f = fiter->f;
+       iter->l = BMIter_New(&iter->iter, iter->bm, BM_LOOPS_OF_FACE, iter->f);
+
+       iter->head.step = bmDM_loopIterStep;
+       iter->head.getLoopCDData = bmDM_getLoopCDData;
+       iter->head.getVertCDData = bmDM_getVertCDData;
+
+       bmvert_to_mvert(iter->l->v, &iter->head.v);
+       iter->head.vindex = BMINDEX_GET(iter->l->v);
+       iter->head.eindex = BMINDEX_GET(iter->l->e);
+
+       return (DMLoopIter*) iter;
+}
+
+static DMFaceIter *bmDM_getFaceIter(void *dm)
+{
+       EditDerivedBMesh *bmdm= dm;
+       bmDM_faceIter *iter = MEM_callocN(sizeof(bmDM_faceIter), "bmDM_faceIter");
+       BMIter biter;
+       BMVert *v;
+       BMEdge *e;
+       int i;
+
+       iter->bm = bmdm->tc->bm;
+       iter->f = BMIter_New(&iter->iter, iter->bm, BM_FACES_OF_MESH, NULL);
+       
+       iter->head.step = bmDM_faceIterStep;
+       iter->head.free = bmDM_iterFree;
+       iter->head.getCDData = bmDM_getFaceCDData;
+       iter->head.getLoopsIter = bmDM_newLoopsIter;
+       
+       iter->head.mat_nr = iter->f->mat_nr;
+       iter->head.flags = BMFlags_To_MEFlags(iter->f);
+
+       /*set up vert/edge indices*/
+       i = 0;
+       BM_ITER(v, &biter, iter->bm, BM_VERTS_OF_MESH, NULL) {
+               BMINDEX_SET(v, i);
+               i++;
+       }
+
+       i = 0;
+       BM_ITER(e, &biter, iter->bm, BM_EDGES_OF_MESH, NULL) {
+               BMINDEX_SET(e, i);
+               i++;
+       }
+
+       return (DMFaceIter*) iter;
+}
+
+static void bmDM_release(void *dm)
+{
+       EditDerivedBMesh *bmdm= dm;
 
        if (DM_release(dm)) {
                if (bmdm->vertexCos) {
@@ -1196,21 +1343,24 @@ DerivedMesh *getEditDerivedBMesh(BMEditMesh *em, Object *ob,
 
        bmdm->tc = em;
 
-       DM_init((DerivedMesh*)bmdm, em->bm->totvert, em->bm->totedge, em->tottri);
+       DM_init((DerivedMesh*)bmdm, em->bm->totvert, em->bm->totedge, em->tottri,
+                em->bm->totloop, em->bm->totface);
 
        bmdm->dm.getMinMax = bmDM_getMinMax;
 
        bmdm->dm.getNumVerts = bmDM_getNumVerts;
        bmdm->dm.getNumEdges = bmDM_getNumEdges;
-       bmdm->dm.getNumFaces = bmDM_getNumFaces;
+       bmdm->dm.getNumTessFaces = bmDM_getNumTessFaces;
 
        bmdm->dm.getVert = bmDM_getVert;
        bmdm->dm.getEdge = bmDM_getEdge;
-       bmdm->dm.getFace = bmDM_getFace;
+       bmdm->dm.getTessFace = bmDM_getFace;
        bmdm->dm.copyVertArray = bmDM_copyVertArray;
        bmdm->dm.copyEdgeArray = bmDM_copyEdgeArray;
-       bmdm->dm.copyFaceArray = bmDM_copyFaceArray;
-       bmdm->dm.getFaceDataArray = bmDM_getFaceDataArray;
+       bmdm->dm.copyTessFaceArray = bmDM_copyFaceArray;
+       bmdm->dm.getTessFaceDataArray = bmDM_getFaceDataArray;
+
+       bmdm->dm.newFaceIter = bmDM_getFaceIter;
 
        bmdm->dm.foreachMappedVert = bmDM_foreachMappedVert;
        bmdm->dm.foreachMappedEdge = bmDM_foreachMappedEdge;
index 5488d50e2264c736330bcac9bb08bf5cdc4f73c3..9c58844372fdc1be4ef1950f126d7a215a973499 100644 (file)
@@ -2282,8 +2282,8 @@ static void write_vert_stl(Object *ob, MVert *verts, int index, FILE *fpSTL)
 static int write_derivedmesh_stl(FILE *fpSTL, Object *ob, DerivedMesh *dm)
 {
        MVert *mvert = dm->getVertArray(dm);
-       MFace *mface = dm->getFaceArray(dm);
-       int i, numfacets = 0, totface = dm->getNumFaces(dm);
+       MFace *mface = dm->getTessFaceArray(dm);
+       int i, numfacets = 0, totface = dm->getNumTessFaces(dm);
        float zero[3] = {0.0f, 0.0f, 0.0f};
 
        for (i=0; i<totface; i++, mface++) {
index 9eefd48cae49e58c854494cde768b0f625096300..14bff9b5d577f11852f22cb06111902b0cffc342 100644 (file)
@@ -294,7 +294,7 @@ static DerivedMesh *fluidsim_read_obj(char *filename)
                return NULL;
        }
        
-       dm = CDDM_new(numverts, 0, numfaces);
+       dm = CDDM_new(numverts, 0, numfaces, 0, 0);
        
        if(!dm)
        {
@@ -351,7 +351,7 @@ static DerivedMesh *fluidsim_read_obj(char *filename)
                printf("Fluidsim: error in reading data from file.\n");
        
        // read triangles from file
-       mface = CDDM_get_faces(dm);
+       mface = CDDM_get_tessfaces(dm);
        for(i=0; i<numfaces; i++) 
        {
                int face[4];
@@ -387,6 +387,7 @@ static DerivedMesh *fluidsim_read_obj(char *filename)
        CDDM_apply_vert_normals(dm, (short (*)[3])normals);
        MEM_freeN(normals);
        
+       CDDM_tessfaces_to_faces(dm);
        // CDDM_calc_normals(result);
 
        return dm;
@@ -454,12 +455,12 @@ DerivedMesh *fluidsim_read_cache(Object *ob, DerivedMesh *orgdm, FluidsimModifie
        }
        
        // assign material + flags to new dm
-       mface = orgdm->getFaceArray(orgdm);
+       mface = orgdm->getTessFaceArray(orgdm);
        mat_nr = mface[0].mat_nr;
        flag = mface[0].flag;
        
-       mface = dm->getFaceArray(dm);
-       numfaces = dm->getNumFaces(dm);
+       mface = dm->getTessFaceArray(dm);
+       numfaces = dm->getNumTessFaces(dm);
        for(i=0; i<numfaces; i++) 
        {
                mface[i].mat_nr = mat_nr;
@@ -613,9 +614,9 @@ void initElbeemMesh(struct Scene *scene, struct Object *ob,
        //dm = mesh_create_derived_no_deform(ob,NULL);
 
        mvert = dm->getVertArray(dm);
-       mface = dm->getFaceArray(dm);
+       mface = dm->getTessFaceArray(dm);
        totvert = dm->getNumVerts(dm);
-       totface = dm->getNumFaces(dm);
+       totface = dm->getNumTessFaces(dm);
 
        *numVertices = totvert;
        verts = MEM_callocN( totvert*3*sizeof(float), "elbeemmesh_vertices");
index ad48814f21c2fe763663b1b7a6b8d3b39693966e..5ce0552636c0974baad355f09d5e3502b28c5541 100644 (file)
@@ -418,7 +418,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;
@@ -431,7 +431,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 */
@@ -447,7 +447,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),
@@ -523,7 +523,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);
@@ -564,8 +564,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;
 
@@ -582,6 +582,7 @@ static DerivedMesh *buildModifier_applyModifier(ModifierData *md, Object *ob,
                   }
 
                   CDDM_calc_normals(result);
+                  CDDM_tessfaces_to_faces(result);
 
                   BLI_ghash_free(vertHash, NULL, NULL);
                   BLI_ghash_free(edgeHash, NULL, NULL);
@@ -589,7 +590,7 @@ static DerivedMesh *buildModifier_applyModifier(ModifierData *md, Object *ob,
                   MEM_freeN(vertMap);
                   MEM_freeN(edgeMap);
                   MEM_freeN(faceMap);
-
+                       
                   return result;
 }
 
@@ -653,7 +654,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
@@ -847,7 +848,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)) &&
@@ -864,7 +865,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 */
@@ -918,8 +919,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;
                
@@ -944,6 +945,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;
 }
@@ -1193,18 +1196,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);
@@ -1355,13 +1358,13 @@ 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);
                          *mf = inMF;
@@ -1432,10 +1435,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);
 
@@ -1494,7 +1497,7 @@ 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);
                                  mface[numFaces] = cap_mface[i];
@@ -1533,10 +1536,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);
 
@@ -1595,7 +1598,7 @@ 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);
                                  mface[numFaces] = cap_mface[i];
@@ -1628,6 +1631,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;
 }
@@ -1823,7 +1828,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;
@@ -1834,7 +1839,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) {
@@ -1969,9 +1974,9 @@ 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);
                *mf = inMF;
@@ -1986,7 +1991,7 @@ 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);
@@ -1999,7 +2004,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) {
@@ -2013,7 +2018,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++;
@@ -2028,6 +2033,8 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
        CDDM_lower_num_edges(result, numEdges);
        CDDM_lower_num_faces(result, numFaces);
 
+       CDDM_tessfaces_to_faces(result);
+
        return result;
 }
 
@@ -2362,7 +2369,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);
@@ -2394,7 +2401,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);
@@ -2436,11 +2443,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) {
@@ -2469,7 +2477,7 @@ static DerivedMesh *CDDM_from_smoothmesh(SmoothMesh *mesh)
 
                DM_copy_face_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;
@@ -2482,6 +2490,8 @@ static DerivedMesh *CDDM_from_smoothmesh(SmoothMesh *mesh)
                }
        }
 
+       CDDM_tessfaces_to_faces(result);
+
        return result;
 }
 
@@ -3512,12 +3522,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);
                        MTFace *tf;
 
                        validate_layer_name(&dm->faceData, CD_MTFACE, dmd->uvlayer_name);
@@ -3830,7 +3840,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);
@@ -3937,8 +3947,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) {
@@ -4074,9 +4084,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++) {
@@ -4150,7 +4160,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];
@@ -5111,12 +5121,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);
                        MTFace *tf;
 
                        validate_layer_name(&dm->faceData, CD_MTFACE, wmd->uvlayer_name);
@@ -5949,8 +5959,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);
@@ -6148,8 +6158,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);
 
@@ -6342,7 +6352,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_HAIR;
@@ -6351,7 +6361,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){
@@ -6466,7 +6476,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;
@@ -6482,7 +6492,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);
@@ -6535,8 +6545,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;
@@ -6583,7 +6593,8 @@ static DerivedMesh * particleInstanceModifier_applyModifier(
                end_latt_deform(psys->lattice);
                psys->lattice= NULL;
        }
-
+       
+       CDDM_tessfaces_to_faces(result);
        return result;
 }
 static DerivedMesh *particleInstanceModifier_applyModifierEM(
@@ -6646,8 +6657,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;
 
@@ -6729,12 +6740,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");
@@ -6820,14 +6831,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++){
@@ -6842,8 +6853,8 @@ 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);
                *dest = source;
@@ -6879,7 +6890,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];
@@ -6887,7 +6898,7 @@ 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);
+                               df1=CDDM_get_tessface(splitdm,curdupface);
                                DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
                                *df1=*mf;
                                curdupface++;
@@ -6911,12 +6922,12 @@ 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);
+                               df1=CDDM_get_tessface(splitdm,curdupface);
                                DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
                                *df1=*mf;
                                curdupface++;
 
-                               df2=CDDM_get_face(splitdm,curdupface);
+                               df2=CDDM_get_tessface(splitdm,curdupface);
                                DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
                                *df2=*mf;
                                curdupface++;
@@ -6988,17 +6999,17 @@ 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);
+                               df1=CDDM_get_tessface(splitdm,curdupface);
                                DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
                                *df1=*mf;
                                curdupface++;
 
-                               df2=CDDM_get_face(splitdm,curdupface);
+                               df2=CDDM_get_tessface(splitdm,curdupface);
                                DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
                                *df2=*mf;
                                curdupface++;
 
-                               df3=CDDM_get_face(splitdm,curdupface);
+                               df3=CDDM_get_tessface(splitdm,curdupface);
                                DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
                                *df3=*mf;
                                curdupface++;
@@ -7089,17 +7100,17 @@ static DerivedMesh * explodeModifier_splitEdges(ExplodeModifierData *emd, Derive
                                        VecMulf(dupve->co,0.25);
 
 
-                                       df1=CDDM_get_face(splitdm,curdupface);
+                                       df1=CDDM_get_tessface(splitdm,curdupface);
                                        DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
                                        *df1=*mf;
                                        curdupface++;
 
-                                       df2=CDDM_get_face(splitdm,curdupface);
+                                       df2=CDDM_get_tessface(splitdm,curdupface);
                                        DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
                                        *df2=*mf;
                                        curdupface++;
 
-                                       df3=CDDM_get_face(splitdm,curdupface);
+                                       df3=CDDM_get_tessface(splitdm,curdupface);
                                        DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
                                        *df3=*mf;
                                        curdupface++;
@@ -7129,17 +7140,17 @@ 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);
+                                       df1=CDDM_get_tessface(splitdm,curdupface);
                                        DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
                                        *df1=*mf;
                                        curdupface++;
 
-                                       df2=CDDM_get_face(splitdm,curdupface);
+                                       df2=CDDM_get_tessface(splitdm,curdupface);
                                        DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
                                        *df2=*mf;
                                        curdupface++;
 
-                                       df3=CDDM_get_face(splitdm,curdupface);
+                                       df3=CDDM_get_tessface(splitdm,curdupface);
                                        DM_copy_face_data(splitdm,splitdm,i,curdupface,1);
                                        *df3=*mf;
                                        curdupface++;
@@ -7194,7 +7205,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;
 
 }
@@ -7216,7 +7228,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;
 
@@ -7238,7 +7250,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);
@@ -7257,7 +7269,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 */
@@ -7323,8 +7335,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;
 
@@ -7360,6 +7372,7 @@ static DerivedMesh * explodeModifier_explodeMesh(ExplodeModifierData *emd,
                psmd->psys->lattice= NULL;
        }
 
+       CDDM_tessfaces_to_faces(explode);
        return explode;
 }
 
@@ -7393,7 +7406,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;
                        
@@ -7640,7 +7653,6 @@ static void meshdeformModifier_do(
        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];
@@ -7654,7 +7666,6 @@ static void meshdeformModifier_do(
                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;
index dfd83a7b42ef4e88f4b6670046d6076d1190d0a3..6b935c90c250dd6ce655760e1eea73bf26a6b1af 100644 (file)
@@ -459,7 +459,7 @@ void multiresModifier_subdivide(MultiresModifierData *mmd, Object *ob, int dista
                mrdm = multires_dm_create_from_derived(&mmd_sub, orig, me, 0, 0);
                totsubvert = mrdm->getNumVerts(mrdm);
                totsubedge = mrdm->getNumEdges(mrdm);
-               totsubface = mrdm->getNumFaces(mrdm);
+               totsubface = mrdm->getNumTessFaces(mrdm);
                orig->needsFree = 1;
                orig->release(orig);
                
@@ -1192,7 +1192,7 @@ static void multiresModifier_update(DerivedMesh *dm)
                        final = multires_subdisp_pre(dm, totlvl - lvl, 0);
 
                        multires_subdisp(orig, me, final, lvl, totlvl, dm->getNumVerts(dm), dm->getNumEdges(dm),
-                                        dm->getNumFaces(dm), 1);
+                                        dm->getNumTessFaces(dm), 1);
 
                        subco_dm->release(subco_dm);
                        orig->release(orig);
index 7d998a481f68abcb094e8cef5a91bb52b1754013..6029e7985459eb1cb338d3d915aa9d55c1d952b3 100644 (file)
@@ -636,9 +636,9 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot)
                return tot;
 
        mvert= dm->getVertArray(dm);
-       mface= dm->getFaceArray(dm);
-       origindex= dm->getFaceDataArray(dm, CD_ORIGINDEX);
-       totface= dm->getNumFaces(dm);
+       mface= dm->getTessFaceArray(dm);
+       origindex= dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
+       totface= dm->getNumTessFaces(dm);
        totorigface= me->totface;
 
        if(totface == 0 || totorigface == 0 || origindex == NULL)
@@ -1078,7 +1078,7 @@ float psys_interpolate_value_from_verts(DerivedMesh *dm, short from, int index,
                case PART_FROM_FACE:
                case PART_FROM_VOLUME:
                {
-                       MFace *mf=dm->getFaceData(dm,index,CD_MFACE);
+                       MFace *mf=dm->getTessFaceData(dm,index,CD_MFACE);
                        return interpolate_particle_value(values[mf->v1],values[mf->v2],values[mf->v3],values[mf->v4],fw,mf->v4);
                }
                        
@@ -1126,11 +1126,11 @@ int psys_particle_dm_face_lookup(Object *ob, DerivedMesh *dm, int index, float *
        int quad, findex, totface;
        float uv[2], (*faceuv)[2];
 
-       mface = dm->getFaceDataArray(dm, CD_MFACE);
-       origindex = dm->getFaceDataArray(dm, CD_ORIGINDEX);
-       osface = dm->getFaceDataArray(dm, CD_ORIGSPACE);
+       mface = dm->getTessFaceDataArray(dm, CD_MFACE);
+       origindex = dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
+       osface = dm->getTessFaceDataArray(dm, CD_ORIGSPACE);
 
-       totface = dm->getNumFaces(dm);
+       totface = dm->getNumTessFaces(dm);
        
        if(osface==NULL || origindex==NULL) {
                /* Assume we dont need osface data */
@@ -1199,7 +1199,7 @@ static int psys_map_index_on_dm(DerivedMesh *dm, int from, int index, int index_
                        *mapindex = index;
                }
                else  { /* FROM_FACE/FROM_VOLUME */
-                       if(index >= dm->getNumFaces(dm))
+                       if(index >= dm->getNumTessFaces(dm))
                                return 0;
 
                        *mapindex = index;
@@ -1223,15 +1223,15 @@ static int psys_map_index_on_dm(DerivedMesh *dm, int from, int index, int index_
 
                        i = index_dmcache;
 
-                       if(i== DMCACHE_NOTFOUND || i >= dm->getNumFaces(dm))
+                       if(i== DMCACHE_NOTFOUND || i >= dm->getNumTessFaces(dm))
                                return 0;
 
                        *mapindex = i;
 
                        /* modify the original weights to become
                         * weights for the derived mesh face */
-                       osface= dm->getFaceDataArray(dm, CD_ORIGSPACE);
-                       mface= dm->getFaceData(dm, i, CD_MFACE);
+                       osface= dm->getTessFaceDataArray(dm, CD_ORIGSPACE);
+                       mface= dm->getTessFaceData(dm, i, CD_MFACE);
 
                        if(osface == NULL)
                                mapfw[0]= mapfw[1]= mapfw[2]= mapfw[3]= 0.0f;
@@ -1289,7 +1289,7 @@ void psys_particle_on_dm(DerivedMesh *dm, int from, int index, int index_dmcache
                MTFace *mtface;
                MVert *mvert;
 
-               mface=dm->getFaceData(dm,mapindex,CD_MFACE);
+               mface=dm->getTessFaceData(dm,mapindex,CD_MFACE);
                mvert=dm->getVertDataArray(dm,CD_MVERT);
                mtface=CustomData_get_layer(&dm->faceData,CD_MTFACE);
 
@@ -2825,10 +2825,10 @@ static void psys_face_mat(Object *ob, DerivedMesh *dm, ParticleData *pa, float m
 
        int i = pa->num_dmcache==DMCACHE_NOTFOUND ? pa->num : pa->num_dmcache;
        
-       if (i==-1 || i >= dm->getNumFaces(dm)) { Mat4One(mat); return; }
+       if (i==-1 || i >= dm->getNumTessFaces(dm)) { Mat4One(mat); return; }
 
-       mface=dm->getFaceData(dm,i,CD_MFACE);
-       osface=dm->getFaceData(dm,i,CD_ORIGSPACE);
+       mface=dm->getTessFaceData(dm,i,CD_MFACE);
+       osface=dm->getTessFaceData(dm,i,CD_ORIGSPACE);
        
        if(orco && (orcodata=dm->getVertDataArray(dm, CD_ORCO))) {
                VECCOPY(v[0], orcodata[mface->v1]);
@@ -3146,7 +3146,7 @@ static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, fl
 
        if(pa) {
                i= (pa->num_dmcache==DMCACHE_NOTFOUND)? pa->num: pa->num_dmcache;
-               if(i >= dm->getNumFaces(dm))
+               if(i >= dm->getNumTessFaces(dm))
                        i = -1;
        }
        else
@@ -3158,7 +3158,7 @@ static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, fl
                texco[2]= 0.0f;
        }
        else {
-               mf= dm->getFaceData(dm, i, CD_MFACE);
+               mf= dm->getTessFaceData(dm, i, CD_MFACE);
 
                psys_interpolate_uvs(&tf[i], mf->v4, fuv, texco);
 
@@ -3824,7 +3824,7 @@ void psys_get_dupli_texture(Object *ob, ParticleSettings *part, ParticleSystemMo
                if(part->childtype == PART_CHILD_FACES) {
                        mtface= CustomData_get_layer(&psmd->dm->faceData, CD_MTFACE);
                        if(mtface) {
-                               mface= psmd->dm->getFaceData(psmd->dm, cpa->num, CD_MFACE);
+                               mface= psmd->dm->getTessFaceData(psmd->dm, cpa->num, CD_MFACE);
                                mtface += cpa->num;
                                psys_interpolate_uvs(mtface, mface->v4, cpa->fuv, uv);
                        }
@@ -3844,11 +3844,11 @@ void psys_get_dupli_texture(Object *ob, ParticleSettings *part, ParticleSystemMo
                        num= pa->num_dmcache;
 
                        if(num == DMCACHE_NOTFOUND)
-                               if(pa->num < psmd->dm->getNumFaces(psmd->dm))
+                               if(pa->num < psmd->dm->getNumTessFaces(psmd->dm))
                                        num= pa->num;
 
                        if(mtface && num != DMCACHE_NOTFOUND) {
-                               mface= psmd->dm->getFaceData(psmd->dm, num, CD_MFACE);
+                               mface= psmd->dm->getTessFaceData(psmd->dm, num, CD_MFACE);
                                mtface += num;
                                psys_interpolate_uvs(mtface, mface->v4, pa->fuv, uv);
                        }
index f8b1852b728de8508c23977e9524aecfc5728b92..caff933ecc0cddca22042639f7770daae0125756 100644 (file)
@@ -274,7 +274,7 @@ void psys_calc_dmcache(Object *ob, DerivedMesh *dm, ParticleSystem *psys)
                        origindex= DM_get_vert_data_layer(dm, CD_ORIGINDEX);
                }
                else { /* FROM_FACE/FROM_VOLUME */
-                       totdmelem= dm->getNumFaces(dm);
+                       totdmelem= dm->getNumTessFaces(dm);
                        totelem= me->totface;
                        origindex= DM_get_face_data_layer(dm, CD_ORIGINDEX);
                }
@@ -406,8 +406,8 @@ static void distribute_particles_in_grid(DerivedMesh *dm, ParticleSystem *psys)
                int a, a1, a2, a0mul, a1mul, a2mul, totface;
                int amax= from==PART_FROM_FACE ? 3 : 1;
 
-               totface=dm->getNumFaces(dm);
-               mface=dm->getFaceDataArray(dm,CD_MFACE);
+               totface=dm->getNumTessFaces(dm);
+               mface=dm->getTessFaceDataArray(dm,CD_MFACE);
                
                for(a=0; a<amax; a++){
                        if(a==0){ a0mul=res*res; a1mul=res; a2mul=1; }
@@ -416,7 +416,7 @@ static void distribute_particles_in_grid(DerivedMesh *dm, ParticleSystem *psys)
 
                        for(a1=0; a1<size[(a+1)%3]; a1++){
                                for(a2=0; a2<size[(a+2)%3]; a2++){
-                                       mface=dm->getFaceDataArray(dm,CD_MFACE);
+                                       mface=dm->getTessFaceDataArray(dm,CD_MFACE);
 
                                        pa=psys->particles + a1*a1mul + a2*a2mul;
                                        VECCOPY(co1,pa->fuv);
@@ -630,7 +630,7 @@ void psys_thread_distribute_particle(ParticleThread *thread, ParticleData *pa, C
                MFace *mface;
 
                pa->num = i = ctx->index[p];
-               mface = dm->getFaceData(dm,i,CD_MFACE);
+               mface = dm->getTessFaceData(dm,i,CD_MFACE);
                
                switch(distr){
                case PART_DISTR_JIT:
@@ -657,7 +657,7 @@ void psys_thread_distribute_particle(ParticleThread *thread, ParticleData *pa, C
                if(from==PART_FROM_VOLUME){
                        MVert *mvert=dm->getVertDataArray(dm,CD_MVERT);
 
-                       tot=dm->getNumFaces(dm);
+                       tot=dm->getNumTessFaces(dm);
 
                        psys_interpolate_face(mvert,mface,0,0,pa->fuv,co1,nor,0,0,0,0);
 
@@ -669,7 +669,7 @@ void psys_thread_distribute_particle(ParticleThread *thread, ParticleData *pa, C
                        min_d=2.0;
                        intersect=0;
 
-                       for(i=0,mface=dm->getFaceDataArray(dm,CD_MFACE); i<tot; i++,mface++){
+                       for(i=0,mface=dm->getTessFaceDataArray(dm,CD_MFACE); i<tot; i++,mface++){
                                if(i==pa->num) continue;
 
                                v1=mvert[mface->v1].co;
@@ -731,7 +731,7 @@ void psys_thread_distribute_particle(ParticleThread *thread, ParticleData *pa, C
                        return;
                }
 
-               mf= dm->getFaceData(dm, ctx->index[p], CD_MFACE);
+               mf= dm->getTessFaceData(dm, ctx->index[p], CD_MFACE);
 
                //switch(distr){
                //      case PART_DISTR_JIT:
@@ -1102,7 +1102,7 @@ int psys_threads_init_distribution(ParticleThread *threads, Scene *scene, Derive
                        break;
                case PART_FROM_VOLUME:
                case PART_FROM_FACE:
-                       tot = dm->getNumFaces(dm);
+                       tot = dm->getNumTessFaces(dm);
                        break;
                case PART_FROM_PARTICLE:
                        if(psys->target_ob)
@@ -1162,7 +1162,7 @@ int psys_threads_init_distribution(ParticleThread *threads, Scene *scene, Derive
                orcodata= dm->getVertDataArray(dm, CD_ORCO);
 
                for(i=0; i<tot; i++){
-                       MFace *mf=dm->getFaceData(dm,i,CD_MFACE);
+                       MFace *mf=dm->getTessFaceData(dm,i,CD_MFACE);
 
                        if(orcodata) {
                                VECCOPY(co1, orcodata[mf->v1]);
@@ -1231,7 +1231,7 @@ int psys_threads_init_distribution(ParticleThread *threads, Scene *scene, Derive
                        }
                        else { /* PART_FROM_FACE / PART_FROM_VOLUME */
                                for(i=0;i<tot; i++){
-                                       MFace *mf=dm->getFaceData(dm,i,CD_MFACE);
+                                       MFace *mf=dm->getTessFaceData(dm,i,CD_MFACE);
                                        tweight = vweight[mf->v1] + vweight[mf->v2] + vweight[mf->v3];
                                
                                        if(mf->v4) {
@@ -1297,7 +1297,7 @@ int psys_threads_init_distribution(ParticleThread *threads, Scene *scene, Derive
        /* for hair, sort by origindex, allows optimizations in rendering */
        /* however with virtual parents the children need to be in random order */
        if(part->type == PART_HAIR && !(part->childtype==PART_CHILD_FACES && part->parents!=0.0)) {
-               COMPARE_ORIG_INDEX= dm->getFaceDataArray(dm, CD_ORIGINDEX);
+               COMPARE_ORIG_INDEX= dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
                if(COMPARE_ORIG_INDEX)
                        qsort(index, totpart, sizeof(int), compare_orig_index);
        }
@@ -2919,8 +2919,8 @@ int psys_intersect_dm(Scene *scene, Object *ob, DerivedMesh *dm, float *vert_cos
                VECCOPY(p_max,pa_minmax+3);
        }
 
-       totface=dm->getNumFaces(dm);
-       mface=dm->getFaceDataArray(dm,CD_MFACE);
+       totface=dm->getNumTessFaces(dm);
+       mface=dm->getTessFaceDataArray(dm,CD_MFACE);
        mvert=dm->getVertDataArray(dm,CD_MVERT);
        
        /* lets intersect the faces */
@@ -3361,7 +3361,7 @@ static int boid_see_mesh(ListBase *lb, Scene *scene, Object *pob, ParticleSystem
                                psys_enable_all(ob);
                        }
 
-                       mface=dm->getFaceDataArray(dm,CD_MFACE);
+                       mface=dm->getTessFaceDataArray(dm,CD_MFACE);
                        mface+=min_face;
                        mvert=dm->getVertDataArray(dm,CD_MVERT);
 
@@ -3876,7 +3876,7 @@ static void boid_body(Scene *scene, BoidVecFunc *bvf, ParticleData *pa, Particle
                                dm=mesh_get_derived_final(scene, zob, 0);
                                psys_enable_all(zob);
 
-                               mface=dm->getFaceDataArray(dm,CD_MFACE);
+                               mface=dm->getTessFaceDataArray(dm,CD_MFACE);
                                mface+=min_face;
                                mvert=dm->getVertDataArray(dm,CD_MVERT);
 
index d7accd54fb96ea4acb80fe1cbfe8aab6c26842cb..d7070e4cdd66eeff56e626b16af626f558069c0b 100644 (file)
@@ -247,11 +247,11 @@ static ccd_Mesh *ccd_mesh_make(Object *ob, DerivedMesh *dm)
        
        /* first some paranoia checks */
        if (!dm) return NULL;
-       if (!dm->getNumVerts(dm) || !dm->getNumFaces(dm)) return NULL;
+       if (!dm->getNumVerts(dm) || !dm->getNumTessFaces(dm)) return NULL;
        
        pccd_M = MEM_mallocN(sizeof(ccd_Mesh),"ccd_Mesh");
        pccd_M->totvert = dm->getNumVerts(dm);
-       pccd_M->totface = dm->getNumFaces(dm);
+       pccd_M->totface = dm->getNumTessFaces(dm);
        pccd_M->savety  = CCD_SAVETY;
        pccd_M->bbmin[0]=pccd_M->bbmin[1]=pccd_M->bbmin[2]=1e30f;
        pccd_M->bbmax[0]=pccd_M->bbmax[1]=pccd_M->bbmax[2]=-1e30f;
@@ -280,7 +280,7 @@ static ccd_Mesh *ccd_mesh_make(Object *ob, DerivedMesh *dm)
                
        }
        /* alloc and copy faces*/
-    pccd_M->mface = dm->dupFaceArray(dm);
+    pccd_M->mface = dm->dupTessFaceArray(dm);
        
        /* OBBs for idea1 */
     pccd_M->mima = MEM_mallocN(sizeof(ccdf_minmax)*pccd_M->totface,"ccd_Mesh_Faces_mima");
@@ -343,10 +343,10 @@ static void ccd_mesh_update(Object *ob,ccd_Mesh *pccd_M, DerivedMesh *dm)
        
        /* first some paranoia checks */
        if (!dm) return ;
-       if (!dm->getNumVerts(dm) || !dm->getNumFaces(dm)) return ;
+       if (!dm->getNumVerts(dm) || !dm->getNumTessFaces(dm)) return ;
 
        if ((pccd_M->totvert != dm->getNumVerts(dm)) ||
-               (pccd_M->totface != dm->getNumFaces(dm))) return;
+               (pccd_M->totface != dm->getNumTessFaces(dm))) return;
 
        pccd_M->bbmin[0]=pccd_M->bbmin[1]=pccd_M->bbmin[2]=1e30f;
        pccd_M->bbmax[0]=pccd_M->bbmax[1]=pccd_M->bbmax[2]=-1e30f;
index 15969fc9ab91b810b26735afb4f743a861e46018..97248f0c78e8facecf369aec801536bec71965cd 100644 (file)
@@ -230,10 +230,11 @@ static void get_face_uv_map_vert(UvVertMap *vmap, struct MFace *mf, int fi, CCGV
 }
 
 static int ss_sync_from_uv(CCGSubSurf *ss, CCGSubSurf *origss, DerivedMesh *dm, MTFace *tface) {
-       MFace *mface = dm->getFaceArray(dm);
+#if 0
+       MFace *mface = dm->getTessFaceArray(dm);
        MVert *mvert = dm->getVertArray(dm);
        int totvert = dm->getNumVerts(dm);
-       int totface = dm->getNumFaces(dm);
+       int totface = dm->getNumTessFaces(dm);
        int i, j, seam;
        UvMapVert *v;
        UvVertMap *vmap;
@@ -323,6 +324,7 @@ static int ss_sync_from_uv(CCGSubSurf *ss, CCGSubSurf *origss, DerivedMesh *dm,
        free_uv_vert_map(vmap);
        ccgSubSurf_processSync(ss);
 
+#endif
        return 1;
 }
 
@@ -348,7 +350,7 @@ static void set_subsurf_uv(CCGSubSurf *ss, DerivedMesh *dm, DerivedMesh *result,
        }
 
        /* get some info from CCGSubsurf */
-       totface = ccgSubSurf_getNumFaces(uvss);
+       totface = ccgSubSurf_getNumTessFaces(uvss);
        edgeSize = ccgSubSurf_getEdgeSize(uvss);
        gridSize = ccgSubSurf_getGridSize(uvss);
        gridFaces = gridSize - 1;
@@ -480,6 +482,8 @@ static DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh,
        int gridFaces = gridSize - 1;
        int edgeBase, faceBase;
        int i, j, k, S, x, y, index;
+       int *vertIdx = NULL;
+       V_DECLARE(vertIdx);
        CCGVertIterator *vi;
        CCGEdgeIterator *ei;
        CCGFaceIterator *fi;
@@ -515,7 +519,7 @@ static DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh,
                edgeMap2[GET_INT_FROM_POINTER(ccgSubSurf_getEdgeEdgeHandle(e))] = e;
        }
 
-       totface = ccgSubSurf_getNumFaces(ss);
+       totface = ccgSubSurf_getNumTessFaces(ss);
        faceMap2 = MEM_mallocN(totface*sizeof(*faceMap2), "facemap");
        fi = ccgSubSurf_getFaceIterator(ss);
        for(; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) {
@@ -528,17 +532,17 @@ static DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh,
        if(ms) {
                result = MultiresDM_new(ms, dm, ccgSubSurf_getNumFinalVerts(ss),
                                        ccgSubSurf_getNumFinalEdges(ss),
-                                       ccgSubSurf_getNumFinalFaces(ss));
+                                       ccgSubSurf_getNumFinalFaces(ss), 0, 0);
        }
        else {
                if(dm) {
                        result = CDDM_from_template(dm, ccgSubSurf_getNumFinalVerts(ss),
                                                    ccgSubSurf_getNumFinalEdges(ss),
-                                                   ccgSubSurf_getNumFinalFaces(ss));
+                                                   ccgSubSurf_getNumFinalFaces(ss), 0, 0);
                } else {
                        result = CDDM_new(ccgSubSurf_getNumFinalVerts(ss),
                                          ccgSubSurf_getNumFinalEdges(ss),
-                                         ccgSubSurf_getNumFinalFaces(ss));
+                                         ccgSubSurf_getNumFinalFaces(ss), 0, 0);
                }
        }
 
@@ -551,10 +555,12 @@ static DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh,
                CCGFace *f = faceMap2[index];
                int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f);
                FaceVertWeight *weight = (numVerts == 4) ? qweight : tweight;
-               int vertIdx[4];
+
+               V_RESET(vertIdx);
 
                for(S = 0; S < numVerts; S++) {
                        CCGVert *v = ccgSubSurf_getFaceVert(ss, f, S);
+                       V_GROW(vertIdx);
 
                        vertIdx[S] = GET_INT_FROM_POINTER(ccgSubSurf_getVertVertHandle(v));
                }
@@ -736,9 +742,10 @@ static DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh,
 
        // load faces
        i = 0;
-       mf = CDDM_get_faces(result);
-       origIndex = result->getFaceData(result, 0, CD_ORIGINDEX);
+       mf = CDDM_get_tessfaces(result);
+       origIndex = result->getTessFaceData(result, 0, CD_ORIGINDEX);
 
+#if 0 //BMESH_TODO
        for(index = 0; index < totface; index++) {
                CCGFace *f = faceMap2[index];
                int numVerts = ccgSubSurf_getFaceNumVerts(f);
@@ -749,7 +756,7 @@ static DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh,
 
                if(!ssFromEditmesh) {
                        MFace origMFace;
-                       dm->getFace(dm, faceIdx, &origMFace);
+                       dm->getTessFace(dm, faceIdx, &origMFace);
                        
                        mat_nr = origMFace.mat_nr;
                        flag = origMFace.flag;
@@ -788,7 +795,7 @@ static DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh,
                                                        w[j][otherS] = (*weight)[j][3];
                                                }
 
-                                               DM_interp_face_data(dm, result, &faceIdx, NULL,
+                                               DM_interp_tessface_data(dm, result, &faceIdx, NULL,
                                                                    &w, 1, i);
                                                weight++;
                                        }
@@ -801,6 +808,7 @@ static DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh,
                        }
                }
        }
+#endif
 
        MEM_freeN(faceMap2);
        MEM_freeN(edgeMap2);
@@ -808,6 +816,8 @@ static DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh,
 
        MEM_freeN(tweight);
        MEM_freeN(qweight);
+       
+       V_FREE(vertIdx);
 
        if(useSubsurfUv) {
                CustomData *fdata = &result->faceData;
@@ -828,18 +838,22 @@ static void ss_sync_from_derivedmesh(CCGSubSurf *ss, DerivedMesh *dm,
                                      float (*vertexCos)[3], int useFlatSubdiv)
 {
        float creaseFactor = (float) ccgSubSurf_getSubdivisionLevels(ss);
-       CCGVertHDL fVerts[4];
+       CCGVertHDL *fVerts = NULL;
+       V_DECLARE(fVerts);
        int totvert = dm->getNumVerts(dm);
        int totedge = dm->getNumEdges(dm);
-       int totface = dm->getNumFaces(dm);
+       int totface = dm->getNumTessFaces(dm);
+       int totpoly = dm->getNumFaces(dm);
        int i;
        int *index;
        MVert *mvert = dm->getVertArray(dm);
        MEdge *medge = dm->getEdgeArray(dm);
-       MFace *mface = dm->getFaceArray(dm);
+       MFace *mface = dm->getTessFaceArray(dm);
        MVert *mv;
        MEdge *me;
        MFace *mf;
+       DMFaceIter *fiter;
+       DMLoopIter *liter;
 
        ccgSubSurf_initFullSync(ss);
 
@@ -871,28 +885,31 @@ static void ss_sync_from_derivedmesh(CCGSubSurf *ss, DerivedMesh *dm,
 
                ((int*)ccgSubSurf_getEdgeUserData(ss, e))[1] = *index;
        }
-
-       mf = mface;
-       index = (int *)dm->getFaceDataArray(dm, CD_ORIGINDEX);
-       for (i = 0; i < totface; i++, mf++, index++) {
+       
+       fiter = dm->newFaceIter(dm);
+       for (i=0; !fiter->done; fiter->step(fiter), i++) {
                CCGFace *f;
+               V_RESET(fVerts);
 
-               fVerts[0] = SET_INT_IN_POINTER(mf->v1);
-               fVerts[1] = SET_INT_IN_POINTER(mf->v2);
-               fVerts[2] = SET_INT_IN_POINTER(mf->v3);
-               fVerts[3] = SET_INT_IN_POINTER(mf->v4);
+               index = (int*) fiter->getCDData(fiter, CD_ORIGINDEX, -1);
+               liter = fiter->getLoopsIter(fiter);
 
-               // this is very bad, means mesh is internally consistent.
-               // it is not really possible to continue without modifying
-               // other parts of code significantly to handle missing faces.
-               // since this really shouldn't even be possible we just bail.
-               if(ccgSubSurf_syncFace(ss, SET_INT_IN_POINTER(i), fVerts[3] ? 4 : 3,
+               for (; !liter->done; liter->step(liter)) {
+                       V_GROW(fVerts);
+                       fVerts[V_COUNT(fVerts)-1] = SET_INT_IN_POINTER(liter->vindex);
+               }
+
+               /* this is very bad, means mesh is internally inconsistent.
+                * it is not really possible to continue without modifying
+                * other parts of code significantly to handle missing faces.
+                * since this really shouldn't even be possible we just bail.*/
+               if(ccgSubSurf_syncFace(ss, SET_INT_IN_POINTER(i), fiter->len, 
                                       fVerts, &f) == eCCGError_InvalidValue) {
                        static int hasGivenError = 0;
 
                        if(!hasGivenError) {
-                               //XXX error("Unrecoverable error in SubSurf calculation,"
-                               //      " mesh is inconsistent.");
+                               printf("Unrecoverable error in SubSurf calculation,"
+                                      " mesh is inconsistent.\n");
 
                                hasGivenError = 1;
                        }
@@ -974,7 +991,7 @@ static int ccgDM_getNumEdges(DerivedMesh *dm) {
 
        return ccgSubSurf_getNumFinalEdges(ccgdm->ss);
 }
-static int ccgDM_getNumFaces(DerivedMesh *dm) {
+static int ccgDM_getNumTessFaces(DerivedMesh *dm) {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
 
        return ccgSubSurf_getNumFinalFaces(ccgdm->ss);
@@ -988,9 +1005,9 @@ static void ccgDM_getFinalVert(DerivedMesh *dm, int vertNum, MVert *mv)
 
        memset(mv, 0, sizeof(*mv));
 
-       if((vertNum < ccgdm->edgeMap[0].startVert) && (ccgSubSurf_getNumFaces(ss) > 0)) {
+       if((vertNum < ccgdm->edgeMap[0].startVert) && (ccgSubSurf_getNumTessFaces(ss) > 0)) {
                /* this vert comes from face data */
-               int lastface = ccgSubSurf_getNumFaces(ss) - 1;
+               int lastface = ccgSubSurf_getNumTessFaces(ss) - 1;
                CCGFace *f;
                int x, y, grid, numVerts;
                int offset;
@@ -1063,7 +1080,7 @@ static void ccgDM_getFinalEdge(DerivedMesh *dm, int edgeNum, MEdge *med)
 
        if(edgeNum < ccgdm->edgeMap[0].startEdge) {
                /* this edge comes from face data */
-               int lastface = ccgSubSurf_getNumFaces(ss) - 1;
+               int lastface = ccgSubSurf_getNumTessFaces(ss) - 1;
                CCGFace *f;
                int x, y, grid, numVerts;
                int offset;
@@ -1145,8 +1162,8 @@ static void ccgDM_getFinalFace(DerivedMesh *dm, int faceNum, MFace *mf)
        int offset;
        int grid;
        int x, y;
-       int lastface = ccgSubSurf_getNumFaces(ss) - 1;
-       char *faceFlags = dm->getFaceDataArray(dm, CD_FLAGS);
+       int lastface = ccgSubSurf_getNumTessFaces(ss) - 1;
+       char *faceFlags = dm->getTessFaceDataArray(dm, CD_FLAGS);
 
        memset(mf, 0, sizeof(*mf));
 
@@ -1182,7 +1199,7 @@ static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert)
        int edgeSize = ccgSubSurf_getEdgeSize(ss);
        int i = 0;
 
-       totface = ccgSubSurf_getNumFaces(ss);
+       totface = ccgSubSurf_getNumTessFaces(ss);
        for(index = 0; index < totface; index++) {
                CCGFace *f = ccgdm->faceMap[index].face;
                int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f);
@@ -1237,7 +1254,7 @@ static void ccgDM_copyFinalEdgeArray(DerivedMesh *dm, MEdge *medge)
        int i = 0;
        int *edgeFlags = dm->getEdgeDataArray(dm, CD_FLAGS);
 
-       totface = ccgSubSurf_getNumFaces(ss);
+       totface = ccgSubSurf_getNumTessFaces(ss);
        for(index = 0; index < totface; index++) {
                CCGFace *f = ccgdm->faceMap[index].face;
                int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f);
@@ -1307,6 +1324,133 @@ static void ccgDM_copyFinalEdgeArray(DerivedMesh *dm, MEdge *medge)
        }
 }
 
+struct ccgDM_faceIter;
+
+typedef struct ccgDM_loopIter {
+       DMLoopIter head;
+       int curloop;
+       CCGDerivedMesh *ccgdm;
+       struct ccgDM_faceIter *fiter;
+} ccgDM_loopIter;
+
+typedef struct ccgDM_faceIter {
+       DMFaceIter head;
+       CCGDerivedMesh *ccgdm;
+       MFace mface;
+
+       ccgDM_loopIter liter;
+} ccgDM_faceIter;
+
+void ccgDM_faceIterStep(void *self)
+{
+       ccgDM_faceIter *fiter = self;
+
+       if (fiter->head.index >= ccgSubSurf_getNumTessFaces(fiter->ccgdm->ss)) {
+               fiter->head.done = 1;
+               return;
+       };
+
+       fiter->head.index++;
+       
+       ccgDM_getFinalFace((DerivedMesh*)fiter->ccgdm, fiter->head.index, &fiter->mface);
+
+       fiter->head.flags = fiter->mface.flag;
+       fiter->head.mat_nr = fiter->mface.mat_nr;
+       fiter->head.len = fiter->mface.v4 ? 4 : 3;
+}
+
+void ccgDM_faceIterCData(void *self, int type, int layer)
+{
+       ccgDM_faceIter *fiter = self;
+       
+       if (layer == -1) 
+               return CustomData_get(&fiter->ccgdm->dm.faceData, fiter->head.index, type);
+       else
+               return CustomData_get_n(&fiter->ccgdm->dm.faceData, type, fiter->head.index, layer);
+}
+
+void ccgDM_loopIterStep(void *self)
+{
+       ccgDM_loopIter *liter = self;
+       MFace *mf = &liter->fiter->mface;
+       int i, in;
+
+       if (liter->head.index >= liter->fiter->head.len) {
+               liter->head.done = 1;
+               return;
+       }
+
+       liter->head.index++;
+       i = liter->head.index;
+
+       switch (i) {
+               case 0:
+                       in = liter->fiter->mface.v1;
+                       break;
+               case 1:
+                       in = liter->fiter->mface.v2;
+                       break;
+               case 2:
+                       in = liter->fiter->mface.v3;
+                       break;
+               case 3:
+                       in = liter->fiter->mface.v4;
+                       break;
+       }
+
+       liter->head.vindex = in;
+       /*we don't set .eindex*/
+       ccgDM_getFinalVert((DerivedMesh*)liter->ccgdm, in, &liter->head.v);
+       
+}
+
+void *ccgDM_loopIterGetVCData(void *self, int type, int layer)
+{
+       ccgDM_loopIter *liter = self;
+
+       if (layer == -1)
+               return CustomData_get(&liter->ccgdm->dm.vertData, liter->head.index, type);
+       else return CustomData_get_n(&liter->ccgdm->dm.vertData, type, liter->head.index, layer);
+}
+
+void *ccgDM_loopIterGetCData(void *self, int type, int layer)
+{
+       ccgDM_loopIter *liter = self;
+       
+       /*BMESH_TODO
+         yeek, this has to convert mface-style uv/mcols to loop-style*/
+       return NULL;
+}
+
+DMLoopIter *ccgDM_faceIterGetLIter(void *self)
+{
+       ccgDM_faceIter *fiter = self;
+       
+       fiter->liter.head.index = -1;
+       fiter->liter.head.done = 0;
+       fiter->liter.head.step(&fiter->liter);
+
+       return (DMLoopIter*) &fiter->liter;
+}
+
+DMFaceIter *ccgDM_newFaceIter(DerivedMesh *dm)
+{
+       ccgDM_faceIter *fiter = MEM_callocN(sizeof(ccgDM_faceIter), "ccgDM_faceIter");
+       
+       fiter->head.free = MEM_freeN;
+       fiter->head.step = ccgDM_faceIterStep;
+       fiter->head.index = -1;
+       fiter->head.getCDData = ccgDM_faceIterCData;
+       fiter->head.getLoopsIter = ccgDM_faceIterGetLIter;
+
+       fiter->liter.fiter = fiter;
+       fiter->liter.head.getLoopCDData = ccgDM_loopIterGetCData;
+       fiter->liter.head.getVertCDData = ccgDM_loopIterGetVCData;
+       fiter->liter.head.step = ccgDM_loopIterStep;
+
+       fiter->head.step(fiter);
+}
+
 static void ccgDM_copyFinalFaceArray(DerivedMesh *dm, MFace *mface)
 {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
@@ -1316,9 +1460,9 @@ static void ccgDM_copyFinalFaceArray(DerivedMesh *dm, MFace *mface)
        int gridSize = ccgSubSurf_getGridSize(ss);
        int edgeSize = ccgSubSurf_getEdgeSize(ss);
        int i = 0;
-       char *faceFlags = dm->getFaceDataArray(dm, CD_FLAGS);
+       char *faceFlags = dm->getTessFaceDataArray(dm, CD_FLAGS);
 
-       totface = ccgSubSurf_getNumFaces(ss);
+       totface = ccgSubSurf_getNumTessFaces(ss);
        for(index = 0; index < totface; index++) {
                CCGFace *f = ccgdm->faceMap[index].face;
                int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f);
@@ -1381,7 +1525,7 @@ static void ccgdm_getVertCos(DerivedMesh *dm, float (*cos)[3]) {
                edgeMap2[GET_INT_FROM_POINTER(ccgSubSurf_getEdgeEdgeHandle(e))] = e;
        }
 
-       totface = ccgSubSurf_getNumFaces(ss);
+       totface = ccgSubSurf_getNumTessFaces(ss);
        faceMap2 = MEM_mallocN(totface*sizeof(*faceMap2), "facemap");
        fi = ccgSubSurf_getFaceIterator(ss);
        for (; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) {
@@ -1689,7 +1833,7 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, v
        CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss);
        GPUVertexAttribs gattribs;
        DMVertexAttribs attribs;
-       MTFace *tf = dm->getFaceDataArray(dm, CD_MTFACE);
+       MTFace *tf = dm->getTessFaceDataArray(dm, CD_MTFACE);
        int gridSize = ccgSubSurf_getGridSize(ss);
        int gridFaces = gridSize - 1;
        int edgeSize = ccgSubSurf_getEdgeSize(ss);
@@ -1726,7 +1870,7 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, v
        }                                                                                                                                                       \
 }
 
-       totface = ccgSubSurf_getNumFaces(ss);
+       totface = ccgSubSurf_getNumTessFaces(ss);
        for(a = 0, i = 0; i < totface; i++) {
                CCGFace *f = ccgdm->faceMap[i].face;
                int S, x, y, drawSmooth;
@@ -1921,7 +2065,7 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm,
        int i, totface, flag, gridSize = ccgSubSurf_getGridSize(ss);
        int gridFaces = gridSize - 1;
 
-       totface = ccgSubSurf_getNumFaces(ss);
+       totface = ccgSubSurf_getNumTessFaces(ss);
        for(i = 0; i < totface; i++) {
                CCGFace *f = ccgdm->faceMap[i].face;
                int S, x, y, numVerts = ccgSubSurf_getFaceNumVerts(f);
@@ -2053,7 +2197,7 @@ static void ccgDM_drawMappedFacesTex(DerivedMesh *dm, int (*setDrawOptions)(void
 static void ccgDM_drawUVEdges(DerivedMesh *dm)
 {
 
-       MFace *mf = dm->getFaceArray(dm);
+       MFace *mf = dm->getTessFaceArray(dm);
        MTFace *tf = DM_get_face_data_layer(dm, CD_MTFACE);
        int i;
        
@@ -2088,7 +2232,7 @@ static void ccgDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *u
        CCGSubSurf *ss = ccgdm->ss;
        CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss);
        int i, gridSize = ccgSubSurf_getGridSize(ss);
-       char *faceFlags = dm->getFaceDataArray(dm, CD_FLAGS);
+       char *faceFlags = dm->getTessFaceDataArray(dm, CD_FLAGS);
 
        for (i=0; !ccgFaceIterator_isStopped(fi); i++,ccgFaceIterator_next(fi)) {
                CCGFace *f = ccgFaceIterator_getCurrent(fi);
@@ -2273,6 +2417,8 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
        int edgeSize;
        int gridSize;
        int gridFaces;
+       int *vertIdx = NULL;
+       V_DECLARE(vertIdx);
        int gridSideVerts;
        /*int gridInternalVerts; - as yet unused */
        int gridSideEdges;
@@ -2284,7 +2430,8 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
 
        DM_from_template(&ccgdm->dm, dm, ccgSubSurf_getNumFinalVerts(ss),
                                         ccgSubSurf_getNumFinalEdges(ss),
-                                        ccgSubSurf_getNumFinalFaces(ss));
+                                        ccgSubSurf_getNumFinalFaces(ss),
+                                        0, 0);
        DM_add_face_layer(&ccgdm->dm, CD_FLAGS, CD_CALLOC, NULL);
        DM_add_edge_layer(&ccgdm->dm, CD_FLAGS, CD_CALLOC, NULL);
 
@@ -2293,21 +2440,24 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
 
        ccgdm->dm.getMinMax = ccgDM_getMinMax;
        ccgdm->dm.getNumVerts = ccgDM_getNumVerts;
-       ccgdm->dm.getNumFaces = ccgDM_getNumFaces;
+       ccgdm->dm.getNumTessFaces = ccgDM_getNumTessFaces;
+       ccgdm->dm.getNumFaces = ccgDM_getNumTessFaces;
+
+       ccgdm->dm.newFaceIter = ccgDM_newFaceIter;
 
        ccgdm->dm.getNumEdges = ccgDM_getNumEdges;
        ccgdm->dm.getVert = ccgDM_getFinalVert;
        ccgdm->dm.getEdge = ccgDM_getFinalEdge;
-       ccgdm->dm.getFace = ccgDM_getFinalFace;
+       ccgdm->dm.getTessFace = ccgDM_getFinalFace;
        ccgdm->dm.copyVertArray = ccgDM_copyFinalVertArray;
        ccgdm->dm.copyEdgeArray = ccgDM_copyFinalEdgeArray;
-       ccgdm->dm.copyFaceArray = ccgDM_copyFinalFaceArray;
+       ccgdm->dm.copyTessFaceArray = ccgDM_copyFinalFaceArray;
        ccgdm->dm.getVertData = DM_get_vert_data;
        ccgdm->dm.getEdgeData = DM_get_edge_data;
-       ccgdm->dm.getFaceData = DM_get_face_data;
+       ccgdm->dm.getTessFaceData = DM_get_face_data;
        ccgdm->dm.getVertDataArray = DM_get_vert_data_layer;
        ccgdm->dm.getEdgeDataArray = DM_get_edge_data_layer;
-       ccgdm->dm.getFaceDataArray = DM_get_face_data_layer;
+       ccgdm->dm.getTessFaceDataArray = DM_get_face_data_layer;
 
        ccgdm->dm.getVertCos = ccgdm_getVertCos;
        ccgdm->dm.foreachMappedVert = ccgDM_foreachMappedVert;
@@ -2354,7 +2504,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
                ccgdm->edgeMap[GET_INT_FROM_POINTER(ccgSubSurf_getEdgeEdgeHandle(e))].edge = e;
        }
 
-       totface = ccgSubSurf_getNumFaces(ss);
+       totface = ccgSubSurf_getNumTessFaces(ss);
        ccgdm->faceMap = MEM_mallocN(totface * sizeof(*ccgdm->faceMap), "faceMap");
        fi = ccgSubSurf_getFaceIterator(ss);
        for(; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) {
@@ -2380,7 +2530,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
 
        /* mvert = dm->getVertArray(dm); - as yet unused */
        medge = dm->getEdgeArray(dm);
-       mface = dm->getFaceArray(dm);
+       mface = dm->getTessFaceArray(dm);
 
        vertOrigIndex = DM_get_vert_data_layer(&ccgdm->dm, CD_ORIGINDEX);
        /*edgeOrigIndex = DM_get_edge_data_layer(&ccgdm->dm, CD_ORIGINDEX);*/
@@ -2396,7 +2546,6 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
                int origIndex = GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(ss, f));
                FaceVertWeight *weight = (numVerts == 4) ? qweight : tweight;
                int S, x, y;
-               int vertIdx[4];
 
                ccgdm->faceMap[index].startVert = vertNum;
                ccgdm->faceMap[index].startEdge = edgeNum;
@@ -2404,9 +2553,11 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
 
                /* set the face base vert */
                *((int*)ccgSubSurf_getFaceUserData(ss, f)) = vertNum;
-
+               
+               V_RESET(vertIdx);
                for(S = 0; S < numVerts; S++) {
                        CCGVert *v = ccgSubSurf_getFaceVert(ss, f, S);
+                       V_GROW(vertIdx);
 
                        vertIdx[S] = GET_INT_FROM_POINTER(ccgSubSurf_getVertVertHandle(v));
                }
@@ -2459,6 +2610,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
                        *(int *)DM_get_edge_data(&ccgdm->dm, edgeNum + i,
                                                 CD_ORIGINDEX) = ORIGINDEX_NONE;
 
+#if 0 //BMESH_TODO
                for(S = 0; S < numVerts; S++) {
                        int prevS = (S - 1 + numVerts) % numVerts;
                        int nextS = (S + 1) % numVerts;
@@ -2478,7 +2630,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
                                                w[j][otherS] = (*weight)[j][3];
                                        }
 
-                                       DM_interp_face_data(dm, &ccgdm->dm, &origIndex, NULL,
+                                       DM_interp_tessface_data(dm, &ccgdm->dm, &origIndex, NULL,
                                                            &w, 1, faceNum);
                                        weight++;
 
@@ -2489,6 +2641,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
                                }
                        }
                }
+#endif
 
                faceFlags[index*4] = mface[origIndex].flag;
                faceFlags[index*4 + 1] = mface[origIndex].mat_nr;
@@ -2571,6 +2724,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
        MEM_freeN(qweight);
        MEM_freeN(tweight);
 
+       V_FREE(vertIdx);
        return ccgdm;
 }
 
index 02b37cf1b77289513e4818335b2274742a63bf2e..6aca2ee843e69250786fa4d91e1ebeb4ca713e94 100644 (file)
@@ -319,6 +319,9 @@ BMesh *init_editmesh_to_bmesh(struct EditMesh *em, struct BMOperator *op);
 /*converts a bmesh to an editmesh*/
 struct EditMesh *bmesh_to_editmesh(BMesh *bm);
 
+/*convert between bmesh and Mesh flags*/
+int BMFlags_To_MEFlags(void *element);
+
 /*include the rest of the API*/
 #include "bmesh_filters.h"
 #include "bmesh_iterators.h"
index fc06148296a60a75ea7ba216f3b6b8864a86acd7..d224979cc09e38a2b30afbdbf0e15ed63cd75369 100644 (file)
@@ -34,6 +34,9 @@
 #include "BKE_customdata.h" 
 #include "BKE_utildefines.h"
 
+#include "DNA_meshdata_types.h"
+#include "DNA_mesh_types.h"
+
 #include "bmesh.h"
 #include "bmesh_private.h"
 
@@ -483,3 +486,25 @@ BMesh *BM_Copy_Mesh(BMesh *bmold)
 
        return bm;
 }
+
+int BMFlags_To_MEFlags(void *element) {
+       BMHeader *h = element;
+       int f = 0;
+
+       if (h->flag & BM_HIDDEN) f |= ME_HIDE;
+
+       if (h->type == BM_FACE) {
+               if (h->flag & BM_SELECT) f |= ME_FACE_SEL;
+               if (h->flag & BM_SMOOTH) f |= ME_SMOOTH;
+       } else if (h->type == BM_EDGE) {
+               if (h->flag & BM_SELECT) f |= BM_SELECT;
+               if (h->flag & BM_SEAM) f |= ME_SEAM;
+               if (h->flag & BM_SHARP) f |= ME_SHARP;
+               if (BM_Wire_Edge(NULL, element)) f |= ME_LOOSEEDGE;
+       } else if (h->type == BM_VERT) {
+               if (h->flag & BM_SELECT) f |= BM_SELECT;
+               if (h->flag & BM_HIDDEN) f |= ME_HIDE;
+       }
+
+       return f;
+}
\ No newline at end of file
index 8807b21e65323e7f855099a8aac9256fc8331142..83179dd3843ae2a9d1ae7c11197148b40e180ad0 100644 (file)
@@ -1151,8 +1151,8 @@ static void meshdeform_ray_tree_create(MeshDeformBind *mdb)
 
        MESHDEFORM_BIND= mdb;
 
-       mface= mdb->cagedm->getFaceArray(mdb->cagedm);
-       totface= mdb->cagedm->getNumFaces(mdb->cagedm);
+       mface= mdb->cagedm->getTessFaceArray(mdb->cagedm);
+       totface= mdb->cagedm->getNumTessFaces(mdb->cagedm);
 
        mdb->raytree= RE_ray_tree_create(64, totface, min, max,
                meshdeform_ray_coords_func, meshdeform_ray_check_func);
@@ -1178,8 +1178,8 @@ static int meshdeform_intersect(MeshDeformBind *mdb, Isect *isec)
 
        isec->labda= 1e10;
 
-       mface= mdb->cagedm->getFaceArray(mdb->cagedm);
-       totface= mdb->cagedm->getNumFaces(mdb->cagedm);
+       mface= mdb->cagedm->getTessFaceArray(mdb->cagedm);
+       totface= mdb->cagedm->getNumTessFaces(mdb->cagedm);
 
        for(f=0; f<totface; f++, mface++) {
                VECCOPY(face[0], mdb->cagecos[mface->v1]);
index 766615f0c7c4156ce06e45a5374744ac47de12fa..8427ab608e3b57a51ae7d87dab5a60b3835308eb 100644 (file)
@@ -1120,7 +1120,7 @@ static void erase_vertices(EditMesh *em, ListBase *l)
        }
 }
 
-static int delete_mesh(Object *obedit, wmOperator *op, int event)
+static int delete_mesh(Object *obedit, wmOperator *op, int event, Scene *scene)
 {
        BMEditMesh *bem = ((Mesh*)obedit->data)->edit_btmesh;
        EditMesh *em = NULL;
@@ -1275,8 +1275,8 @@ static int delete_mesh(Object *obedit, wmOperator *op, int event)
                str= "Erase Only Faces";
        }
        
+       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        return OPERATOR_FINISHED;
-//     DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
 }
 
 /* Note, these values must match delete_mesh() event values */
@@ -1295,8 +1295,9 @@ static EnumPropertyItem prop_mesh_delete_types[] = {
 static int delete_mesh_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       
-       delete_mesh(obedit, op, RNA_enum_get(op->ptr, "type"));
+       Scene *scene = CTX_data_scene(C);
+
+       delete_mesh(obedit, op, RNA_enum_get(op->ptr, "type"), scene);
        
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
        
index 1c2b3c6b309dab35e021df5bf8d72b8056ff3805..232082855cb6b7b382d7f42c37c5f8c705f50297 100644 (file)
@@ -999,7 +999,7 @@ static void recalc_emitter_field(Object *ob, ParticleSystem *psys)
 
        BLI_kdtree_free(edit->emitter_field);
 
-       totface=dm->getNumFaces(dm);
+       totface=dm->getNumTessFaces(dm);
        totvert=dm->getNumVerts(dm);
 
        edit->emitter_cosnos=MEM_callocN(totface*6*sizeof(float),"emitter cosnos");
@@ -1011,7 +1011,7 @@ static void recalc_emitter_field(Object *ob, ParticleSystem *psys)
 
        mvert=dm->getVertDataArray(dm,CD_MVERT);
        for(i=0; i<totface; i++, vec+=6, nor+=6) {
-               mface=dm->getFaceData(dm,i,CD_MFACE);
+               mface=dm->getTessFaceData(dm,i,CD_MFACE);
 
                mvert=dm->getVertData(dm,mface->v1,CD_MVERT);
                VECCOPY(vec,mvert->co);
index 77cd06581fd48a04311ca5b1e451590bab712cb2..5e830af5c085fdfd7bb467ece5c8cdf2e11c2c58 100644 (file)
@@ -2929,11 +2929,11 @@ static void project_paint_begin(ProjPaintState *ps)
                return; 
        }
        ps->dm_mvert = ps->dm->getVertArray(ps->dm);
-       ps->dm_mface = ps->dm->getFaceArray(ps->dm);
-       ps->dm_mtface= ps->dm->getFaceDataArray(ps->dm, CD_MTFACE);
+       ps->dm_mface = ps->dm->getTessFaceArray(ps->dm);
+       ps->dm_mtface= ps->dm->getTessFaceDataArray(ps->dm, CD_MTFACE);
        
        ps->dm_totvert = ps->dm->getNumVerts(ps->dm);
-       ps->dm_totface = ps->dm->getNumFaces(ps->dm);
+       ps->dm_totface = ps->dm->getNumTessFaces(ps->dm);
        
        /* use clone mtface? */
        
index 85ea55331dcb416f90c45d8e38818b8c34ec29da..46d41c043bdb2b2514e72cb5f72097a6c60612e7 100644 (file)
@@ -80,9 +80,9 @@ static void imapaint_tri_weights(Object *ob, float *v1, float *v2, float *v3, fl
 void imapaint_pick_uv(Scene *scene, Object *ob, Mesh *mesh, unsigned int faceindex, int *xy, float *uv)
 {
        DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
-       int *index = dm->getFaceDataArray(dm, CD_ORIGINDEX);
-       MTFace *tface = dm->getFaceDataArray(dm, CD_MTFACE), *tf;
-       int numfaces = dm->getNumFaces(dm), a;
+       int *index = dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
+       MTFace *tface = dm->getTessFaceDataArray(dm, CD_MTFACE), *tf;
+       int numfaces = dm->getNumTessFaces(dm), a;
        float p[2], w[3], absw, minabsw;
        MFace mf;
        MVert mv[4];
@@ -93,7 +93,7 @@ void imapaint_pick_uv(Scene *scene, Object *ob, Mesh *mesh, unsigned int faceind
        /* test all faces in the derivedmesh with the original index of the picked face */
        for(a = 0; a < numfaces; a++) {
                if(index[a] == faceindex) {
-                       dm->getFace(dm, a, &mf);
+                       dm->getTessFace(dm, a, &mf);
 
                        dm->getVert(dm, mf.v1, &mv[0]);
                        dm->getVert(dm, mf.v2, &mv[1]);
index 8f1e382631428b6b220f00cda0a095b7390c6f89..cdac40e6cd9a08cc0aa9d289d84c14d50b46419e 100644 (file)
@@ -1068,10 +1068,10 @@ static void sculpt_update_mesh_elements(bContext *C)
        if((ss->multires = sculpt_multires_active(ob))) {
                DerivedMesh *dm = mesh_get_derived_final(CTX_data_scene(C), ob, CD_MASK_BAREMESH);
                ss->totvert = dm->getNumVerts(dm);
-               ss->totface = dm->getNumFaces(dm);
+               ss->totface = dm->getNumTessFaces(dm);
                ss->mvert = dm->getVertDataArray(dm, CD_MVERT);
-               ss->mface = dm->getFaceDataArray(dm, CD_MFACE);
-               ss->face_normals = dm->getFaceDataArray(dm, CD_NORMAL);
+               ss->mface = dm->getTessFaceDataArray(dm, CD_MFACE);
+               ss->face_normals = dm->getTessFaceDataArray(dm, CD_NORMAL);
        }
        else {
                Mesh *me = get_mesh(ob);
index 12e20728c62d1647d2fa839361d5a7d1c8b66641..ffece48dc959250a9a0cf9a075c3666c68de061f 100644 (file)
@@ -2327,7 +2327,7 @@ static void draw_mesh_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base
        
        totvert = dm->getNumVerts(dm);
        totedge = dm->getNumEdges(dm);
-       totface = dm->getNumFaces(dm);
+       totface = dm->getNumTessFaces(dm);
        
        /* vertexpaint, faceselect wants this, but it doesnt work for shaded? */
        if(dt!=OB_SHADED)
index 8dd203d95cee0f75fd1699ab28c1cb7b125ed515..ad8ef95a870bf93d0a0eb6e541c8320eb9ce2517 100644 (file)
@@ -1116,7 +1116,7 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, B
 {
        int retval = 0;
        int totvert = dm->getNumVerts(dm);
-       int totface = dm->getNumFaces(dm);
+       int totface = dm->getNumTessFaces(dm);
        
        if (totvert > 0) {
                float imat[4][4];
@@ -1151,14 +1151,14 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, B
                                case SCE_SNAP_MODE_FACE:
                                { 
                                        MVert *verts = dm->getVertArray(dm);
-                                       MFace *faces = dm->getFaceArray(dm);
+                                       MFace *faces = dm->getTessFaceArray(dm);
                                        int *index_array = NULL;
                                        int index = 0;
                                        int i;
                                        
                                        if (em != NULL)
                                        {
-                                               index_array = dm->getFaceDataArray(dm, CD_ORIGINDEX);
+                                               index_array = dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
                                                EDBM_init_index_arrays(em, 0, 0, 1);
                                        }
                                        
@@ -1506,7 +1506,7 @@ int peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[][4], float ray_sta
 {
        int retval = 0;
        int totvert = dm->getNumVerts(dm);
-       int totface = dm->getNumFaces(dm);
+       int totface = dm->getNumTessFaces(dm);
        
        if (totvert > 0) {
                float imat[4][4];
@@ -1536,7 +1536,7 @@ int peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[][4], float ray_sta
                
                if (test == 1) {
                        MVert *verts = dm->getVertArray(dm);
-                       MFace *faces = dm->getFaceArray(dm);
+                       MFace *faces = dm->getTessFaceArray(dm);
                        int i;
                        
                        for( i = 0; i < totface; i++) {
index 4ca7244e976b67b7a4d30a269cd3eaa49c88be62..6e417a3bd57f09d59e45c777e3e1b7c50d50422d 100644 (file)
@@ -1402,7 +1402,7 @@ static void get_particle_uvco_mcol(short from, DerivedMesh *dm, float *fuv, int
        if(sd->uvco && ELEM(from,PART_FROM_FACE,PART_FROM_VOLUME)) {
                for(i=0; i<sd->totuv; i++) {
                        if(num != DMCACHE_NOTFOUND) {
-                               MFace *mface = dm->getFaceData(dm, num, CD_MFACE);
+                               MFace *mface = dm->getTessFaceData(dm, num, CD_MFACE);
                                MTFace *mtface = (MTFace*)CustomData_get_layer_n(&dm->faceData, CD_MTFACE, i);
                                mtface += num;
                                
@@ -1419,7 +1419,7 @@ static void get_particle_uvco_mcol(short from, DerivedMesh *dm, float *fuv, int
        if(sd->mcol && ELEM(from,PART_FROM_FACE,PART_FROM_VOLUME)) {
                for(i=0; i<sd->totcol; i++) {
                        if(num != DMCACHE_NOTFOUND) {
-                               MFace *mface = dm->getFaceData(dm, num, CD_MFACE);
+                               MFace *mface = dm->getTessFaceData(dm, num, CD_MFACE);
                                MCol *mc = (MCol*)CustomData_get_layer_n(&dm->faceData, CD_MCOL, i);
                                mc += num * 4;
 
@@ -1637,8 +1637,8 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
                                if(ma->amb != 0.0f)
                                        dosurfacecache= 1;
 
-                       totface= psmd->dm->getNumFaces(psmd->dm);
-                       origindex= psmd->dm->getFaceDataArray(psmd->dm, CD_ORIGINDEX);
+                       totface= psmd->dm->getNumTessFaces(psmd->dm);
+                       origindex= psmd->dm->getTessFaceDataArray(psmd->dm, CD_ORIGINDEX);
                        if(origindex) {
                                for(a=0; a<totface; a++)
                                        strandbuf->totbound= MAX2(strandbuf->totbound, origindex[a]);
@@ -1696,7 +1696,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
                        num= pa->num_dmcache;
 
                        if(num == DMCACHE_NOTFOUND)
-                               if(pa->num < psmd->dm->getNumFaces(psmd->dm))
+                               if(pa->num < psmd->dm->getNumTessFaces(psmd->dm))
                                        num= pa->num;
 
                        get_particle_uvco_mcol(part->from, psmd->dm, pa->fuv, num, &sd);
@@ -1769,7 +1769,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
                                num = parent->num_dmcache;
 
                                if(num == DMCACHE_NOTFOUND)
-                                       if(parent->num < psmd->dm->getNumFaces(psmd->dm))
+                                       if(parent->num < psmd->dm->getNumTessFaces(psmd->dm))
                                                num = parent->num;
 
                                get_particle_uvco_mcol(part->from, psmd->dm, pa->fuv, num, &sd);
@@ -2849,10 +2849,10 @@ static struct edgesort *make_mesh_edge_lookup(DerivedMesh *dm, int *totedgesort)
        unsigned int *mcol=NULL;
        int a, totedge=0, totface;
        
-       mface= dm->getFaceArray(dm);
-       totface= dm->getNumFaces(dm);
-       tface= dm->getFaceDataArray(dm, CD_MTFACE);
-       mcol= dm->getFaceDataArray(dm, CD_MCOL);
+       mface= dm->getTessFaceArray(dm);
+       totface= dm->getNumTessFaces(dm);
+       tface= dm->getTessFaceDataArray(dm, CD_MTFACE);
+       mcol= dm->getTessFaceDataArray(dm, CD_MCOL);
        
        if(mcol==NULL && tface==NULL) return NULL;
        
@@ -3028,7 +3028,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
        totvert= dm->getNumVerts(dm);
 
        /* attempt to autsmooth on original mesh, only without subsurf */
-       if(do_autosmooth && me->totvert==totvert && me->totface==dm->getNumFaces(dm))
+       if(do_autosmooth && me->totvert==totvert && me->totface==dm->getNumTessFaces(dm))
                use_original_normals= 1;
        
        ms = (totvert==me->totvert)?me->msticky:NULL;
@@ -3089,8 +3089,8 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
                                }
 
                                if(ok) {
-                                       end= dm->getNumFaces(dm);
-                                       mface= dm->getFaceArray(dm);
+                                       end= dm->getNumTessFaces(dm);
+                                       mface= dm->getTessFaceArray(dm);
 
                                        for(a=0; a<end; a++, mface++) {
                                                int v1, v2, v3, v4, flag;
index 3c8c1640b7585a1d4347a3e82e29d1867df84bf7..fc52f0fc9f4dfd1644c18b36b20e6637fb22c90e 100644 (file)
@@ -943,7 +943,7 @@ StrandSurface *cache_strand_surface(Render *re, ObjectRen *obr, DerivedMesh *dm,
        int a, totvert, totface;
 
        totvert= dm->getNumVerts(dm);
-       totface= dm->getNumFaces(dm);
+       totface= dm->getNumTessFaces(dm);
 
        for(mesh=re->strandsurface.first; mesh; mesh=mesh->next)
                if(mesh->obr.ob == obr->ob && mesh->obr.par == obr->par
@@ -975,7 +975,7 @@ StrandSurface *cache_strand_surface(Render *re, ObjectRen *obr, DerivedMesh *dm,
                Mat4MulVecfl(mat, co[a]);
        }
 
-       mface= dm->getFaceArray(dm);
+       mface= dm->getTessFaceArray(dm);
        for(a=0; a<mesh->totface; a++, mface++) {
                mesh->face[a][0]= mface->v1;
                mesh->face[a][1]= mface->v2;
index 5220361d10d5d8a1d4702d1b3f5651523e44f8c4..459415f86cdcfe39a34324b421e23ad8e94aa2f5 100644 (file)
@@ -734,16 +734,16 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
        MVert *mvert = dm->getVertArray(dm);
        int totvert = dm->getNumVerts(dm);
 
-       MFace *mface = dm->getFaceArray(dm);
-       MTFace *tface = static_cast<MTFace*>(dm->getFaceDataArray(dm, CD_MTFACE));
-       MCol *mcol = static_cast<MCol*>(dm->getFaceDataArray(dm, CD_MCOL));
+       MFace *mface = dm->getTessFaceArray(dm);
+       MTFace *tface = static_cast<MTFace*>(dm->getTessFaceDataArray(dm, CD_MTFACE));
+       MCol *mcol = static_cast<MCol*>(dm->getTessFaceDataArray(dm, CD_MCOL));
        float (*tangent)[3] = NULL;
-       int totface = dm->getNumFaces(dm);
+       int totface = dm->getNumTessFaces(dm);
        const char *tfaceName = "";
 
        if(tface) {
                DM_add_tangent_layer(dm);
-               tangent = (float(*)[3])dm->getFaceDataArray(dm, CD_TANGENT);
+               tangent = (float(*)[3])dm->getTessFaceDataArray(dm, CD_TANGENT);
        }
 
        // Determine if we need to make a skinned mesh