Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Film physics-only recipes without baking bodies to keyframes (#1017)

Nguyen Xuan An10021013b184
diff --git a/changes/1017.md b/changes/1017.md
new file mode 100644
index 00000000..278ef049
--- /dev/null
+++ b/changes/1017.md
@@ -0,0 +1 @@
+- A render job films a recipe whose only motion is physics, cloth or particles with `motion: { start: 0 }`, no `bake-motion` first and no 32 node cap (#1017)
diff --git a/changes/1017.size.md b/changes/1017.size.md
new file mode 100644
index 00000000..0baff2ee
--- /dev/null
+++ b/changes/1017.size.md
@@ -0,0 +1,2 @@
+- 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
diff --git a/docs/agent-render-jobs.md b/docs/agent-render-jobs.md
index a7c5d736..d46b6c5b 100644
--- a/docs/agent-render-jobs.md
+++ b/docs/agent-render-jobs.md
@@ -354,3 +354,5 @@ Partial files count toward the store budget and remain until explicit release.
The tests use actual temporary files and controlled callbacks.
They cover snapshots, persistence, hashes, cancellation, deadlines, restart recovery, quotas, path rejection, and file aliases.
The tests do not run browsers, ffmpeg, or GPU rendering.
+
+A recipe whose only moving content is `physics`, `cloth` or `particles` takes the same `motion` setting: the job plays the bake on the motion clock, with no authored motion and no `bake-motion` step (so the 32 node cap does not apply). A video without `duration` runs as long as the bake, counted from `motion.start`, and a longer one is rejected. A recipe with nothing that moves fails with an error that lists authored motion, physics, cloth, particles, placed clips and map sequences as the accepted sources.
diff --git a/docs/physics-film-still.jpg b/docs/physics-film-still.jpg
new file mode 100644
index 00000000..816c1367
Binary files /dev/null and b/docs/physics-film-still.jpg differ
diff --git a/scripts/agent-render-jobs.mjs b/scripts/agent-render-jobs.mjs
index 254dfaa8..c5182980 100644
--- a/scripts/agent-render-jobs.mjs
+++ b/scripts/agent-render-jobs.mjs
@@ -84,6 +84,16 @@ function jsonCopy(value, maximum = MAXIMUM_JSON_BYTES) {
return JSON.parse(text);
}
+/** Seconds the recipe's physics or cloth bake covers, or undefined when it has neither. Both play on the motion clock. */
+function bakedPhysicsDuration(recipe) {
+ const durations = [recipe?.physics?.duration, recipe?.cloth?.duration].filter(Number.isFinite);
+ return durations.length ? Math.max(...durations) : undefined;
+}
+
+function playsPhysics(recipe) {
+ return Boolean(recipe?.physics || recipe?.cloth || recipe?.particles);
+}
+
function settingsFrom(input, clips, recipe) {
objectKeys(input, ['kind', 'width', 'height', 'fps', 'duration', 'animation', 'motion', 'rendererTime', 'passes', 'renderer', 'timeline', 'audio', 'encoder', 'transparent', 'format', 'multilayer', 'region'], 'settings');
if (!['image', 'stills', 'video'].includes(input.kind)) throw new TypeError('kind must be image, stills or video.');
@@ -93,7 +103,10 @@ function settingsFrom(input, clips, recipe) {
if (input.kind === 'video' && (width % 2 || height % 2)) throw new RangeError('Video dimensions must be even.');
const fps = boundedNumber(input.fps ?? 24, 1, MAXIMUM_JOB_FPS, 'fps', true);
const timelineStart = timelineStartFrom(input, recipe);
- const defaultDuration = timelineStart === undefined || input.kind === 'image' ? 1 : filmTimelineDuration(recipe.timeline) - timelineStart;
+ // A physics-only film runs as long as its bake, counted from the motion start.
+ const bakeSeconds = recipe?.format === '67js.scene' && !recipe.motion ? bakedPhysicsDuration(recipe) : undefined;
+ const bakeDefault = bakeSeconds && input.kind !== 'image' && input.motion ? Math.max(0.1, bakeSeconds - (Number(input.motion.start) || 0)) : undefined;
+ const defaultDuration = timelineStart === undefined || input.kind === 'image' ? bakeDefault ?? 1 : filmTimelineDuration(recipe.timeline) - timelineStart;
const duration = boundedNumber(input.duration ?? defaultDuration, 0.1, MAXIMUM_VIDEO_SECONDS, 'duration');
const frameCount = input.kind === 'image' ? 1 : input.kind === 'stills' ? 8 : Math.ceil(fps * duration);
if (frameCount > 900) throw new RangeError('Job exceeds 900 frames.');
@@ -119,8 +132,8 @@ function settingsFrom(input, clips, recipe) {
const placesClips = recipe?.format === '67js.scene' && recipeAssetNeeds(recipe).some(need => need.copies > 1);
// A map sequence reads the same clock.
const sequenced = JSON.stringify(recipe?.materials ?? []).includes('"sequence":{');
- if (!['67js.scene', '67js.asset'].includes(recipe?.format) || (!recipe.motion && !placesClips && !sequenced)) {
- throw new RangeError('Motion settings require a recipe with authored motion or a placed clip (or a map sequence).');
+ if (!['67js.scene', '67js.asset'].includes(recipe?.format) || (!recipe.motion && !placesClips && !sequenced && !(recipe.format === '67js.scene' && playsPhysics(recipe)))) {
+ throw new RangeError('Motion settings require a recipe with authored motion, physics (or cloth, particles), a placed clip or a map sequence.');
}
const motionDuration = recipe.motion ? boundedNumber(recipe.motion.duration, 0.1, 30, 'motion duration') : undefined;
if (recipe.motion?.loop !== undefined && typeof recipe.motion.loop !== 'boolean') {
@@ -131,6 +144,9 @@ function settingsFrom(input, clips, recipe) {
if (recipe.motion && !recipe.motion.loop && start + lastSampleTime > motionDuration) {
throw new RangeError('Motion range exceeds the authored duration.');
}
+ if (!recipe.motion && bakeSeconds && start + lastSampleTime > bakeSeconds) {
+ throw new RangeError(`Motion range exceeds the physics bake duration of ${bakeSeconds} s; shorten the job or lengthen physics.duration.`);
+ }
result.motion = { start };
}
if (input.animation !== undefined) {
diff --git a/skills/render-67js-media/SKILL.md b/skills/render-67js-media/SKILL.md
index 6a3f058f..1d849d16 100644
--- a/skills/render-67js-media/SKILL.md
+++ b/skills/render-67js-media/SKILL.md
@@ -42,6 +42,8 @@ submit call fails: tell the user which launch option is missing.
- Use `settings.motion: { "start": 0 }` to play recipe tracks (camera, nodes, lights, sun, sky, effects). Without it the
job holds the first pose, which is the usual reason a video is a still frame. A recipe with a `timeline` uses
`settings.timeline` and rejects `motion` and `animation`.
+- A recipe whose only motion is `physics` (or `cloth`, `particles`) is filmed with the same `motion: { "start": 0 }`; the
+ job plays the bake on the scene clock, so do not `bake-motion` first. Video `duration` defaults to the bake length.
- Imported clips use `settings.animation`; the two clocks are independent.
- For compositing, `settings.transparent`, `settings.format` (`png16`, `exr`) and `settings.region` are off by default; video runs up to 60 fps (`references/jobs.md`, Compositing output).
- Path tracing (`settings.renderer`) is offline and slow, for stills; video and passes use the rasterizer.
diff --git a/skills/render-67js-media/references/jobs.md b/skills/render-67js-media/references/jobs.md
index 34a63a27..9edacd40 100644
--- a/skills/render-67js-media/references/jobs.md
+++ b/skills/render-67js-media/references/jobs.md
@@ -33,6 +33,9 @@ render the video.
Video is H.264 with one frame in flight. At most 60 s and 900 frames, so 60 s needs 15 fps or less. A nonlooping
motion must cover `start + duration`. The animated lights, sun, sky and effects tracks play with the same setting.
+A recipe with `physics` or `cloth` and no authored motion plays its bake on the same clock: send `motion: { "start": 0 }`,
+leave `duration` out to film the whole bake, and skip `bake-motion` (its 32 node cap does not apply). Nothing that moves
+still fails with an error naming motion, physics, cloth, particles, clips and map sequences.
Motion blur (`effects.motionBlur.shutter`) needs camera tracks and this `motion` setting.
## Shots, cuts and sound
diff --git a/src/agent-scene-capabilities.js b/src/agent-scene-capabilities.js
index 553097fb..e3a11f2f 100644
--- a/src/agent-scene-capabilities.js
+++ b/src/agent-scene-capabilities.js
@@ -310,6 +310,7 @@ export const AGENT_SCENE_CAPABILITIES = Object.freeze({
sensors: true, collisionLayers: 16,
breakableJoints: 'fixed joint breakImpulse (N s): breaks when a body takes a contact impulse (force x 1/60 s) over it in one step; scene_inspect lists jointBreaks. scene_apply fracture-node { node, cells 2-64, strength N s, seed 1, impact [x,y,z] in geometry space, impactRadius, density 1, friction }: replaces a convex root node by cells nodes NAME-frag-i (fragment geometries) with convex bodies and one breakable fixed joint NAME-glue-a-b per neighbour pair; send it after the set-physics that holds the floor, ball and duration (set-physics replaces the section). docs/physics.md.',
ragdoll: 'physics.ragdoll {armature}: limp capsule per bone; needs a floor',
+ film: 'render motion {start 0} plays this bake, cloth and particles with no bake-motion; video duration defaults to the bake.',
limits: Object.freeze({ maxBodies: 128, maxJoints: 512, maxDuration: 10, framesPerSecond: 60, maxTrimeshTriangles: 20000, maxHullPoints: 2048 }),
}),
// Recipe cloth: a position-based solver (no peer dependency) records any root mesh node as a deformable sheet.
diff --git a/tests/agent-render-jobs.test.js b/tests/agent-render-jobs.test.js
index efedc623..773908a8 100644
--- a/tests/agent-render-jobs.test.js
+++ b/tests/agent-render-jobs.test.js
@@ -87,7 +87,29 @@ test('a scene that places a clip takes motion settings without authored motion,
assert.equal((await terminal(controller, submitted.jobId)).state, 'completed');
assert.equal(controller.status(submitted.jobId).settings.motion.start, 2);
input.snapshot.recipe = { format: '67js.scene', nodes: [{ id: 'prop', asset: { id } }] };
- await assert.rejects(controller.submit(input), /authored motion or a placed clip/);
+ await assert.rejects(controller.submit(input), /authored motion, physics .* a placed clip/);
+ await controller.release(submitted.jobId);
+ await controller.close();
+});
+
+test('a scene with physics takes motion settings, defaults the video to the bake length and stops at its end', async context => {
+ const root = await temporary(context);
+ const controller = await createAgentRenderJobs({ root, limits, run: writeImage });
+ const input = request();
+ input.snapshot.recipe = { format: '67js.scene', physics: { duration: 2, bodies: [] } };
+ input.settings = { kind: 'video', width: 64, height: 64, fps: 10, motion: { start: 0 } };
+ const submitted = await controller.submit(input);
+ assert.equal(controller.status(submitted.jobId).settings.duration, 2);
+ assert.equal(controller.status(submitted.jobId).settings.frameCount, 20);
+ await terminal(controller, submitted.jobId);
+ input.settings.duration = 3;
+ await assert.rejects(controller.submit(input), /physics bake duration of 2 s/);
+ input.snapshot.recipe = { format: '67js.scene', cloth: { duration: 1, sheets: [] } };
+ input.settings = { kind: 'image', width: 64, height: 64, motion: { start: 0.5 } };
+ const clothJob = await controller.submit(input);
+ assert.equal(controller.status(clothJob.jobId).settings.motion.start, 0.5);
+ await terminal(controller, clothJob.jobId);
+ await controller.release(clothJob.jobId);
await controller.release(submitted.jobId);
await controller.close();
});
diff --git a/tests/physics-film.test.js b/tests/physics-film.test.js
new file mode 100644
index 00000000..39480c80
--- /dev/null
+++ b/tests/physics-film.test.js
@@ -0,0 +1,134 @@
+// A render job films a recipe whose only motion is physics: no authored motion and no bake-motion step.
+// Runs the real MCP server, so it needs Chrome and ffmpeg like the other MCP tests.
+// Set PHYSICS_FILM_CLIP to a file path to also keep the wall film there (640x360, 3 s) as a visual proof, and
+// 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 { tmpdir } from 'node:os';
+import { join, resolve } from 'node:path';
+import { spawnSync } from 'node:child_process';
+import { setTimeout as delay } from 'node:timers/promises';
+import { Client } from '@modelcontextprotocol/client';
+import { StdioClientTransport } from '@modelcontextprotocol/client/stdio';
+
+const FRAME_WIDTH = 128;
+const FRAME_HEIGHT = 64;
+const clipPath = process.env.PHYSICS_FILM_CLIP;
+
+let directory;
+let client;
+
+before(async () => {
+ directory = await mkdtemp(join(tmpdir(), '67js-physics-film-'));
+ const transport = new StdioClientTransport({ command: process.execPath,
+ args: [resolve('bin/67js-mcp.mjs'), '--backend', process.env.PHYSICS_FILM_BACKEND ?? 'cpu', '--memory', '96', '--jobs', join(directory, 'jobs'),
+ ...(process.env.PHYSICS_FILM_BROWSER ? ['--browser', process.env.PHYSICS_FILM_BROWSER] : [])],
+ cwd: directory, stderr: 'pipe' });
+ client = new Client({ name: '67js-physics-film-test', version: '1' });
+ await client.connect(transport);
+});
+
+after(async () => {
+ await client?.close();
+ await rm(directory, { recursive: true, force: true });
+});
+
+async function call(name, argumentsValue = {}, timeout = 120000) {
+ const result = await client.callTool({ name, arguments: argumentsValue }, { timeout });
+ assert.equal(result.isError, undefined, result.content?.find(item => item.type === 'text')?.text);
+ return result.structuredContent;
+}
+
+async function finished(jobId) {
+ const deadline = Date.now() + 240000;
+ while (Date.now() < deadline) {
+ const record = await call('scene_render_status', { jobId });
+ if (['completed', 'failed', 'cancelled'].includes(record.state)) {
+ return record;
+ }
+ await delay(200);
+ }
+ throw new Error('The render job did not finish in time.');
+}
+
+function decodedFrames(file, width, height) {
+ const decoded = spawnSync('ffmpeg', ['-v', 'error', '-i', file, '-f', 'rawvideo', '-pix_fmt', 'rgb24', '-threads', '1', 'pipe:1'],
+ { windowsHide: true, maxBuffer: 256 * 1024 ** 2 });
+ assert.equal(decoded.status, 0, decoded.stderr.toString());
+ const frameBytes = width * height * 3;
+ const frames = [];
+ for (let offset = 0; offset + frameBytes <= decoded.stdout.length; offset += frameBytes) {
+ frames.push(decoded.stdout.subarray(offset, offset + frameBytes));
+ }
+ return frames;
+}
+
+function sceneWithGround(nodes, physics) {
+ return {
+ format: '67js.scene', schemaVersion: 1,
+ geometries: [{ id: 'slab', type: 'box', bevel: 0 }, { id: 'ball', type: 'sphere' }],
+ materials: [{ id: 'brick', color: [0.6, 0.3, 0.2] }, { id: 'steel', color: [0.7, 0.7, 0.75] }],
+ nodes: [{ id: 'floor', geometry: 'slab', material: 'brick', translation: [0, -0.25, 0], scale: [8, 0.5, 8] }, ...nodes],
+ camera: { eye: [4, 2.5, 7], target: [0, 1, 0] },
+ ...(physics ? { physics } : {}),
+ };
+}
+
+async function submitVideo(sessionId, 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 } });
+ 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 () => {
+ 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]);
+ await call('scene_dispose', { sessionId });
+});
+
+test('a recipe with nothing that moves still errors and names physics as a source', async () => {
+ const recipe = sceneWithGround([{ id: 'rock', geometry: 'ball', material: 'steel', translation: [0, 1, 0] }]);
+ const { sessionId } = await call('scene_create', { recipe });
+ const result = await client.callTool({ name: 'scene_render_submit', arguments: { sessionId, expectedRevision: 0,
+ settings: { kind: 'video', width: FRAME_WIDTH, height: FRAME_HEIGHT, motion: { start: 0 } } } });
+ assert.equal(result.isError, true);
+ assert.match(result.content[0].text, /authored motion, physics/);
+ 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);
+ 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);
+ assert.equal(frames.length, wide ? 72 : 18);
+ assert.notDeepEqual(frames[0], frames[frames.length - 1], 'the wall changes over the film');
+ if (clipPath) {
+ await copyFile(result.artifacts[0].path, clipPath);
+ }
+ await call('scene_dispose', { sessionId });
+});