VoxelMap

A heightmap terrain's data: a square grid of heights (0-255) and colours (palette indexes), with mip levels, where level n averages 2^n x 2^n cells. Each level is an roByteArray, cell (x, z) at index (z << levelShift) + x. A colour index past the palette draws as palette colour 0 (only fromArrays() checks them).

Make one with BGE.VoxelMaps.fromFile() (a .bvox from tools/voxel-map.py; the fast way), BGE.VoxelMaps.fromArrays(), BGE.VoxelMaps.fromLevels() or BGE.VoxelMapGenerator.

Properties

  • size (integer) — Cells along each side, a power of 2
  • sizeShift (integer) — log2(size)
  • mask (integer) — size - 1
  • palette (Array.<integer>) — RGB colours (0xRRGGBB), at most 256
  • heightLevels (Array.<roByteArray>) — Heights per level, level 0 (full size) first
  • colorLevels (Array.<roByteArray>) — Palette indexes per level, level 0 first
  • edgeMode (string) — BGE.VoxelEdgeMode
  • flatHeight (integer) — Height past the edges with edgeMode flat
  • flatColor (integer) — Palette index past the edges with edgeMode flat

Constructor

new VoxelMap( sizeShift: integer, palette: Array.<integer>, heightLevels: Array.<roByteArray>, colorLevels: Array.<roByteArray>, ): VoxelMap

Use the BGE.VoxelMaps functions, which check their input; this doesn't.

Parameters

  • sizeShift (integer) — log2 of the size
  • palette (Array.<integer>) — RGB colours
  • heightLevels (Array.<roByteArray>) — per level, level 0 first
  • colorLevels (Array.<roByteArray>) — per level, level 0 first

Instance Methods

getLevelCount(): integer

How many mip levels the map has, level 0 included.

Returns

  • integer

cellHeight(ix: integer, iz: integer): integer

The height (0-255) of a whole cell, past the edges by edgeMode.

Parameters

  • ix (integer)
  • iz (integer)

Returns

  • integer

colorAt(ix: integer, iz: integer): integer

The palette index of a whole cell, past the edges by edgeMode.

Parameters

  • ix (integer)
  • iz (integer)

Returns

  • integer

heightAt(x: float, z: float): float

The height (0-255, fractional) at a map position in cells, blended between the four nearest cell centres (cell i's centre is at i + 0.5): for standing on the terrain.

Parameters

  • x (float)
  • z (float)

Returns

  • float

toByteArray(): roByteArray

The map as a .bvox file's bytes (see BGE.VoxelMaps.fromByteArray() for the layout).

Returns

  • roByteArray

saveToFile(path: string): boolean

Writes the map as a .bvox file.

Parameters

  • path (string) — e.g. "tmp:/island.bvox"

Returns

  • boolean — whether it was written