diff options
author | Joseph Eagar <joeedh@gmail.com> | 2011-06-14 07:16:08 +0400 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2011-06-14 07:16:08 +0400 |
commit | 73a545b0d52e61ca8a648f3f81e05dbeb2ba8c9b (patch) | |
tree | 894354af7ac7eb54d8d2adb5d7bb2c66b0b63fb1 /source/blender/blenkernel | |
parent | f122a74b1e778bc902fa57f0689ac89c1dacbcef (diff) |
=bmesh=
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).
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_DerivedMesh.h | 46 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 198 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/cdderivedmesh.c | 151 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/editderivedbmesh.c | 207 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/modifiers_bmesh.c | 40 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/multires.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 333 |
7 files changed, 332 insertions, 645 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index 3bf7306bf12..bac5bd7d4e4 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -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 diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 62f9c65d2ea..cb4627db7a7 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -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) { diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index e3e07f11bab..c3840e91c3b 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -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"); diff --git a/source/blender/blenkernel/intern/editderivedbmesh.c b/source/blender/blenkernel/intern/editderivedbmesh.c index ed331b7da2f..f8a21c6478f 100644 --- a/source/blender/blenkernel/intern/editderivedbmesh.c +++ b/source/blender/blenkernel/intern/editderivedbmesh.c @@ -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; diff --git a/source/blender/blenkernel/intern/modifiers_bmesh.c b/source/blender/blenkernel/intern/modifiers_bmesh.c index 7b6e843e74e..6454019be57 100644 --- a/source/blender/blenkernel/intern/modifiers_bmesh.c +++ b/source/blender/blenkernel/intern/modifiers_bmesh.c @@ -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); diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 3dfec66d2e5..64ac05fc2b1 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -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)); } diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 6ce299187f2..5a6817aec80 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -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; } |