From ac3e3eceba2506235652a5a92a85b5f4567f91f1 Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Sat, 22 Oct 2005 19:34:31 +0000 Subject: [PATCH] Long on the wishlist! - CTRL+click in EditMesh now extrudes selection. If no selection, it adds a new vertex. Try it on a full selected monkey. Fun! :) - CTRL+click now also adds the new stuff aligned with the view, as if you had translated it to the mouse cursor. Only new vertices are added with respect to 3D cursor location. --- source/blender/include/BIF_editmesh.h | 2 +- source/blender/src/editmesh_add.c | 102 ++++++++++++++++++-------- source/blender/src/editview.c | 2 +- 3 files changed, 72 insertions(+), 34 deletions(-) diff --git a/source/blender/include/BIF_editmesh.h b/source/blender/include/BIF_editmesh.h index 3829afb04be..1895a960f70 100644 --- a/source/blender/include/BIF_editmesh.h +++ b/source/blender/include/BIF_editmesh.h @@ -66,7 +66,7 @@ extern void separate_mesh_loose(void); /* ******************* editmesh_add.c */ extern void add_primitiveMesh(int type); extern void adduplicate_mesh(void); -extern void addvert_mesh(void); +extern void add_click_mesh(void); extern void addedgeface_mesh(void); /* ******************* editmesh_lib.c */ diff --git a/source/blender/src/editmesh_add.c b/source/blender/src/editmesh_add.c index e79806e7cf9..544bfd3e74f 100644 --- a/source/blender/src/editmesh_add.c +++ b/source/blender/src/editmesh_add.c @@ -116,46 +116,84 @@ static short icoface[20][3] = { {10,9,11} }; -void addvert_mesh(void) +static void get_view_aligned_coordinate(float *fp) +{ + float dvec[3]; + short mx, my, mval[0]; + + getmouseco_areawin(mval); + mx= mval[0]; + my= mval[1]; + + project_short_noclip(fp, mval); + + initgrabz(fp[0], fp[1], fp[2]); + + if(mval[0]!=IS_CLIPPED) { + window_to_3d(dvec, mval[0]-mx, mval[1]-my); + VecSubf(fp, fp, dvec); + } +} + +void add_click_mesh(void) { EditMesh *em = G.editMesh; - EditVert *eve,*v1=0; - float *curs, mat[3][3],imat[3][3]; - - // hurms, yah... - if(G.scene->selectmode==SCE_SELECT_FACE) return; - + EditVert *eve, *v1; + float min[3], max[3]; + int done= 0; + TEST_EDITMESH - - Mat3CpyMat4(mat, G.obedit->obmat); - Mat3Inv(imat, mat); - - v1= em->verts.first; - while(v1) { - if(v1->f & SELECT) break; - v1= v1->next; - } - eve= v1; - - /* prevent there are more selected */ - EM_clear_flag_all(SELECT); - eve= addvertlist(0); + INIT_MINMAX(min, max); - curs= give_cursor(); - VECCOPY(eve->co, curs); - VecSubf(eve->co, eve->co, G.obedit->obmat[3]); - - Mat3MulVecfl(imat, eve->co); - eve->f= SELECT; - - if(v1) { - addedgelist(v1, eve, NULL); - v1->f= 0; + for(v1= em->verts.first;v1; v1=v1->next) { + if(v1->f & SELECT) { + DO_MINMAX(v1->co, min, max); + done= 1; + } } + + /* call extrude? */ + if(done) { + float vec[3]; + float nor[3]= {0.0, 0.0, 0.0}; + + /* centre */ + VecAddf(min, min, max); + VecMulf(min, 0.5f); + VECCOPY(vec, min); + + Mat4MulVecfl(G.obedit->obmat, min); // view space + get_view_aligned_coordinate(min); + Mat4Invert(G.obedit->imat, G.obedit->obmat); + Mat4MulVecfl(G.obedit->imat, min); // back in object space + + VecSubf(min, min, vec); + + extrudeflag(SELECT, nor); + translateflag(SELECT, min); + recalc_editnormals(); + } + else { + float mat[3][3],imat[3][3]; + float *curs= give_cursor(); + + eve= addvertlist(0); + + Mat3CpyMat4(mat, G.obedit->obmat); + Mat3Inv(imat, mat); + + VECCOPY(eve->co, curs); + VecSubf(eve->co, eve->co, G.obedit->obmat[3]); + + Mat3MulVecfl(imat, eve->co); + + eve->f= SELECT; + } + countall(); - BIF_undo_push("Add vertex"); + BIF_undo_push("Add vertex/edge/face"); allqueue(REDRAWVIEW3D, 0); DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA); diff --git a/source/blender/src/editview.c b/source/blender/src/editview.c index 7f45e353ecd..7c343058d8a 100644 --- a/source/blender/src/editview.c +++ b/source/blender/src/editview.c @@ -853,7 +853,7 @@ void mouse_cursor(void) allqueue(REDRAWVIEW3D, 1); if(lr_click) { - if(G.obedit->type==OB_MESH) addvert_mesh(); + if(G.obedit->type==OB_MESH) add_click_mesh(); else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) addvert_Nurb(0); else if (G.obedit->type==OB_ARMATURE) addvert_armature(); VECCOPY(fp, oldcurs);