3D engine that AI agents drive
Treat only a lone part as not a floor, so a room keeps its own floor (part of #53)
Nguyen Xuan An82d47dc51227
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e1c3cb3f..4c52dbe1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,7 +2,7 @@## Unreleased-- Fix the automatic floor skipping a lone flat object (part of issue #53). A part counts as the recipe's own floor only when it is also at least 1.5 times wider than everything else in the scene, so a gear lying flat, which spans its whole scene and is the lowest geometry, now gets a floor and a contact shadow (before, `agentGroundPlacement` returned null for it). The surface judge on the six cold recipes goes from 0 before the floor, to 6 with the first rule, to 7 with this fix (gear 0 to 1; one call per task, so direction only). A flat object with a hub on it is still read as a plate. Core did not change.+- Fix the automatic floor skipping a lone flat object (part of issue #53). A lone part never counts as the recipe's own floor, so a gear lying flat, which spans its whole scene and is the lowest geometry, now gets a floor and a contact shadow (before, `agentGroundPlacement` returned null for it). The surface judge on the six cold recipes goes from 0 before the floor, to 6 with the first rule, to 7 with this fix (gear 0 to 1; one call per task, so direction only). A flat object with a hub on it is still read as a plate. Core did not change.- Let the path tracer stop converged pixels, draw normal and roughness maps on box-projected materials, and finish a 1080p still (part of issue #129, which stays open). `noiseThreshold` (0 to 1, default 0.03, 0 draws every sample) stops a pixel once the standard error of its mean luminance is under that share of the mean plus 0.05, checked from 16 samples on and after every 8 more; the decision reads only the pixel's own samples, so bands and thread counts still give the same bytes, and `report.averageSamples` says what was used. Shadow rays no longer interpolate the surface they hit unless it is a cutout (pixels unchanged, 1.23 to 1.36 times faster per thread on the demo room). Box-projected parts are traced with the UVs of their projection (`boxProjectedGeometry`, with `columnLengths` now exported from `src/export-box-uv.js`), so their colour, normal and metallic-roughness maps are all read (before, a box-projected colour map read one texel); `report.ignored` no longer lists them. Render jobs may set `maxSeconds` up to 600 (was 240; the deadline is `maxSeconds` plus 60 s): the 1920 by 1080, 64 sample still of `tests/fixtures/demo-room.recipe.json` took 246.4 s in the tracer (30.7 samples per pixel on average, 8 threads, 257 s per job), 6 s past the old limit. Measured, and not all good: at 24 fixed samples with the filter `brick-graph` is 0.0024 and `character` 0.0048 worse than at 64; adaptive sampling costs `spot-area` 0.0658 to 0.0900 against Cycles at the default threshold; drawing one light at the first hit was tried and dropped (twice as fast, 66 percent more error). `brick-graph` did not improve against the same tracer at 64 samples (0.1370 to 0.1373); the darker floor of `character` and `outdoor-hdri` was narrowed but not found. `bench/reference/run.mjs` takes `--noise-threshold` and records `averageSamples`. Core did not change.diff --git a/bench/agent-modeling/README.md b/bench/agent-modeling/README.mdindex ac4529f3..e595c9f7 100644--- a/bench/agent-modeling/README.md+++ b/bench/agent-modeling/README.md@@ -214,7 +214,7 @@ The exposure change above was reverted: on the six cold recipes no subject pixel### Gear sees no floor: the floor rule misread it (2026-11-01, issue #53)-Cause, measured by calling `agentGroundPlacement` on the six stored cold recipes: for `gear` it returned null. The gear is one thin part that spans its whole scene and is the lowest geometry, so the rule "a part that spans 90 percent of the scene, is thin and lowest is the recipe's own floor" took the gear for a floor, and no floor was added. The other five returned a placement at height 0. This was an engine fault, not a camera limit. Fix in `src/agent-ground.js`: a floor part must also be at least 1.5 times wider than everything else in the scene, so a lone flat object (or one with nothing else) gets a floor. The limit that remains: a flat object with a small hub or shaft on it still reads as a plate with something on it, and gets no floor. `tests/agent-ground.test.js` covers the lone gear.+Cause, measured by calling `agentGroundPlacement` on the six stored cold recipes: for `gear` it returned null. The gear is one thin part that spans its whole scene and is the lowest geometry, so the rule "a part that spans 90 percent of the scene, is thin and lowest is the recipe's own floor" took the gear for a floor, and no floor was added. The other five returned a placement at height 0. This was an engine fault, not a camera limit. Fix in `src/agent-ground.js`: a lone part never counts as a floor, so a lone flat object gets one. A room floor still counts although its walls are as wide (test). The limit that remains: a flat object with a small hub or shaft on it still reads as a plate with something on it, and gets no floor. `tests/agent-ground.test.js` covers the lone gear.Same six cold recipes, drawn from the same fixed cameras, judged by `surface-judge.mjs` (Sonnet, `results/2026-11-01-surface-judge-gear-fix.json`, $1.12; one judge call per task, so one point is inside the noise):diff --git a/src/agent-ground.js b/src/agent-ground.jsindex de0d799a..9d485944 100644--- a/src/agent-ground.js+++ b/src/agent-ground.js@@ -9,8 +9,6 @@ const DISC_SEGMENTS = 48;const FLOOR_SPAN_SHARE = 0.9;const FLOOR_THINNESS = 0.25;const FLOOR_LOWEST_TOLERANCE = 1e-3;-// A floor is much wider than whatever stands on it. A lone flat object, such as a gear lying down, is not a floor.-const FLOOR_OVERSIZE = 1.5;// The disc reaches this many scene half-widths past the scene, so its edge stays out of a framed shot.const DISC_REACH = 6;const MINIMUM_RADIUS = 2;@@ -44,12 +42,7 @@ function sceneBounds(boundsList) {return { minimum, maximum };}-function footprintExtent(boundsList) {- const { minimum, maximum } = sceneBounds(boundsList);- return Math.max(maximum[0] - minimum[0], maximum[2] - minimum[2]);-}--function formsFloor(bounds, scene, othersExtent) {+function formsFloor(bounds, scene) {const widthX = scene.maximum[0] - scene.minimum[0];const widthZ = scene.maximum[2] - scene.minimum[2];const partX = bounds.maximum[0] - bounds.minimum[0];@@ -58,8 +51,7 @@ function formsFloor(bounds, scene, othersExtent) {const isWide = partX >= FLOOR_SPAN_SHARE * widthX && partZ >= FLOOR_SPAN_SHARE * widthZ;const isThin = partHeight <= FLOOR_THINNESS * Math.max(partX, partZ);const isLowest = bounds.minimum[1] <= scene.minimum[1] + FLOOR_LOWEST_TOLERANCE;- const isOversized = Math.max(partX, partZ) >= FLOOR_OVERSIZE * othersExtent;- return isWide && isThin && isLowest && isOversized;+ return isWide && isThin && isLowest;}/**@@ -75,11 +67,9 @@ export function agentGroundPlacement(parts, environment) {return null;}const scene = sceneBounds(boundsList);- const formsFloorOverOthers = (bounds, index) => {- const others = boundsList.filter((_, otherIndex) => otherIndex !== index);- return others.length > 0 && formsFloor(bounds, scene, footprintExtent(others));- };- if (boundsList.some(formsFloorOverOthers)) {+ // A floor holds something. A lone flat object, such as a gear lying down, is the subject.+ const hasOtherParts = boundsList.length > 1;+ if (hasOtherParts && boundsList.some(bounds => formsFloor(bounds, scene))) {return null;}const halfWidth = Math.max(scene.maximum[0] - scene.minimum[0], scene.maximum[2] - scene.minimum[2]) / 2;diff --git a/tests/agent-ground.test.js b/tests/agent-ground.test.jsindex 4d81b329..718d7c8b 100644--- a/tests/agent-ground.test.js+++ b/tests/agent-ground.test.js@@ -31,6 +31,13 @@ test('a lone flat object, such as a gear lying down, still gets a floor', () =>assert.equal(agentGroundPlacement([gear], defaultEnvironment).height, 0);});+test('a room floor counts as a floor although its walls are as wide', () => {+ const floor = boxPart([0, -0.05, 0], [6, 0.1, 6]);+ const backWall = boxPart([0, 1.5, -3], [6, 3, 0.2]);+ const sideWall = boxPart([-3, 1.5, 0], [0.2, 3, 6]);+ assert.equal(agentGroundPlacement([floor, backWall, sideWall], defaultEnvironment), null);+});+test('a raised tabletop, a tall wall and a small plate do not count as a floor', () => {const legs = boxPart([0, 0.35, 0], [1.2, 0.7, 0.7]);const top = boxPart([0, 0.75, 0], [1.2, 0.05, 0.7]);