From 27b9a0cd670ff1dabe031596cef76908df76c3c8 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Wed, 8 May 2019 12:08:54 +0300 Subject: Copy Scale: support raising the copied scale to an arbitrary power. Since scale is multiplicative, the appropriate way to partially copy it is to use power. However, the influence slider of constraints uses linear interpolation. Thus, there is no way to correctly split scale via constraints without adding this feature. In addition, this allows inverting scale by using negative powers, fulfilling the function of Copy Rotation's Invert checkboxes. --- source/blender/blenkernel/intern/constraint.c | 5 +++++ source/blender/blenloader/intern/versioning_280.c | 22 ++++++++++++++++++++++ source/blender/makesdna/DNA_constraint_types.h | 2 +- source/blender/makesrna/intern/rna_constraint.c | 7 +++++++ 4 files changed, 35 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 2ccfcf45e46..218dfbd7b14 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -1882,6 +1882,7 @@ static void sizelike_new_data(void *cdata) bSizeLikeConstraint *data = (bSizeLikeConstraint *)cdata; data->flag = SIZELIKE_X | SIZELIKE_Y | SIZELIKE_Z | SIZELIKE_MULTIPLY; + data->power = 1.0f; } static void sizelike_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) @@ -1929,6 +1930,10 @@ static void sizelike_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *ta mat4_to_size(size, ct->matrix); mat4_to_size(obsize, cob->matrix); + for (int i = 0; i < 3; i++) { + size[i] = powf(size[i], data->power); + } + 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. */ diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index 194459a1eda..b2e171108d8 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -702,6 +702,16 @@ static void do_version_constraints_maintain_volume_mode_uniform(ListBase *lb) } } +static void do_version_constraints_copy_scale_power(ListBase *lb) +{ + for (bConstraint *con = lb->first; con; con = con->next) { + if (con->type == CONSTRAINT_TYPE_SIZELIKE) { + bSizeLikeConstraint *data = (bSizeLikeConstraint *)con->data; + data->power = 1.0f; + } + } +} + void do_versions_after_linking_280(Main *bmain) { bool use_collection_compat_28 = true; @@ -3348,6 +3358,18 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } { + /* Added a power option to Copy Scale. */ + if (!DNA_struct_elem_find(fd->filesdna, "bSizeLikeConstraint", "float", "power")) { + LISTBASE_FOREACH (Object *, ob, &bmain->objects) { + do_version_constraints_copy_scale_power(&ob->constraints); + if (ob->pose) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { + do_version_constraints_copy_scale_power(&pchan->constraints); + } + } + } + } + /* Versioning code until next subversion bump goes here. */ } } diff --git a/source/blender/makesdna/DNA_constraint_types.h b/source/blender/makesdna/DNA_constraint_types.h index 3abd5b4456e..c09ea400f4c 100644 --- a/source/blender/makesdna/DNA_constraint_types.h +++ b/source/blender/makesdna/DNA_constraint_types.h @@ -289,7 +289,7 @@ typedef struct bLocateLikeConstraint { typedef struct bSizeLikeConstraint { struct Object *tar; int flag; - int reserved1; + float power; /** MAX_ID_NAME-2. */ char subtarget[64]; } bSizeLikeConstraint; diff --git a/source/blender/makesrna/intern/rna_constraint.c b/source/blender/makesrna/intern/rna_constraint.c index ef3ea19fa57..41ad94f6119 100644 --- a/source/blender/makesrna/intern/rna_constraint.c +++ b/source/blender/makesrna/intern/rna_constraint.c @@ -1327,6 +1327,13 @@ static void rna_def_constraint_size_like(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Copy Z", "Copy the target's Z scale"); RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update"); + prop = RNA_def_property(srna, "power", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "power"); + RNA_def_property_float_default(prop, 1.0f); + RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, 3); + RNA_def_property_ui_text(prop, "Power", "Raise the target's scale to the specified power"); + RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update"); + 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", "Combine original scale with copied scale"); -- cgit v1.2.3