TerrainRegionFarModel

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

A TerrainRegionFarModel draws one region with less detail, for when it is far from the camera. It uses only every few samples, the step, so a region of 64 samples with a step of 4 is drawn with 17 by 17 vertices instead of 65 by 65. Far away, the difference can't be seen, and drawing costs much less. This is the same idea as the outer rings of Terrain3D's clipmap, which have fewer vertices the farther out they are. Where a far model meets a region drawn in full detail, or a far model built when its neighbor wasn't loaded, their edges don't line up exactly, which would leave thin cracks. So every edge of a far model has a skirt: a short strip that hangs straight down from the edge, out of sight from above, and fills any crack. A far model only draws. It is never collided with, since only the ground near the player needs collision.

Example Code

use Libraries.Game.Game
use Libraries.Game.Graphics.Worlds.TerrainData
use Libraries.Game.Graphics.Worlds.TerrainRegionFarModel

class Main is Game
action Main
    StartGame()
end

action CreateGame
    TerrainData data
    data:AddRegion(0, 0)
    TerrainRegionFarModel model
    model:Build(data, data:GetRegion(0, 0), undefined, 4, 4, 1)
    Add(model)
end
end

Actions

Build(Libraries.Game.Graphics.Worlds.TerrainData data, Libraries.Game.Graphics.Worlds.TerrainRegion region, Libraries.Game.Graphics.Texture texture, number textureRepeat, integer sampleStep, number depth)

This action builds the model for one region, and places it in the world. The region's heights must be loaded while it is built, but not after. Building again updates the mesh in place when the region size, step and splat setting are unchanged. Otherwise it makes a new mesh, and the renderer cannot yet free the old one.

Parameters

GetLocationX()

This action returns the region location this model draws, along x.

Returns

integer: The region location along x.

GetLocationZ()

This action returns the region location this model draws, along z.

Returns

integer: The region location along z.

NeedsRebuild()

This action returns true if the model must be rebuilt before it is shown again.

Returns

boolean: True if the model is out of date.

PlaceInWorld()

This action places the model in the world and scales it to the vertex spacing, the same as any TerrainPatch, but lower by the skirt depth, since its vertices are measured up from the bottom of its skirts.

SetInPlaceUpdates(boolean inPlace)

This action sets whether building again may update the existing mesh in place, rather than making a new one. It is on by default.

Parameters

  • inPlace boolean: True to update meshes in place when possible.

SetNeedsRebuild(boolean rebuild)

This action marks whether the ground this model draws has changed since it was built, so it must be rebuilt before it is shown again.

Parameters

  • rebuild boolean: True if the model must be rebuilt.

SetSplatArea(integer startX, integer startZ, integer width, integer depth)

This action sets which samples the terrain's splat texture covers, so the model's texture coordinates point at the right pixels. It takes effect the next time the model is built.

Parameters

  • startX integer: The first sample along x the splat texture covers.
  • startZ integer: The first sample along z the splat texture covers.
  • width integer: How many samples the splat texture covers along x.
  • depth integer: How many samples the splat texture covers along z.

SetUsesSplat(boolean splat)

This action sets whether the model is drawn with texture splatting. It takes effect the next time the model is built.

Parameters

  • splat boolean: True to draw with texture splatting.

WasBuiltInPlace()

This action returns true if the last build updated the existing mesh in place, or false if it loaded a new mesh.

Returns

boolean: True if the last build was an update in place.

Inherited Actions

110 actions from Libraries.Game.Graphics.Model
14 actions from Libraries.Game.Graphics.Worlds.Terrain
12 actions from Libraries.Game.Graphics.Worlds.TerrainPatch
62 actions from Libraries.Interface.Item
211 actions from Libraries.Interface.Item3D
3 actions from Libraries.Language.Object