Skip to content

Cube

The Cube is a 3D box primitive with equal-length sides. It supports positioning via x, y, z, independent rotation around each axis, and automatic flat shading based on the context's light direction.

NOTE

For the full API, see the 3D API Reference.

Demo

Usage

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

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

Properties

  • x / y / z — Position in world space (default 0)
  • size — Side length of the cube
  • rotationX / rotationY / rotationZ — Rotation around each axis in radians (default 0)
  • fill — Base fill color (shading is applied per-face)

Type Guard

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

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