Skip to content

3D engine that AI agents drive

Show skipped object reflection probes in inspect and apply (#2221)

Nguyen Xuan Anc85ff821c5f4
diff --git a/changes/2221.md b/changes/2221.md
new file mode 100644
index 00000000..d0f9e5ad
--- /dev/null
+++ b/changes/2221.md
@@ -0,0 +1 @@
+- scene_inspect and the scene_apply answer carry a `reflection-skipped` diagnostic when smooth metal keeps only the sky reflection because the automatic object probes were skipped (over 200000 triangles, or too many parts); it names the triangle count, the limit and the fix (#2221).
diff --git a/changes/2221.size.md b/changes/2221.size.md
new file mode 100644
index 00000000..b9390d32
--- /dev/null
+++ b/changes/2221.size.md
@@ -0,0 +1,2 @@
+- scene:agent-scene+lazy: 269 bytes gzip for the reflection-skipped diagnostic and the triangle count in the skip reason, so an agent learns why smooth metal reflects only the sky (#2221).
+- goal:agent-scene: 31 bytes gzip of core wiring (state field and diagnostic hook) that make the skipped reflection probes visible to agents; the diagnostic text itself sits in the lazy reflections module (#2221).
diff --git a/docs/mcp.md b/docs/mcp.md
index 7ab11baf..9a73d811 100644
--- a/docs/mcp.md
+++ b/docs/mcp.md
@@ -191,7 +191,7 @@ Every error an agent can reach names what failed and what to do next. `tests/too
Every tool schema is read on every turn, so `node scripts/measure-tool-cost.mjs` reports the bytes and estimated tokens of each schema and of each typical result, and `npm run tool-cost` fails a pull request when one grows past its allowance against the base branch (`bench/tool-cost/README.md`). The current total is the last line of that script's output, and `bench/tool-cost-ceilings.json` holds the ceiling it may not pass. To save space, a mesh geometry's `edits` and `stack` in a recipe, and `motion` in `scene_apply` and asset recipes, are advertised as plain objects: the full field list is in `mesh_edit`, `mesh_stack` and `scene_create`, and the backend still validates every field and names the valid choices when one is wrong. A small mesh change is far cheaper as `mesh_edit` (187 bytes in the measured case) than as a whole recipe rewrite (1,254 bytes with the dispose).
-`mesh_inspect` lint adds warnings for `intersecting-parts`, `self-intersection`, `thin-wall`, `floating-part` and `asymmetric`. They never set `ok` to false, run within face budgets, and list any check they skipped in `skippedChecks`. `scene_inspect` returns a `diagnostics` list only when there is something to say: ignored material fields, blended transmission, unused materials or geometries, and for imported assets the decoder's not-drawn features, rigs with no joints or no skin, and assets with no clips. Each item has `kind`, `severity`, `target`, `message` and `fix`.
+`mesh_inspect` lint adds warnings for `intersecting-parts`, `self-intersection`, `thin-wall`, `floating-part` and `asymmetric`. They never set `ok` to false, run within face budgets, and list any check they skipped in `skippedChecks`. `scene_inspect` returns a `diagnostics` list only when there is something to say: ignored material fields, blended transmission, unused materials or geometries, `reflection-skipped` (smooth metal keeps only the sky reflection because the automatic object probes were skipped: over 200000 triangles, too many reflective or other parts; the message names the count and the limit, the fix is fewer triangles or `environment.objectReflections` false, and `scene_apply` carries it too), and for imported assets the decoder's not-drawn features, rigs with no joints or no skin, and assets with no clips. Each item has `kind`, `severity`, `target`, `message` and `fix`.
`scene_look` keeps the PNG under the 1 MiB response budget by itself: when a busy picture (planks, bricks, emissive text) encodes over it, the preview renders again at 0.75 of the size, up to four times with the aspect kept, and the metadata names the size that came back (`returnedWidth`, `returnedHeight`, `note`). It fails only when the smallest step still does not fit.
diff --git a/src/agent-reflections.js b/src/agent-reflections.js
index 0d797433..f7192b09 100644
--- a/src/agent-reflections.js
+++ b/src/agent-reflections.js
@@ -1,4 +1,4 @@
-import { traceObjectProbes } from './probe-trace.js';
+import { NO_REFLECTIVE_PART, traceObjectProbes } from './probe-trace.js';
import { placeProbes } from './reflection-probes.js';
// Object reflections: every smooth metal part of a recipe gets a probe of its own, traced from the scene around it, so
@@ -42,7 +42,17 @@ export function stageObjectReflections(cache, recipe, sourceParts, drawnParts, g
return cache;
}
const placed = placeObjectReflections(sourceParts, drawnParts, environment, environmentMap);
- return { key, worldMatrices, sourceParts, drawnParts, result: placed.report.placed > 0 ? placed : null };
+ const skipped = placed.report.placed > 0 || placed.report.skipped === NO_REFLECTIVE_PART ? null : placed.report.skipped ?? null;
+ return { key, worldMatrices, sourceParts, drawnParts, result: placed.report.placed > 0 ? placed : null, skipped };
+}
+
+/** The scene_inspect and scene_apply diagnostic for smooth metal that keeps only the sky reflection because the automatic probes were skipped. */
+export function reflectionSkippedDiagnostic(reason) {
+ return {
+ kind: 'reflection-skipped', severity: 'warning', target: 'environment.objectReflections',
+ message: `Smooth metal parts reflect only the sky: the automatic object reflection probes were skipped (${reason}).`,
+ fix: 'Use fewer triangles or fewer reflective parts so the probes can trace, or set environment.objectReflections to false (scene_apply set-environment) to turn them off and drop this warning.',
+ };
}
function sameFloats(first, second) {
diff --git a/src/agent-scene.js b/src/agent-scene.js
index ab95198a..f809116d 100644
--- a/src/agent-scene.js
+++ b/src/agent-scene.js
@@ -1612,6 +1612,7 @@ export function createAgentScene(input, inputLimits = {}, options = {}) {
let lightBake = null;
// Why the last stage's rebake could not run (a size limit), for the staged state to report.
let skippedBake = null;
+ let skippedReflections = null;
let lightLinkCache = null;
let objectReflectionCache = null;
// Puts the staged graph's matrices back when an edit that moved them in place is refused after the move.
@@ -1845,6 +1846,7 @@ export function createAgentScene(input, inputLimits = {}, options = {}) {
// Parts a pose replaces (cloth, particles, ocean) are new objects with no flush rank, so the pose ranks them again.
rankFlushParts: parts => stageCoplanarOffsets(recipe, parts),
bakeSkipped: skippedBake,
+ reflectionSkipped: skippedReflections,
bakeReport: lightBakeResult ? agentSceneModule('bake').withLocalVolumeReport({ ...lightBakeResult.report, reused: lightBakeResult.reused }, recipe.environment.localVolumes) : null,
reflectionReport: reflected ? reflected.report : null,
// A renderer holding the deformed cloth parts of the old state needs the rest parts back as a topology change.
@@ -1936,10 +1938,12 @@ export function createAgentScene(input, inputLimits = {}, options = {}) {
// Smooth metal parts get a probe of the scene around them (src/agent-reflections.js), unless environment.objectReflections
// is false. It runs only when that code is loaded, which a recipe with a metallic value of 0.5 or more does.
function stageObjectReflections(recipe, sourceRestParts, drawnParts, graph) {
+ skippedReflections = null;
if (recipe.environment.objectReflections === false || !agentSceneModuleLoaded('reflections')) {
return null;
}
objectReflectionCache = agentSceneModule('reflections').stageObjectReflections(objectReflectionCache, recipe, sourceRestParts, drawnParts, graph, agentEnvironmentMap(recipe.environment));
+ skippedReflections = objectReflectionCache.skipped;
return objectReflectionCache.result;
}
@@ -2398,7 +2402,7 @@ export function createAgentScene(input, inputLimits = {}, options = {}) {
return result;
});
const resident = geometryStats(ownedGeometryRecords());
- const diagnostics = [...recipeDiagnostics(state.recipe), ...closedRoomProblems(), ...staleBakeProblems(), ...(state.bakeSkipped ? [agentSceneModule('bake').bakeSkippedDiagnostic(state.bakeSkipped)] : []),...coplanarProblems(), ...(state.particleSampler?.diagnostics() ?? [])];
+ const diagnostics = [...recipeDiagnostics(state.recipe), ...closedRoomProblems(), ...staleBakeProblems(), ...(state.bakeSkipped ? [agentSceneModule('bake').bakeSkippedDiagnostic(state.bakeSkipped)] : []), ...(state.reflectionSkipped ? [agentSceneModule('reflections').reflectionSkippedDiagnostic(state.reflectionSkipped)] : []),...coplanarProblems(), ...(state.particleSampler?.diagnostics() ?? [])];
return {
revision, topologyRevision,
...(state.recipe.motion?.ik?.length ? { motionIk: agentSceneModule('motion').compileAgentMotion(state.recipe.motion, state.recipe).sweepIk() } : {}),
diff --git a/src/probe-trace.js b/src/probe-trace.js
index e748cbb3..527ca2ca 100644
--- a/src/probe-trace.js
+++ b/src/probe-trace.js
@@ -13,6 +13,8 @@ export const MAXIMUM_PROBES = 4;
// Probes and the irradiance grid trace on the CPU, and their work grows with the node count, samples and the time limit rather
// than with the part count, so they take as many parts as the GPU lightmap bake does (#1218).
export const MAX_PROBE_GRID_PARTS = 1024;
+/** The skip reason of a scene that has nothing to reflect: not a problem, so no diagnostic follows it. */
+export const NO_REFLECTIVE_PART = 'no reflective part';
export const PROBE_MAP_WIDTH = 64;
// An automatic probe is only worth placing in a room: below this share of rays hitting a part the scene is open air.
export const ENCLOSED_HIT_FRACTION = 0.9;
@@ -300,9 +302,10 @@ export function traceObjectProbes(parts, lighting, options = {}) {
// Many small metal parts (lamp posts, spires) read as shapes and not as mirrors, and each probe costs a trace and a draw batch.
const tooManyOthers = parts.length - 1 > MAX_PROBE_GRID_PARTS;
// The probe trace builds a triangle world that takes at most MAX_BAKE_TRIANGLES; a big scene keeps its sky reflection instead of failing the edit.
- const tooManyTriangles = reflective.length > 0 && countTriangles(parts) > MAX_BAKE_TRIANGLES;
+ const triangleCount = reflective.length > 0 ? countTriangles(parts) : 0;
+ const tooManyTriangles = triangleCount > MAX_BAKE_TRIANGLES;
const wanted = reflective.length > MAXIMUM_OBJECT_PROBES || tooManyOthers || tooManyTriangles ? [] : reflective;
- const skipped = wanted.length > 0 ? null : reflective.length > MAXIMUM_OBJECT_PROBES ? `more than ${MAXIMUM_OBJECT_PROBES} reflective parts` : tooManyOthers ? `more than ${MAX_PROBE_GRID_PARTS} other parts` : tooManyTriangles ? `more than ${MAX_BAKE_TRIANGLES} triangles for the automatic object reflection probes (set environment.objectReflections to false to silence this)` : 'no reflective part';
+ const skipped = wanted.length > 0 ? null : reflective.length > MAXIMUM_OBJECT_PROBES ? `more than ${MAXIMUM_OBJECT_PROBES} reflective parts` : tooManyOthers ? `more than ${MAX_PROBE_GRID_PARTS} other parts` : tooManyTriangles ? `${triangleCount} triangles, more than the ${MAX_BAKE_TRIANGLES} the automatic object reflection probes take` : NO_REFLECTIVE_PART;
if (wanted.length === 0 || parts.length < 2) {
return { traced: [], automatic: true, requested: reflective.length, skipped, seconds: 0 };
}
diff --git a/tests/agent-object-reflections.test.js b/tests/agent-object-reflections.test.js
index 2c73dfd8..15876848 100644
--- a/tests/agent-object-reflections.test.js
+++ b/tests/agent-object-reflections.test.js
@@ -95,3 +95,33 @@ test('a metallic scene over the bake triangle limit applies and skips the automa
const revision = scene.inspect().revision;
scene.apply([{ type: 'add-material', material: { id: 'iron', color: [0.04, 0.04, 0.05], roughness: 0.2, metallic: 0.6 } }], { expectedRevision: revision });
});
+
+function overTheTriangleLimit() {
+ const recipe = stillLife();
+ recipe.geometries.push({ id: 'dense', type: 'sphere', segments: 400, rings: 300 });
+ recipe.nodes.push({ id: 'dense', geometry: 'dense', material: 'floor', translation: [2, 0.5, 0], scale: [0.5, 0.5, 0.5] });
+ return recipe;
+}
+
+function skipDiagnostic(scene) {
+ return (scene.inspect().diagnostics ?? []).find(diagnostic => diagnostic.kind === 'reflection-skipped');
+}
+
+test('skipped automatic probes show in scene_inspect with the triangle count, the limit and the fix (#2221)', () => {
+ const scene = createAgentScene(overTheTriangleLimit());
+ const warning = skipDiagnostic(scene);
+ assert.equal(warning.severity, 'warning');
+ assert.match(warning.message, /\d{6} triangles, more than the 200000/);
+ assert.match(warning.fix, /environment\.objectReflections to false/);
+ assert.match(warning.fix, /fewer triangles/);
+
+ scene.apply([{ type: 'set-camera', fov: 40 }], { expectedRevision: scene.inspect().revision });
+ assert.ok(skipDiagnostic(scene), 'an unrelated edit keeps the warning');
+ scene.apply([{ type: 'set-environment', environment: { objectReflections: false } }], { expectedRevision: scene.inspect().revision });
+ assert.equal(skipDiagnostic(scene), undefined, 'turning the probes off clears it');
+});
+
+test('scenes with probes placed, or with nothing to reflect, carry no reflection-skipped diagnostic (#2221)', () => {
+ assert.equal(skipDiagnostic(createAgentScene(stillLife())), undefined);
+ assert.equal(skipDiagnostic(createAgentScene(stillLife(0.9))), undefined);
+});