FoliageCoverage
Package: Libraries.Game.Graphics.Worlds · Inherits from: Libraries.Language.Object
A FoliageCoverage holds where one foliage asset grows over one region of a terrain: a square grid of spots, each with a coverage from 0 (none) to 1 (the asset's full density). The Foliage brush paints coverage, and TerrainFoliage works out the copies from it, so the asset's settings, such as its density, can change after painting and the whole painted area follows. The grid starts at the region's corner. Spot (0, 0) is at the corner, and each spot is spacing world units from the next.
Example Code
use Libraries.Game.Graphics.Worlds.FoliageCoverage
FoliageCoverage coverage
coverage:Setup(0, 0, 0, 128, 2)
coverage:Set(10, 20, 0.5)
output coverage:Get(10, 20)
Actions
CopyValues()
This action returns a copy of every spot's coverage, row by row, such as to keep it for undo.
Returns
Libraries.Containers.Array<number>: The copy.
FromJson(Libraries.Data.Formats.JavaScriptObjectNotation json)
This action reads the values written by ToJson. If the grid's size differs from this coverage's, or the runs don't fill it, nothing is read and it returns false.
Parameters
jsonLibraries.Data.Formats.JavaScriptObjectNotation: The object.
Returns
boolean: True if the values were read.
Get(integer x, integer z)
This action returns the coverage at a spot, or 0 outside the grid.
Parameters
xinteger: The spot along x, from 0.zinteger: The spot along z, from 0.
Returns
number: The coverage, from 0 to 1.
GetAsset()
This action returns the asset's number in the foliage list.
Returns
integer: The number.
GetAt(number localX, number localZ)
This action returns the coverage at a place inside the region, blended from the four spots around it, so the edges of a painted area are soft. Places past the grid's last spots use the nearest spot.
Parameters
localXnumber: The place along x, in world units from the region's corner.localZnumber: The place along z, in world units from the region's corner.
Returns
number: The coverage, from 0 to 1.
GetLocationX()
This action returns the region's location along x.
Returns
integer: The location.
GetLocationZ()
This action returns the region's location along z.
Returns
integer: The location.
GetSpacing()
This action returns how far apart the spots are, in world units.
Returns
number: The spacing.
GetSpotCount()
This action returns how many spots there are along each side.
Returns
integer: The count.
HasAny()
This action returns true if any spot has coverage.
Returns
boolean: True if the asset grows anywhere in the region.
Set(integer x, integer z, number value)
This action sets the coverage at a spot, kept between 0 and 1. Spots outside the grid are ignored.
Parameters
xinteger: The spot along x, from 0.zinteger: The spot along z, from 0.valuenumber: The coverage, from 0 to 1.
SetAsset(integer assetNumber)
This action sets the asset's number, for when the foliage list's assets move.
Parameters
assetNumberinteger: The new number.
SetValues(Libraries.Containers.Array<number> copy)
This action sets every spot's coverage from a copy made by CopyValues. A copy of another size is ignored.
Parameters
copyLibraries.Containers.Array<number>: The copy.
Setup(integer assetNumber, integer x, integer z, integer spotCount, number spotSpacing)
This action sets which asset and region the coverage is for, and makes its grid, with no coverage anywhere.
Parameters
assetNumberinteger: The asset's number in the foliage list.xinteger: The region's location along x.zinteger: The region's location along z.spotCountinteger: How many spots there are along each side.spotSpacingnumber: How far apart the spots are, in world units.
ToJson(text assetName)
This action writes the coverage as a JSON object: the asset, the asset's name (so a file can be checked against the list), the grid's size, and the values as runs of the same level, from 0 to 255, since most of a region is either bare or fully covered.
Parameters
assetNametext: The asset's name.
Returns
Libraries.Data.Formats.JavaScriptObjectNotation: The object.