TerrainItem

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

A TerrainItem is a terrain as an item: it holds a WorldTerrain loaded from a terrain's folder, and its region models are its children. So a terrain can go into a layer, be saved in a scene, and be loaded with LoadScene, like a model. Quorum Studio's scene editor adds one from its palette. A terrain's heights are world positions, so a TerrainItem stays at the origin: it isn't moved, turned or scaled. Its region models have collision by default, so physics objects land on it. A terrain is loaded from its terrain.json file, which TerrainData's Save writes into the terrain's folder beside the region images. A new terrain, made with CreateFlat, is flat and plain: it has no painting and no materials. It needs Vulkan.

Example Code

use Libraries.Game.Game
use Libraries.Game.Graphics.Worlds.TerrainItem

class Main is Game
TerrainItem ground

action Main
    UseVulkan(true)
    StartGame()
end

action CreateGame
    EnablePhysics3D(true)
    ground:Load("Terrains/Terrain1/terrain.json")
    Add(ground)
    output "The ground at the origin is at height " + ground:GetWorldTerrain():GetData():GetHeight(0, 0)
end
end

Actions

AddLake(number x, number z, number width, number depth, number level)

This action adds a lake: a rectangle of water centered on a point, at a level. It can be larger than its hollow, since the ground hides the water wherever it rises above it.

Parameters

  • x number: The lake's middle along x.
  • z number: The lake's middle along z.
  • width number: Its size along x.
  • depth number: Its size along z.
  • level number: The water's height.

Returns

Libraries.Game.Graphics.Worlds.TerrainLake: The lake.

CreateFlat(Libraries.System.File file, integer regionsAcross, integer regionSize, number spacing)

This action makes a new, flat terrain at height 0, centered on the origin, saves it into the folder of the terrain.json file given, and makes its region models. The folder is made if it isn't there. The terrain has no painting and no materials, so it draws plain.

Parameters

  • file Libraries.System.File: Where the terrain.json file goes.
  • regionsAcross integer: How many regions along x and along z.
  • regionSize integer: How many samples along each side of a region: 64, 128, 256, 512, 1024 or 2048.
  • spacing number: How far apart the samples are, in world units.

Dispose()

This action gives back the places the terrain's ground textures hold in the renderer, once the terrain is no longer used, such as when its scene is closed. Remove the terrain from its layer first. If it is added and drawn again, it takes new places on its next update.

FoliageChanged()

This action makes the foliage's drawing again on the next update, after copies were added or removed by code, or the foliage list's assets changed. The foliage brush in a scene editor calls RefreshFoliage with the area it changed instead, which is quicker.

FollowGround(number x, number z, number radius)

This action keeps the foliage in an area on the ground under it, after the ground there was sculpted: placed copies move onto the ground, keeping each asset's height offset, and the copies worked out from coverage are worked out again, since the slopes changed too. A scene editor calls it as the ground changes.

Parameters

  • x number: The area's middle along x, in world units.
  • z number: The area's middle along z, in world units.
  • radius number: How far the area reaches from its middle; a negative radius is the whole terrain.

Returns

integer: How many cells of foliage moved.

GetCollisionMode()

This action returns how the terrain can be collided with.

Returns

integer: WorldTerrain's COLLISION_FULL, COLLISION_DYNAMIC or COLLISION_DISABLED.

GetDrawRadius()

This action returns how near a region must be to be drawn while streaming.

Returns

number: The draw radius, in world units.

GetDrawnFoliageCount()

This action returns how many foliage instances the shown cells draw now, after thinning: a card's planes count as one each, so a two-plane card counts twice.

Returns

integer: The number of instances drawn.

GetFoliageAssetFile(Libraries.Game.Graphics.Worlds.FoliageAsset asset)

This action returns an asset's model file, or its card picture, whose path is relative to the foliage list's file.

Parameters

Returns

Libraries.System.File: The file.

GetFoliageCellCount()

This action returns how many foliage cells the terrain draws from: one per cell and asset with copies.

Returns

integer: The number of cells.

GetFoliageFile()

This action returns the foliage list file's path, as a scene names it.

Returns

text: The path, or an empty text for no foliage list.

GetFoliageList()

This action returns the terrain's foliage list.

Returns

Libraries.Game.Graphics.Worlds.FoliageList: The list, or undefined if it has none.

GetFoliagePathFile(text path)

This action returns the file for a path in the foliage list, such as an asset's model or a level of detail's picture: a full path as it is, and any other relative to the foliage list's file.

Parameters

  • path text: The path.

Returns

Libraries.System.File: The file.

GetFollowItem()

This action returns the item the terrain keeps its regions around.

Returns

Libraries.Interface.Item3D: The item, or undefined for the camera.

GetFriction()

This action returns how much the ground's surface resists things sliding on it.

Returns

number: The friction.

GetMaterial()

This action returns the ground's terrain material.

Returns

Libraries.Game.Graphics.Worlds.TerrainMaterial: The terrain material, or undefined for plain ground.

GetMaterialFile()

This action returns the terrain material file's path, as a scene names it.

Returns

text: The path, or an empty text for plain ground.

GetPrintChoices()

This action returns how the terrain prints: its size (as large as fits on the bed, or a longest side in millimeters), how many times their true height the hills print, and the base under them. Change them on the object returned; Print uses them, and a scene saves them with the terrain.

Returns

Libraries.Game.Graphics.Worlds.TerrainPrintMesh: The terrain's print choices.

Example

use Libraries.Game.Graphics.Worlds.TerrainItem
use Libraries.Game.Graphics.Worlds.TerrainPrintMesh

TerrainItem ground
TerrainPrintMesh choices = ground:GetPrintChoices()
choices:SetLongestSide(150)
choices:SetHillScale(2)

GetRenderBounds(Libraries.Game.BoundingBox local)

This action fills in the box around every region the terrain has, in its own coordinates. The layer's render tree uses it to decide whether the terrain is in view, and the region models are the item's children, so they show or hide with it. Without it, a terrain has no size, and the layer treats it as a point at its position, hiding the whole terrain whenever that point is out of view.

Parameters

Returns

boolean: True, or false if the terrain has no regions.

GetShownFoliageCellCount()

This action returns how many foliage cells are shown now: within their asset's draw distance of the camera and, for assets that cast no shadows, in its view.

Returns

integer: The number of cells shown.

GetTerrainFile()

This action returns the terrain.json file's path, as given to Load or CreateFlat.

Returns

text: The path, or an empty text if no terrain is loaded.

GetTerrainFoliage()

This action returns where every copy of the terrain's foliage stands. It is loaded and saved with the terrain.

Returns

Libraries.Game.Graphics.Worlds.TerrainFoliage: The terrain's foliage.

GetWater()

This action returns the terrain's water: its sea and lakes, and their look. After changing it, call WaterChanged so it is drawn again. It is loaded and saved with the terrain.

Returns

Libraries.Game.Graphics.Worlds.TerrainWater: The water.

GetWaterLevelAt(number x, number z)

This action returns the height of the water over a point, or TerrainWater's NO_WATER where there is none.

Parameters

  • x number: The point along x.
  • z number: The point along z.

Returns

number: The water's height.

GetWorldTerrain()

This action returns the WorldTerrain the item holds, to read heights, edit the ground, or update its collision.

Returns

Libraries.Game.Graphics.Worlds.WorldTerrain: The WorldTerrain.

HasCollision()

This action returns whether the terrain's region models have collision shapes.

Returns

boolean: True for collision.

IsMissing()

This action returns true if Load was given a terrain.json file that isn't there. The item then has no regions, and draws nothing.

Returns

boolean: True if the terrain's files weren't found.

IsStreaming()

This action returns true if the terrain streams its regions.

Returns

boolean: True for streaming.

IsUnderWater(number x, number y, number z)

This action returns true if a point is in the water: below the water there, and above the ground.

Parameters

  • x number: The point along x.
  • y number: The point's height.
  • z number: The point along z.

Returns

boolean: True if the point is under water.

Load(text path)

This action loads a terrain from its terrain.json file, and makes its region models, as the item's children.

Parameters

  • path text: The terrain.json file's path.

Load(Libraries.System.File file)

This action loads a terrain from its terrain.json file, and makes its region models, as the item's children. The item must not have a terrain loaded already.

Parameters

LoadCardTexture(Libraries.System.File file)

This action loads a card's picture with mipmaps, as a cut-out picture: without mipmaps, distant cards are read from the full-size picture and flicker; with plain mipmaps, thin blades fade below the cut and the grass thins out far away. A cut-out picture's smaller levels keep the same share of pixels past the cut (a half, the cut a card's plane uses).

Parameters

Returns

Libraries.Game.Graphics.Texture: The texture.

LoadFoliageList(Libraries.System.File file)

This action loads a foliage list file and gives it to the terrain.

Parameters

LoadMaterial(Libraries.System.File file)

This action loads a terrain material file and gives the ground its look.

Parameters

Print(Libraries.System.File file)

This action makes a 3D printer file (G-code) of the terrain's ground, for a generic printer: a 220 by 220 millimeter bed, a 0.4 millimeter nozzle, and PLA plastic. The ground is made into a solid block with straight sides and a flat 2 millimeter base, as large as fits on the bed (its longer side is 80% of the bed), with hills in true proportion. To print for a particular printer, pass a Profile too.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Worlds.TerrainItem
use Libraries.System.File

class Main is Game
    TerrainItem ground

    action Main
        StartGame()
    end

    action CreateGame
        ground:Load("Terrains/Terrain1/terrain.json")
        Add(ground)
        File file
        file:SetPath("Prints/ground.gcode")
        ground:Print(file)
    end
end

Print(text path)

This action makes a 3D printer file (G-code) of the terrain's ground, for a generic printer, at a path relative to the folder the program runs in. See Print(File) for the printer and the size.

Parameters

  • path text: Where to write the G-code.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Worlds.TerrainItem

class Main is Game
    TerrainItem ground

    action Main
        StartGame()
    end

    action CreateGame
        ground:Load("Terrains/Terrain1/terrain.json")
        Add(ground)
        ground:Print("Prints/ground.gcode")
    end
end

Print(Libraries.System.File file, Libraries.Fabrication.Profiles.Profile profile)

This action makes a 3D printer file (G-code) of the terrain's ground, with the printer, filament and settings in the profile. Load profiles with a ProfileManager. The ground is made into a solid block with straight sides and a flat base, sized by the terrain's print choices (GetPrintChoices): unless they are changed, as large as fits on the profile's bed (its longer side is 80% of the bed), with hills in true proportion, on a 2 millimeter base. If the profile packages for Bambu printers (write3mf), a .gcode.3mf file is also written beside the G-code, with the same name.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Worlds.TerrainItem
use Libraries.System.File
use Libraries.Fabrication.Profiles.ProfileManager

class Main is Game
    TerrainItem ground

    action Main
        StartGame()
    end

    action CreateGame
        ground:Load("Terrains/Terrain1/terrain.json")
        Add(ground)
        ProfileManager profiles
        profiles:Load("Profiles/profiles.json")
        File file
        file:SetPath("Prints/ground.gcode")
        ground:Print(file, profiles:Require("ender3-v2"))
    end
end

Print(text path, Libraries.Fabrication.Profiles.Profile profile)

This action makes a 3D printer file (G-code) of the terrain's ground, with the settings in the profile, at a path relative to the folder the program runs in. See Print(File, Profile).

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Worlds.TerrainItem
use Libraries.Fabrication.Profiles.ProfileManager

class Main is Game
    TerrainItem ground

    action Main
        StartGame()
    end

    action CreateGame
        ground:Load("Terrains/Terrain1/terrain.json")
        Add(ground)
        ProfileManager profiles
        profiles:Load("Profiles/profiles.json")
        ground:Print("Prints/ground.gcode", profiles:Require("ender3-v2"))
    end
end

RebuildRegionModels()

This action makes the region models again after regions were added or removed, such as by a scene editor's region tools.

RefreshFoliage(number x, number z, number radius)

This action works out the foliage's copies in an area again from its coverage, and makes their drawing again now, such as after a brush stroke painted coverage there, or one was undone.

Parameters

  • x number: The area's middle along x, in world units.
  • z number: The area's middle along z, in world units.
  • radius number: How far the area reaches from its middle.

RefreshMaterial()

This action gives the terrain its material again, after the TerrainMaterial changed, and makes the region models again.

RefreshMaterialLayer(integer layer)

This action gives the terrain one layer of its material again, after a map of that layer's Material changed, and makes the region models again.

Parameters

  • layer integer: The layer, from 0.

RefreshRenderBounds()

This action gives the layer's render tree the terrain's box again, after regions were added or removed or the ground was raised or lowered. A terrain not in a layer has nothing to tell.

RemoveSea()

This action takes the sea away.

SaveTerrain()

This action saves the terrain's heights, and any painting, back into its folder.

SetCollision(boolean enabled)

This action sets whether the terrain's region models have collision shapes, so physics objects land on them. Set it before Load or CreateFlat. Quorum Studio's editor turns it off, since it only draws.

Parameters

  • enabled boolean: True for collision, the default.

SetCollisionMode(integer mode)

This action sets how the terrain can be collided with: WorldTerrain's COLLISION_FULL, every region (the default); COLLISION_DYNAMIC, only near moving bodies, for large worlds; or COLLISION_DISABLED. Set it before Load or CreateFlat.

Parameters

  • mode integer: The collision mode.

SetFoliageFile(text path)

This action sets the foliage list file's path, as a scene names it.

Parameters

  • path text: The path, or an empty text for none.

SetFoliageList(Libraries.Game.Graphics.Worlds.FoliageList list)

This action gives the terrain its foliage list: the assets its copies are of. The copies themselves are in GetTerrainFoliage, by each asset's number in the list.

Parameters

SetFollowItem(Libraries.Interface.Item3D item)

This action sets the item the terrain keeps its regions and collision around, such as a player's car. Undefined, the default, uses the camera.

Parameters

SetFriction(number friction)

This action sets how much the ground's surface resists things sliding on it. Set it before Load or CreateFlat.

Parameters

  • friction number: The friction.

SetMaterial(Libraries.Game.Graphics.Worlds.TerrainMaterial material)

This action gives the ground a look: its layers and how they blend. The region models are made again with it. Undefined goes back to plain ground. Call it again after changing the TerrainMaterial.

Parameters

SetMaterialFile(text path)

This action sets the terrain material file's path, as a scene names it.

Parameters

  • path text: The path, or an empty text for plain ground.

SetSeaLevel(number level)

This action puts a sea around the terrain at a height: water reaching the horizon, hidden wherever the ground is higher.

Parameters

  • level number: The sea's height.

SetStreaming(boolean stream, number radius)

This action sets whether the terrain streams: it then loads and draws only the regions within the draw radius of the camera, or of the item it follows (SetFollowItem), loading and unloading regions as that moves. For large terrains. Set it before Load; streaming starts on the item's first update in a layer.

Parameters

  • stream boolean: True to stream.
  • radius number: How near, in world units, a region must be to be drawn. It must be more than 0.

Update(number secondsSinceUpdate)

This action keeps the terrain up to date each frame, so a game needs no code for it: ground textures become ready to draw, and a streaming terrain loads and unloads regions around the camera, or the item it follows. The layer calls it.

Parameters

  • secondsSinceUpdate number: The time since the last frame.

Update(Libraries.Game.Layer3D layer, number x, number z)

This action keeps the terrain up to date, and should be called once a frame, with where the camera or player is. Ground textures that are painted onto the terrain only show once the renderer has them ready, which this checks. A plain terrain needs nothing from it, so calling it costs little.

Parameters

  • layer Libraries.Game.Layer3D: The layer the terrain is in.
  • x number: Where the camera or player is, along x.
  • z number: Where the camera or player is, along z.

Returns

boolean: True if anything about the terrain changed.

WaterChanged()

This action draws the water again on the next update, after its sea, lakes or look were changed.

Inherited Actions

62 actions from Libraries.Interface.Item
213 actions from Libraries.Interface.Item3D
3 actions from Libraries.Language.Object