← All ideas
  • Published 23 Jun 2020

Cyclic noise in the graph editor noise modifier.

It would be very handy if there was an option to make the noise in the fcurves noise modifier cyclic.

This way you can add some randomness to a cyclic animation without breaking the looping.

I hacked together a possible implementation myself (patch attached). What do people think? It's just a quick 'proof of concept' implementation without thinking it through to much, but it does the job for my looping animation.

patch for the current ( yesterdays) blender git master:

diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c
index c85283e3653..5e23a4cd479 100644
--- a/source/blender/blenkernel/intern/fmodifier.c
+++ b/source/blender/blenkernel/intern/fmodifier.c
@@ -821,11 +821,27 @@ static void fcm_noise_evaluate(
   FMod_Noise *data = (FMod_Noise *)fcm->data;
   float noise;

-  /* generate noise using good old Blender Noise
-   * - 0.1 is passed as the 'z' value, otherwise evaluation fails for size = phase = 1
-   *   with evaltime being an integer (which happens when evaluating on frame by frame basis)
-   */
-  noise = BLI_turbulence(data->size, evaltime - data->offset, data->phase, 0.1f, data->depth);
+  short cyclic = data->cyclic;
+
+  if (cyclic)
+  {
+    /* wrap around in a circle */
+    float alongcircle = evaltime - data->offset;
+
+    float angle = alongcircle * 2 * M_PI / cyclic;
+    float radius = cyclic * .5 * M_1_PI;
+
+    noise = BLI_turbulence(data->size, radius * cos(angle), radius*sin(angle), data->phase,  data->depth);
+  }
+  else
+  {
+   /* generate noise using good old Blender Noise
+    * - 0.1 is passed as the 'z' value, otherwise evaluation fails for size = phase = 1
+    *   with evaltime being an integer (which happens when evaluating on frame by frame basis)
+    */
+   noise = BLI_turbulence(data->size, evaltime - data->offset, data->phase, 0.1f, data->depth);
+  }
+

   /* combine the noise with existing motion data */
   switch (data->modification) {
diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c
index eadaa449b92..c80a694562a 100644
--- a/source/blender/editors/animation/fmodifier_ui.c
+++ b/source/blender/editors/animation/fmodifier_ui.c
@@ -562,6 +562,7 @@ static void draw_modifier__noise(uiLayout *layout,
   col = uiLayoutColumn(split, false);
   uiItemR(col, &ptr, "phase", 0, NULL, ICON_NONE);
   uiItemR(col, &ptr, "depth", 0, NULL, ICON_NONE);
+  uiItemR(col, &ptr, "cyclic", 0, NULL, ICON_NONE);
 }

 /* callback to add new envelope data point */
diff --git a/source/blender/makesdna/DNA_anim_types.h b/source/blender/makesdna/DNA_anim_types.h
index 6a024ec9e7e..15ed80ed2ad 100644
--- a/source/blender/makesdna/DNA_anim_types.h
+++ b/source/blender/makesdna/DNA_anim_types.h
@@ -260,6 +260,8 @@ typedef struct FMod_Noise {

   short depth;
   short modification;
+  short cyclic;
+  char _pad[2];
 } FMod_Noise;

 /* modification modes */
diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c
index e49186f4cb1..3b78780af55 100644
--- a/source/blender/makesrna/intern/rna_fcurve.c
+++ b/source/blender/makesrna/intern/rna_fcurve.c
@@ -1524,6 +1524,12 @@ static void rna_def_fmodifier_noise(BlenderRNA *brna)
   RNA_def_property_int_sdna(prop, NULL, "depth");
   RNA_def_property_ui_text(prop, "Depth", "Amount of fine level detail present in the noise");
   RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
+
+  prop = RNA_def_property(srna, "cyclic", PROP_INT, PROP_UNSIGNED);
+  RNA_def_property_int_sdna(prop, NULL, "cyclic");
+  RNA_def_property_ui_text(prop, "Cycle", "Repeat noise after number of frames (0 means infinite)");
+  RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
+
 }

 /* --------- */

cyclenoise.png

75%

Development Status: Open

Upvote 3 Downvote 1
Baardaap
23 Jun 2020

0 Comments