rig-parts 1.43.0 → 1.45.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 +66 -0
- package/docs/AUTHORING.md +34 -1
- package/docs/STABILITY.md +2 -0
- package/package.json +1 -1
- package/src/build.ts +45 -17
- package/src/limbs.ts +244 -0
- package/src/parts.ts +10 -0
- package/src/remesh.ts +26 -11
- package/src/retune.ts +418 -0
- package/src/rig.ts +7 -28
package/cli.ts
CHANGED
|
@@ -31,6 +31,7 @@ import { basisLines, branchSqueezeLine, checkProposal, compare, compareLines, DE
|
|
|
31
31
|
import { BASIS_FILE, BASIS_SPEC, basisFile, basisLine, coverageLines, serializeBasis } from './src/diagnostics.ts';
|
|
32
32
|
import { BEND_DEGREES, BEND_WORST_SHARE, DUST_MAX_PX, DUST_MAX_SHARE, IDLE_BOUND_PX, MESH_DRAFT_REPORT, MESH_DRAFT_SPEC, meshDraftStage, MORE_TRIANGLES_FLAG, TOLERANCE_FIGURE_DIVISOR } from './src/meshdraft.ts';
|
|
33
33
|
import { PROVENANCE_FILE, REMESH_SPEC, remeshStage } from './src/remesh.ts';
|
|
34
|
+
import { RETUNE_FILE, RETUNE_SPEC, retuneStage } from './src/retune.ts';
|
|
34
35
|
import { checkPainting } from './src/paintcheck.ts';
|
|
35
36
|
import { readPng, writePng } from './src/raster/png.ts';
|
|
36
37
|
import { REQUIREMENTS_SENTENCE } from './src/requirements.ts';
|
|
@@ -384,6 +385,30 @@ usage:
|
|
|
384
385
|
REMESH_DELTA_TOPOLOGY). No config entry is built: the baseline is the
|
|
385
386
|
input itself; the splice, the gate and check are as for --mesh.
|
|
386
387
|
|
|
388
|
+
rig-parts retune --rig <dir> --config <config.json> --parts <dir> --out <dir>
|
|
389
|
+
[--requirements <file.json>] [--idle-keys ctl|direct]
|
|
390
|
+
[--page-edges pot|free] [--pack-shape rect|polygon]
|
|
391
|
+
Splice the constraints and the idle a config states onto a gated rig
|
|
392
|
+
(the directory rig writes) and write a new revision into --out, which
|
|
393
|
+
must not exist (RETUNE_OUT_FRESH); the input is never written. The
|
|
394
|
+
config is built once through the rig stage (RETUNE_CONFIG_REFUSED,
|
|
395
|
+
quoting each problem), and that build must state the input's stops,
|
|
396
|
+
bones, slots, skeleton, images, every invariant but detached and every
|
|
397
|
+
byte of motion.json but animations.idle (RETUNE_REQUEST_HELD): a moved
|
|
398
|
+
bone, a redrawn image, a stops change or an animations_from change is
|
|
399
|
+
no retune. No attachment is compared — the input's meshes are carried
|
|
400
|
+
over as bytes, repairs included, and a meshes change in the config is
|
|
401
|
+
never read (remesh is a mesh's producer). rig.json takes the build's
|
|
402
|
+
constraints and invariants.detached, motion.json its animations.idle,
|
|
403
|
+
every other byte is the input's (RETUNE_PRESERVED); rigc's build gate
|
|
404
|
+
passes over the revision (RETUNE_RIGC_GREEN); check measures every bar
|
|
405
|
+
on it that it measures on the input and fails none the input meets
|
|
406
|
+
(RETUNE_CHECK_HELD). --out receives the revision and ${RETUNE_FILE}
|
|
407
|
+
(spec "${RETUNE_SPEC}": the request, both versions, every input file's
|
|
408
|
+
SHA-256, what was held, which constraint fields and idle tracks changed,
|
|
409
|
+
both checks and their scope) — no path and no clock, so the same request
|
|
410
|
+
writes the same bytes. Prints what changed and a hash table of every file.
|
|
411
|
+
|
|
387
412
|
rig-parts check --rig <dir> --out <dir> [--parts <dir>] [--source <painting.png>]
|
|
388
413
|
[--page-edges pot|free] [--pack-shape rect|polygon]
|
|
389
414
|
[--requirements <file.json>] [--seam-pairs] [--keep-stills]
|
|
@@ -848,6 +873,7 @@ const TAKES = {
|
|
|
848
873
|
compose: { valued: ['--scene', '--out', '--requirements', '--accept'], switches: [] },
|
|
849
874
|
'mesh-draft': { valued: ['--config', '--parts', '--out', '--requirements', '--idle-keys', '--page-edges', '--pack-shape'], switches: ['--more-triangles'] },
|
|
850
875
|
remesh: { valued: ['--rig', '--config', '--parts', '--part', '--mesh', '--delta', '--out', '--requirements', '--idle-keys', '--page-edges', '--pack-shape'], switches: [] },
|
|
876
|
+
retune: { valued: ['--rig', '--config', '--parts', '--out', '--requirements', '--idle-keys', '--page-edges', '--pack-shape'], switches: [] },
|
|
851
877
|
painting: { valued: ['--keypoints', '--person'], switches: [] },
|
|
852
878
|
} as const satisfies Record<string, { valued: readonly string[]; switches: readonly string[] }>;
|
|
853
879
|
|
|
@@ -1700,6 +1726,45 @@ function cmdRemesh(args: string[]): number {
|
|
|
1700
1726
|
}
|
|
1701
1727
|
}
|
|
1702
1728
|
|
|
1729
|
+
/** `retune` (issue #527): the constraints and the idle a config states, spliced onto a gated rig, into a new revision. */
|
|
1730
|
+
function cmdRetune(args: string[]): number {
|
|
1731
|
+
const f = flags(args, 'retune', ['--rig', '--config', '--parts', '--out']);
|
|
1732
|
+
if (typeof f === 'string') return usage(f);
|
|
1733
|
+
const keys = idleKeysOf(f.get('--idle-keys'));
|
|
1734
|
+
if (!isIdleKeys(keys)) return usage(keys);
|
|
1735
|
+
const edges = pageEdgesOf(f.get('--page-edges'));
|
|
1736
|
+
if (!isPageEdges(edges)) return usage(edges);
|
|
1737
|
+
const shape = packShapeOf(f.get('--pack-shape'));
|
|
1738
|
+
if (!isPackShape(shape)) return usage(shape);
|
|
1739
|
+
let bin: string;
|
|
1740
|
+
try {
|
|
1741
|
+
bin = findRigc(import.meta.dir, process.env.PATH ?? '');
|
|
1742
|
+
} catch (err) {
|
|
1743
|
+
return printRefusal(err);
|
|
1744
|
+
}
|
|
1745
|
+
const runner = rigcRunner(bin);
|
|
1746
|
+
const said = runner(['--version']);
|
|
1747
|
+
const rigcVersion = said.status === 0 ? (said.out.trim().split('\n')[0] ?? '') : '';
|
|
1748
|
+
if (rigcVersion === '') return printRefusal(new PartsError([{ code: 'RETUNE_RIGC_GREEN', object: 'rigc --version', detail: `exited ${said.status}${rigcRanClause(said)}; the provenance names the rigc that gated the revision, so its version is required` }]));
|
|
1749
|
+
const scratch = mkdtempSync(join(tmpdir(), 'rig-parts-retune-'));
|
|
1750
|
+
try {
|
|
1751
|
+
const req = f.get('--requirements');
|
|
1752
|
+
retuneStage(
|
|
1753
|
+
{ rig: f.get('--rig') as string, config: f.get('--config') as string, parts: f.get('--parts') as string, out: f.get('--out') as string, idleKeys: keys, pageEdges: edges, packShape: shape, ...(req === undefined ? {} : { requirements: req }) },
|
|
1754
|
+
runner,
|
|
1755
|
+
bin,
|
|
1756
|
+
{ parts: version(), rigc: rigcVersion },
|
|
1757
|
+
scratch,
|
|
1758
|
+
console.log,
|
|
1759
|
+
);
|
|
1760
|
+
return EXIT_OK;
|
|
1761
|
+
} catch (err) {
|
|
1762
|
+
return printRefusal(err);
|
|
1763
|
+
} finally {
|
|
1764
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1703
1768
|
/**
|
|
1704
1769
|
* `painting --keypoints <k.json> [--person <id>] <painting.png>` (issue #350): what the painting must be before
|
|
1705
1770
|
* See-through runs on it, read off its pixels and the body-18 joints `propose --keypoints` reads. Writes nothing.
|
|
@@ -1770,6 +1835,7 @@ function main(argv: string[]): number | Promise<number> {
|
|
|
1770
1835
|
if (command === 'compose') return cmdCompose(rest);
|
|
1771
1836
|
if (command === 'mesh-draft') return cmdMeshDraft(rest);
|
|
1772
1837
|
if (command === 'remesh') return cmdRemesh(rest);
|
|
1838
|
+
if (command === 'retune') return cmdRetune(rest);
|
|
1773
1839
|
if (command === 'painting') return cmdPainting(rest);
|
|
1774
1840
|
if (command === 'guide') return cmdGuide(rest);
|
|
1775
1841
|
const later = LATER.find(([name]) => name === command);
|
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 |
|
|
@@ -2835,6 +2835,7 @@ says why each requirement exists and what breaks without it.
|
|
|
2835
2835
|
| <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
2836
|
| <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
2837
|
| <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 |
|
|
2838
|
+
| <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
2839
|
| <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
2840
|
|
|
2840
2841
|
### propose
|
|
@@ -2979,6 +2980,38 @@ gate and `check` are the `--mesh` path's. A constraint is a statement about this
|
|
|
2979
2980
|
revision's triangulation only: the rig spec has no field for it, so a later edit of the
|
|
2980
2981
|
revision reads it as any other edge.
|
|
2981
2982
|
|
|
2983
|
+
### retune
|
|
2984
|
+
|
|
2985
|
+
| rule | means | change |
|
|
2986
|
+
| --- | --- | --- |
|
|
2987
|
+
| <a id="RETUNE_OUT_FRESH"></a>`RETUNE_OUT_FRESH` | `--out` exists, or lies inside `--rig`: a revision is a new directory beside the input, never written over it | name a directory that does not exist yet |
|
|
2988
|
+
| <a id="RETUNE_INPUT_PRESENT"></a>`RETUNE_INPUT_PRESENT` | `--rig` is not the directory `rig` writes: `rig.json`, `motion.json`, `mesh_report.json` or `images/` is missing | point `--rig` at a `rig` output (`build`'s `rig/`, or a `remesh` or `retune` revision) |
|
|
2989
|
+
| <a id="RETUNE_INPUT_WRITTEN"></a>`RETUNE_INPUT_WRITTEN` | `rig.json` or `motion.json` is not the text this package's writer prints for its value (reformatted, or written by something else); the revision is spliced as text, so it could not carry every other byte over | use the files as `rig` wrote them |
|
|
2990
|
+
| <a id="RETUNE_CONFIG_REFUSED"></a>`RETUNE_CONFIG_REFUSED` | the rig stage refused the config as written — the loader, a mesh's own checks, an `auto` mesh's motion gate under the new idle, or rigc's gate; each problem is quoted, and nothing was written | change the field the quoted problem names |
|
|
2991
|
+
| <a id="RETUNE_REQUEST_HELD"></a>`RETUNE_REQUEST_HELD` | the config's build does not state the input's `stops`, `bones` (a bone moved, renamed, added, re-inherited, or a `<bone>_ctl` added or dropped), `slots`, `skeleton`, `images`, an image file, an `invariants` entry other than `detached`, or a byte of `motion.json` outside `animations.idle` (`animations_from`, the groups, the easings, the face deform); the first differing leaf is named | make it a config change and rebuild with `rig --config` |
|
|
2992
|
+
| <a id="RETUNE_PRESERVED"></a>`RETUNE_PRESERVED` | the spliced revision differs from the input outside `rig.json`'s `constraints` and `invariants.detached` and `motion.json`'s `animations.idle`; the file and the path that moved are named | a defect in this package: report it with the line |
|
|
2993
|
+
| <a id="RETUNE_RIGC_GREEN"></a>`RETUNE_RIGC_GREEN` | rigc's build gate refused the revision (its lines quoted), or `rigc --version` named no version for the provenance | read rigc's line; nothing was written |
|
|
2994
|
+
| <a id="RETUNE_CHECK_HELD"></a>`RETUNE_CHECK_HELD` | `check` on the revision did not measure a bar it measured on the input, or failed a bar the input met; the revision's own FAIL line is quoted | soften the constraint or the idle track the line names |
|
|
2995
|
+
|
|
2996
|
+
A retune replaces a rig's physics and its idle and nothing else. The config is built
|
|
2997
|
+
once through the rig stage; from that build `rig.json` takes `constraints` and
|
|
2998
|
+
`invariants.detached` (which the rig stage derives from the constraints), and
|
|
2999
|
+
`motion.json` takes `animations.idle`. Every other byte is the input's: every
|
|
3000
|
+
attachment and image, every `mesh_report.json` row and every other animation, so a
|
|
3001
|
+
mesh the config does not reproduce — a `remesh` revision, or a repair accepted after
|
|
3002
|
+
the config was written — is carried over as it is. What the build must state as the
|
|
3003
|
+
input does is held, and a config that moves it is refused rather than half-applied:
|
|
3004
|
+
a `stops` change (it rewires bones, slots and weights onto the drawn links
|
|
3005
|
+
`<link>_d`, so it is outside what a retune holds byte for byte), a moved, renamed or
|
|
3006
|
+
re-`inherit`ed bone, a new control bone under `--idle-keys ctl`, a redrawn image, or a
|
|
3007
|
+
change to `animations_from`. No mesh is compared or written, so a `meshes` change in
|
|
3008
|
+
the config is left out of the revision — `retune.json`'s `held.not_compared` says so;
|
|
3009
|
+
`remesh` is the producer of a mesh. `retune.json` names the input's SHA-256 per file,
|
|
3010
|
+
what was held, which constraint fields changed (and which constraints were added or
|
|
3011
|
+
removed), how many idle tracks changed and the idle's duration before and after, both
|
|
3012
|
+
versions and both checks, and quotes `check`'s own physics line as the scope of the
|
|
3013
|
+
revision's check.
|
|
3014
|
+
|
|
2982
3015
|
### rig-c's mesh refusals, quoted in a line
|
|
2983
3016
|
|
|
2984
3017
|
rig-c's mesh library refuses a malformed input by throwing with a code of its own. This
|
package/docs/STABILITY.md
CHANGED
|
@@ -62,6 +62,7 @@ defaults are the help's too, and none is guessed from the art.
|
|
|
62
62
|
| `compose` | `--scene`, `--out`; optional `--requirements`, `--accept` |
|
|
63
63
|
| `mesh-draft` | `--config`, `--parts`, `--out`; optional `--requirements`, `--idle-keys` (ctl, direct), `--page-edges` (pot, free), `--pack-shape` (rect, polygon), `--more-triangles` |
|
|
64
64
|
| `remesh` | `--rig`, `--config`, `--parts`, `--part`, `--out`, and one of `--mesh` or `--delta` (issue #526); optional `--requirements`, `--idle-keys` (ctl, direct), `--page-edges` (pot, free), `--pack-shape` (rect, polygon) |
|
|
65
|
+
| `retune` | `--rig`, `--config`, `--parts`, `--out`; optional `--requirements`, `--idle-keys` (ctl, direct), `--page-edges` (pot, free), `--pack-shape` (rect, polygon) |
|
|
65
66
|
| `painting` | one positional path, the painting; `--keypoints`; optional `--person` |
|
|
66
67
|
| `guide` | one positional argument: a rule name, `§<n>`, `§<n>.<m>` or `§<n>.<m>.<k>` |
|
|
67
68
|
| (none) | `--version`, `--help` |
|
|
@@ -199,6 +200,7 @@ every number) are AUTHORING §3's tables, and the loader refuses any other by na
|
|
|
199
200
|
| `basis.json` | `propose` | spec `spine-parts-basis/1` |
|
|
200
201
|
| `config.json`, `mesh_draft.json` | `mesh-draft` | `config.json` is the config read, byte for byte, but for each drafted part's `meshes` entry; `mesh_draft.json` is spec `rig-parts-mesh-draft/1`: `rules`, `lattice_check`, `draft_check`, `figure_overdraw`, and per lattice part `part`, `mode`, `lattice`, `candidate` (with `bridges` — `units`, `joins` of `span` and `area_px2`, `area_px2`, `overdraw`, and `faint` only when an island was left out as faint — only when the candidate is a bridged one, issue #326), `delta` (under `--more-triangles` only), `readings`, `gate` (each line's `reading`, `pass`, `text`, `margin`), `note`; and `not_compared` (issue #307), only when the config holds an `auto` or `contour` entry: per such entry, in config order, `part`, `mode` and `note` — the part was neither drafted nor compared, and a config of lattices alone writes no such key |
|
|
201
202
|
| `rig.json`, `motion.json`, `mesh_report.json`, `images/`, `remesh.json` | `remesh` | the input revision's files, `rig.json` and `mesh_report.json` with the part's attachment and row replaced (under `--delta` the row is the input's with its counts, `bones` and influences recomputed and `mode` "delta"), every other file byte for byte; `remesh.json` is spec `rig-parts-remesh/1`: `request` (`part`, `mesh`, `mesh_sha256`, `idle_keys`, `page_edges`, `pack_shape`; under `--delta`, issue #526: `part`, `delta` — the mesh edit as read — `delta_sha256`, `ops`, `applied` — `moved`, `added`, `removed`, `constrained` — `idle_keys`, `page_edges`, `pack_shape`), `versions` (`parts`, `rigc`), `input` (`rig` — `path`, `bytes`, `sha256` per file — `config_sha256`, `parts_json_sha256`), `baseline` (`reproduced`, `not_compared`; under `--delta` `reproduced` holds one sentence: no config is built, the input is the baseline), `target` (`before`, `after`: `vertices`, `triangles`, `hull`), `preserved` (`identical`, `spliced`), `revision` (per file as `input.rig`), `check` (`input`, `revision`: `pass`, `measured`, `not_met`, `skipped`, `physics`; `scope`) |
|
|
203
|
+
| `rig.json`, `motion.json`, `mesh_report.json`, `images/`, `retune.json` | `retune` | the input revision's files, `rig.json` with `constraints` and `invariants.detached` replaced and `motion.json` with `animations.idle` replaced by the config's build, every other file byte for byte; `retune.json` is spec `rig-parts-retune/1`: `request` (`idle_keys`, `page_edges`, `pack_shape`), `versions` (`parts`, `rigc`), `input` (`rig` — `path`, `bytes`, `sha256` per file — `config_sha256`, `parts_json_sha256`), `held` (`compared`, `not_compared`), `changed` (`constraints` — each `name`, `type`, `fields` — `added`, `removed`, `idle`: `tracks_changed`, `duration` as before and after), `preserved` (`identical`, `spliced`), `revision` (per file as `input.rig`), `check` (`input`, `revision`: `pass`, `measured`, `not_met`, `skipped`, `physics`; `scope`) |
|
|
202
204
|
| the scene report | `compose` | spec `spine-parts-scene-report/1` |
|
|
203
205
|
| `idle.png`, `idle-indexed.png`, `idle.gif` | `loop`, `build --loop` | APNG and GIF encodings of the rendered idle |
|
|
204
206
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rig-parts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.45.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/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/remesh.ts
CHANGED
|
@@ -447,6 +447,12 @@ export function preservedProblems(input: FileTree, revision: FileTree, part: str
|
|
|
447
447
|
return out;
|
|
448
448
|
}
|
|
449
449
|
|
|
450
|
+
/** The codes the shared readings below refuse with, by the revising command that runs them (`remesh`, `retune`). */
|
|
451
|
+
export const REVISION_CODES = {
|
|
452
|
+
remesh: { inputPresent: 'REMESH_INPUT_PRESENT', inputWritten: 'REMESH_INPUT_WRITTEN', checkHeld: 'REMESH_CHECK_HELD' },
|
|
453
|
+
retune: { inputPresent: 'RETUNE_INPUT_PRESENT', inputWritten: 'RETUNE_INPUT_WRITTEN', checkHeld: 'RETUNE_CHECK_HELD' },
|
|
454
|
+
} as const;
|
|
455
|
+
|
|
450
456
|
/** One side of the check block, read off a check report. */
|
|
451
457
|
export function checkSide(r: CheckReport): CheckSide {
|
|
452
458
|
return {
|
|
@@ -458,19 +464,23 @@ export function checkSide(r: CheckReport): CheckSide {
|
|
|
458
464
|
};
|
|
459
465
|
}
|
|
460
466
|
|
|
461
|
-
/**
|
|
462
|
-
|
|
467
|
+
/**
|
|
468
|
+
* Step 7: every bar the input measured is measured on the revision, and no bar the input met is failed by it. `op`
|
|
469
|
+
* names the revising command (`retune` reuses this reading under its own code, `RETUNE_CHECK_HELD`).
|
|
470
|
+
*/
|
|
471
|
+
export function checkHeldProblems(input: CheckSide, revision: CheckSide, problems: readonly Problem[], op: 'remesh' | 'retune' = 'remesh'): Problem[] {
|
|
472
|
+
const code = REVISION_CODES[op].checkHeld;
|
|
463
473
|
const out: Problem[] = [];
|
|
464
474
|
for (const bar of input.measured) {
|
|
465
475
|
if (!revision.measured.includes(bar)) {
|
|
466
476
|
const why = revision.skipped.find((s) => s.bar === bar)?.reason ?? 'not measured';
|
|
467
|
-
out.push({ code
|
|
477
|
+
out.push({ code, object: `check bar ${bar}`, detail: `measured on the input and not on the revision (${why}); the revision is held to every bar the input was` });
|
|
468
478
|
}
|
|
469
479
|
}
|
|
470
480
|
for (const bar of revision.not_met) {
|
|
471
481
|
if (input.not_met.includes(bar)) continue;
|
|
472
482
|
const quoted = problems.filter((p) => p.code.includes(bar) || p.object.includes(bar)).map(problemLine);
|
|
473
|
-
out.push({ code
|
|
483
|
+
out.push({ code, object: `check bar ${bar}`, detail: `met on the input and not on the revision${quoted.length > 0 ? `: ${quoted.join(' | ')}` : ''}; a ${op} may not fail a bar its input meets` });
|
|
474
484
|
}
|
|
475
485
|
return out;
|
|
476
486
|
}
|
|
@@ -511,24 +521,29 @@ export function modelAttachmentHash(modelText: string, part: string): string | n
|
|
|
511
521
|
return entry === undefined ? null : createHash('sha256').update(JSON.stringify(entry)).digest('hex');
|
|
512
522
|
}
|
|
513
523
|
|
|
514
|
-
/**
|
|
515
|
-
|
|
524
|
+
/**
|
|
525
|
+
* Step 1's tree rules: the files `rig` writes are present, and the ones the splice rewrites (`spliced`) are this
|
|
526
|
+
* writer's bytes. `op` names the revising command, whose codes these are (`retune` splices `rig.json` and `motion.json`).
|
|
527
|
+
*/
|
|
528
|
+
export function inputTreeProblems(tree: FileTree, root: string, op: 'remesh' | 'retune' = 'remesh', spliced: readonly string[] = ['rig.json', 'mesh_report.json']): Problem[] {
|
|
529
|
+
const present = REVISION_CODES[op].inputPresent;
|
|
530
|
+
const writtenCode = REVISION_CODES[op].inputWritten;
|
|
516
531
|
const out: Problem[] = [];
|
|
517
532
|
for (const f of RIG_TREE_FILES) {
|
|
518
|
-
if (!tree.has(f)) out.push({ code:
|
|
533
|
+
if (!tree.has(f)) out.push({ code: present, object: `${root}/${f}`, detail: 'is absent; the input revision is the directory rig writes — rig.json, motion.json, mesh_report.json and images/' });
|
|
519
534
|
}
|
|
520
|
-
if (![...tree.keys()].some((k) => k.startsWith('images/'))) out.push({ code:
|
|
521
|
-
for (const f of
|
|
535
|
+
if (![...tree.keys()].some((k) => k.startsWith('images/'))) out.push({ code: present, object: `${root}/images/`, detail: 'holds no image; the input revision is the directory rig writes' });
|
|
536
|
+
for (const f of spliced) {
|
|
522
537
|
const b = tree.get(f);
|
|
523
538
|
if (b === undefined) continue;
|
|
524
539
|
let value: unknown;
|
|
525
540
|
try {
|
|
526
541
|
value = JSON.parse(text(b));
|
|
527
542
|
} catch (err) {
|
|
528
|
-
out.push({ code:
|
|
543
|
+
out.push({ code: writtenCode, object: `${root}/${f}`, detail: `does not parse as JSON: ${(err as Error).message}` });
|
|
529
544
|
continue;
|
|
530
545
|
}
|
|
531
|
-
if (rigJsonText(value) !== text(b)) out.push({ code:
|
|
546
|
+
if (rigJsonText(value) !== text(b)) out.push({ code: writtenCode, object: `${root}/${f}`, detail: 'is not the text this package\'s writer prints for its value; the revision is spliced as text, so an input reformatted by hand cannot be carried over byte for byte' });
|
|
532
547
|
}
|
|
533
548
|
return out;
|
|
534
549
|
}
|
package/src/retune.ts
ADDED
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `rig-parts retune` (issue #527): splice the constraints and the idle a config states onto an existing, gated rig,
|
|
3
|
+
* and write a new package revision beside the input — every other byte of the input carried over, the input never
|
|
4
|
+
* written. The remesh (`src/remesh.ts`) of physics and motion: a reviewer's damping, wind, strength or
|
|
5
|
+
* idle-track change reaches the rig without a whole rebuild, which would drop every repair the config does not
|
|
6
|
+
* reproduce.
|
|
7
|
+
*
|
|
8
|
+
* ## The steps, each one a refusal by name
|
|
9
|
+
*
|
|
10
|
+
* 1. **The input** ({@link readTree}): `--rig` holds `rig.json`, `motion.json`, `mesh_report.json` and `images/`, as
|
|
11
|
+
* `rig` writes them; `rig.json` and `motion.json` must be the bytes this package's writer prints for what they
|
|
12
|
+
* parse to (`RETUNE_INPUT_WRITTEN`), since the revision is spliced as text. `--out` must not exist
|
|
13
|
+
* (`RETUNE_OUT_FRESH`).
|
|
14
|
+
* 2. **The rebuild**: the config as written is built through the rig stage — one build, every check it owns — and a
|
|
15
|
+
* refusal there is quoted (`RETUNE_CONFIG_REFUSED`).
|
|
16
|
+
* 3. **The hold** ({@link holdProblems}): the rebuild must state the input's `stops`, `bones` (names, parents,
|
|
17
|
+
* transforms, `inherit`), `slots`, `skeleton` and `images`, every image file, every `invariants` entry but
|
|
18
|
+
* `detached`, and every byte of `motion.json` but `animations.idle` (`RETUNE_REQUEST_HELD`, naming the first
|
|
19
|
+
* difference). A `stops` change rewires bones, slots and weights onto drawn links, so it is no retune. No
|
|
20
|
+
* attachment is compared: the input's meshes may be repairs the config does not reproduce, and they are carried
|
|
21
|
+
* over as bytes — so a `meshes` change in the config is never read into the revision (`remesh` is its producer).
|
|
22
|
+
* 4. **The splice** ({@link spliceRevision}): the input's `rig.json` with `constraints` and `invariants.detached`
|
|
23
|
+
* (derived from the constraints, rig.ts's `detachedRules`) the rebuild's, and its `motion.json` with
|
|
24
|
+
* `animations.idle` the rebuild's; every other file is the input's bytes.
|
|
25
|
+
* 5. **The preserve assertion** ({@link preservedProblems}): every file but those two byte-identical to the input's;
|
|
26
|
+
* `rig.json` identical outside `constraints` and `invariants.detached`, `motion.json` outside `animations.idle`
|
|
27
|
+
* (`RETUNE_PRESERVED`, naming the first path that moved).
|
|
28
|
+
* 6. **The gate and check**: the revision goes through rigc's build gate (`RETUNE_RIGC_GREEN`) and through `check`
|
|
29
|
+
* beside the input; every bar the input measured is measured, none the input met is failed (`RETUNE_CHECK_HELD`).
|
|
30
|
+
* 7. **The write**: `--out` receives the revision's files and {@link RETUNE_FILE} — spec {@link RETUNE_SPEC} — with
|
|
31
|
+
* no path and no clock in it, so a second identical request writes the same bytes.
|
|
32
|
+
*
|
|
33
|
+
* Pure in the sense `src/` is held to: rigc runs as a process, but the process is injected, as `src/build.ts` takes it.
|
|
34
|
+
*/
|
|
35
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
36
|
+
import { dirname, join, resolve, sep } from 'node:path';
|
|
37
|
+
import { checkStage, gateThroughRigc, type Log, rigStage } from './build.ts';
|
|
38
|
+
import { type CheckReport, DEFAULT_PACK_SHAPE, DEFAULT_PAGE_EDGES, type PackShape, type PageEdges, rigcRanClause, type RigcRunner } from './check.ts';
|
|
39
|
+
import { PartsError, type Problem, problemLine, refuseIfAny } from './errors.ts';
|
|
40
|
+
import { type CheckSide, checkHeldProblems, checkSide, checkScope, type FileTree, firstDifference, type HashRow, hashRows, inputTreeProblems, perturbed, readTree, sha256 } from './remesh.ts';
|
|
41
|
+
import { DEFAULT_IDLE_KEYS, type IdleKeys, rigJsonText } from './rig.ts';
|
|
42
|
+
|
|
43
|
+
/** The provenance file's spec. */
|
|
44
|
+
export const RETUNE_SPEC = 'rig-parts-retune/1';
|
|
45
|
+
|
|
46
|
+
/** The provenance file, at the revision's root beside `rig.json`. */
|
|
47
|
+
export const RETUNE_FILE = 'retune.json';
|
|
48
|
+
|
|
49
|
+
/** The two files the splice rewrites; every other file of the input is carried over as bytes. */
|
|
50
|
+
export const RETUNE_SPLICED = ['rig.json', 'motion.json'] as const;
|
|
51
|
+
|
|
52
|
+
/** What the hold compares between the input and the rebuild (step 3), as the provenance lists it. */
|
|
53
|
+
export const RETUNE_HELD = ['rig.json stops', 'rig.json bones', 'rig.json slots', 'rig.json skeleton', 'rig.json images', 'rig.json invariants but detached', 'images/', 'motion.json but animations.idle'] as const;
|
|
54
|
+
|
|
55
|
+
/** The provenance's sentence for what the hold does not compare. */
|
|
56
|
+
export const RETUNE_NOT_COMPARED =
|
|
57
|
+
'every attachment and every mesh_report.json row: carried over from the input as bytes, whether or not the config reproduces it; a meshes change in the config is never read into the revision (remesh is the producer of a mesh)';
|
|
58
|
+
|
|
59
|
+
export interface RetuneInput {
|
|
60
|
+
/** The input revision: the directory `rig` wrote (`rig.json`, `motion.json`, `mesh_report.json`, `images/`). */
|
|
61
|
+
rig: string;
|
|
62
|
+
/** The config whose constraints and idle the revision takes; every other field must reproduce the input. */
|
|
63
|
+
config: string;
|
|
64
|
+
/** The directory holding `parts.json` and `parts/` the input was built from. */
|
|
65
|
+
parts: string;
|
|
66
|
+
/** The new revision's directory; it must not exist. */
|
|
67
|
+
out: string;
|
|
68
|
+
idleKeys?: IdleKeys;
|
|
69
|
+
pageEdges?: PageEdges;
|
|
70
|
+
packShape?: PackShape;
|
|
71
|
+
requirements?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Planted faults for the selftest (issue #527) — never set by the CLI: `perturb` changes the first uv of the named
|
|
76
|
+
* part's attachment in the revision after the splice, `skipPreserve` takes the preserve assertion out and `skipHold`
|
|
77
|
+
* the hold, so the selftest can show what each one stops and what stops the revision without it.
|
|
78
|
+
*/
|
|
79
|
+
export interface RetunePlant {
|
|
80
|
+
perturb?: string;
|
|
81
|
+
skipPreserve?: boolean;
|
|
82
|
+
skipHold?: boolean;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** One constraint the request changed: its name and type, and each field whose value moved, in the rebuild's order. */
|
|
86
|
+
export interface ConstraintChange {
|
|
87
|
+
name: string;
|
|
88
|
+
type: string;
|
|
89
|
+
fields: string[];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** `retune.json` (spec {@link RETUNE_SPEC}). */
|
|
93
|
+
export interface RetuneProvenance {
|
|
94
|
+
spec: typeof RETUNE_SPEC;
|
|
95
|
+
request: { idle_keys: IdleKeys; page_edges: PageEdges; pack_shape: PackShape };
|
|
96
|
+
versions: { parts: string; rigc: string };
|
|
97
|
+
input: { rig: HashRow[]; config_sha256: string; parts_json_sha256: string };
|
|
98
|
+
held: { compared: string[]; not_compared: string };
|
|
99
|
+
changed: { constraints: ConstraintChange[]; added: string[]; removed: string[]; idle: { tracks_changed: number; duration: [number, number] } };
|
|
100
|
+
preserved: { identical: string[]; spliced: string[] };
|
|
101
|
+
revision: HashRow[];
|
|
102
|
+
check: { input: CheckSide; revision: CheckSide; scope: string };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface RetuneResult {
|
|
106
|
+
provenance: RetuneProvenance;
|
|
107
|
+
written: string[];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
type Json = Record<string, unknown>;
|
|
111
|
+
|
|
112
|
+
const isRecord = (v: unknown): v is Json => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
113
|
+
const text = (b: Uint8Array): string => new TextDecoder().decode(b);
|
|
114
|
+
const bytesOf = (s: string): Uint8Array => new TextEncoder().encode(s);
|
|
115
|
+
const bytesEqual = (a: Uint8Array | undefined, b: Uint8Array | undefined): boolean => a !== undefined && b !== undefined && a.length === b.length && a.every((x, i) => x === b[i]);
|
|
116
|
+
|
|
117
|
+
/** A rig's files as the hold and the splice read them: `rig.json` and `motion.json` parsed, `images/` by file. */
|
|
118
|
+
export interface RigFiles {
|
|
119
|
+
rig: Json;
|
|
120
|
+
motion: Json;
|
|
121
|
+
images: Map<string, Uint8Array>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** {@link RigFiles} off a tree read by {@link readTree}. */
|
|
125
|
+
export function rigFiles(tree: FileTree): RigFiles {
|
|
126
|
+
const images = new Map<string, Uint8Array>();
|
|
127
|
+
for (const [k, b] of tree) if (k.startsWith('images/')) images.set(k, b);
|
|
128
|
+
return { rig: JSON.parse(text(tree.get('rig.json') as Uint8Array)) as Json, motion: JSON.parse(text(tree.get('motion.json') as Uint8Array)) as Json, images };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** `invariants` without `detached`, or undefined when nothing else is in it. */
|
|
132
|
+
function invariantsBut(inv: unknown): Json | undefined {
|
|
133
|
+
if (!isRecord(inv)) return undefined;
|
|
134
|
+
const rest: Json = {};
|
|
135
|
+
for (const [k, v] of Object.entries(inv)) if (k !== 'detached') rest[k] = v;
|
|
136
|
+
return Object.keys(rest).length === 0 ? undefined : rest;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** `rig.json` without `constraints` and `invariants.detached` — what the preserve assertion holds byte for byte. */
|
|
140
|
+
export function rigOutsideRetune(rig: Json): Json {
|
|
141
|
+
const out: Json = {};
|
|
142
|
+
for (const [k, v] of Object.entries(rig)) {
|
|
143
|
+
if (k === 'constraints') continue;
|
|
144
|
+
if (k === 'invariants') {
|
|
145
|
+
const rest = invariantsBut(v);
|
|
146
|
+
if (rest !== undefined) out[k] = rest;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
out[k] = v;
|
|
150
|
+
}
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** `motion.json` without `animations.idle` — what the hold and the preserve assertion hold byte for byte. */
|
|
155
|
+
export function motionOutsideIdle(motion: Json): Json {
|
|
156
|
+
const out: Json = {};
|
|
157
|
+
for (const [k, v] of Object.entries(motion)) {
|
|
158
|
+
if (k !== 'animations' || !isRecord(v)) {
|
|
159
|
+
out[k] = v;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
out[k] = Object.fromEntries(Object.entries(v).filter(([name]) => name !== 'idle'));
|
|
163
|
+
}
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Step 3: what the rebuild must state as the input does. `stops` first, so a stops change is named as one rather than
|
|
169
|
+
* as the bones it rewires. Each difference names its first leaf; every one is collected.
|
|
170
|
+
*/
|
|
171
|
+
export function holdProblems(input: RigFiles, rebuilt: RigFiles): Problem[] {
|
|
172
|
+
const out: Problem[] = [];
|
|
173
|
+
const held = (object: string, what: string, why: string): void => {
|
|
174
|
+
out.push({ code: 'RETUNE_REQUEST_HELD', object, detail: `the config changes it (${what}); ${why}, so nothing is written — make it a rebuild with rig --config` });
|
|
175
|
+
};
|
|
176
|
+
const top = 'a retune replaces constraints and the idle and holds every other byte of the input';
|
|
177
|
+
const stops = firstDifference(input.rig.stops, rebuilt.rig.stops, 'stops');
|
|
178
|
+
if (stops !== null) held('rig.json stops', `input vs rebuilt: ${stops}`, 'a stops change rewires bones, slots and weights onto drawn links (<link>_d), which a retune holds');
|
|
179
|
+
for (const key of ['bones', 'slots', 'skeleton', 'images']) {
|
|
180
|
+
const d = firstDifference(input.rig[key], rebuilt.rig[key], key);
|
|
181
|
+
if (d !== null) held(`rig.json ${key}`, `input vs rebuilt: ${d}`, key === 'bones' ? `${top}; a moved, renamed, added or re-inherited bone (a <bone>_ctl among them) moves every weight bound to it` : top);
|
|
182
|
+
}
|
|
183
|
+
const inv = firstDifference(invariantsBut(input.rig.invariants), invariantsBut(rebuilt.rig.invariants), 'invariants');
|
|
184
|
+
if (inv !== null) held('rig.json invariants', `input vs rebuilt: ${inv}`, `${top}; only invariants.detached derives from the constraints`);
|
|
185
|
+
for (const path of [...new Set([...input.images.keys(), ...rebuilt.images.keys()])].sort()) {
|
|
186
|
+
const a = input.images.get(path);
|
|
187
|
+
const b = rebuilt.images.get(path);
|
|
188
|
+
if (bytesEqual(a, b)) continue;
|
|
189
|
+
held(path, a === undefined ? 'the rebuild writes it and the input has none' : b === undefined ? 'the input has it and the rebuild writes none' : `input ${a.length} bytes ${sha256(a).slice(0, 12)}… vs rebuilt ${b.length} bytes ${sha256(b).slice(0, 12)}…`, top);
|
|
190
|
+
}
|
|
191
|
+
const mi = motionOutsideIdle(input.motion);
|
|
192
|
+
const mr = motionOutsideIdle(rebuilt.motion);
|
|
193
|
+
if (rigJsonText(mi) !== rigJsonText(mr)) {
|
|
194
|
+
held('motion.json', `input vs rebuilt outside animations.idle: ${firstDifference(mi, mr) ?? 'the same value, different bytes'}`, `${top}; spec, archetype, cut, easings, groups and every animation but idle (animations_from, the face deform) are held`);
|
|
195
|
+
}
|
|
196
|
+
return out;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Step 4: the revision — the input tree with `rig.json`'s `constraints` and `invariants.detached` and `motion.json`'s
|
|
201
|
+
* `animations.idle` the rebuild's, each key in the place the rig stage writes it. Every other entry is the input's
|
|
202
|
+
* own bytes, by reference.
|
|
203
|
+
*/
|
|
204
|
+
export function spliceRevision(input: FileTree, rebuilt: RigFiles): FileTree {
|
|
205
|
+
const inRig = JSON.parse(text(input.get('rig.json') as Uint8Array)) as Json;
|
|
206
|
+
const inMotion = JSON.parse(text(input.get('motion.json') as Uint8Array)) as Json;
|
|
207
|
+
const detached = isRecord(rebuilt.rig.invariants) ? rebuilt.rig.invariants.detached : undefined;
|
|
208
|
+
const invariantsOf = (inv: unknown): Json | undefined => {
|
|
209
|
+
// The rig stage writes `detached` after `idleDrivesMeshes` and before `deformMayFold` and `axes` (src/rig.ts).
|
|
210
|
+
const rest = invariantsBut(inv) ?? {};
|
|
211
|
+
const out: Json = {};
|
|
212
|
+
if ('idleDrivesMeshes' in rest) out.idleDrivesMeshes = rest.idleDrivesMeshes;
|
|
213
|
+
if (detached !== undefined) out.detached = detached;
|
|
214
|
+
for (const [k, v] of Object.entries(rest)) if (k !== 'idleDrivesMeshes') out[k] = v;
|
|
215
|
+
return Object.keys(out).length === 0 ? undefined : out;
|
|
216
|
+
};
|
|
217
|
+
const rig: Json = {};
|
|
218
|
+
const put = (k: string, v: unknown): void => {
|
|
219
|
+
if (v !== undefined) rig[k] = v;
|
|
220
|
+
};
|
|
221
|
+
for (const [k, v] of Object.entries(inRig)) {
|
|
222
|
+
if (k === 'constraints') put(k, rebuilt.rig.constraints);
|
|
223
|
+
else if (k === 'invariants') put(k, invariantsOf(v));
|
|
224
|
+
else rig[k] = v;
|
|
225
|
+
if (k === 'skins' && !('constraints' in inRig)) put('constraints', rebuilt.rig.constraints);
|
|
226
|
+
}
|
|
227
|
+
if (!('invariants' in inRig)) put('invariants', invariantsOf(undefined));
|
|
228
|
+
const animations = inMotion.animations as Json;
|
|
229
|
+
const motion: Json = { ...inMotion, animations: Object.fromEntries(Object.entries(animations).map(([k, v]) => [k, k === 'idle' ? (rebuilt.motion.animations as Json).idle : v])) };
|
|
230
|
+
const out: FileTree = new Map(input);
|
|
231
|
+
out.set('rig.json', bytesOf(rigJsonText(rig)));
|
|
232
|
+
out.set('motion.json', bytesOf(rigJsonText(motion)));
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** Where two values differ by top-level key, or by attachment under `skins`, so a moved part is named as the part it is. */
|
|
237
|
+
function movedPaths(a: Json, b: Json): Array<{ where: string; diff: string }> {
|
|
238
|
+
const out: Array<{ where: string; diff: string }> = [];
|
|
239
|
+
for (const k of [...new Set([...Object.keys(a), ...Object.keys(b)])]) {
|
|
240
|
+
if (k !== 'skins' || !isRecord(a.skins) || !isRecord(b.skins)) {
|
|
241
|
+
const d = firstDifference(a[k], b[k], k);
|
|
242
|
+
if (d !== null) out.push({ where: k, diff: d });
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
const sa = a.skins;
|
|
246
|
+
const sb = b.skins;
|
|
247
|
+
for (const skin of [...new Set([...Object.keys(sa), ...Object.keys(sb)])]) {
|
|
248
|
+
const pa = isRecord(sa[skin]) ? (sa[skin] as Json) : {};
|
|
249
|
+
const pb = isRecord(sb[skin]) ? (sb[skin] as Json) : {};
|
|
250
|
+
for (const slot of [...new Set([...Object.keys(pa), ...Object.keys(pb)])]) {
|
|
251
|
+
const xa = isRecord(pa[slot]) ? (pa[slot] as Json) : {};
|
|
252
|
+
const xb = isRecord(pb[slot]) ? (pb[slot] as Json) : {};
|
|
253
|
+
for (const name of [...new Set([...Object.keys(xa), ...Object.keys(xb)])]) {
|
|
254
|
+
const where = `skins.${skin}.${slot}.${name}`;
|
|
255
|
+
const d = firstDifference(xa[name], xb[name], where);
|
|
256
|
+
if (d !== null) out.push({ where, diff: d });
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return out;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Step 5, the preserve assertion: every file but `rig.json` and `motion.json` byte-identical in the revision and none
|
|
266
|
+
* added or dropped; `rig.json` identical outside `constraints` and `invariants.detached`, `motion.json` outside
|
|
267
|
+
* `animations.idle`, each moved path named.
|
|
268
|
+
*/
|
|
269
|
+
export function preservedProblems(input: FileTree, revision: FileTree): Problem[] {
|
|
270
|
+
const out: Problem[] = [];
|
|
271
|
+
const moved = (object: string, detail: string): void => {
|
|
272
|
+
out.push({ code: 'RETUNE_PRESERVED', object, detail: `${detail}; a retune carries every byte but the constraints and the idle over from the input, so nothing is written` });
|
|
273
|
+
};
|
|
274
|
+
const outside: Record<string, { strip: (v: Json) => Json; what: string }> = {
|
|
275
|
+
'rig.json': { strip: rigOutsideRetune, what: 'constraints and invariants.detached' },
|
|
276
|
+
'motion.json': { strip: motionOutsideIdle, what: 'animations.idle' },
|
|
277
|
+
};
|
|
278
|
+
for (const path of [...new Set([...input.keys(), ...revision.keys()])].sort()) {
|
|
279
|
+
const a = input.get(path);
|
|
280
|
+
const b = revision.get(path);
|
|
281
|
+
if (a === undefined || b === undefined) {
|
|
282
|
+
moved(path, a === undefined ? 'is in the revision and not in the input' : 'is in the input and not in the revision');
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
const o = outside[path];
|
|
286
|
+
if (o === undefined) {
|
|
287
|
+
if (!bytesEqual(a, b)) moved(path, `is not the input's bytes (input ${a.length} bytes ${sha256(a).slice(0, 12)}…, revision ${b.length} bytes ${sha256(b).slice(0, 12)}…)`);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
const x = o.strip(JSON.parse(text(a)) as Json);
|
|
291
|
+
const y = o.strip(JSON.parse(text(b)) as Json);
|
|
292
|
+
if (rigJsonText(x) === rigJsonText(y)) continue;
|
|
293
|
+
const where = movedPaths(x, y);
|
|
294
|
+
if (where.length === 0) moved(path, `differs from the input outside ${o.what} in its bytes, though not in its value`);
|
|
295
|
+
for (const w of where) moved(`${path} ${w.where}`, `differs from the input outside ${o.what} — input vs revision at ${w.diff}`);
|
|
296
|
+
}
|
|
297
|
+
return out;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** What the request changed, for the provenance: constraints by name and field, and the idle's tracks and duration. */
|
|
301
|
+
export function changedOf(input: RigFiles, rebuilt: RigFiles): RetuneProvenance['changed'] {
|
|
302
|
+
const list = (r: Json): Json[] => (Array.isArray(r.constraints) ? (r.constraints as unknown[]).filter(isRecord) : []);
|
|
303
|
+
const before = new Map(list(input.rig).map((c) => [String(c.name), c]));
|
|
304
|
+
const after = list(rebuilt.rig);
|
|
305
|
+
const afterNames = new Set(after.map((c) => String(c.name)));
|
|
306
|
+
const constraints: ConstraintChange[] = [];
|
|
307
|
+
for (const c of after) {
|
|
308
|
+
const was = before.get(String(c.name));
|
|
309
|
+
if (was === undefined) continue;
|
|
310
|
+
const keys = [...new Set([...Object.keys(c), ...Object.keys(was)])];
|
|
311
|
+
const fields = keys.filter((k) => JSON.stringify(c[k]) !== JSON.stringify(was[k]));
|
|
312
|
+
if (fields.length > 0) constraints.push({ name: String(c.name), type: String(c.type), fields });
|
|
313
|
+
}
|
|
314
|
+
const idleOf = (m: Json): { duration: number; tracks: unknown[] } => (m.animations as Json).idle as { duration: number; tracks: unknown[] };
|
|
315
|
+
const ia = idleOf(input.motion);
|
|
316
|
+
const ib = idleOf(rebuilt.motion);
|
|
317
|
+
let tracks = 0;
|
|
318
|
+
for (let i = 0; i < Math.max(ia.tracks.length, ib.tracks.length); i++) if (JSON.stringify(ia.tracks[i]) !== JSON.stringify(ib.tracks[i])) tracks++;
|
|
319
|
+
return {
|
|
320
|
+
constraints,
|
|
321
|
+
added: after.map((c) => String(c.name)).filter((n) => !before.has(n)),
|
|
322
|
+
removed: [...before.keys()].filter((n) => !afterNames.has(n)),
|
|
323
|
+
idle: { tracks_changed: tracks, duration: [ia.duration, ib.duration] },
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* The stage: steps 1–7 of the module header. Writes `input.out` only when every step is green; refuses with every
|
|
329
|
+
* problem of the first step that found one.
|
|
330
|
+
*/
|
|
331
|
+
export function retuneStage(input: RetuneInput, rigc: RigcRunner, checkBin: string, versions: { parts: string; rigc: string }, scratch: string, log: Log, plant: RetunePlant = {}): RetuneResult {
|
|
332
|
+
const idleKeys = input.idleKeys ?? DEFAULT_IDLE_KEYS;
|
|
333
|
+
const pageEdges = input.pageEdges ?? DEFAULT_PAGE_EDGES;
|
|
334
|
+
const packShape = input.packShape ?? DEFAULT_PACK_SHAPE;
|
|
335
|
+
// 1. The input and the out.
|
|
336
|
+
const outAt = resolve(input.out);
|
|
337
|
+
const rigAt = resolve(input.rig);
|
|
338
|
+
if (existsSync(outAt)) throw new PartsError([{ code: 'RETUNE_OUT_FRESH', object: input.out, detail: 'exists; a revision is written into a new directory, never over the input or an earlier revision' }]);
|
|
339
|
+
if (!existsSync(rigAt) || !statSync(rigAt).isDirectory()) throw new PartsError([{ code: 'RETUNE_INPUT_PRESENT', object: input.rig, detail: 'is not a directory; the input revision is the directory rig writes' }]);
|
|
340
|
+
if (outAt.startsWith(`${rigAt}${sep}`)) throw new PartsError([{ code: 'RETUNE_OUT_FRESH', object: input.out, detail: `is inside the input ${input.rig}; a revision is written beside the input, never into it` }]);
|
|
341
|
+
const tree = readTree(rigAt);
|
|
342
|
+
refuseIfAny(inputTreeProblems(tree, input.rig, 'retune', RETUNE_SPLICED));
|
|
343
|
+
const inFiles = rigFiles(tree);
|
|
344
|
+
// 2. The rebuild.
|
|
345
|
+
log(`rig-parts retune: ${input.rig}, ${tree.size} file(s); the rebuild is the config as written`);
|
|
346
|
+
const rebuiltAt = join(scratch, 'rebuild', 'rig');
|
|
347
|
+
try {
|
|
348
|
+
rigStage({ config: input.config, parts: input.parts, out: rebuiltAt, idleKeys, pageEdges, packShape }, rigc, join(scratch, 'rebuild', 'gate'), (l) => log(`[rebuild:rig] ${l}`));
|
|
349
|
+
} catch (err) {
|
|
350
|
+
if (!(err instanceof PartsError)) throw err;
|
|
351
|
+
throw new PartsError(err.problems.map((p) => ({ code: 'RETUNE_CONFIG_REFUSED', object: `${input.config} as written`, detail: `the rig stage refuses it, nothing is written: ${problemLine(p)}` })));
|
|
352
|
+
}
|
|
353
|
+
const rebuilt = rigFiles(readTree(rebuiltAt));
|
|
354
|
+
// 3. The hold.
|
|
355
|
+
if (plant.skipHold !== true) refuseIfAny(holdProblems(inFiles, rebuilt));
|
|
356
|
+
log(` held: ${RETUNE_HELD.join(', ')} — the rebuild states each as the input does; no attachment is compared`);
|
|
357
|
+
const changed = changedOf(inFiles, rebuilt);
|
|
358
|
+
// 4–5. The splice and the preserve assertion.
|
|
359
|
+
let revision = spliceRevision(tree, rebuilt);
|
|
360
|
+
if (plant.perturb !== undefined) revision = perturbed(revision, plant.perturb);
|
|
361
|
+
if (plant.skipPreserve !== true) refuseIfAny(preservedProblems(tree, revision));
|
|
362
|
+
const spliced: string[] = [...RETUNE_SPLICED];
|
|
363
|
+
const identical = [...tree.keys()].filter((k) => !spliced.includes(k));
|
|
364
|
+
for (const c of changed.constraints) log(` constraint ${c.name} (${c.type}): ${c.fields.join(', ')} changed`);
|
|
365
|
+
if (changed.added.length > 0) log(` constraints added: ${changed.added.join(', ')}`);
|
|
366
|
+
if (changed.removed.length > 0) log(` constraints removed: ${changed.removed.join(', ')}`);
|
|
367
|
+
log(` idle: ${changed.idle.tracks_changed} track(s) changed, duration ${changed.idle.duration[0]} -> ${changed.idle.duration[1]}`);
|
|
368
|
+
log(` preserved: ${identical.length} file(s) byte-identical to the input; rig.json identical outside constraints and invariants.detached; motion.json identical outside animations.idle`);
|
|
369
|
+
// 6. The gate and check.
|
|
370
|
+
const pngs = [...revision].filter(([k]) => k.startsWith('images/')).map(([k, b]) => [k.slice('images/'.length), b] as const);
|
|
371
|
+
const texts = [...revision].filter(([k]) => !k.startsWith('images/')).map(([k, b]) => [k, text(b)] as const);
|
|
372
|
+
const gate = gateThroughRigc(pngs, texts, rigc, join(scratch, 'gate'), { pageEdges, packShape });
|
|
373
|
+
for (const g of gate) {
|
|
374
|
+
log(` rigc ${g.label}, the revision: exit ${g.status}`);
|
|
375
|
+
for (const l of g.lines) log(` ${l.trim()}`);
|
|
376
|
+
}
|
|
377
|
+
refuseIfAny(gate.filter((g) => g.status !== 0).map((g) => ({ code: 'RETUNE_RIGC_GREEN', object: `rigc ${g.label} over the revision`, detail: `exited ${g.status}${g.lines.length > 0 ? `: ${g.lines.map((l) => l.trim()).join(' | ')}` : ''}${rigcRanClause(g)}; exit 0 is required before anything is written, and nothing was` })));
|
|
378
|
+
const staged = join(scratch, 'revision');
|
|
379
|
+
for (const [k, b] of revision) {
|
|
380
|
+
mkdirSync(dirname(join(staged, k)), { recursive: true });
|
|
381
|
+
writeFileSync(join(staged, k), b);
|
|
382
|
+
}
|
|
383
|
+
const checkOf = (rig: string, name: string): CheckReport =>
|
|
384
|
+
checkStage({ rig, parts: input.parts, out: join(scratch, name), pageEdges, packShape, ...(input.requirements === undefined ? {} : { requirements: input.requirements }) }, rigc, checkBin, (l) => log(`[${name}] ${l}`));
|
|
385
|
+
const inCheck = checkOf(rigAt, 'check-input');
|
|
386
|
+
const revCheck = checkOf(staged, 'check-revision');
|
|
387
|
+
const sides = { input: checkSide(inCheck), revision: checkSide(revCheck) };
|
|
388
|
+
refuseIfAny(checkHeldProblems(sides.input, sides.revision, revCheck.problems, 'retune'));
|
|
389
|
+
const scope = checkScope(sides.revision.physics);
|
|
390
|
+
log(` check: input ${sides.input.pass ? 'PASS' : `FAIL (${sides.input.not_met.join(', ')})`}, revision ${sides.revision.pass ? 'PASS' : `FAIL (${sides.revision.not_met.join(', ')})`}, the same ${sides.revision.measured.length} bar(s) measured; ${scope}`);
|
|
391
|
+
// 7. The write.
|
|
392
|
+
const provenance: RetuneProvenance = {
|
|
393
|
+
spec: RETUNE_SPEC,
|
|
394
|
+
request: { idle_keys: idleKeys, page_edges: pageEdges, pack_shape: packShape },
|
|
395
|
+
versions,
|
|
396
|
+
input: { rig: hashRows(tree), config_sha256: sha256(new Uint8Array(readFileSync(input.config))), parts_json_sha256: sha256(new Uint8Array(readFileSync(join(input.parts, 'parts.json')))) },
|
|
397
|
+
held: { compared: [...RETUNE_HELD], not_compared: RETUNE_NOT_COMPARED },
|
|
398
|
+
changed,
|
|
399
|
+
preserved: { identical, spliced },
|
|
400
|
+
revision: hashRows(revision),
|
|
401
|
+
check: { ...sides, scope },
|
|
402
|
+
};
|
|
403
|
+
const written: string[] = [];
|
|
404
|
+
mkdirSync(outAt, { recursive: true });
|
|
405
|
+
for (const [k, b] of revision) {
|
|
406
|
+
mkdirSync(dirname(join(outAt, k)), { recursive: true });
|
|
407
|
+
writeFileSync(join(outAt, k), b);
|
|
408
|
+
written.push(k);
|
|
409
|
+
}
|
|
410
|
+
writeFileSync(join(outAt, RETUNE_FILE), rigJsonText(provenance));
|
|
411
|
+
written.push(RETUNE_FILE);
|
|
412
|
+
log(' file sha256 (input) sha256 (revision)');
|
|
413
|
+
const inHash = new Map(hashRows(tree).map((r) => [r.path, r.sha256]));
|
|
414
|
+
for (const r of provenance.revision) log(` ${r.path.padEnd(40)} ${(inHash.get(r.path) ?? 'absent').slice(0, 16)} ${r.sha256.slice(0, 16)}${inHash.get(r.path) === r.sha256 ? '' : ' (spliced)'}`);
|
|
415
|
+
log(`rig-parts retune: wrote ${written.length} file(s) under ${input.out}, the provenance in ${RETUNE_FILE}`);
|
|
416
|
+
rmSync(staged, { recursive: true, force: true });
|
|
417
|
+
return { provenance, written };
|
|
418
|
+
}
|
package/src/rig.ts
CHANGED
|
@@ -166,6 +166,7 @@ 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';
|
|
@@ -1092,20 +1093,7 @@ export function deriveAlternateDrawn(
|
|
|
1092
1093
|
const altEyeAim = deg(pts.r_eye, pts.l_eye);
|
|
1093
1094
|
out.head = places(normaliseDegrees((turn.get('head') ?? 0) + (altEyeAim - setupEyeAim)));
|
|
1094
1095
|
}
|
|
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
|
-
];
|
|
1096
|
+
const limbPairs = skeletonLimbJoints(pts);
|
|
1109
1097
|
for (const [bone, a, b] of limbPairs) {
|
|
1110
1098
|
if (B.has(bone)) out[bone] = places(normaliseDegrees(deg(a, b)));
|
|
1111
1099
|
}
|
|
@@ -2379,21 +2367,10 @@ export function buildRig(
|
|
|
2379
2367
|
return [wx + CX, cropToSpineY(wy, H)];
|
|
2380
2368
|
};
|
|
2381
2369
|
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
|
-
};
|
|
2370
|
+
const skSegs: Map<string, readonly [Point, Point]> | null =
|
|
2371
|
+
alt.skeleton === undefined ? null : new Map(skeletonLimbJoints(alt.skeleton).map(([bone, a, b]) => [bone, [pt(a), pt(b)] as const]));
|
|
2395
2372
|
segs = segs.map((s) => {
|
|
2396
|
-
const skPair = skSegs?.
|
|
2373
|
+
const skPair = skSegs?.get(s.bone);
|
|
2397
2374
|
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
2375
|
});
|
|
2399
2376
|
const nonSkirt = segs.filter((s) => !hipChainLinks.has(s.bone));
|
|
@@ -2489,6 +2466,8 @@ export function buildRig(
|
|
|
2489
2466
|
slots: slotMap,
|
|
2490
2467
|
...(hideList.length > 0 ? { hides: hideList } : {}),
|
|
2491
2468
|
...(drawn === undefined ? {} : { drawn }),
|
|
2469
|
+
...(alt.drawnLength === undefined ? {} : { drawnLength: { ...alt.drawnLength } }),
|
|
2470
|
+
...(alt.registration === undefined ? {} : { registration: { offset: [alt.registration.offset[0], alt.registration.offset[1]], scale: alt.registration.scale } }),
|
|
2492
2471
|
...(coversFace && cfg.turn !== undefined ? { threshold: { ...FACE_RATED_BAND } } : {}),
|
|
2493
2472
|
};
|
|
2494
2473
|
}
|