diff options
author | Kevin C. Burke <blastframe> | 2022-01-25 13:40:46 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2022-01-25 13:41:40 +0300 |
commit | 17b0c06946bef39e29e3b0b1a5faaf8faca35daa (patch) | |
tree | 8d0ce3b0f680206d5e1da36f9f3bb718dc58d64b /source/blender/editors/animation | |
parent | a000de7c2a4da1fb57cb22658b29d1ac17c9cd51 (diff) |
Animation: Equalize Handle Operator
The Equalize Handles operator allows users to make selected handle
lengths uniform: either respecting their original angle from the key
control point or by flattening their angle (removing the overshoot
sometimes produced by certain handle types).
Design: T94172
Reviewed by: sybren
Differential Revision: https://developer.blender.org/D13702
Diffstat (limited to 'source/blender/editors/animation')
-rw-r--r-- | source/blender/editors/animation/keyframes_edit.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/source/blender/editors/animation/keyframes_edit.c b/source/blender/editors/animation/keyframes_edit.c index 145d67b7810..dfe6566df67 100644 --- a/source/blender/editors/animation/keyframes_edit.c +++ b/source/blender/editors/animation/keyframes_edit.c @@ -1283,6 +1283,61 @@ static short set_bezt_sine(KeyframeEditData *UNUSED(ked), BezTriple *bezt) return 0; } +static void handle_flatten(float vec[3][3], const int idx, const float direction[2]) +{ + BLI_assert_msg(idx == 0 || idx == 2, "handle_flatten() expects a handle index"); + + add_v2_v2v2(vec[idx], vec[1], direction); +} + +static void handle_set_length(float vec[3][3], const int idx, const float handle_length) +{ + BLI_assert_msg(idx == 0 || idx == 2, "handle_set_length() expects a handle index"); + + float handle_direction[2]; + sub_v2_v2v2(handle_direction, vec[idx], vec[1]); + normalize_v2_length(handle_direction, handle_length); + add_v2_v2v2(vec[idx], vec[1], handle_direction); +} + +void ANIM_fcurve_equalize_keyframes_loop(FCurve *fcu, + const eEditKeyframes_Equalize mode, + const float handle_length, + const bool flatten) +{ + uint i; + BezTriple *bezt; + const float flat_direction_left[2] = {-handle_length, 0.f}; + const float flat_direction_right[2] = {handle_length, 0.f}; + + /* Loop through an F-Curves keyframes. */ + for (bezt = fcu->bezt, i = 0; i < fcu->totvert; bezt++, i++) { + if ((bezt->f2 & SELECT) == 0) { + continue; + } + + /* Perform handle equalization if mode is 'Both' or 'Left'. */ + if (mode & EQUALIZE_HANDLES_LEFT) { + if (flatten) { + handle_flatten(bezt->vec, 0, flat_direction_left); + } + else { + handle_set_length(bezt->vec, 0, handle_length); + } + } + + /* Perform handle equalization if mode is 'Both' or 'Right'. */ + if (mode & EQUALIZE_HANDLES_RIGHT) { + if (flatten) { + handle_flatten(bezt->vec, 2, flat_direction_right); + } + else { + handle_set_length(bezt->vec, 2, handle_length); + } + } + } +} + KeyframeEditFunc ANIM_editkeyframes_ipo(short mode) { switch (mode) { |