From 4d73db4c6b98e2095787291a4c64f6ca26b91ec7 Mon Sep 17 00:00:00 2001 From: William Wong Date: Mon, 19 Oct 2026 15:31:05 +0100 Subject: [PATCH] feat(perform): follow the body, and let the room set the stage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The stage camera was framed on a body at the origin and real models do not stay there: a line covers 2.11 m on Kimodo and 3.89 m on SnapMoGen. Measured on a body covering that 3.89 m, it was on screen for 55% of the phrase and walked out of its own spotlight, which is a radial gradient pinned to the centre of the viewport. The camera now eases after the pelvis in x and z, trailing it by at most 0.27 m so it reads as an operator following a dancer rather than a body pinned to the glass. It moves the viewpoint and never the motion. Displacement is a finding in this project — how far a body goes is part of how the model read the prompt — so nothing is subtracted, the floor still streams past underneath and the floor path still carries the whole trace. That is a different thing from pelvis-aligning, which stays parked. The pan arithmetic is in follow.ts, out of the animation loop, because a camera that overshoots or that eases differently on a 60 Hz laptop and a 120 Hz projector is wrong in a way that is hard to see. 1 - exp(-rate * dt) composes exactly, so two half-steps land where one whole step does; measured drift of the viewer's own angle and distance while following is 3.6e-15 m. Then three controls, because what a room needs is decided in the room: - F, and a checkbox, for the camera follow. On entering performance, off leaving, overridable at any point. - O, and a checkbox, for the phrase under the body. Hiding it leaves the body alone on the stage. - A speed control, T to cycle and [ ] to step. ONE list of speeds: there were briefly two, a short cycle for T and the full set for the select, and the only thing that bought was 1.5x and 2x being unreachable by the key whose job is changing the speed. tempo.ts is tested for exactly that. The transport's toggles are hidden while performing, so the visible controls serve the bench and the keys do the work in the room — the same reason esc is always live. The overlay now lists them. Performance opens at real time rather than half speed. The argument for 0.5x still holds, but it is the performer's judgement and not something to impose on arrival, and it only became reasonable to drop once every speed was a keypress away. README.md, usage.md and lecture-performance.md all claimed half speed and are corrected rather than left contradicting the code. Two legibility fixes for a projector, both measured against the performance background: - The keyboard hints rendered at 1.73:1 — --ink-faint at opacity 0.55, where text that small wants 4.5:1, and the base colour alone only reaches 3.22:1. The whole meta row is --ink-dim now at 7.63:1, 11px to 12px. - A long line covered the body it was describing. Day 4's level-E prompts average 38.7 words, so a line really can be a paragraph. The phrase is capped at 30vh at 24px, and when it is genuinely cut it fades out instead of ending on a clean edge, because a clean edge reads as a finished sentence and misrepresents what the body is answering. What this does not settle: with the ghost-cloud on it follows the selected body only, so the far siblings leave the frame — and the far siblings are where roughly three quarters of the spread lives. That stays a research decision, recorded in roadmap.md, to be made from the back of a room. The spotlight still does not travel either; following the body centres it and therefore lights it, which fixes the symptom and not the cause. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_014yJSPiRjB5WvTH2x4LB8V6 --- README.md | 2 +- docs/lecture-performance.md | 14 +++-- docs/roadmap.md | 30 ++++++++--- docs/usage.md | 47 ++++++++++++++-- frontend/app/index.html | 29 +++++++++- frontend/app/src/follow.test.ts | 71 ++++++++++++++++++++++++ frontend/app/src/follow.ts | 65 ++++++++++++++++++++++ frontend/app/src/main.ts | 95 ++++++++++++++++++++++++++++----- frontend/app/src/renderer.ts | 80 +++++++++++++++++++++++++-- frontend/app/src/style.css | 30 +++++++++-- frontend/app/src/tempo.test.ts | 67 +++++++++++++++++++++++ frontend/app/src/tempo.ts | 58 ++++++++++++++++++++ 12 files changed, 548 insertions(+), 40 deletions(-) create mode 100644 frontend/app/src/follow.test.ts create mode 100644 frontend/app/src/follow.ts create mode 100644 frontend/app/src/tempo.test.ts create mode 100644 frontend/app/src/tempo.ts diff --git a/README.md b/README.md index bde0e55..8bfb260 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ continuity in the system to make the columns match — **the asymmetry *is* the ![Performance mode — the chrome falls away, the phrase goes large](docs/screenshots/performance-mode.png) Press P and the instrument becomes a stage: the chrome falls away, the phrase the -body is answering goes large, playback slows to half speed to be followed by a body — but +body is answering goes large, the speed is yours to set so a body can follow it — but the **poem keeps growing**, and you can still write and generate live, in front of the room. The audience does not just watch generated movement — they watch the **evolution of diff --git a/docs/lecture-performance.md b/docs/lecture-performance.md index 97da39b..5b12cc8 100644 --- a/docs/lecture-performance.md +++ b/docs/lecture-performance.md @@ -38,12 +38,17 @@ software does is in service of making those two moments possible. ![Performance mode — the instrument chrome falls away, the phrase goes large](screenshots/performance-mode.png) Hit **Perform** (or press P) for the projectable stage: the instrument chrome -falls away, the phrase goes large, playback slows to half speed to be followed by a body — +falls away, the phrase goes large, the speed is yours to set so a body can follow it — but the **poem keeps growing** and you can still write and generate live, in front of the room. - The background drops to near-black, chosen for a projector in a dark room. -- Playback re-seats to **0.5× tempo**, because a body has to be able to follow it. +- Playback opens at **real time**, and every speed down to 0.1× is a keypress away + (T, or [ ]). A body has to be able to follow and re-embody + what it sees — but how slow that needs to be is the performer's judgement, not a default. +- **The camera follows the body**, easing after the pelvis so a line that travels several + metres stays on screen and inside the spotlight. It moves the viewpoint, never the motion — + the travel is still there, still on the floor and still in the floor-path register. - The phrase the body is answering right now is set large and centred; the lines still waiting stay in the poem on the left. - boots straight into it, for plugging into a projector. @@ -53,7 +58,10 @@ room. |---|---| | P | enter / leave performance mode | | space | play / pause | -| T | cycle tempo (0.5× → 0.25× → 1×) | +| T | cycle the speed, wrapping round every value | +| [ ] | step the speed slower / faster | +| F | camera follow on / off | +| O | the phrase shown / hidden | | R | read the four notation registers | | C | compare models (the triptych) | | N | one line / the whole poem | diff --git a/docs/roadmap.md b/docs/roadmap.md index f1e4f87..ed9622c 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -56,14 +56,28 @@ quietly half-built. the body: the spotlight is a radial gradient pinned to the centre of the viewport, so a body at 3.9 m stands outside its own light. - A camera that followed the pelvis would fix that **without touching the data**, which is a - different thing from pelvis-aligning the motion and does not reopen the decision above. But - with the ghost-cloud on it cannot be done innocently: following the selected line's body - drifts the far siblings out of frame, and the far siblings are where that ~75% lives. - Following the centroid centres nobody. So **what a follow camera should follow is a research - decision rather than a UI default**, and it waits on seeing the extended floor from the back - of a room — the judgement Track 3 of [`v4-proposal.md`](v4-proposal.md) says should not be - made at a desk. + **The camera now follows the body in performance mode, and only there.** It eases after the + pelvis in x and z, panning the camera and its orbit target together so the viewer's angle and + distance survive, and it moves **the viewpoint and never the motion** — a different thing + from pelvis-aligning, which does not reopen the decision above. Measured on a body covering + SnapMoGen's 3.89 m: on screen for 55% of the phrase before, 100% after, trailing the pelvis + by at most 0.27 m. The bench keeps a fixed world frame, because travel is easier to judge + against ground that holds still, and the triptych never gets it at all — equalising travel + across the panels would hide the difference between a model that covers 3.89 m and one that + covers 0.09 m, which is the comparison those panels exist to make. + + **Two things it does not settle.** + + *What to follow when the ghost-cloud is on.* It follows the selected body; the siblings stay + where the model put them, so the far ones leave the frame — and the far ones are where that + ~75% lives. Following the centroid centres nobody. This stays a research decision rather + than a UI default, to be made from the back of a room and not at a desk, which is what + Track 3 of [`v4-proposal.md`](v4-proposal.md) asks for. + + *The spotlight still does not travel.* It is a radial gradient pinned to the centre of the + viewport, so following the body happens to fix the symptom — the body is centred again, and + therefore lit — without fixing the cause. A body deliberately left off-centre, or a second + figure, would still be outside the light. **From v2 — the poem's unfinished edges:** diff --git a/docs/usage.md b/docs/usage.md index 69f0aa3..49f1250 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -53,8 +53,11 @@ hunting for a mouse in front of an audience. | C | **Compare** — open / close the multi-model triptych | | P | **Perform** — enter / leave performance mode | | space | play / pause | -| T | cycle tempo: 0.5× → 0.25× → 1× | +| T | cycle the speed, wrapping round: 0.1 · 0.25 · 0.5 · 0.75 · 1 · 1.5 · 2 | +| [ ] | step the speed slower / faster through every value the control offers | | G | ghost-cloud on / off | +| F | **follow** — the camera tracks the body, or stops | +| O | the phrase under the body, shown or hidden | | esc | leave the current mode; from a line, unfocus it | **In the poem:** enter starts a new line, backspace at the start of a @@ -85,6 +88,13 @@ clicking through chrome in front of a room. | `localhost:5173/?registers=1` | straight into the four notation registers | | `localhost:5173/?compare=1` | straight into the triptych | | `localhost:5173/?perform=1` | straight into the projectable performance stage | +| `…/?follow=1` · `?follow=0` | camera follow on or off, whatever the mode would have chosen | +| `…/?phrase=0` | boot with the phrase hidden — the body alone on the stage | +| `…/?speed=0.25` | any speed the control offers: 0.1, 0.25, 0.5, 0.75, 1, 1.5, 2 | + +The three above are read **after** the mode flags, so an explicit choice beats the mode's +default — `?perform=1&follow=0` opens the stage with a still camera. A `?speed=` that is not +one of the offered values is ignored rather than guessed at. --- @@ -105,8 +115,11 @@ Around the stage: - **Poem rail** (left) — the score you are writing. See below. - **Notation rail** (right) — two of the four registers, small: the notation strip and the floor path. R opens all four, large. -- **Transport** (bottom) — play/pause, a scrub bar, the ghost-cloud toggle, and a frame - counter. Scrubbing moves the figure, the ghosts, and every open register together. +- **Transport** (bottom) — play/pause, a scrub bar, a **speed** control, the ghost-cloud + toggle, a **follow** toggle, a **phrase** toggle, and a frame counter. Scrubbing moves the + figure, the ghosts, and every open register together. The controls themselves are stripped + in performance mode, where the keys do the same jobs — you do not want to be hunting for a + mouse in front of a room. ### The poem — the core contribution @@ -408,11 +421,35 @@ the same poem.** The performer keeps working — writing, drafting, baking — w room sees only the body, the phrase and the score. What changes: the instrument chrome falls away, the background darkens, a spotlight gathers the -eye onto the body, the phrase goes large beneath it, and **playback drops to half speed** — -because a human has to be able to *follow and re-embody it*. The score gets thicker strokes and +eye onto the body, and the phrase goes large beneath it — capped at a third of the window, so +a long line cannot cover the body it describes. The score gets thicker strokes and bigger labels: it has to be readable by a body, from across a room. The poem keeps growing in the corner — research log as set. +**And the camera follows the body.** A line can travel several metres — 3.89 m on SnapMoGen — +and the stage was framed on a body at the origin, so a travelling body used to leave the shot +for nearly half the phrase and walk out of its own spotlight. The camera now eases after the +pelvis, trailing it by about a quarter of a metre so it reads as an operator following a dancer +rather than the body being pinned to the glass. + +**It moves the viewpoint and not the motion.** How far a body goes is part of how the model read +the prompt, so nothing is subtracted: the floor still streams past underneath, and the floor-path +register still shows the whole trace. Dragging to orbit works exactly as before — the camera and +its target move together, so your angle and distance are kept — but **right-drag panning is +overridden while performing**, because the camera is busy keeping the body on screen. Leaving +performance mode puts the camera back on the origin. + +**All three are switchable from the stage**, because what a room needs is a judgement made in +the room: F stops the camera following, O takes the phrase away and leaves +the body alone, and T or [ ] change the speed. Performance +opens at **real time**, so the first thing the room sees is the motion as the model made it — +and every speed down to 0.1× is one keypress away when a body needs to follow it. + +With the **ghost-cloud** on, the camera follows the selected body only. The siblings stay where +the model put them and the far ones can leave the frame — and most of the spread between +siblings *is* how far each one travelled. What a camera should do about that is an open +question, not a settled default; see [`roadmap.md`](roadmap.md). + T cycles the tempo, space plays and pauses, esc gets you out. `?perform=1` boots straight into it, for plugging into a projector. diff --git a/frontend/app/index.html b/frontend/app/index.html index 6bb5a1b..276afab 100644 --- a/frontend/app/index.html +++ b/frontend/app/index.html @@ -127,9 +127,9 @@
⟳ loop - 0.5× tempo + 1× tempo re-embody - space play · T tempo · esc exit + space play · T / [ ] speed · F follow · O phrase · esc exit
@@ -293,11 +293,36 @@

4 · Laban-inspired score

+ + + + + + — / —
diff --git a/frontend/app/src/follow.test.ts b/frontend/app/src/follow.test.ts new file mode 100644 index 0000000..0ecaccf --- /dev/null +++ b/frontend/app/src/follow.test.ts @@ -0,0 +1,71 @@ +/** + * What the follow camera is allowed to do. + * + * Two of these matter more than they look. A camera that overshoots oscillates around the + * body, and a camera whose easing depends on the frame rate feels like a different camera on + * a projector than on the laptop it was tuned on — and the projector is the one that counts. + * + * Run with `npm test` (Node runs TypeScript directly; no test runner is installed). + */ + +import assert from "node:assert/strict"; +import { test } from "node:test"; + +import { FOLLOW_RATE, followPan } from "./follow.ts"; + +const at = (x: number, z: number) => ({ x, z }); + +test("a body already centred does not move the camera", () => { + const pan = followPan(at(2, -1), at(2, -1), 1 / 60); + assert.equal(pan.dx, 0); + assert.equal(pan.dz, 0); +}); + +test("the camera moves toward the body, never past it", () => { + // One frame closes part of the gap. Overshooting would oscillate around the body. + const pan = followPan(at(0, 0), at(4, 0), 1 / 60); + assert.ok(pan.dx > 0, "moves toward the body"); + assert.ok(pan.dx < 4, "does not arrive in one frame"); + // Even an absurdly long frame cannot pass the body. + const huge = followPan(at(0, 0), at(4, 0), 10); + assert.ok(huge.dx < 4); +}); + +test("easing is frame-rate independent", () => { + // Two half-steps must land exactly where one whole step does, or the camera follows + // faster on a faster display and its feel becomes a property of the hardware. + const dt = 1 / 30; + const one = followPan(at(0, 0), at(6, 0), dt).dx; + + let x = 0; + for (let i = 0; i < 2; i++) x += followPan(at(x, 0), at(6, 0), dt / 2).dx; + + assert.ok(Math.abs(one - x) < 1e-12, `${one} vs ${x}`); +}); + +test("it follows x and z, and nothing else", () => { + const pan = followPan(at(0, 0), at(3, -5), 1 / 60); + assert.ok(pan.dx > 0); + assert.ok(pan.dz < 0); + // There is no third component to get wrong: following height would bob the camera in + // time with the walk cycle. + assert.deepEqual(Object.keys(pan).sort(), ["dx", "dz"]); +}); + +test("a stalled clock pans nothing", () => { + // The first frame after a tab regains focus can report dt 0, and a paused stage asks for + // this every frame forever. + for (const dt of [0, -1, Number.NaN]) { + const pan = followPan(at(0, 0), at(9, 9), dt); + assert.equal(pan.dx, 0, `dt ${dt}`); + assert.equal(pan.dz, 0, `dt ${dt}`); + } +}); + +test("the default rate closes most of the gap in about half a second", () => { + // Pins the feel, so changing FOLLOW_RATE is a deliberate act with a visible consequence + // rather than a number nudged until a test went green. + let x = 0; + for (let i = 0; i < 30; i++) x += followPan(at(x, 0), at(1, 0), 1 / 60, FOLLOW_RATE).dx; + assert.ok(x > 0.55 && x < 0.75, `covered ${x.toFixed(3)} of the gap in 0.5 s`); +}); diff --git a/frontend/app/src/follow.ts b/frontend/app/src/follow.ts new file mode 100644 index 0000000..e63b091 --- /dev/null +++ b/frontend/app/src/follow.ts @@ -0,0 +1,65 @@ +/** + * How the camera follows a travelling body. + * + * The stage camera was framed on a body at the origin, and real models do not stay there — + * one line covers 2.11 m on Kimodo and 3.89 m on SnapMoGen. A body that travels walks out of + * the frame, and out of the performance view's spotlight, which is a radial gradient fixed to + * the centre of the viewport. + * + * What this does NOT do is change the motion. Displacement is a finding in this project — how + * far a body goes is part of how the model read the prompt — so the data is untouched and the + * floor still streams past underneath. Only the viewpoint moves. That is a different thing + * from pelvis-aligning the motion, which stays parked as an option (see docs/roadmap.md). + * + * The arithmetic lives here rather than in the animation loop for the same reason + * `timeline.ts` and `register-view.ts` do: a camera that eases at the wrong rate, or that + * overshoots, or that drifts differently on a 60 Hz laptop and a 120 Hz projector, is wrong + * in a way that is hard to see and easy to argue about. Here it can be tested. + */ + +/** Where the camera aims: the body's x/z, at the height the stage was framed for. */ +export const FOLLOW_HEIGHT = 1.0; + +/** + * How fast the camera closes the gap, as a rate per second. + * + * It is a time constant, not a per-frame fraction: at 1.8 the camera covers about 63% of the + * distance to the body in the first 0.55 s. The lag is the point — a camera that snapped to + * the pelvis would nail the body to the glass and read as the body standing still while the + * world slid past. This reads as an operator following a dancer, and it is the one number + * here most worth changing in a room. + */ +export const FOLLOW_RATE = 1.8; + +export interface Pan { + dx: number; + dz: number; +} + +/** + * How far to pan this frame, so the body eases toward the centre of the shot. + * + * Applied to the orbit target **and** the camera position, by the same amount — that is what + * keeps it a pan. Moving only the target would swing the camera round the body and throw away + * whatever angle and distance the viewer had chosen. + * + * Frame-rate independent by construction: `1 - exp(-rate * dt)` composes exactly, so two + * half-steps land in the same place as one whole step. A fixed per-frame fraction would + * follow faster on a faster display, which would make the camera's feel a property of the + * hardware rather than a decision. + * + * Never overshoots: the factor is in [0, 1) for any non-negative `dt`. + * + * Only x and z. Following the body's height as well would make the camera bob with the + * pelvis — a camera breathing in time with the walk cycle, which reads as the floor moving. + */ +export function followPan( + from: { x: number; z: number }, + to: { x: number; z: number }, + dt: number, + rate: number = FOLLOW_RATE, +): Pan { + if (!(dt > 0) || !(rate > 0)) return { dx: 0, dz: 0 }; + const k = 1 - Math.exp(-rate * dt); + return { dx: (to.x - from.x) * k, dz: (to.z - from.z) * k }; +} diff --git a/frontend/app/src/main.ts b/frontend/app/src/main.ts index 5c91649..aab6634 100644 --- a/frontend/app/src/main.ts +++ b/frontend/app/src/main.ts @@ -31,6 +31,7 @@ import type { CanonicalMotion } from "./types"; import { openAutosave } from "./autosave"; import { askFor, continuityLabel, readPanel } from "./triptych"; import { wholePoemAction, wholePoemLabel, wholePoemTitle } from "./whole-poem"; +import { FULL_SPEED, PERFORM_TEMPO, TEMPO_STEPS, stepTempo } from "./tempo"; import { SessionError, fromSession, restore, sessionFilename, sessionUrl, toSession } from "./session"; // Where the FastAPI service listens. Keep in sync with service/ CORS + --port. @@ -99,6 +100,9 @@ const playPauseEl = $("playpause"); const scrubEl = $("scrub"); const counterEl = $("counter"); const ghostsEl = $("ghosts"); +const followEl = $("follow"); +const overlayEl = $("overlay"); +const tempoEl = $("tempo"); const notationSvgEl = document.getElementById("notation-svg") as unknown as SVGSVGElement; const floorSvgEl = document.getElementById("floor-svg") as unknown as SVGSVGElement; const appEl = $("app"); @@ -1208,16 +1212,42 @@ function setReading(on: boolean): void { // (writing, drafting, baking) while the room sees only the body, the line it is // answering, and the score. Slowed down, because a human has to be able to follow it. -const TEMPOS = [0.5, 0.25, 1]; // performance opens at half speed; T cycles -const FULL_SPEED = TEMPOS.indexOf(1); let performing = false; -// Where T picks up from. The bench plays at full speed, so it starts here and the first -// press steps to 0.5x; performance mode re-seats it at 0.5x (index 0) when it opens. -let tempoIdx = FULL_SPEED; function setTempo(rate: number): void { renderer.setTempo(rate); perfTempoEl.textContent = `${rate}× tempo`; + // The select, the overlay's label and the renderer say the same thing or they are lying + // about the speed the room is watching. + tempoEl.value = String(rate); +} + +/** `[` and `]` — one speed slower or faster, stopping at the ends. */ +function nudgeTempo(by: -1 | 1): void { + setTempo(stepTempo(Number(tempoEl.value), by, false)); +} + +/** + * Follow the body with the camera, or stop. + * + * Kept in one place so the checkbox, the key and performance mode cannot disagree about + * whether the camera is moving — a control that misreports that is worse than no control. + */ +function setFollowing(on: boolean): void { + followEl.checked = on; + renderer.setFollow(on); +} + +/** + * Show or hide the phrase under the body. + * + * Hiding it leaves the body alone on the stage, which is sometimes what a room wants — and + * it is the performer's call, not the instrument's. Press O again to bring it back; the key + * is listed in the overlay itself while the overlay is the thing you can see. + */ +function setOverlay(on: boolean): void { + overlayEl.checked = on; + appEl.classList.toggle("overlay-off", !on); } /** @@ -1342,6 +1372,16 @@ function setPerforming(on: boolean): void { // Rating is editorial. The room is here for the body, not for someone's marking. if (on && reviewing) setReviewing(false); renderer.setPerformanceMode(on); + // Entering the room turns the camera follow on and the phrase back up; leaving puts them + // back. These are defaults for the mode, not a lock — F and O override either at any + // point, the same way T re-seats the speed on entry and you can still change it after. + // + // The bench defaults to not following because it is for inspection, where travel is easier + // to judge against ground that holds still. The triptych never follows at all: equalising + // travel across the panels would hide the difference between a model that covers 3.89 m + // and one that covers 0.09 m, which is the comparison those panels exist to make. + setFollowing(on); + if (on) setOverlay(true); performEl.textContent = on ? "Exit" : "Perform"; modePillEl.textContent = on ? "Performance" : "Search instrument · live"; @@ -1349,18 +1389,16 @@ function setPerforming(on: boolean): void { if (!on) updateScoreHead(); // the title may be naming a line, not the whole poem if (on) { - tempoIdx = 0; // performance opens at half speed — a body has to be able to follow it - setTempo(TEMPOS[tempoIdx]); + setTempo(PERFORM_TEMPO); renderer.play(); } else { - tempoIdx = FULL_SPEED; - setTempo(TEMPOS[tempoIdx]); + setTempo(FULL_SPEED); } } +/** `T` — the next speed, wrapping round, so every speed is reachable from one key. */ function cycleTempo(): void { - tempoIdx = (tempoIdx + 1) % TEMPOS.length; - setTempo(TEMPOS[tempoIdx]); + setTempo(stepTempo(Number(tempoEl.value), 1, true)); } /** @@ -1506,7 +1544,16 @@ renderer.onFrame(({ frame, total, fps, playing, segmentIndex }) => { if (scoreScope === "line") buildScore(); const line = playingLines[segmentIndex]; // The room reads the sentence the body is answering right now, not the whole poem. - if (line) perfPhraseEl.textContent = `“${line.text}”`; + if (line) { + perfPhraseEl.textContent = `“${line.text}”`; + // A long line is capped at 30vh so it cannot cover the body. Say when that happened: + // a phrase cut to a clean edge reads as a finished sentence, which misrepresents what + // the body is answering. Measured here, once per line boundary rather than per frame. + perfPhraseEl.classList.toggle( + "clipped", + perfPhraseEl.scrollHeight > perfPhraseEl.clientHeight + 1, + ); + } for (const [id, row] of rows) row.classList.toggle("playing", id === line?.id); } }); @@ -1816,6 +1863,9 @@ function transportLead(): StickFigureRenderer { playPauseEl.addEventListener("click", () => setPlayingAll(!transportLead().playing)); ghostsEl.addEventListener("change", () => renderer.setGhostsVisible(ghostsEl.checked)); +followEl.addEventListener("change", () => setFollowing(followEl.checked)); +overlayEl.addEventListener("change", () => setOverlay(overlayEl.checked)); +tempoEl.addEventListener("change", () => setTempo(Number(tempoEl.value))); scrubEl.addEventListener("input", () => { userScrubbing = true; @@ -1873,6 +1923,18 @@ window.addEventListener("keydown", (e) => { case "t": cycleTempo(); break; + case "[": + nudgeTempo(-1); // slower + break; + case "]": + nudgeTempo(1); // faster + break; + case "f": + setFollowing(!followEl.checked); + break; + case "o": + setOverlay(!overlayEl.checked); + break; case "g": ghostsEl.checked = !ghostsEl.checked; renderer.setGhostsVisible(ghostsEl.checked); @@ -2030,3 +2092,12 @@ const boot = new URLSearchParams(location.search); if (boot.has("perform")) setPerforming(true); if (boot.has("compare")) setComparing(true); if (boot.has("registers")) setReading(true); +// Read after the mode flags, so an explicit choice beats the mode's default. `?speed=` takes +// any rate the control offers; anything else is ignored rather than guessed at. +if (boot.has("follow")) setFollowing(boot.get("follow") !== "0"); +if (boot.has("phrase")) setOverlay(boot.get("phrase") !== "0"); +if (boot.has("speed")) { + const rate = Number(boot.get("speed")); + if (TEMPO_STEPS.includes(rate)) setTempo(rate); +} + diff --git a/frontend/app/src/renderer.ts b/frontend/app/src/renderer.ts index 7604356..b9ed150 100644 --- a/frontend/app/src/renderer.ts +++ b/frontend/app/src/renderer.ts @@ -8,6 +8,7 @@ import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js"; import type { CanonicalMotion } from "./types"; import { buildTimeline, entryAt, type TimelineEntry } from "./timeline"; import { JOINT_INDEX, LANDMARK_JOINTS, TRAIL_JOINTS } from "./skeleton"; +import { FOLLOW_HEIGHT, followPan } from "./follow"; // House palette (matches frontend/mockups/styles.css). const STAGE_BG = 0x0b0c10; @@ -114,6 +115,8 @@ export class StickFigureRenderer { // the stage itself: a lab bench is lit for inspection, a performance is lit for a room private grid?: THREE.GridHelper; + /** Whether the camera tracks the body. Off on the bench, on for the room. */ + private following = false; constructor(container: HTMLElement, opts: RendererOptions = {}) { this.container = container; @@ -134,7 +137,7 @@ export class StickFigureRenderer { container.appendChild(this.renderer.domElement); this.controls = new OrbitControls(this.camera, this.renderer.domElement); - this.controls.target.set(0, 1.0, 0); // chest height — the body, not the floor + this.controls.target.set(0, FOLLOW_HEIGHT, 0); // chest height — the body, not the floor this.controls.enableDamping = true; this.controls.update(); @@ -284,9 +287,74 @@ export class StickFigureRenderer { } /** - * Light the stage for a room rather than for inspection: a darker ground, a dimmer - * grid. The figure stays exactly as it is — this is the *only* honest thing to change, - * since the notation is the work. + * Follow the body, or stop following it. + * + * Separate from `setPerformanceMode` because it is a different kind of change: the palette + * is about the room's light, this is about where the camera is pointed. Keeping them apart + * also leaves the bench able to opt in later without inheriting a dark background. + * + * While following, the camera owns the orbit target: dragging to orbit still works, because + * the follow pans the camera and its target together and so preserves the angle and + * distance, but right-drag panning is overridden every frame. That is the trade — the + * instrument can keep a travelling body on screen, or it can let you put the target + * anywhere, and in front of a room the first one matters more. + * + * Switching off snaps the target home rather than easing back. It happens at the moment + * performance mode is left, when the chrome returns and the tempo changes anyway, and an + * ease would fight the first manual pan for as long as it ran. + */ + setFollow(on: boolean): void { + if (this.following === on) return; + this.following = on; + if (!on) { + const home = new THREE.Vector3(0, FOLLOW_HEIGHT, 0); + // The camera moves by the same delta as the target, which is what makes it a pan and + // leaves the viewer's angle and distance exactly as they left them. + this.camera.position.add(home.clone().sub(this.controls.target)); + this.controls.target.copy(home); + this.controls.update(); + } + } + + /** + * Ease the shot toward the body. Called every frame, playing or not. + * + * The pelvis is read from the playhead rather than from whatever `applyFrame` last wrote, + * because `applyFrame` is also reached from `seek`, `seekSegment` and `loadSequence`, + * outside the animation loop — reading the frame here is what makes those cases work + * without four places having to remember the camera. + * + * It follows the primary body only. With the ghost-cloud on, the siblings travel 2.31-4.77 m + * and stay where the model put them, so the far ones will leave the frame — and roughly + * three quarters of the spread between siblings *is* that travel. What a camera should do + * about that is a research decision and is recorded as open in docs/roadmap.md; it is not + * guessed at here. + */ + private updateFollow(dt: number): void { + if (!this.following || !this.motion) return; + const pose = this.poseAt(Math.round(this.frameFloat)); + const pelvis = pose?.[JOINT_INDEX["pelvis"]]; + if (!pelvis) return; + + const { dx, dz } = followPan( + { x: this.controls.target.x, z: this.controls.target.z }, + { x: pelvis[0], z: pelvis[2] }, + dt, + ); + if (dx === 0 && dz === 0) return; + + this.controls.target.x += dx; + this.controls.target.z += dz; + this.camera.position.x += dx; + this.camera.position.z += dz; + } + + /** + * Light the stage for a room rather than for inspection: a darker ground, a dimmer grid. + * + * The figure itself stays exactly as it is — the notation is the work, so nothing here + * touches the body. The camera is the one other thing the room needs and it has its own + * switch, `setFollow`, rather than being folded in here. */ setPerformanceMode(on: boolean): void { this.scene.background = new THREE.Color(on ? PERF_BG : STAGE_BG); @@ -507,6 +575,10 @@ export class StickFigureRenderer { this.emit(); } + // Outside the block above on purpose: a paused stage still gets scrubbed, and the + // camera has to come with the playhead. Before `controls.update()`, so the damping + // this frame consumes the new target rather than lagging a frame behind it. + this.updateFollow(dt); this.controls.update(); this.renderer.render(this.scene, this.camera); }; diff --git a/frontend/app/src/style.css b/frontend/app/src/style.css index 6993e61..a4c2eb2 100644 --- a/frontend/app/src/style.css +++ b/frontend/app/src/style.css @@ -494,12 +494,24 @@ body.resizing { cursor: col-resize; user-select: none; } /* the phrase the room is watching — hidden until performing */ .perf-overlay { display: none; } .perf-phrase { - font-size: 30px; + font-size: 24px; font-style: italic; - line-height: 1.35; + line-height: 1.3; color: var(--ink); max-width: 80%; margin: 0 auto; + /* A line of a poem can be a paragraph — Day 4's level-E prompts average 38.7 words. Left + unbounded the phrase grows up the screen and covers the body it is describing, which + inverts the whole point of the stage. A third of the window is the most it may take. */ + max-height: 30vh; + overflow: hidden; +} +/* Set by main.ts only when the phrase really is taller than its box. A phrase that has been + cut has to LOOK cut: a clean edge reads as the end of the sentence, which is a lie about + what the body is answering. */ +.perf-phrase.clipped { + mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 2em), transparent 100%); + -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 2em), transparent 100%); } .perf-meta { margin-top: 16px; @@ -507,13 +519,16 @@ body.resizing { cursor: col-resize; user-select: none; } gap: 18px; justify-content: center; font-family: var(--mono); - font-size: 11px; + font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; - color: var(--ink-faint); + /* Was --ink-faint, and the key hints were --ink-faint at opacity 0.55 on top of that: + 1.73:1 against the performance background, where small text wants 4.5:1. The row is + read from across a room, or it is decoration. --ink-dim measures 7.63:1. */ + color: var(--ink-dim); } .perf-meta .on { color: var(--accent); } -.perf-keys { opacity: 0.55; text-transform: none; letter-spacing: 0.04em; } +.perf-keys { text-transform: none; letter-spacing: 0.04em; } /* ---- what changes when performing ---- */ #app.performing { background: #07080b; } @@ -528,6 +543,10 @@ body.resizing { cursor: col-resize; user-select: none; } pointer-events: none; } +/* O hides the phrase. More specific than the rule above, so no !important is needed — + and the body is then alone on the stage, which is sometimes what the room wants. */ +#app.performing.overlay-off .perf-overlay { display: none; } + /* a spotlight, so the eye goes to the body */ #app.performing .stage-view::after { content: ""; @@ -547,6 +566,7 @@ body.resizing { cursor: col-resize; user-select: none; } #app.performing .tag, #app.performing .telemetry, #app.performing .model-select, +#app.performing .duration, #app.performing .counter, #app.performing .toggle, #app.performing .rail-hint, diff --git a/frontend/app/src/tempo.test.ts b/frontend/app/src/tempo.test.ts new file mode 100644 index 0000000..7f21ccb --- /dev/null +++ b/frontend/app/src/tempo.test.ts @@ -0,0 +1,67 @@ +/** + * That every speed can actually be reached. + * + * This file exists because of a shipped fault: `T` cycled a three-value list while the control + * offered seven, so 1.5x and 2x could not be reached by the key that changes the speed. It read + * as a design choice until someone pressed the key enough times. + * + * Run with `npm test` (Node runs TypeScript directly; no test runner is installed). + */ + +import assert from "node:assert/strict"; +import { test } from "node:test"; + +import { FULL_SPEED, PERFORM_TEMPO, TEMPO_STEPS, stepTempo, tempoIndex } from "./tempo.ts"; + +test("cycling reaches every speed, including the fast ones", () => { + // The regression this file is named for. + const seen = new Set(); + let rate = FULL_SPEED; + for (let i = 0; i < TEMPO_STEPS.length; i++) { + rate = stepTempo(rate, 1, true); + seen.add(rate); + } + assert.deepEqual([...seen].sort((a, b) => a - b), [...TEMPO_STEPS]); + assert.ok(seen.has(1.5) && seen.has(2), "1.5x and 2x are reachable by cycling"); +}); + +test("cycling returns to where it started", () => { + let rate = PERFORM_TEMPO; + for (let i = 0; i < TEMPO_STEPS.length; i++) rate = stepTempo(rate, 1, true); + assert.equal(rate, PERFORM_TEMPO); +}); + +test("stepping stops at the ends instead of wrapping", () => { + // Holding [ must not hand you double speed in front of a room. + let slow = FULL_SPEED; + for (let i = 0; i < 20; i++) slow = stepTempo(slow, -1, false); + assert.equal(slow, TEMPO_STEPS[0]); + + let fast = FULL_SPEED; + for (let i = 0; i < 20; i++) fast = stepTempo(fast, 1, false); + assert.equal(fast, TEMPO_STEPS[TEMPO_STEPS.length - 1]); +}); + +test("stepping moves one speed at a time, in the right direction", () => { + assert.equal(stepTempo(0.5, 1, false), 0.75); + assert.equal(stepTempo(0.5, -1, false), 0.25); +}); + +test("the defaults are speeds the controls actually offer", () => { + // Otherwise entering performance would put the select and the renderer out of step. + assert.ok(TEMPO_STEPS.includes(PERFORM_TEMPO)); + assert.ok(TEMPO_STEPS.includes(FULL_SPEED)); +}); + +test("a rate between two steps lands on one of them", () => { + assert.equal(tempoIndex(0.4), TEMPO_STEPS.indexOf(0.5)); + assert.equal(stepTempo(0.4, 1, false), 0.75); + // And a rate past the end does not fall off it. + assert.equal(tempoIndex(99), TEMPO_STEPS.length - 1); + assert.equal(stepTempo(99, 1, false), TEMPO_STEPS[TEMPO_STEPS.length - 1]); +}); + +test("the list is sorted, which is what makes stepping mean slower and faster", () => { + const sorted = [...TEMPO_STEPS].sort((a, b) => a - b); + assert.deepEqual(TEMPO_STEPS, sorted); +}); diff --git a/frontend/app/src/tempo.ts b/frontend/app/src/tempo.ts new file mode 100644 index 0000000..803c72b --- /dev/null +++ b/frontend/app/src/tempo.ts @@ -0,0 +1,58 @@ +/** + * Playback speed, and how the controls move through it. + * + * Half speed exists because a body has to be able to follow and re-embody what it sees, and + * how slow that needs to be is a studio judgement rather than a constant — so the speed is + * adjustable from the stage, by key as well as by control, since there is no mouse in front + * of a room. + * + * **One list.** There were briefly two — a short cycle for `T` and the full set for the + * select — and the only thing that bought was 1.5x and 2x being unreachable by the key whose + * whole job is changing the speed. A set of values half the controls can reach is the kind of + * fault that looks like a preference until someone tries it, which is why the stepping lives + * here where it can be tested rather than in the keydown switch. + */ + +/** Every speed there is, slowest first. */ +export const TEMPO_STEPS = [0.1, 0.25, 0.5, 0.75, 1, 1.5, 2]; + +/** + * The speed the room opens at. + * + * It was 0.5 — the argument being that a body has to be able to follow and re-embody what it + * sees. That argument still holds, but it is a judgement for the performer rather than + * something the instrument should impose on arrival, and now that every speed is a keypress + * away (T, or [ and ]) imposing it bought nothing. Opening at real time also means the first + * thing the room sees is the motion as the model produced it. + */ +export const PERFORM_TEMPO = 1; + +export const FULL_SPEED = 1; + +/** + * Where a rate sits in the list — or the nearest step at or above it, for a rate that + * somehow sits between two (nothing sets one today; a hand-edited `?speed=` could). + */ +export function tempoIndex(rate: number): number { + const at = TEMPO_STEPS.indexOf(rate); + if (at >= 0) return at; + const near = TEMPO_STEPS.findIndex((r) => r >= rate); + return near < 0 ? TEMPO_STEPS.length - 1 : near; +} + +/** + * The next speed along. + * + * `wrap` is the difference between the two controls, and it is deliberate. `T` cycles, so + * every speed is reachable by pressing one key repeatedly. `[` and `]` step and stop at the + * ends, because holding `[` to get as slow as possible should not suddenly hand you double + * speed in front of a room. + */ +export function stepTempo(rate: number, by: -1 | 1, wrap: boolean): number { + const n = TEMPO_STEPS.length; + const at = tempoIndex(rate); + const next = wrap + ? (at + by + n) % n + : Math.min(n - 1, Math.max(0, at + by)); + return TEMPO_STEPS[next]; +}