From feca8c4644143ece08d0fdd90af480a7f4a9ddc8 Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Sat, 30 Apr 2005 09:55:37 +0000 Subject: [PATCH] Manipulator with "normal alignment" now aligns to edges too (if no faces selected) and to vertex normals. Only issue is that vertexnormals are not updated on each editing command (it's a bit too much overhead...) so use a TAB+TAB for now to enforce proper vertexnormals. --- source/blender/src/transform_manipulator.c | 38 ++++++++++++++++------ 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/source/blender/src/transform_manipulator.c b/source/blender/src/transform_manipulator.c index 998c1298d46..c2049d4fdba 100644 --- a/source/blender/src/transform_manipulator.c +++ b/source/blender/src/transform_manipulator.c @@ -185,21 +185,39 @@ static int calc_manipulator(ScrArea *sa) if(G.obedit->type==OB_MESH) { EditMesh *em = G.editMesh; EditVert *eve; + float vec[3]; + int do_norm= 0; + if(v3d->twmode == V3D_MANIP_NORMAL) { + EditFace *efa; + + for(efa= em->faces.first; efa; efa= efa->next) { + if(efa->f & SELECT) { + VECADD(normal, normal, efa->n); + VecSubf(vec, efa->v2->co, efa->v1->co); + VECADD(plane, plane, vec); + } + } + if(normal[0]==0.0 && normal[1]==0.0 && normal[2]==0.0) do_norm= 1; + } + + /* do vertices for center, and if still no normal found, use vertex normals */ for(eve= em->verts.first; eve; eve= eve->next) { if(eve->f & SELECT) { + if(do_norm) VECADD(normal, normal, eve->no); + totsel++; calc_tw_center(eve->co); } } - if(v3d->twmode == V3D_MANIP_NORMAL) { - EditFace *efa; - float vec[3]; - for(efa= em->faces.first; efa; efa= efa->next) { - if(efa->f & SELECT) { - VecAddf(normal, normal, efa->n); - VecSubf(vec, efa->v2->co, efa->v1->co); - VecAddf(plane, plane, vec); + /* the edge case... */ + if(do_norm && v3d->twmode == V3D_MANIP_NORMAL) { + EditEdge *eed; + + for(eed= em->edges.first; eed; eed= eed->next) { + if(eed->f & SELECT) { + VecSubf(vec, eed->v2->co, eed->v1->co); + VECADD(plane, plane, vec); } } } @@ -366,9 +384,9 @@ static int calc_manipulator(ScrArea *sa) Mat3Transp(mat); Mat3MulVecfl(mat, normal); Mat3MulVecfl(mat, plane); - + Normalise(normal); - Normalise(plane); + if(0.0==Normalise(plane)) VECCOPY(plane, mat[1]); VECCOPY(mat[2], normal); Crossf(mat[0], normal, plane);