Skip to contents

Create a terrain tile with optional image overlay

Usage

create_terrain(
  script,
  method_name = NULL,
  heightmap_path,
  x_pos,
  z_pos,
  width,
  height,
  length,
  heightmap_resolution,
  texture_path = "",
  exec = TRUE
)

Arguments

script

A unifir_script object, created by make_script or returned by an add_prop_* function.

method_name

The internal name to use for the C# method created. Will be randomly generated if not set.

heightmap_path

The file path to the heightmap to import as terrain.

x_pos, z_pos

The position of the corner of the terrain.

width, height, length

The dimensions of the terrain tile, in linear units.

heightmap_resolution

The resolution of the heightmap image.

texture_path

Optional: the file path to the image to use as a terrain overlay.

exec

Logical: Should the C# method be included in the set executed by MainFunc?

Examples

if (requireNamespace("terra", quietly = TRUE)) {
  raster <- tempfile(fileext = ".tiff")
  r <- terra::rast(matrix(rnorm(1000^2, mean = 100, sd = 20), 1000),
    extent = terra::ext(0, 1000, 0, 1000)
  )
  terra::writeRaster(r, raster)

  script <- make_script("example_script",
    unity = waiver()
  )
  create_terrain(
    script,
    heightmap_path = raster,
    x_pos = 0,
    z_pos = 0,
    width = 1000,
    height = terra::minmax(r)[[2]],
    length = 1000,
    heightmap_resolution = 1000
  )
}
#> A `unifir_script` object with 4 props
#> 
#>                name          type
#> 1    LoadPNGAutoAdd       LoadPNG
#> 2 AddTextureAutoAdd    AddTexture
#> 3    ReadRawAutoAdd       ReadRaw
#> 4  SailAnGovernCall CreateTerrain