📚 Encyclopedia

Web Development · updated 2026-10-13

three.js in a static site (bundling, viewers, snapshots)

threejswebglesbuild3d-viewersnapshotstouch

Notes from using three.js (r186) without a framework on 3d.jhampton.io and on justinahampton.com pages (the orrery's 3D view, the planet globe).

Getting the library

Viewer details

No-build alternative: import map from a CDN

For a single-file toy, skip bundling: an <script type="importmap"> mapping three to https://unpkg.com/three@0.160.0/build/three.module.js (and three/addons/ to the examples folder) lets import * as THREE from 'three' work in a plain HTML file opened from any static server. Turbo Circuit 3D (a Trackmania-style racer, 2026-08) was built this way, with procedural low-poly meshes and no asset files. Give each variant its own localStorage key so a 2D and a 3D version of the same game do not overwrite each other's best laps.

Orienting a flat object across a path

To stand a banner (a start gate) across a track at a point with ground-plane normal nrm (the across-track direction, in x/z): local +X under rotation.y = θ maps to world (cos θ, 0, -sin θ), so θ = -Math.atan2(nrm.z, nrm.x) aligns the banner's width with the normal exactly. An extra + Math.PI/2 (a common reflex) aligns it with the tangent instead and the gate renders edge-on as a sliver along the road. Derive rotations by mapping a local axis to world coordinates rather than by trial and error.

Snapshots

Headless rendering

WebGL in headless Chrome needs SwiftShader: --use-gl=angle --use-angle=swiftshader --enable-unsafe-swiftshader. A full model page screenshot works with plain --screenshot and --virtual-time-budget=15000. Software GL frame rates say nothing about a real GPU; add a quality safety valve (the planet drops fine relief after 12 slow frames in a row) and say it is untested on hardware.

See also

Linked from

Sources: justinahampton memory (3d-subdomain, 3d-create-templates, freetime-orrery, freetime-planet)