FoliageStroke
Package: Libraries.Interface.Controls.Scenes · Inherits from: Libraries.Language.Object
A FoliageStroke is one stroke of a terrain's Foliage tool in the scene editor: while it goes, each dab paints where one foliage asset grows, its coverage, under the brush, or lowers it. The copies are worked out from the coverage afterward (TerrainItem's RefreshFoliage), so the asset's settings, such as its density, can change later and the painted area follows. The stroke keeps each coverage it touched as it was before the stroke, and as it is after, so the whole stroke can be undone and redone as one step. A dab moves the coverage toward the brush's target: full near the middle, fading to nothing at the edge. The target is the brush's density scale, from 0 for none to 1 for the asset's full density, so a light brush paints sparse growth and a strong one thick growth. To keep a held brush from repeating the same dab, a new one is made only once the brush has moved half a radius from the last one.
Example Code
use Libraries.Interface.Controls.Scenes.FoliageStroke
use Libraries.Game.Graphics.Worlds.TerrainItem
TerrainItem ground
ground:Load("Scenes/Terrains/Terrain1/terrain.json")
FoliageStroke stroke
stroke:Begin(ground:GetTerrainFoliage(), ground:GetFoliageList(), 0, stroke:ADD_COPIES)
if stroke:Apply(10, 20, 5, 1)
ground:RefreshFoliage(10, 20, 5)
end
boolean changed = stroke:End()
Variables
integer REMOVE_ASSETinteger ADD_COPIES: lower every asset's.integer REMOVE_ALL
Actions
Apply(number x, number z, number radius, number densityScale)
Makes a dab at the brush, if it is the first or the brush has moved half a radius since the last one. Draw the foliage there again afterward if it returns true (TerrainItem's RefreshFoliage).
Parameters
xnumber: The brush's middle along x, in world unitsznumber: The brush's middle along z, in world unitsradiusnumber: The brush's radius, in world unitsdensityScalenumber: The coverage the brush paints toward, from 0 to 1; more is taken as 1
Returns
boolean: True if any coverage changed
Begin(Libraries.Game.Graphics.Worlds.TerrainFoliage terrainFoliage, Libraries.Game.Graphics.Worlds.FoliageList foliageList, integer assetNumber, integer strokeMode)
Starts a stroke.
Parameters
terrainFoliageLibraries.Game.Graphics.Worlds.TerrainFoliage: The terrain's foliagefoliageListLibraries.Game.Graphics.Worlds.FoliageList: The terrain's foliage listassetNumberinteger: The asset painted or lowered, by its number in the liststrokeModeinteger: ADD_COPIES, REMOVE_ASSET or REMOVE_ALL
End()
Ends the stroke, keeping each touched coverage as it is now, for redo, and counting the copies now, so the foliage must have been drawn again since the last dab.
Returns
boolean: True if the stroke changed any coverage
GetAddedCount()
Returns how many more copies there were after the stroke than before, or 0 if there were fewer.
Returns
integer: The count
GetAreaMiddleX()
Returns the middle of the area the stroke touched, along x.
Returns
number: The x, in world units
GetAreaMiddleZ()
Returns the middle of the area the stroke touched, along z.
Returns
number: The z, in world units
GetAreaRadius()
Returns how far the area the stroke touched reaches from its middle, at most.
Returns
number: The distance, in world units
GetAssetName()
Returns the name of the asset the stroke painted or lowered, or "foliage" when it lowered them all.
Returns
text: The name
GetMode()
Returns what the stroke does.
Returns
integer: ADD_COPIES, REMOVE_ASSET or REMOVE_ALL
GetRemovedCount()
Returns how many fewer copies there were after the stroke than before, or 0 if there were more.
Returns
integer: The count
IsGoing()
Returns true while the stroke is going.
Returns
boolean: True between Begin and End
Redo()
Puts every touched coverage as it was after the stroke again. Draw the foliage there again afterward.
Undo()
Puts every touched coverage back as it was before the stroke. Draw the foliage there again afterward.