rig-parts 1.71.1 → 1.72.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # rig-parts
1
+ # @rig-c/parts — CLI `rig-parts`
2
2
 
3
3
  **AI-authored 2D character rigs from one anime painting, verified before they
4
4
  are written.** rig-parts generates no images. The painting and See-through layers
@@ -157,7 +157,7 @@ atlas written by anything else would have no oracle behind it.
157
157
  | stage | tool | what it owns |
158
158
  | --- | --- | --- |
159
159
  | painting + See-through layers → parts and specs | **rig-parts** (npm `@rig-c/parts`) | the merge of two runs, the measurements, the rig spec and motion spec |
160
- | specs → Spine skeleton data | **[rig-c](https://github.com/rig-c/core)** (npm `rig-c`) | compile, the gate (rigc's own validator in an install; the round trip through `spine-core` where the runtime is beside it, as in this repository's CI), the named assertions, the packer, the renderer |
160
+ | specs → Spine skeleton data | **[@rig-c/core](https://github.com/rig-c/core)** (canonical npm `@rig-c/core`; this package's dependency is literally `rig-c`) | compile, the gate (rigc's own validator in an install; the round trip through `spine-core` where the runtime is beside it, as in this repository's CI), the named assertions, the packer, the renderer |
161
161
  | skeleton data → a page | **[rig-play](https://github.com/rig-c/play)** (npm `@rig-c/play`; formerly spine-html), a sibling project | a DOM renderer; rigc's `rig-play` profile is its policy, and every build here is gated under that profile as well as under `spine` |
162
162
 
163
163
  rig-parts never writes Spine data itself. Everything on disk under `check/build/`
@@ -512,11 +512,11 @@ as this port wrote it in issue #227).
512
512
  [Bun](https://bun.sh) 1.2 or later. `npm i -D @rig-c/parts` installs the
513
513
  `rig-parts` command (`npm install -g @rig-c/parts` puts it on `PATH`); it hands off
514
514
  to Bun and says so in one sentence if Bun is not on `PATH`. **`@rig-c/parts` is the
515
- package's name; versions 1.0.0-rc.1 to 1.5.3 were published as `rig-parts`, and
515
+ package's canonical name; versions 1.0.0-rc.1 to 1.5.3 were published as `rig-parts`, the convenience install name, and
516
516
  versions up to 0.16.0
517
- as `spine-parts`, its former name**, and the install keeps a `spine-parts` command
517
+ as `spine-parts`, the legacy install name**, and the install keeps a `spine-parts` command
518
518
  beside `rig-parts` for the transition, the same launcher under both names. On npm
519
- both former names stay published beside `@rig-c/parts` at every version, as aliases
519
+ both compatibility names stay published beside `@rig-c/parts` at every version, as aliases
520
520
  carrying the same files with only the `name` in `package.json` changed, so a
521
521
  project that depends on either keeps receiving every release; a new
522
522
  install names `@rig-c/parts` ([RELEASING.md](RELEASING.md), *The registry side*). rig-c
@@ -587,10 +587,15 @@ separate, and its agreement reading cannot certify an image's polarity.
587
587
 
588
588
  Assembly emits registered part sheets and references; rig emits PAD4 sheets and
589
589
  `depth_sheets.json`. Since 1.68.0 (#777), [config.turn.roles](docs/AUTHORING.md#3-configjson-field-by-field)
590
- uses depth sheets for 2.5D head turns with grid surfaces and `yaw_dial`/`pitch_dial`
590
+ uses depth sheets for 2.5D head turns with grid or authored weighted surfaces and `yaw_dial`/`pitch_dial`
591
591
  controls; see [`CONFIG_TURN_ROLE_UNKNOWN`](docs/AUTHORING.md#CONFIG_TURN_ROLE_UNKNOWN)
592
592
  and [`CONFIG_TURN_SURFACE_REQUIRED`](docs/AUTHORING.md#CONFIG_TURN_SURFACE_REQUIRED).
593
- Authored weighted body meshes do not consume depth sheets. No-image builds keep the
594
- legacy output bytes. `comfy seethrough --config <file> --depth-run <full|head>`
593
+ `turn.body.roles` adds independent body yaw. A weighted mesh declared as
594
+ `"surface"` in either group and blending head and torso bones receives both
595
+ fields in proportion to its skin weights. Each sibling island takes only its
596
+ own group; parts without a blended attachment keep their existing role behavior
597
+ and output bytes. Unlisted meshes do not consume turn depth sheets. See the
598
+ [blended surface contract](docs/AUTHORING.md#per-layer-depth-sheets-773).
599
+ No-image builds keep the legacy output bytes. `comfy seethrough --config <file> --depth-run <full|head>`
595
600
  uses the same opt-in; its default captures art only. Standalone authored part
596
601
  references remain active declarations. See [the input contract and refusals](docs/AUTHORING.md#per-layer-depth-sheets-773).
package/docs/AUTHORING.md CHANGED
@@ -41,7 +41,7 @@ with `flattenRig(built)`, not with the built file.
41
41
  | what | why | how |
42
42
  | --- | --- | --- |
43
43
  | [Bun](https://bun.sh) 1.2 or later | rig-parts and rig-c are Bun programs | `npm install -g @rig-c/parts` installs the command; it says so if Bun is missing |
44
- | [rig-c](https://www.npmjs.com/package/rig-c) | compiles, gates, packs and renders every rig; rig-parts writes no Spine data itself | installed with rig-parts as a dependency (`node_modules/.bin/rigc`); with no Spine runtime beside it, it gates with its own validator, and `rigc --version` says `entry: cli_core.ts` |
44
+ | [@rig-c/core](https://www.npmjs.com/package/@rig-c/core) | compiles, gates, packs and renders every rig; rig-parts writes no Spine data itself | installed with rig-parts as the literal dependency `rig-c` (`node_modules/.bin/rigc`); with no Spine runtime beside it, it gates with its own validator, and `rigc --version` says `entry: cli_core.ts` |
45
45
  | [See-through](https://github.com/shitagaki-lab/see-through), somewhere | the layer decomposition is the input | any route in README *Getting See-through layers*; it runs twice per character, outside this tool |
46
46
  | a GPU, wherever See-through runs | See-through is a diffusion model | nothing in rig-parts itself uses a GPU |
47
47
 
@@ -136,7 +136,7 @@ read by no CPU stage).
136
136
  | `motion.animations_from` | rig; check (named; read for folds) | optional, never proposed (issue #183): a path, relative to the config file's directory, to a file in rig-c's motion-spec shape, `{"spec": "rigc-motion/1", "animations": {"<name>": {"duration": …, "tracks": [...]}, …}}` — an expression, a gesture, anything beside the idle. On every `rig` and `build` each of its animations is written into `rig/motion.json` after `idle`, as read: nothing added, re-keyed or judged here (except `derive` keys on `turn`/`tilt`, issue #436, and `{"t": …, "set": "<name>" \| null}` keys on slot `"attachment"` tracks, issue #473, which expand to `"v": "<set>_<slot>"` or `"v": null` when the set hides the slot, or `"v": "<slot>"` for `null`, refused with `CONFIG_SET_COVERS_SLOT` when the set is undeclared or does not cover the track's slot), and each is rigc's to accept or refuse at the rig stage's gate, in rigc's words. It may name what `motion.json` already holds — the bones `bones` declares, the easings `shut` and `open`, the groups `eyes` and `brows` when the blink writes them — and nothing else from the file reaches it. The loader refuses, every problem at once: no such file or one that cannot be read (`CONFIG_FILE_PRESENT`), text that is not JSON (`CONFIG_IS_JSON`), a file that is not an object, a `spec` other than `"rigc-motion/1"`, an `animations` that is not a table of objects (`CONFIG_FIELD_TYPE`), any other key — rig-c's `easings`, `groups`, `setup`, `physics`, `mix`, `archetype` and `cut` included, which would be read and not written (`CONFIG_KEY_KNOWN`), an animation named `idle` (`CONFIG_ANIMATION_NAME_FREE`), and a key written twice in one object of the file, which JSON would fold into its last value without a word (`CONFIG_KEY_UNIQUE`). `check` names the others on one line (`beside the idle: …`) and reads each for folds, with the idle — `ANIMATIONS_DO_NOT_FOLD` (§7, issues #320, #333); every other bar reads the idle. Absent, `motion.json` holds the idle alone, byte for byte as before, and `check` reads that idle for folds |
137
137
  | `constraints` | rig (handed to rig-c as `rig.json`'s `constraints`); `compare` and the coverage lines (roles) | **authored**, optional; `propose` writes none, but with `--cloth` (issue #364), where it writes the recipe's physics and swing transforms (*Recipe: cloth and hair that answer the world*, below). A list of constraints in **rig-c's own rig-spec shape** (`RigConstraint`: `ik`, `transform`, `path`, `physics`, `slider` — rig-c's `src/rig.ts` documents every field), in the order rigc applies them. The loader checks only what this package owns: each entry is an object with a `type` rigc names (`CONFIG_CONSTRAINT_TYPE_KNOWN`) and a non-empty `name`, unique within its kind as rigc finds constraints (`CONFIG_CONSTRAINT_NAME_UNIQUE`; an ik and a transform may share one); every bone it names — `bones`, an ik's `target`, a transform's `source`, a physics or slider constraint's `bone` — is a bone `bones` declares, a chain link as `<chain><i>` (`CONFIG_NAME_RESOLVES`); the bone a constraint follows does not sit under a bone it drives (`CONFIG_CONSTRAINT_TARGET_DETACHED`). Every other field (`mix`, `softness`, `properties`, a path's `slot`, a slider's `animation`) and every value is rigc's to accept or refuse at the rig stage's gate, in rigc's words (`RIG_RIGC_GREEN`) — an ik's `bones` as a shape too: from rig-c 2.15.0 rigc refuses an ik over more than two bones, or over a pair whose second bone is not the first's child (issue #103; this loader refused both itself until then). A note and an `x-` record may ride on an entry; the rig stage leaves them out of what it hands rigc. Under the default `--idle-keys ctl` a two-bone ik whose child link the idle keys is split by that link's control, and rigc refuses the pair: run `rig --idle-keys direct` or `build --idle-keys direct` (the rig stage adds that sentence, naming the flag on the command that ran, to rigc's line; `build` forwards it to its rig stage, issue #95). Each bone a constraint follows is declared to rigc as `invariants.detached` from every bone it drives, which rigc's gate rule `A25` checks |
138
138
  | `stops` | rig (handed to rig-c as `rig.json`'s `stops`, and moves slots, mesh weights and child bones on stopped links onto `<link>_d`); `propose --from-config` (`LINT stop on <chain> …`) | **authored**, optional (issues #404, #447): `[{chain, links?, against, at, inward, outward, lower?: {inward, outward}}]` — rig-c's leg stops (`RigStop`, rig-c 2.56.0, `rig-c/src/stop.ts`). `chain` is a chain `bones` declares (`CONFIG_NAME_RESOLVES`, `RIG_NAME_RESOLVES`); `links`, optional, is a non-empty list of links of that chain (`CONFIG_NAME_RESOLVES`, `CONFIG_FIELD_TYPE`), or absent for every link of `chain` in chain order; `against` is a bone `bones` declares, a chain link as `<chain><i>` (`CONFIG_NAME_RESOLVES`, `RIG_NAME_RESOLVES`); `at` is `[x, y]` in `against`'s local space, as rig-c's stop takes it (`CONFIG_FIELD_TYPE`): since each chain link (`leg_r0`, `leg_r1`) is turned to point along its segment (`+x` from origin to next link or tip, `+y` 90° counter-clockwise in Spine world), `at: [d, n]` sits `d` px from `against`'s origin toward its end and `n` px perpendicular to it; `inward`, `outward` and `lower.inward`, `lower.outward` are finite numbers (`CONFIG_FIELD_TYPE`). Every other stop rule — non-negative bounds, each stopped link written by a constraint, `against` not under the stopped chain, the aim not degenerate, `\|rest\| + outward <= 180°` (`RIG_STOP_BOUNDS`) — is rigc's to accept or refuse at the rig stage's gate, in rigc's words (`RIG_RIGC_GREEN`). **Rising-limb / prone geometry (issue #447):** rig-c's `expandStops` aims `<chain>_rest` from `links[0]`'s setup origin at `<chain>_touch` (`at` in `against`'s local frame) and clamps `<link>_d` inside `[rest − inward, rest + outward]`; Spine wraps rotation at `±180°`, so `\|rest\| + outward <= 180°` is required (`RIG_STOP_BOUNDS`). Whenever `<chain>_touch` lies **above** `links[0]`'s root in rig pixels (`ty < y0`, i.e. higher Spine `y` — e.g. stopping a hanging cloth chain against a rising shin `leg_<s1>` in a prone or kneeling pose where the knee sits below `links[0]` and the ankle above it, so positive `at[0]` walks upward along the shin past `links[0]`'s root), `rest` lands in the upper half-plane (`\|rest\| > 90°`) and `\|rest\| + outward` exceeds `180°`. Stop against the descending thigh (`leg_<s0>`), set `links` to start at a link whose root sits above `<chain>_touch`, or omit the stop when the rising shin sits outside the hanging chain's sweep; `propose --from-config` prints `LINT stop on <chain> …` with the exact coordinates and angles when `<chain>_touch` lies above `links[0]`'s root or `\|rest\| + outward > 180°`. For every stopped link `<link>`, the rig stage moves any slot on `<link>`, any mesh weight on `<link>`, and any bone whose parent is `<link>` (a branched cloth tree's branches hanging from `<trunk_last>`, before `--idle-keys ctl` adds `<bone>_ctl` and before `turn` adds `turn_<part>_<bone>`) onto `<link>_d`, the drawn link bone rig-c's `expandStops` creates at `<link>`'s setup frame to carry the clamped rotation. Absent, `rig.json` carries no `stops` and no byte of any output moves |
139
- | `turn` | rig (adds the turn control or 2.5D head-turn producer) | **proposed** only with `propose --full`/`--head` (issue #251), then corrected, or **authored** for 2.5D depth-sampled head turns (issue #763): `{pivot?, depths?, deform?, band?, radius?, surface?: {radius?}, head?: {pivot?, radius?}, roles?, counter?, grid?, unitDepths?, body?}`. When `roles` is declared (`{<part>: "surface" \| "unit" \| "rear"}`, issue #763; `CONFIG_TURN_ROLE_UNKNOWN`, `CONFIG_TURN_SURFACE_REQUIRED`, `CONFIG_TURN_SURFACE_REGION`, `CONFIG_TURN_UNIT_MESH_BONES`), the rig stage runs the 2.5D depth-sampled head-turn producer: it edge-extends each turn-bound part's depth sheet across its transparent border and semi-transparent fringe from the nearest fully opaque (`alpha === 255`) texel before `PAD = 4` clamping (`padTurnDepthSheet`, `DEPTH_SILHOUETTE_SIZE_MISMATCH`), promotes `"surface"` regions to `generator: {kind: "grid", cols, rows, depth}` (`grid`: `[cols, rows]` or `{<part>: [cols, rows]}`, default `[13, 16]`, bounded at `<= 2,400` triangles per slot and `<= 4,000` total, `RIG_TURN_GRID_BUDGET`, `RIG_TURN_SURFACE_DEPTH_REQUIRED`, `RIG_TURN_SHARED_DEPTH_SCALE`), emits `faceshift` and `rear_shift` under `head` (`CONFIG_TURN_HEAD_BONE`, `RIG_TURN_HEAD_BONE`), `<part>_surface` and `<part>_unit` under `faceshift`, and `yaw_dial` and `pitch_dial` under `root` (`CONFIG_TURN_BONE_FREE`, `RIG_TURN_NAME_FREE`), re-parents `"unit"` region bones and `"rear"` bones and mesh weights to `faceshift` and `rear_shift` (while `"unit"` mesh parts receive their own `<part>_unit` carrier under `faceshift`, rebind direct `"head"` weights to `<part>_unit`, reparent bound chain roots to `<part>_unit` while keeping chain skinning weights intact, and key `<part>_unit` in `turn_units`, #790), samples each `"unit"` bone's depth from the `"surface"` depth sheet at its rest position (or reads `unitDepths.<part>`, `RIG_TURN_UNIT_DEPTH_REQUIRED`), enforces ear occlusion (`ear_r`/`ear_l` drawn before `"surface"` in `assemble.plan`, `CONFIG_TURN_EAR_DRAW_ORDER`, and behind the cheek surface, `RIG_TURN_EAR_DEPTH_BEHIND_CHEEK`), and writes `turn` and `tilt` `derive` tracks (`pivot` default `55` rig px, `counter` default `0.1` in `[0, 1]`, `CONFIG_TURN_COUNTER_RANGE`). `depths` holds, per part, the See-through layer's `depth_median` the part came from (larger = further back), read from the run the part was assembled from; a `painting:` patch has none and is not carried. A rider (issue #271) — a part from an `eyewhite`, `irides`, `eyelash`, `eyebrow`, `nose` or `mouth` layer — is drafted at the `face` part's depth, 0.001 nearer when parts.json draws it after the face and 0.001 further when before: See-through makes no depth of its own for the eye group (it cuts them from one depth map of the combined eyes) and clamps nose and mouth to the face's median − 0.001, and the two runs' own medians for these layers disagreed by up to 0.47 and swapped their order against the face. Every other layer — ears, headwear and earwear included — keeps its own median, unless it rides another part's bone. With no `face` part, or more than one, the riders keep their own and a note says so. A rider by bone (issue #535) — a part every *ownable* bone of which (a chain link, or a bone no other bone hangs from; `head`, `chest` and any bone with a child are shared and never count on their own) is *hosted* by another carried part, the host of a bone being the carried part that binds it (its region's bone; a mesh's `segments`, `contour` and `auto` regions' bones) with the most `opaque_px`, the earlier in parts.json on a tie, and which hosts no bone itself — is drafted at its host's depth, 0.001 nearer when drawn after the host and 0.001 further when before, and a note names the host, the bones and its own median: a pin, clip or ornament on the back hair's links travels with the back hair, not with its own layer's depth. `propose` reads the proposal's own `bones`, `meshes` and `regions`; the face riders are read by their tag first and never by their bones. A part bound to two hosts' bones rides neither and a note says so. In the rig stage, an authored depth on a rider by bone whose fraction differs from its host's by more than 0.1 of the dial (`TURN_RIDER_APART`, a share of `pivot − nearest`) is refused (`CONFIG_TURN_RIDER_DEPTH`); the host is read off `parts.json`'s `opaque_px`, so the config loader cannot see it. One note lists each part's depth and where it came from; a carrier the other run places more than 10 % of `pivot − nearest` away gets a note naming both values and the run read — the two runs are not reconciled. `pivot` is the depth that stays put; `propose` drafts the mean of the parts' depths weighted by `opaque_px`, the one depth at which the painted pixels' centroid does not slide under the dial. The rig stage adds a bone `turn` under `root` at its origin that nothing keys — its local x is the dial, in rig px — and carries each part by `(pivot − depth) / (pivot − nearest depth)` of it: the nearest part all of it, a part behind the pivot the other way, a part at the pivot not at all. Each part rides leaf twins (`turn_<part>_<bone>`, an identity child of every bone its slot and weights bind) moved by one `transform` constraint (`turn_<part>`, after the config's own); the idle's keys, the `<bone>_ctl` controls and a physics constraint stay on the bones, and the dial moves none of them. Optional `deform` (`Partial<FaceDeformFractions>`, issue #436) overrides the Set B ×2.5 face surface deformation table (`FACE_DEFORM_FRACTIONS`, checked against `FACE_DEFORM_RANGES` by `CONFIG_TURN_DEFORM_RANGE`); when `applyFaceSurfaceDeform` runs on a rig whose `motion` carries `tilt` or `turn` slider `derive` keys, it requires `config.turn` (`CONFIG_TURN_REQUIRED`, issue #478; `propose --full`/`--head` drafts it), promotes `face` on `head` (or `turn_face_head` when `turn` is declared) to the uneven 5×5 grid mesh, keys `face`, `hair_front` and `hair_back` deform timelines and ear/topknot tracks from `evalPitchFaceSurface` and `evalYawFaceSurface`, and samples the same deform field across each `features` member's rest span (`featRx = (24 / 106) · W`, `featRy = (12 / 128) · H`) with its depth fraction `z / zRef` as the field's angle input and chord foreshortening (`scalex` narrowing on the leading side and widening on the trailing side, `scaley` on pitch) so every feature's bounding box stays inside the deformed face plate across the rated band (issue #468). On yaw (`issue #479`), `evalYawFaceSurface` evaluates a **cylinder projection** (`cylinderYawDx`: `Δx(x, θ, R) = R · (sin(clamp(arcsin(clamp(x / R, −1, 1)) − θ, −π/2, π/2)) − clamp(x / R, −1, 1))`) of radius `R` (`turnSurfaceRadius`: `turn.surface.radius ?? turn.radius ?? turn.head.radius`, positive rig px checked by `CONFIG_FIELD_TYPE`, defaulting to half the face plate's opaque width `W / 2`) tapered by a cubic Hermite outline weight (`wOutline = 1` for `\|ux\| <= 0.7`, reaching `0` at `\|ux\| = 1.0`) so features slide across a fixed outline (`iris` shift within `±2%` of `cylinderYawDx`), the trailing cheek strip widens (`>= 1.54×` at `±15°`), and the leading jaw edge holds fixed (`0 px` shift) unless explicit horizontal `turn.deform` overrides (`turn_mid_x`, `turn_lead_compress_x`, `turn_trail_shift_x`) request the flat yaw table. On yaw (`issue #478`), `applyFaceSurfaceDeform` also derives a **head-only pivot** (`headTurnPivot`: `turn.head.pivot` when authored, otherwise the `opaque_px`-weighted mean of `depths[part]` across the head parts `DEFAULT_HEAD_TURN_PARTS` — `face`, `hair_front`, `hair_back`, `ear_r`, `ear_l`, `hairpin` — from `parts.json`, falling back to `turn.pivot`) so a forward torso or arm in `turn.depths` does not pull the head's rotation axis in front of `face`: `hair_back` (`depth_median > headPivot`, negative `headTurnFraction`) and `hairpin` behind `headPivot` translate opposite to the face's turn (`dx = s · turn_face_center_x · W · (headPivot − depth) / (headPivot − nearestHeadDepth)`), emerging on the trailing side to compensate for the leading-cheek foreshortening and keeping the combined head silhouette width near-constant across `±15°` without any same-sign `turn_hair_back_cheek_x` term. Optional `band` (`number` or `{yaw?, pitch?}`, positive degrees, issue #472) declares the rig's rated face turn band (default `FACE_RATED_BAND`: `yaw <= 15°`, `pitch <= 12°`); declaring a `turn.band` or a `motion.animations_from` `turn`/`tilt` `derive.degrees` above `±15°` yaw or `±12°` pitch without an `assemble.alternates` entry that replaces `face` is refused (`CONFIG_FACE_BAND_EXCEEDED`), and on a single-plate rig `applyFaceSurfaceDeform` adds self-targeting transform constraints `yaw_clamp` (`[-15, 15]`) and `pitch_clamp` (`[-12, 12]`) ahead of the slider constraints so driving `yaw` or `pitch` beyond the rated band clamps at the boundary. At rest: with `turn` declared, no pixel differs by more than 1 level at dial 0 (not byte-identical; the cause is float noise in the identity child bones, and the constraints add nothing); without `turn`, byte-identical. Neither `pivot` nor `depths` has a default (`CONFIG_FIELD_PRESENT`); `pivot` and `head.pivot` must lie behind the nearest part (`CONFIG_TURN_PIVOT_BEHIND_NEAREST`). Absent, no control is added and no byte of any output moves |
139
+ | `turn` | rig (adds the turn control or 2.5D head-turn producer) | **proposed** only with `propose --full`/`--head` (issue #251), then corrected, or **authored** for 2.5D depth-sampled head turns (issue #763): `{pivot?, depths?, deform?, band?, radius?, surface?: {radius?}, head?: {pivot?, radius?}, roles?, counter?, grid?, unitDepths?, body?}`. When `roles` is declared (`{<part>: "surface" \| "unit" \| "rear"}`, issue #763; `CONFIG_TURN_ROLE_UNKNOWN`, `CONFIG_TURN_SURFACE_REQUIRED`, `RIG_TURN_SURFACE_MESH_BINDINGS`, `CONFIG_TURN_UNIT_MESH_BONES`), the rig stage runs the 2.5D depth-sampled head-turn producer: it edge-extends each turn-bound part's depth sheet across its transparent border and semi-transparent fringe from the nearest fully opaque (`alpha === 255`) texel before `PAD = 4` clamping (`padTurnDepthSheet`, `DEPTH_SILHOUETTE_SIZE_MISMATCH`), keeps authored `"surface"` meshes and their skinning (#795), sampling each vertex at its weighted setup position on its own extended sheet and emitting one inverse-setup-bone offset per influence (`D = -(pivot + z - zRef) * sin(angle)`, on x for yaw and y for pitch, with no narrowing or 2D spin); shared frames moved by another turn role are refused (`RIG_TURN_SURFACE_MESH_BINDINGS`), as are alternate drawings without their own depth sampling frame (`RIG_TURN_SURFACE_MESH_ATTACHMENT`). It promotes `"surface"` regions to `generator: {kind: "grid", cols, rows, depth}` (`grid`: `[cols, rows]` or `{<part>: [cols, rows]}`, default `[13, 16]`, bounded at `<= 2,400` triangles per slot and `<= 4,000` total, `RIG_TURN_GRID_BUDGET`, `RIG_TURN_SURFACE_DEPTH_REQUIRED`, `RIG_TURN_SHARED_DEPTH_SCALE`), emits `faceshift` and `rear_shift` under `head` (`CONFIG_TURN_HEAD_BONE`, `RIG_TURN_HEAD_BONE`), `<part>_surface` and `<part>_unit` under `faceshift`, and `yaw_dial` and `pitch_dial` under `root` (`CONFIG_TURN_BONE_FREE`, `RIG_TURN_NAME_FREE`), re-parents `"unit"` region bones and `"rear"` bones and mesh weights to `faceshift` and `rear_shift` (while `"unit"` mesh parts receive their own `<part>_unit` carrier under `faceshift`, rebind direct `"head"` weights to `<part>_unit`, reparent bound chain roots to `<part>_unit` while keeping chain skinning weights intact, and key `<part>_unit` in `turn_units`, #790), samples each `"unit"` bone's depth from the `"surface"` depth sheet at its rest position (or reads `unitDepths.<part>`, `RIG_TURN_UNIT_DEPTH_REQUIRED`), enforces ear occlusion (`ear_r`/`ear_l` drawn before the `face` surface in `assemble.plan`, `CONFIG_TURN_EAR_DRAW_ORDER`, and behind the cheek surface, `RIG_TURN_EAR_DEPTH_BEHIND_CHEEK`), and writes `turn` and `tilt` `derive` tracks (`pivot` default `55` rig px, `counter` default `0.1` in `[0, 1]`, `CONFIG_TURN_COUNTER_RANGE`). `depths` holds, per part, the See-through layer's `depth_median` the part came from (larger = further back), read from the run the part was assembled from; a `painting:` patch has none and is not carried. A rider (issue #271) — a part from an `eyewhite`, `irides`, `eyelash`, `eyebrow`, `nose` or `mouth` layer — is drafted at the `face` part's depth, 0.001 nearer when parts.json draws it after the face and 0.001 further when before: See-through makes no depth of its own for the eye group (it cuts them from one depth map of the combined eyes) and clamps nose and mouth to the face's median − 0.001, and the two runs' own medians for these layers disagreed by up to 0.47 and swapped their order against the face. Every other layer — ears, headwear and earwear included — keeps its own median, unless it rides another part's bone. With no `face` part, or more than one, the riders keep their own and a note says so. A rider by bone (issue #535) — a part every *ownable* bone of which (a chain link, or a bone no other bone hangs from; `head`, `chest` and any bone with a child are shared and never count on their own) is *hosted* by another carried part, the host of a bone being the carried part that binds it (its region's bone; a mesh's `segments`, `contour` and `auto` regions' bones) with the most `opaque_px`, the earlier in parts.json on a tie, and which hosts no bone itself — is drafted at its host's depth, 0.001 nearer when drawn after the host and 0.001 further when before, and a note names the host, the bones and its own median: a pin, clip or ornament on the back hair's links travels with the back hair, not with its own layer's depth. `propose` reads the proposal's own `bones`, `meshes` and `regions`; the face riders are read by their tag first and never by their bones. A part bound to two hosts' bones rides neither and a note says so. In the rig stage, an authored depth on a rider by bone whose fraction differs from its host's by more than 0.1 of the dial (`TURN_RIDER_APART`, a share of `pivot − nearest`) is refused (`CONFIG_TURN_RIDER_DEPTH`); the host is read off `parts.json`'s `opaque_px`, so the config loader cannot see it. One note lists each part's depth and where it came from; a carrier the other run places more than 10 % of `pivot − nearest` away gets a note naming both values and the run read — the two runs are not reconciled. `pivot` is the depth that stays put; `propose` drafts the mean of the parts' depths weighted by `opaque_px`, the one depth at which the painted pixels' centroid does not slide under the dial. The rig stage adds a bone `turn` under `root` at its origin that nothing keys — its local x is the dial, in rig px — and carries each part by `(pivot − depth) / (pivot − nearest depth)` of it: the nearest part all of it, a part behind the pivot the other way, a part at the pivot not at all. Each part rides leaf twins (`turn_<part>_<bone>`, an identity child of every bone its slot and weights bind) moved by one `transform` constraint (`turn_<part>`, after the config's own); the idle's keys, the `<bone>_ctl` controls and a physics constraint stay on the bones, and the dial moves none of them. Optional `deform` (`Partial<FaceDeformFractions>`, issue #436) overrides the Set B ×2.5 face surface deformation table (`FACE_DEFORM_FRACTIONS`, checked against `FACE_DEFORM_RANGES` by `CONFIG_TURN_DEFORM_RANGE`); when `applyFaceSurfaceDeform` runs on a rig whose `motion` carries `tilt` or `turn` slider `derive` keys, it requires `config.turn` (`CONFIG_TURN_REQUIRED`, issue #478; `propose --full`/`--head` drafts it), promotes `face` on `head` (or `turn_face_head` when `turn` is declared) to the uneven 5×5 grid mesh, keys `face`, `hair_front` and `hair_back` deform timelines and ear/topknot tracks from `evalPitchFaceSurface` and `evalYawFaceSurface`, and samples the same deform field across each `features` member's rest span (`featRx = (24 / 106) · W`, `featRy = (12 / 128) · H`) with its depth fraction `z / zRef` as the field's angle input and chord foreshortening (`scalex` narrowing on the leading side and widening on the trailing side, `scaley` on pitch) so every feature's bounding box stays inside the deformed face plate across the rated band (issue #468). On yaw (`issue #479`), `evalYawFaceSurface` evaluates a **cylinder projection** (`cylinderYawDx`: `Δx(x, θ, R) = R · (sin(clamp(arcsin(clamp(x / R, −1, 1)) − θ, −π/2, π/2)) − clamp(x / R, −1, 1))`) of radius `R` (`turnSurfaceRadius`: `turn.surface.radius ?? turn.radius ?? turn.head.radius`, positive rig px checked by `CONFIG_FIELD_TYPE`, defaulting to half the face plate's opaque width `W / 2`) tapered by a cubic Hermite outline weight (`wOutline = 1` for `\|ux\| <= 0.7`, reaching `0` at `\|ux\| = 1.0`) so features slide across a fixed outline (`iris` shift within `±2%` of `cylinderYawDx`), the trailing cheek strip widens (`>= 1.54×` at `±15°`), and the leading jaw edge holds fixed (`0 px` shift) unless explicit horizontal `turn.deform` overrides (`turn_mid_x`, `turn_lead_compress_x`, `turn_trail_shift_x`) request the flat yaw table. On yaw (`issue #478`), `applyFaceSurfaceDeform` also derives a **head-only pivot** (`headTurnPivot`: `turn.head.pivot` when authored, otherwise the `opaque_px`-weighted mean of `depths[part]` across the head parts `DEFAULT_HEAD_TURN_PARTS` — `face`, `hair_front`, `hair_back`, `ear_r`, `ear_l`, `hairpin` — from `parts.json`, falling back to `turn.pivot`) so a forward torso or arm in `turn.depths` does not pull the head's rotation axis in front of `face`: `hair_back` (`depth_median > headPivot`, negative `headTurnFraction`) and `hairpin` behind `headPivot` translate opposite to the face's turn (`dx = s · turn_face_center_x · W · (headPivot − depth) / (headPivot − nearestHeadDepth)`), emerging on the trailing side to compensate for the leading-cheek foreshortening and keeping the combined head silhouette width near-constant across `±15°` without any same-sign `turn_hair_back_cheek_x` term. Optional `band` (`number` or `{yaw?, pitch?}`, positive degrees, issue #472) declares the rig's rated face turn band (default `FACE_RATED_BAND`: `yaw <= 15°`, `pitch <= 12°`); declaring a `turn.band` or a `motion.animations_from` `turn`/`tilt` `derive.degrees` above `±15°` yaw or `±12°` pitch without an `assemble.alternates` entry that replaces `face` is refused (`CONFIG_FACE_BAND_EXCEEDED`), and on a single-plate rig `applyFaceSurfaceDeform` adds self-targeting transform constraints `yaw_clamp` (`[-15, 15]`) and `pitch_clamp` (`[-12, 12]`) ahead of the slider constraints so driving `yaw` or `pitch` beyond the rated band clamps at the boundary. At rest: with `turn` declared, no pixel differs by more than 1 level at dial 0 (not byte-identical; the cause is float noise in the identity child bones, and the constraints add nothing); without `turn`, byte-identical. Neither `pivot` nor `depths` has a default (`CONFIG_FIELD_PRESENT`); `pivot` and `head.pivot` must lie behind the nearest part (`CONFIG_TURN_PIVOT_BEHIND_NEAREST`). Absent, no control is added and no byte of any output moves |
140
140
  | `scene` | assemble (the recomposite, its holes and the figure's mask); check, through `parts.json`'s `scene` block (`RECOMPOSITE_HOLES`, the seam) | **authored**, optional; `propose` writes none (issue #242). `{}` declares the painting a scene: the figure and its surroundings in one image, See-through's full run holding only the figure. With it, `assemble` reads the recomposite figures, the hole list and the `uncovered:` lines inside the figure — the rig pixels where any full-run layer's alpha is above 8 (`OPAQUE_ALPHA_ABOVE`, the cut every layer's painted pixels are read by) — each line starting `inside the figure (config.scene: …, <n> of <m> rig px)`; writes that figure as `figure_rig.png` (white on black) beside the recomposite, and a `scene` block in `parts.json`; flags error pixels on the error map inside it only (outside, the painting grey); and `check` leaves out of the seam every frame pixel whose composite sample reaches the painting's outermost row or column, saying how many (`seam_border` in `check.json`, and on the seam line). It takes no field: the figure and its threshold are derived. A key in it other than a record or an annotation is `CONFIG_KEY_KNOWN`. Absent, no byte of any output moves |
141
141
  | `cloth` | `propose --cloth` only; no other stage reads it, so it moves no byte of any build | **authored**, optional (issue #364): one recipe per tag, `{"bottomwear": {…}, "back hair": {…}, "front hair": {…}}`, each `{chains, links, wind, gravity, split?, length_ratio?, strength?, damping?, alternate_damping?, translate?, swing?, part?, influence?}`. `influence` (issue #518) — `{across, max, shape, radius?}`: the parts this recipe meshes are drafted in the influence mode (`meshes.<part>.influence` above) at their lattice's cell, with `across`, `max` and `shape` as declared (each required — the reading behind the radius did not vary them) and `radius` as declared or, absent, drafted as the farthest vertex's distance plus 3 cells (the `influence.radius` row); without it the parts keep their lattice. `chains` — trees across the piece (for `back hair`, per side of the eye axis), a whole number, 1 or more; `links` — links from root to tip on every path, 1 or more; `split` — `{at, into}`: the first `at` links are the trunk, which forks into `into` (2 or more) branches; `at` below `links` (`CONFIG_CLOTH_SPLIT_BEFORE_TIP`); `length_ratio` — a path's last link over its first, above 0, default 0.5; `strength` — `{trunk, branch, edge}`, each above 0 and below the spring's stability bound (`CONFIG_CLOTH_SPRING_STABLE`), default 100 / 100 / 50; `damping` — in [0, 1], absent: rig-c's default; `alternate_damping` — the odd trees' damping, in [0, 1], beside `damping` and different from it (`CONFIG_CLOTH_ALTERNATE_DIFFERS`); `wind`, `gravity` — `[root, tip]`, each 0 or more, tip at or above root (`CONFIG_CLOTH_RESPONSE_GROWS_TO_TIP`); `translate` — the x and y mix of a dangling end's flutter, above 0 and at most 1; `swing` — `bottomwear` only, `{scales}`, one positive scale per tree (`CONFIG_CLOTH_SWING_SCALE_PER_TREE`); `part` — `bottomwear` only (`CONFIG_CLOTH_PART_ON_BOTTOMWEAR`), a non-empty part or cut-piece name: the `topwear` part that holds a skirt See-through returned inside it (a dress), or its skirt piece cut by `assemble.cuts`, which takes the skirt's trees (issue #402, *A skirt inside topwear* below; the part is checked by `propose`, `PROPOSE_CLOTH_PART`). The two defaults are the recipe's own, measured on its synthetic fixture (the recipe below). The recipe below says what each field drafts. The config written: `propose --cloth <config.json> --write-config <out.json>` (issue #537) writes this config's own text back with the sections the recipe drafts spliced in — `meshes.<part>` and `regions.<part>`, and `bones`, `constraints` and `motion.tracks` entry by entry by name (issue #552) — and every other byte as read; `--from <previous config>` (issue #571) takes an entry equal to the previous recipe's draft as the recipe's (*The config written*, under the recipe below) |
142
142
  | `proposed_rig_scale` | assemble, rig, build, `propose --from-config`/`--compare` | **proposed** by `propose` (issue #354): `parts.json`'s `scale_rig_per_source`, the `assemble.rig_scale` the rig sections (`bones`, `meshes`, `limbs`, `motion`) were drafted at. Held equal to `assemble.rig_scale` when present (`CONFIG_PROPOSED_RIG_SCALE`; 0, negative or not a number: `CONFIG_FIELD_TYPE`). Absent on a hand-authored config, where no byte of any output moves |
@@ -4513,11 +4513,13 @@ and stay absent).
4513
4513
  | <a id="CONFIG_TURN_COUNTER_RANGE"></a>`CONFIG_TURN_COUNTER_RANGE` | `config.turn.counter` (or `config.turn.body.counter`) is outside `[0, 1]` | supply a non-negative rear counter-translation fraction in `[0, 1]` |
4514
4514
  | <a id="CONFIG_TURN_ROLE_UNKNOWN"></a>`CONFIG_TURN_ROLE_UNKNOWN` | `config.turn.roles.<part>` (or `config.turn.body.roles.<part>`) is not `"surface"`, `"unit"` or `"rear"` | declare `"surface"`, `"unit"` or `"rear"` |
4515
4515
  | <a id="CONFIG_TURN_SURFACE_REQUIRED"></a>`CONFIG_TURN_SURFACE_REQUIRED` | `config.turn.roles` (or `config.turn.body.roles`) declares no `"surface"` part | declare at least one part as `"surface"` |
4516
- | <a id="CONFIG_TURN_SURFACE_REGION"></a>`CONFIG_TURN_SURFACE_REGION` | `config.turn.roles.<part>` (or `config.turn.body.roles.<part>`) declares `"surface"` for a part that is also in `config.meshes` | attach `"surface"` parts in `config.regions` (so the rig stage promotes them to depth-backed grid meshes on `<part>_surface`), or give the mesh part role `"unit"` or `"rear"` |
4517
4516
  | <a id="CONFIG_TURN_UNIT_MESH_BONES"></a>`CONFIG_TURN_UNIT_MESH_BONES` | `config.turn.roles.<part>` (or `config.turn.body.roles.<part>`) declares `"unit"` for a mesh part in `config.meshes` that binds a bone outside the `"head"` subtree (or outside the torso carrier subtree for `turn.body`), or shares a bound bone or chain with another `"unit"` mesh part, so its bones cannot be moved under `<part>_unit` (#790) | bind each `"unit"` mesh only to `"head"` and its own child bones or chains under `"head"` (or to the torso root bone and its own non-head descendants for `turn.body`), or give the part role `"rear"` |
4518
- | <a id="CONFIG_TURN_EAR_DRAW_ORDER"></a>`CONFIG_TURN_EAR_DRAW_ORDER` | an ear part in `config.turn.roles` is drawn after a `"surface"` part in `assemble.plan` | place `ear_r` and `ear_l` before `face` in `assemble.plan` so the turning cheek occludes the far ear |
4517
+ | <a id="CONFIG_TURN_EAR_DRAW_ORDER"></a>`CONFIG_TURN_EAR_DRAW_ORDER` | an ear part in `config.turn.roles` is drawn after `face` with role `"surface"` in `assemble.plan` | place `ear_r` and `ear_l` before `face` in `assemble.plan` so the turning cheek occludes the far ear |
4519
4518
  | <a id="CONFIG_TURN_HEAD_BONE"></a>`CONFIG_TURN_HEAD_BONE` | `config.turn.roles` is declared without a single bone `"head"` in `config.bones`, or `config.turn.body` without a single bone `"chest"` / `"hip"` (or its declared `bone`) | declare `"head"` (or the body turn root bone) as a single bone in `config.bones` |
4520
4519
  | <a id="CONFIG_TURN_SLIDER_NAME_FREE"></a>`CONFIG_TURN_SLIDER_NAME_FREE` | `config.turn.body.slider` (or the default `"body_yaw_dial"`) collides with a head turn dial (`"yaw"`, `"pitch"`, `"yaw_dial"`, `"pitch_dial"`) or an existing slider constraint in `config.constraints` (#787) | choose a distinct slider name in `config.turn.body.slider` |
4520
+ | <a id="RIG_TURN_SURFACE_MESH_GROUPS"></a>`RIG_TURN_SURFACE_MESH_GROUPS` | a surface part contains a blended attachment but lacks one 2.5D group, includes an ungrouped positive influence in any attachment, or also declares a unit/rear role | declare both `turn.roles` and `turn.body`, a body root outside head, surface in one or both groups, and bindings wholly inside those two subtrees |
4521
+ | <a id="RIG_TURN_SURFACE_MESH_BINDINGS"></a>`RIG_TURN_SURFACE_MESH_BINDINGS` | an authored surface mesh has unresolved/nonclosing weights or shares a frame moved by a unit/rear turn carrier | provide weighted bindings closing at 1 in the authored frame; use independent chains for parts with different roles |
4522
+ | <a id="RIG_TURN_SURFACE_MESH_ATTACHMENT"></a>`RIG_TURN_SURFACE_MESH_ATTACHMENT` | a surface mesh has an alternate drawing without its own registered depth sampling frame | use the base attachment; explicit islands retain their own slot, attachment and bindings |
4521
4523
  | <a id="RIG_TURN_SURFACE_DEPTH_REQUIRED"></a>`RIG_TURN_SURFACE_DEPTH_REQUIRED` | a part with role `"surface"` in `config.turn.roles` or `config.turn.body.roles` carries no depth sheet in `parts.json` | run `assemble` with `config.depth` or provide `<part>_depth.png` in `parts.json` |
4522
4524
  | <a id="RIG_TURN_GRID_BUDGET"></a>`RIG_TURN_GRID_BUDGET` | a `"surface"` grid exceeds 2,400 triangles on one slot or 4,000 triangles across all `"surface"` slots | lower `config.turn.grid` / `config.turn.body.grid` `[cols, rows]` within the per-slot and total budgets |
4523
4525
  | <a id="RIG_TURN_HEAD_BONE"></a>`RIG_TURN_HEAD_BONE` | `buildRig` found no `"head"` (or body turn root) bone when emitting 2.5D turn carriers | declare `"head"` (or the body turn root bone) in `config.bones` |
@@ -5565,15 +5567,51 @@ still split has separate lower/upper scalar slices at the same row as the art;
5565
5567
  both keep original source provenance. Its references describe inputs for Core's
5566
5568
  `generator.depth = {image, near, zScale}`; sources are provenance, not Core
5567
5569
  fields. Since 1.68.0 (#777), [config.turn.roles](#3-configjson-field-by-field) consumes
5568
- depth sheets for 2.5D head turns with grid surfaces and `yaw_dial`/`pitch_dial`
5570
+ depth sheets for 2.5D head turns with grid surfaces or authored weighted surface meshes (#795) and `yaw_dial`/`pitch_dial`
5569
5571
  controls, and `config.turn.body` (#787) extends the same 2.5D turn pipeline to
5570
5572
  torso/body parts under an independent `body_yaw_dial` (or `turn.body.slider`)
5571
5573
  dial; see [`CONFIG_TURN_ROLE_UNKNOWN`](#CONFIG_TURN_ROLE_UNKNOWN),
5572
5574
  [`CONFIG_TURN_SURFACE_REQUIRED`](#CONFIG_TURN_SURFACE_REQUIRED),
5573
- [`CONFIG_TURN_SURFACE_REGION`](#CONFIG_TURN_SURFACE_REGION),
5575
+ [`RIG_TURN_SURFACE_MESH_BINDINGS`](#RIG_TURN_SURFACE_MESH_BINDINGS),
5574
5576
  [`CONFIG_TURN_UNIT_MESH_BONES`](#CONFIG_TURN_UNIT_MESH_BONES) and
5575
5577
  [`CONFIG_TURN_SLIDER_NAME_FREE`](#CONFIG_TURN_SLIDER_NAME_FREE).
5576
- Authored weighted body meshes not named in `config.turn.body.roles` are unchanged and do not consume depth sheets. Measurement sheets are not packed
5578
+ A weighted surface spanning the head and body subtrees (#796) takes both
5579
+ fields. Declare it as `"surface"` in `turn.roles` or `turn.body.roles` (both is
5580
+ also accepted), with both 2.5D groups present. Head descendants belong to the
5581
+ head group; the body root (`turn.body.bone`, otherwise `chest`, otherwise `hip`)
5582
+ and its descendants outside head belong to the body group. Each vertex's
5583
+ setup position samples that part's own extended sheet; each group's pivot and
5584
+ reference-depth rule produce its offset. A vertex with 0.7 torso and 0.3 head
5585
+ weights receives `0.7 * bodyOffset + 0.3 * headOffset`. Each influence stores
5586
+ only its group's inverse-frame offset; Spine applies its weight once. Head yaw
5587
+ and pitch and body yaw remain independent and additive. No bone is rebound,
5588
+ no topology is regenerated, and the neutral keys are empty. The split is
5589
+ enabled only when a part contains an attachment with positive bindings to
5590
+ both groups. Every attachment of that part then carries its own
5591
+ group mask: a head-only sibling island receives head yaw/pitch only; a
5592
+ body-only sibling receives body yaw only. An inactive group's timeline is
5593
+ omitted, so a zero timeline cannot overwrite the active slider's deform.
5594
+ Their authored topology and binding order remain unchanged. A part with no blended attachment keeps its explicit
5595
+ role behavior and output bytes, even if separate single-group islands bind
5596
+ different subtrees. Generated meshes and explicit mixed attachments use the
5597
+ same split.
5598
+
5599
+ An unlisted mesh does not opt in merely by spanning the subtrees. A blended
5600
+ surface requires its own depth sheet (`RIG_TURN_SURFACE_DEPTH_REQUIRED`) and
5601
+ both groups, with every positive influence in one of their subtrees, including
5602
+ on sibling attachments (`RIG_TURN_SURFACE_MESH_GROUPS`). Zero weights do not
5603
+ make an attachment blended or require the other group; on the split path
5604
+ their deform pairs are zero and retain their place in the binding stream.
5605
+ Every binding name must still resolve and weights must still close at one,
5606
+ even for an inactive sibling. Do not use `"unit"` to opt in: its existing
5607
+ `CONFIG_TURN_UNIT_MESH_BONES` rule still requires one carrier subtree.
5608
+ Shared unit/rear carriers that move a surface's binding frame remain refused
5609
+ by `RIG_TURN_SURFACE_MESH_BINDINGS`; a blended surface does not add a second
5610
+ carrier translation to compensate. Alternate drawings still need their own
5611
+ registered sampling frame (`RIG_TURN_SURFACE_MESH_ATTACHMENT`).
5612
+
5613
+ Authored weighted body meshes absent from both surface-role tables are unchanged
5614
+ and do not consume depth sheets. Measurement sheets are not packed
5577
5615
  art. An authored `parts.json` depth reference remains an active standalone
5578
5616
  `rig` declaration even without config opt-in: its file/size/color/opacity
5579
5617
  guards still apply. With binding inactive there is no added reference, file or
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rig-parts",
3
- "version": "1.71.1",
3
+ "version": "1.72.0",
4
4
  "description": "AI-authored 2D character parts from one anime painting and its See-through layer decomposition: measured parts, weighted-mesh rig specs, verified through rig-c before anything is written. A CLI for agents that cannot see the image.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/config.ts CHANGED
@@ -4797,13 +4797,6 @@ function checkTurn(
4797
4797
  c.fail('CONFIG_TURN_ROLE_UNKNOWN', `${at}.roles.${part}`, `is ${show(role)}; expected one of ${TURN_ROLES.map((x) => `"${x}"`).join(', ')}`);
4798
4798
  } else {
4799
4799
  if (role === 'surface') {
4800
- if (meshParts.has(part)) {
4801
- c.fail(
4802
- 'CONFIG_TURN_SURFACE_REGION',
4803
- `${at}.roles.${part}`,
4804
- `declares "${part}" as "surface", and config.meshes.${part} also declares a mesh for "${part}"; a 2.5D turn "surface" part must be attached in config.regions so the rig stage can promote it to a depth-backed grid mesh`,
4805
- );
4806
- }
4807
4800
  surfaceParts.push(part);
4808
4801
  }
4809
4802
  if (role === 'unit') {
@@ -4853,7 +4846,7 @@ function checkTurn(
4853
4846
  }
4854
4847
  for (const ear of earParts) {
4855
4848
  const earIdx = parts.indexOf(ear);
4856
- for (const surf of surfaceParts) {
4849
+ for (const surf of surfaceParts.filter((p) => p === 'face')) {
4857
4850
  const surfIdx = parts.indexOf(surf);
4858
4851
  if (earIdx !== -1 && surfIdx !== -1 && earIdx > surfIdx) {
4859
4852
  c.fail(
@@ -4867,7 +4860,7 @@ function checkTurn(
4867
4860
  if (!bones.has('head')) {
4868
4861
  c.fail('CONFIG_TURN_HEAD_BONE', `${at}.roles`, 'requires a declared "head" bone in config.bones to parent the 2.5D turn carriers');
4869
4862
  }
4870
- for (const reserved of [FACESHIFT_BONE, REAR_SHIFT_BONE, ...surfaceParts.map(turnSurfaceBone), ...unitMeshParts.map(turnUnitBone)]) {
4863
+ for (const reserved of [FACESHIFT_BONE, REAR_SHIFT_BONE, ...surfaceParts.filter((p) => !meshParts.has(p)).map(turnSurfaceBone), ...unitMeshParts.map(turnUnitBone)]) {
4871
4864
  if (bones.has(reserved)) {
4872
4865
  c.fail('CONFIG_TURN_BONE_FREE', `bone "${reserved}"`, `is a carrier bone the rig stage adds under head for config.turn.roles, and config.bones already declares a bone of that name; rename it`);
4873
4866
  }
@@ -4935,13 +4928,6 @@ function checkTurn(
4935
4928
  if (typeof role !== 'string' || !(TURN_ROLES as readonly string[]).includes(role)) {
4936
4929
  c.fail('CONFIG_TURN_ROLE_UNKNOWN', `${bAt}.roles.${part}`, `is ${show(role)}; expected one of ${TURN_ROLES.map((x) => `"${x}"`).join(', ')}`);
4937
4930
  } else if (role === 'surface') {
4938
- if (meshParts.has(part)) {
4939
- c.fail(
4940
- 'CONFIG_TURN_SURFACE_REGION',
4941
- `${bAt}.roles.${part}`,
4942
- `declares "${part}" as "surface", and config.meshes.${part} also declares a mesh for "${part}"; a 2.5D turn "surface" part must be attached in config.regions so the rig stage can promote it to a depth-backed grid mesh`,
4943
- );
4944
- }
4945
4931
  bodySurfaceParts.push(part);
4946
4932
  } else if (role === 'unit' && meshParts.has(part)) {
4947
4933
  bodyUnitMeshParts.push(part);
@@ -4984,7 +4970,7 @@ function checkTurn(
4984
4970
  if (bodySurfaceParts.length === 0) {
4985
4971
  c.fail('CONFIG_TURN_SURFACE_REQUIRED', `${bAt}.roles`, 'declares no part with role "surface"; at least one surface part is required for 2.5D body turn');
4986
4972
  }
4987
- for (const reserved of [BODYSHIFT_BONE, BODY_REAR_SHIFT_BONE, ...bodySurfaceParts.map(turnSurfaceBone), ...bodyUnitMeshParts.map(turnUnitBone)]) {
4973
+ for (const reserved of [BODYSHIFT_BONE, BODY_REAR_SHIFT_BONE, ...bodySurfaceParts.filter((p) => !meshParts.has(p)).map(turnSurfaceBone), ...bodyUnitMeshParts.map(turnUnitBone)]) {
4988
4974
  if (bones.has(reserved)) {
4989
4975
  c.fail('CONFIG_TURN_BONE_FREE', `bone "${reserved}"`, `is a carrier bone the rig stage adds for config.turn.body.roles, and config.bones already declares a bone of that name; rename it`);
4990
4976
  }
package/src/rig.ts CHANGED
@@ -2435,12 +2435,8 @@ export function buildWaistPairSource(
2435
2435
  const isBodySurface = cfg.turn?.body?.roles?.[p.name] === 'surface';
2436
2436
  if (isHeadSurface || isBodySurface) {
2437
2437
  const roleField = isHeadSurface ? `config.turn.roles.${p.name}` : `config.turn.body.roles.${p.name}`;
2438
- if (cfg.meshes[p.name] !== undefined) {
2439
- fail(
2440
- 'CONFIG_TURN_SURFACE_REGION',
2441
- roleField,
2442
- `declares "${p.name}" as "surface", and config.meshes.${p.name} also declares a mesh for "${p.name}"; a 2.5D turn "surface" part must be attached in config.regions so the rig stage can promote it to a depth-backed grid mesh`,
2443
- );
2438
+ if (cfg.meshes[p.name] !== undefined && configuredAlts.some((a) => (a.parts === undefined || a.parts.includes(p.name)) && !(a.hides ?? []).includes(p.name))) {
2439
+ fail('RIG_TURN_SURFACE_MESH_ATTACHMENT', roleField, `declares an alternate drawing for surface mesh "${p.name}"; alternate drawings need their own registered depth sampling frame`);
2444
2440
  continue;
2445
2441
  }
2446
2442
  if (p.depth === undefined || scalar === undefined) {
@@ -3134,7 +3130,7 @@ export function buildWaistPairSource(
3134
3130
  unitMeshBones.push({ name: turnUnitBone(p.name), parent: FACESHIFT_BONE, x: 0, y: 0 });
3135
3131
  continue;
3136
3132
  }
3137
- if (roles[p.name] !== 'surface') continue;
3133
+ if (roles[p.name] !== 'surface' || cfg.meshes[p.name] !== undefined) continue;
3138
3134
  const [cols, rows] = resolveTurnGrid(cfg.turn, p.name);
3139
3135
  totalGridTriangles += 2 * (cols - 1) * (rows - 1);
3140
3136
  const cx = p.x + p.w / 2;
@@ -3324,7 +3320,7 @@ export function buildWaistPairSource(
3324
3320
  unitMeshBones.push({ name: turnUnitBone(p.name), parent: BODYSHIFT_BONE, x: 0, y: 0 });
3325
3321
  continue;
3326
3322
  }
3327
- if (bodyRoles[p.name] !== 'surface') continue;
3323
+ if (bodyRoles[p.name] !== 'surface' || cfg.meshes[p.name] !== undefined) continue;
3328
3324
  const [cols, rows] = resolveTurnGrid(bodySpec, p.name, cfg.turn);
3329
3325
  totalGridTriangles += 2 * (cols - 1) * (rows - 1);
3330
3326
  const cx = p.x + p.w / 2;
@@ -3665,6 +3661,7 @@ export function buildWaistPairSource(
3665
3661
  stills,
3666
3662
  boneLandmarks,
3667
3663
  hasAlternateFaceSet,
3664
+ surfaceMeshes: turnSurfaceMeshes(cfg, rig, parts.rig_size),
3668
3665
  });
3669
3666
  }
3670
3667
  bindFaceSurfaceDeform(motion, (merged) => {
@@ -3680,6 +3677,7 @@ export function buildWaistPairSource(
3680
3677
  stills,
3681
3678
  boneLandmarks,
3682
3679
  hasAlternateFaceSet,
3680
+ surfaceMeshes: turnSurfaceMeshes(cfg, rig, parts.rig_size),
3683
3681
  });
3684
3682
  }
3685
3683
  if (cfg.turn?.roles === undefined && (cfg.turn === undefined || cfg.turn.body === undefined || cfg.turn.depths !== undefined)) {
@@ -4177,3 +4175,24 @@ function refuseSharedWaistMotion(motion: MotionSpec, top: string, bone: string):
4177
4175
  if (record(value) && Array.isArray(value.tracks) && value.tracks.some((track) => record(track) && track.bone === bone)) refuse('RIG_WAIST_MOTION', `animation "${animation}" drives generated waist bone "${bone}"; original tracks must retain their authored targets`);
4178
4176
  }
4179
4177
  }
4178
+
4179
+ /** Final named bindings, including explicit islands; grid surfaces keep their Core path. */
4180
+ function turnSurfaceMeshes(cfg: CharacterConfig, rig: RigSpec, canvas: readonly [number, number]) {
4181
+ const meshes = [];
4182
+ for (const part of Object.keys(cfg.meshes)) {
4183
+ if (cfg.turn?.roles?.[part] !== 'surface' && cfg.turn?.body?.roles?.[part] !== 'surface') continue;
4184
+ for (const slot of rig.slots) {
4185
+ if (slot.name !== part && !slot.name.startsWith(`${part}__island`)) continue;
4186
+ for (const [attachment, att] of Object.entries(rig.skins.default[slot.name] ?? {})) {
4187
+ if (!('type' in att) || att.weights === undefined || att.weights.length === 0) {
4188
+ throw new PartsError([{ code: 'RIG_TURN_SURFACE_MESH_BINDINGS', object: `surface mesh "${slot.name}/${attachment}"`, detail: 'requires an authored weighted mesh with named bindings; a region or unresolved generator cannot carry weighted depth offsets' }]);
4189
+ }
4190
+ if (attachment !== part && !slot.name.startsWith(`${part}__island`)) {
4191
+ throw new PartsError([{ code: 'RIG_TURN_SURFACE_MESH_ATTACHMENT', object: `surface mesh "${slot.name}/${attachment}"`, detail: `requires the base drawing "${part}"; alternate drawings need their own registered depth sampling frame` }]);
4192
+ }
4193
+ meshes.push({ part, slot: slot.name, attachment, weights: att.weights, canvas });
4194
+ }
4195
+ }
4196
+ }
4197
+ return meshes;
4198
+ }
package/src/turn.ts CHANGED
@@ -28,8 +28,8 @@
28
28
  * that the depth maps do not carry relief inside a layer, so a part moves as
29
29
  * one piece. Pure: no file, no clock.
30
30
  */
31
- import { computeWorldTransforms, toBoneLocalVector, toWorld, type BoneTransform } from './coords.ts';
32
- import { extendDepthSilhouette, type PartDepthReference } from './depthsheets.ts';
31
+ import { computeWorldTransforms, setupToPaintingPoint, toBoneLocalVector, toWorld, type BoneTransform } from './coords.ts';
32
+ import { extendDepthSilhouette, sampleDepthFloat, type PartDepthReference } from './depthsheets.ts';
33
33
  import { type Problem, refuseIfAny } from './errors.ts';
34
34
  import type { Raster } from './raster/index.ts';
35
35
  import { pyRound } from './round.ts';
@@ -1480,6 +1480,16 @@ export interface Depth25DTurnOptions {
1480
1480
  stills: Readonly<Record<string, { row: number; bone: string }>>;
1481
1481
  boneLandmarks: ReadonlyMap<string, readonly [number, number]>;
1482
1482
  hasAlternateFaceSet: boolean;
1483
+ /** Existing weighted attachments; offsets are emitted per binding, never per UV. */
1484
+ surfaceMeshes?: ReadonlyArray<{
1485
+ part: string;
1486
+ slot: string;
1487
+ attachment: string;
1488
+ weights: ReadonlyArray<ReadonlyArray<{ bone: string; x: number; y: number; weight: number }>>;
1489
+ canvas: readonly [number, number];
1490
+ /** Every attachment of a part containing a blended mesh carries its own group mask. */
1491
+ groups?: ReadonlyMap<string, 'head' | 'body'>;
1492
+ }>;
1483
1493
  }
1484
1494
 
1485
1495
  interface Depth25DGroupSpec {
@@ -1752,6 +1762,7 @@ function buildDepth25DTurnGroup(
1752
1762
  });
1753
1763
  }
1754
1764
  for (const [part, { zRef }] of surfaceSheets) {
1765
+ if (opts.surfaceMeshes?.some((m) => m.part === part)) continue;
1755
1766
  const surfShift = pyRound(-zRef, 4);
1756
1767
  if (surfShift !== 0) {
1757
1768
  tracks.push({
@@ -1800,7 +1811,63 @@ function buildDepth25DTurnGroup(
1800
1811
  };
1801
1812
  }>;
1802
1813
  }> = [];
1803
- for (const part of surfaceSheets.keys()) {
1814
+ for (const [part, { rec, ext, zRef }] of surfaceSheets) {
1815
+ const authored = opts.surfaceMeshes?.filter((m) => m.part === part) ?? [];
1816
+ if (authored.length > 0) {
1817
+ const world = computeWorldTransforms(rig.bones);
1818
+ for (const mesh of authored) {
1819
+ // An all-zero timeline can overwrite another slider's deform (Core A40).
1820
+ // A sibling with no positive binding in this group owns no timeline here.
1821
+ const active = mesh.groups === undefined || [...mesh.groups.values()].includes(group.fieldPrefix === 'config.turn' ? 'head' : 'body');
1822
+ const vertices = mesh.weights.map((row, index) => {
1823
+ let wx = 0, wy = 0, total = 0;
1824
+ for (const w of row) {
1825
+ const frame = world.get(w.bone);
1826
+ if (frame === undefined) {
1827
+ problems.push({ code: 'RIG_TURN_SURFACE_MESH_BINDINGS', object: `surface mesh "${mesh.slot}/${mesh.attachment}" vertex ${index}`, detail: `names missing bone "${w.bone}"; every influence must resolve in the final setup` });
1828
+ continue;
1829
+ }
1830
+ // A unit/rear mesh sharing this root would move our bindings too.
1831
+ let ancestor = rig.bones.find((b) => b.name === w.bone);
1832
+ while (ancestor !== undefined) {
1833
+ if ([FACESHIFT_BONE, REAR_SHIFT_BONE, BODYSHIFT_BONE, BODY_REAR_SHIFT_BONE].includes(ancestor.name)) {
1834
+ problems.push({ code: 'RIG_TURN_SURFACE_MESH_BINDINGS', object: `${group.fieldPrefix}.roles.${part}`, detail: `binds "${w.bone}" through turn carrier "${ancestor.name}" shared with another role; surface mesh bindings must retain their authored frame` });
1835
+ break;
1836
+ }
1837
+ ancestor = rig.bones.find((b) => b.name === ancestor?.parent);
1838
+ }
1839
+ const [x, y] = toWorld(frame, w.x, w.y);
1840
+ wx += x * w.weight; wy += y * w.weight; total += w.weight;
1841
+ }
1842
+ if (!Number.isFinite(total) || Math.abs(total - 1) > 0.0001) {
1843
+ problems.push({ code: 'RIG_TURN_SURFACE_MESH_BINDINGS', object: `surface mesh "${mesh.slot}/${mesh.attachment}" vertex ${index}`, detail: `has influence sum ${total}; weights closing at 1 are required to sample a setup position` });
1844
+ }
1845
+ const [cx, cy] = setupToPaintingPoint([wx, wy], mesh.canvas, mesh.canvas);
1846
+ const z = levelToDepthZ(sampleDepthFloat(ext, cx - rec.x, cy - rec.y), rec.depth);
1847
+ return { row, depth: pivot + z - zRef };
1848
+ });
1849
+ if (problems.length > startProblems || !active) continue;
1850
+ deform.push({
1851
+ slot: mesh.slot,
1852
+ attachment: mesh.attachment,
1853
+ keys: keyList.map(({ t, deg }) => deg === 0 ? { t } : {
1854
+ t,
1855
+ // Spine's weighted deform is one bind-space pair per influence.
1856
+ // Do not multiply by weight: the runtime performs that sum once.
1857
+ vertices: vertices.flatMap(({ row, depth }) => {
1858
+ const d = -depth * Math.sin(deg * Math.PI / 180);
1859
+ return row.flatMap((w) => {
1860
+ if (mesh.groups !== undefined && (w.weight === 0 || mesh.groups.get(w.bone) !== (group.fieldPrefix === 'config.turn' ? 'head' : 'body'))) return [0, 0];
1861
+ const frame = world.get(w.bone)!; // every influence resolved before emitting keys
1862
+ const [x, y] = toBoneLocalVector(frame, kind === 'yaw' ? d : 0, kind === 'pitch' ? d : 0);
1863
+ return [pyRound(x, 6), pyRound(y, 6)];
1864
+ });
1865
+ }),
1866
+ }),
1867
+ });
1868
+ }
1869
+ continue;
1870
+ }
1804
1871
  deform.push({
1805
1872
  slot: part,
1806
1873
  attachment: part,
@@ -1894,6 +1961,60 @@ export function buildDepth25DTurn(
1894
1961
  const problems: Problem[] = [];
1895
1962
  const { yaw: yawMax, pitch: pitchMax } = resolveTurnBands(opts.turn);
1896
1963
 
1964
+ // Only a surface opt-in spanning both authored subtrees changes paths (#796).
1965
+ // Single-group meshes keep #795's role and bytes, including explicit islands.
1966
+ const parents = new Map(rig.bones.map((b) => [b.name, b.parent]));
1967
+ const bodyRoot = opts.turn.body?.bone ?? (parents.has('chest') ? 'chest' : 'hip');
1968
+ const descends = (bone: string, root: string): boolean => {
1969
+ const seen = new Set<string>();
1970
+ for (let cur: string | undefined = bone; cur !== undefined && !seen.has(cur); cur = parents.get(cur)) {
1971
+ if (cur === root) return true;
1972
+ seen.add(cur);
1973
+ }
1974
+ return false;
1975
+ };
1976
+ const blended = new Set<string>();
1977
+ const classified = opts.surfaceMeshes?.map((mesh) => {
1978
+ const groups = new Map<string, 'head' | 'body'>();
1979
+ const outside = new Set<string>();
1980
+ for (const w of mesh.weights.flat()) {
1981
+ if (w.weight <= 0) continue;
1982
+ if (descends(w.bone, 'head')) groups.set(w.bone, 'head');
1983
+ else if (descends(w.bone, bodyRoot)) groups.set(w.bone, 'body');
1984
+ else outside.add(w.bone);
1985
+ }
1986
+ if (new Set(groups.values()).size === 2) blended.add(mesh.part);
1987
+ return { mesh, groups, outside };
1988
+ });
1989
+ // A part's role covers every island, but each attachment keeps its own mask.
1990
+ // Without a blended attachment the explicit role still owns the legacy path.
1991
+ const surfaceMeshes = classified?.map(({ mesh, groups, outside }) => {
1992
+ if (!blended.has(mesh.part)) return mesh;
1993
+ if (opts.turn.roles === undefined || opts.turn.body === undefined || outside.size > 0 || descends(bodyRoot, 'head')) {
1994
+ problems.push({
1995
+ code: 'RIG_TURN_SURFACE_MESH_GROUPS', object: `surface mesh "${mesh.slot}/${mesh.attachment}"`,
1996
+ detail: `belongs to a part with blended head and body bindings${outside.size === 0 ? '' : ` with ungrouped bone(s) ${[...outside].map(b => `"${b}"`).join(', ')}`}; declare both config.turn.roles and config.turn.body with a body root outside head, and bind every influence to one of those subtrees`,
1997
+ });
1998
+ return mesh;
1999
+ }
2000
+ // A second declaration cannot ask the same attachment to be both a sampled
2001
+ // surface and a unit/rear carrier. No binding is reparented here.
2002
+ const roles = [opts.turn.roles[mesh.part], opts.turn.body.roles[mesh.part]];
2003
+ if (roles.some(role => role !== undefined && role !== 'surface')) {
2004
+ problems.push({ code: 'RIG_TURN_SURFACE_MESH_GROUPS', object: `surface mesh "${mesh.slot}/${mesh.attachment}"`, detail: 'declares a unit/rear role as well as surface across the head and body groups; declare surface in one or both groups so its authored frames are retained' });
2005
+ return mesh;
2006
+ }
2007
+ return { ...mesh, groups };
2008
+ });
2009
+ refuseIfAny(problems);
2010
+ if (blended.size > 0) {
2011
+ const surfaceRoles = Object.fromEntries([...blended].map(part => [part, 'surface' as const]));
2012
+ opts = { ...opts, surfaceMeshes, turn: { ...opts.turn,
2013
+ roles: { ...opts.turn.roles, ...surfaceRoles },
2014
+ body: { ...opts.turn.body!, roles: { ...opts.turn.body!.roles, ...surfaceRoles } },
2015
+ } };
2016
+ }
2017
+
1897
2018
  if (opts.turn.roles !== undefined) {
1898
2019
  buildDepth25DTurnGroup(
1899
2020
  rig,