3D engine that AI agents drive
Merge remote-tracking branch 'origin/main' into HEAD
Nguyen Xuan An7416afb80577
diff --cc CHANGELOG.mdindex 2506aef1,2a7a607b..d7336b46--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -2,8 -2,9 +2,11 @@@## Unreleased+- Use one expression language for fields and drivers (issue #98). `src/expression.js` holds the limits, number literals, operator table, syntax and hostile-input checks; `src/mesh-fields.js` (per mesh element: attributes, noise, random, vectors) and `src/motion-expression.js` (per time: `time`, node reads) only add their own inputs, and each rejects the other's with a message that names the context. **This changes driver expressions** (neither language was released): an operator with one operand may be written bare, `{"neg": x}`, in drivers as in fields; `if` takes its second operand when the condition is not 0 (a driver used above 0); `sqrt` of a negative, `pow` overflow and `mod` by 0 give 0 instead of an error; `smoothstep` with equal edges is a step; `div` by 0 is still a non-finite error in a driver, because a hostile-input test pins it, and 0 in a field. Drivers gain `ceil`, `round`, `sign`, `lte`, `gte`, `eq`, `and`, `or`, `not` and booleans; fields gain `atan2` and `saturate`. The unknown-operator hint of fields lists operators in a new order. Error messages for a malformed driver changed in wording and are all TypeErrors. The MCP schema for drivers now points at the field language instead of listing operators (schemas 183,741 to 183,762 bytes), and the `scene_capabilities` budget rises from 3,050 to 3,100 bytes for two operator names.++ - Add branches and labelled images to the agent tools (part of issue #67, no new tool). `scene_apply` with a `branch` name runs the operations on a scratch copy and stores the result in a snapshot store that holds one copy per distinct recipe (8 branches), leaving the scene, its revision and its checkpoints untouched. `scene_review` shots take a `branch` and render it in a private scene; `scene_restore` with `branch` keeps one. `labels: true` on `scene_look` and `scene_review` draws part names, material tags and mesh lint problems on the image and returns them as JSON with pixel positions. Branch names are bounded (`^[a-z][a-z0-9_-]{0,23}$`). The tool-schema budget rose by 800 bytes in total (150 for `scene_apply`). `npm run smoke:agent-branches` drives it through MCP on SwiftShader.++ - Add a bounded material node graph (issue #50): material `pattern` of `type: "graph"` bakes noise, voronoi, wave, checker, gradient, ramp, maths and `uv` nodes on the CPU into base colour, roughness, metallic, emission and height (a normal map, so bump). The graph is data, never shader text; nodes, depth, ramp stops, texture size and work are checked before any pixel is computed. Add `mapping: "uv"` to every pattern so it follows `uv_unwrap` UVs instead of box projection; the emissive map now box-maps like the other maps. The 11 presets bake the same bytes as before. Covered in the MCP schema, `scene_capabilities` (`materialGraph`, `materialMappings`), GLB export, `docs/agent-scene.md`, `docs/material-maps.md` and the `brick-graph` reference scene.- Add `decimate`, `remesh` and generated levels of detail (issue #40). `decimate` (a `ratio` of triangles) is a quadric edge collapse of our own that keeps open boundaries, the borders between tags and the tags themselves; it measured 0.25 to 0.85 of the Hausdorff error of meshoptimizer 1.3.0 on the same meshes and adds no dependency, but takes about 2.5 s on 100k triangles where meshoptimizer takes 0.09 s. `remesh` (`voxelSize` or `resolution`, at most 192 per side and 4,194,304 cells, checked before allocation) builds a closed quad surface from a BVH signed distance with surface nets. Both are edits and stack nodes, in the MCP schemas, and load on demand with the mesh code. `generateMeshLods`, `generateGeometryLods` and `generateAssetLods` (also in `67js/addons/mesh`) return levels with a measured error for runtime selection (issue #37). Four decimate and two remesh cases join the Blender comparison, compared by volume, area and Hausdorff distance because face counts differ.- Make the default look good without tuning. Recipes get an image-based environment: `environment.setup` (`daylight` by default, `overcast`, `sunset`, `studio`) selects a small procedural sky map generated in code, plus its key light, with `environmentIntensity` and `environmentRotation`; no URLs or files from tool input. `effects.ambientOcclusion` (0 to 1) and `ambientOcclusionRadius` add screen-space ambient occlusion from the depth texture. It is off by default: measured with `npm run reference -- --ambient-occlusion`, it improved no score by more than 0.002 (strength 0.8: -0.0019 in foliage, +0.0047 in lit-interior; strength 0.4, radius 0.3: within +0.0013 everywhere). When used it compiles and allocates on first use and costs about 16 ms on a 190 ms SwiftShader frame (8 percent). `scene_capabilities` lists `lightingSetups`, `defaultLightingSetup` and `ambientOcclusion`. **This changes the look of every existing recipe that sets no lighting**: it now has an environment map, a key color of `[3, 2.8, 2.5]` instead of `[5.2, 4.7, 4.1]`, and a fill intensity of `0` instead of `1`. The engine default is unchanged (occlusion off, no map) so code scenes keep their pixels. Screen-space reflections are not part of this. The `scene:lit-box` size budget rises by 100 bytes gzip for the environment and occlusion code. The reference suite gets `--ambient-occlusion`, and its Blender renderer drops triangles that repeat a vertex, which crashed Blender on the skinned characterdiff --cc bench/size/baseline.jsonindex 3bc3c06f,132a1512..0c615fd5--- a/bench/size/baseline.json+++ b/bench/size/baseline.json@@@ -14,9 -14,9 +14,9 @@@},"bundles": {"entry:core": {- "min": 274298,- "gzip": 77983,- "brotli": 66640- "min": 274345,- "gzip": 77993,- "brotli": 66486++ "min": 274408,++ "gzip": 78007,++ "brotli": 66600},"entry:model": {"min": 40093,@@@ -64,9 -64,9 +64,9 @@@"brotli": 12998},"entry:mesh": {-- "min": 210457,-- "gzip": 71261,-- "brotli": 60364++ "min": 211151,++ "gzip": 71754,++ "brotli": 60810},"entry:shrinkwrap": {"min": 56188,@@@ -129,24 -129,24 +129,24 @@@"brotli": 762},"entry:agent-scene": {- "min": 189992,- "gzip": 57090,- "brotli": 49452- "min": 190633,- "gzip": 57326,- "brotli": 49610++ "min": 190657,++ "gzip": 57334,++ "brotli": 49621},"entry:agent-scene+lazy": {- "min": 489100,- "gzip": 160873,- "brotli": 140211- "min": 498812,- "gzip": 164401,- "brotli": 143354++ "min": 497784,++ "gzip": 164822,++ "brotli": 143860},"entry:agent-asset": {- "min": 269753,- "gzip": 81908,- "brotli": 71452- "min": 270394,- "gzip": 82147,- "brotli": 71444++ "min": 273341,++ "gzip": 83733,++ "brotli": 72966},"entry:agent-asset+lazy": {- "min": 516201,- "gzip": 168134,- "brotli": 146309- "min": 525913,- "gzip": 171671,- "brotli": 149210++ "min": 524940,++ "gzip": 172137,++ "brotli": 149822},"entry:hdri": {"min": 8075,@@@ -154,24 -154,24 +154,24 @@@"brotli": 2801},"scene:lit-box": {- "min": 206306,- "gzip": 56013,- "brotli": 47870+ "min": 206353,+ "gzip": 56023,+ "brotli": 47903},"scene:gltf-box": {- "min": 264183,- "gzip": 74981,- "brotli": 64331+ "min": 264230,+ "gzip": 74991,+ "brotli": 64299},"scene:agent-scene": {- "min": 293377,- "gzip": 84106,- "brotli": 72209- "min": 294018,- "gzip": 84354,- "brotli": 72502++ "min": 294042,++ "gzip": 84365,++ "brotli": 72463},"scene:agent-scene+lazy": {- "min": 592485,- "gzip": 187890,- "brotli": 162954- "min": 602197,- "gzip": 191435,- "brotli": 166207++ "min": 601169,++ "gzip": 191853,++ "brotli": 166724}}}diff --cc bench/size/budgets.jsonindex 1d2d99fa,9fb937a1..88289792--- a/bench/size/budgets.json+++ b/bench/size/budgets.json@@@ -15,7 -15,7 +15,7 @@@"entry:sculpt": 2500,"entry:surface": 10100,"entry:mesh-query": 15900,-- "entry:mesh": 72700,++ "entry:mesh": 73200,"entry:shrinkwrap": 18300,"entry:surface-attachment": 11800,"entry:physics": 18000,@@@ -28,14 -28,14 +28,14 @@@"entry:grass": 4400,"entry:clutter": 5300,"entry:texture-set": 900,- "entry:agent-scene": 58300,- "entry:agent-scene+lazy": 164100,- "entry:agent-asset": 83600,- "entry:agent-asset+lazy": 171500,+ "entry:agent-scene": 58500,- "entry:agent-scene+lazy": 167700,- "entry:agent-asset": 83800,- "entry:agent-asset+lazy": 175200,++ "entry:agent-scene+lazy": 168200,++ "entry:agent-asset": 85500,++ "entry:agent-asset+lazy": 175600,"entry:hdri": 3300,"scene:lit-box": 57200,"scene:gltf-box": 76500,- "scene:agent-scene": 85800,- "scene:agent-scene+lazy": 191700+ "scene:agent-scene": 86100,- "scene:agent-scene+lazy": 195300++ "scene:agent-scene+lazy": 195700}}diff --cc bench/tool-cost-budgets.jsonindex 056b447b,6afa0d4d..f7517b6b--- a/bench/tool-cost-budgets.json+++ b/bench/tool-cost-budgets.json@@@ -1,16 -1,16 +1,16 @@@{- "measured": "2026-10-31, from scripts/measure-tool-cost.mjs; was 373388 schema bytes before shared IDs and recipe references",- "schemaTotalBytes": 183800,- "measured": "2026-10-31, from scripts/measure-tool-cost.mjs; raised by 800 total and 150 for scene_apply for branch and labels fields (no new tool); was 373388 schema bytes before shared IDs and recipe references",++ "measured": "2026-10-31, from scripts/measure-tool-cost.mjs; raised by 800 total and 150 for scene_apply for branch and labels fields (no new tool); raised by 20 for scene_create and 20 for the scene_capabilities result after merging the expression language with the material graph; was 373388 schema bytes before shared IDs and recipe references",+ "schemaTotalBytes": 190700,"schemaToolBytes": {- "scene_create": 59400,- "scene_apply": 44300,- "scene_create": 60900,++ "scene_create": 60920,+ "scene_apply": 47550,"mesh_edit": 34000,- "scene_create_asset": 18300,+ "scene_create_asset": 19750,"mesh_stack": 11500},"schemaOtherToolBytes": 4000,"resultBytes": {- "scene_capabilities": 3100,- "scene_capabilities": 3410,++ "scene_capabilities": 3430,"scene_create": 1400,"scene_inspect": 1400,"mesh_inspect": 1200,