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
This commit is contained in:
Christoph Lendenfeld 2021-12-17 22:43:02 +00:00
parent 76fd2ff9fa
commit 8e31e53aa0
Notes: blender-bot 2023-02-14 08:28:46 +01:00
Referenced by issue #81785, Implementation: Modal Key Manipulation Operators
6 changed files with 36 additions and 12 deletions

@ -1 +1 @@
Subproject commit 9d270fd007f628b23ccbcbd87caa2dc35286b26a
Subproject commit 620b85f16d03a6aadd7cae56969c9c29b06b992d

@ -1 +1 @@
Subproject commit b3c179b2869d86c44a4b29e2c638ce2a596a820d
Subproject commit c60fef38175ad989ee0c45e924cb27e1417c8667

@ -1 +1 @@
Subproject commit 16467648282500cc229c271f62201ef897f2c2c3
Subproject commit 7936dde9ece881d531b1a2ee6c45ddb56d30038c

View File

@ -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;

View File

@ -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,

@ -1 +1 @@
Subproject commit b22d19e47f4d0353082f3d9f30ee8d244c5266d5
Subproject commit 26bc78162ec89f21453ce3ded7b999bc6649f32b