Fix T88342: 'To Sphere' and 'Push/Pull' not working in Pose mode

Some modes don't take into account that `TransData` may be in data space.
This commit is contained in:
Germano Cavalcante
2021-06-16 16:47:34 -03:00
parent d03b26edbd
commit 845f4cebad
2 changed files with 41 additions and 7 deletions

View File

@@ -77,6 +77,8 @@ static void applyPushPull(TransInfo *t, const int UNUSED(mval[2]))
t->con.applyRot(t, NULL, NULL, axis_global, NULL);
}
const bool is_data_space = (t->options & CTX_POSE_BONE) != 0;
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
TransData *td = tc->data;
for (i = 0; i < tc->data_len; i++, td++) {
@@ -101,6 +103,9 @@ static void applyPushPull(TransInfo *t, const int UNUSED(mval[2]))
}
}
normalize_v3_length(vec, distance * td->factor);
if (is_data_space) {
mul_m3_v3(td->smtx, vec);
}
add_v3_v3v3(td->loc, td->iloc, vec);
}

View File

@@ -55,8 +55,10 @@ static void to_sphere_radius_update(TransInfo *t)
{
struct ToSphereInfo *data = t->custom.mode.data;
float radius = 0.0f;
float vec[3];
const bool is_local_center = transdata_check_local_center(t, t->around);
const bool is_data_space = (t->options & CTX_POSE_BONE) != 0;
if (t->flag & T_PROP_EDIT_ALL) {
int factor_accum = 0.0f;
@@ -67,7 +69,15 @@ static void to_sphere_radius_update(TransInfo *t)
continue;
}
const float *center = is_local_center ? td->center : tc->center_local;
radius += td->factor * len_v3v3(center, td->iloc);
if (is_data_space) {
copy_v3_v3(vec, td->center);
}
else {
copy_v3_v3(vec, td->iloc);
}
sub_v3_v3(vec, center);
radius += td->factor * len_v3(vec);
factor_accum += td->factor;
}
}
@@ -80,7 +90,15 @@ static void to_sphere_radius_update(TransInfo *t)
TransData *td = tc->data;
for (int i = 0; i < tc->data_len; i++, td++) {
const float *center = is_local_center ? td->center : tc->center_local;
radius += len_v3v3(center, td->iloc);
if (is_data_space) {
copy_v3_v3(vec, td->center);
}
else {
copy_v3_v3(vec, td->iloc);
}
sub_v3_v3(vec, center);
radius += len_v3(vec);
}
}
radius /= (float)t->data_len_all;
@@ -99,6 +117,7 @@ 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);
const bool is_data_space = (t->options & CTX_POSE_BONE) != 0;
float vec[3];
float ratio, radius;
@@ -142,16 +161,26 @@ static void applyToSphere(TransInfo *t, const int UNUSED(mval[2]))
}
const float *center = is_local_center ? td->center : tc->center_local;
if (is_data_space) {
copy_v3_v3(vec, td->center);
}
else {
copy_v3_v3(vec, td->iloc);
}
sub_v3_v3v3(vec, td->iloc, center);
sub_v3_v3(vec, center);
radius = normalize_v3(vec);
tratio = ratio * td->factor;
mul_v3_fl(vec, radius * (1.0f - tratio) + data->radius * tratio);
add_v3_v3(vec, center);
add_v3_v3v3(td->loc, center, vec);
if (is_data_space) {
sub_v3_v3(vec, td->center);
mul_m3_v3(td->smtx, vec);
add_v3_v3(vec, td->iloc);
}
copy_v3_v3(td->loc, vec);
}
}