VoxelMap - A grid of blocks, a 3D tile map: it draws itself, and objects with collideLevel collide with it
- pos3D is its corner, as a 2D tile layer's is, and each cell is one world unit, so cell (x, y, z) fills
pos3D + (x..x+1, y..y+1, z..z+1); it stays upright and unscaled at the root
- A block's type is a number from 1 to 255, 0 is empty; a type shows that tile of the sheet on every face unless
setBlockType gives it its own faces, or makes it see-through or transparent
- Faces between blocks are left out, and the map is drawn in chunks of 16 cells a side, a chunk built again only
when a block in or beside it changes
- Objects with collideLevel collide with it, see EngineObject3D.collideWithVoxel, and raycast finds the block a ray
hits and the face it comes in through
Create a voxel map, it draws itself and joins the level's collision
pos3D Vector3 optionalIts corner
mapSize Vector3 optionalCells along X, Y and Z
tileInfo TileInfo optionalThe sheet's first tile, as for a TileLayer, a block's type counts tiles from it;
give the tiles a border of their own edge pixels, 2 or more, and that padding, or the blurred mipmaps of the
distance blend each tile with the ones beside it and show seams along the block edges
const map = new VoxelMap(vec3(), vec3(32, 16, 32), tile(0, 16));
map.setBlockType(1, {top: 0, side: 1, bottom: 2}); // grass
map.setVoxel(vec3(3, 0, 5), 1);
Darken the corners where blocks meet, rebuild() after changing it
The block type of each cell, x + mapSize.x * (y + mapSize.y * z), 0 empty; call
rebuild() after changing it directly
The sheet's first tile, rebuild() after changing it or resizing its texture
Build the chunks that changed, the map calls it before it draws
Destroy the map, it leaves the level's collision and lets go of its meshes
immediate boolean optional
The block type at a cell, 0 for empty or outside the map
cell Vector3
The first block a ray hits, walking the grid cell by cell: its distance along the ray, its cell, the normal of
the face it comes in through, which a new block goes against, and its type
- A ray that starts inside a block hits it at 0, its normal back along the ray
ray Ray3DIts distance is in the ray's own units, as the other raycasts
maxDistance number optionaltest function optional(type, cell) says which blocks count, every block by default
Build every chunk again, after changing data directly or ambientOcclusion
Draw the solid and see-through blocks, the transparent ones draw through its child
Give a block type its own faces, or make it see-through or transparent
type number1 to 255
faces number|Array<number>|{top?: number, side: number, bottom?: number}A tile index for every face, six in the order +x, -x, +y, -y, +z, -z, or the side's with the top and bottom's, which default to the side's
Set the block at a cell, 0 clears it; a cell outside the map is ignored
cell Vector3type number0 to 255
Keeps an eye on its placement, called automatically each frame