Skip to main content

The VoxelInteract class is used to interact with voxels in the World instance. It consists of two main parts:

You can use these two properties to place blocks, remove blocks, and more.

Example

// Create a new VoxelInteract instance.
const voxelInteract = new VoxelInteract(camera, world);

// Add the voxel interact to the scene.
world.add(voxelInteract);

// Set the target block to air.
if (voxelInteract.target) {
const [vx, vy, vz] = voxelInteract.target;
world.updateVoxel(vx, vy, vz, 0);
}

// Update the interaction every frame.
voxelInteract.update();

VoxelInteract

Hierarchy​

  • Group

    ↳ VoxelInteract

Constructors​

constructor​

• new VoxelInteract(object, world, options?): VoxelInteract

Create a new VoxelInteract instance.

Parameters​

NameTypeDescription
objectObject3D<Object3DEventMap>The object that the interactions should be raycasting from.
worldWorld<any>The World instance that the interactions should be raycasting in.
optionsPartial<VoxelInteractOptions>Parameters to customize the VoxelInteract instance.

Returns​

VoxelInteract

Overrides​

Group.constructor

Properties​

active​

• active: boolean = true

Whether or not is this VoxelInteract instance currently active.


object​

• object: Object3D<Object3DEventMap>

The object that the interactions should be raycasting from.


options​

• options: VoxelInteractOptions

Parameters to customize the VoxelInteract instance.


potential​

• potential: Object

The potential orientation and location of the block placement. If no block placement is possible, this will be null.

Type declaration​

NameTypeDescription
placement{ facingPlayerRotation: number ; facingPlayerYRotation: number ; facingPlayerYRotation4: number ; facingPlayerYRotation8: number ; verticalHalf: "bottom" | "top" }Additional placement hints derived from the raycast hit point and player position. Useful for blocks like slabs (top/bottom) and signs (facing player).
placement.facingPlayerRotationnumberThe rotation value that would make the block face toward the player. Useful for signs, paintings, and other wall-mounted blocks.
placement.facingPlayerYRotationnumberThe Y-rotation value (16 segments) that would make the block face toward the player.
placement.facingPlayerYRotation4numberThe Y-rotation value (4 segments) that would make the block face toward the player.
placement.facingPlayerYRotation8numberThe Y-rotation value (8 segments) that would make the block face toward the player.
placement.verticalHalf"bottom" | "top"Whether the hit point is in the top or bottom half of the target voxel space. Useful for determining slab placement (top slab vs bottom slab).
rotationnumberThe rotation that the block placement's major axis should be facing.
voxelCoords3The 3D coordinates of the potential block placement.
yRotationnumberThe rotation along the Y axis that the block placement's major axis should be facing. This only works if rotation is PY_ROTATION or NY_ROTATION.
yRotation4number-
yRotation8number-

target​

• target: Coords3

The targeted voxel coordinates of the block that the camera is looking at. If no block is targeted, this will be null.


world​

• world: World<any>

The World instance that the interactions should be raycasting in.

Accessors​

lookingAt​

• get lookingAt(): Block

Get the voxel ID of the targeted voxel. null if no voxel is targeted.

Returns​

Block

Methods​

getAABBOverride​

▸ getAABBOverride(voxel): AABB[]

Parameters​

NameType
voxelCoords3

Returns​

AABB[]


removeAABBOverride​

▸ removeAABBOverride(voxel): void

Parameters​

NameType
voxelCoords3

Returns​

void


setAABBOverride​

▸ setAABBOverride(voxel, aabbs, owner?): void

Parameters​

NameType
voxelCoords3
aabbsAABB[]
owner?Coords3

Returns​

void


toggle​

▸ toggle(force?): void

Parameters​

NameTypeDefault value
forcebooleannull

Returns​

void


update​

▸ update(): void

Raycasts from the given object's position and direction to find the targeted voxel and potential block placement. If no block is targeted, then VoxelInteract.target and VoxelInteract.potential will both be null.

Returns​

void