TerrainMaterial

Package: Libraries.Game.Graphics.Worlds · Inherits from: Libraries.Language.Object

A TerrainMaterial is the whole look of a terrain's ground: up to four layers, each a Material, and how they blend. Layers 1 to 4 are painted with the splat weights' red, green, blue and alpha. A new terrain's weights are all red, so the first layer covers the whole ground until other layers are painted. A layer's Material can be a texture set, which has bumps and roughness and blends with other texture sets by height, or a plain texture. Plain layers share one tile size: the first plain layer's. Terrains can share one TerrainMaterial. It is kept in a file, with Load and Save, which names each layer's material file relative to its own folder: { "Format": "Quorum Terrain Material", "Version": 1, "Name": "Meadow", "Layers": [ { "Name": "Grass", "Material": "../../Textures/Ground037_1K-PNG/Ground037.json" }, { "Name": "Rock", "Material": "../../Textures/Rocks002_1K-PNG/Rocks002.json" } ], "Blend Softness": 0.2 }

Example Code

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

TerrainItem ground
ground:Load("Scenes/Terrains/Terrain1/terrain.json")
File file
file:SetPath("Scenes/Materials/Meadow.json")
TerrainMaterial meadow
meadow:Load(file)
ground:SetMaterial(meadow)

Actions

AddLayer(text layerName, Libraries.Game.Graphics.Models.Data.Material material)

This action adds a layer after the others. There can be four.

Parameters

ApplyTo(Libraries.Game.Graphics.Worlds.WorldTerrain terrain)

This action gives a WorldTerrain this terrain material's look. Texture set layers go to its layer materials, plain layers to its TextureSplat, and the blend softness and splat program are set. With no layers, the ground goes back to plain. Only layers whose material changed are loaded again, since loading a texture set takes a moment and uses up texture places in the renderer. The terrain's region models must be made again afterward, as TerrainItem's SetMaterial does.

Parameters

Copy()

This action returns a copy with the same name, file, layers and blend softness. The layers' Materials are shared, not copied. Undo keeps copies like this.

Returns

Libraries.Game.Graphics.Worlds.TerrainMaterial: The copy.

CopyFrom(Libraries.Game.Graphics.Worlds.TerrainMaterial other)

This action makes this terrain material the same as another: its name, file, layers and blend softness. The layers' Materials are shared.

Parameters

GetBlendSoftness()

This action returns how softly texture set layers blend where they meet, from 0.01 to 1.

Returns

number: The softness.

GetFile()

This action returns the file the terrain material was loaded from or last saved to.

Returns

Libraries.System.File: The file, or undefined.

GetLayerCount()

This action returns how many layers there are, from 0 to 4.

Returns

integer: The number of layers.

GetLayerMaterial(integer layer)

This action returns a layer's material.

Parameters

  • layer integer: The layer, from 0.

Returns

Libraries.Game.Graphics.Models.Data.Material: The layer's Material.

GetLayerName(integer layer)

This action returns a layer's name.

Parameters

  • layer integer: The layer, from 0.

Returns

text: The layer's name.

GetName()

This action returns the terrain material's name, such as "Meadow".

Returns

text: The name.

HasMixedPlainTileSizes()

This action returns true if the plain layers don't all have the same tile size. Plain layers share the first one's, so the others' are ignored.

Returns

boolean: True if plain layers' tile sizes differ.

Load(Libraries.System.File file, Libraries.Containers.HashTable<text:Libraries.Game.Graphics.Models.Data.Material> materials)

This action reads a terrain material file, sharing layer materials already loaded: a material file whose full path is in the table is used from there, and others are loaded and added to it. A scene loads its terrain materials with one table, so terrains naming the same material file share one Material, and changing it changes it everywhere.

Parameters

Load(Libraries.System.File file)

This action reads a terrain material file, and each layer's material file. A layer whose material file isn't there keeps its place, with an empty Material, so the painting of the layers after it stays right.

Parameters

  • file Libraries.System.File: The terrain material file, a .json file whose "Format" is "Quorum Terrain Material".

ReloadLayer(Libraries.Game.Graphics.Worlds.WorldTerrain terrain, integer layer)

This action gives a WorldTerrain one layer again, after a map of the layer's Material changed: ApplyTo only notices a layer whose Material is a different object. The set is packed again, unless the renderer already has one with the same maps. The terrain's region models must be made again afterward, as TerrainItem's RefreshMaterial does.

Parameters

RemoveLayer(integer layer)

This action removes a layer; the layers after it move down one place. It doesn't change any terrain's painting: TerrainData's RemoveSplatLayer does that.

Parameters

  • layer integer: The layer, from 0.

Save(Libraries.System.File file)

This action writes the terrain material to a file, naming each layer's material file relative to it. It doesn't write the layers' material files; SaveMaterials does. The folder must exist.

Parameters

SaveMaterials()

This action writes each layer's material back to the file it was loaded from, such as after its tile size changed. Layers whose material has no file are skipped.

SetBlendSoftness(number softness)

This action sets how softly texture set layers blend where they meet. Near 0, the higher layer wins outright; near 1, they fade into each other.

Parameters

  • softness number: From 0.01 to 1.

SetLayer(integer layer, text layerName, Libraries.Game.Graphics.Models.Data.Material material)

This action gives a layer a different name and material. Its painted places stay the same.

Parameters

SetName(text name)

This action sets the terrain material's name, which is saved in its file.

Parameters

  • name text: The name.

SwapLayers(integer first, integer second)

This action swaps two layers' places: their names and materials. No terrain's painting changes, so where the first was painted, the second now shows, and the other way around.

Parameters

  • first integer: One layer, from 0.
  • second integer: The other layer, from 0.

Inherited Actions

3 actions from Libraries.Language.Object