19. September 2023

Iterations for Geometry Generation

This example uses a basic iteration to create a circle from a given number (Count) of points with a certain Radius.

The setup utilizes several concepts that are very commonly used within Scene Nodes.

The Loop starts out with a basic Range iterator, which resembles the command with the same name in Python. It iterates from 0 to the given Count-1. By using a Range Mapper node this is turned into values between 0 and PI*2, though PI*2 is never reached because we are using Count as the end of the input range, not Count-1. This is necessary since on a circle the angles represented by PI*2 and 0 are the same and we do not want overlapping spline points.

The Angle values that come from the Range Mapper are then used to transform a positional vector. For this a Transform Vector node is used. If you are interested please read up on matrix transformations, but to use it in this kind of context it is enough to know that the point defined by the positional vector is moved according to the matrix, in this case it is rotated.

Since this is an iteration this happens Count times with changing values, giving us a series of positions in a circular distribution.

To end the iteration these values are now collected using an Assemble Collection node. The type of the node is Array<Vector>, which means that for every iteration step a new element is appended to an indexed list of vectors. The value of the element is the position that was calculated. The assembly if the array is controlled via the …} scope connection. This makes sure the Assemble Collection node collects the correct values. It might be obvious in this small setup, but in bigger setups this can be a lot more difficult since different to source code nodes don’t have any kind of indention or similar to indicate the nesting of iterations.

To finalize the Spline using the Assemble Spline node the information how many segments the spline will consist of is needed. This is equal to the number of iterations and by using the Fill Array node it is easy to create an array<Integer> with a single element of the value Count.

Example-Iteration-for-Spline-Creation.c4d