Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Run the physics film checks on stills so CI needs no ffmpeg (#1017)

Nguyen Xuan An542c25717af8
diff --git a/changes/1017.size.md b/changes/1017.size.md
index 0baff2ee..e94b700f 100644
--- a/changes/1017.size.md
+++ b/changes/1017.size.md
@@ -1,2 +1,3 @@
- scene:agent-scene: one physics capability line (about 54 bytes gzip) tells an agent that a render job films physics without bake-motion, so it stops baking and hitting the 32 node cap
- goal:agent-scene: the same line, an agent-facing capability that replaces a failing workflow
+- scene:agent-scene+lazy: the same physics capability line, which reaches the lazy bundle too; it tells an agent that a render job films physics without bake-motion
diff --git a/tests/physics-film.test.js b/tests/physics-film.test.js
index 39480c80..51479829 100644
--- a/tests/physics-film.test.js
+++ b/tests/physics-film.test.js
@@ -4,7 +4,7 @@
// PHYSICS_FILM_BACKEND (gpu) with PHYSICS_FILM_BROWSER (a Chrome wrapper) to film on a GPU.
import test, { after, before } from 'node:test';
import assert from 'node:assert/strict';
-import { mkdtemp, rm, copyFile } from 'node:fs/promises';
+import { mkdtemp, rm, copyFile, readFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { spawnSync } from 'node:child_process';
@@ -75,24 +75,48 @@ function sceneWithGround(nodes, physics) {
};
}
-async function submitVideo(sessionId, settings) {
+async function submitJob(sessionId, kind, settings) {
const submitted = await call('scene_render_submit', { sessionId, expectedRevision: (await call('scene_inspect', { sessionId })).revision,
- settings: { kind: 'video', width: FRAME_WIDTH, height: FRAME_HEIGHT, fps: 6, ...settings } });
+ settings: { kind, width: FRAME_WIDTH, height: FRAME_HEIGHT, fps: 6, ...settings } });
const record = await finished(submitted.jobId);
assert.equal(record.state, 'completed', JSON.stringify(record.error ?? record));
return call('scene_render_result', { jobId: submitted.jobId });
}
-test('a video job films a falling body from physics alone, for the length of the bake', async () => {
+// The eight PNGs of a stills job need no ffmpeg, so the physics checks read them and only the encode test needs the encoder.
+async function stillBytes(result) {
+ assert.equal(result.artifacts.length, 8);
+ return Promise.all(result.artifacts.map(artifact => readFile(artifact.path)));
+}
+
+async function createFracturedWall() {
+ const recipe = sceneWithGround([
+ { id: 'wall', geometry: 'slab', material: 'brick', translation: [0, 1.25, 0], scale: [4, 2.5, 0.4] },
+ { id: 'ball', geometry: 'ball', material: 'steel', translation: [0, 1.2, 5], scale: [0.5, 0.5, 0.5] },
+ ]);
+ const { sessionId } = await call('scene_create', { recipe });
+ const applied = await call('scene_apply', { sessionId, expectedRevision: 0, operations: [
+ { type: 'set-physics', physics: { duration: 3, bodies: [
+ { node: 'floor', type: 'fixed', shape: 'box' },
+ { node: 'ball', shape: 'ball', density: 400, velocity: [0, 0.3, -18] },
+ ] } },
+ { type: 'fracture-node', node: 'wall', seed: 7, cells: 64, strength: 1, impact: [0, 0, 0.2], impactRadius: 0.8 },
+ ] });
+ assert.ok(applied.revision > 0);
+ const inspected = await call('scene_inspect', { sessionId });
+ assert.equal(inspected.physics.bodies.filter(body => body.node.startsWith('wall-frag-')).length, 64);
+ return sessionId;
+}
+
+test('a stills job films a falling body from physics alone, spread over the bake', async () => {
const recipe = sceneWithGround(
[{ id: 'drop', geometry: 'ball', material: 'steel', translation: [0, 3, 0], scale: [0.5, 0.5, 0.5] }],
{ duration: 1.5, bodies: [{ node: 'floor', type: 'fixed', shape: 'box' }, { node: 'drop', shape: 'ball' }] });
const { sessionId } = await call('scene_create', { recipe });
- const result = await submitVideo(sessionId, { motion: { start: 0 } });
- const frames = decodedFrames(result.artifacts[0].path, FRAME_WIDTH, FRAME_HEIGHT);
- assert.equal(frames.length, 9, 'the default duration is the 1.5 s bake at 6 fps');
- assert.notDeepEqual(frames[0], frames[4], 'the ball moves between frame 0 and frame 4');
- assert.notDeepEqual(frames[4], frames[8]);
+ const result = await submitJob(sessionId, 'stills', { motion: { start: 0 } });
+ const frames = await stillBytes(result);
+ assert.ok(!frames[0].equals(frames[3]), 'the ball moves between frame 0 and frame 3');
+ assert.ok(!frames[3].equals(frames[7]), 'and between frame 3 and frame 7');
await call('scene_dispose', { sessionId });
});
@@ -106,25 +130,21 @@ test('a recipe with nothing that moves still errors and names physics as a sourc
await call('scene_dispose', { sessionId });
});
-test('a 64 piece fractured wall renders as video with the ball breaking it', async () => {
- const recipe = sceneWithGround([
- { id: 'wall', geometry: 'slab', material: 'brick', translation: [0, 1.25, 0], scale: [4, 2.5, 0.4] },
- { id: 'ball', geometry: 'ball', material: 'steel', translation: [0, 1.2, 5], scale: [0.5, 0.5, 0.5] },
- ]);
- const { sessionId } = await call('scene_create', { recipe });
- const applied = await call('scene_apply', { sessionId, expectedRevision: 0, operations: [
- { type: 'set-physics', physics: { duration: 3, bodies: [
- { node: 'floor', type: 'fixed', shape: 'box' },
- { node: 'ball', shape: 'ball', density: 400, velocity: [0, 0.3, -18] },
- ] } },
- { type: 'fracture-node', node: 'wall', seed: 7, cells: 64, strength: 1, impact: [0, 0, 0.2], impactRadius: 0.8 },
- ] });
- assert.ok(applied.revision > 0);
+test('a 64 piece fractured wall renders as stills with the ball breaking it', async () => {
+ const sessionId = await createFracturedWall();
+ const frames = await stillBytes(await submitJob(sessionId, 'stills', { motion: { start: 0 } }));
+ assert.ok(!frames[0].equals(frames[7]), 'the wall changes over the film');
+ assert.ok(!frames[2].equals(frames[4]));
+ await call('scene_dispose', { sessionId });
+});
+
+const hasFfmpeg = spawnSync('ffmpeg', ['-version'], { windowsHide: true }).status === 0;
+
+test('a 64 piece fractured wall encodes as video for the length of the bake', { skip: !hasFfmpeg && 'ffmpeg is not installed' }, async () => {
+ const sessionId = await createFracturedWall();
const wide = clipPath !== undefined;
- const result = await submitVideo(sessionId, wide ? { width: 640, height: 360, fps: 24, motion: { start: 0 } } : { motion: { start: 0 } });
- const width = wide ? 640 : FRAME_WIDTH;
- const height = wide ? 360 : FRAME_HEIGHT;
- const frames = decodedFrames(result.artifacts[0].path, width, height);
+ const result = await submitJob(sessionId, 'video', wide ? { width: 640, height: 360, fps: 24, motion: { start: 0 } } : { motion: { start: 0 } });
+ const frames = decodedFrames(result.artifacts[0].path, wide ? 640 : FRAME_WIDTH, wide ? 360 : FRAME_HEIGHT);
assert.equal(frames.length, wide ? 72 : 18);
assert.notDeepEqual(frames[0], frames[frames.length - 1], 'the wall changes over the film');
if (clipPath) {