3D engine that AI agents drive
Give a lone flat object an automatic floor (Part of #53)
Nguyen Xuan An3390ff6a2c73
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 35074dd7..e1c3cb3f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,8 @@## 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.+- 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.- Read the textures inside glTF layer extensions and accept TEXCOORD_1 (part of issue #51). `clearcoatTexture`, `clearcoatRoughnessTexture`, `clearcoatNormalTexture`, `anisotropyTexture`, `sheenColorTexture` and `sheenRoughnessTexture` load into `material.layerMaps` and draw through shader features in `material-layer-shaders`, and `exportGlb` writes them back. Occlusion, emissive and metallic-roughness textures may read TEXCOORD_1. Against Cycles, `AnisotropyBarnLamp` goes from 0.4758 to 0.3584, `AnisotropyDiscTest` from 0.3481 to 0.2808 and `ClearCoatTest` from 0.2344 to 0.2306; `TransmissionTest` is unchanged and `SheenChair` still waits on per-map texture transforms. The core entry grows by about 345 bytes gzip.diff --git a/bench/agent-modeling/README.md b/bench/agent-modeling/README.mdindex c0d48fe6..ac4529f3 100644--- a/bench/agent-modeling/README.md+++ b/bench/agent-modeling/README.md@@ -212,6 +212,24 @@ The exposure change above was reverted: on the six cold recipes no subject pixel`surface-judge.mjs` asks one reference-free question per task, "does the object sit on a surface, with a believable contact shadow", 0 to 3 over the three cameras (`results/2026-11-01-surface-judge.json`, Sonnet, same six cold recipes). Before the automatic floor: 0, 0, 0, 0, 0, 0. After: crate 1, mug 1, table 2, soap 1, chair 1, gear 0. The judge's notes say the same thing each time: the three-quarter view shows a floor and a shadow, and the front and side views do not, because those cameras sit at floor height and see a floor edge-on. Gear showed no floor in any view. The fixed cameras limit this score, so read it as a direction.+### 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.++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):++| Task | No floor | Floor, first rule | Floor, gear fix |+| --- | --- | --- | --- |+| crate | 0 | 1 | 2 |+| mug | 0 | 1 | 1 |+| table | 0 | 2 | 1 |+| soap | 0 | 1 | 1 |+| chair | 0 | 1 | 1 |+| gear | 0 | 0 | 1 |+| Total | 0 | 6 | 7 |++Every note names the same gap: the three-quarter view shows a surface and a shadow, the front and side views (orthographic at floor height) show an edge-on floor and a flat grey backdrop. The cameras were not raised: the benchmark cameras are not what an agent sees in the preview, so raising them would not show that the floor reads to an agent. The gear's three-quarter view, opened by hand, shows the floor but only a faint shadow, and a floor colour close to the backdrop. Read the 0 to 6 to 7 as direction (inferred from one judge call per task), not as a measured lift of one point.+## Clip layers (2026-10-31)`robot-walk-wave` asks for a character that walks and waves at once through `motion.layers`. The check `assetWalkAndWave` reloads the exported recipe, plays each layer alone (keeping its own speed, offset and loop) and compares part matrices at two times: the legs must match Walking and move, the right arm must leave Walking, the left arm must keep walking. Cold Sonnet, no skill, `results/2026-10-31-11-40-sonnet-walk-wave-cold-fixed-grader.json`: 1 of 1, 7 tool calls (2 errors), $0.31. A first run, with a check that compared against Walking at speed 1 only, failed on a recipe the agent had correct (it set per-layer speeds); the check was fixed and that recipe grades as a pass. One run is not a rate.diff --git a/bench/agent-modeling/results/2026-11-01-surface-judge-gear-fix.json b/bench/agent-modeling/results/2026-11-01-surface-judge-gear-fix.jsonnew file mode 100644index 00000000..3f59b50d--- /dev/null+++ b/bench/agent-modeling/results/2026-11-01-surface-judge-gear-fix.json@@ -0,0 +1,44 @@+{+ "question": "does the object sit on a surface, with a believable contact shadow",+ "model": "sonnet",+ "scale": "0 to 3 over the front, side and three-quarter cameras",+ "recipes": "the six cold Haiku recipes of results/2026-11-01-01-36-haiku-look-after.json, drawn after the lone-flat-object floor fix",+ "records": [+ {+ "task": "crate",+ "score": 2,+ "costUsd": 0.1926678,+ "note": "The three-quarter view shows the crate on a ground disc with a believable cast shadow, but the front and side views are flat-on with no ground plane or shadow, so the crate looks like it floats there."+ },+ {+ "task": "mug",+ "score": 1,+ "costUsd": 0.1926159,+ "note": "The three-quarter view shows a ground plane with a soft cast shadow, but the front and side views are flat grey with no visible surface or shadow, so the mug looks detached in those two."+ },+ {+ "task": "table",+ "score": 1,+ "costUsd": 0.1856988,+ "note": "The three-quarter view shows the table standing on a ground plane with a believable cast shadow, but the front and side views are flat grey with no visible surface or shadow, so the table looks like it floats in those two."+ },+ {+ "task": "soap",+ "score": 1,+ "costUsd": 0.1858154,+ "note": "The three-quarter view shows a ground plane and a soft contact shadow, but the front and side views are flat horizon-level shots with a uniform grey background, no visible surface and no shadow, so the object looks detached there."+ },+ {+ "task": "chair",+ "score": 1,+ "costUsd": 0.1856913,+ "note": "The three-quarter view shows the chair on a ground plane with a believable cast shadow, but the front and side views show no ground or shadow at all, so the chair looks like it floats there."+ },+ {+ "task": "gear",+ "score": 1,+ "costUsd": 0.1858949,+ "note": "The three-quarter view shows a pale ground plane with a faint soft shadow at the gear's right edge, but the front and side views are a flat grey backdrop with no visible surface or shadow under the thin slab, so it looks detached in two of three views."+ }+ ]+}diff --git a/docs/parity.md b/docs/parity.mdindex 553dc7a2..cd7fdd99 100644--- a/docs/parity.md+++ b/docs/parity.md@@ -192,7 +192,7 @@ To move to a new Blender release, run `node scripts/parity-manual-snapshot.mjs`.| Rendering > Cameras | partial | Perspective, orthographic views, focal length, animated paths, depth of field from depth and camera motion blur, both repeatable per frame. Object motion blur and bokeh shapes are missing. | [camera-path](../tests/camera-path.test.js), [camera](../tests/camera.test.js), [render-passes](../tests/render-passes.test.js) | #54 || Rendering > Lights > Light Objects | partial | One directional light with a shadow, 8 point lights, 8 spot lights and 4 rectangular area lights. Point and spot lights can cast shadows from one 24-tile atlas (a point light takes 6 tiles, a spot light 1). Area lights use a representative point and cast no shadow. The directional shadow is a single map, or up to four cascades through `addons/cascaded-shadows` (`shadowCascades` on the renderer and `environment.shadowCascades` in recipes, three by themselves when `shadow.extent` is above 40): scene `long-street` scores 0.1555 against Cycles with one map and 0.1398 with three cascades, for about 0.2 ms more a frame on an RTX 3060 when the camera moves. | [lighting](../tests/lighting.test.js), [cascades](../tests/cascaded-shadows.test.js), `npm run reference` scenes `spot-area` and `long-street` | #52 || Rendering > Lights > Light Linking | partial | `addons/light-linking`: a light's `affects` list (and `environment.keyAffects` for the sun) limits it to the named parts through `applyLightLinks`, as a Blender receiver collection does; the shader skips a light whose bit in the part's mask is clear. Linking changes what a light adds, not what it shadows. The path tracer and the light bake ignore it, recipes do not reach it (`lightLinking: false` in `scene_capabilities`) and there is no blocker list. Scene `light-linking` scores 0.0998 against Cycles. | [light-linking](../tests/light-linking.test.js), `npm run reference` scene `light-linking` | #52 |-| Rendering > Lights > World Environment | partial | Recipes pick a named setup (`daylight`, `overcast`, `sunset`, `studio`) that carries a procedural environment map, with opt-in screen-space ambient occlusion. Code can load any HDRI; recipes reach only the named maps, with no URLs or files. No reflections between objects yet. The MCP preview adds an automatic floor with a contact shadow (`environment.ground: false` removes it). Cold-run reference-free score for sitting on a surface: 0 before, 1 to 2 after, on the three-quarter view only. | [environment](../tests/environment.test.js), [default look](../tests/default-look.test.js) | #53 |+| Rendering > Lights > World Environment | partial | Recipes pick a named setup (`daylight`, `overcast`, `sunset`, `studio`) that carries a procedural environment map, with opt-in screen-space ambient occlusion. Code can load any HDRI; recipes reach only the named maps, with no URLs or files. No reflections between objects yet. The MCP preview adds an automatic floor with a contact shadow (`environment.ground: false` removes it). Cold-run reference-free score for sitting on a surface, summed over six tasks and 0 to 3 each: 0 before, 6 with the floor and 7 after a lone flat object (a gear) stopped being read as a floor; the front and side cameras see it edge-on, so only the three-quarter view shows it. | [environment](../tests/environment.test.js), [default look](../tests/default-look.test.js) | #53 || Rendering > Materials > Components | partial | Surfaces with PBR factors and five maps, a clear coat, transmission with thickness, attenuation and IOR, sheen, and specular weight and tint. Anisotropic highlights and a thin-film iridescence layer, as in the glTF extensions, are compiled in only when a part uses them. There is no subsurface scattering, volume material or displacement. | [texture-set](../tests/texture-set.test.js), [material-layers](../tests/material-layers.test.js) | #50, #51 || Rendering > Materials > Assignment | done | A node names one material. | [agent-scene](../tests/agent-scene.test.js) | || Rendering > Materials > Preview | out of scope | Interface for a person. Agents use `scene_look`. | | |diff --git a/src/agent-ground.js b/src/agent-ground.jsindex bb9c775e..de0d799a 100644--- a/src/agent-ground.js+++ b/src/agent-ground.js@@ -9,6 +9,8 @@ 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;@@ -42,7 +44,12 @@ function sceneBounds(boundsList) {return { minimum, maximum };}-function formsFloor(bounds, scene) {+function footprintExtent(boundsList) {+ const { minimum, maximum } = sceneBounds(boundsList);+ return Math.max(maximum[0] - minimum[0], maximum[2] - minimum[2]);+}++function formsFloor(bounds, scene, othersExtent) {const widthX = scene.maximum[0] - scene.minimum[0];const widthZ = scene.maximum[2] - scene.minimum[2];const partX = bounds.maximum[0] - bounds.minimum[0];@@ -51,7 +58,8 @@ function formsFloor(bounds, scene) {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;- return isWide && isThin && isLowest;+ const isOversized = Math.max(partX, partZ) >= FLOOR_OVERSIZE * othersExtent;+ return isWide && isThin && isLowest && isOversized;}/**@@ -67,7 +75,11 @@ export function agentGroundPlacement(parts, environment) {return null;}const scene = sceneBounds(boundsList);- if (boundsList.some(bounds => formsFloor(bounds, scene))) {+ const formsFloorOverOthers = (bounds, index) => {+ const others = boundsList.filter((_, otherIndex) => otherIndex !== index);+ return others.length > 0 && formsFloor(bounds, scene, footprintExtent(others));+ };+ if (boundsList.some(formsFloorOverOthers)) {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 52460231..4d81b329 100644--- a/tests/agent-ground.test.js+++ b/tests/agent-ground.test.js@@ -26,6 +26,11 @@ test('a wide thin lowest part counts as the recipe own floor', () => {assert.equal(agentGroundPlacement([slab, crate], defaultEnvironment), null);});+test('a lone flat object, such as a gear lying down, still gets a floor', () => {+ const gear = boxPart([0, 0.01, 0], [0.2, 0.02, 0.2]);+ assert.equal(agentGroundPlacement([gear], defaultEnvironment).height, 0);+});+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]);