Skip to content

armgit / raea

Public Imported from GitHub
0

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.

MC2: a piece's cuts planned as a chain of hooks on the frame's thirds, and checked by name before anything renders (docs/match-cuts.feature). sdk/guides/craft/match-cuts/chain.ts holds the thirds (nine points, four lines, FULL), the glyphs and which read as the same thing, hooks (what the eye is on, where, and optionally the part that draws it, the way it moves, its colour and light), shots with the join they are cut into by (graphic, motion, eye, full, sound, hard) and chain(), which places each shot on the piece's frames; toFrame and onFrame put a point in the world on the frame and back (Y up, vertical field of view, as Bevy draws it: a ball placed by them lands within 0.0004 of the frame of where the render draws it). Its eleven plan checks: hooks, length (to a frame), lands (every match cut lands the eye where the last shot left it; a point on a thirds line lands on that line; FULL only on FULL), glyph (graphic cuts and montages), motion (the direction kept), carry (a shot that moves the eye says what moves it), hard (says what it lands on), beats (cut to music, every picture cut on a beat; an eye-trace cut always), bridge (J and L sounds that fit their shots), montage (three or more shots handing one hook on) and loop. It imports nothing, so bun and raea check's bundle both run it; plan.ts runs the checks on a NAME.chain.ts by name (--only lands,glyph). A chain is NAME.chain.ts, since cuts.ts is a project's footage edit. bench/direction/match-cuts: a twelve-second chain using every join passes all eleven, and each of fourteen cheats made from it by one change fails the check it names and no other. On the chain of the film this was taken from, lands, glyph and length pass as its own checks do, and beats finds its montage's cuts drifting 44-51 ms off the song's beats

shinyobjectz85c13e6daaff
diff --git a/bench/direction/match-cuts/cheats.ts b/bench/direction/match-cuts/cheats.ts
new file mode 100644
index 00000000..a51c661a
--- /dev/null
+++ b/bench/direction/match-cuts/cheats.ts
@@ -0,0 +1,43 @@
+// MC2's cases (docs/match-cuts.feature): every plan check passes on good.chain.ts, and each cheat below, good.chain.ts with one
+// thing changed, fails the check it names and no other. `bun cheats.ts` in the bench's copy; exit 1 on a miss.
+import good from "./good.chain";
+import { chain, planned, type Chain, type Hook, type Placed } from "./checks/match-cuts/chain";
+
+/** good with shot `i` (by its name) changed */
+const shot = (name: string, f: (s: Placed) => Partial<Placed>, top: Partial<Chain> = {}): Chain =>
+ chain({ ...good, ...top, shots: good.shots.map((s) => (s.name === name ? { ...s, ...f(s) } : s)) });
+const hook = (h: Hook, more: Partial<Hook>): Hook => ({ ...h, ...more });
+
+export const CHEATS: { fails: string; what: string; chain: Chain }[] = [
+ { fails: "hooks", what: "a hook that says nothing of what the eye is on", chain: shot("bus", (s) => ({ out: hook(s.out, { what: "" }) })) },
+ { fails: "length", what: "the chain a second short of the piece", chain: chain({ ...good, length: 13 }) },
+ { fails: "lands", what: "the rain lands on the upper left, the steam left the eye upper right", chain: shot("window", (s) => ({ in: hook(s.in, { at: "TL" }) })) },
+ { fails: "lands", what: "a full cut into a shot that doesn't start filled", chain: shot("crema", (s) => ({ in: hook(s.in, { at: "CC" }) })) },
+ { fails: "glyph", what: "a graphic cut from steam to a circle", chain: shot("window", (s) => ({ in: hook(s.in, { glyph: "circle" }) })) },
+ { fails: "motion", what: "the cyclist rides left out of a tram going right", chain: shot("street", (s) => ({ in: hook(s.in, { move: "left" }) })) },
+ { fails: "carry", what: "the eye moves from the lid to the steam with nothing carrying it", chain: shot("kitchen", () => ({ carry: undefined })) },
+ { fails: "hard", what: "a hard cut on nothing", chain: shot("office", () => ({ on: undefined })) },
+ { fails: "beats", what: "the montage's last cut off the beat", chain: chain({ ...good, shots: good.shots.map((s) => (s.name === "dial" ? { ...s, seconds: 0.4 } : s.name === "record" ? { ...s, seconds: 0.6 } : s)) }) },
+ { fails: "beats", what: "an eye-trace cut in a chain with no beats", chain: chain({ ...good, beats: undefined }) },
+ { fails: "bridge", what: "a J bridge longer than the shot it plays under", chain: shot("bus", (s) => ({ bridge: { ...s.bridge!, seconds: 0.75 } })) },
+ { fails: "bridge", what: "a sound cut with no sound carried", chain: shot("bus", () => ({ bridge: undefined })) },
+ { fails: "montage", what: "a montage of two shots", chain: shot("record", () => ({ montage: undefined })) },
+ { fails: "loop", what: "the loop back from a square to the kettle's circle", chain: shot("office", (s) => ({ out: hook(s.out, { glyph: "rect" }) })) },
+];
+
+if (import.meta.main) {
+ let bad = 0;
+ const all = planned(good);
+ const passed = all.every((r) => !r.fails.length);
+ if (!passed) bad++;
+ console.log(`${passed ? "ok " : "FAIL"} good.chain.ts: ${all.filter((r) => !r.fails.length).length} of ${all.length} plan checks pass`);
+ for (const r of all.filter((r) => r.fails.length)) console.log(` ${r.id}: ${r.fails.join("; ")}`);
+ for (const c of CHEATS) {
+ const failed = planned(c.chain).filter((r) => r.fails.length);
+ const ok = failed.length === 1 && failed[0].id === c.fails;
+ if (!ok) bad++;
+ console.log(`${ok ? "ok " : "FAIL"} ${c.what}: fails ${failed.map((r) => r.id).join(", ") || "nothing"} (want ${c.fails})`);
+ for (const r of failed) console.log(` ${r.id}: ${r.fails.join("; ")}`);
+ }
+ process.exit(bad ? 1 : 0);
+}
diff --git a/bench/direction/match-cuts/good.chain.ts b/bench/direction/match-cuts/good.chain.ts
new file mode 100644
index 00000000..82d3a16d
--- /dev/null
+++ b/bench/direction/match-cuts/good.chain.ts
@@ -0,0 +1,27 @@
+// MC2's chain (docs/match-cuts.feature): twelve seconds that use every join once or more, on 120 bpm's beats, and loop. The
+// bench copies craft/match-cuts to checks/cuts beside it, as a project does; cuts.tsx is its graybox.
+import { chain } from "./checks/match-cuts/chain";
+
+const h = (what: string, at: import("./checks/match-cuts/chain").At, glyph: import("./checks/match-cuts/chain").Glyph, part: string, more: object = {}) => ({ what, at, glyph, part, ...more });
+
+export default chain({
+ title: "Morning",
+ fps: 30,
+ length: 12,
+ aspect: [16, 9],
+ beats: Array.from({ length: 25 }, (_, i) => i * 0.5),
+ loop: true,
+ shots: [
+ // the loop's cut back into the first shot is graphic: the mug's circle at the centre to the kettle's lid there
+ { name: "kitchen", scene: "kitchen", seconds: 2, in: h("the kettle's lid", "CC", "circle", "lid"), out: h("the steam", "TR", "streaks", "steam"), carry: "the steam rises to the upper right" },
+ { name: "window", scene: "window", seconds: 2, cut: "graphic", in: h("rain on the glass", "TR", "streaks", "rain"), out: h("the tram passing below", "MR", "rect", "tram", { move: "right" }), carry: "a drop runs down the glass onto the tram" },
+ { name: "street", scene: "street", seconds: 1.5, cut: "motion", in: h("a cyclist crossing", "MR", "rect", "cyclist", { move: "right" }), out: h("the stop's clock", "TL", "circle", "7:45"), carry: "the camera pans with the cyclist and tilts up to the clock" },
+ { name: "cafe", scene: "cafe", seconds: 1.5, cut: "eye", on: "the downbeat at 5.5 s", in: h("the barista's face", "TL", "blob", "barista"), out: h("the cup, pushed into", "FULL", "rect", "cup"), carry: "the push into the cup until it fills the lens" },
+ { name: "crema", scene: "cup", seconds: 1, cut: "full", in: h("the coffee filling the frame", "FULL", "blob", "coffee"), out: h("the crema's ring", "CC", "circle", "crema"), carry: "the pull back to the ring at the centre" },
+ { name: "saucer", scene: "saucer", seconds: 0.5, cut: "graphic", montage: true, in: h("a saucer", "CC", "circle", "saucer"), out: h("a saucer", "CC", "circle", "saucer") },
+ { name: "dial", scene: "clocktower", seconds: 0.5, cut: "graphic", montage: true, in: h("a clock's face", "CC", "circle", "dial"), out: h("a clock's face", "TC", "circle", "dial"), carry: "the tilt up hands the face to the upper third" },
+ { name: "record", scene: "record shop", seconds: 0.5, cut: "graphic", montage: true, in: h("a record", "TC", "circle", "record"), out: h("a record", "TC", "circle", "record") },
+ { name: "bus", scene: "bus", seconds: 1, cut: "sound", bridge: { kind: "J", sound: "brakes", seconds: 0.5 }, in: h("the bus doors", "ML", "rect", "doors"), out: h("the bus doors", "ML", "rect", "doors") },
+ { name: "office", scene: "office", seconds: 1.5, cut: "hard", on: "the kick on the bar at 10.5 s", bridge: { kind: "L", sound: "doors", seconds: 0.5 }, in: h("the monitor", "BR", "rect", "monitor"), out: h("the mug on the desk", "CC", "circle", "mug"), carry: "the cursor drags the mug to the centre" },
+ ],
+});
diff --git a/docs/match-cuts.feature b/docs/match-cuts.feature
new file mode 100644
index 00000000..3df4583b
--- /dev/null
+++ b/docs/match-cuts.feature
@@ -0,0 +1,78 @@
+@spec
+Feature: Match cuts on the thirds: a piece's cuts planned as a chain of hooks, checked in the plan and in the render
+ Shane, 11-10: "lets also ink in this match cut framework too to the skills library its a cool idea and worth sedning
+ to a subagent to flesh out more ways to use and check and utilize it throughout ahot planning. the other agent workeid
+ on it for the stay video".
+
+ A film made for Stay planned its cuts on the frame's thirds: each shot takes the eye in where the last one left it,
+ on the same kind of thing (a hook), and its action carries the eye to the place the next cut leaves from. This
+ feature makes that a planning guide, a plan-level module with its checks, a render-level check, and a board any
+ project can draw its chain on. All of it is craft: a guide, and a kit a project copies from the skill
+ (sdk/guides/craft/match-cuts, copied to the skill's craft/match-cuts and from there to a project's
+ checks/match-cuts), with no change to the SDK or the CLI. A chain lives in NAME.chain.ts beside its storyboard
+ (cuts.ts is a project's footage edit, `raea cut`'s). The scenarios are built in the order MC2, MC1, MC3, MC4, MC5
+ and land together at the release go, so none waits on another one landing.
+
+ Background:
+ Given the frame's thirds: nine points (the four intersections, the middles of the thirds lines, the centre), four
+ lines (H1, H2 across, V1, V2 down) and FULL, a thing that fills the frame
+ And a hook: what the eye is on (its glyph: circle, rect, hline, vline, vanish, diag, blob, streaks, dots), where on
+ the thirds, and optionally the part that draws it, the way it moves, its colour and its light
+ And a chain: the piece's shots in order, each with an in hook and an out hook, how it is cut into (graphic, motion,
+ eye, full, sound or hard) and what carries the eye from in to out
+
+ Rule: The plan is checked before anything renders
+
+ @done
+ Scenario: MC2. chain.ts: the thirds, hooks and the chain, with Stay's checks made general and run by name
+ # Status 11-10: built. chain.ts holds the thirds, glyphs, hooks, chain() and eleven plan checks, imports nothing,
+ # and runs under bun and inside raea check's bundle. toFrame and onFrame place a ball within 0.0004 of the frame of
+ # where the render draws it. On good.chain.ts every check passes, and each of the fourteen cheats in cheats.ts fails
+ # its own check and no other. plan.ts runs them all or by name (--only lands,glyph) and refuses an id it doesn't
+ # have. Two of MC5's fresh agents found it skipping the file when --only was absent, which is fixed, with a bench
+ # case. On Stay's chain lands, glyph and length pass, as its own checks do, and beats finds its montage 44-51 ms
+ # off the song's beats.
+ Given the plan
+ | crate | file | lines | job |
+ | - | sdk/guides/craft/match-cuts/chain.ts | 300 | the thirds, glyphs, hooks, shots and chain(); the plan checks (hooks, length, lands, glyph, motion, carry, hard, beats, bridge, montage, loop), each a function of the chain; where a point in the world falls on the frame; no raea imports, so bun and raea check's bundle both run it |
+ | - | sdk/guides/craft/match-cuts/plan.ts | 60 | `bun plan.ts NAME.chain.ts [--only ID,ID]`: the plan checks on a chain file, one line each, exit 1 on a failure |
+ | - | bench/direction/match-cuts/good.chain.ts | 80 | a short chain that uses every join: graphic, motion, eye on a beat, a FULL wipe, J and L sound bridges, a montage handing a circle on, a hard cut on a hit, and a loop back to the opening |
+ | - | bench/direction/match-cuts/cheats.ts | 120 | one cheat per plan check, each made from good.chain.ts by one change, which that check must fail |
+ Then every plan check passes on good.chain.ts and fails its own cheat, and no other check fails a cheat by accident
+ And the checks Stay holds its chain to (twenty places aside: a film's own) are lands, glyph and length here
+
+ Rule: The guide teaches the planner
+
+ Scenario: MC1. `raea guide match-cuts`: planning cuts as a chain of hooks on the thirds
+ Given the plan
+ | crate | file | lines | job |
+ | - | sdk/guides/craft/motion/match-cuts.md | 200 | the chain, choosing hooks (shape, motion direction, colour, light, sound), the action that carries the eye, when a hard cut beats a match; graphic, motion, eye-trace on a beat, FULL wipe, J and L bridges, a montage's hand-off and a loop, each with how it is checked; the render check's limits |
+ Then the story, pitch and explain modes and the router's plan step route to it
+ And tools/skills.sh copies craft/match-cuts into the skill, so the guide's files are where it says
+
+ Rule: The render is checked at every cut
+
+ Scenario: MC3. thirds.ts: at each cut the hooked part sits at its thirds place on the frame before and the frame after
+ 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 |
+ | - | bench/direction/match-cuts/graybox.tsx | 160 | a graybox of good.chain.ts's chain whose hooks sit where the chain says, and its cheats |
+ | - | bench/direction/match-cuts/match-cuts.sh | 120 | the plan cases, then raea check on the graybox (none found) and on each render cheat (some found), as asks.sh does |
+ Then each cheat fails: a hook off its place; one there mid-shot but gone by the cut; a 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
+
+ Rule: The person picks from a board
+
+ Scenario: MC4. board.tsx: any project's chain and places drawn on the thirds to pick from (`raea show board.tsx`)
+ Given the plan
+ | crate | file | lines | job |
+ | - | sdk/guides/craft/match-cuts/board.tsx | 220 | Board({ chain, places }): the eye's path through the piece, each shot's frame with its in and out hooks, the place library with picks and notes sent back with app.result |
+ Then a project's board.tsx is three lines: import Board, its chain and its places, and draw them
+
+ Rule: The guide is shown to help
+
+ Scenario: MC5. A fresh agent plans one short piece with the guide and without it; the plan checks compare them, and one graybox is rendered and checked
+ Then both runs get chain.ts's types and the same brief; only one gets the guide
+ And the plan checks' results for both are recorded here, with what the guide changed
+ And the guided chain's graybox passes the render check, or its findings are recorded and fixed
diff --git a/sdk/guides/craft/match-cuts/chain.ts b/sdk/guides/craft/match-cuts/chain.ts
new file mode 100644
index 00000000..59df4324
--- /dev/null
+++ b/sdk/guides/craft/match-cuts/chain.ts
@@ -0,0 +1,324 @@
+// A piece's cuts planned as a chain of hooks on the frame's thirds (`raea guide match-cuts`). Each shot takes the eye
+// in where the last one left it, on a hook (what the eye is on, and where on the thirds), and its action carries the
+// eye to the hook the next cut leaves from. A storyboard (NAME.script.ts) states its chain beside it, in NAME.chain.ts:
+//
+// import { chain } from "./checks/match-cuts/chain";
+// export default chain({ fps: 30, length: 12, shots: [
+// { scene: "kitchen", seconds: 4, in: { what: "the kettle", at: "CC", glyph: "circle" }, out: { what: "the steam", at: "TR", glyph: "streaks" }, carry: "the steam rises to the upper right" },
+// { scene: "street", seconds: 8, cut: "graphic", in: { what: "rain on the window", at: "TR", glyph: "streaks" }, ... },
+// ] });
+//
+// and the plan checks below hold it, by name: `bun checks/match-cuts/plan.ts NAME.chain.ts --only lands,glyph`. The render
+// check (thirds.ts) holds the composition to the same chain, at every cut.
+//
+// It imports nothing, so bun runs it and so does raea check's bundle. A project copies this folder from the skill
+// (craft/match-cuts) into its checks/match-cuts/, as it copies a note's worked checks.
+
+/** The nine points: the thirds' four crossings, the middles of the thirds lines, and the centre. */
+export type Point = "TL" | "TC" | "TR" | "ML" | "CC" | "MR" | "BL" | "BC" | "BR";
+/** The four thirds lines: H1 and H2 across (upper, lower), V1 and V2 down (left, right). */
+export type Line = "H1" | "H2" | "V1" | "V2";
+/** Where a hook is: a point, a line, or FULL, a thing that fills the frame (a screen pushed into, a sheet over the lens). */
+export type At = Point | Line | "FULL";
+/** What a hook is, as the eye reads its shape. */
+export type Glyph = "circle" | "rect" | "hline" | "vline" | "vanish" | "diag" | "blob" | "streaks" | "dots";
+/** The way a hook moves on screen at the cut: across, up or down, toward the lens or away, or turning. */
+export type Move = "left" | "right" | "up" | "down" | "in" | "out" | "cw" | "ccw";
+/** How a shot is cut into from the one before it:
+ * - graphic: the same place, a thing of the same shape (a sun to a dryer's window);
+ * - motion: the same place, moving the same way (a pan's sweep to a car passing in the pan's direction);
+ * - eye: the same place, any thing, on a beat (the eye is already there when the cut comes);
+ * - full: a thing fills the lens and the next shot starts filled (a wipe by a flank, a sheet, a push into a screen);
+ * - sound: the picture moves on and a sound carries the cut (a J or L bridge);
+ * - hard: the place breaks on purpose, on a hit (a shock, a jump in time, a new act). */
+export type Join = "graphic" | "motion" | "eye" | "full" | "sound" | "hard";
+
+export type Hook = {
+ /** what the eye is on, in words ("the sun's disc, sinking") */
+ what: string;
+ at: At;
+ glyph: Glyph;
+ /** the part or text that draws it, as raea/check's named() reads a name: the render check measures it */
+ part?: string;
+ /** the way it moves on screen at the cut: a motion join keeps it */
+ move?: Move;
+ /** its colour or its light, when the match is on them (words; the board shows them) */
+ colour?: string;
+ light?: string;
+};
+
+/** A sound carried across a cut: J, the next shot's sound starts `seconds` before the cut, under the shot before; L,
+ * the shot before's sound runs `seconds` into the next. `sound` names its file as the render check finds it (the
+ * file's name, or its start). */
+export type Bridge = { kind: "J" | "L"; sound: string; seconds: number };
+
+export type Shot = {
+ /** its Sequence's name in the composition */
+ name?: string;
+ /** the place it is in */
+ scene: string;
+ seconds: number;
+ /** where the eye comes in, and where the next cut leaves from */
+ in: Hook;
+ out: Hook;
+ /** how it is cut into from the shot before (graphic when unset); the first shot's is the loop's, when it loops */
+ cut?: Join;
+ /** what the cut lands on: a beat, a hit, a word (a hard cut must say) */
+ on?: string;
+ /** a sound carried across the cut into this shot */
+ bridge?: Bridge;
+ /** what carries the eye from in to out: a drag, the camera's move, a light's sweep (needed when they differ) */
+ carry?: string;
+ /** one of a montage's shots: a run of them hands one hook on, cut to cut */
+ montage?: boolean;
+ /** anything else the board shows */
+ note?: string;
+};
+
+export type ChainInput = {
+ title?: string;
+ fps: number;
+ /** the piece's length in seconds: the shots must run it to a frame */
+ length: number;
+ /** the frame's shape, width by height (16:9 when unset), for the board and the render check's tolerance */
+ aspect?: [number, number];
+ /** the music's beats in seconds, when cut to music: every cut lands on one */
+ beats?: number[];
+ /** the last shot's out cuts back to the first shot's in, as the piece plays again */
+ loop?: boolean;
+ shots: Shot[];
+};
+
+/** A shot placed in the piece: its start in seconds, its first frame and how many frames it runs. */
+export type Placed = Shot & { from: number; frame: number; frames: number };
+export type Chain = Omit<ChainInput, "shots"> & { shots: Placed[] };
+
+/** A cut: the shot it leaves and the one it lands in, how it joins them, and when. */
+export type Cut = { leaves: Placed; lands: Placed; join: Join; time: number; frame: number; index: number };
+
+/** A place a chain can cut to: its hooks, for the board's library. */
+export type Place = { id: string; title: string; about?: string; hooks: Hook[]; props?: string[]; kind?: string };
+
+/** A point's place on the frame, 0..1 across and down. */
+export const POINTS: Record<Point, [number, number]> = {
+ TL: [1 / 3, 1 / 3], TC: [1 / 2, 1 / 3], TR: [2 / 3, 1 / 3],
+ ML: [1 / 3, 1 / 2], CC: [1 / 2, 1 / 2], MR: [2 / 3, 1 / 2],
+ BL: [1 / 3, 2 / 3], BC: [1 / 2, 2 / 3], BR: [2 / 3, 2 / 3],
+};
+/** A line's place: H across at that height, V down at that width. */
+export const LINES: Record<Line, { axis: "H" | "V"; at: number }> = {
+ H1: { axis: "H", at: 1 / 3 }, H2: { axis: "H", at: 2 / 3 }, V1: { axis: "V", at: 1 / 3 }, V2: { axis: "V", at: 2 / 3 },
+};
+export const NAMES: Record<At, string> = {
+ TL: "upper-left third", TC: "upper third, centre", TR: "upper-right third", ML: "left third, middle", CC: "centre",
+ MR: "right third, middle", BL: "lower-left third", BC: "lower third, centre", BR: "lower-right third",
+ H1: "upper thirds line", H2: "lower thirds line", V1: "left thirds line", V2: "right thirds line", FULL: "the whole frame",
+};
+export const GLYPHS: Glyph[] = ["circle", "rect", "hline", "vline", "vanish", "diag", "blob", "streaks", "dots"];
+export const JOINS: Join[] = ["graphic", "motion", "eye", "full", "sound", "hard"];
+const isPoint = (a: At): a is Point => a in POINTS;
+const isLine = (a: At): a is Line => a in LINES;
+
+/** Where a thing at `at` sits, 0..1 across and down: a line at its middle, FULL at the centre. */
+export const centreOf = (at: At): [number, number] => {
+ if (at === "FULL") return [0.5, 0.5];
+ if (isPoint(at)) return POINTS[at];
+ const l = LINES[at];
+ return l.axis === "H" ? [0.5, l.at] : [l.at, 0.5];
+};
+
+/** Glyphs that read as the same thing across a cut. */
+export const SAME: Glyph[][] = [["circle"], ["rect"], ["hline"], ["vline", "diag"], ["vanish"], ["blob", "streaks", "dots"]];
+export const matches = (a: Glyph, b: Glyph) => SAME.some((g) => g.includes(a) && g.includes(b));
+
+/** Whether a cut from `a` lands the eye on `b`: the same place, or a point on the line the other is. FULL lands only
+ * on FULL. */
+export const lands = (a: At, b: At): boolean => {
+ if (a === b) return true;
+ if (a === "FULL" || b === "FULL") return false;
+ const on = (p: At, l: At) => isPoint(p) && isLine(l) && POINTS[p][LINES[l].axis === "H" ? 1 : 0] === LINES[l].at;
+ return on(a, b) || on(b, a);
+};
+
+/** The chain with each shot placed: its start, its first frame (rounded to the piece's frames) and its frames. */
+export function chain(c: ChainInput): Chain {
+ let t = 0;
+ const starts = c.shots.map((s) => { const at = t; t += s.seconds; return at; });
+ const frameOf = (s: number) => Math.round(s * c.fps);
+ const shots = c.shots.map((s, i) => {
+ const frame = frameOf(starts[i]);
+ const end = i + 1 < c.shots.length ? frameOf(starts[i + 1]) : frameOf(t);
+ return { ...s, from: Math.round(starts[i] * 1e6) / 1e6, frame, frames: end - frame };
+ });
+ return { ...c, shots };
+}
+
+/** The chain's cuts in order: each between a shot and the next. The loop's way back to the first shot isn't one
+ * (it is no cut in the composition); `loop` checks it. */
+export function cuts(c: Chain): Cut[] {
+ return c.shots.slice(1).map((s, i) => ({ leaves: c.shots[i], lands: s, join: s.cut ?? "graphic", time: s.from, frame: s.frame, index: i + 1 }));
+}
+
+/** Each shot as its Sequence: its name, first frame and frames (`<Sequence name from durationInFrames>`). */
+export const sequences = (c: Chain) => c.shots.map((s, i) => ({ name: s.name ?? `${i + 1}-${s.scene}`, from: s.frame, durationInFrames: s.frames }));
+
+const said = (c: Cut) => `${c.index}: ${c.leaves.scene} ${c.leaves.out.at} ${c.leaves.out.glyph} -> ${c.lands.scene} ${c.lands.in.at} ${c.lands.in.glyph}`;
+const atTime = (t: number) => `${t.toFixed(2)} s`;
+
+/** A plan check: what it holds the chain to, and each place the chain breaks it (none: it holds). */
+export type PlanCheck = { id: string; text: string; run: (c: Chain) => string[] };
+
+export const PLAN: PlanCheck[] = [
+ {
+ id: "hooks",
+ text: "every hook says what the eye is on, its place on the thirds and its glyph",
+ run: (c) => c.shots.flatMap((s, i) => (["in", "out"] as const).flatMap((k) => {
+ const h = s[k];
+ const bad = [!h?.what?.trim() && "no what", !(h?.at in NAMES) && `no place on the thirds (${h?.at})`, !GLYPHS.includes(h?.glyph) && `no glyph (${h?.glyph})`, s.cut && !JOINS.includes(s.cut) && `a cut that is no join (${s.cut})`].filter(Boolean);
+ return bad.length ? [`shot ${i + 1} (${s.scene}) ${k}: ${bad.join(", ")}`] : [];
+ })),
+ },
+ {
+ id: "length",
+ text: "the chain runs the piece's length to a frame, and every shot is at least a frame",
+ run: (c) => {
+ if (!(c.fps > 0) || !(c.length > 0)) return [`fps ${c.fps} and length ${c.length} must both be more than 0`];
+ const total = c.shots.reduce((a, s) => a + s.seconds, 0);
+ const out = Math.abs(total - c.length) <= 1 / c.fps + 1e-9 ? [] : [`the shots run ${atTime(total)}, the piece ${atTime(c.length)}`];
+ return [...out, ...c.shots.filter((s) => s.frames < 1).map((s) => `shot ${c.shots.indexOf(s) + 1} (${s.scene}) is under a frame (${s.seconds} s)`)];
+ },
+ },
+ {
+ id: "lands",
+ text: "every match cut lands the eye on the thirds place the last shot left it",
+ run: (c) => cuts(c).filter((k) => k.join !== "hard" && k.join !== "sound").filter((k) => {
+ if (k.join === "full") return k.leaves.out.at !== "FULL" || k.lands.in.at !== "FULL";
+ return !lands(k.leaves.out.at, k.lands.in.at);
+ }).map((k) => `${said(k)}${k.join === "full" ? " (a full cut leaves on a thing filling the frame and lands on one)" : ""}`),
+ },
+ {
+ id: "glyph",
+ text: "a graphic cut, and every cut in a montage, lands on the same kind of thing",
+ run: (c) => cuts(c).filter((k) => k.join === "graphic" || (k.leaves.montage && k.lands.montage)).filter((k) => !matches(k.leaves.out.glyph, k.lands.in.glyph)).map(said),
+ },
+ {
+ id: "motion",
+ text: "a motion cut keeps the way the thing moves across the cut",
+ run: (c) => cuts(c).filter((k) => k.join === "motion").filter((k) => !k.leaves.out.move || k.leaves.out.move !== k.lands.in.move).map((k) => `${k.index}: ${k.leaves.scene} moves ${k.leaves.out.move ?? "nowhere said"}, ${k.lands.scene} ${k.lands.in.move ?? "nowhere said"}`),
+ },
+ {
+ id: "carry",
+ text: "a shot whose eye moves from its in to its out says what carries it there",
+ run: (c) => c.shots.filter((s) => !lands(s.in.at, s.out.at) && !s.carry?.trim()).map((s) => `shot ${c.shots.indexOf(s) + 1} (${s.scene}): ${s.in.at} to ${s.out.at} with nothing carrying the eye`),
+ },
+ {
+ id: "hard",
+ text: "a hard cut says what it lands on (a hit, a word, a beat)",
+ run: (c) => cuts(c).filter((k) => k.join === "hard" && !k.lands.on?.trim()).map((k) => `${k.index}: the hard cut into ${k.lands.scene} at ${atTime(k.time)} lands on nothing said`),
+ },
+ {
+ id: "beats",
+ text: "cut to music, every picture cut lands on a beat; an eye-trace cut always does",
+ run: (c) => {
+ const near = (t: number) => (c.beats ?? []).some((b) => Math.abs(b - t) <= 1 / c.fps + 1e-6);
+ return cuts(c).filter((k) => k.join === "eye" || (c.beats && k.join !== "sound")).filter((k) => !near(k.time)).map((k) => c.beats ? `${k.index}: the ${k.join} cut into ${k.lands.scene} at ${atTime(k.time)} is off the beat` : `${k.index}: an eye-trace cut at ${atTime(k.time)}, and the chain has no beats to land it on`);
+ },
+ },
+ {
+ id: "bridge",
+ text: "a sound cut carries a sound across it, and every bridge fits the shot it reaches into",
+ run: (c) => cuts(c).flatMap((k) => {
+ const b = k.lands.bridge;
+ if (!b) return k.join === "sound" ? [`${k.index}: a sound cut into ${k.lands.scene} with no bridge`] : [];
+ if (b.kind !== "J" && b.kind !== "L") return [`${k.index}: a bridge is J or L, not ${b.kind}`];
+ if (!b.sound?.trim() || !(b.seconds > 0)) return [`${k.index}: a bridge names its sound and runs more than 0 s`];
+ const into = b.kind === "J" ? k.leaves : k.lands;
+ return b.seconds <= into.seconds ? [] : [`${k.index}: the ${b.kind} bridge runs ${b.seconds} s into ${into.scene}, which is ${into.seconds} s`];
+ }),
+ },
+ {
+ id: "montage",
+ text: "a montage is three or more shots handing one hook on, with no hard cut inside it",
+ run: (c) => {
+ const runs: Placed[][] = [];
+ c.shots.forEach((s, i) => { if (s.montage) (c.shots[i - 1]?.montage ? runs[runs.length - 1] : (runs[runs.length] = [])).push(s); });
+ return runs.flatMap((r) => {
+ const first = r[0].in.glyph;
+ const where = `the montage from ${r[0].scene} (shot ${c.shots.indexOf(r[0]) + 1})`;
+ if (r.length < 3) return [`${where} is ${r.length} shot(s)`];
+ const off = r.flatMap((s) => [s.in, s.out]).filter((h) => !matches(first, h.glyph));
+ const hard = r.slice(1).filter((s) => s.cut === "hard" || s.cut === "sound");
+ return [...(off.length ? [`${where} hands on ${first}, and ${off.map((h) => `${h.what} (${h.glyph})`).join(", ")} isn't one`] : []), ...hard.map((s) => `${where}: ${s.scene} is cut into ${s.cut}`)];
+ });
+ },
+ },
+ {
+ id: "loop",
+ text: "a piece that loops cuts from its last shot back to its first as a match",
+ run: (c) => {
+ if (!c.loop || c.shots.length < 2) return [];
+ const a = c.shots[c.shots.length - 1], b = c.shots[0], join = b.cut ?? "graphic";
+ const k: Cut = { leaves: a, lands: b, join, time: c.length, frame: Math.round(c.length * c.fps), index: c.shots.length };
+ if (join === "hard" || join === "sound") return [`the loop back to ${b.scene} is a ${join} cut, not a match`];
+ if (join === "full" ? a.out.at !== "FULL" || b.in.at !== "FULL" : !lands(a.out.at, b.in.at)) return [`the loop: ${said(k)}`];
+ if (join === "graphic" && !matches(a.out.glyph, b.in.glyph)) return [`the loop: ${said(k)}`];
+ if (join === "motion" && (!a.out.move || a.out.move !== b.in.move)) return [`the loop: ${a.scene} moves ${a.out.move ?? "nowhere said"}, ${b.scene} ${b.in.move ?? "nowhere said"}`];
+ return [];
+ },
+ },
+];
+
+/** The plan checks on a chain (`only`: these by id), each with every place the chain breaks it. */
+export function planned(c: Chain, only?: string[]): { id: string; text: string; fails: string[] }[] {
+ const unknown = (only ?? []).filter((id) => !PLAN.some((p) => p.id === id));
+ if (unknown.length) throw new Error(`no plan check named ${unknown.join(", ")}: ${PLAN.map((p) => p.id).join(", ")}`);
+ return PLAN.filter((p) => !only?.length || only.includes(p.id)).map((p) => {
+ let fails: string[];
+ try { fails = p.run(c); } catch (e) { fails = [`couldn't read the chain: ${e instanceof Error ? e.message : String(e)}`]; }
+ return { id: p.id, text: p.text, fails };
+ });
+}
+
+/** A camera as raea world's Camera has it: its eye, the point it looks at, its vertical field of view in degrees (a
+ * perspective camera) or the height it sees in metres (an orthographic one). Y is up, as Bevy's looking_at, or Z
+ * when it looks straight up or down. */
+export type View = { eye: number[]; look: number[]; fov?: number | null; ortho?: number | null };
+type Basis = { f: number[]; r: number[]; u: number[] };
+const sub = (a: number[], b: number[]) => a.map((x, i) => x - b[i]);
+const dot = (a: number[], b: number[]) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
+const cross = (a: number[], b: number[]) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
+const unit = (a: number[]) => { const l = Math.hypot(a[0], a[1], a[2]) || 1; return a.map((x) => x / l); };
+function basis(cam: View): Basis {
+ const f = unit(sub(cam.look, cam.eye));
+ const y = cross(f, [0, 1, 0]);
+ const r = unit(cross(f, dot(y, y) < 1e-6 ? [0, 0, 1] : [0, 1, 0]));
+ return { f, r, u: cross(r, f) };
+}
+/** Half the height the camera sees at `z` metres ahead. */
+const halfAt = (cam: View, z: number) => (cam.ortho ? cam.ortho / 2 : z * Math.tan(((cam.fov ?? 45) * Math.PI) / 360));
+
+/** Where a point in the world falls on the frame: 0..1 across and down, and how far ahead of the eye it is (0 or less:
+ * at or behind it). `aspect` is the frame's width over its height. */
+export function toFrame(p: number[], cam: View, aspect: number): { u: number; v: number; z: number } {
+ const { f, r, u } = basis(cam);
+ const d = sub(p, cam.eye);
+ const z = dot(d, f);
+ const half = halfAt(cam, z);
+ return { u: 0.5 + dot(d, r) / (half * aspect) / 2, v: 0.5 - dot(d, u) / half / 2, z };
+}
+
+/** The point in the world `z` metres ahead of the eye that falls on the frame at (u, v): where to put a part so it
+ * sits at a hook's place (`onFrame(...centreOf("TR"), 6, cam, 16 / 9)`). */
+export function onFrame(fu: number, fv: number, z: number, cam: View, aspect: number): [number, number, number] {
+ const { f, r, u } = basis(cam);
+ const half = halfAt(cam, z);
+ const x = (2 * fu - 1) * half * aspect, y = (1 - 2 * fv) * half;
+ return [0, 1, 2].map((k) => cam.eye[k] + f[k] * z + r[k] * x + u[k] * y) as [number, number, number];
+}
+/** `cam` moved, not turned, so the world point `p` falls on `at`'s place at the depth it has now: where one part is the
+ * hook at both ends of a shot, place it for the in hook and aim the shot's last camera with this for the out. */
+export function slideTo(cam: View, at: At, p: number[], aspect: number): View {
+ const [fu, fv] = centreOf(at);
+ const by = sub(p, onFrame(fu, fv, toFrame(p, cam, aspect).z, cam, aspect));
+ return { ...cam, eye: cam.eye.map((x, i) => x + by[i]), look: cam.look.map((x, i) => x + by[i]) };
+}
diff --git a/sdk/guides/craft/match-cuts/plan.ts b/sdk/guides/craft/match-cuts/plan.ts
new file mode 100644
index 00000000..e7ea3fc7
--- /dev/null
+++ b/sdk/guides/craft/match-cuts/plan.ts
@@ -0,0 +1,33 @@
+// The plan checks on a chain file, by name, before anything renders (`raea guide match-cuts`):
+//
+// bun checks/match-cuts/plan.ts NAME.chain.ts every plan check
+// bun checks/match-cuts/plan.ts NAME.chain.ts --only lands,glyph
+//
+// The file's default export is a chain (chain.ts's `chain({...})`). One line a check, PASS or FAIL with where the chain
+// breaks it; exit 1 when one fails, 2 when the file can't be read.
+import { resolve } from "node:path";
+import { PLAN, planned, type Chain } from "./chain";
+
+const args = process.argv.slice(2);
+const at = args.indexOf("--only");
+const only = at >= 0 ? (args[at + 1] ?? "").split(",").map((s) => s.trim()).filter(Boolean) : undefined;
+const file = args.find((a, i) => !a.startsWith("--") && (at < 0 || i !== at + 1));
+if (!file) {
+ console.error(`usage: bun plan.ts NAME.chain.ts [--only ID,ID]\nchecks: ${PLAN.map((p) => p.id).join(", ")}`);
+ process.exit(2);
+}
+let c: Chain;
+try {
+ const m = await import(resolve(file));
+ c = m.default ?? m.chain;
+ if (!c || !Array.isArray(c.shots)) throw new Error("its default export isn't a chain({ fps, length, shots })");
+} catch (e) {
+ console.error(`${file}: ${e instanceof Error ? e.message : String(e)}`);
+ process.exit(2);
+}
+const results = planned(c, only);
+const w = Math.max(...results.map((r) => r.id.length));
+for (const r of results) console.log(`${r.fails.length ? "FAIL" : "PASS"} ${r.id.padEnd(w)} ${r.text}${r.fails.length ? `\n ${r.fails.join("\n ")}` : ""}`);
+const bad = results.filter((r) => r.fails.length).length;
+console.log(`\n${c.title ?? file}: ${c.shots.length} shots, ${c.shots.length - 1} cuts; ${results.length - bad} pass, ${bad} fail`);
+process.exit(bad ? 1 : 0);