Vary geometry size and shape using an expression

You can use expressions to drive randomization of the geometry's size, shape, and orientation. This way, you can instance the same geometry multiple times, but have each instance appear differently in the scene.

A simple way to add variation to instanced geometry is to use a randomization expression.

To add randomization to the Twist attribute

  1. In the Primitive Attributes section, click this icon beside Twist.
  2. In the XGen Expression Editor, type the following expression: rand(0,360).

  3. Click Accept.

    Each tree now has its own unique Twist value.

Generate variation using a Collection expression

Another way to generate randomization is to create a Collection expression. This type of expression can be applied to different primitive attribute values for all the Descriptions in the Collection.

In this example, you use a Collection expression to create a custom XGen attribute with a slider control. Using the slider control, you can generate randomized values which you can apply to attributes such as Length, Width, Depth, and Twist.

  1. In the XGen window, click the Expressions tab.
  2. Beside Name, type a name for the custom expression such as randomizer.

    Leave this expression set to Float as it uses float values.

  3. Click the icon to create the attribute.
  4. Click the icon beside the attribute.
  5. In the XGen Expression Editor type:

    $a=;

    This creates a slider control for the attribute.

  6. Type the following expression on the next line:

    $a*rand(0.1, 3.0).

  7. Click Accept.

    In the expression, the slider value is multiplied by a randomization function. You can now set primitive attributes to use the randomized values generated by the expression.

  8. Click the Primitives tab, and click the icon beside Length.
  9. Clear what appears in the XGen Expression Editor, and type the custom attribute name followed by (); for example, randomizer(). Click Accept.

    The values assigned to Length is now randomly generated based on the custom attribute slider setting.

  10. Repeat the step above for Width, Depth, and Twist.
  11. Click the Expressions tab, and then use the custom attribute slider to generate an appropriate value.

    You can also use the randomizer() expression to vary the size and orientation of the grass clumps in the scene.

Render the scene using your desired renderer. See Shading and Rendering XGen Primitives.