rig-parts 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -9
- package/cli.ts +8 -2
- package/docs/AUTHORING.md +41 -11
- package/package.json +1 -1
- package/src/assemble.ts +199 -16
- package/src/build.ts +13 -3
- package/src/check.ts +7 -4
- package/src/headframe.ts +207 -0
- package/src/motion.ts +20 -3
- package/src/propose.ts +406 -17
- package/src/rig.ts +124 -17
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ input is silent.
|
|
|
15
15
|
|
|
16
16
|
<p align="center">
|
|
17
17
|
<img src="https://raw.githubusercontent.com/rig-c/parts/main/assets/demo-source.png" alt="The demo painting: a generated full-body character in a white and pink idol dress with a layered skirt and long pink twin tails, standing with her arms held away from her body and her hands open" height="420" />
|
|
18
|
-
<img src="https://raw.githubusercontent.com/rig-c/parts/main/assets/demo-idle.png" alt="The same character rigged, breathing, blinking once and swaying her hair, sleeves and skirt in a
|
|
18
|
+
<img src="https://raw.githubusercontent.com/rig-c/parts/main/assets/demo-idle.png" alt="The same character rigged, breathing, blinking once and swaying her hair, sleeves and skirt in a 3.3-second loop" height="420" />
|
|
19
19
|
</p>
|
|
20
20
|
|
|
21
21
|
<p align="center">
|
|
@@ -37,17 +37,17 @@ config beside the values it replaced: the two outer skirt chains were moved out
|
|
|
37
37
|
against 1.4725; moved, 2.425). One input-stage edit: <code>hair_back</code> is taken
|
|
38
38
|
from the full run, because the twin tails leave the head crop sideways (a plan edit).
|
|
39
39
|
<code>check</code> printed, verbatim:<br/>
|
|
40
|
-
<code>
|
|
41
|
-
<code>loop: idle
|
|
40
|
+
<code>51 assertions: 25 measured (25 passed, 0 failed), 26 skipped, 0 not in profile "spine-html"</code><br/>
|
|
41
|
+
<code>loop: idle 41 frame(s) at 12 fps, f0000 vs f0040 (t = 3.333333333333333s): max |d| 0 (0 required)</code><br/>
|
|
42
42
|
<code>seam: setup pose at 654x1216, scale 0.9438: mean |d| 0.147 (<= 1.0), 0 px over 40, 0.00 rig px (the count / s²; <= 50), 0 px over 80 (reported)</code><br/>
|
|
43
43
|
<code>pack: skeleton.png 1051x972, 23 region(s), 96.9% covered, padding 2, page edges free, shape polygon</code><br/>
|
|
44
|
-
The loop is that build's indexed APNG,
|
|
45
|
-
256-entry palette at a measured error of max
|
|
46
|
-
frame (the lossless APNG beside it, the exactness record, is
|
|
47
|
-
GIF, at the same error,
|
|
44
|
+
The loop is that build's indexed APNG, 40 frames at 12 fps, 725,845 bytes, one
|
|
45
|
+
256-entry palette at a measured error of max 70, mean 0.631 per channel over every
|
|
46
|
+
frame (the lossless APNG beside it, the exactness record, is 4,514,756 bytes; the
|
|
47
|
+
GIF, at the same error, 784,074). The rig's hair, skirt, sleeves, bows and earrings
|
|
48
48
|
carry physics, which rigc's render starts from rest, so the idle is played three
|
|
49
|
-
periods ahead and the loop is the fourth:
|
|
50
|
-
|
|
49
|
+
periods ahead and the loop is the fourth: the frame one period after its first differs
|
|
50
|
+
from it by max 7 levels, 0 px over 40 (<code>--lead-in</code>). Frame 29 (2.417 s) is the
|
|
51
51
|
closed eye: the blink holds for 0.084 s, one 12 fps frame rounded up; the painting is
|
|
52
52
|
shown at half size, resampled and written by this package's PNG codec (nothing here
|
|
53
53
|
encodes JPEG). <code>rig-parts sheet</code> made the contact sheet. Its
|
package/cli.ts
CHANGED
|
@@ -26,7 +26,7 @@ import { makeInputs } from './src/inputs.ts';
|
|
|
26
26
|
import { idleKeysOf, isIdleKeys } from './src/rig.ts';
|
|
27
27
|
import { figuresPhrase, implausibleRules, layerFigures, type LayerSet, pct, readLayers, ruleSummary, times } from './src/layers.ts';
|
|
28
28
|
import { checkImageSize, choosePerson, KEYPOINTS_SPEC, loadKeypoints, type RigJoints, toRigJoints } from './src/keypoints.ts';
|
|
29
|
-
import { basisLines, checkProposal, compare, compareLines, drawLandmarks, HIP_MIN_FRACTION, lint, lintLine, type PartSet, proposeWithBasis, readPartSet, serializeProposal, WRIST_ON_PART_PX } from './src/propose.ts';
|
|
29
|
+
import { basisLines, checkProposal, compare, compareLines, drawLandmarks, FRINGE_STEP_PX, HIP_MIN_FRACTION, lint, lintLine, type PartSet, proposeWithBasis, readPartSet, serializeProposal, WRIST_ON_PART_PX } from './src/propose.ts';
|
|
30
30
|
import { BASIS_FILE, BASIS_SPEC, basisFile, basisLine, coverageLines, serializeBasis } from './src/diagnostics.ts';
|
|
31
31
|
import { readPng, writePng } from './src/raster/png.ts';
|
|
32
32
|
import { REQUIREMENTS_SENTENCE } from './src/requirements.ts';
|
|
@@ -88,8 +88,13 @@ usage:
|
|
|
88
88
|
from the head run's hair and neck, said in the first note; with no
|
|
89
89
|
head-run hair or neck it is refused (PROPOSE_FACE_PRESENT). Prints every
|
|
90
90
|
note and a LINT line for each chain link that lies off its mesh's art, for a
|
|
91
|
+
link of a fringe chain (hung from head on a head-run front hair mesh, its tip
|
|
92
|
+
no lower than the chin) that drifts more than ${FRINGE_STEP_PX} px plus a pixel's
|
|
93
|
+
rounding across the head's down axis (the eye line's perpendicular), for a
|
|
91
94
|
hip that is not below the chest, and for a hip above ${HIP_MIN_FRACTION} of the figure's
|
|
92
|
-
height (the shoulders);
|
|
95
|
+
height (the shoulders); the fringe's three chains stand in the head's frame,
|
|
96
|
+
rooted on the part's art, and a note says they are a template, not its
|
|
97
|
+
locks; a headwear/earwear layer with hanging strands
|
|
93
98
|
gets one pendulum chain per strand and a note with each strand's x, rows
|
|
94
99
|
and width ("-- no chain proposed" is the one to act on; AUTHORING §3).
|
|
95
100
|
--compare prints each shared bone's distance, proposal to config, in px.
|
|
@@ -799,6 +804,7 @@ function printLint(P: PartSet, spec: { bones: CharacterConfig['bones']; meshes:
|
|
|
799
804
|
if (res.basis !== undefined) for (const l of basisLines(res.basis)) console.log(l);
|
|
800
805
|
for (const f of res.findings) console.log(lintLine(f));
|
|
801
806
|
for (const m of res.unknownMeshes) console.log(`note: mesh ${JSON.stringify(m)} names no part in parts.json, so it was not linted`);
|
|
807
|
+
for (const w of res.lockUnread) console.log(`note: off-lock not read: ${w}`);
|
|
802
808
|
for (const b of res.missingTorsoBones) {
|
|
803
809
|
console.log(
|
|
804
810
|
res.basis?.torso.read === true
|
package/docs/AUTHORING.md
CHANGED
|
@@ -91,13 +91,13 @@ read by no CPU stage).
|
|
|
91
91
|
| `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 |
|
|
92
92
|
| `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 |
|
|
93
93
|
| `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` 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 |
|
|
94
|
-
| `bones` | rig; `propose --from-config` | **proposed** by `propose`, then corrected. A single bone `{name, parent, at, tip?}` or a chain `{chain, parent, points, tip}` 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. 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 |
|
|
94
|
+
| `bones` | rig; `propose --from-config` | **proposed** by `propose`, then corrected. A single bone `{name, parent, at, tip?}` or a chain `{chain, parent, points, tip}` 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 |
|
|
95
95
|
| `meshes.<part>` | rig | **proposed**, then corrected. Exactly one of `grid` (the lattice: cell size, px — what `propose` writes), `contour` (the outline mode, authored; the next row and "A contour mesh" below) or `auto` (the automatic mode, authored; "An automatic mesh" below) — two, or none, is `CONFIG_MESH_MODE`. In every mode: `r` (added to every distance before weighting: `w = 1/(d + r)²`), `segments` (a chain name, a bone name with a `tip`, or `[bone, [x0,y0], [x1,y1]]`), and, **authored**, optional, `exponent` (issue #161): a number above 0 that replaces the 2 in that rule, `w = 1/(d + r)^exponent` — a larger one hands each vertex more fully to its nearest bone; absent is 2 and changes no byte, a value that is not a number above 0 is `CONFIG_FIELD_TYPE` at `meshes.<part>.exponent`, and a declared one is echoed as `exponent` in the mesh's `mesh_report.json` row; the exponent is the distance rule's, so declared beside `rule: "heat"` it is refused (`CONFIG_FIELD_TYPE` at `meshes.<part>.exponent`). The segment list is the one authored decision about a layer: which bones may pull it. The slot's bone is the first segment's. Optional `rule` (issue #161): `"distance"` — the rule above, and what an absent `rule` means (every byte is the same) — or `"heat"`, bone heat over the part's own silhouette, in every mode: the lattice's art (alpha above 8) with holes filled, or for `contour` and `auto` the silhouette their outline is traced from (that mode's art — alpha above 8 for `contour`, alpha 1 and above for `auto` — less any island a declared `stray` left out, holes filled, grown by its `margin`); each bound bone's sources are the silhouette pixels whose centre lies within 0.75 px of its segment (a pixel two bones reach goes to the nearer, a tie to the first listed), held at 1 for that bone and 0 for the others; the field is solved by row-major Gauss–Seidel over-relaxation to a sweep change under 1e-7 within 20000 sweeps; a vertex reads the nearest silhouette pixel and takes the same cap and floor (and `regions`) as the distance rule; `r` is not read. The mesh's `mesh_report.json` row gains `heat` (the constants, each bone's sources and sweeps, the residual). Any other value is `CONFIG_FIELD_TYPE`; a bound bone with no source pixel is `RIG_HEAT_BONE_SOURCE`, an island no bone has a source in `RIG_HEAT_ISLAND_SOURCE`, a solve past its sweep bound `RIG_HEAT_CONVERGED` — none is weighted 0 |
|
|
96
96
|
| `meshes.<part>.contour` | rig | **authored**, optional (issue #84): `{tolerance, margin, spacing, budget?, stray?, regions?}`. `tolerance` — rig-c's Douglas–Peucker tolerance on the traced outline, px, 0 or more; `margin` — how far the silhouette grows before it is traced, px: 0, or 1 or more (a pixel joins when its centre lies within `margin` of an art pixel's centre; a value above 0 and below 1 adds nothing and is refused, `CONFIG_FIELD_TYPE`); `spacing` — the background interior spacing, px, above 0; `budget` — the most vertices the mesh may have (refused above it, nothing thinned); `stray` — the largest island, in art pixels, that may be left out of the mesh (absent: none is); `regions` — local deformation regions, each `{name, shape, bone, spacing, band}` with `shape` `"circle"` (`cx, cy, r`) or `"polygon"` (`points`, 3 or more): `bone` is the region's control bone (any bone `bones` declares), `spacing` the interior spacing inside the region and its band, `band` the width the bone's weight falls across. Every length and position is **rig px**, like every other in the config; the part image is the rig less `(x − 4, y − 4)` (its box less the pad), a translation, so a length is the same number in both. A region's `cx`, `cy`, `r`, `band` and `points` are multiples of 1/256 px (`CONFIG_FIELD_TYPE` otherwise); region names are unique per mesh (`CONFIG_REGION_NAME_UNIQUE`). The alpha threshold is not a field: art is alpha above 8, the lattice's and `check`'s |
|
|
97
97
|
| `meshes.<part>.ribs` | rig | **authored**, optional (issue #188), in the `contour` and `auto` modes: `{<chain>: {stations}, …}`, each key a chain this mesh's `segments` name. Each link of the chain gets a row of vertices across the part at its origin and at `stations` points evenly between its origin and its end (`stations`, a whole number, 0 or more, required; a chain of L links carries L × (stations + 1) ribs), each rib a row of vertices across the part, kept as a row of locked edges; the rule is "Ribs along a chain" under "A contour mesh". Absent places none and changes no byte. Refused: a lattice mesh with ribs (`CONFIG_RIBS_MODE` — its vertices are its grid's corners), a key that is not one of the mesh's chains (`CONFIG_NAME_RESOLVES`), an object naming no chain or a `stations` that is not a whole number from 0 (`CONFIG_FIELD_TYPE`); at the rig stage `CONTOUR_RIB_ART`, `CONTOUR_RIB_LINK`, `CONTOUR_RIB_CROSSING`, `CONTOUR_RIB_EDGE` (the contour refusals). The mesh's `mesh_report.json` row gains `ribs` — the declaration, the ribs placed and the vertices they hold — and its contour report (the source's, in `auto`) lists each rib's vertices |
|
|
98
98
|
| `regions.<part>` | rig | **proposed**: the bone a rigid part rides. Every plan part is exactly one of a mesh or a region (`CONFIG_PART_ATTACHED`) |
|
|
99
|
-
| `motion.duration` | rig; check (the loop is measured at this time) | proposed as 4 s; a whole number of 1/12 s ticks, because `check` renders at 12 fps |
|
|
100
|
-
| `motion.tracks` | rig | **proposed**, then tuned. Single `{bone, prop, amp, period, phase, base?}` or chain `{chain, amps, period, phase, lag}` — one amplitude per link, link `i` at phase `phase + lag·i`. Every `period` must divide `duration` (`CONFIG_PERIOD_DIVIDES_DURATION`). A bone property is keyed by one track (`CONFIG_BONE_PROPERTY_KEYED_ONCE`): a chain keys `rotate` on every link, the blink's `eyes` group `scaley` and its `brows` group `translatey` on every member, so a single track on any of those is a second track on it — rigc would refuse it one stage later, `animation "idle" has two tracks on eye.scaley`. A chain link is turned along its chain (the `bones` row), so a `translatex`/`translatey` key on a bone whose parent is a turned link, or a `scale`/`shear` key on a turned link, would move or stretch along the link and not along the picture's axis: the rig stage refuses it (`RIG_KEY_FRAME_UNTURNED`); `rotate` is keyed on any bone |
|
|
99
|
+
| `motion.duration` | rig; check (the loop is measured at this time) | proposed as 40 frames at 12 fps, `40/12` s, written `3.3333333333333335` (issue #252; the reference proposed 4 s, and every period it drafted is scaled with it so each track keeps its cycles per idle); a whole number of 1/12 s ticks, because `check` renders at 12 fps and compares frame 0 with the frame at this time — read within 10^-9 s (`TIME_SLACK`, issue #244), since a whole number of frames is often not exact in binary: rigc's 40th frame sits at `40 × (1/12)` = `3.333333333333333`. Half a frame off is `CHECK_LOOP_LAST_FRAME_AT_DURATION` |
|
|
100
|
+
| `motion.tracks` | rig | **proposed**, then tuned. Single `{bone, prop, amp, period, phase, base?}` or chain `{chain, amps, period, phase, lag}` — one amplitude per link, link `i` at phase `phase + lag·i`. Every `period` must divide `duration` (`CONFIG_PERIOD_DIVIDES_DURATION`). A bone property is keyed by one track (`CONFIG_BONE_PROPERTY_KEYED_ONCE`): a chain keys `rotate` on every link, the blink's `eyes` group `scaley` and its `brows` group `translatey` on every member, so a single track on any of those is a second track on it — rigc would refuse it one stage later, `animation "idle" has two tracks on eye.scaley`. The proposed breath (issue #252) is `chest` `translatey` travelling 2.5 % of the `topwear` part's height peak to peak (amplitude half of it to two decimals, `base` the amplitude, so the chest rises from the setup pose and returns) — height, because the travel is along y; the `breath:` note prints the fraction, the part, its height and the pixels. No `topwear` part: no height to scale by, so the breath keeps the reference's amplitude 1.3 (2.6 px peak to peak) and the note says so — scale it to the figure. `chest` `scalex` and the `head` and `neck` rolls are a ratio and angles and are proposed the same on every figure. A chain link is turned along its chain (the `bones` row), so a `translatex`/`translatey` key on a bone whose parent is a turned link, or a `scale`/`shear` key on a turned link, would move or stretch along the link and not along the picture's axis: the rig stage refuses it (`RIG_KEY_FRAME_UNTURNED`); `rotate` is keyed on any bone |
|
|
101
101
|
| `motion.blink` | rig | **proposed**: `{t, eyes, brows, squash, brow_drop}`; the whole blink, `t` to `t + 0.364` s (`t + 0.314` s without brows: the brows' keys are the ones that end last), must fit inside the idle (`RIG_BLINK_INSIDE_IDLE`). The `eyes` group's `scaley` squashes every part on the eye bones about the bone's origin, the eyewhite's centre. Optional: a figure with no `eyewhite-r`/`-l` part has no eye bone, so `propose` writes no `blink` and notes `no blink: no eyewhite part (looked for: eyewhite-r, eyewhite-l), …`; with eyes and no `eyebrow-r`/`-l` part it writes the blink without `brows` and `brow_drop` and notes `blink without brows: …`. `brows` and `brow_drop` are stated together or not at all (`CONFIG_BLINK_BROWS_PAIRED`), and a group that names no bone is refused (`CONFIG_BLINK_GROUP_MEMBERS`) — rigc would refuse it one stage later, `group "eyes" declares no members` — as is a group that names one bone twice (`CONFIG_BLINK_GROUP_UNIQUE`; rigc: `group "eyes" names member "eye" twice`). An `irides-*` or `eyelash-*` part on a side with no eyewhite has no eye bone to ride: `propose` places it on `head` as a region, which the blink does not move, and notes `no eyewhite part for eye_r (looked for: eyewhite-r): iris (head:irides-r) is placed on head as a region, …`. The timing is fixed, not a field (table below) |
|
|
102
102
|
| `motion.blink.still` | rig | **proposed** only for a lash `propose` notes (below), then checked: `{<part>: {row, bone}}` — the rows of that region part above `row` (rig px, y down) are drawn by a second slot `<part>_still` on `bone` and do not blink; rows from `row` down keep the part's slot and blink. The part must be a region on a bone `eyes` names, `bone` one it does not (`CONFIG_STILL_OFF_THE_BLINK`), and `row` a row of the part with no art across its whole width (`RIG_STILL_ROW_CLEAR`) |
|
|
103
103
|
| `motion.animations_from` | rig; check (named, not measured) | optional, never proposed (issue #183): a path, relative to the config file's directory, to a file in rig-c's motion-spec shape, `{"spec": "rigc-motion/1", "animations": {"<name>": {"duration": …, "tracks": [...]}, …}}` — an expression, a gesture, anything beside the idle. On every `rig` and `build` each of its animations is written into `rig/motion.json` after `idle`, as read: nothing added, re-keyed or judged here, and each is rigc's to accept or refuse at the rig stage's gate, in rigc's words. It may name what `motion.json` already holds — the bones `bones` declares, the easings `shut` and `open`, the groups `eyes` and `brows` when the blink writes them — and nothing else from the file reaches it. The loader refuses, every problem at once: no such file or one that cannot be read (`CONFIG_FILE_PRESENT`), text that is not JSON (`CONFIG_IS_JSON`), a file that is not an object, a `spec` other than `"rigc-motion/1"`, an `animations` that is not a table of objects (`CONFIG_FIELD_TYPE`), any other key — rig-c's `easings`, `groups`, `setup`, `physics`, `mix`, `archetype` and `cut` included, which would be read and not written (`CONFIG_KEY_KNOWN`), an animation named `idle` (`CONFIG_ANIMATION_NAME_FREE`), and a key written twice in one object of the file, which JSON would fold into its last value without a word (`CONFIG_KEY_UNIQUE`). `check` measures the idle alone and prints one line naming the others (`beside the idle: …`). Absent, `motion.json` holds the idle alone, byte for byte as before |
|
|
@@ -156,6 +156,26 @@ chain — or, when the accessory has hanging strands, one pendulum chain per str
|
|
|
156
156
|
swing, hair of another shape, whether an accessory swings — is yours to add, and
|
|
157
157
|
`notes` in `proposal.json` says where it guessed.
|
|
158
158
|
|
|
159
|
+
**The fringe stands in the head's frame (issue #249).** The three fringe chains,
|
|
160
|
+
`bang_r`, `bang_c` and `bang_l`, are a template: columns at 0.25, 0.5 and 0.75 of the
|
|
161
|
+
face box's width, with the reference's 10 px outward step per link. The columns run
|
|
162
|
+
along the head's down axis — the perpendicular of the eye line through `eye_r` and
|
|
163
|
+
`eye_l` as `bones` writes them, the roll the `head frame:` note prints — and each root
|
|
164
|
+
sits 13 px below where the part's art starts on its column (the run of art that crosses
|
|
165
|
+
the brow line), so on a tilted head the chains lean with the head and start on the hair,
|
|
166
|
+
not on a hat above it. The opaque shape cannot separate locks painted inside one mass of
|
|
167
|
+
hair, so a note names the part and says the columns are a template: move them onto the
|
|
168
|
+
locks. With no eye pair the columns stand on the page, and the note says why. `lint`
|
|
169
|
+
holds every chain hung from `head` on a head-run `front hair` mesh whose tip is no lower
|
|
170
|
+
than the chin (the face box's bottom centre, along that axis; a strand hanging past the
|
|
171
|
+
chin hangs with its weight): a link that drifts across the head's down axis by more than
|
|
172
|
+
the template's widest step plus a pixel's rounding at each end (10 + sqrt(2) px, an
|
|
173
|
+
angle of atan(11.41 / reach) for the link's reach down the axis) is a
|
|
174
|
+
`LINT <link> at … runs to … N degrees off the head's down axis` line. The page-vertical
|
|
175
|
+
template the proposer wrote before issue #249 fires it on any head tilted more than a few
|
|
176
|
+
degrees (the trailer character, 23.7 degrees: all six links; `reference-demo`, 3.2
|
|
177
|
+
degrees, and `reference-sample`, -4.9 degrees: one link each).
|
|
178
|
+
|
|
159
179
|
**A posed figure: `propose --keypoints`.** The proposer's ratios assume a
|
|
160
180
|
standing figure: the hip below the chest, sleeves hanging from the shoulders. A
|
|
161
181
|
seated, reclining or otherwise posed figure is told where its joints are with one
|
|
@@ -1237,8 +1257,8 @@ proposal in as the steps above say (`RL01`); every step must exit 0.
|
|
|
1237
1257
|
| --- | --- | --- | --- |
|
|
1238
1258
|
| `layers` | the table, then the `WARN` lines | every tag the plan will need has opaque pixels; one `face` in the head run; `0 WARN line(s)` | a run whose layer PNG is not its box's size (`LAYERS_PNG_MATCHES_BBOX`); a `WARN PLAN_LAYER_…` line (§6, *Plausibility*) |
|
|
1239
1259
|
| `sheet` of both runs | the tile list (and the sheet, if you can see) | eyes, irises, lashes and brows as left/right pairs in the head run | a head box that cut off an ornament: move `head_box`, re-run the head crop |
|
|
1240
|
-
| `assemble` | one line per part, the `pixels:` totals (opaque = visible + occluded; taken; visible but not projected), then `recomposite vs source: mean \|d\|, within 8, error px > 40, uncovered error px`, then `uncovered holes (8-connected): N` and the largest five as `uncovered hole K: <px> px at x,y wxh (between "<part>" <px> px, …)`, then one `uncovered: <n> of the <N> uncovered error px lie on the full run's "<tag>", in a body of <px> px at x,y wxh; <the rule that left it out>` line per full-run layer the plan does not take from the full run whose uncovered error holds a body (5x5-opened, 8-connected, at least 150 full-run px in rig px); and look at `render/recomposite_error_rig.png`. Between the part lines and the totals, one `cut: "<part>" opaque <n> = "<part>" <kept> + "<piece>" <taken> …` line per part an `assemble.cuts` entry cut (below; it ends `; under <n> px filled, <m> px left empty` when a cut of that part has `under`), then one `fringe pushed back: "<part>" <px> px, where the painting shows "<holder>" <px> px, …` line per part whose fringe was cleared (below) | on the examples: `reference-sample` 0.83 / 98.0 % / 4,359 / 1,185, 259 holes, the largest 94 px; `reference-demo` 2.34 / 95.8 % / 10,340 / 1,564, 453 holes, the largest 70 px (default rule) — many slivers along part edges, no hole a region could hide | one large hole: part of the figure is in no layer — a plan entry is missing, hair left the head crop sideways (reference-demo's `hair_back` is taken from the full run for that reason), or See-through split one garment into two and left the space between them in neither (a skirt as two trouser legs); the `between` parts say where. When neither run holds it at all, an `assemble.patches` entry cuts it from the painting (below) |
|
|
1241
|
-
| `propose` | `note:` lines, `LINT` lines, the `coverage` lines, `landmarks.png`, `basis.json` | no LINT line: every chain link lies on its mesh's art, and the hip is below the chest and the figure's top quarter; the `coverage:` summary says how many bones that verdict covers — a `not checked` bone was read by no check (its line says why), and a `ratio` or `fallback` bone in `basis.json` is a guess | a link off the art (a bone on the background) — move it onto the layer; `LINT hip at [x, y] is not below chest at [x, y]: …` or `LINT hip at [x, y] is above 0.25 of the figure height (figure y T..B, so hip y must be at least L): a hip at the shoulders` — move `hip` down to the waist (and `chest` between it and the neck); a `hanging strand … -- no chain proposed` note — that strand hangs stiff until you add a chain down the x and rows it names (§3); a `no blink: …` or `blink without brows: …` note — the idle will not blink (or its brows will not drop), because no part came from an `eyewhite` (or `eyebrow`) layer; the note names the tags looked for; a `no eyewhite part for eye_<s> …` note — the iris and lash parts it names ride `head` and do not blink, because no `eyewhite-<s>` part made that side's eye bone: take the eyewhite from the other run, or keep them on `head`; a `no face part: face box derived from …` note (always the first) — `head`, `neck` and every face-height scale come from a box guessed off the hair and neck (§3): check `head` and `neck` on `landmarks_head.png` and move them; when it adds `the blink shuts the eyes over no face part`, read `BLINK_NO_HOLE` after `check` — an eye with no face under it can open a hole (the `reference-sample` with only its face removed: 587 px). Under `--keypoints`: the `lint rule set:` line first (joints, or screen and why), then the joint notes — `missing: the rule "…" placed bone X instead` is a bone still guessed; `not used — …` names why an arm's joints did not place its sleeve (for a wrist on no part, the nearest part and the `--wrist-snap` that would bind it); a `wrist snap: …` note is a wrist bound past 15 px by the flag — check that chain's tip on `landmarks.png`; a `one handwear part holds both wrists` note is two chains on one mesh — cut the part with `assemble.cuts` to separate them; `LINT chest at … is not between the neck joint …`, `LINT hip at … is not past chest …`, `LINT hip at … is nearer the neck joint …` and `LINT <chain><i> at … does not advance from <s>_shoulder toward <s>_wrist` are the joint-frame lines: move that bone between, past or along the joints they name |
|
|
1260
|
+
| `assemble` | one line per part, the `pixels:` totals (opaque = visible + occluded; taken; visible but not projected), then `recomposite vs source: mean \|d\|, within 8, error px > 40, uncovered error px`, then `uncovered holes (8-connected): N` and the largest five as `uncovered hole K: <px> px at x,y wxh (between "<part>" <px> px, …)`, then one `uncovered: <n> of the <N> uncovered error px lie on the full run's "<tag>", in a body of <px> px at x,y wxh; <the rule that left it out>` line per full-run layer the plan does not take from the full run whose uncovered error holds a body (5x5-opened, 8-connected, at least 150 full-run px in rig px), then one `drift: "<part>" refuses <n> px of <run>:<tag> (its colour more than 90 off the painting, max channel), in a body of <px> px at x,y wxh (…); by the plan's draw order "<holder>" holds <px> px of it (…), "<holder>" drawn in front of "<part>"` line per part whose drift refusals hold a body (the same opening and bar) that another part holds in the draw order — that layer is not what the painting shows there (none on the five public paintings); and look at `render/recomposite_error_rig.png`. Between the part lines and the totals, one `cut: "<part>" opaque <n> = "<part>" <kept> + "<piece>" <taken> …` line per part an `assemble.cuts` entry cut (below; it ends `; under <n> px filled, <m> px left empty` when a cut of that part has `under`), then one `fringe pushed back: "<part>" <px> px, where the painting shows "<holder>" <px> px, …` line per part whose fringe was cleared (below) | on the examples: `reference-sample` 0.83 / 98.0 % / 4,359 / 1,185, 259 holes, the largest 94 px; `reference-demo` 2.34 / 95.8 % / 10,340 / 1,564, 453 holes, the largest 70 px (default rule) — many slivers along part edges, no hole a region could hide | one large hole: part of the figure is in no layer — a plan entry is missing, hair left the head crop sideways (reference-demo's `hair_back` is taken from the full run for that reason), or See-through split one garment into two and left the space between them in neither (a skirt as two trouser legs); the `between` parts say where. When neither run holds it at all, an `assemble.patches` entry cuts it from the painting (below) |
|
|
1261
|
+
| `propose` | `note:` lines, `LINT` lines, the `coverage` lines, `landmarks.png`, `basis.json` | no LINT line: every chain link lies on its mesh's art, and the hip is below the chest and the figure's top quarter; the `coverage:` summary says how many bones that verdict covers — a `not checked` bone was read by no check (its line says why), and a `ratio` or `fallback` bone in `basis.json` is a guess | a link off the art (a bone on the background) — move it onto the layer; `LINT <link> at … runs to … N degrees off the head's down axis …` — a fringe link that does not lean with the head (§3, the fringe in the head's frame): move it along the lock it drives; `LINT hip at [x, y] is not below chest at [x, y]: …` or `LINT hip at [x, y] is above 0.25 of the figure height (figure y T..B, so hip y must be at least L): a hip at the shoulders` — move `hip` down to the waist (and `chest` between it and the neck); a `hanging strand … -- no chain proposed` note — that strand hangs stiff until you add a chain down the x and rows it names (§3); a `no blink: …` or `blink without brows: …` note — the idle will not blink (or its brows will not drop), because no part came from an `eyewhite` (or `eyebrow`) layer; the note names the tags looked for; a `no eyewhite part for eye_<s> …` note — the iris and lash parts it names ride `head` and do not blink, because no `eyewhite-<s>` part made that side's eye bone: take the eyewhite from the other run, or keep them on `head`; a `no face part: face box derived from …` note (always the first) — `head`, `neck` and every face-height scale come from a box guessed off the hair and neck (§3): check `head` and `neck` on `landmarks_head.png` and move them; when it adds `the blink shuts the eyes over no face part`, read `BLINK_NO_HOLE` after `check` — an eye with no face under it can open a hole (the `reference-sample` with only its face removed: 587 px). Under `--keypoints`: the `lint rule set:` line first (joints, or screen and why), then the joint notes — `missing: the rule "…" placed bone X instead` is a bone still guessed; `not used — …` names why an arm's joints did not place its sleeve (for a wrist on no part, the nearest part and the `--wrist-snap` that would bind it); a `wrist snap: …` note is a wrist bound past 15 px by the flag — check that chain's tip on `landmarks.png`; a `one handwear part holds both wrists` note is two chains on one mesh — cut the part with `assemble.cuts` to separate them; `LINT chest at … is not between the neck joint …`, `LINT hip at … is not past chest …`, `LINT hip at … is nearer the neck joint …` and `LINT <chain><i> at … does not advance from <s>_shoulder toward <s>_wrist` are the joint-frame lines: move that bone between, past or along the joints they name |
|
|
1242
1262
|
| `compare` | one line per pair (origin, parent, tip, length, direction — or SKIP and why), then the per-row summary, the unmapped bones of each side, `required:`, each side's roles and the `controls:` line | proposal against the config you corrected: the rows you changed and no others. Config against the `rig.json` `build` writes for it: measured on both examples, every origin within 6.19e-7 px (the rig's offsets are written to 6 places) and every chain link's tip and length within 4.99e-4 px (`length` is written to 3), printed to three places as `0.000` (a signed figure as `+0.000` or `-0.000`); `parent … is the right's ancestor at depth 2, <bone>_ctl between` for every keyed mesh bone, no `DIFFERENT` and no `NOT MAPPED` | `parent DIFFERENT: left a, right b` — a bone hangs from another parent than the other side's; `frames not related` — a rig with no stage (`skeleton.width`/`height`), two configs at different `rig_scale`: the distance rows SKIP, so declare the frame in a `--map` file if the author knows it; `FAIL STRUCTURE_REQUIRED_PRESENT` — a bone the map requires is missing through its pairs |
|
|
1243
1263
|
| `rig` (inside `build`) | one line per mesh: vertices, triangles, bones, influences, `cover`; the `bones` line; the `idle keys` line; then rigc's gate lines (with A15's declared SKIP under `--idle-keys direct`); in `rig.json`, each chain link's (or its `_ctl`'s) `length` and `rotation` | `cover 1.00000` on every mesh, both gate summaries `0 failed` (the compile and the packed pages); every link's `length` the distance to the next link and `rotation` its direction (Spine degrees, counter-clockwise, y up, local to the parent), every offset under it — a child bone's `x, y`, a weight's bind `x, y`, a region's `x, y` — in that turned frame, and a region on a link carrying `rotation` that turns it back upright. Nothing moved: `flattenRig` (`src/rig.ts`) turns every offset back and gives the unturned numbers | `RIG_LATTICE_ONE_LOOP`: change that mesh's `grid` |
|
|
1244
1264
|
| `check` (inside `build`) | the gate lines verbatim, the pack line, `loop:` (and `loop physics:` when the rig declares a physics constraint, §7), `seam:`, the six judgement lines, `RECOMPOSITE_HOLES` and, under `--source`, `SETUP_POSE_VS_SOURCE` (§7), `check.json`; the last line says how many of the nine bars measured and names the ones that said SKIP | `check: PASS; 9 of 9 bar(s) measured, 0 skipped` on the examples, and a judgement line SKIP only where the character lacks what it reads; on a rig spec with no `parts.json` or no `idle` (a merged rig, §7 *Measuring a rig rig-parts did not assemble*), PASS with the skipped bars named | `CHECK_SEAM_WITHIN_BAR` or `CHECK_LOOP_CLOSES` (§6) |
|
|
@@ -1255,9 +1275,10 @@ entry, no dithering, filter None) — and is the small file to show. `idle.gif`
|
|
|
1255
1275
|
(`loop --out x.gif`) is the same median cut in a GIF. The indexed APNG and the GIF
|
|
1256
1276
|
print their palette error, per channel over R, G and B of every frame (and alpha's
|
|
1257
1277
|
max for the APNG); a figure is a measurement of the file, not a bar. On the demo
|
|
1258
|
-
(the README's animation since issue #224's follow-up: `build --loop --lead-in 3
|
|
1259
|
-
2.
|
|
1260
|
-
at max
|
|
1278
|
+
(the README's animation since issue #224's follow-up: `build --loop --lead-in 3`), on
|
|
1279
|
+
the 40-frame idle of issue #252 (rig-c 2.40.0): 4,514,756 B lossless, 725,845 B indexed
|
|
1280
|
+
and 784,074 B GIF, both palette files at max 70, mean 0.631; on the 4 s idle before it
|
|
1281
|
+
(rig-c 2.33.0): 5,148,992, 727,486 and 781,526 B at max 69, mean 0.630 — the two share one quantiser, so their error is the same by
|
|
1261
1282
|
construction and the size is the difference. From issue #227 until then, `build --loop`
|
|
1262
1283
|
with default flags, before the demo carried physics: 5,832,634, 827,857 and 889,063 B
|
|
1263
1284
|
at max 65, mean 0.879.
|
|
@@ -1271,7 +1292,7 @@ renders the idle played n + 1 times back to back (`idle_lead_in`, the build's ot
|
|
|
1271
1292
|
animations kept so the viewport is fitted as for the idle frames), keeps the last
|
|
1272
1293
|
period, drops its end frame (the next period's first) and prints how far that end frame
|
|
1273
1294
|
is from the first kept one — the jump the loop will show. The settling is the rig's, not
|
|
1274
|
-
a constant: on the demo, `--lead-in 1` and `2` each still read max |d| 117, 305 px over 40, and `3` reads max 1, 0 px over 40. The idle
|
|
1295
|
+
a constant: on the demo's 4 s idle, `--lead-in 1` and `2` each still read max |d| 117, 305 px over 40, and `3` reads max 1, 0 px over 40; on its 40-frame idle (issue #252, a shorter period and a breath twice as far), `3` reads max 7, 0 px over 40. The idle
|
|
1275
1296
|
must repeat without an invented value — every track keyed from 0 to the duration, ending
|
|
1276
1297
|
where it starts — or the build refuses it (`LOOP_LEAD_IN_IDLE`). `check` and its bars
|
|
1277
1298
|
read `check/idle_frames/` as before; only the loop files move. On reference-demo with `--seam silhouette`
|
|
@@ -1408,10 +1429,19 @@ production rigs most favourable to it, it adds 0.15 % of the rectangle area over
|
|
|
1408
1429
|
stage 1 at tolerance 0, and nothing at the mesher's tolerance 1 or under `pot`; on
|
|
1409
1430
|
these two examples −0.3 to −1.3 points. No build converts a region attachment.
|
|
1410
1431
|
|
|
1432
|
+
Which layer of a run owns a pixel — the one that may take the painting's pixel there
|
|
1433
|
+
— follows the plan: where two planned layers of one run are both opaque (`alpha >=
|
|
1434
|
+
250`), the one the plan draws in front owns it, whatever See-through's depth says
|
|
1435
|
+
(issue #255). A layer no plan entry takes keeps its depth: where it is in front, the
|
|
1436
|
+
painting shows a layer the rig does not draw, and no planned part takes that pixel.
|
|
1437
|
+
The proposer writes each run's parts in depth order, so on a proposed plan the two
|
|
1438
|
+
agree; they differ only where an author reorders the plan, and on the five public
|
|
1439
|
+
paintings no pixel changes owner.
|
|
1440
|
+
|
|
1411
1441
|
`--project core` (the default) is the reference's projection rule: a layer takes the
|
|
1412
1442
|
painting's pixel only inside its top-most `alpha >= 250` area eroded by a 5x5 square,
|
|
1413
1443
|
so a part a few pixels wide (a lash, a brow, an iris) takes none. `--project visible`
|
|
1414
|
-
keeps the erosion only along a rim where a
|
|
1444
|
+
keeps the erosion only along a rim where a layer of the run in front owns the pixel, and
|
|
1415
1445
|
takes every other top-most `alpha >= 250` pixel; neither rule takes a fringe pixel
|
|
1416
1446
|
(alpha below 250). On the examples it lowered the pixels that are visible but not
|
|
1417
1447
|
projected from 36,227 to 22,476 (`reference-sample`) and 76,801 to 49,672 (`reference-demo`), recomposite
|
|
@@ -1516,7 +1546,7 @@ immediately behind `X`; `"front"` patches last, then `"front"` pieces). Its coun
|
|
|
1516
1546
|
| `projected_core_px` | the projection rule's candidates: top-most `alpha >= 250`, eroded (`core`) or kept off a front rim (`visible`) |
|
|
1517
1547
|
| `source_px_taken` | of those, the ones that took the painting's pixel (the reference's count, before any merge) |
|
|
1518
1548
|
| `visible_not_projected_px` | visible pixels whose colour did not come from projection — too thin for the core, a fringe, a rim, refused for drift, or a merge ring |
|
|
1519
|
-
| `refused_drift_px` | candidates refused because See-through's pixel and the painting's differ by more than 90 |
|
|
1549
|
+
| `refused_drift_px` | candidates refused because See-through's pixel and the painting's differ by more than 90. On top-most pixels the seam override repaints refused pixels afterwards, so the field is not a count of pixels left unlike the painting: measured on scarf's `topwear`, 24,944 of 26,472 (issue #255) |
|
|
1520
1550
|
| `merged_px` | pixels brought in below the head crop, and the ring that closes their seam |
|
|
1521
1551
|
| `seam_override_px` | pixels the seam pass recoloured to the painting |
|
|
1522
1552
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rig-parts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.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/assemble.ts
CHANGED
|
@@ -73,6 +73,17 @@
|
|
|
73
73
|
* recorded with the same `<run>:<tag>` (its pixels came from that layer).
|
|
74
74
|
* The cut is made after step 4, so the new part takes the merged pixels and
|
|
75
75
|
* every later step treats it as a part of its own.
|
|
76
|
+
* - **The owner of a pixel follows the plan** (`pixelOwners`, issue #255):
|
|
77
|
+
* where two planned layers of one run are both opaque, the one the plan
|
|
78
|
+
* draws in front owns the pixel for projection; the reference went by
|
|
79
|
+
* See-through's depth alone. The proposer writes each run's parts in depth
|
|
80
|
+
* order, so the two differ only where an author reorders a plan; on the
|
|
81
|
+
* public examples no pixel changes owner, and they assemble to the bytes
|
|
82
|
+
* they did.
|
|
83
|
+
* - **The drift line** (`driftBodies`, issue #255) is this port's: a part
|
|
84
|
+
* whose `DRIFT_LIMIT` refusals hold a body another part holds in the draw
|
|
85
|
+
* order is named, with the body and that part; the reference printed the
|
|
86
|
+
* refused count alone.
|
|
76
87
|
* - **What lies under a piece** (`cuts[].under`, `fillUnder`, issue #193) is
|
|
77
88
|
* this port's: an authored image the base takes where the cut removed its
|
|
78
89
|
* pixels, so a piece that swings away leaves no hole. The stage reads that
|
|
@@ -449,8 +460,8 @@ export interface ProjectionStats {
|
|
|
449
460
|
taken: number;
|
|
450
461
|
refused: number;
|
|
451
462
|
/**
|
|
452
|
-
* Where no
|
|
453
|
-
*
|
|
463
|
+
* Where no layer of the run in front of this one (`frontOf`) owns the
|
|
464
|
+
* pixel (`pixelOwners`): the owner is this layer, one behind it, or none. A
|
|
454
465
|
* pixel of this layer with alpha above 8 is VISIBLE exactly where this is
|
|
455
466
|
* set, and OCCLUDED everywhere else.
|
|
456
467
|
*/
|
|
@@ -466,12 +477,71 @@ function maxDiff(a: Uint8ClampedArray, i: number, b: Uint8ClampedArray, j: numbe
|
|
|
466
477
|
return Math.max(Math.abs(a[i] - b[j]), Math.abs(a[i + 1] - b[j + 1]), Math.abs(a[i + 2] - b[j + 2]));
|
|
467
478
|
}
|
|
468
479
|
|
|
480
|
+
/**
|
|
481
|
+
* The plan's rank of each layer of one run (issue #255): the index of the
|
|
482
|
+
* last plan entry that takes the layer from this run, or -1 for a layer no
|
|
483
|
+
* plan entry takes (an `extend_below_crop` layer included: its pixels are
|
|
484
|
+
* copied into another part, and it keeps See-through's depth).
|
|
485
|
+
*/
|
|
486
|
+
export function planRanks(tags: readonly string[], run: Run, plan: readonly PlanEntry[]): number[] {
|
|
487
|
+
return tags.map((tag) => {
|
|
488
|
+
let r = -1;
|
|
489
|
+
plan.forEach(([, ru, tg], i) => {
|
|
490
|
+
if (ru === run && tg === tag) r = i;
|
|
491
|
+
});
|
|
492
|
+
return r;
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Whether layer `o` of a run is in front of layer `i` of the same run: by the
|
|
498
|
+
* plan when both are planned (`rank` >= 0 for both; the later plan entry is
|
|
499
|
+
* drawn in front), by See-through's depth (the run's own order) otherwise.
|
|
500
|
+
* `rank` null is depth throughout, the reference's rule.
|
|
501
|
+
*/
|
|
502
|
+
export function frontOf(o: number, i: number, rank: readonly number[] | null): boolean {
|
|
503
|
+
if (rank !== null && rank[o] >= 0 && rank[i] >= 0) return rank[o] > rank[i];
|
|
504
|
+
return o > i;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Who owns each rig pixel of one run, for projection (issue #255).
|
|
509
|
+
*
|
|
510
|
+
* ⚖️ Invariant: per pixel, the DEPTH owner is the run's top-most layer with
|
|
511
|
+
* alpha >= `CORE_ALPHA` there (-1: none), the reference's rule. When `rank`
|
|
512
|
+
* is given and the depth owner is a planned layer, the owner is instead the
|
|
513
|
+
* planned layer at alpha >= `CORE_ALPHA` there with the greatest rank: where
|
|
514
|
+
* two planned parts both hold a pixel, the one the plan draws in front takes
|
|
515
|
+
* it, whatever See-through's depth says. A depth owner no plan entry takes is
|
|
516
|
+
* kept — the painting there shows a layer the rig does not draw, and no
|
|
517
|
+
* planned part may take it. Where plan and depth agree the owner is the
|
|
518
|
+
* reference's, pixel for pixel.
|
|
519
|
+
*/
|
|
520
|
+
export function pixelOwners(rigLayers: readonly Raster[], rank: readonly number[] | null): Int32Array {
|
|
521
|
+
const n = rigLayers.length === 0 ? 0 : rigLayers[0].width * rigLayers[0].height;
|
|
522
|
+
const owner = new Int32Array(n).fill(-1);
|
|
523
|
+
for (let p = 0; p < n; p++) {
|
|
524
|
+
let depth = -1;
|
|
525
|
+
let best = -1;
|
|
526
|
+
for (let i = 0; i < rigLayers.length; i++) {
|
|
527
|
+
if (rigLayers[i].data[p * 4 + 3] < CORE_ALPHA) continue;
|
|
528
|
+
depth = i;
|
|
529
|
+
if (rank !== null && rank[i] >= 0 && (best < 0 || rank[i] > rank[best])) best = i;
|
|
530
|
+
}
|
|
531
|
+
owner[p] = rank !== null && depth >= 0 && rank[depth] >= 0 ? best : depth;
|
|
532
|
+
}
|
|
533
|
+
return owner;
|
|
534
|
+
}
|
|
535
|
+
|
|
469
536
|
/**
|
|
470
537
|
* Step 3, over one run's layers in draw order. Modifies each rig layer's
|
|
471
538
|
* colour in place and returns its counts.
|
|
472
539
|
*
|
|
473
|
-
* ⚖️ Invariant: a layer's CORE is where it is the
|
|
474
|
-
* layer of its own run,
|
|
540
|
+
* ⚖️ Invariant: a layer's CORE is where it is the pixel's owner
|
|
541
|
+
* (`pixelOwners`: the top-most `alpha >= 250` layer of its own run, or, with
|
|
542
|
+
* `rank`, the planned one the plan draws in front — issue #255, not in the
|
|
543
|
+
* reference, which is the same wherever plan and depth agree), eroded by a
|
|
544
|
+
* 5x5 square. Inside the core, the pixels
|
|
475
545
|
* that agree with the painting (max channel difference <= `DRIFT_LIMIT`),
|
|
476
546
|
* closed by 5x5 and cut back to the core — and, for the head run, kept
|
|
477
547
|
* `HEAD_WINDOW_INSET` pixels inside the head crop — are the ACCEPTED set. The
|
|
@@ -484,22 +554,20 @@ function maxDiff(a: Uint8ClampedArray, i: number, b: Uint8ClampedArray, j: numbe
|
|
|
484
554
|
*
|
|
485
555
|
* With `rule: 'visible'` (NOT in the reference) the core is the top-most
|
|
486
556
|
* `alpha >= 250` set less every pixel within the 5x5 square of a pixel where a
|
|
487
|
-
*
|
|
557
|
+
* layer in front of it (`frontOf`) is the owner — the erosion kept only along a rim with
|
|
488
558
|
* a neighbour in front, where the painting's pixel may be that neighbour's
|
|
489
559
|
* edge. Every other step is the same. Fringe pixels (alpha below 250) are not
|
|
490
560
|
* projected under either rule: the painting there is this layer blended with
|
|
491
561
|
* what is behind it.
|
|
492
562
|
*
|
|
493
|
-
* Both rules return `clear` (no
|
|
563
|
+
* Both rules return `clear` (no layer in front of this one, by `frontOf`, is the owner) and `takenMask`, the
|
|
494
564
|
* masks the part counts in `parts.json` are derived from; `takenMask` is a
|
|
495
565
|
* subset of the top-most set, and so of `clear`.
|
|
496
566
|
*/
|
|
497
|
-
export function projectSource(rigLayers: Raster[], srcr: Raster, frame: Frame, run: Run, rule: ProjectRule = DEFAULT_PROJECT_RULE): ProjectionStats[] {
|
|
567
|
+
export function projectSource(rigLayers: Raster[], srcr: Raster, frame: Frame, run: Run, rule: ProjectRule = DEFAULT_PROJECT_RULE, rank: readonly number[] | null = null): ProjectionStats[] {
|
|
498
568
|
const { W, H } = frame;
|
|
499
|
-
const owner =
|
|
500
|
-
|
|
501
|
-
for (let p = 0; p < W * H; p++) if (r.data[p * 4 + 3] >= CORE_ALPHA) owner[p] = i;
|
|
502
|
-
});
|
|
569
|
+
const owner = pixelOwners(rigLayers, rank);
|
|
570
|
+
const inFront = (o: number, i: number): boolean => frontOf(o, i, rank);
|
|
503
571
|
let win: Mask | null = null;
|
|
504
572
|
if (run === 'head') {
|
|
505
573
|
win = newMask(W, H);
|
|
@@ -516,7 +584,7 @@ export function projectSource(rigLayers: Raster[], srcr: Raster, frame: Frame, r
|
|
|
516
584
|
const takenMask = newMask(W, H);
|
|
517
585
|
let anyTop = false;
|
|
518
586
|
for (let p = 0; p < W * H; p++) {
|
|
519
|
-
if (owner[p]
|
|
587
|
+
if (owner[p] === -1 || owner[p] === i || !inFront(owner[p], i)) clear.data[p] = 1;
|
|
520
588
|
if (owner[p] === i && r.data[p * 4 + 3] >= CORE_ALPHA) {
|
|
521
589
|
top.data[p] = 1;
|
|
522
590
|
anyTop = true;
|
|
@@ -527,7 +595,7 @@ export function projectSource(rigLayers: Raster[], srcr: Raster, frame: Frame, r
|
|
|
527
595
|
if (rule === 'core') core = erode(top, CORE_KERNEL);
|
|
528
596
|
else {
|
|
529
597
|
const front = newMask(W, H);
|
|
530
|
-
for (let p = 0; p < W * H; p++) if (owner[p]
|
|
598
|
+
for (let p = 0; p < W * H; p++) if (owner[p] >= 0 && owner[p] !== i && inFront(owner[p], i)) front.data[p] = 1;
|
|
531
599
|
const rim = dilate(front, CORE_KERNEL);
|
|
532
600
|
core = newMask(W, H);
|
|
533
601
|
for (let p = 0; p < W * H; p++) if (top.data[p] === 1 && rim.data[p] === 0) core.data[p] = 1;
|
|
@@ -1602,6 +1670,8 @@ export interface AssembleResult {
|
|
|
1602
1670
|
cuts: CutCount[];
|
|
1603
1671
|
/** The full-run layers the plan does not take from the full run whose uncovered error holds a body (`uncoveredErrorLayers`); empty otherwise. */
|
|
1604
1672
|
uncovered: UncoveredErrorLayer[];
|
|
1673
|
+
/** The parts whose `DRIFT_LIMIT` refusals hold a body another part holds in the draw order (`driftBodies`), in draw order; empty otherwise. */
|
|
1674
|
+
drift: DriftBodies[];
|
|
1605
1675
|
seamRule: SeamRule;
|
|
1606
1676
|
projectRule: ProjectRule;
|
|
1607
1677
|
}
|
|
@@ -1664,7 +1734,7 @@ export function assemble(input: AssembleInput): AssembleResult {
|
|
|
1664
1734
|
const layers = runLayers(set, input.resolution);
|
|
1665
1735
|
if (run === 'full') fullTags.push(...layers.filter((l) => l.opaqueRunPx > 0).map((l) => l.tag));
|
|
1666
1736
|
const rigLayers = layers.map((l) => layerToRig(l.canvas, frame, run));
|
|
1667
|
-
const st = projectSource(rigLayers, srcr, frame, run, projectRule);
|
|
1737
|
+
const st = projectSource(rigLayers, srcr, frame, run, projectRule, planRanks(layers.map((l) => l.tag), run, plan));
|
|
1668
1738
|
layers.forEach((l, i) => {
|
|
1669
1739
|
rig.set(`${run}:${l.tag}`, rigLayers[i]);
|
|
1670
1740
|
stats.set(`${run}:${l.tag}`, st[i]);
|
|
@@ -1958,6 +2028,23 @@ export function assemble(input: AssembleInput): AssembleResult {
|
|
|
1958
2028
|
return { record: whole, image: b.r };
|
|
1959
2029
|
});
|
|
1960
2030
|
const pushedBy = pushBackFringe(stack, srcr, seamRule, seamRule === 'silhouette' ? silhouette : null);
|
|
2031
|
+
// Issue #255: a part's drift refusals in a body, and who holds the body in the draw order (the push-back clears
|
|
2032
|
+
// only fringe below CORE_ALPHA, and the seam override only recolours, so the holders read here are final).
|
|
2033
|
+
const holderAt = new Int32Array(W * H).fill(-1);
|
|
2034
|
+
stack.forEach(({ image }, i) => {
|
|
2035
|
+
for (let p = 0; p < W * H; p++) if (image.data[p * 4 + 3] >= CORE_ALPHA) holderAt[p] = i;
|
|
2036
|
+
});
|
|
2037
|
+
const stackNames = stack.map((q) => q.record.name);
|
|
2038
|
+
const drift: DriftBodies[] = [];
|
|
2039
|
+
order.forEach((d) => {
|
|
2040
|
+
if ('patch' in d) return;
|
|
2041
|
+
const { name, b } = pieceAt(d);
|
|
2042
|
+
if (b.st.refusedMask === null) return;
|
|
2043
|
+
const refused = newMask(W, H);
|
|
2044
|
+
for (let p = 0; p < W * H; p++) if (b.st.refusedMask.data[p] === 1 && (b.region === null || b.region.data[p] === 1)) refused.data[p] = 1;
|
|
2045
|
+
const found = driftBodies(name, b.key, refused, bodyMinPx(frame), holderAt, stackNames);
|
|
2046
|
+
if (found !== null) drift.push(found);
|
|
2047
|
+
});
|
|
1961
2048
|
const pushedOf: FringePushed[][] = plan.map(() => []);
|
|
1962
2049
|
const pushedOfCut: FringePushed[][] = cuts.map(() => []);
|
|
1963
2050
|
order.forEach((d, i) => {
|
|
@@ -2048,11 +2135,99 @@ export function assemble(input: AssembleInput): AssembleResult {
|
|
|
2048
2135
|
figures,
|
|
2049
2136
|
cuts: cutCounts,
|
|
2050
2137
|
uncovered,
|
|
2138
|
+
drift,
|
|
2051
2139
|
seamRule,
|
|
2052
2140
|
projectRule,
|
|
2053
2141
|
};
|
|
2054
2142
|
}
|
|
2055
2143
|
|
|
2144
|
+
// ---------------------------------------------------------------------------
|
|
2145
|
+
// refused bodies: a part whose layer is not what the painting shows (issue #255)
|
|
2146
|
+
// ---------------------------------------------------------------------------
|
|
2147
|
+
|
|
2148
|
+
/** A part whose `DRIFT_LIMIT` refusals hold a body, and which parts the draw order puts there. */
|
|
2149
|
+
export interface DriftBodies {
|
|
2150
|
+
/** The part, and its `<run>:<tag>`. */
|
|
2151
|
+
part: string;
|
|
2152
|
+
from: string;
|
|
2153
|
+
/** The part's `refused_drift_px`, in a body or not. */
|
|
2154
|
+
refusedPx: number;
|
|
2155
|
+
/** The bar the bodies were held to (`bodyMinPx`, the uncovered line's). */
|
|
2156
|
+
minPx: number;
|
|
2157
|
+
/** The bodies, largest first (`bodiesOf`). */
|
|
2158
|
+
bodies: UncoveredBody[];
|
|
2159
|
+
/**
|
|
2160
|
+
* Over every pixel of the bodies, the part that holds it in the draw order
|
|
2161
|
+
* — the top-most at alpha >= `CORE_ALPHA`, as the seam pass reads a holder
|
|
2162
|
+
* (`seamCandidates`) — with its pixel count, most first, then by name.
|
|
2163
|
+
*/
|
|
2164
|
+
holders: Array<{ part: string; px: number }>;
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
/**
|
|
2168
|
+
* A part's refused bodies that another part holds in the draw order (issue
|
|
2169
|
+
* #255).
|
|
2170
|
+
*
|
|
2171
|
+
* ⚖️ Invariant: `refused` is the part's projection core pixels whose layer
|
|
2172
|
+
* colour is more than `DRIFT_LIMIT` off the painting (`projectSource`'s
|
|
2173
|
+
* `refusedMask`, cut to the part's region); its bodies are `bodiesOf(refused,
|
|
2174
|
+
* minPx)` — the pixels that survive a `BODY_KERNEL` opening, in 8-connected
|
|
2175
|
+
* components of at least `minPx` — the same reading of "a body" as an
|
|
2176
|
+
* uncovered layer's, and the stage passes the same bar (`bodyMinPx`).
|
|
2177
|
+
* `holderAt` is, per rig pixel, the index into `names` of the top-most part
|
|
2178
|
+
* at alpha >= `CORE_ALPHA` in draw order (-1: none), as the seam pass reads a
|
|
2179
|
+
* holder. The result is non-null exactly when the bodies hold a pixel whose
|
|
2180
|
+
* holder is another part: the plan draws that part over the body, which is
|
|
2181
|
+
* the signature of "this layer is not the owner here".
|
|
2182
|
+
*
|
|
2183
|
+
* Not every body: a body the part holds itself, with nothing drawn over it,
|
|
2184
|
+
* is See-through's colour for the part's own pixels disagreeing with the
|
|
2185
|
+
* painting, and on four of the five public paintings it holds bodies of
|
|
2186
|
+
* hundreds to tens of thousands of pixels that no other part touches (the
|
|
2187
|
+
* pull request that added this has the figures); a line there would name no
|
|
2188
|
+
* owner, which is what the line exists to name.
|
|
2189
|
+
*/
|
|
2190
|
+
export function driftBodies(part: string, from: string, refused: Mask, minPx: number, holderAt: Int32Array, names: readonly string[]): DriftBodies | null {
|
|
2191
|
+
let refusedPx = 0;
|
|
2192
|
+
for (let p = 0; p < refused.data.length; p++) refusedPx += refused.data[p];
|
|
2193
|
+
if (refusedPx === 0) return null;
|
|
2194
|
+
const { bodies, pixels } = bodiesWithPixels(refused, minPx);
|
|
2195
|
+
if (bodies.length === 0) return null;
|
|
2196
|
+
const count = new Map<string, number>();
|
|
2197
|
+
for (let p = 0; p < pixels.data.length; p++) {
|
|
2198
|
+
if (pixels.data[p] === 0 || holderAt[p] < 0) continue;
|
|
2199
|
+
const n = names[holderAt[p]];
|
|
2200
|
+
count.set(n, (count.get(n) ?? 0) + 1);
|
|
2201
|
+
}
|
|
2202
|
+
if (![...count.keys()].some((n) => n !== part)) return null;
|
|
2203
|
+
const holders = [...count.entries()].map(([q, px]) => ({ part: q, px })).sort((a, b) => b.px - a.px || (a.part < b.part ? -1 : a.part > b.part ? 1 : 0));
|
|
2204
|
+
return { part, from, refusedPx, minPx, bodies, holders };
|
|
2205
|
+
}
|
|
2206
|
+
|
|
2207
|
+
/**
|
|
2208
|
+
* One `drift` line under the `uncovered` lines: the part, its refused pixels,
|
|
2209
|
+
* their bodies, and the parts the plan's draw order puts on them —
|
|
2210
|
+
* `drift: "topwear" refuses 196 px of full:topwear (its colour more than 90
|
|
2211
|
+
* off the painting, max channel), in a body of 196 px at 16,12 14x14 (at
|
|
2212
|
+
* least 150 px past a 5x5 opening); by the plan's draw order "face" holds 196
|
|
2213
|
+
* px of it (the top-most part at alpha >= 250), drawn in front of "topwear"`.
|
|
2214
|
+
*/
|
|
2215
|
+
export function driftLine(d: DriftBodies): string {
|
|
2216
|
+
const total = d.bodies.reduce((a, b) => a + b.px, 0);
|
|
2217
|
+
const big = d.bodies[0];
|
|
2218
|
+
const held = d.bodies.length > 1 ? `${d.bodies.length} bodies of ${total} px, the largest ${big.px} px at ${bodyBox(big)}` : `a body of ${big.px} px at ${bodyBox(big)}`;
|
|
2219
|
+
const others = d.holders.filter((h) => h.part !== d.part).map((h) => `"${h.part}"`);
|
|
2220
|
+
return (
|
|
2221
|
+
`drift: "${d.part}" refuses ${d.refusedPx} px of ${d.from} (its colour more than ${DRIFT_LIMIT} off the painting, max channel), in ${held} (at least ${fmtPx(d.minPx)} px past a ${BODY_KERNEL}x${BODY_KERNEL} opening); ` +
|
|
2222
|
+
`by the plan's draw order ${d.holders.map((h) => `"${h.part}" holds ${h.px} px`).join(', ')} of it (the top-most part at alpha >= ${CORE_ALPHA}), ${others.join(', ')} drawn in front of "${d.part}"`
|
|
2223
|
+
);
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
/** A rig-pixel bar as the lines print it: a whole number as it is, otherwise to one decimal. */
|
|
2227
|
+
function fmtPx(n: number): string {
|
|
2228
|
+
return Number.isInteger(n) ? String(n) : n.toFixed(1);
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2056
2231
|
// ---------------------------------------------------------------------------
|
|
2057
2232
|
// uncovered bodies: a full-run layer the plan leaves out (issue #233)
|
|
2058
2233
|
// ---------------------------------------------------------------------------
|
|
@@ -2104,12 +2279,20 @@ export interface UncoveredLayer {
|
|
|
2104
2279
|
* the box's top row and left column.
|
|
2105
2280
|
*/
|
|
2106
2281
|
export function bodiesOf(mask: Mask, minPx: number): UncoveredBody[] {
|
|
2282
|
+
return bodiesWithPixels(mask, minPx).bodies;
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2285
|
+
/** `bodiesOf`, and the mask of every pixel that lies in one of the bodies it returns. */
|
|
2286
|
+
export function bodiesWithPixels(mask: Mask, minPx: number): { bodies: UncoveredBody[]; pixels: Mask } {
|
|
2107
2287
|
const opened = dilate(erode(mask, BODY_KERNEL), BODY_KERNEL);
|
|
2108
2288
|
for (let p = 0; p < opened.data.length; p++) if (mask.data[p] === 0) opened.data[p] = 0;
|
|
2109
2289
|
const cc = connectedComponents(opened, 8);
|
|
2110
|
-
const
|
|
2290
|
+
const keep = cc.stats.map((s, l) => l > 0 && s.area > 0 && s.area >= minPx);
|
|
2291
|
+
const all = cc.stats.filter((s, l) => keep[l]);
|
|
2111
2292
|
all.sort((a, b) => b.area - a.area || a.top - b.top || a.left - b.left);
|
|
2112
|
-
|
|
2293
|
+
const pixels = newMask(mask.width, mask.height);
|
|
2294
|
+
for (let p = 0; p < pixels.data.length; p++) if (keep[cc.labels[p]]) pixels.data[p] = 1;
|
|
2295
|
+
return { bodies: all.map((s) => ({ px: s.area, x: s.left, y: s.top, w: s.width, h: s.height })), pixels };
|
|
2113
2296
|
}
|
|
2114
2297
|
|
|
2115
2298
|
/** A body's box as the hole lines print one: `x,y wxh`. */
|
package/src/build.ts
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
44
44
|
import { dirname, join, resolve } from 'node:path';
|
|
45
45
|
import { type AnimFrame, EncodeError, encodeApng, encodeIndexedApng, INDEXED_DEFAULTS } from './apng.ts';
|
|
46
|
-
import { assemble, type AssembleResult, cutLines, figuresLine, holeLines, type ProjectRule, type SeamRule, stageFields, uncoveredLine } from './assemble.ts';
|
|
46
|
+
import { assemble, type AssembleResult, cutLines, driftLine, figuresLine, holeLines, type ProjectRule, type SeamRule, stageFields, uncoveredLine } from './assemble.ts';
|
|
47
47
|
import { allocationClause, type Reducer, stageBClause, unboundedClause } from './automesh.ts';
|
|
48
48
|
import { residualClause } from './autoenvelope.ts';
|
|
49
49
|
import { type AutoMotionCase, failingRows, idleSchedule, localRow, motionClause, motionDeformation, motionDocument, motionInput, motionRowText, motionStimulus, motionVerdict, noStimulusProblem, type ReplayCandidate, runComparison, stimulusMotion, withStimulus } from './automotion.ts';
|
|
@@ -230,6 +230,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
230
230
|
log(figuresLine(result.figures));
|
|
231
231
|
for (const l of holeLines(result.figures)) log(l);
|
|
232
232
|
for (const u of result.uncovered) log(uncoveredLine(u));
|
|
233
|
+
for (const d of result.drift) log(driftLine(d));
|
|
233
234
|
log(`wrote ${outs.partsJson}, ${result.images.length} PNG(s) in ${outs.partsDir}, ${outs.recomposite}, ${outs.errorMap} (uncovered error px red, covered error px blue, the painting grey)`);
|
|
234
235
|
return result;
|
|
235
236
|
}
|
|
@@ -946,7 +947,9 @@ export function barsSummary(r: CheckReport): string {
|
|
|
946
947
|
/**
|
|
947
948
|
* The rig stage's face-axis line (issue #239): the eye line's angle, the parts it runs between and the face bones
|
|
948
949
|
* turned to it, or why there is no line and the face bones keep the page's axes — the note a one-eyed painting gets.
|
|
949
|
-
* With a line it also names the `invariants.axes` entry written for rigc's A51, its tolerance, or why none was
|
|
950
|
+
* With a line it also names the `invariants.axes` entry written for rigc's A51, its tolerance, or why none was; and
|
|
951
|
+
* the entry holding the face bones whose own tip lies along the line, or each such bone with why it is not held
|
|
952
|
+
* (issue #258) — a face with no entry is never silent.
|
|
950
953
|
*/
|
|
951
954
|
export function faceAxisLine(f: FaceAxis): string {
|
|
952
955
|
const own = f.ownTip.length === 0 ? '' : `; ${f.ownTip.join(', ')} ${f.ownTip.length === 1 ? 'takes its' : 'take their'} own tip`;
|
|
@@ -958,7 +961,14 @@ export function faceAxisLine(f: FaceAxis): string {
|
|
|
958
961
|
: f.noAxis !== null
|
|
959
962
|
? `; no invariants.axes entry: ${f.noAxis}`
|
|
960
963
|
: '';
|
|
961
|
-
|
|
964
|
+
// Issue #258: the tipped face bones are held in an entry of their own, or each is named with why it is not.
|
|
965
|
+
const tips =
|
|
966
|
+
f.noAxis !== null && f.turned.length === 0
|
|
967
|
+
? ''
|
|
968
|
+
: `${f.tipAxis === null ? '' : `; invariants.axes "${f.tipAxis.name}" holds ${f.tipAxis.bones.join(', ')}, whose own tips lie along the line within whole-pixel rounding, tolerance ${f.tipAxis.tolerance} degrees (rigc's A51)`}${f.tipOff.map((t) => `; ${t}`).join('')}`;
|
|
969
|
+
// Issue #250: the slotless bone carrying the face's up axis under head, or why there is none.
|
|
970
|
+
const up = f.headUp !== null ? `; head_up under head along the face's up axis, ${f.headUp.rotation} degrees, ${f.headUp.length} px (head's origin to the eye midpoint along it)` : f.headUpNone !== null ? `; no head_up: ${f.headUpNone}` : '';
|
|
971
|
+
return ` face axis: ${pyRound(f.degrees, 6)} degrees, the line through the eye bones eye_r and eye_l (on ${f.parts[0]} and ${f.parts[1]}); ${turned}${own}${held}${tips}${up}`;
|
|
962
972
|
}
|
|
963
973
|
|
|
964
974
|
/** A judgement line as the console prints it: its name, its status, then its figures and bars as check.json holds them (a SKIP prints its reason). */
|