Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Merge remote-tracking branch 'origin/main' into HEAD

Nguyen Xuan Anebba7d4f02e1
diff --cc CHANGELOG.md
index e1c81fe8,fbfdc253..47225bb6
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -2,7 -2,7 +2,8 @@@
## Unreleased
+- Add authored rigs (#46): a recipe `armatures` list (bones with a name, parent, head and tail, or a `humanoid` or `quadruped` preset fitted to a mesh node's bounds, with `landmarks` to move bones), and a `skin` on a mesh node that binds it with automatic weights, plus a `set-armatures` operation. Each bone becomes a recipe node, so keyframed bone rotation and `motion.ik` run through the same paths as imported rigs, and humanoid bones carry the `HUMANOID_BONES` names so `retargetClip` maps them. Weights are the distance to each bone segment with an inverse-fourth-power falloff, the nearest four kept; they depend only on position, so hard-edge seams never open. `scene_inspect` gains `rig`: unweighted vertices, bones with no vertices, and joint axis problems (zero-length bones, straight limb chains, knees that bend backward). `scene_export_glb` writes the bones and a walk clip baked at 30 frames a second from tracks and IK. Add the `rigged-walker` task to the agent modeling suite, with a reference and three failing variants. Blender 5.2 opens the exported walker as 1 armature, 21 bones, 14 meshes with 21 vertex groups each and 1 action of 24 frames; three.js loads 14 skinned meshes and the clip.
+ - Add joint limits, node constraints and drivers to motion (issue #58). Two-bone IK takes `limits` per joint and axis in degrees and `bendToward`; `scene_inspect` `motionIk` now carries `limited` (each pose a limit changed) and `warnings` (`hyperextended`, and `wrong-bend` for a knee or elbow bent the unnatural way, which a wrong pole used to hide behind `reached`). `motion.constraints` adds `copy_location`, `copy_rotation`, `copy_scale`, `limit_location`, `limit_rotation`, `track_to`, `child_of` (with an inverse and an influence blend) and `floor`, and `motion.drivers` sets a node component or material property from a bounded JSON expression over time and other nodes (never run as code). The order is tracks, IK, drivers, constraints, with no state between samples, so a seek equals playing. `copy_rotation`, `limit_rotation`, `track_to`, `child_of` and `floor` match Blender 5.2 world matrices in 8 recorded cases (`tests/fixtures/blender/constraints.json`). Joint limits are also in `67js/addons/skeleton-pose`. The `leg-plant` task joins the agent modeling suite. The expression language is a new small one in `src/motion-expression.js`: the field expressions of the mesh addon were not on `main` yet
- 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.
diff --cc bench/size/baseline.json
index f74c23e2,2e850a56..27980fbf
--- a/bench/size/baseline.json
+++ b/bench/size/baseline.json
@@@ -129,14 -129,14 +129,14 @@@
"brotli": 762
},
"entry:agent-scene": {
- "min": 399226,
- "gzip": 126629,
- "brotli": 107783
- "min": 419435,
- "gzip": 133124,
- "brotli": 113067
++ "min": 436033,
++ "gzip": 138526,
++ "brotli": 117531
},
"entry:agent-asset": {
- "min": 425353,
- "gzip": 133851,
- "brotli": 113836
- "min": 445545,
- "gzip": 140377,
- "brotli": 119117
++ "min": 462140,
++ "gzip": 145796,
++ "brotli": 123807
},
"entry:hdri": {
"min": 8075,
@@@ -154,9 -154,9 +154,9 @@@
"brotli": 63362
},
"scene:agent-scene": {
- "min": 498424,
- "gzip": 152612,
- "brotli": 129631
- "min": 518633,
- "gzip": 159129,
- "brotli": 135030
++ "min": 535231,
++ "gzip": 164487,
++ "brotli": 139515
}
}
}
diff --cc bench/size/budgets.json
index 55612b49,94138060..ce6b18b2
--- a/bench/size/budgets.json
+++ b/bench/size/budgets.json
@@@ -28,11 -28,11 +28,11 @@@
"entry:grass": 4400,
"entry:clutter": 5300,
"entry:texture-set": 900,
- "entry:agent-scene": 132000,
- "entry:agent-asset": 139300,
- "entry:agent-scene": 135800,
- "entry:agent-asset": 143200,
++ "entry:agent-scene": 141300,
++ "entry:agent-asset": 148800,
"entry:hdri": 3300,
"scene:lit-box": 56000,
"scene:gltf-box": 75300,
- "scene:agent-scene": 158000
- "scene:agent-scene": 162400
++ "scene:agent-scene": 167800
}
}
diff --cc docs/agent-motion.md
index fd01efe0,1adc4ec2..c86571ed
--- a/docs/agent-motion.md
+++ b/docs/agent-motion.md
@@@ -115,38 -115,77 +115,107 @@@ On an imported asset, joints are its `n
Each sample stages the clip and overrides, reads the local pose, solves, and stages again, so the rest of the body stays on
the selected clip and skins and rigid parts all follow. Targets are in world space, under the asset's `root`, which needs a
uniform scale. Some rigs have no chain to the foot: if the foot is not a descendant of the lower leg, two-bone IK refuses it.
- There are no joint angle limits. [Skeleton pose layers](skeleton-pose.md) add clip layers and masks in code.
+ [Skeleton pose layers](skeleton-pose.md) add clip layers and masks in code.
+
+ ### Joint limits and sanity warnings
+
+ A two-bone solver takes `limits: { "root": { "x": [min, max], "y": [...], "z": [...] }, "middle": {...} }` in degrees. Each
+ range bounds how far that joint turns away from its rest rotation, per axis of the joint's own frame, as Euler XYZ (the
+ order Blender uses). A limited joint is clamped after the solve and the end rotation is restored, so a clamped knee leaves
+ the foot short of its target and `reached` turns false. `motionIk[n].limited` lists each joint and axis a limit changed:
+ `{ joint, axis, requested, applied, atTime }`, degrees, first time it happens.
+
+ `motionIk[n].warnings` lists `{ code, message, atTime }` once per code:
+
+ | Code | When |
+ | --- | --- |
+ | `hyperextended` | The middle joint is within 5 degrees of straight: the target is at or past the limb's reach |
+ | `wrong-bend` | The middle joint bends opposite to its natural side, which a pole on the wrong side produces while the foot still arrives |
+
+ The natural side is `bendToward` (a world direction, such as `[0, 0, 1]` for a knee on a character that faces +z) or, when
+ that is absent, the way the limb is bent in its rest pose. A limb that rests perfectly straight and has no `bendToward` is
+ never checked for the wrong bend, so give legs and arms one.
+
+ ## Constraints
+
+ `motion.constraints` is a list of Blender-style node constraints, at most 32. Each names the constrained `node` (a recipe
+ node, or an editable asset node), a `type`, a `target` node where the type needs one, and an `influence`: 0 to 1 (default 1)
+ or an expression. Influence blends the node's matrix before and after the constraint, location, rotation and scale
+ separately, as Blender does. Euler angles are XYZ in degrees. `space` is `world` (default) or `local`, local being the node's
+ own transform under its parent.
+
+ | Type | Fields | Meaning |
+ | --- | --- | --- |
+ | `copy_location` | `target`, `axes`, `invert`, `offset`, `space` | The chosen axes take the target's location; `offset` adds it to the node's own |
+ | `copy_rotation` | `target`, `axes`, `invert`, `mix` (`replace` or `add`), `space` | The chosen Euler axes take the target's |
+ | `copy_scale` | `target`, `axes`, `offset`, `space` | The chosen axes take the target's scale; `offset` multiplies |
+ | `limit_location` | `x`, `y`, `z` as `[min, max]`, `space` | Clamp the location per axis |
+ | `limit_rotation` | `x`, `y`, `z` as `[min, max]` degrees, `space` | Clamp the Euler angles per axis |
+ | `track_to` | `target`, `trackAxis` (default `-z`), `upAxis` (default `y`), `worldUp` (default `[0, 1, 0]`) | Turn the node so its track axis points at the target and its up axis leans toward `worldUp`. Blender's up is Z, so its numbers match with `worldUp: [0, 0, 1]` |
+ | `child_of` | `target`, `inverse` (`rest` or `none`) | The node follows the target: its world matrix becomes target * inverse * its own. `rest` uses the inverse of the target's rest matrix, so the node stays put until the target moves; Blender's default is `none` |
+ | `floor` | `target`, `axis` (default `+y`), `offset` | Keep the node on the positive side of the plane through the target, along `axis`, plus `offset` |
+
+ Not covered yet: `use_*` switches on `child_of`, `limit_scale`, `copy_transforms`, `damped_track`, `locked_track`,
+ `stretch_to`, bone sub-targets and `head_tail`.
+
+ ## Drivers
+
+ `motion.drivers` sets one node component or material property from a bounded expression, at most 32. A target is
+ `{ "kind": "node", "id", "property": "translation" | "rotation" | "scale", "component": "x" | "y" | "z" }` (rotation is Euler
+ XYZ in degrees) or `{ "kind": "material", "id", "property" }` for `emission`, `metallic` and `roughness`, or with a
+ `component` for `color` and `emissiveColor` (`x`, `y`, `z` for red, green, blue). A driven property cannot also have a track.
+
+ An expression is JSON data and is never run as code: a number, the string `"time"`, a read of another node
+ `{ "node", "property", "component", "space" }`, or one operator object such as `{ "mul": ["time", 2] }`. Operators: `add`,
+ `mul`, `min`, `max` (2 to 8 operands), `sub`, `div`, `pow`, `mod`, `atan2`, `gt`, `lt`, `neg`, `abs`, `sin`, `cos` (radians),
+ `sqrt`, `floor`, `fract`, `saturate`, `clamp(x, low, high)`, `mix(a, b, t)`, `smoothstep(low, high, x)` and
+ `if(condition, then, otherwise)`. An expression has at most 64 parts and 8 levels, and a result that is not finite is an
+ error. The operator names follow the field expressions of the mesh addon where they overlap.
+
+ ### Evaluation order
+
+ For any time, the pose is built in this order and keeps no state between samples, so seeking gives the same pose as playing
+ to that time:
+
+ 1. Tracks, and for an asset the selected clip.
+ 2. IK, in list order.
+ 3. Drivers. They read the pose from steps 1 and 2, so one driver never sees another's result.
+ 4. Constraints, in list order. Each reads the pose the ones before it left. Expressions in `influence` read the pose from
+ step 2.
+
+ IK targets that follow a node see that node before drivers and constraints move it. Material drivers on an imported asset
+ read node values from the tracks and rest pose, not the clip.
+## Authored rigs
+
+A recipe `armatures` list holds skeletons. Each bone has a `name`, a `parent` (a bone name or `null`), a rest `head` in the
+armature's own space and an optional `tail`; without one the tail is the mean of the children's heads. Instead of
+`bones`, give `preset: "humanoid"` or `"quadruped"` and `fit: { node }` (a mesh node whose bounds size the rig) or
+`fit: { bounds: { min, max } }`. `fit.landmarks` moves a bone head by name, or its tail as `<name>Tail`. Presets are
+resolved to explicit bones when the recipe is read, so a stored recipe does not change when the mesh does. A humanoid
+faces +Z with Y up and uses the `HUMANOID_BONES` names, so `retargetClip` maps it without overrides. Its knees sit a little
+forward of the leg line and its elbows a little behind, so a two-bone solve without a pole folds them the right way.
+A quadruped lies along Z and names its legs `leftFrontUpperLeg`, `rightHindFoot` and so on.
+
+Every bone becomes a recipe node (ID is `prefix` plus the name; the armature root is a node with the armature's ID), parented
+like the bones and carrying the `armature` field. Those nodes are regenerated from `armatures` each time the recipe is read, so edit
+bones with `set-armatures`, not `set-node`. Node rotation tracks and `motion.ik` address bones like any node; rotation is local
+to the bone head, and at rest it is the identity. Positive X rotation swings a hanging limb backward, so a thigh swings from
+negative to positive and a shin folds with positive values.
+
+A mesh node binds with `skin: { armature, maxInfluences, maxDistance }`. Weights are the distance from each vertex to each bone
+segment, `((nearest + softness) / (distance + softness))^4`, with the nearest four kept and normalised. Bone heat diffusion
+or a geodesic falloff would be smoother where two limbs pass close, but needs a sparse solve per bone; this method depends only on
+position, so vertices split at a hard edge get identical weights and seams never open. A vertex farther than `maxDistance`
+(default a quarter of the rig's size) from every bone still binds to its nearest bones and is reported as unweighted.
+`scene_inspect` returns `rig` per armature with `skinned` (vertices and `unweightedVertices` per node), `bonesWithNoVertices`
+and `jointAxisProblems` (`zero-length`, `straight-chain`, `knee-bends-backward`, `elbow-bends-forward`).
+
+`scene_export_glb` writes the bones at rest, the skins and a clip named `motion` baked at 30 frames a second from tracks and
+IK (bone nodes only). In code, `scene.rigExport()` returns the `nodes` and `clips` options for `exportGlb`. Skinned parts render and export their
+bone-driven shape; the node transform of a skinned mesh does not move it, move the armature instead. The `rigged-walker`
+task in `bench/agent-modeling` builds and walks a character this way.
+
## Internal sampling helpers
`normalizeAgentMotion(input, recipe)` returns canonical plain JSON, or `null` for absent motion.
diff --cc skills/build-67js-scene/SKILL.md
index 56b3cdda,7c9f611c..22bdd8c4
--- a/skills/build-67js-scene/SKILL.md
+++ b/skills/build-67js-scene/SKILL.md
@@@ -40,10 -40,9 +40,10 @@@ Use `simplify-code` and `engineering-wo
- A surface look in a recipe (wood, planks, bricks, tiles, marble, stone, concrete, metal, rust, fabric) uses the material `pattern` field, which needs no UVs. See "Material patterns" in the checkout's `docs/agent-scene.md`.
- Glass, water, gems, car paint and cloth in a recipe use the material layer fields `transmission` (with `thickness` and `ior`), `clearcoat`, `sheenColor` and `specular`. A transmissive material needs a nonzero `thickness` to bend the view behind it, and does not show blended surfaces. Ranges and limits are in "Material layers" in the checkout's `docs/material-maps.md`.
- Layered skeletal animation in code (a clip on some joints only, additive clips, foot planting, reaching, looking at a point) uses `createAssetPose` from `src/skeleton-pose.js` and the checkout's `docs/skeleton-pose.md`. Clip layers are not available through MCP.
- - Jointed motion (an arm reaching, a lamp or head tracking a point) on a recipe or an imported character uses `motion.ik`, which needs no quaternions: on a recipe parent the joint nodes and put sizes on child mesh nodes, on an asset find `node-N` IDs with `scene_inspect` kind hierarchy and aim with `worldForward`. Read `motionIk` from `scene_inspect`. See "Inverse kinematics" in the checkout's `docs/agent-motion.md`.
+ - Jointed motion (an arm reaching, a lamp or head tracking a point) on a recipe or an imported character uses `motion.ik`, which needs no quaternions: on a recipe parent the joint nodes and put sizes on child mesh nodes, on an asset find `node-N` IDs with `scene_inspect` kind hierarchy and aim with `worldForward`. Read `motionIk` from `scene_inspect`: besides `reached`, it lists `warnings` (`wrong-bend` when a knee or elbow bends the unnatural way, `hyperextended`) and `limited` (poses a joint limit changed). Give a leg or arm `bendToward` (a world direction, such as `[0, 0, 1]` for a knee on a character facing +z) and `limits` per joint in degrees, and fix any warning before you finish. `motion.constraints` (copy, limit, `track_to`, `child_of`, `floor`, Blender's meanings, Euler XYZ degrees) and `motion.drivers` (a node or material property from a bounded JSON expression) run after IK and give the same pose at any time. See "Inverse kinematics", "Constraints" and "Drivers" in the checkout's `docs/agent-motion.md`.
- 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`.
- 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.
diff --cc src/agent-scene-capabilities.js
index 032d7176,754d5244..db87923f
--- a/src/agent-scene-capabilities.js
+++ b/src/agent-scene-capabilities.js
@@@ -45,8 -45,8 +45,10 @@@ export const AGENT_SCENE_CAPABILITIES
lightLinking: false,
proceduralMotion: true,
motionIk: Object.freeze(['two-bone', 'aim']),
+ // Authored rigs: armatures expand into bone nodes, and a node `skin` binds a mesh with automatic weights (four influences).
+ rigging: Object.freeze({ presets: Object.freeze(['humanoid', 'quadruped']), maxArmatures: 16, maxBones: 128, maxInfluences: 4, weights: 'bone-distance' }),
+ motionConstraints: Object.freeze(['copy_location', 'copy_rotation', 'copy_scale', 'limit_location', 'limit_rotation', 'track_to', 'child_of', 'floor']),
+ motionDrivers: Object.freeze({ maxDrivers: 32, maxConstraints: 32, maxExpressionParts: 64, maxExpressionDepth: 8 }),
// Recipe physics: Rapier (an optional peer) bakes bodies on nodes offline; playback is a seek into the bake.
physics: Object.freeze({
bodyTypes: Object.freeze(['dynamic', 'fixed', 'kinematic']),