3D engine that AI agents drive
Refuse a floorSkyTrace that is not a boolean (part of #197)
Nguyen Xuan Ana402565ea880
diff --git a/changes/197-sun-rooms.size.md b/changes/197-sun-rooms.size.mdindex 3b97d97a..002a9611 100644--- a/changes/197-sun-rooms.size.md+++ b/changes/197-sun-rooms.size.md@@ -1,3 +1,3 @@- entry:floor-sky-visibility: +285 bytes gzip (15101 to 15386) for the onlyClosedRooms option, the room strength, the mean visibility in the report, applyDefaultFloorSky and the recipe stage with its cache-- scene:agent-scene: +286 bytes gzip (103055 to 103341) for the floorSkyTrace field, one conditional call into the lazy module and the module entry with its markers; the sun and closed-room tests live in the lazy chunk-- scene:agent-scene+lazy: +3739 bytes gzip (359885 to 363624), the same code plus the floor sky module loaded+- scene:agent-scene: +300 bytes gzip (103053 to 103353) for the floorSkyTrace field with its type check, one conditional call into the lazy module and the module entry with its markers; the sun and closed-room tests live in the lazy chunk. Goal growth accepted by the lead: the trace is on by default, so an agent that builds a sun-lit closed room gets the right light without knowing any flag, a real capability rather than a score gain. Measured FLIP against Cycles: temple-hall -0.0023, the three temple options -0.0051 to -0.0096, dark-shaft +0.0017 (no visible change, see the PR).+- scene:agent-scene+lazy: +3751 bytes gzip (359885 to 363636), the same code plus the floor sky module loadeddiff --git a/docs/agent-look.md b/docs/agent-look.mdindex 4085b7db..055480cb 100644--- a/docs/agent-look.md+++ b/docs/agent-look.md@@ -109,7 +109,7 @@ Sky colors use display RGB, matching the renderer's existing environment contrac| `ground` | on | Absent unless set. `false` removes the preview's automatic floor and contact shadow || `resolveCoplanar` | off | `'offset'` puts the smaller part of each coplanar pair (see the `coplanar-overlap` warning) on the next depth layer, drawn with a polygon offset; `false` or absent leaves parts as authored. Geometry never moves. Parts that set `decal` or `depthLayer` keep their own || `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` |-| `floorSkyTrace` | on | Absent unless set. A closed room a sun lights gets the sky each floor texel sees traced into its floor (`applyFloorSkyVisibility`, strength 0.2), so shadowed floors under a roof or between walls get less world and sky light; it makes the dark end of halls closer to Cycles. Open scenes and rooms lit by lamps alone are left as they are. `false` turns it off. It loads lazily with a recipe that names its sun (`keyColor` or `keyIntensity`), costs about 1 s of trace when the scene is built and adds triangles to the floor (0.1 to 0.4 ms per frame in the reference halls). |+| `floorSkyTrace` | on | Absent unless set. A closed room a sun lights gets the sky each floor texel sees traced into its floor (`applyFloorSkyVisibility`, strength 0.2), so shadowed floors under a roof or between walls get less world and sky light; it makes the dark end of halls closer to Cycles. Open scenes and rooms lit by lamps alone are left as they are. `false` turns it off; a value that is not a boolean is refused. It loads lazily with a recipe that names its sun (`keyColor` or `keyIntensity`), costs about 1 s of trace when the scene is built and adds triangles to the floor (0.1 to 0.4 ms per frame in the reference halls). || `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.jsindex 5ecab5bd..c9735d81 100644--- a/src/agent-look.js+++ b/src/agent-look.js@@ -272,8 +272,11 @@ function environmentFrom(input = {}) {}environment.objectReflections = input.objectReflections;}- // Only `false` opts out of the floor sky trace (src/floor-sky-visibility.js); any other value leaves it on.+ // `false` opts out of the floor sky trace that src/floor-sky-visibility.js gives sun-lit closed rooms.if (input.floorSkyTrace !== undefined) {+ if (typeof input.floorSkyTrace !== 'boolean') {+ throw new TypeError('environment.floorSkyTrace must be a boolean.');+ }environment.floorSkyTrace = input.floorSkyTrace;}// Outlines and line geometry; null clears them. The module checks the fields and loads on demand.diff --git a/tests/agent-floor-sky-trace.test.js b/tests/agent-floor-sky-trace.test.jsindex 9b71db1c..26df49a8 100644--- a/tests/agent-floor-sky-trace.test.js+++ b/tests/agent-floor-sky-trace.test.js@@ -41,6 +41,12 @@ test('environment.floorSkyTrace false turns the trace off', () => {assert.equal(floorHasSkyVisibility(createAgentScene(room({ keyColor: [3, 3, 3], floorSkyTrace: false }))), false);});+test('environment.floorSkyTrace that is not a boolean is refused, not read as on', () => {+ for (const value of ['off', 0, null, { enabled: false }]) {+ assert.throws(() => createAgentScene(room({ keyColor: [3, 3, 3], floorSkyTrace: value })), /floorSkyTrace must be a boolean/);+ }+});+test('a room with no sun and open ground are left as they were', () => {assert.equal(floorHasSkyVisibility(createAgentScene(room({ keyColor: [0, 0, 0] }))), false);const open = room({ keyColor: [3, 3, 3] });