forked from bartvdbraak/blender
Edit Mesh/Curve: Median center for click extrude
Was using bound-box center which depends on rotation.
This commit is contained in:
parent
f4b5d0ba3a
commit
49f4ac17bf
@ -4791,13 +4791,13 @@ static int ed_editcurve_addvert(Curve *cu, EditNurb *editnurb, const float locat
|
||||
{
|
||||
Nurb *nu;
|
||||
|
||||
float minmax[2][3];
|
||||
float center[3];
|
||||
float temp[3];
|
||||
bool nu_has_select = false;
|
||||
|
||||
uint verts_len;
|
||||
bool changed = false;
|
||||
|
||||
INIT_MINMAX(minmax[0], minmax[1]);
|
||||
zero_v3(center);
|
||||
verts_len = 0;
|
||||
|
||||
for (nu = editnurb->nurbs.first; nu; nu = nu->next) {
|
||||
int i;
|
||||
@ -4806,8 +4806,8 @@ static int ed_editcurve_addvert(Curve *cu, EditNurb *editnurb, const float locat
|
||||
|
||||
for (i = 0, bezt = nu->bezt; i < nu->pntsu; i++, bezt++) {
|
||||
if (BEZT_ISSEL_ANY_HIDDENHANDLES(cu, bezt)) {
|
||||
minmax_v3v3_v3(UNPACK2(minmax), bezt->vec[1]);
|
||||
nu_has_select = true;
|
||||
add_v3_v3(center, bezt->vec[1]);
|
||||
verts_len += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4816,18 +4816,18 @@ static int ed_editcurve_addvert(Curve *cu, EditNurb *editnurb, const float locat
|
||||
|
||||
for (i = 0, bp = nu->bp; i < nu->pntsu; i++, bp++) {
|
||||
if (bp->f1 & SELECT) {
|
||||
minmax_v3v3_v3(UNPACK2(minmax), bp->vec);
|
||||
nu_has_select = true;
|
||||
add_v3_v3(center, bp->vec);
|
||||
verts_len += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nu_has_select && ed_editcurve_extrude(cu, editnurb)) {
|
||||
float ofs[3], center[3];
|
||||
if (verts_len && ed_editcurve_extrude(cu, editnurb)) {
|
||||
float ofs[3];
|
||||
int i;
|
||||
|
||||
mid_v3_v3v3(center, minmax[0], minmax[1]);
|
||||
mul_v3_fl(center, 1.0f / (float)verts_len);
|
||||
sub_v3_v3v3(ofs, location_init, center);
|
||||
|
||||
if ((cu->flag & CU_3D) == 0) {
|
||||
|
@ -506,8 +506,8 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const w
|
||||
ViewContext vc;
|
||||
BMVert *v1;
|
||||
BMIter iter;
|
||||
float min[3], max[3];
|
||||
bool done = false;
|
||||
float center[3];
|
||||
uint verts_len;
|
||||
bool use_proj;
|
||||
|
||||
em_setup_viewcontext(C, &vc);
|
||||
@ -519,29 +519,33 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const w
|
||||
use_proj = ((vc.scene->toolsettings->snap_flag & SCE_SNAP) &&
|
||||
(vc.scene->toolsettings->snap_mode == SCE_SNAP_MODE_FACE));
|
||||
|
||||
INIT_MINMAX(min, max);
|
||||
zero_v3(center);
|
||||
verts_len = 0;
|
||||
|
||||
BM_ITER_MESH (v1, &iter, vc.em->bm, BM_VERTS_OF_MESH) {
|
||||
if (BM_elem_flag_test(v1, BM_ELEM_SELECT)) {
|
||||
minmax_v3v3_v3(min, max, v1->co);
|
||||
done = true;
|
||||
add_v3_v3(center, v1->co);
|
||||
verts_len += 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* call extrude? */
|
||||
if (done) {
|
||||
if (verts_len != 0) {
|
||||
const char extrude_htype = edbm_extrude_htype_from_em_select(vc.em);
|
||||
const bool rot_src = RNA_boolean_get(op->ptr, "rotate_source");
|
||||
BMEdge *eed;
|
||||
float vec[3], cent[3], mat[3][3];
|
||||
float mat[3][3];
|
||||
float vec[3], ofs[3];
|
||||
float nor[3] = {0.0, 0.0, 0.0};
|
||||
|
||||
/* 2D normal calc */
|
||||
const float mval_f[2] = {(float)event->mval[0],
|
||||
(float)event->mval[1]};
|
||||
|
||||
mul_v3_fl(center, 1.0f / (float)verts_len);
|
||||
|
||||
/* check for edges that are half selected, use for rotation */
|
||||
done = false;
|
||||
bool done = false;
|
||||
BM_ITER_MESH (eed, &iter, vc.em->bm, BM_EDGES_OF_MESH) {
|
||||
if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
|
||||
float co1[2], co2[2];
|
||||
@ -582,21 +586,20 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const w
|
||||
}
|
||||
|
||||
/* center */
|
||||
mid_v3_v3v3(cent, min, max);
|
||||
copy_v3_v3(min, cent);
|
||||
copy_v3_v3(ofs, center);
|
||||
|
||||
mul_m4_v3(vc.obedit->obmat, min); /* view space */
|
||||
ED_view3d_win_to_3d_int(vc.v3d, vc.ar, min, event->mval, min);
|
||||
mul_m4_v3(vc.obedit->imat, min); // back in object space
|
||||
mul_m4_v3(vc.obedit->obmat, ofs); /* view space */
|
||||
ED_view3d_win_to_3d_int(vc.v3d, vc.ar, ofs, event->mval, ofs);
|
||||
mul_m4_v3(vc.obedit->imat, ofs); // back in object space
|
||||
|
||||
sub_v3_v3(min, cent);
|
||||
sub_v3_v3(ofs, center);
|
||||
|
||||
/* calculate rotation */
|
||||
unit_m3(mat);
|
||||
if (done) {
|
||||
float angle;
|
||||
|
||||
normalize_v3_v3(vec, min);
|
||||
normalize_v3_v3(vec, ofs);
|
||||
|
||||
angle = angle_normalized_v3v3(vec, nor);
|
||||
|
||||
@ -616,7 +619,7 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const w
|
||||
|
||||
if (rot_src) {
|
||||
EDBM_op_callf(vc.em, op, "rotate verts=%hv cent=%v matrix=%m3",
|
||||
BM_ELEM_SELECT, cent, mat);
|
||||
BM_ELEM_SELECT, center, mat);
|
||||
|
||||
/* also project the source, for retopo workflow */
|
||||
if (use_proj)
|
||||
@ -625,21 +628,21 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const w
|
||||
|
||||
edbm_extrude_ex(vc.obedit, vc.em, extrude_htype, BM_ELEM_SELECT, true, true);
|
||||
EDBM_op_callf(vc.em, op, "rotate verts=%hv cent=%v matrix=%m3",
|
||||
BM_ELEM_SELECT, cent, mat);
|
||||
BM_ELEM_SELECT, center, mat);
|
||||
EDBM_op_callf(vc.em, op, "translate verts=%hv vec=%v",
|
||||
BM_ELEM_SELECT, min);
|
||||
BM_ELEM_SELECT, ofs);
|
||||
}
|
||||
else {
|
||||
const float *curs = ED_view3d_cursor3d_get(vc.scene, vc.v3d);
|
||||
const float *cursor = ED_view3d_cursor3d_get(vc.scene, vc.v3d);
|
||||
BMOperator bmop;
|
||||
BMOIter oiter;
|
||||
|
||||
copy_v3_v3(min, curs);
|
||||
ED_view3d_win_to_3d_int(vc.v3d, vc.ar, min, event->mval, min);
|
||||
|
||||
mul_m4_v3(vc.obedit->imat, min); // back in object space
|
||||
copy_v3_v3(center, cursor);
|
||||
ED_view3d_win_to_3d_int(vc.v3d, vc.ar, center, event->mval, center);
|
||||
|
||||
mul_m4_v3(vc.obedit->imat, center); // back in object space
|
||||
|
||||
EDBM_op_init(vc.em, &bmop, op, "create_vert co=%v", min);
|
||||
EDBM_op_init(vc.em, &bmop, op, "create_vert co=%v", center);
|
||||
BMO_op_exec(vc.em->bm, &bmop);
|
||||
|
||||
BMO_ITER (v1, &oiter, bmop.slots_out, "vert.out", BM_VERT) {
|
||||
|
Loading…
Reference in New Issue
Block a user