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/makesrna/intern/rna_constraint.c | |
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/makesrna/intern/rna_constraint.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_constraint.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_constraint.c b/source/blender/makesrna/intern/rna_constraint.c index 6a10074810d..8e57de9baeb 100644 --- a/source/blender/makesrna/intern/rna_constraint.c +++ b/source/blender/makesrna/intern/rna_constraint.c @@ -633,6 +633,23 @@ static void rna_ArmatureConstraint_target_clear(ID *id, bConstraint *con, Main * ED_object_constraint_dependency_tag_update(bmain, (Object *)id, con); } +static void rna_ActionConstraint_mix_mode_set(PointerRNA *ptr, int value) +{ + bConstraint *con = (bConstraint *)ptr->data; + bActionConstraint *acon = (bActionConstraint *)con->data; + + acon->mix_mode = value; + + /* The After mode can be computed in world space for efficiency + * and backward compatibility, while Before requires Local. */ + if (ELEM(value, ACTCON_MIX_AFTER, ACTCON_MIX_AFTER_FULL)) { + con->ownspace = CONSTRAINT_SPACE_WORLD; + } + else { + con->ownspace = CONSTRAINT_SPACE_LOCAL; + } +} + static void rna_ActionConstraint_minmax_range( PointerRNA *ptr, float *min, float *max, float *UNUSED(softmin), float *UNUSED(softmax)) { @@ -1618,6 +1635,29 @@ static void rna_def_constraint_action(BlenderRNA *brna) {0, NULL, 0, NULL, NULL}, }; + static const EnumPropertyItem mix_mode_items[] = { + {ACTCON_MIX_BEFORE, + "BEFORE", + 0, + "Before Original", + "Apply the action channels before the original transformation, " + "as if applied to an imaginary parent with Aligned Inherit Scale"}, + {ACTCON_MIX_AFTER, + "AFTER", + 0, + "After Original", + "Apply the action channels after the original transformation, " + "as if applied to an imaginary child with Aligned Inherit Scale"}, + {ACTCON_MIX_AFTER_FULL, + "AFTER_FULL", + 0, + "After Original (Full Scale)", + "Apply the action channels after the original transformation, as if " + "applied to an imaginary child with Full Inherit Scale. This mode " + "can create shear and is provided only for backward compatibility"}, + {0, NULL, 0, NULL, NULL}, + }; + srna = RNA_def_struct(brna, "ActionConstraint", "Constraint"); RNA_def_struct_ui_text( srna, "Action Constraint", "Map an action to the transform axes of a bone"); @@ -1626,6 +1666,16 @@ static void rna_def_constraint_action(BlenderRNA *brna) rna_def_constraint_target_common(srna); + prop = RNA_def_property(srna, "mix_mode", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "mix_mode"); + RNA_def_property_enum_items(prop, mix_mode_items); + RNA_def_property_enum_funcs(prop, NULL, "rna_ActionConstraint_mix_mode_set", NULL); + RNA_def_property_ui_text( + prop, + "Mix Mode", + "Specify how existing transformations and the action channels are combined"); + RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update"); + prop = RNA_def_property(srna, "transform_channel", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "type"); RNA_def_property_enum_items(prop, transform_channel_items); |