Video: voxel titles, new opening with world turn, app punch-ins and callouts, six-screen montage, props sequence; site carries the new film
This commit is contained in:
37 files changed
+2672
-165
No files matched your search
@@ -0,0 +1,200 @@
|
||||
// SVG for callout slabs, leaders and the margin grid.
|
||||
import { BEAT, LAND, WINDOW, glide, place, seconds, settle, view } from "./plan.mjs";
|
||||
|
||||
const COS = Math.cos(Math.PI / 6);
|
||||
const SIN = Math.sin(Math.PI / 6);
|
||||
const ACCENT = "#3d7fe5";
|
||||
const STONE = "#efefec";
|
||||
const INK = "#1d1d1f";
|
||||
const MUTED = "#6e6e73";
|
||||
const W = 1920;
|
||||
const H = 1080;
|
||||
|
||||
const clamp = (v, lo = 0, hi = 1) => Math.min(hi, Math.max(lo, v));
|
||||
const f = (v) => v.toFixed(2);
|
||||
const pts = (list) => list.map(([x, y]) => `${f(x)},${f(y)}`).join(" ");
|
||||
|
||||
/** A grid point to screen pixels around an origin. */
|
||||
const iso = (u, [ox, oy]) => (x, y, z) => [ox + (x - y) * COS * u, oy + ((x + y) * SIN - z) * u];
|
||||
|
||||
/** A three-tone block, like site/src/iso.ts, with a CSS tone. */
|
||||
function block(p, { w, d, h }, tone) {
|
||||
const face = (list, shade) => {
|
||||
const fill = shade ? `color-mix(in oklab, ${tone}, black ${shade}%)` : tone;
|
||||
return `<polygon points="${pts(list)}" style="fill:${fill}"/>`;
|
||||
};
|
||||
return [
|
||||
face([p(0, d, 0), p(w, d, 0), p(w, 0, 0), p(w, 0, h), p(0, 0, h), p(0, d, h)], 9),
|
||||
face([p(0, d, 0), p(w, d, 0), p(w, d, h), p(0, d, h)], 9),
|
||||
face([p(w, d, 0), p(w, 0, 0), p(w, 0, h), p(w, d, h)], 20),
|
||||
face([p(0, 0, h), p(w, 0, h), p(w, d, h), p(0, d, h)], 0),
|
||||
].join("");
|
||||
}
|
||||
|
||||
const SLAB_U = 18;
|
||||
const LEFT = { w: 4, d: 2, h: 1, x: WINDOW.x - 14 };
|
||||
const RIGHT = { w: 2, d: 4, h: 1, x: WINDOW.x + WINDOW.w + 14 };
|
||||
|
||||
/** Points along an elbow path, cut at progress l. */
|
||||
function elbow(a, b, l) {
|
||||
const corner = [b[0], a[1]];
|
||||
const first = Math.abs(corner[0] - a[0]);
|
||||
const total = first + Math.abs(b[1] - corner[1]);
|
||||
let left = total * l;
|
||||
if (left <= first) return [a, [a[0] + Math.sign(corner[0] - a[0]) * left, a[1]]];
|
||||
left -= first;
|
||||
return [a, corner, [corner[0], corner[1] + Math.sign(b[1] - corner[1]) * left]];
|
||||
}
|
||||
|
||||
/** Which margin a callout stands in and how high. */
|
||||
function stance(a, c) {
|
||||
const mid = view(a, (seconds(a, c.at[0]) + seconds(a, c.at[1])) / 2);
|
||||
const [bx, by, bw, bh] = c.box;
|
||||
const side = c.side ?? (place([bx + bw / 2, 0], mid)[0] < W / 2 ? "left" : "right");
|
||||
const edge = [side === "left" ? bx : bx + bw, by + bh / 2];
|
||||
return { side, edge, y: clamp(place(edge, mid)[1], 132, 1036) };
|
||||
}
|
||||
|
||||
/** Corner ticks around a frame-space box. */
|
||||
function ticks([x0, y0], [x1, y1]) {
|
||||
const pad = 6;
|
||||
const [l, t, r, b] = [x0 - pad, y0 - pad, x1 + pad, y1 + pad];
|
||||
const n = Math.min(16, (r - l) / 3, (b - t) / 3);
|
||||
return [
|
||||
[[l, t + n], [l, t], [l + n, t]],
|
||||
[[r - n, t], [r, t], [r, t + n]],
|
||||
[[r, b - n], [r, b], [r - n, b]],
|
||||
[[l + n, b], [l, b], [l, b - n]],
|
||||
]
|
||||
.map((c) => `<polyline points="${pts(c)}"/>`)
|
||||
.join("");
|
||||
}
|
||||
|
||||
/** One callout at time t, or nothing outside its life. */
|
||||
function callout(a, c, t) {
|
||||
const born = seconds(a, c.at[0]);
|
||||
const gone = seconds(a, c.at[1]);
|
||||
if (t < born - LAND || t > gone) return "";
|
||||
const rise = settle((t - (born - LAND)) / LAND);
|
||||
const fall = settle((t - (gone - LAND)) / LAND);
|
||||
const alpha = rise * (1 - fall);
|
||||
const drop = SLAB_U * (1 - rise) + SLAB_U * fall;
|
||||
const { side, edge, y } = stance(a, c);
|
||||
const shape = side === "left" ? LEFT : RIGHT;
|
||||
const base = iso(SLAB_U, [0, 0]);
|
||||
const tip = side === "left" ? base(shape.w, 0, shape.h) : base(0, shape.d, shape.h);
|
||||
const origin = [shape.x - tip[0], y + drop - tip[1]];
|
||||
const p = iso(SLAB_U, origin);
|
||||
const anchor = [shape.x, y + drop];
|
||||
const top = p(0, 0, shape.h)[1];
|
||||
const cx = (p(0, shape.d, shape.h)[0] + p(shape.w, 0, shape.h)[0]) / 2;
|
||||
|
||||
const now = view(a, t);
|
||||
const target = place(edge, now);
|
||||
const [bx, by, bw, bh] = c.box;
|
||||
const frame = ticks(place([bx, by], now), place([bx + bw, by + bh], now));
|
||||
const reach = settle(clamp((t - born) / (BEAT / 2)));
|
||||
const path = elbow(anchor, target, reach);
|
||||
const mark = clamp((reach - 0.85) / 0.15);
|
||||
const font = `font:600 22px 'SF Pro Text','SF Pro Display',system-ui`;
|
||||
const [mx, my] = target;
|
||||
return `<g opacity="${f(alpha)}">
|
||||
<polyline points="${pts(path)}" fill="none" stroke="${ACCENT}" stroke-width="1.5"/>
|
||||
<g opacity="${f(mark)}" fill="none" stroke="${ACCENT}" stroke-width="2">${frame}</g>
|
||||
<polygon opacity="${f(mark)}" fill="${ACCENT}"
|
||||
points="${pts([[mx, my - 5], [mx + 8.66, my], [mx, my + 5], [mx - 8.66, my]])}"/>
|
||||
${block(p, shape, ACCENT)}
|
||||
<text x="${f(cx)}" y="${f(top - 35)}" text-anchor="middle" fill="${INK}" style="${font}">${c.en}</text>
|
||||
<text x="${f(cx)}" y="${f(top - 11)}" text-anchor="middle" fill="${MUTED}"
|
||||
style="font:300 15px 'PingFang SC',system-ui;letter-spacing:0.04em">${c.zh}</text>
|
||||
</g>`;
|
||||
}
|
||||
|
||||
const svg = (body) =>
|
||||
`<svg xmlns="http://www.w3.org/2000/svg" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}">${body}</svg>`;
|
||||
|
||||
/** The callout layer of one app at time t. */
|
||||
export function calloutFrame(a, t) {
|
||||
return svg(a.callouts.map((c) => callout(a, c, t)).join(""));
|
||||
}
|
||||
|
||||
const GRID_U = 24;
|
||||
const GAP = 18;
|
||||
const HOLE = { x: WINDOW.x - GAP, y: WINDOW.y - GAP, x1: WINDOW.x + WINDOW.w + GAP };
|
||||
const GROUND = iso(GRID_U, [W / 2, -GRID_U * 20]);
|
||||
|
||||
/** Whether a frame point lies in the margin the grid may use. */
|
||||
const free = ([x, y]) => x > 4 && x < W - 4 && y > 4 && y < H - 4 && !(x > HOLE.x - 4 && x < HOLE.x1 + 4 && y > HOLE.y - 4);
|
||||
|
||||
/** Tiles whose lifted cube stays inside the margin. */
|
||||
export const TILES = (() => {
|
||||
const out = [];
|
||||
for (let i = -60; i < 160; i++) {
|
||||
for (let j = -60; j < 160; j++) {
|
||||
const corners = [GROUND(i, j, 0), GROUND(i + 1, j, 0), GROUND(i + 1, j + 1, 0), GROUND(i, j + 1, 0)];
|
||||
const up = corners.map(([x, y]) => [x, y - GRID_U]);
|
||||
if ([...corners, ...up].every(free)) out.push([i, j]);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
})();
|
||||
|
||||
/** A seeded generator, mulberry32. */
|
||||
function random(seed) {
|
||||
let s = seed >>> 0;
|
||||
return () => {
|
||||
s = (s + 0x6d2b79f5) >>> 0;
|
||||
let r = Math.imul(s ^ (s >>> 15), 1 | s);
|
||||
r = (r + Math.imul(r ^ (r >>> 7), 61 | r)) ^ r;
|
||||
return ((r ^ (r >>> 14)) >>> 0) / 4294967296;
|
||||
};
|
||||
}
|
||||
|
||||
/** Lifts per section: tile, landing beat and settling beat. */
|
||||
export function lifts(a, seed) {
|
||||
const next = random(seed);
|
||||
const busy = [];
|
||||
const out = [];
|
||||
for (let beat = 5; beat <= 15; beat++) {
|
||||
const n = 2 + Math.floor(next() * 2);
|
||||
for (let k = 0; k < n; k++) {
|
||||
const tile = TILES[Math.floor(next() * TILES.length)];
|
||||
const until = Math.min(16, beat + 1 + Math.floor(next() * 3));
|
||||
const key = tile.join(",");
|
||||
if (busy.some((b) => b.key === key && b.until > beat)) continue;
|
||||
busy.push({ key, until });
|
||||
out.push({ tile, up: seconds(a, beat), down: seconds(a, until) });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
const LINES = (() => {
|
||||
const segs = [];
|
||||
for (let k = -60; k < 160; k++) {
|
||||
segs.push(`M${pts([GROUND(k, -60, 0)])}L${pts([GROUND(k, 160, 0)])}`);
|
||||
segs.push(`M${pts([GROUND(-60, k, 0)])}L${pts([GROUND(160, k, 0)])}`);
|
||||
}
|
||||
return segs.join("");
|
||||
})();
|
||||
|
||||
const CLIP = `<clipPath id="m"><path clip-rule="evenodd" d="M0,0H${W}V${H}H0Z
|
||||
M${HOLE.x},${HOLE.y}H${HOLE.x1}V${H}H${HOLE.x}Z"/></clipPath>`;
|
||||
|
||||
/** The grid layer at time t for the given lifts. */
|
||||
export function gridFrame(list, t) {
|
||||
const cubes = list
|
||||
.map(({ tile, up, down }) => {
|
||||
const rise = settle((t - (up - LAND)) / LAND);
|
||||
const sink = glide((t - (down - LAND)) / LAND);
|
||||
return { tile, h: rise * (1 - sink) };
|
||||
})
|
||||
.filter((c) => c.h > 0.001)
|
||||
.sort((p, q) => p.tile[0] + p.tile[1] - (q.tile[0] + q.tile[1]));
|
||||
const body = cubes
|
||||
.map(({ tile: [i, j], h }) => block((x, y, z) => GROUND(i + x, j + y, z), { w: 1, d: 1, h }, STONE))
|
||||
.join("");
|
||||
return svg(`<defs>${CLIP}</defs><g clip-path="url(#m)">
|
||||
<path d="${LINES}" stroke="#e7e7e4" stroke-width="1" fill="none"/>
|
||||
<g opacity="0.75">${body}</g></g>`);
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Composites fx layers over a mock letterboxed recording for review."""
|
||||
import io
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from pathlib import Path
|
||||
|
||||
from PIL import Image
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
OUT = HERE.parent / "out"
|
||||
PLAN = json.loads((HERE.parent / "edit" / "plan.json").read_text())
|
||||
FPS = 30
|
||||
BEAT = 60 / 112
|
||||
STARTS = {"doc": 32, "table": 48, "show": 64, "pdf": 80, "tree": 96, "mark": 112}
|
||||
|
||||
|
||||
def lerp(points, x):
|
||||
"""Piecewise linear through points, extended past both ends."""
|
||||
i = 0
|
||||
while i < len(points) - 2 and x > points[i + 1][0]:
|
||||
i += 1
|
||||
(x0, y0), (x1, y1) = points[i], points[i + 1]
|
||||
return y0 + (x - x0) * (y1 - y0) / (x1 - x0)
|
||||
|
||||
|
||||
def source(app, frame):
|
||||
"""Recording file and time shown at a global frame."""
|
||||
pieces = next(s for s in PLAN["sections"] if s["app"] == app)["pieces"]
|
||||
beat = frame / FPS / BEAT - STARTS[app]
|
||||
piece = pieces[0]
|
||||
for p in pieces[1:]:
|
||||
if beat >= p["anchors"][0][0]:
|
||||
piece = p
|
||||
return OUT / "rec" / f"{piece['src']}.mp4", lerp(piece["anchors"], beat)
|
||||
|
||||
|
||||
def grab(path, t):
|
||||
png = subprocess.run(
|
||||
["ffmpeg", "-v", "error", "-ss", f"{max(t, 0):.3f}", "-i", str(path), "-frames:v", "1",
|
||||
"-f", "image2pipe", "-vcodec", "png", "-"],
|
||||
check=True, capture_output=True).stdout
|
||||
return Image.open(io.BytesIO(png)).convert("RGB")
|
||||
|
||||
|
||||
def layer(name, frame):
|
||||
path = OUT / "extra" / name / f"{frame:05d}.png"
|
||||
return Image.open(path).convert("RGBA") if path.exists() else None
|
||||
|
||||
|
||||
def compose(app, frame, rect):
|
||||
"""One mock frame: recording through the view, cards, then layers."""
|
||||
win = PLAN["window"]
|
||||
x, y, w, h = rect
|
||||
rec = grab(*source(app, frame)).crop((round(x), round(y), round(x + w), round(y + h)))
|
||||
canvas = Image.new("RGBA", (1920, 1080), "#fbfbfa")
|
||||
canvas.paste(rec.resize((win["w"], win["h"]), Image.LANCZOS), (win["x"], win["y"]))
|
||||
for card in (OUT / "edit" / "cards" / "frame.png", OUT / "edit" / "cards" / f"{app}.png"):
|
||||
canvas.alpha_composite(Image.open(card).convert("RGBA"))
|
||||
for name in ("fx-grid", f"{app}-fx"):
|
||||
top = layer(name, frame)
|
||||
if top is not None:
|
||||
canvas.alpha_composite(top)
|
||||
return canvas.convert("RGB")
|
||||
|
||||
|
||||
def main():
|
||||
app, target = sys.argv[1], Path(sys.argv[2])
|
||||
picks = [int(f) for f in sys.argv[3:]]
|
||||
track = json.loads((OUT / "extra" / f"{app}-fx" / "view.json").read_text())
|
||||
first, rects = track["first"], track["rects"]
|
||||
frames = picks or list(range(first, first + len(rects)))
|
||||
target.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def one(frame):
|
||||
compose(app, frame, rects[frame - first]).save(target / f"{app}-{frame:05d}.png")
|
||||
|
||||
with ThreadPoolExecutor(8) as pool:
|
||||
list(pool.map(one, frames))
|
||||
if not picks:
|
||||
subprocess.run(
|
||||
["ffmpeg", "-v", "error", "-y", "-framerate", str(FPS), "-start_number", str(first),
|
||||
"-i", str(target / f"{app}-%05d.png"), "-c:v", "libx264", "-crf", "18",
|
||||
"-pix_fmt", "yuv420p", str(target / f"{app}-mock.mp4")],
|
||||
check=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,179 @@
|
||||
// Beats, punch-ins and callouts for the six app sections.
|
||||
import { readFileSync } from "node:fs";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url));
|
||||
export const EDIT_PLAN = resolve(here, "../edit/plan.json");
|
||||
|
||||
export const FPS = 30;
|
||||
export const BEAT = 60 / 112;
|
||||
export const LAND = 0.2;
|
||||
|
||||
/** The letterbox window, read from the integrator's plan. */
|
||||
export const WINDOW = JSON.parse(readFileSync(EDIT_PLAN, "utf8")).window;
|
||||
export const REC = { w: 1920, h: 1080 };
|
||||
|
||||
/** CSS cubic-bezier timing, solved by bisection. */
|
||||
function bezier(x1, y1, x2, y2) {
|
||||
const at = (a, b, u) => 3 * a * u * (1 - u) ** 2 + 3 * b * u * u * (1 - u) + u ** 3;
|
||||
return (x) => {
|
||||
if (x <= 0) return 0;
|
||||
if (x >= 1) return 1;
|
||||
let [lo, hi] = [0, 1];
|
||||
for (let i = 0; i < 50; i++) {
|
||||
const mid = (lo + hi) / 2;
|
||||
if (at(x1, x2, mid) < x) lo = mid;
|
||||
else hi = mid;
|
||||
}
|
||||
return at(y1, y2, (lo + hi) / 2);
|
||||
};
|
||||
}
|
||||
|
||||
export const settle = bezier(0.2, 0.8, 0.3, 1);
|
||||
export const glide = bezier(0.65, 0, 0.35, 1);
|
||||
|
||||
/**
|
||||
* Per app: first beat of its section, punch-ins and callouts.
|
||||
* Beats count from the section's bar 1; rects and boxes are recording pixels.
|
||||
* A punch-in eases in over `in`, holds, eases out over `out`;
|
||||
* when one's `out` equals the next one's `in`, the view pans directly.
|
||||
*/
|
||||
export const APPS = [
|
||||
{
|
||||
app: "doc",
|
||||
start: 32,
|
||||
zooms: [
|
||||
{ rect: [280, 190, 960, 540], in: [4.5, 5], out: [8, 8.5] },
|
||||
{ rect: [250, 187, 900, 506.25], in: [10, 10.5], out: [13.5, 14] },
|
||||
],
|
||||
callouts: [
|
||||
{ en: "Type", zh: "离线输入", at: [5, 8], box: [385, 405, 750, 100] },
|
||||
{ en: "Bold ⌘B", zh: "加粗", at: [11, 14], box: [553, 407, 52, 28] },
|
||||
{ en: "125%", zh: "缩放", at: [15, 16], box: [1828, 1054, 54, 24] },
|
||||
],
|
||||
},
|
||||
{
|
||||
app: "table",
|
||||
start: 48,
|
||||
zooms: [
|
||||
{ rect: [0, 70, 1140, 641.25], in: [4.5, 5], out: [7.5, 8] },
|
||||
{ rect: [145, 110, 900, 506.25], in: [12, 12.5], out: [14.5, 15] },
|
||||
],
|
||||
callouts: [
|
||||
{ en: "=SUM", zh: "求和", at: [5, 7.5], box: [178, 92, 110, 24] },
|
||||
{ en: "Fill right", zh: "向右填充", at: [6, 8], box: [229, 414, 892, 36] },
|
||||
{ en: "Chart", zh: "插入图表", at: [13, 15], box: [232, 158, 726, 408] },
|
||||
],
|
||||
},
|
||||
{
|
||||
app: "show",
|
||||
start: 64,
|
||||
zooms: [
|
||||
{ rect: [920, 252, 1000, 562.5], in: [5, 5.5], out: [7.5, 8] },
|
||||
{ rect: [360, 202, 1200, 675], in: [12.5, 13], out: [15.5, 16] },
|
||||
],
|
||||
callouts: [
|
||||
{ en: "Fly In", zh: "飞入", at: [5.5, 7], box: [1580, 340, 200, 30] },
|
||||
{ en: "Preview", zh: "预览动画", at: [8, 10], box: [1722, 768, 158, 30] },
|
||||
{ en: "Fly In", zh: "飞入", at: [13, 15], box: [425, 423, 1068, 92], side: "left" },
|
||||
{ en: "Fade In", zh: "淡入", at: [15, 16], box: [585, 612, 750, 54], side: "right" },
|
||||
],
|
||||
},
|
||||
{
|
||||
app: "pdf",
|
||||
start: 80,
|
||||
zooms: [
|
||||
{ rect: [605, 360, 960, 540], in: [6.5, 7], out: [8.5, 9] },
|
||||
{ rect: [480, 270, 960, 540], in: [10, 10.5], out: [12.5, 13] },
|
||||
{ rect: [760, 540, 960, 540], in: [14.5, 15], out: [15.5, 16] },
|
||||
],
|
||||
callouts: [
|
||||
{ en: "Highlight", zh: "高亮", at: [7, 9], box: [822, 617, 525, 38] },
|
||||
{ en: "Draw", zh: "手写签名", at: [10, 13], box: [727, 478, 466, 190] },
|
||||
{ en: "Sign", zh: "签名", at: [15, 16], box: [1148, 848, 184, 78] },
|
||||
],
|
||||
},
|
||||
{
|
||||
app: "tree",
|
||||
start: 96,
|
||||
zooms: [
|
||||
{ rect: [960, 120, 960, 540], in: [4.5, 5], out: [6, 6.5] },
|
||||
{ rect: [0, 517.5, 1000, 562.5], in: [6.5, 7], out: [8.5, 9] },
|
||||
{ rect: [0, 140, 900, 506.25], in: [9.5, 10], out: [12.5, 13] },
|
||||
],
|
||||
callouts: [
|
||||
{ en: "Stage hunk", zh: "暂存此块", at: [5, 6.5], box: [1805, 168, 98, 26] },
|
||||
{ en: "Commit", zh: "提交", at: [7, 9], box: [508, 1013, 129, 29] },
|
||||
{ en: "History", zh: "提交历史", at: [10, 13], box: [2, 170, 640, 605] },
|
||||
],
|
||||
},
|
||||
{
|
||||
app: "mark",
|
||||
start: 112,
|
||||
zooms: [
|
||||
{ rect: [603, 150, 960, 540], in: [8.5, 9], out: [10.5, 11] },
|
||||
{ rect: [603, 530, 960, 540], in: [10.5, 11], out: [11.5, 12] },
|
||||
],
|
||||
callouts: [
|
||||
{ en: "Math", zh: "公式", at: [9, 10.5], box: [652, 291, 862, 245] },
|
||||
{ en: "Mermaid", zh: "流程图", at: [11, 12], box: [672, 880, 820, 100] },
|
||||
{ en: "Source ⌘2", zh: "源码", at: [13, 15], box: [1845, 1056, 26, 22] },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
/** Global seconds of a section beat. */
|
||||
export const seconds = (a, beat) => (a.start + beat) * BEAT;
|
||||
|
||||
/** Global frames of bars 2–4 of a section. */
|
||||
export function frames(a) {
|
||||
const first = Math.ceil(seconds(a, 4) * FPS - 1e-6);
|
||||
const end = Math.ceil(seconds(a, 16) * FPS - 1e-6);
|
||||
return { first, count: end - first };
|
||||
}
|
||||
|
||||
const FULL = [0, 0, REC.w, REC.h];
|
||||
const mix = (a, b, p) => a.map((v, i) => v + (b[i] - v) * p);
|
||||
|
||||
/** Eased moves of the view rect, as [t0, t1, from, to, ease]. */
|
||||
function moves(a) {
|
||||
const out = [];
|
||||
a.zooms.forEach((z, i) => {
|
||||
const prev = a.zooms[i - 1];
|
||||
const panned = prev && prev.out[0] === z.in[0] && prev.out[1] === z.in[1];
|
||||
if (!panned) out.push([seconds(a, z.in[0]), seconds(a, z.in[1]), FULL, z.rect, settle]);
|
||||
const next = a.zooms[i + 1];
|
||||
const pans = next && next.in[0] === z.out[0] && next.in[1] === z.out[1];
|
||||
out.push([seconds(a, z.out[0]), seconds(a, z.out[1]), z.rect, pans ? next.rect : FULL, glide]);
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
/** The recording rect shown in the window at time t. */
|
||||
export function view(a, t) {
|
||||
let rect = FULL;
|
||||
for (const [t0, t1, from, to, ease] of moves(a)) {
|
||||
if (t >= t1) rect = to;
|
||||
else if (t > t0) return mix(from, to, ease((t - t0) / (t1 - t0)));
|
||||
else break;
|
||||
}
|
||||
return rect;
|
||||
}
|
||||
|
||||
/** Recording pixel to frame pixel through a view rect. */
|
||||
export function place([rx, ry], [vx, vy, vw, vh]) {
|
||||
return [WINDOW.x + ((rx - vx) / vw) * WINDOW.w, WINDOW.y + ((ry - vy) / vh) * WINDOW.h];
|
||||
}
|
||||
|
||||
/** The punch-ins in the integrator's terms, global seconds. */
|
||||
export function zoomList(a) {
|
||||
const r = (v) => Math.round(v * 10000) / 10000;
|
||||
return a.zooms.map((z) => ({
|
||||
t0: r(seconds(a, z.in[0])),
|
||||
t1: r(seconds(a, z.out[1])),
|
||||
rect: z.rect,
|
||||
in: z.in.map((b) => r(seconds(a, b))),
|
||||
out: z.out.map((b) => r(seconds(a, b))),
|
||||
}));
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
// Renders the app callout layers, punch-in tracks and margin grid.
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { copyFileSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { createRequire } from "node:module";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { calloutFrame, gridFrame, lifts } from "./draw.mjs";
|
||||
import { APPS, EDIT_PLAN, FPS, frames, view, zoomList } from "./plan.mjs";
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url));
|
||||
const require = createRequire(resolve(here, "../scenes/package.json"));
|
||||
const { chromium } = require("playwright");
|
||||
const extra = resolve(here, "../out/extra");
|
||||
const PAGES = 6;
|
||||
|
||||
const browser = await chromium.launch();
|
||||
|
||||
/** A transparent film-sized page that shows one SVG. */
|
||||
async function open() {
|
||||
const page = await browser.newPage({ viewport: { width: 1920, height: 1080 }, deviceScaleFactor: 1 });
|
||||
page.on("pageerror", (e) => {
|
||||
throw e;
|
||||
});
|
||||
await page.setContent(
|
||||
`<!doctype html><meta charset="utf-8"><style>html,body{margin:0;background:transparent}
|
||||
svg{display:block;-webkit-font-smoothing:antialiased}</style><body></body>`,
|
||||
);
|
||||
return page;
|
||||
}
|
||||
|
||||
const pages = await Promise.all(Array.from({ length: PAGES }, open));
|
||||
|
||||
/** Writes PNGs for global frames, spreading work over pages. */
|
||||
async function paint(dir, list, draw) {
|
||||
let next = 0;
|
||||
await Promise.all(
|
||||
pages.map(async (page) => {
|
||||
while (next < list.length) {
|
||||
const frame = list[next++];
|
||||
await page.evaluate((s) => {
|
||||
document.body.innerHTML = s;
|
||||
return document.fonts.ready;
|
||||
}, draw(frame / FPS));
|
||||
await page.screenshot({ path: join(dir, `${String(frame).padStart(5, "0")}.png`), omitBackground: true });
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
function ffmpeg(args) {
|
||||
const run = spawnSync("ffmpeg", ["-hide_banner", "-v", "error", "-y", ...args], { stdio: "inherit" });
|
||||
if (run.status !== 0) throw new Error(`ffmpeg failed: ${args.join(" ")}`);
|
||||
}
|
||||
|
||||
/** An H.264 preview of an over layer on the light field. */
|
||||
function preview(name, first, count) {
|
||||
const dir = join(extra, name);
|
||||
ffmpeg([
|
||||
"-f", "lavfi", "-i", `color=c=0xfbfbfa:s=1920x1080:r=${FPS}`,
|
||||
"-framerate", String(FPS), "-start_number", String(first), "-i", join(dir, "%05d.png"),
|
||||
"-filter_complex", "[0][1]overlay=format=auto:shortest=1,format=yuv420p",
|
||||
"-frames:v", String(count), "-c:v", "libx264", "-crf", "18", join(extra, `${name}.mp4`),
|
||||
]);
|
||||
}
|
||||
|
||||
function fresh(name) {
|
||||
const dir = join(extra, name);
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
mkdirSync(dir, { recursive: true });
|
||||
return dir;
|
||||
}
|
||||
|
||||
const manifest = (dir, name, first, count) =>
|
||||
writeFileSync(join(dir, "manifest.json"), JSON.stringify({ name, first, count, fps: FPS, kind: "over" }, null, 1));
|
||||
|
||||
const wanted = process.argv.slice(2);
|
||||
const want = (name) => !wanted.length || wanted.includes(name);
|
||||
console.log(`plan: ${EDIT_PLAN}`);
|
||||
|
||||
for (const a of APPS) {
|
||||
const name = `${a.app}-fx`;
|
||||
if (!want(name)) continue;
|
||||
const { first, count } = frames(a);
|
||||
const dir = fresh(name);
|
||||
const list = Array.from({ length: count }, (_, k) => first + k);
|
||||
writeFileSync(join(dir, "zoom.json"), JSON.stringify(zoomList(a), null, 1));
|
||||
const rects = list.map((fr) => view(a, fr / FPS).map((v) => Math.round(v * 100) / 100));
|
||||
writeFileSync(join(dir, "view.json"), JSON.stringify({ first, rects }));
|
||||
await paint(dir, list, (t) => calloutFrame(a, t));
|
||||
manifest(dir, name, first, count);
|
||||
preview(name, first, count);
|
||||
console.log(`${name}: frames ${first}–${first + count - 1}`);
|
||||
}
|
||||
|
||||
if (want("fx-grid")) {
|
||||
const dir = fresh("fx-grid");
|
||||
const spans = APPS.map((a, i) => ({ ...frames(a), lifts: lifts(a, 0x5eed + i) }));
|
||||
const first = spans[0].first;
|
||||
const last = spans.at(-1).first + spans.at(-1).count - 1;
|
||||
for (const s of spans) {
|
||||
const list = Array.from({ length: s.count }, (_, k) => s.first + k);
|
||||
await paint(dir, list, (t) => gridFrame(s.lifts, t));
|
||||
}
|
||||
const empty = join(dir, "empty.png");
|
||||
await pages[0].evaluate(() => (document.body.innerHTML = ""));
|
||||
await pages[0].screenshot({ path: empty, omitBackground: true });
|
||||
for (let fr = first; fr <= last; fr++) {
|
||||
if (!spans.some((s) => fr >= s.first && fr < s.first + s.count)) {
|
||||
copyFileSync(empty, join(dir, `${String(fr).padStart(5, "0")}.png`));
|
||||
}
|
||||
}
|
||||
rmSync(empty);
|
||||
manifest(dir, "fx-grid", first, last - first + 1);
|
||||
preview("fx-grid", first, last - first + 1);
|
||||
console.log(`fx-grid: frames ${first}–${last}`);
|
||||
}
|
||||
|
||||
await browser.close();
|
||||
Reference in new issue
Block a user