diff options
author | Christoph Lendenfeld <chris.lend@gmx.at> | 2021-12-25 15:40:53 +0300 |
---|---|---|
committer | Christoph Lendenfeld <chris.lend@gmx.at> | 2021-12-25 15:40:53 +0300 |
commit | 9085b4a731fd5315eb97c00fc4bbf7c163698ebc (patch) | |
tree | 7d24710d413d7cea5ef1e808306a19fc8080ca4a /source/blender/editors/animation | |
parent | e505957b47a9db99b958fa02325074120f129c94 (diff) |
Blend To Neighbor Implementation
This patch adds the blend to neighbor operator to the Graph editor.
The operator acts like the blend to neighbor operator for a pose context, just working on keyframes.
Reviewed by: Sybren A. Stüvel
Differential Revision: https://developer.blender.org/D9374
Ref: D9374
Diffstat (limited to 'source/blender/editors/animation')
-rw-r--r-- | source/blender/editors/animation/keyframes_general.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 4fa5dee99a6..3c2e66d9367 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -367,6 +367,37 @@ ListBase find_fcurve_segments(FCurve *fcu) return segments; } +static BezTriple fcurve_segment_start_get(FCurve *fcu, int index) +{ + BezTriple start_bezt = index - 1 >= 0 ? fcu->bezt[index - 1] : fcu->bezt[index]; + return start_bezt; +} + +static BezTriple fcurve_segment_end_get(FCurve *fcu, int index) +{ + BezTriple end_bezt = index < fcu->totvert ? fcu->bezt[index] : fcu->bezt[index - 1]; + return end_bezt; +} + +/* ---------------- */ + +void blend_to_neighbor_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor) +{ + const float blend_factor = fabs(factor * 2 - 1); + BezTriple target_bezt; + /* Find which key to blend towards. */ + if (factor < 0.5f) { + target_bezt = fcurve_segment_start_get(fcu, segment->start_index); + } + else { + target_bezt = fcurve_segment_end_get(fcu, segment->start_index + segment->length); + } + /* Blend each key individually. */ + for (int i = segment->start_index; i < segment->start_index + segment->length; i++) { + fcu->bezt[i].vec[1][1] = interpf(target_bezt.vec[1][1], fcu->bezt[i].vec[1][1], blend_factor); + } +} + /* ---------------- */ /* Check if the keyframe interpolation type is supported */ |