A Voxelize world handles the chunk loading and rendering, as well as any 3D objects.
This class extends the ThreeJS Scene class.
This means that you can add any ThreeJS objects to the world, and they will be rendered. The world
also implements NetIntercept, which means it intercepts chunk-related packets from the server
and constructs chunk meshes from them.
There are a couple components that are by default created by the world that holds data:
- World.registry: A block registry that handles block textures and block instances.
- World.chunks: A chunk manager that stores all the chunks in the world.
- World.physics: A physics engine that handles voxel AABB physics simulation of client-side physics.
- World.loader: An asset loader that handles loading textures and other assets.
- World.sky: A sky that can render the sky and the sun.
- World.clouds: A clouds that renders the cubical clouds.
One thing to keep in mind that there are no specific setters like setVoxelByVoxel or setVoxelRotationByVoxel.
This is because, instead, you should use updateVoxel and updateVoxels to update voxels.
Example
const world = new VOXELIZE.World();
// Update the voxel at `(0, 0, 0)` to a voxel type `12` in the world across the network.
world.updateVoxel(0, 0, 0, 12)
// Register the interceptor with the network.
network.register(world);
// Register an image to block sides.
world.applyBlockTexture("Test", VOXELIZE.ALL_FACES, "https://example.com/test.png");
// Update the world every frame.
world.update(controls.position);

Type parameters
| Name | Type |
|---|---|
T | any |
Hierarchy
-
Scene↳
World
Implements
Constructors
constructor
• new World<T>(options?): World<T>
Create a new Voxelize world.
Type parameters
| Name | Type |
|---|---|
T | any |
Parameters
| Name | Type | Description |
|---|---|---|
options | Partial<WorldOptions> | The options to create the world. |
Returns
World<T>
Overrides
Scene.constructor
Properties
chunkPipeline
• chunkPipeline: ChunkPipeline
Pipeline for chunk lifecycle state machine (request -> processing -> loaded).
chunkRenderer
• chunkRenderer: ChunkRenderer
Chunk rendering state (materials, uniforms).
clouds
• clouds: Clouds
The clouds that renders the cubical clouds.
csmRenderer
• csmRenderer: CSMRenderer = null
The CSM (Cascaded Shadow Map) renderer for shader-based lighting.
extraInitData
• extraInitData: Record<string, unknown> = {}
isInitialized
• isInitialized: boolean = false
Whether or not this world is connected to the server and initialized with data from the server.
items
• items: ItemRegistry
The item registry that holds all item definitions and provides utility methods for item operations.
loader
• loader: Loader
An asset loader to load in things like textures, images, GIFs and audio buffers.
meshPipeline
• meshPipeline: MeshPipeline
Pipeline for mesh generation with ordering guarantees.
meshTransfer
• Readonly meshTransfer: Object
Configure and inspect mesh worker buffer transfer (transfer vs SharedArrayBuffer).
Type declaration
| Name | Type |
|---|---|
benchmark | (options: MeshTransferBenchmarkOptions) => Promise<MeshTransferBenchmarkResult> |
configure | (config: { mode?: WorkerTransferMode }) => void |
getMode | () => WorkerTransferMode |
getStats | () => MeshWorkerTransferStats | Record<WorkerTransferStrategy, MeshWorkerTransferStats> |
getStatus | () => { isCrossOriginIsolated: boolean ; isSharedArrayBufferAvailable: boolean ; mode: WorkerTransferMode ; pool: ChunkSharedPoolStats ; stats: MeshWorkerTransferStats | Record<WorkerTransferStrategy, MeshWorkerTransferStats> ; strategy: WorkerTransferStrategy } |
getStrategy | () => WorkerTransferStrategy |
isSharedArrayBufferAvailable | () => boolean |
resetStats | () => void |
setStrategy | (strategy: "transfer" | "shared") => void |
options
• options: WorldOptions
The options to create the world.
physics
• physics: Engine
The voxel physics engine using @voxelize/physics-engine.
registry
• registry: Registry
The block registry that holds all block data, such as texture and block properties.
sky
• sky: Sky
The sky that renders the sky and the sun.
Accessors
deleteRadius
• get deleteRadius(): number
Returns
number
renderRadius
• get renderRadius(): number
Returns
number
• set renderRadius(radius): void
Parameters
| Name | Type |
|---|---|
radius | number |
Returns
void
time
• get time(): number
Returns
number
• set time(time): void
Parameters
| Name | Type |
|---|---|
time | number |
Returns
void
Methods
addBlockEntityUpdateListener
▸ addBlockEntityUpdateListener(listener): () => void
Parameters
| Name | Type |
|---|---|
listener | BlockEntityUpdateListener<T> |
Returns
fn
▸ (): void
Returns
void
addBlockUpdateListener
▸ addBlockUpdateListener(listener): () => void
Parameters
| Name | Type |
|---|---|
listener | BlockUpdateListener |
Returns
fn
▸ (): void
Returns
void
addChunkInitListener
▸ addChunkInitListener(coords, listener): () => void
Parameters
| Name | Type |
|---|---|
coords | Coords2 |
listener | (chunk: Chunk) => void |
Returns
fn
▸ (): void
Returns
void
applyBlockFrames
▸ applyBlockFrames(idOrName, faceNames, keyframes, fadeFrames?): Promise<void>
Apply a set of keyframes to a block. This will load the keyframes from the sources and start the animation to play the keyframes on the block's texture atlas.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
idOrName | string | number | undefined | The ID or name of the block. |
faceNames | string | string[] | undefined | The face name or names to apply the texture to. |
keyframes | [number, string | Color | HTMLImageElement][] | undefined | The keyframes to apply to the texture. |
fadeFrames | number | 0 | The number of frames to fade between each keyframe. |
Returns
Promise<void>
applyBlockGif
▸ applyBlockGif(idOrName, faceNames, source, interval?): Promise<void>
Apply a GIF animation to a block. This will load the GIF from the source and start the animation using applyBlockFrames internally.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
idOrName | string | undefined | The ID or name of the block. |
faceNames | string | string[] | undefined | The face name or names to apply the texture to. |
source | string | undefined | The source of the GIF. Note that this must be a GIF file ending with .gif. |
interval | number | 66.666667 | The interval between each frame of the GIF in milliseconds. Defaults to 66.666667ms. |
Returns
Promise<void>
applyBlockTexture
▸ applyBlockTexture(idOrName, faceNames, source): void
Apply a texture to a face or faces of a block. This will automatically load the image from the source and draw it onto the block's texture atlas.
Parameters
| Name | Type | Description |
|---|---|---|
idOrName | string | number | The ID or name of the block. |
faceNames | string | string[] | The face names to apply the texture to. |
source | string | Color | Texture<unknown> | HTMLImageElement | The source of the texture. |
Returns
void
Deprecated
When applying the same texture to multiple faces, use texture groups instead for better atlas efficiency. Define texture_group on the server-side block faces and use applyTextureGroup or applyTextureGroups on the client.
applyBlockTextureAt
▸ applyBlockTextureAt(idOrName, faceName, source, voxel): CustomChunkShaderMaterial
Parameters
| Name | Type |
|---|---|
idOrName | string | number |
faceName | string |
source | string | Color | Texture<unknown> | HTMLImageElement |
voxel | Coords3 |
Returns
applyBlockTextures
▸ applyBlockTextures(data): Promise<void[]>
Apply multiple block textures at once. See applyBlockTexture for more information.
Parameters
| Name | Type | Description |
|---|---|---|
data | { faceNames: string | string[] ; idOrName: string | number ; source: string | Color }[] | The data to apply the block textures. |
Returns
Promise<void[]>
A promise that resolves when all the textures are applied.
Deprecated
When applying the same texture to multiple faces, use texture groups instead for better atlas efficiency. Define texture_group on the server-side block faces and use applyTextureGroup or applyTextureGroups on the client.
applyTextureGroup
▸ applyTextureGroup(groupName, source): any
Parameters
| Name | Type |
|---|---|
groupName | string |
source | string | Color | Texture<unknown> | HTMLImageElement |
Returns
any
applyTextureGroups
▸ applyTextureGroups(data): Promise<any[]>
Parameters
| Name | Type |
|---|---|
data | { groupName: string ; source: string | Color | Texture<unknown> | HTMLImageElement }[] |
Returns
Promise<any[]>
benchmarkMeshTransfer
▸ benchmarkMeshTransfer(options): Promise<MeshTransferBenchmarkResult>
Parameters
| Name | Type |
|---|---|
options | MeshTransferBenchmarkOptions |
Returns
Promise<MeshTransferBenchmarkResult>
customizeBlockDynamic
▸ customizeBlockDynamic(idOrName, fn): void
Parameters
| Name | Type |
|---|---|
idOrName | string | number |
fn | (pos: Coords3) => { aabbs: AABB[] ; faces: { corners: { pos: [number, number, number] ; uv: number[] }[] ; dir: [number, number, number] ; independent: boolean ; isolated: boolean ; name: string ; range: UV ; textureGroup: string }[] ; isTransparent: [boolean, boolean, boolean, boolean, boolean, boolean] } |
Returns
void
customizeMaterialShaders
▸ customizeMaterialShaders(idOrName, faceName?, data?): CustomChunkShaderMaterial
Parameters
| Name | Type | Default value |
|---|---|---|
idOrName | string | number | undefined |
faceName | string | null |
data | Object | undefined |
data.fragmentShader | string | undefined |
data.uniforms? | Object | undefined |
data.vertexShader | string | undefined |
Returns
floodLight
▸ floodLight(queue, color, min?, max?): void
Parameters
| Name | Type |
|---|---|
queue | LightNode[] |
color | LightColor |
min? | Coords3 |
max? | Coords3 |
Returns
void
getAABBOverride
▸ getAABBOverride(voxel): AABB[]
Parameters
| Name | Type |
|---|---|
voxel | Coords3 |
Returns
AABB[]
getBaseFogRange
▸ getBaseFogRange(): WorldFogRange
Returns
getBlockAABBsAt
▸ getBlockAABBsAt(vx, vy, vz): AABB[]
Parameters
| Name | Type |
|---|---|
vx | number |
vy | number |
vz | number |
Returns
AABB[]
getBlockAABBsByIdAt
▸ getBlockAABBsByIdAt(id, vx, vy, vz): AABB[]
Parameters
| Name | Type |
|---|---|
id | number |
vx | number |
vy | number |
vz | number |
Returns
AABB[]
getBlockAABBsForDynamicPatterns
▸ getBlockAABBsForDynamicPatterns(vx, vy, vz, dynamicPatterns): { aabb: AABB ; worldSpace: boolean }[]
Parameters
| Name | Type |
|---|---|
vx | number |
vy | number |
vz | number |
dynamicPatterns | BlockDynamicPattern[] |
Returns
{ aabb: AABB ; worldSpace: boolean }[]
getBlockAt
▸ getBlockAt(px, py, pz): Block
Get the block type data by a 3D world position.
Parameters
| Name | Type | Description |
|---|---|---|
px | number | The x coordinate of the position. |
py | number | The y coordinate of the position. |
pz | number | The z coordinate of the position. |
Returns
The block at the given position, or null if it does not exist.
getBlockById
▸ getBlockById(id): Block
Get the block type data by a block id.
Parameters
| Name | Type | Description |
|---|---|---|
id | number | The block id. |
Returns
The block data for the given id, or null if it does not exist.
getBlockByIdSafe
▸ getBlockByIdSafe(id): Block
Parameters
| Name | Type |
|---|---|
id | number |
Returns
getBlockByName
▸ getBlockByName(name): Block
Get the block type data by a block name.
Parameters
| Name | Type | Description |
|---|---|---|
name | string | The block name. |
Returns
The block data for the given name, or null if it does not exist.
getBlockEntityDataAt
▸ getBlockEntityDataAt(px, py, pz): T
Parameters
| Name | Type |
|---|---|
px | number |
py | number |
pz | number |
Returns
T
getBlockEntityIdAt
▸ getBlockEntityIdAt(px, py, pz): string
Parameters
| Name | Type |
|---|---|
px | number |
py | number |
pz | number |
Returns
string
getBlockFaceMaterial
▸ getBlockFaceMaterial(idOrName, faceName?, voxel?): CustomChunkShaderMaterial
Parameters
| Name | Type |
|---|---|
idOrName | string | number |
faceName? | string |
voxel? | Coords3 |
Returns
getBlockFacesByFaceNames
▸ getBlockFacesByFaceNames(id, faceNames, warnUnknown?): { corners: { pos: [number, number, number] ; uv: number[] }[] ; dir: [number, number, number] ; independent: boolean ; isolated: boolean ; name: string ; range: UV ; textureGroup: string }[]
Parameters
| Name | Type | Default value |
|---|---|---|
id | number | undefined |
faceNames | string | RegExp | string[] | undefined |
warnUnknown | boolean | false |
Returns
{ corners: { pos: [number, number, number] ; uv: number[] }[] ; dir: [number, number, number] ; independent: boolean ; isolated: boolean ; name: string ; range: UV ; textureGroup: string }[]
getBlockFacesForDynamicPatterns
▸ getBlockFacesForDynamicPatterns(blockId, dynamicPatterns): { corners: { pos: [number, number, number] ; uv: number[] }[] ; dir: [number, number, number] ; independent: boolean ; isolated: boolean ; name: string ; range: UV ; textureGroup: string }[]
Parameters
| Name | Type |
|---|---|
blockId | number |
dynamicPatterns | BlockDynamicPattern[] |
Returns
{ corners: { pos: [number, number, number] ; uv: number[] }[] ; dir: [number, number, number] ; independent: boolean ; isolated: boolean ; name: string ; range: UV ; textureGroup: string }[]
getBlockOf
▸ getBlockOf(idOrName): Block
Parameters
| Name | Type |
|---|---|
idOrName | string | number |
Returns
getBlockPassableForDynamicPatterns
▸ getBlockPassableForDynamicPatterns(vx, vy, vz, dynamicPatterns, defaultPassable): boolean
Parameters
| Name | Type |
|---|---|
vx | number |
vy | number |
vz | number |
dynamicPatterns | BlockDynamicPattern[] |
defaultPassable | boolean |
Returns
boolean
getChunkByCoords
▸ getChunkByCoords(cx, cz): Chunk
Get a chunk by its 2D coordinates.
Parameters
| Name | Type | Description |
|---|---|---|
cx | number | The x coordinate of the chunk. |
cz | number | The z coordinate of the chunk. |
Returns
The chunk at the given coordinates, or undefined if it does not exist.
getChunkByName
▸ getChunkByName(name): Chunk
Get a chunk by its name.
Parameters
| Name | Type | Description |
|---|---|---|
name | string | The name of the chunk to get. |
Returns
The chunk with the given name, or undefined if it does not exist.
getChunkByPosition
▸ getChunkByPosition(px, py, pz): Chunk
Get a chunk that contains a given position.
Parameters
| Name | Type | Description |
|---|---|---|
px | number | The x coordinate of the position. |
py | number | The y coordinate of the position. |
pz | number | The z coordinate of the position. |
Returns
The chunk that contains the position at the given position, or undefined if it does not exist.
getChunkStatus
▸ getChunkStatus(cx, cz): "requested" | "processing" | "loaded" | "to request"
Get the status of a chunk.
Parameters
| Name | Type | Description |
|---|---|---|
cx | number | The x 2D coordinate of the chunk. |
cz | number | The z 2D coordinate of the chunk. |
Returns
"requested" | "processing" | "loaded" | "to request"
The status of the chunk.