From 1c0cf60377f4dfeec7f6faec9eac4213ef4a45ba Mon Sep 17 00:00:00 2001 From: Joseph Eagar Date: Wed, 23 Feb 2011 00:01:50 +0000 Subject: [PATCH] =bmesh= Fixed join meshes, and an annoying modifier bug (making modifiers not work in editmode). Also fixed a tesselation bug. Also got edge slide to work right, yay! Dunno why I couldn't get it working right before; took me twenty minutes to fix. --- .../blender/blenkernel/intern/cdderivedmesh.c | 2 - source/blender/blenkernel/intern/mesh.c | 48 +++++------------ source/blender/bmesh/bmesh.h | 2 +- source/blender/bmesh/intern/bmesh_newcore.c | 5 +- source/blender/editors/mesh/knifetool.c | 6 ++- source/blender/editors/mesh/meshtools.c | 12 ++--- .../blender/editors/space_view3d/drawobject.c | 3 ++ source/blender/editors/transform/transform.c | 54 ++++++++----------- source/blender/modifiers/intern/MOD_mirror.c | 2 +- 9 files changed, 53 insertions(+), 81 deletions(-) diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index c3404e35c05..107ea5f35fe 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -1794,8 +1794,6 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *me) CD_CALLOC, dm->numVertData); CustomData_merge(&em->bm->edata, &dm->edgeData, CD_MASK_DERIVEDMESH, CD_CALLOC, dm->numEdgeData); - CustomData_merge(&em->bm->pdata, &dm->faceData, CD_MASK_DERIVEDMESH, - CD_CALLOC, dm->numFaceData); CustomData_merge(&em->bm->ldata, &dm->loopData, CD_MASK_DERIVEDMESH, CD_CALLOC, dm->numLoopData); CustomData_merge(&em->bm->pdata, &dm->polyData, CD_MASK_DERIVEDMESH, diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 3949902607b..f205d8f9e9a 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -1923,38 +1923,14 @@ int mesh_recalcTesselation(CustomData *fdata, mp = mpoly; polyorigIndex = use_poly_origindex? CustomData_get_layer(pdata, CD_ORIGINDEX) : NULL; for (i=0; iloopstart; - - if (mp->totloop < 5) { - BLI_array_growone(mf); - BLI_array_growone(origIndex); + if (mp->totloop > 2) { + ml = mloop + mp->loopstart; - origIndex[k] = use_face_origindex ? k : i; - - for (j=0; jtotloop; j++, ml++) { - switch (j) { - case 0: - mf[k].v1 = mp->loopstart + j; - case 1: - mf[k].v2 = mp->loopstart + j; - case 2: - mf[k].v3 = mp->loopstart + j; - case 3: - mf[k].v4 = mp->loopstart + j; - } - } - if (mp->totloop == 4 && !mf->v4) { - SWAP(int, mf[k].v1, mf[k].v4); - SWAP(int, mf[k].v2, mf[k].v3); - } - - k++; - } else { firstv = NULL; lastv = NULL; for (j=0; jtotloop; j++, ml++) { v = BLI_addfillvert(mvert[ml->v].co); - if (polyorigIndex) + if (polyorigIndex && use_poly_origindex) v->tmp.l = polyorigIndex[i]; else v->tmp.l = i; @@ -1980,6 +1956,8 @@ int mesh_recalcTesselation(CustomData *fdata, mf[k].v1 = f->v1->keyindex; mf[k].v2 = f->v2->keyindex; mf[k].v3 = f->v3->keyindex; + + /*put poly index in mf->v4*/ mf[k].v4 = f->v1->tmp.l; mf[k].mat_nr = mp->mat_nr; @@ -2003,28 +1981,28 @@ int mesh_recalcTesselation(CustomData *fdata, mface = mf; for (i=0; iv1 > mf->v2) SWAP(int, mf->v1, mf->v2); - if (mf->v2 > mf->v3) SWAP(int, mf->v2, mf->v3); - if (mf->v1 > mf->v2) SWAP(int, mf->v1, mf->v2); - if (mf->v4 && mf->v1 > mf->v4) SWAP(int, mf->v1, mf->v4); + /*sort loop indices to ensure winding is correct*/ if (mf->v1 > mf->v2) SWAP(int, mf->v1, mf->v2); if (mf->v2 > mf->v3) SWAP(int, mf->v2, mf->v3); if (mf->v1 > mf->v2) SWAP(int, mf->v1, mf->v2); + if (mf->v1 > mf->v2) SWAP(int, mf->v1, mf->v2); + if (mf->v2 > mf->v3) SWAP(int, mf->v2, mf->v3); + if (mf->v1 > mf->v2) SWAP(int, mf->v1, mf->v2); + lindex[0] = mf->v1; lindex[1] = mf->v2; lindex[2] = mf->v3; - lindex[4] = mf->v4; /*transform loop indices to vert indices*/ mf->v1 = mloop[mf->v1].v; mf->v2 = mloop[mf->v2].v; mf->v3 = mloop[mf->v3].v; - mf->v4 = mf->v4 ? mloop[mf->v4].v : 0; mesh_loops_to_corners(fdata, ldata, pdata, - lindex, i, mf->v4, numTex, numCol, mf->v4 ? 4 : 3); + lindex, i, mf->v4, numTex, numCol, 3); + + mf->v4 = 0; } return totface; diff --git a/source/blender/bmesh/bmesh.h b/source/blender/bmesh/bmesh.h index 53d724d6e8d..01f714000f0 100644 --- a/source/blender/bmesh/bmesh.h +++ b/source/blender/bmesh/bmesh.h @@ -144,7 +144,7 @@ defining edges[0], and define the winding of the new face.*/ struct BMFace *BM_Make_Ngon ( struct BMesh *bm, struct BMVert *v1, struct BMVert *v2, struct BMEdge **edges, int len, int nodouble ); /*stuff for dealing with header flags*/ -#define BM_TestHFlag(ele, f) (((BMHeader*)ele)->flag & (f)) +#define BM_TestHFlag(ele, f) (ele && (((BMHeader*)ele)->flag & (f))) #define BM_SetHFlag(ele, f) (((BMHeader*)ele)->flag = ((BMHeader*)ele)->flag | (f)) #define BM_ClearHFlag(ele, f) (((BMHeader*)ele)->flag = ((BMHeader*)ele)->flag & ~(f)) diff --git a/source/blender/bmesh/intern/bmesh_newcore.c b/source/blender/bmesh/intern/bmesh_newcore.c index 7d2af4d3430..dc0225e5440 100644 --- a/source/blender/bmesh/intern/bmesh_newcore.c +++ b/source/blender/bmesh/intern/bmesh_newcore.c @@ -657,7 +657,7 @@ void bmesh_clear_systag_elements(BMesh *bm, void *veles, int tot, int flag) static int count_flagged_radial(BMLoop *l, int flag) { BMLoop *l2 = l; - int i = 0; + int i = 0, c=0; do { if (!l2) { @@ -667,10 +667,11 @@ static int count_flagged_radial(BMLoop *l, int flag) i += bmesh_api_getflag(l2->f, flag) ? 1 : 0; l2 = bmesh_radial_nextloop(l2); - if (i >= 800000) { + if (c >= 800000) { bmesh_error(); return 0; } + c++; } while (l2 != l); return i; diff --git a/source/blender/editors/mesh/knifetool.c b/source/blender/editors/mesh/knifetool.c index 6d648d0e0cc..84b3771272e 100755 --- a/source/blender/editors/mesh/knifetool.c +++ b/source/blender/editors/mesh/knifetool.c @@ -1583,7 +1583,11 @@ static int knifetool_invoke (bContext *C, wmOperator *op, wmEvent *evt) static int knifetool_modal (bContext *C, wmOperator *op, wmEvent *event) { knifetool_opdata *kcd= op->customdata; - + + if (!C) { + return OPERATOR_FINISHED; + } + view3d_operator_needs_opengl(C); switch (event->type) { diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 35e1a0975e5..a99ca251cc2 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -435,8 +435,6 @@ int join_mesh_exec(bContext *C, wmOperator *op) medge->v1+= vertofs; medge->v2+= vertofs; } - - edgeofs += me->totedge; } if (me->totloop) { @@ -447,8 +445,6 @@ int join_mesh_exec(bContext *C, wmOperator *op) mloop->v += vertofs; mloop->e += edgeofs; } - - loopofs += me->totloop; } if(me->totpoly) { @@ -472,13 +468,15 @@ int join_mesh_exec(bContext *C, wmOperator *op) mpoly->mat_nr= matmap[(int)mpoly->mat_nr]; } - polyofs += me->totface; + polyofs += me->totpoly; } - /* vertofs is used to help newly added verts be reattached to their edge/face - * (cannot be set earlier, or else reattaching goes wrong) + /* these are used for relinking (cannot be set earlier, + * or else reattaching goes wrong) */ vertofs += me->totvert; + edgeofs += me->totedge; + loopofs += me->totloop; /* free base, now that data is merged */ if(base->object != ob) diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 887eeb8c330..6b3d9abf181 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -1992,6 +1992,9 @@ static int draw_dm_faces_sel__setDrawOptions(void *userData, int index, int *dra int vcount, pin=0; int opac = UI_GetThemeValue(TH_PIN_OPAC); + if (!efa) + return 0; + if (!BM_TestHFlag(efa, BM_HIDDEN)) { /* Check if all verts of a face are pinned. If so, then display it in a darker shade. */ diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index ce447374bed..31fd6f70842 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -4460,38 +4460,44 @@ static int createSlideVerts(TransInfo *t) TransDataSlideVert *sv1, *sv2; float vec1[3], dis2, ec2[3], vec[3], mval[2] = {t->mval[0], t->mval[1]}, d, z2; - /*search cross edges for magnitude of transform vector*/ + /*search cross edges for visible edge to the mouse cursor, + then use the shared vertex to calculate screen vector*/ dis2 = -1.0f; for (i=0; i<2; i++) { - BM_ITER(e2, &iter2, em->bm, BM_EDGES_OF_VERT, i?e->v1:e->v2) { + v = i?e->v1:e->v2; + BM_ITER(e2, &iter2, em->bm, BM_EDGES_OF_VERT, v) { if (BM_TestHFlag(e2, BM_SELECT)) continue; if (!BMBVH_EdgeVisible(btree, e2, v3d, t->obedit)) continue; - view3d_project_float_v3(ar, e2->v1->co, vec1, projectMat); - view3d_project_float_v3(ar, e2->v2->co, vec2, projectMat); + j = GET_INT_FROM_POINTER(BLI_smallhash_lookup(&table, (intptr_t)v)); + + if (tempsv[j].down) { + view3d_project_float_v3(ar, tempsv[j].down->co, vec1, projectMat); + } else { + add_v3_v3v3(vec1, v->co, tempsv[j].downvec); + view3d_project_float_v3(ar, vec1, vec1, projectMat); + } + + if (tempsv[j].up) { + view3d_project_float_v3(ar, tempsv[j].up->co, vec2, projectMat); + } else { + add_v3_v3v3(vec1, v->co, tempsv[j].upvec); + view3d_project_float_v3(ar, vec2, vec2, projectMat); + } + d = dist_to_line_segment_v2(mval, vec1, vec2); if (dis2 == -1.0f || d < dis2) { dis2 = d; ee = e2; size = len_v3v3(vec1, vec2); + sub_v3_v3v3(dir, vec1, vec2); } } } - - view3d_project_float_v3(ar, e->v1->co, vec1, projectMat); - view3d_project_float_v3(ar, e->v2->co, vec2, projectMat); - - d = dist_to_line_segment_v2(mval, vec1, vec2); - if ((d < dis || dis == -1.0) && (!le || BMBVH_EdgeVisible(btree, e, v3d, t->obedit))) { - le = e; - dis = d; - sub_v3_v3v3(dir, vec1, vec2); - normalize_v3(dir); - } } } @@ -4500,23 +4506,7 @@ static int createSlideVerts(TransInfo *t) /*dir holds a vector along edge loop*/ copy_v3_v3(end, dir); - - /*find perpindicular 2d line*/ - SWAP(float, end[0], end[1]); - - if (le) { - j = GET_INT_FROM_POINTER(BLI_smallhash_lookup(&table, (intptr_t)le->v1)); - sv = tempsv + j; - copy_v3_v3(vec, sv->upvec); - normalize_v3(vec); - - if (dot_v2v2(vec, end) > 0.0) { - mul_v3_fl(end, -1.0); - } - } - - size *= 0.5; - mul_v3_fl(end, size); + mul_v3_fl(end, 0.5); sld->start[0] = t->mval[0] + start[0]; sld->start[1] = t->mval[1] + start[1]; diff --git a/source/blender/modifiers/intern/MOD_mirror.c b/source/blender/modifiers/intern/MOD_mirror.c index 7a92242ba74..f393d834874 100644 --- a/source/blender/modifiers/intern/MOD_mirror.c +++ b/source/blender/modifiers/intern/MOD_mirror.c @@ -189,7 +189,7 @@ DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd, BMEdit_Free(em); MEM_freeN(em); - + return result; }