From 52a2d5cbd269c4f7f84a866a3080ce821dce80d3 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 5 Nov 2020 15:41:35 +1100 Subject: Transform: support individual origins for "To Sphere" --- .../blender/editors/transform/transform_mode_tosphere.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/source/blender/editors/transform/transform_mode_tosphere.c b/source/blender/editors/transform/transform_mode_tosphere.c index d50b26d3e5a..15906f2c90c 100644 --- a/source/blender/editors/transform/transform_mode_tosphere.c +++ b/source/blender/editors/transform/transform_mode_tosphere.c @@ -56,6 +56,8 @@ static void to_sphere_radius_update(TransInfo *t) struct ToSphereInfo *data = t->custom.mode.data; float radius = 0.0f; + const bool is_local_center = transdata_check_local_center(t, t->around); + if (t->flag & T_PROP_EDIT_ALL) { int factor_accum = 0.0f; FOREACH_TRANS_DATA_CONTAINER (t, tc) { @@ -64,7 +66,8 @@ static void to_sphere_radius_update(TransInfo *t) if (td->factor == 0.0f) { continue; } - radius += td->factor * len_v3v3(tc->center_local, td->iloc); + const float *center = is_local_center ? td->center : tc->center_local; + radius += td->factor * len_v3v3(center, td->iloc); factor_accum += td->factor; } } @@ -76,7 +79,8 @@ static void to_sphere_radius_update(TransInfo *t) FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (int i = 0; i < tc->data_len; i++, td++) { - radius += len_v3v3(tc->center_local, td->iloc); + const float *center = is_local_center ? td->center : tc->center_local; + radius += len_v3v3(center, td->iloc); } } radius /= (float)t->data_len_all; @@ -94,6 +98,8 @@ static void to_sphere_radius_update(TransInfo *t) static void applyToSphere(TransInfo *t, const int UNUSED(mval[2])) { + const bool is_local_center = transdata_check_local_center(t, t->around); + float vec[3]; float ratio, radius; int i; @@ -135,7 +141,9 @@ static void applyToSphere(TransInfo *t, const int UNUSED(mval[2])) continue; } - sub_v3_v3v3(vec, td->iloc, tc->center_local); + const float *center = is_local_center ? td->center : tc->center_local; + + sub_v3_v3v3(vec, td->iloc, center); radius = normalize_v3(vec); @@ -143,7 +151,7 @@ static void applyToSphere(TransInfo *t, const int UNUSED(mval[2])) mul_v3_fl(vec, radius * (1.0f - tratio) + data->radius * tratio); - add_v3_v3v3(td->loc, tc->center_local, vec); + add_v3_v3v3(td->loc, center, vec); } } -- cgit v1.2.3