Transform: default to median center instead of bounds
When neither bounds or median is selected, snapping the cursor to the selection was using bounds which often doesn't give useful results. Resolves T78135
This commit is contained in:
@@ -140,7 +140,16 @@ void ED_armature_origin_set(
|
||||
mul_m4_v3(ob->imat, cent);
|
||||
}
|
||||
else {
|
||||
if (around == V3D_AROUND_CENTER_MEDIAN) {
|
||||
if (around == V3D_AROUND_CENTER_BOUNDS) {
|
||||
float min[3], max[3];
|
||||
INIT_MINMAX(min, max);
|
||||
for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
|
||||
minmax_v3v3_v3(min, max, ebone->head);
|
||||
minmax_v3v3_v3(min, max, ebone->tail);
|
||||
}
|
||||
mid_v3_v3v3(cent, min, max);
|
||||
}
|
||||
else { /* #V3D_AROUND_CENTER_MEDIAN. */
|
||||
int total = 0;
|
||||
zero_v3(cent);
|
||||
for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
|
||||
@@ -152,15 +161,6 @@ void ED_armature_origin_set(
|
||||
mul_v3_fl(cent, 1.0f / (float)total);
|
||||
}
|
||||
}
|
||||
else {
|
||||
float min[3], max[3];
|
||||
INIT_MINMAX(min, max);
|
||||
for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
|
||||
minmax_v3v3_v3(min, max, ebone->head);
|
||||
minmax_v3v3_v3(min, max, ebone->tail);
|
||||
}
|
||||
mid_v3_v3v3(cent, min, max);
|
||||
}
|
||||
}
|
||||
|
||||
/* Do the adjustments */
|
||||
|
||||
@@ -2956,13 +2956,16 @@ static int gp_snap_cursor_to_sel(bContext *C, wmOperator *UNUSED(op))
|
||||
}
|
||||
}
|
||||
|
||||
if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CENTER_MEDIAN && count) {
|
||||
mul_v3_fl(centroid, 1.0f / (float)count);
|
||||
copy_v3_v3(cursor, centroid);
|
||||
}
|
||||
else {
|
||||
if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CENTER_BOUNDS) {
|
||||
mid_v3_v3v3(cursor, min, max);
|
||||
}
|
||||
else { /* #V3D_AROUND_CENTER_MEDIAN. */
|
||||
zero_v3(cursor);
|
||||
if (count) {
|
||||
mul_v3_fl(centroid, 1.0f / (float)count);
|
||||
copy_v3_v3(cursor, centroid);
|
||||
}
|
||||
}
|
||||
|
||||
DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
|
||||
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
|
||||
|
||||
@@ -1098,15 +1098,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
|
||||
mul_m4_v3(obedit->imat, cent);
|
||||
}
|
||||
else {
|
||||
if (around == V3D_AROUND_CENTER_MEDIAN) {
|
||||
if (em->bm->totvert) {
|
||||
const float total_div = 1.0f / (float)em->bm->totvert;
|
||||
BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
|
||||
madd_v3_v3fl(cent, eve->co, total_div);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (around == V3D_AROUND_CENTER_BOUNDS) {
|
||||
float min[3], max[3];
|
||||
INIT_MINMAX(min, max);
|
||||
BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
|
||||
@@ -1114,6 +1106,14 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
mid_v3_v3v3(cent, min, max);
|
||||
}
|
||||
else { /* #V3D_AROUND_CENTER_MEDIAN. */
|
||||
if (em->bm->totvert) {
|
||||
const float total_div = 1.0f / (float)em->bm->totvert;
|
||||
BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
|
||||
madd_v3_v3fl(cent, eve->co, total_div);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
|
||||
@@ -1211,12 +1211,12 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
|
||||
else if (centermode == ORIGIN_TO_CENTER_OF_MASS_VOLUME) {
|
||||
BKE_mesh_center_of_volume(me, cent);
|
||||
}
|
||||
else if (around == V3D_AROUND_CENTER_MEDIAN) {
|
||||
BKE_mesh_center_median(me, cent);
|
||||
}
|
||||
else {
|
||||
else if (around == V3D_AROUND_CENTER_BOUNDS) {
|
||||
BKE_mesh_center_bounds(me, cent);
|
||||
}
|
||||
else { /* #V3D_AROUND_CENTER_MEDIAN. */
|
||||
BKE_mesh_center_median(me, cent);
|
||||
}
|
||||
|
||||
negate_v3_v3(cent_neg, cent);
|
||||
BKE_mesh_translate(me, cent_neg, 1);
|
||||
@@ -1231,12 +1231,12 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
|
||||
if (centermode == ORIGIN_TO_CURSOR) {
|
||||
/* done */
|
||||
}
|
||||
else if (around == V3D_AROUND_CENTER_MEDIAN) {
|
||||
BKE_curve_center_median(cu, cent);
|
||||
}
|
||||
else {
|
||||
else if (around == V3D_AROUND_CENTER_BOUNDS) {
|
||||
BKE_curve_center_bounds(cu, cent);
|
||||
}
|
||||
else { /* #V3D_AROUND_CENTER_MEDIAN. */
|
||||
BKE_curve_center_median(cu, cent);
|
||||
}
|
||||
|
||||
/* don't allow Z change if curve is 2D */
|
||||
if ((ob->type == OB_CURVE) && !(cu->flag & CU_3D)) {
|
||||
@@ -1324,12 +1324,12 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
|
||||
if (centermode == ORIGIN_TO_CURSOR) {
|
||||
/* done */
|
||||
}
|
||||
else if (around == V3D_AROUND_CENTER_MEDIAN) {
|
||||
BKE_mball_center_median(mb, cent);
|
||||
}
|
||||
else {
|
||||
else if (around == V3D_AROUND_CENTER_BOUNDS) {
|
||||
BKE_mball_center_bounds(mb, cent);
|
||||
}
|
||||
else { /* #V3D_AROUND_CENTER_MEDIAN. */
|
||||
BKE_mball_center_median(mb, cent);
|
||||
}
|
||||
|
||||
negate_v3_v3(cent_neg, cent);
|
||||
BKE_mball_translate(mb, cent_neg);
|
||||
@@ -1351,12 +1351,12 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
|
||||
if (centermode == ORIGIN_TO_CURSOR) {
|
||||
/* done */
|
||||
}
|
||||
else if (around == V3D_AROUND_CENTER_MEDIAN) {
|
||||
BKE_lattice_center_median(lt, cent);
|
||||
}
|
||||
else {
|
||||
else if (around == V3D_AROUND_CENTER_BOUNDS) {
|
||||
BKE_lattice_center_bounds(lt, cent);
|
||||
}
|
||||
else { /* #V3D_AROUND_CENTER_MEDIAN. */
|
||||
BKE_lattice_center_median(lt, cent);
|
||||
}
|
||||
|
||||
negate_v3_v3(cent_neg, cent);
|
||||
BKE_lattice_translate(lt, cent_neg, 1);
|
||||
|
||||
@@ -850,12 +850,12 @@ static bool snap_curs_to_sel_ex(bContext *C, float cursor[3])
|
||||
return false;
|
||||
}
|
||||
|
||||
if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CENTER_MEDIAN) {
|
||||
mul_v3_fl(centroid, 1.0f / (float)count);
|
||||
copy_v3_v3(cursor, centroid);
|
||||
if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CENTER_BOUNDS) {
|
||||
mid_v3_v3v3(cursor, min, max);
|
||||
}
|
||||
else {
|
||||
mid_v3_v3v3(cursor, min, max);
|
||||
mul_v3_fl(centroid, 1.0f / (float)count);
|
||||
copy_v3_v3(cursor, centroid);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user