diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2019-11-23 13:11:39 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2019-12-24 19:58:09 +0300 |
commit | 33eabb82207e165de45fb6a0ea74dec962de7265 (patch) | |
tree | 714a714819fe27d1f998b0a3c3c7824e786be9ac /source/blender/blenkernel | |
parent | 9378debd26f7b20babcc251bdef64563a56c6ae0 (diff) |
Action Constraint: introduce a mix mode setting.
Currently the action channels are applied after the existing
transformation, as if the action controlled a child of the
bone. This is not very natural, but more importantly, the
transform tools are not designed to work conveniently with an
additional 'pseudo-child' transformation, resulting in effects
like an unexpected pivot location.
Implementing a Before mode that integrates the action channels
as if applied to a parent allows using the special transform
tool code intended for dealing with such constraints.
Note that in either mode, Action constraints should be added
in reverse order, putting a new constraint before the existing
ones that the Action was keyframed to work together.
In order to implement the option, extract a utility from
the Copy Transform constraint code for combining transforms
with special anti-shear scale handling that matches the
Aligned Inherit Scale mode.
The Before mode also requires switching the constraint to
the Local owner space, while the After mode can still use the
World space for efficiency as before. Since the constraint
doesn't have an Owner space option in the UI, this has to be
handled in an RNA setter.
For full backward compatibility, the original simple matrix
multiplication mode is preserved as the third option, but it
is not recommended due to creating shear.
Differential Revision: https://developer.blender.org/D6297
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index c397fbcf115..a17a09297c5 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -2062,36 +2062,21 @@ static void translike_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t bConstraintTarget *ct = targets->first; if (VALID_CONS_TARGET(ct)) { - if (data->mix_mode == TRANSLIKE_MIX_REPLACE) { - /* just copy the entire transform matrix of the target */ - copy_m4_m4(cob->matrix, ct->matrix); - } - else { - float old_loc[3], old_rot[3][3], old_size[3]; - float new_loc[3], new_rot[3][3], new_size[3]; - - /* Separate matrices so they can be combined in a way that avoids shear. */ - mat4_to_loc_rot_size(old_loc, old_rot, old_size, cob->matrix); - mat4_to_loc_rot_size(new_loc, new_rot, new_size, ct->matrix); - - switch (data->mix_mode) { - case TRANSLIKE_MIX_BEFORE: - mul_v3_m4v3(new_loc, ct->matrix, old_loc); - mul_m3_m3m3(new_rot, new_rot, old_rot); - mul_v3_v3(new_size, old_size); - break; + switch (data->mix_mode) { + case TRANSLIKE_MIX_REPLACE: + copy_m4_m4(cob->matrix, ct->matrix); + break; - case TRANSLIKE_MIX_AFTER: - mul_v3_m4v3(new_loc, cob->matrix, new_loc); - mul_m3_m3m3(new_rot, old_rot, new_rot); - mul_v3_v3(new_size, old_size); - break; + case TRANSLIKE_MIX_BEFORE: + mul_m4_m4m4_aligned_scale(cob->matrix, ct->matrix, cob->matrix); + break; - default: - BLI_assert(false); - } + case TRANSLIKE_MIX_AFTER: + mul_m4_m4m4_aligned_scale(cob->matrix, cob->matrix, ct->matrix); + break; - loc_rot_size_to_mat4(cob->matrix, new_loc, new_rot, new_size); + default: + BLI_assert(!"Unknown Copy Transforms mix mode"); } } } @@ -2555,6 +2540,9 @@ static void actcon_new_data(void *cdata) /* set type to 20 (Loc X), as 0 is Rot X for backwards compatibility */ data->type = 20; + + /* Set the mix mode to After Original with anti-shear scale handling. */ + data->mix_mode = ACTCON_MIX_AFTER; } static void actcon_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) @@ -2695,18 +2683,28 @@ static void actcon_get_tarmat(struct Depsgraph *UNUSED(depsgraph), } } -static void actcon_evaluate(bConstraint *UNUSED(con), bConstraintOb *cob, ListBase *targets) +static void actcon_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets) { + bActionConstraint *data = con->data; bConstraintTarget *ct = targets->first; if (VALID_CONS_TARGET(ct)) { - float temp[4][4]; + switch (data->mix_mode) { + case ACTCON_MIX_BEFORE: + mul_m4_m4m4_aligned_scale(cob->matrix, ct->matrix, cob->matrix); + break; - /* Nice and simple... we just need to multiply the matrices, as the get_target_matrix - * function has already taken care of everything else. - */ - copy_m4_m4(temp, cob->matrix); - mul_m4_m4m4(cob->matrix, temp, ct->matrix); + case ACTCON_MIX_AFTER: + mul_m4_m4m4_aligned_scale(cob->matrix, cob->matrix, ct->matrix); + break; + + case ACTCON_MIX_AFTER_FULL: + mul_m4_m4m4(cob->matrix, cob->matrix, ct->matrix); + break; + + default: + BLI_assert(!"Unknown Action mix mode"); + } } } |