Transforms: Repeater

A repeater can be used to copy any simple or complex shape at regular intervals. These are not physical, but virtual copies.

Syntax

You must specify the number of repetitions, and the vector difference between two consecutive copies:

Repetitions can be nested, to create duplicates in two and three dimensions, as this example shows:

    repeat(15, [0, 0, 2.2],
        repeat(15, [0, 2.2, 0],
            repeat(15, [2.2, 0, 0],
                sphere([-16,-16,-8], 0.2, goldenMetal))));

The loop operator

Using the Repeat class can be confusing: which parameter stands for the number of repetition, and which for the distance? You can use, instead, the loop operator:

    any-shape loop times by distance

The loop operator has the same precedence as move, spin and size: they evaluate after any other additive operator in a expression. Of course, you can also nest loops. If you must translate a script already written with Repeat, and find nested repetitions, the most sensible way to simplify the expression is starting with the outer instance, and then proceeding to the inner instances:

    repeat(15, [0, 2.2, 0],
        repeat(15, [2.2, 0, 0],
            sphere([-16,-16,-8], 0.2, goldenMetal)))
                loop 15 by 2.2^Z;

In the next step, we transform the repetition along the Y axis:

    repeat(15, [2.2, 0, 0],
        sphere([-16,-16,-8], 0.2, goldenMetal))
            loop 15 by 2.2^Z
            loop 15 by 2.2^Y;

Finally, we can remove the last instance of repeat:

    sphere([-16,-16,-8], 0.2, goldenMetal)
        loop 15 by 2.2^Z
        loop 15 by 2.2^Y
        loop 15 by 2.2^X;

This a common pattern: a repetition along the three axis of coordinates. Which is the preferred order? Assuming that the camera is orientated along the Z axis, it is recommended to move the repetitions along the X and Y axis to the outer level. That's because most hit tests will be caused by rays from the camera (primary rays), and XSight RT does a better job optimizing Repeat when the repetition is almost orthogonal to the direction of the ray being tested.

Implementation

Repetitions are implemented by transforming the visual ray and testing against the original shape. We use several techniques for avoid testing as many times as repetitions have been specified:

When the loop has three or less repetitions, the original shape is cloned the required number of times. The maximum number of repetitions is controled by the Loop threshold option in the XSight RT Options dialog box:

When repetitions are axis-aligned, the rectangular bounds are tight enough to make sense. The repeater can also use a virtual cylinder to bind their items.

This last optimization is more effective when the number of repetitions is large.

See also

Home | Small Instantiation Language overview | Scenes | Predefined shapes | Solid shapes | Transforms | CSG operations | Surfaces