3D engine that AI agents drive
Merge origin/main
Nguyen Xuan An143366e6e3e1
diff --cc CHANGELOG.mdindex 2f4cc741,4df02c5f..9de0dec2--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -2,7 -2,17 +2,18 @@@## Unreleased+- 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` (default `0.8`, `0` turns it off) and `ambientOcclusionRadius` add screen-space ambient occlusion from the depth texture; 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]`, a fill intensity of `0` instead of `1`, and occlusion. The engine default is unchanged (occlusion off, no map) so code scenes keep their pixels. Reference scores against Cycles move by +0.0013 to -0.0019 in 8 of 9 scenes and by +0.0047 in `lit-interior`. Screen-space reflections are not part of this. Size budgets rise: `entry:core` +3,000, `entry:gltf` +500, `entry:agent-scene` +1,400, `entry:agent-asset` +1,300, `scene:lit-box` +3,500, `scene:gltf-box` +3,100, `scene:agent-scene` +3,100 (bytes gzip, about half of it spot and area light code from the lights branch)+ - Reach Rapier from recipes: a `physics` section (and a `set-physics` operation) puts rigid bodies on node IDs with box, ball, capsule, convex or trimesh colliders fitted to their geometry, joints, gravity and a duration of up to 10 seconds. It is recorded once at 60 steps a second and seeks like `motion`, so a seek back repeats the same frame (checked as identical PNG bytes on SwiftShader through MCP). `scene_inspect` reports per-body final positions and resting times, contacts and sensor enter and leave events. Rapier stays an optional peer, served to the preview from `node_modules` like Manifold, so the MCP server bundle does not grow.+ - Add trimesh and convex-hull colliders (bounded triangle and point counts, checked before allocation), sensors with enter and leave events, and 16-bit collision groups and masks to `addons/physics`, plus `contactEvents`, `restFrames`, `bakePhysicsScene`, `loadPhysicsEngine` and `setPhysicsModuleLoader`. A collider with `sensor` now bakes instead of throwing.+ - Add the `tray-drop` task to the agent modeling suite: balls dropped into a pocket cut in an authored mesh, graded on a fixed trimesh body, balls resting on the pocket floor and a repeatable seek. Raise four size budgets for the physics code (`entry:physics` to 17,900, `entry:agent-scene` to 121,100, `entry:agent-asset` to 128,500, `scene:agent-scene` to 147,300 bytes gzip).++ - Add bounded field expressions: a JSON language of math, comparison, logic, vectors, seeded noise and attributes (position, normal, index, tags) that compiles once to closures over typed arrays and never executes a string. It limits nodes (64), depth (12), elements (250,000) and node-evaluations (8 million) before it evaluates, and only reads operator names from a fixed table. It drives a `{ "field": expression }` face selection rule, `set_position` and `displace` as edits and stack nodes, and a `where` filter for instances. `displace` and `set_position` match Blender's Displace modifier and a Geometry Nodes Set Position node in five new golden cases+ - Add `instances` on a recipe node: repeat its geometry at the points of a grid, a seeded scatter in a box or the surface of a geometry, with `where`, `yaw`, `alignToNormal` and `scale`, at most 2048 candidate points. It expands to ordinary nodes that share geometry and material, so the renderer draws one instanced batch. Add the `pillar-court` task to the agent modeling suite+ - Add the `scene_export_glb` MCP tool (22 tools now) and morph weight clips in `exportGlb`. The tool writes the active recipe or imported asset scene as a GLB under `<jobs>/exports/` with a server-chosen name and returns the path, byte count and SHA-256; it takes no path, keeps the newest eight files and refuses more than 32 MiB. It exports the current pose (pattern textures, imported textures, skins, morph weights, IK as posed), `motionTime` seeks authored motion first, and `clip` adds an imported asset's source clip. Clip tracks with `property: 'weights'` write a SCALAR sampler of one weight per target. Checked in Blender 5.2: a patterned recipe opens with 2 meshes and 3 images, the robot with IK opens as 1 armature, 43 bones and 20 meshes, and its Walking clip as one action of 23 frames. Nothing in `src/index.js` changes, so no size budget moves+ - Add material layers: `clearcoat` and `clearcoatRoughness`, `transmission` with `thickness`, `ior`, `attenuationColor` and `attenuationDistance`, `sheenColor` and `sheenRoughness`, and `specular` and `specularColor`. Recipes, the MCP schema, glTF import and export (`KHR_materials_clearcoat`, `transmission`, `volume`, `ior`, `specular`, `sheen`) all take them, each checked at the boundary. Transmission refracts the opaque scene like the `liquid` material. Anisotropy and iridescence are not rendered yet. Import of those two still warns+ - Change the glTF import of the six layer extensions above from accepted-and-ignored to rendered, so `asset.warnings` no longer lists them+ - Add spot lights (`environment.spotLights`, 8), rectangular area lights (`environment.areaLights`, 4) and shadows for point and spot lights (`castShadow: true`). Intensity of a spot light is candela, as for a point light, with Blender's cone mask. Area lights use a representative point, within 1.2 percent of Cycles on the axis. Shadows share one 2048 x 3072 depth atlas of 24 tiles (24 MiB, allocated on first use): a point light takes 6 and a spot light 1, and a request for more is an error. The shader code and the atlas exist only in a scene that uses them. Recipes get all of it through `set-environment`, the MCP schema and `scene_capabilities` (`maxSpotLights`, `maxAreaLights`, `localShadows`). Cascaded directional shadows and light linking are not part of this+- Add ten cutting and repair edits: `fill_holes`, `dissolve_faces`, `dissolve_edges`, `dissolve_verts`, `dissolve_limited`, `bisect_plane` (with `fill`, `clearInner`, `clearOuter`), `bridge_edge_loops` (with `segments`), `subdivide_edges`, `grid_fill` and `knife_project`. Each tags what it makes, and the edge rule `{ "open": true }` picks boundary edges. The lint message for an open boundary now suggests `fill_holes`. 18 new cases match Blender in counts, face sizes, area, volume and positions; the knife is compared only with a straight plane cut and differs where a face runs along the projection direction- Export textures, skeletons and clips to GLB: `exportGlb(parts, { nodes, clips, maxTextureSize })` now writes `map`, `normalMap`, `metallicRoughnessMap`, `occlusionMap` and `emissiveMap` as embedded PNG (limit 2048 px by default, with an error that names the option), skins with joint nodes and inverse bind matrices, and animation clips (translation, rotation and scale tracks; SMOOTH becomes cubic with zero tangents). Pattern materials export their baked textures with box projected UVs, so the picture matches without `uv_unwrap`. It previously threw on skins and on every texture channel. The `entry:core` size budget goes from 67,100 to 70,500 bytes gzip (+3,400)- Make the first frame and the SwiftShader frame cost less, with the same pixels. The main fragment shader now compiles only the features that a scene uses (maps, splat layers, moss, alpha and the special material tags), and a part that needs another feature later recompiles it. All programs, with the environment prefilter, now start together and use `KHR_parallel_shader_compile`. On an RTX 3060 the first frame went from 3.7 to 4.4 seconds down to 0.5 to 1.0 seconds, and a SwiftShader frame costs 0.4 to 0.5 times what it did. `bench/runtime/PROFILE.md` has the profilediff --cc bench/reference/README.mdindex f33ae801,8f5b1e93..d5ba2a85--- a/bench/reference/README.md+++ b/bench/reference/README.md@@@ -46,10 -46,10 +46,11 @@@ EEVEE against Cycles is a yardstick: i## Limits- Scores come from one camera for each scene and one machine. They do not measure motion or speed.-- 67.js reaches an HDRI only from code. A recipe can not set one yet, so these scores are better than what an agent gets today (issue #53).+- This suite sets an HDRI from code and turns occlusion on at the recipe default. A recipe reaches only the named procedural setups, so these scores still describe a better environment than an agent gets (issue #53).+- `character` has no new EEVEE render: Blender 5.2.2 crashed on that scene in `mesh_set_custom_normals` in every retry (a pre-existing crash that this change does not touch), so its EEVEE columns keep the earlier numbers.- The Blender leaf material has no translucency, and the 67.js foliage shader adds it by a trick. `foliage` is therefore partly a difference in materials.- `render-blender.py` does not read normal maps. No scene uses one yet, so a new scene with a normal map must add that first.- - `glass` compares the 67.js `liquid` material with a Blender glass material. 67.js has no glass material (issue #51).+ - `glass` and `car-paint` use the real 67.js `transmission` and `clearcoat` layers, and the Blender side sets the same values on the Principled BSDF. 67.js refracts through the front surface only, so the sphere does not show the inverted sky that Cycles traces through the back face.+ - `car-paint` scored 0.1521 against Cycles and `glass` 0.1326 (it was 0.1450 with the `liquid` material). The other scenes scored the same as in the table above, to four digits. The table above is the 2026-10-30 baseline and has not been rewritten.- `fog` has no noise on either side. EEVEE and 67.js approximate scattering, and Cycles follows 8 volume bounces.- Sample counts are fixed: 256 for Cycles with denoising, 64 for EEVEE and 4 MSAA samples for 67.js.diff --cc docs/parity.mdindex e5f1c083,7c80bc69..81bb7dc6--- a/docs/parity.md+++ b/docs/parity.md@@@ -190,8 -190,8 +190,8 @@@ To move to a new Blender release, run `| Rendering > Cameras | partial | Perspective, orthographic views, focal length and animated paths. There is no depth of field. | [camera-path](../tests/camera-path.test.js), [camera](../tests/camera.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, not cascaded. | [lighting](../tests/lighting.test.js), `npm run reference` scene `spot-area` | #52 || Rendering > Lights > Light Linking | missing | No light linking. | | #52 |-| Rendering > Lights > World Environment | partial | Recipes have sky colors, daylight and fog. Code can load an HDRI, and recipes can not reach it. | [environment](../tests/environment.test.js) | #53 |+| Rendering > Lights > World Environment | partial | Recipes pick a named setup (`daylight`, `overcast`, `sunset`, `studio`) that carries a procedural environment map, and get 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. | [environment](../tests/environment.test.js), [default look](../tests/default-look.test.js) | #53 |- | Rendering > Materials > Components | partial | Surfaces with PBR factors and five maps. There are no volume materials or displacement. | [texture-set](../tests/texture-set.test.js) | #50, #51 |+ | 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. There is no anisotropy, iridescence, subsurface scattering, volume material or displacement. | [texture-set](../tests/texture-set.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`. | | || Rendering > Materials > Settings | partial | Opaque and blend in recipes, and mask on imported assets, with double-sided support. | [gltf-extensions](../tests/gltf-extensions.test.js) | #51 |diff --cc scripts/agent-preview-browser.jsindex cf032eec,98814e37..1ea6c503--- a/scripts/agent-preview-browser.js+++ b/scripts/agent-preview-browser.js@@@ -2,9 -2,12 +2,12 @@@ import { createAgentScene, needsMeshBooimport { Renderer67 } from '../src/renderer.js';import { applyProjection } from '../src/camera.js';import { mat4 } from 'gl-matrix';-import { resolveAgentShadow } from '../src/agent-look.js';+import { resolveAgentShadow, agentEnvironmentMap } from '../src/agent-look.js';import { createAgentAssetScene } from '../src/agent-asset.js';import { parseGltf } from '../src/gltf.js';+ import { exportGlb } from '../src/export.js';+ import { weightTracksFromGltfAnimation } from '../src/export-skeleton.js';+ import { clipFromGltfAnimation } from '../src/skeleton-pose.js';let active = null;let canvas = document.querySelector('canvas');diff --cc scripts/mcp-server.mjsindex f1129ba4,367054d1..7979b838--- a/scripts/mcp-server.mjs+++ b/scripts/mcp-server.mjs@@@ -5,7 -5,8 +5,8 @@@ 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 } from '../src/agent-scene-capabilities.js';+import { MATERIAL_PATTERN_TYPES, LIGHTING_SETUP_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);const positive = finite.positive();diff --cc src/agent-scene.jsindex df114fba,25d1500c..eb469183--- a/src/agent-scene.js+++ b/src/agent-scene.js@@@ -3,11 -3,14 +3,14 @@@ import { box, cylinder, sphere, torusimport { lathe, extrude, tube } from './modeling.js';import { createSceneGraph } from './scene-graph.js';import { applyProjection } from './camera.js';-import { normalizeAgentLook } from './agent-look.js';+import { normalizeAgentLook, environmentPatchWithSetup } from './agent-look.js';import { normalizeAgentMotion, compileAgentMotion } from './agent-motion.js';+ import { normalizeAgentPhysics, bakeAgentPhysics } from './agent-physics.js';import { meshReport, generateMeshGeometry, MESH_SMOOTH_ANGLE_DEFAULT } from './agent-mesh.js';import { normalizeMeshEdits, normalizeMeshStack } from './mesh-recipe.js';+ import { expandInstancedNodes } from './mesh-instances.js';import { AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS, MAX_MATERIAL_PATTERNS, RECIPE_ALPHA_MODES } from './agent-scene-capabilities.js';+ import { MATERIAL_LAYER_FIELDS, validateMaterialLayers } from './material-layers.js';import { materialPatternTextures, normalizeMaterialPattern } from './material-patterns.js';export { AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS };export { normalizeAgentLook, resolveAgentShadow } from './agent-look.js';diff --cc tests/agent-preview.test.jsindex 90e04617,291eea6b..47ca8b14--- a/tests/agent-preview.test.js+++ b/tests/agent-preview.test.js@@@ -3,9 -3,9 +3,9 @@@ import assert from 'node:assert/strict'import { readFile } from 'node:fs/promises';import { Script, createContext } from 'node:vm';import { mat4 } from 'gl-matrix';- import { createAgentScene, needsMeshBooleans, loadMeshBooleans, meshBooleansLoaded } from '../src/agent-scene.js';+ import { createAgentScene, needsMeshBooleans, loadMeshBooleans, meshBooleansLoaded, needsPhysics, loadPhysicsEngine, physicsEngineLoaded } from '../src/agent-scene.js';import { applyProjection } from '../src/camera.js';-import { resolveAgentShadow } from '../src/agent-look.js';+import { resolveAgentShadow, agentEnvironmentMap } from '../src/agent-look.js';import { createAgentAssetScene } from '../src/agent-asset.js';import { parseGltf } from '../src/gltf.js';import { skinnedStripAsset } from './fixtures/skinned-strip.js';@@@ -67,8 -67,9 +67,9 @@@ function previewHarness()needsMeshBooleans, loadMeshBooleans, meshBooleansLoaded,// The harness loads Manifold from node_modules directly, so the preview's served-file loader is ignored.setManifoldModuleLoader: () => {},+ needsPhysics, loadPhysicsEngine, physicsEngineLoaded, setPhysicsModuleLoader: () => {},parseGltf, Uint8Array, atob,- applyProjection, mat4, resolveAgentShadow,+ applyProjection, mat4, resolveAgentShadow, agentEnvironmentMap,Renderer67: FaultInjectedRenderer,});// Evaluate only trusted repository adapter code; inject the driver boundary for failure cases.