TerrainBrush
Package: Libraries.Game.Graphics.Worlds · Inherits from: Libraries.Language.Object
A TerrainBrush holds the settings for changing a terrain by hand: which tool and operation to use (see TerrainTool), how big the brush is, how strong it is, and how its effect fades from the center to the edge. A TerrainStroke uses a brush to change a TerrainData, one press of the mouse or key at a time. The settings: - **Size:** the brush's radius, in world units. - **Strength:** how fast the brush works. For raising and lowering, it is how many world units per second the center moves. For everything else (smoothing, flattening, ramps and painting) it is a rate: in one second at strength 1, the center moves about 63% of the way to its goal, and in a quarter second about 22%. Either way, a stroke does the same thing at any frame rate. - **Falloff:** how the effect fades out. By default it fades smoothly from full at the center to nothing at the edge. Gamma changes how sharp that is: more than 1 keeps the effect closer to the center, less than 1 spreads it out toward the edge. - **Shape:** optionally, a square of numbers from 0 to 1, such as one made from a gray image, used in place of the round falloff. It can be turned with SetRotation. - **Slope range:** optionally, only ground between two steepnesses is changed, such as painting rock only on slopes. - **Target height:** the height flattening moves toward. With SetFlattenToStart, the stroke uses the ground's height where it starts. - **Layer:** the ground texture painting adds: 0 red, 1 green, 2 blue, 3 alpha. - **Gradient:** for ramps, the two points and their heights. These follow Terrain3D's brush settings.
Example Code
use Libraries.Game.Graphics.Worlds.TerrainBrush
use Libraries.Game.Graphics.Worlds.TerrainTool
TerrainTool tools
TerrainBrush brush
brush:SetTool(tools:SCULPT, tools:ADD)
brush:SetSize(8)
brush:SetStrength(2)
output brush:GetDescription()
Actions
ClearShape()
This action takes away the brush's shape, so it uses its round fade again.
ClearSlopeRange()
This action lets the brush change ground of any steepness again.
FlattensToStart()
This action returns true if flattening uses the height where each stroke starts.
Returns
boolean: True if flattening uses the starting height.
GetDescription()
This action returns a sentence describing the brush's main settings, for showing or speaking, such as "raise, size 8, strength 2".
Returns
text: The description.
GetGamma()
This action returns how sharply the brush's effect fades.
Returns
number: The gamma.
GetGradientHeight(number worldX, number worldZ)
This action returns the ramp's height at a world position: the height at the nearest point along the line from the ramp's start to its end.
Parameters
worldXnumber: A position along x, in world units.worldZnumber: A position along z, in world units.
Returns
number: The ramp's height there.
GetLayer()
This action returns which ground texture painting adds.
Returns
integer: 0 for red, 1 green, 2 blue, 3 alpha.
GetName()
This action returns a short name for what the brush does, such as "raise" or "paint".
Returns
text: The name.
GetOperation()
This action returns the brush's operation.
Returns
integer: The operation, from TerrainTool.
GetRotation()
This action returns how far the brush's shape is turned.
Returns
number: The angle in degrees.
GetSize()
This action returns the brush's radius.
Returns
number: The radius in world units.
GetSpacing()
This action returns how far apart, in world units, a stroke applies the brush when it moves a long way at once: a quarter of the brush's size, so fast strokes leave no gaps.
Returns
number: The spacing.
GetStrength()
This action returns how fast the brush works.
Returns
number: The strength.
GetTargetHeight()
This action returns the height flattening moves toward.
Returns
number: The height in world units.
GetTool()
This action returns the brush's tool.
Returns
integer: The tool, from TerrainTool.
GetWeight(number offsetX, number offsetZ)
This action returns how strongly the brush acts at an offset from its center, from 1 (full) to 0 (none). With no shape, it is a smooth fade from the center to the edge of the circle. With a shape, it is the shape's value there, across the square around the circle. Either way, gamma is applied.
Parameters
offsetXnumber: The offset from the brush's center along x, in world units.offsetZnumber: The offset from the brush's center along z, in world units.
Returns
number: The weight, from 0 to 1.
HasGradient()
This action returns true if the brush has a ramp set.
Returns
boolean: True if SetGradient has been called.
HasShape()
This action returns true if the brush has a shape.
Returns
boolean: True if a shape is used in place of the round fade.
IsSlopeAllowed(number degrees)
This action returns true if a steepness is inside the brush's slope range, or if the brush has no slope range.
Parameters
degreesnumber: A steepness, in degrees from flat.
Returns
boolean: True if the brush may change ground this steep.
SetFlattenToStart(boolean toStart)
This action sets whether flattening uses the ground's height where each stroke starts, instead of the target height. The stroke sets the target height when it starts.
Parameters
toStartboolean: True to flatten to the height where the stroke starts.
SetGamma(number gamma)
This action sets how sharply the brush's effect fades from its center. 1 is the plain smooth fade; more than 1 keeps the effect nearer the center, and less than 1 spreads it toward the edge.
Parameters
gammanumber: The power the fade is raised to. It must be more than 0.
SetGradient(number startX, number startZ, number startHeight, number endX, number endZ, number endHeight)
This action sets the ramp a GRADIENT brush pulls the ground toward: a straight slope from one point and height to another. Past either end, the ramp stays at that end's height.
Parameters
startXnumber: Where the ramp starts along x, in world units.startZnumber: Where the ramp starts along z, in world units.startHeightnumber: The ramp's height at its start.endXnumber: Where the ramp ends along x, in world units.endZnumber: Where the ramp ends along z, in world units.endHeightnumber: The ramp's height at its end.
SetLayer(integer channel)
This action sets which ground texture painting adds.
Parameters
channelinteger: 0 for red, 1 green, 2 blue, 3 alpha.
SetRotation(number degrees)
This action sets how far the brush's shape is turned, in degrees around the vertical axis. It has no effect on the round fade.
Parameters
degreesnumber: The angle in degrees.
SetShape(Libraries.Containers.Number32BitArray values, integer width)
This action gives the brush a shape in place of its round fade: a square of numbers from 0 to 1, one row after another, covering the square around the brush from one edge to the other. The numbers are copied, so changing the array afterward doesn't change the brush.
Parameters
valuesLibraries.Containers.Number32BitArray: The shape, width times width numbers.widthinteger: How many numbers along each side. It must be at least 2.
SetShapeFromImage(Libraries.Game.Graphics.PixelMap map)
This action gives the brush a shape from a square gray image: white is full strength and black is none. Only the red part of each pixel is read. Like PixelMap itself, this needs a running game.
Parameters
mapLibraries.Game.Graphics.PixelMap: The image. It must be square, and at least 2 by 2.
SetSize(number radius)
This action sets the brush's radius.
Parameters
radiusnumber: The radius in world units. It must be more than 0.
SetSlopeRange(number lowest, number highest)
This action limits the brush to ground with a steepness in a range, in degrees from flat.
Parameters
lowestnumber: The least steep ground the brush changes, in degrees.highestnumber: The steepest ground the brush changes, in degrees.
SetStrength(number strength)
This action sets how fast the brush works (see the class description).
Parameters
strengthnumber: The strength. It can't be less than 0.
SetTargetHeight(number height)
This action sets the height flattening moves toward.
Parameters
heightnumber: The height in world units.
SetTool(integer tool, integer operation)
This action sets the brush's tool and operation, such as SCULPT and ADD for raising the ground. The pair must make sense together (see TerrainTool's IsValid).
Parameters
toolinteger: The tool, from TerrainTool.operationinteger: The operation, from TerrainTool.
UsesSlopeRange()
This action returns true if the brush only changes ground in a range of steepness.
Returns
boolean: True if there is a slope range.