Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Parborg <darkdefende@gmail.com>2019-11-21 13:58:35 +0300
committerSebastian Parborg <darkdefende@gmail.com>2019-11-21 13:58:35 +0300
commit8bc57e5b91eb80f4625b7e64eafa5aa43964ca2a (patch)
treec338937119bf8f7c02cf488a5c4d0b268a242887 /source/blender/editors/space_graph/graph_edit.c
parent122ba774e024bca0819bbaa56cdfa3c47dd49f0a (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/graph_edit.c')
-rw-r--r--source/blender/editors/space_graph/graph_edit.c72
1 files changed, 72 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 */