diff options
-rw-r--r-- | release/scripts/startup/bl_ui/space_dopesheet.py | 3 | ||||
-rw-r--r-- | release/scripts/startup/bl_ui/space_graph.py | 2 | ||||
-rw-r--r-- | source/blender/editors/animation/keyframes_general.c | 41 | ||||
-rw-r--r-- | source/blender/editors/include/ED_keyframes_edit.h | 2 | ||||
-rw-r--r-- | source/blender/editors/space_action/action_edit.c | 9 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_edit.c | 10 |
6 files changed, 55 insertions, 12 deletions
diff --git a/release/scripts/startup/bl_ui/space_dopesheet.py b/release/scripts/startup/bl_ui/space_dopesheet.py index 0b7502b585b..7fd9719a6e3 100644 --- a/release/scripts/startup/bl_ui/space_dopesheet.py +++ b/release/scripts/startup/bl_ui/space_dopesheet.py @@ -339,6 +339,7 @@ class DOPESHEET_MT_key(Menu): layout.separator() layout.operator("action.clean") + layout.operator("action.clean", text="Clean Channels").channels = True layout.operator("action.sample") layout.separator() @@ -421,6 +422,8 @@ class DOPESHEET_MT_delete(Menu): layout.separator() layout.operator("action.clean") + layout.operator("action.clean", text="Clean Channels").channels = True + if __name__ == "__main__": # only for live edit. bpy.utils.register_module(__name__) diff --git a/release/scripts/startup/bl_ui/space_graph.py b/release/scripts/startup/bl_ui/space_graph.py index 2f5381e58c8..104fd14797e 100644 --- a/release/scripts/startup/bl_ui/space_graph.py +++ b/release/scripts/startup/bl_ui/space_graph.py @@ -258,6 +258,7 @@ class GRAPH_MT_key(Menu): layout.separator() layout.operator("graph.clean") + layout.operator("graph.clean", text="Clean Channels").channels = True layout.operator("graph.smooth") layout.operator("graph.sample") layout.operator("graph.bake") @@ -293,6 +294,7 @@ class GRAPH_MT_delete(Menu): layout.separator() layout.operator("graph.clean") + layout.operator("graph.clean", text="Clean Channels").channels = True if __name__ == "__main__": # only for live edit. diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index c198184db6f..cb49c2fc861 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -179,17 +179,22 @@ void duplicate_fcurve_keys(FCurve *fcu) /* **************************************************** */ /* Various Tools */ -/* Basic F-Curve 'cleanup' function that removes 'double points' and unnecessary keyframes on linear-segments only */ -void clean_fcurve(FCurve *fcu, float thresh) +/* Basic F-Curve 'cleanup' function that removes 'double points' and unnecessary keyframes on linear-segments only + * optionally clears up curve if one keyframe with default value remains */ +void clean_fcurve(struct bAnimContext *ac, bAnimListElem *ale, float thresh, bool cleardefault) { + FCurve *fcu = (FCurve *)ale->key_data; BezTriple *old_bezts, *bezt, *beztn; BezTriple *lastb; int totCount, i; /* check if any points */ - if ((fcu == NULL) || (fcu->bezt == NULL) || (fcu->totvert <= 1)) + if ((fcu == NULL) || (fcu->bezt == NULL) || (fcu->totvert == 0) || + (!cleardefault && fcu->totvert == 1)) + { return; - + } + /* make a copy of the old BezTriples, and clear F-Curve */ old_bezts = fcu->bezt; totCount = fcu->totvert; @@ -284,6 +289,34 @@ void clean_fcurve(FCurve *fcu, float thresh) /* now free the memory used by the old BezTriples */ if (old_bezts) MEM_freeN(old_bezts); + + /* final step, if there is just one key in fcurve, check if it's + * the default value and if is, remove fcurve completely. */ + if (cleardefault && fcu->totvert == 1) { + float default_value = 0.0f; + PointerRNA id_ptr, ptr; + PropertyRNA *prop; + RNA_id_pointer_create(ale->id, &id_ptr); + + /* get property to read from, and get value as appropriate */ + if (RNA_path_resolve_property(&id_ptr, fcu->rna_path, &ptr, &prop)) { + if (RNA_property_type(prop) == PROP_FLOAT) + default_value = RNA_property_float_get_default_index(&ptr, prop, fcu->array_index); + } + + if (fcu->bezt->vec[1][1] == default_value) { + clear_fcurve_keys(fcu); + + /* check if curve is really unused and if it is, return signal for deletion */ + if ((list_has_suitable_fmodifier(&fcu->modifiers, 0, FMI_TYPE_GENERATE_CURVE) == 0) && + (fcu->driver == NULL)) + { + AnimData *adt = ale->adt; + ANIM_fcurve_delete_from_animdata(ac, adt, fcu); + ale->key_data = NULL; + } + } + } } /* ---------------- */ diff --git a/source/blender/editors/include/ED_keyframes_edit.h b/source/blender/editors/include/ED_keyframes_edit.h index 05c7b226cd2..c6ef303b694 100644 --- a/source/blender/editors/include/ED_keyframes_edit.h +++ b/source/blender/editors/include/ED_keyframes_edit.h @@ -255,7 +255,7 @@ bool delete_fcurve_keys(struct FCurve *fcu); void clear_fcurve_keys(struct FCurve *fcu); void duplicate_fcurve_keys(struct FCurve *fcu); -void clean_fcurve(struct FCurve *fcu, float thresh); +void clean_fcurve(struct bAnimContext *ac, struct bAnimListElem *ale, float thresh, bool cleardefault); void smooth_fcurve(struct FCurve *fcu); void sample_fcurve(struct FCurve *fcu); diff --git a/source/blender/editors/space_action/action_edit.c b/source/blender/editors/space_action/action_edit.c index 90c38426164..a28b4c1a4f2 100644 --- a/source/blender/editors/space_action/action_edit.c +++ b/source/blender/editors/space_action/action_edit.c @@ -898,7 +898,7 @@ void ACTION_OT_delete(wmOperatorType *ot) /* ******************** Clean Keyframes Operator ************************* */ -static void clean_action_keys(bAnimContext *ac, float thresh) +static void clean_action_keys(bAnimContext *ac, float thresh, bool clean_chan) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; @@ -910,7 +910,7 @@ static void clean_action_keys(bAnimContext *ac, float thresh) /* loop through filtered data and clean curves */ for (ale = anim_data.first; ale; ale = ale->next) { - clean_fcurve((FCurve *)ale->key_data, thresh); + clean_fcurve(ac, ale, thresh, clean_chan); ale->update |= ANIM_UPDATE_DEFAULT; } @@ -925,6 +925,7 @@ static int actkeys_clean_exec(bContext *C, wmOperator *op) { bAnimContext ac; float thresh; + bool clean_chan; /* get editor data */ if (ANIM_animdata_get_context(C, &ac) == 0) @@ -937,9 +938,10 @@ static int actkeys_clean_exec(bContext *C, wmOperator *op) /* get cleaning threshold */ thresh = RNA_float_get(op->ptr, "threshold"); + clean_chan = RNA_boolean_get(op->ptr, "channels"); /* clean keyframes */ - clean_action_keys(&ac, thresh); + clean_action_keys(&ac, thresh, clean_chan); /* set notifier that keyframes have changed */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); @@ -964,6 +966,7 @@ void ACTION_OT_clean(wmOperatorType *ot) /* properties */ ot->prop = RNA_def_float(ot->srna, "threshold", 0.001f, 0.0f, FLT_MAX, "Threshold", "", 0.0f, 1000.0f); + RNA_def_boolean(ot->srna, "channels", false, "Channels", ""); } /* ******************** Sample Keyframes Operator *********************** */ diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index cc18df92cb1..348898b0cc6 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -982,7 +982,7 @@ void GRAPH_OT_delete(wmOperatorType *ot) /* ******************** Clean Keyframes Operator ************************* */ -static void clean_graph_keys(bAnimContext *ac, float thresh) +static void clean_graph_keys(bAnimContext *ac, float thresh, bool clean_chan) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; @@ -994,7 +994,7 @@ static void clean_graph_keys(bAnimContext *ac, float thresh) /* loop through filtered data and clean curves */ for (ale = anim_data.first; ale; ale = ale->next) { - clean_fcurve((FCurve *)ale->key_data, thresh); + clean_fcurve(ac, ale, thresh, clean_chan); ale->update |= ANIM_UPDATE_DEFAULT; } @@ -1009,6 +1009,7 @@ static int graphkeys_clean_exec(bContext *C, wmOperator *op) { bAnimContext ac; float thresh; + bool clean_chan; /* get editor data */ if (ANIM_animdata_get_context(C, &ac) == 0) @@ -1016,9 +1017,9 @@ static int graphkeys_clean_exec(bContext *C, wmOperator *op) /* get cleaning threshold */ thresh = RNA_float_get(op->ptr, "threshold"); - + clean_chan = RNA_boolean_get(op->ptr, "channels"); /* clean keyframes */ - clean_graph_keys(&ac, thresh); + clean_graph_keys(&ac, thresh, clean_chan); /* set notifier that keyframes have changed */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); @@ -1043,6 +1044,7 @@ void GRAPH_OT_clean(wmOperatorType *ot) /* properties */ ot->prop = RNA_def_float(ot->srna, "threshold", 0.001f, 0.0f, FLT_MAX, "Threshold", "", 0.0f, 1000.0f); + RNA_def_boolean(ot->srna, "channels", false, "Channels", ""); } /* ******************** Bake F-Curve Operator *********************** */ |