Voxel3D

Voxel Scene

Voxel models drawn as large pixels with a dark contour and a disc behind, moved by the scroll. Models come apart, land voxel by voxel and throw cubes. A scene weighs a few kilobytes, with no image or model files.
import { VoxelScene, Volume, solids, decodeVolume, loadVox } from "pleate/effects/voxel-scene";

A burger coming together

Scroll the page: the layers meet, then the crumbs fly. Switch the palette and the disc follows.

Six layers, apart

Each part of a model knows where to go when it comes apart.

They come together

The scroll moves them. Go back and they separate again.

Crumbs included

A burst of cubes flies the moment the bun lands, always in the same way.

Props

setup(ctx)

Builds the scene once per mount. ctx is a ThreeScene context with add(), burst(), shadow() and disc; ctx.scene is what gets drawn as pixels.

(ctx) => { frame?, theme?, dispose? } | Promise

ctx.add(model, size)

Adds a model with its largest side at `size`. The actor has group, parts (by id), size, explode(0..1) and build(0..1).

VoxelActordefault size 2

ctx.burst({ count, colors, cube, spread, gravity, seed })

Flying cubes. The same value always gives the same picture, so it can follow the scroll.

{ mesh, set(0..1) }

ctx.shadow(radius) / ctx.disc

A dithered shadow on the ground, and where the picture sits: center moves the models and the disc together.

Mesh / { radius, center }

pixel

Side of one pixel of the picture.

number (px)default 4

outline

Color of the contour.

string | falsedefault "#2a1720"

disc

The flat disc behind, in the accent color unless told otherwise.

boolean | { color, radius, center }default false

bands / dither / grain / light

Steps of light, softness between them, difference between single voxels, and where the light comes from.

number / 0..1 / 0..1 / [x, y, z]default 4 / 0.55 / 0.3

progress / loop / fov / fallback / label

The scroll of the enclosing ScrollScene by default. Draws only when something changed unless loop is always.

as in ThreeScene

new Volume(w, h, d)

A model in code, from solids: box, ellipsoid, cylinder, ring, and, or, not. Colors are any CSS color, theme variables included.

fill, carve, paint, speckle, set

volumeFromPixels(drawing, depth, rim)

Any pixel drawing as a standing voxel model.

Volume

loadVox(url) / decodeVolume(text)

A MagicaVoxel file, or a model saved as a short string with encodeVolume.

Promise<Volume> / Volume

Accessibility

  • Pass label to describe the picture; without it the canvas is hidden from screen readers.
  • Nothing draws off screen or in a hidden tab, and the WebGL context is released on unmount.
  • Reduced motion stops the clock. What the scroll moves still moves, since the reader moves it.
  • Without WebGL2 the fallback shows instead: a PixelArt of the same thing works well.