diff options
author | Sebastian Parborg <darkdefende@gmail.com> | 2019-11-21 13:58:35 +0300 |
---|---|---|
committer | Sebastian Parborg <darkdefende@gmail.com> | 2019-11-21 13:58:35 +0300 |
commit | 8bc57e5b91eb80f4625b7e64eafa5aa43964ca2a (patch) | |
tree | c338937119bf8f7c02cf488a5c4d0b268a242887 /source/blender/editors/space_graph | |
parent | 122ba774e024bca0819bbaa56cdfa3c47dd49f0a (diff) |
Add curve decimate in the graph editor
Added a animation curve decimate operator in the graph editor
Reviewed By: Sybren
Differential Revision: http://developer.blender.org/D4841
Diffstat (limited to 'source/blender/editors/space_graph')
-rw-r--r-- | source/blender/editors/space_graph/graph_edit.c | 72 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_ops.c | 1 |
3 files changed, 74 insertions, 0 deletions
diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index 7ca0b6afadc..1a488118403 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -1298,6 +1298,78 @@ void GRAPH_OT_clean(wmOperatorType *ot) RNA_def_boolean(ot->srna, "channels", false, "Channels", ""); } +/* ******************** Decimate Keyframes Operator ************************* */ + +static void decimate_graph_keys(bAnimContext *ac, float remove_ratio) +{ + ListBase anim_data = {NULL, NULL}; + bAnimListElem *ale; + int filter; + + /* filter data */ + filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT | + ANIMFILTER_SEL | ANIMFILTER_NODUPLIS); + ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); + + /* loop through filtered data and clean curves */ + for (ale = anim_data.first; ale; ale = ale->next) { + decimate_fcurve(ale, remove_ratio); + + ale->update |= ANIM_UPDATE_DEFAULT; + } + + ANIM_animdata_update(ac, &anim_data); + ANIM_animdata_freelist(&anim_data); +} + +/* ------------------- */ + +static int graphkeys_decimate_exec(bContext *C, wmOperator *op) +{ + bAnimContext ac; + float remove_ratio; + + /* get editor data */ + if (ANIM_animdata_get_context(C, &ac) == 0) { + return OPERATOR_CANCELLED; + } + + remove_ratio = RNA_float_get(op->ptr, "remove_ratio"); + decimate_graph_keys(&ac, remove_ratio); + + /* set notifier that keyframes have changed */ + WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); + + return OPERATOR_FINISHED; +} + +void GRAPH_OT_decimate(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Decimate Keyframes"; + ot->idname = "GRAPH_OT_decimate"; + ot->description = + "Decimate F-Curves by removing keyframes that influence the curve shape the least"; + + /* api callbacks */ + ot->exec = graphkeys_decimate_exec; + ot->poll = graphop_editable_keyframes_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + ot->prop = RNA_def_float_percentage(ot->srna, + "remove_ratio", + 1.0f / 3.0f, + 0.0f, + 1.0f, + "Remove", + "The percentage of keyframes to remove", + 0.0f, + 1.0f); +} + /* ******************** Bake F-Curve Operator *********************** */ /* This operator bakes the data of the selected F-Curves to F-Points */ diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index 320240221b5..abd8d2db04a 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -99,6 +99,7 @@ void GRAPH_OT_paste(struct wmOperatorType *ot); void GRAPH_OT_duplicate(struct wmOperatorType *ot); void GRAPH_OT_delete(struct wmOperatorType *ot); void GRAPH_OT_clean(struct wmOperatorType *ot); +void GRAPH_OT_decimate(struct wmOperatorType *ot); void GRAPH_OT_sample(struct wmOperatorType *ot); void GRAPH_OT_bake(struct wmOperatorType *ot); void GRAPH_OT_sound_bake(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_graph/graph_ops.c b/source/blender/editors/space_graph/graph_ops.c index c9dc9803105..17cf5dca594 100644 --- a/source/blender/editors/space_graph/graph_ops.c +++ b/source/blender/editors/space_graph/graph_ops.c @@ -461,6 +461,7 @@ void graphedit_operatortypes(void) WM_operatortype_append(GRAPH_OT_sound_bake); WM_operatortype_append(GRAPH_OT_smooth); WM_operatortype_append(GRAPH_OT_clean); + WM_operatortype_append(GRAPH_OT_decimate); WM_operatortype_append(GRAPH_OT_euler_filter); WM_operatortype_append(GRAPH_OT_delete); WM_operatortype_append(GRAPH_OT_duplicate); |