Revision: 20027 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20027 Author: broken Date: 2009-05-02 06:20:36 +0200 (Sat, 02 May 2009)
Log Message: ----------- * 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 Modified Paths: -------------- branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c branches/blender2.5/blender/source/blender/editors/space_graph/graph_buttons.c branches/blender2.5/blender/source/blender/makesdna/DNA_anim_types.h branches/blender2.5/blender/source/blender/makesrna/intern/rna_fcurve.c Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c =================================================================== --- branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c 2009-05-02 03:09:40 UTC (rev 20026) +++ branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c 2009-05-02 04:20:36 UTC (rev 20027) @@ -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 @@ /* 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 @@ NULL /*fcm_noise_verify*/, /* verify */ fcm_noise_evaluate /* evaluate */ }; -#endif // XXX not yet implemented /* Filter F-Curve Modifier --------------------------- */ @@ -1961,7 +1996,7 @@ 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 */ Modified: branches/blender2.5/blender/source/blender/editors/space_graph/graph_buttons.c =================================================================== --- branches/blender2.5/blender/source/blender/editors/space_graph/graph_buttons.c 2009-05-02 03:09:40 UTC (rev 20026) +++ branches/blender2.5/blender/source/blender/editors/space_graph/graph_buttons.c 2009-05-02 04:20:36 UTC (rev 20027) @@ -460,7 +460,7 @@ /* closing bracket and '+' sign */ if ( (i != (data->poly_order - 1)) || ((i==0) && data->poly_order==2) ) - uiDefBut(block, LABEL, 1, ") \xD7", 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 @@ /* --------------- */ +/* 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 @@ 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... Modified: branches/blender2.5/blender/source/blender/makesdna/DNA_anim_types.h =================================================================== --- branches/blender2.5/blender/source/blender/makesdna/DNA_anim_types.h 2009-05-02 03:09:40 UTC (rev 20026) +++ branches/blender2.5/blender/source/blender/makesdna/DNA_anim_types.h 2009-05-02 04:20:36 UTC (rev 20027) @@ -166,6 +166,26 @@ 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 Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_fcurve.c =================================================================== --- branches/blender2.5/blender/source/blender/makesrna/intern/rna_fcurve.c 2009-05-02 03:09:40 UTC (rev 20026) +++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_fcurve.c 2009-05-02 04:20:36 UTC (rev 20027) @@ -118,8 +118,8 @@ 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_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 @@ rna_def_fmodifier_cycles(brna); rna_def_fmodifier_python(brna); rna_def_fmodifier_limits(brna); + rna_def_fmodifier_noise(brna); } _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs