From c9d6989098e2defbaea36b767169f521c8a5d62a Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Thu, 7 Jul 2011 13:59:28 +0000 Subject: Animation Goodie: Cyclic "Extrapolation" can be toggled from the "Set Extrapolation" tool again Added "Make Cyclic" and "Clear Cyclic" options to "Set Extrapolation" tool (found from Channels menu) in Animation Editors. These options simply add or remove (respectively) Cycles FModifiers from the selected F-Curves, making them have cyclic extrapolation with a single click, instead of having to go through the FModifiers UI (or Graph- Editor only "Add FModifier" operator), which should make it easier to do this apparently common chore. --- source/blender/editors/space_graph/graph_edit.c | 36 ++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'source/blender/editors/space_graph/graph_edit.c') diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index 4abf00f82d3..d88a18ffcbc 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -1269,10 +1269,17 @@ void GRAPH_OT_sample (wmOperatorType *ot) /* ******************** Set Extrapolation-Type Operator *********************** */ +/* defines for make/clear cyclic extrapolation tools */ +#define MAKE_CYCLIC_EXPO -1 +#define CLEAR_CYCLIC_EXPO -2 + /* defines for set extrapolation-type for selected keyframes tool */ static EnumPropertyItem prop_graphkeys_expo_types[] = { {FCURVE_EXTRAPOLATE_CONSTANT, "CONSTANT", 0, "Constant Extrapolation", ""}, {FCURVE_EXTRAPOLATE_LINEAR, "LINEAR", 0, "Linear Extrapolation", ""}, + + {MAKE_CYCLIC_EXPO, "MAKE_CYCLIC", 0, "Make Cyclic (F-Modifier)", "Add Cycles F-Modifier if one doesn't exist already"}, + {CLEAR_CYCLIC_EXPO, "CLEAR_CYCLIC", 0, "Clear Cyclic (F-Modifier)", "Remove Cycles F-Modifier if not needed anymore"}, {0, NULL, 0, NULL, NULL} }; @@ -1290,7 +1297,34 @@ static void setexpo_graph_keys(bAnimContext *ac, short mode) /* loop through setting mode per F-Curve */ for (ale= anim_data.first; ale; ale= ale->next) { FCurve *fcu= (FCurve *)ale->data; - fcu->extend= mode; + + if (mode >= 0) { + /* just set mode setting */ + fcu->extend= mode; + } + else { + /* shortcuts for managing Cycles F-Modifiers to make it easier to toggle cyclic animation + * without having to go through FModifier UI in Graph Editor to do so + */ + if (mode == MAKE_CYCLIC_EXPO) { + /* only add if one doesn't exist */ + if (list_has_suitable_fmodifier(&fcu->modifiers, FMODIFIER_TYPE_CYCLES, -1) == 0) { + // TODO: add some more preset versions which set different extrapolation options? + add_fmodifier(&fcu->modifiers, FMODIFIER_TYPE_CYCLES); + } + } + else if (mode == CLEAR_CYCLIC_EXPO) { + /* remove all the modifiers fitting this description */ + FModifier *fcm, *fcn=NULL; + + for (fcm = fcu->modifiers.first; fcm; fcm = fcn) { + fcn = fcm->next; + + if (fcm->type == FMODIFIER_TYPE_CYCLES) + remove_fmodifier(&fcu->modifiers, fcm); + } + } + } } /* cleanup */ -- cgit v1.2.3