@rig-c/parts 1.21.0 → 1.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/AUTHORING.md CHANGED
@@ -101,7 +101,7 @@ read by no CPU stage).
101
101
  | `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 |
102
102
  | `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 |
103
103
  | `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 |
104
- | `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?}, …]}}`, 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` or `cap_shape` (`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. 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 |
104
+ | `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 |
105
105
  | `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. 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`). 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. 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 |
106
106
  | `meshes.<part>` | rig | **proposed**, then corrected. Exactly one of `grid` (the lattice: cell size, px — what `propose` writes: by default one spacing for the figure, round(H / 37) rig px with H the height of every part's box together, a part whose tenth of its short side is already coarser keeping that, and under `propose --grid-rule part` the reference's tenth of the part's short side clamped to 5..36, issue #265), `contour` (the outline mode, authored; the next row and "A contour mesh" below) or `auto` (the automatic mode, authored; "An automatic mesh" below) — two, or none, is `CONFIG_MESH_MODE`. In every mode: `r` (added to every distance before weighting: `w = 1/(d + r)²`), `segments` (a chain name, a bone name with a `tip`, or `[bone, [x0,y0], [x1,y1]]`), and, **authored**, optional, `exponent` (issue #161): a number above 0 that replaces the 2 in that rule, `w = 1/(d + r)^exponent` — a larger one hands each vertex more fully to its nearest bone; absent is 2 and changes no byte, a value that is not a number above 0 is `CONFIG_FIELD_TYPE` at `meshes.<part>.exponent`, and a declared one is echoed as `exponent` in the mesh's `mesh_report.json` row; the exponent is the distance rule's, so declared beside `rule: "heat"` it is refused (`CONFIG_FIELD_TYPE` at `meshes.<part>.exponent`). The segment list is the one authored decision about a layer: which bones may pull it. The slot's bone is the first segment's. Optional `rule` (issue #161): `"distance"` — the rule above, and what an absent `rule` means (every byte is the same) — or `"heat"`, bone heat over the part's own silhouette, in every mode: the lattice's art (alpha above 8, less any island a declared `stray` left out) with holes filled, or for `contour` and `auto` the silhouette their outline is traced from (that mode's art — alpha above 8 for `contour`, alpha 1 and above for `auto` — less any island a declared `stray` left out, holes filled, grown by its `margin`); each bound bone's sources are the silhouette pixels whose centre lies within 0.75 px of its segment (a pixel two bones reach goes to the nearer, a tie to the first listed), held at 1 for that bone and 0 for the others; the field is solved by row-major Gauss–Seidel over-relaxation to a sweep change under 1e-7 within 20000 sweeps; a vertex reads the nearest silhouette pixel and takes the same cap and floor (and `regions`) as the distance rule; `r` is not read. The mesh's `mesh_report.json` row gains `heat` (the constants, each bone's sources and sweeps, the residual). Any other value is `CONFIG_FIELD_TYPE`; a bound bone with no source pixel is `RIG_HEAT_BONE_SOURCE`, an island no bone has a source in `RIG_HEAT_ISLAND_SOURCE`, a solve past its sweep bound `RIG_HEAT_CONVERGED` — none is weighted 0. The rule is chosen per mesh, so `RIG_HEAT_BONE_SOURCE` names three remedies: move the segment onto the art, take the bone out of `segments`, or keep this part on the distance rule — the one to take when the bone anchors the part from outside its art (a torso bone under a neck), since the first moves a bone another part placed and the second drops the anchor (issue #303). On a lattice, `RIG_HEAT_ISLAND_SOURCE` on an island that is dust — at most 4 px and at most 0.1 % of the part's art px, `mesh-draft`'s line — names `meshes.<part>.stray` and the figure that leaves it out, with the value declared; an island above that line keeps the segment remedy, a real piece being a real authoring question |
107
107
  | `meshes.<part>.contour` | rig | **authored**, optional (issue #84): `{tolerance, margin, spacing, maxEdge?, budget?, stray?, bridges?, 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; `maxEdge` (issue #265) — the longest outline edge, px, above 0: every simplified edge longer than it is cut into `ceil(length / maxEdge)` equal pieces, each cut point on the 1/256 px grid, before any region or rib touches the outline (absent: nothing is cut, and no byte moves; under 2/256 px the rig stage refuses it, `CONTOUR_PARAMETER`, because two cut points could snap together); the row echoes it in `params` and counts the points it added in `contour.outlineCut`, both only when declared; `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); `bridges` (issue #326) — `true`, its one value: islands are read in this order — **dust first** (those `stray` leaves out), **then faint islands** (every pixel's alpha under 64, a quarter of full opacity: left out the same way, their pixels kept in the image but not meshed, so not drawn, and named in the row's `contour.bridges.faint` with their px, brightest alpha and box), **then every visible island is meshed and bridged, whatever the bridge costs** — overdraw is reported, never a reason to drop art; the largest island, or a tie for it, is never left out, faint or not: dropping it would draft the part without its art, and a part whose main body is faint is a question about the layer, which the plan and the author own, not one for the mesh — and the pieces are joined into the one outline rig-c takes by bridges — the kept islands, holes filled, grow together by `margin`, so islands closer than about twice the margin are one grown silhouette, traced as one; each silhouette is traced, simplified, capped, refined and triangulated as a one-island mesh is; then, starting from the silhouette with the most art, the nearest pair of a vertex on the joined outline and one on a silhouette still apart whose quad holds (wound as the mesh, crossing no outline, holding no other vertex, one closed outline after) is joined by that quad, two triangles over no art, until none is apart. Coverage and overshoot read the silhouettes' triangles; a bridge's area is in `meshArea` and in the row's `contour.bridges` (`islands`, `units`, and per join `unit`, `span` — its two crossing edges, px — `area`, `vertices`, `pair`; and `faint`, only when an island was left out as faint), and the row's `params` echoes `bridges`, both only when declared; `art_coverage` counts a faint island's pixels as art not covered. Absent, a second island is refused as below and no byte moves; on one island it writes the mesh the undeclared entry writes. Any other value is `CONFIG_FIELD_TYPE`; beside `ribs` it is `CONTOUR_PARAMETER` (a rib runs across one outline); a join no pair makes is `CONTOUR_BRIDGE`. A bridge stretches with whatever pulls its two ends apart, so it belongs on a part whose pieces ride one bone — the only case `mesh-draft` drafts; `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 |
@@ -506,6 +506,26 @@ layers, as follows; every step is arithmetic on the declared bones and the layer
506
506
  angle, the rest pose composites to the hard cut's bytes and no bend shows through the fade what
507
507
  lies behind the limb. The `limb cap:` line adds `edge "feather": N px of "<upper>" faded …`, and
508
508
  the record `edge`, `feather_radius` and `feathered_px`.
509
+ - **`cut_band: N`** (issue #360, opt-in on the segment below a joint whose two segments take one
510
+ part). The cut is placed rather than typed: of the lines parallel to the joint line at whole-pixel
511
+ offsets `-N .. N` along the axis, the one that crosses the fewest **stroke pixels**. A line crosses
512
+ the pixels a joint line runs through (the limb's art whose centre lies within half a pixel of it,
513
+ across the run of art through its point — the reading the limb's width uses); a stroke pixel is one
514
+ of those, over the whole band, whose integer BT.601 luma is at or below the **Otsu split** of their
515
+ luma histogram (the dark class of the two that maximise the between-class variance). The split is
516
+ derived from the band's own art and no threshold is typed: art of one luma has no split and so no
517
+ stroke. Ties go to the line nearer the joint, then to the upper side, so with nothing to avoid the
518
+ joint line itself is chosen. The bone does not move — the joint, the cap's disc and the limb's width
519
+ stay at its origin; only the line that splits the pixels between the two pieces moves, and the cap
520
+ takes the disc's pixels on the upper side of that line (under `edge: "feather"` the fade runs from
521
+ that line to the band's arc). The art read is the layer as the cut splits it, before the seam pass
522
+ recolours what the painting shows. A cut off the joint line leaves a sliver of one piece on the other
523
+ side of the pivot; `SEAM_OVER_RANGE` reads what that costs at a bend. A band with a line off the
524
+ limb's art is `ASSEMBLE_LIMB_CUT_BAND`. The `limb cap:` line adds `cut_band N: the cut
525
+ <k> px before|past the joint line (toward "<part>"), through [x, y], crosses <n> stroke px; the joint
526
+ line crosses <m> (stroke: luma <T> or below, the Otsu split of the <px> px …)`, and the record
527
+ `cut_band`, `cut_offset`, `cut_at`, `cut_crossed`, `joint_crossed`, `band_px` and, when the band has
528
+ a split, `stroke_luma_max`.
509
529
  - **Draw order.** A limb stands where its upper segment's part stood in the plan, its parts
510
530
  lowest first, so the upper is drawn over the lower at every joint: upper arm over forearm,
511
531
  thigh over shin, shin over foot. The parts it took leave the order.
@@ -2010,7 +2030,7 @@ move off it (`AS245`).
2010
2030
  | --- | --- | --- | --- |
2011
2031
  | `layers` | the table, then one `author-made: layer "author:<label>" — …` line per layer the author made (group `author` in the table; §5, *A layer the author made*), 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*) |
2012
2032
  | `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 |
2013
- | `assemble` | one line per part — its counts (`op=` opaque, `vis=` visible, `src=` taken / candidates, `unproj=` visible but not projected, `drift=<n> (<p>% of core)`, `merged=`, `seam=`; *parts.json*, below). `drift=` is `refused_drift_px` in rig px and its share of the part's candidates, `projected_core_px`, which it is a subset of (issue #314); no bar reads either. On the four public examples the share runs to 94.5 % (`scarf` `hair_back`, 479 of 507) and the count to 26,472 (`scarf` `topwear`, 22.3 %), and the seam override repaints refused top-most pixels afterwards, so a large count says where See-through's colour was not taken, not that the part is unlike the painting: the `drift:` line below is the one that names a body of them another part holds. Then 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 `author-made: part "<part>" (<run>:author:<label>) — …` line per part from a layer the author made (below, *A layer the author made*), then 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 — with `config.limbs` (issue #349) — one `limb cut: "<part>" opaque <n> = "<segment part>" <px> + …` line per part a limb takes and one `limb cap:` line per joint, its cap's pixels from the cap image, from the layer and missing, and its box — under `cap_shape: "disc"` also from the upper segment, under `edge: "feather"` the pixels faded (issue #360) (§3, *Limbs: cut at their joints*), 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) |
2033
+ | `assemble` | one line per part — its counts (`op=` opaque, `vis=` visible, `src=` taken / candidates, `unproj=` visible but not projected, `drift=<n> (<p>% of core)`, `merged=`, `seam=`; *parts.json*, below). `drift=` is `refused_drift_px` in rig px and its share of the part's candidates, `projected_core_px`, which it is a subset of (issue #314); no bar reads either. On the four public examples the share runs to 94.5 % (`scarf` `hair_back`, 479 of 507) and the count to 26,472 (`scarf` `topwear`, 22.3 %), and the seam override repaints refused top-most pixels afterwards, so a large count says where See-through's colour was not taken, not that the part is unlike the painting: the `drift:` line below is the one that names a body of them another part holds. Then 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 `author-made: part "<part>" (<run>:author:<label>) — …` line per part from a layer the author made (below, *A layer the author made*), then 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 — with `config.limbs` (issue #349) — one `limb cut: "<part>" opaque <n> = "<segment part>" <px> + …` line per part a limb takes and one `limb cap:` line per joint, its cap's pixels from the cap image, from the layer and missing, and its box — under `cap_shape: "disc"` also from the upper segment, under `edge: "feather"` the pixels faded, under `cut_band` the line the cut was placed on and the stroke pixels it and the joint line cross (issue #360) (§3, *Limbs: cut at their joints*), 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) |
2014
2034
  | `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 |
2015
2035
  | `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 |
2016
2036
  | `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` |
@@ -2590,6 +2610,7 @@ says why each requirement exists and what breaks without it.
2590
2610
  | <a id="ASSEMBLE_UNDER_DRAW"></a>`ASSEMBLE_UNDER_DRAW` | a cut with `under` draws its piece behind its part, which the fill would hide it under | that cut's `draw`: `"front"`, or `{"before": …}` the plan part after its `from` |
2591
2611
  | <a id="ASSEMBLE_LIMB_TAKES"></a><a id="ASSEMBLE_LIMB_PIXELS"></a>`ASSEMBLE_LIMB_TAKES`, `ASSEMBLE_LIMB_PIXELS` | a part a limb takes has no opaque pixel, or a limb segment gets none of it — the joint lines through the bones' origins put none of the limb's pixels on it, or another limb's polyline is nearer every one (issue #349) | the bones: their origins on the limb's art, each joint where the limb bends |
2592
2612
  | <a id="ASSEMBLE_LIMB_JOINT"></a><a id="ASSEMBLE_LIMB_JOINT_ON_ART"></a>`ASSEMBLE_LIMB_JOINT`, `ASSEMBLE_LIMB_JOINT_ON_ART` | a joint has no line — the upper bone has no length, or the limb folds straight back on itself — or its bone's origin lies on none of the limb's art within 1 px along the line, so the limb has no width there to size the cap by (issue #349); under `cap_shape: "disc"`, also a bone's origin on the very edge of the run, which has no half-width about it (issue #360) | the joint's bone: on the limb's art, at the joint |
2613
+ | <a id="ASSEMBLE_LIMB_CUT_BAND"></a>`ASSEMBLE_LIMB_CUT_BAND` | a segment's `cut_band` reaches past the limb: a line of its band, the detail names the one nearest the joint and a point it passes through, crosses none of the limb's art within 1 px of that point, so a cut placed there would cut nothing (issue #360) | `cut_band`: the widest band whose every line crosses the limb, which the detail gives |
2593
2614
  | <a id="ASSEMBLE_LIMB_CAP_PRESENT"></a><a id="ASSEMBLE_LIMB_CAP_DECODES"></a><a id="ASSEMBLE_LIMB_CAP_SIZE"></a><a id="ASSEMBLE_LIMB_CAP_EMPTY"></a>`ASSEMBLE_LIMB_CAP_PRESENT`, `ASSEMBLE_LIMB_CAP_DECODES`, `ASSEMBLE_LIMB_CAP_SIZE`, `ASSEMBLE_LIMB_CAP_EMPTY` | a segment's `cap` names no file (relative to the config's directory) or one that is not a PNG; an image not the size of the cap's box (the detail gives both, and the box's corner); or one transparent over every cap pixel (issue #349) | the image: the box the `limb cap:` line prints, `w`x`h`, its pixel `(i, j)` rig pixel `(x + i, y + j)`; to keep the layer's cap, drop `cap` |
2594
2615
  | <a id="ASSEMBLE_HIDDEN_ONE_SOURCE"></a>`ASSEMBLE_HIDDEN_ONE_SOURCE` | a cut's `under`, or a limb segment's `cap`, names a file, and the part it reads also has a hidden-art layer (`<layer>:hidden`, issue #359): reading either would be a guess | remove the file from the config, or the hidden-art layer from the input |
2595
2616
  | <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 |
package/docs/STABILITY.md CHANGED
@@ -126,7 +126,7 @@ part name, `[i]` an entry of a list):
126
126
  - **assemble.cuts[i]** — required: `from`, `into`, `polygon`, `draw`, `overlap`; optional: `under`, `under_fill`
127
127
  - **assemble.cuts[i].draw**, when an object — required: `before`
128
128
  - **limbs.&lt;limb&gt;** — required: `segments` (issue #349)
129
- - **limbs.&lt;limb&gt;.segments[i]** — required: `part`, `from`, `bone`; required below a joint (i > 0): `joint`; optional below a joint: `range`, `cap`, `edge`, `cap_shape`
129
+ - **limbs.&lt;limb&gt;.segments[i]** — required: `part`, `from`, `bone`; required below a joint (i > 0): `joint`; optional below a joint: `range`, `cap`, `edge`, `cap_shape`, `cut_band`
130
130
  - **bones[i]**, a single bone — required: `name`, `parent`, `at`; optional: `tip`, `inherit`
131
131
  - **bones[i]**, a chain — required: `chain`, `parent`, `points`, `tip`
132
132
  - **meshes.&lt;part&gt;** — exactly one of `grid`, `contour`, `auto`; required in every mode: `r`, `segments`; optional in every mode: `exponent`, `rule`; optional with `contour` or `auto`: `ribs`; optional with `grid` or `contour`: `influences` (issue #284; beside `auto` it is refused, CONFIG_INFLUENCES_MODE); optional with `grid`: `stray` (issue #303; beside `contour` or `auto` it is refused, CONFIG_STRAY_MODE)
@@ -178,7 +178,7 @@ every number) are AUTHORING §3's tables, and the loader refuses any other by na
178
178
 
179
179
  | file | written by | what is stable |
180
180
  | --- | --- | --- |
181
- | `parts.json`, `parts/<name>.png` | `assemble`, `build` | one record per part: `from` (`<run>:<tag>` with a See-through v3 tag, `<run>:author:<label>` for a layer the author made — issue #256, read by no role rule — or `painting:<name>` for a patch), `cut_from` on a cut's piece only (the plan part it was cut from, issue #230), `limb` on a limb segment's part only (issue #349: `name`, `segment`, `of`, `bone`, and below a joint `joint`, `range` when the config segment declares one (issue #360), and `cap` — `at`, `width`, `radius`, `box`, `layer_px`, `image_px` with a cap image, `image_layer` after it when that image was a hidden-art layer — issue #359, `<run>:<layer>:hidden` — `missing_px`, then `shape` and `upper_px` under the segment's `cap_shape`, and `edge`, `feather_radius` and `feathered_px` under its `edge`, issue #360), the box `x`, `y`, `w`, `h` (rig px), the pixel counts `src/parts.ts` documents (`opaque_px`, `visible_px`, `occluded_px`, `projected_core_px`, `source_px_taken`, `visible_not_projected_px`, `refused_drift_px`, `merged_px`, `seam_override_px`, and `fringe_pushed_back` when not empty); `rig_size`, `scale_rig_per_source`, `ghost_px`, `recomposite`, and `scene` (`figure_alpha_above`, `figure_px`, `figure_mask`) under `config.scene` only, with the figure's mask `figure_rig.png` beside the recomposite (issue #242); `single_run_pad` (`file_size`, `side`, `left`, `top`) last, only for one run whose file is not the `seethrough.resolution` square (issue #366) |
181
+ | `parts.json`, `parts/<name>.png` | `assemble`, `build` | one record per part: `from` (`<run>:<tag>` with a See-through v3 tag, `<run>:author:<label>` for a layer the author made — issue #256, read by no role rule — or `painting:<name>` for a patch), `cut_from` on a cut's piece only (the plan part it was cut from, issue #230), `limb` on a limb segment's part only (issue #349: `name`, `segment`, `of`, `bone`, and below a joint `joint`, `range` when the config segment declares one (issue #360), and `cap` — `at`, `width`, `radius`, `box`, `layer_px`, `image_px` with a cap image, `image_layer` after it when that image was a hidden-art layer — issue #359, `<run>:<layer>:hidden` — `missing_px`, then `shape` and `upper_px` under the segment's `cap_shape`, and `edge`, `feather_radius` and `feathered_px` under its `edge`, and `cut_band`, `cut_offset`, `cut_at`, `cut_crossed`, `joint_crossed`, `band_px` and `stroke_luma_max` (when the band has a split) under its `cut_band`, issue #360), the box `x`, `y`, `w`, `h` (rig px), the pixel counts `src/parts.ts` documents (`opaque_px`, `visible_px`, `occluded_px`, `projected_core_px`, `source_px_taken`, `visible_not_projected_px`, `refused_drift_px`, `merged_px`, `seam_override_px`, and `fringe_pushed_back` when not empty); `rig_size`, `scale_rig_per_source`, `ghost_px`, `recomposite`, and `scene` (`figure_alpha_above`, `figure_px`, `figure_mask`) under `config.scene` only, with the figure's mask `figure_rig.png` beside the recomposite (issue #242); `single_run_pad` (`file_size`, `side`, `left`, `top`) last, only for one run whose file is not the `seethrough.resolution` square (issue #366) |
182
182
  | `rig/rig.json`, `rig/motion.json`, `rig/images/` | `rig`, `build`, `compose` | rig-c's rig spec and motion spec, `spec` `rigc-rig/1` and `rigc-motion/1`: the format is rig-c's, and this package writes only what rig-c's parser accepts; a bone carries `inherit` only where config.bones declares one, rig-c's mode name as written (issue #348) |
183
183
  | `rig/mesh_report.json` | `rig`, `build` | one row per mesh: `part`, `vertices`, `triangles`, `hull`, `bones`, `max_influences`, `mean_influences`, `art_coverage`, then `grid` (a lattice); `mode` "contour" with `params`, `contour`, `regions` (`params.maxEdge` and `contour.outlineCut` only when the mesh declares `contour.maxEdge`; `params.bridges` and `contour.bridges` — `islands`, `units`, `joins`, and `faint` only when an island was left out as faint — only when it declares `contour.bridges`); or `mode` "auto" with `settings`, `source`, `result`, `residuals`, `worst_residual`, `worst_region`, `motion_amplitude`, `termination`, `weights`, `regions`, `deformation`, `quality_report` (rig-c's `mesh-quality-report/1` document whole), `motion_report`, and, only when they apply, `stray_cleared` (after `source`, when `source.stray` is declared), `skinning_residual` and `replay` (`AutoMeshReport` in `src/rig.ts`); in every mode, `exponent` when the mesh declares one (after `grid`, or after `mode`); `influences`, as declared, when a lattice or contour mesh declares it (after `exponent`, or where `exponent` would be); `stray` and `stray_cleared` when a lattice mesh declares `stray` (after `influences`, or where `influences` would be); `ribs` when a contour or auto mesh declares them (after `exponent`, or after `mode`), and then `contour.ribs` (`source.contour.ribs` in the automatic mode) |
184
184
  | `check/check.json` and the rest of `check/` | `check`, `build`, `compose` | the reference's fields in its order (`gate_spine_html_green`, `rigc_entry`, `pack_mode`, `loop_max_diff`, the seam figures — `seam_mean`, `seam_px_over_40`, `seam_px_over_80` and, from issue #216, `seam_frame_scale`, the frame scale the bar divides the count by), `loop_physics` after `loop_max_diff` when the rig declares a physics constraint, `seam_border` after the seam figures when `parts.json` declares a scene (issue #242), `seam_pairs` after the seam figures when the seam bar fails or `--seam-pairs` asks (each row's picture under `check/seam/`; `--keep-stills` leaves the setup-pose still and its `frames.json` under `check/setup_still/`), then the judgement lines (`BREATH_VISIBLE`, `BLINK_NO_HOLE`, `CHAIN_LAG`, `TIP_OVER_ROOT`, `STILL_REGIONS_DARK`, `TEXTURE_STRETCH`), `ANIMATIONS_DO_NOT_FOLD` after them when `motion.json` holds an animation, the idle included — on every rig with an idle since issue #333 (issue #320: `status`, `animations`, `fps`, `physics_left_out`, `folding`, `folding_undeclared`, `declared_not_folding`, `bar`), `FEET_STAY_LEVEL` after it when a `footwear` part rides a bone that hangs from another and `motion.json` holds an animation (issue #348: `status`, `reason` on a SKIP only, `animations`, `fps`, `physics_left_out`, `bar_degrees`, `bar`, `feet` — each `part`, `bone`, `hangs_from`, `status`, `frames_posed`, `worst`), `LIMB_ONE_BONE` after it (and after `STRESS_OFF_CHAIN` where that is written) when `parts.json` holds a limb segment's part (issue #349: `status`, `parts` — each `part`, `limb`, `bone`, `status`, `others`), `SEAM_OVER_RANGE` after it when a limb record carries a `range` (issue #360: `status`, `frame_scale`, `physics_left_out`, `bar` — `mean`, `rig_px_over_40`, `level` — and `joints`, each `part`, `limb`, `segment`, `joint`, `bone`, `range`, `at`, `radius`, `under_px`, `status`, `poses` — each `degrees`, `status`, `mean`, `px_over_40`, `px_over_80`, `rig_px_over_40` — and `unread` on a joint not read), `RECOMPOSITE_HOLES` (its first figure `declared_scene` when `parts.json` declares a scene), `SETUP_POSE_VS_SOURCE`, `skipped`, a `requirements` block under `--requirements`, and `PASS`; `check/build/skeleton.json`, `.atlas` and `.png` are the packed artifact rig-c writes |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rig-c/parts",
3
- "version": "1.21.0",
3
+ "version": "1.22.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
@@ -104,7 +104,7 @@ import { type Problem, refuseIfAny } from './errors.ts';
104
104
  import { figuresPhrase, implausibleRules, type Layer, type LayerFigures, layerFigures, type LayerSet, NEAR_WHITE_MIN, OPAQUE_ALPHA_ABOVE, ruleSummary } from './layers.ts';
105
105
  import { padToSquare, squarePad } from './inputs.ts';
106
106
  import { type CapRecord, type LimbRecord, PAINTING_RUN, type PartRecord, type PartsFile, type RecompositeRecord, type SceneRecord, type SingleRunPad } from './parts.ts';
107
- import { type BonePlace, bonePlaces, capBox, coveredRadius, featherWeight, halfWidthAbout, inDisc, jointLine, type JointLine, jointOffsets, limbPolyline, limbRun, nearestLimb, pastJoint, segmentOf } from './limbs.ts';
107
+ import { type BonePlace, bonePlaces, capBox, coveredRadius, type CutPlacement, featherWeight, halfWidthAbout, inDisc, jointLine, type JointLine, jointOffsets, limbPolyline, limbRun, luma601, nearestLimb, pastJoint, placeCut, segmentOf } from './limbs.ts';
108
108
  import {
109
109
  alphaComposite,
110
110
  connectedComponents,
@@ -1859,6 +1859,22 @@ export interface LimbCount {
1859
1859
  joints: Array<{ limb: string; joint: string; part: string; upper: string; cap: CapRecord }>;
1860
1860
  }
1861
1861
 
1862
+ /**
1863
+ * What `cut_band` did at a joint (issue #360, item 14), for the `limb cap:`
1864
+ * line: the line chosen — its offset from the joint line and a point it
1865
+ * passes through — the stroke pixels it crosses, those the joint line
1866
+ * crosses, and the split that made a pixel a stroke.
1867
+ */
1868
+ function cutPhrase(k: CapRecord, upper: string, lower: string): string {
1869
+ const off = k.cut_offset ?? 0;
1870
+ const where = off === 0 ? 'on the joint line' : `${Math.abs(off)} px ${off < 0 ? `before the joint line (toward "${upper}")` : `past the joint line (toward "${lower}")`}`;
1871
+ const stroke =
1872
+ k.stroke_luma_max === undefined
1873
+ ? `no stroke: the ${k.band_px ?? 0} px of the limb's art the band's lines cross hold one luma, so nothing splits from it`
1874
+ : `stroke: luma ${k.stroke_luma_max} or below, the Otsu split of the ${k.band_px ?? 0} px of the limb's art the band's lines cross`;
1875
+ return `cut_band ${k.cut_band ?? 0}: the cut ${where}, through [${(k.cut_at ?? k.at).join(', ')}], crosses ${k.cut_crossed ?? 0} stroke px; the joint line crosses ${k.joint_crossed ?? 0} (${stroke})`;
1876
+ }
1877
+
1862
1878
  /**
1863
1879
  * The lines `assemble` prints for the limbs (issue #349), one per part a limb
1864
1880
  * took — ` limb cut: "<of>" opaque <n> = "<part>" <px> + …` — and one per
@@ -1879,6 +1895,7 @@ export function limbLines(counts: readonly LimbCount[]): string[] {
1879
1895
  : `a disc of radius ${k.radius} px (cap_shape "disc": the joint's distance to the nearer side of the limb, ${k.width} px across the joint line)`;
1880
1896
  const shaped = [
1881
1897
  ...(k.edge === undefined ? [] : [`edge "feather": ${k.feathered_px ?? 0} px of "${j.upper}" faded across the ${k.feather_radius ?? 0} px about the joint that "${j.part}" covers at every turn`]),
1898
+ ...(k.cut_band === undefined ? [] : [cutPhrase(k, j.upper, j.part)]),
1882
1899
  ];
1883
1900
  const miss =
1884
1901
  k.missing_px === 0
@@ -1919,6 +1936,11 @@ export function limbOrder(order: readonly DrawSlot[], plan: readonly PlanEntry[]
1919
1936
  return out;
1920
1937
  }
1921
1938
 
1939
+ /** The point a joint line moved `offset` px along its axis passes through, to 3 places (issue #360, `cut_band`). */
1940
+ function shiftedAt(line: JointLine, offset: number): [number, number] {
1941
+ return [pyRound(line.at[0] + offset * line.axis[0], 3), pyRound(line.at[1] + offset * line.axis[1], 3)];
1942
+ }
1943
+
1922
1944
  /**
1923
1945
  * Cut every declared limb (module comment of `src/limbs.ts`): each part a limb
1924
1946
  * takes is split among the limbs that take it (nearest polyline), then each
@@ -1980,6 +2002,9 @@ function cutLimbs(
1980
2002
  );
1981
2003
  }
1982
2004
  refuseIfAny(problems);
2005
+ // The line each segment's pixels are split by: the joint line, or where cut_band placed the cut (issue #360).
2006
+ const cutLines = new Map([...lines].map(([l, ls]) => [l, [...ls]]));
2007
+ const placements = new Map<string, Extract<CutPlacement, { ok: true }>>();
1983
2008
  // Each part a limb takes, in the order the limbs first take them.
1984
2009
  const sources = [...new Set(parts.map((q) => q.of))];
1985
2010
  const pieces: Array<Built | null> = parts.map(() => null);
@@ -2003,14 +2028,42 @@ function cutLimbs(
2003
2028
  for (let x = 0; x < W; x++) {
2004
2029
  const p = y * W + x;
2005
2030
  if (b.r.data[p * 4 + 3] === 0) continue;
2006
- const li = on.length === 1 ? 0 : nearestLimb(lns, x, y);
2007
- const l = on[li];
2008
- own[p] = names.indexOf(l);
2031
+ own[p] = names.indexOf(on[on.length === 1 ? 0 : nearestLimb(lns, x, y)]);
2032
+ }
2033
+ }
2034
+ // Issue #360 (item 14): each joint of this part that declares cut_band has its cut placed, on the limb's own art.
2035
+ for (const l of on) {
2036
+ const li = names.indexOf(l);
2037
+ limbs[l].segments.forEach((sg, k) => {
2038
+ if (k === 0 || sg.cut_band === undefined || sg.from !== src || limbs[l].segments[k - 1].from !== src) return;
2039
+ const line = (lines.get(l) as Array<JointLine | null>)[k] as JointLine;
2040
+ const art = (x: number, y: number): boolean => x >= 0 && y >= 0 && x < W && y < H && own[y * W + x] === li && b.r.data[(y * W + x) * 4 + 3] > OPAQUE_ALPHA_ABOVE;
2041
+ const luma = (x: number, y: number): number => luma601(b.r.data[(y * W + x) * 4], b.r.data[(y * W + x) * 4 + 1], b.r.data[(y * W + x) * 4 + 2]);
2042
+ // The joint line on no art is ASSEMBLE_LIMB_JOINT_ON_ART at the caps; nothing is placed about it.
2043
+ if (limbRun(line, art, [0, 0, W - 1, H - 1]) === null) return;
2044
+ const placed = placeCut(line, sg.cut_band, art, luma, [0, 0, W - 1, H - 1]);
2045
+ if (!placed.ok) {
2046
+ problems.push({
2047
+ code: 'ASSEMBLE_LIMB_CUT_BAND',
2048
+ object: `config.limbs.${l}.segments[${k}] (joint "${String(sg.joint)}", part "${sg.part}").cut_band`,
2049
+ detail: `is ${sg.cut_band}, and the line ${Math.abs(placed.offset)} px ${placed.offset < 0 ? 'before' : 'past'} the joint line, through [${shiftedAt(line, placed.offset).join(', ')}], crosses none of the limb's art within 1 px of that point — the band reaches past the limb there, and a cut placed off the art is no cut; a band whose every line crosses the limb is required — ${Math.abs(placed.offset) > 1 ? `cut_band ${Math.abs(placed.offset) - 1} or less` : 'leave cut_band out'}`,
2050
+ });
2051
+ return;
2052
+ }
2053
+ (cutLines.get(l) as Array<JointLine | null>)[k] = placed.line;
2054
+ placements.set(`${l}/${k}`, placed);
2055
+ });
2056
+ }
2057
+ for (let y = 0; y < H; y++) {
2058
+ for (let x = 0; x < W; x++) {
2059
+ const p = y * W + x;
2060
+ if (b.r.data[p * 4 + 3] === 0) continue;
2061
+ const l = names[own[p]];
2009
2062
  const segs = limbs[l].segments;
2010
2063
  const first = segs.findIndex((sg) => sg.from === src);
2011
2064
  let last = first;
2012
2065
  while (last + 1 < segs.length && segs[last + 1].from === src) last++;
2013
- const k = segmentOf(lines.get(l) as Array<JointLine | null>, first, last, x, y);
2066
+ const k = segmentOf(cutLines.get(l) as Array<JointLine | null>, first, last, x, y);
2014
2067
  const at = parts.findIndex((q) => q.limb === l && q.segment === k);
2015
2068
  rasters[at].data.set(b.r.data.subarray(p * 4, p * 4 + 4), p * 4);
2016
2069
  if (b.region === null || b.region.data[p] === 1) regions[at].data[p] = 1;
@@ -2102,6 +2155,9 @@ function cutLimbs(
2102
2155
  }
2103
2156
  const lower = rasters[at];
2104
2157
  const lowerSrc = builtOf(sg.from) as Built;
2158
+ // Issue #360 (cut_band): the cap's pixels are the disc's on the upper side of the cut, wherever it was placed.
2159
+ const cut = (cutLines.get(l) as Array<JointLine | null>)[k] as JointLine;
2160
+ const placed = placements.get(`${l}/${k}`);
2105
2161
  const ownLower = owners.get(sg.from) as Int32Array;
2106
2162
  let layerPx = 0;
2107
2163
  let imagePx = 0;
@@ -2109,7 +2165,7 @@ function cutLimbs(
2109
2165
  let missing = 0;
2110
2166
  for (let y = Math.max(0, box[1]); y < Math.min(H, box[1] + box[3]); y++) {
2111
2167
  for (let x = Math.max(0, box[0]); x < Math.min(W, box[0] + box[2]); x++) {
2112
- if (!inDisc(line.at, radius, x, y) || pastJoint(line, x, y)) continue;
2168
+ if (!inDisc(line.at, radius, x, y) || pastJoint(cut, x, y)) continue;
2113
2169
  const p = y * W + x;
2114
2170
  const u = img === null ? -1 : ((y - box[1]) * img.width + (x - box[0])) * 4;
2115
2171
  if (img !== null && img.data[u + 3] > 0) {
@@ -2137,12 +2193,12 @@ function cutLimbs(
2137
2193
  const fb = capBox(line.at, band);
2138
2194
  for (let y = Math.max(0, fb[1]); y < Math.min(H, fb[1] + fb[3]); y++) {
2139
2195
  for (let x = Math.max(0, fb[0]); x < Math.min(W, fb[0] + fb[2]); x++) {
2140
- if (band === 0 || !inDisc(line.at, band, x, y) || pastJoint(line, x, y)) continue;
2196
+ if (band === 0 || !inDisc(line.at, band, x, y) || pastJoint(cut, x, y)) continue;
2141
2197
  const p = y * W + x;
2142
2198
  const ua = upper.data[p * 4 + 3];
2143
2199
  if (ua === 0) continue;
2144
2200
  const o = jointOffsets(line, x, y);
2145
- const na = Math.floor(ua * featherWeight(band, o.along, o.across) + 0.5);
2201
+ const na = Math.floor(ua * featherWeight(band, o.along, o.across, placed?.offset ?? 0) + 0.5);
2146
2202
  if (na === ua) continue;
2147
2203
  if (na === 0) upper.data.fill(0, p * 4, p * 4 + 4);
2148
2204
  else upper.data[p * 4 + 3] = na;
@@ -2161,6 +2217,17 @@ function cutLimbs(
2161
2217
  missing_px: missing,
2162
2218
  ...(disc ? { shape: 'disc' as const, upper_px: upperPx } : {}),
2163
2219
  ...(sg.edge === 'feather' ? { edge: 'feather' as const, feather_radius: band, feathered_px: featheredPx } : {}),
2220
+ ...(placed === undefined
2221
+ ? {}
2222
+ : {
2223
+ cut_band: sg.cut_band as number,
2224
+ cut_offset: placed.offset,
2225
+ cut_at: shiftedAt(line, placed.offset),
2226
+ cut_crossed: placed.crossed,
2227
+ joint_crossed: placed.jointCrossed,
2228
+ band_px: placed.bandPx,
2229
+ ...(placed.strokeLumaMax === null ? {} : { stroke_luma_max: placed.strokeLumaMax }),
2230
+ }),
2164
2231
  };
2165
2232
  if (hidden !== null) readHidden(hidden.layer, `config.limbs.${l}.segments[${k}].cap (part "${sg.part}")`);
2166
2233
  parts[at].record.cap = cap;
package/src/config.ts CHANGED
@@ -661,7 +661,10 @@ export interface ConfigConstraint {
661
661
  * piece out across the cap, and `cap_shape: "disc"` sizes the cap by the
662
662
  * limb's half-width about the joint and fills it from the art, the upper
663
663
  * segment's included. Absent, the cut
664
- * is hard and the cap the layer's half-disc of half the limb's width.
664
+ * is hard and the cap the layer's half-disc of half the limb's width. A third,
665
+ * `cut_band: N` (issue #360, item 14), places the cut on the line within N px
666
+ * of the joint line that crosses the fewest stroke pixels; absent, the cut is
667
+ * the joint line.
665
668
  */
666
669
  export interface LimbSegment {
667
670
  part: string;
@@ -672,6 +675,8 @@ export interface LimbSegment {
672
675
  cap?: string;
673
676
  edge?: 'feather';
674
677
  cap_shape?: 'disc';
678
+ /** Issue #360 (item 14): the half-width, whole rig px, of the band about the joint line the cut is placed in (`placeCut` in `src/limbs.ts`). Absent, the cut is the joint line. */
679
+ cut_band?: number;
675
680
  }
676
681
 
677
682
  /** A limb (issue #349): its segments, upper first; each segment's bone is the child of the one before. */
@@ -2202,7 +2207,9 @@ interface LimbNames {
2202
2207
  * is measured from rest, so rest is in it); `cap` a non-empty path; `edge`
2203
2208
  * `"feather"` and `cap_shape` `"disc"` (issue #360), each the one value its
2204
2209
  * field takes — absent is the hard cut and the layer's half-disc
2205
- * (`CONFIG_FIELD_TYPE` on any other). A limb
2210
+ * (`CONFIG_FIELD_TYPE` on any other); `cut_band` a whole number of px, 1 or
2211
+ * more (`CONFIG_FIELD_TYPE`), on a segment that takes the segment above's
2212
+ * part (`CONFIG_KEY_KNOWN`: between two layers nothing is cut). A limb
2206
2213
  * has two segments or more. With `names` null (no `bones`), bones are not
2207
2214
  * resolved. Returns the limb parts and the parts the limbs take.
2208
2215
  */
@@ -2227,13 +2234,13 @@ function checkLimbs(c: Check, v: Json, made: { parts: string[]; patches: string[
2227
2234
  const bones: Array<string | null> = [];
2228
2235
  segs.forEach((entry, i) => {
2229
2236
  const sat = `${at}.segments[${i}]`;
2230
- const e = c.object(sat, entry, ['part', 'from', 'bone'], ['joint', 'range', 'cap', 'edge', 'cap_shape']);
2237
+ const e = c.object(sat, entry, ['part', 'from', 'bone'], ['joint', 'range', 'cap', 'edge', 'cap_shape', 'cut_band']);
2231
2238
  froms.push(null);
2232
2239
  bones.push(null);
2233
2240
  if (e === null) return;
2234
2241
  // The upper segment sits below no joint; every other sits below one, which it names.
2235
2242
  if (i === 0) {
2236
- for (const k of ['joint', 'range', 'cap', 'edge', 'cap_shape'].filter((q) => q in e)) c.fail('CONFIG_KEY_KNOWN', `${sat}.${k}`, `is not a field on the upper segment; it sits below no joint, so ${k} belongs to the segment below the joint it names (segments[1] and on)`);
2243
+ for (const k of ['joint', 'range', 'cap', 'edge', 'cap_shape', 'cut_band'].filter((q) => q in e)) c.fail('CONFIG_KEY_KNOWN', `${sat}.${k}`, `is not a field on the upper segment; it sits below no joint, so ${k} belongs to the segment below the joint it names (segments[1] and on)`);
2237
2244
  } else if (!('joint' in e)) c.fail('CONFIG_FIELD_PRESENT', `${sat}.joint`, 'is absent and required; a segment after the first sits below a joint, at its bone\'s origin, and names it');
2238
2245
  if ('part' in e && c.string(`${sat}.part`, e.part)) {
2239
2246
  const name = e.part;
@@ -2278,6 +2285,14 @@ function checkLimbs(c: Check, v: Json, made: { parts: string[]; patches: string[
2278
2285
  if ('cap_shape' in e && e.cap_shape !== 'disc') {
2279
2286
  c.fail('CONFIG_FIELD_TYPE', `${sat}.cap_shape`, `is ${show(e.cap_shape)}; "disc" is required — the cap a disc of the limb's half-width about the joint, filled from the art, the upper segment's included; leave cap_shape out for the layer's half-disc of half the limb's width`);
2280
2287
  }
2288
+ // Issue #360 (item 14): the band the cut is placed in, whole px, on a joint whose two segments take one part.
2289
+ if ('cut_band' in e && i > 0) {
2290
+ if (!(typeof e.cut_band === 'number' && Number.isInteger(e.cut_band) && e.cut_band >= 1)) {
2291
+ c.fail('CONFIG_FIELD_TYPE', `${sat}.cut_band`, `is ${show(e.cut_band)}; a whole number of rig px, 1 or more, is required — the half-width of the band about the joint line the cut is placed in (the line there that crosses the fewest stroke pixels); leave cut_band out to cut at the joint line`);
2292
+ } else if (typeof e.from === 'string' && typeof froms[i - 1] === 'string' && froms[i - 1] !== e.from) {
2293
+ c.fail('CONFIG_KEY_KNOWN', `${sat}.cut_band`, `is not a field on a segment whose from ("${e.from}") is not the segment above's ("${String(froms[i - 1])}"); no line is cut between two layers — each segment takes its own part whole — so there is no cut to place`);
2294
+ }
2295
+ }
2281
2296
  });
2282
2297
  froms.forEach((f, i) => {
2283
2298
  if (f === null || i === 0 || froms[i - 1] === f) return;
package/src/limbs.ts CHANGED
@@ -62,6 +62,25 @@
62
62
  * out across its width over art that stays opaque under it at any angle,
63
63
  * so at rest the two pieces composite to what they did and a bend never
64
64
  * shows through it what lies behind the limb.
65
+ * - **`cut_band: N`** (issue #360, item 14; opt-in on the segment below a
66
+ * joint between two segments that take one part). The cut is placed, not
67
+ * moved by hand: of the lines parallel to the joint line at whole-pixel
68
+ * offsets `-N .. N` along the axis, the one that crosses the fewest stroke
69
+ * pixels ({@link placeCut}). A line crosses the pixels a joint line runs
70
+ * through, as {@link limbRun} reads them: the limb's art whose centre lies
71
+ * within half a pixel of it, across the run of art through its point. A
72
+ * **stroke pixel** is one of those, over the whole band, whose luma (the
73
+ * integer BT.601 `(299 R + 587 G + 114 B + 500) / 1000` truncated, the
74
+ * luma `recompositeErrorMap` in `src/assemble.ts` reads) is at or below the
75
+ * Otsu split of their luma histogram ({@link otsuDarkMax}: the dark class
76
+ * of the two that maximise the between-class variance). The split is
77
+ * derived from the band's own art and no number is typed: art of one luma
78
+ * has no split and so no stroke. A tie goes to the line nearer the joint,
79
+ * then to the one on the upper side, so with no stroke in the band the
80
+ * joint line itself is chosen. The bone does not move: the joint, the
81
+ * cap's disc and the limb's width stay where the bone's origin puts them;
82
+ * only the line that splits the pixels between the two pieces moves, and
83
+ * the cap takes the disc's pixels on the upper side of that line.
65
84
  */
66
85
  import type { BoneEntry, Limb } from './config.ts';
67
86
 
@@ -181,6 +200,11 @@ export function limbRun(line: JointLine, art: (x: number, y: number) => boolean,
181
200
  ts.push(-dx * ay + dy * ax);
182
201
  }
183
202
  }
203
+ return runOfOffsets(ts);
204
+ }
205
+
206
+ /** The run through 0 of the offsets `ts` along a line ({@link limbRun}): sorted, the nearest within 1 px, grown while neighbours are at most 1.5 apart. Sorts `ts` in place. */
207
+ function runOfOffsets(ts: number[]): [number, number] | null {
184
208
  if (ts.length === 0) return null;
185
209
  ts.sort((a, b) => a - b);
186
210
  let near = 0;
@@ -249,12 +273,149 @@ export function coveredRadius(at: Pt, radius: number, opaque: (x: number, y: num
249
273
  * `-along / sqrt(radius² - across²)` — 0 on the line, 1 on the disc's arc, so
250
274
  * the overlap band fades out across its width. 1 where the disc has no height.
251
275
  */
252
- export function featherWeight(radius: number, along: number, across: number): number {
276
+ export function featherWeight(radius: number, along: number, across: number, offset = 0): number {
253
277
  const h2 = radius * radius - across * across;
254
278
  if (h2 <= 0) return 1;
279
+ // Issue #360 (cut_band): with the cut `offset` px along the axis, the fade runs from the cut's line to the arc.
280
+ if (offset !== 0) {
281
+ const span = offset + Math.sqrt(h2);
282
+ return span <= 0 ? 1 : Math.max(0, Math.min(1, (offset - along) / span));
283
+ }
255
284
  return Math.max(0, Math.min(1, -along / Math.sqrt(h2)));
256
285
  }
257
286
 
287
+ /** The integer BT.601 luma of a colour, `(299 R + 587 G + 114 B + 500) / 1000` truncated (the one `recompositeErrorMap` reads). */
288
+ export function luma601(r: number, g: number, b: number): number {
289
+ return Math.floor((299 * r + 587 * g + 114 * b + 500) / 1000);
290
+ }
291
+
292
+ /**
293
+ * The Otsu split of a luma histogram (`hist[v]` pixels of luma `v`): the
294
+ * largest luma of the dark class, among the splits `luma <= T | luma > T`
295
+ * with a pixel on each side, that maximises the between-class variance
296
+ * `(T's dark sum · n − dark count · total sum)² / (dark count · light count)`
297
+ * (the variance times n², which ranks the splits alike). Compared exactly, in
298
+ * integers; a tie goes to the lower `T`. Null when no split has a pixel on
299
+ * each side — every pixel of one luma — or when every split's variance is 0.
300
+ */
301
+ export function otsuDarkMax(hist: ArrayLike<number>): number | null {
302
+ let n = 0;
303
+ let sum = 0;
304
+ for (let v = 0; v < hist.length; v++) {
305
+ n += hist[v];
306
+ sum += v * hist[v];
307
+ }
308
+ const N = BigInt(n);
309
+ const S = BigInt(sum);
310
+ let best: number | null = null;
311
+ let bestNum = 0n;
312
+ let bestDen = 1n;
313
+ let n0 = 0;
314
+ let s0 = 0;
315
+ for (let t = 0; t + 1 < hist.length; t++) {
316
+ n0 += hist[t];
317
+ s0 += t * hist[t];
318
+ const n1 = n - n0;
319
+ if (n0 === 0 || n1 === 0) continue;
320
+ const d = BigInt(s0) * N - BigInt(n0) * S;
321
+ const num = d * d;
322
+ const den = BigInt(n0) * BigInt(n1);
323
+ if (num === 0n) continue;
324
+ if (best === null || num * bestDen > bestNum * den) {
325
+ best = t;
326
+ bestNum = num;
327
+ bestDen = den;
328
+ }
329
+ }
330
+ return best;
331
+ }
332
+
333
+ /** A joint line moved `offset` px along its axis (issue #360, `cut_band`): the same axis, through `at + offset · axis`. */
334
+ export function shiftedLine(line: JointLine, offset: number): JointLine {
335
+ return offset === 0 ? line : { at: [line.at[0] + offset * line.axis[0], line.at[1] + offset * line.axis[1]], axis: line.axis };
336
+ }
337
+
338
+ /** One line of a cut's band (issue #360, `cut_band`): its offset along the axis from the joint, and the stroke pixels it crosses. */
339
+ export interface CutCandidate {
340
+ offset: number;
341
+ crossed: number;
342
+ }
343
+
344
+ /** Where `cut_band` put the cut (module comment), or why it could not. */
345
+ export type CutPlacement =
346
+ | {
347
+ ok: true;
348
+ /** The chosen line's offset along the axis from the joint (above 0: past it, toward the lower segment). */
349
+ offset: number;
350
+ line: JointLine;
351
+ crossed: number;
352
+ /** The stroke pixels the joint line itself crosses. */
353
+ jointCrossed: number;
354
+ /** The Otsu split's dark class's largest luma, or null when the band's art has no split (no stroke). */
355
+ strokeLumaMax: number | null;
356
+ /** The art pixels the band's lines cross, counted once each. */
357
+ bandPx: number;
358
+ candidates: CutCandidate[];
359
+ }
360
+ | { ok: false; offset: number };
361
+
362
+ /**
363
+ * Place a joint's cut within `band` px of its line (module comment, `cut_band`):
364
+ * every whole offset `-band .. band` is a candidate line; each crosses the
365
+ * art pixels (`art`) whose centre lies within half a pixel of it, across the
366
+ * run of art through its point ({@link limbRun}); the stroke pixels are those
367
+ * at or below the Otsu split of the luma (`luma`) of every pixel the band's
368
+ * lines cross. The fewest stroke pixels wins, then the smaller offset, then the
369
+ * negative one (the upper side). `{ok: false, offset}` names the offset nearest
370
+ * the joint (the negative one on a tie) whose line crosses no run of art: the
371
+ * band reaches past the limb there, and a band of `|offset| - 1` would not.
372
+ */
373
+ export function placeCut(
374
+ line: JointLine,
375
+ band: number,
376
+ art: (x: number, y: number) => boolean,
377
+ luma: (x: number, y: number) => number,
378
+ box: readonly [number, number, number, number],
379
+ ): CutPlacement {
380
+ const W = box[2] - box[0] + 1;
381
+ // One pass over the box: the art within band + 1 px of the joint line, a margin past every candidate's half pixel.
382
+ const near: Array<[number, number]> = [];
383
+ for (let y = box[1]; y <= box[3]; y++) {
384
+ for (let x = box[0]; x <= box[2]; x++) {
385
+ if (Math.abs(jointOffsets(line, x, y).along) <= band + 1 && art(x, y)) near.push([x, y]);
386
+ }
387
+ }
388
+ const crossedBy: Array<number[] | null> = [];
389
+ for (let t = -band; t <= band; t++) {
390
+ const l = shiftedLine(line, t);
391
+ // The pixels limbRun reads on this line, with their offsets across it.
392
+ const on = near.map(([x, y]) => ({ x, y, o: jointOffsets(l, x, y) })).filter((q) => Math.abs(q.o.along) <= 0.5);
393
+ const run = runOfOffsets(on.map((q) => q.o.across));
394
+ crossedBy.push(run === null ? null : on.filter((q) => q.o.across >= run[0] && q.o.across <= run[1]).map((q) => (q.y - box[1]) * W + (q.x - box[0])));
395
+ }
396
+ // A line off the limb's art is no candidate: the one nearest the joint is named (the upper side first on a tie).
397
+ const off = crossedBy.map((px, i) => (px === null ? i - band : null)).filter((t): t is number => t !== null);
398
+ if (off.length > 0) return { ok: false, offset: off.reduce((a, t) => (Math.abs(t) < Math.abs(a) ? t : a)) };
399
+ const lines = crossedBy as number[][];
400
+ const lumaAt = (p: number): number => luma(box[0] + (p % W), box[1] + Math.floor(p / W));
401
+ const seen = new Set<number>();
402
+ const hist = new Array<number>(256).fill(0);
403
+ for (const px of lines) {
404
+ for (const p of px) {
405
+ if (seen.has(p)) continue;
406
+ seen.add(p);
407
+ hist[lumaAt(p)]++;
408
+ }
409
+ }
410
+ const split = otsuDarkMax(hist);
411
+ const candidates = lines.map((px, i) => ({ offset: i - band, crossed: split === null ? 0 : px.filter((p) => lumaAt(p) <= split).length }));
412
+ let best = candidates[band];
413
+ for (const c of candidates) {
414
+ if (c.crossed < best.crossed || (c.crossed === best.crossed && (Math.abs(c.offset) < Math.abs(best.offset) || (Math.abs(c.offset) === Math.abs(best.offset) && c.offset < best.offset)))) best = c;
415
+ }
416
+ return { ok: true, offset: best.offset, line: shiftedLine(line, best.offset), crossed: best.crossed, jointCrossed: candidates[band].crossed, strokeLumaMax: split, bandPx: seen.size, candidates };
417
+ }
418
+
258
419
  /** The box `[x, y, w, h]` (rig px) of the pixels whose centre lies within `radius` of `at`: the cap image's size and place. */
259
420
  export function capBox(at: Pt, radius: number): [number, number, number, number] {
260
421
  const x0 = Math.ceil(at[0] - radius - 0.5);
package/src/parts.ts CHANGED
@@ -168,10 +168,49 @@ export interface CapRecord {
168
168
  edge?: 'feather';
169
169
  feather_radius?: number;
170
170
  feathered_px?: number;
171
+ /**
172
+ * Issue #360 (item 14), written only under the segment's `cut_band`: the
173
+ * band; the chosen line's offset along the axis from the joint (above 0:
174
+ * past it, toward the lower segment) and a point it passes through; the
175
+ * stroke pixels it crosses and those the joint line crosses; the art
176
+ * pixels the band's lines cross, each once; and the stroke class's largest
177
+ * luma, absent when the band's art has no split (`placeCut` in
178
+ * `src/limbs.ts`). `at`, `width` and `radius` stay the joint's.
179
+ */
180
+ cut_band?: number;
181
+ cut_offset?: number;
182
+ cut_at?: [number, number];
183
+ cut_crossed?: number;
184
+ joint_crossed?: number;
185
+ band_px?: number;
186
+ stroke_luma_max?: number;
171
187
  }
172
188
 
173
189
  const LIMB_KEYS = ['name', 'segment', 'of', 'bone', 'joint', 'range', 'cap'] as const;
174
- const CAP_KEYS = ['at', 'width', 'radius', 'box', 'layer_px', 'image_px', 'image_layer', 'missing_px', 'shape', 'upper_px', 'edge', 'feather_radius', 'feathered_px'] as const;
190
+ const CAP_KEYS = [
191
+ 'at',
192
+ 'width',
193
+ 'radius',
194
+ 'box',
195
+ 'layer_px',
196
+ 'image_px',
197
+ 'image_layer',
198
+ 'missing_px',
199
+ 'shape',
200
+ 'upper_px',
201
+ 'edge',
202
+ 'feather_radius',
203
+ 'feathered_px',
204
+ 'cut_band',
205
+ 'cut_offset',
206
+ 'cut_at',
207
+ 'cut_crossed',
208
+ 'joint_crossed',
209
+ 'band_px',
210
+ 'stroke_luma_max',
211
+ ] as const;
212
+ /** The cap keys only `cut_band` writes (issue #360, item 14). */
213
+ const CUT_KEYS = ['cut_offset', 'cut_at', 'cut_crossed', 'joint_crossed', 'band_px', 'stroke_luma_max'] as const;
175
214
 
176
215
  /** The limb record with its keys in the fixed order, so two runs write the same bytes. */
177
216
  function orderedLimb(l: LimbRecord): Record<string, unknown> {
@@ -516,12 +555,25 @@ function checkParts(raw: unknown, path: string): PartsFile {
516
555
  (!('image_layer' in co) || ('image_px' in co && typeof co.image_layer === 'string' && co.image_layer !== '')) &&
517
556
  // Issue #360: a disc cap carries its count, a feathered edge its band and count, and neither carries them alone.
518
557
  ('shape' in co ? co.shape === 'disc' && isCount(co.upper_px) : !('upper_px' in co)) &&
519
- ('edge' in co ? co.edge === 'feather' && typeof co.feather_radius === 'number' && Number.isFinite(co.feather_radius) && co.feather_radius >= 0 && isCount(co.feathered_px) : !('feather_radius' in co) && !('feathered_px' in co));
558
+ ('edge' in co ? co.edge === 'feather' && typeof co.feather_radius === 'number' && Number.isFinite(co.feather_radius) && co.feather_radius >= 0 && isCount(co.feathered_px) : !('feather_radius' in co) && !('feathered_px' in co)) &&
559
+ // Issue #360 (item 14): a placed cut carries its band, line and counts, the line inside the band; none of them rides alone.
560
+ ('cut_band' in co
561
+ ? isCount(co.cut_band) &&
562
+ co.cut_band >= 1 &&
563
+ Number.isInteger(co.cut_offset) &&
564
+ Math.abs(co.cut_offset as number) <= co.cut_band &&
565
+ pt(co.cut_at, 2) &&
566
+ isCount(co.cut_crossed) &&
567
+ isCount(co.joint_crossed) &&
568
+ isCount(co.band_px) &&
569
+ (co.cut_crossed as number) <= (co.joint_crossed as number) &&
570
+ (!('stroke_luma_max' in co) || (isCount(co.stroke_luma_max) && co.stroke_luma_max <= 255))
571
+ : CUT_KEYS.every((k) => !(k in co)));
520
572
  if (!ok) {
521
573
  fail(
522
574
  'PARTS_FIELD_TYPE',
523
575
  `${object} "cap"`,
524
- `is ${show(c)}; {at: [x, y], width, radius, box: [x, y, w, h], layer_px, image_px?, image_layer? (with image_px), missing_px, shape? ("disc", with upper_px), edge? ("feather", with feather_radius and feathered_px)} is required`,
576
+ `is ${show(c)}; {at: [x, y], width, radius, box: [x, y, w, h], layer_px, image_px?, image_layer? (with image_px), missing_px, shape? ("disc", with upper_px), edge? ("feather", with feather_radius and feathered_px), cut_band? (with cut_offset inside the band, cut_at, cut_crossed at most joint_crossed, band_px, stroke_luma_max? 0..255)} is required`,
525
577
  );
526
578
  }
527
579
  }