Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gavrilov <angavrilov@gmail.com>2019-09-04 14:59:18 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2019-09-06 07:58:13 +0300
commitf8362836a5c8feff3715ca823025caba249208c2 (patch)
treec3406460a139947c4613b86e392a1f4ffb6a5e2d /source/blender/blenkernel/intern
parentf4056e9ec3a89afbc592af3e3d169d2d584a9937 (diff)
Copy Transforms: add a mixing mode option.
Allow combining location, rotation and scale at the same time, using one constraint. The mixing modes are based on matrix multiplication, but handle scale in a way that avoids creating shear. Reviewers: brecht Differential Revision: https://developer.blender.org/D5640
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r--source/blender/blenkernel/intern/constraint.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 803aae76422..317973cc0c1 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -2090,13 +2090,43 @@ static void translike_flush_tars(bConstraint *con, ListBase *list, bool no_copy)
}
}
-static void translike_evaluate(bConstraint *UNUSED(con), bConstraintOb *cob, ListBase *targets)
+static void translike_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
{
+ bTransLikeConstraint *data = con->data;
bConstraintTarget *ct = targets->first;
if (VALID_CONS_TARGET(ct)) {
- /* just copy the entire transform matrix of the target */
- copy_m4_m4(cob->matrix, ct->matrix);
+ 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;
+
+ 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;
+
+ default:
+ BLI_assert(false);
+ }
+
+ loc_rot_size_to_mat4(cob->matrix, new_loc, new_rot, new_size);
+ }
}
}