From 133b715f37144cb3e4271cb905f69947ab9e2b0a Mon Sep 17 00:00:00 2001 From: Apsides Labs Date: Thu, 5 Nov 2026 19:06:52 +0530 Subject: [PATCH 01/10] =?UTF-8?q?feat(kit):=20scene-kit=20=E2=80=94=20stag?= =?UTF-8?q?es,=20cast,=20lights,=20motion,=20shots,=20HUD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kit/lib/scene-kit.js | 704 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 704 insertions(+) create mode 100644 kit/lib/scene-kit.js diff --git a/kit/lib/scene-kit.js b/kit/lib/scene-kit.js new file mode 100644 index 0000000..a5a1291 --- /dev/null +++ b/kit/lib/scene-kit.js @@ -0,0 +1,704 @@ +/** + * scene-kit.js — the reusable half of a Reelwright film. + * + * A film used to need a scene.js that re-invented the renderer, the lights, the + * cast, the HUD and the camera path from scratch (templates/scene.js is 1,100 + * lines of exactly that, hard-wired to one shop set). This module is that work, + * extracted and parameterised, so a new film only has to describe its sets: + * + * import * as K from './scene-kit.js'; + * const app = K.createApp({ w: 1080, h: 1920 }); + * const rig = await K.loadRig('./assets/readyplayer.me.glb'); + * const stages = K.createStages(app.scene, [ { key:'office', t0:0, t1:T.s3, build(g){ ... } } ]); + * const hud = K.makeHud({ film: FILM, lines: LINES, safe: K.SAFE }); + * + * Everything here is deterministic: no Math.random, no Date, no per-run state. + * Frame i must be a pure function of t = i / FPS. + */ +import * as THREE from 'three'; +import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'; +import { clone as skClone } from 'three/addons/utils/SkeletonUtils.js'; + +// ---------------------------------------------------------------- maths +export const clamp = (x, a, b) => Math.min(b, Math.max(a, x)); +export const lerp = (a, b, t) => a + (b - a) * t; +export const smooth = t => { t = clamp(t, 0, 1); return t * t * (3 - 2 * t); }; +export const easeOut = t => 1 - Math.pow(1 - clamp(t, 0, 1), 3); +export const easeInOut = t => { t = clamp(t, 0, 1); return t < .5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2; }; +export const seg = (t, a, b) => clamp((t - a) / Math.max(1e-6, b - a), 0, 1); +export function rng(s) { let a = s; return () => { a |= 0; a = a + 0x6D2B79F5 | 0; let t = Math.imul(a ^ a >>> 15, 1 | a); t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t; return ((t ^ t >>> 14) >>> 0) / 4294967296; }; } + +// the union of TikTok + Reels + Shorts UI, on a 1080x1920 frame +export const SAFE = { x0: 120, x1: 880, y0: 290, y1: 1240 }; + +// ---------------------------------------------------------------- app +export function createApp(opts = {}) { + const w = opts.w || 1080, h = opts.h || 1920; + const renderer = new THREE.WebGLRenderer({ antialias: false, preserveDrawingBuffer: true }); + renderer.setPixelRatio(1); + renderer.setSize(w, h); + renderer.outputColorSpace = THREE.SRGBColorSpace; + renderer.toneMapping = opts.tone ?? THREE.ACESFilmicToneMapping; + renderer.toneMappingExposure = opts.exposure ?? 1.2; + if (opts.shadows !== false) { + renderer.shadowMap.enabled = true; + renderer.shadowMap.type = THREE.PCFSoftShadowMap; + } + document.body.appendChild(renderer.domElement); + + const scene = new THREE.Scene(); + if (opts.background !== undefined) scene.background = new THREE.Color(opts.background); + if (opts.fog) scene.fog = new THREE.Fog(opts.fog[0], opts.fog[1], opts.fog[2]); + + const camera = new THREE.PerspectiveCamera(opts.fov ?? 38, w / h, 0.1, opts.far ?? 400); + camera.position.set(0, 2, 8); + + const out = document.createElement('canvas'); + out.width = w; out.height = h; + const ctx = out.getContext('2d'); + + return { renderer, scene, camera, out, ctx, w, h }; +} + +// ---------------------------------------------------------------- lights +/** + * A key / fill / rim rig. Every Reelwright film before this shipped with the + * lights hard-coded to one room; this is the same rig, tunable. + */ +export function threePoint(scene, opts = {}) { + const key = new THREE.DirectionalLight(opts.keyColor ?? 0xffd2a0, opts.keyIntensity ?? 3.0); + key.position.set(...(opts.keyPos || [3.4, 4.2, 2.4])); + if (opts.shadows !== false) { + key.castShadow = true; + key.shadow.mapSize.set(opts.shadowMap ?? 1024, opts.shadowMap ?? 1024); + const s = opts.shadowSpan ?? 7; + key.shadow.camera.left = -s; key.shadow.camera.right = s; + key.shadow.camera.top = s; key.shadow.camera.bottom = -s; + key.shadow.camera.near = 0.5; key.shadow.camera.far = opts.shadowFar ?? 40; + key.shadow.bias = -0.0015; + key.shadow.normalBias = 0.02; + } + scene.add(key); + + const fill = new THREE.DirectionalLight(opts.fillColor ?? 0x7f9dc9, opts.fillIntensity ?? 1.1); + fill.position.set(...(opts.fillPos || [-4, 2.4, 2.0])); + scene.add(fill); + + const rim = new THREE.DirectionalLight(opts.rimColor ?? 0xa9c4ea, opts.rimIntensity ?? 1.4); + rim.position.set(...(opts.rimPos || [-1.5, 3.0, -5])); + scene.add(rim); + + const ambient = new THREE.AmbientLight(opts.ambientColor ?? 0x6b7d9e, opts.ambient ?? 1.5); + scene.add(ambient); + + let practical = null; + if (opts.practical) { + practical = new THREE.PointLight(opts.practical.color ?? 0xffcf94, opts.practical.intensity ?? 14, opts.practical.distance ?? 12, 2); + practical.position.set(...(opts.practical.pos || [0, 3, -2])); + scene.add(practical); + } + return { key, fill, rim, ambient, practical }; +} + +// ---------------------------------------------------------------- geometry +export const mat = (color, o = {}) => new THREE.MeshLambertMaterial(Object.assign({ color }, o)); +export const flat = (color, o = {}) => new THREE.MeshBasicMaterial(Object.assign({ color }, o)); + +export function plane(w, h, material, x, y, z, parent) { + const m = new THREE.Mesh(new THREE.PlaneGeometry(w, h), material); + m.position.set(x, y, z); parent.add(m); return m; +} +export function box(w, h, d, material, x, y, z, parent, shadow = true) { + const m = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), typeof material === 'number' ? mat(material) : material); + m.position.set(x, y, z); + m.castShadow = shadow; m.receiveShadow = shadow; + parent.add(m); return m; +} +export function cyl(r1, r2, h, material, x, y, z, parent) { + const m = new THREE.Mesh(new THREE.CylinderGeometry(r1, r2, h, 12), typeof material === 'number' ? mat(material) : material); + m.position.set(x, y, z); + m.castShadow = true; m.receiveShadow = true; + parent.add(m); return m; +} + +export function canvasTex(w, h, draw) { + const c = document.createElement('canvas'); c.width = w; c.height = h; + const g = c.getContext('2d'); draw(g, w, h); + const t = new THREE.CanvasTexture(c); + t.colorSpace = THREE.SRGBColorSpace; + t.anisotropy = 4; + return t; +} +export function gradientTex(stops, h = 640) { + return canvasTex(64, h, g => { + const gr = g.createLinearGradient(0, 0, 0, h); + for (const [p, col] of stops) gr.addColorStop(p, col); + g.fillStyle = gr; g.fillRect(0, 0, 64, h); + }); +} +export function softDot(colour, opacity) { + return canvasTex(128, 128, g => { + const gr = g.createRadialGradient(64, 64, 2, 64, 64, 64); + gr.addColorStop(0, colour); + gr.addColorStop(1, 'rgba(0,0,0,0)'); + g.globalAlpha = opacity; g.fillStyle = gr; g.fillRect(0, 0, 128, 128); + }); +} + +/** A height profile over x, triangulated as a strip. Monotonic x required. */ +export function strip(pts, color, bottom = -40, material) { + const pos = []; + for (let i = 0; i < pts.length - 1; i++) { + const [x0, y0] = pts[i], [x1, y1] = pts[i + 1]; + pos.push(x0, y0, 0, x1, y1, 0, x1, bottom, 0); + pos.push(x0, y0, 0, x1, bottom, 0, x0, bottom, 0); + } + const geo = new THREE.BufferGeometry(); + geo.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3)); + const m = new THREE.Mesh(geo, material || new THREE.MeshBasicMaterial({ color, side: THREE.DoubleSide })); + return m; +} +export function ridgePts(seed, x0, x1, baseY, amp, n) { + const r = rng(seed); + const pts = []; + for (let i = 0; i <= n; i++) { + const x = x0 + (x1 - x0) * (i / n); + const edge = Math.sin((i / n) * Math.PI); + const y = baseY + amp * Math.pow(edge, 0.8) * (0.22 + 0.78 * Math.pow(r(), 1.4)) * (i % 2 ? 1 : 0.55); + pts.push([x, y]); + } + return pts; +} +/** Everything of a profile above `snowY`, clipped where it crosses. */ +export function snowLine(pts, snowY) { + const o = []; + for (let i = 0; i < pts.length - 1; i++) { + const [x0, y0] = pts[i], [x1, y1] = pts[i + 1]; + if ((y0 - snowY) * (y1 - snowY) < 0) o.push([x0 + (x1 - x0) * (snowY - y0) / (y1 - y0), snowY]); + if (y1 > snowY) o.push([x1, y1]); + } + return o; +} +/** A snow-capped massif from a hand-authored profile: shadow face, lit face, snow. */ +export function peakGroup(profile, { scale = 1, z = -20, lit = 0xd2dbe7, shadow = 0x8ea3bd, snow = 0xfbfcff, snowY = 8.4 } = {}) { + const g = new THREE.Group(); + const s = strip(profile.map(([x, y]) => [x - 1.15, y - 0.55]), shadow); + s.position.z = -0.2; g.add(s); + g.add(strip(profile, lit)); + const cap = strip(snowLine(profile, snowY), snow, snowY); + cap.position.z = 0.3; g.add(cap); + g.scale.setScalar(scale); + g.position.z = z; + return g; +} + +/** A soft ellipse on the floor, so a character does not look pasted on. */ +export function contactShadow(parent, y = 0.01, s = 1.1) { + const tex = softDot('rgba(0,0,0,0.55)', 1); + const m = new THREE.Mesh( + new THREE.PlaneGeometry(s, s * 0.5), + new THREE.MeshBasicMaterial({ map: tex, transparent: true, depthWrite: false }) + ); + m.rotation.x = -Math.PI / 2; + m.position.y = y; + parent.add(m); + return m; +} + +// ---------------------------------------------------------------- the cast +export const BONES = ['Hips', 'Spine', 'Spine1', 'Spine2', 'Neck', 'Head', 'LeftShoulder', 'LeftArm', 'LeftForeArm', + 'RightShoulder', 'RightArm', 'RightForeArm', 'LeftUpLeg', 'RightUpLeg', 'LeftLeg', 'RightLeg']; + +export async function loadRig(url) { + const gltf = await new GLTFLoader().loadAsync(url); + return gltf.scene; +} + +/** + * Clone the rig into a person you can pose and recolour. + * PBR materials are converted to Lambert: cheaper on a software rasteriser and + * a better match for the flat, poster-like grade the kit aims at. + */ +export function makeHuman(rig, opts = {}) { + const root = skClone(rig); + const convert = (m) => { + const n = new THREE.MeshLambertMaterial({ + map: m.map || null, + color: m.color ? m.color.clone() : new THREE.Color(0xffffff) + }); + if (m.transparent) { n.transparent = true; n.opacity = m.opacity; } + return n; + }; + root.traverse(o => { + if (!o.isMesh) return; + o.frustumCulled = false; + o.castShadow = opts.shadows !== false; + o.receiveShadow = opts.shadows !== false; + o.material = Array.isArray(o.material) ? o.material.map(convert) : convert(o.material); + const mats = Array.isArray(o.material) ? o.material : [o.material]; + if (opts.hide && opts.hide.includes(o.name)) o.visible = false; + mats.forEach(m => { + if (o.name === 'Wolf3D_Outfit_Top' && opts.top !== undefined) { m.map = null; m.color.set(opts.top); } + if (o.name === 'Wolf3D_Outfit_Bottom' && opts.bottom !== undefined) { m.map = null; m.color.set(opts.bottom); } + if (o.name === 'Wolf3D_Outfit_Footwear' && opts.shoes !== undefined) { m.map = null; m.color.set(opts.shoes); } + if ((o.name === 'Wolf3D_Skin' || o.name === 'Wolf3D_Body') && opts.skin !== undefined) m.color.set(opts.skin); + if (o.name === 'Wolf3D_Hair' && opts.hair !== undefined) { m.map = null; m.color.set(opts.hair); } + }); + }); + + const bones = {}; + root.traverse(o => { if (o.isBone && BONES.includes(o.name)) bones[o.name] = o; }); + const rest = {}; + Object.entries(bones).forEach(([n, b]) => rest[n] = b.quaternion.clone()); + + const morphs = []; + root.traverse(o => { if (o.isMesh && o.morphTargetDictionary && 'mouthOpen' in o.morphTargetDictionary) morphs.push(o); }); + + const wrapper = new THREE.Group(); + wrapper.add(root); + const scale = opts.height ? 1 : (opts.scale ?? 1); + root.scale.setScalar(scale); + root.updateMatrixWorld(true); + if (opts.height) { + const b = new THREE.Box3().setFromObject(root); + const h = b.max.y - b.min.y; + root.scale.setScalar(opts.height / h); + root.updateMatrixWorld(true); + } + const b2 = new THREE.Box3().setFromObject(root); + root.position.y = -b2.min.y; + + const human = { root: wrapper, inner: root, bones, rest, morphs, opts }; + if (opts.shadow !== false) contactShadow(wrapper, 0.012, opts.shadowSize ?? 0.9); + return human; +} + +// pose presets, radians, relative to the rig's rest pose +export const POSE = { + idle: { LeftArm: [0, 0, -0.20], RightArm: [0, 0, 0.20], LeftForeArm: [0, 0, -0.12], RightForeArm: [0, 0, 0.12], Spine: [0.02, 0, 0] }, + talk: { LeftArm: [0.10, 0, -0.24], RightArm: [0.16, 0, 0.30], LeftForeArm: [0.35, 0, -0.25], RightForeArm: [0.45, 0, 0.30], Spine: [0.02, 0, 0], Head: [0.04, 0, 0] }, + present: { LeftArm: [0.25, 0, -0.55], RightArm: [0.25, 0, 0.55], LeftForeArm: [0.55, 0, -0.45], RightForeArm: [0.55, 0, 0.45], Spine: [-0.03, 0, 0] }, + pointUp: { LeftArm: [0, 0, -0.2], RightArm: [-1.25, 0, 0.35], RightForeArm: [-0.35, 0, 0.1], Spine: [0.03, 0, 0], Head: [-0.06, 0, 0] }, + listen: { LeftArm: [0.05, 0, -0.18], RightArm: [0.05, 0, 0.18], LeftForeArm: [0.25, 0, -0.2], RightForeArm: [0.25, 0, 0.2], Spine: [0.05, 0, 0], Head: [0.10, 0.12, 0.04] }, + write: { LeftArm: [0.42, 0, -0.30], RightArm: [0.52, 0, 0.34], LeftForeArm: [0.70, 0, -0.28], RightForeArm: [0.78, 0, 0.30], Spine: [0.10, 0, 0], Head: [0.16, 0, 0] }, + sad: { LeftArm: [0.02, 0, -0.10], RightArm: [0.02, 0, 0.10], LeftForeArm: [0.05, 0, -0.05], RightForeArm: [0.05, 0, 0.05], Spine: [0.12, 0, 0], Spine1: [0.10, 0, 0], Head: [0.22, 0, 0] }, + happy: { LeftArm: [0.15, 0, -0.35], RightArm: [0.15, 0, 0.35], LeftForeArm: [0.4, 0, -0.3], RightForeArm: [0.4, 0, 0.3], Spine: [-0.04, 0, 0], Head: [-0.05, 0, 0] } +}; + +const _q = new THREE.Quaternion(), _e = new THREE.Euler(); +export function poseHuman(h, pose, blend = 1) { + for (const [name, e] of Object.entries(pose)) { + const b = h.bones[name]; if (!b) continue; + _e.set(e[0], e[1], e[2]); + _q.setFromEuler(_e); + const target = h.rest[name].clone().multiply(_q); + b.quaternion.copy(h.rest[name]).slerp(target, blend); + } +} +export function speak(h, amount) { + if (!h) return; + h.morphs.forEach(m => { + const d = m.morphTargetDictionary; + if ('mouthOpen' in d) m.morphTargetInfluences[d.mouthOpen] = amount; + if ('mouthSmile' in d) m.morphTargetInfluences[d.mouthSmile] = 0.12; + }); +} +/** Narration amplitude at time t, from the envelope the voice step measured. */ +export function mouthAt(envelope, t) { + if (!envelope || !envelope.data || !envelope.data.length) return 0; + const f = Math.floor(t * (envelope.fps || 30)); + const v = envelope.data[Math.max(0, Math.min(envelope.data.length - 1, f))] || 0; + return Math.pow(clamp(v * 1.6, 0, 1), 0.8) * 0.55; +} +/** Is line `id` being spoken at t? */ +export function speaking(lines, id, t, pad = 0.1) { + const tm = lines && lines[id]; + if (!tm) return 0; + return t >= tm.start - pad && t <= tm.start + tm.dur + pad ? 1 : 0; +} + +// ---------------------------------------------------------------- stages +/** + * A film is a list of stages. Each stage owns a group, a camera path and an + * optional per-frame update; the manager shows one at a time and cuts on the + * beat boundaries you give it. + */ +export function createStages(scene, defs) { + const stages = defs.map(d => { + const group = new THREE.Group(); + group.name = d.key; + group.visible = false; + scene.add(group); + const api = d.build(group) || {}; + return Object.assign({}, d, { group, api }); + }); + + function at(t) { + for (const s of stages) if (t >= s.t0 && t < s.t1) return s; + return stages[stages.length - 1]; + } + + return { + stages, + at, + update(t) { + const s = at(t); + for (const x of stages) x.group.visible = (x === s); + const u = easeInOut(seg(t, s.t0, s.t1)); + if (s.api.camera) s.api.camera(u, t); + if (s.api.update) s.api.update(t, u); + return s; + } + }; +} + +// ---------------------------------------------------------------- HUD +/** + * Cards, big numbers and burned-in captions, all inside the platform safe area. + */ +export function makeHud(opts) { + const film = opts.film || {}; + const lines = opts.lines || {}; + const safe = opts.safe || SAFE; + const accent = opts.accent || (film.graphics && film.graphics.title && film.graphics.title.accent) || '#e8b64c'; + const col = opts.column || { x: safe.x0, w: 520 }; + const fontOf = (size, weight) => `${weight || 700} ${size}px ${opts.font || '"DejaVu Sans", Arial, sans-serif'}`; + + function wrap(g, str, maxW, size, weight) { + g.font = fontOf(size, weight); + const words = String(str).split(/\s+/); + const out = []; + let cur = ''; + for (const w of words) { + const tryLine = cur ? cur + ' ' + w : w; + if (g.measureText(tryLine).width > maxW && cur) { out.push(cur); cur = w; } + else cur = tryLine; + } + if (cur) out.push(cur); + return out; + } + function text(g, s, x, y, size, weight, color, align = 'center', maxW = 0) { + g.font = fontOf(size, weight); + g.fillStyle = color; + g.textAlign = align; + g.textBaseline = 'alphabetic'; + if (maxW) { + const rows = wrap(g, s, maxW, size, weight); + rows.forEach((ln, i) => g.fillText(ln, x, y + i * size * 1.16)); + return rows.length * size * 1.16; + } + g.fillText(s, x, y); + return size; + } + function card(g, x, y, w, h, alpha, bar) { + g.save(); + g.globalAlpha = alpha; + g.fillStyle = 'rgba(8,13,21,0.84)'; + const r = 26; + g.beginPath(); + g.moveTo(x + r, y); g.lineTo(x + w - r, y); g.quadraticCurveTo(x + w, y, x + w, y + r); + g.lineTo(x + w, y + h - r); g.quadraticCurveTo(x + w, y + h, x + w - r, y + h); + g.lineTo(x + r, y + h); g.quadraticCurveTo(x, y + h, x, y + h - r); + g.lineTo(x, y + r); g.quadraticCurveTo(x, y, x + r, y); + g.closePath(); g.fill(); + g.strokeStyle = 'rgba(255,255,255,0.09)'; g.lineWidth = 2; g.stroke(); + if (bar) { g.fillStyle = bar; g.fillRect(x, y + 26, 6, h - 52); } + g.restore(); + } + function alphaIn(t, a, b, fade = 0.4) { + if (t < a - fade || t > b + fade) return 0; + return Math.min(seg(t, a - fade, a), 1 - seg(t, b, b + fade)); + } + + const G = film.graphics || {}; + const times = opts.times || {}; + + function drawTitle(g, t) { + if (!G.title) return; + const a = alphaIn(t, opts.titleIn ?? 0.5, opts.titleOut ?? 4.7); + if (a <= 0) return; + g.save(); g.globalAlpha = a; + card(g, col.x, 330, col.w, 300, 0.9, accent); + const used = text(g, G.title.heading || film.title || '', col.x + col.w / 2, 425, 44, 700, '#ffffff', 'center', 430); + if (G.title.sub) text(g, G.title.sub, col.x + col.w / 2, 425 + used + 26, 28, 400, 'rgba(255,255,255,0.62)'); + g.restore(); + } + function drawSteps(g, t) { + if (!G.steps || !G.steps.length) return; + const a = alphaIn(t, times.stepsIn ?? 0, times.stepsOut ?? 0, 0.3); + if (a <= 0) return; + const rowH = 72, top = 320; + g.save(); g.globalAlpha = a; + card(g, col.x, top, col.w, rowH * G.steps.length + 62, 0.88, null); + text(g, opts.stepsLabel || 'METHOD', col.x + 40, top + 42, 22, 700, 'rgba(255,255,255,0.5)', 'left'); + const lit = times.stepBeats || []; + G.steps.forEach((row, i) => { + const group = Math.min(Math.max(0, lit.length - 1), Math.floor((i / G.steps.length) * lit.length)); + const on = t >= (lit[group] ?? 0) - 0.15; + const y = top + 56 + i * rowH; + g.globalAlpha = a * (on ? 1 : 0.32); + g.font = fontOf(20, 700); + g.fillStyle = on ? 'rgba(255,255,255,0.45)' : 'rgba(255,255,255,0.28)'; + g.textAlign = 'left'; + g.fillText(String(row.n), col.x + 40, y + 26); + g.font = fontOf(26, on ? 700 : 400); + g.fillStyle = on ? '#ffffff' : 'rgba(255,255,255,0.55)'; + g.fillText(String(row.label), col.x + 76, y + 26); + if (on) { g.fillStyle = row.color || accent; g.fillRect(col.x + col.w - 44, y + 8, 8, 8); } + }); + g.restore(); + } + function drawProof(g, t) { + if (!G.proof) return; + const a = alphaIn(t, times.proofIn ?? 0, times.proofOut ?? 0, 0.45); + if (a <= 0) return; + const rows = G.proof.lines || []; + g.save(); g.globalAlpha = a; + card(g, col.x, 340, col.w, 300, 0.9, G.proof.accent || accent); + text(g, rows[0] || '', col.x + col.w / 2, 470, 74, 700, '#ffffff'); + if (rows[1]) text(g, rows[1], col.x + col.w / 2, 522, 26, 400, 'rgba(255,255,255,0.64)'); + if (G.proof.foot) text(g, G.proof.foot, col.x + col.w / 2, 586, 22, 400, G.proof.accent || accent); + g.restore(); + } + function drawEnd(g, t, dur) { + if (!G.end) return; + const a = alphaIn(t, Math.max(0, dur - 5.2), dur + 1, 0.55); + if (a <= 0) return; + g.save(); g.globalAlpha = a; + card(g, col.x, 340, col.w, 300, 0.9, G.end.accent || accent); + text(g, G.end.line1 || '', col.x + col.w / 2, 452, 44, 700, '#ffffff'); + if (G.end.line2) text(g, G.end.line2, col.x + col.w / 2, 508, 44, 700, '#ffffff'); + if (G.end.foot) text(g, G.end.foot, col.x + col.w / 2, 588, 22, 400, G.end.accent || accent); + g.restore(); + } + function drawCaptions(g, t) { + if (film.captions === false) return; + const size = film.captionSize || 38; + (film.lines || []).forEach((ln, i) => { + const tm = lines[ln.id]; + if (!tm) return; + const a = Math.min(seg(t, tm.start - 0.05, tm.start + 0.12), 1 - seg(t, tm.start + tm.dur, tm.start + tm.dur + 0.16)); + if (a <= 0) return; + g.save(); g.globalAlpha = a; + const rows = wrap(g, ln.text, 760, size, 700); + const lh = size * 1.18; + const y0 = 1168 - (rows.length - 1) * lh; + g.font = fontOf(size, 700); + g.textAlign = 'center'; + g.lineWidth = 8; g.strokeStyle = 'rgba(4,8,14,0.94)'; g.lineJoin = 'round'; + rows.forEach((ln2, k) => g.strokeText(ln2, 500, y0 + k * lh)); + g.fillStyle = '#ffffff'; + rows.forEach((ln2, k) => g.fillText(ln2, 500, y0 + k * lh)); + g.restore(); + }); + } + + return { + card, text, wrap, alphaIn, accent, + draw(g, t, dur) { + drawSteps(g, t); + drawProof(g, t); + drawEnd(g, t, dur); + drawTitle(g, t); + drawCaptions(g, t); + if (opts.vignette !== false) { + const v = film.grade && film.grade.vignette !== undefined ? film.grade.vignette : 0.34; + const vg = g.createRadialGradient(540, 860, 420, 540, 860, 1220); + vg.addColorStop(0, 'rgba(0,0,0,0)'); + vg.addColorStop(1, `rgba(0,0,0,${v.toFixed(3)})`); + g.fillStyle = vg; g.fillRect(0, 0, 1080, 1920); + } + if (opts.debugSafe) { + g.strokeStyle = 'rgba(255,60,60,0.9)'; g.lineWidth = 3; + g.strokeRect(safe.x0, safe.y0, safe.x1 - safe.x0, safe.y1 - safe.y0); + } + } + }; +} + +// ---------------------------------------------------------------- run +/** Wire a frame function to the renderer, the HUD and the page contract. */ +export function run(app, { fps, dur, update, hud }) { + const { renderer, scene, camera, ctx, out, w, h } = app; + const sx = w / 1080, sy = h / 1920; + window.renderFrame = function (i) { + const t = clamp(i / fps, 0, dur); + update(t); + renderer.render(scene, camera); + ctx.drawImage(renderer.domElement, 0, 0); + if (hud) { + ctx.save(); + ctx.setTransform(sx, 0, 0, sy, 0, 0); + ctx.textBaseline = 'alphabetic'; + hud.draw(ctx, t, dur); + ctx.restore(); + } + return out.toDataURL('image/jpeg', 0.92); + }; + window.FPS = fps; + window.TOTAL = Math.round(fps * dur); + window.sceneReady = true; +} + +// ---------------------------------------------------------------- motion +/** One bone's local rotation on top of its rest pose. */ +export function boneRot(h, name, x = 0, y = 0, z = 0) { + const b = h.bones[name]; if (!b) return; + _e.set(x, y, z); + _q.setFromEuler(_e); + b.quaternion.copy(h.rest[name]).multiply(_q); +} + +/** Procedural walk: legs swing, arms counter-swing, body bobs. */ +export function walkCycle(h, t, { speed = 1, amp = 0.55, bob = 0.028 } = {}) { + const p = t * 5.2 * speed; + const s = Math.sin(p); + boneRot(h, 'LeftUpLeg', s * amp); + boneRot(h, 'RightUpLeg', -s * amp); + boneRot(h, 'LeftLeg', Math.max(0, -s) * amp * 1.1); + boneRot(h, 'RightLeg', Math.max(0, s) * amp * 1.1); + boneRot(h, 'LeftArm', -s * amp * 0.75, 0, -0.18); + boneRot(h, 'RightArm', s * amp * 0.75, 0, 0.18); + boneRot(h, 'LeftForeArm', Math.max(0, s) * 0.3, 0, -0.1); + boneRot(h, 'RightForeArm', Math.max(0, -s) * 0.3, 0, 0.1); + boneRot(h, 'Spine1', 0.02, s * 0.04, 0); + h.inner.position.y = Math.abs(Math.sin(p)) * bob; +} + +/** Head look, yaw/pitch in radians. */ +export function headLook(h, yaw = 0, pitch = 0) { + boneRot(h, 'Neck', pitch * 0.4, yaw * 0.4, 0); + boneRot(h, 'Head', pitch * 0.6, yaw * 0.6, 0); +} + +/** Deterministic camera micro-motion, so a frame never reads as a still. */ +export function handheld(t, amp = 0.006) { + return { + x: Math.sin(t * 1.7) * amp + Math.sin(t * 0.63 + 1.1) * amp * 0.6, + y: Math.sin(t * 1.31 + 0.7) * amp * 0.8 + Math.sin(t * 0.41) * amp * 0.5, + roll: Math.sin(t * 0.87 + 2.1) * amp * 0.45 + }; +} + +/** A shot list for one stage: hard cuts between camera setups. */ +export function shotPicker(shots) { + return function pick(t) { + let s = shots[shots.length - 1]; + for (const x of shots) { if (t >= x.t0 && t < x.t1) { s = x; break; } } + const u = clamp((t - s.t0) / Math.max(1e-6, s.t1 - s.t0), 0, 1); + s.cam(easeInOut(u), t); + return s; + }; +} + +/** Drifting dust motes, deterministic from t. */ +export function motes(parent, opts = {}) { + const count = opts.count ?? 90; + const spread = opts.spread || [8, 5, 6]; + const centre = opts.centre || [0, 2, -3]; + const r = rng(opts.seed ?? 3); + const pos = new Float32Array(count * 3); + const phase = new Float32Array(count); + for (let i = 0; i < count; i++) { + pos[i * 3] = centre[0] + (r() - 0.5) * spread[0]; + pos[i * 3 + 1] = centre[1] + (r() - 0.5) * spread[1]; + pos[i * 3 + 2] = centre[2] + (r() - 0.5) * spread[2]; + phase[i] = r() * Math.PI * 2; + } + const geo = new THREE.BufferGeometry(); + geo.setAttribute('position', new THREE.BufferAttribute(pos.slice(), 3)); + const m = new THREE.PointsMaterial({ + size: opts.size ?? 0.022, + map: softDot('#ffffff', 1), + color: opts.colour ?? 0xffd9a0, + transparent: true, + opacity: opts.opacity ?? 0.45, + depthWrite: false, + blending: THREE.AdditiveBlending + }); + const pts = new THREE.Points(geo, m); + pts.frustumCulled = false; + parent.add(pts); + const base = pos.slice(); + return { + mesh: pts, + update(t) { + const a = geo.attributes.position.array; + for (let i = 0; i < count; i++) { + a[i * 3] = base[i * 3] + Math.sin(t * 0.7 + phase[i]) * 0.16; + a[i * 3 + 1] = base[i * 3 + 1] + Math.sin(t * 0.45 + phase[i] * 1.7) * 0.2; + a[i * 3 + 2] = base[i * 3 + 2] + Math.cos(t * 0.6 + phase[i]) * 0.12; + } + geo.attributes.position.needsUpdate = true; + } + }; +} + +/** Falling snow, wrapping around. */ +export function snowfall(parent, opts = {}) { + const count = opts.count ?? 240; + const area = opts.area || [26, 16, 14]; + const centre = opts.centre || [0, 6, -6]; + const speed = opts.speed ?? 0.9; + const r = rng(opts.seed ?? 9); + const pos = new Float32Array(count * 3); + const phase = new Float32Array(count); + for (let i = 0; i < count; i++) { + pos[i * 3] = centre[0] + (r() - 0.5) * area[0]; + pos[i * 3 + 1] = centre[1] + (r() - 0.5) * area[1]; + pos[i * 3 + 2] = centre[2] + (r() - 0.5) * area[2]; + phase[i] = r() * 4; + } + const geo = new THREE.BufferGeometry(); + geo.setAttribute('position', new THREE.BufferAttribute(pos.slice(), 3)); + const m = new THREE.PointsMaterial({ + size: opts.size ?? 0.05, + map: softDot('#ffffff', 1), + color: opts.colour ?? 0xffffff, + transparent: true, + opacity: opts.opacity ?? 0.75, + depthWrite: false + }); + const pts = new THREE.Points(geo, m); + pts.frustumCulled = false; + parent.add(pts); + const base = pos.slice(); + const top = centre[1] + area[1] / 2; + return { + mesh: pts, + update(t) { + const a = geo.attributes.position.array; + for (let i = 0; i < count; i++) { + const fall = (t * speed + phase[i]) % area[1]; + a[i * 3] = base[i * 3] + Math.sin(t * 0.5 + phase[i]) * 0.35; + a[i * 3 + 1] = top - fall; + a[i * 3 + 2] = base[i * 3 + 2]; + } + geo.attributes.position.needsUpdate = true; + } + }; +} + +/** A wall with a real opening, so the mountain can be seen from indoors. */ +export function windowOpening(parent, opts = {}) { + const { w = 1.9, h = 2.5, x = 0, y = 3, z = -7.4, wallW = 30, wallH = 16, wallY = 4, wallMat } = opts; + const M = wallMat || mat(0x23304a); + const x0 = -wallW / 2, x1 = wallW / 2, y0 = wallY - wallH / 2, y1 = wallY + wallH / 2; + const panel = (pw, ph, px, py) => { + const m = new THREE.Mesh(new THREE.PlaneGeometry(pw, ph), M); + m.position.set(px, py, z); + m.receiveShadow = true; + parent.add(m); + }; + panel((x - w / 2) - x0, wallH, (x0 + (x - w / 2)) / 2, wallY); + panel(x1 - (x + w / 2), wallH, ((x + w / 2) + x1) / 2, wallY); + panel(w, y1 - (y + h / 2), x, ((y + h / 2) + y1) / 2); + panel(w, (y - h / 2) - y0, x, (y0 + (y - h / 2)) / 2); + const frameMat = mat(0x2a1f16); + box(0.05, h, 0.06, frameMat, x, y, z + 0.03, parent); + box(w, 0.05, 0.06, frameMat, x, y, z + 0.03, parent); + box(w + 0.12, 0.08, 0.1, frameMat, x, y + h / 2, z + 0.03, parent); + box(w + 0.12, 0.08, 0.1, frameMat, x, y - h / 2, z + 0.03, parent); + box(0.08, h, 0.1, frameMat, x - w / 2, y, z + 0.03, parent); + box(0.08, h, 0.1, frameMat, x + w / 2, y, z + 0.03, parent); +} From 200b304ed2aa8522d08880ec1e6a4f7557a96d10 Mon Sep 17 00:00:00 2001 From: Apsides Labs Date: Thu, 5 Nov 2026 19:06:55 +0530 Subject: [PATCH 02/10] build: ship scene-kit.js into the render site --- kit/build.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kit/build.py b/kit/build.py index 9bfa2f4..26eaf08 100644 --- a/kit/build.py +++ b/kit/build.py @@ -82,10 +82,8 @@ def step_site(film_path, build, film): shutil.copy2(os.path.join(film_dir, "scene.js"), os.path.join(site, "scene.js")) shutil.copy2(os.path.join(ROOT, "templates", "index.html"), os.path.join(site, "index.html")) shutil.copy2(os.path.join(build, "envelope.json"), os.path.join(site, "envelope.json")) - if os.path.exists(os.path.join(build, "words.json")): - shutil.copy2(os.path.join(build, "words.json"), os.path.join(site, "words.json")) - for item in ("three.module.js", "jsm", "fonts", "assets"): + for item in ("three.module.js", "scene-kit.js", "jsm", "fonts", "assets"): src, dst = os.path.join(LIB, item), os.path.join(site, item) if os.path.isdir(src): shutil.copytree(src, dst, dirs_exist_ok=True) From cc7ee949bf845e4cb3c2340ce38a049958086c01 Mon Sep 17 00:00:00 2001 From: Apsides Labs Date: Thu, 5 Nov 2026 19:06:59 +0530 Subject: [PATCH 03/10] docs: scene-kit reference, including what it does not do --- docs/scene-kit.md | 133 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 docs/scene-kit.md diff --git a/docs/scene-kit.md b/docs/scene-kit.md new file mode 100644 index 0000000..b782c0d --- /dev/null +++ b/docs/scene-kit.md @@ -0,0 +1,133 @@ +# scene-kit — stages, cast, lights, HUD + +`kit/lib/scene-kit.js` is the reusable half of a film. Before 2.1 every film +re-invented the renderer, the lights, the cast, the camera path and the HUD +inside its own `scene.js`; `templates/scene.js` was 1,100 lines of exactly that, +wired to one shop set. This module is that work, extracted and parameterised. + +A film's `scene.js` becomes a description of its sets instead of an engine. + +```js +import * as K from './scene-kit.js'; + +const app = K.createApp({ w: 1080, h: 1920, exposure: 1.22, shadows: true }); +const rig = await K.loadRig('./assets/readyplayer.me.glb'); +const envelope = await fetch('./envelope.json').then(r => r.json()); + +const stages = K.createStages(app.scene, [ + { key: 'office', t0: -1, t1: T.s3, build: office }, + { key: 'plain', t0: T.s3, t1: T.s7, build: plain } +]); + +const hud = K.makeHud({ film: FILM, lines: LINES, safe: K.SAFE }); +K.run(app, { fps: FPS, dur: DUR, hud, update: t => stages.update(t) }); +``` + +## Stages + +`createStages(scene, defs)` takes a list of `{ key, t0, t1, build }`. `build(group)` +adds meshes to that stage's group and returns `{ camera(u), update(t, u) }`. + +- Only one stage is visible at a time, so a film can cut between locations. +- `t0`/`t1` are seconds, normally beat times from `timeline.js` (`T.s3`), so the + cut follows the measured speech instead of a hand-typed number. +- `camera(u)` gets the stage's local progress 0..1, eased; `update(t, u)` gets + absolute time. +- Cuts are hard. There is no built-in cross-fade; a fade belongs in the HUD. +- Lights inside a stage's group are only active while that stage is visible. + +## Cast + +```js +const rig = await K.loadRig('./assets/readyplayer.me.glb'); // 67 bones, RPM sample +const clerk = K.makeHuman(rig, { + height: 1.70, top: 0x35507a, bottom: 0x1e2434, skin: 0x9a7150, + hide: ['Wolf3D_Headwear', 'Wolf3D_Beard'] +}); +clerk.root.position.set(0.75, 0, -3.9); +group.add(clerk.root); + +K.poseHuman(clerk, K.POSE.write); // bone quaternions, blended from rest +K.speak(clerk, K.mouthAt(envelope, t)); // mouth from the narration envelope +``` + +- `makeHuman` clones the rig, converts PBR materials to Lambert, recolours + outfit/skin/hair, scales to a height in metres, drops the feet to y=0 and adds + a contact shadow. +- `POSE` ships `idle, talk, present, pointUp, listen, write, sad, happy`. They are + static blends from the rest pose — no walk cycle, no IK. +- `mouthAt(envelope, t)` reads the RMS envelope `voice.py` already writes, so lip + movement matches the narration with no extra pass. +- `speaking(lines, id, t)` says whether a line is being spoken, which is how a + stage decides who moves their mouth. + +## Lights + +`K.threePoint(group, opts)` builds key/fill/rim plus ambient and an optional +practical point light. Only the key casts shadows. + +```js +K.threePoint(group, { + keyColor: 0xffc98a, keyIntensity: 3.4, keyPos: [3.6, 3.6, 2.2], shadowMap: 512, + fillColor: 0x7d9ac6, fillIntensity: 2.1, + ambientColor: 0x8fa2bd, ambient: 2.3, + practical: { color: 0xffcf94, intensity: 16, distance: 10, pos: [0.6, 2.9, -2.2] } +}); +``` + +Shadow maps are the expensive part on a CPU rasteriser: 512 is enough at 720p, and +`shadows: false` plus the contact shadow is the cheap option that still reads. + +## Geometry helpers + +`mat`, `flat`, `plane`, `box`, `cyl`, `canvasTex`, `gradientTex`, `softDot`, +`strip` (a height profile over x, triangulated by hand because `ShapeGeometry` +drops vertices on these profiles), `ridgePts`, `snowLine`, `peakGroup`, +`contactShadow`. + +## HUD + +`makeHud({ film, lines, safe })` draws the title card, steps panel, proof card, +end card, burned-in captions and the vignette inside the platform safe area. +Timing comes from `times: { stepsIn, stepsOut, stepBeats, proofIn, proofOut }`. +Cards sit in the left column (`column: {x, w}`) so they do not cover the subject. + +## What this does not do + +- No walk cycles, no IK, no facial animation beyond `mouthOpen`/`mouthSmile`. +- One rig, recoloured per character. Distinct faces need distinct GLBs. +- Hard cuts only; no transitions, wipes or dissolves. +- No automatic framing: you place the camera and the props yourself, per stage. + +That is the honest boundary. A walking crowd is not something this kit will give +you. + +## Motion, shots and life + +A locked-off camera on a still set reads as a slideshow. Three additions fix that. + +**Shots.** `K.shotPicker([{ t0, t1, cam(u, t) }])` returns `pick(t)`: it selects the +active camera setup and runs its move. A stage can cut several times — wide to +close-up — without becoming a new stage. + +```js +const pick = K.shotPicker([ + { t0: -1, t1: T.s2, cam(u, t) { /* wide, walking in */ } }, + { t0: T.s2, t1: 999, cam(u, t) { /* close-up */ } } +]); +return { camera(u, t) { pick(t); }, update(t) { /* ... */ } }; +``` + +**A moving cast.** The rig has no animation clips, so `K.walkCycle(h, t, opts)` +drives the legs and arms procedurally, and `K.headLook(h, yaw, pitch)` turns the +head. Keep character position a pure function of `t` +(`root.position.x = K.lerp(a, b, K.smooth(K.seg(t, t0, t1)))`) so a resumed render +matches an uninterrupted one. + +**Life in the frame.** `K.motes()` for dust or far clouds, `K.snowfall()` for snow, +`K.handheld(t, amp)` for a few tenths of a degree of camera drift, and +`K.windowOpening()` to cut a real hole in a wall so the same mountain can be seen +outside every interior — which is what makes five locations feel like one world. + +All of it is deterministic: no `Math.random`, no `Date`, no state carried between +frames. From a5eea60c79648d9547029e9927ce957f434de4af Mon Sep 17 00:00:00 2001 From: Apsides Labs Date: Thu, 5 Nov 2026 19:07:02 +0530 Subject: [PATCH 04/10] docs: drop the no-scene-code claim, document scene-kit --- README.md | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index faf29d0..bc5582a 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,38 @@ Captions are on by default and follow the voice word by word: the word being spo { "captions": true, "captionAccent": "#ffd45e" } ``` +## Scenes, cast and lights + +A film can cut between locations. `kit/lib/scene-kit.js` provides the pieces a +`scene.js` used to re-invent: a stage manager, a poseable cast, a lighting rig, +set geometry helpers and the HUD. + +```js +import * as K from './scene-kit.js'; + +const app = K.createApp({ w: 1080, h: 1920, shadows: true }); +const rig = await K.loadRig('./assets/readyplayer.me.glb'); + +const stages = K.createStages(app.scene, [ + { key: 'office', t0: -1, t1: T.s3, build: office }, // cut on a measured beat + { key: 'plain', t0: T.s3, t1: T.s7, build: plain } +]); + +const clerk = K.makeHuman(rig, { height: 1.70, top: 0x35507a, skin: 0x9a7150 }); +K.poseHuman(clerk, K.POSE.write); +K.speak(clerk, K.mouthAt(envelope, t)); // mouth follows the narration envelope +``` + +Each stage owns a group, a camera path and optionally its own lights, so five +locations in one film is a list of five entries rather than five engines. Inside a +stage, `shotPicker` cuts between camera setups (wide, close-up, low angle), and +`walkCycle`, `headLook`, `motes`, `snowfall` and `handheld` keep the frame moving. Full +reference in [`docs/scene-kit.md`](docs/scene-kit.md). + +What it deliberately does not do: no walk cycles, no IK, no facial animation +beyond the mouth, hard cuts only (no dissolves), and one rig recoloured per +character. + ## Quality checks `qa.py` decodes the finished MP4 at low resolution and reports black frames, blown frames, still runs, hard pops and loudness. It exits non-zero on failure, so CI can gate on it. @@ -134,10 +166,10 @@ integrated loudness -14.2 LUFS · true peak -1.6 dBTP ``` kit/ voice, music, mix, render, encode, qa, doctor, build, make -kit/lib/ three.js, loaders, OutlineEffect, Devanagari font, rigged avatar -films/ one directory per film: film.json and scene.js +kit/lib/ three.js, loaders, scene-kit, OutlineEffect, Devanagari font, rigged avatar +films/ one directory per film: film.json and scene.js (built on scene-kit) templates/ starter film.json, scene.js and index.html -docs/ format reference, styles, safe areas, speed, portability, qa +docs/ format reference, scene-kit, styles, safe areas, speed, portability, qa assets/ logo and banner ``` From f3e5d5cb1bc75dc83e32e51c922607550a4f0041 Mon Sep 17 00:00:00 2001 From: Apsides Labs Date: Thu, 5 Nov 2026 19:07:06 +0530 Subject: [PATCH 05/10] docs: how to build a film with more than one set --- START-HERE.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/START-HERE.md b/START-HERE.md index f8f55bc..60ec251 100644 --- a/START-HERE.md +++ b/START-HERE.md @@ -59,6 +59,14 @@ One sentence per line works best: each line becomes one spoken clip, one caption - **Slow.** Expected without a GPU. Try `--draft` first. - **Anything else.** Run `make doctor` for an environment report, or `make test` to check the pipeline on a three-line film. Both print what is broken. + +## More than one set + +`make.py` writes a single-set film. If your story moves between places, write the +stages yourself with `kit/lib/scene-kit.js` — each stage is a set, a camera path +and its own lights, cut on a measured beat. See +[`docs/scene-kit.md`](docs/scene-kit.md). + ## Going further The file `make.py` writes is ordinary JSON: lines, colours, music cues, captions, safe areas. Edit it and rebuild: From d69b9b12162d9bd15f4258278206a22c14e44b9a Mon Sep 17 00:00:00 2001 From: Apsides Labs Date: Thu, 5 Nov 2026 19:07:09 +0530 Subject: [PATCH 06/10] chore: changelog for 2.1.0 and 2.2.0 From 55b91f03cdcc380bdc886195261360bf118e43a1 Mon Sep 17 00:00:00 2001 From: Apsides Labs Date: Thu, 5 Nov 2026 19:07:12 +0530 Subject: [PATCH 07/10] =?UTF-8?q?feat(films):=20The=20Mountain=20Nobody=20?= =?UTF-8?q?Saw=20=E2=80=94=2036s=20cut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- films/everest/film.json | 194 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 films/everest/film.json diff --git a/films/everest/film.json b/films/everest/film.json new file mode 100644 index 0000000..293818b --- /dev/null +++ b/films/everest/film.json @@ -0,0 +1,194 @@ +{ + "schema": 1, + "slug": "the-mountain-nobody-saw", + "title": "The Mountain Nobody Saw", + "fps": 20, + "size": [ + 720, + 1280 + ], + "style": "real", + "safeArea": "all", + "captions": true, + "captionSize": 38, + "grade": { + "exposure": 1.12, + "lift": [ + 22, + 16, + 26 + ], + "vignette": 0.34 + }, + "voice": { + "model": "en_US-lessac-medium", + "length_scale": 1.0, + "pitch": 0.98, + "gain": 0.86 + }, + "lead": 0.9, + "gap": 0.32, + "tail": 1.0, + "lines": [ + { + "id": "l1", + "text": "In eighteen fifty-two, a clerk in Calcutta finished the sums that found the tallest mountain on Earth." + }, + { + "id": "l2", + "text": "He never saw it." + }, + { + "id": "l3", + "text": "The peak stood a hundred and eighty kilometres away, behind a closed border." + }, + { + "id": "l4", + "text": "So they measured it without going there. With triangles." + }, + { + "id": "l5", + "text": "Six observations, from plains barely sixty metres up. The air bent the light by six minutes of arc. The mountain was less than one." + }, + { + "id": "l6", + "text": "Radhanath Sikdar took the mean. Twenty-nine thousand and two feet." + }, + { + "id": "l7", + "text": "Waugh announced it in eighteen fifty-six. They named it Everest, after a man who never saw it." + }, + { + "id": "l8", + "text": "It already had names. Chomolungma. Sagarmatha." + } + ], + "beats": { + "s2": "l2", + "s3": "l3", + "s4": "l4", + "s5": "l5", + "s6": "l6", + "s7": "l7", + "s8": "l8" + }, + "graphics": { + "title": { + "heading": "THE MOUNTAIN NOBODY SAW", + "sub": "Calcutta · 1852", + "accent": "#e8b64c" + }, + "steps": [ + { + "n": "1", + "label": "TRIANGULATE", + "color": "#cfd8e3" + }, + { + "n": "2", + "label": "READ THE ANGLE", + "color": "#cfd8e3" + }, + { + "n": "3", + "label": "CORRECT FOR AIR", + "color": "#cfd8e3" + }, + { + "n": "4", + "label": "SIX OBSERVATIONS", + "color": "#cfd8e3" + }, + { + "n": "5", + "label": "28,990 – 29,026 FT", + "color": "#e8b64c" + }, + { + "n": "6", + "label": "TAKE THE MEAN", + "color": "#e8b64c" + } + ], + "proof": { + "stars": 0, + "lines": [ + "29,002 FT", + "mean of six observations" + ], + "foot": "8,840 m · 1852", + "accent": "#e8b64c" + }, + "end": { + "line1": "CHOMOLUNGMA", + "line2": "SAGARMATHA", + "foot": "named Everest, 1865", + "accent": "#e8b64c" + } + }, + "music": { + "bed_gain": 0.34, + "cues": [ + { + "at": "l1", + "inst": "pad", + "note": "C3", + "dur": 10 + }, + { + "at": "l1", + "inst": "pluck", + "every": 1.1, + "count": 7, + "notes": [ + "C4", + "E4", + "G4", + "B4", + "G4", + "E4" + ] + }, + { + "at": "l4", + "inst": "pad", + "note": "A2", + "dur": 9 + }, + { + "at": "l5", + "inst": "pad", + "note": "F2", + "dur": 8 + }, + { + "at": "l6", + "inst": "bell", + "offset": 0.1, + "note": "C5" + }, + { + "at": "l6", + "inst": "coin", + "offset": 0.55 + }, + { + "at": "l7", + "inst": "pad", + "note": "G2", + "dur": 8 + }, + { + "at": "l8", + "inst": "bell", + "offset": 0.2, + "note": "C4" + } + ] + }, + "audio": { + "target_lufs": -14, + "ceiling_dbtp": -1.5, + "duck_db": -3.5 + } +} \ No newline at end of file From 7da3e764f061af131af3899c6638e2acaef09f5a Mon Sep 17 00:00:00 2001 From: Apsides Labs Date: Thu, 5 Nov 2026 19:07:15 +0530 Subject: [PATCH 08/10] feat(films): five locations, eight shots, moving cast --- films/everest/scene.js | 441 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 441 insertions(+) create mode 100644 films/everest/scene.js diff --git a/films/everest/scene.js b/films/everest/scene.js new file mode 100644 index 0000000..824ccfd --- /dev/null +++ b/films/everest/scene.js @@ -0,0 +1,441 @@ +import * as THREE from 'three'; +import { FPS, DUR, T, LINES } from './timeline.js'; +import { FILM } from './film.js'; +import * as K from './scene-kit.js'; + +// ===================================================================== +// The Mountain Nobody Saw — five locations, eight shots, a moving cast +// Peak XV, 1852. Every cut derives from T (measured speech). +// ===================================================================== +const Q = new URLSearchParams(location.search); +const app = K.createApp({ + w: parseInt(Q.get('w') || '1080', 10), + h: parseInt(Q.get('h') || '1920', 10), + exposure: 1.22, shadows: true +}); +const { scene, camera } = app; + +const rig = await K.loadRig('./assets/readyplayer.me.glb'); +const envelope = await fetch('./envelope.json').then(r => r.json()).catch(() => null); + +const CLERK = { height: 1.70, top: 0x35507a, bottom: 0x1e2434, skin: 0x9a7150, hair: 0x1a1410, + hide: ['Wolf3D_Headwear', 'Wolf3D_Beard'] }; +const SURVEYOR = { height: 1.76, top: 0x38465c, bottom: 0x252c3a, skin: 0x9a7150, hair: 0x1a1410, + hide: ['Wolf3D_Headwear', 'Wolf3D_Beard'] }; +const OFFICIAL_A = { height: 1.74, top: 0x453a56, bottom: 0x272733, skin: 0xbe9773 }; +const OFFICIAL_B = { height: 1.72, top: 0x2b3849, bottom: 0x22242e, skin: 0xc4a07c, hide: ['Wolf3D_Beard'] }; + +const PEAK = [ + [-3.2, -26], [-2.0, -16], [-1.0, -10.5], [-0.1, -5.6], [0.8, -1.2], + [1.7, 3.0], [2.5, 6.4], [3.3, 9.0], [4.1, 10.6], [4.9, 11.2], + [5.6, 10.3], [6.3, 8.9], [7.1, 7.2], [7.9, 5.4], + [8.7, 6.2], [9.5, 4.0], [10.4, 1.4], [11.4, -2.4], [12.6, -8.0], [13.8, -15], [14.8, -26] +]; +const DUSK = [[0, '#060c16'], [0.32, '#0f2036'], [0.58, '#25415e'], [0.84, '#7d5334'], [1, '#c9873f']]; + +function addHair(human, colour = 0x1b1512) { + const head = human.bones.Head; + if (!head) return; + const hairMat = K.mat(colour); + const cap = new THREE.Mesh(new THREE.SphereGeometry(0.122, 24, 18, 0, Math.PI * 2, 0, Math.PI * 0.56), hairMat); + cap.position.set(0, 0.104, -0.030); cap.scale.set(1.03, 1.05, 1.1); + cap.castShadow = true; head.add(cap); + const back = new THREE.Mesh(new THREE.SphereGeometry(0.072, 16, 12), hairMat); + back.position.set(0, 0.056, -0.078); back.scale.set(1.12, 1.3, 1.0); + head.add(back); +} +function legs(h) { + K.boneRot(h, 'LeftUpLeg'); K.boneRot(h, 'RightUpLeg'); + K.boneRot(h, 'LeftLeg'); K.boneRot(h, 'RightLeg'); +} +function shake(t, amp = 0.005) { + const h = K.handheld(t, amp); + camera.position.x += h.x; + camera.position.y += h.y; + camera.rotation.z += h.roll; +} +function outsidePeak(group, z, scale, x) { + K.plane(300, 200, new THREE.MeshBasicMaterial({ map: K.gradientTex(DUSK) }), 0, 8, z - 40, group); + const p = K.peakGroup(PEAK, { scale, z: z - 20, lit: 0x9fb3c9, shadow: 0x64788f, snow: 0xd8e6f5 }); + p.position.x = x; + group.add(p); + return p; +} + +// ===================================================================== +// 1 · the Calcutta office — he walks in, then a close-up +// ===================================================================== +function office(group) { + const L = K.threePoint(group, { + keyColor: 0xffc98a, keyIntensity: 3.6, keyPos: [3.6, 3.6, 2.2], shadowMap: 512, + fillColor: 0x7d9ac6, fillIntensity: 2.0, fillPos: [-3.4, 2.2, 2.4], + ambientColor: 0x8fa2bd, ambient: 2.2, + practical: { color: 0xffcf94, intensity: 16, distance: 10, pos: [0.6, 2.9, -2.2] } + }); + + const floor = K.plane(30, 24, K.mat(0x2a2118), 0, 0, 0, group); + floor.rotation.x = -Math.PI / 2; + floor.receiveShadow = true; + + K.windowOpening(group, { w: 1.9, h: 2.5, x: 2.9, y: 3.3, z: -7.4, wallMat: K.mat(0x23304a) }); + outsidePeak(group, -7.4, 0.5, 1.1); + + for (let i = 0; i < 3; i++) { + K.box(2.5, 0.08, 0.5, 0x2a1e14, -2.0, 1.55 + i * 0.66, -5.6, group); + for (let k = 0; k < 5; k++) { + K.box(0.17, 0.4, 0.32, [0x8a6a4a, 0x6d7f96, 0x9a7b52, 0x5d6b52, 0x7a5c46][k], -2.85 + k * 0.42, 1.78 + i * 0.66, -5.6, group); + } + } + + K.box(3.0, 0.1, 1.2, 0x6b4a2f, 0.55, 0.78, -3.2, group); + for (const dx of [-1.25, 1.25]) for (const dz of [-0.42, 0.42]) { + K.box(0.1, 0.78, 0.1, 0x53381f, 0.55 + dx, 0.39, -3.2 + dz, group); + } + K.box(0.8, 0.02, 0.55, 0xe8e0c8, 0.2, 0.84, -3.1, group); + K.box(0.55, 0.02, 0.4, 0x2f2a22, 1.15, 0.84, -3.05, group); + const bulb = new THREE.Mesh(new THREE.SphereGeometry(0.13, 12, 10), K.flat(0xffe6bd)); + bulb.position.set(0.6, 2.55, -2.3); group.add(bulb); + + const dust = K.motes(group, { count: 110, centre: [0.7, 2.2, -3.0], spread: [5, 3.4, 4], size: 0.02, opacity: 0.4 }); + + const clerk = K.makeHuman(rig, CLERK); + addHair(clerk); + clerk.root.position.set(3.2, 0, -3.9); + clerk.root.rotation.y = -0.32; + group.add(clerk.root); + + const WALK_A = 0.15, WALK_B = 2.4; + const pick = K.shotPicker([ + { t0: -1, t1: T.s2 ?? 5, cam(u, t) { + camera.position.set(K.lerp(2.0, 1.35, u), K.lerp(1.98, 1.86, u), K.lerp(6.0, 5.2, u)); + camera.lookAt(K.lerp(1.1, 0.9, u), K.lerp(1.55, 1.45, u), -3.4); + shake(t); + } }, + { t0: T.s2 ?? 5, t1: 999, cam(u, t) { + camera.position.set(K.lerp(1.3, 1.15, u), K.lerp(1.68, 1.63, u), K.lerp(-1.45, -1.2, u)); + camera.lookAt(0.78, 1.55, -3.9); + shake(t, 0.003); + } } + ]); + + return { + camera(u, t) { pick(t); }, + update(t) { + const walking = t > WALK_A && t < WALK_B; + clerk.root.position.x = K.lerp(3.2, 0.75, K.smooth(K.seg(t, WALK_A, WALK_B))); + if (walking) { + K.walkCycle(clerk, t, { speed: 1.05, amp: 0.5 }); + K.headLook(clerk, -0.25, 0.1); + } else { + K.poseHuman(clerk, K.POSE.write, 1); + legs(clerk); + const looking = t > (T.s2 ?? 5); + K.headLook(clerk, looking ? -0.5 : -0.15, looking ? -0.2 : 0.16); + } + const talking = K.speaking(LINES, 'l1', t) || K.speaking(LINES, 'l2', t); + K.speak(clerk, K.mouthAt(envelope, t) * (talking ? 1 : 0)); + L.practical.intensity = 16 * (1 + 0.035 * Math.sin(t * 7.3) + 0.02 * Math.sin(t * 2.1)); + dust.update(t); + } + }; +} + +// ===================================================================== +// 2 · the plains — the surveyor walks to the instrument +// ===================================================================== +function plain(group) { + K.threePoint(group, { + keyColor: 0xffb877, keyIntensity: 2.5, keyPos: [-6, 4.5, 6], + fillColor: 0x5f7fae, fillIntensity: 1.5, fillPos: [5, 3, 4], + ambientColor: 0x4f6076, ambient: 1.4 + }); + + K.plane(400, 260, new THREE.MeshBasicMaterial({ map: K.gradientTex(DUSK) }), 0, 14, -110, group); + const ground = K.plane(120, 70, K.mat(0x3a4a3c), 0, -0.02, -18, group); + ground.rotation.x = -Math.PI / 2; + ground.receiveShadow = true; + + for (const [seed, base, amp, z, col] of [[11, 3, 7.5, -74, 0x2b3f57], [23, 1.5, 6.0, -58, 0x21324a], [37, 0.5, 5.0, -44, 0x18263a]]) { + const m = K.strip(K.ridgePts(seed, -90, 90, base, amp, 24), col); + m.position.z = z; group.add(m); + } + const peak = K.peakGroup(PEAK, { scale: 0.9, z: -40 }); + peak.position.x = 2.5; group.add(peak); + + const tx = -0.1, tz = -2.6; + for (const [dx, dz, rz] of [[-0.32, -0.22, 0.2], [0.32, -0.22, -0.2], [0, 0.32, 0]]) { + const leg = K.cyl(0.028, 0.028, 0.95, 0x2a3240, tx + dx, 0.46, tz + dz, group); + leg.rotation.z = rz; leg.rotation.x = dz * 0.35; + } + K.box(0.24, 0.18, 0.24, 0x33404f, tx, 0.98, tz, group); + const barrel = K.cyl(0.05, 0.05, 0.6, 0x3d4a5a, tx + 0.1, 1.14, tz, group); + barrel.rotation.z = -Math.PI / 2.6; + + const surveyor = K.makeHuman(rig, SURVEYOR); + addHair(surveyor); + surveyor.root.position.set(-2.3, 0, -3.4); + surveyor.root.rotation.y = -0.18; + group.add(surveyor.root); + + for (const [x, z] of [[-2.0, -6.0], [3.0, -7.2]]) { + K.cyl(0.022, 0.022, 0.8, 0xd9c48a, x, 0.4, z, group); + } + const clouds = K.motes(group, { count: 26, centre: [2, 6, -34], spread: [40, 6, 10], size: 0.5, opacity: 0.05, colour: 0xc8d8ea, seed: 21 }); + + const WA = (T.s3 ?? 7) + 0.2, WB = (T.s3 ?? 7) + 2.4; + const pick = K.shotPicker([ + { t0: T.s3 ?? 7, t1: T.s4 ?? 11, cam(u, t) { + camera.position.set(K.lerp(1.7, 1.1, u), K.lerp(1.95, 1.82, u), K.lerp(7.2, 6.3, u)); + camera.lookAt(K.lerp(0.5, 0.35, u), K.lerp(1.75, 1.8, u), -11); + shake(t); + } }, + { t0: T.s4 ?? 11, t1: T.s5 ?? 14, cam(u, t) { + camera.position.set(K.lerp(-0.4, -0.15, u), K.lerp(0.7, 0.78, u), K.lerp(0.95, 0.6, u)); + camera.lookAt(K.lerp(1.0, 1.3, u), K.lerp(1.5, 1.62, u), -14); + shake(t, 0.004); + } }, + { t0: T.s5 ?? 14, t1: 999, cam(u, t) { + camera.position.set(K.lerp(2.5, 2.15, u), K.lerp(1.62, 1.54, u), K.lerp(1.6, 1.2, u)); + camera.lookAt(0.8, 1.45, -3.6); + shake(t, 0.004); + } } + ]); + + return { + camera(u, t) { pick(t); }, + update(t) { + const walking = t > WA && t < WB; + surveyor.root.position.x = K.lerp(-2.3, 0.85, K.smooth(K.seg(t, WA, WB))); + if (walking) { + K.walkCycle(surveyor, t, { speed: 1.1, amp: 0.52 }); + K.headLook(surveyor, 0.1, 0.05); + } else { + K.poseHuman(surveyor, t > WB ? K.POSE.pointUp : K.POSE.talk, 1); + legs(surveyor); + K.headLook(surveyor, t > WB ? -0.2 : 0.15, t > WB ? -0.22 : 0); + } + const talking = K.speaking(LINES, 'l5', t); + K.speak(surveyor, K.mouthAt(envelope, t) * (talking ? 1 : 0)); + clouds.update(t); + } + }; +} + +// ===================================================================== +// 3 · the summit — snow, arcs, a push into the snow line +// ===================================================================== +function summit(group) { + K.threePoint(group, { + keyColor: 0xffc48a, keyIntensity: 3.0, keyPos: [-8, 6, 5], + fillColor: 0x6d8dbb, fillIntensity: 1.4, fillPos: [6, 4, 3], + ambientColor: 0x54687f, ambient: 1.5, shadows: false + }); + + K.plane(400, 260, new THREE.MeshBasicMaterial({ + map: K.gradientTex([[0, '#070d18'], [0.3, '#12253d'], [0.62, '#2c4a6b'], [0.86, '#b5763f'], [1, '#e0a15c']]) + }), 0, 10, -110, group); + + const peak = K.peakGroup(PEAK, { scale: 0.92, z: -16, lit: 0xd8e1ec, shadow: 0x93a8c2 }); + peak.position.x = -2.1; group.add(peak); + + const arcTex = K.canvasTex(720, 720, (g, w, h) => { + g.clearRect(0, 0, w, h); + for (let i = 0; i < 3; i++) { + g.beginPath(); + g.arc(w / 2, h * 1.02, 170 + i * 58, Math.PI * 1.14, Math.PI * 1.86); + g.strokeStyle = `rgba(255,196,110,${0.5 - i * 0.13})`; + g.lineWidth = 5 - i; + g.stroke(); + } + }); + const arcs = K.plane(12, 12, new THREE.MeshBasicMaterial({ map: arcTex, transparent: true, depthWrite: false }), -2.1, 4.4, -10, group); + K.plane(26, 10, new THREE.MeshBasicMaterial({ map: K.softDot('#ffd8a0', 0.28), transparent: true, depthWrite: false }), -1.0, 5.0, -13, group); + const snow = K.snowfall(group, { count: 220, centre: [-1, 6, -9], area: [22, 14, 10], size: 0.045, speed: 0.85 }); + + const cut = (T.s6 ?? 20) + 2.2; + const pick = K.shotPicker([ + { t0: T.s6 ?? 20, t1: cut, cam(u, t) { + camera.position.set(K.lerp(-0.8, 0.1, u), K.lerp(4.9, 5.5, u), K.lerp(20.5, 17.5, u)); + camera.lookAt(K.lerp(-0.7, -0.1, u), K.lerp(6.6, 7.1, u), -16); + shake(t, 0.004); + } }, + { t0: cut, t1: 999, cam(u, t) { + camera.position.set(K.lerp(-1.5, -0.4, u), K.lerp(7.2, 8.1, u), K.lerp(11.0, 8.2, u)); + camera.lookAt(K.lerp(-2.0, -1.4, u), K.lerp(8.6, 9.2, u), -16); + shake(t, 0.0035); + } } + ]); + + return { + camera(u, t) { pick(t); }, + update(t) { + arcs.material.opacity = 0.55 + 0.45 * Math.sin(t * 1.2); + snow.update(t); + } + }; +} + +// ===================================================================== +// 4 · the map room — two men, a table, the same mountain outside +// ===================================================================== +function mapRoom(group) { + const L = K.threePoint(group, { + keyColor: 0xffcf9a, keyIntensity: 2.9, keyPos: [2.8, 4.0, 2.6], shadowMap: 512, + fillColor: 0x7f8fc4, fillIntensity: 1.2, fillPos: [-3.6, 2.4, 2.0], + ambientColor: 0x6a6480, ambient: 1.5, + practical: { color: 0xffc98a, intensity: 12, distance: 9, pos: [0.8, 2.6, -2.4] } + }); + + const floor = K.plane(30, 24, K.mat(0x1d1a24), 0, 0, 0, group); + floor.rotation.x = -Math.PI / 2; + floor.receiveShadow = true; + + K.windowOpening(group, { w: 1.6, h: 2.9, x: 3.4, y: 3.6, z: -7.4, wallMat: K.mat(0x2c2437) }); + outsidePeak(group, -7.4, 0.5, 2.6); + + const mapTex = K.canvasTex(512, 320, (g, w, h) => { + g.fillStyle = '#e8e0cc'; g.fillRect(0, 0, w, h); + g.strokeStyle = 'rgba(60,70,90,0.3)'; g.lineWidth = 1; + for (let x = 0; x < w; x += 32) { g.beginPath(); g.moveTo(x, 0); g.lineTo(x, h); g.stroke(); } + for (let y = 0; y < h; y += 32) { g.beginPath(); g.moveTo(0, y); g.lineTo(w, y); g.stroke(); } + g.strokeStyle = 'rgba(120,90,60,0.5)'; g.lineWidth = 2; + for (let i = 0; i < 7; i++) { g.beginPath(); g.ellipse(300, 150, 40 + i * 26, 26 + i * 17, 0.2, 0, Math.PI * 2); g.stroke(); } + g.fillStyle = 'rgba(190,60,50,0.9)'; g.beginPath(); g.arc(300, 150, 6, 0, Math.PI * 2); g.fill(); + g.strokeStyle = 'rgba(190,60,50,0.8)'; g.lineWidth = 3; + g.beginPath(); g.moveTo(300, 150); g.lineTo(392, 96); g.stroke(); + g.fillStyle = 'rgba(40,45,60,0.75)'; g.font = 'bold 20px "DejaVu Sans", sans-serif'; + g.fillText('PEAK XV', 330, 84); + }); + + K.box(2.3, 0.1, 1.3, 0x5d4029, 0.55, 0.86, -3.0, group); + for (const [x, z] of [[-0.4, -3.5], [1.5, -3.5], [-0.4, -2.5], [1.5, -2.5]]) { + K.box(0.09, 0.86, 0.09, 0x4a321f, x, 0.43, z, group); + } + const mapPlane = K.plane(1.75, 1.05, new THREE.MeshLambertMaterial({ map: mapTex }), 0.55, 0.92, -3.0, group); + mapPlane.rotation.x = -Math.PI / 2; + mapPlane.receiveShadow = true; + + K.plane(2.2, 1.35, new THREE.MeshLambertMaterial({ map: mapTex }), 0.4, 4.3, -7.35, group); + K.box(2.4, 0.08, 0.08, 0x3a2f22, 0.4, 5.0, -7.35, group); + K.box(2.4, 0.08, 0.08, 0x3a2f22, 0.4, 3.6, -7.35, group); + + const waugh = K.makeHuman(rig, OFFICIAL_A); + waugh.root.position.set(-1.4, 0, -3.95); + waugh.root.rotation.y = 0.42; + group.add(waugh.root); + + const everest = K.makeHuman(rig, OFFICIAL_B); + everest.root.position.set(2.5, 0, -3.95); + everest.root.rotation.y = -0.42; + group.add(everest.root); + + const WA = (T.s7 ?? 24) + 0.2, WB = (T.s7 ?? 24) + 2.0; + const cut = (T.s7 ?? 24) + 2.6; + const pick = K.shotPicker([ + { t0: T.s7 ?? 24, t1: cut, cam(u, t) { + camera.position.set(K.lerp(1.5, 0.95, u), K.lerp(2.05, 1.9, u), K.lerp(6.4, 5.7, u)); + camera.lookAt(K.lerp(0.7, 0.6, u), K.lerp(1.55, 1.5, u), -3.3); + shake(t); + } }, + { t0: cut, t1: 999, cam(u, t) { + camera.position.set(K.lerp(1.35, 0.85, u), K.lerp(1.62, 1.58, u), K.lerp(1.7, 1.25, u)); + camera.lookAt(K.lerp(0.7, 0.62, u), K.lerp(1.45, 1.42, u), -3.6); + shake(t, 0.0035); + } } + ]); + + return { + camera(u, t) { pick(t); }, + update(t) { + const walking = t > WA && t < WB; + waugh.root.position.x = K.lerp(-1.4, -0.25, K.smooth(K.seg(t, WA, WB))); + everest.root.position.x = K.lerp(2.5, 1.45, K.smooth(K.seg(t, WA, WB))); + if (walking) { + K.walkCycle(waugh, t, { speed: 1.0, amp: 0.45 }); + K.walkCycle(everest, t + 0.5, { speed: 1.0, amp: 0.45 }); + K.headLook(waugh, 0.2, 0); K.headLook(everest, -0.2, 0); + } else { + const waughTalking = K.speaking(LINES, 'l7', t); + K.poseHuman(waugh, waughTalking ? K.POSE.present : K.POSE.talk, 1); + K.poseHuman(everest, K.POSE.listen, 1); + legs(waugh); legs(everest); + K.headLook(waugh, -0.08, 0.04); + K.headLook(everest, 0.12, 0.04); + K.speak(waugh, K.mouthAt(envelope, t) * (waughTalking ? 1 : 0)); + K.speak(everest, 0); + } + L.practical.intensity = 12 * (1 + 0.04 * Math.sin(t * 6.1)); + } + }; +} + +// ===================================================================== +// 5 · finale — the mountain with its own names +// ===================================================================== +function finale(group) { + K.threePoint(group, { + keyColor: 0xffb877, keyIntensity: 2.6, keyPos: [-7, 4, 6], + fillColor: 0x5f7fae, fillIntensity: 1.3, fillPos: [5, 3, 4], + ambientColor: 0x4f6076, ambient: 1.4, shadows: false + }); + + K.plane(400, 260, new THREE.MeshBasicMaterial({ map: K.gradientTex(DUSK) }), 0, 14, -110, group); + const sun = new THREE.Mesh(new THREE.CircleGeometry(2.4, 40), K.flat(0xf6c078)); + sun.position.set(-12, 8.6, -100); group.add(sun); + K.plane(14, 14, new THREE.MeshBasicMaterial({ map: K.softDot('#f0b96b', 0.35), transparent: true, depthWrite: false }), -12, 8.6, -99.4, group); + + for (const [seed, base, amp, z, col] of [[11, 3, 7.5, -74, 0x2b3f57], [23, 1.5, 6.0, -58, 0x21324a]]) { + const m = K.strip(K.ridgePts(seed, -90, 90, base, amp, 26), col); + m.position.z = z; group.add(m); + } + const peak = K.peakGroup(PEAK, { scale: 1.0, z: -22 }); + peak.position.x = 1.5; group.add(peak); + const near = K.strip(K.ridgePts(51, -90, 90, -3.0, 4.2, 18), 0x0d1725); + near.position.z = -8; group.add(near); + const clouds = K.motes(group, { count: 30, centre: [0, 7, -40], spread: [46, 6, 12], size: 0.6, opacity: 0.05, colour: 0xc8d8ea, seed: 33 }); + + const pick = K.shotPicker([ + { t0: T.s8 ?? 29, t1: 999, cam(u, t) { + camera.position.set(K.lerp(-0.6, 1.1, u), K.lerp(2.7, 3.4, u), K.lerp(17.5, 13.5, u)); + camera.lookAt(K.lerp(1.4, 2.1, u), K.lerp(5.4, 6.1, u), -22); + shake(t, 0.004); + } } + ]); + + return { + camera(u, t) { pick(t); }, + update(t) { clouds.update(t); } + }; +} + +// ===================================================================== +// cut list +// ===================================================================== +const stages = K.createStages(scene, [ + { key: 'office', t0: -1, t1: T.s3 ?? 7, build: office }, + { key: 'plain', t0: T.s3 ?? 7, t1: T.s6 ?? 20, build: plain }, + { key: 'summit', t0: T.s6 ?? 20, t1: T.s7 ?? 24, build: summit }, + { key: 'mapRoom', t0: T.s7 ?? 24, t1: T.s8 ?? 29, build: mapRoom }, + { key: 'final', t0: T.s8 ?? 29, t1: DUR + 1, build: finale } +]); + +const hud = K.makeHud({ + film: FILM, + lines: LINES, + safe: K.SAFE, + debugSafe: Q.get('safe') === '1', + times: { + stepsIn: (T.s4 ?? 11) + 0.1, + stepsOut: T.s6 ?? 20, + stepBeats: [T.s4 ?? 11, T.s5 ?? 14, (T.s5 ?? 14) + 1.4], + proofIn: T.s6 ?? 20, + proofOut: T.s7 ?? 24 + } +}); + +K.run(app, { + fps: FPS, + dur: DUR, + hud, + update(t) { stages.update(t); } +}); From 52aa142d1b8c351426560c18bcfc618bb4d6b00b Mon Sep 17 00:00:00 2001 From: Apsides Labs Date: Thu, 5 Nov 2026 19:37:19 +0530 Subject: [PATCH 09/10] docs: architecture now shows stages, shots and scene-kit --- docs/architecture.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/docs/architecture.md b/docs/architecture.md index fd14f6f..ffee18c 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -9,7 +9,7 @@ kit/build.py ──► build//site/ timeline.js generated: FPS, DUR, T{}, LINES{} film.js generated: the whole film.json as FILM envelope.json generated - three.module.js, jsm/, fonts/, assets/ from kit/lib/ + three.module.js, scene-kit.js, jsm/, fonts/, assets/ from kit/lib/ kit/render.js ──► build//frames/f00000.jpg … kit/encode.py ──► build//.mp4 @@ -29,19 +29,26 @@ timeline.js export const T = { s5: 29.15, ... } scene.js if (t < T.s5) return camLerp(...) ``` -## Layers in the scene +## Layers in a film -1. **Set**, static geometry, built once at load: shop, counter, shelves, street, houses -2. **Cast**, cloned skinned meshes, posed per frame through bones -3. **Camera**, keyed positions blended with easing -4. **HUD**, Canvas 2D drawn *after* the 3D pass, in screen space +1. **Stages**, one per location: a group of static geometry with its own lights and + its own camera path. Only one is visible at a time, so moving between locations + is a visibility change rather than a reload. Built with `kit/lib/scene-kit.js`. +2. **Shots**, inside a stage: `shotPicker` selects the active camera setup — wide, + close-up, low angle — and runs its move, so a location is not one locked-off + camera for its whole duration. +3. **Cast**, cloned skinned meshes from one GLB, posed per frame through bones, + walking with `walkCycle` and speaking with `mouthAt` off `envelope.json`. +4. **Life**, dust motes, snow, drifting far clouds and a few tenths of a degree of + handheld camera drift, so no frame reads as a still. +5. **HUD**, Canvas 2D drawn *after* the 3D pass, in screen space. The HUD lives in 2D deliberately. 3D text under a 9:16 perspective gets cropped by tight framing and shears at the edges; a 2D pass is always crisp, always correctly placed, and free to render. ## Per-frame pipeline ``` -update(t) pose bones, place props, move camera +stages.update(t) pick the stage and the shot, pose bones, move camera renderer.render() 3D pass (WebGL) drawHUD(t, ctx2d) 2D pass, cards, captions, progress bar vignette + fade Canvas 2D gradient, cheap From 3bea08965d7569f5a9994a7002cb560281e4a472 Mon Sep 17 00:00:00 2001 From: Apsides Labs Date: Thu, 5 Nov 2026 19:37:22 +0530 Subject: [PATCH 10/10] ci: parse scene files as ESM and assert build.py ships scene-kit --- .github/workflows/ci.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index defa2ac..6871fd7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,17 @@ jobs: - name: Python syntax run: python -m py_compile kit/*.py - name: JavaScript syntax - run: node --check kit/render.js + run: | + node --check kit/render.js + # scene files are ES modules; parse them as .mjs so --check does not + # treat `import` as a CommonJS syntax error + for f in $(ls kit/lib/*.js films/*/scene.js templates/scene.js 2>/dev/null); do + cp "$f" /tmp/check.mjs + node --check /tmp/check.mjs + echo "ok $f" + done + - name: build.py ships scene-kit.js + run: grep -q "scene-kit.js" kit/build.py - name: film.json files parse run: | python - <<'PY'