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 2sizeShift(integer) — log2(size)mask(integer) — size - 1palette(Array.<integer>) — RGB colours (0xRRGGBB), at most 256heightLevels(Array.<roByteArray>) — Heights per level, level 0 (full size) firstcolorLevels(Array.<roByteArray>) — Palette indexes per level, level 0 firstedgeMode(string) —BGE.VoxelEdgeModeflatHeight(integer) — Height past the edges with edgeMode flatflatColor(integer) — Palette index past the edges with edgeMode flat
Constructor
new VoxelMap(
sizeShift: integer,
palette: Array.<integer>,
heightLevels: Array.<roByteArray>,
colorLevels: Array.<roByteArray>,
): VoxelMapUse the BGE.VoxelMaps functions, which check their input; this doesn't.
Parameters
sizeShift(integer) — log2 of the sizepalette(Array.<integer>) — RGB coloursheightLevels(Array.<roByteArray>) — per level, level 0 firstcolorLevels(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