FoliageCellItem

Package: Libraries.Game.Graphics.Worlds · Inherits from: Libraries.Interface.Item3D, Libraries.Interface.Item, Libraries.Language.Object

A FoliageCellItem draws the copies in one FoliageCell. It draws them all with one model that has copies (Model:SetCopies), so the renderer draws every copy in one instanced draw: the asset's model, or for a card asset, one upright two-sided picture, copied once per plane of each copy. A TerrainItem makes one per cell and holds them as children, hides the cells farther from the camera than their asset's draw distance or outside its view, and tells the shown ones how far away they are (UpdateForDistance), which picks the level of detail and thins the copies near the draw distance. Each model is a FoliageCellDrawing. Besides the level drawn, a cell may draw the next level for a growing share of its copies near that level's distance, so it changes a little at a time, and a simpler level only into the shadows in place of a detailed level's shadow. The item stands at the origin, so each copy's place is its world place. The model shares its file's blueprint, so the file is loaded once however many cells use it.

Example Code

use Libraries.Game.Graphics.Worlds.FoliageCellItem
use Libraries.Game.Graphics.Worlds.FoliageCell
use Libraries.Game.Graphics.Worlds.FoliageAsset
use Libraries.System.File

FoliageCell cell
cell:Set(0, 0, 0, 32)
cell:Add(4, 0, 6, 0, 1, 1)
FoliageAsset rock
rock:SetModelPath("Models/Rock.glb")
File modelFile
modelFile:SetPath("Models/Rock.glb")
FoliageCellItem item
item:Set(cell, rock, modelFile)
item:Build()

Actions

Build()

This action makes the item's models again from its cell's copies, after copies were added, removed or moved, or the asset changed. The old models are taken out and disposed.

Clear()

This action takes out and disposes the models.

GetAsset()

This action returns the cell's asset.

Returns

Libraries.Game.Graphics.Worlds.FoliageAsset: The asset.

GetCell()

This action returns the cell the item draws.

Returns

Libraries.Game.Graphics.Worlds.FoliageCell: The cell.

GetCellMiddleX()

This action returns the cell's middle along x, in world units.

Returns

number: The x.

GetCellMiddleZ()

This action returns the cell's middle along z, in world units.

Returns

number: The z.

GetDrawnCopyCount()

This action returns how many copies are drawn after thinning, at the level drawn and the level faded into. A card's planes count as one copy each.

Returns

integer: The count.

GetLevel()

This action returns the level of detail drawn: 0 for the asset's own mesh.

Returns

integer: The level.

GetModel()

This action returns the model drawing the copies at the level drawn.

Returns

Libraries.Game.Graphics.Model: The model, or undefined before Build.

GetReach()

This action returns how tall the tallest copy reaches above where it stands, in world units, once built.

Returns

number: The height.

GetRenderBounds(Libraries.Game.BoundingBox local)

This action fills in the box around every copy, in world units, from the cell's lowest and highest copies and the tallest copy's reach.

Parameters

Returns

boolean: True, or false if the cell is empty.

IsNearCamera()

This action returns whether the cell is within its asset's draw distance of the camera.

Returns

boolean: True if it is near enough to draw.

PlaceAgain()

This action moves the copies up or down to their heights, after they followed the ground. It is quicker than Build, since nothing is loaded again; it works out the copies again, so copies added or removed are right too.

Set(Libraries.Game.Graphics.Worlds.FoliageCell foliageCell, Libraries.Game.Graphics.Worlds.FoliageAsset foliageAsset, Libraries.System.File file)

This action sets the cell to draw, its asset, and the asset's model or card picture file. Levels of detail are given with SetLevelSource.

Parameters

SetCardTexture(Libraries.Game.Graphics.Texture texture)

This action sets the picture every card of the asset shares, so it is loaded once. Without it, Build loads the picture itself.

Parameters

SetGround(Libraries.Game.Graphics.Worlds.TerrainData data)

This action sets the terrain's heights, so copies of an asset that leans with the slope can find it.

Parameters

SetInView(boolean visible)

This action sets whether the cell is inside the camera's view. The cell shows when it is near and in view.

Parameters

  • visible boolean: True if any of the cell is in view.

SetLevelSource(integer levelNumber, Libraries.System.File file, Libraries.Game.Graphics.Texture cardTexture)

This action sets a level of detail's file: its model, or for a card level, its picture, with the picture's texture if it is already loaded.

Parameters

SetNearCamera(boolean near)

This action sets whether the cell is within its asset's draw distance of the camera. The cell shows when it is near and in view.

Parameters

  • near boolean: True if the cell is near enough to draw.

UpdateForDistance(number distance)

This action tells the item how far the camera is from the cell's nearest side. It picks the level of detail for that distance, how much the copies thin out near the draw distance, and how far they have faded into the next level, and draws them again only if any of these changed, so calling it a few times a second costs little.

Parameters

  • distance number: How far the camera is, in world units.

Returns

boolean: True if what is drawn changed.

Inherited Actions

64 actions from Libraries.Interface.Item
215 actions from Libraries.Interface.Item3D
3 actions from Libraries.Language.Object