Constructor
new VoxelMap(pos3Dopt, mapSizeopt, tileInfoopt)
Create a voxel map, it draws itself and joins the level's collision
| Name | Type | Attributes | Description |
|---|---|---|---|
pos3D | Vector3 | <optional> | Its corner |
mapSize | Vector3 | <optional> | Cells along X, Y and Z |
tileInfo | TileInfo | <optional> | The 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 |
- Source
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);Extends
- EngineObject3D
Members
ambientOcclusion
Properties| Type | Description |
|---|---|
| boolean | Darken the corners where blocks meet, rebuild() after changing it |
- Source
blockTypes :Array.<({faces: Array.<number>, seeThrough: boolean, transparent: boolean}|undefined)>
- Array.<({faces: Array.<number>, seeThrough: boolean, transparent: boolean}|undefined)>
- Source
chunkCenters :Array.<Vector3>
- Array.<Vector3>
- Source
chunkMeshes :Array.<(Mesh|undefined)>
- Array.<(Mesh|undefined)>
- Source
chunkTransparentMeshes :Array.<(Mesh|undefined)>
- Array.<(Mesh|undefined)>
- Source
data
Properties| Type | Description |
|---|---|
| Uint8Array | The block type of each cell, x + mapSize.x * (y + mapSize.y * z), 0 empty; call rebuild() after changing it directly |
- Source
mapSize
Properties| Type | Description |
|---|---|
| Vector3 | Cells along X, Y and Z |
- Source
tileInfo
Properties| Type | Description |
|---|---|
| TileInfo | The sheet's first tile, rebuild() after changing it or resizing its texture |
- Source
Methods
buildChunks()
Build the chunks that changed, the map calls it before it draws
destroy(immediateopt)
Destroy the map, it leaves the level's collision and lets go of its meshes
| Name | Type | Attributes | Description |
|---|---|---|---|
immediate | boolean | <optional> |
getVoxel(cell) → {number}
The block type at a cell, 0 for empty or outside the map
| Name | Type | Description |
|---|---|---|
cell | Vector3 |
- Type:
- number
raycast(ray, maxDistanceopt, testopt) → {VoxelHit|undefined}
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
| Name | Type | Attributes | Description |
|---|---|---|---|
ray | Ray3D | Its distance is in the ray's own units, as the other raycasts | |
maxDistance | number | <optional> | |
test | function | <optional> | (type, cell) says which blocks count, every block by default |
- Type:
- VoxelHit |
undefined
rebuild()
Build every chunk again, after changing data directly or ambientOcclusion
render3D()
Draw the solid and see-through blocks, the transparent ones draw through its child
setBlockType(type, faces)
Give a block type its own faces, or make it see-through or transparent
| Name | Type | Description |
|---|---|---|
type | number | 1 to 255 |
faces | ||
|
setVoxel(cell, type)
Set the block at a cell, 0 clears it; a cell outside the map is ignored
| Name | Type | Description |
|---|---|---|
cell | Vector3 | |
type | number | 0 to 255 |
update()
Keeps an eye on its placement, called automatically each frame