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:
authorMatt Ebb <matt@mke3.net>2009-05-02 08:20:36 +0400
committerMatt Ebb <matt@mke3.net>2009-05-02 08:20:36 +0400
commit4b025d68657c197b302516b96f69405aa957accf (patch)
tree1bfd149869f57c1caca4a022659ed016fe60b455
parent76cedc4b9abe5a50db03a1ccd1875213effae264 (diff)
* Added a new F-Curve modifier type: Noise
Thanks Aligorith for making such an easy to use system! http://mke3.net/blender/devel/2.5/fcurve_noise_modifier.mov
-rw-r--r--source/blender/blenkernel/intern/fcurve.c41
-rw-r--r--source/blender/editors/space_graph/graph_buttons.c36
-rw-r--r--source/blender/makesdna/DNA_anim_types.h20
-rw-r--r--source/blender/makesrna/intern/rna_fcurve.c46
4 files changed, 137 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index 5bfff141714..cb54d77f08e 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -19,6 +19,7 @@
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
+#include "BLI_noise.h"
#include "BKE_fcurve.h"
#include "BKE_curve.h"
@@ -1823,7 +1824,42 @@ static FModifierTypeInfo FMI_CYCLES = {
/* Noise F-Curve Modifier --------------------------- */
-#if 0 // XXX not yet implemented
+static void fcm_noise_new_data (void *mdata)
+{
+ FMod_Noise *data= (FMod_Noise *)mdata;
+
+ /* defaults */
+ data->size= 1.0f;
+ data->strength= 1.0f;
+ data->phase= 1.0f;
+ data->depth = 0;
+ data->modification = FCM_NOISE_MODIF_REPLACE;
+}
+
+static void fcm_noise_evaluate (FCurve *fcu, FModifier *fcm, float *cvalue, float evaltime)
+{
+ FMod_Noise *data= (FMod_Noise *)fcm->data;
+ float noise;
+
+ noise = BLI_turbulence(data->size, evaltime, data->phase, 0.f, data->depth);
+
+ switch (data->modification) {
+ case FCM_NOISE_MODIF_ADD:
+ *cvalue= *cvalue + noise * data->strength;
+ break;
+ case FCM_NOISE_MODIF_SUBTRACT:
+ *cvalue= *cvalue - noise * data->strength;
+ break;
+ case FCM_NOISE_MODIF_MULTIPLY:
+ *cvalue= *cvalue * noise * data->strength;
+ break;
+ case FCM_NOISE_MODIF_REPLACE:
+ default:
+ *cvalue= *cvalue + (noise - 0.5f) * data->strength;
+ break;
+ }
+}
+
static FModifierTypeInfo FMI_NOISE = {
FMODIFIER_TYPE_NOISE, /* type */
sizeof(FMod_Noise), /* size */
@@ -1837,7 +1873,6 @@ static FModifierTypeInfo FMI_NOISE = {
NULL /*fcm_noise_verify*/, /* verify */
fcm_noise_evaluate /* evaluate */
};
-#endif // XXX not yet implemented
/* Filter F-Curve Modifier --------------------------- */
@@ -1961,7 +1996,7 @@ static void fmods_init_typeinfo ()
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]= NULL/*&FMI_NOISE*/; /* Apply-Noise F-Curve Modifier */ // XXX unimplemented
+ 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 */
diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c
index 357079a2c3c..9c7c3c3e812 100644
--- a/source/blender/editors/space_graph/graph_buttons.c
+++ b/source/blender/editors/space_graph/graph_buttons.c
@@ -460,7 +460,7 @@ static void draw_modifier__generator(uiBlock *block, FCurve *fcu, FModifier *fcm
/* closing bracket and '+' sign */
if ( (i != (data->poly_order - 1)) || ((i==0) && data->poly_order==2) )
- uiDefBut(block, LABEL, 1, ") ×", 280, cy, 30, 20, NULL, 0.0, 0.0, 0, 0, "");
+ uiDefBut(block, LABEL, 1, ") â—Š", 280, cy, 30, 20, NULL, 0.0, 0.0, 0, 0, "");
else
uiDefBut(block, LABEL, 1, ")", 280, cy, 30, 20, NULL, 0.0, 0.0, 0, 0, "");
@@ -571,6 +571,36 @@ static void draw_modifier__cycles(uiBlock *block, FCurve *fcu, FModifier *fcm, i
/* --------------- */
+/* draw settings for noise modifier */
+static void draw_modifier__noise(uiBlock *block, FCurve *fcu, FModifier *fcm, int *yco, short *height, short width, short active, int rb_col)
+{
+ FMod_Noise *data= (FMod_Noise *)fcm->data;
+ int cy= (*yco - 30), cy1= (*yco - 50), cy2= (*yco - 70);
+ char cyc_mode[]="Modification %t|Replace %x0|Add %x1|Subtract %x2|Multiply %x3";
+
+ /* set the height */
+ (*height) = 80;
+
+ /* basic settings (backdrop + some padding) */
+ DRAW_BACKDROP((*height));
+
+ uiDefButS(block, MENU, B_FMODIFIER_REDRAW, cyc_mode,
+ 3, cy, 150, 20, &data->modification, 0, 0, 0, 0, "Method of modifying the existing F-Curve use before first keyframe");
+
+ uiDefButF(block, NUM, B_FMODIFIER_REDRAW, "Size:",
+ 3, cy1, 150, 20, &data->size, 0.000001, 10000.0, 0.01, 3, "");
+ uiDefButF(block, NUM, B_FMODIFIER_REDRAW, "Strength:",
+ 3, cy2, 150, 20, &data->strength, 0.0, 10000.0, 0.01, 3, "");
+
+ uiDefButF(block, NUM, B_FMODIFIER_REDRAW, "Phase:",
+ 155, cy1, 150, 20, &data->phase, 0.0, 100000.0, 0.1, 3, "");
+ uiDefButS(block, NUM, B_FMODIFIER_REDRAW, "Depth:",
+ 155, cy2, 150, 20, &data->depth, 0, 128, 1, 3, "");
+
+}
+
+/* --------------- */
+
#define BINARYSEARCH_FRAMEEQ_THRESH 0.0001
/* Binary search algorithm for finding where to insert Envelope Data Point.
@@ -880,6 +910,10 @@ static void graph_panel_modifier_draw(uiBlock *block, FCurve *fcu, FModifier *fc
draw_modifier__limits(block, fcu, fcm, yco, &height, width, active, rb_col);
break;
+ case FMODIFIER_TYPE_NOISE: /* Noise */
+ draw_modifier__noise(block, fcu, fcm, yco, &height, width, active, rb_col);
+ break;
+
default: /* unknown type */
height= 96;
//DRAW_BACKDROP(height); // XXX buggy...
diff --git a/source/blender/makesdna/DNA_anim_types.h b/source/blender/makesdna/DNA_anim_types.h
index d015d703309..7a2be3ff2a8 100644
--- a/source/blender/makesdna/DNA_anim_types.h
+++ b/source/blender/makesdna/DNA_anim_types.h
@@ -166,6 +166,26 @@ enum {
FCM_LIMIT_YMAX = (1<<3),
} eFMod_Limit_Flags;
+/* noise modifier data */
+typedef struct FMod_Noise {
+ float size;
+ float strength;
+ float phase;
+ float pad;
+
+ short depth;
+ short modification;
+
+} FMod_Noise;
+
+/* modification modes */
+enum {
+ FCM_NOISE_MODIF_REPLACE = 0, /* Modify existing curve, matching it's shape */
+ FCM_NOISE_MODIF_ADD, /* Add noise to the curve */
+ FCM_NOISE_MODIF_SUBTRACT, /* Subtract noise from the curve */
+ FCM_NOISE_MODIF_MULTIPLY, /* Multiply the curve by noise */
+} eFMod_Noise_Modifications;
+
/* Drivers -------------------------------------- */
/* Driver Target
diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c
index 23557b3aa31..2380d7e29e1 100644
--- a/source/blender/makesrna/intern/rna_fcurve.c
+++ b/source/blender/makesrna/intern/rna_fcurve.c
@@ -118,8 +118,8 @@ StructRNA *rna_FModifierType_refine(struct PointerRNA *ptr)
return &RNA_FModifierEnvelope;
case FMODIFIER_TYPE_CYCLES:
return &RNA_FModifierCycles;
- //case FMODIFIER_TYPE_NOISE:
- // return &RNA_FModifierNoise;
+ case FMODIFIER_TYPE_NOISE:
+ return &RNA_FModifierNoise;
//case FMODIFIER_TYPE_FILTER:
// return &RNA_FModifierFilter;
case FMODIFIER_TYPE_PYTHON:
@@ -410,6 +410,47 @@ static void rna_def_fmodifier_limits(BlenderRNA *brna)
/* --------- */
+static void rna_def_fmodifier_noise(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ static EnumPropertyItem prop_modification_items[] = {
+ {FCM_NOISE_MODIF_REPLACE, "REPLACE", "Replace", ""},
+ {FCM_NOISE_MODIF_ADD, "ADD", "Add", ""},
+ {FCM_NOISE_MODIF_SUBTRACT, "SUBTRACT", "Subtract", ""},
+ {FCM_NOISE_MODIF_MULTIPLY, "MULTIPLY", "Multiply", ""},
+ {0, NULL, NULL, NULL}};
+
+ srna= RNA_def_struct(brna, "FModifierNoise", "FModifier");
+ RNA_def_struct_ui_text(srna, "Noise F-Curve Modifier", "Gives randomness to the modified F-Curve.");
+ RNA_def_struct_sdna_from(srna, "FMod_Noise", "data");
+
+ prop= RNA_def_property(srna, "modification", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_items(prop, prop_modification_items);
+ RNA_def_property_ui_text(prop, "Modification", "Method of modifying the existing F-Curve.");
+
+ prop= RNA_def_property(srna, "size", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "size");
+ RNA_def_property_ui_text(prop, "Size", "Scaling (in time) of the noise");
+
+ prop= RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "strength");
+ RNA_def_property_ui_text(prop, "Strength", "Amplitude of the noise - the amount that it modifies the underlying curve");
+
+ prop= RNA_def_property(srna, "phase", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "phase");
+ RNA_def_property_ui_text(prop, "Phase", "A random seed for the noise effect");
+
+ prop= RNA_def_property(srna, "depth", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "depth");
+ RNA_def_property_ui_text(prop, "Depth", "Amount of fine level detail present in the noise");
+
+}
+
+
+/* --------- */
+
void rna_def_fmodifier(BlenderRNA *brna)
{
StructRNA *srna;
@@ -603,6 +644,7 @@ void RNA_def_fcurve(BlenderRNA *brna)
rna_def_fmodifier_cycles(brna);
rna_def_fmodifier_python(brna);
rna_def_fmodifier_limits(brna);
+ rna_def_fmodifier_noise(brna);
}