3D engine that AI agents drive
JavaScript 3d3d-engineagentic-aiai-agentsblenderclaude-codegame-enginegaussian-splattinggltfjavascriptmcpmcp-servermodel-context-protocolpath-tracerpath-tracingpbrrenderingthreejs-alternativewebgl2webgpu
Name the field and value the caller sent in two errors (#2051)
Nguyen Xuan An5bd9c86969dd
diff --git a/changes/2051.md b/changes/2051.mdnew file mode 100644index 00000000..ccc57923--- /dev/null+++ b/changes/2051.md@@ -0,0 +1 @@+- A scene_look motionTime on a scene with nothing to animate now reports `motionTime: got <your value>`, and the stills duration error leads with the fix and a rounded value (#2051)diff --git a/scripts/agent-preview-browser.js b/scripts/agent-preview-browser.jsindex c8cbbdcb..78898af2 100644--- a/scripts/agent-preview-browser.js+++ b/scripts/agent-preview-browser.js@@ -31,6 +31,7 @@ import { assetCopyKey, recipeAssetNeeds } from '../src/agent-scene-assets.js';import { exportGlb } from '../src/export.js';import '../src/texture-update.js';import { staleRevisionMessage } from '../src/agent-errors.js';+import { sampleMotionAtZeroForGround } from './motion-ground-sample.js';import { updatePartVertices } from '../src/update-part-vertices.js';import { rasterOptionsFor } from './agent-render-quality.mjs';import { hasPatternTextures } from './agent-preview-textures.js';@@ -357,7 +358,7 @@ function automaticGroundPlacement(scene) {function sampleMotionTime(scene, time) {if (motionGrounds.get(scene)?.revision !== scene.revision) {- scene.sampleMotion(0);+ sampleMotionAtZeroForGround(scene, time);motionGrounds.set(scene, { revision: scene.revision, placement: agentGroundPlacement(scene.parts, scene.environment) });}scene.sampleMotion(time);diff --git a/scripts/agent-render-jobs.mjs b/scripts/agent-render-jobs.mjsindex ae1f4fc2..5300831d 100644--- a/scripts/agent-render-jobs.mjs+++ b/scripts/agent-render-jobs.mjs@@ -204,7 +204,7 @@ function stillsFrameCountFrom(input) {function stillsSequenceDuration(input, frames, fps) {const span = (frames - 1) / fps;if (input.duration !== undefined && Math.abs(input.duration - span) > 1e-9) {- throw new RangeError(`duration is (stillCount - 1) / fps = ${span} s when stillCount is set; leave duration out.`);+ throw new RangeError(`Leave duration out when stillCount is set: it is (stillCount - 1) / fps = ${Number(span.toFixed(4))} s here, and you sent ${input.duration}.`);}return span;}diff --git a/scripts/motion-ground-sample.js b/scripts/motion-ground-sample.jsnew file mode 100644index 00000000..71aee3b0--- /dev/null+++ b/scripts/motion-ground-sample.js@@ -0,0 +1,15 @@+import { invalidField } from '../src/field-error.js';++// The preview samples a scene at 0 to place its automatic floor before it samples the time the caller asked for. A scene+// with nothing to sample refuses that 0 with a field named `time`, which the caller never sent, so the refusal is+// restated against the motionTime they did send.+export function sampleMotionAtZeroForGround(scene, requestedMotionTime) {+ try {+ scene.sampleMotion(0);+ } catch (error) {+ if (error.fieldPath !== 'time') {+ throw error;+ }+ throw invalidField('motionTime', requestedMotionTime, 'null, because this scene has no motion, physics, cloth, particles, placed asset clip or grid volume frames to sample; add motion first');+ }+}diff --git a/tests/agent-render-output.test.js b/tests/agent-render-output.test.jsindex ae982364..deed93aa 100644--- a/tests/agent-render-output.test.js+++ b/tests/agent-render-output.test.js@@ -149,7 +149,8 @@ test('stillCount needs stills, stays under its cap and names the cap and what toconst controller = await withController(context, recordingRunner([]));await assert.rejects(controller.submit(submission({ kind: 'video', width: 64, height: 64, stillCount: 4 })), /stillCount needs kind stills/);await assert.rejects(controller.submit(submission({ kind: 'stills', width: 64, height: 64, stillCount: 301 })), /render a longer clip in parts, each from its own motion\.start\) must be within 2 and 300/);- await assert.rejects(controller.submit(submission({ kind: 'stills', width: 64, height: 64, stillCount: 10, fps: 10, duration: 5 })), /leave duration out/);+ await assert.rejects(controller.submit(submission({ kind: 'stills', width: 64, height: 64, stillCount: 10, fps: 10, duration: 5 })), /Leave duration out when stillCount is set: it is \(stillCount - 1\) \/ fps = 0\.9 s here, and you sent 5\.$/);+ await assert.rejects(controller.submit(submission({ kind: 'stills', width: 64, height: 64, stillCount: 3, duration: 5 })), /= 0\.0833 s here, and you sent 5\.$/);await assert.rejects(controller.submit(submission({ kind: 'stills', width: 1500, height: 1500 })), /square frame fits up to 1440x1440/);});diff --git a/tests/motion-ground-sample.test.js b/tests/motion-ground-sample.test.jsnew file mode 100644index 00000000..1eae232e--- /dev/null+++ b/tests/motion-ground-sample.test.js@@ -0,0 +1,31 @@+import './support/load-agent-scene-modules.mjs';+import test from 'node:test';+import assert from 'node:assert/strict';+import { createAgentScene } from '../src/agent-scene.js';+import { sampleMotionAtZeroForGround } from '../scripts/motion-ground-sample.js';++// Issue 2051: scene_look with motionTime 1 on a scene with nothing to animate reported "time: got 0".++const recipe = {+ format: 'crucible.scene',+ schemaVersion: 1,+ geometries: [{ id: 'cube', type: 'box', bevel: 0 }],+ materials: [{ id: 'paint', color: [0.8, 0.2, 0.2] }],+ nodes: [{ id: 'box', geometry: 'cube', material: 'paint' }],+};++test('a scene with nothing to sample refuses the motionTime the caller sent, not a time of 0', () => {+ const scene = createAgentScene(recipe);+ assert.throws(() => sampleMotionAtZeroForGround(scene, 1), error => {+ assert.ok(error instanceof RangeError);+ assert.match(error.message, /^motionTime: got 1; expected null, because this scene has no motion/);+ assert.equal(error.fieldPath, 'motionTime');+ return true;+ });+});++test('an error that is not about the sampled time passes through unchanged', () => {+ const failure = new TypeError('boom');+ const scene = { sampleMotion() { throw failure; } };+ assert.throws(() => sampleMotionAtZeroForGround(scene, 1), error => error === failure);+});