3D engine that AI agents drive
Merge remote-tracking branch 'origin/main' into merged/feat-ragdoll
Nguyen Xuan Anad74aa9bba53
diff --cc CHANGELOG.mdindex c1dfbf68,dd55b57a..e11aca4e--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -2,7 -2,8 +2,9 @@@## Unreleased+- Add ragdolls (part of issue #96): `physics.ragdoll` in a recipe with armatures and `physics` in an asset recipe (`set-physics`) bind a capsule body to every bone or joint and play the fall back as the pose of those bones, the same bytes for the same seek. New `src/ragdoll.js`, loaded with the physics code only. New suite task `robot-ragdoll`. The lazy budgets of `agent-scene+lazy` and `agent-asset+lazy` rise by 100 and 800 bytes gzip for it; the core entries did not grow from this. Joints have no swing limits yet.+ - Add terrain holes and a recipe `terrain` geometry (part of issue #64; layers beyond four and the navmesh are not built). `createTerrain({ holes: [{ center: [x, z], radius }] })` leaves no surface where a cell centre is inside a circle, and `terrain.isHole(x, z)` answers for a point; without `holes` the seeded meshes are byte-identical (a digest test). A recipe geometry `{ type: "terrain", size, resolution, seed, amplitude, holes }` builds one seeded ground mesh with the same holes; it loads on demand through the new `terrain` module (core did not grow), the tool schema entry is one line with the fields in `scene_capabilities` `terrain`, and the schema total budget did not change (scene_create and scene_apply rose by a few hundred bytes, mesh_edit fell by the same amount). New suite task `terrain-hole-walk` (ground with a 3 m opening and a walker that has to go around it) with the checks `groundRelief` and `walkPath`. Measured: Haiku passed it 2 of 2 (9 and 6 tool calls, $0.29 in all) and both exported recipes used the `terrain` geometry; there was no control run without the feature, so this shows agents find it, not how many could do without.+ - Bake patterned, textured and emissive parts, and skip hair hosts (part of issue #128). A recipe `bake` used to skip every part with a pattern, a map or emission (31 parts, the floor and every wall, in the demo room) and failed `scene_create` with "Textured geometry requires UV channel 0" on a node that hosts hair. Those parts now keep `uvs` and their look and take the bounced light through a new `lightMap` material slot on a second UV set (`geometry.lightUvs`); the fragment shader adds `color * (1 - metallic) * lightMap * lightMapScale`, so a brick pattern tints its own bounced light. Hair and particle host nodes are skipped and listed in `report.skipped`. The shader branch compiles out of scenes with no light map; the renderer carries about 650 bytes of gzip for it in `entry:core` (see `docs/light-bake.md` for the measured sizes). GLB export writes `TEXCOORD_1` and the light map as the emissive texture (an approximation: glTF has no light map slot). The path tracer ignores baked maps by design. New reference scene `brick-room` (a recipe-built closed brick room).- Make the path tracer about 2.8 times faster per thread and draw normal and metallic-roughness maps (part of issue #129; a 1080p still of the 181,708 triangle demo room at 64 samples still does not fit the 240 s job limit). Profiling the demo room showed the ray query dominating: 54 percent of the time sat in the generic BVH visitor, which called a closure per box and per triangle and kept distances in a boxed array. `createTracer` in `src/ray-query.js` now walks the BVH with typed stacks, a slab test on inverse directions and triangles packed in leaf order; pixels are bit-identical to before (checksum of a band unchanged) and it runs 1.2 times faster alone. The larger gain is shadow rays: the demo room has 11 light sources, and every bounce traced all of them. The first hit of a path still samples every light; later hits draw one at random and divide by its chance (and the environment multiple importance weights use that chance), which gives 23,300 paths a second per thread against 9,800, with the average moved by less than 1 percent in the demo room and 3 percent allowed by a test. Image jobs now use 8 workers, up from 4 (the machine limit). `normalMap` (with `normalScale`, tangent frame from the UVs as in the rasterizer) and `metallicRoughnessMap` (green scales roughness, blue scales metallic) are drawn on UV-mapped materials; on box-projected materials (`boxMapScale`) they are still ignored and `report.ignored` says so. The `entry:path-tracer` size budget goes from 12,900 to 13,800 bytes gzip for the maps, light selection and the packed ray query; `entry:core` did not change. Tests: maps tilt and mask the light, one light drawn at random keeps the average, and bands drawn in any order give the pixels of the whole image.diff --cc bench/size/baseline.jsonindex f8a6b805,fe433e1f..5ef009df--- a/bench/size/baseline.json+++ b/bench/size/baseline.json@@@ -144,24 -144,24 +144,24 @@@"brotli": 762},"entry:agent-scene": {- "min": 208967,- "gzip": 63945,- "brotli": 55786- "min": 209968,- "gzip": 64321,- "brotli": 56194++ "min": 210130,++ "gzip": 65170,++ "brotli": 57066},"entry:agent-scene+lazy": {- "min": 623239,- "gzip": 213035,- "brotli": 188048- "min": 635119,- "gzip": 218126,- "brotli": 192679++ "min": 644038,++ "gzip": 221802,++ "brotli": 196072},"entry:agent-asset": {- "min": 303069,- "gzip": 94728,- "brotli": 82813- "min": 303994,- "gzip": 95078,- "brotli": 83130++ "min": 305436,++ "gzip": 96859,++ "brotli": 85071},"entry:agent-asset+lazy": {- "min": 659080,- "gzip": 223845,- "brotli": 196982- "min": 670884,- "gzip": 228911,- "brotli": 201552++ "min": 681111,++ "gzip": 233531,++ "brotli": 205993},"entry:hdri": {"min": 8075,@@@ -179,34 -179,34 +179,34 @@@"brotli": 1425},"entry:material-layer-shaders": {- "min": 71379,- "gzip": 18505,- "brotli": 16205+ "min": 71833,+ "gzip": 18658,+ "brotli": 16359},"scene:lit-box": {- "min": 215844,- "gzip": 59286,- "brotli": 50588+ "min": 217804,+ "gzip": 59861,+ "brotli": 51117},"scene:gltf-box": {- "min": 275471,- "gzip": 79332,- "brotli": 68903+ "min": 277431,+ "gzip": 79898,+ "brotli": 69584},"scene:gltf-box+lazy": {- "min": 281904,- "gzip": 81319,- "brotli": 70712+ "min": 283864,+ "gzip": 81888,+ "brotli": 71399},"scene:agent-scene": {- "min": 318701,- "gzip": 94262,- "brotli": 81921- "min": 321129,- "gzip": 95055,- "brotli": 82718++ "min": 321299,++ "gzip": 95954,++ "brotli": 83554},"scene:agent-scene+lazy": {- "min": 732973,- "gzip": 243364,- "brotli": 214130- "min": 746280,- "gzip": 248859,- "brotli": 219206++ "min": 755207,++ "gzip": 252588,++ "brotli": 222505}}}diff --cc bench/size/budgets.jsonindex 4ca133f0,505ff138..78bfcc58--- a/bench/size/budgets.json+++ b/bench/size/budgets.json@@@ -26,24 -26,24 +26,24 @@@"entry:skeleton-pose": 19200,"entry:vehicle": 14700,"entry:vegetation": 17900,- "entry:terrain": 3100,+ "entry:terrain": 3400,"entry:grass": 4400,"entry:clutter": 5300,- "entry:light-bake": 25400,+ "entry:light-bake": 25900,"entry:path-tracer": 13800,"entry:texture-set": 900,- "entry:agent-scene": 65300,- "entry:agent-scene+lazy": 217400,- "entry:agent-asset": 96700,- "entry:agent-asset+lazy": 229200,- "entry:agent-scene": 65700,- "entry:agent-scene+lazy": 222500,- "entry:agent-asset": 97000,- "entry:agent-asset+lazy": 233500,++ "entry:agent-scene": 66500,++ "entry:agent-scene+lazy": 226300,++ "entry:agent-asset": 98800,++ "entry:agent-asset+lazy": 238300,"entry:hdri": 3300,"entry:camera-effects": 8600,"entry:render-passes": 1700,- "entry:material-layer-shaders": 18900,- "scene:lit-box": 60500,- "scene:gltf-box": 81000,- "scene:gltf-box+lazy": 83000,- "scene:agent-scene": 96200,- "scene:agent-scene+lazy": 248300+ "entry:material-layer-shaders": 19100,+ "scene:lit-box": 61100,+ "scene:gltf-box": 81500,+ "scene:gltf-box+lazy": 83600,- "scene:agent-scene": 97000,- "scene:agent-scene+lazy": 253900++ "scene:agent-scene": 97900,++ "scene:agent-scene+lazy": 257700}}diff --cc bench/tool-cost-budgets.jsonindex 361284cd,376ca431..171d4a76--- a/bench/tool-cost-budgets.json+++ b/bench/tool-cost-budgets.json@@@ -10,7 -10,7 +10,7 @@@},"schemaOtherToolBytes": 4000,"resultBytes": {- "scene_capabilities": 12230,- "scene_capabilities": 12430,++ "scene_capabilities": 12460,"scene_create": 1400,"scene_inspect": 1400,"mesh_inspect": 1200,diff --cc skills/build-67js-scene/SKILL.mdindex de63a72a,d1e3bd88..118bf550--- a/skills/build-67js-scene/SKILL.md+++ b/skills/build-67js-scene/SKILL.md@@@ -47,10 -48,10 +48,10 @@@ Use `simplify-code` and `engineering-wo- Agent tool calls use the installed `67js-mcp` stdio server from release `0.5.0` onward. Read `docs/mcp.md` for launch and PNG feedback.- Agent render jobs use `docs/agent-render-jobs.md`. Check source versus published support, configure a private store and poll until terminal.- A character or creature that must move (a walker, a quadruped) gets a recipe `armatures` entry and a `skin` on each mesh node: `{ "id": "rig", "preset": "humanoid", "fit": { "bounds": { "min": [...], "max": [...] } } }` (or `fit.node`), then `skin: { "armature": "rig" }` on every body part. Bones are nodes named `hips`, `leftUpperLeg`, `leftLowerLeg` and so on, so rotation tracks and `motion.ik` address them directly (rotation is local, about the bone head; positive X swings a hanging limb backward). Build the mesh at rest in the preset's pose (facing +Z, arms down), and read `rig` in `scene_inspect`: unweighted vertices, bones with no vertices, joint axis problems. Weights are by distance to the bone segments, so give limbs the same loops you want to bend. See "Authored rigs" in `docs/agent-motion.md`.-- Things that fall, pile up or rest on an authored mesh (dropped objects, a ball in a bowl, a trigger zone) use the recipe `physics` section: bodies on root node IDs, `shape: 'trimesh'` on a fixed body so objects follow the mesh, `sensor: true` for triggers, `layer` and `collidesWith` for masks. Seek with `motionTime` like motion, and read `physics` from `scene_inspect` (resting times, contacts, sensor events) instead of guessing from a picture. Needs the optional peer `@dimforge/rapier3d-compat`; bodies bound to bones for ragdolls are not supported. See "Recipe physics" in the checkout's `docs/physics.md`.+- Things that fall, pile up or rest on an authored mesh (dropped objects, a ball in a bowl, a trigger zone) use the recipe `physics` section: bodies on root node IDs, `shape: 'trimesh'` on a fixed body so objects follow the mesh, `sensor: true` for triggers, `layer` and `collidesWith` for masks. Seek with `motionTime` like motion, and read `physics` from `scene_inspect` (resting times, contacts, sensor events) instead of guessing from a picture. Needs the optional peer `@dimforge/rapier3d-compat`; a limp character uses `physics.ragdoll` (`{ armature }` for a recipe armature; an imported asset takes `physics: { duration, floor, ragdoll: {} }` and falls from its current pose onto a floor at world height `floor`), needs a floor body in a scene recipe, and reports `physics.ragdoll` (`lowestY`, `highestY`, `restsAtTime`); joints have no swing limits. See "Recipe physics" in the checkout's `docs/physics.md`.- Flags, curtains, capes and cloths draped over props use the recipe `cloth` section: a `grid` geometry node (flat sheet in XY, `segments` up to 64) listed in `sheets` with `pin` edges (`top`, `left`, a corner...), `wind` in m/s, and fixed `colliders` (`ball` or `box` fitted to their node). Seek with `motionTime`; a flag needs wind along its length (+x for a left pin), not across it. No peer needed, no self collision, no soft bodies. Units, defaults and limits are in `scene_capabilities` under `cloth`; see "Recipe cloth" in `docs/physics.md`.- Sparks, dust, embers, confetti and fur use the recipe `particles` section: a root node whose small low-poly geometry (a box) is the particle, in an emitter system with `seed`, `count` (at most 2000), `rate` (omit for one burst), `lifetime`, `speed`, `spread`, `drag`, `floor` and an `emitter` shape; a system with `type: "hair"` grows strands from a `surface` node. Seek with `motionTime`; the same seed and time give the same particles. The node transform does not move particles, and there is no collision beyond the floor, bounce or per-particle colour. Fields and limits are in `scene_capabilities` under `particles`; see "Recipe particles and hair" in `docs/physics.md`. Smoke, fire and browser liquid are not supported.- - A closed room, or any scene lit by point lights, is dark where the light does not reach. Add the recipe `bake` section (`{ "preset": "standard" }`, or `draft` to try fast, `fine` to finish) or the `set-bake` operation: it writes bounced light into lightmaps when the scene builds and reruns only when parts, lights, materials or the bake change. `scene_inspect` shows `bake.seconds` and `bake.skipped` (parts with maps, patterns, emission, alpha, skins or morphs are left as they were). It bakes the rest pose and no spot or area lights. Read `docs/light-bake.md`.+ - A closed room, or any scene lit by point lights, is dark where the light does not reach. Add the recipe `bake` section (`{ "preset": "standard" }`, or `draft` to try fast, `fine` to finish) or the `set-bake` operation: it writes bounced light into lightmaps when the scene builds and reruns only when parts, lights, materials or the bake change. `scene_inspect` shows `bake.seconds` and `bake.skipped` (alpha, skins, morphs, procedural tags and hair or particle hosts are left as they were; patterned, textured and emissive parts are baked and keep their pattern). It bakes the rest pose and no spot or area lights. Read `docs/light-bake.md`.- Agent procedural animation uses `docs/agent-motion.md` from release `0.7.0`. Author recipe tracks, then seek through `sampleMotion` or MCP `motionTime`.- Agent imported character motion uses `docs/agent-character-motion.md` from release `0.8.0`. Inspect source joints before authoring local tracks.- To pick between variants, fork each with `scene_apply` and a `branch` name (the scene and revision stay put), compare them in one `scene_review` with a `branch` per shot, then keep the winner with `scene_restore` and its `branch`. Add `labels: true` to `scene_look` or `scene_review` to match node names and lint problems to what the image shows. Docs: `docs/agent-review.md`.