Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Test and document that a fixed camera stays locked during a physics film (#1089)

Nguyen Xuan Andd11cde501f9
diff --git a/changes/1089.md b/changes/1089.md
new file mode 100644
index 00000000..1391fc38
--- /dev/null
+++ b/changes/1089.md
@@ -0,0 +1 @@
+- A render job holds a recipe camera locked for the whole physics, cloth or particle film, and a regression test now checks it (#1089)
diff --git a/docs/agent-render-jobs.md b/docs/agent-render-jobs.md
index d46b6c5b..0ae49d69 100644
--- a/docs/agent-render-jobs.md
+++ b/docs/agent-render-jobs.md
@@ -356,3 +356,5 @@ They cover snapshots, persistence, hashes, cancellation, deadlines, restart reco
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.
+
+The camera does not move with the bake. A recipe `camera` (`eye`, `target`, lens) is the same on every frame of a physics, cloth or particle film, so shards flying out of frame do not pull the view. Nothing frames the scene by its bounds: only an authored `camera` motion track or a timeline shot changes the camera. Set `camera.eye` and `camera.target` for a locked shot; left out, the default camera is used, also locked. `tests/physics-film.test.js` checks that a static marker stays on the same pixels from the first frame to the last.
diff --git a/tests/physics-film.test.js b/tests/physics-film.test.js
index 39480c80..7a1e5272 100644
--- a/tests/physics-film.test.js
+++ b/tests/physics-film.test.js
@@ -132,3 +132,48 @@ test('a 64 piece fractured wall renders as video with the ball breaking it', asy
}
await call('scene_dispose', { sessionId });
});
+
+function markerCentroid(frame, width, height) {
+ let sumX = 0;
+ let sumY = 0;
+ let count = 0;
+ for (let y = 0; y < height; y++) {
+ for (let x = 0; x < width; x++) {
+ const offset = (y * width + x) * 3;
+ const [red, green, blue] = [frame[offset], frame[offset + 1], frame[offset + 2]];
+ if (green > red + 40 && green > blue + 40) {
+ sumX += x;
+ sumY += y;
+ count++;
+ }
+ }
+ }
+ assert.ok(count > 0, 'the green marker is visible in the frame');
+ return { x: sumX / count, y: sumY / count, count };
+}
+
+test('a fixed camera stays locked while a fractured wall flies apart', async () => {
+ const width = 320;
+ const height = 180;
+ 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] },
+ { id: 'marker', geometry: 'slab', material: 'green', translation: [1.5, 0.5, 3], scale: [0.6, 1, 0.6] },
+ ]);
+ recipe.materials.push({ id: 'green', color: [0.1, 0.9, 0.1] });
+ const { sessionId } = await call('scene_create', { recipe });
+ 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 },
+ ] });
+ const result = await submitVideo(sessionId, { width, height, fps: 6, motion: { start: 0 } });
+ const frames = decodedFrames(result.artifacts[0].path, width, height);
+ const first = markerCentroid(frames[0], width, height);
+ const last = markerCentroid(frames[frames.length - 1], width, height);
+ assert.ok(Math.abs(first.x - last.x) < 1 && Math.abs(first.y - last.y) < 1,
+ `the static marker moved on screen from ${JSON.stringify(first)} to ${JSON.stringify(last)}`);
+ await call('scene_dispose', { sessionId });
+});