1
$\begingroup$

I’m using animation nodes to randomize texture coordinates when the frame changes. Its working well, but I’d like to have it only update every nth frame, like not change for 15 frames or so. I’ve tried using ‘min time difference’ but that doesn’t seem to have an effect.

I’ve got the node tree set to Auto execution, and ‘frame changed’ is also checked (always, tree, and property are off) the min time diff is set to .5 which seems to be .5 seconds. I would think this would make it update only every 15 frames (at 30 fps) however the texture is updating every frame… how can I delay the change?

enter image description here

I know this can't work as shown, but here is what I've got. The viewer on math node show the frame it should wait for: 20. but I'm not sure how to get that to happen. once it gets to 20 it should pick another random frame by adding the the current time with the random number output, and so on.

$\endgroup$
  • $\begingroup$ hmm. thought there was a response here. The thing I’m stumped on is how to get the node tree to only update on the next randomly chosen frame number. I’m using the repeat time, random number, and time info nodes, which updates the texture every frame. Any idea how store a number added to the current frame (to get the next update frame) and have it wait to do the transform on that frame? $\endgroup$ – fjg3d Jun 18 '18 at 18:23
  • $\begingroup$ In Animation Nodes, you can't execute a node tree if a certain condition is satisfied (Unless you use a script). However, there are methods to achieve what you want, we just need to see your current node tree in order to help. $\endgroup$ – Omar Emara Jun 18 '18 at 19:22
  • $\begingroup$ Ok updated with pic. $\endgroup$ – fjg3d Jun 18 '18 at 20:01
5
$\begingroup$

You don't need conditional executions to achieve this effect, what you need is a constant seed for every nth interval. For instance, if I floor divide the time by 10, the result will be zero for the first 10 frames, 1 for the next 10 frames, 2 for the next 10 frames and so on. If I used the result of the floor division as seed, the random offset will be constants for every 10 frames.

Example

If you want the length of the intervals to be random, we may use an approach as follows. We will initialize a variable with some integer--say zero, at each execution, we will replace that variable by another random integer if some boolean is true, that boolean has some probability $P$ of being true. The value of the variable is then constant for some interval that depends on $P$ and changes if the boolean is true. The implementation may be as follow:

Random Interval

AN.seed if hasattr(AN, "seed") else 0

The above expression checks if AN has a variable called seed, if it has, it returns its value, if not, it restuns zero.

AN.seed = (new if y else original)

This expression sets the variable to the frame number if the boolean y is true. The boolean is true if the value of a random variable $\in [0,1]$ of a uniform distribution is less than 0.1 (meaning the probability of being true is equal to 0.1). The probable length of the intervals is inversely proportional to the probability $P$.

Now all you have to do is to use the value of that variable as seed for the random generator and everything should work as you expect it to.

$\endgroup$
  • $\begingroup$ Thanks! this is very helpful. Is it possible to make the interval random as well? like between a range of 2-15 frames as opposed to every 10? so the first interval might be 6, and the next might be 14? $\endgroup$ – fjg3d Jun 18 '18 at 20:59
  • $\begingroup$ @fjg3d Edited the answer. $\endgroup$ – Omar Emara Jun 19 '18 at 11:50
  • $\begingroup$ Cool! This works great.Thanks for taking time to set this up. $\endgroup$ – fjg3d Jun 20 '18 at 0:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.