voxolith

Examples

The live Voxolith example pages and apps, from one .vox model to a streamed valley in 2 cm voxels, with source and what each shows.

The examples are small, complete programs: each page is one main.ts in voxolith/examples, running live at voxolith.github.io/examples/. They all need a browser with WebGPU. Each page below says what the example shows, links the live page and its source, points at the APIs it uses, and lists the URL options it reads.

The world example: the whole generated valley from above, a village among the woods
exampleshowssize
hello-voxload a .vox model and draw it with a turning camera~35 lines
orbita voxel grid written by hand, an orbit camera, rendering on demand~55 lines
minecraft-regiondrop a Minecraft .mca region and fly through it in first person~85 lines
worlda generated valley: terrain, river, village, forest, a lamp to carry, day and night, weather~470 lines + layout
valleythe same valley at 20, 50 or 100 voxels per metre: refined models as instances, streamed ground, rats at 1 cm~490 lines
nightwoodfirst person in a misty forest at night at 20, 50 or 100 voxels per metre: moonlight, a lit cottage, fireflies, fog as the view distance~270 lines
temporaltemporal accumulation of shadows and AO: a moonlit scene, a one-tap toggle, soft shadows, GPU time off and on~320 lines
creaturerigged, animated rats you can wound and dismember with a tap~375 lines
swarmhundreds of animated rats through one crowd, with a live cost overlay~150 lines
instancestrees and a crowd drawn by reference, nothing written into the world~145 lines
benchthe renderer benchmark: one deterministic scene with every expensive renderer path, four fixed views, at 20, 50 or 100 voxels per metre~470 lines

If you are new, read them in that order: each builds on ideas from the ones before. The tutorial walks through most of the same ground one step at a time.

Running them locally

git clone https://github.com/voxolith/examples

Clone it into a workspace with the renderer, engine and generators, as in Installation, add "examples" to the workspace list, then:

bun install
bun run --cwd examples dev

Open the https://localhost:5173 URL and pick an example from the landing page.

Common URL options

Every example reads a few options through the shared startup code (src/shared/boot.ts):

optioneffect
?diagshow the adapter, the 3D texture limit and the storage binding limit in the page
?perfwhere the example uses makePerf: show the frame-time and render-scale overlay; all but the bench also log the load timeline to the console, with the load time and "first frame at X s" in the overlay's label
?e2eexpose test hooks on window for the end-to-end input checks; not for normal use

Every page also shows the same loading screen while it loads: one row per step the page lists and an overall bar, then a corner pill for anything that continues in the background. A load that fails says so on that screen.

GPU validation errors and a lost device are shown in the page too, since a phone has no console.

Offline

After one visit online, every example page loads offline, including pages you never opened: a service worker caches the whole build on the first visit (see Offline and installing). Generated models come from the IndexedDB model cache, or are generated again in the browser, and the pages with instanced scenery read their models' encodings and static bakes from a second IndexedDB cache, the scene cache (voxolith-scene, up to 2.5 GiB, least recently used out first), or compute them again. Both caps are sized to what the pages store at every scale (106 MB of models, 1816 MB of encodings and bakes, measured). With the caches, a coarse first stage and the ground filled on workers, a warm first frame of nightwood at 100 voxels per metre is 1.0 s, where it was 30.8 s with the model cache alone (measured). The examples only cache; they are not an installable app. A new deploy takes over quietly and runs on the next load, and a deploy that changed a worker's code starts its cache cold once, since each is salted by its worker's hashed URL. The dev server caches nothing. A production build served from localhost keeps the model and scene caches but registers no service worker, so it does not work offline there.

Apps

Larger programs built on the same packages, each in its own repository:

  • Viewer: open MagicaVoxel .vox files and Minecraft .mca regions, or build models from the generators and share them as codes. Installable, and it works offline after one visit, including every sample you have opened. Source
  • Demolition Shot: aim, release, watch it crumble. A mobile demolition game and installable PWA, the engine's showcase. Source
  • Editor: a voxel editor, in its early days. Installable, and it opens offline after one visit. Source
Demolition Shot: a brick tower on a checkered field, the slingshot in the foreground

On this page