A utility class for all things related to chunks and chunk coordinates.
Example
// Get the chunk coordinates of a voxel, (0, 0) with `chunkSize=16`.
const chunkCoords = ChunkUtils.mapVoxelToChunk([1, 10, 12]);
Methods
getChunkName
▸ getChunkName(coords
, concat?
): string
Convert a 2D chunk coordinate to a string representation.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
coords | Coords2 | undefined | The coordinates to convert. |
concat | string | `" | "` |
Returns
string
The string representation of the coordinates.
getVoxelName
▸ getVoxelName(coords
, concat?
): string
Convert a 3D voxel coordinate to a string representation.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
coords | Coords3 | undefined | The coordinates to convert. |
concat | string | `" | "` |
Returns
string
The string representation of the coordinates.
mapChunkToVoxel
▸ mapChunkToVoxel(chunkPos
, chunkSize
): Coords3
Map a 2D chunk coordinate to the 3D voxel coordinate.
Parameters
Name | Type | Description |
---|---|---|
chunkPos | Coords2 | The chunk coordinate to map. |
chunkSize | number | The horizontal dimension of a chunk. |
Returns
The mapped coordinate.
mapVoxelToChunk
▸ mapVoxelToChunk(voxelPos
, chunkSize
): Coords2
Map a 3D voxel coordinate to the 2D chunk coordinate.
Parameters
Name | Type | Description |
---|---|---|
voxelPos | Coords3 | The voxel coordinate to map. |
chunkSize | number | The horizontal dimension of a chunk. |
Returns
The mapped coordinate.
mapVoxelToChunkLocal
▸ mapVoxelToChunkLocal(voxelPos
, chunkSize
): Coords3
Map a 3D voxel coordinate to the local 3D voxel coordinate in the situated chunk.
Parameters
Name | Type | Description |
---|---|---|
voxelPos | Coords3 | The voxel coordinate to map. |
chunkSize | number | The horizontal dimension of a chunk. |
Returns
The mapped coordinate.
mapWorldToVoxel
▸ mapWorldToVoxel(worldPos
): Coords3
Map a 3D world coordinate to the 3D voxel coordinate. Since a voxel is exactly 1 unit in size, this is just a floor operation.
Parameters
Name | Type | Description |
---|---|---|
worldPos | Coords3 | The world coordinate to map. |
Returns
The mapped coordinate.
parseChunkName
▸ parseChunkName(name
, concat?
): number
[]
Given a chunk representation, parse the chunk coordinates.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
name | string | undefined | The string representation of the chunk. |
concat | string | `" | "` |
Returns
number
[]
The parsed chunk coordinates.
scaleCoordsF
▸ scaleCoordsF(coords
, factor
): Coords3
Scale and floor a 3D coordinate.
Parameters
Name | Type | Description |
---|---|---|
coords | Coords3 | The coordinates to scale and floor. |
factor | number | The factor to scale by. |
Returns
The scaled and floored coordinates.