playMaker

Author Topic: "Noise" Action[SOLVED]  (Read 8673 times)

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
"Noise" Action[SOLVED]
« on: April 03, 2011, 04:49:45 AM »
In 3dsmax, the 3D package I use in my work, there's a great controller called a "noise float". Basically what I would want is to be able to control a value over time in an interpolated random fashion similar to the screen-shot I posted below. If this could be implemented as a float and maybe int (though I guess you could use convert the float to int if you needed to) that would be a bonus.
« Last Edit: January 15, 2018, 02:30:52 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: "Noise" Action
« Reply #1 on: April 05, 2011, 01:52:28 AM »
Hi,

 Ok, I have put together a simple PerlinNoise action that should get you started. It doesn't have all the fanciness of the max noise generator, tho. I have some code that lerp the noise for some similar ramp in and out effect, but that would complicate this action unnecessarily for now.  It outputs a float ranging from 0 to 1. You can then do whatever you want with it and convert it to int or multiply it etc etc.

 Hope you find it useful :)

 Bye,

 Jean



Code: [Select]
/// <summary>
///
/// Jean Fabre April 2011
/// http://www.fabrejean.net
///
/// More infos on the playmaker api for actions: https://hutonggames.fogbugz.com/default.asp?W351
///
/// This action uses PerlinNoise generator with a random seed on the x axis and an animated value on the y axis.
///
/// </summary>
using UnityEngine;


namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Effects)]
[Tooltip("PerlinNoise action")]
public class PerlinNoise : FsmStateAction {

[RequiredField]
[Tooltip("PerlinNoise animation speed")]
public FsmFloat speed;

[RequiredField]
[Tooltip("the actual PerlinNoise result ranging from 0 to 1")]
[UIHint(UIHint.Variable)]
public FsmFloat perlinNoise;

[Tooltip("If set to false, will not animate over time")]
public bool everyFrame;

/// <summary>
/// randomness for the perlinnoise.
/// </summary>
private float _seed;

/// <summary>
/// Reset all values
/// </summary>
public override void Reset()
{

_seed = Random.Range(0f, 65535f);
speed = new FsmFloat();
speed.Value = 1f;
perlinNoise= null;
everyFrame = true;

}// Reset

/// <summary>
/// Compute the perlinNoise and finish the action if only supposed to run once.
/// <see cref="everyFrame"/>
/// </summary>
public override void OnEnter()
{

ComputePerlinNoise();

if (!everyFrame)
Finish();

}// OnEnter


/// <summary>
/// If the action is suppose to run every frame, we compute the noise here
/// <see cref="everyFrame"/>
/// </summary>
public override void OnUpdate()
{

ComputePerlinNoise();

}// OnUpdate


/// <summary>
/// Compute and store the current perlin noise.
/// </summary>
private void ComputePerlinNoise(){

perlinNoise.Value = Mathf.PerlinNoise(_seed, speed.Value*Time.time);

}// ComputePerlinNoise

}// PerlinNoise
}// namespace HutongGames.PlayMaker.Actions
« Last Edit: June 25, 2013, 01:53:39 AM by jeanfabre »

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
Re: "Noise" Action
« Reply #2 on: April 05, 2011, 02:07:34 AM »
Thank you very much, this will come very handy! That was very nice of you.

Don't let this make me sound ungrateful, but if maybe the developer would want to take it a step further and integrate all the functionality of the max controller that would be even more amazing.

Again, thank you and I hope karma pays you back (or if you are a starving student or something I'll paypal you a donation!). I am sure for now I can fade it in and out using other actions. Going to go play with this now.

indeed

  • Junior Playmaker
  • **
  • Posts: 85
Re: "Noise" Action
« Reply #3 on: January 04, 2018, 05:04:48 PM »
Hey Jean, would it be possible to modify this action so that the random seed can be changed? I often want to use multiple noise functions within the same action, but this seems to generate the same seed for all instances.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: "Noise" Action
« Reply #4 on: January 05, 2018, 05:20:05 AM »
I don't think the action works anymore :/
Available for Playmaker work

indeed

  • Junior Playmaker
  • **
  • Posts: 85
Re: "Noise" Action
« Reply #5 on: January 06, 2018, 01:41:14 PM »
Oh, the noise action, "Perlin Noise" on the ecosystem, works fine for me. I'd just like to be able to change the random seed.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: "Noise" Action
« Reply #6 on: January 09, 2018, 06:05:16 AM »
Hi,

 Done, please redownload, now the seeding is exposed. Let me know if this is ok for you.

 Bye,

 Jean

indeed

  • Junior Playmaker
  • **
  • Posts: 85
Re: "Noise" Action
« Reply #7 on: January 12, 2018, 05:09:33 PM »
This is great, thank you!!!