FoliageAsset
Package: Libraries.Game.Graphics.Worlds · Inherits from: Libraries.Language.Object
A FoliageAsset is one kind of plant or object that can be scattered over a terrain, such as a pine, a rock or a tuft of grass. It names the model to draw, or a picture for a flat card, and says how copies of it are placed: how many per square unit, how much their size, turn and shade vary, and on what slopes they grow. A FoliageList holds the assets a terrain uses; TerrainFoliage holds where each copy stands.
Example Code
use Libraries.Game.Graphics.Worlds.FoliageAsset
FoliageAsset pine
pine:SetName("Pine")
pine:SetModelPath("Models/Pine.glb")
pine:SetDensity(0.02)
pine:SetRandomScale(0.3)
pine:SetMaximumSlope(35)
Variables
integer MAXIMUM_LEVELS: the up axis, in degrees from +x toward +z.
Actions
CastsShadows()
This action returns true if copies cast shadows.
Returns
boolean: True for shadows.
ClearLevel(integer level)
This action leaves a level of detail unused.
Parameters
levelinteger: The level, from 1 to MAXIMUM_LEVELS.
Copy()
This action returns a copy of the asset.
Returns
Libraries.Game.Graphics.Worlds.FoliageAsset: The copy.
CopyFrom(Libraries.Game.Graphics.Worlds.FoliageAsset other)
This action makes this asset the same as another.
Parameters
otherLibraries.Game.Graphics.Worlds.FoliageAsset: The asset to copy.
FromJavaScriptObjectNotation(Libraries.Data.Formats.JavaScriptObjectNotation json)
This action reads the asset from one entry of a foliage list file. Values the entry doesn't have keep their defaults.
Parameters
jsonLibraries.Data.Formats.JavaScriptObjectNotation: The entry.
GetBaseScale()
This action returns each copy's base scale.
Returns
number: The scale.
GetCardPicturePath()
This action returns a card's picture, relative to the foliage list's file.
Returns
text: The path.
GetCardPlanes()
This action returns how many crossed quads a card has.
Returns
integer: From 1 to 3.
GetDensity()
This action returns how many copies grow on each square unit where the asset's coverage is full. Where the coverage is lower, fewer grow.
Returns
number: The density.
GetDrawDistance()
This action returns how far from the camera copies are drawn.
Returns
number: The distance, in world units.
GetFadeMargin()
This action returns how far a level of detail fades into the next.
Returns
number: The distance, in world units; 0 switches at once.
GetFixedTilt()
This action returns how far every copy leans, in degrees.
Returns
number: The lean, in degrees from upright.
GetFixedTurn()
This action returns the turn every copy gets about the up axis, in degrees, added to its random turn.
Returns
number: The turn, in degrees.
GetGrowsOnLayer()
This action returns where the asset grows: 0 where the Foliage brush painted its coverage, or a material layer, from 1 to 4, to grow wherever that layer is painted on the ground, as much as it is painted.
Returns
integer: 0, or the layer from 1 to 4.
GetHeightOffset()
This action returns how far above the ground each copy stands.
Returns
number: The offset, in world units; below 0 sinks it.
GetLastShadowLevel()
This action returns the farthest level of detail that casts shadows. Levels past it cast none, which saves drawing far copies into the shadows.
Returns
integer: The level, from 0 to MAXIMUM_LEVELS; MAXIMUM_LEVELS (the default) lets every level cast.
GetLevelCardPicturePath(integer level)
This action returns a level of detail's card picture.
Parameters
levelinteger: The level, from 1 to MAXIMUM_LEVELS.
Returns
text: The path, or "" if the level isn't a card.
GetLevelDistance(integer level)
This action returns the distance from the camera a level of detail is used from. Level 0 is used from 0.
Parameters
levelinteger: The level, from 0 to MAXIMUM_LEVELS.
Returns
number: The distance, in world units.
GetLevelForDistance(number distance)
This action returns the level of detail to draw at a distance from the camera: the used level with the greatest distance that is no farther than it, or 0 for the asset's own mesh.
Parameters
distancenumber: The distance from the camera, in world units.
Returns
integer: The level, from 0 to MAXIMUM_LEVELS.
GetLevelModelPath(integer level)
This action returns a level of detail's model path.
Parameters
levelinteger: The level, from 1 to MAXIMUM_LEVELS.
Returns
text: The path, or "" if the level isn't a model.
GetLevelPath(integer level)
This action returns a level of detail's model or card picture, relative to the foliage list's file. Level 0 gives the asset's own model or card picture.
Parameters
levelinteger: The level, from 0 to MAXIMUM_LEVELS.
Returns
text: The path, or "" for an unused level.
GetMaximumSlope()
This action returns the steepest slope it grows on.
Returns
number: Degrees from flat.
GetMinimumSlope()
This action returns the least slope it grows on.
Returns
number: Degrees from flat.
GetModelPath()
This action returns the model's path, relative to the foliage list's file, or "" for a card.
Returns
text: The path.
GetName()
This action returns the asset's name, such as "Pine".
Returns
text: The name.
GetRandomHue()
This action returns how far each copy's hue may turn either way, in degrees.
Returns
number: The most turn, in degrees.
GetRandomScale()
This action returns how much each copy's size varies.
Returns
number: The share either way, from 0 to 1.
GetRandomTilt()
This action returns how much more each copy may lean, at random, in degrees.
Returns
number: The most extra lean, in degrees.
GetShadeVariation()
This action returns how much each copy's shade varies.
Returns
number: From 0 to 1.
GetShadowLevel()
This action returns the level of detail whose mesh throws the shadow for nearer levels, or 0 for each level's own.
Returns
integer: The level, from 0 to MAXIMUM_LEVELS.
GetTintBlue()
This action returns the blue part of the color copies are tinted.
Returns
number: The blue part, from 0 to 1.
GetTintGreen()
This action returns the green part of the color copies are tinted.
Returns
number: The green part, from 0 to 1.
GetTintRed()
This action returns the red part of the color copies are tinted.
Returns
number: The red part, from 0 to 1.
GetWind()
This action returns how much copies sway in the wind.
Returns
number: How far a point moves sideways per unit of height above where the copy stands, 0 for none.
GetWindDirection()
This action returns the wind's direction.
Returns
number: Degrees about the up axis, from +x toward +z.
GrowsOnSlope(number degrees)
This action returns true if a slope is in the range this asset grows on.
Parameters
degreesnumber: The slope, in degrees from flat.
Returns
boolean: True if it can grow there.
HasLevel(integer level)
This action returns true if a level of detail is used: it has a model or a card picture. Level 0, the asset's own mesh, is always used.
Parameters
levelinteger: The level, from 0 to MAXIMUM_LEVELS.
Returns
boolean: True if the level is used.
HasRandomTurn()
This action returns true if each copy is turned a random amount.
Returns
boolean: True for random turns.
IsAlignedToNormal()
This action returns whether copies lean with the ground's slope.
Returns
boolean: True if they lean with the slope.
IsCard()
This action returns true if the asset is drawn as a flat card instead of a model.
Returns
boolean: True for a card.
IsLevelCard(integer level)
This action returns true if a level of detail is a card. Level 0 is the asset's own mesh.
Parameters
levelinteger: The level, from 0 to MAXIMUM_LEVELS.
Returns
boolean: True for a card.
IsTinted()
This action returns true if copies are tinted a color other than white.
Returns
boolean: True if tinted.
SetAlignedToNormal(boolean value)
This action sets whether copies lean with the ground's slope, standing at right angles to it, as grass and rocks often do; trees usually stand upright.
Parameters
valueboolean: True to lean with the slope.
SetBaseScale(number scale)
This action sets each copy's base scale.
Parameters
scalenumber: The scale, more than 0.
SetCardPicturePath(text path)
This action sets a card's picture, a .png with transparent parts.
Parameters
pathtext: The path, relative to the foliage list's file.
SetCardPlanes(integer planes)
This action sets how many crossed quads a card has.
Parameters
planesinteger: From 1 to 3.
SetCastsShadows(boolean value)
This action sets whether copies cast shadows. Grass usually doesn't.
Parameters
valueboolean: True for shadows.
SetDensity(number value)
This action sets how many copies grow on each square unit where the asset's coverage is full, such as 0.02 for trees or 2 for grass. Copies already painted change to match.
Parameters
valuenumber: The density, more than 0.
SetDrawDistance(number distance)
This action sets how far from the camera copies are drawn.
Parameters
distancenumber: The distance, in world units, more than 0.
SetFadeMargin(number distance)
This action sets how far a level of detail fades into the next: over this distance before the next level's start, a growing share of the copies switch, chosen by where they stand, so a cell changes a little at a time instead of all at once.
Parameters
distancenumber: The distance, in world units; 0, the default, switches at once.
SetFixedTilt(number degrees)
This action sets how far every copy leans, in degrees from upright, in a direction chosen for each copy.
Parameters
degreesnumber: The lean, from 0 to 90.
SetFixedTurn(number degrees)
This action sets a turn every copy gets about the up axis, in degrees, added to its random turn, such as to face a model's front one way when random turn is off.
Parameters
degreesnumber: The turn, in degrees.
SetGrowsOnLayer(integer layer)
This action sets where the asset grows: 0 where the Foliage brush painted its coverage, or a material layer, from 1 to 4.
Parameters
layerinteger: 0, or the layer from 1 to 4.
SetHeightOffset(number offset)
This action sets how far above the ground each copy stands.
Parameters
offsetnumber: The offset, in world units; below 0 sinks it.
SetLastShadowLevel(integer level)
This action sets the farthest level of detail that casts shadows. It only matters if the asset casts shadows.
Parameters
levelinteger: The level, from 0 to MAXIMUM_LEVELS.
Example
use Libraries.Game.Graphics.Worlds.FoliageAsset
FoliageAsset pine
pine:SetModelPath("Models/Pine.glb")
pine:SetLevelCardPicture(1, "Pictures/PineCard.png")
pine:SetLevelDistance(1, 60)
pine:SetLastShadowLevel(0)
SetLevelCardPicture(integer level, text path)
This action makes a level of detail a card: crossed upright pictures, as many planes as the asset's cards have.
Parameters
levelinteger: The level, from 1 to MAXIMUM_LEVELS.pathtext: The picture, relative to the foliage list's file; "" leaves the level unused.
SetLevelDistance(integer level, number distance)
This action sets the distance from the camera a level of detail is used from.
Parameters
levelinteger: The level, from 1 to MAXIMUM_LEVELS.distancenumber: The distance, in world units.
SetLevelModel(integer level, text path)
This action makes a level of detail a model, used from its distance on instead of the asset's own mesh.
Parameters
levelinteger: The level, from 1 to MAXIMUM_LEVELS.pathtext: The model, relative to the foliage list's file, such as "Models/PineLow.glb"; "" leaves the level unused.
Example
use Libraries.Game.Graphics.Worlds.FoliageAsset
FoliageAsset pine
pine:SetModelPath("Models/Pine.glb")
pine:SetDrawDistance(400)
pine:SetLevelModel(1, "Models/PineLow.glb")
pine:SetLevelDistance(1, 80)
pine:SetLevelCardPicture(2, "Pictures/PineCard.png")
pine:SetLevelDistance(2, 200)
SetMaximumSlope(number degrees)
This action sets the steepest slope it grows on.
Parameters
degreesnumber: From 0 to 90.
SetMinimumSlope(number degrees)
This action sets the least slope it grows on.
Parameters
degreesnumber: From 0 to 90.
SetModelPath(text path)
This action sets the model to draw, such as "Models/Pine.glb", relative to the foliage list's file.
Parameters
pathtext: The path, or "" for a card.
SetName(text value)
This action sets the asset's name.
Parameters
valuetext: The name.
SetRandomHue(number degrees)
This action sets how far each copy's hue may turn either way, in degrees, so a field of grass has greener and yellower tufts. It turns the tint's hue, so it shows only on a colored tint, or a model whose textures are colored and whose tint is set.
Parameters
degreesnumber: The most turn, from 0 to 180.
SetRandomScale(number share)
This action sets how much each copy's size varies, as a share of the base scale either way.
Parameters
sharenumber: From 0 (all the same) to 1.
SetRandomTilt(number degrees)
This action sets how much more each copy may lean, at random, in degrees, on top of the fixed lean, so grass and reeds don't all stand straight.
Parameters
degreesnumber: The most extra lean, from 0 to 90.
Example
use Libraries.Game.Graphics.Worlds.FoliageAsset
FoliageAsset grass
grass:SetCardPicturePath("Pictures/Grass.png")
grass:SetRandomTilt(12)
grass:SetAlignedToNormal(true)
SetRandomTurn(boolean value)
This action sets whether each copy is turned a random amount about the up axis.
Parameters
valueboolean: True for random turns.
SetShadeVariation(number variation)
This action sets how much each copy's shade varies.
Parameters
variationnumber: From 0 (all the same) to 1.
SetShadowLevel(integer level)
This action sets the level of detail whose mesh throws the shadow for nearer levels, a "shadow stand-in": a detailed tree near the camera is drawn without its own shadow, and a simpler level is drawn only into the shadows in its place. Levels from this one on throw their own shadows. 0 lets every level throw its own.
Parameters
levelinteger: The level, from 0 to MAXIMUM_LEVELS.
Example
use Libraries.Game.Graphics.Worlds.FoliageAsset
FoliageAsset pine
pine:SetModelPath("Models/Pine.glb")
pine:SetLevelModel(1, "Models/PineSimple.glb")
pine:SetLevelDistance(1, 40)
pine:SetShadowLevel(1)
SetTint(number red, number green, number blue)
This action sets the color copies are tinted: it replaces the model's color, which its textures are multiplied by, and each copy's shade and hue vary it. White, the default, leaves the model's own color.
Parameters
rednumber: The red part, from 0 to 1.greennumber: The green part, from 0 to 1.bluenumber: The blue part, from 0 to 1.
Example
use Libraries.Game.Graphics.Worlds.FoliageAsset
FoliageAsset grass
grass:SetCardPicturePath("Pictures/Grass.png")
grass:SetTint(0.8, 1, 0.6)
grass:SetRandomHue(15)
SetWind(number strength)
This action sets how much copies sway in the wind. The terrain's cells give it to the asset's models' materials when they are built, so a terrain shows a change after its FoliageChanged. The materials belong to the model file or card picture, so other models from the same file sway the same.
Parameters
strengthnumber: How far a point moves sideways per unit of height above where the copy stands, such as 0.03 for grass; 0 for none.
Example
use Libraries.Game.Graphics.Worlds.FoliageAsset
FoliageAsset grass
grass:SetCardPicturePath("Pictures/Grass.png")
grass:SetWind(0.08)
SetWindDirection(number degrees)
This action sets the wind's direction.
Parameters
degreesnumber: Degrees about the up axis, from +x toward +z.
ToJavaScriptObjectNotation()
This action writes the asset as one entry of a foliage list file.
Returns
Libraries.Data.Formats.JavaScriptObjectNotation: The entry.