Transform: support individual origins for "To Sphere"

This commit is contained in:
Campbell Barton 2020-11-05 15:41:35 +11:00
parent 8d88d9fd33
commit 52a2d5cbd2
1 changed files with 12 additions and 4 deletions

View File

@ -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);
}
}