Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
MC3: the match cuts checked in the render: at each cut of a chain, the hooked part sits at its thirds place on the frame before the cut and on the frame after it (sdk/guides/craft/match-cuts/thirds.ts). landsOnThirds(chain) is a raea/check system on the chain's cut frames only, reading raea world's facts with no render: a part (named() as raea/check matches names) by its world box projected through the frame's camera, its corners clipped at the near plane; a text by its laid-out box, named by its words; where several share a name, the one nearest its place. A point holds within a tolerance of the frame (0.06 when the rule's values don't say), a line on its axis, FULL to a share of the frame (0.9). Each cut of the chain must be a cut of the composition, a Sequence starting on the chain's frame with the shot's name; a J bridge's sound is placed its seconds before the cut and playing on the frame before; an L bridge's still playing on the cut's frame and its last; the plan checks run once after the frames, so one rule holds both. A project makes it from its chain in a three-line file of its own and names that in a rule or an ask. bench/direction/match-cuts/graybox.tsx builds the chain as a project would (each shot a Sequence from sequences(), each hook placed with onFrame and carried over its shot), and match-cuts.sh checks it: nothing found on it, and each of nine cheats found: a hook off its place, one gone from its place by the cut, the part renamed, a cut ten frames late, a FULL covering half the frame, a part behind the camera, a hook naming no part, the J sound starting at the cut, the L sound stopping at it. The whole bench runs in 7 s. What it can't see: a part hidden behind another, a camera rolled about its view, the eye's way inside a shot, and a 2D graphic that isn't text
shinyobjectzb4aaa8204f7e
diff --git a/bench/direction/match-cuts/checks/morning-nopart.ts b/bench/direction/match-cuts/checks/morning-nopart.tsnew file mode 100644index 00000000..a6b7665f--- /dev/null+++ b/bench/direction/match-cuts/checks/morning-nopart.ts@@ -0,0 +1,7 @@+// A cheat on the chain, not the render: the dial's out hook names no part, so nothing could measure it.+import { chain } from "./match-cuts/chain";+import { landsOnThirds } from "./match-cuts/thirds";+import morning from "../good.chain";++const { part: _, ...out } = morning.shots.find((s) => s.name === "dial")!.out;+export default landsOnThirds(chain({ ...morning, shots: morning.shots.map((s) => (s.name === "dial" ? { ...s, out } : s)) }), { id: "lands-on-thirds-nopart", plan: false });diff --git a/bench/direction/match-cuts/checks/morning.ts b/bench/direction/match-cuts/checks/morning.tsnew file mode 100644index 00000000..985c556e--- /dev/null+++ b/bench/direction/match-cuts/checks/morning.ts@@ -0,0 +1,5 @@+// The check as a project makes it from its chain (raea guide match-cuts): the kit's landsOnThirds, its chain.+import { landsOnThirds } from "./match-cuts/thirds";+import morning from "../good.chain";++export default landsOnThirds(morning);diff --git a/bench/direction/match-cuts/graybox.tsx b/bench/direction/match-cuts/graybox.tsxnew file mode 100644index 00000000..38aa591a--- /dev/null+++ b/bench/direction/match-cuts/graybox.tsx@@ -0,0 +1,95 @@+// MC3's graybox (docs/match-cuts.feature): good.chain.ts built as a project would build it, each shot a Sequence from+// the chain and each hook a part placed on its thirds place with onFrame, the out hook carried there over the shot. One+// composition holds the chain; each other one is a cheat the render check must fail.+import { AbsoluteFill, Audio, Composition, Sequence, registerRoot, useCurrentFrame } from "raea";+import { Sphere } from "raea/3d";+import { Camera3d } from "raea/camera";+import { DirectionalLight } from "raea/light";+import { Cuboid, Mesh3d } from "raea/mesh";+import { StandardMaterial } from "raea/pbr";+import { Transform } from "raea/transform";+import good from "./good.chain";+import { centreOf, onFrame, sequences, type Glyph, type Hook } from "./checks/match-cuts/chain";++const W = 640, H = 360, ASPECT = W / H;+const EYE = [0, 0, 6], CAM = { eye: EYE, look: [0, 0, 0], fov: 45 };+/** the frame's half height and width on the plane the hooks stand on (6 m ahead) */+const HALF = 6 * Math.tan((22.5 * Math.PI) / 180);++type Cheat = "off" | "drift" | "renamed" | "late" | "unfilled" | "behind" | "jlate" | "lstop";+export const CHEATS: Cheat[] = ["off", "drift", "renamed", "late", "unfilled", "behind", "jlate", "lstop"];++const ease = (t: number) => t * t * (3 - 2 * t);+const lerp = (a: number[], b: number[], t: number) => a.map((x, i) => x + (b[i] - x) * t);++/** a hook's part: its glyph's shape at (u, v) on the frame, or filling it (`fill` 1: the frame, more: past it); `grow` scales it */+function Hooked({ name, glyph, uv, fill = 0, z = 0, grow = 1 }: { name: string; glyph: Glyph; uv: number[]; fill?: number; z?: number; grow?: number }) {+ const [x, y] = onFrame(uv[0], uv[1], 6 - z, CAM, ASPECT);+ const half: [number, number, number] = fill > 0 ? [HALF * ASPECT * fill, HALF * fill, 0.05]+ : glyph === "rect" ? [0.4, 0.28, 0.05] : glyph === "streaks" ? [0.06, 0.45, 0.06] : glyph === "blob" ? [0.35, 0.25, 0.2] : glyph === "hline" ? [1.2, 0.04, 0.04] : [0.25, 0.25, 0.25];+ const colour = { circle: "#e8a33d", rect: "#2bb3a6", streaks: "#9fd8ff", blob: "#d65a7a" }[glyph as string] ?? "#cccccc";+ return (+ <Mesh3d name={name} transform={Transform.fromXyz(x, y, z).withScale([grow, grow, grow])}>+ {glyph === "circle" && !fill ? <Sphere radius={0.25} /> : <Cuboid half_size={half} />}+ <StandardMaterial base_color={colour} />+ </Mesh3d>+ );+}++/** one shot: its in hook's part where the chain says, and its out hook's carried from the in place to its own */+function Shot({ i, frames, cheat }: { i: number; frames: number; cheat?: Cheat }) {+ const f = useCurrentFrame();+ const s = good.shots[i];+ const t = ease(Math.min(1, f / Math.max(1, frames - 1)));+ const at = (h: Hook) => centreOf(h.at);+ let inAt = at(s.in), outAt = at(s.out);+ if (cheat === "off" && s.name === "window") inAt = centreOf("TL");+ // drift: the steam is at its place halfway through, then leaves it+ const outUv = cheat === "drift" && s.name === "kitchen" ? (t < 0.5 ? lerp(inAt, outAt, t * 2) : lerp(outAt, centreOf("CC"), (t - 0.5) * 2)) : lerp(inAt, outAt, t);+ const outName = cheat === "renamed" && s.out.part === "steam" ? "vapour" : s.out.part!;+ // a FULL hook fills the frame at its end of the shot (1.15: past its edges); unfilled, half of it+ const outFill = s.out.at === "FULL" ? (cheat === "unfilled" ? 0.15 + 0.55 * t : 0.15 + t) : 0;+ const inFill = s.in.at === "FULL" ? 1.15 * (1 - t) + 0.1 * t : 0;+ // the carried part stands 0.6 m nearer the eye than the in part, so the two never pass through each other+ const behind = cheat === "behind" && s.out.part === "mug" ? 8 * t : 0.6;+ const same = s.in.part === s.out.part;+ return (+ <AbsoluteFill style={{ background: "#202630" }}>+ <Camera3d transform={Transform.fromXyz(EYE[0], EYE[1], EYE[2]).lookingAt([0, 0, 0])} />+ <DirectionalLight illuminance={9000} transform={Transform.fromXyz(2, 4, 6).lookingAt([0, 0, 0])} />+ {!same && s.in.part !== "7:45" && <Hooked name={s.in.part!} glyph={s.in.glyph} uv={s.in.at === "FULL" ? centreOf("CC") : inAt} fill={inFill} />}+ {s.out.part === "7:45" ? (+ // a text hook: the clock's time, its box centred on the out place+ <div style={{ position: "absolute", left: outAt[0] * W - 60, top: outAt[1] * H - 24, width: 120, height: 48, lineHeight: "48px", textAlign: "center", fontSize: 36, color: "#f4efe6" }}>7:45</div>+ ) : (+ <Hooked name={outName} glyph={s.out.glyph} uv={s.out.at === "FULL" ? lerp(inAt, centreOf("CC"), t) : outUv} fill={outFill} z={same ? 0 : behind} grow={same || outFill ? 1 : Math.max(0.01, Math.min(1, t * 4))} />+ )}+ </AbsoluteFill>+ );+}++function Piece({ cheat }: { cheat?: Cheat }) {+ const seqs = sequences(good);+ // late: the window shot starts ten frames after the chain's cut+ if (cheat === "late") { seqs[0].durationInFrames += 10; seqs[1].from += 10; seqs[1].durationInFrames -= 10; }+ const cut = (name: string) => seqs.find((s) => s.name === name)!.from;+ return (+ <AbsoluteFill style={{ background: "#202630" }}>+ {seqs.map((q, i) => (+ <Sequence key={q.name} name={q.name} from={q.from} durationInFrames={q.durationInFrames}>+ <Shot i={i} frames={q.durationInFrames} cheat={cheat} />+ </Sequence>+ ))}+ {/* J: the brakes start half a second before the cut into the bus; L: the doors run on half a second into the office */}+ <Sequence from={cut("bus") - (cheat === "jlate" ? 0 : 15)} durationInFrames={45}><Audio src="media/brakes.wav" /></Sequence>+ <Sequence from={cut("bus")} durationInFrames={cheat === "lstop" ? 30 : 60}><Audio src="media/doors.wav" /></Sequence>+ </AbsoluteFill>+ );+}++registerRoot(() => (+ <>+ <Composition id="graybox" component={Piece} width={W} height={H} fps={good.fps} durationInFrames={Math.round(good.length * good.fps)} />+ {CHEATS.map((c) => <Composition key={c} id={c} component={() => <Piece cheat={c} />} width={W} height={H} fps={good.fps} durationInFrames={Math.round(good.length * good.fps)} />)}+ </>+));diff --git a/bench/direction/match-cuts/match-cuts.sh b/bench/direction/match-cuts/match-cuts.shnew file mode 100755index 00000000..78d530ae--- /dev/null+++ b/bench/direction/match-cuts/match-cuts.sh@@ -0,0 +1,59 @@+#!/usr/bin/env bash+# The match-cut checks' proof (docs/match-cuts.feature MC2, MC3), in a copy of this folder with the kit copied+# (sdk/guides/craft/match-cuts to checks/match-cuts), as a project copies it:+# 1. the plan checks (chain.ts) pass on good.chain.ts, and each cheat in cheats.ts fails the one check it names;+# `bun checks/match-cuts/plan.ts` runs them by name.+# 2. the render check (thirds.ts) on the graybox of that chain finds nothing, and finds each of its cheats.+#+# RAEA_BIN=path/to/raea bash bench/direction/match-cuts/match-cuts.sh (KEEP=1 keeps the copy)+set -uo pipefail+here=$(cd "$(dirname "$0")" && pwd)+root=$(cd "$here/../../.." && pwd)+raea=${RAEA_BIN:-raea}+work=$(mktemp -d "${TMPDIR:-/tmp}/raea-match-cuts.XXXXXX")+if [ -n "${KEEP:-}" ]; then trap 'echo "match-cuts: kept $work"' EXIT; else trap 'rm -rf "$work"' EXIT; fi+cp -R "$here/." "$work/"+rm -f "$work/match-cuts.sh"+mkdir -p "$work/.raea" "$work/out" "$work/checks/match-cuts"+: >"$work/.raea/project"+cp "$root"/sdk/guides/craft/match-cuts/* "$work/checks/match-cuts/"+cd "$work" || exit 2+bad=0++echo "1. the plan checks"+bun cheats.ts || bad=$((bad + 1))+out=$(bun checks/match-cuts/plan.ts good.chain.ts --only lands,glyph 2>&1)+if [ $? -eq 0 ] && grep -q "2 pass, 0 fail" <<<"$out"; then echo "ok plan.ts runs two checks by name"; else echo "FAIL plan.ts --only lands,glyph: $out"; bad=$((bad + 1)); fi+bun checks/match-cuts/plan.ts good.chain.ts --only nope >/dev/null 2>&1+[ $? -ne 0 ] && echo "ok plan.ts refuses a check it doesn't have" || { echo "FAIL plan.ts ran a check named nope"; bad=$((bad + 1)); }++echo "2. the render check on the graybox (graybox.tsx) and its cheats"+# the two bridges' sounds: two seconds of a tone each, written here (16-bit mono, 48 kHz)+mkdir -p media+bun -e 'for (const [f, hz] of [["media/brakes.wav", 220], ["media/doors.wav", 330]]) { const n = 96000, b = Buffer.alloc(44 + n * 2); b.write("RIFF", 0); b.writeUInt32LE(36 + n * 2, 4); b.write("WAVEfmt ", 8); b.writeUInt32LE(16, 16); b.writeUInt16LE(1, 20); b.writeUInt16LE(1, 22); b.writeUInt32LE(48000, 24); b.writeUInt32LE(96000, 28); b.writeUInt16LE(2, 32); b.writeUInt16LE(16, 34); b.write("data", 36); b.writeUInt32LE(n * 2, 40); for (let i = 0; i < n; i++) b.writeInt16LE(Math.round(8000 * Math.sin((2 * Math.PI * hz * i) / 48000)), 44 + i * 2); await Bun.write(f, b); }' || { echo "match-cuts: couldn't write the tones"; exit 2; }+# COMPOSITION ASK WANT: `raea check graybox.tsx --composition COMPOSITION --only ASK` finds nothing (none) or+# something (some), and every finding it prints is shown+case_() {+ local comp=$1 id=$2 want=$3 out code n+ out=$("$raea" check graybox.tsx --composition "$comp" --only "$id" --json 2>"out/$comp.$id.err")+ code=$?+ if [ $code -eq 2 ] || ! jq -e .compositions >/dev/null 2>&1 <<<"$out"; then+ echo "FAIL $comp --only $id: raea check couldn't check it (exit $code): $(tail -3 "out/$comp.$id.err")"+ bad=$((bad + 1))+ return+ fi+ n=$(jq '[.compositions[].findings[]] | length' <<<"$out")+ local ok=1+ { [ "$want" = none ] && [ "$n" -ne 0 ]; } && ok=0+ { [ "$want" = some ] && [ "$n" -eq 0 ]; } && ok=0+ [ $ok -eq 1 ] || bad=$((bad + 1))+ printf '%s %s --only %s: %s finding(s)\n' "$([ $ok -eq 1 ] && echo "ok " || echo FAIL)" "$comp" "$id" "$n"+ jq -r '.compositions[].findings[] | " \(.level) \(.frames // "" | tostring): \(.says)"' <<<"$out"+}+case_ graybox n1.1 none+for c in off drift renamed late unfilled behind jlate lstop; do case_ "$c" n1.1 some; done+# the chain's own cheat: a hook that names no part (checks/morning-nopart.ts), on the graybox that holds+case_ graybox n1.2 some++[ $bad -eq 0 ] && echo "match-cuts: all ok" || echo "match-cuts: $bad failed"+exit $((bad > 0))diff --git a/bench/direction/match-cuts/notes/1/n1.ts b/bench/direction/match-cuts/notes/1/n1.tsnew file mode 100644index 00000000..cd688ceb--- /dev/null+++ b/bench/direction/match-cuts/notes/1/n1.ts@@ -0,0 +1,13 @@+// A note as the person said it, restated as asks held by the match-cut render check (MC3), copied to checks/ by+// match-cuts.sh with the kit, as a project copies them.+import { note } from "raea/note";++export default note({+ words: ["Every cut should land where my eye already is."],+ from: "session",+ round: 1,+ asks: [+ { text: "every cut lands on the thirds place the last shot left the eye", about: "cuts", not: ["the shots' order"], verb: "recut", check: "../../checks/morning.ts" },+ { text: "every hook names the part that draws it", about: "cuts", not: ["the shots' order"], verb: "recut", check: "../../checks/morning-nopart.ts" },+ ],+});diff --git a/docs/match-cuts.feature b/docs/match-cuts.featureindex 3df4583b..79e413b0 100644--- a/docs/match-cuts.feature+++ b/docs/match-cuts.feature@@ -52,7 +52,14 @@ Feature: Match cuts on the thirds: a piece's cuts planned as a chain of hooks, cRule: The render is checked at every cut+ @doneScenario: MC3. thirds.ts: at each cut the hooked part sits at its thirds place on the frame before and the frame after+ # Status 11-10: built. landsOnThirds(chain) reads raea world's facts on the cut frames only, with no render. A part+ # is measured by its world box through the frame's camera, which is aimed with lookingAt or a rotation; a text by its+ # laid-out box. On the bench's graybox it finds nothing, and it finds each of the nine cheats above. It runs from a+ # note's ask (--only n1.1) or a controller's rule (--only and the check file's name: morning). The whole bench,+ # plan, render and board, runs in 9 s. What it can't see: a part hidden behind another, a camera rolled about its+ # view, the eye's way inside a shot, and a 2D graphic that isn't text.Given the plan| crate | file | lines | job || - | sdk/guides/craft/match-cuts/thirds.ts | 260 | landsOnThirds(chain): a raea/check system on the chain's cut frames; each hooked part projected through the frame's camera (or a text's box) and held to its place within a tolerance, FULL to a share of the frame; each chain cut a cut in the composition; J and L bridges' cues; the plan checks after the frames |diff --git a/sdk/guides/craft/match-cuts/thirds.ts b/sdk/guides/craft/match-cuts/thirds.tsnew file mode 100644index 00000000..e84f8ee5--- /dev/null+++ b/sdk/guides/craft/match-cuts/thirds.ts@@ -0,0 +1,183 @@+// The match cuts, checked in the render (`raea guide match-cuts`): at every cut of a chain (chain.ts), the hooked part+// sits at its thirds place on the frame before the cut and on the frame after it. A project makes the check from its+// chain in a file of its own, and a rule (a controller's, or a note's ask) names that file:+//+// // checks/film-cuts.ts+// import { landsOnThirds } from "./match-cuts/thirds";+// import film from "../film.chain";+// export default landsOnThirds(film);+//+// { label: "the cuts land on the thirds", type: "rule", check: "../checks/film-cuts.ts", values: { tolerance: 0.06 } }+//+// `raea check film.tsx --only film-cuts` runs it alone (a rule goes by its check file's name; a note's ask by its own+// id, as `--only n1.1`), and its findings say `lands-on-thirds`. Its values: `tolerance`, how far a hook may sit from its+// place, as a share of the frame's width (across) and height (down), 0.06 when unset (the thirds' points are a sixth of+// the frame apart); `full`, the share of the frame a FULL hook covers, 0.9 when unset; `plan`, false to leave out the+// plan checks, which otherwise run once after the frames, so one rule holds both.+//+// It reads raea world's facts, no render: a part (matched by raea/check's named(): its name, its model file, its layer+// key, or component:Name) by its world box, projected through the frame's camera; a text by its laid-out box. Where+// several parts have the name, the one nearest its place is measured. Each cut of the chain must be a cut of the+// composition: a Sequence that starts on the chain's frame (and has the shot's name, when the chain gives one). A J+// bridge's sound is placed `seconds` before the cut and is playing on the frame before it; an L bridge's is playing on+// the cut's frame and on the bridge's last.+//+// Its cheats, each failed (bench/direction/match-cuts/match-cuts.sh): a hook off its place; one at its place mid-shot+// that has left by the cut; the hooked part renamed or gone; a cut off the chain's frame; a FULL that doesn't fill the+// frame; a part behind the camera; a hook that names no part; a J bridge's sound starting at the cut; an L bridge's+// sound stopping at it.+//+// What it can't see: a part hidden behind another (it measures where things are, not what is drawn over them), a+// camera rolled about its view (it takes Y as up), the eye's way inside a shot (the plan's carry says it), and a 2D+// graphic that isn't text (raea world has no box for one).+import { check, found, named, type Camera, type Check, type Cue, type Part, type Shot, type Text, type World } from "raea/check";+import { LINES, NAMES, centreOf, cuts as cutsOf, planned, toFrame, type At, type Chain, type Cut, type Hook, type View } from "./chain";++type Box = [number, number, number, number];+/** A hook measured on a frame: where its centre falls, the box it covers on the frame (clipped to it), and what. */+type Seen = { id: number; name: string; u: number; v: number; cover: number };+/** One thing to measure on a frame: a cut's out hook on the frame before it, its in hook on its own frame. */+type Look = { cut: Cut | null; side: "out" | "in"; hook: Hook; loop?: boolean };++/** How far (u, v) is from `at`, as a share of the frame: across and down for a point, one of them for a line. */+function off(at: At, u: number, v: number): number {+ if (at === "FULL") return 0;+ const [tu, tv] = centreOf(at);+ if (at in LINES) return LINES[at as keyof typeof LINES].axis === "H" ? Math.abs(v - tv) : Math.abs(u - tu);+ return Math.max(Math.abs(u - tu), Math.abs(v - tv));+}++const area = (b: Box) => Math.max(0, Math.min(1, b[2]) - Math.max(0, b[0])) * Math.max(0, Math.min(1, b[3]) - Math.max(0, b[1]));++/** A world box on the frame: its corners in front of the eye and where its edges cross the near plane, projected. Null+ * when it is all behind the eye. */+function boxOnFrame(min: number[], max: number[], cam: View, aspect: number, near: number): Box | null {+ const corners = [0, 1, 2, 3, 4, 5, 6, 7].map((i) => [i & 1 ? max[0] : min[0], i & 2 ? max[1] : min[1], i & 4 ? max[2] : min[2]]);+ const z = corners.map((p) => toFrame(p, cam, aspect).z);+ const pts: number[][] = corners.filter((_, i) => z[i] > near);+ for (let i = 0; i < 8; i++) for (const bit of [1, 2, 4]) {+ const j = i | bit;+ if (j === i || (z[i] > near) === (z[j] > near)) continue;+ const t = (near - z[i]) / (z[j] - z[i]);+ pts.push(corners[i].map((x, k) => x + (corners[j][k] - x) * (t + 1e-6)));+ }+ if (!pts.length) return null;+ const on = pts.map((p) => toFrame(p, cam, aspect));+ return [Math.min(...on.map((p) => p.u)), Math.min(...on.map((p) => p.v)), Math.max(...on.map((p) => p.u)), Math.max(...on.map((p) => p.v))];+}++/** Every part or text named `part` on the frame, measured; and the parts of that name behind the eye. */+function measure(world: World, part: string, aspect: number): { seen: Seen[]; behind: string[] } {+ const seen: Seen[] = [];+ const behind: string[] = [];+ const camId = world.find({ with: ["Camera"] })[0];+ const cam = camId === undefined ? undefined : world.component<Camera>(camId, "Camera");+ for (const id of world.find({ with: ["Text"] })) {+ const t = world.component<Text>(id, "Text")!;+ if (!t.box || !(named(world, id, part) || t.words.toLowerCase().startsWith(part.toLowerCase()))) continue;+ const b = t.box as Box;+ seen.push({ id, name: t.words, u: (b[0] + b[2]) / 2, v: (b[1] + b[3]) / 2, cover: area(b) });+ }+ for (const id of world.find({ with: ["Part"] })) {+ const p = world.component<Part>(id, "Part")!;+ if (!named(world, id, part) || !p.min || !p.max) continue;+ if (!cam) { behind.push(`${p.name} (no camera on the frame)`); continue; }+ const centre = [0, 1, 2].map((k) => (p.min![k] + p.max![k]) / 2);+ const c = toFrame(centre, cam, aspect);+ const box = boxOnFrame(p.min, p.max, cam, aspect, cam.near);+ if (c.z <= cam.near || !box) { behind.push(p.name); continue; }+ seen.push({ id, name: p.name, u: c.u, v: c.v, cover: area(box) });+ }+ return { seen, behind };+}++const pct = (x: number) => `${Math.round(x * 100)}%`;+const stem = (s: string) => (s.split("/").pop() ?? s).replace(/\.[^.]+$/, "").toLowerCase();++export type Options = { id?: string; tolerance?: number; full?: number; plan?: boolean };++/** The check that holds a composition to its chain at every cut (its values override `opts`). */+export function landsOnThirds(c: Chain, opts: Options = {}): Check {+ const fps = c.fps;+ const looks = new Map<number, Look[]>();+ const at = (f: number, l: Look) => { if (f >= 0) looks.set(f, [...(looks.get(f) ?? []), l]); };+ const all = cutsOf(c);+ for (const k of all) {+ if (k.join === "hard") continue;+ at(k.frame - 1, { cut: k, side: "out", hook: k.leaves.out });+ at(k.frame, { cut: k, side: "in", hook: k.lands.in });+ }+ const last = Math.round(c.length * fps) - 1;+ if (c.loop && c.shots.length > 1) {+ at(0, { cut: null, side: "in", hook: c.shots[0].in, loop: true });+ at(last, { cut: null, side: "out", hook: c.shots[c.shots.length - 1].out, loop: true });+ }+ // the frames a bridge is heard on: J the frame before its cut; L its cut's frame and its last+ const lEnd = (k: Cut) => k.frame + Math.max(1, Math.round(k.lands.bridge!.seconds * fps)) - 1;+ const frames = new Set<number>(looks.keys());+ for (const k of all) {+ frames.add(k.frame);+ if (k.lands.bridge?.kind === "J") frames.add(k.frame - 1);+ if (k.lands.bridge?.kind === "L") frames.add(lEnd(k));+ }++ return check(+ { id: opts.id ?? "lands-on-thirds", text: "at every cut the hooked part sits at its thirds place, on the frame before and the frame after", frames: [...frames].filter((f) => f >= 0).sort((a, b) => a - b) },+ (world, frame, values, memo) => {+ const fr = world.resource("Frame") as { width: number; height: number };+ const aspect = fr.width / fr.height;+ const tol = Number(values.tolerance ?? opts.tolerance ?? 0.06);+ const full = Number(values.full ?? opts.full ?? 0.9);+ memo.cuts ??= {};+ memo.unnamed ??= {};+ const shots = world.find({ with: ["Shot"] }).map((id) => world.component<Shot>(id, "Shot")!);+ for (const k of all) {+ if (k.frame !== frame) continue;+ const name = k.lands.name;+ if (shots.some((s) => s.from === frame && (!name || s.name === name))) memo.cuts[k.index] = true;+ }+ for (const l of looks.get(frame) ?? []) {+ const where = l.loop ? `the loop's ${l.side === "in" ? "first" : "last"} frame` : `the frame ${l.side === "out" ? "before" : "after"} cut ${l.cut!.index} (${l.cut!.leaves.scene} to ${l.cut!.lands.scene}, ${l.cut!.time.toFixed(2)} s)`;+ if (!l.hook.part?.trim()) { memo.unnamed[`${l.cut?.index ?? "loop"} ${l.side}`] = `${l.hook.what} (${where})`; continue; }+ const { seen, behind } = measure(world, l.hook.part, aspect);+ if (!seen.length) {+ found({ about: [l.hook.part], says: behind.length ? `${l.hook.what} (${l.hook.part}) is behind the camera on ${where}` : `no part or text named ${l.hook.part} (${l.hook.what}) on ${where}`, fix: behind.length ? "put it in front of the camera, at its place" : "name the part as the chain's hook does (raea world lists the frame's parts)" });+ continue;+ }+ if (l.hook.at === "FULL") {+ const best = seen.reduce((a, s) => (s.cover > a.cover ? s : a));+ if (best.cover < full) found({ about: [best.id], says: `${l.hook.what} (${best.name}) covers ${pct(best.cover)} of ${where}, not the whole frame`, measure: { name: "cover", value: Math.round(best.cover * 100) / 100, unit: "share", limit: full } });+ continue;+ }+ const best = seen.reduce((a, s) => (off(l.hook.at, s.u, s.v) < off(l.hook.at, a.u, a.v) ? s : a));+ const d = off(l.hook.at, best.u, best.v);+ if (d > tol) found({ about: [best.id], says: `${l.hook.what} (${best.name}) sits at ${pct(best.u)} across, ${pct(best.v)} down on ${where}, ${pct(d)} of the frame from the ${NAMES[l.hook.at]}`, measure: { name: "off", value: Math.round(d * 1000) / 1000, unit: "share", limit: tol } });+ }+ // the bridges: a cue of the bridge's sound, by its file's name or its layer+ const cues = world.find({ with: ["Cue"] }).map((id) => ({ id, cue: world.component<Cue>(id, "Cue")! }));+ const heard = (sound: string) => cues.filter(({ id, cue }) => named(world, id, sound) || stem(cue.source).startsWith(sound.toLowerCase()));+ for (const k of all) {+ const b = k.lands.bridge;+ if (!b) continue;+ const into = `cut ${k.index} (${k.leaves.scene} to ${k.lands.scene}, ${k.time.toFixed(2)} s)`;+ if (b.kind === "J" && frame === k.frame - 1) {+ const want = k.time - b.seconds;+ const got = heard(b.sound);+ if (!got.some(({ cue }) => Math.abs(cue.at - want) <= 1.5 / fps)) found({ about: [b.sound], says: got.length ? `the J bridge's ${b.sound} starts at ${got[0].cue.at.toFixed(2)} s, not ${b.seconds} s before ${into}` : `the J bridge's ${b.sound} isn't playing on the frame before ${into}`, fix: `start it at ${want.toFixed(2)} s, under the shot before` });+ }+ if (b.kind === "L" && (frame === k.frame || frame === lEnd(k))) {+ const got = heard(b.sound).filter(({ cue }) => cue.at < k.time - 0.5 / fps);+ if (!got.length) found({ about: [b.sound], says: `the L bridge's ${b.sound} ${frame === k.frame ? "stops at" : "doesn't run"} ${b.seconds} s past ${into}`, fix: `let the sound the shot before started run ${b.seconds} s into ${k.lands.scene}` });+ }+ }+ },+ (values, memo) => {+ for (const k of all) {+ if (!memo.cuts?.[k.index]) found({ about: [k.lands.name ?? k.lands.scene], frames: [k.frame, k.frame + 1], says: `the chain cuts into ${k.lands.scene} on frame ${k.frame} (${k.time.toFixed(2)} s), and the composition doesn't: no Sequence${k.lands.name ? ` named ${k.lands.name}` : ""} starts there`, fix: "build each shot as its Sequence from the chain (chain.ts sequences())" });+ }+ for (const [k, what] of Object.entries((memo.unnamed ?? {}) as Record<string, string>)) found({ says: `the hook ${what} names no part, so nothing measures it`, fix: "give the hook the part that draws it (part: its name in the scene)" });+ if ((values.plan ?? opts.plan ?? true) === false) return;+ for (const r of planned(c)) for (const f of r.fails) found({ says: `the plan, ${r.id}: ${f}`, fix: r.text });+ },+ );+}