diff options
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 */ |