From 1d536da57e34a7e611747b12d6a43e5392c29580 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 19 Apr 2011 05:34:05 +0000 Subject: fix [#27016] Add new vertex at wrong position ( bpy.ops.mesh.dupli_extrude_cursor() ) also found curve click-extrude was always aligning the new points depth to (0,0,0), now work the same as mesh edit - align to the selected point or the cursor if none are seleted. --- source/blender/editors/curve/editcurve.c | 53 +++++++++++++++-------- source/blender/editors/mesh/editmesh_add.c | 14 +++--- source/blender/editors/space_view3d/view3d_snap.c | 8 +--- 3 files changed, 42 insertions(+), 33 deletions(-) (limited to 'source') diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 4ef5f80dcf6..d8748c7ad76 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -4413,11 +4413,10 @@ static int addvert_Nurb(bContext *C, short mode, float location[3]) Nurb *nu, *newnu= NULL; BezTriple *bezt, *newbezt = NULL; BPoint *bp, *newbp = NULL; - float mat[3][3],imat[3][3], temp[3]; + float imat[4][4], temp[3]; int ok= 0; - copy_m3_m4(mat, obedit->obmat); - invert_m3_m3(imat,mat); + invert_m4_m4(imat, obedit->obmat); findselectedNurbvert(&editnurb->nurbs, &nu, &bezt, &bp); @@ -4451,10 +4450,14 @@ static int addvert_Nurb(bContext *C, short mode, float location[3]) temp[0] = 1; temp[1] = 0; temp[2] = 0; + copy_v3_v3(newbezt->vec[1], location); - sub_v3_v3(newbezt->vec[1], obedit->obmat[3]); - sub_v3_v3v3(newbezt->vec[0], newbezt->vec[1],temp); - add_v3_v3v3(newbezt->vec[2], newbezt->vec[1],temp); + sub_v3_v3v3(newbezt->vec[0], newbezt->vec[1], temp); + add_v3_v3v3(newbezt->vec[2], newbezt->vec[1], temp); + + mul_m4_v3(imat, newbezt->vec[0]); + mul_m4_v3(imat, newbezt->vec[1]); + mul_m4_v3(imat, newbezt->vec[2]); ok= 1; nu= newnu; @@ -4473,9 +4476,7 @@ static int addvert_Nurb(bContext *C, short mode, float location[3]) newnu->orderu= 2; newnu->pntsu= 1; - copy_v3_v3(newbp->vec, location); - sub_v3_v3(newbp->vec, obedit->obmat[3]); - mul_m3_v3(imat,newbp->vec); + mul_v3_m4v3(newbp->vec, imat, location); newbp->vec[3]= 1.0; newnu->knotsu= newnu->knotsv= NULL; @@ -4555,9 +4556,7 @@ static int addvert_Nurb(bContext *C, short mode, float location[3]) copy_v3_v3(newbezt->vec[2], bezt->vec[2]); } else { - copy_v3_v3(newbezt->vec[1], location); - sub_v3_v3(newbezt->vec[1], obedit->obmat[3]); - mul_m3_v3(imat,newbezt->vec[1]); + mul_v3_m4v3(newbezt->vec[1], imat, location); sub_v3_v3v3(temp, newbezt->vec[1],temp); add_v3_v3v3(newbezt->vec[0], bezt->vec[0],temp); add_v3_v3v3(newbezt->vec[2], bezt->vec[2],temp); @@ -4622,9 +4621,7 @@ static int addvert_Nurb(bContext *C, short mode, float location[3]) copy_v3_v3(newbp->vec, bp->vec); } else { - copy_v3_v3(newbp->vec, location); - sub_v3_v3(newbp->vec, obedit->obmat[3]); - mul_m3_v3(imat,newbp->vec); + mul_v3_m4v3(newbp->vec, imat, location); newbp->vec[3]= 1.0; if(!newnu && nu->orderu<4 && nu->orderu<=nu->pntsu) @@ -4666,13 +4663,33 @@ static int add_vertex_exec(bContext *C, wmOperator *op) static int add_vertex_invoke(bContext *C, wmOperator *op, wmEvent *event) { RegionView3D *rv3d= CTX_wm_region_view3d(C); - ViewContext vc; - float location[3] = {0.0f, 0.0f, 0.0f}; - short mval[2]; if(rv3d && !RNA_property_is_set(op->ptr, "location")) { + Curve *cu; + ViewContext vc; + float location[3]; + short mval[2]; + + Nurb *nu; + BezTriple *bezt; + BPoint *bp; + view3d_set_viewcontext(C, &vc); + cu= vc.obedit->data; + + findselectedNurbvert(&cu->editnurb->nurbs, &nu, &bezt, &bp); + + if(bezt) { + mul_v3_m4v3(location, vc.obedit->obmat, bezt->vec[1]); + } + else if (bp) { + mul_v3_m4v3(location, vc.obedit->obmat, bp->vec); + } + else { + copy_v3_v3(location, give_cursor(vc.scene, vc.v3d)); + } + mval[0]= event->x - vc.ar->winrct.xmin; mval[1]= event->y - vc.ar->winrct.ymin; diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c index ec84d7f830f..2609a745398 100644 --- a/source/blender/editors/mesh/editmesh_add.c +++ b/source/blender/editors/mesh/editmesh_add.c @@ -139,7 +139,7 @@ static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event) /* call extrude? */ if(done) { - short rot_src= RNA_boolean_get(op->ptr, "rotate_source"); + const short rot_src= RNA_boolean_get(op->ptr, "rotate_source"); EditEdge *eed; float vec[3], cent[3], mat[3][3]; float nor[3]= {0.0, 0.0, 0.0}; @@ -246,20 +246,16 @@ static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event) } else if(vc.em->selectmode & SCE_SELECT_VERTEX) { - float mat[3][3],imat[3][3]; - float *curs= give_cursor(vc.scene, vc.v3d); + float imat[4][4]; + const float *curs= give_cursor(vc.scene, vc.v3d); copy_v3_v3(min, curs); view3d_get_view_aligned_coordinate(&vc, min, event->mval); eve= addvertlist(vc.em, 0, NULL); - copy_m3_m4(mat, vc.obedit->obmat); - invert_m3_m3(imat, mat); - - copy_v3_v3(eve->co, min); - mul_m3_v3(imat, eve->co); - sub_v3_v3v3(eve->co, eve->co, vc.obedit->obmat[3]); + invert_m4_m4(imat, vc.obedit->obmat); + mul_v3_m4v3(eve->co, imat, min); eve->f= SELECT; } diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c index f007b46dd95..a3d42aa5579 100644 --- a/source/blender/editors/space_view3d/view3d_snap.c +++ b/source/blender/editors/space_view3d/view3d_snap.c @@ -788,9 +788,7 @@ static int snap_curs_to_sel(bContext *C, wmOperator *UNUSED(op)) VECCOPY(curs, centroid); } else { - curs[0]= (min[0]+max[0])/2; - curs[1]= (min[1]+max[1])/2; - curs[2]= (min[2]+max[2])/2; + mid_v3_v3v3(curs, min, max); } MEM_freeN(transvmain); transvmain= NULL; @@ -828,9 +826,7 @@ static int snap_curs_to_sel(bContext *C, wmOperator *UNUSED(op)) VECCOPY(curs, centroid); } else { - curs[0]= (min[0]+max[0])/2; - curs[1]= (min[1]+max[1])/2; - curs[2]= (min[2]+max[2])/2; + mid_v3_v3v3(curs, min, max); } } } -- cgit v1.2.3