3D engine that AI agents drive
Add CRITICAL procedural film scenes and deterministic timeline
Nguyen Xuan Anf686733a5640
diff --git a/docs/film-storyboard.md b/docs/film-storyboard.mdnew file mode 100644index 00000000..90f1a7ff--- /dev/null+++ b/docs/film-storyboard.md@@ -0,0 +1,88 @@+# CRITICAL++`CRITICAL` is an original 32-second short rendered from procedural 3D geometry in 67.js.+The film moves from intimate scientific detail through an ignition to an empty, scorched landscape.+Its visual motifs include machined metal, intersecting atomic orbits, interference waves, an isolated tower, fire, and smoke.+The film contains no copied footage, dialogue, music, logos, or claims of official affiliation.++## Timeline++| Seconds | Set | Image and camera | Grade |+| --- | --- | --- | --- |+| 0 to 5 | `apparatus` | A close view of the optical aperture withdraws to reveal the pressure chamber, fasteners, copper pipes, and ceramic feedthroughs. | Cool metal with one amber filament. |+| 5 to 10 | `atom` | The camera arcs around a clustered nucleus inside five luminous, intersecting orbital rings. | Blue light in a dark field. |+| 10 to 13.5 | `waves` | A lateral dolly crosses a physical interference chamber with a suspended wave trace and calibrated grid. | Full monochrome. |+| 13.5 to 17 | `desert` | A wide camera approaches a skeletal test tower below a dusk horizon. | Restrained warm earth. |+| 17 to 19 | `desert` | A hard cut moves close to the suspended vessel. The camera advances and tightens its field of view. | Darker, partly monochrome. |+| 19 to 26 | `ignition` | A flash reveals an expanding incandescent core, boiling fire cells, a smoke crown, dust rings, and ejected embers. | Orange fire against a cool sky. |+| 26 to 32 | `aftermath` | The camera withdraws from collapsed struts, low embers, and drifting smoke. The title appears at 28 seconds. | Muted earth and black ash. |++The opening fades from black during the first 0.8 seconds.+The ending fades to black from 31 to 32 seconds.+The only text is `CRITICAL` and `A 67.js short`.+The title reaches full opacity at 29.2 seconds.++## Renderer contract++`FILM_DURATION` equals `32`.+`createFilmScenes()` returns six sets keyed by the names in the timeline.+Each set contains `parts`, `environment`, and `ground: false`.+The desert sets contain their own terrain and supply `shadowBounds`.++Each part uses the existing renderer shape `{ name, geometry, matrix, material }`.+Repeated details share geometry objects for instancing.+Matrices use `gl-matrix` column-major transforms.+Materials contain `tag`, `color`, `metallic`, `roughness`, and `emission`.+The ignition includes the `fire`, `smoke`, and `particle` tags for procedural shader animation.++The environment contains linear `fogColor`, `fogDensity`, display-space `skyTop` and `skyBottom`, `lightDirection`, and `daylight`.+The shadow bounds contain `extent`, `target`, `eye`, `near`, and `far`.++`sampleFilm(time)` accepts a finite number in seconds and clamps it to `[0, 32]`.+Invalid values throw a `TypeError`.+The return value contains these fields:++| Field | Meaning |+| --- | --- |+| `scene` | The set key. |+| `camera` | World-space `eye`, world-space `target`, and `fov` in degrees. |+| `time` | Clamped absolute film time. |+| `sceneTime` | Seconds since the set first appeared. It continues across the desert camera cut. |+| `exposure` | Authored exposure, including the brief ignition lift. |+| `monochrome` | Grade blend from zero for color to one for monochrome. |+| `fade` | Black-overlay opacity. Zero is visible. One is black. |+| `flash` | White-overlay opacity. It peaks at 19 seconds and decays exponentially. |+| `explosionProgress` | An eased zero-to-one ignition expansion. The aftermath holds one. |+| `title`, `subtitle` | Empty strings before 28 seconds, then the final title. |+| `titleOpacity` | Title opacity including its fade and the terminal black. |++The ignition geometry describes its final size.+Its core sits at `[0, 7, 0]` with radius approximately seven units.+Fire cells surround the core, and the smoke crown reaches approximately 24 units high.++The renderer expands ignition positions around the world origin using `explosionProgress`.+Scaling only individual mesh radii leaves separated cells at the beginning of ignition.+Terrain keeps its authored position and scale.+The aftermath smoke uses full expansion and its own local `sceneTime`.++The renderer can use `time` for continuous noise and `sceneTime` for shot-specific effects.+All scene construction and sampling are deterministic.+The source uses no random generator, clock, browser state, or mutable playback state.++## Measured scene budgets++Triangle counts include every instance, including repeated meshes.++| Set | Parts | Triangles |+| --- | ---: | ---: |+| `apparatus` | 280 | 46,316 |+| `atom` | 159 | 116,640 |+| `waves` | 263 | 40,044 |+| `desert` | 264 | 41,620 |+| `ignition` | 612 | 332,316 |+| `aftermath` | 313 | 100,284 |++`node --test tests/film.test.js` passed four tests.+The tests check exact cuts, deterministic samples, finite cameras, camera continuity within shots, material contracts, and scene budgets.+The tests sample the full timeline at 60 frames per second.+The parent renderer integration owns rendered-frame inspection, the final color grade, and audiovisual export.diff --git a/src/film.js b/src/film.jsnew file mode 100644index 00000000..36335c51--- /dev/null+++ b/src/film.js@@ -0,0 +1,317 @@+import { mat4, quat, vec3 } from 'gl-matrix';+import { box, cylinder, sphere, torus } from './geometry.js';++export const FILM_DURATION = 32;+const FULL_TURN = Math.PI * 2;+const HALF_PI = Math.PI / 2;++const materials = {+ steel: { tag: 'steel', color: [0.35, 0.39, 0.42], metallic: 0.94, roughness: 0.25, emission: 0 },+ graphite: { tag: 'graphite', color: [0.035, 0.043, 0.05], metallic: 0.7, roughness: 0.34, emission: 0 },+ copper: { tag: 'copper', color: [0.63, 0.25, 0.08], metallic: 0.92, roughness: 0.28, emission: 0 },+ ceramic: { tag: 'armor', color: [0.78, 0.75, 0.65], metallic: 0.12, roughness: 0.38, emission: 0 },+ orbit: { tag: 'light', color: [0.63, 0.83, 1], metallic: 0.15, roughness: 0.24, emission: 5 },+ amber: { tag: 'indicator', color: [1, 0.34, 0.035], metallic: 0.1, roughness: 0.3, emission: 4 },+ terrain: { tag: 'terrain', color: [0.38, 0.27, 0.17], metallic: 0, roughness: 0.94, emission: 0 },+ rock: { tag: 'terrain', color: [0.24, 0.19, 0.14], metallic: 0, roughness: 0.95, emission: 0 },+ ash: { tag: 'terrain', color: [0.055, 0.046, 0.042], metallic: 0, roughness: 0.96, emission: 0 },+ fire: { tag: 'fire', color: [1, 0.24, 0.012], metallic: 0, roughness: 0.7, emission: 8 },+ core: { tag: 'fire', color: [1, 0.75, 0.26], metallic: 0, roughness: 0.5, emission: 18 },+ smoke: { tag: 'smoke', color: [0.2, 0.14, 0.1], metallic: 0, roughness: 1, emission: 0.04 },+ particle: { tag: 'particle', color: [1, 0.37, 0.035], metallic: 0, roughness: 0.65, emission: 6 },+};++function createBuilder(meshes) {+ const parts = [];+ function add(name, mesh, position, scale, material, rotation = [0, 0, 0]) {+ const orientation = quat.fromEuler(quat.create(), ...rotation.map(angle => angle * 180 / Math.PI));+ const matrix = mat4.fromRotationTranslationScale(mat4.create(), orientation, position, scale);+ parts.push({ name, geometry: meshes[mesh], matrix, material: materials[material] });+ }+ function beam(name, start, end, radius, material = 'steel') {+ const difference = vec3.subtract(vec3.create(), end, start);+ const length = vec3.length(difference);+ const direction = vec3.scale(vec3.create(), difference, 1 / length);+ const orientation = quat.rotationTo(quat.create(), [0, 1, 0], direction);+ const center = start.map((value, axis) => (value + end[axis]) / 2);+ parts.push({+ name,+ geometry: meshes.cylinder,+ matrix: mat4.fromRotationTranslationScale(mat4.create(), orientation, center, [radius, length, radius]),+ material: materials[material],+ });+ }+ return { parts, add, beam };+}++function createApparatus(meshes) {+ const builder = createBuilder(meshes);+ const { add, beam } = builder;+ add('Optical bench', 'box', [0, -0.55, 0], [7, 0.22, 4.5], 'graphite');+ add('Pressure chamber', 'cylinder', [0, 0.5, 0], [0.92, 2.5, 0.92], 'graphite', [HALF_PI, 0, 0]);+ for (let index = 0; index < 11; index++) {+ const depth = -1.2 + index * 0.24;+ add('Machined cooling collar', 'ring', [0, 0.5, depth], [1.02, 1.02, 0.6], index % 2 ? 'steel' : 'copper');+ for (let bolt = 0; bolt < 12; bolt++) {+ const angle = bolt / 12 * FULL_TURN;+ add('Hexagonal collar fastener', 'bolt', [Math.cos(angle) * 1.02, 0.5 + Math.sin(angle) * 1.02, depth + 0.055], [0.04, 0.09, 0.04], 'steel', [HALF_PI, 0, 0]);+ }+ }+ add('Front iris', 'cylinder', [0, 0.5, 1.3], [0.8, 0.05, 0.8], 'steel', [HALF_PI, 0, 0]);+ add('Dark optical aperture', 'cylinder', [0, 0.5, 1.34], [0.5, 0.06, 0.5], 'graphite', [HALF_PI, 0, 0]);+ add('Incandescent filament rim', 'thinRing', [0, 0.5, 1.385], [0.48, 0.48, 0.48], 'amber');+ for (let index = 0; index < 64; index++) {+ const angle = index / 64 * FULL_TURN;+ add('Engraved calibration mark', 'box', [Math.cos(angle) * 0.68, 0.5 + Math.sin(angle) * 0.68, 1.342], [index % 8 ? 0.036 : 0.08, 0.009, 0.009], 'graphite', [0, 0, angle]);+ }+ for (const side of [-1, 1]) {+ add('Ceramic stand', 'box', [side * 1.2, -0.05, 0], [0.28, 0.8, 2.8], 'ceramic');+ for (let index = 0; index < 9; index++) {+ const depth = -1 + index * 0.25;+ beam('Copper vacuum pipe', [side * 1.06, 0.38, depth], [side * 1.8, 0.65, depth], 0.035, 'copper');+ add('Electrical feedthrough', 'cylinder', [side * 1.8, 0.44, depth], [0.075, 0.38, 0.075], 'ceramic');+ add('Feedthrough terminal', 'sphere', [side * 1.8, 0.67, depth], [0.065, 0.065, 0.065], 'copper');+ }+ }+ for (let index = 0; index < 6; index++) {+ add('Instrument rack', 'box', [-2.4, -0.27 + index * 0.23, -0.6], [0.8, 0.2, 1.4], 'graphite');+ add('Analog dial bezel', 'ring', [-2.4, -0.27 + index * 0.23, 0.13], [0.075, 0.075, 0.4], 'steel');+ }+ return builder.parts;+}++function createAtom(meshes) {+ const { parts, add } = createBuilder(meshes);+ for (let orbit = 0; orbit < 5; orbit++) {+ add('Intersecting luminous orbit', 'thinRing', [0, 0, 0], [2.9, 1.7, 2.5], 'orbit', [orbit * 0.58, orbit * 0.81, orbit * 0.39]);+ const angle = orbit * 1.37;+ add('Orbital electron', 'sphere', [Math.cos(angle) * 2.6, Math.sin(angle) * 1.7, Math.sin(orbit * 2.4) * 1.2], [0.07, 0.07, 0.07], 'core');+ }+ for (let index = 0; index < 39; index++) {+ const angle = index * 2.399963;+ const elevation = 1 - 2 * (index + 0.5) / 39;+ const radius = Math.sqrt(1 - elevation * elevation) * 0.53;+ add('Nucleus cluster', 'sphere', [Math.cos(angle) * radius, elevation * 0.53, Math.sin(angle) * radius], [0.19, 0.19, 0.19], index % 3 ? 'copper' : 'steel');+ }+ for (let index = 0; index < 110; index++) {+ const angle = index * 2.399963;+ const radius = 4 + index % 7 * 0.48;+ add('Suspended speck', 'sphere', [Math.cos(angle) * radius, Math.sin(index * 1.7) * 3.5, Math.sin(angle) * radius], [0.008, 0.008, 0.008], 'orbit');+ }+ return parts;+}++function createWaveChamber(meshes) {+ const { parts, add, beam } = createBuilder(meshes);+ add('Wave chamber slab', 'box', [0, -0.12, 0], [12, 0.16, 7], 'graphite');+ for (let index = -24; index <= 24; index++) {+ beam('Scientific grid', [index * 0.22, 0, -3], [index * 0.22, 0, 3], 0.007, 'steel');+ }+ for (let index = -14; index <= 14; index++) {+ beam('Scientific grid', [-5.3, 0, index * 0.22], [5.3, 0, index * 0.22], 0.007, 'steel');+ }+ for (let index = 0; index < 170; index++) {+ const horizontal = -5 + index * 10 / 169;+ const next = -5 + (index + 1) * 10 / 169;+ const wave = value => Math.sin(value * 5.2) * Math.exp(-value * value * 0.055);+ beam('Wave trace', [horizontal, 0.12 + wave(horizontal) * 0.75, 0], [next, 0.12 + wave(next) * 0.75, 0], 0.023, 'orbit');+ }+ for (let index = 0; index < 14; index++) {+ add('Concentric interference shell', 'thinRing', [0, 0.1, -0.6], [0.2 + index * 0.21, 0.2 + index * 0.21, 0.3], 'steel', [HALF_PI, 0, 0]);+ }+ return parts;+}++function addDesert(builder, aftermath = false) {+ const { add } = builder;+ add('Desert floor', 'box', [0, -0.65, 0], [260, 1, 260], aftermath ? 'ash' : 'terrain');+ for (let index = 0; index < 180; index++) {+ const angle = index * 2.399963;+ const radius = 14 + Math.sqrt(index / 180) * 108;+ const width = 0.5 + (index % 9) * 0.22;+ add('Weathered desert stone', 'rock', [Math.cos(angle) * radius, -0.05, Math.sin(angle) * radius], [width, width * 0.3, width * 0.7], aftermath ? 'ash' : 'rock', [0.12, angle, 0.1]);+ }+ for (let index = 0; index < 24; index++) {+ const angle = index / 24 * FULL_TURN;+ add('Distant broken ridge', 'rock', [Math.cos(angle) * 114, 0.7, Math.sin(angle) * 114], [14 + index % 4 * 4, 3 + index % 5 * 1.8, 9], aftermath ? 'ash' : 'rock', [0, angle, 0]);+ }+}++function createDesert(meshes) {+ const builder = createBuilder(meshes);+ const { add, beam } = builder;+ addDesert(builder);+ for (const horizontal of [-1.3, 1.3]) {+ for (const depth of [-1.3, 1.3]) {+ beam('Test tower leg', [horizontal * 1.5, 0, depth * 1.5], [horizontal, 10, depth], 0.065);+ for (let level = 0; level < 5; level++) {+ beam('Tower diagonal brace', [horizontal, level * 2, depth], [-horizontal, level * 2 + 2, depth], 0.035);+ beam('Tower transverse brace', [horizontal, level * 2, depth], [horizontal, level * 2 + 2, -depth], 0.035);+ }+ }+ }+ add('Tower platform', 'box', [0, 10, 0], [3.2, 0.18, 3.2], 'steel');+ add('Suspended test vessel', 'sphere', [0, 11, 0], [0.85, 0.95, 0.85], 'graphite');+ add('Vessel equatorial seam', 'ring', [0, 11, 0], [0.87, 0.87, 0.87], 'steel', [HALF_PI, 0, 0]);+ for (let index = 0; index < 10; index++) {+ add('Ladder rung', 'cylinder', [1.5, 0.5 + index, 1.4], [0.027, 0.7, 0.027], 'steel', [0, 0, HALF_PI]);+ }+ beam('Signal cable', [0.15, 10, 0], [9, 0, 2], 0.021, 'graphite');+ add('Remote junction box', 'box', [9, 0.3, 2], [0.8, 0.7, 0.8], 'graphite');+ return builder.parts;+}++function createIgnition(meshes) {+ const builder = createBuilder(meshes);+ const { add } = builder;+ addDesert(builder);+ add('Incandescent ignition core', 'sphere', [0, 7, 0], [6.8, 7, 6.8], 'core');+ for (let index = 0; index < 160; index++) {+ const angle = index * 2.399963;+ const elevation = 1 - 2 * (index + 0.5) / 160;+ const radius = Math.sqrt(1 - elevation * elevation) * (6.2 + index % 5 * 0.18);+ const size = 0.8 + index % 7 * 0.19;+ add('Boiling fire cell', 'sphere', [Math.cos(angle) * radius, 7.5 + elevation * 6.6, Math.sin(angle) * radius], [size, size * 1.16, size], index % 4 ? 'fire' : 'core');+ }+ for (let index = 0; index < 110; index++) {+ const angle = index * 2.399963;+ const radius = 2 + index % 11 * 0.48;+ const height = 12 + index / 110 * 10;+ const size = 1.4 + index % 6 * 0.22;+ add('Rolling smoke crown', 'sphere', [Math.cos(angle) * radius, height, Math.sin(angle) * radius], [size * 1.3, size, size * 1.3], 'smoke');+ }+ for (let index = 0; index < 6; index++) {+ add('Dust shock ring', 'gasRing', [0, 0.2 + index * 0.14, 0], [10 + index * 2.3, 10 + index * 2.3, 2.5], 'smoke', [HALF_PI, 0, index * 0.07]);+ }+ for (let index = 0; index < 130; index++) {+ const angle = index * 2.399963;+ const radius = 8 + index % 19 * 0.56;+ add('Ejected ember', 'sphere', [Math.cos(angle) * radius, 1 + index % 17 * 0.6, Math.sin(angle) * radius], [0.035, 0.09, 0.035], 'particle');+ }+ return builder.parts;+}++function createAftermath(meshes) {+ const builder = createBuilder(meshes);+ const { add, beam } = builder;+ addDesert(builder, true);+ add('Scorched impact basin', 'cylinder', [0, -0.02, 0], [12, 0.16, 12], 'graphite');+ for (let index = 0; index < 18; index++) {+ const angle = index * 2.399963;+ const radius = 1 + index % 6;+ beam('Collapsed tower strut', [Math.cos(angle) * radius, 0.1, Math.sin(angle) * radius], [Math.cos(angle + 0.5) * (radius + 3), 0.22, Math.sin(angle + 0.5) * (radius + 3)], 0.06, 'graphite');+ }+ for (let index = 0; index < 55; index++) {+ const angle = index * 2.399963;+ const radius = 1 + index % 7 * 0.8;+ add('Low ember', 'sphere', [Math.cos(angle) * radius, 0.16, Math.sin(angle) * radius], [0.12, 0.025, 0.12], 'particle');+ }+ for (let index = 0; index < 34; index++) {+ const angle = index * 2.399963;+ const height = 1.6 + index * 0.33;+ const size = 0.8 + index / 34 * 1.1;+ add('Residual smoke plume', 'sphere', [Math.cos(angle) * 1.4 + height * 0.14, height, Math.sin(angle) * 1.4], [size, size * 1.2, size], 'smoke');+ }+ return builder.parts;+}++export function createFilmScenes() {+ const meshes = {+ box: box(0.04, 3),+ cylinder: cylinder(24),+ bolt: cylinder(6),+ sphere: sphere(24, 16),+ rock: sphere(12, 8),+ ring: torus(0.055, 64, 8),+ thinRing: torus(0.008, 96, 6),+ gasRing: torus(0.045, 96, 8),+ };+ const studio = {+ fogColor: [0.007, 0.009, 0.012], fogDensity: 0.028,+ skyTop: [0.009, 0.013, 0.02], skyBottom: [0.025, 0.032, 0.04],+ lightDirection: [-0.4, 0.8, 0.5], daylight: 0.65,+ };+ const desert = {+ fogColor: [0.14, 0.105, 0.075], fogDensity: 0.007,+ skyTop: [0.075, 0.11, 0.15], skyBottom: [0.5, 0.33, 0.21],+ lightDirection: [-0.65, 0.22, -0.5], daylight: 0.7,+ };+ const desertShadows = { extent: 55, target: [0, 6, 0], eye: [-35, 45, -35], near: 1, far: 140 };+ return {+ apparatus: { parts: createApparatus(meshes), environment: studio, ground: false },+ atom: {+ parts: createAtom(meshes), ground: false,+ environment: { ...studio, fogDensity: 0.06, skyTop: [0.002, 0.004, 0.009], skyBottom: [0.008, 0.012, 0.02], daylight: 0.2 },+ },+ waves: { parts: createWaveChamber(meshes), environment: studio, ground: false },+ desert: { parts: createDesert(meshes), environment: desert, ground: false, shadowBounds: desertShadows },+ ignition: { parts: createIgnition(meshes), environment: desert, ground: false, shadowBounds: desertShadows },+ aftermath: {+ parts: createAftermath(meshes), ground: false, shadowBounds: desertShadows,+ environment: {+ fogColor: [0.023, 0.018, 0.015], fogDensity: 0.016,+ skyTop: [0.013, 0.022, 0.032], skyBottom: [0.13, 0.075, 0.042],+ lightDirection: [-0.6, 0.3, -0.4], daylight: 0.3,+ },+ },+ };+}++// Each shot owns its camera endpoints. Cuts are deliberate; motion within a shot is continuous.+const shots = [+ { start: 0, end: 5, scene: 'apparatus', eye: [[0.37, 0.73, 2.12], [1.65, 1.02, 3.65]], target: [[0, 0.5, 1.28], [0, 0.48, 0.4]], fov: [34, 39], exposure: 0.95, monochrome: 0.25 },+ { start: 5, end: 10, scene: 'atom', eye: [[0.5, 0.3, 6.8], [4.8, 2.5, 5.1]], target: [[0, 0, 0], [0, 0, 0]], fov: [48, 43], exposure: 0.82, monochrome: 0 },+ { start: 10, end: 13.5, scene: 'waves', eye: [[-3.8, 3.4, 5.3], [0.5, 2.2, 4.4]], target: [[-0.8, 0, 0], [0.8, 0.05, 0]], fov: [49, 42], exposure: 0.85, monochrome: 1 },+ { start: 13.5, end: 17, scene: 'desert', eye: [[29, 6, 37], [21, 5, 29]], target: [[0, 6, 0], [0, 7.5, 0]], fov: [44, 40], exposure: 0.8, monochrome: 0.12 },+ { start: 17, end: 19, scene: 'desert', eye: [[4.7, 9.1, 6.2], [3.8, 10, 4.8]], target: [[0, 10.7, 0], [0, 11, 0]], fov: [36, 31], exposure: 0.68, monochrome: 0.25 },+ { start: 19, end: 26, scene: 'ignition', eye: [[28, 7, 39], [37, 11, 49]], target: [[0, 7, 0], [0, 11, 0]], fov: [48, 53], exposure: 0.66, monochrome: 0 },+ { start: 26, end: 32, scene: 'aftermath', eye: [[18, 3.2, 24], [22, 5, 30]], target: [[0, 2.5, 0], [0, 3.7, 0]], fov: [45, 46], exposure: 0.72, monochrome: 0.35 },+];++function smoothstep(value) {+ const bounded = Math.max(0, Math.min(1, value));+ return bounded * bounded * (3 - 2 * bounded);+}++function interpolate(first, second, fraction) {+ return first + (second - first) * fraction;+}++export function sampleFilm(time) {+ if (!Number.isFinite(time)) throw new TypeError('Film time must be finite.');+ const boundedTime = Math.max(0, Math.min(FILM_DURATION, time));+ const shotIndex = shots.findIndex(shot => boundedTime < shot.end);+ const shot = shots[shotIndex < 0 ? shots.length - 1 : shotIndex];+ const progress = (boundedTime - shot.start) / (shot.end - shot.start);+ const eased = smoothstep(progress);+ const sceneStart = shots.find(candidate => candidate.scene === shot.scene).start;+ const sceneTime = boundedTime - sceneStart;+ const explosionProgress = shot.scene === 'ignition' ? smoothstep(sceneTime / 5.5) : shot.scene === 'aftermath' ? 1 : 0;+ const camera = {+ eye: shot.eye[0].map((value, axis) => interpolate(value, shot.eye[1][axis], eased)),+ target: shot.target[0].map((value, axis) => interpolate(value, shot.target[1][axis], eased)),+ fov: interpolate(...shot.fov, eased),+ };+ let title = '';+ let subtitle = '';+ if (boundedTime >= 28) {+ title = 'CRITICAL';+ subtitle = 'A 67.js short';+ }+ const visibility = smoothstep(boundedTime / 0.8) * (1 - smoothstep((boundedTime - 31) / 1));+ const flash = boundedTime >= 19 && boundedTime < 19.65 ? Math.exp(-(boundedTime - 19) * 7) : 0;+ return {+ scene: shot.scene,+ camera,+ exposure: shot.exposure + flash * 1.5,+ monochrome: shot.monochrome,+ fade: 1 - visibility,+ title,+ subtitle,+ time: boundedTime,+ sceneTime,+ explosionProgress,+ flash,+ titleOpacity: boundedTime >= 28 ? smoothstep((boundedTime - 28) / 1.2) * visibility : 0,+ };+}diff --git a/tests/film.test.js b/tests/film.test.jsnew file mode 100644index 00000000..1b7642ba--- /dev/null+++ b/tests/film.test.js@@ -0,0 +1,94 @@+import assert from 'node:assert/strict';+import test from 'node:test';+import { createFilmScenes, FILM_DURATION, sampleFilm } from '../src/film.js';++test('film timeline includes every set with exact cut boundaries and terminal black', () => {+ const cuts = [[0, 'apparatus'], [5, 'atom'], [10, 'waves'], [13.5, 'desert'], [19, 'ignition'], [26, 'aftermath']];+ assert.equal(FILM_DURATION, 32);+ for (const [time, scene] of cuts) {+ const sample = sampleFilm(time);+ assert.equal(sample.scene, scene);+ assert.equal(sample.sceneTime, 0);+ }+ assert.deepEqual(sampleFilm(-10), sampleFilm(0));+ assert.deepEqual(sampleFilm(100), sampleFilm(32));+ assert.equal(sampleFilm(0).fade, 1);+ assert.equal(sampleFilm(2).fade, 0);+ assert.equal(sampleFilm(32).fade, 1);+ assert.equal(sampleFilm(29.5).title, 'CRITICAL');+ assert.equal(sampleFilm(29.5).titleOpacity, 1);+ assert.equal(sampleFilm(18.9).explosionProgress, 0);+ assert.equal(sampleFilm(19).flash, 1);+ assert.equal(sampleFilm(25.9).explosionProgress, 1);+ assert.equal(sampleFilm(27).explosionProgress, 1);+});++test('all frame samples are deterministic, finite, bounded and have usable cameras', () => {+ const scenes = createFilmScenes();+ for (let frame = 0; frame <= FILM_DURATION * 60; frame++) {+ const time = frame / 60;+ const sample = sampleFilm(time);+ assert.deepEqual(sample, sampleFilm(time));+ assert.ok(scenes[sample.scene]);+ for (const value of [...sample.camera.eye, ...sample.camera.target, sample.camera.fov, sample.exposure, sample.time, sample.sceneTime]) {+ assert.ok(Number.isFinite(value));+ }+ for (const value of [sample.fade, sample.monochrome, sample.explosionProgress, sample.flash, sample.titleOpacity]) {+ assert.ok(value >= 0 && value <= 1);+ }+ assert.ok(sample.camera.fov >= 20 && sample.camera.fov <= 65);+ assert.ok(Math.hypot(...sample.camera.eye.map((value, axis) => value - sample.camera.target[axis])) > 0.5);+ }+ for (const invalid of [NaN, Infinity, -Infinity, undefined, '1']) {+ assert.throws(() => sampleFilm(invalid), TypeError);+ }+});++test('camera motion stays continuous and eases to rest within each authored shot', () => {+ const boundaries = [0, 5, 10, 13.5, 17, 19, 26, 32];+ const distance = (first, second) => Math.hypot(...first.map((value, axis) => value - second[axis]));+ for (let index = 0; index < boundaries.length - 1; index++) {+ const start = boundaries[index];+ const end = boundaries[index + 1];+ assert.ok(distance(sampleFilm(start).camera.eye, sampleFilm(end - 0.001).camera.eye) > 0.1);+ assert.ok(distance(sampleFilm(start).camera.eye, sampleFilm(start + 0.001).camera.eye) < 0.001);+ assert.ok(distance(sampleFilm(end - 0.002).camera.eye, sampleFilm(end - 0.001).camera.eye) < 0.001);+ for (let time = start; time + 0.01 < end; time += 0.01) {+ assert.ok(distance(sampleFilm(time).camera.eye, sampleFilm(time + 0.01).camera.eye) < 0.1);+ assert.ok(distance(sampleFilm(time).camera.target, sampleFilm(time + 0.01).camera.target) < 0.04);+ }+ }+});++test('six 3D sets respect instancing, material, geometry and scene budgets', () => {+ const scenes = createFilmScenes();+ assert.equal(Object.keys(scenes).length, 6);+ const budgets = {};+ for (const [name, scene] of Object.entries(scenes)) {+ assert.equal(scene.ground, false);+ assert.ok(scene.environment.fogDensity >= 0);+ assert.equal(scene.environment.lightDirection.length, 3);+ assert.ok(scene.parts.length > 100 && scene.parts.length < 1000);+ const triangleCount = scene.parts.reduce((total, part) => total + part.geometry.indices.length / 3, 0);+ assert.ok(triangleCount < 600000, name);+ assert.ok(new Set(scene.parts.map(part => part.geometry)).size <= 8);+ for (const part of scene.parts) {+ assert.ok(part.name);+ assert.ok(part.matrix instanceof Float32Array);+ assert.equal(part.matrix.length, 16);+ assert.equal(part.matrix[15], 1);+ assert.ok(Array.from(part.matrix).every(Number.isFinite));+ assert.ok(part.geometry.positions instanceof Float32Array);+ assert.ok(part.geometry.normals instanceof Float32Array);+ assert.ok(part.geometry.indices instanceof Uint32Array);+ assert.ok(part.material.color.every(value => value >= 0 && value <= 1));+ assert.ok(part.material.roughness > 0 && part.material.roughness <= 1);+ assert.ok(part.material.metallic >= 0 && part.material.metallic <= 1);+ assert.ok(part.material.emission >= 0);+ }+ budgets[name] = { parts: scene.parts.length, triangles: triangleCount };+ }+ assert.ok(scenes.ignition.parts.some(part => part.material.tag === 'fire'));+ assert.ok(scenes.ignition.parts.some(part => part.material.tag === 'smoke'));+ console.log(JSON.stringify(budgets));+});