Create a Rule to combine properties
Compose a Rule to manipulate two properties of your model at the same time: a slider that combines the trunk height and radius of an existing tree model.
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
From the menu, select Window > Rules.
In the script editor of the Rules window, compose the following statement:
GrowthValue = rule("Growth", 0.5, 0.0, 1.0)
- 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
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 theTrunkHeight
variable value linearly change between20
and80
when you move the slider between between0
and1
.Select the Trunk generator of the tree.
In the Property Bar, select the Spine tab.
Under Spine > Length, right-click on the Absolute property and select Copy edit line for script.
Under the local variable statement in the Rule editor, paste the copied information.
Update the
VALUE
parameter of theset_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
- 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
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 theTrunkRadius
variable value linearly change between0.2
and1.2
when you move the slider between between0
and1
.Select the Trunk generator of the tree.
In the Property Bar, select the Skin tab.
Under Skin > Radius, right-click on the Absolute property and select Copy edit line for script.
Under the first
set_property_value
statement in the Rule editor, paste the copied information.Update the
VALUE
parameter of the newset_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.