From 47af343b6137e4290cc4a842daac25ff8d8cb65f Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Tue, 24 Jul 2018 18:53:22 +0300 Subject: Implement multiplicative Copy Scale and make it the new default. Scale is a multiplicative quantity, so adding it doesn't make sense. However, for backward compatibility reasons, and in case somebody actually desires the old additive behavior, the old way remains as an option. Without this change the only way to properly combine scale is via parenting or the complicated Transformation constraint. The new mode is turned on by a flag for file compatibility, but the RNA option is reversed so that the new behavior feels more default. Reviewers: aligorith Differential Revision: https://developer.blender.org/D3558 --- .../scripts/startup/bl_ui/properties_constraint.py | 6 +++- source/blender/blenkernel/intern/constraint.c | 37 +++++++++++----------- source/blender/makesdna/DNA_constraint_types.h | 3 +- source/blender/makesrna/intern/rna_constraint.c | 7 +++- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/release/scripts/startup/bl_ui/properties_constraint.py b/release/scripts/startup/bl_ui/properties_constraint.py index b7880e605b3..352b96c6431 100644 --- a/release/scripts/startup/bl_ui/properties_constraint.py +++ b/release/scripts/startup/bl_ui/properties_constraint.py @@ -420,7 +420,11 @@ class ConstraintButtonsPanel: row.prop(con, "use_y", text="Y") row.prop(con, "use_z", text="Z") - layout.prop(con, "use_offset") + row= layout.row() + row.prop(con, "use_offset") + row = row.row() + row.active = con.use_offset + row.prop(con, "use_add") self.space_template(layout, con) diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index ef412f0006e..f4be232b9ae 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -1760,7 +1760,7 @@ static void sizelike_new_data(void *cdata) { bSizeLikeConstraint *data = (bSizeLikeConstraint *)cdata; - data->flag = SIZELIKE_X | SIZELIKE_Y | SIZELIKE_Z; + data->flag = SIZELIKE_X | SIZELIKE_Y | SIZELIKE_Z | SIZELIKE_MULTIPLY; } static void sizelike_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) @@ -1808,29 +1808,28 @@ static void sizelike_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *ta mat4_to_size(size, ct->matrix); mat4_to_size(obsize, cob->matrix); - if ((data->flag & SIZELIKE_X) && (obsize[0] != 0)) { - if (data->flag & SIZELIKE_OFFSET) { - size[0] += (obsize[0] - 1.0f); - mul_v3_fl(cob->matrix[0], size[0] / obsize[0]); + if (data->flag & SIZELIKE_OFFSET) { + /* Scale is a multiplicative quantity, so adding it makes no sense. + * However, the additive mode has to stay for backward compatibility. */ + if (data->flag & SIZELIKE_MULTIPLY) { + /* size[i] *= obsize[i] */ + mul_v3_v3(size, obsize); } - else - mul_v3_fl(cob->matrix[0], size[0] / obsize[0]); + else { + /* 2.7 compatibility mode: size[i] += (obsize[i] - 1.0f) */ + add_v3_v3(size, obsize); + add_v3_fl(size, -1.0f); + } + } + + if ((data->flag & SIZELIKE_X) && (obsize[0] != 0)) { + mul_v3_fl(cob->matrix[0], size[0] / obsize[0]); } if ((data->flag & SIZELIKE_Y) && (obsize[1] != 0)) { - if (data->flag & SIZELIKE_OFFSET) { - size[1] += (obsize[1] - 1.0f); - mul_v3_fl(cob->matrix[1], size[1] / obsize[1]); - } - else - mul_v3_fl(cob->matrix[1], size[1] / obsize[1]); + mul_v3_fl(cob->matrix[1], size[1] / obsize[1]); } if ((data->flag & SIZELIKE_Z) && (obsize[2] != 0)) { - if (data->flag & SIZELIKE_OFFSET) { - size[2] += (obsize[2] - 1.0f); - mul_v3_fl(cob->matrix[2], size[2] / obsize[2]); - } - else - mul_v3_fl(cob->matrix[2], size[2] / obsize[2]); + mul_v3_fl(cob->matrix[2], size[2] / obsize[2]); } } } diff --git a/source/blender/makesdna/DNA_constraint_types.h b/source/blender/makesdna/DNA_constraint_types.h index e1c082748fd..e118fd39bb1 100644 --- a/source/blender/makesdna/DNA_constraint_types.h +++ b/source/blender/makesdna/DNA_constraint_types.h @@ -584,7 +584,8 @@ typedef enum eCopyScale_Flags { SIZELIKE_X = (1<<0), SIZELIKE_Y = (1<<1), SIZELIKE_Z = (1<<2), - SIZELIKE_OFFSET = (1<<3) + SIZELIKE_OFFSET = (1<<3), + SIZELIKE_MULTIPLY = (1<<4), } eCopyScale_Flags; /* bTransformConstraint.to/from */ diff --git a/source/blender/makesrna/intern/rna_constraint.c b/source/blender/makesrna/intern/rna_constraint.c index 6cc9d1ef5a6..6f7580a3944 100644 --- a/source/blender/makesrna/intern/rna_constraint.c +++ b/source/blender/makesrna/intern/rna_constraint.c @@ -961,7 +961,12 @@ static void rna_def_constraint_size_like(BlenderRNA *brna) prop = RNA_def_property(srna, "use_offset", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", SIZELIKE_OFFSET); - RNA_def_property_ui_text(prop, "Offset", "Add original scale into copied scale"); + RNA_def_property_ui_text(prop, "Offset", "Combine original scale with copied scale"); + RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update"); + + prop = RNA_def_property(srna, "use_add", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", SIZELIKE_MULTIPLY); + RNA_def_property_ui_text(prop, "Additive", "Use addition instead of multiplication to combine scale (2.7 compatibility)"); RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update"); } -- cgit v1.2.3