diff options
author | Joseph Eagar <joeedh@gmail.com> | 2009-08-25 14:21:10 +0400 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2009-08-25 14:21:10 +0400 |
commit | 0ea787041d2584b74bee66b854728fa9590bd487 (patch) | |
tree | 9889d957794ee1616e7d60f28a29ea19eb090869 /source/blender | |
parent | 8151a5168422d6b1f974d238f37707f7bc507db7 (diff) |
subsurf works now! YES! take *that* subsurf_ccg.cscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen,editors_space_api,bf_windowmanager,bf_wm still an issue with some modifier combinations though, and I think there's some memory corruption going on, need to valgrind it.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 21 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/cdderivedmesh.c | 7 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/modifiers_bmesh.c | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 62 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_walkers.c | 4 | ||||
-rw-r--r-- | source/blender/editors/mesh/bmesh_tools.c | 75 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_tools.c | 74 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_customdata_types.h | 4 |
8 files changed, 125 insertions, 127 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index f1117a967fd..d32da467845 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -310,6 +310,11 @@ void dm_add_polys_from_iter(CustomData *ldata, CustomData *pdata, DerivedMesh *d for (i=0; i<opdata->totlayer; i++) { void *e1, *e2; + if (opdata->layers[i].type == lasttype) + j++; + else + j = 0; + if (opdata->layers[i].type == CD_MPOLY) continue; @@ -321,11 +326,6 @@ void dm_add_polys_from_iter(CustomData *ldata, CustomData *pdata, DerivedMesh *d 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; } @@ -342,6 +342,11 @@ void dm_add_polys_from_iter(CustomData *ldata, CustomData *pdata, DerivedMesh *d 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); @@ -349,12 +354,6 @@ void dm_add_polys_from_iter(CustomData *ldata, CustomData *pdata, DerivedMesh *d continue; 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; } } diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 0f7ebc05558..b137f6d9963 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -1417,6 +1417,7 @@ DerivedMesh *CDDM_copy(DerivedMesh *source) CustomData_add_layer(&dm->faceData, CD_MFACE, CD_ASSIGN, cddm->mface, numFaces); DM_DupPolys(source, dm); + //CDDM_tessfaces_to_faces(dm); cddm->mloop = CustomData_get_layer(&dm->loopData, CD_MLOOP); cddm->mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY); @@ -1662,6 +1663,10 @@ void CDDM_tessfaces_to_faces(DerivedMesh *dm) EdgeHash *eh = BLI_edgehash_new(); int i, l, totloop, *index1, *index2; + /*ensure we have all the edges we need*/ + CDDM_calc_edges(dm); + + /*build edge hash*/ me = cddm->medge; for (i=0; i<cddm->dm.numEdgeData; i++, me++) { BLI_edgehash_insert(eh, me->v1, me->v2, SET_INT_IN_POINTER(i)); @@ -1687,7 +1692,7 @@ void CDDM_tessfaces_to_faces(DerivedMesh *dm) CustomData_add_layer(&cddm->dm.loopData, CD_MLOOP, CD_ASSIGN, cddm->mloop, totloop); CustomData_add_layer(&cddm->dm.polyData, CD_MPOLY, CD_ASSIGN, cddm->mpoly, cddm->dm.numPolyData); CustomData_merge(&cddm->dm.faceData, &cddm->dm.polyData, - CD_MASK_DERIVEDMESH, CD_DUPLICATE, cddm->dm.numFaceData); + CD_MASK_ORIGINDEX, CD_DUPLICATE, cddm->dm.numFaceData); index1 = CustomData_get_layer(&cddm->dm.faceData, CD_ORIGINDEX); index2 = CustomData_get_layer(&cddm->dm.polyData, CD_ORIGINDEX); diff --git a/source/blender/blenkernel/intern/modifiers_bmesh.c b/source/blender/blenkernel/intern/modifiers_bmesh.c index 74a6e920d69..f7d2d91bb77 100644 --- a/source/blender/blenkernel/intern/modifiers_bmesh.c +++ b/source/blender/blenkernel/intern/modifiers_bmesh.c @@ -198,12 +198,13 @@ BMEditMesh *CDDM_To_BMesh(DerivedMesh *dm, BMEditMesh *existing) break; f = BM_Make_Ngon(bm, verts[0], verts[1], edges, dfiter->len, 0); - f->head.flag = MEFlags_To_BMFlags(dfiter->flags, BM_FACE); - f->mat_nr = dfiter->mat_nr; if (!f) continue; + f->head.flag = MEFlags_To_BMFlags(dfiter->flags, BM_FACE); + f->mat_nr = dfiter->mat_nr; + dliter = dfiter->getLoopsIter(dfiter); l = BMIter_New(&liter, bm, BM_LOOPS_OF_FACE, f); for (j=0; l; l=BMIter_Step(&liter)) { diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 34e517dcf3c..820aa9e1b21 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -540,28 +540,6 @@ static float *get_ss_weights(WeightTable *wtable, int gridCuts, int faceLen) } return wtable->weight_table[faceLen].w; -#if 0 - /*ensure we have at least the triangle and quad weights*/ - if (wtable->len < 4) { - wtable->weight_table = MEM_callocN(sizeof(FaceVertWeightEntry)*5, "weight table alloc"); - wtable->len = 5; - - calc_ss_weights(gridFaces, &wtable->weight_table[4].weight, &wtable->weight_table[3].weight); - wtable->weight_table[4].valid = wtable->weight_table[3].valid = 1; - } - - if (wtable->len <= faceLen) { - void *tmp = MEM_callocN(sizeof(FaceVertWeightEntry)*(faceLen+1), "weight table alloc 2"); - - memcpy(tmp, wtable->weight_table, sizeof(FaceVertWeightEntry)*wtable->len); - MEM_freeN(wtable->weight_table); - - wtable->weight_table = tmp; - wtable->len = faceLen+1; - } - - return wtable->weight_table[faceLen].weight; -#endif } void free_ss_weights(WeightTable *wtable) @@ -2631,7 +2609,6 @@ static CCGDerivedMesh *getCCGDerivedMesh(CSubSurf *ss, int gridSideEdges; int numTex, numCol; int gridInternalEdges; - int index2; float *w = NULL, one = 1.0f; WeightTable wtable = {0}; V_DECLARE(w); @@ -2655,9 +2632,9 @@ static CCGDerivedMesh *getCCGDerivedMesh(CSubSurf *ss, numTex = CustomData_number_of_layers(&cgdm->dm.loopData, CD_MLOOPUV); numCol = CustomData_number_of_layers(&cgdm->dm.loopData, CD_MLOOPCOL); - if (numTex && CustomData_number_of_layers(&cgdm->dm.faceData, CD_MTFACE)==0) + if (numTex && CustomData_number_of_layers(&cgdm->dm.faceData, CD_MTFACE) != numTex) CustomData_from_bmeshpoly(&cgdm->dm.faceData, &cgdm->dm.polyData, &cgdm->dm.loopData, CCS_getNumFinalFaces(ss)); - else if (numCol && CustomData_number_of_layers(&cgdm->dm.faceData, CD_MCOL)==0) + else if (numCol && CustomData_number_of_layers(&cgdm->dm.faceData, CD_MCOL) != numCol) CustomData_from_bmeshpoly(&cgdm->dm.faceData, &cgdm->dm.polyData, &cgdm->dm.loopData, CCS_getNumFinalFaces(ss)); CustomData_set_layer_flag(&cgdm->dm.faceData, CD_FLAGS, CD_FLAG_NOCOPY); @@ -2771,7 +2748,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CSubSurf *ss, mcol = DM_get_tessface_data_layer(&cgdm->dm, CD_MCOL); - index2 = 0; + faceNum = 0; loopindex = loopindex2 = 0; //current loop index for (index = 0; index < totface; index++) { CCFace *f = cgdm->faceMap[index].face; @@ -2787,10 +2764,12 @@ static CCGDerivedMesh *getCCGDerivedMesh(CSubSurf *ss, cgdm->faceMap[index].startVert = vertNum; cgdm->faceMap[index].startEdge = edgeNum; - cgdm->faceMap[index].startFace = index2; - - V_RESET(loopidx); + cgdm->faceMap[index].startFace = faceNum; + /* set the face base vert */ + *((int*)CCS_getFaceUserData(ss, f)) = vertNum; + + V_RESET(loopidx); for (s=0; s<numVerts; s++) { V_GROW(loopidx); loopidx[s] = loopindex++; @@ -2805,7 +2784,8 @@ static CCGDerivedMesh *getCCGDerivedMesh(CSubSurf *ss, } - w2 = w + s*numVerts*g2_wid*g2_wid; + /*I think this is for interpolating the center vert?*/ + w2 = w; // + numVerts*(g2_wid-1)*(g2_wid-1); //numVerts*((g2_wid-1)*g2_wid+g2_wid-1); DM_interp_vert_data(dm, &cgdm->dm, vertidx, w2, numVerts, vertNum); if (vertOrigIndex) @@ -2827,6 +2807,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CSubSurf *ss, } } + /*interpolate per-vert data*/ for(s = 0; s < numVerts; s++) { for(y = 1; y < gridFaces; y++) { for(x = 1; x < gridFaces; x++) { @@ -2842,8 +2823,9 @@ static CCGDerivedMesh *getCCGDerivedMesh(CSubSurf *ss, } } - /* set the face base vert */ - *((int*)CCS_getFaceUserData(ss, f)) = vertNum; + for(i = 0; i < numFinalEdges; ++i) + *(int *)DM_get_edge_data(&cgdm->dm, edgeNum + i, + CD_ORIGINDEX) = ORIGINDEX_NONE; for (s=0; s<numVerts; s++) { /*interpolate per-face data*/ for (y=0; y<gridFaces; y++) { @@ -2867,16 +2849,16 @@ static CCGDerivedMesh *getCCGDerivedMesh(CSubSurf *ss, CustomData_interp(&dm->loopData, &cgdm->dm.loopData, loopidx, w2, NULL, numVerts, loopindex2); loopindex2++; - + /*copy over poly data, e.g. mtexpoly*/ - CustomData_interp(&dm->polyData, &cgdm->dm.polyData, &origIndex, &one, NULL, 1, index2); + CustomData_copy_data(&dm->polyData, &cgdm->dm.polyData, origIndex, faceNum, 1); + //CustomData_interp(&dm->polyData, &cgdm->dm.polyData, &origIndex, &one, NULL, 1, faceNum); /*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); + &cgdm->dm.polyData, loopindex2-4, faceNum, faceNum, numTex, numCol); faceNum++; - index2++; } } } @@ -2944,6 +2926,12 @@ static CCGDerivedMesh *getCCGDerivedMesh(CSubSurf *ss, ++vertOrigIndex; ++vertNum; } + + cgdm->dm.numVertData = vertNum; + cgdm->dm.numEdgeData = edgeNum; + cgdm->dm.numFaceData = faceNum; + cgdm->dm.numLoopData = loopindex2; + cgdm->dm.numPolyData = faceNum; #if 0 for(index = 0; index < totface; ++index) { CCFace *f = cgdm->faceMap[index].face; @@ -3182,7 +3170,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived_with_multires( return result; } else { - int useIncremental = (smd->flags & eSubsurfModifierFlag_Incremental); + int useIncremental = 1; //(smd->flags & eSubsurfModifierFlag_Incremental); int useAging = smd->flags & eSubsurfModifierFlag_DebugIncr; CSubSurf *ss; diff --git a/source/blender/bmesh/intern/bmesh_walkers.c b/source/blender/bmesh/intern/bmesh_walkers.c index 117512804c8..e00c45198aa 100644 --- a/source/blender/bmesh/intern/bmesh_walkers.c +++ b/source/blender/bmesh/intern/bmesh_walkers.c @@ -659,6 +659,10 @@ static void *loopWalker_step(BMWalker *walker) if (rlen != 1 && i == stopi) break; l = BM_OtherFaceLoop(l->e, l->f, v); + + if (!l) + break; + l2 = bmesh_radial_nextloop(l); if (l2 == l) { diff --git a/source/blender/editors/mesh/bmesh_tools.c b/source/blender/editors/mesh/bmesh_tools.c index b6aab260261..5e5452c5cc9 100644 --- a/source/blender/editors/mesh/bmesh_tools.c +++ b/source/blender/editors/mesh/bmesh_tools.c @@ -1965,3 +1965,78 @@ void MESH_OT_bm_test(wmOperatorType *ot) //RNA_def_int(ot->srna, "repeat", 1, 1, 100, "Number of times to smooth the mesh", "", 1, INT_MAX); } + +/********************** Smooth/Solid Operators *************************/ + +void mesh_set_smooth_faces(BMEditMesh *em, short smooth) +{ + BMIter iter; + BMFace *efa; + + if(em==NULL) return; + + BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { + if (BM_TestHFlag(efa, BM_SELECT)) { + if (smooth) + BM_SetHFlag(efa, BM_SMOOTH); + else + BM_ClearHFlag(efa, BM_SMOOTH); + } + } +} + +static int mesh_faces_shade_smooth_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + Object *obedit= CTX_data_edit_object(C); + BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + + mesh_set_smooth_faces(em, 1); + + DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit); + + return OPERATOR_FINISHED; +} + +void MESH_OT_faces_shade_smooth(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Shade Smooth"; + ot->idname= "MESH_OT_faces_shade_smooth"; + + /* api callbacks */ + ot->exec= mesh_faces_shade_smooth_exec; + ot->poll= ED_operator_editmesh; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +static int mesh_faces_shade_flat_exec(bContext *C, wmOperator *op) +{ + Scene *scene = CTX_data_scene(C); + Object *obedit= CTX_data_edit_object(C); + BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh; + + mesh_set_smooth_faces(em, 0); + + DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit); + + return OPERATOR_FINISHED; +} + +void MESH_OT_faces_shade_flat(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Shade Flat"; + ot->idname= "MESH_OT_faces_shade_flat"; + + /* api callbacks */ + ot->exec= mesh_faces_shade_flat_exec; + ot->poll= ED_operator_editmesh; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index ec06d84a786..3abc4796ccf 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -6762,77 +6762,3 @@ void MESH_OT_edge_flip(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -/********************** Smooth/Solid Operators *************************/ - -void mesh_set_smooth_faces(EditMesh *em, short smooth) -{ - EditFace *efa; - - if(em==NULL) return; - - for(efa= em->faces.first; efa; efa=efa->next) { - if(efa->f & SELECT) { - if(smooth) efa->flag |= ME_SMOOTH; - else efa->flag &= ~ME_SMOOTH; - } - } -} - -static int mesh_faces_shade_smooth_exec(bContext *C, wmOperator *op) -{ - Scene *scene= CTX_data_scene(C); - Object *obedit= CTX_data_edit_object(C); - EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data); - - mesh_set_smooth_faces(em, 1); - - BKE_mesh_end_editmesh(obedit->data, em); - - DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit); - - return OPERATOR_FINISHED; -} - -void MESH_OT_faces_shade_smooth(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Shade Smooth"; - ot->idname= "MESH_OT_faces_shade_smooth"; - - /* api callbacks */ - ot->exec= mesh_faces_shade_smooth_exec; - ot->poll= ED_operator_editmesh; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -static int mesh_faces_shade_flat_exec(bContext *C, wmOperator *op) -{ - Scene *scene = CTX_data_scene(C); - Object *obedit= CTX_data_edit_object(C); - EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data); - - mesh_set_smooth_faces(em, 0); - - DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit); - - return OPERATOR_FINISHED; -} - -void MESH_OT_faces_shade_flat(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Shade Flat"; - ot->idname= "MESH_OT_faces_shade_flat"; - - /* api callbacks */ - ot->exec= mesh_faces_shade_flat_exec; - ot->poll= ED_operator_editmesh; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - diff --git a/source/blender/makesdna/DNA_customdata_types.h b/source/blender/makesdna/DNA_customdata_types.h index 98cf7379df9..0d8418d39b2 100644 --- a/source/blender/makesdna/DNA_customdata_types.h +++ b/source/blender/makesdna/DNA_customdata_types.h @@ -62,13 +62,13 @@ typedef struct CustomData { #define CD_MFACE 4 #define CD_MTFACE 5 #define CD_MCOL 6 -#define CD_ORIGINDEX 7 +#define CD_ORIGINDEX 7 #define CD_NORMAL 8 #define CD_FLAGS 9 #define CD_PROP_FLT 10 #define CD_PROP_INT 11 #define CD_PROP_STR 12 -#define CD_ORIGSPACE 13 /* for modifier stack face location mapping */ +#define CD_ORIGSPACE 13 /* for modifier stack face location mapping */ #define CD_ORCO 14 #define CD_MTEXPOLY 15 #define CD_MLOOPUV 16 |