Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Place reflection probes on smooth metal parts by default (part of #167)

Nguyen Xuan An3b5911b350e3
diff --git a/bench/reference/README.md b/bench/reference/README.md
index 53e39f8a..de955835 100644
--- a/bench/reference/README.md
+++ b/bench/reference/README.md
@@ -230,7 +230,7 @@ A probe at the middle of the object and traced without it is the only option the
`traceObjectProbes(parts, lighting, options)` in `src/probe-trace.js` finds the parts with `metallic` of at least 0.5 and `roughness` of at most 0.6, traces one 128 by 64 map at the middle of each one's bounds with that part left out, and returns the same shape as `traceProbes` plus the index of the part. `placeProbes` gives each such part its own probe. More than 8 reflective parts (lamp posts, spires) get none, because they read as shapes and not as mirrors. A trace shades a hit with the direct light, the part's colour (half the colour for metal) and the environment map's diffuse light. A ray that misses reads the environment map.
-`npm run reference -- --object-probes [<id>,<id>]` places these probes on the named scenes (every scene when no ids follow). It is opt in, like `--bake` and `--probes`, and the committed `baseline.json` and `images/` are the default run without it (`metal` 0.1294 again, confirmed on 2026-11-02). The scores below are from a full run with the flag. There is no recipe field: a recipe scene does not place object probes yet, because the recipe path has no map of the sky to light the floor in the reflection (the procedural sky is a colour gradient), and that is the next piece of work.
+Object probes are now the default, as a recipe places them (`src/agent-reflections.js`, lit by the setup map); `environment.objectReflections: false` turns them off. `npm run reference` draws every scene with them, `-- --no-object-probes` without, and `-- --object-probes <id>,<id>` limits them to the named scenes. The committed `baseline.json` and `images/` are the default run (`metal` 0.1036 against 0.1294 without probes; 2026-11-03). Three tries to close the rest of the gap to EEVEE (0.0916) all scored worse and were not kept: one bounce at 64 samples (0.1246), seeing through the part itself so it still shadows what it shows (0.1117), and scaling the sky light of the shown surface by its sky visibility (0.1185).
### Scores against Cycles with `--object-probes` (GPU, full rescore, 2026-11-02)
diff --git a/bench/reference/baseline.json b/bench/reference/baseline.json
index de5c25f3..2bebda50 100644
--- a/bench/reference/baseline.json
+++ b/bench/reference/baseline.json
@@ -75,7 +75,7 @@
"eevee": 41.9
},
"mountain-valley": {
- "cycles": 13.0,
+ "cycles": 13,
"eevee": 28.3
},
"outdoor-hdri": {
@@ -121,18 +121,18 @@
"gpu-vs-cpu": 0.0071
},
"brushed-film": {
- "gpu-vs-cycles": 0.1149,
- "gpu-vs-eevee": 0.1004,
- "cpu-vs-cycles": 0.1146,
- "cpu-vs-eevee": 0.1004,
+ "gpu-vs-cycles": 0.1029,
+ "gpu-vs-eevee": 0.0855,
+ "cpu-vs-cycles": 0.1026,
+ "cpu-vs-eevee": 0.0854,
"eevee-vs-cycles": 0.0984,
- "gpu-vs-cpu": 0.0061
+ "gpu-vs-cpu": 0.0062
},
"car-paint": {
- "gpu-vs-cycles": 0.1059,
- "gpu-vs-eevee": 0.0679,
- "cpu-vs-cycles": 0.1056,
- "cpu-vs-eevee": 0.0679,
+ "gpu-vs-cycles": 0.1038,
+ "gpu-vs-eevee": 0.065,
+ "cpu-vs-cycles": 0.1035,
+ "cpu-vs-eevee": 0.065,
"eevee-vs-cycles": 0.0844,
"gpu-vs-cpu": 0.0059
},
@@ -225,10 +225,10 @@
"gpu-vs-cpu": 0.0095
},
"material-spheres": {
- "gpu-vs-cycles": 0.1312,
- "gpu-vs-eevee": 0.0748,
- "cpu-vs-cycles": 0.131,
- "cpu-vs-eevee": 0.0745,
+ "gpu-vs-cycles": 0.1293,
+ "gpu-vs-eevee": 0.0756,
+ "cpu-vs-cycles": 0.1291,
+ "cpu-vs-eevee": 0.0753,
"eevee-vs-cycles": 0.1053,
"gpu-vs-cpu": 0.007
},
@@ -241,20 +241,20 @@
"gpu-vs-cpu": 0.0281
},
"metal": {
- "gpu-vs-cycles": 0.1294,
- "gpu-vs-eevee": 0.0952,
- "cpu-vs-cycles": 0.1291,
- "cpu-vs-eevee": 0.0953,
+ "gpu-vs-cycles": 0.1036,
+ "gpu-vs-eevee": 0.0782,
+ "cpu-vs-cycles": 0.1033,
+ "cpu-vs-eevee": 0.0783,
"eevee-vs-cycles": 0.0916,
- "gpu-vs-cpu": 0.0067
+ "gpu-vs-cpu": 0.0064
},
"metal-room": {
- "gpu-vs-cycles": 0.5128,
- "gpu-vs-eevee": 0.108,
- "cpu-vs-cycles": 0.5124,
- "cpu-vs-eevee": 0.1086,
+ "gpu-vs-cycles": 0.5076,
+ "gpu-vs-eevee": 0.1082,
+ "cpu-vs-cycles": 0.5072,
+ "cpu-vs-eevee": 0.1088,
"eevee-vs-cycles": 0.5262,
- "gpu-vs-cpu": 0.0061
+ "gpu-vs-cpu": 0.0062
},
"mountain-valley": {
"gpu-vs-cycles": 0.2623,
diff --git a/bench/reference/images/brushed-film.jpg b/bench/reference/images/brushed-film.jpg
index 1d518448..3dbdab84 100644
Binary files a/bench/reference/images/brushed-film.jpg and b/bench/reference/images/brushed-film.jpg differ
diff --git a/bench/reference/images/car-paint.jpg b/bench/reference/images/car-paint.jpg
index ccf683a4..45f76e61 100644
Binary files a/bench/reference/images/car-paint.jpg and b/bench/reference/images/car-paint.jpg differ
diff --git a/bench/reference/images/material-spheres.jpg b/bench/reference/images/material-spheres.jpg
index 58400c5f..efc2f507 100644
Binary files a/bench/reference/images/material-spheres.jpg and b/bench/reference/images/material-spheres.jpg differ
diff --git a/bench/reference/images/metal-room.jpg b/bench/reference/images/metal-room.jpg
index 06a8d1fc..7a659b32 100644
Binary files a/bench/reference/images/metal-room.jpg and b/bench/reference/images/metal-room.jpg differ
diff --git a/bench/reference/images/metal.jpg b/bench/reference/images/metal.jpg
index c5770a51..d75f90cf 100644
Binary files a/bench/reference/images/metal.jpg and b/bench/reference/images/metal.jpg differ
diff --git a/bench/reference/run.mjs b/bench/reference/run.mjs
index 19cb1efa..5ac341b8 100644
--- a/bench/reference/run.mjs
+++ b/bench/reference/run.mjs
@@ -62,7 +62,8 @@ const bakePreset = bakePresetFlag >= 0 ? argumentsGiven[bakePresetFlag + 1] : nu
const probesFlag =argumentsGiven.indexOf('--probes');
const probesValue = probesFlag >= 0 ? argumentsGiven[probesFlag + 1] : undefined;
const probedSceneIds = probesFlag >= 0 && probesValue && !probesValue.startsWith('--') ? probesValue.split(',') : null;
-// --object-probes [<id>,<id>] gives each reflective part of the named scenes (every scene when no ids follow) a probe of its own (traceObjectProbes).
+// Each reflective part gets a probe of its own (traceObjectProbes), as a recipe gives it by default. --no-object-probes draws the scenes without them,
+// and --object-probes <id>,<id> limits them to the named scenes.
const objectProbesFlag = argumentsGiven.indexOf('--object-probes');
const objectProbesValue = objectProbesFlag >= 0 ? argumentsGiven[objectProbesFlag + 1] : undefined;
const objectProbeSceneIds = objectProbesFlag >= 0 && objectProbesValue && !objectProbesValue.startsWith('--') ? objectProbesValue.split(',') : null;
@@ -99,9 +100,9 @@ async function renderBackend(backend, serverUrl, graphics) {
const describe = backend === 'gpu';
const probesThisScene = probesFlag >= 0 && (probedSceneIds === null || probedSceneIds.includes(id));
const bakesThisScene = bakeFlag >= 0 && (bakedSceneIds === null || bakedSceneIds.includes(id));
- // Object probes are opt in: a recipe does not place them yet, so the baseline scores what a user gets by default.
- const objectProbesThisScene = objectProbesFlag >= 0 && (objectProbeSceneIds === null || objectProbeSceneIds.includes(id));
- const probes = objectProbesThisScene ? 'objects' : probesThisScene;
+ // Object probes are on by default, as in a recipe, so the baseline scores what a user gets.
+ const objectProbesThisScene = !argumentsGiven.includes('--no-object-probes') && (objectProbeSceneIds === null || objectProbeSceneIds.includes(id));
+ const probes = probesThisScene || (objectProbesThisScene ? 'objects' : false);
const bake = bakesThisScene ? { ...skyOnlyOptions, ...(bakePreset ? { preset: bakePreset } : {}) } : null;
const result = await page.evaluate(([sceneId, shouldDescribe, ambientOcclusion, ambientOcclusionRadius, bakeOptions, cascadeCount, withProbes, ambientScale]) => window.renderReferenceScene(sceneId, { describe: shouldDescribe, ambientOcclusion, ambientOcclusionRadius, bake: bakeOptions, cascades: cascadeCount, probes: withProbes, ambient: ambientScale }), [id, describe, ambientOcclusion, ambientOcclusionRadius, bake, cascades, probes, ambient]);
if (result.glError !== 0) throw new Error(`${id} on ${backend} gave WebGL error ${result.glError}.`);
diff --git a/bench/size/budgets.json b/bench/size/budgets.json
index 9460c440..7818eec7 100644
--- a/bench/size/budgets.json
+++ b/bench/size/budgets.json
@@ -33,7 +33,7 @@
"entry:light-bake": 28500,
"entry:path-tracer": 14600,
"entry:texture-set": 900,
- "entry:agent-scene": 76500,
+ "entry:agent-scene": 77200,
"entry:agent-scene+lazy": 259200,
"entry:agent-asset": 108500,
"entry:agent-asset+lazy": 270800,
@@ -47,7 +47,7 @@
"scene:lit-box": 62800,
"scene:gltf-box": 84200,
"scene:gltf-box+lazy": 87600,
- "scene:agent-scene": 103300,
+ "scene:agent-scene": 104000,
"scene:agent-scene+lazy": 286000
}
}
diff --git a/changes/issue-167.md b/changes/issue-167.md
new file mode 100644
index 00000000..42e4023e
--- /dev/null
+++ b/changes/issue-167.md
@@ -0,0 +1 @@
+- Give smooth metal parts a reflection probe by default (part of issue #167, which stays open). A recipe part with `metallic` 0.5 or more and `roughness` 0.6 or less (up to 8 such parts) now gets a probe traced from the scene around it, so a chrome sphere shows the floor and its neighbours; `environment.objectReflections: false` turns it off and `scene_inspect` reports `reflections`. Against Cycles `metal` goes from 0.1294 to 0.1036 (EEVEE 0.0916), `brushed-film` 0.1149 to 0.1029, `car-paint` 0.1059 to 0.1038, `material-spheres` 0.1312 to 0.1293 and `metal-room` 0.5128 to 0.5076. A scene with no reflective part draws the same parts and keeps its frame time; `metal` costs about 0.03 ms more on the GPU.
diff --git a/docs/agent-look.md b/docs/agent-look.md
index fd93a6f2..8511a84b 100644
--- a/docs/agent-look.md
+++ b/docs/agent-look.md
@@ -107,6 +107,7 @@ Sky colors use display RGB, matching the renderer's existing environment contrac
| --- | --- | --- |
| `world` | `false` | Boolean world presentation flag. With `true` the setup environment is also the background |
| `ground` | on | Absent unless set. `false` removes the preview's automatic floor and contact shadow |
+| `objectReflections` | on | Absent unless set. Each smooth metal part (`metallic` 0.5 or more, `roughness` 0.6 or less; at most 8 such parts) gets a reflection probe of the scene around it, so a chrome sphere shows the floor and its neighbours. `false` turns it off. Probes are traced at rest, so a part that moves reflects the scene as it started. `scene_inspect` names them in `reflections` |
| `setup` | `daylight` | `daylight`, `overcast`, `sunset` or `studio`. See Lighting setups |
| `environmentIntensity` | `1` | `0` to `100`. Scales the setup's environment light and reflections |
| `environmentRotation` | `0` | `-100` to `100` radians around the vertical axis |
diff --git a/src/agent-look.js b/src/agent-look.js
index b8047577..b1281597 100644
--- a/src/agent-look.js
+++ b/src/agent-look.js
@@ -8,7 +8,7 @@ import { DEFAULT_LIGHTING_SETUP, LIGHTING_SETUP_NAMES, DEFAULT_AMBIENT_OCCLUSION
const ENVIRONMENT_FIELDS = [
'world', 'ground', 'setup', 'environmentIntensity', 'environmentRotation', 'lightDirection', 'keyColor', 'keyIntensity', 'fillIntensity', 'ambientIntensity',
- 'daylight', 'pointLights', 'spotLights', 'areaLights', 'skyTop', 'skyBottom', 'fogColor', 'fogDensity', 'volumeFog', 'liquid', 'shadowCascades', 'keyAffects',
+ 'daylight', 'pointLights', 'spotLights', 'areaLights', 'skyTop', 'skyBottom', 'fogColor', 'fogDensity', 'volumeFog', 'liquid', 'shadowCascades', 'keyAffects', 'objectReflections',
];
const LIQUID_FIELDS = ['thickness', 'ior', 'refraction', 'scattering', 'foamOpacity', 'foamSoftness'];
const EFFECT_FIELDS = ['exposure', 'saturation', 'contrast', 'temperature', 'vignette', 'grain', 'ambientOcclusion', 'ambientOcclusionRadius', 'bloom', 'depthOfField', 'motionBlur'];
@@ -262,6 +262,12 @@ function environmentFrom(input = {}) {
}
environment.ground = input.ground;
}
+ if (input.objectReflections !== undefined) {
+ if (typeof input.objectReflections !== 'boolean') {
+ throw new TypeError('environment.objectReflections must be a boolean.');
+ }
+ environment.objectReflections = input.objectReflections;
+ }
if (input.spotLights !== undefined) {
environment.spotLights = lightListFrom(input.spotLights, MAX_SPOT_LIGHTS, 'spotLights').map(spotLightFrom);
}
diff --git a/src/agent-reflections.js b/src/agent-reflections.js
new file mode 100644
index 00000000..4bfb9c42
--- /dev/null
+++ b/src/agent-reflections.js
@@ -0,0 +1,45 @@
+import { 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
+// a chrome sphere shows the floor and its neighbours and not only the sky. A scene with no such part never loads this
+// module, and one that has it pays one small trace when the parts, lights or materials change.
+
+/**
+ * Places an object probe on each reflective part. `sourceParts` hold world matrices at rest and are what the probes see;
+ * `drawnParts` are the same parts after any bake, and the result keeps their order.
+ * Returns the parts as given when the scene has nothing to reflect (no reflective part, one part, or too many reflective
+ * parts), with a report that says why.
+ */
+export function placeObjectReflections(sourceParts, drawnParts, environment, environmentMap) {
+ const sunScale = environment.keyIntensity ?? 1;
+ const lighting = {
+ pointLights: environment.pointLights,
+ spotLights: environment.spotLights,
+ areaLights: environment.areaLights,
+ keyColor: Array.from(environment.keyColor, channel => channel * sunScale),
+ lightDirection: environment.lightDirection,
+ };
+ const trace = traceObjectProbes(sourceParts, lighting, { environment, environmentMap, rotation: environmentMap?.rotation ?? 0 });
+ if (trace.traced.length === 0) {
+ return { parts: drawnParts, report: { placed: 0, skipped: trace.skipped } };
+ }
+ const placed = placeProbes(drawnParts, trace, { rotation: environmentMap?.rotation ?? 0 });
+ return { parts: placed.parts, report: { placed: placed.report.placed.length, partsWithProbe: placed.report.partsWithProbe, seconds: trace.seconds } };
+}
+
+/**
+ * The recipe stage: places the probes, and traces again only when the parts, lights, setup or materials change.
+ * `cache` is what the last call returned (or null); the result of the new call is its `result`, null when no part got a probe.
+ */
+export function stageObjectReflections(cache, recipe, sourceParts, drawnParts, graph, environmentMap) {
+ const { environment } = recipe;
+ const worldMatrices = sourceParts.map(part => Array.from(graph.getNode(part.name).worldMatrix));
+ const key = JSON.stringify([environment.pointLights, environment.spotLights, environment.areaLights, environment.keyColor, environment.keyIntensity, environment.lightDirection,
+ environment.skyTop, environment.skyBottom, environment.setup, environment.environmentIntensity, environment.environmentRotation, recipe.materials, worldMatrices]);
+ if (cache?.key === key && cache.sourceParts === sourceParts && cache.drawnParts === drawnParts) {
+ return cache;
+ }
+ const placed = placeObjectReflections(sourceParts, drawnParts, environment, environmentMap);
+ return { key, sourceParts, drawnParts, result: placed.report.placed > 0 ? placed : null };
+}
diff --git a/src/agent-scene-capabilities.js b/src/agent-scene-capabilities.js
index cc5bafe6..8eae4128 100644
--- a/src/agent-scene-capabilities.js
+++ b/src/agent-scene-capabilities.js
@@ -252,7 +252,7 @@ export const AGENT_SCENE_CAPABILITIES = Object.freeze({
bake: Object.freeze({
fields: 'preset, or samples (1-256), bounces (1-3), texelsPerUnit (1-12) over it; probes room by default, false for none, or up to 4 {position, radius?}. Same recipe, same bytes.',
presets: BAKE_PRESETS,
- notes: 'Bounced light from point, spot, area and key lights. Reruns when parts, lights, materials or bake change. Skips alpha, skin, morph, hair, cloth (bake.skipped). A preset shrinks to fit, never refuses (bake.used, bake.reduction); explicit settings fail over maxPathWork or past maxSeconds. No environment map or specular. Probes (off by default): specular only, none in glTF.',
+ notes: 'Bounced light from point, spot, area and key lights. Reruns when parts, lights, materials or bake change. Skips alpha, skin, morph, hair, cloth (bake.skipped). A preset shrinks to fit, never refuses (bake.used, bake.reduction); explicit settings fail over maxPathWork or past maxSeconds. No environment map or specular. Probes: specular only, none in glTF.',
limits: Object.freeze({ maxSeconds: BAKE_MAXIMUM_SECONDS, workerMaxSeconds: BAKE_WORKER_MAXIMUM_SECONDS, maxPathWork: BAKE_EXPLICIT_PATH_WORK_LIMIT, maxPointLights: 8 }),
}),
motionLimits: Object.freeze({ maxTracks: 128, maxKeyframesPerTrack: 64, maxKeyframes: 2048, maxDuration: 30 }),
diff --git a/src/agent-scene-modules.js b/src/agent-scene-modules.js
index 2178ecd9..7f6a43eb 100644
--- a/src/agent-scene-modules.js
+++ b/src/agent-scene-modules.js
@@ -12,6 +12,7 @@ const MODULE_LOADERS = {
cloth: () => import('./agent-cloth.js'),
particles: () => import('./agent-particles.js'),
bake: () => import('./agent-bake.js'),
+ reflections: () => import('./agent-reflections.js'),
patterns: () => import('./material-patterns.js'),
relations: () => import('./agent-relations.js'),
timeline: () => import('./film-timeline.js'),
@@ -37,6 +38,8 @@ const MODULE_MARKERS = {
cloth: ['"cloth":{'],
particles: ['"particles":{'],
bake: ['"bake":{'],
+ // A metallic value of 0.5 or more may make a part reflective; the module skips a scene that has no smooth one.
+ reflections: [/"metallic":(0\.[5-9]|1(?![0-9]))/],
patterns: ['"pattern"'],
relations: ['"relations":'],
timeline: ['"timeline":{'],
@@ -67,7 +70,7 @@ export function agentSceneModulesNeeded(value) {
return Object.keys(MODULE_LOADERS);
}
const compact = text.replace(/"\s*:\s*/g, '":');
- return Object.keys(MODULE_MARKERS).filter(name => MODULE_MARKERS[name].some(marker => compact.includes(marker)));
+ return Object.keys(MODULE_MARKERS).filter(name => MODULE_MARKERS[name].some(marker => (marker instanceof RegExp ? marker.test(compact) : compact.includes(marker))));
}
function loadModule(name) {
diff --git a/src/agent-scene.js b/src/agent-scene.js
index c3b8b56f..3bc1912b 100644
--- a/src/agent-scene.js
+++ b/src/agent-scene.js
@@ -2,8 +2,8 @@ import { mat4, mat3 } from 'gl-matrix';
import { box, cylinder, grid, sphere, torus } from './geometry.js';
import { createSceneGraph } from './scene-graph.js';
import { applyProjection } from './camera.js';
-import { normalizeAgentLook, environmentPatchWithSetup, environmentLinksLights } from './agent-look.js';
-import { agentSceneModule } from './agent-scene-modules.js';
+import { normalizeAgentLook, environmentPatchWithSetup, environmentLinksLights, agentEnvironmentMap } from './agent-look.js';
+import { agentSceneModule, agentSceneModuleLoaded } from './agent-scene-modules.js';
import { MESH_SMOOTH_ANGLE_DEFAULT, CURVE_TEXT_LIMITS, AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS, MAX_MATERIAL_PATTERNS, RECIPE_ALPHA_MODES } from './agent-scene-capabilities.js';
import { ALL_LIGHTS_MASK, MATERIAL_LAYER_FIELDS, validateMaterialLayers } from './material-layers.js';
import { recipeDiagnostics, closedRoomDiagnostic } from './agent-diagnostics.js';
@@ -920,6 +920,7 @@ export function createAgentScene(input, inputLimits = {}) {
let particleBake = null;
let lightBake = null;
let lightLinkCache = null;
+ let objectReflectionCache = null;
const skinCache = new Map();
const checkpoints = new Map();
@@ -1061,13 +1062,15 @@ export function createAgentScene(input, inputLimits = {}) {
state.sourceRestParts.every((part, index) => part === nextParts[index]);
const sourceRestParts = sameParts ? state.sourceRestParts : Object.freeze(nextParts);
const lightBakeResult = stageLightBake(recipe, sourceRestParts, graph);
- const restParts = stageLightLinks(recipe, lightBakeResult ? lightBakeResult.parts : sourceRestParts);
+ const reflected = stageObjectReflections(recipe, sourceRestParts, lightBakeResult ? lightBakeResult.parts : sourceRestParts, graph);
+ const restParts = stageLightLinks(recipe, reflected ? reflected.parts : lightBakeResult ? lightBakeResult.parts : sourceRestParts);
const stagedState = {
recipe, geometryRecords, geometries, graph, materialHandles,
// Part identity decides what the next stage reuses, so it compares the parts as built, before any bake.
sourceRestParts,
parts: restParts, restParts,
bakeReport: lightBakeResult ? { ...lightBakeResult.report, reused: lightBakeResult.reused } : 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.
topologyChanged: Boolean(state && (restParts !== state.restParts || state.parts !== state.restParts)),
stats: geometryStats(geometryRecords.values()),
@@ -1131,6 +1134,16 @@ export function createAgentScene(input, inputLimits = {}) {
return { ...lightBake, reused: false };
}
+ // 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) {
+ if (recipe.environment.objectReflections === false || !agentSceneModuleLoaded('reflections')) {
+ return null;
+ }
+ objectReflectionCache = agentSceneModule('reflections').stageObjectReflections(objectReflectionCache, recipe, sourceRestParts, drawnParts, graph, agentEnvironmentMap(recipe.environment));
+ return objectReflectionCache.result;
+ }
+
// A scene that asks for no bake and looks like a closed room gets one diagnostic naming the bake. The ray test costs a
// few milliseconds, so it runs for scene_inspect only and is kept until the scene changes.
let closedRoomCache = null;
@@ -1334,7 +1347,7 @@ export function createAgentScene(input, inputLimits = {}) {
knownKeys(operation, ['type', lookField], 'operation');
const patch = operation[lookField];
// Spot and area lights, cascades and sun links are absent from a recipe until it sets them.
- const optionalFields = lookField === 'environment' ? ['spotLights', 'areaLights', 'shadowCascades', 'keyAffects'] : [];
+ const optionalFields = lookField === 'environment' ? ['spotLights', 'areaLights', 'shadowCascades', 'keyAffects', 'objectReflections'] : [];
knownKeys(patch, [...Object.keys(candidate[lookField]), ...optionalFields], lookField);
const nestedField = lookField === 'environment' ? 'volumeFog' : lookField === 'effects' ? 'bloom' : null;
const merged = { ...candidate[lookField], ...(lookField === 'environment' ? environmentPatchWithSetup(patch) : patch) };
@@ -1492,6 +1505,7 @@ export function createAgentScene(input, inputLimits = {}) {
...(state.clothSampler ? { cloth: state.clothSampler.report() } : {}),
...(state.particleSampler ? { particles: state.particleSampler.report() } : {}),
...(state.bakeReport ? { bake: state.bakeReport } : {}),
+ ...(state.reflectionReport ? { reflections: state.reflectionReport } : {}),
...(state.recipe.armatures ? { rig: rigReport(state.recipe, state.skinBindings) } : {}),
boundsSpace: 'authored-base-world',
...(diagnostics.length ? { diagnostics } : {}),
diff --git a/tests/agent-object-reflections.test.js b/tests/agent-object-reflections.test.js
new file mode 100644
index 00000000..01935227
--- /dev/null
+++ b/tests/agent-object-reflections.test.js
@@ -0,0 +1,51 @@
+import './support/load-agent-scene-modules.mjs';
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { createAgentScene } from '../src/agent-scene.js';
+
+function stillLife(chromeRoughness = 0.05, extraEnvironment = {}) {
+ return {
+ format: '67js.scene', schemaVersion: 1,
+ geometries: [{ id: 'box', type: 'box' }, { id: 'ball', type: 'sphere' }],
+ materials: [
+ { id: 'floor', color: [0.6, 0.6, 0.65], roughness: 0.9 },
+ { id: 'chrome', color: [0.95, 0.95, 0.95], metallic: 1, roughness: chromeRoughness },
+ ],
+ nodes: [
+ { id: 'ground', geometry: 'box', material: 'floor', translation: [0, -0.05, 0], scale: [6, 0.1, 6] },
+ { id: 'ball', geometry: 'ball', material: 'chrome', translation: [0, 0.5, 0], scale: [0.5, 0.5, 0.5] },
+ ],
+ camera: { eye: [0, 1.2, 3], target: [0, 0.5, 0], fov: 50, near: 0.05, far: 20 },
+ environment: extraEnvironment,
+ };
+}
+
+test('a smooth metal part gets its own reflection probe without any field', () => {
+ const scene = createAgentScene(stillLife());
+ const reflections = scene.inspect().reflections;
+ assert.equal(reflections.placed, 1);
+ assert.equal(reflections.partsWithProbe, 1);
+ const byName = new Map(scene.parts.map(part => [part.name, part]));
+ assert.ok(byName.get('ball').material.environmentProbe);
+ assert.equal(byName.get('ground').material.environmentProbe, undefined);
+});
+
+test('a scene with no reflective part reports nothing and keeps its parts untouched', () => {
+ const rough = createAgentScene(stillLife(0.9));
+ assert.equal(rough.inspect().reflections, undefined);
+ assert.ok(rough.parts.every(part => part.material.environmentProbe === undefined));
+});
+
+test('environment.objectReflections false turns the probes off', () => {
+ const scene = createAgentScene(stillLife(0.05, { objectReflections: false }));
+ assert.equal(scene.inspect().reflections, undefined);
+ assert.ok(scene.parts.every(part => part.material.environmentProbe === undefined));
+ assert.throws(() => createAgentScene(stillLife(0.05, { objectReflections: 'no' })), /objectReflections must be a boolean/);
+});
+
+test('an edit that changes nothing the probe sees keeps the traced probe', () => {
+ const scene = createAgentScene(stillLife());
+ const before = scene.parts.find(part => part.name === 'ball').material.environmentProbe;
+ scene.apply([{ type: 'set-environment', environment: { objectReflections: true } }], { expectedRevision: scene.inspect().revision });
+ assert.equal(scene.parts.find(part => part.name === 'ball').material.environmentProbe, before);
+});
diff --git a/tests/agent-scene-on-demand.test.js b/tests/agent-scene-on-demand.test.js
index 88cccb0c..beff1785 100644
--- a/tests/agent-scene-on-demand.test.js
+++ b/tests/agent-scene-on-demand.test.js
@@ -31,6 +31,9 @@ test('markers name the module a recipe needs', () => {
assert.deepEqual(agentSceneModulesNeeded({ geometries: [{ id: 'g', type: 'mesh' }] }), ['mesh']);
assert.deepEqual(agentSceneModulesNeeded({ geometries: [{ id: 'g', type: 'lathe' }] }), ['modeling']);
assert.deepEqual(agentSceneModulesNeeded({ motion: { tracks: [] } }), ['motion']);
+ assert.deepEqual(agentSceneModulesNeeded({ materials: [{ id: 'm', metallic: 0.9 }] }), ['reflections']);
+ assert.deepEqual(agentSceneModulesNeeded({ materials: [{ id: 'm', metallic: 1 }] }), ['reflections']);
+ assert.deepEqual(agentSceneModulesNeeded({ materials: [{ id: 'm', metallic: 0 }, { id: 'n', metallic: 0.2 }] }), []);
assert.deepEqual(agentSceneModulesNeeded({ materials: [{ id: 'm', pattern: { type: 'bricks' } }] }), ['patterns']);
});
diff --git a/tests/curve-text.test.js b/tests/curve-text.test.js
index a31c678a..e21ab14e 100644
--- a/tests/curve-text.test.js
+++ b/tests/curve-text.test.js
@@ -229,7 +229,7 @@ const signRecipe = {
};
test('a recipe draws a labelled sign and a piped curve', () => {
- assert.deepEqual(agentSceneModulesNeeded(signRecipe), ['modeling', 'text']);
+ assert.deepEqual(agentSceneModulesNeeded(signRecipe), ['modeling', 'text', 'reflections']);
const scene = createAgentScene(signRecipe);
const letters = scene.parts.find(part => part.name === 'letters');
const pipe = scene.parts.find(part => part.name === 'pipe');