Brokkr/surfaces/blender/docs/rig.md
Meta Vens 804863ccc9 brokkr_rig: no thin part is a reported outcome; shape rays reach the longest side; gauges, seeds and shrink pinned in core (Soul s2 fix batch)
tendrils on a mesh with no rings reports zero chains instead of raising. The
shape-diameter ray reach was half the longest side, so a body wider than that
read thin; it is the longest side now. chain_gauges, seed_triangle and
shrink_fraction move into core with tests; the live test pins stale colliders
and the no-thin-part mesh.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-12-01 08:38:05 +01:00

10 KiB

Rigging generated creatures for spring-bone tendrils

surfaces/blender/brokkr_rig is a Blender add-on that rigs a fused generated mesh (Tripo and its kin: one skin, body and tendrils welded together) for a spring-bone runtime. It is a host add-on in Brokkr's sense (install.md, "Host add-on actions"), a sibling of brokkr_mesh_polish: it imports that package's operator base, Refused, mesh_object, arrays and arithmetic (weld, components, face adjacency, crease costs, seed growing, principal_frame, boundary_root) instead of copying them, and nothing from brokkr_bridge. Enable brokkr_mesh_polish first; brokkr_rig refuses to register without it. brokkr_actions.json beside its __init__.py lists the three operators agents may run; the arithmetic is core.py (numpy only, tested without Blender). Every action writes a JSON report to brokkr_mesh_polish_result, returned in the receipt's hostResult.

The contract it produces, and who owns it

The GLB the exporter writes has one skin over every bone, every node with translation and rotation at unit scale and no matrix, mesh primitives with exactly POSITION, NORMAL, TEXCOORD_0, JOINTS_0, WEIGHTS_0 (at most 4 influences, weights summing to 1), and VRMC_springBone 1.0: each spring a linear chain whose first joint hangs from a body bone, colliders only on body bones in one group body named by every spring. Stiffness is a rate in 1 per second, not VRM's unit.

Whether a GLB is acceptable is Aetheria's SpringRigData.FromGlbJson, not this add-on, which ships no copy of its refusals. Run the owner's code on the output with SpringRigVerify.VerifyGlb (Aetheria, batch mode):

SPRINGRIG_GLB=<path to the .glb> Unity -batchmode -projectPath <Aetheria checkout> \
  -executeMethod Aetheria.EditorTools.SpringRigVerify.VerifyGlb -logFile <log>

(no -nographics, no -quit; one Unity batch instance at a time). It logs the rig's bone, body, chain, joint and collider counts and exits 0 on PASS.

Export

There is no export action of its own: Brokkr's exportGltf (or File > Export > glTF) writes the GLB, and the add-on's glTF2ExportUserExtension hook writes VRMC_springBone into it, mapping bone names to node indices from the exporter's final node list. It acts only when an exported armature carries brokkr_rig chains, so any other export is untouched. Collider offsets and capsule tails are stored in Blender world space on the body bones and composed into each collider node's local glTF frame at export from the exported nodes' translation, rotation and scale; the gravity direction goes into glTF world. Both follow export_yup.

Actions

body

brokkr_rig.body (object_name, armature_name, spine_bones 2-32, head +y/-y, seeds, crease_cost, smooth_rounds). Bakes the object's transform into its mesh and parents it to the armature at identity, so no node carries a scale.

With no armature_name it makes <object>.rig: a spine of equal bones along the principal axis, the root at the head end (head names which end of world Y; the swim wave runs head to tail), and one bone per seed name. seeds reads as in cut_parts (name=x,y,z; ..., several points may name one part). The spine is an implicit part named spine seeded at the surface nearest each spine joint and the tail point, among triangles whose three vertices have a shape diameter of at least 0.04 of the longest side (a tendril or a sheet never takes a spine seed); a seed named spine adds to it. Each named part is grown from its seeds along concave creases (grow_parts); its bone runs from the root of the part's cut (boundary_root) to its centroid and hangs from the nearest spine bone.

With an existing armature_name the armature is kept as it is: its spine is the first root's heaviest-child chain (as the runtime derives it), every other body bone is seeded at the surface nearest its tail (seeds may add points for a bone by name). The spine's bones must run from the head end to the tail end along the long axis. Chain bones an earlier tendrils left on that armature are removed (the report says how many: chainBonesCleared), because they hang on the old weights; run tendrils again.

Weights: spine bones by axial projection, linear between neighbouring joints; a part's region 1 on its bone; then smooth_rounds Laplacian rounds over the welded vertex graph, the top 4 kept and normalised. They are also kept on the mesh (point attributes rig_src_* and the object property rig_src_bones), because tendrils rewrites the vertex groups.

tendrils

brokkr_rig.tendrils (object_name, armature_name, tau, band, dilate as shares of the longest side, fold_bands, min_joints, blend, stiffness, stiffness_tip_ratio, drag, gravity_power, hit_scale). Needs body first, and starts from the body's weights kept on the mesh, so a run depends only on the mesh and its knobs, never on earlier runs. The mesh is welded; each vertex gets a shape diameter (median of five inward rays, fixed seed; an open sheet with no back face reads 0). The body is the largest component thicker than tau, dilated by dilate. Edge distance from the body is cut into bands of band; each band splits into connected rings, one joint per ring at its centroid, its parent the ring it touches one band nearer.

  • A tree (everything hanging from one root ring) whose farthest vertex lies within fold_bands bands of the body is a surface vein and folds into the body; so does a tree whose main path has fewer than min_joints rings.
  • Each remaining tree's root-to-deepest-leaf path is one spring, ending in a tip joint at the leaf ring's farthest vertex (the runtime gives a chain's last joint its parent's aimed rotation). Side branches cannot be springs of their own (a spring's first joint must hang from a body bone), so their vertices weight rigidly to the main-path bone at their fork.
  • Vertices the distance never reaches (detached shells) weight rigidly, per shell, to the nearest spring bone.
  • Weights: a vertex between joints k and k+1 goes to bone k, blending linearly from bone k-1 over blend bands from joint k, and with the body weights of its nearest body vertex within blend bands of the body.
  • Bones tendril_<chain>_<k>; joint 0 hangs from the body bone with most weight at its ring's body boundary. Bone ID properties: rig_chain, rig_index, rig_stiffness (tapered from the root to the tip by stiffness_tip_ratio), rig_drag, rig_gravity, rig_hit_radius (half the ring's median shape diameter times hit_scale). Running it again replaces every earlier chain.

The report counts chains, spring bones, rigid branches, veins folded, shells attached and unreached vertices, and gauges the rig: chainVertexShare, largestChainShare (the biggest chain's share of the mesh) and fusedContacts (mesh edges joining two different chains). warnings says when one chain holds 4.2% of the mesh or more, which is what a hull plate that became a chain looks like (the lace leviathan reads 2.3%, the skeletal and mantle hulls 7.7% and 11.2%; the bound is the geometric mean of the first two). An open sheet reads shape diameter 0, so on a hull the builder succeeds; read the warning. The gauge is fitted to four meshes and catches a hull whose plates merge into a few big chains. It does not catch one that fragments into many small plate chains: the submarine reads 2.7% largest (9 chains, 11% of the mesh on chains) and gets no warning, and no second signal tried (open-sheet share, ring width in shape diameters, share of the mesh on chains) separated it from the leviathan. Look at the chains in a render before trusting a hull's rig.

A mesh with no thin part (the crystal emblem) has no rings: tendrils is accepted, reports chains 0, removes any chains from an earlier run, and leaves the skin as body made it.

colliders

brokkr_rig.colliders (object_name, armature_name, scale). A capsule per spine bone from head to tail, radius the median radial distance of the body vertices projecting onto it times scale; a sphere per other body bone at the centroid of its heaviest vertices, radius the median distance times scale. Each radius is then shrunk until every spring joint past the first stands at least its hit radius outside it at rest. The report lists each shrink (shrinks: bone, before, after) and the largest fraction (shrunkMax): where tendrils lie on the body at rest the rule fits colliders to the gaps between them (the leviathan's spine_07 shrinks by 91%). Stored as the bone's rig_colliders property list.

What it cannot do

It does not judge a rig: acceptance is the runtime's parse. It does not simulate the springs (the report's chain, joint and collider counts are what was built, not how it moves). It reads thickness from rays against the mesh, so a mesh whose windings face inward needs repair and recalc_normals first. A vein the dilation reaches is absorbed before the fold rule sees it. Seeds on a smooth surface split by distance alone. A fused generated mesh joins tendrils that touch: the edges between two chains stretch when the chains move apart (the leviathan has 132 such edges; fusedContacts counts them).

A recipe

{"requestedBy": "nibu/hands", "importDir": "work", "outputDir": "work",
 "hostAddons": ["brokkr_mesh_polish", "brokkr_rig"], "saveBlend": "work/whale.blend",
 "intents": [
  {"action": "importGltf", "filepath": "whale.glb"},
  {"action": "brokkr_mesh_polish.audit"},
  {"action": "brokkr_mesh_polish.repair", "object_name": "whale_mesh"},
  {"action": "brokkr_mesh_polish.orient", "object_name": "whale_root", "length": 1.0},
  {"action": "brokkr_rig.body", "object_name": "whale_mesh", "spine_bones": 8, "head": "+y", "seeds": "jaw=0.2,0.4,0"},
  {"action": "brokkr_rig.tendrils", "object_name": "whale_mesh", "tau": 0.04, "band": 0.04, "dilate": 0.04},
  {"action": "brokkr_rig.colliders", "object_name": "whale_mesh"},
  {"action": "exportGltf", "filepath": "whale_rigged.glb"}]}

Pick seed points from a flat turntable with brokkr_mesh_polish.pick, and pick head by eye from a render. Run the recipe with tools/run_intents.py under private BLENDER_USER_* directories (mesh-polish.md), then VerifyGlb on whale_rigged.glb.

The live proof is tests/live/rig.py (a synthetic whale through the same intents; rig.result.json is its last run).