The native runtime for three.js: three.js, down to the metal. 45× smaller than Electron, on a Sony PS3, and path-traced at 60 fps on ray-tracing GPUs.
Rust electron-alternativegame-engineglobal-illuminationgraphicsjavascript-runtimemetalpath-tracingray-tracingreal-time-renderingrenderingrustthreejstypescriptvoxelvulkanwebgpuwgpu
Landing page: the hero is a reel of the demos, not a comparison; the showroom opens in the evening
Yifeng "Evan" Wang0d56191d7700
diff --git a/showcase/README.md b/showcase/README.mdindex a0de799..bc09f3f 100644--- a/showcase/README.md+++ b/showcase/README.md@@ -15,7 +15,7 @@ culture. The site's Showcase hosts them as packages (the client repository's rel| `hello/` | The smallest case that works with `tools/showcase.ts` |Measured alone on an Apple M3 Max at 1280 x 720 and render scale 1 (2026-11-12, GPU ms a frame, p50): museum 9.7,-refraction 11.5, jewellery 12.3, daylight-home 13.2, showroom 15.0, colour-lab 15.4; moon-phases 8.0 with spikes to+refraction 11.5, jewellery 12.3, daylight-home 13.2, showroom 14.7 (in the evening, as it opens), colour-lab 15.4; moon-phases 8.0 with spikes to20 while its bodies move. All under the 16.7 ms that 60 fps takes.The rest of this file is the brief each case was written to; a new case follows it.diff --git a/showcase/showroom/case.json b/showcase/showroom/case.jsonindex e93b33b..50e0ac1 100644--- a/showcase/showroom/case.json+++ b/showcase/showroom/case.json@@ -2,8 +2,8 @@"id": "showroom","industry": "Commerce","title": "Boutique Showroom",- "caption": "A shop to walk through, lit by its window and its spots",- "blurb": "A small boutique with six real products on plinths and shelves: click one and the camera walks over for a close look. The only lights are the sun through the shop window and the shop’s own lamps, so the warm bounce off the terrazzo, the soft shadow under each product and the reflections in the floor are traced as you watch, by day and in the evening.",+ "caption": "A shop to walk through, lit by its own spots",+ "blurb": "A small boutique in the evening with six real products on plinths and shelves: click one and the camera walks over for a close look. The only lights are the shop’s own track spots, shelf strips and table lamp, so the pool under each product, its soft shadow and the reflections in the polished floor are traced as you watch; switch to day and the sun through the window takes over.","controls": [{"input": "Click a product",@@ -19,7 +19,7 @@},{"input": "M",- "does": "day to evening and back"+ "does": "evening to day and back"},{"input": "O or Space",diff --git a/showcase/showroom/showroom.game.ts b/showcase/showroom/showroom.game.tsindex bea847c..06ac445 100644--- a/showcase/showroom/showroom.game.ts+++ b/showcase/showroom/showroom.game.ts@@ -2,9 +2,10 @@//// A 6 x 7.2 m shop with a terrazzo floor, plaster walls and a steel shop window in the left wall. Six products stand in// it at their real sizes: a sneaker, sunglasses, a glass table lamp and a boom box on plinths, a velvet chair on a round-// platform in front of a painted arch, water bottles on the oak shelf wall. By day the sun comes through the window and-// most of what lights the room is its patch on the floor, bounced; the track spots pick the products out. In the-// evening the window goes dark and the same spots, the shelf strips and the table lamp carry the room. Nothing is baked+// platform in front of a painted arch, water bottles on the oak shelf wall. It opens in the evening: the window is+// dark and the shop's own lights carry the room, the track spots on the products, the strips under the shelves and+// the table lamp. By day (`mood`) the sun comes through the window and most of what lights the room is its patch on+// the floor, bounced, with the spots picking the products out. Nothing is baked// and there is no fill light: the pools, the soft shadows under the products, the plinths in the polished floor and// the room in the lamp's glass and the sunglasses are all traced.//@@ -13,8 +14,8 @@// lens; click it again, or anywhere else, to step back// next (N, Right) / prev (P, Left) step through the six products// overview (O, Space) back to the view from the door-// mood (M) day <-> evening: the sun sets in two seconds, the exposure-// follows it, the table lamp comes on+// mood (M) evening <-> day: the sun rises in two seconds, the exposure+// follows it, the table lamp goes off// colour (C) the next colourway of the product in view: the sneaker has// three, the chair two (from the door it changes the sneaker)//@@ -219,7 +220,7 @@ function daylight(elevation: number): number {const eye: Vec3 = [...OVERVIEW.eye], look: Vec3 = [...OVERVIEW.target];let zoom = FOV.overview, shown = -2, still = false;let walk = { fromEye: eye.slice() as Vec3, fromLook: look.slice() as Vec3, fromZoom: zoom, t0: 0, seconds: 1, rise: 0 };-let sunElevation = SUN.day;+let sunElevation = SUN.dusk;const colours: Record<string, number> = {};const tmp = new Vector3();const mix = (a: number, b: number, k: number) => a + (b - a) * k;@@ -271,7 +272,7 @@ function frame(f: FrameContext<State>) {// ------------------------------------------------------------------------------------------------ the gameexport default defineGame<State>({- state: { focus: -1, evening: false, colour: { shoe: 0, chair: 0 } },+ state: { focus: -1, evening: true, colour: { shoe: 0, chair: 0 } },setup() {const scene = new Scene();@@ -461,7 +462,7 @@ export default defineGame<State>({camera.id = "camera";camera.position.set(...OVERVIEW.eye);camera.lookAt(...OVERVIEW.target);- camera.setManualExposure(SUN.evDay);+ camera.setManualExposure(SUN.evDusk);scene.add(camera);return { scene, camera, options: { name: "showroom", preset: "preview" as const, width: 1280, height: 720, overrides: { native: { maxBounces: 8 } } } };},diff --git a/showcase/showroom/thumb.jpg b/showcase/showroom/thumb.jpgindex 91feb68..b21d1c8 100644Binary files a/showcase/showroom/thumb.jpg and b/showcase/showroom/thumb.jpg differdiff --git a/site/README.md b/site/README.mdindex d15a980..bdbee52 100644--- a/site/README.md+++ b/site/README.md@@ -43,16 +43,18 @@ the same footer links. The markup is repeated in each page; change it in all fou| Page | What is on it ||---|---|| `index.html` | The landing page (below). Its two buttons, in the hero and at the end: **Download** (to `download/`, named for the visitor's platform by `js/site.js`) and **GitHub**. |-| `showcase/` | Bistro night and Zero-Day as camera moves (the committed media); **Not only games**: the cases (education, commerce, architecture, culture: the packages in `play/` with an `industry`, written in `showcase/` at the repo root), each with what it shows, how to play with it, its links and QR code, and a filter by field; then **Open on your device**: a card for each of the other example packages. The cases' credits go in the footer. |+| `showcase/` | Bistro night as a clip under a divider (three.js | ThreeRT at 60 fps, `media/bistro/hero*.mp4`: both sides in one file so they cannot drift) and Zero-Day as a camera move; **Not only games**: the cases (education, commerce, architecture, culture: the packages in `play/` with an `industry`, written in `showcase/` at the repo root), each with what it shows, how to play with it, its links and QR code, and a filter by field; then **Open on your device**: a card for each of the other example packages. The cases' credits go in the footer. || `download/` | ThreeRT for macOS (the build `releases/latest.json` names) and ThreeRT for iPhone (a TestFlight or App Store link once `ios.url` is set), then how a client loads a game: `threert dev`, scan, traced and live. || `docs/` | Getting started: install the client, open an example, write a scene, the dev loop with the `threert` CLI, the package format, links to the reference documents in `docs/` on GitHub. |### The landing page-1. **Hero:** Bistro night along its own camera move, three.js | ThreeRT under one draggable divider, as a clip- (60 fps, a 12 s loop; `media/bistro/hero.mp4`, `hero-720.mp4`, both sides in one file so they cannot drift). Its first frame is- what shows until it plays, and where it does not: reduced motion, a data saver, autoplay refused. A button pauses- it. "Path tracing at 60 fps."+1. **Hero:** a reel behind the headline: a grid of short clips of this repository's demos (Bistro with a crowd,+ Tokyo at dusk, Kabukichō, the voxel level, the showcase cases) and of OpenStrike, all ThreeRT live, ray traced,+ nothing compared (`media/reel/`: 4 x 3 clips for a wide screen, 2 x 4 for a phone held upright; 60 fps, an 8 s+ loop). Nothing in it takes a touch, so a finger scrolling the page passes over it. Its first frame is what shows+ until it plays, and where it does not: reduced motion, a data saver, autoplay refused. A button pauses it.+ "Path tracing at 60 fps."2. **ThreeRT = Three + RT:** Ray Tracing, Real Time, Runtime.3. **Hello world looks right:** an auto-advancing reel of three starter scenes, the ThreeRT source next to its output(three.js as written | ThreeRT with every setting at its default).@@ -115,11 +117,11 @@ links from where they are served (`js/site.js` `packageLinks`):|---|---|| `index.html`, `showcase/`, `download/`, `docs/` | The pages (sections, their styles and their script) || `css/threert.css` | The visual system: ink, bone and tungsten tokens, type, the nav and footer, the comparison and player components, the cards, steps and QR tiles of the inner pages |-| `js/threert.js` | The wipe comparison (and the clip that can play over its two stills), the synced camera-move player, the code highlighter |+| `js/threert.js` | The wipe comparison (and the clip that can play over its two stills), the reel behind the landing page's headline, the synced camera-move player, the code highlighter. A divider follows a finger only once it moves sideways, so scrolling past one does not move it || `js/site.js` | What the pages share: the visitor's platform, the release and the packages on this host, their links, QR codes || `js/devices.js` | The 3D device rows (three.js), with a still fallback when WebGL is off || `brand/` | The mark ("Three bounces": the three.js triangle, tilted as three.js draws it, and the closed light path inside it, which is three.js's own inner triangle) and its variants. `js/mark.js` draws it live in the lockup and on the landing page, and turns the path on hover |-| `media/` | The renders, WebP, and the hero clip, H.264. Generated; never retouched |+| `media/` | The renders, WebP, and the clips (the reel, the Bistro comparison), H.264. Generated; never retouched || `serve.ts`, `tools/` | Local server, static build, deploy, media and device-still generators; `tools/vendor.ts` names the npm files the pages import (three.js, qrcode-generator) || `worker.ts`, `wrangler.jsonc` | The Cloudflare Worker (www redirect, disk images from R2, byte ranges for the clips, static assets) and its config (threert.dev) || `releases/`, `play/` | Generated, not committed (above) |@@ -134,7 +136,24 @@ bun site/tools/media.ts # out/ -> site/media (stills, camera-move frabun site/tools/device-stills.ts # the 3D device rows -> site/media/devices (headless Chrome, software WebGL)```-The hero clip is recorded apart, on the machine at hand (it needs Bistro in the asset store: `bun scripts/orca.ts+The landing page's reel is recorded on the machine at hand, a clip a demo (`node tools/site-reel.ts` lists them and+what each needs: Bistro and the Quaternius mannequin, the Tokyo tiles, `tools/voxel-level/generate.ts` at mesh,+region and object granularity, the Kabukichō assets), then laid out and encoded:++```bash+node tools/site-reel.ts <clip> --probe # one frame a second, to compose a clip+node tools/site-reel.ts all # every clip, 8.5 s at 960 x 540, in lockstep at 60 fps -> out/site-reel/<clip>/+bun site/tools/reel.ts # out/site-reel -> site/media/reel/reel*.mp4, reel*.webp, reel.json+```++The three OpenStrike clips (`os-assault`, `os-inferno`, `os-dust2`) come from OpenStrike's own repository (the game+is not in this one; its maps are Counter-Strike's, brought by whoever builds it): its headless Mac host with+`tools/site-reel/openstrike-record.patch` applied saves every frame of a bot's match in lockstep+(`OPENSTRIKE_RECORD=<dir> OPENSTRIKE_RECORD_FRAMES=4500 OPENSTRIKE_SCALE=0.8 openstrike-mac --headless --play+--autopilot --squad 6 --skill 2 --map <map> --size 960x540`); 510 consecutive frames of each (the stretch with the+most shooting; for de_dust2 the opening run) go to `out/site-reel/os-<map>/` with a `meta.json` like the others'.++The Bistro comparison clip on Showcase is recorded apart (it needs Bistro in the asset store: `bun scripts/orca.tsbistro`, and ffmpeg):```bash@@ -146,7 +165,7 @@ bun site/tools/hero.ts # out/site-hero -> site/media/bistro/hero*.mpEvery frame of the clip is one frame the live renderer drew, in lockstep at 60 fps; the probe draws the same moveback to back, as on screen, with nothing else on the GPU, and `media/bistro/hero.json` keeps what it measured. The-landing page's footnote quotes that file (machine, size, scale, GPU ms): change the footnote when the clip changes.+Showcase's footnote quotes that file (machine, size, scale, GPU ms): change the footnote when the clip changes.The one committed was recorded on an Apple M3 Max: 1600 × 900 at render scale 0.5 (1920 × 1080 does not hold 60 fpsthere: 22 ms a frame at the lowest scale), a slow 2.2 s stretch of the scene's camera move taken in 6 s.diff --git a/site/css/threert.css b/site/css/threert.cssindex 52e662d..097a277 100644--- a/site/css/threert.css+++ b/site/css/threert.css@@ -100,6 +100,14 @@ a:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px soli.cmp .pa, .cmp .pb { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }.cmp .pb { clip-path: inset(0 0 0 var(--x, 50%)); }.cmp img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }+/* A reel behind a page's opening words (js/threert.js, backdrop): a still, the clip over it once it plays. */+.backdrop { position: absolute; inset: 0; overflow: hidden; background: #000; }+.backdrop img, .backdrop video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }+.backdrop video { opacity: 0; transition: opacity 0.6s; }+.backdrop.playing video { opacity: 1; }+.backdrop .pp { position: absolute; z-index: 6; right: 32px; bottom: 30px; width: 34px; height: 34px; border-radius: 50%; border: 1px solid rgba(236, 232, 225, 0.25); background: rgba(8, 9, 11, 0.6); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); color: #ece8e1; display: grid; place-items: center; cursor: pointer; padding: 0; opacity: 0.7; transition: opacity 0.2s; }+.backdrop .pp:hover, .backdrop .pp:focus-visible { opacity: 1; }+.backdrop .pp[hidden] { display: none; }/* A clip over the stills (js/threert.js, clip): a canvas a pane, shown once it plays; its pause button. */.cmp canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; opacity: 0; transition: opacity 0.5s; }.cmp.playing canvas { opacity: 1; }diff --git a/site/index.html b/site/index.htmlindex 49e6bb9..cca4a87 100644--- a/site/index.html+++ b/site/index.html@@ -9,14 +9,13 @@<link rel="stylesheet" href="css/threert.css"><script type="importmap">{ "imports": { "three": "./vendor/three/three.module.js", "three/addons/": "./vendor/three/addons/" } }</script><style>- /* ---- Hero: the comparison is the page ---- */+ /* ---- Hero: a reel of what the engine draws, the words over its darker side ---- */.hero { position: relative; height: min(100vh, 1000px); min-height: 640px; overflow: hidden; background: #000; }- .hero .cmp { position: absolute; inset: 0; aspect-ratio: auto; border-radius: 0; }- .hero .cmp .lab { top: auto; bottom: 32px; }- .hero .cmp .lab.a { left: 32px; } .hero .cmp .lab.b { right: 32px; }- .hero .cmp::after { content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none; background: linear-gradient(90deg, rgba(6,7,9,.86) 0%, rgba(6,7,9,.55) 34%, rgba(6,7,9,0) 62%), linear-gradient(180deg, rgba(6,7,9,.7) 0%, rgba(6,7,9,0) 16%), linear-gradient(0deg, rgba(6,7,9,.6) 0%, rgba(6,7,9,0) 16%); }- .hero .cmp .knob { top: 74%; }- .hero .cmp .pp { right: auto; left: 50%; bottom: 30px; margin-left: -17px; }+ .hero .backdrop .lab { top: auto; bottom: 32px; left: 32px; z-index: 6; }+ .hero .backdrop .lab i { background: var(--tungsten); box-shadow: 0 0 8px var(--tungsten); }+ .hero .backdrop::after { content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none; background: linear-gradient(90deg, rgba(6,7,9,.93) 0%, rgba(6,7,9,.8) 30%, rgba(6,7,9,.3) 58%, rgba(6,7,9,0) 76%), linear-gradient(180deg, rgba(6,7,9,.72) 0%, rgba(6,7,9,0) 16%), linear-gradient(0deg, rgba(6,7,9,.66) 0%, rgba(6,7,9,0) 16%); }+ /* A screen held upright: the words run the width, so the reel darkens from the top instead. */+ @media (max-aspect-ratio: 4/5) { .hero .backdrop::after { background: linear-gradient(180deg, rgba(6,7,9,.9) 0%, rgba(6,7,9,.78) 46%, rgba(6,7,9,.28) 74%, rgba(6,7,9,.5) 100%); } .hero .backdrop .lab { left: 20px; bottom: 22px; } .hero .backdrop .pp { right: 20px; bottom: 20px; } }.hero .copy { position: absolute; z-index: 7; left: 0; right: 0; top: 132px; pointer-events: none; }.hero .copy .wrap { display: grid; gap: 24px; }.hero .copy a { pointer-events: auto; }@@ -150,7 +149,7 @@</nav><header class="hero">- <div class="cmp" id="hero" data-a="media/bistro/hero-three.webp" data-b="media/bistro/hero-rt.webp" data-video="media/bistro/hero.mp4" data-video-sm="media/bistro/hero-720.mp4" data-la="three.js" data-lb="ThreeRT" data-x="44" data-intro></div>+ <div class="backdrop" id="hero" data-poster="media/reel/reel.webp" data-video="media/reel/reel.mp4" data-poster-tall="media/reel/reel-tall.webp" data-video-tall="media/reel/reel-tall.mp4"><div class="lab"><i></i><span>ThreeRT, live<small>this repository’s demos and OpenStrike</small></span></div></div><div class="copy"><div class="wrap"><h1 class="h-display">Path tracing<span class="l2 ray-text">at 60 fps.</span></h1>@@ -329,14 +328,14 @@<div class="site"><a href="showcase/">Showcase</a><a href="download/">Download</a><a href="docs/">Docs</a><a href="https://github.com/taichi-dev/ThreeRT" rel="noopener">GitHub</a></div></div><div class="note">- <p><sup>1</sup> To our knowledge. 60 fps measured on an Apple M5 MacBook at 1280 × 720 output with dynamic resolution, along each scene’s own camera path; three.js r187 in Chrome on the same machine. The clip at the top of this page is ThreeRT live on an Apple M3 Max at 1600 × 900 (render scale 0.5), every frame as it drew it: 12.8 ms of GPU time a frame at the median, 14.8 ms at the 95th percentile, none over 16.7 ms.</p>- <p>Amazon Lumberyard Bistro: Amazon Lumberyard (2017). Zero-Day: Mike Winkelmann (Beeple) and Kate Anderson (2019). Both from NVIDIA’s Open Research Content Archive (ORCA), CC BY 4.0, converted from FBX to glTF. Damaged Helmet: Khronos glTF sample models. three.js is an independent open-source project; ThreeRT is not affiliated with it.</p>+ <p><sup>1</sup> To our knowledge. 60 fps measured on an Apple M5 MacBook at 1280 × 720 output with dynamic resolution, along each scene’s own camera path; three.js r187 in Chrome on the same machine. The reel at the top of this page is ThreeRT live on an Apple M3 Max: this repository’s demos and OpenStrike, a shooter built on the engine, each clip recorded frame by frame at 60 fps at 960 × 540 (render scale 0.7 to 1).</p>+ <p>Amazon Lumberyard Bistro: Amazon Lumberyard (2017). Zero-Day: Mike Winkelmann (Beeple) and Kate Anderson (2019). Both from NVIDIA’s Open Research Content Archive (ORCA), CC BY 4.0, converted from FBX to glTF. Damaged Helmet: Khronos glTF sample models. Tokyo: 3D city model, Project PLATEAU (MLIT Japan); elevation and aerial photos, GSI; roads and places © OpenStreetMap contributors. The maps in the OpenStrike clips (cs_assault, de_inferno, de_dust2) are Counter-Strike maps, © Valve, and part of neither project. three.js is an independent open-source project; ThreeRT is not affiliated with it.</p></div></div></footer><script type="module">- import { $, $$, compare, sequence, seg, reveal, highlight } from "./js/threert.js";+ import { $, $$, backdrop, compare, sequence, seg, reveal, highlight } from "./js/threert.js";import { downloadButtons, packages, packageLinks } from "./js/site.js";// Sections fade in first, so a part that fails below (a missing three.js, a failed fetch) never blanks the page.@@ -355,7 +354,7 @@guard("download", () => downloadButtons());guard("comparisons", () => {- compare($("#hero"));+ backdrop($("#hero"));for (const el of $$(".details .cmp")) compare(el);for (const el of $$(".seqp")) sequence(el);});diff --git a/site/js/threert.js b/site/js/threert.jsindex a3eef5d..1542c62 100644--- a/site/js/threert.js+++ b/site/js/threert.js@@ -8,6 +8,33 @@ export const $$ = (s, r = document) => [...r.querySelectorAll(s)];const clamp = (v, a, b) => Math.min(b, Math.max(a, v));const KNOB = `<svg width="18" height="12" viewBox="0 0 18 12" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M5.5 1.5 1 6l4.5 4.5M12.5 1.5 17 6l-4.5 4.5"/></svg>`;+/**+ * Dragging a divider. A mouse drags from where it is pressed. A finger does only once it has moved sideways: a touch+ * that turns out to be a scroll (or a tap on the way past) leaves the divider where it was. `move(e)` places it.+ */+function dragging(el, move, skip = () => false) {+ let drag = false, from = null;+ el.addEventListener("pointerdown", (e) => {+ if (e.target.closest("button") || skip(e)) return;+ if (e.pointerType === "touch") { from = [e.clientX, e.clientY]; return; }+ drag = true;+ el.setPointerCapture(e.pointerId);+ move(e);+ });+ el.addEventListener("pointermove", (e) => {+ if (from && !drag) {+ const dx = Math.abs(e.clientX - from[0]), dy = Math.abs(e.clientY - from[1]);+ if (dx > 10 && dx > 1.5 * dy) { drag = true; el.setPointerCapture(e.pointerId); }+ else if (dy > 10) from = null;+ }+ if (drag) move(e);+ });+ const end = () => { drag = false; from = null; };+ el.addEventListener("pointerup", end);+ el.addEventListener("pointercancel", end); // a touch the browser took as a scroll+ return () => drag;+}+const label = (cls, l, s) => `<div class="lab ${cls}"><i></i><span>${l ?? ""}${s ? `<small>${s}</small>` : ""}</span></div>`;/** Wipe comparison. Drag (or click, or arrow keys) to move the divider; `el.cmp.set({...})` swaps the pair. */@@ -36,12 +63,9 @@ export function compare(el) {};set({});setX(x);- let drag = false;const at = (e) => setX(((e.clientX - el.getBoundingClientRect().left) / el.clientWidth) * 100);- el.addEventListener("pointerdown", (e) => { drag = true; el.setPointerCapture(e.pointerId); at(e); });- el.addEventListener("pointermove", (e) => { if (drag || d.hover !== undefined) at(e); });- el.addEventListener("pointerup", () => (drag = false));- el.addEventListener("pointercancel", () => (drag = false));+ const dragged = dragging(el, at);+ if (d.hover !== undefined) el.addEventListener("pointermove", (e) => { if (e.pointerType !== "touch") at(e); });el.addEventListener("keydown", (e) => {if (e.key === "ArrowLeft" || e.key === "ArrowRight") { setX(x + (e.key === "ArrowLeft" ? -4 : 4)); e.preventDefault(); }});@@ -53,7 +77,7 @@ export function compare(el) {const from = x, t0 = performance.now();const step = (t) => {const k = clamp((t - t0) / 1600, 0, 1);- if (drag) return;+ if (dragged()) return;setX(from + Math.sin(k * Math.PI * 2) * 14 * (1 - k));if (k < 1) requestAnimationFrame(step);};@@ -110,7 +134,6 @@ function clip(el, panes) {if (visible && !paused) v.play().then(() => { if (!v.requestVideoFrameCallback) requestAnimationFrame(tick); }, () => {});else v.pause();};- pp.addEventListener("pointerdown", (e) => e.stopPropagation()); // not a drag of the dividerpp.addEventListener("click", () => { paused = !paused; state(); });new IntersectionObserver(([en]) => {visible = en.isIntersecting;@@ -122,6 +145,40 @@ function clip(el, panes) {}, { threshold: 0.05 }).observe(el);}+/**+ * A reel behind a page's opening words: a still (`data-poster`), and over it a clip (`data-video`) that plays, muted+ * and looping, while it is on screen. A screen taller than it is wide gets `data-video-tall` / `data-poster-tall`,+ * laid out for it. Nothing in it takes a touch, so a finger scrolling the page passes over it; a button pauses it.+ * The still stays where the clip should not or cannot play (reduced motion, a data saver, autoplay refused).+ */+export function backdrop(el) {+ const d = el.dataset, tall = !!d.videoTall && matchMedia("(max-aspect-ratio: 4/5)").matches;+ const img = el.appendChild(Object.assign(new Image(), { alt: "", draggable: false, src: (tall && d.posterTall) || d.poster }));+ img.decoding = "async";+ if (matchMedia("(prefers-reduced-motion: reduce)").matches || navigator.connection?.saveData) return;+ const v = el.appendChild(Object.assign(document.createElement("video"), { muted: true, loop: true, playsInline: true, preload: "auto" }));+ v.setAttribute("muted", "");+ v.setAttribute("playsinline", "");+ v.setAttribute("aria-hidden", "true");+ v.disablePictureInPicture = true;+ const pp = el.appendChild(Object.assign(document.createElement("button"), { className: "pp", type: "button", hidden: true }));+ const ICON = { pause: `<svg width="12" height="12" viewBox="0 0 12 12" aria-hidden="true"><rect x="2" y="1.5" width="3" height="9" fill="currentColor"/><rect x="7" y="1.5" width="3" height="9" fill="currentColor"/></svg>`, play: `<svg width="12" height="12" viewBox="0 0 12 12" aria-hidden="true"><path d="M3 1.5v9l7.5-4.5z" fill="currentColor"/></svg>` };+ let visible = false, paused = false;+ v.addEventListener("playing", () => { el.classList.add("playing"); pp.hidden = false; }, { once: true });+ const state = () => {+ pp.innerHTML = paused ? ICON.play : ICON.pause;+ pp.setAttribute("aria-label", paused ? "Play the reel" : "Pause the reel");+ if (visible && !paused) v.play().catch(() => {});+ else v.pause();+ };+ pp.addEventListener("click", () => { paused = !paused; state(); });+ new IntersectionObserver(([en]) => {+ visible = en.isIntersecting;+ if (visible && !v.src) v.src = (tall && d.videoTall) || d.video;+ state();+ }, { threshold: 0.05 }).observe(el);+}+/** Plays the 60-pose camera move of both engines in lockstep, wiped like a comparison. */export function sequence(el) {const d = el.dataset, n = +(d.n ?? 60), fps = +(d.fps ?? 10);@@ -174,12 +231,8 @@ export function sequence(el) {if (visible && !raf) raf = requestAnimationFrame(loop);}, { rootMargin: "400px" });io.observe(el);- let drag = false;const at = (e) => { x = clamp(((e.clientX - el.getBoundingClientRect().left) / el.clientWidth) * 100, 0, 100); draw(); };- el.addEventListener("pointerdown", (e) => { if (e.target.closest(".ctl")) return; drag = true; el.setPointerCapture(e.pointerId); at(e); });- el.addEventListener("pointermove", (e) => drag && at(e));- el.addEventListener("pointerup", () => (drag = false));- el.addEventListener("pointercancel", () => (drag = false)); // a touch the browser took as a scroll+ dragging(el, at, (e) => !!e.target.closest(".ctl"));pp.addEventListener("click", () => { playing = !playing; icon(); });$(".track", el).addEventListener("click", (e) => {const r = e.currentTarget.getBoundingClientRect();diff --git a/site/media/reel/reel-tall.mp4 b/site/media/reel/reel-tall.mp4new file mode 100644index 0000000..564e344Binary files /dev/null and b/site/media/reel/reel-tall.mp4 differdiff --git a/site/media/reel/reel-tall.webp b/site/media/reel/reel-tall.webpnew file mode 100644index 0000000..1700b3cBinary files /dev/null and b/site/media/reel/reel-tall.webp differdiff --git a/site/media/reel/reel.json b/site/media/reel/reel.jsonnew file mode 100644index 0000000..c3f5b6b--- /dev/null+++ b/site/media/reel/reel.json@@ -0,0 +1,268 @@+{+ "at": "2026-11-12T00:02:46.765Z",+ "wide": {+ "width": 1920,+ "height": 1080,+ "cols": 4,+ "rows": 3,+ "fps": 60,+ "seconds": 8,+ "clips": [+ {+ "id": "crowd",+ "what": "Bistro night with a crowd and traffic: 150 walkers, 60 vans with their lights on",+ "width": 960,+ "height": 540,+ "scale": 0.7,+ "machine": "Apple M3 Max",+ "commit": "b646a20",+ "gpu_ms": {+ "p50": 7.35,+ "p95": 7.81+ }+ },+ {+ "id": "os-assault",+ "what": "OpenStrike, path traced: a bot's match on cs_assault (frames 2170 to 2679 of a 75 s recording)",+ "width": 960,+ "height": 540,+ "scale": 0.8,+ "machine": null,+ "commit": null,+ "gpu_ms": null+ },+ {+ "id": "tokyo",+ "what": "Tokyo (PLATEAU city model) around Tokyo Tower from afternoon into night, the lamps coming on",+ "width": 960,+ "height": 540,+ "scale": 1,+ "machine": "Apple M3 Max",+ "commit": "b646a20",+ "gpu_ms": {+ "p50": 8.69,+ "p95": 11.05+ }+ },+ {+ "id": "kabukicho",+ "what": "Kabukicho Ichiban-gai at night in the rain: about 300 signs and their lights, a taxi",+ "width": 960,+ "height": 540,+ "scale": 0.7,+ "machine": "Apple M3 Max",+ "commit": "b646a20",+ "gpu_ms": {+ "p50": 9.14,+ "p95": 9.69+ }+ },+ {+ "id": "home",+ "what": "Daylight Home: golden hour, night with the lamps on, then the morning sun",+ "width": 960,+ "height": 540,+ "scale": 1,+ "machine": "Apple M3 Max",+ "commit": "b646a20",+ "gpu_ms": {+ "p50": 8.98,+ "p95": 11.21+ }+ },+ {+ "id": "jewellery",+ "what": "Jeweller's Window: the display turning under the soft boxes",+ "width": 960,+ "height": 540,+ "scale": 1,+ "machine": "Apple M3 Max",+ "commit": "b646a20",+ "gpu_ms": {+ "p50": 8.61,+ "p95": 9.05+ }+ },+ {+ "id": "os-inferno",+ "what": "OpenStrike, path traced: a bot's match on de_inferno (frames 2485 to 2994 of a 75 s recording)",+ "width": 960,+ "height": 540,+ "scale": 0.8,+ "machine": null,+ "commit": null,+ "gpu_ms": null+ },+ {+ "id": "museum",+ "what": "Sculpture Gallery: walking up to the marble bust and the bronze lion",+ "width": 960,+ "height": 540,+ "scale": 1,+ "machine": "Apple M3 Max",+ "commit": "b646a20",+ "gpu_ms": {+ "p50": 6.01,+ "p95": 7.12+ }+ },+ {+ "id": "voxels",+ "what": "The voxel level under explosions: what is cut loose falls",+ "width": 960,+ "height": 540,+ "scale": 1,+ "machine": "Apple M3 Max",+ "commit": "b646a20",+ "gpu_ms": {+ "p50": 6.97,+ "p95": 7.97+ }+ },+ {+ "id": "colour",+ "what": "Colour Lab: the three lamps switched one by one",+ "width": 960,+ "height": 540,+ "scale": 1,+ "machine": "Apple M3 Max",+ "commit": "b646a20",+ "gpu_ms": {+ "p50": 9.24,+ "p95": 9.57+ }+ },+ {+ "id": "showroom",+ "what": "Boutique Showroom in the evening: walking to the sneaker, then the chair",+ "width": 960,+ "height": 540,+ "scale": 1,+ "machine": "Apple M3 Max",+ "commit": "b646a20",+ "gpu_ms": {+ "p50": 9.78,+ "p95": 10.77+ }+ },+ {+ "id": "os-dust2",+ "what": "OpenStrike, path traced: a bot's match on de_dust2 (frames 60 to 569 of a 75 s recording)",+ "width": 960,+ "height": 540,+ "scale": 0.8,+ "machine": null,+ "commit": null,+ "gpu_ms": null+ }+ ]+ },+ "tall": {+ "width": 720,+ "height": 1440,+ "cols": 2,+ "rows": 4,+ "fps": 60,+ "seconds": 8,+ "clips": [+ {+ "id": "kabukicho",+ "what": "Kabukicho Ichiban-gai at night in the rain: about 300 signs and their lights, a taxi",+ "width": 960,+ "height": 540,+ "scale": 0.7,+ "machine": "Apple M3 Max",+ "commit": "b646a20",+ "gpu_ms": {+ "p50": 9.14,+ "p95": 9.69+ }+ },+ {+ "id": "os-assault",+ "what": "OpenStrike, path traced: a bot's match on cs_assault (frames 2170 to 2679 of a 75 s recording)",+ "width": 960,+ "height": 540,+ "scale": 0.8,+ "machine": null,+ "commit": null,+ "gpu_ms": null+ },+ {+ "id": "home",+ "what": "Daylight Home: golden hour, night with the lamps on, then the morning sun",+ "width": 960,+ "height": 540,+ "scale": 1,+ "machine": "Apple M3 Max",+ "commit": "b646a20",+ "gpu_ms": {+ "p50": 8.98,+ "p95": 11.21+ }+ },+ {+ "id": "jewellery",+ "what": "Jeweller's Window: the display turning under the soft boxes",+ "width": 960,+ "height": 540,+ "scale": 1,+ "machine": "Apple M3 Max",+ "commit": "b646a20",+ "gpu_ms": {+ "p50": 8.61,+ "p95": 9.05+ }+ },+ {+ "id": "crowd",+ "what": "Bistro night with a crowd and traffic: 150 walkers, 60 vans with their lights on",+ "width": 960,+ "height": 540,+ "scale": 0.7,+ "machine": "Apple M3 Max",+ "commit": "b646a20",+ "gpu_ms": {+ "p50": 7.35,+ "p95": 7.81+ }+ },+ {+ "id": "os-inferno",+ "what": "OpenStrike, path traced: a bot's match on de_inferno (frames 2485 to 2994 of a 75 s recording)",+ "width": 960,+ "height": 540,+ "scale": 0.8,+ "machine": null,+ "commit": null,+ "gpu_ms": null+ },+ {+ "id": "museum",+ "what": "Sculpture Gallery: walking up to the marble bust and the bronze lion",+ "width": 960,+ "height": 540,+ "scale": 1,+ "machine": "Apple M3 Max",+ "commit": "b646a20",+ "gpu_ms": {+ "p50": 6.01,+ "p95": 7.12+ }+ },+ {+ "id": "colour",+ "what": "Colour Lab: the three lamps switched one by one",+ "width": 960,+ "height": 540,+ "scale": 1,+ "machine": "Apple M3 Max",+ "commit": "b646a20",+ "gpu_ms": {+ "p50": 9.24,+ "p95": 9.57+ }+ }+ ]+ }+}diff --git a/site/media/reel/reel.mp4 b/site/media/reel/reel.mp4new file mode 100644index 0000000..c8ab6c4Binary files /dev/null and b/site/media/reel/reel.mp4 differdiff --git a/site/media/reel/reel.webp b/site/media/reel/reel.webpnew file mode 100644index 0000000..71db346Binary files /dev/null and b/site/media/reel/reel.webp differdiff --git a/site/showcase/index.html b/site/showcase/index.htmlindex 0a55112..ea2f4c6 100644--- a/site/showcase/index.html+++ b/site/showcase/index.html@@ -80,13 +80,13 @@<section class="sec"><div class="wrap"><div class="feat rv">- <div class="seqp" data-scene="../media/bistro" data-la="three.js · 54 fps" data-lb="ThreeRT · 60 fps"></div>+ <div class="cmp" data-a="../media/bistro/hero-three.webp" data-b="../media/bistro/hero-rt.webp" data-video="../media/bistro/hero.mp4" data-video-sm="../media/bistro/hero-720.mp4" data-la="three.js" data-lb="ThreeRT · 60 fps" data-x="50"></div><div class="txt"><h2>Bistro night</h2><span class="by">Amazon Lumberyard Bistro · ORCA</span><p class="d">A street corner after dark. The string lights, the shop signs and the lamps are the light sources: each one lights the square in its own colour.</p><ul class="ticks"><li>Every emitter is a light</li><li>Warm light from the shop window and the wall lamp spills across the facade and the pavement</li></ul>- <p class="more">Drag the divider: three.js on the left, ThreeRT on the right, the same camera path.<sup>1</sup></p>+ <p class="more">Drag the divider: three.js on the left, ThreeRT on the right, the same camera path, recorded at 60 fps.<sup>1</sup></p></div></div><div class="feat flip rv">@@ -135,7 +135,7 @@<div class="site"><a href="../showcase/">Showcase</a><a href="../download/">Download</a><a href="../docs/">Docs</a><a href="https://github.com/taichi-dev/ThreeRT" rel="noopener">GitHub</a></div></div><div class="note">- <p><sup>1</sup> 60 fps measured on an Apple M5 MacBook at 1280 × 720 output with dynamic resolution, along each scene’s own camera path; three.js r187 in Chrome on the same machine.</p>+ <p><sup>1</sup> 60 fps measured on an Apple M5 MacBook at 1280 × 720 output with dynamic resolution, along each scene’s own camera path; three.js r187 in Chrome on the same machine. The Bistro clip is ThreeRT live on an Apple M3 Max at 1600 × 900 (render scale 0.5), every frame as it drew it: 12.8 ms of GPU time a frame at the median, 14.8 ms at the 95th percentile, none over 16.7 ms.</p><p>Amazon Lumberyard Bistro: Amazon Lumberyard (2017). Zero-Day: Mike Winkelmann (Beeple) and Kate Anderson (2019). Both from NVIDIA’s Open Research Content Archive (ORCA), CC BY 4.0, converted from FBX to glTF. Damaged Helmet: Khronos glTF sample models. three.js is an independent open-source project; ThreeRT is not affiliated with it.</p><p id="caseCredits" hidden></p></div>@@ -143,11 +143,11 @@</footer><script type="module">- import { $, $$, sequence, reveal } from "../js/threert.js";+ import { $, $$, compare, sequence, reveal } from "../js/threert.js";import { guard, packages, packageLinks, qrSvg, reachable } from "../js/site.js";reveal();- guard("camera moves", () => { for (const el of $$(".seqp")) sequence(el); });+ guard("camera moves", () => { for (const el of $$(".feat .cmp")) compare(el); for (const el of $$(".seqp")) sequence(el); });const esc = (s) => String(s).replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);diff --git a/site/tools/reel.ts b/site/tools/reel.tsnew file mode 100644index 0000000..efadeeb--- /dev/null+++ b/site/tools/reel.ts@@ -0,0 +1,63 @@+// Lays the landing page's reel out and encodes it, from the clips tools/site-reel.ts recorded (out/site-reel/<clip>):+// node tools/site-reel.ts all (and the OpenStrike clips: site/README.md, Media)+// bun site/tools/reel.ts [--crf 27] [--crf-sm 28]+// -> site/media/reel/reel.mp4 the grid for a wide screen: 4 x 3 clips, 1920 x 1080, 60 fps, an 8 s loop+// site/media/reel/reel-tall.mp4 the grid for a phone held upright: 2 x 4 clips, 720 x 1440+// site/media/reel/reel.webp, reel-tall.webp their first frames: what the page shows until the reel plays+// site/media/reel/reel.json the clips in each grid, in order, with how each was recorded+// A clip is 8.5 s of frames: the last half second is faded over the first, so every tile loops without a cut.+// H.264, so every browser plays it. Needs ffmpeg on PATH. Sources can be moved with THREERT_OUT (default <repo>/out).+import { $ } from "bun";+import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";+import { join, resolve } from "node:path";+import sharp from "sharp";++const site = resolve(import.meta.dir, "..");+const OUT = process.env.THREERT_OUT ?? join(site, "../out");+const src = join(OUT, "site-reel");+const media = join(site, "media/reel");+const args = process.argv.slice(2);+const opt = (k: string, d: string) => (args.includes(k) ? args[args.indexOf(k) + 1] : d);++/** The grids, row by row. The page's words sit over the left of the wide one and the top of the tall one. */+const WIDE = { cols: 4, rows: 3, tile: [480, 360], clips: ["crowd", "os-assault", "tokyo", "kabukicho", "home", "jewellery", "os-inferno", "museum", "voxels", "colour", "showroom", "os-dust2"] };+const TALL = { cols: 2, rows: 4, tile: [360, 360], clips: ["kabukicho", "os-assault", "home", "jewellery", "crowd", "os-inferno", "museum", "colour"] };+/** Between tiles: the page's ink, a pixel on each side. */+const GAP = 1, INK = "0x060709";++const meta = (id: string) => {+ const f = join(src, id, "meta.json");+ if (!existsSync(f)) throw new Error(`${id}: not recorded (${f} is missing)`);+ const m = JSON.parse(readFileSync(f, "utf8"));+ const n = readdirSync(join(src, id)).filter((x) => /^\d{4}\.png$/.test(x)).length;+ if (n !== m.frames) throw new Error(`${id}: ${n} frames, meta.json says ${m.frames}`);+ return m;+};++async function grid(name: string, g: typeof WIDE, crf: string) {+ const ms = g.clips.map(meta);+ const { fps, seconds, tail } = ms[0];+ if (ms.some((m) => m.fps !== fps || m.seconds !== seconds || m.tail !== tail)) throw new Error("the clips differ in length or frame rate");+ const main = Math.round(seconds * fps), [tw, th] = g.tile, [iw, ih] = [tw - 2 * GAP, th - 2 * GAP];+ const inputs = g.clips.flatMap((id) => ["-framerate", String(fps), "-i", join(src, id, "%04d.png")]);+ // A tile: the middle of the frame at the tile's shape, its tail faded over its start, the gap round it.+ const chains = g.clips.map((_, i) =>+ `[${i}:v]crop='min(iw,ih*${iw}/${ih})':'min(ih,iw*${ih}/${iw})',scale=${iw}:${ih}:flags=lanczos,split[m${i}][t${i}];` ++ `[m${i}]trim=end_frame=${main},setpts=PTS-STARTPTS[a${i}];` ++ `[t${i}]trim=start_frame=${main},setpts=PTS-STARTPTS,format=yuva444p,fade=t=out:st=0:d=${tail}:alpha=1[b${i}];` ++ `[a${i}][b${i}]overlay=eof_action=pass,pad=${tw}:${th}:${GAP}:${GAP}:color=${INK}[v${i}]`);+ const layout = g.clips.map((_, i) => `${(i % g.cols) * tw}_${Math.floor(i / g.cols) * th}`).join("|");+ const filter = `${chains.join(";")};${g.clips.map((_, i) => `[v${i}]`).join("")}xstack=inputs=${g.clips.length}:layout=${layout},format=yuv420p[out]`;+ const out = join(media, `${name}.mp4`);+ await $`ffmpeg -hide_banner -loglevel error -y ${inputs} -filter_complex ${filter} -map [out] -r ${fps} -c:v libx264 -preset slower -crf ${crf} -profile:v high -g ${fps} -color_primaries bt709 -color_trc bt709 -colorspace bt709 -movflags +faststart -an ${out}`;+ const still = join(src, `${name}-first.png`);+ await $`ffmpeg -hide_banner -loglevel error -y -i ${out} -frames:v 1 ${still}`;+ await sharp(still).webp({ quality: 84, effort: 6 }).toFile(join(media, `${name}.webp`));+ console.log(`${name}.mp4: ${g.cols} x ${g.rows} of ${tw} x ${th}, ${(statSync(out).size / 1048576).toFixed(1)} MiB`);+ return { width: g.cols * tw, height: g.rows * th, cols: g.cols, rows: g.rows, fps, seconds, clips: ms.map((m) => ({ id: m.id, what: m.what, width: m.width, height: m.height, scale: m.scale, machine: m.machine ?? null, commit: m.commit ?? null, gpu_ms: m.gpu_ms ?? null })) };+}++mkdirSync(media, { recursive: true });+const wide = await grid("reel", WIDE, opt("--crf", "27"));+const tall = await grid("reel-tall", TALL, opt("--crf-sm", "28"));+writeFileSync(join(media, "reel.json"), JSON.stringify({ at: new Date().toISOString(), wide, tall }, null, 1) + "\n");diff --git a/tools/site-reel.ts b/tools/site-reel.tsnew file mode 100644index 0000000..03f7dec--- /dev/null+++ b/tools/site-reel.ts@@ -0,0 +1,161 @@+// The landing page's reel: short clips of the repository's demos, every one drawn by the live renderer (ray traced,+// nothing compared against), for site/tools/reel.ts to lay out as one grid and encode.+//+// node tools/site-reel.ts <clip>[,<clip>...] | all [--probe] [--force] [--width 960] [--height 540]+//+// A clip is a game or scene of this repository, how it is set going (room, events), what happens while it runs (events+// at times) and where the camera goes. It is recorded in lockstep at 60 fps, a PNG a frame: every frame of a clip is+// one frame the live renderer drew, with its history carried from the frame before, as on screen.+// --probe draws the clip the same way but keeps one frame a second: for composing a clip before recording it.+// -> out/site-reel/<clip>/NNNN.png (seconds + 0.5 s of frames: the half second lets the encoder fade a loop's end into+// its start), meta.json (machine, size, scale, GPU ms a frame: a recording pauses for its PNG, so these are a+// little better than back to back; tools/site-hero.ts --probe is the tool for a figure to quote)+import { execFileSync } from "node:child_process";+import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";+import { join } from "node:path";+import { BISTRO } from "../scenes/bistro.ts";+import { installAssets } from "../showcase/assets.ts";+import { bundleGame } from "./bundle-game.ts";+import { frameStats, rendererBin } from "./lib/bench.ts";+import { gltfCameraPath } from "./lib/gltf-camera.ts";+import { startLive } from "./lib/live.ts";+import { root } from "./three/browser.ts";++const FPS = 60, TAIL = 0.5;+type Pose = { pos: number[]; target: number[]; tan?: number };+type Cmd = Record<string, unknown>;+interface Clip {+ what: string;+ src: string;+ room?: string;+ seconds?: number;+ /** Seconds of the scene's clock before the recording starts (the first frames' history; default 4). */+ settle?: number;+ /** Render scale (a recording cannot use dynamic resolution: its pauses read as headroom). */+ scale?: number;+ bounces?: number;+ /** Sent once, before settling. */+ before?: Cmd[];+ /** Sent at these times (s) into the recording. */+ at?: [number, Cmd][];+ /** The camera at time t (s), when the clip moves it. */+ camera?: (t: number) => Pose;+}+const ev = (type: string, payload: unknown = {}): Cmd => ({ cmd: "event", type, payload });+const ease = (u: number) => (1 - Math.cos(Math.PI * Math.max(0, Math.min(1, u)))) / 2;+const lerp = (a: number[], b: number[], u: number) => a.map((v, i) => v + (b[i] - v) * u);+/** From one pose to another and back, eased at both ends: a move that loops. */+const sway = (a: Pose, b: Pose, seconds: number) => (t: number): Pose => {+ const u = ease(t < seconds / 2 ? t / (seconds / 2) : 2 - t / (seconds / 2));+ return { pos: lerp(a.pos, b.pos, u), target: lerp(a.target, b.target, u), tan: a.tan };+};++let bistroPath: ReturnType<typeof gltfCameraPath> | undefined;+const bistro = (t: number) => (bistroPath ??= gltfCameraPath(join(root, BISTRO), "Camera")).at(t);++const CLIPS: Record<string, Clip> = {+ crowd: {+ what: "Bistro night with a crowd and traffic: 150 walkers, 60 vans with their lights on",+ src: "games/bistro-crowd/bistro-crowd.game.ts", scale: 0.7,+ camera: (t) => bistro(0.4 + 0.22 * t),+ },+ tokyo: {+ what: "Tokyo (PLATEAU city model) around Tokyo Tower from afternoon into night, the lamps coming on",+ // The room's clock runs over the scene's first 10.5 s; the recording is its last 8.5: 16:00 to 17:42.+ src: "games/tokyo/tokyo-tod.game.ts", room: "shiba-15.6-17.7-10.5-r1600", settle: 2,+ },+ voxels: {+ what: "The voxel level under explosions: what is cut loose falls",+ src: "games/voxel-level/level-destruction.game.ts", at: [[0.3, ev("show")]],+ },+ kabukicho: {+ what: "Kabukicho Ichiban-gai at night in the rain: about 300 signs and their lights, a taxi",+ src: "games/kabukicho/kabukicho.game.ts", scale: 0.7, before: [ev("traffic")],+ },+ home: {+ what: "Daylight Home: golden hour, night with the lamps on, then the morning sun",+ src: "showcase/daylight-home/daylight-home.game.ts", at: [[1.0, ev("time")], [4.6, ev("time")]],+ },+ jewellery: {+ what: "Jeweller's Window: the display turning under the soft boxes",+ src: "showcase/jewellery/jewellery.game.ts",+ },+ museum: {+ what: "Sculpture Gallery: walking up to the marble bust and the bronze lion",+ src: "showcase/museum/museum.game.ts", at: [[0.6, ev("next")], [4.4, ev("next")]],+ },+ colour: {+ what: "Colour Lab: the three lamps switched one by one",+ src: "showcase/colour-lab/colour-lab.game.ts", at: [[1.2, ev("red")], [2.4, ev("red")], [3.4, ev("green")], [4.6, ev("green")], [5.6, ev("blue")], [6.8, ev("blue")]],+ },+ moon: {+ what: "Moon Phases: a month of the Moon round the Earth",+ src: "showcase/moon-phases/moon-phases.game.ts",+ },+ showroom: {+ what: "Boutique Showroom in the evening: walking to the sneaker, then the chair",+ src: "showcase/showroom/showroom.game.ts", at: [[0.6, ev("next")], [4.4, ev("next")]],+ },+};++const args = process.argv.slice(2);+const opt = (k: string, d: string) => (args.includes(k) ? args[args.indexOf(k) + 1] : d);+const probe = args.includes("--probe");+const width = Number(opt("--width", "960")), height = Number(opt("--height", "540"));+const ids = !args[0] || args[0].startsWith("-") ? [] : args[0] === "all" ? Object.keys(CLIPS) : args[0].split(",");+if (!ids.length) {+ console.log(Object.entries(CLIPS).map(([id, c]) => `${id.padEnd(10)} ${c.what}`).join("\n"));+ process.exit(0);+}+installAssets();+const pad = (k: number) => String(k).padStart(4, "0");++for (const id of ids) {+ const c = CLIPS[id];+ if (!c) throw new Error(`unknown clip ${id} (${Object.keys(CLIPS).join(", ")})`);+ const dir = join(root, "out/site-reel", probe ? `${id}-probe` : id);+ rmSync(dir, { recursive: true, force: true });+ mkdirSync(dir, { recursive: true });+ const bundle = join(root, "out/bundles", `reel-${id}.js`);+ await bundleGame(join(root, c.src), bundle);+ const frameLog = join(dir, "frames.jsonl");+ const seconds = c.seconds ?? 8, n = Math.round((seconds + TAIL) * FPS), scale = c.scale ?? 1;+ const live = startLive({ bin: rendererBin, assets: root, presets: join(root, "presets"), bundles: join(root, "out/bundles"), label: `reel ${id}` }, bundle, { scale: String(scale), frameLog, width, height, bounces: c.bounces, room: c.room });+ try {+ await live.firstFrame;+ for (const cmd of c.before ?? []) live.send(cmd);+ if (c.camera) live.send({ cmd: "camera", ...c.camera(0) });+ // Lockstep from the first frame: the scene's clock is the frame count, so a clip starts at the same moment of its+ // scene every time. The settling frames are drawn like the rest and not kept.+ live.send({ cmd: "lockstep", dt: 1 / FPS });+ const settle = Math.round((c.settle ?? 4) * FPS);+ live.send({ cmd: "frames", n: settle, sync: "settled" });+ await live.wait((l) => l.endsWith("sync settled"), 300_000);+ const pending = [...(c.at ?? [])].sort((a, b) => a[0] - b[0]);+ for (let k = 0; k < n; k++) {+ const t = k / FPS;+ while (pending.length && pending[0][0] <= t) live.send(pending.shift()![1]);+ const keep = !probe || k % FPS === 0;+ const f = join(dir, `${pad(probe ? k / FPS : k)}.png`);+ const step: Cmd = { ...(c.camera ? { cmd: "camera", ...c.camera(t) } : { cmd: "frames" }), ...(c.camera ? { frames: 1 } : { n: 1 }), ...(keep ? { snapshot: f } : { sync: `k${k}` }) };+ live.send(step);+ await live.wait((l) => (keep ? l.includes(f) : l.endsWith(`sync k${k}`)), 120_000);+ }+ } finally {+ await live.quit().catch(() => {});+ }+ // (The log is complete once the renderer has quit; the recording is its last n frames.)+ const first = await live.firstFrame;+ type F = { gpu: number };+ const logged = readFileSync(frameLog, "utf8").trim().split("\n").filter(Boolean).flatMap((l) => { try { return [JSON.parse(l) as F]; } catch { return []; } }).slice(-n);+ const g = frameStats(logged.map((x) => x.gpu));+ const meta = {+ id, what: c.what, at: new Date().toISOString(), machine: execFileSync("sysctl", ["-n", "machdep.cpu.brand_string"], { encoding: "utf8" }).trim(),+ commit: execFileSync("git", ["rev-parse", "--short", "HEAD"], { cwd: root, encoding: "utf8" }).trim(),+ width, height, fps: FPS, seconds, tail: TAIL, frames: n, scale, room: c.room ?? null, load_s: +(first / 1000).toFixed(1),+ gpu_ms: { p50: +g.p50.toFixed(2), p95: +g.p95.toFixed(2) }, over_budget: logged.filter((x) => x.gpu > 1000 / FPS).length,+ };+ writeFileSync(join(dir, "meta.json"), JSON.stringify(meta, null, 1) + "\n");+ console.log(`${id}${probe ? " (probe)" : ""}: ${n} frames at ${width} x ${height}, scale ${scale}; GPU ms p50 ${meta.gpu_ms.p50}, p95 ${meta.gpu_ms.p95}, ${meta.over_budget} over 16.7; loaded in ${meta.load_s} s -> ${dir}`);+ for (const l of [...new Set(live.lines.filter((x) => /fail|error|panic|not found|missing/i.test(x)))].slice(0, 6)) console.log(`! ${l.slice(0, 240)}`);+}diff --git a/tools/site-reel/openstrike-record.patch b/tools/site-reel/openstrike-record.patchnew file mode 100644index 0000000..f38403d--- /dev/null+++ b/tools/site-reel/openstrike-record.patch@@ -0,0 +1,60 @@+diff --git a/playground/openstrike/host/src/lib.rs b/playground/openstrike/host/src/lib.rs+index bb9fa47..79125ef 100644+--- a/playground/openstrike/host/src/lib.rs++++ b/playground/openstrike/host/src/lib.rs+@@ -909,11 +909,13 @@ impl State {+ fn frame(&mut self) -> Result<()> {+ let t_frame = Instant::now();+ let period = Duration::from_secs_f64(1.0 / FPS as f64);+- if t_frame + Duration::from_millis(2) < self.next_frame {++ // OPENSTRIKE_RECORD (run_headless): every call is a frame, a content frame apart, however long it took.++ let record = std::env::var_os("OPENSTRIKE_RECORD").is_some();++ if !record && t_frame + Duration::from_millis(2) < self.next_frame {+ return Ok(());+ }+ self.next_frame = if t_frame > self.next_frame + period { t_frame + period } else { self.next_frame + period };+- let dt = self.last.elapsed().as_secs_f32().min(0.1);++ let dt = if record { 1.0 / FPS as f32 } else { self.last.elapsed().as_secs_f32().min(0.1) };+ self.last = t_frame;++ // A pending load: show the loading card for a couple of frames, then block on the load.+@@ -1405,14 +1407,39 @@ fn run_headless(args: &[String]) {+ let mut t0 = Instant::now();+ let mut next = 0;+ let mut paused = false;++ // OPENSTRIKE_RECORD=<dir>: a clip. Once the map is loaded the game runs in lockstep (a content frame a call, see++ // `frame`), and after OPENSTRIKE_RECORD_AFTER seconds of it every frame is saved, OPENSTRIKE_RECORD_FRAMES of them++ // (<dir>/0000.png ...). With `--play --autopilot` that is a bot's match as a player sees it, frame for frame.++ let record = std::env::var_os("OPENSTRIKE_RECORD").map(std::path::PathBuf::from);++ let env_num = |k: &str, d: f32| std::env::var(k).ok().and_then(|v| v.parse::<f32>().ok()).unwrap_or(d);++ let (rec_after, rec_frames) = ((env_num("OPENSTRIKE_RECORD_AFTER", 4.0) * FPS as f32) as usize, env_num("OPENSTRIKE_RECORD_FRAMES", 510.0) as usize);++ let (mut played, mut written) = (0usize, 0usize);+ loop {+ // (The seconds run from the end of the load.)+ if s.loading.is_some() {+ t0 = Instant::now();+ }++ if let Some(dir) = &record {++ if s.loading.is_none() {++ if played >= rec_after {++ if written >= rec_frames {++ break;++ }++ s.screenshot = Some(dir.join(format!("{written:04}.png")));++ written += 1;++ }++ played += 1;++ }++ }+ if let Err(e) = s.frame() {+ eprintln!("openstrike-rt: frame: {e:#}");+ }++ if record.is_some() {++ if s.quit {++ break;++ }++ continue;++ }+ if s.quit && s.screenshot.is_none() {+ break;+ }