Randomizing things in Strata 3D: The y-axis Position

Uniformity is not always good in 3D. Many times the mathematical precision of replicating objects detracts from the natural look and lends a plastic, artificial look.

One of the unknown gems in Strata 3D is the possibility to add scripting. In this tutorial we’ll add a very simple Lua script that randomizes the offset of an object in the y-axis by a random number between two values.

To begin, let us create a 1x1x1 in. cube and convert it into a shape.

Let us make 19 copies of an instance of the cube with a horizontal offset of 2 inches.

Now let us replicate these 20 cubes 19 more times, with a -2 offset in the z-axis.

We now have 400 cubes, all sitting at the same height. Using a simple Lua script, we will randomize their y-axis positions.

Double-click any cube to open the shape, and select the cube.

In the Project Window, we’ll see the Object Properties for the selected cube. We may have to expand the object by clicking on the small triangle to the left of the name in the Project Window.

Clicking on the “Equal sign button” next to the Position property brings up the Script Editor.

The Script Editor has three areas: Initialization, Script Source and Result.

The script we’ll use runs like this:

Initialization:

-- Select the axis we'll randomize the position of our objects on.
local alongAxis = s3d.vec.Point3d ( s3d.vec.y_axis )

-- Define the minimum and maximum height offset, in points (72 points per inch).
local minOffset = 36
local maxOffset = 360

Script source:

-- Put our existing keyframed position into a Point3d,

 

local existingPosition = s3d.vec.Point3d (position)
local offsetPosition = alongAxis : Clone () : Multiply (math.random(minOffset,maxOffset))

 

return existingPosition : Add (offsetPosition)

If everything is OK, when clicking the Test button we should get Lua:success in the Result area.

There are two variables in the script: minOffset and maxOffset that hold the minimum and maximum offset values. The position of our cubes wil lbe randomized between these two values.  Play with the values to see what happens.

The position of the cubes will be recalculated after anything we do, so expect things to jump around your screen while editing.

I hope you find this technique as useful as I have, and hopefully this will encourage you to play with the scripting possibilities in Strata 3D.

Try Design 3D & Envizia for just $1