[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38191] branches/soc-2011-pepper/source/ blender/editors: Animation Goodie: Cyclic "Extrapolation" can be toggled from the "Set

Joshua Leung aligorith at gmail.com
Thu Jul 7 15:59:28 CEST 2011


Revision: 38191
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38191
Author:   aligorith
Date:     2011-07-07 13:59:28 +0000 (Thu, 07 Jul 2011)
Log Message:
-----------
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.

Modified Paths:
--------------
    branches/soc-2011-pepper/source/blender/editors/space_action/action_edit.c
    branches/soc-2011-pepper/source/blender/editors/space_graph/graph_edit.c

Modified: branches/soc-2011-pepper/source/blender/editors/space_action/action_edit.c
===================================================================
--- branches/soc-2011-pepper/source/blender/editors/space_action/action_edit.c	2011-07-07 13:57:20 UTC (rev 38190)
+++ branches/soc-2011-pepper/source/blender/editors/space_action/action_edit.c	2011-07-07 13:59:28 UTC (rev 38191)
@@ -920,10 +920,17 @@
 
 /* ******************** 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_actkeys_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}
 };
 
@@ -941,7 +948,34 @@
 	/* 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 */

Modified: branches/soc-2011-pepper/source/blender/editors/space_graph/graph_edit.c
===================================================================
--- branches/soc-2011-pepper/source/blender/editors/space_graph/graph_edit.c	2011-07-07 13:57:20 UTC (rev 38190)
+++ branches/soc-2011-pepper/source/blender/editors/space_graph/graph_edit.c	2011-07-07 13:59:28 UTC (rev 38191)
@@ -1269,10 +1269,17 @@
 
 /* ******************** 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 @@
 	/* 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 */




More information about the Bf-blender-cvs mailing list