rig-parts 1.44.0 → 1.46.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/cli.ts +1 -1
- package/docs/AUTHORING.md +4 -2
- package/package.json +1 -1
- package/src/build.ts +45 -17
- package/src/config.ts +89 -0
- package/src/limbs.ts +244 -0
- package/src/parts.ts +10 -0
- package/src/propose.ts +34 -8
- package/src/rig.ts +67 -30
- package/src/turn.ts +9 -0
package/cli.ts
CHANGED
|
@@ -1292,7 +1292,7 @@ function cmdPropose(args: string[]): number {
|
|
|
1292
1292
|
const prop =
|
|
1293
1293
|
fullRun === undefined && headRun === undefined
|
|
1294
1294
|
? drafted
|
|
1295
|
-
: withTurn(drafted, draftTurn(P, { ...(fullRun === undefined ? {} : { full: readLayers(fullRun) }), ...(headRun === undefined ? {} : { head: readLayers(headRun) }) }));
|
|
1295
|
+
: withTurn(drafted, draftTurn(P, { ...(fullRun === undefined ? {} : { full: readLayers(fullRun) }), ...(headRun === undefined ? {} : { head: readLayers(headRun) }) }, drafted));
|
|
1296
1296
|
// Emit only after green: a proposal the config loader would refuse is not written, nor a basis record that does not hold to it.
|
|
1297
1297
|
checkProposal(P, prop);
|
|
1298
1298
|
const bfile = basisFile(P, prop, basis, cfg === null || cmpPath === undefined ? null : { where: cmpPath, config: cfg });
|
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, #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
|
|
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; with `drawn` alone, cut at the base's joints posed to the set's own `drawn` angles by `poseBoneEntriesForDrawn`, each segment keeping the base's length; with `skeleton` (issue #539), cut at the skeleton's own joint positions by `placeBoneEntriesForSkeleton` — each covered bone the body-18 table names (`sleeve_*`, `arm_*0`/`arm_*1`, `leg_*0`/`leg_*1`) at its skeleton origin with the skeleton segment's own length and direction (`drawn` overriding the direction of a bone it names), and a covered bone the table does not name (a hand link `arm_r2`, a single `foot_r`) placed from its parent's new place — its base offset from the parent, stretched along the parent by the parent's length change and turned by its turn, so a link or a foot at the parent's end lands on the skeleton's end — with its base length and the drawn or base direction, so a foreshortened shin or forearm is cut where it is painted; 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, when the skeleton placed the set's limb bones (issue #539), `drawnLength` (`{<bone>: <ratio>}`, each covered table bone's skeleton segment length over its base length, 6 places) and `registration` (`{offset: [dx, dy], scale}`: the similarity without rotation, about the canvas origin, that maps the skeleton's torso — the mean of its shoulders `r_shoulder`/`l_shoulder` to the mean of its hips `r_hip`/`l_hip`, read where the base declares the bone rooted there, `sleeve_*0`/`arm_*0` and `leg_*0` — onto those base bones' origins, 6 places), both also written to `sets.json`; the set's painting must be registered, its torso within 1 rig px and 1 % in scale of the base's, or the set is refused by name before any joint is cut (`ASSEMBLE_ALT_SKELETON_REGISTERED`, with the offset and scale the painting would need) — 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
|
| `assemble.head_face_underfill` | assemble, `assemble --propose-plan` | **authored**, optional (issue #492): `boolean` (`CONFIG_FIELD_TYPE` on any other). When both runs exist and `full:face` has at least `200` opaque run px (`PROPOSE_MIN_PX`), the stage maps `full:face` into the head canvas via `fullLayerToHead` and measures how much of its hole-filled silhouette (`alpha > 8`) is covered by `head:face` (`alpha > 8`). A head-run `face` covering less than `75 %` (`HEAD_FACE_COVERAGE_FLOOR`, measured `0.0 %..48.6 %` on hollow/omitted head runs vs `84.8 %..99.6 %` on clean head runs across the 4 public examples and 9-standee corpus) is refused with `SEETHROUGH_HEAD_RUN_HOLLOW` unless `head_face_underfill: true` is declared. When `head_face_underfill: true` is declared and `head:face` exists (`opaqueRunPx >= 200`), `fullLayerToHead(full:face)` is composited under `head:face` on the head canvas (`alpha = max(headAlpha, fullAlpha)`, RGB blended by `headAlpha / 255`) before `head:face` is placed in rig space (`underfill=<N>px(full:face)` on the `face` part log line and a `face: head_face_underfill composited …` note in `assemble --propose-plan`). The fill restores transparent pixels only and leaves the cut's own edge where it is — a hollow whose edge is not under hair stays visible, and that is the author's to fix at the cut. When `head:face` has fewer than `200` opaque pixels, `SEETHROUGH_HEAD_RUN_HOLLOW` still fires even under `head_face_underfill: true` because the head run omitted the face layer and cannot supply a jawline |
|
|
113
113
|
| `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 |
|
|
114
114
|
| `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 |
|
|
@@ -126,7 +126,7 @@ read by no CPU stage).
|
|
|
126
126
|
| `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 |
|
|
127
127
|
| `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 |
|
|
128
128
|
| `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 |
|
|
129
|
-
| `turn` | rig (adds the turn control) | **proposed** only with `propose --full`/`--head` (issue #251), then corrected: `{pivot, depths, deform?, band?, radius?, surface?: {radius?}, head?: {pivot?, radius?}}`. `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. With no `face` part, or more than one, the riders keep their own and a note says so. 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 |
|
|
129
|
+
| `turn` | rig (adds the turn control) | **proposed** only with `propose --full`/`--head` (issue #251), then corrected: `{pivot, depths, deform?, band?, radius?, surface?: {radius?}, head?: {pivot?, radius?}}`. `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 |
|
|
130
130
|
| `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 |
|
|
131
131
|
| `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 |
|
|
132
132
|
| `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 |
|
|
@@ -2744,6 +2744,7 @@ See-through with another seed.
|
|
|
2744
2744
|
| <a id="CONFIG_CONSTRAINT_NAME_UNIQUE"></a>`CONFIG_CONSTRAINT_NAME_UNIQUE` | two `constraints` entries of one kind share a `name`; rigc finds a constraint by its kind and its name, so an ik and a transform may share one | rename one |
|
|
2745
2745
|
| <a id="CONFIG_CONSTRAINT_TARGET_DETACHED"></a>`CONFIG_CONSTRAINT_TARGET_DETACHED` | the bone an ik follows (`target`) or a transform reads (`source`) is one of the bones that constraint drives, or sits under one (the detail gives the line of parents) — driving them would move what they follow. This package's refusal: rig-c 2.15.0 gates such a rig green when nothing declares the parentage (measured on the selftest's rig fixture, issue #103) | a bone beside the chain; a scene target is a single bone parented to `root` (§3) |
|
|
2746
2746
|
| <a id="CONFIG_TURN_PIVOT_BEHIND_NEAREST"></a>`CONFIG_TURN_PIVOT_BEHIND_NEAREST` | `turn.pivot` is at or in front of the nearest part's depth: the law `(pivot − depth) / (pivot − nearest)` has no value there, and in front of it every part travels against the dial | a pivot above the smallest depth in `turn.depths` |
|
|
2747
|
+
| <a id="CONFIG_TURN_RIDER_DEPTH"></a>`CONFIG_TURN_RIDER_DEPTH` | the rig stage, with `turn`: a part that rides another part's bone (issue #535 — every ownable bone it binds is hosted by one other carried part, the one binding it with the most `opaque_px`) has a `turn.depths` entry whose fraction `(pivot − depth) / (pivot − nearest)` differs from its host's by more than `TURN_RIDER_APART` (0.1) of the dial, so the turn would move it off what it is pinned to; the detail names the part, its host, the bones, both depths, both fractions, the difference and the bound | the host's depth − 0.001 when parts.json draws the part after its host (+ 0.001 when before), or redraft the turn with `propose --full`/`--head` |
|
|
2747
2748
|
| <a id="CONFIG_CLOTH_SPLIT_BEFORE_TIP"></a>`CONFIG_CLOTH_SPLIT_BEFORE_TIP` | a `cloth` recipe's `split.at` is at or past its `links`: the trunk would leave no link for the branches (issue #364) | `split.at` below `links`, or leave `split` out |
|
|
2748
2749
|
| <a id="CONFIG_CLOTH_RESPONSE_GROWS_TO_TIP"></a>`CONFIG_CLOTH_RESPONSE_GROWS_TO_TIP` | a `cloth` recipe's `wind` or `gravity` is `[root, tip]` with tip below root: the response grows from the root to the tip, where the motion accumulates down the chain | that pair |
|
|
2749
2750
|
| <a id="CONFIG_CLOTH_ALTERNATE_DIFFERS"></a>`CONFIG_CLOTH_ALTERNATE_DIFFERS` | a `cloth` recipe's `alternate_damping` without `damping`, or equal to it: neighbouring trees are declared out of phase, and an alternate that alternates nothing declares nothing | `damping` beside it, a different value, or leave `alternate_damping` out |
|
|
@@ -2835,6 +2836,7 @@ says why each requirement exists and what breaks without it.
|
|
|
2835
2836
|
| <a id="ASSEMBLE_ALT_INPUT_PRESENT"></a>`ASSEMBLE_ALT_INPUT_PRESENT` | an alternate painting set (`assemble.alternates` or `--alt`, issue #454) is missing `source` or `full`, names a file or directory that is not on disk, or lacks a covered part's layer in its runs | give `source` and `full` on the alternate set, or list an occluded part in `hides` |
|
|
2836
2837
|
| <a id="ASSEMBLE_ALT_CANVAS_SIZE"></a>`ASSEMBLE_ALT_CANVAS_SIZE` | an alternate painting's canvas size differs from the primary painting's (issue #454; the detail gives both sizes) | the alternate painting: the primary painting's canvas size, so its parts land in the same rig frame |
|
|
2837
2838
|
| <a id="ASSEMBLE_ALT_SKELETON"></a>`ASSEMBLE_ALT_SKELETON` | an alternate set's `skeleton` file (`assemble.alternates[i].skeleton`, issue #465) is not JSON or does not hold `{"width": W, "height": H, "points": {…the 18 body-18 keypoints}}` | that set's `skeleton` file |
|
|
2839
|
+
| <a id="ASSEMBLE_ALT_SKELETON_REGISTERED"></a>`ASSEMBLE_ALT_SKELETON_REGISTERED` | an alternate set whose `skeleton` places its limb bones (issue #539) is not registered on the base: the similarity without rotation that maps the skeleton's torso (the mean of its shoulders to the mean of its hips, where the base declares `sleeve_*0`/`arm_*0` and `leg_*0`) onto those base bones' origins is more than 1 rig px off (the offset's length) or more than 1 % off in scale; the detail gives the offset `[dx, dy]` rig px and the scale the painting would need (`p -> scale * p + offset`, about the canvas origin) and the bones read. Also when the base declares no bone at one end of the torso, or the skeleton's torso has no length. Refused before any joint is cut | the set's painting and skeleton, registered: the figure at the base figure's torso place and scale on the same canvas (`ASSEMBLE_ALT_CANVAS_SIZE` forbids another canvas); or, on a base with no torso bones, `drawn` in place of `skeleton` |
|
|
2838
2840
|
| <a id="ASSEMBLE_COUNTS_ADD_UP"></a>`ASSEMBLE_COUNTS_ADD_UP` | a part's visible and occluded counts do not add up to its opaque pixels, or a projected pixel is not visible, or a cut part's pieces do not add up to it — an assembler bug, not an input problem | report it with the part named; nothing was written |
|
|
2839
2841
|
|
|
2840
2842
|
### propose
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rig-parts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.46.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,7 +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
|
+
import { placeBoneEntriesForSkeleton, poseBoneEntriesForDrawn, REGISTER_OFFSET_BAR, REGISTER_SCALE_BAR, registeredWithinBar, registerSkeleton, SKELETON_LIMB_BONES, skeletonDrawnLength, skeletonLimbJoints } from './limbs.ts';
|
|
82
82
|
import { type AlternatePartsRecord, type PartRecord, readParts, type RecompositeRecord, type SingleRunPad, tagOf, writeParts } from './parts.ts';
|
|
83
83
|
import { encodePngBytes, readPng, writePng } from './raster/png.ts';
|
|
84
84
|
import type { Raster } from './raster/types.ts';
|
|
@@ -150,6 +150,14 @@ export interface AssembleStageInput {
|
|
|
150
150
|
project: ProjectRule;
|
|
151
151
|
/** `--alt` entries, merged with `config.assemble.alternates` by set name (issue #454). */
|
|
152
152
|
alts?: readonly AlternateCliInput[];
|
|
153
|
+
/**
|
|
154
|
+
* How an alternate set with a `skeleton` is cut (issue #539): `"skeleton"`
|
|
155
|
+
* (the default, the only one the CLI runs) at the skeleton's own joint
|
|
156
|
+
* positions, registered on the base's torso; `"angles"` at the base's joints
|
|
157
|
+
* posed to the skeleton's angles, the rule before #539 — kept for the
|
|
158
|
+
* selftest's control that shows a foreshortened segment refused under it.
|
|
159
|
+
*/
|
|
160
|
+
altPlacement?: 'skeleton' | 'angles';
|
|
153
161
|
}
|
|
154
162
|
|
|
155
163
|
/** Where the assemble stage writes: `parts.json`, the directory of part PNGs, the recomposite, and its error map. */
|
|
@@ -446,34 +454,52 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
446
454
|
const altUnder = alt.cuts !== undefined ? readUnders(input.config, altCuts) : altCuts.map(() => null);
|
|
447
455
|
const altHeadBox = alt.head_box ?? (altRuns.single ? singleRunHeadBox(altSrc.width, altSrc.height, fields.resolution) : fields.headBox);
|
|
448
456
|
let altBones = fields.bones;
|
|
457
|
+
let altDrawnLength: Record<string, number> | undefined;
|
|
458
|
+
let altRegistration: { offset: [number, number]; scale: number } | undefined;
|
|
449
459
|
if (Object.keys(altLimbs).length > 0 && fields.bones !== undefined && (altSkeleton !== undefined || alt.drawn !== undefined)) {
|
|
450
460
|
const coveredLimbBones = new Set(Object.values(altLimbs).flatMap((l) => l.segments.map((sg) => sg.bone)));
|
|
451
461
|
const limbDrawn: Record<string, number> = {};
|
|
462
|
+
const joints = altSkeleton === undefined ? [] : skeletonLimbJoints(altSkeleton);
|
|
452
463
|
if (altSkeleton !== undefined) {
|
|
453
464
|
const deg = (a: readonly [number, number], b: readonly [number, number]): number =>
|
|
454
465
|
(Math.atan2(-(b[1] - a[1]), b[0] - a[0]) * 180) / Math.PI;
|
|
455
|
-
const
|
|
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) {
|
|
466
|
+
for (const [bName, a, b] of joints) {
|
|
470
467
|
if (alt.parts === undefined || coveredLimbBones.has(bName)) limbDrawn[bName] = deg(a, b);
|
|
471
468
|
}
|
|
472
469
|
}
|
|
473
470
|
if (alt.drawn !== undefined) {
|
|
474
471
|
for (const [bName, degVal] of Object.entries(alt.drawn)) limbDrawn[bName] = degVal;
|
|
475
472
|
}
|
|
476
|
-
|
|
473
|
+
const placedBySkeleton = altSkeleton !== undefined && input.altPlacement !== 'angles' && SKELETON_LIMB_BONES.some(([b]) => coveredLimbBones.has(b));
|
|
474
|
+
if (placedBySkeleton && altSkeleton !== undefined) {
|
|
475
|
+
// Issue #539: the painting must sit where the base figure sits before its own joints are cut at.
|
|
476
|
+
const reg = registerSkeleton(fields.bones, altSkeleton);
|
|
477
|
+
if (!reg.ok) {
|
|
478
|
+
const read = reg.anchors.map((a) => `${a.keypoint} on "${a.bone}"`).join(', ') || 'none';
|
|
479
|
+
altProblems.push({
|
|
480
|
+
code: 'ASSEMBLE_ALT_SKELETON_REGISTERED',
|
|
481
|
+
object: `${alt.skeleton} (alternate set "${alt.name}")`,
|
|
482
|
+
detail:
|
|
483
|
+
reg.missing.length > 0
|
|
484
|
+
? `cannot be registered on the base's torso: config.bones declares no bone rooted at the torso's ${reg.missing.join(' or ')} (the shoulders r_shoulder / l_shoulder root sleeve_r0, arm_r0, sleeve_l0, arm_l0; the hips r_hip / l_hip root leg_r0, leg_l0; read: ${read}); a base that declares a bone at each end of the torso is required, or drawn in place of skeleton`
|
|
485
|
+
: `cannot be registered on the base's torso: its torso keypoints (${read}) stand on one point, so the torso has no length; a skeleton whose shoulders and hips are apart is required`,
|
|
486
|
+
});
|
|
487
|
+
continue;
|
|
488
|
+
}
|
|
489
|
+
if (!registeredWithinBar(reg)) {
|
|
490
|
+
altProblems.push({
|
|
491
|
+
code: 'ASSEMBLE_ALT_SKELETON_REGISTERED',
|
|
492
|
+
object: `${alt.skeleton} (alternate set "${alt.name}")`,
|
|
493
|
+
detail: `puts the set's torso off the base's: the painting would need offset [${reg.offset.join(', ')}] rig px and scale ${reg.scale} (p -> scale * p + offset, about the canvas origin; read on ${reg.anchors.map((a) => `${a.keypoint} = "${a.bone}"`).join(', ')}), over the bar of ${REGISTER_OFFSET_BAR} rig px and ${REGISTER_SCALE_BAR * 100} % in scale; a registered painting is required — the set's figure at the base figure's torso place and scale on the same canvas`,
|
|
494
|
+
});
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
altRegistration = { offset: [reg.offset[0], reg.offset[1]], scale: reg.scale };
|
|
498
|
+
altDrawnLength = skeletonDrawnLength(fields.bones, coveredLimbBones, joints);
|
|
499
|
+
altBones = placeBoneEntriesForSkeleton(fields.bones, coveredLimbBones, joints, limbDrawn);
|
|
500
|
+
} else {
|
|
501
|
+
altBones = poseBoneEntriesForDrawn(fields.bones, limbDrawn);
|
|
502
|
+
}
|
|
477
503
|
}
|
|
478
504
|
let altRes: ReturnType<typeof assemble>;
|
|
479
505
|
try {
|
|
@@ -538,6 +564,8 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
538
564
|
...(altRes.parts.single_run_pad === undefined ? {} : { single_run_pad: altRes.parts.single_run_pad }),
|
|
539
565
|
...(altSkeleton === undefined ? {} : { skeleton: altSkeleton }),
|
|
540
566
|
...(alt.drawn === undefined ? {} : { drawn: { ...alt.drawn } }),
|
|
567
|
+
...(altDrawnLength === undefined ? {} : { drawnLength: altDrawnLength }),
|
|
568
|
+
...(altRegistration === undefined ? {} : { registration: altRegistration }),
|
|
541
569
|
},
|
|
542
570
|
images: keptImages,
|
|
543
571
|
});
|
package/src/config.ts
CHANGED
|
@@ -683,6 +683,95 @@ export function weightsABone(rg: AutoRegionSpec): rg is AutoWeightRegionSpec {
|
|
|
683
683
|
return 'bone' in rg;
|
|
684
684
|
}
|
|
685
685
|
|
|
686
|
+
/** The three sections a part's bones are read from: a config's, or a proposal's, which has the same shape (issue #535). */
|
|
687
|
+
export interface PartBinding {
|
|
688
|
+
bones: readonly BoneEntry[];
|
|
689
|
+
meshes: Readonly<Record<string, MeshSpec>>;
|
|
690
|
+
regions: Readonly<Record<string, string>>;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* The bones each part binds (issue #535): a region's `regions.<part>`; for a
|
|
695
|
+
* mesh, every bone its `segments` name (a chain's name standing for each of
|
|
696
|
+
* its links `<chain>0`, `<chain>1`, …; an explicit segment's bone), its
|
|
697
|
+
* `contour` regions' bones (a declared `bust` included) and its `auto`
|
|
698
|
+
* regions' that weight one. The same reading the rig stage makes of the parts
|
|
699
|
+
* an alternate set covers (issue #476). Parts in `meshes` first, then
|
|
700
|
+
* `regions`, each part's bones in the order they are named, once. Pure: a bone
|
|
701
|
+
* that does not resolve is kept by name — the loader and the rig stage refuse
|
|
702
|
+
* it on their own.
|
|
703
|
+
*/
|
|
704
|
+
export function partBoundBones(b: PartBinding): Map<string, string[]> {
|
|
705
|
+
const chains = new Map<string, string[]>();
|
|
706
|
+
for (const e of b.bones) if ('chain' in e) chains.set(e.chain, e.points.map((_, k) => `${e.chain}${k}`));
|
|
707
|
+
const out = new Map<string, string[]>();
|
|
708
|
+
const bind = (part: string, bone: string): void => {
|
|
709
|
+
const list = out.get(part) ?? [];
|
|
710
|
+
if (!list.includes(bone)) list.push(bone);
|
|
711
|
+
out.set(part, list);
|
|
712
|
+
};
|
|
713
|
+
for (const [part, m] of Object.entries(b.meshes)) {
|
|
714
|
+
for (const sg of m.segments) {
|
|
715
|
+
if (typeof sg !== 'string') bind(part, sg[0]);
|
|
716
|
+
else for (const l of chains.get(sg) ?? [sg]) bind(part, l);
|
|
717
|
+
}
|
|
718
|
+
if ('contour' in m) for (const rg of contourRegionsOf(m.contour)) bind(part, rg.bone);
|
|
719
|
+
if ('auto' in m) for (const rg of m.auto.regions ?? []) if (weightsABone(rg)) bind(part, rg.bone);
|
|
720
|
+
}
|
|
721
|
+
for (const [part, bone] of Object.entries(b.regions)) bind(part, bone);
|
|
722
|
+
return out;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* The bones a part can own (issue #535): every chain link, and every bone no
|
|
727
|
+
* other bone hangs from. A trunk bone — `head`, `chest`, anything with a child —
|
|
728
|
+
* is shared by nature, so binding it is never a rider relation on its own.
|
|
729
|
+
*/
|
|
730
|
+
export function ownableBones(bones: readonly BoneEntry[]): Set<string> {
|
|
731
|
+
const parents = new Set(bones.map((e) => e.parent));
|
|
732
|
+
const out = new Set<string>();
|
|
733
|
+
for (const e of bones) {
|
|
734
|
+
if ('chain' in e) e.points.forEach((_, k) => out.add(`${e.chain}${k}`));
|
|
735
|
+
else if (!parents.has(e.name)) out.add(e.name);
|
|
736
|
+
}
|
|
737
|
+
return out;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Issue #535's rider by bone, read off a binding for the carried parts (each
|
|
742
|
+
* with its `opaque_px`, in parts.json's draw order): the host of an ownable
|
|
743
|
+
* bone ({@link ownableBones}) is the carried part binding it with the most
|
|
744
|
+
* opaque pixels, the earlier in draw order on a tie; a part is a rider of `H`
|
|
745
|
+
* when it binds at least one ownable bone, every one of them is hosted by `H`,
|
|
746
|
+
* and it hosts none itself. A part whose ownable bones have two or more hosts
|
|
747
|
+
* rides none of them and is returned in `split` with its hosts. Parts not in
|
|
748
|
+
* `carried` neither host nor ride.
|
|
749
|
+
*/
|
|
750
|
+
export function turnRidersByBone(b: PartBinding, carried: ReadonlyArray<{ part: string; area: number }>): { riders: Map<string, { host: string; bones: string[] }>; split: Array<{ part: string; hosts: string[] }> } {
|
|
751
|
+
const bound = partBoundBones(b);
|
|
752
|
+
const ownable = ownableBones(b.bones);
|
|
753
|
+
const host = new Map<string, { part: string; area: number }>();
|
|
754
|
+
for (const c of carried) {
|
|
755
|
+
for (const bone of bound.get(c.part) ?? []) {
|
|
756
|
+
if (!ownable.has(bone)) continue;
|
|
757
|
+
const h = host.get(bone);
|
|
758
|
+
if (h === undefined || c.area > h.area) host.set(bone, c);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
const hosts = new Set([...host.values()].map((h) => h.part));
|
|
762
|
+
const riders = new Map<string, { host: string; bones: string[] }>();
|
|
763
|
+
const split: Array<{ part: string; hosts: string[] }> = [];
|
|
764
|
+
for (const c of carried) {
|
|
765
|
+
if (hosts.has(c.part)) continue;
|
|
766
|
+
const own = (bound.get(c.part) ?? []).filter((bone) => host.has(bone));
|
|
767
|
+
if (own.length === 0) continue;
|
|
768
|
+
const of = [...new Set(own.map((bone) => (host.get(bone) as { part: string }).part))];
|
|
769
|
+
if (of.length === 1) riders.set(c.part, { host: of[0], bones: own });
|
|
770
|
+
else split.push({ part: c.part, hosts: of });
|
|
771
|
+
}
|
|
772
|
+
return { riders, split };
|
|
773
|
+
}
|
|
774
|
+
|
|
686
775
|
export interface SingleTrack {
|
|
687
776
|
bone: string;
|
|
688
777
|
prop: SingleProp;
|
package/src/limbs.ts
CHANGED
|
@@ -105,7 +105,9 @@
|
|
|
105
105
|
* crossing.
|
|
106
106
|
*/
|
|
107
107
|
import type { BoneEntry, Limb, LimbSplit } from './config.ts';
|
|
108
|
+
import { edgeLength } from './length.ts';
|
|
108
109
|
import { pyRound } from './round.ts';
|
|
110
|
+
import type { KeypointName, PosePoints } from './skeleton.ts';
|
|
109
111
|
|
|
110
112
|
export type Pt = [number, number];
|
|
111
113
|
|
|
@@ -218,6 +220,248 @@ export function poseBoneEntriesForDrawn(bones: readonly BoneEntry[], drawn: Read
|
|
|
218
220
|
});
|
|
219
221
|
}
|
|
220
222
|
|
|
223
|
+
/**
|
|
224
|
+
* The limb bones a body-18 skeleton places (issues #465, #539): each bone's
|
|
225
|
+
* origin keypoint and end keypoint. The one table `assemble` cuts an
|
|
226
|
+
* alternate set at and the `rig` stage derives and weights from; a bone not
|
|
227
|
+
* named here (a hand link `arm_r2`, a single `foot_r`) is placed from its
|
|
228
|
+
* parent ({@link placeBoneEntriesForSkeleton}).
|
|
229
|
+
*/
|
|
230
|
+
export const SKELETON_LIMB_BONES: ReadonlyArray<readonly [string, KeypointName, KeypointName]> = [
|
|
231
|
+
['sleeve_r0', 'r_shoulder', 'r_elbow'],
|
|
232
|
+
['sleeve_r1', 'r_elbow', 'r_wrist'],
|
|
233
|
+
['arm_r0', 'r_shoulder', 'r_elbow'],
|
|
234
|
+
['arm_r1', 'r_elbow', 'r_wrist'],
|
|
235
|
+
['sleeve_l0', 'l_shoulder', 'l_elbow'],
|
|
236
|
+
['sleeve_l1', 'l_elbow', 'l_wrist'],
|
|
237
|
+
['arm_l0', 'l_shoulder', 'l_elbow'],
|
|
238
|
+
['arm_l1', 'l_elbow', 'l_wrist'],
|
|
239
|
+
['leg_r0', 'r_hip', 'r_knee'],
|
|
240
|
+
['leg_r1', 'r_knee', 'r_ankle'],
|
|
241
|
+
['leg_l0', 'l_hip', 'l_knee'],
|
|
242
|
+
['leg_l1', 'l_knee', 'l_ankle'],
|
|
243
|
+
];
|
|
244
|
+
|
|
245
|
+
/** {@link SKELETON_LIMB_BONES} read off `pts`: each bone's origin and end, in `pts`' space, in the table's order. */
|
|
246
|
+
export function skeletonLimbJoints(pts: PosePoints): Array<readonly [string, Pt, Pt]> {
|
|
247
|
+
return SKELETON_LIMB_BONES.map(([bone, a, b]): readonly [string, Pt, Pt] => [bone, [pts[a][0], pts[a][1]], [pts[b][0], pts[b][1]]]);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Issue #539: the torso a set's skeleton is registered by — the keypoints at
|
|
252
|
+
* the root of the limbs, each paired with the base bones that root there in
|
|
253
|
+
* {@link SKELETON_LIMB_BONES} (the first the base declares is read). The
|
|
254
|
+
* shoulders are the torso's top, the hips its bottom.
|
|
255
|
+
*/
|
|
256
|
+
export const SKELETON_TORSO: ReadonlyArray<{ keypoint: KeypointName; end: 'top' | 'bottom'; bones: readonly string[] }> = [
|
|
257
|
+
{ keypoint: 'r_shoulder', end: 'top', bones: ['sleeve_r0', 'arm_r0'] },
|
|
258
|
+
{ keypoint: 'l_shoulder', end: 'top', bones: ['sleeve_l0', 'arm_l0'] },
|
|
259
|
+
{ keypoint: 'r_hip', end: 'bottom', bones: ['leg_r0'] },
|
|
260
|
+
{ keypoint: 'l_hip', end: 'bottom', bones: ['leg_l0'] },
|
|
261
|
+
];
|
|
262
|
+
|
|
263
|
+
/** Issue #539: the most a registered skeleton's torso may sit off the base's, in rig px (the offset's length). */
|
|
264
|
+
export const REGISTER_OFFSET_BAR = 1;
|
|
265
|
+
/** Issue #539: the most a registered skeleton's torso may differ from the base's in scale, as a share (`|s - 1|`). */
|
|
266
|
+
export const REGISTER_SCALE_BAR = 0.01;
|
|
267
|
+
|
|
268
|
+
/** Issue #539: how a set's skeleton sits on the base's torso, or which torso ends the base declares no bone for. */
|
|
269
|
+
export type SkeletonRegistration =
|
|
270
|
+
| { ok: true; offset: Pt; scale: number; anchors: Array<{ keypoint: KeypointName; bone: string }> }
|
|
271
|
+
| { ok: false; missing: Array<'top' | 'bottom'>; anchors: Array<{ keypoint: KeypointName; bone: string }> };
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Issue #539: the similarity without rotation that maps a set's skeleton
|
|
275
|
+
* torso onto the base's, both in rig px — `p -> scale * p + offset`, about the
|
|
276
|
+
* canvas origin, the transform the set's painting would need to sit where the
|
|
277
|
+
* base figure sits. Each end of the torso is the mean of its
|
|
278
|
+
* {@link SKELETON_TORSO} keypoints whose base bone `bones` declares, the
|
|
279
|
+
* base's the mean of those bones' origins; `scale` is the base torso's length
|
|
280
|
+
* over the skeleton's, and `offset` takes the skeleton torso's midpoint, so
|
|
281
|
+
* scaled, onto the base's. Both to 6 places. Not ok when the base declares no
|
|
282
|
+
* bone at one end, or the skeleton's torso has no length.
|
|
283
|
+
*/
|
|
284
|
+
export function registerSkeleton(bones: readonly BoneEntry[], pts: PosePoints): SkeletonRegistration {
|
|
285
|
+
const places = bonePlaces(bones);
|
|
286
|
+
const anchors: Array<{ keypoint: KeypointName; bone: string; end: 'top' | 'bottom' }> = [];
|
|
287
|
+
for (const t of SKELETON_TORSO) {
|
|
288
|
+
const bone = t.bones.find((b) => places.has(b));
|
|
289
|
+
if (bone !== undefined) anchors.push({ keypoint: t.keypoint, bone, end: t.end });
|
|
290
|
+
}
|
|
291
|
+
const named = anchors.map((a) => ({ keypoint: a.keypoint, bone: a.bone }));
|
|
292
|
+
const missing = (['top', 'bottom'] as const).filter((e) => !anchors.some((a) => a.end === e));
|
|
293
|
+
const mean = (end: 'top' | 'bottom', of: (a: { keypoint: KeypointName; bone: string }) => Pt): Pt => {
|
|
294
|
+
const at = anchors.filter((a) => a.end === end).map(of);
|
|
295
|
+
return [at.reduce((s, p) => s + p[0], 0) / at.length, at.reduce((s, p) => s + p[1], 0) / at.length];
|
|
296
|
+
};
|
|
297
|
+
if (missing.length > 0) return { ok: false, missing, anchors: named };
|
|
298
|
+
const base = (a: { bone: string }): Pt => (places.get(a.bone) as BonePlace).at;
|
|
299
|
+
const skel = (a: { keypoint: KeypointName }): Pt => [pts[a.keypoint][0], pts[a.keypoint][1]];
|
|
300
|
+
const bTop = mean('top', base);
|
|
301
|
+
const bBot = mean('bottom', base);
|
|
302
|
+
const kTop = mean('top', skel);
|
|
303
|
+
const kBot = mean('bottom', skel);
|
|
304
|
+
const kLen = edgeLength(kTop[0] - kBot[0], kTop[1] - kBot[1]);
|
|
305
|
+
if (kLen === 0) return { ok: false, missing: [], anchors: named };
|
|
306
|
+
const scale = edgeLength(bTop[0] - bBot[0], bTop[1] - bBot[1]) / kLen;
|
|
307
|
+
const offset: Pt = [(bTop[0] + bBot[0]) / 2 - (scale * (kTop[0] + kBot[0])) / 2, (bTop[1] + bBot[1]) / 2 - (scale * (kTop[1] + kBot[1])) / 2];
|
|
308
|
+
const zero = (v: number): number => (v === 0 ? 0 : v);
|
|
309
|
+
return { ok: true, offset: [zero(pyRound(offset[0], 6)), zero(pyRound(offset[1], 6))], scale: pyRound(scale, 6), anchors: named };
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** Whether a registration is the identity within {@link REGISTER_OFFSET_BAR} and {@link REGISTER_SCALE_BAR}. */
|
|
313
|
+
export function registeredWithinBar(r: { offset: Pt; scale: number }): boolean {
|
|
314
|
+
return edgeLength(r.offset[0], r.offset[1]) <= REGISTER_OFFSET_BAR && Math.abs(r.scale - 1) <= REGISTER_SCALE_BAR;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Issue #539: place `bones` (rig px, y down) where a set's skeleton draws
|
|
319
|
+
* them, so `cutLimbs` cuts the set's painting at the painting's own joints.
|
|
320
|
+
* Every bone in `covered` that `joints` names sits at its skeleton origin and
|
|
321
|
+
* takes the skeleton segment's own length and direction ({@link
|
|
322
|
+
* poseBoneEntriesForDrawn} keeps the base's length, which puts the next joint
|
|
323
|
+
* past a foreshortened segment's painted end); `drawn` overrides the
|
|
324
|
+
* direction of any bone it names, the length staying the skeleton's. Every
|
|
325
|
+
* other bone keeps its base entry unless an ancestor moved: then it is placed
|
|
326
|
+
* from its parent's new place — its base offset from the parent's origin,
|
|
327
|
+
* the part along the parent stretched by the parent's length change and the
|
|
328
|
+
* whole turned by the parent's turn (a chain's next link, or a `foot_r` at
|
|
329
|
+
* the ankle, lands on the parent's new end) — with its base length, and the
|
|
330
|
+
* parent's turn added to its direction unless it inherits no rotation, or
|
|
331
|
+
* `drawn`'s direction when named. With no length change this is
|
|
332
|
+
* {@link poseBoneEntriesForDrawn}'s rule for those bones.
|
|
333
|
+
*/
|
|
334
|
+
export function placeBoneEntriesForSkeleton(
|
|
335
|
+
bones: readonly BoneEntry[],
|
|
336
|
+
covered: ReadonlySet<string>,
|
|
337
|
+
joints: ReadonlyArray<readonly [string, Pt, Pt]>,
|
|
338
|
+
drawn: Readonly<Record<string, number>>,
|
|
339
|
+
): BoneEntry[] {
|
|
340
|
+
const fromSkeleton = new Map<string, readonly [Pt, Pt]>();
|
|
341
|
+
for (const [bone, a, b] of joints) if (covered.has(bone) && !fromSkeleton.has(bone)) fromSkeleton.set(bone, [a, b]);
|
|
342
|
+
if (fromSkeleton.size === 0) return poseBoneEntriesForDrawn(bones, drawn);
|
|
343
|
+
const flat = flatBones(bones);
|
|
344
|
+
const deg = (dx: number, dy: number): number => (Math.atan2(-dy, dx) * 180) / Math.PI;
|
|
345
|
+
const posed = new Map<string, { at: Pt; end: Pt | null; theta: number; length: number }>();
|
|
346
|
+
const solve = (name: string): { at: Pt; end: Pt | null; theta: number; length: number } => {
|
|
347
|
+
const cached = posed.get(name);
|
|
348
|
+
if (cached !== undefined) return cached;
|
|
349
|
+
const node = flat.get(name);
|
|
350
|
+
if (node === undefined) return { at: [0, 0], end: null, theta: 0, length: 0 };
|
|
351
|
+
let at: Pt = [node.at0[0], node.at0[1]];
|
|
352
|
+
let theta = node.theta0;
|
|
353
|
+
let length = node.length;
|
|
354
|
+
const sk = fromSkeleton.get(name);
|
|
355
|
+
if (sk !== undefined) {
|
|
356
|
+
at = [sk[0][0], sk[0][1]];
|
|
357
|
+
length = edgeLength(sk[1][0] - sk[0][0], sk[1][1] - sk[0][1]);
|
|
358
|
+
theta = drawn[name] !== undefined ? drawn[name] : deg(sk[1][0] - sk[0][0], sk[1][1] - sk[0][1]);
|
|
359
|
+
} else {
|
|
360
|
+
let dParent = 0;
|
|
361
|
+
const pNode = flat.get(node.parent);
|
|
362
|
+
if (pNode !== undefined) {
|
|
363
|
+
const pPosed = solve(node.parent);
|
|
364
|
+
dParent = pPosed.theta - pNode.theta0;
|
|
365
|
+
const stretch = pNode.length > 0 ? pPosed.length / pNode.length : 1;
|
|
366
|
+
const t0 = (pNode.theta0 * Math.PI) / 180;
|
|
367
|
+
const ux = Math.cos(t0);
|
|
368
|
+
const uy = -Math.sin(t0);
|
|
369
|
+
const dx0 = node.at0[0] - pNode.at0[0];
|
|
370
|
+
const dy0 = node.at0[1] - pNode.at0[1];
|
|
371
|
+
const along = (dx0 * ux + dy0 * uy) * (stretch - 1);
|
|
372
|
+
const ox = dx0 + along * ux;
|
|
373
|
+
const oy = dy0 + along * uy;
|
|
374
|
+
const rad = (dParent * Math.PI) / 180;
|
|
375
|
+
const cos = Math.cos(rad);
|
|
376
|
+
const sin = Math.sin(rad);
|
|
377
|
+
at = [pPosed.at[0] + ox * cos + oy * sin, pPosed.at[1] - ox * sin + oy * cos];
|
|
378
|
+
}
|
|
379
|
+
const inheritsRot = node.inherit !== 'noRotationOrReflection' && node.inherit !== 'onlyTranslation';
|
|
380
|
+
theta = drawn[name] !== undefined ? drawn[name] : node.theta0 + (inheritsRot ? dParent : 0);
|
|
381
|
+
}
|
|
382
|
+
let end: Pt | null = null;
|
|
383
|
+
if (node.end0 !== null) {
|
|
384
|
+
const rad = (theta * Math.PI) / 180;
|
|
385
|
+
end = sk !== undefined && drawn[name] === undefined ? [sk[1][0], sk[1][1]] : [at[0] + length * Math.cos(rad), at[1] - length * Math.sin(rad)];
|
|
386
|
+
}
|
|
387
|
+
const res = { at, end, theta, length };
|
|
388
|
+
posed.set(name, res);
|
|
389
|
+
return res;
|
|
390
|
+
};
|
|
391
|
+
for (const name of flat.keys()) solve(name);
|
|
392
|
+
return bones.map((b): BoneEntry => {
|
|
393
|
+
if ('chain' in b) {
|
|
394
|
+
const points = b.points.map((_, k): Pt => {
|
|
395
|
+
const s = solve(`${b.chain}${k}`);
|
|
396
|
+
return [s.at[0], s.at[1]];
|
|
397
|
+
});
|
|
398
|
+
const last = solve(`${b.chain}${b.points.length - 1}`);
|
|
399
|
+
const tip: Pt = last.end === null ? [b.tip[0], b.tip[1]] : [last.end[0], last.end[1]];
|
|
400
|
+
return { ...b, points, tip };
|
|
401
|
+
}
|
|
402
|
+
const s = solve(b.name);
|
|
403
|
+
return {
|
|
404
|
+
...b,
|
|
405
|
+
at: [s.at[0], s.at[1]],
|
|
406
|
+
...(b.tip === undefined || s.end === null ? {} : { tip: [s.end[0], s.end[1]] }),
|
|
407
|
+
};
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Issue #539: each covered bone's skeleton segment length over its base
|
|
413
|
+
* length (`sets.json` `drawnLength`), to 6 places, in {@link
|
|
414
|
+
* SKELETON_LIMB_BONES}' order; a bone the base gives no length is left out.
|
|
415
|
+
*/
|
|
416
|
+
export function skeletonDrawnLength(bones: readonly BoneEntry[], covered: ReadonlySet<string>, joints: ReadonlyArray<readonly [string, Pt, Pt]>): Record<string, number> {
|
|
417
|
+
const places = bonePlaces(bones);
|
|
418
|
+
const out: Record<string, number> = {};
|
|
419
|
+
for (const [bone, a, b] of joints) {
|
|
420
|
+
if (!covered.has(bone) || bone in out) continue;
|
|
421
|
+
const p = places.get(bone);
|
|
422
|
+
if (p === undefined || p.end === null) continue;
|
|
423
|
+
const base = edgeLength(p.end[0] - p.at[0], p.end[1] - p.at[1]);
|
|
424
|
+
if (base === 0) continue;
|
|
425
|
+
out[bone] = pyRound(edgeLength(b[0] - a[0], b[1] - a[1]) / base, 6);
|
|
426
|
+
}
|
|
427
|
+
return out;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
interface FlatNode {
|
|
431
|
+
name: string;
|
|
432
|
+
parent: string;
|
|
433
|
+
at0: Pt;
|
|
434
|
+
end0: Pt | null;
|
|
435
|
+
theta0: number;
|
|
436
|
+
length: number;
|
|
437
|
+
inherit?: string;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/** Every bone `bones` declares, chains flattened to their links: origin, end, world direction (Spine degrees) and length. */
|
|
441
|
+
function flatBones(bones: readonly BoneEntry[]): Map<string, FlatNode> {
|
|
442
|
+
const flat = new Map<string, FlatNode>();
|
|
443
|
+
for (const b of bones) {
|
|
444
|
+
if ('chain' in b) {
|
|
445
|
+
b.points.forEach((p, k) => {
|
|
446
|
+
const name = `${b.chain}${k}`;
|
|
447
|
+
const parent = k === 0 ? b.parent : `${b.chain}${k - 1}`;
|
|
448
|
+
const at0: Pt = [p[0], p[1]];
|
|
449
|
+
const end0: Pt = k + 1 < b.points.length ? [b.points[k + 1][0], b.points[k + 1][1]] : [b.tip[0], b.tip[1]];
|
|
450
|
+
const dx = end0[0] - at0[0];
|
|
451
|
+
const dy = end0[1] - at0[1];
|
|
452
|
+
flat.set(name, { name, parent, at0, end0, theta0: (Math.atan2(-dy, dx) * 180) / Math.PI, length: Math.sqrt(dx * dx + dy * dy), inherit: b.link_inherit?.[name] });
|
|
453
|
+
});
|
|
454
|
+
} else {
|
|
455
|
+
const at0: Pt = [b.at[0], b.at[1]];
|
|
456
|
+
const end0: Pt | null = b.tip === undefined ? null : [b.tip[0], b.tip[1]];
|
|
457
|
+
const dx = end0 === null ? 0 : end0[0] - at0[0];
|
|
458
|
+
const dy = end0 === null ? 0 : end0[1] - at0[1];
|
|
459
|
+
flat.set(b.name, { name: b.name, parent: b.parent, at0, end0, theta0: end0 === null ? 0 : (Math.atan2(-dy, dx) * 180) / Math.PI, length: end0 === null ? 0 : Math.sqrt(dx * dx + dy * dy), inherit: b.inherit });
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
return flat;
|
|
463
|
+
}
|
|
464
|
+
|
|
221
465
|
/** A limb's polyline: its segments' bone origins in order, then the last bone's end when it has one. */
|
|
222
466
|
export function limbPolyline(limb: Limb, places: ReadonlyMap<string, BonePlace>): Pt[] {
|
|
223
467
|
const pts = limb.segments.map((s) => (places.get(s.bone) as BonePlace).at);
|
package/src/parts.ts
CHANGED
|
@@ -246,6 +246,10 @@ export interface AlternateSetMap {
|
|
|
246
246
|
slots: Record<string, string>;
|
|
247
247
|
hides?: string[];
|
|
248
248
|
drawn?: Record<string, number>;
|
|
249
|
+
/** Issue #539: each covered limb bone's skeleton length over its base length, when the set gives `skeleton`. */
|
|
250
|
+
drawnLength?: Record<string, number>;
|
|
251
|
+
/** Issue #539: the measured transform onto the base's torso (within the bar), when the set gives `skeleton`. */
|
|
252
|
+
registration?: { offset: [number, number]; scale: number };
|
|
249
253
|
threshold?: { yaw: number; pitch: number };
|
|
250
254
|
}
|
|
251
255
|
|
|
@@ -261,6 +265,10 @@ export interface AlternatePartsRecord {
|
|
|
261
265
|
single_run_pad?: SingleRunPad;
|
|
262
266
|
skeleton?: PosePoints;
|
|
263
267
|
drawn?: Record<string, number>;
|
|
268
|
+
/** Issue #539: as `sets.json`'s; written only when `skeleton` placed the set's limb bones. */
|
|
269
|
+
drawnLength?: Record<string, number>;
|
|
270
|
+
/** Issue #539: as `sets.json`'s; written only when `skeleton` placed the set's limb bones. */
|
|
271
|
+
registration?: { offset: [number, number]; scale: number };
|
|
264
272
|
}
|
|
265
273
|
|
|
266
274
|
export interface PartsFile {
|
|
@@ -407,6 +415,8 @@ export function serializeParts(file: PartsFile): string {
|
|
|
407
415
|
...(a.single_run_pad === undefined ? {} : { single_run_pad: Object.fromEntries(SINGLE_RUN_PAD_KEYS.map((k) => [k, (a.single_run_pad as SingleRunPad)[k]])) }),
|
|
408
416
|
...(a.skeleton === undefined ? {} : { skeleton: Object.fromEntries(KEYPOINT_NAMES.map((k) => [k, (a.skeleton as PosePoints)[k]])) }),
|
|
409
417
|
...(a.drawn === undefined ? {} : { drawn: a.drawn }),
|
|
418
|
+
...(a.drawnLength === undefined ? {} : { drawnLength: a.drawnLength }),
|
|
419
|
+
...(a.registration === undefined ? {} : { registration: { offset: a.registration.offset, scale: a.registration.scale } }),
|
|
410
420
|
})),
|
|
411
421
|
}),
|
|
412
422
|
};
|
package/src/propose.ts
CHANGED
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
import { existsSync } from 'node:fs';
|
|
128
128
|
import { join } from 'node:path';
|
|
129
129
|
import { drawText, GLYPH_H } from 'rig-c/tools/font5x7.ts';
|
|
130
|
-
import { type BoneEntry, type ConfigConstraint, type ConfigStop, contourRegionsOf, deriveBustRegions, type Limb, type MeshSpec, parseConfig, type Point, type Segment, type SkeletonSections } from './config.ts';
|
|
130
|
+
import { type BoneEntry, type ConfigConstraint, type ConfigStop, contourRegionsOf, deriveBustRegions, type Limb, type MeshSpec, type PartBinding, parseConfig, type Point, type Segment, type SkeletonSections, turnRidersByBone } from './config.ts';
|
|
131
131
|
export { contourRegionsOf, deriveBustRegions };
|
|
132
132
|
import { computeExactFrameTransforms, cropToSpineY, normaliseDegrees, toWorld } from './coords.ts';
|
|
133
133
|
import { PartsError, type Problem, refuseIfAny } from './errors.ts';
|
|
@@ -486,8 +486,17 @@ export type TurnRuns = Partial<Record<'full' | 'head', LayerSet>>;
|
|
|
486
486
|
* A rider (issue #271, {@link TURN_RIDER_TAGS}: the eye group, nose, mouth)
|
|
487
487
|
* does not carry its own median: it takes the face part's, offset by
|
|
488
488
|
* {@link turnRiderDepth} by draw order. With no face part, or more than one,
|
|
489
|
-
* the riders keep their own medians and a note says so.
|
|
490
|
-
*
|
|
489
|
+
* the riders keep their own medians and a note says so.
|
|
490
|
+
*
|
|
491
|
+
* A rider by bone (issue #535, {@link turnRidersByBone} over `binds` — the
|
|
492
|
+
* proposal's own `bones`, `meshes` and `regions`, which the CLI passes): a part
|
|
493
|
+
* every ownable bone of which another carried part hosts takes its host's
|
|
494
|
+
* drafted depth, offset by {@link turnRiderDepth} by draw order as the face's
|
|
495
|
+
* riders are, and a note names the host, the bones and its own median. The tag
|
|
496
|
+
* rule is read first: a face rider is never read as a rider by bone, nor as a
|
|
497
|
+
* host. A part bound to two hosts' bones keeps its own median and a note says
|
|
498
|
+
* so. Without `binds` no part is read as a rider by bone — the draft as it was
|
|
499
|
+
* before #535. Every other layer is its own carrier.
|
|
491
500
|
*
|
|
492
501
|
* With no part to carry, or every carried part at one depth (nothing nearer
|
|
493
502
|
* than the pivot), no `turn` is drafted and a note says why. Otherwise one note
|
|
@@ -496,7 +505,7 @@ export type TurnRuns = Partial<Record<'full' | 'head', LayerSet>>;
|
|
|
496
505
|
* each carrier the other run places more than {@link TURN_RUN_APART} of the
|
|
497
506
|
* span away.
|
|
498
507
|
*/
|
|
499
|
-
export function draftTurn(P: PartSet, runs: TurnRuns): { turn: TurnSpec | null; notes: string[] } {
|
|
508
|
+
export function draftTurn(P: PartSet, runs: TurnRuns, binds?: PartBinding): { turn: TurnSpec | null; notes: string[] } {
|
|
500
509
|
P = P.beforeLimbs();
|
|
501
510
|
const problems: Problem[] = [];
|
|
502
511
|
const read: Array<{ part: string; run: 'full' | 'head'; tag: string; base: string | null; own: number; area: number; order: number; piece: boolean }> = [];
|
|
@@ -553,11 +562,28 @@ export function draftTurn(P: PartSet, runs: TurnRuns): { turn: TurnSpec | null;
|
|
|
553
562
|
`turn: rider(s) ${riders.map((x) => `"${x.part}"`).join(', ')} keep their own See-through depth_median: ${faces.length === 0 ? `no part comes from a "${TURN_CARRIER_TAG}" layer` : `${faces.length} parts (${faces.map((x) => `"${x.part}"`).join(', ')}) come from a "${TURN_CARRIER_TAG}" layer, and which one carries them cannot be read off the parts`} — a value in config.turn.depths sets one`,
|
|
554
563
|
);
|
|
555
564
|
}
|
|
556
|
-
const
|
|
557
|
-
|
|
565
|
+
const tagRider = (x: { base: string | null }): boolean => face !== null && isRider(x);
|
|
566
|
+
const tagRows = read.map((x) => {
|
|
567
|
+
if (!tagRider(x) || face === null) return { ...x, depth: x.own, source: `own, ${x.run}:${x.tag}`, host: null as string | null };
|
|
558
568
|
const above = x.order > face.order;
|
|
559
|
-
return { ...x, depth: turnRiderDepth(face.own, above), source: `"${face.part}" ${above ? '-' : '+'} ${TURN_RIDER_OFFSET}, drawn ${above ? 'above' : 'under'} it; own ${x.run}:${x.tag} ${x.own}
|
|
569
|
+
return { ...x, depth: turnRiderDepth(face.own, above), source: `"${face.part}" ${above ? '-' : '+'} ${TURN_RIDER_OFFSET}, drawn ${above ? 'above' : 'under'} it; own ${x.run}:${x.tag} ${x.own}`, host: null as string | null };
|
|
560
570
|
});
|
|
571
|
+
// Issue #535: the riders by bone, read after the tag rule over the parts it left their own carriers.
|
|
572
|
+
const byBone = binds === undefined ? null : turnRidersByBone(binds, tagRows.filter((x) => !tagRider(x)).map((x) => ({ part: x.part, area: x.area })));
|
|
573
|
+
const rowOf = new Map(tagRows.map((x) => [x.part, x]));
|
|
574
|
+
const rows = tagRows.map((x) => {
|
|
575
|
+
const ride = byBone?.riders.get(x.part);
|
|
576
|
+
if (ride === undefined) return x;
|
|
577
|
+
const h = rowOf.get(ride.host) as (typeof tagRows)[number];
|
|
578
|
+
const above = x.order > h.order;
|
|
579
|
+
notes.push(
|
|
580
|
+
`turn: "${x.part}" rides "${ride.host}" by bone — every ownable bone it binds (${ride.bones.join(', ')}) is hosted by "${ride.host}", the carried part binding it with the most opaque px — so it is drafted at "${ride.host}"'s depth ${h.depth} ${above ? '-' : '+'} ${TURN_RIDER_OFFSET}, drawn ${above ? 'above' : 'under'} it; own ${x.run}:${x.tag} ${x.own} (issue #535)`,
|
|
581
|
+
);
|
|
582
|
+
return { ...x, depth: turnRiderDepth(h.depth, above), source: `"${ride.host}" by bone ${above ? '-' : '+'} ${TURN_RIDER_OFFSET}, drawn ${above ? 'above' : 'under'} it; own ${x.run}:${x.tag} ${x.own}`, host: ride.host };
|
|
583
|
+
});
|
|
584
|
+
for (const sp of byBone?.split ?? []) {
|
|
585
|
+
notes.push(`turn: "${sp.part}" binds ownable bones hosted by ${sp.hosts.map((h) => `"${h}"`).join(' and ')}, so it rides none of them by bone and keeps its own See-through depth_median — a value in config.turn.depths sets one (issue #535)`);
|
|
586
|
+
}
|
|
561
587
|
const pivot = turnPivot(rows);
|
|
562
588
|
const depths = Object.create(null) as Record<string, number>;
|
|
563
589
|
for (const r of rows) depths[r.part] = r.depth;
|
|
@@ -580,7 +606,7 @@ export function draftTurn(P: PartSet, runs: TurnRuns): { turn: TurnSpec | null;
|
|
|
580
606
|
// Issue #271: a carrier the other run places elsewhere is named; the run read stays the part's own.
|
|
581
607
|
const span = pivot - nearest.depth;
|
|
582
608
|
for (const r of rows) {
|
|
583
|
-
if (isRider(r) && face !== null) continue;
|
|
609
|
+
if ((isRider(r) && face !== null) || r.host !== null) continue;
|
|
584
610
|
const other = r.run === 'full' ? 'head' : 'full';
|
|
585
611
|
const there = runs[other]?.layers.find((l) => l.name === r.tag);
|
|
586
612
|
if (there === undefined || there.depth === null || there.opaquePx === 0 || !(there.depth < 1)) continue;
|
package/src/rig.ts
CHANGED
|
@@ -132,7 +132,7 @@
|
|
|
132
132
|
* touches the disk, and the same inputs give the same bytes (key order is the
|
|
133
133
|
* order the objects are built in, and every number is rounded by `pyRound`).
|
|
134
134
|
*/
|
|
135
|
-
import { type AutoSpec, type BoneEntry, type InfluenceMeshSpec, type WeightRule, type CharacterConfig, type ConfigConstraint, type ConfigStop, CONSTRAINT_FOLLOWS, constraintForRig, contourRegionsOf, type ContourSpec, DEFAULT_BUST_BONE_L, DEFAULT_BUST_BONE_R, type Point, type RibsSpec, ROOT_BONE, stopForRig, weightsABone } from './config.ts';
|
|
135
|
+
import { type AutoSpec, type BoneEntry, type InfluenceMeshSpec, type WeightRule, type CharacterConfig, type ConfigConstraint, type ConfigStop, CONSTRAINT_FOLLOWS, constraintForRig, contourRegionsOf, type ContourSpec, DEFAULT_BUST_BONE_L, DEFAULT_BUST_BONE_R, type Point, type RibsSpec, ROOT_BONE, stopForRig, turnRidersByBone, weightsABone } from './config.ts';
|
|
136
136
|
import { type BoneTransform, computeExactFrameTransforms, cropToSpineY, normaliseDegrees, toBoneLocal, toWorld } from './coords.ts';
|
|
137
137
|
import { type Problem, refuseIfAny } from './errors.ts';
|
|
138
138
|
import { eyeLineDegrees } from './headframe.ts';
|
|
@@ -166,15 +166,17 @@ import {
|
|
|
166
166
|
import { type ContourChainRibs, type ContourReport, contourMesh, type ContourRegion, type ContourRib } from './contour.ts';
|
|
167
167
|
import { type LocalInfluence, localInfluences } from './localweights.ts';
|
|
168
168
|
import { edgeLength } from './length.ts';
|
|
169
|
+
import { skeletonLimbJoints } from './limbs.ts';
|
|
169
170
|
import { artCoverage, ART_ALPHA, latticeCells, latticeMesh, latticeStray, ONE_LOOP_PASSES } from './mesh.ts';
|
|
170
171
|
import { bindFaceSurfaceDeform, BLINK, blinkHoldMisses, blinkSpan, CONTROL_SUFFIX, controlledBones, IDLE_FPS, idleMotion, type MotionSpec, moveKeysToControls } from './motion.ts';
|
|
171
172
|
import { type AlternateSetMap, PAINTING_RUN, type PartsFile, readFrom, tagOf } from './parts.ts';
|
|
173
|
+
import { readTag } from './tags.ts';
|
|
172
174
|
import { EYE_GROUP_TAGS } from './propose.ts';
|
|
173
175
|
import { alphaAbove, crop, pad, type Raster } from './raster/index.ts';
|
|
174
176
|
import { pyRound } from './round.ts';
|
|
175
177
|
import { boneHeat, type HeatDust, heatInfluences, HEAT_LIMITS, heatRow, type HeatRow, latticeSilhouette, tracedSilhouette } from './heat.ts';
|
|
176
178
|
import type { PosePoints } from './skeleton.ts';
|
|
177
|
-
import { applyFaceSurfaceDeform, FACE_RATED_BAND, TURN_BONE, type TurnSpec, turnConstraintName, turnFractions, turnTwin } from './turn.ts';
|
|
179
|
+
import { applyFaceSurfaceDeform, FACE_RATED_BAND, TURN_BONE, TURN_CARRIER_TAG, TURN_PLACES, TURN_RIDER_APART, TURN_RIDER_TAGS, turnRiderDepth, type TurnSpec, turnConstraintName, turnFractions, turnNearest, turnTwin } from './turn.ts';
|
|
178
180
|
import { DISTANCE_EXPONENT, type FloorForm, type Influence, influences, type InfluenceLimits, type MeshInfluences, meshLimits, type Segment } from './weights.ts';
|
|
179
181
|
|
|
180
182
|
/** Transparent pixels added round every part image — the reference's `PAD`. */
|
|
@@ -557,6 +559,62 @@ export function detachedRules(constraints: readonly ConfigConstraint[]): Detache
|
|
|
557
559
|
return out;
|
|
558
560
|
}
|
|
559
561
|
|
|
562
|
+
/** A fraction as the turn refusals print it: signed, 4 places. */
|
|
563
|
+
function signed4(v: number): string {
|
|
564
|
+
const r = pyRound(v, 4);
|
|
565
|
+
return `${r >= 0 ? '+' : '-'}${Math.abs(r).toFixed(4)}`;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Issue #535: `CONFIG_TURN_RIDER_DEPTH` — an authored `turn.depths` entry for a
|
|
570
|
+
* rider by bone ({@link turnRidersByBone}: a part every ownable bone of which
|
|
571
|
+
* another carried part hosts, the host being the one binding it with the most
|
|
572
|
+
* `opaque_px`) whose fraction differs from its host's by more than
|
|
573
|
+
* {@link TURN_RIDER_APART} of the dial: the ornament would float off what it is
|
|
574
|
+
* pinned to. Read here, not by the config loader, because the host is chosen by
|
|
575
|
+
* `opaque_px`, which only parts.json holds. The candidates are the parts
|
|
576
|
+
* `turn.depths` carries, in parts.json order; a face rider (issue #271: a part
|
|
577
|
+
* from an eye-group, nose or mouth layer beside exactly one part from a `face`
|
|
578
|
+
* layer) is read by its tag, never by its bones, as `propose` reads it.
|
|
579
|
+
*/
|
|
580
|
+
function turnRiderProblems(turn: TurnSpec, cfg: CharacterConfig, recs: PartsFile['parts']): Problem[] {
|
|
581
|
+
const baseOf = (from: string): string | null => {
|
|
582
|
+
const t = tagOf(from);
|
|
583
|
+
return t === null ? null : (readTag(t)?.base ?? null);
|
|
584
|
+
};
|
|
585
|
+
const faces = recs.filter((r) => baseOf(r.from) === TURN_CARRIER_TAG && r.cut_from === undefined);
|
|
586
|
+
const tagRider = (from: string): boolean => {
|
|
587
|
+
const b = baseOf(from);
|
|
588
|
+
return faces.length === 1 && b !== null && TURN_RIDER_TAGS.includes(b);
|
|
589
|
+
};
|
|
590
|
+
const carried = recs.filter((r) => Object.hasOwn(turn.depths, r.name) && !tagRider(r.from));
|
|
591
|
+
const { riders } = turnRidersByBone(cfg, carried.map((r) => ({ part: r.name, area: r.opaque_px })));
|
|
592
|
+
if (riders.size === 0) return [];
|
|
593
|
+
const nearest = turnNearest(turn.depths);
|
|
594
|
+
if (nearest === null) return [];
|
|
595
|
+
const span = turn.pivot - nearest.depth;
|
|
596
|
+
const order = recs.map((r) => r.name);
|
|
597
|
+
const frac = new Map(turnFractions(turn, order).map((f) => [f.part, f.fraction]));
|
|
598
|
+
const problems: Problem[] = [];
|
|
599
|
+
for (const [part, ride] of riders) {
|
|
600
|
+
const fp = frac.get(part) as number;
|
|
601
|
+
const fh = frac.get(ride.host) as number;
|
|
602
|
+
const diff = Math.abs(fp - fh);
|
|
603
|
+
if (!(diff > TURN_RIDER_APART)) continue;
|
|
604
|
+
const above = order.indexOf(part) > order.indexOf(ride.host);
|
|
605
|
+
const want = pyRound(turnRiderDepth(turn.depths[ride.host], above), TURN_PLACES + 3);
|
|
606
|
+
problems.push({
|
|
607
|
+
code: 'CONFIG_TURN_RIDER_DEPTH',
|
|
608
|
+
object: `config.turn.depths.${part}`,
|
|
609
|
+
detail:
|
|
610
|
+
`is ${turn.depths[part]}, fraction ${signed4(fp)} of the dial; "${part}" rides "${ride.host}" by bone — every ownable bone it binds (${ride.bones.join(', ')}) is hosted by "${ride.host}", the carried part binding it with the most opaque px — ` +
|
|
611
|
+
`whose depth ${turn.depths[ride.host]} travels ${signed4(fh)}: the difference ${pyRound(diff, 4)} is more than ${TURN_RIDER_APART} of pivot − nearest (${turn.pivot} − ${nearest.depth} = ${pyRound(span, TURN_PLACES)}), so at the dial's x the part leaves what it rides by ${pyRound(diff, 4)} of it; ` +
|
|
612
|
+
`the host's depth ${above ? '−' : '+'} 0.001 (${want}, drawn ${above ? 'above' : 'under'} it) is required, or redraft the turn with propose --full/--head`,
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
return problems;
|
|
616
|
+
}
|
|
617
|
+
|
|
560
618
|
/** One carried part of the turn control (issue #251): its depth, its fraction, and the twins that carry it. */
|
|
561
619
|
export interface TurnRow {
|
|
562
620
|
part: string;
|
|
@@ -1092,20 +1150,7 @@ export function deriveAlternateDrawn(
|
|
|
1092
1150
|
const altEyeAim = deg(pts.r_eye, pts.l_eye);
|
|
1093
1151
|
out.head = places(normaliseDegrees((turn.get('head') ?? 0) + (altEyeAim - setupEyeAim)));
|
|
1094
1152
|
}
|
|
1095
|
-
const limbPairs
|
|
1096
|
-
['sleeve_r0', pts.r_shoulder, pts.r_elbow],
|
|
1097
|
-
['sleeve_r1', pts.r_elbow, pts.r_wrist],
|
|
1098
|
-
['arm_r0', pts.r_shoulder, pts.r_elbow],
|
|
1099
|
-
['arm_r1', pts.r_elbow, pts.r_wrist],
|
|
1100
|
-
['sleeve_l0', pts.l_shoulder, pts.l_elbow],
|
|
1101
|
-
['sleeve_l1', pts.l_elbow, pts.l_wrist],
|
|
1102
|
-
['arm_l0', pts.l_shoulder, pts.l_elbow],
|
|
1103
|
-
['arm_l1', pts.l_elbow, pts.l_wrist],
|
|
1104
|
-
['leg_r0', pts.r_hip, pts.r_knee],
|
|
1105
|
-
['leg_r1', pts.r_knee, pts.r_ankle],
|
|
1106
|
-
['leg_l0', pts.l_hip, pts.l_knee],
|
|
1107
|
-
['leg_l1', pts.l_knee, pts.l_ankle],
|
|
1108
|
-
];
|
|
1153
|
+
const limbPairs = skeletonLimbJoints(pts);
|
|
1109
1154
|
for (const [bone, a, b] of limbPairs) {
|
|
1110
1155
|
if (B.has(bone)) out[bone] = places(normaliseDegrees(deg(a, b)));
|
|
1111
1156
|
}
|
|
@@ -2379,21 +2424,10 @@ export function buildRig(
|
|
|
2379
2424
|
return [wx + CX, cropToSpineY(wy, H)];
|
|
2380
2425
|
};
|
|
2381
2426
|
const pt = (q: readonly [number, number]): Point => [q[0], q[1]];
|
|
2382
|
-
const skSegs:
|
|
2383
|
-
alt.skeleton === undefined
|
|
2384
|
-
? null
|
|
2385
|
-
: {
|
|
2386
|
-
sleeve_r0: [pt(alt.skeleton.r_shoulder), pt(alt.skeleton.r_elbow)],
|
|
2387
|
-
sleeve_r1: [pt(alt.skeleton.r_elbow), pt(alt.skeleton.r_wrist)],
|
|
2388
|
-
sleeve_l0: [pt(alt.skeleton.l_shoulder), pt(alt.skeleton.l_elbow)],
|
|
2389
|
-
sleeve_l1: [pt(alt.skeleton.l_elbow), pt(alt.skeleton.l_wrist)],
|
|
2390
|
-
leg_r0: [pt(alt.skeleton.r_hip), pt(alt.skeleton.r_knee)],
|
|
2391
|
-
leg_r1: [pt(alt.skeleton.r_knee), pt(alt.skeleton.r_ankle)],
|
|
2392
|
-
leg_l0: [pt(alt.skeleton.l_hip), pt(alt.skeleton.l_knee)],
|
|
2393
|
-
leg_l1: [pt(alt.skeleton.l_knee), pt(alt.skeleton.l_ankle)],
|
|
2394
|
-
};
|
|
2427
|
+
const skSegs: Map<string, readonly [Point, Point]> | null =
|
|
2428
|
+
alt.skeleton === undefined ? null : new Map(skeletonLimbJoints(alt.skeleton).map(([bone, a, b]) => [bone, [pt(a), pt(b)] as const]));
|
|
2395
2429
|
segs = segs.map((s) => {
|
|
2396
|
-
const skPair = skSegs?.
|
|
2430
|
+
const skPair = skSegs?.get(s.bone);
|
|
2397
2431
|
return skPair !== undefined ? { bone: s.bone, a: skPair[0], b: skPair[1] } : { bone: s.bone, a: movePt(s.bone, s.a), b: movePt(s.bone, s.b) };
|
|
2398
2432
|
});
|
|
2399
2433
|
const nonSkirt = segs.filter((s) => !hipChainLinks.has(s.bone));
|
|
@@ -2489,6 +2523,8 @@ export function buildRig(
|
|
|
2489
2523
|
slots: slotMap,
|
|
2490
2524
|
...(hideList.length > 0 ? { hides: hideList } : {}),
|
|
2491
2525
|
...(drawn === undefined ? {} : { drawn }),
|
|
2526
|
+
...(alt.drawnLength === undefined ? {} : { drawnLength: { ...alt.drawnLength } }),
|
|
2527
|
+
...(alt.registration === undefined ? {} : { registration: { offset: [alt.registration.offset[0], alt.registration.offset[1]], scale: alt.registration.scale } }),
|
|
2492
2528
|
...(coversFace && cfg.turn !== undefined ? { threshold: { ...FACE_RATED_BAND } } : {}),
|
|
2493
2529
|
};
|
|
2494
2530
|
}
|
|
@@ -2506,6 +2542,7 @@ export function buildRig(
|
|
|
2506
2542
|
const stops = cfg.stops === undefined ? null : applyStops(cfg.stops, chains, bones, slots, skin);
|
|
2507
2543
|
// ---- the turn control (issue #251) -------------------------------------
|
|
2508
2544
|
// Only when the config has `turn`: every other build adds nothing here, so no byte moves.
|
|
2545
|
+
if (cfg.turn !== undefined) refuseIfAny(turnRiderProblems(cfg.turn, cfg, parts.parts));
|
|
2509
2546
|
const turned = cfg.turn === undefined ? null : applyTurn(cfg.turn, parts.parts.map((p) => p.name), bones, slots, skin, cfg.constraints ?? []);
|
|
2510
2547
|
|
|
2511
2548
|
const name = `${cfg.key}_painting`;
|
package/src/turn.ts
CHANGED
|
@@ -63,6 +63,15 @@ export function turnRiderDepth(carrier: number, above: boolean): number {
|
|
|
63
63
|
return above ? carrier - TURN_RIDER_OFFSET : carrier + TURN_RIDER_OFFSET;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
/**
|
|
67
|
+
* The share of the span (`pivot − nearest`) past which a rider by bone's
|
|
68
|
+
* fraction (issue #535: a part whose every ownable bone another carried part
|
|
69
|
+
* hosts, `turnRidersByBone` in `src/config.ts`) is refused for differing from
|
|
70
|
+
* its host's (`CONFIG_TURN_RIDER_DEPTH`, the rig stage). #535's judgment line,
|
|
71
|
+
* set before it was measured: the same bar as `propose`'s `TURN_RUN_APART`.
|
|
72
|
+
*/
|
|
73
|
+
export const TURN_RIDER_APART = 0.1;
|
|
74
|
+
|
|
66
75
|
/** The control bone the rig stage adds under `root` when the config has `turn`: nothing keys it, and its local x is the dial. */
|
|
67
76
|
export const TURN_BONE = 'turn';
|
|
68
77
|
|