[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21307] branches/soc-2009-aligorith/source /blender: NLA SoC: Separating out F-Modifier API

Joshua Leung aligorith at gmail.com
Thu Jul 2 07:25:16 CEST 2009


Revision: 21307
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21307
Author:   aligorith
Date:     2009-07-02 07:25:14 +0200 (Thu, 02 Jul 2009)

Log Message:
-----------
NLA SoC: Separating out F-Modifier API

* F-Modifier API is now in its own file in blenkernel
* Renamed and refactored these so that they're no dependent on F-Curves, since all they really used was the fcu->modifiers list
* Added missing license blocks to a few files

Modified Paths:
--------------
    branches/soc-2009-aligorith/source/blender/blenkernel/BKE_fcurve.h
    branches/soc-2009-aligorith/source/blender/blenkernel/intern/fcurve.c
    branches/soc-2009-aligorith/source/blender/blenkernel/intern/ipo.c
    branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c
    branches/soc-2009-aligorith/source/blender/editors/animation/drivers.c
    branches/soc-2009-aligorith/source/blender/editors/animation/fmodifier_ui.c
    branches/soc-2009-aligorith/source/blender/editors/animation/keyframing.c
    branches/soc-2009-aligorith/source/blender/editors/animation/keyingsets.c
    branches/soc-2009-aligorith/source/blender/editors/space_graph/graph_draw.c
    branches/soc-2009-aligorith/source/blender/editors/space_graph/graph_edit.c
    branches/soc-2009-aligorith/source/blender/editors/space_graph/graph_utils.c

Added Paths:
-----------
    branches/soc-2009-aligorith/source/blender/blenkernel/intern/fmodifier.c

Modified: branches/soc-2009-aligorith/source/blender/blenkernel/BKE_fcurve.h
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/BKE_fcurve.h	2009-07-02 04:47:36 UTC (rev 21306)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/BKE_fcurve.h	2009-07-02 05:25:14 UTC (rev 21307)
@@ -104,15 +104,15 @@
 
 /* ---------------------- */
 
-struct FModifier *fcurve_add_modifier(struct FCurve *fcu, int type);
-void fcurve_copy_modifiers(ListBase *dst, ListBase *src);
-void fcurve_remove_modifier(struct FCurve *fcu, struct FModifier *fcm);
-void fcurve_free_modifiers(struct FCurve *fcu);
+struct FModifier *add_fmodifier(ListBase *modifiers, int type);
+void copy_fmodifiers(ListBase *dst, ListBase *src);
+void remove_fmodifier(ListBase *modifiers, struct FModifier *fcm);
+void free_fmodifiers(ListBase *modifiers);
 
-struct FModifier *fcurve_find_active_modifier(struct FCurve *fcu);
-void fcurve_set_active_modifier(struct FCurve *fcu, struct FModifier *fcm);
+struct FModifier *find_active_fmodifier(ListBase *modifiers);
+void set_active_fmodifier(ListBase *modifiers, struct FModifier *fcm);
 
-short fcurve_has_suitable_modifier(struct FCurve *fcu, int mtype, short acttype);
+short list_has_suitable_fmodifier(ListBase *modifiers, int mtype, short acttype);
 
 float evaluate_time_fmodifiers(ListBase *modifiers, struct FCurve *fcu, float cvalue, float evaltime);
 void evaluate_value_fmodifiers(ListBase *modifiers, struct FCurve *fcu, float *cvalue, float evaltime);

Modified: branches/soc-2009-aligorith/source/blender/blenkernel/intern/fcurve.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/intern/fcurve.c	2009-07-02 04:47:36 UTC (rev 21306)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/intern/fcurve.c	2009-07-02 05:25:14 UTC (rev 21307)
@@ -56,7 +56,7 @@
 #include "RNA_types.h"
 
 #ifndef DISABLE_PYTHON
-#include "BPY_extern.h" /* for BPY_pydriver_eval() */
+#include "BPY_extern.h" 
 #endif
 
 #define SMALL -1.0e-10
@@ -84,7 +84,7 @@
 	
 	/* free extra data - i.e. modifiers, and driver */
 	fcurve_free_driver(fcu);
-	fcurve_free_modifiers(fcu);
+	free_fmodifiers(&fcu->modifiers);
 	
 	/* free f-curve itself */
 	MEM_freeN(fcu);
@@ -140,7 +140,7 @@
 	fcu_d->driver= fcurve_copy_driver(fcu_d->driver);
 	
 	/* copy modifiers */
-	fcurve_copy_modifiers(&fcu_d->modifiers, &fcu->modifiers);
+	copy_fmodifiers(&fcu_d->modifiers, &fcu->modifiers);
 	
 	/* return new data */
 	return fcu_d;
@@ -1270,1135 +1270,6 @@
 	return cvalue;
 }
 
-/* ******************************** F-Curve Modifiers ********************************* */
-
-/* Template --------------------------- */
-
-/* Each modifier defines a set of functions, which will be called at the appropriate
- * times. In addition to this, each modifier should have a type-info struct, where
- * its functions are attached for use. 
- */
- 
-/* Template for type-info data:
- *	- make a copy of this when creating new modifiers, and just change the functions
- *	  pointed to as necessary
- *	- although the naming of functions doesn't matter, it would help for code
- *	  readability, to follow the same naming convention as is presented here
- * 	- any functions that a constraint doesn't need to define, don't define
- *	  for such cases, just use NULL 
- *	- these should be defined after all the functions have been defined, so that
- * 	  forward-definitions/prototypes don't need to be used!
- *	- keep this copy #if-def'd so that future constraints can get based off this
- */
-#if 0
-static FModifierTypeInfo FMI_MODNAME = {
-	FMODIFIER_TYPE_MODNAME, /* type */
-	sizeof(FMod_ModName), /* size */
-	FMI_TYPE_SOME_ACTION, /* action type */
-	FMI_REQUIRES_SOME_REQUIREMENT, /* requirements */
-	"Modifier Name", /* name */
-	"FMod_ModName", /* struct name */
-	fcm_modname_free, /* free data */
-	fcm_modname_relink, /* relink data */
-	fcm_modname_copy, /* copy data */
-	fcm_modname_new_data, /* new data */
-	fcm_modname_verify, /* verify */
-	fcm_modname_time, /* evaluate time */
-	fcm_modname_evaluate /* evaluate */
-};
-#endif
-
-/* Generator F-Curve Modifier --------------------------- */
-
-/* Generators available:
- * 	1) simple polynomial generator:
- *		- Exanded form - (y = C[0]*(x^(n)) + C[1]*(x^(n-1)) + ... + C[n])  
- *		- Factorised form - (y = (C[0][0]*x + C[0][1]) * (C[1][0]*x + C[1][1]) * ... * (C[n][0]*x + C[n][1]))
- */
-
-static void fcm_generator_free (FModifier *fcm)
-{
-	FMod_Generator *data= (FMod_Generator *)fcm->data;
-	
-	/* free polynomial coefficients array */
-	if (data->coefficients)
-		MEM_freeN(data->coefficients);
-}
-
-static void fcm_generator_copy (FModifier *fcm, FModifier *src)
-{
-	FMod_Generator *gen= (FMod_Generator *)fcm->data;
-	FMod_Generator *ogen= (FMod_Generator *)src->data;
-	
-	/* copy coefficients array? */
-	if (ogen->coefficients)
-		gen->coefficients= MEM_dupallocN(ogen->coefficients);
-}
-
-static void fcm_generator_new_data (void *mdata)
-{
-	FMod_Generator *data= (FMod_Generator *)mdata;
-	float *cp;
-	
-	/* set default generator to be linear 0-1 (gradient = 1, y-offset = 0) */
-	data->poly_order= 1;
-	data->arraysize= 2;
-	cp= data->coefficients= MEM_callocN(sizeof(float)*2, "FMod_Generator_Coefs");
-	cp[0] = 0; // y-offset 
-	cp[1] = 1; // gradient
-}
-
-static void fcm_generator_verify (FModifier *fcm)
-{
-	FMod_Generator *data= (FMod_Generator *)fcm->data;
-	
-	/* requirements depend on mode */
-	switch (data->mode) {
-		case FCM_GENERATOR_POLYNOMIAL: /* expanded polynomial expression */
-		{
-			/* arraysize needs to be order+1, so resize if not */
-			if (data->arraysize != (data->poly_order+1)) {
-				float *nc;
-				
-				/* make new coefficients array, and copy over as much data as can fit */
-				nc= MEM_callocN(sizeof(float)*(data->poly_order+1), "FMod_Generator_Coefs");
-				
-				if (data->coefficients) {
-					if (data->arraysize > (data->poly_order+1))
-						memcpy(nc, data->coefficients, sizeof(float)*(data->poly_order+1));
-					else
-						memcpy(nc, data->coefficients, sizeof(float)*data->arraysize);
-						
-					/* free the old data */
-					MEM_freeN(data->coefficients);
-				}	
-				
-				/* set the new data */
-				data->coefficients= nc;
-				data->arraysize= data->poly_order+1;
-			}
-		}
-			break;
-		
-		case FCM_GENERATOR_POLYNOMIAL_FACTORISED: /* expanded polynomial expression */
-		{
-			/* arraysize needs to be 2*order, so resize if not */
-			if (data->arraysize != (data->poly_order * 2)) {
-				float *nc;
-				
-				/* make new coefficients array, and copy over as much data as can fit */
-				nc= MEM_callocN(sizeof(float)*(data->poly_order*2), "FMod_Generator_Coefs");
-				
-				if (data->coefficients) {
-					if (data->arraysize > (data->poly_order * 2))
-						memcpy(nc, data->coefficients, sizeof(float)*(data->poly_order * 2));
-					else
-						memcpy(nc, data->coefficients, sizeof(float)*data->arraysize);
-						
-					/* free the old data */
-					MEM_freeN(data->coefficients);
-				}	
-				
-				/* set the new data */
-				data->coefficients= nc;
-				data->arraysize= data->poly_order * 2;
-			}
-		}
-			break;	
-	}
-}
-
-static void fcm_generator_evaluate (FCurve *fcu, FModifier *fcm, float *cvalue, float evaltime)
-{
-	FMod_Generator *data= (FMod_Generator *)fcm->data;
-	
-	/* behaviour depends on mode 
-	 * NOTE: the data in its default state is fine too
-	 */
-	switch (data->mode) {
-		case FCM_GENERATOR_POLYNOMIAL: /* expanded polynomial expression */
-		{
-			/* we overwrite cvalue with the sum of the polynomial */
-			float *powers = MEM_callocN(sizeof(float)*data->arraysize, "Poly Powers");
-			float value= 0.0f;
-			unsigned int i;
-			
-			/* for each x^n, precalculate value based on previous one first... this should be 
-			 * faster that calling pow() for each entry
-			 */
-			for (i=0; i < data->arraysize; i++) {
-				/* first entry is x^0 = 1, otherwise, calculate based on previous */
-				if (i)
-					powers[i]= powers[i-1] * evaltime;
-				else
-					powers[0]= 1;
-			}
-			
-			/* for each coefficient, add to value, which we'll write to *cvalue in one go */
-			for (i=0; i < data->arraysize; i++)
-				value += data->coefficients[i] * powers[i];
-			
-			/* only if something changed, write *cvalue in one go */
-			if (data->poly_order) {
-				if (data->flag & FCM_GENERATOR_ADDITIVE)
-					*cvalue += value;
-				else
-					*cvalue= value;
-			}
-				
-			/* cleanup */
-			if (powers) 
-				MEM_freeN(powers);
-		}
-			break;
-			
-		case FCM_GENERATOR_POLYNOMIAL_FACTORISED: /* factorised polynomial */
-		{
-			float value= 1.0f, *cp=NULL;
-			unsigned int i;
-			
-			/* for each coefficient pair, solve for that bracket before accumulating in value by multiplying */
-			for (cp=data->coefficients, i=0; (cp) && (i < data->poly_order); cp+=2, i++) 
-				value *= (cp[0]*evaltime + cp[1]);
-				
-			/* only if something changed, write *cvalue in one go */
-			if (data->poly_order) {
-				if (data->flag & FCM_GENERATOR_ADDITIVE)
-					*cvalue += value;
-				else
-					*cvalue= value;
-			}
-		}
-			break;
-	}
-}
-
-static FModifierTypeInfo FMI_GENERATOR = {
-	FMODIFIER_TYPE_GENERATOR, /* type */
-	sizeof(FMod_Generator), /* size */
-	FMI_TYPE_GENERATE_CURVE, /* action type */
-	FMI_REQUIRES_NOTHING, /* requirements */
-	"Generator", /* name */
-	"FMod_Generator", /* struct name */
-	fcm_generator_free, /* free data */
-	fcm_generator_copy, /* copy data */
-	fcm_generator_new_data, /* new data */
-	fcm_generator_verify, /* verify */
-	NULL, /* evaluate time */
-	fcm_generator_evaluate /* evaluate */
-};
-
-/* Built-In Function Generator F-Curve Modifier --------------------------- */
-
-/* This uses the general equation for equations:
- * 		y = amplitude * fn(phase_multiplier*x + phase_offset) + y_offset
- *
- * where amplitude, phase_multiplier/offset, y_offset are user-defined coefficients,
- * x is the evaluation 'time', and 'y' is the resultant value
- *
- * Functions available are
- *	sin, cos, tan, sinc (normalised sin), natural log, square root 
- */
-
-static void fcm_fn_generator_new_data (void *mdata)
-{
-	FMod_FunctionGenerator *data= (FMod_FunctionGenerator *)mdata;
-	
-	/* set amplitude and phase multiplier to 1.0f so that something is generated */
-	data->amplitude= 1.0f;
-	data->phase_multiplier= 1.0f;
-}
-
-/* Unary 'normalised sine' function
- * 	y = sin(PI + x) / (PI * x),
- * except for x = 0 when y = 1.
- */
-static double sinc (double x)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list