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
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

toggle

toggle(force?): void

Toggle on/off of this VoxelInteract instance.

Parameters

NameTypeDefault valueDescription
forceanynullWhether or not should it be a forceful toggle on/off. Defaults to null.

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