[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27601] trunk/blender/source/blender: F-Modifier Goodies (as requested by @ndy):

Joshua Leung aligorith at gmail.com
Thu Mar 18 14:04:46 CET 2010


Revision: 27601
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27601
Author:   aligorith
Date:     2010-03-18 14:04:46 +0100 (Thu, 18 Mar 2010)

Log Message:
-----------
F-Modifier Goodies (as requested by @ndy):

* Copy/Paste operators for F-Modifiers
Available in Graph and NLA Editors. Use the Copy/Paste buttons beside the 'Add Modifier' buttons.

Copy copies all the modifiers of the ACTIVE F-Curve or Strip depending on the editor.
Paste pastes modifiers from the buffer to all the selected F-Curves or Strips, adding the new modifiers to the ends of each list.

* 'Stepped Interpolation' F-Modifier
This modifier holds each interpolated value from the F-Curve for several frames without changing the timing. 

This allows to preview motions 'on-twos' for example without altering the timing, or having to go through setting heaps of keyframes. In this case, Andy wanted to use this for CG <-> StopMo.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_fcurve.h
    trunk/blender/source/blender/blenkernel/intern/fmodifier.c
    trunk/blender/source/blender/editors/animation/fmodifier_ui.c
    trunk/blender/source/blender/editors/include/ED_anim_api.h
    trunk/blender/source/blender/editors/space_graph/graph_buttons.c
    trunk/blender/source/blender/editors/space_graph/graph_edit.c
    trunk/blender/source/blender/editors/space_graph/graph_intern.h
    trunk/blender/source/blender/editors/space_graph/graph_ops.c
    trunk/blender/source/blender/editors/space_nla/nla_buttons.c
    trunk/blender/source/blender/editors/space_nla/nla_edit.c
    trunk/blender/source/blender/editors/space_nla/nla_intern.h
    trunk/blender/source/blender/editors/space_nla/nla_ops.c
    trunk/blender/source/blender/makesdna/DNA_anim_types.h
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/intern/rna_fcurve.c
    trunk/blender/source/blender/windowmanager/intern/wm_init_exit.c

Modified: trunk/blender/source/blender/blenkernel/BKE_fcurve.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_fcurve.h	2010-03-18 11:47:22 UTC (rev 27600)
+++ trunk/blender/source/blender/blenkernel/BKE_fcurve.h	2010-03-18 13:04:46 UTC (rev 27601)
@@ -158,6 +158,7 @@
 /* ---------------------- */
 
 struct FModifier *add_fmodifier(ListBase *modifiers, int type);
+struct FModifier *copy_fmodifier(struct FModifier *src);
 void copy_fmodifiers(ListBase *dst, ListBase *src);
 int remove_fmodifier(ListBase *modifiers, struct FModifier *fcm);
 int remove_fmodifier_index(ListBase *modifiers, int index);

Modified: trunk/blender/source/blender/blenkernel/intern/fmodifier.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/fmodifier.c	2010-03-18 11:47:22 UTC (rev 27600)
+++ trunk/blender/source/blender/blenkernel/intern/fmodifier.c	2010-03-18 13:04:46 UTC (rev 27601)
@@ -871,6 +871,49 @@
 	fcm_limits_evaluate /* evaluate */
 };
 
+/* Stepped F-Curve Modifier --------------------------- */
+
+static void fcm_stepped_new_data (void *mdata) 
+{
+	FMod_Stepped *data= (FMod_Stepped *)mdata;
+	
+	/* just need to set the step-size to 2-frames by default */
+	// XXX: or would 5 be more normal?
+	data->step_size = 2.0f;
+}
+
+static float fcm_stepped_time (FCurve *fcu, FModifier *fcm, float cvalue, float evaltime)
+{
+	FMod_Stepped *data= (FMod_Stepped *)fcm->data;
+	int snapblock;
+	
+	/* we snap to the start of the previous closest block of 'step_size' frames 
+	 * after the start offset has been discarded 
+	 *	- i.e. round down
+	 */
+	snapblock = (int)((evaltime - data->start) / data->step_size);
+	
+	/* reapply the offset, and multiple the snapblock by the size of the steps to get 
+	 * the new time to evaluate at 
+	 */
+	return ((float)snapblock * data->step_size) + data->start;
+}
+
+static FModifierTypeInfo FMI_STEPPED = {
+	FMODIFIER_TYPE_STEPPED, /* type */
+	sizeof(FMod_Limits), /* size */
+	FMI_TYPE_GENERATE_CURVE, /* action type */  /* XXX... err... */   
+	FMI_REQUIRES_RUNTIME_CHECK, /* requirements */
+	"Stepped", /* name */
+	"FMod_Stepped", /* struct name */
+	NULL, /* free data */
+	NULL, /* copy data */
+	fcm_stepped_new_data, /* new data */
+	NULL, /* verify */
+	fcm_stepped_time, /* evaluate time */
+	NULL /* evaluate */
+};
+
 /* F-Curve Modifier API --------------------------- */
 /* All of the F-Curve Modifier api functions use FModifierTypeInfo structs to carry out
  * and operations that involve F-Curve modifier specific code.
@@ -892,6 +935,7 @@
 	fmodifiersTypeInfo[6]=  NULL/*&FMI_FILTER*/;			/* Filter F-Curve Modifier */  // XXX unimplemented
 	fmodifiersTypeInfo[7]=  &FMI_PYTHON;			/* Custom Python F-Curve Modifier */
 	fmodifiersTypeInfo[8]= 	&FMI_LIMITS;			/* Limits F-Curve Modifier */
+	fmodifiersTypeInfo[9]= 	&FMI_STEPPED;			/* Stepped F-Curve Modifier */
 }
 
 /* This function should be used for getting the appropriate type-info when only
@@ -968,6 +1012,31 @@
 	return fcm;
 }
 
+/* Make a copy of the specified F-Modifier */
+FModifier *copy_fmodifier (FModifier *src)
+{
+	FModifierTypeInfo *fmi= fmodifier_get_typeinfo(src);
+	FModifier *dst;
+	
+	/* sanity check */
+	if (src == NULL)
+		return NULL;
+		
+	/* copy the base data, clearing the links */
+	dst = MEM_dupallocN(src);
+	dst->next = dst->prev = NULL;
+	
+	/* make a new copy of the F-Modifier's data */
+	dst->data = MEM_dupallocN(src->data);
+	
+	/* only do specific constraints if required */
+	if (fmi && fmi->copy_data)
+		fmi->copy_data(dst, src);
+		
+	/* return the new modifier */
+	return dst;
+}
+
 /* Duplicate all of the F-Modifiers in the Modifier stacks */
 void copy_fmodifiers (ListBase *dst, ListBase *src)
 {

Modified: trunk/blender/source/blender/editors/animation/fmodifier_ui.c
===================================================================
--- trunk/blender/source/blender/editors/animation/fmodifier_ui.c	2010-03-18 11:47:22 UTC (rev 27600)
+++ trunk/blender/source/blender/editors/animation/fmodifier_ui.c	2010-03-18 13:04:46 UTC (rev 27601)
@@ -30,6 +30,9 @@
  * This file defines the (C-Coded) templates + editing callbacks needed 
  * by the interface stuff or F-Modifiers, as used by F-Curves in the Graph Editor,
  * and NLA-Strips in the NLA Editor.
+ *
+ * Copy/Paste Buffer for F-Modifiers:
+ * For now, this is also defined in this file so that it can be shared between the 
  */
  
 #include <string.h>
@@ -47,15 +50,18 @@
 
 #include "RNA_access.h"
 
+#include "ED_anim_api.h"
+
 #include "UI_interface.h"
 #include "UI_resources.h"
 
+/* ********************************************** */
+/* UI STUFF */
+
 // XXX! --------------------------------
 /* temporary definition for limits of float number buttons (FLT_MAX tends to infinity with old system) */
 #define UI_FLT_MAX 	10000.0f
 
-/* ********************************************** */
-
 #define B_REDR 					1
 #define B_FMODIFIER_REDRAW		20
 
@@ -549,7 +555,23 @@
 
 /* --------------- */
 
+/* draw settings for stepped interpolation modifier */
+static void draw_modifier__stepped(uiLayout *layout, ID *id, FModifier *fcm, short width)
+{
+	uiLayout *col;
+	PointerRNA ptr;
+	
+	/* init the RNA-pointer */
+	RNA_pointer_create(id, &RNA_FModifierStepped, fcm, &ptr);
+	
+	col= uiLayoutColumn(layout, 0);
+	
+	uiItemR(col, NULL, 0, &ptr, "step_size", 0);
+	uiItemR(col, NULL, 0, &ptr, "start_offset", 0);
+}
 
+/* --------------- */
+
 void ANIM_uiTemplate_fmodifier_draw (uiLayout *layout, ID *id, ListBase *modifiers, FModifier *fcm)
 {
 	FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm);
@@ -635,6 +657,10 @@
 			case FMODIFIER_TYPE_NOISE: /* Noise */
 				draw_modifier__noise(box, id, fcm, width);
 				break;
+				
+			case FMODIFIER_TYPE_STEPPED: /* Stepped */
+				draw_modifier__stepped(box, id, fcm, width);
+				break;
 			
 			default: /* unknown type */
 				break;
@@ -643,3 +669,81 @@
 }
 
 /* ********************************************** */
+/* COPY/PASTE BUFFER STUFF */
+
+/* Copy/Paste Buffer itself (list of FModifier 's) */
+static ListBase fmodifier_copypaste_buf = {NULL, NULL};
+
+/* ---------- */
+
+/* free the copy/paste buffer */
+void free_fmodifiers_copybuf (void)
+{
+	/* just free the whole buffer */
+	free_fmodifiers(&fmodifier_copypaste_buf);
+}
+
+/* copy the given F-Modifiers to the buffer, returning whether anything was copied or not
+ * assuming that the buffer has been cleared already with free_fmodifiers_copybuf()
+ *	- active: only copy the active modifier
+ */
+short ANIM_fmodifiers_copy_to_buf (ListBase *modifiers, short active)
+{
+	short ok = 1;
+	
+	/* sanity checks */
+	if ELEM(NULL, modifiers, modifiers->first)
+		return 0;
+		
+	/* copy the whole list, or just the active one? */
+	if (active) {
+		FModifier *fcm = find_active_fmodifier(modifiers);
+		
+		if (fcm) {
+			FModifier *fcmN = copy_fmodifier(fcm);
+			BLI_addtail(&fmodifier_copypaste_buf, fcmN);
+		}
+		else
+			ok = 0;
+	}
+	else
+		copy_fmodifiers(&fmodifier_copypaste_buf, modifiers);
+		
+	/* did we succeed? */
+	return ok;
+}
+
+/* 'Paste' the F-Modifier(s) from the buffer to the specified list 
+ *	- replace: free all the existing modifiers to leave only the pasted ones 
+ */
+short ANIM_fmodifiers_paste_from_buf (ListBase *modifiers, short replace)
+{
+	FModifier *fcm;
+	short ok = 0;
+	
+	/* sanity checks */
+	if (modifiers == NULL)
+		return 0;
+		
+	/* if replacing the list, free the existing modifiers */
+	if (replace)
+		free_fmodifiers(modifiers);
+		
+	/* now copy over all the modifiers in the buffer to the end of the list */
+	for (fcm= fmodifier_copypaste_buf.first; fcm; fcm= fcm->next) {
+		/* make a copy of it */
+		FModifier *fcmN = copy_fmodifier(fcm);
+		
+		/* make sure the new one isn't active, otherwise the list may get several actives */
+		fcmN->flag &= ~FMODIFIER_FLAG_ACTIVE;
+		
+		/* now add it to the end of the list */
+		BLI_addtail(modifiers, fcmN);
+		ok = 1;
+	}
+	
+	/* did we succeed? */
+	return ok;
+}
+
+/* ********************************************** */

Modified: trunk/blender/source/blender/editors/include/ED_anim_api.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_anim_api.h	2010-03-18 11:47:22 UTC (rev 27600)
+++ trunk/blender/source/blender/editors/include/ED_anim_api.h	2010-03-18 13:04:46 UTC (rev 27601)
@@ -452,9 +452,28 @@
 /* ************************************************* */
 /* F-MODIFIER TOOLS */
 
+/* ------------- UI Panel Drawing -------------- */
+
 /* draw a given F-Modifier for some layout/UI-Block */
 void ANIM_uiTemplate_fmodifier_draw(struct uiLayout *layout, struct ID *id, ListBase *modifiers, struct FModifier *fcm);
 
+/* ------------- Copy/Paste Buffer -------------- */
+
+
+/* free the copy/paste buffer */
+void free_fmodifiers_copybuf(void);
+
+/* copy the given F-Modifiers to the buffer, returning whether anything was copied or not
+ * assuming that the buffer has been cleared already with free_fmodifiers_copybuf()
+ *	- active: only copy the active modifier
+ */
+short ANIM_fmodifiers_copy_to_buf(ListBase *modifiers, short active);
+
+/* 'Paste' the F-Modifier(s) from the buffer to the specified list 
+ *	- replace: free all the existing modifiers to leave only the pasted ones 
+ */
+short ANIM_fmodifiers_paste_from_buf(ListBase *modifiers, short replace);
+
 /* ************************************************* */
 /* ASSORTED TOOLS */
 

Modified: trunk/blender/source/blender/editors/space_graph/graph_buttons.c
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_buttons.c	2010-03-18 11:47:22 UTC (rev 27600)
+++ trunk/blender/source/blender/editors/space_graph/graph_buttons.c	2010-03-18 13:04:46 UTC (rev 27601)
@@ -610,8 +610,13 @@
 		row= uiLayoutRow(pa->layout, 0);
 		block= uiLayoutGetBlock(row);
 		
-		// XXX for now, this will be a operator button which calls a temporary 'add modifier' operator
+		// XXX for now, this will be a operator button which calls a 'add modifier' operator
 		uiDefButO(block, BUT, "GRAPH_OT_fmodifier_add", WM_OP_INVOKE_REGION_WIN, "Add Modifier", 10, 0, 150, 20, "Adds a new F-Curve Modifier for the active F-Curve");
+		
+		/* copy/paste (as sub-row)*/
+		row= uiLayoutRow(row, 1);
+			uiItemO(row, "", ICON_COPYDOWN, "GRAPH_OT_fmodifier_copy");
+			uiItemO(row, "", ICON_PASTEDOWN, "GRAPH_OT_fmodifier_paste");
 	}
 	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list