Skip to content

Cube

A 3D cube (box) shape with equal-length sides.

Usage

ts
import { createCube } from '@ripl/3d';

const cube = createCube({
    x: 0,
    y: 0,
    z: 0,
    size: 2,
    fillStyle: '#4488ff',
});

Properties

PropertyTypeDefaultDescription
xnumber0X position in world space
ynumber0Y position in world space
znumber0Z position in world space
sizenumberSide length of the cube
rotationXnumber0Rotation around the X axis (radians)
rotationYnumber0Rotation around the Y axis (radians)
rotationZnumber0Rotation around the Z axis (radians)
fillStylestringBase fill color (shading is applied per-face)

Type Guard

ts
import { elementIsCube } from '@ripl/3d';

if (elementIsCube(element)) {
    console.log(element.size);
}

Demo