Using arrays to avoid Repeat part II

Part I is here

Another building block for using arrays instead of Repeat loops: an array that looks like [0,0,0,0, 1,1,1,1, 2,2,2,2, …].

Again, the trick is to use this array as the indices for Select in Array.

Here’s how to build this kind of array:

Here’s a simple example. I get the positions of the objects in a group, and then use those positions to add points in a point cloud. Basically, I have a group of objects, and an array of vectors (the interpolated array). When I add a point, I take an object position and add a vector to it to get the point position.

In pseudo-code:

For each object in group
      for each vector in array
             Add Point
             Point Position = vector + object position 

If that ICE tree is hard to follow, then it may help to use some attributes to store intermediate values(arrays). That way you can separate out some branches of the tree:

3 thoughts on “Using arrays to avoid Repeat part II

  1. Thanks for the tutorial. I tried to use this way to loop for my own purposes, trying to avoid the repeat node. But I failed to find a way to alter a variable which needs to change every iteration.

    While the counter in the repeat node gets increased every time the repeat gets executed, I pass a value to a global variable. THe next time my loop gets calculated all calculations depend on this variable.

    Is there a way to use your approach with my needs? So far it seems that this kind of loop needs a “fixed” execution, in which no variables can change.


    • Hi

      You would build another array that contains the pre-calculated values of your global variable.
      So, it depends on whether you can figure out a pattern for your global variable.

      What would your loop look like in scripting?

      • That’s the point. It can’t be pre-calculated. I use this loop to “grow” strands on a surface. I move the strand/point position “forward” (last position + movement vector), find the closest location on the mesh (as the position by itself might be inside or above the mesh) and then store this position inside a temporary strandPosition array AND use it as the starting position for the next forward movement. So the next iteration of the loop depends on the last result of its predecessor. It’s a dynamic process. Values can’t be stored in advance. So I wonder whether I NEED to go with repeat or if there is a faster and/or more elegant way to do this.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s