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
TL3h: in progress: a freeze frame and footage played backward (sdk/timeline)
shinyobjectzbd670d90405a
diff --git a/sdk/timeline/src/cache.ts b/sdk/timeline/src/cache.tsindex 1d78c614..6c7070fe 100644--- a/sdk/timeline/src/cache.ts+++ b/sdk/timeline/src/cache.ts@@ -33,7 +33,7 @@ function look(k: Track, n: number, c: Clip): string {const phase = still ? `p${c.in! - c.start * (c.speed && c.speed > 0 ? c.speed : 1)}` : `s${c.start}+${c.length}`const keys = Object.entries(c.keys ?? {}).map(([p, ks]) => [p, ks.map((x) => [x.at + c.start, x.value, x.ease ?? "linear"])])const fades = [c.fadeIn ? [c.start, c.fadeIn] : 0, c.fadeOut ? [end(c), c.fadeOut] : 0]- return JSON.stringify([n, k.kind, c.kind, phase, c.speed ?? 1, c.curve ?? null, c.shows ?? null, c.props ?? null, keys, c.volume ?? 1, fades, c.at ?? null])+ return JSON.stringify([n, k.kind, c.kind, c.freeze ? `f${c.in}` : c.reverse ? `r${c.start}+${c.length}:${c.in}` : phase, c.speed ?? 1, c.curve ?? null, c.shows ?? null, c.props ?? null, keys, c.volume ?? 1, fades, c.at ?? null])}/** Every drawn thing on the timeline as the span it covers and what it draws there. */diff --git a/sdk/timeline/src/model.ts b/sdk/timeline/src/model.tsindex 85d6dd49..73aaf19b 100644--- a/sdk/timeline/src/model.ts+++ b/sdk/timeline/src/model.ts@@ -50,6 +50,10 @@ export interface Clip {curve?: SpeedPoint[]/** under a curve: how many source frames the clip shows (its length is the time the curve takes over them) */shows?: Frames+ /** footage played backward: its last source frame first (TL3h) */+ reverse?: boolean+ /** a still: the source frame `in` held for the clip's whole length (TL3h) */+ freeze?: boolean/** turned off: drawn dimmed, left out of the picture and the sound (TL3g) */off?: boolean/** it can't be changed here, and why ("set in code", TL0c) */diff --git a/sdk/timeline/src/ops.ts b/sdk/timeline/src/ops.tsindex c149e07b..c0a5e7aa 100644--- a/sdk/timeline/src/ops.ts+++ b/sdk/timeline/src/ops.ts@@ -26,7 +26,10 @@ export type Op =/** a clip put on the timeline: on `track`, else the first of `kind` with room, else a new track of that kind */| { op: "add"; kind: TrackKind; clip: Clip; track?: string }/** a clip's own fields; `props` are merged into its props; a speed or a curve changes its length (TL6) */- | { op: "set"; id: string; set: Partial<Pick<Clip, "name" | "off" | "volume" | "fadeIn" | "fadeOut" | "speed" | "group">> & { curve?: SpeedPoint[] | null; props?: Record<string, Value | boolean> } }+ /** a still of the frame under `at` on a clip (the main track's, when none is named), `length` frames long, put in+ * there: the clip is split and the still goes between its halves (TL3h) */+ | { op: "freeze"; at: Frames; length: Frames; id?: string }+ | { op: "set"; id: string; set: Partial<Pick<Clip, "name" | "off" | "volume" | "fadeIn" | "fadeOut" | "speed" | "group" | "reverse">> & { curve?: SpeedPoint[] | null; props?: Record<string, Value | boolean> } }/** a property's key at a frame of its clip: made, or its value (and ease) changed (TL5a) */| { op: "key"; id: string; prop: string; at: Frames; value: Value; ease?: Ease }| { op: "unkey"; id: string; prop: string; at: Frames }@@ -210,6 +213,28 @@ function run(t: Timeline, op: Exclude<Op, { op: "restore" }>): Timeline {for (const m of clip.inside!) next = place(next, m.kind, { ...m.clip, start: clip.start + m.clip.start })return next}+ case "freeze": {+ const at = whole(op.at)+ const under = (c: Clip) => c.start <= at && at < end(c)+ const host = op.id ? open(t, op.id) : (() => {+ const k = t.tracks.find((x) => isMain(x) && !x.locked) ?? no("there is no main track to hold a still")+ const c = k.clips.find((x) => under(x) && !x.locked) ?? no("no clip is under the playhead")+ return { track: k, clip: c }+ })()+ const c = host.clip+ if (!under(c)) no("the playhead isn't on that clip")+ if (c.in === undefined || c.freeze) no(`${c.name ?? c.id} has no footage to take a still from`)+ const len = Math.max(1, whole(op.length))+ const into = at - c.start+ const first = c.in ?? 0+ const frame = c.reverse ? first + Math.round((c.length - 1 - into) * speedOf(c)) : first + Math.round(into * speedOf(c))+ const still: Clip = { id: fresh(t, `${c.id}-still`), kind: c.kind, name: "Freeze", start: at, length: len, in: frame, source: c.source, freeze: true }+ // the clip's two halves either side of the still (none before it when the playhead is on its first frame),+ // what follows on the track making room+ const parts = into > 0 ? halves(c, at, fresh(t, c.id)) : [undefined, c] as const+ const after = parts[1] ? { ...parts[1], start: at + len } : undefined+ return withTracks(t, (k) => (k.id !== host.track.id ? k : { ...k, clips: [...k.clips.flatMap((x) => (x.id === c.id ? [parts[0], still, after].filter((y): y is Clip => !!y) : [x.start >= end(c) ? { ...x, start: x.start + len } : x]))] }))+ }case "add": {if (find(t, op.clip.id)) no(`there is already a clip ${op.clip.id}`)if (!(op.clip.length >= 1) || op.clip.start < 0) no("a clip is at least one frame long and starts in the film")diff --git a/sdk/timeline/src/play.ts b/sdk/timeline/src/play.tsindex ff395b7a..ee3bb612 100644--- a/sdk/timeline/src/play.ts+++ b/sdk/timeline/src/play.ts@@ -22,6 +22,9 @@ export function showing(t: Timeline, frame: Frames): Showing | undefined {const c = main(t).find((x) => x.start <= frame && frame < end(x))if (!c) return undefinedconst into = frame - c.start+ // a still holds its frame; footage played backward runs from its last source frame to its first+ if (c.freeze) return { clip: c, source: c.in!, rate: 0 }+ if (c.reverse && !c.curve) return { clip: c, source: c.in! + (c.length - 1 - into) * speedOf(c), rate: -speedOf(c) }if (c.curve) {const span = c.shows ?? c.length / played(c.curve, 1)const at = curveAt(c.curve, span, into)@@ -34,7 +37,8 @@ export function showing(t: Timeline, frame: Frames): Showing | undefined {/** The timeline frame at which clip `id` shows source frame `source`, when it does (a constant-speed clip). */export function frameOf(t: Timeline, id: string, source: number): Frames | undefined {const c = main(t).find((x) => x.id === id)- if (!c || c.curve) return undefined+ // a still and footage played backward are stepped by the timeline's own clock, not read back from the player's+ if (!c || c.curve || c.freeze || c.reverse) return undefinedconst f = c.start + (source - c.in!) / speedOf(c)return f >= c.start - 0.5 && f < end(c) + 0.5 ? Math.min(end(c), Math.max(c.start, f)) : undefined}@@ -54,6 +58,10 @@ export function ready(t: Timeline, source: Range[]): Range[] {const out: Range[] = []for (const c of main(t)) {if (c.curve) continue+ if (c.freeze) {+ if (source.some(([a, b]) => a <= c.in! && c.in! < b)) out.push([c.start, end(c)])+ continue+ }const rate = speedOf(c), from = c.in!, to = c.in! + c.length * ratefor (const [a, b] of source) {const lo = Math.max(a, from), hi = Math.min(b, to)diff --git a/sdk/timeline/test/ops.test.ts b/sdk/timeline/test/ops.test.tsindex 6bfea367..63f6d8b9 100644--- a/sdk/timeline/test/ops.test.ts+++ b/sdk/timeline/test/ops.test.ts@@ -29,6 +29,8 @@ describe("TL0b: an operation is a pure function with an inverse", () => {{ op: "cut", id: "b", side: "left", at: 50 },{ op: "duplicate", ids: ["c"] },{ op: "compound", ids: ["a", "title"] },+ { op: "freeze", at: 40, length: 90 },+ { op: "set", id: "b", set: { reverse: true } },{ op: "set", id: "b", set: { speed: 2 } },{ op: "key", id: "b", prop: "scale", at: 10, value: 1.2 },{ op: "mark", marker: { id: "m1", at: 45 } },diff --git a/sdk/timeline/test/play.test.ts b/sdk/timeline/test/play.test.tsindex ae5411f5..13404269 100644--- a/sdk/timeline/test/play.test.ts+++ b/sdk/timeline/test/play.test.ts@@ -45,4 +45,22 @@ describe("TL10a: an edited film plays from its own frames, with no render", () =expect(ready(t, [[0, 120], [210, 300]])).toEqual([[0, 90], [120, 210]])expect(ready(film(), [[0, 300]])).toEqual([[0, 300]])})++ test("a still holds its frame and footage played backward runs from its last frame: both stepped by the timeline", () => {+ // a 2 s still of the frame at 1 s, put into the first scene there+ const t = done(film(), { op: "freeze", at: 30, length: 60 })+ expect(t.tracks[0].clips.map((c) => `${c.id} ${c.start}-${c.start + c.length}${c.freeze ? " still" : ""}`)).toEqual(["scene-1 0-30", "scene-1-still+ 30-90 still", "scene-1+ 90-150", "scene-2 150-240", "scene-3 240-360"])+ expect(showing(t, 29)).toMatchObject({ source: 29, rate: 1 })+ expect([30, 60, 89].map((f) => showing(t, f)!.source)).toEqual([30, 30, 30])+ expect(showing(t, 60)!.rate).toBe(0)+ expect(showing(t, 90)).toMatchObject({ source: 30, rate: 1 })+ expect(frameOf(t, "scene-1-still+", 30)).toBeUndefined()+ // the second scene (source 90 to 180) backward: its first frame shows the scene's last+ const r = done(film(), { op: "set", id: "scene-2", set: { reverse: true } })+ expect([90, 91, 179].map((f) => showing(r, f)!.source)).toEqual([179, 178, 90])+ expect(showing(r, 100)!.rate).toBe(-1)+ // a still is ready when its one frame is+ expect(ready(t, [[0, 40]])).toEqual([[0, 100]])+ expect(apply(film(), { op: "freeze", at: 500, length: 60 })).toEqual({ ok: false, why: "no clip is under the playhead" })+ })})