Terrain

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

This is a default and very primitive Terrain class that can be used to store data from a height map image.

Example Code

use Libraries.Game.Game
use Libraries.Game.Game
use Libraries.Game.Graphics.PixelMap
use Libraries.System.File
use Libraries.Game.Graphics.Color
use Libraries.Compute.BitwiseOperations
use Libraries.Game.Graphics.Worlds.Terrain
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Game.Graphics.PointLight
use Libraries.Game.Graphics.Camera
use Libraries.Game.Graphics.Worlds.Terrain

class Main is Game
Terrain terrain
action Main
    UseVulkan(true)
    StartGame()
end

action CreateGame
    File file
    file:SetPath("Terrain.png")
    terrain:LoadHeightMap(file)
    
    number scale = 0.5
    terrain:Scale(scale,scale,scale)
    terrain:SetY(-15)
    terrain:SetX(-25)
    terrain:SetZ(10)
    
    Color color
    Add(terrain)
    
    DirectionalLight light
    light:SetIntensity(3)
    light:SetColor(color:LightGray())
    light:SetDirection(-1, -5, -1)
    Add(light)
    
    PointLight light2
    light2:SetIntensity(100)
    light2:SetColor(color:Green())
    light2:SetPosition(0, 3, -15)
    Add(light2)
end

action Update(number seconds)
    Camera camera = GetCamera3D()
    camera:Move(0,0,2 * seconds)
end
end

Actions

FillAtPixel(integer x, integer y, Libraries.Containers.Array<Libraries.Compute.Vector3> vertices, Libraries.Game.BoundingBox box, boolean leftTriangle)

This action fills the vertices for a single pixel at the position x,z. The position is put into two places, the first three vertices in the already filled vertices array, and the bounding box is computed. If any of these objects are undefined, this will crash, as this action is an optimization to reduce memory and increase reuse.

Parameters

  • x integer: the x in the pixel map
  • y integer: the y in the pixel map, which translates to z in the heightmap.
  • vertices Libraries.Containers.Array<Libraries.Compute.Vector3>: This array must be filled with exactly three vectors, representing the triangle created in the mesh. Attrbiute: Parameter box the location of the bounding box to fill from the triangle.
  • box Libraries.Game.BoundingBox
  • leftTriangle boolean: Whether it is the left or right triangle in the mesh.

FillAtPixel(integer x, integer y, Libraries.Containers.Array<Libraries.Compute.Vector3> vertices, Libraries.Game.BoundingBox box)

The model data needs a unique ID, the meshes, and materials.

Parameters

GetPixelHeight()

Calculate the tangents

Returns

integer

GetPixelWidth()

Calculate the bitangents

Returns

integer

GetRenderBounds(Libraries.Game.BoundingBox local)

This action fills in the box around the terrain's mesh, in its own coordinates. The mesh starts at the terrain's position, at one corner, and runs one unit per height sample across and deep, as tall as its highest point. The terrain's scale is in its transform, so it is not applied here.

Parameters

Returns

boolean: True, or false if the terrain has not been built yet.

GetStickHeight()

This action get the amount to scale the height values. By default, they are scaled by 30 * some amount of white in the pixel in the heightmap, which is itself scaled from 0 to 1. Thus, we have 0 to 30 by default.

Returns

number

GetStickLength()

We likely want to let the user map materials and textures.

Returns

number

GetStickWidth()

This action get the amount to scale the height values. By default, they are scaled by 30 * some amount of white in the pixel in the heightmap, which is itself scaled from 0 to 1. Thus, we have 0 to 30 by default.

Returns

number

GetTextureSplat()

This action fills in the box around the terrain's mesh, in its own coordinates. The mesh starts at the terrain's position, at one corner, and runs one unit per height sample across and deep, as tall as its highest point. The terrain's scale is in its transform, so it is not applied here.

Returns

Libraries.Game.Graphics.Worlds.TextureSplat: True, or false if the terrain has not been built yet.

LoadHeightMap(Libraries.System.File file)

This action loads a height map from a gray scale image. The amount of white in every pixel generates the height in the model.

Parameters

LoadHeightMap(text path)

This action loads a height map from a gray scale image. The amount of white in every pixel generates the height in the model.

Parameters

  • path text

LoadHeightMap(Libraries.Game.Graphics.PixelMap map, text key)

This action loads a height map from a gray scale image. The amount of white in every pixel generates the height in the model.

Parameters

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

This action makes a 3D printer file (G-code) of the height map, with the printer, filament and settings in the profile. The ground is made into a solid block with straight sides and a flat 2 millimeter base, as large as fits on the profile's bed (its longer side is 80% of the bed), with hills in true proportion. Print(file) and Print(path), with no profile, print for a generic printer the same way.

Parameters

Example

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

class Main is Game
    Terrain terrain

    action Main
        StartGame()
    end

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

SetHeightScale(number stickHeight)

This action get the amount to scale the height values. By default, they are scaled by 30 * some amount of white in the pixel in the heightmap, which is itself scaled from 0 to 1. Thus, we have 0 to 30 by default.

Parameters

  • stickHeight number

SetStickDepth(number stickDepth)

Calculate the indices

Parameters

  • stickDepth number

SetStickWidth(number stickWidth)

This action get the amount to scale the height values. By default, they are scaled by 30 * some amount of white in the pixel in the heightmap, which is itself scaled from 0 to 1. Thus, we have 0 to 30 by default.

Parameters

  • stickWidth number

SetTextureSplat(Libraries.Game.Graphics.Worlds.TextureSplat textureSplat)

This action makes a 3D printer file (G-code) of the height map, with the printer, filament and settings in the profile. The ground is made into a solid block with straight sides and a flat 2 millimeter base, as large as fits on the profile's bed (its longer side is 80% of the bed), with hills in true proportion. Print(file) and Print(path), with no profile, print for a generic printer the same way.

Parameters

Example

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

class Main is Game
    Terrain terrain

    action Main
        StartGame()
    end

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

Inherited Actions

110 actions from Libraries.Game.Graphics.Model
62 actions from Libraries.Interface.Item
211 actions from Libraries.Interface.Item3D
3 actions from Libraries.Language.Object