Documentation

SpeedTree Modeler

SpeedTree Modeler

Create a Rule to combine properties

Compose a Rule to manipulate two properties of your model at the same time, using a slider that combines the trunk height and radius of an existing tree model.
Read time 3 minutesLast updated 2 hours ago

This procedure builds a single slider that adjusts both the trunk height and radius of an existing tree model together, working up through the following sections.
Note
To get proper and meaningful results from this example Rule, you need to use a tree with a first level branch generator named "Trunk" that can afford a height value between 20 and 80 and a trunk radius value between 0.2 and 1.2. For example, use the Conifer available in the Samples provided with the Modeler.

Create a slider with a normalized range

  1. From the menu, select Window > Rules.
  2. In the script editor of the Rules window, compose the following statement:
    GrowthValue = rule("Growth", 0.5, 0.0, 1.0)
  3. Click anywhere outside the Rules window.
The UI section of the Rule window displays a slider named Growth in a section named Shape. The slider allows you to change the value of a variable named
GrowthValue
between
0
and
1
and the default value is
0.5
.

Make the slider proportionally control the trunk height

  1. Create and isolate a local
    TrunkHeight
    variable and interpolate its value in a suitable range according to the slider's range.
    GrowthValue = rule("Growth", 0.5, 0.0, 1.0)do local TrunkHeight = math.lerp(20, 80, GrowthValue)end
    In this example, the
    math.lerp
    function makes the
    TrunkHeight
    variable value linearly change between
    20
    and
    80
    when you move the slider between between
    0
    and
    1
    .
  2. Select the Trunk generator of the tree.
  3. In the Property Bar, select the Spine tab.
  4. Under Spine > Length, right-click on the Absolute property and select Copy edit line for script.
  5. Under the local variable statement in the Rule editor, paste the copied information.
  6. Update the
    VALUE
    parameter of the
    set_property_value
    function to match the Rule's variable name (
    TrunkHeight
    ):
    GrowthValue = rule("Growth", 0.5, 0.0, 1.0)do local TrunkHeight = math.lerp(20, 80, GrowthValue) set_property_value("=Trunk", "Spine:Length:Absolute", TrunkHeight)end
  7. Click anywhere outside the Rules window.
When you adjust the slider, the trunk of the tree gets longer or shorter.

Combine the trunk radius with the trunk height

  1. Create a local
    TrunkRadius
    variable and interpolate its value in a suitable range according to the slider's range.
    GrowthValue = rule("Growth", 0.5, 0.0, 1.0)do local TrunkHeight = math.lerp(20, 80, GrowthValue) local TrunkRadius = math.lerp(0.2, 1.2, GrowthValue) set_property_value("=Trunk", "Spine:Length:Absolute", TrunkHeight)end
    In this example, the
    math.lerp
    function makes the
    TrunkRadius
    variable value linearly change between
    0.2
    and
    1.2
    when you move the slider between between
    0
    and
    1
    .
  2. Select the Trunk generator of the tree.
  3. In the Property Bar, select the Skin tab.
  4. Under Skin > Radius, right-click on the Absolute property and select Copy edit line for script.
  5. Under the first
    set_property_value
    statement in the Rule editor, paste the copied information.
  6. Update the
    VALUE
    parameter of the new
    set_property_value
    function to match the Rule's variable name (
    TrunkRadius
    ):
    GrowthValue = rule("Growth", 0.5, 0.0, 1.0)do local TrunkHeight = math.lerp(20, 80, GrowthValue) local TrunkRadius = math.lerp(0.2, 1.2, GrowthValue) set_property_value("=Trunk", "Spine:Length:Absolute", TrunkHeight) set_property_value("=Trunk", "Skin:Radius:Absolute", TrunkRadius)end
When you adjust the slider, the trunk height and radius values get higher or lower at the same time.

Additional resources