@rig-c/parts 1.35.0 → 1.36.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/docs/AUTHORING.md CHANGED
@@ -108,7 +108,7 @@ read by no CPU stage).
108
108
  | `assemble.extend_below_crop` | assemble | **proposed** with the plan: `{part, run, tag}` — a head-run part that reaches the bottom of the head crop is continued from a full-run layer, whole connected components |
109
109
  | `assemble.patches` | assemble; `meshes`/`regions` keys may name them too | **authored**, optional: `[{name, box, alpha, draw}]` — an extra part cut from the **painting** itself, for figure no See-through layer holds (a hem both runs dropped). `box` is `[x0, y0, x1, y1]` in **rig** pixels, `x1`/`y1` exclusive — the space of `parts.json` and `recomposite_rig.png`, where the hole is found; `alpha` is `"silhouette"` (the painting's figure silhouette inside the box, the one `--seam silhouette` uses) or `"box"` (the whole box); `draw` is `"back"`, `"front"` or `{"before": "<plan part>"}`. A patch is always a region: its bone is `regions.<name>`, in the one place every region's bone lives, and a `meshes` entry for it is refused. See §5 for how to place one |
110
110
  | `assemble.cuts` | assemble; `meshes`/`regions` keys may name the new parts too, and must (each is a part like any other) | **authored**, optional (issue #170): `[{from, into, polygon, draw, overlap, under, under_fill}]`, `under` and `under_fill` optional — a plan part's layer cut by a polygon the author draws: the pixels of plan part `from` whose **centre** lies inside `polygon` (even-odd; a centre exactly on an edge is outside) leave `from` and make the new part `into`, colour and alpha, so every pixel of the layer ends in exactly one of the two. `polygon` is `[[x, y], …]`, at least three points, non-negative integer **rig** pixels — the space of `parts.json` and of the patches' boxes. The file that shows the layer in those coordinates is `assemble`'s own `rig/parts/<from>.png`, placed at its `parts.json` `x`, `y` (the PNG's pixel `(i, j)` is rig pixel `(x + i, y + j)`), or `render/recomposite_rig.png`, the whole rig 1:1; the contact sheets (`sheet`) are scaled and carry no coordinates. `draw` is `"back"`, `"front"` or `{"before": "<plan part>"}`, as for a patch (to keep the setup pose, draw the piece immediately in front of `from` — `{"before": "<the plan part after from>"}`, or `"front"` when `from` is the last plan part; `{"before": "<from>"}` draws it behind `from`, which `under` refuses as `ASSEMBLE_UNDER_DRAW` because the fill would hide it). `from` must be a plan part (`CONFIG_NAME_RESOLVES`; a patch or another cut's piece is refused), `into` a new name (`CONFIG_PART_UNIQUE`), the polygon three or more integer points (`CONFIG_FIELD_TYPE`). The piece's `parts.json` record carries `from`'s `<run>:<tag>` and its own counts, each split from the layer's by where the pixel lies; it is a mesh or a region under its own name, and the coverage rule holds it like a plan part. What the config cannot know the stage refuses: a polygon point past the rig (`ASSEMBLE_CUT_INSIDE`), two cuts of one part sharing a pixel (`ASSEMBLE_CUT_OVERLAP`), a cut that takes none of the layer's opaque pixels or leaves `from` none (`ASSEMBLE_CUT_PIXELS`). `overlap` is required, a non-negative integer of rig pixels with no default (`CONFIG_FIELD_TYPE`): the **band** — the polygon's pixels within `overlap` px of its edge by Chebyshev distance (the polygon's mask less its erosion by a `2 * overlap + 1` square) — stays in `from` as well as going to the piece, so the piece's resampled edge has art under it; the counts stay a strict partition and the band is the base's extra copy, printed on the `cut:` line. At `0` the two abut and `check`'s seam bar judges the edge between them (`CHECK_SEAM_WITHIN_BAR`, §5). A band only covers the edge at rest: a piece that swings well clear of where it was painted shows the hole it leaves, and a thin piece's band shows a ghost of the piece. `under` (issue #193), optional, is the author's image of what lies under the piece: a PNG path relative to the config's directory (`CONFIG_FIELD_TYPE` unless a non-empty string), in rig pixels over the polygon's **bounding box** — the least and greatest polygon x and y, so the image is `max x − min x` by `max y − min y` and its pixel `(i, j)` is rig pixel `(min x + i, min y + j)`. Where the cut removed pixels from `from` — the piece's pixels (alpha above 0) less the band — `from` takes the image's pixel, colour and alpha wherever the image's alpha is at least the alpha the cut removed there (**filled**); elsewhere `from` stays empty there (**left empty**): a transparent pixel is the author's statement that nothing lies under it (the background, or a part drawn behind), and a less opaque one is not half-filled. The image is read nowhere else, so its pixels over the band, over the box outside the polygon or where the layer had no art never change `from`. The `cut:` line then ends `; under <n> px filled, <m> px left empty` (`n + m` is every removed pixel), so an unintended hole is a number in the log, not a guess; the filled pixels count in `from`'s `opaque_px` and `occluded_px` (the piece is drawn over them), never as visible or projected. The stage refuses: a file that is not there (`ASSEMBLE_UNDER_PRESENT`) or not a PNG (`ASSEMBLE_UNDER_DECODES`), an image not exactly the box's size (`ASSEMBLE_UNDER_SIZE`, both sizes given), an image that fills none of the removed pixels — all transparent there, or another file (`ASSEMBLE_UNDER_EMPTY`; to leave the whole hole, drop `under`), and a piece drawn behind `from` (`ASSEMBLE_UNDER_DRAW`: the fill would hide it; draw it `"front"` or `{"before": "<the plan part after from>"}`). Producing the image is the author's, by whatever means; absent, `from` keeps only its band. `under_fill` (issue #360), optional, is the one value `"colour"` (`CONFIG_FIELD_TYPE` on any other): the same pixels are filled and left empty, and a filled pixel takes the image's **colour** at the alpha the cut removed there instead of the image's alpha, so `from`'s alpha is the uncut layer's wherever the image fills and its silhouette does not grow — an opaque image over a soft edge leaves the edge soft. It applies to the part's hidden-art layer as well as to a file; a cut with neither is refused (`ASSEMBLE_UNDER_FILL_SOURCE`). The `cut:` line's filled count then says how many took the colour only: `; under 190 px filled (190 colour only, at the alpha the cut removed), 0 px left empty`. Absent, a filled pixel takes the image's colour and alpha, as above |
111
- | `assemble.alternates` | assemble, rig, check (`--set`, `--all-sets`) | **authored**, optional (issues #454, #465, #472, #473): `[{name, source?, full?, head?, head_box?, parts?, hides?, cuts?, skeleton?, drawn?}]` — alternate painting sets assembled into `<out>/rig/parts/<set>_<part>.png` (`parts.json` `alternates`), attached on each covered slot in `rig.json` as `<set>_<part>` beside the base attachment, and indexed in `<out>/rig/sets.json` (`rig-parts-sets/1`: `sets.<set>.slots`, `.hides`, `.drawn` when present, and `.threshold: {yaw: 15, pitch: 12}` when the set replaces `face` on a rig with `turn` or `turn`/`tilt` slider animations). `source`, `full` and `head` may instead be given on the CLI with `--alt <name>=<source>:<full>[:<head>]`. `parts` lists the subset of parts the set replaces (default: every part not in `hides`); a **subset set** (issue #473, e.g. mouth visemes `a`, `i`, `u` with `"parts": ["mouth"]`) cuts only its covered parts from the alternate runs (refusing with `ASSEMBLE_ALT_INPUT_PRESENT` if a covered part's layer is missing or empty), writes only `{slot: "<set>_<slot>"}` in `sets.json` so `@rig-c/play`'s `setSet(name)` switches those slots while leaving every other slot on its base attachment (and `setSet(null)` restores the base pose), may be keyed on a slot attachment track in `motion.animations_from` as `{"t": …, "set": "<name>" \| null}` (`CONFIG_SET_COVERS_SLOT` if `"set"` is undeclared or does not cover the track's slot), and under `check --set <name>` counts `ANIMATIONS_DO_NOT_FOLD` only on its own covered slots; `hides` lists slots the set hides (`null` in `sets.json`). `skeleton` (a pose file path relative to the config's directory, `{"width": W, "height": H, "points": {…}}` with all 18 body-18 keypoints on the canvas, validated by the same rules as `generation.control.skeleton`: `CONFIG_FILE_PRESENT`, `CONFIG_IS_JSON`, `CONFIG_FIELD_TYPE`, `CONFIG_KEY_KNOWN`, `CONFIG_KEY_UNIQUE`, `CONFIG_POSE_CANVAS`, `CONFIG_POSE_KEYPOINTS`, `CONFIG_POSE_IN_CANVAS`) or `drawn` (`{<bone>: <worldDegrees>}`, each bone resolved against `bones`, `CONFIG_NAME_RESOLVES`) declares the posed angles the alternate was painted at (issue #465); when `skeleton` is given, `assemble` derives `drawn` from its 18 keypoints (with `drawn` overriding any bone named in both), records both `skeleton` (scaled by `assemble.rig_scale` to rig px) and `drawn` in `parts.json` `alternates`, and the `rig` stage writes `<set>_*` region and mesh attachments in the bone-local frame of `poseRigBonesForDrawn(bones, drawn)` (weighting limb segments directly from `skeleton`'s joint endpoints when `skeleton` is present) and emits `drawn` in `sets.json` so `rig-pose` and `check --set <name>` / `--all-sets` pose the bones at `drawn` without rotating the already-posed art a second time |
111
+ | `assemble.alternates` | assemble, rig, check (`--set`, `--all-sets`) | **authored**, optional (issues #454, #465, #472, #473, #476): `[{name, source?, full?, head?, head_box?, parts?, hides?, cuts?, skeleton?, drawn?}]` — alternate painting sets assembled into `<out>/rig/parts/<set>_<part>.png` (`parts.json` `alternates`), attached on each covered slot in `rig.json` as `<set>_<part>` beside the base attachment, and indexed in `<out>/rig/sets.json` (`rig-parts-sets/1`: `sets.<set>.slots`, `.hides`, `.drawn` when present, and `.threshold: {yaw: 15, pitch: 12}` when the set replaces `face` on a rig with `turn` or `turn`/`tilt` slider animations). `source`, `full` and `head` may instead be given on the CLI with `--alt <name>=<source>:<full>[:<head>]`. `parts` lists the subset of parts the set replaces (default: every part not in `hides`); a **subset set** (issue #473, e.g. mouth visemes `a`, `i`, `u` with `"parts": ["mouth"]`) cuts only its covered parts from the alternate runs (refusing with `ASSEMBLE_ALT_INPUT_PRESENT` if a covered part's layer is missing or empty), writes only `{slot: "<set>_<slot>"}` in `sets.json` so `@rig-c/play`'s `setSet(name)` switches those slots while leaving every other slot on its base attachment (and `setSet(null)` restores the base pose), may be keyed on a slot attachment track in `motion.animations_from` as `{"t": …, "set": "<name>" \| null}` (`CONFIG_SET_COVERS_SLOT` if `"set"` is undeclared or does not cover the track's slot), and under `check --set <name>` counts `ANIMATIONS_DO_NOT_FOLD` only on its own covered slots; `hides` lists slots the set hides (`null` in `sets.json`). A **gesture subset set** (issue #476) covers a limb chain declared in `config.limbs.<limb>` (all of its segment `part`s, cut at the base's joints posed to the set's own `drawn` angles by `poseBoneEntriesForDrawn`; naming the unsplit `from` layer, covering only some segments of the limb, or declaring polygon `cuts` on a limb set is refused with `CONFIG_LIMB_SET_JOINTS`) and carries `drawn` (or `skeleton`) for the covered bones only (giving `drawn` for an uncovered bone is refused with `CONFIG_SET_COVERS_BONE` / `RIG_SET_COVERS_BONE`; uncovered bones keep the base's `drawn`). `skeleton` (a pose file path relative to the config's directory, `{"width": W, "height": H, "points": {…}}` with all 18 body-18 keypoints on the canvas, validated by the same rules as `generation.control.skeleton`: `CONFIG_FILE_PRESENT`, `CONFIG_IS_JSON`, `CONFIG_FIELD_TYPE`, `CONFIG_KEY_KNOWN`, `CONFIG_KEY_UNIQUE`, `CONFIG_POSE_CANVAS`, `CONFIG_POSE_KEYPOINTS`, `CONFIG_POSE_IN_CANVAS`) or `drawn` (`{<bone>: <worldDegrees>}`, each bone resolved against `bones`, `CONFIG_NAME_RESOLVES`) declares the posed angles the alternate was painted at (issue #465); when `skeleton` is given, `assemble` derives `drawn` from its 18 keypoints (filtered to covered bones on a subset set, with `drawn` overriding any bone named in both), records both `skeleton` (scaled by `assemble.rig_scale` to rig px) and `drawn` in `parts.json` `alternates`, and the `rig` stage writes `<set>_*` region and mesh attachments in the bone-local frame of `poseRigBonesForDrawn(bones, drawn)` (weighting limb segments directly from `skeleton`'s joint endpoints when `skeleton` is present) and emits `drawn` in `sets.json` so `rig-pose` and `check --set <name>` / `--all-sets` pose the bones at `drawn` without rotating the already-posed art a second time |
112
112
  | `limbs` | assemble (the cut and the caps), rig (through `regions`), check (`LIMB_ONE_BONE`) | **proposed** by `propose --keypoints` (issue #349), then checked: `{<limb>: {segments: [{part, from, bone}, {part, from, bone, joint, range?, cap?, edge?, cap_shape?, cut_band?}, …]}}`, the upper segment first. The rule is *Limbs: cut at their joints* below the table. `part` is a new part (`CONFIG_PART_NAME`, `CONFIG_PART_UNIQUE` against the plan, patches, cuts and every other limb part); `from` a plan part or a cut's piece (`CONFIG_NAME_RESOLVES`) — the layer the segment's pixels come from, which is cut into the limb parts and is not itself made: a `meshes` or `regions` entry for it is `CONFIG_NAME_RESOLVES`, and the segments of one limb that take one part are consecutive (`CONFIG_LIMB_FROM_RUN`); `bone` a declared bone, each segment's the child of the one before (`CONFIG_LIMB_BONES_CHAIN`); the upper segment names no `joint`, `range`, `cap`, `edge`, `cap_shape` or `cut_band` (`CONFIG_KEY_KNOWN`), every other names its `joint` (`CONFIG_FIELD_PRESENT`) — the joint is its bone's origin; `range` is `[min, max]` degrees from rest with `min <= 0 <= max` (`CONFIG_LIMB_RANGE`), which `assemble` writes into the lower part's `parts.json` record and `check` poses the joint at — its two ends and its middle — reading the seam there (`SEAM_OVER_RANGE`, issue #360; rig-c needs no rotation limit); `cap` a PNG path relative to the config's directory (`CONFIG_FIELD_TYPE`); `edge` `"feather"` and `cap_shape` `"disc"` (issue #360), each the one value its field takes (`CONFIG_FIELD_TYPE` on any other) — the cut's geometry at that joint, *Limbs: cut at their joints* below; absent, the cut is hard and the cap the layer's half-disc of half the limb's width; `cut_band` a whole number of px, 1 or more (`CONFIG_FIELD_TYPE`), on a segment that takes the segment above's part — between two layers nothing is cut, so a band there is `CONFIG_KEY_KNOWN` — places the cut within that many px of the joint line (issue #360, *Limbs: cut at their joints*); absent, the cut is the joint line. Each limb part is attached like any part — `regions.<part>`, which must be the segment's `bone` (`CONFIG_LIMB_BONE`), or a mesh, which `check` holds to that bone alone (`LIMB_ONE_BONE`). With `limbs`, `assemble` reads `bones` too (`CONFIG_FIELD_PRESENT` without it). Absent, nothing is cut at a joint and no byte of any output moves |
113
113
  | `bones` | rig; `propose --from-config` | **proposed** by `propose`, then corrected. A single bone `{name, parent, at, tip?}` or a chain `{chain, parent, points, tip, link_inherit?}` whose links are named `<chain>0 … <chain>n`. Parents come before children. In `rig.json` each link is **turned along its chain** — `rotation` is the direction from its origin to the next link's (the last link's to `tip`) and `length` that distance (issue #73), so a physics constraint added downstream finds a lever; under `--idle-keys ctl` the link's `<link>_ctl` carries the turn and the length and the link sits at local rotation 0 beneath it. A single bone with a `tip` is turned the same way, towards its tip, with that distance as its length (issue #239); a tip on the bone's own origin is refused (`RIG_TIP_DISTINCT`). The five face bones `eye_r`, `eye_l`, `brow_r`, `brow_l` and `mouth` (by name, when one has no tip of its own) are turned to the eye line — the line through the origins of `eye_r` and `eye_l` as `bones` writes them, read image-left to image-right, drawn when parts.json holds both an `eyewhite-r` and an `eyewhite-l` part — so the blink's `scaley` squashes across the eye line on a tilted head; move an eye bone and the line moves with it. With one eyewhite or none, or an eye bone missing, the rig stage's `face axis:` line says so and they keep the page's axes. A bone under a face bone keeps the face's axis. With the line, `rig.json` also declares `invariants.axes` — one entry, `"face"`, through `eye_r` and `eye_l`, holding the turned face bones (and their controls) — so rig-c's gate holds the build to the line; the line is the one rigc draws through the same two bones, so the tolerance is only the float floor — the largest gap the emitted (float32) bones have to it, rounded up to 6 places plus one 6-place unit — and the `face axis:` line prints it. With the line the rig stage also adds `head_up` (issue #250): a slotless bone under `head`, at head's origin, turned to the eye line + 90 degrees and as long as the eye midpoint lies from head's origin along that axis — the head's frame, which a rule that needs it reads; `head` keeps its own frame, so no key on it or under it changes meaning, and a config bone of that name is refused (`RIG_HEAD_UP_NAME_FREE`). A face bone with its own `tip` is held too (issue #258), in a second entry, `"face_tips"`, when its tip lies along the line within whole-pixel rounding — a tip written in whole pixels sits at most sqrt(2)/2 px off the point of the line it stands for, so its direction may sit up to asin((sqrt(2)/2) / length) degrees off — with its tolerance measured the same way; a tip further off is the bone's own axis, and the `face axis:` line names it with its gap and that bound. A failure is rig-c's `A51_BONES_LIE_ALONG_THEIR_DECLARED_AXIS` line, which names the bone and the fix (rig-c's `docs/AUTHORING.md` §3.7 and §5.2); with no line no entry is written and A51 reports SKIP. Every region on a turned bone is turned back, so the setup pose does not move. Any other single bone keeps world rotation 0; one whose parent is a link is turned back upright. A single bone may declare `inherit` (issue #348): what it takes from its parent's transform, one of rig-c's own mode names exactly as rig-c's table spells them — `normal`, `onlyTranslation`, `noRotationOrReflection`, `noScale`, `noScaleOrReflection` (rig-c's `RigBone.inherit`) — written to that bone in `rig.json` as declared; any other spelling, `"NoScale"` included (the runtime would fold its first letter; nothing here folds or maps), is refused (`CONFIG_BONE_INHERIT`), and a chain takes no `inherit` (`CONFIG_KEY_KNOWN`). A chain may instead declare `link_inherit` (issue #369), an object mapping its own expanded link names to those same modes, for example `"link_inherit": {"leg_r1": "noScale"}`. Only the named link changes; omitted links inherit normally. A key outside this chain is `CONFIG_NAME_RESOLVES`, with this chain's valid link names in the detail; a non-object or non-string mode is `CONFIG_FIELD_TYPE`, and another mode spelling is `CONFIG_BONE_INHERIT`. The mode is forwarded to the expanded link, or to its control under `--idle-keys ctl`, by the same rule as a single bone. This is an authored opt-in: `propose` does not add it. Its setup rotation is the turn from where rig-c's own poser puts the bone with no rotation of its own under that mode, so it still stands upright (or along its tip) at the setup pose. Where the idle gives the bone a `<bone>_ctl`, the mode goes on the control: the control is the bone the parent's rotation reaches, and the bone under it inherits normally, so the idle's keys moved onto the control still turn it. A foot that does not take its shin's rotation (`noRotationOrReflection` or `onlyTranslation`) keeps its shoe level while the leg is posed (`FEET_STAY_LEVEL`, §7); which mode is the author's. `noScale` keeps a shin or shoe's shape under a scaled parent but still takes the parent's rotation: a shoe that must also stay level needs a separate rotation constraint, for example a transform constraint from an unrotated bone. This does not change the proposed feet's existing inheritance or `FEET_STAY_LEVEL` default. An automatic mesh weighted through a bone with a mode other than `normal` gets no derived amplitude (its row names the bone) and no residual envelope (rig-c's `SKINNING_RANGE_UNSUPPORTED`). Absent, `rig.json` carries no `inherit` and no byte moves |
114
114
  | `meshes.<part>` | rig | **proposed**, then corrected. Exactly one of `grid` (the lattice: cell size, px — what `propose` writes: by default one spacing for the figure, round(H / 37) rig px with H the height of every part's box together, a part whose tenth of its short side is already coarser keeping that, and under `propose --grid-rule part` the reference's tenth of the part's short side clamped to 5..36, issue #265), `contour` (the outline mode, authored; the next row and "A contour mesh" below) or `auto` (the automatic mode, authored; "An automatic mesh" below) — two, or none, is `CONFIG_MESH_MODE`. In every mode: `r` (added to every distance before weighting: `w = 1/(d + r)²`), `segments` (a chain name, a bone name with a `tip`, or `[bone, [x0,y0], [x1,y1]]`), and, **authored**, optional, `exponent` (issue #161): a number above 0 that replaces the 2 in that rule, `w = 1/(d + r)^exponent` — a larger one hands each vertex more fully to its nearest bone; absent is 2 and changes no byte, a value that is not a number above 0 is `CONFIG_FIELD_TYPE` at `meshes.<part>.exponent`, and a declared one is echoed as `exponent` in the mesh's `mesh_report.json` row; the exponent is the distance rule's, so declared beside `rule: "heat"` it is refused (`CONFIG_FIELD_TYPE` at `meshes.<part>.exponent`). The segment list is the one authored decision about a layer: which bones may pull it. The slot's bone is the first segment's. Optional `rule` (issue #161): `"distance"` — the rule above, and what an absent `rule` means (every byte is the same) — or `"heat"`, bone heat over the part's own silhouette, in every mode: the lattice's art (alpha above 8, less any island a declared `stray` left out) with holes filled, or for `contour` and `auto` the silhouette their outline is traced from (that mode's art — alpha above 8 for `contour`, alpha 1 and above for `auto` — less any island a declared `stray` left out, holes filled, grown by its `margin`); each bound bone's sources are the silhouette pixels whose centre lies within 0.75 px of its segment (a pixel two bones reach goes to the nearer, a tie to the first listed), held at 1 for that bone and 0 for the others; the field is solved by row-major Gauss–Seidel over-relaxation to a sweep change under 1e-7 within 20000 sweeps; a vertex reads the nearest silhouette pixel and takes the same cap and floor (and `regions`) as the distance rule; `r` is not read. The mesh's `mesh_report.json` row gains `heat` (the constants, each bone's sources and sweeps, the residual). Any other value is `CONFIG_FIELD_TYPE`; a bound bone with no source pixel is `RIG_HEAT_BONE_SOURCE`, an island no bone has a source in `RIG_HEAT_ISLAND_SOURCE`, a solve past its sweep bound `RIG_HEAT_CONVERGED` — none is weighted 0. The rule is chosen per mesh, so `RIG_HEAT_BONE_SOURCE` names three remedies: move the segment onto the art, take the bone out of `segments`, or keep this part on the distance rule — the one to take when the bone anchors the part from outside its art (a torso bone under a neck), since the first moves a bone another part placed and the second drops the anchor (issue #303). On a lattice, `RIG_HEAT_ISLAND_SOURCE` on an island that is dust — at most 4 px and at most 0.1 % of the part's art px, `mesh-draft`'s line — names `meshes.<part>.stray` and the figure that leaves it out, with the value declared; an island above that line keeps the segment remedy, a real piece being a real authoring question |
@@ -2681,6 +2681,8 @@ See-through with another seed.
2681
2681
  | <a id="CONFIG_PROPOSED_RIG_SCALE"></a>`CONFIG_PROPOSED_RIG_SCALE` | `proposed_rig_scale` (the `scale_rig_per_source` `propose` drafted the rig sections at, issue #354) differs from `assemble.rig_scale`: the coordinates in `bones`, `meshes`, `limbs` and `motion` are in that rig canvas's pixels and do not scale when `assemble.rig_scale` changes | re-run `assemble` and `propose` at the new `assemble.rig_scale`, or restore `assemble.rig_scale` to `proposed_rig_scale` |
2682
2682
  | <a id="CONFIG_BUST_CLEARANCE"></a>`CONFIG_BUST_CLEARANCE` | `meshes.<part>.contour.bust` (issue #475): `clearance <= 0`, `R_r + R_l >= \|apex_r − apex_l\|` (the derived outer radii overlap or touch across the apex span `D`, or `cleavage` sits off the segment so `d_r + d_l − 2·clearance >= D`), or a derived `R_s`, `r_s = round(alpha × R_s)` or `band_s = round(R_s) − r_s` is not positive; the detail names `clearance`, `R_r + R_l` and `D` | raise `contour.bust.clearance` so `0 < clearance < d_s` and `R_r + R_l < \|apex_r − apex_l\|`, or place `cleavage` between `apex_r` and `apex_l` |
2683
2683
  | <a id="CONFIG_SET_COVERS_SLOT"></a>`CONFIG_SET_COVERS_SLOT` | `motion.animations_from` (issue #473): a track key carries `"set": "<name>" \| null` on a track other than `property: "attachment"`, names an alternate set not declared in `assemble.alternates`, or names an alternate set that does not cover the track's `slot` (neither in `slots` nor in `hides`); the detail names the set, the slot and the slots that set covers | declare the set in `assemble.alternates`, add the slot to that set's `parts` (or `hides`), or key `"set"` on a slot the set covers |
2684
+ | <a id="CONFIG_SET_COVERS_BONE"></a>`CONFIG_SET_COVERS_BONE` | `assemble.alternates[i].drawn.<bone>` (issue #476): a subset set (`parts` present) states a `drawn` world angle for a bone none of its covered parts ride; the detail names the bone, the set, and the bones its covered parts ride | remove the uncovered bone from that set's `drawn`, or add the part that rides it to `parts` |
2685
+ | <a id="CONFIG_LIMB_SET_JOINTS"></a>`CONFIG_LIMB_SET_JOINTS` | `assemble.alternates[i]` (issue #476): a gesture set over a limb chain declared in `config.limbs.<limb>` names the unsplit `from` layer instead of the limb's segment `part`s, covers (or hides) only a subset of the limb chain's segments, or declares custom polygon `cuts` on the limb; the detail names the limb and its segment parts | cover all segment `part`s of `config.limbs.<limb>` in `parts` with no custom `cuts`, so `assemble` cuts the set at the base's joints |
2684
2686
 
2685
2687
  ### inputs
2686
2688
 
@@ -2808,6 +2810,7 @@ says why each requirement exists and what breaks without it.
2808
2810
  | <a id="RIG_BLINK_INSIDE_IDLE"></a>`RIG_BLINK_INSIDE_IDLE` | the blink runs outside the idle | `motion.blink.t` |
2809
2811
  | <a id="RIG_BLINK_HOLD_SPANS_A_FRAME"></a>`RIG_BLINK_HOLD_SPANS_A_FRAME` | the tree's `BLINK.hold` is shorter than one frame at `IDLE_FPS`, so for some `motion.blink.t` no idle frame — and no frame of the loop — shows the closed eye; the detail counts the phases that miss and names the first | nothing in the config: `BLINK.hold` in `src/motion.ts`, at least `1/IDLE_FPS` s (§3) |
2810
2812
  | <a id="RIG_STILL_ROW_INSIDE_PART"></a><a id="RIG_STILL_ROW_CLEAR"></a><a id="RIG_STILL_PIECES_HAVE_ART"></a><a id="RIG_STILL_NAME_FREE"></a>`RIG_STILL_ROW_INSIDE_PART`, `RIG_STILL_ROW_CLEAR`, `RIG_STILL_PIECES_HAVE_ART`, `RIG_STILL_NAME_FREE` | a `motion.blink.still` row that is not strictly inside the part, that crosses art (a cut through art changes the render even at rest), that leaves one piece with no art, or whose `<part>_still` slot name another part already has | that entry's `row` — a row with no art between the crease and the lash line — or rename the other part |
2813
+ | <a id="RIG_SET_COVERS_BONE"></a>`RIG_SET_COVERS_BONE` | `assemble.alternates[i].drawn.<bone>` (issue #476): a subset set in `parts.json` `alternates` (`parts` present) states a `drawn` world angle for a bone none of its covered slots ride; the detail names the bone, the set, and the covered bones | remove the uncovered bone from that set's `drawn`, or add the part that rides it to `parts` |
2811
2814
  | <a id="RIG_RIGC_GREEN"></a>`RIG_RIGC_GREEN` | rig-c refused the rig; its own FAIL or compile-error line is quoted, and nothing was written. A `constraints` field rigc does not read, or a value it refuses, is this line in rigc's words (`constraint "aim" (ik) has a key this compiler does not read: "mixx" (did you mean "mix"?)`), as is `A25_DETACHED_BONE_PARENTAGE` on a declared scene target. So is an ik whose `bones` are more than two, or two of which the second is not the first's child: from rig-c 2.15.0 its rig-spec parser refuses both by name (`ik constraint "reach" names 3 bones …`, `ik constraint "reach": "hem1" is not a child of "body" ("hem0" stands between) …`; firejune/rigc#1205), and this package no longer refuses them itself (issue #103; it did from #92 while rigc's gate passed them). Under `--idle-keys ctl` a two-bone ik over a chain link and its child link is that second refusal too, because the child's `<link>_ctl` stands between them; rigc's remedy names the control, which a config cannot, so when rigc's line says that control alone stands between, the rig stage adds a sentence naming `--idle-keys direct` on the command that ran | the field rigc's line names; for the split pair, `rig --idle-keys direct` or `build --idle-keys direct`, as the line says, which keys the link in place — rig-c's own AUTHORING §5 maps each of its assertions (`node_modules/rig-c/docs/AUTHORING.md`) |
2812
2815
 
2813
2816
  ### mesh-draft
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rig-c/parts",
3
- "version": "1.35.0",
3
+ "version": "1.36.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/build.ts CHANGED
@@ -78,6 +78,7 @@ import { encodeGif } from './gif.ts';
78
78
  import { CONTROL_SUFFIX, withAnimations } from './motion.ts';
79
79
  import type { PaletteError } from './palette.ts';
80
80
  import { type LayerSet, readLayers } from './layers.ts';
81
+ import { poseBoneEntriesForDrawn } from './limbs.ts';
81
82
  import { type AlternatePartsRecord, type PartRecord, readParts, type RecompositeRecord, type SingleRunPad, tagOf, writeParts } from './parts.ts';
82
83
  import { encodePngBytes, readPng, writePng } from './raster/png.ts';
83
84
  import type { Raster } from './raster/types.ts';
@@ -444,24 +445,68 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
444
445
  const altCuts: Cut[] = rawCuts.map((c) => ({ ...c, draw: remapDraw(c.draw) }));
445
446
  const altUnder = alt.cuts !== undefined ? readUnders(input.config, altCuts) : altCuts.map(() => null);
446
447
  const altHeadBox = alt.head_box ?? (altRuns.single ? singleRunHeadBox(altSrc.width, altSrc.height, fields.resolution) : fields.headBox);
447
- const altRes = assemble({
448
- source: altSrc,
449
- full: altRuns.full,
450
- head: altRuns.head,
451
- resolution: fields.resolution,
452
- headBox: altHeadBox,
453
- rigScale: fields.rigScale,
454
- plan: altPlan,
455
- extend: altExtend,
456
- patches: altPatches,
457
- cuts: altCuts,
458
- under: altUnder,
459
- ...(Object.keys(altLimbs).length > 0 ? { limbs: altLimbs, bones: fields.bones } : {}),
460
- ...(fields.scene === undefined ? {} : { scene: fields.scene }),
461
- ...(fields.armSplit !== undefined && altPlan.some((e) => e[1] === 'full' && (e[2] === 'handwear-r' || e[2] === 'handwear-l')) ? { armSplit: fields.armSplit } : {}),
462
- seamRule: input.seam,
463
- projectRule: input.project,
464
- });
448
+ let altBones = fields.bones;
449
+ if (Object.keys(altLimbs).length > 0 && fields.bones !== undefined && (altSkeleton !== undefined || alt.drawn !== undefined)) {
450
+ const coveredLimbBones = new Set(Object.values(altLimbs).flatMap((l) => l.segments.map((sg) => sg.bone)));
451
+ const limbDrawn: Record<string, number> = {};
452
+ if (altSkeleton !== undefined) {
453
+ const deg = (a: readonly [number, number], b: readonly [number, number]): number =>
454
+ (Math.atan2(-(b[1] - a[1]), b[0] - a[0]) * 180) / Math.PI;
455
+ const skPairs: ReadonlyArray<readonly [string, readonly [number, number], readonly [number, number]]> = [
456
+ ['sleeve_r0', altSkeleton.r_shoulder, altSkeleton.r_elbow],
457
+ ['sleeve_r1', altSkeleton.r_elbow, altSkeleton.r_wrist],
458
+ ['arm_r0', altSkeleton.r_shoulder, altSkeleton.r_elbow],
459
+ ['arm_r1', altSkeleton.r_elbow, altSkeleton.r_wrist],
460
+ ['sleeve_l0', altSkeleton.l_shoulder, altSkeleton.l_elbow],
461
+ ['sleeve_l1', altSkeleton.l_elbow, altSkeleton.l_wrist],
462
+ ['arm_l0', altSkeleton.l_shoulder, altSkeleton.l_elbow],
463
+ ['arm_l1', altSkeleton.l_elbow, altSkeleton.l_wrist],
464
+ ['leg_r0', altSkeleton.r_hip, altSkeleton.r_knee],
465
+ ['leg_r1', altSkeleton.r_knee, altSkeleton.r_ankle],
466
+ ['leg_l0', altSkeleton.l_hip, altSkeleton.l_knee],
467
+ ['leg_l1', altSkeleton.l_knee, altSkeleton.l_ankle],
468
+ ];
469
+ for (const [bName, a, b] of skPairs) {
470
+ if (alt.parts === undefined || coveredLimbBones.has(bName)) limbDrawn[bName] = deg(a, b);
471
+ }
472
+ }
473
+ if (alt.drawn !== undefined) {
474
+ for (const [bName, degVal] of Object.entries(alt.drawn)) limbDrawn[bName] = degVal;
475
+ }
476
+ altBones = poseBoneEntriesForDrawn(fields.bones, limbDrawn);
477
+ }
478
+ let altRes: ReturnType<typeof assemble>;
479
+ try {
480
+ altRes = assemble({
481
+ source: altSrc,
482
+ full: altRuns.full,
483
+ head: altRuns.head,
484
+ resolution: fields.resolution,
485
+ headBox: altHeadBox,
486
+ rigScale: fields.rigScale,
487
+ plan: altPlan,
488
+ extend: altExtend,
489
+ patches: altPatches,
490
+ cuts: altCuts,
491
+ under: altUnder,
492
+ ...(Object.keys(altLimbs).length > 0 ? { limbs: altLimbs, bones: altBones } : {}),
493
+ ...(fields.scene === undefined ? {} : { scene: fields.scene }),
494
+ ...(fields.armSplit !== undefined && altPlan.some((e) => e[1] === 'full' && (e[2] === 'handwear-r' || e[2] === 'handwear-l')) ? { armSplit: fields.armSplit } : {}),
495
+ seamRule: input.seam,
496
+ projectRule: input.project,
497
+ });
498
+ } catch (err) {
499
+ if (err instanceof PartsError) {
500
+ for (const p of err.problems) {
501
+ altProblems.push({
502
+ ...p,
503
+ object: `${p.object} (alternate set "${alt.name}")`,
504
+ });
505
+ }
506
+ continue;
507
+ }
508
+ throw err;
509
+ }
465
510
  const keptImages = altRes.images
466
511
  .filter(({ record }) => coveredSet.has(record.name))
467
512
  .map(({ record, image }) => ({ name: `${alt.name}_${record.name}`, image }));
package/src/config.ts CHANGED
@@ -1210,13 +1210,14 @@ function parseEarlyConfigFrom(raw: Json, door: EarlyDoor, base: string | null):
1210
1210
  if ('scene' in t) checkScene(c, t.scene);
1211
1211
  // Issue #349: the limbs' joints are their bones' origins, so the bones are read with them, and only then.
1212
1212
  let limbs: LimbNames | null = null;
1213
+ let names: { bones: Set<string>; chains: Map<string, number>; parents: Map<string, string> } | null = null;
1213
1214
  if ('limbs' in t) {
1214
1215
  if (!('bones' in t)) c.fail('CONFIG_FIELD_PRESENT', 'config.bones', 'is absent; config.limbs names bones, and each joint is its bone\'s origin, so assemble reads the bones with the limbs');
1215
- const names = 'bones' in t ? checkBones(c, t.bones) : null;
1216
+ names = 'bones' in t ? checkBones(c, t.bones) : null;
1216
1217
  limbs = checkLimbs(c, t.limbs, made, names);
1217
1218
  }
1218
1219
  if (isPlainObject(t.assemble) && 'alternates' in t.assemble) {
1219
- checkAlternates(c, t.assemble.alternates, made, limbs, null);
1220
+ checkAlternates(c, t.assemble.alternates, made, limbs, names?.bones ?? null, names?.chains ?? null, t.regions, t.meshes);
1220
1221
  }
1221
1222
  }
1222
1223
  if ('cloth' in t) checkCloth(c, t.cloth);
@@ -1368,7 +1369,7 @@ function parseConfigFrom(raw: Json, base: string | null): { config: CharacterCon
1368
1369
  const names = 'bones' in t ? checkBones(c, t.bones) : { bones: new Set<string>([ROOT_BONE]), chains: new Map<string, number>(), parents: new Map<string, string>() };
1369
1370
  const limbs = 'limbs' in t ? checkLimbs(c, t.limbs, { parts, patches, cuts }, 'bones' in t ? names : null) : null;
1370
1371
  if (isPlainObject(t.assemble) && 'alternates' in t.assemble) {
1371
- checkAlternates(c, t.assemble.alternates, { parts, patches, cuts }, limbs, names.bones);
1372
+ checkAlternates(c, t.assemble.alternates, { parts, patches, cuts }, limbs, names.bones, names.chains, t.regions, t.meshes);
1372
1373
  }
1373
1374
  if ('meshes' in t) checkMeshes(c, t.meshes, names.bones, names.chains);
1374
1375
  if ('regions' in t) checkRegions(c, t.regions, names.bones);
@@ -1902,10 +1903,18 @@ function checkAlternates(
1902
1903
  made: { parts: string[]; patches: string[]; cuts: string[] },
1903
1904
  limbs: LimbNames | null,
1904
1905
  bones: Set<string> | null = null,
1906
+ chains: Map<string, number> | null = null,
1907
+ regions: Json = undefined,
1908
+ meshes: Json = undefined,
1905
1909
  ): void {
1906
1910
  const p = 'config.assemble.alternates';
1907
1911
  if (!c.array(p, v, true)) return;
1908
- const allSlots = new Set<string>([...made.parts, ...made.patches, ...made.cuts, ...(limbs?.parts.keys() ?? [])]);
1912
+ const allSlots = new Set<string>([
1913
+ ...made.parts.filter((n) => !(limbs?.consumed.has(n) ?? false)),
1914
+ ...made.patches,
1915
+ ...made.cuts,
1916
+ ...(limbs?.parts.keys() ?? []),
1917
+ ]);
1909
1918
  const seenNames = new Map<string, number>();
1910
1919
  (v as Json[]).forEach((entry, i) => {
1911
1920
  const at = `${p}[${i}]`;
@@ -1934,29 +1943,135 @@ function checkAlternates(
1934
1943
  }
1935
1944
  if ('head_box' in e) checkHeadBox(c, `${at}.head_box`, e.head_box);
1936
1945
  const altCuts = 'cuts' in e ? checkCuts(c, e.cuts, made.parts, [], `${at}.cuts`) : [];
1946
+ let cutsConsumedLimb = false;
1947
+ if (limbs !== null && 'cuts' in e && Array.isArray(e.cuts)) {
1948
+ e.cuts.forEach((ce, ci) => {
1949
+ if (!isPlainObject(ce) || typeof ce.from !== 'string') return;
1950
+ const byLimb = limbs.consumed.get(ce.from);
1951
+ if (byLimb !== undefined) {
1952
+ cutsConsumedLimb = true;
1953
+ const segList = (limbs.chains.get(byLimb)?.parts ?? []).map((s) => `"${s}"`).join(', ');
1954
+ c.fail(
1955
+ 'CONFIG_LIMB_SET_JOINTS',
1956
+ `${at}.cuts[${ci}].from`,
1957
+ `cuts "${ce.from}", which config.limbs.${byLimb} cuts at the base's joints into ${segList}; a gesture set over a limb chain is cut at the base's joints and may not declare its own polygon cuts for that layer`,
1958
+ );
1959
+ }
1960
+ });
1961
+ }
1937
1962
  const validParts = new Set<string>([...allSlots, ...altCuts]);
1963
+ const seenParts = new Set<string>();
1938
1964
  if ('parts' in e && c.array(`${at}.parts`, e.parts, true)) {
1939
- const seen = new Set<string>();
1940
1965
  (e.parts as Json[]).forEach((pn, k) => {
1941
1966
  if (!c.string(`${at}.parts[${k}]`, pn)) return;
1942
- if (!validParts.has(pn)) {
1967
+ const byLimb = limbs?.consumed.get(pn);
1968
+ if (byLimb !== undefined) {
1969
+ const segList = (limbs?.chains.get(byLimb)?.parts ?? []).map((s) => `"${s}"`).join(', ');
1970
+ c.fail(
1971
+ 'CONFIG_LIMB_SET_JOINTS',
1972
+ `${at}.parts[${k}]`,
1973
+ `names "${pn}", which config.limbs.${byLimb} cuts at the base's joints into ${segList}; a gesture set covers the limb chain's segment parts at the base's joints, not the unsplit layer`,
1974
+ );
1975
+ } else if (!validParts.has(pn)) {
1943
1976
  c.fail('CONFIG_NAME_RESOLVES', `${at}.parts[${k}]`, `is ${show(pn)}; a slot of the base rig (or a part made by this alternate's cuts) is required`);
1944
- } else if (seen.has(pn)) {
1977
+ } else if (seenParts.has(pn)) {
1945
1978
  c.fail('CONFIG_PART_UNIQUE', `${at}.parts[${k}]`, `repeats "${pn}"; each covered part is named once`);
1946
- } else seen.add(pn);
1979
+ } else seenParts.add(pn);
1947
1980
  });
1948
1981
  }
1982
+ const seenHides = new Set<string>();
1949
1983
  if ('hides' in e && c.array(`${at}.hides`, e.hides, false)) {
1950
- const seen = new Set<string>();
1951
1984
  (e.hides as Json[]).forEach((hn, k) => {
1952
1985
  if (!c.string(`${at}.hides[${k}]`, hn)) return;
1953
- if (!allSlots.has(hn)) {
1986
+ const byLimb = limbs?.consumed.get(hn);
1987
+ if (byLimb !== undefined) {
1988
+ const segList = (limbs?.chains.get(byLimb)?.parts ?? []).map((s) => `"${s}"`).join(', ');
1989
+ c.fail(
1990
+ 'CONFIG_LIMB_SET_JOINTS',
1991
+ `${at}.hides[${k}]`,
1992
+ `names "${hn}", which config.limbs.${byLimb} cuts at the base's joints into ${segList}; a gesture set covers the limb chain's segment parts at the base's joints, not the unsplit layer`,
1993
+ );
1994
+ } else if (!allSlots.has(hn)) {
1954
1995
  c.fail('CONFIG_NAME_RESOLVES', `${at}.hides[${k}]`, `is ${show(hn)}; a slot of the base rig is required`);
1955
- } else if (seen.has(hn)) {
1996
+ } else if (seenHides.has(hn)) {
1956
1997
  c.fail('CONFIG_PART_UNIQUE', `${at}.hides[${k}]`, `repeats "${hn}"; each hidden slot is named once`);
1957
- } else seen.add(hn);
1998
+ } else seenHides.add(hn);
1958
1999
  });
1959
2000
  }
2001
+ if ('parts' in e && limbs !== null) {
2002
+ for (const [limbName, chain] of limbs.chains) {
2003
+ const coveredSegs = chain.parts.filter((sp) => seenParts.has(sp) && !seenHides.has(sp));
2004
+ const hiddenSegs = chain.parts.filter((sp) => seenHides.has(sp));
2005
+ if ((coveredSegs.length > 0 || hiddenSegs.length > 0) && coveredSegs.length !== chain.parts.length) {
2006
+ c.fail(
2007
+ 'CONFIG_LIMB_SET_JOINTS',
2008
+ `${at}.parts`,
2009
+ `covers [${coveredSegs.map((s) => `"${s}"`).join(', ')}]${hiddenSegs.length > 0 ? ` (and hides [${hiddenSegs.map((s) => `"${s}"`).join(', ')}])` : ''} of config.limbs.${limbName}, which cuts at the base's joints into [${chain.parts.map((s) => `"${s}"`).join(', ')}]; a gesture set over a limb chain must cover all ${chain.parts.length} of its segment parts so it is cut at the base's joints`,
2010
+ );
2011
+ } else if (coveredSegs.length === chain.parts.length && !cutsConsumedLimb && 'cuts' in e && Array.isArray(e.cuts) && e.cuts.length > 0) {
2012
+ c.fail(
2013
+ 'CONFIG_LIMB_SET_JOINTS',
2014
+ `${at}.cuts`,
2015
+ `declares custom polygon cuts on a gesture set covering config.limbs.${limbName}; a gesture set is cut at the base's joints and declares no cuts of its own`,
2016
+ );
2017
+ }
2018
+ }
2019
+ }
2020
+ if ('parts' in e && 'drawn' in e && isPlainObject(e.drawn)) {
2021
+ const activeParts = [...seenParts].filter((pn) => !seenHides.has(pn));
2022
+ const coveredBones = new Set<string>();
2023
+ let allPartsResolved = activeParts.length > 0;
2024
+ for (const pn of activeParts) {
2025
+ const limbSeg = limbs?.parts.get(pn);
2026
+ if (limbSeg !== undefined) {
2027
+ coveredBones.add(limbSeg.bone);
2028
+ } else if (isPlainObject(regions) && typeof regions[pn] === 'string') {
2029
+ coveredBones.add(regions[pn]);
2030
+ } else if (isPlainObject(meshes) && isPlainObject(meshes[pn])) {
2031
+ const m = meshes[pn] as Record<string, Json>;
2032
+ if (Array.isArray(m.segments)) {
2033
+ for (const s of m.segments) {
2034
+ if (typeof s === 'string') {
2035
+ const links = chains?.get(s);
2036
+ if (links !== undefined) {
2037
+ for (let lk = 0; lk < links; lk++) coveredBones.add(`${s}${lk}`);
2038
+ } else {
2039
+ coveredBones.add(s);
2040
+ }
2041
+ } else if (Array.isArray(s) && typeof s[0] === 'string') {
2042
+ coveredBones.add(s[0]);
2043
+ }
2044
+ }
2045
+ }
2046
+ if (isPlainObject(m.contour)) {
2047
+ if (Array.isArray(m.contour.regions)) {
2048
+ for (const rg of m.contour.regions) if (isPlainObject(rg) && typeof rg.bone === 'string') coveredBones.add(rg.bone);
2049
+ }
2050
+ if (isPlainObject(m.contour.bust)) {
2051
+ coveredBones.add(typeof m.contour.bust.bone_r === 'string' ? m.contour.bust.bone_r : DEFAULT_BUST_BONE_R);
2052
+ coveredBones.add(typeof m.contour.bust.bone_l === 'string' ? m.contour.bust.bone_l : DEFAULT_BUST_BONE_L);
2053
+ }
2054
+ }
2055
+ if (isPlainObject(m.auto) && Array.isArray(m.auto.regions)) {
2056
+ for (const rg of m.auto.regions) if (isPlainObject(rg) && typeof rg.bone === 'string') coveredBones.add(rg.bone);
2057
+ }
2058
+ } else {
2059
+ allPartsResolved = false;
2060
+ }
2061
+ }
2062
+ if (allPartsResolved) {
2063
+ const coveredList = [...coveredBones].map((b) => `"${b}"`).join(', ') || 'none';
2064
+ for (const bName of Object.keys(e.drawn)) {
2065
+ if ((bones === null || bones.has(bName)) && !coveredBones.has(bName)) {
2066
+ c.fail(
2067
+ 'CONFIG_SET_COVERS_BONE',
2068
+ `${at}.drawn.${bName}`,
2069
+ `names "${bName}", which alternate set "${String(e.name ?? '')}" does not cover (covered bones: ${coveredList}); a subset set may state drawn angles only for the bones its covered parts ride`,
2070
+ );
2071
+ }
2072
+ }
2073
+ }
2074
+ }
1960
2075
  });
1961
2076
  }
1962
2077
 
@@ -2593,6 +2708,7 @@ function checkRegions(c: Check, v: Json, bones: Set<string>): void {
2593
2708
  interface LimbNames {
2594
2709
  parts: Map<string, { bone: string; at: string }>;
2595
2710
  consumed: Map<string, string>;
2711
+ chains: Map<string, { parts: string[]; bones: string[]; froms: string[] }>;
2596
2712
  }
2597
2713
 
2598
2714
  /**
@@ -2618,7 +2734,7 @@ interface LimbNames {
2618
2734
  * resolved. Returns the limb parts and the parts the limbs take.
2619
2735
  */
2620
2736
  function checkLimbs(c: Check, v: Json, made: { parts: string[]; patches: string[]; cuts: string[] }, names: { bones: Set<string>; parents: Map<string, string> } | null): LimbNames {
2621
- const out: LimbNames = { parts: new Map(), consumed: new Map() };
2737
+ const out: LimbNames = { parts: new Map(), consumed: new Map(), chains: new Map() };
2622
2738
  if (!isPlainObject(v)) {
2623
2739
  c.fail('CONFIG_FIELD_TYPE', 'config.limbs', `is ${show(v)}; an object of limb name -> {"segments": [...]} is required`);
2624
2740
  return out;
@@ -2663,11 +2779,13 @@ function checkLimbs(c: Check, v: Json, made: { parts: string[]; patches: string[
2663
2779
  continue;
2664
2780
  }
2665
2781
  const segs = o.segments as Json[];
2782
+ const segParts: Array<string | null> = [];
2666
2783
  const froms: Array<string | null> = [];
2667
2784
  const bones: Array<string | null> = [];
2668
2785
  segs.forEach((entry, i) => {
2669
2786
  const sat = `${at}.segments[${i}]`;
2670
2787
  const e = c.object(sat, entry, ['part', 'from', 'bone'], ['joint', 'range', 'cap', 'edge', 'cap_shape', 'cut_band']);
2788
+ segParts.push(null);
2671
2789
  froms.push(null);
2672
2790
  bones.push(null);
2673
2791
  if (e === null) return;
@@ -2683,6 +2801,7 @@ function checkLimbs(c: Check, v: Json, made: { parts: string[]; patches: string[
2683
2801
  } else if (firstAt.has(name)) c.fail('CONFIG_PART_UNIQUE', `${sat}.part`, `names the part "${name}" again (first at ${firstAt.get(name)})`);
2684
2802
  else {
2685
2803
  firstAt.set(name, sat);
2804
+ segParts[i] = name;
2686
2805
  if ('bone' in e && typeof e.bone === 'string') out.parts.set(name, { bone: e.bone, at: `config.limbs.${limb} segment ${i}` });
2687
2806
  }
2688
2807
  }
@@ -2727,6 +2846,11 @@ function checkLimbs(c: Check, v: Json, made: { parts: string[]; patches: string[
2727
2846
  }
2728
2847
  }
2729
2848
  });
2849
+ out.chains.set(limb, {
2850
+ parts: segParts.filter((q): q is string => q !== null),
2851
+ bones: bones.filter((q): q is string => q !== null),
2852
+ froms: [...new Set(froms.filter((q): q is string => q !== null))],
2853
+ });
2730
2854
  limbFroms.set(limb, new Set(froms.filter((f): f is string => f !== null)));
2731
2855
  froms.forEach((f, i) => {
2732
2856
  if (f === null || i === 0 || froms[i - 1] === f) return;
package/src/limbs.ts CHANGED
@@ -125,6 +125,98 @@ export function bonePlaces(bones: readonly BoneEntry[]): Map<string, BonePlace>
125
125
  return out;
126
126
  }
127
127
 
128
+ /**
129
+ * Issue #476: pose `bones` (in rig pixels, y down) so every bone named in
130
+ * `drawn` takes that world angle (in Spine degrees, CCW, y up) while keeping
131
+ * its base length and parent-to-child joint offsets. Used by `assemble` when
132
+ * an alternate set covers a limb chain at its own `drawn` angles, so `cutLimbs`
133
+ * cuts the set's painting at the base's joints posed to `drawn`.
134
+ */
135
+ export function poseBoneEntriesForDrawn(bones: readonly BoneEntry[], drawn: Readonly<Record<string, number>>): BoneEntry[] {
136
+ if (Object.keys(drawn).length === 0) return [...bones];
137
+ interface FlatNode {
138
+ name: string;
139
+ parent: string;
140
+ at0: Pt;
141
+ end0: Pt | null;
142
+ theta0: number;
143
+ length: number;
144
+ inherit?: string;
145
+ }
146
+ const flat = new Map<string, FlatNode>();
147
+ for (const b of bones) {
148
+ if ('chain' in b) {
149
+ b.points.forEach((p, k) => {
150
+ const name = `${b.chain}${k}`;
151
+ const parent = k === 0 ? b.parent : `${b.chain}${k - 1}`;
152
+ const at0: Pt = [p[0], p[1]];
153
+ const end0: Pt = k + 1 < b.points.length ? [b.points[k + 1][0], b.points[k + 1][1]] : [b.tip[0], b.tip[1]];
154
+ const dx = end0[0] - at0[0];
155
+ const dy = end0[1] - at0[1];
156
+ const theta0 = (Math.atan2(-dy, dx) * 180) / Math.PI;
157
+ const length = Math.sqrt(dx * dx + dy * dy);
158
+ flat.set(name, { name, parent, at0, end0, theta0, length, inherit: b.link_inherit?.[name] });
159
+ });
160
+ } else {
161
+ const at0: Pt = [b.at[0], b.at[1]];
162
+ const end0: Pt | null = b.tip === undefined ? null : [b.tip[0], b.tip[1]];
163
+ const dx = end0 === null ? 0 : end0[0] - at0[0];
164
+ const dy = end0 === null ? 0 : end0[1] - at0[1];
165
+ const theta0 = end0 === null ? 0 : (Math.atan2(-dy, dx) * 180) / Math.PI;
166
+ const length = end0 === null ? 0 : Math.sqrt(dx * dx + dy * dy);
167
+ flat.set(b.name, { name: b.name, parent: b.parent, at0, end0, theta0, length, inherit: b.inherit });
168
+ }
169
+ }
170
+ const posed = new Map<string, { at: Pt; end: Pt | null; theta: number }>();
171
+ const solve = (name: string): { at: Pt; end: Pt | null; theta: number } => {
172
+ const cached = posed.get(name);
173
+ if (cached !== undefined) return cached;
174
+ const node = flat.get(name);
175
+ if (node === undefined) return { at: [0, 0], end: null, theta: 0 };
176
+ let at: Pt = [node.at0[0], node.at0[1]];
177
+ let dParent = 0;
178
+ const pNode = flat.get(node.parent);
179
+ if (pNode !== undefined) {
180
+ const pPosed = solve(node.parent);
181
+ dParent = pPosed.theta - pNode.theta0;
182
+ const rad = (dParent * Math.PI) / 180;
183
+ const cos = Math.cos(rad);
184
+ const sin = Math.sin(rad);
185
+ const dx0 = node.at0[0] - pNode.at0[0];
186
+ const dy0 = node.at0[1] - pNode.at0[1];
187
+ at = [pPosed.at[0] + dx0 * cos + dy0 * sin, pPosed.at[1] - dx0 * sin + dy0 * cos];
188
+ }
189
+ const inheritsRot = node.inherit !== 'noRotationOrReflection' && node.inherit !== 'onlyTranslation';
190
+ const theta = drawn[name] !== undefined ? drawn[name] : node.theta0 + (inheritsRot ? dParent : 0);
191
+ let end: Pt | null = null;
192
+ if (node.end0 !== null) {
193
+ const rad = (theta * Math.PI) / 180;
194
+ end = [at[0] + node.length * Math.cos(rad), at[1] - node.length * Math.sin(rad)];
195
+ }
196
+ const res = { at, end, theta };
197
+ posed.set(name, res);
198
+ return res;
199
+ };
200
+ for (const name of flat.keys()) solve(name);
201
+ return bones.map((b): BoneEntry => {
202
+ if ('chain' in b) {
203
+ const points = b.points.map((_, k): Pt => {
204
+ const s = solve(`${b.chain}${k}`);
205
+ return [s.at[0], s.at[1]];
206
+ });
207
+ const last = solve(`${b.chain}${b.points.length - 1}`);
208
+ const tip: Pt = last.end === null ? [b.tip[0], b.tip[1]] : [last.end[0], last.end[1]];
209
+ return { ...b, points, tip };
210
+ }
211
+ const s = solve(b.name);
212
+ return {
213
+ ...b,
214
+ at: [s.at[0], s.at[1]],
215
+ ...(b.tip === undefined || s.end === null ? {} : { tip: [s.end[0], s.end[1]] }),
216
+ };
217
+ });
218
+ }
219
+
128
220
  /** A limb's polyline: its segments' bone origins in order, then the last bone's end when it has one. */
129
221
  export function limbPolyline(limb: Limb, places: ReadonlyMap<string, BonePlace>): Pt[] {
130
222
  const pts = limb.segments.map((s) => (places.get(s.bone) as BonePlace).at);
package/src/rig.ts CHANGED
@@ -1007,8 +1007,12 @@ export function deriveAlternateDrawn(
1007
1007
  const limbPairs: ReadonlyArray<readonly [string, readonly [number, number], readonly [number, number]]> = [
1008
1008
  ['sleeve_r0', pts.r_shoulder, pts.r_elbow],
1009
1009
  ['sleeve_r1', pts.r_elbow, pts.r_wrist],
1010
+ ['arm_r0', pts.r_shoulder, pts.r_elbow],
1011
+ ['arm_r1', pts.r_elbow, pts.r_wrist],
1010
1012
  ['sleeve_l0', pts.l_shoulder, pts.l_elbow],
1011
1013
  ['sleeve_l1', pts.l_elbow, pts.l_wrist],
1014
+ ['arm_l0', pts.l_shoulder, pts.l_elbow],
1015
+ ['arm_l1', pts.l_elbow, pts.l_wrist],
1012
1016
  ['leg_r0', pts.r_hip, pts.r_knee],
1013
1017
  ['leg_r1', pts.r_knee, pts.r_ankle],
1014
1018
  ['leg_l0', pts.l_hip, pts.l_knee],
@@ -2109,17 +2113,44 @@ export function buildRig(
2109
2113
  for (const [altIdx, alt] of parts.alternates.entries()) {
2110
2114
  const cfgAlt = cfg.alternates?.find((a) => a.name === alt.name);
2111
2115
  const explicitDrawn = alt.drawn ?? cfgAlt?.drawn;
2116
+ const isSubsetSet = alt.parts !== undefined || cfgAlt?.parts !== undefined;
2117
+ let coveredBones: Set<string> | null = null;
2118
+ if (isSubsetSet) {
2119
+ coveredBones = new Set<string>();
2120
+ for (const pName of Object.keys(alt.slots)) {
2121
+ if (pName in cfg.regions) coveredBones.add(cfg.regions[pName]);
2122
+ for (const s of meshSegments.get(pName) ?? []) coveredBones.add(s.bone);
2123
+ const m = cfg.meshes[pName];
2124
+ if (m !== undefined) {
2125
+ if ('contour' in m) for (const rg of contourRegionsOf(m.contour)) coveredBones.add(rg.bone);
2126
+ if ('auto' in m) for (const rg of m.auto.regions ?? []) if (weightsABone(rg)) coveredBones.add(rg.bone);
2127
+ }
2128
+ }
2129
+ }
2112
2130
  if (explicitDrawn !== undefined) {
2113
2131
  for (const boneName of Object.keys(explicitDrawn)) {
2114
2132
  if (!B.has(boneName)) {
2115
2133
  fail('RIG_NAME_RESOLVES', `config.alternates[${altIdx}].drawn.${boneName}`, `names the bone "${boneName}", which config.bones does not declare`);
2134
+ } else if (coveredBones !== null && !coveredBones.has(boneName)) {
2135
+ const coveredList = [...coveredBones].map((b) => `"${b}"`).join(', ') || 'none';
2136
+ fail(
2137
+ 'RIG_SET_COVERS_BONE',
2138
+ `config.assemble.alternates[${altIdx}].drawn.${boneName}`,
2139
+ `names "${boneName}", which alternate set "${alt.name}" does not cover (covered bones: ${coveredList}); a subset set may state drawn angles only for the bones its covered parts ride`,
2140
+ );
2116
2141
  }
2117
2142
  }
2118
2143
  }
2119
2144
  refuseIfAny(problems);
2120
- const derived = alt.skeleton === undefined ? undefined : deriveAlternateDrawn(alt.skeleton, B, turn, CX, H);
2145
+ const rawDerived = alt.skeleton === undefined ? undefined : deriveAlternateDrawn(alt.skeleton, B, turn, CX, H);
2146
+ const derived =
2147
+ rawDerived === undefined
2148
+ ? undefined
2149
+ : coveredBones === null
2150
+ ? rawDerived
2151
+ : Object.fromEntries(Object.entries(rawDerived).filter(([k]) => coveredBones.has(k)));
2121
2152
  const drawn: Record<string, number> | undefined =
2122
- derived === undefined && explicitDrawn === undefined
2153
+ (derived === undefined || Object.keys(derived).length === 0) && explicitDrawn === undefined
2123
2154
  ? undefined
2124
2155
  : {
2125
2156
  ...(derived ?? {}),
@@ -2365,7 +2396,7 @@ export function buildRig(
2365
2396
  * keys against `rig.slots` and `sets.json`. When no key carries `"set"`, nothing
2366
2397
  * is touched and no byte moves.
2367
2398
  */
2368
- function expandSetAttachmentKeys(rig: RigSpec, sets: AttachmentSetsFile | undefined, merged: MotionSpec): void {
2399
+ export function expandSetAttachmentKeys(rig: RigSpec, sets: AttachmentSetsFile | undefined, merged: MotionSpec): void {
2369
2400
  let hasAnySetKey = false;
2370
2401
  for (const [animName, anim] of Object.entries(merged.animations)) {
2371
2402
  if (animName === 'idle' || typeof anim !== 'object' || anim === null || Array.isArray(anim)) continue;
@@ -2388,8 +2419,28 @@ function expandSetAttachmentKeys(rig: RigSpec, sets: AttachmentSetsFile | undefi
2388
2419
  if (!hasAnySetKey) return;
2389
2420
 
2390
2421
  const baseSlots = new Map<string, string | null>();
2422
+ const slotBoneMap = new Map<string, string>();
2391
2423
  for (const sl of rig.slots) {
2392
2424
  baseSlots.set(sl.name, sl.attachment ?? null);
2425
+ const rawBone = sl.bone.startsWith(`${sl.name}__`) ? sl.bone.slice(`${sl.name}__`.length) : sl.bone;
2426
+ slotBoneMap.set(sl.name, rawBone);
2427
+ }
2428
+ const setupRotByBone = new Map<string, number>();
2429
+ for (const b of rig.bones) setupRotByBone.set(b.name, b.rotation ?? 0);
2430
+ const setBoneDeltas = new Map<string, Map<string, number>>();
2431
+ if (sets !== undefined) {
2432
+ for (const [setName, entry] of Object.entries(sets.sets)) {
2433
+ if (entry.drawn === undefined || Object.keys(entry.drawn).length === 0) continue;
2434
+ const posed = poseRigBonesForDrawn(rig.bones, entry.drawn, rig.stops);
2435
+ const deltas = new Map<string, number>();
2436
+ for (const b of posed) {
2437
+ if (Object.hasOwn(entry.drawn, b.name)) {
2438
+ const d = places(normaliseDegrees((b.rotation ?? 0) - (setupRotByBone.get(b.name) ?? 0)));
2439
+ deltas.set(b.name, d);
2440
+ }
2441
+ }
2442
+ setBoneDeltas.set(setName, deltas);
2443
+ }
2393
2444
  }
2394
2445
  const declaredSets =
2395
2446
  sets === undefined || Object.keys(sets.sets).length === 0
@@ -2403,6 +2454,14 @@ function expandSetAttachmentKeys(rig: RigSpec, sets: AttachmentSetsFile | undefi
2403
2454
  if (animName === 'idle' || typeof anim !== 'object' || anim === null || Array.isArray(anim)) continue;
2404
2455
  const tracks = (anim as Record<string, unknown>).tracks;
2405
2456
  if (!Array.isArray(tracks)) continue;
2457
+ const existingRotateBones = new Set<string>();
2458
+ for (const tr of tracks) {
2459
+ if (typeof tr === 'object' && tr !== null && !Array.isArray(tr)) {
2460
+ const r = tr as Record<string, unknown>;
2461
+ if (r.property === 'rotate' && typeof r.bone === 'string') existingRotateBones.add(r.bone);
2462
+ }
2463
+ }
2464
+ const synthesizedRotate = new Map<string, Array<Record<string, unknown>>>();
2406
2465
  tracks.forEach((tr, ti) => {
2407
2466
  if (typeof tr !== 'object' || tr === null || Array.isArray(tr)) return;
2408
2467
  const trRec = tr as Record<string, unknown>;
@@ -2410,6 +2469,9 @@ function expandSetAttachmentKeys(rig: RigSpec, sets: AttachmentSetsFile | undefi
2410
2469
  if (!Array.isArray(keys)) return;
2411
2470
  const slot = typeof trRec.slot === 'string' && trRec.slot !== '' ? trRec.slot : null;
2412
2471
  const isAttachmentTrack = trRec.property === 'attachment' && slot !== null;
2472
+ const slotBone = slot === null ? undefined : slotBoneMap.get(slot);
2473
+ let trackTouchesDrawnBone = false;
2474
+ const rawSetKeysForBone: Array<{ t: unknown; setVal: string | null }> = [];
2413
2475
  keys.forEach((k, ki) => {
2414
2476
  if (typeof k !== 'object' || k === null || Array.isArray(k) || !('set' in k)) return;
2415
2477
  const kRec = k as Record<string, unknown>;
@@ -2442,6 +2504,7 @@ function expandSetAttachmentKeys(rig: RigSpec, sets: AttachmentSetsFile | undefi
2442
2504
  return;
2443
2505
  }
2444
2506
  resolvedV = baseSlots.get(slot) ?? null;
2507
+ rawSetKeysForBone.push({ t: kRec.t, setVal: null });
2445
2508
  } else if (typeof setVal !== 'string' || setVal === '') {
2446
2509
  problems.push({
2447
2510
  code: 'CONFIG_FIELD_TYPE',
@@ -2472,6 +2535,10 @@ function expandSetAttachmentKeys(rig: RigSpec, sets: AttachmentSetsFile | undefi
2472
2535
  });
2473
2536
  return;
2474
2537
  }
2538
+ if (slotBone !== undefined && setBoneDeltas.get(setVal)?.has(slotBone) === true) {
2539
+ trackTouchesDrawnBone = true;
2540
+ }
2541
+ rawSetKeysForBone.push({ t: kRec.t, setVal });
2475
2542
  }
2476
2543
  const expanded: Record<string, unknown> = {};
2477
2544
  for (const [prop, val] of Object.entries(kRec)) {
@@ -2480,7 +2547,25 @@ function expandSetAttachmentKeys(rig: RigSpec, sets: AttachmentSetsFile | undefi
2480
2547
  }
2481
2548
  keys[ki] = expanded;
2482
2549
  });
2550
+ if (
2551
+ problems.length === 0 &&
2552
+ trackTouchesDrawnBone &&
2553
+ slotBone !== undefined &&
2554
+ !existingRotateBones.has(slotBone) &&
2555
+ !synthesizedRotate.has(slotBone)
2556
+ ) {
2557
+ const rotKeys = rawSetKeysForBone.map((rk, idx) => {
2558
+ const d = rk.setVal === null ? 0 : (setBoneDeltas.get(rk.setVal)?.get(slotBone) ?? 0);
2559
+ return idx + 1 < rawSetKeysForBone.length ? { t: rk.t, v: [d], curve: 'stepped' } : { t: rk.t, v: [d] };
2560
+ });
2561
+ synthesizedRotate.set(slotBone, rotKeys);
2562
+ }
2483
2563
  });
2564
+ if (problems.length === 0) {
2565
+ for (const [boneName, rotKeys] of synthesizedRotate) {
2566
+ tracks.push({ bone: boneName, property: 'rotate', keys: rotKeys });
2567
+ }
2568
+ }
2484
2569
  }
2485
2570
  refuseIfAny(problems);
2486
2571
  }