3D engine that AI agents drive
Merge remote-tracking branch 'origin/main' into HEAD
Nguyen Xuan An81414bd30f3e
diff --cc CHANGELOG.mdindex 4209ac4d,4bbe8eb6..216fdc15--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -2,8 -2,12 +2,14 @@@## Unreleased+- Add render passes, depth of field and camera motion blur (issue #54, first slice). Render jobs of kind `image` or `stills` take `settings.passes` (`albedo`, `normal`, `emission`, `depth`, `objectId`) and write each as a raw, unantialiased PNG beside the lit image (`render-depth.png`, `frame-3-objectId.png`); depth is 16 bits over 100 m in red and green, object IDs are 24 bits with the part names in the job metrics. In code, `renderer.render({ pass })` draws a pass into its own non-multisampled target. `effects.depthOfField` (`blur`, `focusDistance`) and `effects.motionBlur` (`shutter`) are new recipe effects: fixed sample patterns and a per-pixel rotation from the pixel position, so a seek to a frame repeats the same pixels. They live in the new `67js/addons/camera-effects` entry; the preview installs it, and the core renderer only gains a stage hook and the pass branch (a compiled-out shader feature). Motion blur follows camera tracks only, sampled from time at `motion.start + elapsed - shutter`. Measured on SwiftShader through MCP (`npm run smoke:render-passes`): 8 stills with 5 passes each, then four seeks, all byte-identical to the same frame in the sequence. Temporal anti-aliasing, accumulation and the compositing graph of #54 are not part of this slice.++ - Expose clip layers, bone masks and name retargeting through MCP, and morph clips in `createAssetPose` (issue #59, in part). An asset recipe's `motion.layers` (up to 8) plays the file's own clips at motion time with a bone `mask`, `weight`, `speed`, `offset`, `loop`, `additive` with `reference`, `bones` (clip track to another asset node) and `morph`, before tracks and IK, so a character walks and waves at once; everything is checked against the asset and bounded, and a seek equals playing. `morphClipFromGltfAnimation` and a layer's `morphs` put morph weights through `createAssetPose` (masks pick parts by their owning bone), `createAssetLayerEvaluator` serves hosts that stage the pose themselves, and `asset.stagePose` takes `morphWeights`. Add the `robot-walk-wave` task to the agent modeling suite and extend `npm run smoke:character`. Not done: foot tilt on slopes, full-body IK, and rest-pose retargeting from another asset through MCP. Raise `entry:skeleton-pose` to 19,000 and `entry:agent-asset` to 85,200 bytes gzip, and the tool schema budgets by 800 bytes (`scene_apply` to 47,800, `scene_create_asset` to 20,150, total to 190,700).+ - 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 412b5e1c,02e1b477..7102dc97--- a/bench/size/baseline.json+++ b/bench/size/baseline.json@@@ -14,9 -14,9 +14,9 @@@},"bundles": {"entry:core": {- "min": 277563,- "gzip": 79010,- "brotli": 67555- "min": 274408,- "gzip": 78007,- "brotli": 66600++ "min": 277673,++ "gzip": 79031,++ "brotli": 67391},"entry:model": {"min": 40093,@@@ -39,9 -39,9 +39,9 @@@"brotli": 7331},"entry:gltf": {- "min": 153718,- "gzip": 47184,- "brotli": 40362- "min": 153176,- "gzip": 46991,- "brotli": 40335++ "min": 154791,++ "gzip": 47466,++ "brotli": 40606},"entry:modeling": {"min": 15517,@@@ -129,59 -129,49 +129,59 @@@"brotli": 762},"entry:agent-scene": {- "min": 192267,- "gzip": 57778,- "brotli": 49957- "min": 190657,- "gzip": 57336,- "brotli": 49589++ "min": 192932,++ "gzip": 58010,++ "brotli": 50224},"entry:agent-scene+lazy": {- "min": 491375,- "gzip": 161557,- "brotli": 140698- "min": 500517,- "gzip": 165719,- "brotli": 144583++ "min": 502792,++ "gzip": 166390,++ "brotli": 145171},"entry:agent-asset": {- "min": 272031,- "gzip": 82581,- "brotli": 71917- "min": 281287,- "gzip": 86290,- "brotli": 75357++ "min": 283565,++ "gzip": 86956,++ "brotli": 75945},"entry:agent-asset+lazy": {- "min": 518479,- "gzip": 168806,- "brotli": 146806- "min": 532886,- "gzip": 174694,- "brotli": 152213++ "min": 535164,++ "gzip": 175358,++ "brotli": 152837},"entry:hdri": {"min": 8075,"gzip": 3138,"brotli": 2801},+ "entry:camera-effects": {+ "min": 23985,+ "gzip": 8396,+ "brotli": 6688+ },+ "entry:render-passes": {+ "min": 3412,+ "gzip": 1608,+ "brotli": 1425+ },"scene:lit-box": {- "min": 209404,- "gzip": 57025,- "brotli": 48681- "min": 206353,- "gzip": 56023,- "brotli": 47903++ "min": 209451,++ "gzip": 57034,++ "brotli": 48658},"scene:gltf-box": {- "min": 267284,- "gzip": 75956,- "brotli": 65218- "min": 265256,- "gzip": 75253,- "brotli": 64620++ "min": 268357,++ "gzip": 76237,++ "brotli": 65528},"scene:agent-scene": {- "min": 296711,- "gzip": 85191,- "brotli": 73189- "min": 294042,- "gzip": 84365,- "brotli": 72463++ "min": 297376,++ "gzip": 85436,++ "brotli": 73344},"scene:agent-scene+lazy": {- "min": 595819,- "gzip": 188973,- "brotli": 163948- "min": 603902,- "gzip": 192748,- "brotli": 167481++ "min": 607236,++ "gzip": 193818,++ "brotli": 168362}}}diff --cc bench/size/budgets.jsonindex c22f91ee,26b3db79..212db5cc--- a/bench/size/budgets.json+++ b/bench/size/budgets.json@@@ -5,12 -5,12 +5,12 @@@"agent-scene": 100000},"budgets": {-- "entry:core": 79600,++ "entry:core": 80700,"entry:model": 14400,"entry:nature": 13200,"entry:motion": 13600,"entry:canvas2d": 9400,- "entry:gltf": 47700,- "entry:gltf": 48000,++ "entry:gltf": 48500,"entry:modeling": 6600,"entry:sculpt": 2500,"entry:surface": 10100,@@@ -28,16 -28,14 +28,16 @@@"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": 169100,- "entry:agent-asset": 88100,- "entry:agent-asset+lazy": 178200,++ "entry:agent-scene": 59200,++ "entry:agent-scene+lazy": 169800,++ "entry:agent-asset": 88700,++ "entry:agent-asset+lazy": 178900,"entry:hdri": 3300,- "scene:lit-box": 57200,- "scene:gltf-box": 76800,- "scene:agent-scene": 86100,- "scene:agent-scene+lazy": 196700+ "entry:camera-effects": 8600,+ "entry:render-passes": 1700,- "scene:lit-box": 57200,- "scene:gltf-box": 76500,- "scene:agent-scene": 85800,- "scene:agent-scene+lazy": 191700++ "scene:lit-box": 58200,++ "scene:gltf-box": 77800,++ "scene:agent-scene": 87200,++ "scene:agent-scene+lazy": 197700}}diff --cc scripts/mcp-server.mjsindex 80b583ef,27fb60a1..78a117ce--- a/scripts/mcp-server.mjs+++ b/scripts/mcp-server.mjs@@@ -5,7 -6,7 +6,7 @@@ import { setPriority, constants } fromimport { resolve } from 'node:path';import { pathToFileURL } from 'node:url';import packageMetadata from '../package.json' with { type: 'json' };- import { MATERIAL_PATTERN_TYPES, LIGHTING_SETUP_NAMES, RENDER_PASS_NAMES } from '../src/agent-scene-capabilities.js';-import { MATERIAL_PATTERN_TYPES, MATERIAL_MAPPINGS, MATERIAL_GRAPH_OUTPUTS, MATERIAL_GRAPH_OPERATORS, MATERIAL_GRAPH_LIMITS, LIGHTING_SETUP_NAMES } from '../src/agent-scene-capabilities.js';++import { MATERIAL_PATTERN_TYPES, MATERIAL_MAPPINGS, MATERIAL_GRAPH_OUTPUTS, MATERIAL_GRAPH_OPERATORS, MATERIAL_GRAPH_LIMITS, LIGHTING_SETUP_NAMES, RENDER_PASS_NAMES } from '../src/agent-scene-capabilities.js';import { MATERIAL_LAYER_SCALAR_RANGES, MATERIAL_LAYER_COLOR_RANGES } from '../src/material-layers.js';const finite = z.number().min(-3.4028234663852886e38).max(3.4028234663852886e38);diff --cc src/shaders.jsindex 41bc2816,b0e13065..55c99cce--- a/src/shaders.js+++ b/src/shaders.js@@@ -716,11 -693,7 +716,11 @@@ void main()}float alpha = surfaceAlpha(textureAlpha);vec3 emission = emissionColor * surface.z;- if (USES_EMISSIVE_MAP) emission *= texture(emissiveMap, textureUV).rgb;+ if (USES_EMISSIVE_MAP) emission *= (boxMapScale > 0.0 ? sampleBox(emissiveMap) : texture(emissiveMap, textureUV)).rgb;+ if (USES_RENDER_PASS) {+ outputColor = vec4(renderPassValue(color, normal, emission), 1.0);+ return;+ }if (TAG_UNLIT) {vec3 radiance = color * exposure + emission;outputColor = vec4(hdrEnabled > 0.5 ? radiance : pow(max(radiance, vec3(0)), vec3(1.0 / 2.2)), alpha);diff --cc tests/agent-preview.test.jsindex d7fc34ef,f35be166..630076c4--- a/tests/agent-preview.test.js+++ b/tests/agent-preview.test.js@@@ -69,10 -70,8 +70,10 @@@ function previewHarness()setManifoldModuleLoader: () => {},needsPhysics, loadPhysicsEngine, physicsEngineLoaded, setPhysicsModuleLoader: () => {},parseGltf, Uint8Array, atob,- applyProjection, mat4, resolveAgentShadow, agentEnvironmentMap,+ applyProjection, mat4, resolveAgentShadow, agentEnvironmentMap, BRANCH_LIMITS, createBranchStore, printableLabel,Renderer67: FaultInjectedRenderer,+ // The optional addons only plug stages into a real renderer; the fault-injected one needs none.+ installCameraEffects: renderer => renderer, installRenderPasses: renderer => renderer,});// Evaluate only trusted repository adapter code; inject the driver boundary for failure cases.new Script(source).runInContext(context);diff --cc tests/agent-runtime.test.jsindex 4bf7384c,e901888a..dedf2fa6--- a/tests/agent-runtime.test.js+++ b/tests/agent-runtime.test.js@@@ -6,8 -6,9 +6,9 @@@ import { readFile } from 'node:fs/promiimport { createServer } from 'node:http';import { randomUUID } from 'node:crypto';import { createContext, Script } from 'node:vm';-import { AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS } from '../src/agent-scene-capabilities.js';+import { AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS, RENDER_PASS_NAMES, RENDER_PASS_DEPTH_RANGE } from '../src/agent-scene-capabilities.js';import { normalizeReview, REVIEW_LIMITS } from '../scripts/agent-review.mjs';+ import { BRANCH_LIMITS, validateBranchName } from '../src/agent-branches.js';test('runtime reports real scene capabilities without launching a browser and closes idempotently', async () => {const runtime = createAgentRuntime({ backend: 'cpu', memory: 64 });@@@ -96,7 -97,7 +97,7 @@@ async function reviewRuntimeHarness({ fconst context = createContext({ createServer, randomUUID, existsSync: () => true,readFile: async () => '', packageMetadata: { version: 'test' },createRequire: () => ({ resolve: () => { throw new Error('no peer in tests'); } }),- AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS, RENDER_PASS_NAMES, RENDER_PASS_DEPTH_RANGE, normalizeReview, REVIEW_LIMITS, isPreviewHost,- AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS, normalizeReview, REVIEW_LIMITS, isPreviewHost, BRANCH_LIMITS, validateBranchName,++ AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS, RENDER_PASS_NAMES, RENDER_PASS_DEPTH_RANGE, normalizeReview, REVIEW_LIMITS, isPreviewHost, BRANCH_LIMITS, validateBranchName,chromium: { launch: async () => browser }, URL, Buffer, process, performance, setTimeout, clearTimeout,});new Script(`${source}\nglobalThis.runtime = createAgentRuntime({ backend: 'cpu' });`).runInContext(context);