Skip to content

3D engine that AI agents drive

Skip automatic object probes past the bake triangle limit (#2202)

Nguyen Xuan An6f0886ecce32
diff --git a/changes/2202.md b/changes/2202.md
new file mode 100644
index 00000000..a7e982de
--- /dev/null
+++ b/changes/2202.md
@@ -0,0 +1 @@
+- A scene with more than 200000 triangles and a smooth metal part no longer fails with "Light bake takes at most 200000 triangles" when no bake was asked for: the automatic object reflection probes are skipped and the sky reflection stays (#2202).
diff --git a/changes/2202.size.md b/changes/2202.size.md
new file mode 100644
index 00000000..1354bf72
--- /dev/null
+++ b/changes/2202.size.md
@@ -0,0 +1 @@
+- scene:agent-scene+lazy: 83 bytes gzip for the triangle check that keeps big metallic scenes from failing on the automatic probes (#2202).
diff --git a/src/probe-trace.js b/src/probe-trace.js
index 00a284cb..e748cbb3 100644
--- a/src/probe-trace.js
+++ b/src/probe-trace.js
@@ -2,7 +2,7 @@ import { computeIrradianceCoefficients, evaluateIrradiance } from './environment
import { createTracer } from './ray-query.js';
import { isLiveGeometry } from './live-geometry.js';
import {
- averageMapColor, buildWorld, createDirectIrradiance, createGatherer, emittedRadiance, hitNormal, normalizeLights, sceneScale, validatePart, withReach,
+ MAX_BAKE_TRIANGLES, averageMapColor, buildWorld, createDirectIrradiance, createGatherer, emittedRadiance, hitNormal, normalizeLights, sceneScale, validatePart, withReach,
} from './light-bake.js';
// The half of reflection probes that needs no GPU and no renderer: validating a probe list, placing the automatic probe
@@ -277,6 +277,10 @@ function skyMissRadiance(environment) {
};
}
+function countTriangles(parts) {
+ return parts.reduce((total, part) => total + part.geometry.indices.length / 3, 0);
+}
+
/** A part that shows its surroundings: metal with a smooth enough surface for a reflection to read as a picture. */
export function isReflectivePart(material) {
return (material.metallic ?? 0) >= OBJECT_PROBE_MINIMUM_METALLIC && (material.roughness ?? 1) <= OBJECT_PROBE_MAXIMUM_ROUGHNESS;
@@ -295,8 +299,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;
- const wanted = reflective.length > MAXIMUM_OBJECT_PROBES || tooManyOthers ? [] : 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` : 'no reflective part';
+ // 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 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';
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 60ce5511..2c73dfd8 100644
--- a/tests/agent-object-reflections.test.js
+++ b/tests/agent-object-reflections.test.js
@@ -84,3 +84,14 @@ test('the object reflection cache is replaced when only the physical sky changes
const withoutSunDisc = stageObjectReflections(first, withSky({ ...recipe.environment.sky, sunDisc: false }), sourceParts, sourceParts, graph, null);
assert.notEqual(withoutSunDisc, first);
});
+
+test('a metallic scene over the bake triangle limit applies and skips the automatic probes (#2202)', () => {
+ 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] });
+ const scene = createAgentScene(recipe);
+ assert.equal(scene.inspect().reflections, undefined);
+ assert.ok(scene.parts.every(part => part.material.environmentProbe === undefined));
+ 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 });
+});