Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2009-07-02 06:12:37 +0400
committerJoshua Leung <aligorith@gmail.com>2009-07-02 06:12:37 +0400
commit1588de008a7c9c80d193034c0f8b4dc766620a38 (patch)
tree6283229555be564f8f0820d4ed817920cdedb58b /source/blender/blenkernel/intern/fcurve.c
parentede921fdfac1c76b8c54cae1723fbe9efd891939 (diff)
NLA SoC: Separated 'Built-In Function Generator' FModifier into a separate FModifier
Started cleaning up FModifiers in preparation for allowing them to be used on NLA Strips. This commit separates the 'Built-in Function' mode for the Generator modifier out into its own modifier, since it was being quite frequently used (and the RNA wrapping for this used to be quite hackish). BACKWARDS COMPATABILITY WARNING: Old files with FModifiers saved (i.e. old 2.5 files, but not any others) will not load correctly as a result of these changes (the wrong modifiers will be shown). I've decided that there are not likely to be many files affected by this yet, but doing this will result in a much nicer modifiers-define list in the long run.
Diffstat (limited to 'source/blender/blenkernel/intern/fcurve.c')
-rw-r--r--source/blender/blenkernel/intern/fcurve.c256
1 files changed, 130 insertions, 126 deletions
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index 27ca6332cdc..e52c63d1b21 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -1,5 +1,5 @@
/**
- * $Id: fcurve.c 21023 2009-06-20 04:02:49Z aligorith $
+ * $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
@@ -1314,11 +1314,6 @@ static FModifierTypeInfo FMI_MODNAME = {
* 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]))
- * 2) simple builin 'functions':
- * of the form (y = C[0] * fn( C[1]*x + C[2] ) + C[3])
- * where fn() can be any one of:
- * sin, cos, tan, ln, sqrt
- * 3) expression...
*/
static void fcm_generator_free (FModifier *fcm)
@@ -1409,44 +1404,10 @@ static void fcm_generator_verify (FModifier *fcm)
data->arraysize= data->poly_order * 2;
}
}
- break;
-
- case FCM_GENERATOR_FUNCTION: /* builtin function */
- {
- /* arraysize needs to be 4*/
- if (data->arraysize != 4) {
- float *nc;
-
- /* free the old data */
- if (data->coefficients)
- MEM_freeN(data->coefficients);
-
- /* make new coefficients array, and init using default values */
- nc= data->coefficients= MEM_callocN(sizeof(float)*4, "FMod_Generator_Coefs");
- data->arraysize= 4;
-
- nc[0]= 1.0f;
- nc[1]= 1.0f;
- nc[2]= 0.0f;
- nc[3]= 0.0f;
- }
- }
break;
}
}
-/* Unary 'normalised sine' function
- * y = sin(PI + x) / (PI * x),
- * except for x = 0 when y = 1.
- */
-static double sinc (double x)
-{
- if (fabs(x) < 0.0001)
- return 1.0;
- else
- return sin(M_PI * x) / (M_PI * x);
-}
-
static void fcm_generator_evaluate (FCurve *fcu, FModifier *fcm, float *cvalue, float evaltime)
{
FMod_Generator *data= (FMod_Generator *)fcm->data;
@@ -1509,86 +1470,6 @@ static void fcm_generator_evaluate (FCurve *fcu, FModifier *fcm, float *cvalue,
}
}
break;
-
- case FCM_GENERATOR_FUNCTION: /* builtin function */
- {
- double arg= data->coefficients[1]*evaltime + data->coefficients[2];
- double (*fn)(double v) = NULL;
-
- /* get function pointer to the func to use:
- * WARNING: must perform special argument validation hereto guard against crashes
- */
- switch (data->func_type)
- {
- /* simple ones */
- case FCM_GENERATOR_FN_SIN: /* sine wave */
- fn= sin;
- break;
- case FCM_GENERATOR_FN_COS: /* cosine wave */
- fn= cos;
- break;
- case FCM_GENERATOR_FN_SINC: /* normalised sine wave */
- fn= sinc;
- break;
-
- /* validation required */
- case FCM_GENERATOR_FN_TAN: /* tangent wave */
- {
- /* check that argument is not on one of the discontinuities (i.e. 90deg, 270 deg, etc) */
- if IS_EQ(fmod((arg - M_PI_2), M_PI), 0.0) {
- if ((data->flag & FCM_GENERATOR_ADDITIVE) == 0)
- *cvalue = 0.0f; /* no value possible here */
- }
- else
- fn= tan;
- }
- break;
- case FCM_GENERATOR_FN_LN: /* natural log */
- {
- /* check that value is greater than 1? */
- if (arg > 1.0f) {
- fn= log;
- }
- else {
- if ((data->flag & FCM_GENERATOR_ADDITIVE) == 0)
- *cvalue = 0.0f; /* no value possible here */
- }
- }
- break;
- case FCM_GENERATOR_FN_SQRT: /* square root */
- {
- /* no negative numbers */
- if (arg > 0.0f) {
- fn= sqrt;
- }
- else {
- if ((data->flag & FCM_GENERATOR_ADDITIVE) == 0)
- *cvalue = 0.0f; /* no value possible here */
- }
- }
- break;
-
- default:
- printf("Invalid Function-Generator for F-Modifier - %d \n", data->func_type);
- }
-
- /* execute function callback to set value if appropriate */
- if (fn) {
- float value= (float)(data->coefficients[0]*fn(arg) + data->coefficients[3]);
-
- if (data->flag & FCM_GENERATOR_ADDITIVE)
- *cvalue += value;
- else
- *cvalue= value;
- }
- }
- break;
-
-#ifndef DISABLE_PYTHON
- case FCM_GENERATOR_EXPRESSION: /* py-expression */
- // TODO...
- break;
-#endif /* DISABLE_PYTHON */
}
}
@@ -1607,6 +1488,128 @@ static FModifierTypeInfo FMI_GENERATOR = {
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)
+{
+ if (fabs(x) < 0.0001)
+ return 1.0;
+ else
+ return sin(M_PI * x) / (M_PI * x);
+}
+
+static void fcm_fn_generator_evaluate (FCurve *fcu, FModifier *fcm, float *cvalue, float evaltime)
+{
+ FMod_FunctionGenerator *data= (FMod_FunctionGenerator *)fcm->data;
+ double arg= data->phase_multiplier*evaltime + data->phase_offset;
+ double (*fn)(double v) = NULL;
+
+ /* get function pointer to the func to use:
+ * WARNING: must perform special argument validation hereto guard against crashes
+ */
+ switch (data->type)
+ {
+ /* simple ones */
+ case FCM_GENERATOR_FN_SIN: /* sine wave */
+ fn= sin;
+ break;
+ case FCM_GENERATOR_FN_COS: /* cosine wave */
+ fn= cos;
+ break;
+ case FCM_GENERATOR_FN_SINC: /* normalised sine wave */
+ fn= sinc;
+ break;
+
+ /* validation required */
+ case FCM_GENERATOR_FN_TAN: /* tangent wave */
+ {
+ /* check that argument is not on one of the discontinuities (i.e. 90deg, 270 deg, etc) */
+ if IS_EQ(fmod((arg - M_PI_2), M_PI), 0.0) {
+ if ((data->flag & FCM_GENERATOR_ADDITIVE) == 0)
+ *cvalue = 0.0f; /* no value possible here */
+ }
+ else
+ fn= tan;
+ }
+ break;
+ case FCM_GENERATOR_FN_LN: /* natural log */
+ {
+ /* check that value is greater than 1? */
+ if (arg > 1.0f) {
+ fn= log;
+ }
+ else {
+ if ((data->flag & FCM_GENERATOR_ADDITIVE) == 0)
+ *cvalue = 0.0f; /* no value possible here */
+ }
+ }
+ break;
+ case FCM_GENERATOR_FN_SQRT: /* square root */
+ {
+ /* no negative numbers */
+ if (arg > 0.0f) {
+ fn= sqrt;
+ }
+ else {
+ if ((data->flag & FCM_GENERATOR_ADDITIVE) == 0)
+ *cvalue = 0.0f; /* no value possible here */
+ }
+ }
+ break;
+
+ default:
+ printf("Invalid Function-Generator for F-Modifier - %d \n", data->type);
+ }
+
+ /* execute function callback to set value if appropriate */
+ if (fn) {
+ float value= (float)(data->amplitude*fn(arg) + data->value_offset);
+
+ if (data->flag & FCM_GENERATOR_ADDITIVE)
+ *cvalue += value;
+ else
+ *cvalue= value;
+ }
+}
+
+static FModifierTypeInfo FMI_FN_GENERATOR = {
+ FMODIFIER_TYPE_FN_GENERATOR, /* type */
+ sizeof(FMod_FunctionGenerator), /* size */
+ FMI_TYPE_GENERATE_CURVE, /* action type */
+ FMI_REQUIRES_NOTHING, /* requirements */
+ "Built-In Function", /* name */
+ "FMod_FunctionGenerator", /* struct name */
+ NULL, /* free data */
+ NULL, /* copy data */
+ fcm_fn_generator_new_data, /* new data */
+ NULL, /* verify */
+ NULL, /* evaluate time */
+ fcm_fn_generator_evaluate /* evaluate */
+};
+
/* Envelope F-Curve Modifier --------------------------- */
static void fcm_envelope_free (FModifier *fcm)
@@ -2081,12 +2084,13 @@ static void fmods_init_typeinfo ()
{
fmodifiersTypeInfo[0]= NULL; /* 'Null' F-Curve Modifier */
fmodifiersTypeInfo[1]= &FMI_GENERATOR; /* Generator F-Curve Modifier */
- fmodifiersTypeInfo[2]= &FMI_ENVELOPE; /* Envelope F-Curve Modifier */
- fmodifiersTypeInfo[3]= &FMI_CYCLES; /* Cycles F-Curve Modifier */
- fmodifiersTypeInfo[4]= &FMI_NOISE; /* Apply-Noise F-Curve Modifier */
- fmodifiersTypeInfo[5]= NULL/*&FMI_FILTER*/; /* Filter F-Curve Modifier */ // XXX unimplemented
- fmodifiersTypeInfo[6]= &FMI_PYTHON; /* Custom Python F-Curve Modifier */
- fmodifiersTypeInfo[7]= &FMI_LIMITS; /* Limits F-Curve Modifier */
+ fmodifiersTypeInfo[2]= &FMI_FN_GENERATOR; /* Built-In Function Generator F-Curve Modifier */
+ fmodifiersTypeInfo[3]= &FMI_ENVELOPE; /* Envelope F-Curve Modifier */
+ fmodifiersTypeInfo[4]= &FMI_CYCLES; /* Cycles F-Curve Modifier */
+ fmodifiersTypeInfo[5]= &FMI_NOISE; /* Apply-Noise F-Curve Modifier */
+ 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 */
}
/* This function should be used for getting the appropriate type-info when only