diff options
author | Joseph Eagar <joeedh@gmail.com> | 2009-08-19 00:05:08 +0400 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2009-08-19 00:05:08 +0400 |
commit | f7cef59b3dff4c3094aaae0f54cd8fe35e011748 (patch) | |
tree | 802b2c66b22c37eafcbac2cd7631135cef5e2073 /source/blender/blenkernel/intern | |
parent | 3c7b9347ec6f4cb506e5954433ae5f2a0cde5b3d (diff) |
rearranged some code a bit
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 94 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/cdderivedmesh.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/customdata.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/editderivedbmesh.c | 82 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/modifiers_bmesh.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 212 |
6 files changed, 322 insertions, 88 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index eadb4e566ce..ca6dc9407ff 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -282,27 +282,75 @@ void dm_add_polys_from_iter(CustomData *ldata, CustomData *pdata, DerivedMesh *d { DMFaceIter *iter = dm->newFaceIter(dm); DMLoopIter *liter; + CustomData *oldata, *opdata; MPoly *mpoly; MLoop *mloop; - int i; + int 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"); - mpoly = MEM_callocN(sizeof(MPoly)*dm->getNumFaces(dm), "MPoly from dm_add_polys_from_iter"); - CustomData_add_layer(ldata, CD_MLOOP, CD_ASSIGN, mloop, totloop); + 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)); - i = 0; + l = 0; for (; !iter->done; iter->step(iter), mpoly++) { mpoly->flag = iter->flags; - mpoly->loopstart = i; + 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 == CD_MPOLY) + continue; + + e1 = iter->getCDData(iter, opdata->layers[i].type, j); + e2 = CustomData_get_layer_n(pdata, opdata->layers[i].type, j); + + CustomData_copy_elements(opdata->layers[i].type, e1, e2, 1); + + if (opdata->layers[i].type == lasttype) + j++; + else + j = 0; + + lasttype = opdata->layers[i].type; + } + liter = iter->getLoopsIter(iter); - for (; !liter->done; liter->step(liter), mloop++, i++) { + for (; !liter->done; liter->step(liter), mloop++, l++) { mloop->v = liter->vindex; mloop->e = liter->eindex; + + j = 0; + lasttype = -1; + for (i=0; i<oldata->totlayer; i++) { + void *e1, *e2; + + if (oldata->layers[i].type == CD_MLOOP) + continue; + + e1 = liter->getLoopCDData(liter, oldata->layers[i].type, j); + e2 = CustomData_get_layer_n(ldata, oldata->layers[i].type, j); + + CustomData_copy_elements(oldata->layers[i].type, e1, e2, 1); + + if (oldata->layers[i].type == lasttype) + j++; + else + j = 0; + + lasttype = oldata->layers[i].type; + } } } iter->free(iter); @@ -312,33 +360,21 @@ void DM_DupPolys(DerivedMesh *source, DerivedMesh *target) { DMFaceIter *iter = source->newFaceIter(source); DMLoopIter *liter; - MPoly *mpoly; - MLoop *mloop; - int i; + int totloop = 0; - mloop = MEM_callocN(sizeof(MLoop)*source->numLoopData, "MLoop from dm_add_polys_from_iter"); - mpoly = MEM_callocN(sizeof(MPoly)*source->getNumFaces(source), "MPoly from dm_add_polys_from_iter"); - - CustomData_add_layer(&target->loopData, CD_MLOOP, CD_ASSIGN, mloop, source->numLoopData); - CustomData_add_layer(&target->polyData, CD_MPOLY, CD_ASSIGN, mpoly, source->getNumFaces(source)); - - target->numLoopData = source->numLoopData; - target->numPolyData = source->numPolyData; - - i = 0; - for (; !iter->done; iter->step(iter), mpoly++) { - mpoly->flag = iter->flags; - mpoly->loopstart = i; - mpoly->totloop = iter->len; - mpoly->mat_nr = iter->mat_nr; - + for (; !iter->done; iter->step(iter)) { liter = iter->getLoopsIter(iter); - for (; !liter->done; liter->step(liter), mloop++, i++) { - mloop->v = liter->vindex; - mloop->e = liter->eindex; + for (; !liter->done; liter->step(liter)) { + totloop++; } } + iter->free(iter); + + 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) @@ -1044,7 +1080,7 @@ static void emDM_drawFacesTex_common(void *dm, } } -static void emDM_drawFacesTex(void *dm, int (*setDrawOptions)(MTFace *tface, MCol *mcol, int matnr)) +static void emDM_drawFacesTex(void *dm, int (*setDrawOptions)(MTFace *tface, int has_vcol, int matnr)) { emDM_drawFacesTex_common(dm, setDrawOptions, NULL, NULL); } diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 61355c4265e..0f7ebc05558 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -1311,7 +1311,7 @@ void *cddm_faceiter_getcddata(void *self, int type, int layer) void *cddm_loopiter_getcddata(void *self, int type, int layer) { - CDDM_FaceIter *iter = self; + CDDM_LoopIter *iter = self; if (layer == -1) return CustomData_get(&iter->cddm->dm.loopData, iter->head.index, type); @@ -1321,13 +1321,13 @@ void *cddm_loopiter_getcddata(void *self, int type, int layer) void *cddm_loopiter_getvertcddata(void *self, int type, int layer) { - CDDM_FaceIter *iter = self; + CDDM_LoopIter *iter = self; if (layer == -1) return CustomData_get(&iter->cddm->dm.vertData, - iter->cddm->mloop[iter->head.index].v, + iter->cddm->mloop[iter->head.vindex].v, type); else return CustomData_get_n(&iter->cddm->dm.vertData, type, - iter->cddm->mloop[iter->head.index].v, layer); + iter->cddm->mloop[iter->head.vindex].v, layer); } DMLoopIter *cddmiter_get_loopiter(void *self) @@ -1406,8 +1406,6 @@ DerivedMesh *CDDM_copy(DerivedMesh *source) CustomData_copy_data(&source->vertData, &dm->vertData, 0, 0, numVerts); CustomData_copy_data(&source->edgeData, &dm->edgeData, 0, 0, numEdges); CustomData_copy_data(&source->faceData, &dm->faceData, 0, 0, numFaces); - CustomData_copy_data(&source->loopData, &dm->loopData, 0, 0, numLoops); - CustomData_copy_data(&source->polyData, &dm->polyData, 0, 0, numPolys); /* now add mvert/medge/mface layers */ cddm->mvert = source->dupVertArray(source); diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 17a822aaee0..72c3e3b0188 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -1465,6 +1465,16 @@ void CustomData_set_only_copy(const struct CustomData *data, data->layers[i].flag |= CD_FLAG_NOCOPY; } +void CustomData_copy_elements(int type, void *source, void *dest, int count) +{ + const LayerTypeInfo *typeInfo = layerType_getInfo(type); + + if (typeInfo->copy) + typeInfo->copy(source, dest, count); + else + memcpy(dest, source, typeInfo->size*count); +} + void CustomData_copy_data(const CustomData *source, CustomData *dest, int source_index, int dest_index, int count) { diff --git a/source/blender/blenkernel/intern/editderivedbmesh.c b/source/blender/blenkernel/intern/editderivedbmesh.c index c34f5253a42..a17d16ce754 100644 --- a/source/blender/blenkernel/intern/editderivedbmesh.c +++ b/source/blender/blenkernel/intern/editderivedbmesh.c @@ -275,6 +275,9 @@ typedef struct EditDerivedBMesh { /*private variables, for number of verts/edges/faces within the above hash/table members*/ int tv, te, tf; + + /*customdata layout of the tesselated faces*/ + CustomData tessface_layout; } EditDerivedBMesh; static void bmdm_recalc_lookups(EditDerivedBMesh *bmdm) @@ -1312,6 +1315,8 @@ void bmDM_faceIterStep(void *self) 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; @@ -1330,16 +1335,16 @@ void bmDM_loopIterStep(void *self) { bmDM_loopIter *iter = self; - iter->l = iter->nextl; + iter->l = BMIter_Step(&iter->iter); + if (!iter->l) { + iter->head.done = 1; + return; + } bmvert_to_mvert(iter->l->v, &iter->head.v); iter->head.index++; iter->head.vindex = BMINDEX_GET(iter->l->v); iter->head.eindex = BMINDEX_GET(iter->l->e); - - iter->nextl = BMIter_Step(&iter->iter); - - if (!iter->nextl) iter->head.done = 1; } void *bmDM_getLoopCDData(void *self, int type, int layer) @@ -1378,15 +1383,15 @@ DMLoopIter *bmDM_newLoopsIter(void *faceiter) iter->bm = fiter->bm; iter->f = fiter->f; - iter->nextl = BMIter_New(&iter->iter, iter->bm, BM_LOOPS_OF_FACE, iter->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->nextl->v, &iter->head.v); - iter->head.vindex = BMINDEX_GET(iter->nextl->v); - iter->head.eindex = BMINDEX_GET(iter->nextl->e); + bmvert_to_mvert(iter->l->v, &iter->head.v); + iter->head.vindex = BMINDEX_GET(iter->l->v); + iter->head.eindex = BMINDEX_GET(iter->l->e); return (DMLoopIter*) iter; } @@ -1450,19 +1455,76 @@ static void bmDM_release(void *dm) } } +CustomData *bmDm_getVertDataLayout(DerivedMesh *dm) +{ + EditDerivedBMesh *bmdm = (EditDerivedBMesh*)dm; + + return &bmdm->tc->bm->vdata; +} + +CustomData *bmDm_getEdgeDataLayout(DerivedMesh *dm) +{ + EditDerivedBMesh *bmdm = (EditDerivedBMesh*)dm; + + return &bmdm->tc->bm->edata; +} + +CustomData *bmDm_getTessFaceDataLayout(DerivedMesh *dm) +{ + EditDerivedBMesh *bmdm = (EditDerivedBMesh*)dm; + + return &bmdm->tessface_layout; +} + +CustomData *bmDm_getLoopDataLayout(DerivedMesh *dm) +{ + EditDerivedBMesh *bmdm = (EditDerivedBMesh*)dm; + + return &bmdm->tc->bm->ldata; +} + +CustomData *bmDm_getFaceDataLayout(DerivedMesh *dm) +{ + EditDerivedBMesh *bmdm = (EditDerivedBMesh*)dm; + + return &bmdm->tc->bm->pdata; +} + + DerivedMesh *getEditDerivedBMesh(BMEditMesh *em, Object *ob, float (*vertexCos)[3]) { EditDerivedBMesh *bmdm = MEM_callocN(sizeof(*bmdm), "bmdm"); BMesh *bm = em->bm; - + int i; + bmdm->tc = em; DM_init((DerivedMesh*)bmdm, em->bm->totvert, em->bm->totedge, em->tottri, em->bm->totloop, em->bm->totface); + + for (i=0; i<bm->ldata.totlayer; i++) { + if (bm->ldata.layers[i].type == CD_MLOOPCOL) { + CustomData_add_layer(&bmdm->tessface_layout, CD_MCOL, CD_ASSIGN, NULL, 0); + } else if (bm->ldata.layers[i].type == CD_MLOOPUV) { + CustomData_add_layer(&bmdm->tessface_layout, CD_MTFACE, CD_ASSIGN, NULL, 0); + } + } + + bmdm->dm.numVertData = bm->totvert; + bmdm->dm.numEdgeData = bm->totedge; + bmdm->dm.numFaceData = em->tottri; + bmdm->dm.numLoopData = bm->totloop; + bmdm->dm.numPolyData = bm->totface; bmdm->dm.getMinMax = bmDM_getMinMax; + bmdm->dm.getVertDataLayout = bmDm_getVertDataLayout; + bmdm->dm.getEdgeDataLayout = bmDm_getEdgeDataLayout; + bmdm->dm.getTessFaceDataLayout = bmDm_getTessFaceDataLayout; + bmdm->dm.getLoopDataLayout = bmDm_getLoopDataLayout; + bmdm->dm.getFaceDataLayout = bmDm_getFaceDataLayout; + bmdm->dm.getNumVerts = bmDM_getNumVerts; bmdm->dm.getNumEdges = bmDM_getNumEdges; bmdm->dm.getNumTessFaces = bmDM_getNumTessFaces; diff --git a/source/blender/blenkernel/intern/modifiers_bmesh.c b/source/blender/blenkernel/intern/modifiers_bmesh.c index 33ca50bfe85..f69e0efcea6 100644 --- a/source/blender/blenkernel/intern/modifiers_bmesh.c +++ b/source/blender/blenkernel/intern/modifiers_bmesh.c @@ -605,7 +605,7 @@ DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd, BMO_Finish_Op(bm, &op); BMEdit_RecalcTesselation(em); - result = CDDM_from_BMEditMesh(em, NULL); + result = CDDM_from_BMEditMesh(em, NULL); //CDDM_copy(getEditDerivedBMesh(em, ob, NULL)); BMEdit_Free(em); MEM_freeN(em); diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 93efaf87c96..ba53bbe7767 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -91,6 +91,10 @@ typedef struct CCGDerivedMesh CCGDerivedMesh; static int cgdm_getVertMapIndex(CSubSurf *ss, CCVert *v); static int cgdm_getEdgeMapIndex(CSubSurf *ss, CCEdge *e); static int cgdm_getFaceMapIndex(CSubSurf *ss, CCFace *f); +static CCGDerivedMesh *getCCGDerivedMesh(CSubSurf *ss, + int drawInteriorEdges, + int useSubsurfUv, + DerivedMesh *dm); /// @@ -177,6 +181,7 @@ static int getEdgeIndex(CSubSurf *ss, CCEdge *e, int x, int edgeSize) { return edgeBase + x-1; } } + static int getFaceIndex(CSubSurf *ss, CCFace *f, int S, int x, int y, int edgeSize, int gridSize) { int faceBase = *((int*) CCS_getFaceUserData(ss, f)); int numVerts = CCS_getFaceNumVerts(f); @@ -573,6 +578,15 @@ static DerivedMesh *ss_to_cdderivedmesh(CSubSurf *ss, int ssFromEditmesh, int drawInteriorEdges, int useSubsurfUv, DerivedMesh *dm, MultiresSubsurf *ms) { + DerivedMesh *cgdm, *result; + + cgdm = getCCGDerivedMesh(ss, drawInteriorEdges, useSubsurfUv, dm); + result = CDDM_copy(cgdm); + cgdm->needsFree = 1; + cgdm->release(cgdm); + + return result; +#if 0 DerivedMesh *result; int edgeSize = CCS_getEdgeSize(ss); int gridSize = CCS_getGridSize(ss); @@ -948,6 +962,7 @@ static DerivedMesh *ss_to_cdderivedmesh(CSubSurf *ss, int ssFromEditmesh, V_FREE(w); return result; +#endif } static void ss_sync_from_derivedmesh(CSubSurf *ss, DerivedMesh *dm, @@ -1455,6 +1470,7 @@ typedef struct cgdm_faceIter { MFace mface; cgdm_loopIter liter; + EdgeHash *ehash; /*edge map for populating loopiter->eindex*/ } cgdm_faceIter; void cgdm_faceIterStep(void *self) @@ -1494,7 +1510,7 @@ void cgdm_loopIterStep(void *self) { cgdm_loopIter *liter = self; MFace *mf = &liter->fiter->mface; - int i, in; + int i, v1, v2; if (liter->head.index >= liter->fiter->head.len) { liter->head.done = 1; @@ -1506,23 +1522,27 @@ void cgdm_loopIterStep(void *self) switch (i) { case 0: - in = liter->fiter->mface.v1; + v1 = liter->fiter->mface.v1; + v2 = liter->fiter->mface.v2; break; case 1: - in = liter->fiter->mface.v2; + v1 = liter->fiter->mface.v2; + v2 = liter->fiter->mface.v3; break; case 2: - in = liter->fiter->mface.v3; + v1 = liter->fiter->mface.v3; + v2 = liter->fiter->mface.v4; break; case 3: - in = liter->fiter->mface.v4; + v1 = liter->fiter->mface.v4; + v2 = liter->fiter->mface.v1; break; } - liter->head.vindex = in; - - /*we don't set .eindex*/ - cgdm_getFinalVert((DerivedMesh*)liter->cgdm, in, &liter->head.v); + liter->head.vindex = v1; + liter->head.eindex = GET_INT_FROM_POINTER(BLI_edgehash_lookup(liter->fiter->ehash, v1, v2)); + + cgdm_getFinalVert((DerivedMesh*)liter->cgdm, v1, &liter->head.v); } void *cgdm_loopIterGetVCData(void *self, int type, int layer) @@ -1554,11 +1574,27 @@ DMLoopIter *cgdm_faceIterGetLIter(void *self) return (DMLoopIter*) &fiter->liter; } +void cgdm_faceIterFree(void *vfiter) +{ + cgdm_faceIter *fiter = vfiter; + BLI_edgehash_free(fiter->ehash, NULL); + MEM_freeN(fiter); +} + DMFaceIter *cgdm_newFaceIter(DerivedMesh *dm) { cgdm_faceIter *fiter = MEM_callocN(sizeof(cgdm_faceIter), "cgdm_faceIter"); + MEdge medge; + int i, totedge = cgdm_getNumEdges(dm); + + fiter->ehash = BLI_edgehash_new(); - fiter->head.free = MEM_freeN; + for (i=0; i<totedge; i++) { + cgdm_getFinalEdge(dm, i, &medge); + BLI_edgehash_insert(fiter->ehash, medge.v1, medge.v2, SET_INT_IN_POINTER(i)); + } + + fiter->head.free = cgdm_faceIterFree; fiter->head.step = cgdm_faceIterStep; fiter->head.index = -1; fiter->head.getCDData = cgdm_faceIterCData; @@ -2174,7 +2210,7 @@ static void cgdm_drawFacesColored(DerivedMesh *dm, int useTwoSided, unsigned cha } static void cgdm_drawFacesTex_common(DerivedMesh *dm, - int (*drawParams)(MTFace *tface, MCol *mcol, int matnr), + int (*drawParams)(MTFace *tface, int has_vcol, int matnr), int (*drawParamsMapped)(void *userData, int index), void *userData) { @@ -2205,7 +2241,7 @@ static void cgdm_drawFacesTex_common(DerivedMesh *dm, } if(drawParams) - flag = drawParams(tf, mcol, mat_nr); + flag = drawParams(tf, mcol!=NULL, mat_nr); else flag= (drawParamsMapped)? drawParamsMapped(userData, index): 1; @@ -2305,7 +2341,7 @@ static void cgdm_drawFacesTex_common(DerivedMesh *dm, } } -static void cgdm_drawFacesTex(DerivedMesh *dm, int (*setDrawOptions)(MTFace *tface, MCol *mcol, int matnr)) +static void cgdm_drawFacesTex(DerivedMesh *dm, int (*setDrawOptions)(MTFace *tface, int has_vcol, int matnr)) { cgdm_drawFacesTex_common(dm, setDrawOptions, NULL, NULL); } @@ -2578,8 +2614,9 @@ static CCGDerivedMesh *getCCGDerivedMesh(CSubSurf *ss, int *vertOrigIndex, *faceOrigIndex, *polyOrigIndex; /* *edgeOrigIndex - as yet, unused */ int *edgeFlags; char *faceFlags, *polyFlags; - int *loopidx = NULL; + int *loopidx = NULL, *vertidx = NULL; V_DECLARE(loopidx); + V_DECLARE(vertidx); int loopindex, loopindex2; int edgeSize; int gridSize; @@ -2591,8 +2628,6 @@ static CCGDerivedMesh *getCCGDerivedMesh(CSubSurf *ss, int gridInternalEdges; int index2; float *w = NULL; - DMFaceIter *dfiter, *dfiter2; - DMLoopIter *dliter, *dliter2; WeightTable wtable = {0}; V_DECLARE(w); /* MVert *mvert = NULL; - as yet unused */ @@ -2732,52 +2767,82 @@ static CCGDerivedMesh *getCCGDerivedMesh(CSubSurf *ss, mcol = DM_get_tessface_data_layer(&cgdm->dm, CD_MCOL); index2 = 0; - dfiter = dm->newFaceIter(dm); - dfiter2 = cgdm->dm.newFaceIter(cgdm); loopindex = loopindex2 = 0; //current loop index - for (index = 0; index < totface; index++, dfiter->step(dfiter)) { + for (index = 0; index < totface; index++) { CCFace *f = cgdm->faceMap[index].face; int numVerts = CCS_getFaceNumVerts(f); int numFinalEdges = numVerts * (gridSideEdges + gridInternalEdges); int mapIndex = cgdm_getFaceMapIndex(ss, f); int origIndex = GET_INT_FROM_POINTER(CCS_getFaceFaceHandle(ss, f)); int g2_wid = gridCuts+2; + float *w2; int s, x, y; + w = get_ss_weights(&wtable, gridCuts, numVerts); + cgdm->faceMap[index].startVert = vertNum; cgdm->faceMap[index].startEdge = edgeNum; - cgdm->faceMap[index].startFace = faceNum; - - V_RESET(w); + cgdm->faceMap[index].startFace = index2; + V_RESET(loopidx); - + for (s=0; s<numVerts; s++) { V_GROW(loopidx); loopidx[s] = loopindex++; } + + V_RESET(vertidx); + for(s = 0; s < numVerts; s++) { + CCVert *v = CCS_getFaceVert(ss, f, s); + + V_GROW(vertidx); + vertidx[s] = GET_INT_FROM_POINTER(CCS_getVertVertHandle(v)); + } + - w = get_ss_weights(&wtable, gridCuts, numVerts); + w2 = w + s*numVerts*g2_wid*g2_wid; + DM_interp_vert_data(dm, &cgdm->dm, vertidx, w2, + numVerts, vertNum); + if (vertOrigIndex) + *vertOrigIndex = ORIGINDEX_NONE; + ++vertOrigIndex; + ++vertNum; - /* set the face base vert */ - *((int*)CCS_getFaceUserData(ss, f)) = vertNum; - for (s=0; s<numVerts; s++) { - int x1, y1; + /*interpolate per-vert data*/ + for(s = 0; s < numVerts; s++) { + for(x = 1; x < gridFaces; x++) { + w2 = w + s*numVerts*g2_wid*g2_wid + x*numVerts; + DM_interp_vert_data(dm, &cgdm->dm, vertidx, w2, + numVerts, vertNum); - for (y1=0; y1<gridFaces; y1++) { - for (x1=0; x1<gridFaces; x1++) { - float *w2; + if (vertOrigIndex) + *vertOrigIndex = ORIGINDEX_NONE; + ++vertOrigIndex; + ++vertNum; + } + } - x = x1; //gridFaces - x1 - 1; - y = y1; //gridFaces - y1 - 1; - //for (i=0; i<4; i++) { - /*float f1, f2; - f1 = (float)x / ((float)gridFaces-1.0f); - f2 = (float)y / ((float)gridFaces-1.0f); + for(s = 0; s < numVerts; s++) { + for(y = 1; y < gridFaces; y++) { + for(x = 1; x < gridFaces; x++) { + w2 = w + s*numVerts*g2_wid*g2_wid + (y*g2_wid+x)*numVerts; + DM_interp_vert_data(dm, &cgdm->dm, vertidx, w2, + numVerts, vertNum); - mcol->r = f1*255.0f; - mcol->g = f2*255.0f; - mcol->b = 0;*/ + if (vertOrigIndex) + *vertOrigIndex = ORIGINDEX_NONE; + ++vertOrigIndex; + ++vertNum; + } + } + } + /* set the face base vert */ + *((int*)CCS_getFaceUserData(ss, f)) = vertNum; + for (s=0; s<numVerts; s++) { + /*interpolate per-face data*/ + for (y=0; y<gridFaces; y++) { + for (x=0; x<gridFaces; x++) { w2 = w + s*numVerts*g2_wid*g2_wid + (y*g2_wid+x)*numVerts; CustomData_interp(&dm->loopData, &cgdm->dm.loopData, loopidx, w2, NULL, numVerts, loopindex2); @@ -2798,9 +2863,10 @@ static CCGDerivedMesh *getCCGDerivedMesh(CSubSurf *ss, loopidx, w2, NULL, numVerts, loopindex2); loopindex2++; - //} + /*copy over poly data, e.g. mtexpoly*/ CustomData_interp(&dm->polyData, &cgdm->dm.polyData, &origIndex, w, NULL, 1, index2); + /*generate tesselated face data used for drawing*/ ccg_loops_to_corners(&cgdm->dm.faceData, &cgdm->dm.loopData, &cgdm->dm.polyData, loopindex2-4, index2, index2, numTex, numCol); @@ -2808,6 +2874,69 @@ static CCGDerivedMesh *getCCGDerivedMesh(CSubSurf *ss, } } } + + edgeNum += numFinalEdges; + } + + for(index = 0; index < totvert; ++index) { + CCVert *v = cgdm->vertMap[index].vert; + int mapIndex = cgdm_getVertMapIndex(cgdm->ss, v); + int vidx; + + vidx = GET_INT_FROM_POINTER(CCS_getVertVertHandle(v)); + + cgdm->vertMap[index].startVert = vertNum; + + /* set the vert base vert */ + *((int*) CCS_getVertUserData(ss, v)) = vertNum; + + DM_copy_vert_data(dm, &cgdm->dm, vidx, vertNum, 1); + + *vertOrigIndex = mapIndex; + ++vertOrigIndex; + ++vertNum; + } + + edgeFlags = DM_get_edge_data_layer(&cgdm->dm, CD_FLAGS); + for(index = 0; index < totedge; ++index) { + CCEdge *e = cgdm->edgeMap[index].edge; + int numFinalEdges = edgeSize - 1; + int mapIndex = cgdm_getEdgeMapIndex(ss, e); + int x; + int vertIdx[2]; + int edgeIdx = GET_INT_FROM_POINTER(CCS_getEdgeEdgeHandle(e)); + + CCVert *v; + v = CCS_getEdgeVert0(e); + vertIdx[0] = GET_INT_FROM_POINTER(CCS_getVertVertHandle(v)); + v = CCS_getEdgeVert1(e); + vertIdx[1] = GET_INT_FROM_POINTER(CCS_getVertVertHandle(v)); + + cgdm->edgeMap[index].startVert = vertNum; + cgdm->edgeMap[index].startEdge = edgeNum; + + /* set the edge base vert */ + *((int*)CCS_getEdgeUserData(ss, e)) = vertNum; + + for(x = 1; x < edgeSize - 1; x++) { + float w[2]; + w[1] = (float) x / (edgeSize - 1); + w[0] = 1 - w[1]; + DM_interp_vert_data(dm, &cgdm->dm, vertIdx, w, 2, vertNum); + *vertOrigIndex = ORIGINDEX_NONE; + ++vertOrigIndex; + ++vertNum; + } + + for(i = 0; i < numFinalEdges; ++i) { + if(edgeIdx >= 0 && edgeFlags) + edgeFlags[edgeNum + i] = medge[edgeIdx].flag; + + *(int *)DM_get_edge_data(&cgdm->dm, edgeNum + i, + CD_ORIGINDEX) = mapIndex; + } + + edgeNum += numFinalEdges; } #if 0 for(index = 0; index < totface; ++index) { @@ -2838,7 +2967,6 @@ static CCGDerivedMesh *getCCGDerivedMesh(CSubSurf *ss, ++vertOrigIndex; ++vertNum; - for(S = 0; S < numVerts; S++) { int prevS = (S - 1 + numVerts) % numVerts; int nextS = (S + 1) % numVerts; |