diff options
author | Christoph Lendenfeld <chris.lend@gmx.at> | 2021-12-18 01:43:02 +0300 |
---|---|---|
committer | Christoph Lendenfeld <chris.lend@gmx.at> | 2021-12-18 01:43:02 +0300 |
commit | 8e31e53aa0ee9693582ad5b72cfe5732b57c72fd (patch) | |
tree | 674efb3d625f939881ae3255a656995987aa904e /source | |
parent | 76fd2ff9fa49c7aefe530635472bc61cf7c5a3e2 (diff) |
Function to return a list of keyframe segments
Add a function that returns a list of keyframe segments
A segment being a continuous selection of keyframes
Will be used by future operators in the graph editor
Reviewed by: Sybren A. Stüvel
Differential Revision: https://developer.blender.org/D13531
Ref: D13531
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/animation/keyframes_general.c | 35 | ||||
-rw-r--r-- | source/blender/editors/include/ED_keyframes_edit.h | 5 | ||||
m--------- | source/tools | 0 |
3 files changed, 32 insertions, 8 deletions
diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index dc5d71b5a1e..4fa5dee99a6 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -345,6 +345,28 @@ static bool find_fcurve_segment(FCurve *fcu, return in_segment; } +/* Return a list of FCurveSegment with a start index and a length. + * A segment is a continuous selection of keyframes. + * Keys that have BEZT_FLAG_IGNORE_TAG set are treated as unselected. + * The caller is responsible for freeing the memory. */ +ListBase find_fcurve_segments(FCurve *fcu) +{ + ListBase segments = {NULL, NULL}; + int segment_start_idx = 0; + int segment_len = 0; + int current_index = 0; + + while (find_fcurve_segment(fcu, current_index, &segment_start_idx, &segment_len)) { + FCurveSegment *segment; + segment = MEM_callocN(sizeof(*segment), "FCurveSegment"); + segment->start_index = segment_start_idx; + segment->length = segment_len; + BLI_addtail(&segments, segment); + current_index = segment_start_idx + segment_len; + } + return segments; +} + /* ---------------- */ /* Check if the keyframe interpolation type is supported */ @@ -440,15 +462,12 @@ bool decimate_fcurve(bAnimListElem *ale, float remove_ratio, float error_sq_max) fcu->bezt[i].f2 &= ~BEZT_FLAG_TEMP_TAG; } - /* Only decimate the individual selected curve segments. */ - int segment_start_idx = 0; - int segment_len = 0; - int current_index = 0; - - while (find_fcurve_segment(fcu, current_index, &segment_start_idx, &segment_len)) { - decimate_fcurve_segment(fcu, segment_start_idx, segment_len, remove_ratio, error_sq_max); - current_index = segment_start_idx + segment_len; + ListBase segments = find_fcurve_segments(fcu); + LISTBASE_FOREACH (FCurveSegment *, segment, &segments) { + decimate_fcurve_segment( + fcu, segment->start_index, segment->length, remove_ratio, error_sq_max); } + BLI_freelistN(&segments); uint old_totvert = fcu->totvert; fcu->bezt = NULL; diff --git a/source/blender/editors/include/ED_keyframes_edit.h b/source/blender/editors/include/ED_keyframes_edit.h index bafe68bd28d..8a7831db0ea 100644 --- a/source/blender/editors/include/ED_keyframes_edit.h +++ b/source/blender/editors/include/ED_keyframes_edit.h @@ -380,6 +380,11 @@ bool delete_fcurve_keys(struct FCurve *fcu); void clear_fcurve_keys(struct FCurve *fcu); void duplicate_fcurve_keys(struct FCurve *fcu); +typedef struct FCurveSegment { + struct FCurveSegment *next, *prev; + int start_index, length; +} FCurveSegment; +ListBase find_fcurve_segments(struct FCurve *fcu); void clean_fcurve(struct bAnimContext *ac, struct bAnimListElem *ale, float thresh, diff --git a/source/tools b/source/tools -Subproject b22d19e47f4d0353082f3d9f30ee8d244c5266d +Subproject 26bc78162ec89f21453ce3ded7b999bc6649f32 |