=bmesh=
authorJoseph Eagar <joeedh@gmail.com>
Tue, 14 Jun 2011 03:16:08 +0000 (03:16 +0000)
committerJoseph Eagar <joeedh@gmail.com>
Tue, 14 Jun 2011 03:16:08 +0000 (03:16 +0000)
Removed the DerivedMesh face iterators (they sucked).
This should make subsurf faster.  Also sped up multires
a bit (not sure if it's strictly correct, need to look
at it later).

source/blender/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/editderivedbmesh.c
source/blender/blenkernel/intern/modifiers_bmesh.c
source/blender/blenkernel/intern/multires.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/blenlib/BLI_edgehash.h
source/blender/editors/mesh/editface.c
source/blender/editors/sculpt_paint/sculpt.c

index 3bf7306bf12aacff2004017c6ec51469275abf51..bac5bd7d4e40ca06ae9249346167b3aa1d1e7fb4 100644 (file)
@@ -104,43 +104,6 @@ Note: all mface interfaces now officially operate on tesselated data.
       Also, the mface origindex layer indexes mpolys, not mfaces.
 */
 
-/*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;
-
-       /*you can set mat_nr and flags, and the backends 
-         must detect and update the internal faces*/
-       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 DMGridData {
        float co[3];
        float no[3];
@@ -170,9 +133,6 @@ struct DerivedMesh {
 
        /* Misc. Queries */
        
-       /*face iterator.  initializes iter.*/
-       DMFaceIter *(*newFaceIter)(DerivedMesh *dm);
-
        /*recalculates mesh tesselation*/
        void (*recalcTesselation)(DerivedMesh *dm);
 
@@ -199,6 +159,8 @@ struct DerivedMesh {
        struct MVert *(*getVertArray)(DerivedMesh *dm);
        struct MEdge *(*getEdgeArray)(DerivedMesh *dm);
        struct MFace *(*getTessFaceArray)(DerivedMesh *dm);
+       struct MLoop *(*getLoopArray)(DerivedMesh *dm);
+       struct MPoly *(*getPolyArray)(DerivedMesh *dm);
 
        /* copy all verts/edges/faces from the derived mesh into
         * *{vert/edge/face}_r (must point to a buffer large enough)
@@ -206,6 +168,8 @@ struct DerivedMesh {
        void (*copyVertArray)(DerivedMesh *dm, struct MVert *vert_r);
        void (*copyEdgeArray)(DerivedMesh *dm, struct MEdge *edge_r);
        void (*copyTessFaceArray)(DerivedMesh *dm, struct MFace *face_r);
+               void (*copyLoopArray)(DerivedMesh *dm, struct MLoop *loop_r);
+               void (*copyPolyArray)(DerivedMesh *dm, struct MPoly *poly_r);
 
        /* return a copy of all verts/edges/faces from the derived mesh
         * it is the caller's responsibility to free the returned pointer
@@ -213,6 +177,8 @@ struct DerivedMesh {
        struct MVert *(*dupVertArray)(DerivedMesh *dm);
        struct MEdge *(*dupEdgeArray)(DerivedMesh *dm);
        struct MFace *(*dupTessFaceArray)(DerivedMesh *dm);
+               struct MLoop *(*dupLoopArray)(DerivedMesh *dm);
+               struct MPoly *(*dupPolyArray)(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
index 62f9c65d2eae673f4b4bc426f343b07f24a450af..cb4627db7a78a98f2403ae7284e05ba3d269d9ff 100644 (file)
@@ -125,6 +125,34 @@ static MFace *dm_getFaceArray(DerivedMesh *dm)
        return mface;
 }
 
+static MLoop *dm_getLoopArray(DerivedMesh *dm)
+{
+       MLoop *mloop = CustomData_get_layer(&dm->loopData, CD_MLOOP);
+
+       if (!mloop) {
+               mloop = CustomData_add_layer(&dm->loopData, CD_MLOOP, CD_CALLOC, NULL,
+                       dm->numLoopData);
+               CustomData_set_layer_flag(&dm->loopData, CD_MLOOP, CD_FLAG_TEMPORARY);
+               dm->copyLoopArray(dm, mloop);
+       }
+
+       return mloop;
+}
+
+static MPoly *dm_getPolyArray(DerivedMesh *dm)
+{
+       MPoly *mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY);
+
+       if (!mpoly) {
+               mpoly = CustomData_add_layer(&dm->polyData, CD_MPOLY, CD_CALLOC, NULL,
+                       dm->getNumFaces(dm));
+               CustomData_set_layer_flag(&dm->polyData, CD_MPOLY, CD_FLAG_TEMPORARY);
+               dm->copyPolyArray(dm, mpoly);
+       }
+
+       return mpoly;
+}
+
 static MVert *dm_dupVertArray(DerivedMesh *dm)
 {
        MVert *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumVerts(dm),
@@ -155,6 +183,26 @@ static MFace *dm_dupFaceArray(DerivedMesh *dm)
        return tmp;
 }
 
+static MLoop *dm_dupLoopArray(DerivedMesh *dm)
+{
+       MLoop *tmp = MEM_callocN(sizeof(*tmp) * dm->numLoopData,
+                                                        "dm_dupLoopArray tmp");
+
+       if(tmp) dm->copyLoopArray(dm, tmp);
+
+       return tmp;
+}
+
+static MPoly *dm_dupPolyArray(DerivedMesh *dm)
+{
+       MPoly *tmp = MEM_callocN(sizeof(*tmp) * dm->numFaceData,
+                                                        "dm_dupPolyArray tmp");
+
+       if(tmp) dm->copyPolyArray(dm, tmp);
+
+       return tmp;
+}
+
 static CustomData *dm_getVertCData(DerivedMesh *dm)
 {
        return &dm->vertData;
@@ -186,9 +234,13 @@ void DM_init_funcs(DerivedMesh *dm)
        dm->getVertArray = dm_getVertArray;
        dm->getEdgeArray = dm_getEdgeArray;
        dm->getTessFaceArray = dm_getFaceArray;
+       dm->getLoopArray = dm_getLoopArray;
+       dm->getPolyArray = dm_getPolyArray;
        dm->dupVertArray = dm_dupVertArray;
        dm->dupEdgeArray = dm_dupEdgeArray;
        dm->dupTessFaceArray = dm_dupFaceArray;
+       dm->dupLoopArray = dm_dupLoopArray;
+       dm->dupPolyArray = dm_dupPolyArray;
 
        dm->getVertDataLayout = dm_getVertCData;
        dm->getEdgeDataLayout = dm_getEdgeCData;
@@ -272,105 +324,29 @@ int DM_release(DerivedMesh *dm)
        }
 }
 
-static void dm_add_polys_from_iter(CustomData *ldata, CustomData *pdata, DerivedMesh *dm, int totloop)
+void DM_DupPolys(DerivedMesh *source, DerivedMesh *target)
 {
-       DMFaceIter *iter = dm->newFaceIter(dm);
-       DMLoopIter *liter;
-       CustomData *oldata, *opdata;
-       MPoly *mpoly;
-       MLoop *mloop;
-       int p, l, i, j, lasttype;
-
-       oldata = dm->getLoopDataLayout(dm);
-       opdata = dm->getFaceDataLayout(dm);
-
-       CustomData_copy(oldata, ldata, CD_MASK_DERIVEDMESH, CD_CALLOC, totloop);
-       CustomData_copy(opdata, pdata, CD_MASK_DERIVEDMESH, CD_CALLOC, dm->getNumFaces(dm));
-
-       mloop = MEM_callocN(sizeof(MLoop)*totloop, "MLoop from dm_add_polys_from_iter");
-       CustomData_add_layer(ldata, CD_MLOOP, CD_ASSIGN, mloop, totloop);
-       mpoly = MEM_callocN(sizeof(MPoly)*dm->getNumFaces(dm), "MPoly from dm_add_polys_from_iter");
-       CustomData_add_layer(pdata, CD_MPOLY, CD_ASSIGN, mpoly, dm->getNumFaces(dm));
-
-       l = 0;
-       for (p=0; !iter->done; iter->step(iter), mpoly++, p++) {
-               mpoly->flag = iter->flags;
-               mpoly->loopstart = l;
-               mpoly->totloop = iter->len;
-               mpoly->mat_nr = iter->mat_nr;
-               
-               j = 0;
-               lasttype = -1;
-               for (i=0; i<opdata->totlayer; i++) {
-                       void *e1, *e2;
-
-                       if (opdata->layers[i].type == lasttype)
-                               j++;
-                       else
-                               j = 0;
+       CustomData_copy(&source->loopData, &target->loopData, CD_MASK_DERIVEDMESH, CD_CALLOC, source->numLoopData);
+       CustomData_copy(&source->polyData, &target->polyData, CD_MASK_DERIVEDMESH, CD_CALLOC, source->numPolyData);
 
-                       if (opdata->layers[i].type == CD_MPOLY)
-                               continue;
-                       
-                       e1 = iter->getCDData(iter, opdata->layers[i].type, j);
-                       e2 = (char*)CustomData_get_n(pdata, opdata->layers[i].type, p, j);
-                       
-                       if (!e2)
-                               continue;
-
-                       CustomData_copy_elements(opdata->layers[i].type, e1, e2, 1);
-                       
-                       lasttype = opdata->layers[i].type;                              
-               }
-
-               liter = iter->getLoopsIter(iter);
-               for (; !liter->done; liter->step(liter), mloop++, l++) {
-                       mloop->v = liter->vindex;
-                       mloop->e = liter->eindex;
+       target->numLoopData = source->numLoopData;
+       target->numPolyData = source->numPolyData;
 
-                       j = 0;
-                       lasttype = -1;
-                       for (i=0; i<oldata->totlayer; i++) {
-                               void *e1, *e2;
+       if (!CustomData_has_layer(&target->polyData, CD_MPOLY)) {
+               MPoly *mpoly;
+               MLoop *mloop;
 
-                               if (oldata->layers[i].type == CD_MLOOP)
-                                       continue;
-                               
-                               if (oldata->layers[i].type == lasttype)
-                                       j++;
-                               else
-                                       j = 0;
-
-                               e1 = liter->getLoopCDData(liter, oldata->layers[i].type, j);
-                               e2 = CustomData_get_n(ldata, oldata->layers[i].type, l, j);
-                               
-                               if (!e2)
-                                       continue;
-
-                               CustomData_copy_elements(oldata->layers[i].type, e1, e2, 1);
-                               lasttype = oldata->layers[i].type;                              
-                       }
-               }
+               mloop = source->dupLoopArray(source);
+               mpoly = source->dupPolyArray(source);
+               CustomData_add_layer(&target->loopData, CD_MLOOP, CD_ASSIGN, mloop, source->numLoopData);
+               CustomData_add_layer(&target->polyData, CD_MPOLY, CD_ASSIGN, mpoly, source->numPolyData);
        }
-       iter->free(iter);
-}
-
-void DM_DupPolys(DerivedMesh *source, DerivedMesh *target)
-{
-       DMFaceIter *iter = source->newFaceIter(source);
-       int totloop = source->numLoopData;
-
-       dm_add_polys_from_iter(&target->loopData, &target->polyData, source, totloop);
-
-       target->numLoopData = totloop;
-       target->numPolyData = source->getNumFaces(source);
 }
 
 void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob)
 {
        /* dm might depend on me, so we need to do everything with a local copy */
        Mesh tmp = *me;
-       DMFaceIter *iter;
        int totvert, totedge, totface, totloop, totpoly;
        int did_shapekeys=0;
        
@@ -384,14 +360,7 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob)
        totedge = tmp.totedge = dm->getNumEdges(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);
-       
-       tmp.totloop = totloop;
+       totloop = tmp.totloop = dm->numLoopData;
 
        CustomData_copy(&dm->vertData, &tmp.vdata, CD_MASK_MESH, CD_DUPLICATE, totvert);
        CustomData_copy(&dm->edgeData, &tmp.edata, CD_MASK_MESH, CD_DUPLICATE, totedge);
@@ -432,8 +401,13 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob)
                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->dupTessFaceArray(dm), totface);
-       if(!CustomData_has_layer(&tmp.pdata, CD_MPOLY))
-               dm_add_polys_from_iter(&tmp.ldata, &tmp.pdata, dm, totloop);
+       if(!CustomData_has_layer(&tmp.pdata, CD_MPOLY)) {
+               tmp.mloop = dm->dupLoopArray(dm);
+               tmp.mpoly = dm->dupPolyArray(dm);
+
+               CustomData_add_layer(&tmp.ldata, CD_MLOOP, CD_ASSIGN, tmp.mloop, tmp.totloop);
+               CustomData_add_layer(&tmp.pdata, CD_MPOLY, CD_ASSIGN, tmp.mpoly, tmp.totpoly);
+       }
 
        /* object had got displacement layer, should copy this layer to save sculpted data */
        /* NOTE: maybe some other layers should be copied? nazgul */
@@ -455,7 +429,7 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob)
        /*  ok, this should now use new CD shapekey data,
            which shouuld be fed through the modifier 
                stack*/
-       if(tmp.totvert != me->totvert && !did_shapekeys) {
+       if(tmp.totvert != me->totvert && !did_shapekeys && me->key) {
                printf("YEEK! this should be recoded! Shape key loss!!!\n");
                if(tmp.key) tmp.key->id.us--;
                tmp.key = NULL;
@@ -922,13 +896,13 @@ static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm)
 {
        // Mesh *me = ob->data; // UNUSED
        MFace *mf = dm->getTessFaceArray(dm);
-       DMFaceIter *dfiter;
-       DMLoopIter *dliter;
+       MLoop *mloop = dm->getLoopArray(dm), *ml;
+       MPoly *mp = dm->getPolyArray(dm);
        ColorBand *coba= stored_cb;     /* warning, not a local var */
        unsigned char *wtcol;
        unsigned char(*wlcol)[4] = NULL;
        BLI_array_declare(wlcol);
-       int i, totface=dm->getNumTessFaces(dm), totloop;
+       int i, j, totface=dm->getNumTessFaces(dm), totloop;
        int *origIndex = dm->getVertDataArray(dm, CD_ORIGINDEX);
        
        wtcol = MEM_callocN (sizeof (unsigned char) * totface*4*4, "weightmap");
@@ -948,22 +922,18 @@ static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm)
 
        /*now add to loops, so the data can be passed through the modifier stack*/
        totloop = 0;
-       dfiter = dm->newFaceIter(dm);
-       for (; !dfiter->done; dfiter->step(dfiter)) {
-               dliter = dfiter->getLoopsIter(dfiter);
-               for (; !dliter->done; dliter->step(dliter), totloop++) {
-                       int *oi = (int*)dliter->getVertCDData(dliter, CD_ORIGINDEX, -1);
-                       
+       for (i=0; i<dm->numPolyData; i++, mp++) {
+               ml = mloop + mp->loopstart;
+
+               for (j=0; j<mp->totloop; j++, ml++, totloop++) {
                        BLI_array_growone(wlcol);
-                       
-                       calc_weightpaint_vert_color(ob, coba, oi ? *oi : dliter->vindex, 
-                                                   (unsigned char *)&wlcol[totloop]);                   
+
+                       calc_weightpaint_vert_color(ob, coba, origIndex ? origIndex[ml->v] : ml->v,
+                                                                               (unsigned char *)&wlcol[totloop]);
                }
        }
 
        CustomData_add_layer(&dm->loopData, CD_WEIGHT_MLOOPCOL, CD_ASSIGN, wlcol, totloop);
-
-       dfiter->free(dfiter);
 }
 
 
@@ -1886,7 +1856,7 @@ float *mesh_get_mapped_verts_nors(Scene *scene, Object *ob)
        if(ob->type!=OB_MESH || me->totvert==0)
                return NULL;
        
-       dm= mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
+       dm= mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH|CD_MASK_ORIGINDEX);
        vertexcosnos= MEM_callocN(6*sizeof(float)*me->totvert, "vertexcosnos map");
        
        if(dm->foreachMappedVert) {
index e3e07f11bab96aefff3a1df8615622469b55cf73..c3840e91c3b9eb1d1cd382b06ef25ee46f1bd92e 100644 (file)
@@ -101,8 +101,6 @@ typedef struct {
        struct IndexNode *fmap_mem;
 } CDDerivedMesh;
 
-DMFaceIter *cdDM_newFaceIter(DerivedMesh *source);
-
 /**************** DerivedMesh interface functions ****************/
 static int cdDM_getNumVerts(DerivedMesh *dm)
 {
@@ -160,6 +158,18 @@ static void cdDM_copyFaceArray(DerivedMesh *dm, MFace *face_r)
        memcpy(face_r, cddm->mface, sizeof(*face_r) * dm->numFaceData);
 }
 
+static void cdDM_copyLoopArray(DerivedMesh *dm, MLoop *loop_r)
+{
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
+       memcpy(loop_r, cddm->mloop, sizeof(*loop_r) * dm->numLoopData);
+}
+
+static void cdDM_copyPolyArray(DerivedMesh *dm, MPoly *poly_r)
+{
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
+       memcpy(poly_r, cddm->mpoly, sizeof(*poly_r) * dm->numPolyData);
+}
+
 static void cdDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3])
 {
        CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
@@ -1553,14 +1563,14 @@ static CDDerivedMesh *cdDM_create(const char *desc)
        dm->getNumTessFaces = cdDM_getNumTessFaces;
        dm->getNumFaces = cdDM_getNumFaces;
 
-       dm->newFaceIter = cdDM_newFaceIter;
-
        dm->getVert = cdDM_getVert;
        dm->getEdge = cdDM_getEdge;
        dm->getTessFace = cdDM_getFace;
        dm->copyVertArray = cdDM_copyVertArray;
        dm->copyEdgeArray = cdDM_copyEdgeArray;
        dm->copyTessFaceArray = cdDM_copyFaceArray;
+       dm->copyLoopArray = cdDM_copyLoopArray;
+       dm->copyPolyArray = cdDM_copyPolyArray;
        dm->getVertData = DM_get_vert_data;
        dm->getEdgeData = DM_get_edge_data;
        dm->getTessFaceData = DM_get_face_data;
@@ -2018,139 +2028,6 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *UNUSED(me), int use_mdis
        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;
-
-static void cddm_freeiter(void *self)
-{
-       MEM_freeN(self);
-}
-
-static void cddm_stepiter(void *self)
-{
-       CDDM_FaceIter *iter = self;
-       MPoly *mp;
-       
-       mp = iter->cddm->mpoly + iter->head.index;
-       mp->flag = iter->head.flags;
-       mp->mat_nr = iter->head.mat_nr;
-
-       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;
-}
-
-static 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);
-}
-
-static void *cddm_loopiter_getcddata(void *self, int type, int layer)
-{
-       CDDM_LoopIter *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);
-}
-
-static void *cddm_loopiter_getvertcddata(void *self, int type, int layer)
-{
-       CDDM_LoopIter *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);
-}
-
-static 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;
-}
-
-static 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;
-}
-
-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;
-
-       if (source->numFaceData) {
-               iter->head.index = -1;
-               iter->head.step(iter);
-       } else {
-               iter->head.done = 1;
-       }
-
-       return (DMFaceIter*) iter;
-}
-
 DerivedMesh *CDDM_copy(DerivedMesh *source, int faces_from_tessfaces)
 {
        CDDerivedMesh *cddm = cdDM_create("CDDM_copy cddm");
index ed331b7da2f10883ed3804b281c9ba7e152acf3c..f8a21c6478f3d4d8a3a89ac85a4e5e8fec4995b1 100644 (file)
@@ -1298,6 +1298,58 @@ static void bmDM_copyFaceArray(DerivedMesh *dm, MFace *face_r)
        }
 }
 
+
+static void bmDM_copyLoopArray(DerivedMesh *dm, MLoop *loop_r)
+{
+       EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
+       BMesh *bm = ((EditDerivedBMesh *)dm)->tc->bm;
+       BMIter iter, liter;
+       BMVert *v;
+       BMFace *f;
+       BMLoop *l;
+       BMEdge *e;
+       int i;
+
+       i = 0;
+       BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) {
+               BM_SetIndex(v, i++);
+       }
+
+       i = 0;
+       BM_ITER(e, &iter, bm, BM_EDGES_OF_MESH, NULL) {
+               BM_SetIndex(e, i++);
+       }
+
+       i = 0;
+       BM_ITER(f, &iter, bm, BM_FACES_OF_MESH, NULL) {
+               BM_ITER(l, &liter, bm, BM_LOOPS_OF_FACE, f) {
+                       loop_r[i].v = BM_GetIndex(l->v);
+                       loop_r[i].e = BM_GetIndex(l->e);
+                       i++;
+               }
+       }
+}
+
+static void bmDM_copyPolyArray(DerivedMesh *dm, MPoly *poly_r)
+{
+       EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
+       BMesh *bm = ((EditDerivedBMesh *)dm)->tc->bm;
+       BMIter iter, liter;
+       BMFace *f;
+       int i, j;
+
+       i = j = 0;
+       BM_ITER(f, &iter, bm, BM_FACES_OF_MESH, NULL) {
+               poly_r[i].flag = BMFlags_To_MEFlags(f);
+               poly_r[i].loopstart = j;
+               poly_r[i].totloop = f->len;
+               poly_r[i].mat_nr = f->mat_nr;
+
+               i++;
+               j += f->len;
+       }
+}
+
 static void *bmDM_getFaceDataArray(DerivedMesh *dm, int type)
 {
        EditDerivedBMesh *bmdm= (EditDerivedBMesh*) dm;
@@ -1338,157 +1390,6 @@ static void *bmDM_getFaceDataArray(DerivedMesh *dm, int type)
        return datalayer;
 }
 
-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;
-
-static void bmDM_faceIterStep(void *self)
-{
-       bmDM_faceIter *iter = self;
-       
-       if (iter->f) {
-               iter->f->mat_nr = iter->head.mat_nr;
-               iter->f->head.flag = MEFlags_To_BMFlags(iter->head.flags, BM_FACE);
-       }
-
-       iter->f = iter->nextf;
-
-       iter->head.mat_nr = iter->f->mat_nr;
-       iter->head.flags = BMFlags_To_MEFlags(iter->f);
-       iter->head.index++;
-
-       iter->head.len = iter->f->len;
-
-       iter->nextf = BMIter_Step(&iter->iter);
-
-       if (!iter->nextf) iter->head.done = 1;
-}
-
-static 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->head.data, type);
-       else return CustomData_bmesh_get_n(&iter->bm->pdata, iter->f->head.data, type, layer);
-}
-
-static void bmDM_loopIterStep(void *self)
-{
-       bmDM_loopIter *iter = self;
-
-       iter->l = BMIter_Step(&iter->iter);
-       if (!iter->l) {
-               iter->head.done = 1;
-               return;
-       }
-
-       bmvert_to_mvert(iter->bm, iter->l->v, &iter->head.v);
-       iter->head.index++;
-       iter->head.vindex = BM_GetIndex(iter->l->v);
-       iter->head.eindex = BM_GetIndex(iter->l->e);
-}
-
-static 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->head.data, type);
-       else return CustomData_bmesh_get_n(&iter->bm->ldata, iter->l->head.data, type, layer);
-}
-
-static 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->head.data, type);
-       else return CustomData_bmesh_get_n(&iter->bm->vdata, iter->l->v->head.data, type, layer);
-}
-
-static void bmDM_iterFree(void *self)
-{
-       MEM_freeN(self);
-}
-
-static void bmDM_nulliterFree(void *UNUSED(self))
-{
-}
-
-static 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->bm, iter->l->v, &iter->head.v);
-       iter->head.vindex = BM_GetIndex(iter->l->v);
-       iter->head.eindex = BM_GetIndex(iter->l->e);
-
-       return (DMLoopIter*) iter;
-}
-
-static DMFaceIter *bmDM_getFaceIter(DerivedMesh *dm)
-{
-       EditDerivedBMesh *bmdm= (EditDerivedBMesh*)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 = iter->nextf = 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) {
-               BM_SetIndex(v, i);
-               i++;
-       }
-
-       i = 0;
-       BM_ITER(e, &biter, iter->bm, BM_EDGES_OF_MESH, NULL) {
-               BM_SetIndex(e, i);
-               i++;
-       }
-
-       return (DMFaceIter*) iter;
-}
-
 static void bmDM_getVertCos(DerivedMesh *dm, float (*cos_r)[3])
 {
        EditDerivedBMesh *emdm= (EditDerivedBMesh*) dm;
@@ -1606,9 +1507,11 @@ DerivedMesh *getEditDerivedBMesh(BMEditMesh *em, Object *UNUSED(ob),
        bmdm->dm.copyVertArray = bmDM_copyVertArray;
        bmdm->dm.copyEdgeArray = bmDM_copyEdgeArray;
        bmdm->dm.copyTessFaceArray = bmDM_copyFaceArray;
+       bmdm->dm.copyLoopArray = bmDM_copyLoopArray;
+       bmdm->dm.copyPolyArray = bmDM_copyPolyArray;
+
        bmdm->dm.getTessFaceDataArray = bmDM_getFaceDataArray;
 
-       bmdm->dm.newFaceIter = bmDM_getFaceIter;
        bmdm->dm.recalcTesselation = bmDM_recalcTesselation;
 
        bmdm->dm.foreachMappedVert = bmDM_foreachMappedVert;
index 7b6e843e74e33394259af240fd704cd56d94fdf2..6454019be57a9c5dfdbee3c958edb64ccd0e74c1 100644 (file)
@@ -112,8 +112,8 @@ BMEditMesh *CDDM_To_BMesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing)
        BMEditMesh *em = existing;
        MVert *mv, *mvert;
        MEdge *me, *medge;
-       DMFaceIter *dfiter;
-       DMLoopIter *dliter;
+       MPoly *mpoly, *mp;
+       MLoop *mloop, *ml;
        BMVert *v, **vtable, **verts=NULL;
        BMEdge *e, **etable, **edges=NULL;
        BMFace *f;
@@ -171,45 +171,41 @@ BMEditMesh *CDDM_To_BMesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing)
        MEM_freeN(medge);
        
        /*do faces*/
-       k = 0;
-       dfiter = dm->newFaceIter(dm);
-       for (; !dfiter->done; dfiter->step(dfiter)) {
+       mpoly = mp = dm->getPolyArray(dm);
+       mloop = dm->getLoopArray(dm);
+       for (i=0; i<dm->numFaceData; i++, mp++) {
                BMLoop *l;
 
                BLI_array_empty(verts);
                BLI_array_empty(edges);
 
-               dliter = dfiter->getLoopsIter(dfiter);
-               for (j=0; !dliter->done; dliter->step(dliter), j++) {
+               ml = mloop + mp->loopstart;
+               for (j=0; j<mp->totloop; j++, ml++) {
                        BLI_array_growone(verts);
                        BLI_array_growone(edges);
 
-                       verts[j] = vtable[dliter->vindex];
-                       edges[j] = etable[dliter->eindex];
+                       verts[j] = vtable[ml->v];
+                       edges[j] = etable[ml->e];
                }
 
-               if (j < 2)
-                       break;
-               
-               f = BM_Make_Ngon(bm, verts[0], verts[1], edges, dfiter->len, 0);
+               f = BM_Make_Ngon(bm, verts[0], verts[1], edges, mp->totloop, 0);
 
-               if (!f) 
+               if (!f)
                        continue;
 
-               f->head.flag = MEFlags_To_BMFlags(dfiter->flags, BM_FACE);
-               f->mat_nr = dfiter->mat_nr;
+               f->head.flag = MEFlags_To_BMFlags(mp->flag, BM_FACE);
+               f->mat_nr = mp->mat_nr;
 
-               dliter = dfiter->getLoopsIter(dfiter);
                l = BMIter_New(&liter, bm, BM_LOOPS_OF_FACE, f);
-               for (j=0; l; l=BMIter_Step(&liter)) {
+               k = mp->loopstart;
+
+               for (j=0; l; l=BMIter_Step(&liter), k++) {
                        CustomData_to_bmesh_block(&dm->loopData, &bm->ldata, k, &l->head.data);
-                       k += 1;
                }
 
-               CustomData_to_bmesh_block(&dm->polyData, &bm->pdata, 
-                       dfiter->index, &f->head.data);
+               CustomData_to_bmesh_block(&dm->polyData, &bm->pdata,
+                       i, &f->head.data);
        }
-       dfiter->free(dfiter);
 
        MEM_freeN(vtable);
        MEM_freeN(etable);
index 3dfec66d2e5fe91fa52d9e434aa0d882d8f8003d..64ac05fc2b197d3de1ddd984f5c09609d4228f13 100644 (file)
@@ -481,7 +481,7 @@ static DerivedMesh *subsurf_dm_create_local(Object *ob, DerivedMesh *dm, int lvl
        if(optimal)
                smd.flags |= eSubsurfModifierFlag_ControlEdges;
 
-       return subsurf_make_derived_from_derived(dm, &smd, 0, NULL, 0, 0, (ob->mode & OB_MODE_EDIT));
+               return subsurf_make_derived_from_derived(dm, &smd, 0, NULL, 0, 0, (ob->mode & OB_MODE_EDIT));
 }
 
 
index 6ce299187f2b3fc3a1b21e392e90f9c84137143d..5a6817aec8022c0ce0624f9c23c37a64f056d8e0 100644 (file)
@@ -471,8 +471,8 @@ static void free_ss_weights(WeightTable *wtable)
 
 #if 0
 static DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh,
-                                 int drawInteriorEdges, int useSubsurfUv,
-                                 DerivedMesh *dm, struct MultiresSubsurf *ms)
+                                                                int drawInteriorEdges, int useSubsurfUv,
+                                                                DerivedMesh *dm, struct MultiresSubsurf *ms)
 {
        DerivedMesh *cgdm, *result;
        double curt = PIL_check_seconds_timer();
@@ -481,7 +481,7 @@ static DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh,
        result = CDDM_copy(cgdm, 1);
 
        printf("subsurf conversion time: %.6lf\n", PIL_check_seconds_timer() - curt);
-       
+
        cgdm->needsFree = 1;
        cgdm->release(cgdm);
 
@@ -497,20 +497,20 @@ static int ss_sync_from_derivedmesh(CCGSubSurf *ss, DerivedMesh *dm,
        float creaseFactor = (float) ccgSubSurf_getSubdivisionLevels(ss);
        CCGVertHDL *fVerts = NULL;
        BLI_array_declare(fVerts);
-       int totvert = dm->getNumVerts(dm);
-       int totedge = dm->getNumEdges(dm);
-       /*int totface = dm->getNumTessFaces(dm);*/ /*UNUSED*/
-       /*int totpoly = dm->getNumFaces(dm);*/ /*UNUSED*/
-       int i;
-       int *index;
        MVert *mvert = dm->getVertArray(dm);
        MEdge *medge = dm->getEdgeArray(dm);
        MFace *mface = dm->getTessFaceArray(dm);
        MVert *mv;
        MEdge *me;
+       MLoop *mloop = dm->getLoopArray(dm), *ml;
+       MPoly *mpoly = dm->getPolyArray(dm), *mp;
        /*MFace *mf;*/ /*UNUSED*/
-       DMFaceIter *fiter;
-       DMLoopIter *liter;
+       int totvert = dm->getNumVerts(dm);
+       int totedge = dm->getNumEdges(dm);
+       /*int totface = dm->getNumTessFaces(dm);*/ /*UNUSED*/
+       /*int totpoly = dm->getNumFaces(dm);*/ /*UNUSED*/
+       int i, j;
+       int *index;
 
        ccgSubSurf_initFullSync(ss);
 
@@ -542,31 +542,30 @@ static int ss_sync_from_derivedmesh(CCGSubSurf *ss, DerivedMesh *dm,
 
                ((int*)ccgSubSurf_getEdgeUserData(ss, e))[1] = (index)? *index++: i;
        }
-       
-       fiter = dm->newFaceIter(dm);
-       for (i=0; !fiter->done; fiter->step(fiter), i++) {
-               CCGFace *f;
-               BLI_array_empty(fVerts);
 
-               index = (int*) fiter->getCDData(fiter, CD_ORIGINDEX, -1);
-               liter = fiter->getLoopsIter(fiter);
+       mp = mpoly;
+       index = DM_get_face_data_layer(dm, CD_ORIGINDEX);
+       for (i=0; i<dm->numPolyData; i++, mp++) {
+               CCGFace *f=NULL;
+
+               BLI_array_empty(fVerts);
 
-               for (; !liter->done; liter->step(liter)) {
-                       BLI_array_growone(fVerts);
-                       fVerts[BLI_array_count(fVerts)-1] = SET_INT_IN_POINTER(liter->vindex);
+               ml = mloop + mp->loopstart;
+               for (j=0; j<mp->totloop; j++, ml++) {
+                       BLI_array_append(fVerts, SET_INT_IN_POINTER(ml->v));
                }
 
                /* 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, 
+               if(ccgSubSurf_syncFace(ss, SET_INT_IN_POINTER(i), mp->totloop,
                                                           fVerts, &f) == eCCGError_InvalidValue) {
                        static int hasGivenError = 0;
 
                        if(!hasGivenError) {
                                printf("Unrecoverable error in SubSurf calculation,"
-                                      " mesh is inconsistent.\n");
+                                          " mesh is inconsistent.\n");
 
                                hasGivenError = 1;
                        }
@@ -574,9 +573,8 @@ static int ss_sync_from_derivedmesh(CCGSubSurf *ss, DerivedMesh *dm,
                        return 0;
                }
 
-               ((int*)ccgSubSurf_getFaceUserData(ss, f))[1] = (index)? *index++: i;
+               ((int*)ccgSubSurf_getFaceUserData(ss, f))[1] = index ? *index++: i;
        }
-       fiter->free(fiter);
 
        ccgSubSurf_processSync(ss);
 
@@ -776,8 +774,38 @@ static void ccgDM_getFinalEdge(DerivedMesh *dm, int edgeNum, MEdge *med)
                int edgeSize = ccgSubSurf_getEdgeSize(ss);
                int gridSideEdges;
                int gridInternalEdges;
+                               int lasti, previ;
+
+                               i = lastface;
+                               lasti = 0;
+                               while (1) {
+                                       previ = i;
+                                       if (cgdm->faceMap[i].startEdge >= edgeNum) {
+                                               i -= fabs(i-lasti)/2.0f;
+                                       } else if (cgdm->faceMap[i].startEdge < edgeNum) {
+                                               i += fabs(i-lasti)/2.0;
+                                       } else {
+                                               break;
+                                       }
 
-               i = 0;
+                                       if (i < 0) {
+                                               i = 0;
+                                               break;
+                                       }
+
+                                       if (i > lastface) {
+                                               i = lastface;
+                                               break;
+
+                                       }
+
+                                       if (i == lasti)
+                                          break;
+
+                                       lasti = previ;
+                               }
+
+                               i = i > 0 ? i - 1 : i;
                while(i < lastface && edgeNum >= cgdm->faceMap[i + 1].startEdge)
                        ++i;
 
@@ -1030,164 +1058,120 @@ static void ccgDM_copyFinalEdgeArray(DerivedMesh *dm, MEdge *medge)
        }
 }
 
-struct cgdm_faceIter;
-
-typedef struct cgdm_loopIter {
-       DMLoopIter head;
-       int curloop;
-       int lindex; //loop index within the mesh, not the face
-       CCGDerivedMesh *cgdm;
-       struct cgdm_faceIter *fiter;
-} cgdm_loopIter;
-
-typedef struct cgdm_faceIter {
-       DMFaceIter head;
-       CCGDerivedMesh *cgdm;
-       MFace *mface, *mf;
-
-       cgdm_loopIter liter;
-       EdgeHash *ehash; /*edge map for populating loopiter->eindex*/
-} cgdm_faceIter;
-
-static void cgdm_faceIterStep(void *self)
+static void ccgDM_copyFinalFaceArray(DerivedMesh *dm, MFace *mface)
 {
-       cgdm_faceIter *fiter = self;
+       CCGDerivedMesh *cgdm = (CCGDerivedMesh*) dm;
+       CCGSubSurf *ss = cgdm->ss;
+       int index;
+       int totface;
+       int gridSize = ccgSubSurf_getGridSize(ss);
+       int edgeSize = ccgSubSurf_getEdgeSize(ss);
+       int i = 0;
+       char *faceFlags = cgdm->faceFlags;
 
-       if (!fiter->cgdm || !fiter->cgdm->ss) {
-               fiter->head.done = 1;
-               return;
-       }
+       totface = ccgSubSurf_getNumFaces(ss);
+       for(index = 0; index < totface; index++) {
+               CCGFace *f = cgdm->faceMap[index].face;
+               int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f);
+               int flag = (faceFlags)? faceFlags[index*2]: ME_SMOOTH;
+               int mat_nr = (faceFlags)? faceFlags[index*2+1]: 0;
 
-       if (fiter->head.index+1 >= ccgSubSurf_getNumFinalFaces(fiter->cgdm->ss)) {
-               fiter->head.done = 1;
-               return;
-       };
+               for(S = 0; S < numVerts; S++) {
+                       for(y = 0; y < gridSize - 1; y++) {
+                               for(x = 0; x < gridSize - 1; x++) {
+                                       MFace *mf = &mface[i];
+                                       mf->v1 = getFaceIndex(ss, f, S, x + 0, y + 0,
+                                                                                 edgeSize, gridSize);
+                                       mf->v2 = getFaceIndex(ss, f, S, x + 0, y + 1,
+                                                                                 edgeSize, gridSize);
+                                       mf->v3 = getFaceIndex(ss, f, S, x + 1, y + 1,
+                                                                                 edgeSize, gridSize);
+                                       mf->v4 = getFaceIndex(ss, f, S, x + 1, y + 0,
+                                                                                 edgeSize, gridSize);
+                                       if (faceFlags) {
+                                               mat_nr = faceFlags[index*2+1];
+                                               mf->flag = faceFlags[index*2];
+                                       } else mf->flag = flag;
 
-       fiter->head.index++;
-       
-       fiter->mf++;
+                                       mf->mat_nr = mat_nr;
+                                       mf->flag = flag;
 
-       fiter->head.flags = fiter->mface->flag;
-       fiter->head.mat_nr = fiter->mface->mat_nr;
-       fiter->head.len = 4;
+                                       i++;
+                               }
+                       }
+               }
+       }
 }
 
-static void *cgdm_faceIterCData(void *self, int type, int layer)
+static void ccgDM_copyFinalLoopArray(DerivedMesh *dm, MLoop *mloop)
 {
-       cgdm_faceIter *fiter = self;
-       
-       if (layer == -1) 
-               return CustomData_get(&fiter->cgdm->dm.polyData, fiter->head.index, type);
-       else
-               return CustomData_get_n(&fiter->cgdm->dm.polyData, type, fiter->head.index, layer);
-}
+       CCGDerivedMesh *cgdm = (CCGDerivedMesh*) dm;
+       CCGSubSurf *ss = cgdm->ss;
+       int index;
+       int totface;
+       int gridSize = ccgSubSurf_getGridSize(ss);
+       int edgeSize = ccgSubSurf_getEdgeSize(ss);
+       int i = 0;
+       MLoop *mv;
+       char *faceFlags = cgdm->faceFlags;
 
-static void cgdm_loopIterStep(void *self)
-{
-       cgdm_loopIter *liter = self;
-       /* MFace *mf = liter->fiter->mface; */ /*UNUSED*/
-       int i, v1, v2;
+       if (!cgdm->ehash) {
+               MEdge *medge;
 
-       liter->head.index++;
-       i = liter->head.index;
+               cgdm->ehash = BLI_edgehash_new();
+               medge = cgdm->dm.getEdgeArray((DerivedMesh*)cgdm);
 
-       if (liter->head.index >= 4) {
-               liter->head.done = 1;
-               return;
+               for (i=0; i<cgdm->dm.numEdgeData; i++) {
+                       BLI_edgehash_insert(cgdm->ehash, medge[i].v1, medge[i].v2, SET_INT_IN_POINTER(i));
+               }
        }
 
-       switch (i) {
-               case 0:
-                       v1 = liter->fiter->mf->v1;
-                       v2 = liter->fiter->mf->v2;
-                       break;
-               case 1:
-                       v1 = liter->fiter->mf->v2;
-                       v2 = liter->fiter->mf->v3;
-                       break;
-               case 2:
-                       v1 = liter->fiter->mf->v3;
-                       v2 = liter->fiter->mf->v4;
-                       break;
-               case 3:
-                       v1 = liter->fiter->mf->v4;
-                       v2 = liter->fiter->mf->v1;
-                       break;
-       }
-
-       liter->head.vindex = v1;
-       liter->head.eindex = GET_INT_FROM_POINTER(BLI_edgehash_lookup(liter->fiter->cgdm->ehash, v1, v2));
-       liter->lindex += 1;
-       
-       ccgDM_getFinalVert((DerivedMesh*)liter->cgdm, v1, &liter->head.v);
-}
-
-static void *cgdm_loopIterGetVCData(void *self, int type, int layer)
-{
-       cgdm_loopIter *liter = self;
+       totface = ccgSubSurf_getNumFaces(ss);
+       mv = mloop;
+       for(index = 0; index < totface; index++) {
+               CCGFace *f = cgdm->faceMap[index].face;
+               int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f);
+               int flag = (faceFlags)? faceFlags[index*2]: ME_SMOOTH;
+               int mat_nr = (faceFlags)? faceFlags[index*2+1]: 0;
 
-       if (layer == -1)
-               return CustomData_get(&liter->cgdm->dm.vertData, liter->head.vindex, type);
-       else return CustomData_get_n(&liter->cgdm->dm.vertData, type, liter->head.vindex, layer);
-}
+               for(S = 0; S < numVerts; S++) {
+                       for(y = 0; y < gridSize - 1; y++) {
+                               for(x = 0; x < gridSize - 1; x++) {
+                                       int v1, v2, v3, v4;
 
-static void *cgdm_loopIterGetCData(void *self, int type, int layer)
-{
-       cgdm_loopIter *liter = self;
+                                       v1 = getFaceIndex(ss, f, S, x + 0, y + 0,
+                                                                                 edgeSize, gridSize);
 
-       if (layer == -1)
-               return CustomData_get(&liter->cgdm->dm.loopData, liter->lindex, type);
-       else return CustomData_get_n(&liter->cgdm->dm.loopData, type, liter->lindex, layer);
-}
+                                       v2 = getFaceIndex(ss, f, S, x + 0, y + 1,
+                                                                                 edgeSize, gridSize);
+                                       v3 = getFaceIndex(ss, f, S, x + 1, y + 1,
+                                                                                 edgeSize, gridSize);
+                                       v4 = getFaceIndex(ss, f, S, x + 1, y + 0,
+                                                                                 edgeSize, gridSize);
 
-static DMLoopIter *cgdm_faceIterGetLIter(void *self)
-{
-       cgdm_faceIter *fiter = self;
-       
-       fiter->liter.head.index = -1;
-       fiter->liter.head.done = 0;
-       fiter->liter.head.step(&fiter->liter);
+                                       mv->v = v1;
+                                       mv->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(cgdm->ehash, v1, v2));
+                                       mv++, i++;
 
-       return (DMLoopIter*) &fiter->liter;
-}
+                                       mv->v = v2;
+                                       mv->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(cgdm->ehash, v2, v3));
+                                       mv++, i++;
 
-static void cgdm_faceIterFree(void *vfiter)
-{
-       cgdm_faceIter *fiter = vfiter;
+                                       mv->v = v3;
+                                       mv->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(cgdm->ehash, v3, v4));
+                                       mv++, i++;
 
-       MEM_freeN(fiter->mface);
-       MEM_freeN(fiter);
+                                       mv->v = v4;
+                                       mv->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(cgdm->ehash, v4, v1));
+                                       mv++, i++;
+                               }
+                       }
+               }
+       }
 }
 
-static DMFaceIter *cgdm_newFaceIter(DerivedMesh *dm)
-{
-       cgdm_faceIter *fiter = MEM_callocN(sizeof(cgdm_faceIter), "cgdm_faceIter");
-       /*MEdge medge;*/ /*UNUSED*/
-       /*int totedge = cgdm_getNumEdges(dm);*/ /*UNUSED*/
-
-       fiter->cgdm = (CCGDerivedMesh *)dm;
-       fiter->liter.cgdm = (CCGDerivedMesh *)dm;
-       fiter->mface = fiter->mf = dm->dupTessFaceArray(dm);
-       fiter->mf--;
-
-       fiter->head.free = cgdm_faceIterFree;
-       fiter->head.step = cgdm_faceIterStep;
-       fiter->head.index = -1;
-       fiter->head.getCDData = cgdm_faceIterCData;
-       fiter->head.getLoopsIter = cgdm_faceIterGetLIter;
-
-       fiter->liter.fiter = fiter;
-       fiter->liter.head.getLoopCDData = cgdm_loopIterGetCData;
-       fiter->liter.head.getVertCDData = cgdm_loopIterGetVCData;
-       fiter->liter.head.step = cgdm_loopIterStep;
-       fiter->liter.lindex = -1;
-
-       fiter->head.step(fiter);
 
-       return (DMFaceIter *)fiter;
-}
-
-static void ccgDM_copyFinalFaceArray(DerivedMesh *dm, MFace *mface)
+static void ccgDM_copyFinalPolyArray(DerivedMesh *dm, MPoly *mface)
 {
        CCGDerivedMesh *cgdm = (CCGDerivedMesh*) dm;
        CCGSubSurf *ss = cgdm->ss;
@@ -1195,7 +1179,7 @@ static void ccgDM_copyFinalFaceArray(DerivedMesh *dm, MFace *mface)
        int totface;
        int gridSize = ccgSubSurf_getGridSize(ss);
        int edgeSize = ccgSubSurf_getEdgeSize(ss);
-       int i = 0;
+       int i = 0, k = 0;
        char *faceFlags = cgdm->faceFlags;
 
        totface = ccgSubSurf_getNumFaces(ss);
@@ -1208,15 +1192,8 @@ static void ccgDM_copyFinalFaceArray(DerivedMesh *dm, MFace *mface)
                for(S = 0; S < numVerts; S++) {
                        for(y = 0; y < gridSize - 1; y++) {
                                for(x = 0; x < gridSize - 1; x++) {
-                                       MFace *mf = &mface[i];
-                                       mf->v1 = getFaceIndex(ss, f, S, x + 0, y + 0,
-                                                                                 edgeSize, gridSize);
-                                       mf->v2 = getFaceIndex(ss, f, S, x + 0, y + 1,
-                                                                                 edgeSize, gridSize);
-                                       mf->v3 = getFaceIndex(ss, f, S, x + 1, y + 1,
-                                                                                 edgeSize, gridSize);
-                                       mf->v4 = getFaceIndex(ss, f, S, x + 1, y + 0,
-                                                                                 edgeSize, gridSize);
+                                       MPoly *mf = &mface[i];
+
                                        if (faceFlags) {
                                                mat_nr = faceFlags[index*2+1];
                                                mf->flag = faceFlags[index*2];
@@ -1224,7 +1201,10 @@ static void ccgDM_copyFinalFaceArray(DerivedMesh *dm, MFace *mface)
 
                                        mf->mat_nr = mat_nr;
                                        mf->flag = flag;
+                                       mf->loopstart = k;
+                                       mf->totloop = 4;
 
+                                       k += 4;
                                        i++;
                                }
                        }
@@ -2669,7 +2649,6 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
        ccgdm->dm.getNumGrids = ccgDM_getNumGrids;
        ccgdm->dm.getPBVH = ccgDM_getPBVH;
 
-       ccgdm->dm.newFaceIter = cgdm_newFaceIter;
        ccgdm->dm.getVert = ccgDM_getFinalVert;
        ccgdm->dm.getEdge = ccgDM_getFinalEdge;
        ccgdm->dm.getTessFace = ccgDM_getFinalFace;
@@ -2678,6 +2657,8 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
        ccgdm->dm.copyVertArray = ccgDM_copyFinalVertArray;
        ccgdm->dm.copyEdgeArray = ccgDM_copyFinalEdgeArray;
        ccgdm->dm.copyTessFaceArray = ccgDM_copyFinalFaceArray;
+       ccgdm->dm.copyLoopArray = ccgDM_copyFinalLoopArray;
+       ccgdm->dm.copyPolyArray = ccgDM_copyFinalPolyArray;
        ccgdm->dm.getVertData = DM_get_vert_data;
        ccgdm->dm.getEdgeData = DM_get_edge_data;
        ccgdm->dm.getTessFaceData = DM_get_face_data;
@@ -2828,7 +2809,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
                }
                
                BLI_array_empty(vertidx);
-               for(s = 0; s < numVerts; s++) {
+                               for(s = 0; s < numVerts; s++) {
                        CCGVert *v = ccgSubSurf_getFaceVert(ss, f, s);
                        
                        BLI_array_growone(vertidx);
@@ -3014,12 +2995,6 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
        BLI_array_free(loopidx);
        free_ss_weights(&wtable);
 
-       ccgdm->ehash = BLI_edgehash_new();
-       for (i=0; i<ccgdm->dm.numEdgeData; i++) {
-               ccgDM_getFinalEdge((DerivedMesh*)ccgdm, i, &medge2);
-               BLI_edgehash_insert(ccgdm->ehash, medge2.v1, medge2.v2, SET_INT_IN_POINTER(i));
-       }
-
        return ccgdm;
 }
 
index 1827d69dcab923a9746dffa4553af417f642d1d7..4cb65b8dd121e39ad2ed120858c03e3513a416f8 100644 (file)
@@ -146,7 +146,7 @@ BM_INLINE void BLI_edgehash_insert(EdgeHash *eh, int v0, int v1, void *val) {
        e->next= eh->buckets[hash];
        eh->buckets[hash]= e;
        
-       if (++eh->nentries>eh->nbuckets*3) {
+        if (++eh->nentries>eh->nbuckets*3) {
                EdgeEntry *e, **old= eh->buckets;
                int i, nold= eh->nbuckets;
                
index afb663bcfa2f734ab46624b5d199b8d0fc0e379d..e2669936f753c28659c493cef99aff3a58af40b7 100644 (file)
@@ -75,30 +75,24 @@ void paintface_flush_flags(Object *ob)
 {
        Mesh *me= get_mesh(ob);
        DerivedMesh *dm= ob->derivedFinal;
-       MPoly *mf_orig;
-       DMFaceIter *fiter;
+       MPoly *mf_orig, *mp;
        int *index = NULL;
        int totface;
-       int i;
+       int i, j;
        
        if(me==NULL || dm==NULL)
                return;
 
-       fiter = dm->newFaceIter(dm);
        totface = dm->getNumFaces(dm);
+       index = DM_get_face_data_layer(dm, CD_ORIGINDEX);
+       mp = dm->getPolyArray(dm);
+       for (i=0; i<dm->numPolyData; i++, index++, mp++) {
+               if (!index)
+                       break;
 
-       for (i=0; !fiter->done; fiter->step(fiter), i++) {
-               index = fiter->getCDData(fiter, CD_ORIGINDEX, -1);
-               if (!index) {
-                       fiter->free(fiter);
-                       return;
-               }
-               
                mf_orig = me->mpoly + *index;
-               fiter->flags = mf_orig->flag; 
+               mp->flag = mf_orig->flag;
        }
-
-       fiter->free(fiter);
 }
 
 /* returns 0 if not found, otherwise 1 */
index 434518c6d7e21c54db2a6cd1dc7833bf63c1bf05..9414cc00341320fa128509230e072a44a7833f8c 100644 (file)
@@ -3389,12 +3389,16 @@ static void sculpt_flush_update(bContext *C)
        ARegion *ar = CTX_wm_region(C);
        MultiresModifierData *mmd = ss->multires;
 
-       if(mmd)
-               multires_mark_as_modified(ob);
+       if (!ss->cache) {
+               if(mmd)
+                       multires_mark_as_modified(ob);
+       }
+
        if(ob->derivedFinal) /* VBO no longer valid */
                GPU_drawobject_free(ob->derivedFinal);
 
-       DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+       if (!ss->cache)
+               DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
        
        if(ss->modifiers_active) {
                ED_region_tag_redraw(ar);
@@ -3518,6 +3522,7 @@ static void sculpt_stroke_done(bContext *C, struct PaintStroke *UNUSED(stroke))
 
                sculpt_cache_free(ss->cache);
                ss->cache = NULL;
+               sculpt_flush_update(C);
 
                sculpt_undo_push_end();