Rules
Rules create a simple, customized editing interface in the Modeler. Rules can simplify and speed up your modeling process or make it easy for others to manipulate the model.
You write Rules using the Lua scripting language. Once you write a Rule, you can apply it to your model and edit it in the Rules window.
Write Rules based on any existing properties in the Property Bar. Properties that you adjust often or that you always adjust in sequence are great candidates for Rules.
To access the Rules window, select Window > Rules.
Write a Rule
Rules are based on Lua scripting syntax. Each Rule needs at least two lines of script:
- One line that defines the Rule slider.
- One line that uses the value of the Rule to edit the model.
This example shows the script and slider for a Rule called Height. When you adjust the slider, the spine of the Trunk generator gets longer or shorter based on the absolute height of its parent.
The first line defines the Rule slider as follows:
- Category name (Shape)
- Slider name (Height)
- Current value (1.0)
- Minimum value (0.0)
- Maximum value (2.0)
The second line uses the value from the Rule (stored in the Lua variable named Height) to change one of the properties that controls the length of the branch generator named Trunk in the model.
Once you've written a Rule, click outside the Rules window to load the slider.
Use a Rule to edit your model
You can use a Rule to edit your model. To use a Rule to edit your model:
Open the Property Bar and find the property you want to edit. Make sure you have the correct generator selected.
Right-click on the property name and select Copy edit line for script.
Paste that information into the Rules scripting window.
Update the
VALUE
variable to match a Rule.Click outside the Rules window and use the slider to edit your model.
Note
Use SpeedTree's search syntax to set what generators to modify in a Rule.
Best practices for Rules
- Add Rules once you’re comfortable with the SpeedTree properties and how they impact your model and each other.
- Rules work best when most parts of the model are created using relative properties. For example, when lengths are based on a percent of the parent's length instead of an absolute value.
- Don't set any property value more than once in a script. Use a Lua variable to store the results of complex calculations and then set the property once with that variable.
- If you write two rules that impact the same property, the last rule executed wins.