3D engine that AI agents drive
Merge remote-tracking branch 'origin/main' into merged/layer-textures
Nguyen Xuan Anbdf853b0e46d
diff --cc CHANGELOG.mdindex 1ea0b2e8,6f4db382..2fb1a082--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -2,8 -2,10 +2,12 @@@## Unreleased+- 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.+- Score material scenes and Khronos sample assets against their baseline (parts of issues #50 and #51). `brick-flat` is the control for `brick-graph`: the same wall in the graph's average colour with no maps. `npm run reference -- --khronos` draws Khronos sample assets downloaded into gitignored `artifacts/khronos/` and scores them against Cycles reading the same GLB, on the pixels the asset covers (`khronos.json`, `images/khronos-*.jpg`; `baseline.json` is unchanged). The brick bump is not weaker than Blender's: its bright edge is stronger and bump 0 would score better (0.2065 against 0.2269), so no engine change. The assets found two importer faults, fixed in `src/gltf.js`: `KHR_xmp` and `KHR_xmp_json_ld` metadata refused the whole file, and `KHR_materials_variants` is now accepted with a warning. Still open: texture slots in layer extensions (the anisotropy textures matter, both anisotropy assets score worse with the factor than with none) and occlusion on TEXCOORD_1 (`SheenChair`).+ - Let recipes reach cascaded sun shadows and light linking (part of issue #52; the lit-interior score goal is still open). `environment.shadowCascades` (0 to 4) and `affects` on point, spot and area lights plus `environment.keyAffects` name nodes; both addons load on demand through `src/agent-scene-modules.js`, `scene_capabilities` now reports `lightLinking` and `shadowCascades`, unknown node IDs are refused with the next action, and `set-environment` and `scene_export_recipe` carry the fields. The light bake honours `affects` (a linked light adds nothing at a part it skips, even as a bounce) and the path tracer lists linking in `report.ignored`. Default: a scene without `shadowCascades` whose `shadow.extent` is above 40 gets three cascades (the single map is then 4 cm per texel or coarser; `long-street` scores 0.1555 with one map and 0.1398 with three, for about 0.2 ms on an RTX 3060); every scene at or below 40 draws as before, and `shadowCascades: 0` keeps one map. `node scripts/smoke-mcp-linking.mjs` proves one recipe with both through the MCP server, with a seek giving identical PNG bytes. The MCP schema total stays at its budget by shortening environment descriptions.++ - Add an automatic floor with a contact shadow to the MCP preview, and measure the default look on cold runs (part of issue #53; its done condition is not shown, see below). Breaking look change: a recipe with no floor of its own now draws a light grey disc under its lowest geometry at that height, so the key light's shadow falls on something; before, objects floated on a flat grey backdrop. It is not a recipe node: `src/agent-ground.js` builds it from world bounds on every draw (`agentGroundPlacement`), so the exported recipe, `scene.parts`, silhouettes and the suite's checks do not hold it, and it reaches the renderer through the `ground` option, which now also accepts a part (about 20 bytes in `entry:core`). It is left out when a part already forms a floor: one that spans at least 90 percent of the scene's width and depth, is thinner than a quarter of its width, and is the lowest geometry. `environment.ground: false` switches it off (the field is absent from recipes that do not set it). Nothing else about the default look changed: `effects.exposure` stays 1 (an exposure of 0.8 was tried and dropped: on the six cold recipes no pixel of the subject reached 250 at either value, and mean luma was 157 to 199 at 1 and 142 to 187 at 0.8), setup `daylight`, occlusion 0. The suite's look harness drew without the setup's environment map, so its images were darker than the preview shows; it now draws with the map and the floor, and `regrade.mjs` finds files of runs made with `--runs`. Measured on six cold Haiku recipes with a reference-free Sonnet vision question ("does the object sit on a surface, with a believable contact shadow", 0 to 3): 0, 0, 0, 0, 0, 0 before and 1, 1, 2, 1, 1, 0 after. The judge named the front and side cameras as the gap: they are orthographic at floor height, so a floor is edge-on and a shadow falls behind the object, and only the three-quarter view shows it. The reference-based judge (shape, proportions, features, surface) tied at 66 of 72 across the dropped exposure change, because it cannot see lighting defaults. Tool schema text was shortened to pay for the `ground` field.+- Measure what an equal feature set costs against three.js (part of issue #74; no engine change, no speed-up). `bench/runtime` gets the engines `67js-ldr`, `67js-one-sample`, `67js-ldr-one-sample` and `three-one-sample` (run with `--engine`) and a `--cpu-only` flag. Measured: with no MSAA and no HDR target 67js is still 5.2 to 5.7 times three.js on SwiftShader in `large-mesh`, `many-materials` and `instanced-objects` (7.8, 5.3 and 7.8 with the defaults), so the gap is the lit shader and not those two features. On the RTX 3060 `large-mesh` costs 3.6 ms against 0.6 ms and is not explained by HDR, MSAA, the vertex shader or the vertex attributes; on ANGLE Vulkan the ratio is 2.3 instead of 5.8. Skipping zero-intensity fill lights was tried and reverted (inside the noise). The profile is in `bench/runtime/PROFILE.md`.- Add cascaded sun shadows and light linking (part of issue #52; recipes do not reach either, and `lit-interior` was already improved by the light bake, not by this work). `addons/cascaded-shadows`: `new Renderer67(canvas, parts, { shadowCascades: createCascadedShadows({ count: 3 }) })` fits up to four depth maps to slices of the camera's view, with sphere fitting and texel snapping so edges do not crawl; on the new `long-street` reference scene the score against Cycles goes from 0.1555 to 0.1398 for about 0.2 ms more a frame on an RTX 3060 (+25 percent on SwiftShader) when the camera moves. `addons/light-linking`: `applyLightLinks(parts, environment)` limits a light to the parts named in its `affects` list (`environment.keyAffects` for the sun) through a per-part mask in `material.lightMask`; the new `light-linking` reference scene scores 0.0998 against Cycles with the same lists as Blender receiver collections. Both keep their GLSL out of the core bundle (`registerShaderFeatureCode`, new slots `sunVisibility`, `linkSun`, `linkPoint`, `linkSpot` and `linkArea`), and `npm run reference -- --cascades <n>` and `frame-time.mjs <scene> <backend> --cascades` measure them. No earlier reference scene moved.diff --cc bench/reference/baseline.jsonindex cd1abc10,d4441e4f..07cc4cc9--- a/bench/reference/baseline.json+++ b/bench/reference/baseline.json@@@ -2,69 -2,65 +2,69 @@@"metric": "FLIP (LDR), mean error, lower is better","blenderVersion": "5.2.2 LTS","seconds": {+ "brick-flat": {+ "cycles": 24.4,+ "eevee": 6.4+ },"brick-graph": {- "cycles": 16.4,- "eevee": 8.5+ "cycles": 25.9,+ "eevee": 29.8},"brick-room": {- "cycles": 29.1,- "eevee": 2.2+ "cycles": 122.6,+ "eevee": 2.9},"brushed-film": {- "cycles": 15.9,- "eevee": 2.0+ "cycles": 28.7,+ "eevee": 0.6},"car-paint": {- "cycles": 13.8,- "eevee": 3.4+ "cycles": 46.9,+ "eevee": 2.3},"character": {- "cycles": 17.6,- "eevee": 3.8+ "cycles": 27.8,+ "eevee": 1.7},"fog": {- "cycles": 40.9,- "eevee": 3.9+ "cycles": 186.7,+ "eevee": 1.3},"foliage": {- "cycles": 28.1,- "eevee": 9.9+ "cycles": 44.8,+ "eevee": 0.6},"glass": {- "cycles": 22.2,- "eevee": 16.7+ "cycles": 15.1,+ "eevee": 0.5},"light-linking": {- "cycles": 12.1,- "eevee": 4.0+ "cycles": 21.3,+ "eevee": 1.0},"lit-interior": {- "cycles": 21.8,- "eevee": 4.7+ "cycles": 64.2,+ "eevee": 12.1},"long-street": {- "cycles": 12.8,- "eevee": 4.8+ "cycles": 50.7,+ "eevee": 0.6},"material-spheres": {- "cycles": 18.4,- "eevee": 4.4+ "cycles": 15.2,+ "eevee": 0.7},"metal": {- "cycles": 32.5,- "eevee": 4.6+ "cycles": 52.5,+ "eevee": 1.0},"outdoor-hdri": {- "cycles": 9.4,- "eevee": 5.0+ "cycles": 11.5,+ "eevee": 0.8},"spot-area": {- "cycles": 12.0,- "eevee": 2.2+ "cycles": 18.4,+ "eevee": 0.7}},"graphics": {diff --cc bench/size/baseline.jsonindex 107bedd8,cddc58f4..fc0fb879--- a/bench/size/baseline.json+++ b/bench/size/baseline.json@@@ -14,9 -14,9 +14,9 @@@},"bundles": {"entry:core": {- "min": 289074,- "gzip": 82693,- "brotli": 70523- "min": 288009,- "gzip": 82348,- "brotli": 70217++ "min": 289090,++ "gzip": 82703,++ "brotli": 70463},"entry:model": {"min": 40093,@@@ -39,14 -39,14 +39,14 @@@"brotli": 7331},"entry:gltf": {- "min": 156410,- "gzip": 48011,- "brotli": 41568+ "min": 158507,- "gzip": 48585,- "brotli": 42083++ "gzip": 48584,++ "brotli": 42047},"entry:gltf+lazy": {- "min": 169452,- "gzip": 51780,- "brotli": 45001- "min": 162843,- "gzip": 50001,- "brotli": 43377++ "min": 169480,++ "gzip": 51789,++ "brotli": 44979},"entry:modeling": {"min": 21149,@@@ -129,14 -129,14 +129,14 @@@"brotli": 4675},"entry:light-bake": {-- "min": 72900,-- "gzip": 26484,-- "brotli": 23361++ "min": 73438,++ "gzip": 26713,++ "brotli": 23608},"entry:path-tracer": {-- "min": 33334,-- "gzip": 13432,-- "brotli": 11761++ "min": 33435,++ "gzip": 13479,++ "brotli": 11838},"entry:texture-set": {"min": 1837,@@@ -144,24 -144,24 +144,24 @@@"brotli": 762},"entry:agent-scene": {- "min": 211709,- "gzip": 65808,- "brotli": 57572- "min": 211577,- "gzip": 65756,- "brotli": 57523++ "min": 214722,++ "gzip": 66960,++ "brotli": 58652},"entry:agent-scene+lazy": {- "min": 663920,- "gzip": 228461,- "brotli": 201694- "min": 659276,- "gzip": 227206,- "brotli": 200480++ "min": 677234,++ "gzip": 233780,++ "brotli": 206588},"entry:agent-asset": {- "min": 307016,- "gzip": 97483,- "brotli": 85682- "min": 306884,- "gzip": 97436,- "brotli": 85596++ "min": 309821,++ "gzip": 98589,++ "brotli": 86642},"entry:agent-asset+lazy": {- "min": 700994,- "gzip": 240176,- "brotli": 211765- "min": 696350,- "gzip": 238925,- "brotli": 210566++ "min": 714100,++ "gzip": 245447,++ "brotli": 216586},"entry:hdri": {"min": 8075,@@@ -179,44 -179,44 +179,44 @@@"brotli": 1425},"entry:material-layer-shaders": {- "min": 76528,- "gzip": 19676,- "brotli": 17263- "min": 71897,- "gzip": 18688,- "brotli": 16369++ "min": 76556,++ "gzip": 19687,++ "brotli": 17305},"entry:light-linking": {- "min": 67578,- "gzip": 17981,- "brotli": 15804- "min": 67458,- "gzip": 17938,- "brotli": 15753++ "min": 67970,++ "gzip": 18132,++ "brotli": 15941},"entry:cascaded-shadows": {- "min": 95594,- "gzip": 26620,- "brotli": 22668- "min": 95474,- "gzip": 26574,- "brotli": 22646++ "min": 95719,++ "gzip": 26679,++ "brotli": 22674},"scene:lit-box": {- "min": 218625,- "gzip": 60169,- "brotli": 51383- "min": 218221,- "gzip": 59990,- "brotli": 51264++ "min": 218641,++ "gzip": 60179,++ "brotli": 51428},"scene:gltf-box": {- "min": 280207,- "gzip": 80800,- "brotli": 70220- "min": 277847,- "gzip": 80037,- "brotli": 69616++ "min": 280223,++ "gzip": 80810,++ "brotli": 70295},"scene:gltf-box+lazy": {- "min": 291152,- "gzip": 83995,- "brotli": 73136- "min": 284280,- "gzip": 82027,- "brotli": 71422++ "min": 291196,++ "gzip": 84016,++ "brotli": 73226},"scene:agent-scene": {- "min": 323543,- "gzip": 96819,- "brotli": 84320- "min": 323127,- "gzip": 96652,- "brotli": 84272++ "min": 326356,++ "gzip": 97862,++ "brotli": 85183},"scene:agent-scene+lazy": {- "min": 775754,- "gzip": 259481,- "brotli": 228479- "min": 770826,- "gzip": 258108,- "brotli": 227330++ "min": 788868,++ "gzip": 264689,++ "brotli": 233118}}}diff --cc bench/size/budgets.jsonindex 46fd96f0,3de373e2..1541bc02--- a/bench/size/budgets.json+++ b/bench/size/budgets.json@@@ -1,5 -1,5 +1,5 @@@{-- "archiveBytes": 716000,++ "archiveBytes": 724000,"goals": {"lit-box": 50000,"gltf-box": 80000,@@@ -29,23 -29,23 +29,23 @@@"entry:terrain": 3400,"entry:grass": 4400,"entry:clutter": 5300,-- "entry:light-bake": 27100,++ "entry:light-bake": 27300,"entry:path-tracer": 13800,"entry:texture-set": 900,- "entry:agent-scene": 67200,- "entry:agent-scene+lazy": 233100,- "entry:agent-asset": 99500,- "entry:agent-asset+lazy": 245000,- "entry:agent-scene": 67100,- "entry:agent-scene+lazy": 232600,- "entry:agent-asset": 99400,- "entry:agent-asset+lazy": 244300,++ "entry:agent-scene": 68300,++ "entry:agent-scene+lazy": 238500,++ "entry:agent-asset": 100600,++ "entry:agent-asset+lazy": 250400,"entry:hdri": 3300,"entry:camera-effects": 8600,"entry:render-passes": 1700,- "entry:material-layer-shaders": 19100,- "entry:light-linking": 18300,- "entry:cascaded-shadows": 27200,- "scene:lit-box": 61200,- "scene:gltf-box": 81700,- "scene:gltf-box+lazy": 83700,- "scene:agent-scene": 98600,- "scene:agent-scene+lazy": 263500+ "entry:material-layer-shaders": 20100,- "entry:light-linking": 18400,- "entry:cascaded-shadows": 27200,++ "entry:light-linking": 18500,++ "entry:cascaded-shadows": 27300,+ "scene:lit-box": 61400,+ "scene:gltf-box": 82500,+ "scene:gltf-box+lazy": 85700,- "scene:agent-scene": 98800,- "scene:agent-scene+lazy": 264700++ "scene:agent-scene": 99900,++ "scene:agent-scene+lazy": 270000}}