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.
This commit is contained in:
Joseph Eagar 2011-02-23 00:01:50 +00:00
parent 8b4eab10f1
commit 1c0cf60377
9 changed files with 53 additions and 81 deletions

@ -1794,8 +1794,6 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *me)
CD_CALLOC, dm->numVertData); CD_CALLOC, dm->numVertData);
CustomData_merge(&em->bm->edata, &dm->edgeData, CD_MASK_DERIVEDMESH, CustomData_merge(&em->bm->edata, &dm->edgeData, CD_MASK_DERIVEDMESH,
CD_CALLOC, dm->numEdgeData); 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, CustomData_merge(&em->bm->ldata, &dm->loopData, CD_MASK_DERIVEDMESH,
CD_CALLOC, dm->numLoopData); CD_CALLOC, dm->numLoopData);
CustomData_merge(&em->bm->pdata, &dm->polyData, CD_MASK_DERIVEDMESH, CustomData_merge(&em->bm->pdata, &dm->polyData, CD_MASK_DERIVEDMESH,

@ -1923,38 +1923,14 @@ int mesh_recalcTesselation(CustomData *fdata,
mp = mpoly; mp = mpoly;
polyorigIndex = use_poly_origindex? CustomData_get_layer(pdata, CD_ORIGINDEX) : NULL; polyorigIndex = use_poly_origindex? CustomData_get_layer(pdata, CD_ORIGINDEX) : NULL;
for (i=0; i<totpoly; i++, mp++) { for (i=0; i<totpoly; i++, mp++) {
ml = mloop + mp->loopstart; if (mp->totloop > 2) {
ml = mloop + mp->loopstart;
if (mp->totloop < 5) {
BLI_array_growone(mf);
BLI_array_growone(origIndex);
origIndex[k] = use_face_origindex ? k : i;
for (j=0; j<mp->totloop; 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; firstv = NULL;
lastv = NULL; lastv = NULL;
for (j=0; j<mp->totloop; j++, ml++) { for (j=0; j<mp->totloop; j++, ml++) {
v = BLI_addfillvert(mvert[ml->v].co); v = BLI_addfillvert(mvert[ml->v].co);
if (polyorigIndex) if (polyorigIndex && use_poly_origindex)
v->tmp.l = polyorigIndex[i]; v->tmp.l = polyorigIndex[i];
else else
v->tmp.l = i; v->tmp.l = i;
@ -1980,6 +1956,8 @@ int mesh_recalcTesselation(CustomData *fdata,
mf[k].v1 = f->v1->keyindex; mf[k].v1 = f->v1->keyindex;
mf[k].v2 = f->v2->keyindex; mf[k].v2 = f->v2->keyindex;
mf[k].v3 = f->v3->keyindex; mf[k].v3 = f->v3->keyindex;
/*put poly index in mf->v4*/
mf[k].v4 = f->v1->tmp.l; mf[k].v4 = f->v1->tmp.l;
mf[k].mat_nr = mp->mat_nr; mf[k].mat_nr = mp->mat_nr;
@ -2003,28 +1981,28 @@ int mesh_recalcTesselation(CustomData *fdata,
mface = mf; mface = mf;
for (i=0; i<totface; i++, mf++) { for (i=0; i<totface; i++, mf++) {
/*ensure winding is correct*/ /*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->v4 && mf->v1 > mf->v4) SWAP(int, mf->v1, mf->v4);
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->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->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[0] = mf->v1;
lindex[1] = mf->v2; lindex[1] = mf->v2;
lindex[2] = mf->v3; lindex[2] = mf->v3;
lindex[4] = mf->v4;
/*transform loop indices to vert indices*/ /*transform loop indices to vert indices*/
mf->v1 = mloop[mf->v1].v; mf->v1 = mloop[mf->v1].v;
mf->v2 = mloop[mf->v2].v; mf->v2 = mloop[mf->v2].v;
mf->v3 = mloop[mf->v3].v; mf->v3 = mloop[mf->v3].v;
mf->v4 = mf->v4 ? mloop[mf->v4].v : 0;
mesh_loops_to_corners(fdata, ldata, pdata, 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; return totface;

@ -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 ); 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*/ /*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_SetHFlag(ele, f) (((BMHeader*)ele)->flag = ((BMHeader*)ele)->flag | (f))
#define BM_ClearHFlag(ele, f) (((BMHeader*)ele)->flag = ((BMHeader*)ele)->flag & ~(f)) #define BM_ClearHFlag(ele, f) (((BMHeader*)ele)->flag = ((BMHeader*)ele)->flag & ~(f))

@ -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) static int count_flagged_radial(BMLoop *l, int flag)
{ {
BMLoop *l2 = l; BMLoop *l2 = l;
int i = 0; int i = 0, c=0;
do { do {
if (!l2) { if (!l2) {
@ -667,10 +667,11 @@ static int count_flagged_radial(BMLoop *l, int flag)
i += bmesh_api_getflag(l2->f, flag) ? 1 : 0; i += bmesh_api_getflag(l2->f, flag) ? 1 : 0;
l2 = bmesh_radial_nextloop(l2); l2 = bmesh_radial_nextloop(l2);
if (i >= 800000) { if (c >= 800000) {
bmesh_error(); bmesh_error();
return 0; return 0;
} }
c++;
} while (l2 != l); } while (l2 != l);
return i; return i;

@ -1583,7 +1583,11 @@ static int knifetool_invoke (bContext *C, wmOperator *op, wmEvent *evt)
static int knifetool_modal (bContext *C, wmOperator *op, wmEvent *event) static int knifetool_modal (bContext *C, wmOperator *op, wmEvent *event)
{ {
knifetool_opdata *kcd= op->customdata; knifetool_opdata *kcd= op->customdata;
if (!C) {
return OPERATOR_FINISHED;
}
view3d_operator_needs_opengl(C); view3d_operator_needs_opengl(C);
switch (event->type) { switch (event->type) {

@ -435,8 +435,6 @@ int join_mesh_exec(bContext *C, wmOperator *op)
medge->v1+= vertofs; medge->v1+= vertofs;
medge->v2+= vertofs; medge->v2+= vertofs;
} }
edgeofs += me->totedge;
} }
if (me->totloop) { if (me->totloop) {
@ -447,8 +445,6 @@ int join_mesh_exec(bContext *C, wmOperator *op)
mloop->v += vertofs; mloop->v += vertofs;
mloop->e += edgeofs; mloop->e += edgeofs;
} }
loopofs += me->totloop;
} }
if(me->totpoly) { if(me->totpoly) {
@ -472,13 +468,15 @@ int join_mesh_exec(bContext *C, wmOperator *op)
mpoly->mat_nr= matmap[(int)mpoly->mat_nr]; 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 /* these are used for relinking (cannot be set earlier,
* (cannot be set earlier, or else reattaching goes wrong) * or else reattaching goes wrong)
*/ */
vertofs += me->totvert; vertofs += me->totvert;
edgeofs += me->totedge;
loopofs += me->totloop;
/* free base, now that data is merged */ /* free base, now that data is merged */
if(base->object != ob) if(base->object != ob)

@ -1992,6 +1992,9 @@ static int draw_dm_faces_sel__setDrawOptions(void *userData, int index, int *dra
int vcount, pin=0; int vcount, pin=0;
int opac = UI_GetThemeValue(TH_PIN_OPAC); int opac = UI_GetThemeValue(TH_PIN_OPAC);
if (!efa)
return 0;
if (!BM_TestHFlag(efa, BM_HIDDEN)) { if (!BM_TestHFlag(efa, BM_HIDDEN)) {
/* Check if all verts of a face are pinned. If so, then display it in a darker shade. */ /* Check if all verts of a face are pinned. If so, then display it in a darker shade. */

@ -4460,38 +4460,44 @@ static int createSlideVerts(TransInfo *t)
TransDataSlideVert *sv1, *sv2; TransDataSlideVert *sv1, *sv2;
float vec1[3], dis2, ec2[3], vec[3], mval[2] = {t->mval[0], t->mval[1]}, d, z2; 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; dis2 = -1.0f;
for (i=0; i<2; i++) { 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)) if (BM_TestHFlag(e2, BM_SELECT))
continue; continue;
if (!BMBVH_EdgeVisible(btree, e2, v3d, t->obedit)) if (!BMBVH_EdgeVisible(btree, e2, v3d, t->obedit))
continue; 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); d = dist_to_line_segment_v2(mval, vec1, vec2);
if (dis2 == -1.0f || d < dis2) { if (dis2 == -1.0f || d < dis2) {
dis2 = d; dis2 = d;
ee = e2; ee = e2;
size = len_v3v3(vec1, vec2); 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*/ /*dir holds a vector along edge loop*/
copy_v3_v3(end, dir); copy_v3_v3(end, dir);
mul_v3_fl(end, 0.5);
/*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);
sld->start[0] = t->mval[0] + start[0]; sld->start[0] = t->mval[0] + start[0];
sld->start[1] = t->mval[1] + start[1]; sld->start[1] = t->mval[1] + start[1];

@ -189,7 +189,7 @@ DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
BMEdit_Free(em); BMEdit_Free(em);
MEM_freeN(em); MEM_freeN(em);
return result; return result;
} }