spine-parts 2.32.0 → 2.33.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 +20 -2
- package/docs/STABILITY.md +2 -2
- package/package.json +1 -1
- package/src/build.ts +5 -2
- package/src/config.ts +25 -8
- package/src/occluders.ts +175 -10
- package/src/occluderstage.ts +85 -6
- package/src/parts.ts +43 -2
- package/src/takelayers.ts +18 -2
package/docs/AUTHORING.md
CHANGED
|
@@ -161,7 +161,7 @@ read by no CPU stage).
|
|
|
161
161
|
| `assemble.yield_refused` | assemble | **authored**, optional boolean, default `false` (issue #819; other types: `CONFIG_FIELD_TYPE`). With `true`, an original front projection-core pixel refused at max-channel drift > `DRIFT_LIMIT` (90) can yield when its original source pixel is still opaque. Non-core rim pixels (0 < alpha < `CORE_ALPHA`, 250) on the same 8-connected part body can then yield too (issue #832). Connectivity reads the part support before clearing: the opaque border outside the eroded projection core connects the body to its rim but is not itself newly cleared. A separate rim island without a yielded core seed is unchanged. At every cleared pixel, the actual top-most opaque holder below it (alpha >= 250), after earlier yields, must have colour within 90 of the painting. A deeper matching part cannot bypass an intervening opaque mismatch. This setting also applies to alternate sets. A yielded pixel's alpha becomes 0 and its RGB is not repainted. Accepted own-core pixels in the same connected support within the original yielded core's Gaussian footprint (radius 4 rig pixels), with a matching opaque behind holder, finish to painting RGB while retaining alpha and ownership (issue #841); original refusals, protected samples and replacements are excluded. Away from that footprint projection is unchanged. Merge/ring replacements, samples explicitly kept by `keep_under_occluders`, and pixels outside a derived piece cannot connect a rim or be newly yielded. Front is relative to the matching part behind, so original refusals in another run are eligible even when a different part is the global top holder. The reading proceeds back to front against the current behind pixels; alpha changes do not repaint or create a new matching colour. `yieldReadings` optionally records `finishedProjection` (accepted samples whose RGB changed), and records `yieldedRim` as the rim subset of total `yielded`, skipped core merge/ring/nonopaque/no-match counts and original/final global holders; a yielded pixel also taken by projection closing is omitted from the written `source_px_taken` count. Existing cuts/patches and thresholds are unchanged. The `drift:` line reports `yielded N px` per affected part, even below the drift-body size bar; with the setting off it names `assemble.yield_refused: true` as the conditional remedy. Rebuild and inspect the newly exposed layer in motion before considering any cut; a mismatching or absent behind holder cannot be repaired by this setting. |
|
|
162
162
|
| `assemble.keep_under_occluders` | assemble | **authored**, optional array of unique source part names from `assemble.plan`, default `[]` (issue #825). For each named part, keep its own See-through RGBA where the front-most covering part in the final draw stack has alpha greater than 0 and below `CORE_ALPHA` (250), including a cover in the other run. Covers at raw alpha <= 8 are ghosts and are not kept under; a ghost-cleaned sample with final alpha 0 is absent cover and does not trigger restoration. Only original opaque own-layer samples are restored after source projection/closing and protected from later seam re-take; merged/rim, cap, under-fill and authored replacement pixels are excluded. This keeps their existing provenance and makes no holes; fully opaque cover and absent cover keep the old path. Cuts and limb pieces inherit the source part's protection. Unknown names: `CONFIG_NAME_RESOLVES`; duplicates: `CONFIG_PART_UNIQUE`; invalid shape: `CONFIG_FIELD_TYPE`. Inspect the part's own amodal layer first: this handle preserves its existing content and cannot complete a missing pixel — in particular, it does not close a motion opening inside the figure (`figure_openings` / [Openings inside the figure on undeclared layer pairs](#openings-inside-the-figure-on-undeclared-layer-pairs-issue-933)) where the lower layer has no opaque core under an opaque upper layer (measured with every `assemble.plan` part named in `keep_under_occluders`: `0` of `1` pair-animation warnings across `demo`'s eight animations closed, with `hair_back\|handwear_r` on `hop` frame `5` staying at `40` cells over `28` allowed in `38x70` world units at `2.517` world units/cell, while `scarf` reads `CLEAR` (`0` warnings) both with and without `keep_under_occluders`; use `assemble.extend_painting` when the lower part lacks opaque source material under an opaque upper cover). Example: `"keep_under_occluders": ["shin_r"]`. |
|
|
163
163
|
| `assemble.require_hidden_extent` | assemble, build | **authored**, optional array of unique `{part, occluder}` source-name pairs from `assemble.plan` (issue #1047). The distinct occluder must draw after the part. Before cleanup, projection, underfill, cuts or limb splitting, the original selected source is normalized to the rig grid. Own support is alpha >8. Its enclosed holes are `fillHoles(support) \ support`, using four-connected exterior background. Any hole cell under the resolved front-most named occluder (alpha >8) refuses `ASSEMBLE_HIDDEN_EXTENT_ABSENT`. Zero holes with measurable filled-support overlap passes. No overlap or unavailable original ancestry refuses `ASSEMBLE_HIDDEN_EXTENT_UNMEASURED`. A region take's output (`assemble.take`) counts as the selected source. Cover resolves over `assemble.plan` source families only; cut slots are not resolved as cover, which is a stated limit. Omitted or `[]` adds no reading or output. This is a source-support bar reached by build at assemble. See [Original hidden extent required](#original-hidden-extent-required). |
|
|
164
|
-
| `assemble.occluders` | assemble, build | **authored**, optional (
|
|
164
|
+
| `assemble.occluders` | assemble, build | **authored**, optional (issues #1230, #1241): `[{image, sha256, under, over?, rgb_within}]` — an RGBA PNG of what stands in front of the character on the painting's grid (`image`, relative to the config's directory; another size refuses `ASSEMBLE_OCCLUDER_GRID`), its bytes' sha256 (`CONFIG_OCCLUDER_SHA256`), the plan parts it stands over (`under`, `CONFIG_NAME_RESOLVES`), optional distinct plan parts that draw this occluder (`over`, `CONFIG_NAME_RESOLVES`, `CONFIG_PART_UNIQUE`), and an integer 0–255 (`rgb_within`). After any take and before projection, a pixel of an `under` part's selected layer at alpha above 128, where the occluder's alpha is above 0, within `rgb_within` (max channel) of the painting there, is the occluder's colour copied into the layer: `assemble` prints `WARN ASSEMBLE_OCCLUDER_COLOUR_COPIED` with the part, the rig px count and the first pixel. When `over` is declared, each `(over, under)` pair in an entry draws `over` in front of `under` regardless of mixed-run depth or two-run role band (`ASSEMBLE_OCCLUDER_DRAW_ORDER` if `assemble.plan` draws `over` behind `under`, `ASSEMBLE_OCCLUDER_DRAW_CYCLE` on contradictory `over`/`under` cycles, `ASSEMBLE_OCCLUDER_OVER_TAKEN` if an `over` part's layer is not taken by `assemble.take`). Without `over`, no output byte moves. |
|
|
165
165
|
| `assemble.editor_receipts` | assemble, build | **authored**, optional (issue #946): `{receipts: [{file, sha256, from_sha256, editor}], required?, trace_parts?}`. Each receipt records an image edited in an image editor; `file` (relative to the config's directory) must exist and hash to `sha256`, verified at assemble; `from_sha256` and `editor` are the author's declaration, held only to form. With `required: true`, every author-made layer, hidden-art layer, cut `under` and limb `cap` the build reads, alternate sets' runs included, needs a receipt whose `sha256` is its file's. With `trace_parts: true` (issue #947), every part's pixels must trace to a layer of the split or to a receipted image: the receipts are demanded as under `required`, and every shape the config draws through a part — a cut's `polygon`, `seethrough.arm_split`, a limb's `split.line`, a patch's `box`, a painting extension's `band` — is refused (`ASSEMBLE_PART_SOURCE`). Absent, no file is read and no byte moves. See [Editor receipts](#editor-receipts-assembleeditor_receipts-issue-946) and [Part sources](#part-sources-assembleeditor_receiptstrace_parts-issue-947). |
|
|
166
166
|
| `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?, hybrid?}, …], split?, layout?, front?}}`, 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"` (issue #360), the one value it takes, and `cap_shape` `"disc"` (issue #360) or `"ball"` (issue #579) (`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. Optional `front` (issue #664), `{parts: [<own segment part>, …], after: "<produced part>"}`, gives each named segment a second slot `<part>_front`, empty at setup, placed after `after`'s slot family, for a gesture set to draw on (`CONFIG_FRONT_SCOPE`, `CONFIG_FRONT_NAME`, `CONFIG_FRONT_LAYOUT`; *Front slots (issue #664)* below) |
|
|
167
167
|
| `bones` | rig; `propose --from-config` | **proposed** by `propose`, then corrected. A single bone `{name, parent, at, tip?}` or a chain `{chain, parent, points, tip, link_inherit?}` whose links are named `<chain>0 … <chain>n`. Parents come before children. In `rig.json` each link is **turned along its chain** — `rotation` is the direction from its origin to the next link's (the last link's to `tip`) and `length` that distance (issue #73), so a physics constraint added downstream finds a lever; under `--idle-keys ctl` the link's `<link>_ctl` carries the turn and the length and the link sits at local rotation 0 beneath it. A single bone with a `tip` is turned the same way, towards its tip, with that distance as its length (issue #239); a tip on the bone's own origin is refused (`RIG_TIP_DISTINCT`). The five face bones `eye_r`, `eye_l`, `brow_r`, `brow_l` and `mouth` (by name, when one has no tip of its own) are turned to the eye line — the line through the origins of `eye_r` and `eye_l` as `bones` writes them, read image-left to image-right, drawn when parts.json holds both an `eyewhite-r` and an `eyewhite-l` part — so the blink's `scaley` squashes across the eye line on a tilted head; move an eye bone and the line moves with it. With one eyewhite or none, or an eye bone missing, the rig stage's `face axis:` line says so and they keep the page's axes. A bone under a face bone keeps the face's axis. With the line, `rig.json` also declares `invariants.axes` — one entry, `"face"`, through `eye_r` and `eye_l`, holding the turned face bones (and their controls) — so rig-c's gate holds the build to the line; the line is the one rigc draws through the same two bones, so the tolerance is only the float floor — the largest gap the emitted (float32) bones have to it, rounded up to 6 places plus one 6-place unit — and the `face axis:` line prints it. With the line the rig stage also adds `head_up` (issue #250): a slotless bone under `head`, at head's origin, turned to the eye line + 90 degrees and as long as the eye midpoint lies from head's origin along that axis — the head's frame, which a rule that needs it reads; `head` keeps its own frame, so no key on it or under it changes meaning, and a config bone of that name is refused (`RIG_HEAD_UP_NAME_FREE`). A face bone with its own `tip` is held too (issue #258), in a second entry, `"face_tips"`, when its tip lies along the line within whole-pixel rounding — a tip written in whole pixels sits at most sqrt(2)/2 px off the point of the line it stands for, so its direction may sit up to asin((sqrt(2)/2) / length) degrees off — with its tolerance measured the same way; a tip further off is the bone's own axis, and the `face axis:` line names it with its gap and that bound. A failure is rig-c's `A51_BONES_LIE_ALONG_THEIR_DECLARED_AXIS` line, which names the bone and the fix (rig-c's `docs/AUTHORING.md` §3.7 and §5.2); with no line no entry is written and A51 reports SKIP. Every region on a turned bone is turned back, so the setup pose does not move. Any other single bone keeps world rotation 0; one whose parent is a link is turned back upright. A single bone may declare `inherit` (issue #348): what it takes from its parent's transform, one of rig-c's own mode names exactly as rig-c's table spells them — `normal`, `onlyTranslation`, `noRotationOrReflection`, `noScale`, `noScaleOrReflection` (rig-c's `RigBone.inherit`) — written to that bone in `rig.json` as declared; any other spelling, `"NoScale"` included (the runtime would fold its first letter; nothing here folds or maps), is refused (`CONFIG_BONE_INHERIT`), and a chain takes no `inherit` (`CONFIG_KEY_KNOWN`). A chain may instead declare `link_inherit` (issue #369), an object mapping its own expanded link names to those same modes, for example `"link_inherit": {"leg_r1": "noScale"}`. Only the named link changes; omitted links inherit normally. A key outside this chain is `CONFIG_NAME_RESOLVES`, with this chain's valid link names in the detail; a non-object or non-string mode is `CONFIG_FIELD_TYPE`, and another mode spelling is `CONFIG_BONE_INHERIT`. The mode is forwarded to the expanded link, or to its control under `--idle-keys ctl`, by the same rule as a single bone. This is an authored opt-in: `propose` does not add it. Its setup rotation is the turn from where rig-c's own poser puts the bone with no rotation of its own under that mode, so it still stands upright (or along its tip) at the setup pose. Where the idle gives the bone a `<bone>_ctl`, the mode goes on the control: the control is the bone the parent's rotation reaches, and the bone under it inherits normally, so the idle's keys moved onto the control still turn it. A foot that does not take its shin's rotation (`noRotationOrReflection` or `onlyTranslation`) keeps its shoe level while the leg is posed (`FEET_STAY_LEVEL`, §7); which mode is the author's. `noScale` keeps a shin or shoe's shape under a scaled parent but still takes the parent's rotation: a shoe that must also stay level needs a separate rotation constraint, for example a transform constraint from an unrotated bone. This does not change the proposed feet's existing inheritance or `FEET_STAY_LEVEL` default. An automatic mesh weighted through a bone with a mode other than `normal` gets no derived amplitude (its row names the bone) and no residual envelope (rig-c's `SKINNING_RANGE_UNSUPPORTED`). Absent, `rig.json` carries no `inherit` and no byte moves |
|
|
@@ -5389,7 +5389,23 @@ or a joint.
|
|
|
5389
5389
|
paints. To assemble from it, give that run as `--full` with the real painting
|
|
5390
5390
|
as `--source`, and take the occluder's own layers from the run on the painting
|
|
5391
5391
|
through `config.assemble.take` (their `st_input` is the painting, so the take's
|
|
5392
|
-
input identity holds).
|
|
5392
|
+
input identity holds). When `config.assemble.occluders[i]` also declares
|
|
5393
|
+
`plate: "<plate output dir>"` (issue #1237), `assemble` verifies `<plate>/receipt.json`,
|
|
5394
|
+
binds `receipt.occluder.sha256` to the declared occluder `sha256`
|
|
5395
|
+
(`ASSEMBLE_OCCLUDER_PLATE_OCCLUDER`), `receipt.painting.sha256` to `--source`
|
|
5396
|
+
(`ASSEMBLE_OCCLUDER_PLATE_PAINTING`), and `receipt.output.sha256` to the base
|
|
5397
|
+
(`--full`) See-through run's `meta.json` `image_sha256`
|
|
5398
|
+
(`ASSEMBLE_OCCLUDER_PLATE_BASE_RUN`), and records the bound plate in
|
|
5399
|
+
`parts.json` under `occluder_plates` (`receipt`, `receipt_sha256`,
|
|
5400
|
+
`occluder_sha256`, `painting_sha256`, `output_sha256`, `mask_sha256`).
|
|
5401
|
+
|
|
5402
|
+
When See-through ranks a taken occluder layer deeper (larger `depth_median`)
|
|
5403
|
+
than a plate part it covers, declare `over: ["<part>", ...]` on the matching
|
|
5404
|
+
`config.assemble.occluders[i]` entry alongside `under` (issue #1241). Each
|
|
5405
|
+
`(over, under)` pair in an entry is a declared draw-order pair: the taken
|
|
5406
|
+
`over` part draws in front of `under` in `assemble.plan` without being
|
|
5407
|
+
reordered by `ASSEMBLE_TAKE_PLAN_ORDER`, while undeclared mixed-run pairs keep
|
|
5408
|
+
scalar depth order.
|
|
5393
5409
|
|
|
5394
5410
|
`<out>` holds `plate.png`, `mask.png` (the mask actually used: opaque white
|
|
5395
5411
|
inside, opaque black outside) and `receipt.json`, spec
|
|
@@ -5492,6 +5508,8 @@ recorded transform. The record fields and sampling formula are specified in
|
|
|
5492
5508
|
| <a id="ASSEMBLE_HIDDEN_EXTENT_UNMEASURED"></a>`ASSEMBLE_HIDDEN_EXTENT_UNMEASURED` | a declared pair has no filled own-support overlap under the resolved occluder, empty own support, unavailable original selected-layer ancestry or a partial alternate replacing only one declared source family | resolve the original sources and their declared overlap. An empty hole set with measurable overlap is a valid zero reading. See [Original hidden extent required](#original-hidden-extent-required) |
|
|
5493
5509
|
| <a id="ASSEMBLE_OCCLUDER_COLOUR_COPIED"></a>`ASSEMBLE_OCCLUDER_COLOUR_COPIED` (WARN) | a selected layer of an `assemble.occluders` `under` part holds pixels (alpha above 128) under the occluder (alpha above 0) within `rgb_within` of the painting: the decomposition painted the thing in front into the surface behind it | take the part from a See-through run on the painting with the occluder removed (`comfy plate --mode occluder`), as `--full`, with the occluder's own layers taken from the painting's run through `assemble.take` |
|
|
5494
5510
|
| <a id="CONFIG_OCCLUDER_SHA256"></a><a id="ASSEMBLE_OCCLUDER_GRID"></a>`CONFIG_OCCLUDER_SHA256`, `ASSEMBLE_OCCLUDER_GRID` | an `assemble.occluders` image whose bytes do not hash to its declared `sha256`; an occluder image whose size is not the painting's | declare the bytes the image holds; export the occluder on the painting's grid |
|
|
5511
|
+
| <a id="ASSEMBLE_OCCLUDER_DRAW_ORDER"></a><a id="ASSEMBLE_OCCLUDER_DRAW_CYCLE"></a><a id="ASSEMBLE_OCCLUDER_OVER_TAKEN"></a>`ASSEMBLE_OCCLUDER_DRAW_ORDER`, `ASSEMBLE_OCCLUDER_DRAW_CYCLE`, `ASSEMBLE_OCCLUDER_OVER_TAKEN` | `assemble.plan` draws an `assemble.occluders[i].over` part behind one of its `under` parts; `over`/`under` declarations form a draw-order cycle within one entry or across entries; an `over` part's plan layer is not taken by `assemble.take` | place every `over` part after its `under` parts in `assemble.plan` (back to front); remove contradictory `over`/`under` cycles; take the `over` part's layer through a whole-layer `assemble.take` entry or omit it from `over` |
|
|
5512
|
+
| <a id="ASSEMBLE_OCCLUDER_PLATE_OCCLUDER"></a><a id="ASSEMBLE_OCCLUDER_PLATE_PAINTING"></a><a id="ASSEMBLE_OCCLUDER_PLATE_BASE_RUN"></a>`ASSEMBLE_OCCLUDER_PLATE_OCCLUDER`, `ASSEMBLE_OCCLUDER_PLATE_PAINTING`, `ASSEMBLE_OCCLUDER_PLATE_BASE_RUN` | an `assemble.occluders[i].plate` receipt whose `occluder.sha256` differs from the declared occluder `sha256`, whose `painting.sha256` differs from `--source`, or whose `output.sha256` differs from the base (`--full`) See-through run's `meta.json` `image_sha256` | re-run `comfy plate --mode occluder` and `comfy seethrough` against the current occluder and `--source` painting so the plate receipt binds all three |
|
|
5495
5513
|
| <a id="CONFIG_HIDDEN_EXTENT_ORDER"></a>`CONFIG_HIDDEN_EXTENT_ORDER` | `assemble.require_hidden_extent` names the same source as part and occluder, or names an occluder drawn before the part | declare distinct source parts with the occluder after the part in `assemble.plan` |
|
|
5496
5514
|
| <a id="DIFF_COMPONENTS_INPUT"></a>`DIFF_COMPONENTS_INPUT` | `diff-components` needs readable PNG stack/painting/part images, a writable `--out` target when writing, explicit parts, positive integer floor, a finite threshold in [0,255], matching native dimensions and valid coverage/domain inputs; flags must be unique and known, with nonempty values | Supply the named missing or invalid input; no resampling or inferred figure is performed |
|
|
5497
5515
|
| <a id="DIFF_COMPONENTS_BINDING"></a>`DIFF_COMPONENTS_BINDING` | The shipped report reader found a stack or painting SHA-256 different from the supplied bytes; found and required digests are printed | Regenerate against the bytes being reviewed |
|
package/docs/STABILITY.md
CHANGED
|
@@ -317,7 +317,7 @@ part name, `[i]` an entry of a list):
|
|
|
317
317
|
- **assemble** — required: `rig_scale`, `plan` (from plain `assemble` on); optional: `seam`, `project`, `ground`, `extend_below_crop`, `patches`, `cuts`, `alternates`, `head_face_underfill`, `yield_refused`, `stage_map`, `keep_under_occluders`, `require_hidden_extent`, `extend_painting`, `edge_splits`, `take`, `editor_receipts`, `occluders`
|
|
318
318
|
- **assemble.edge_splits[i]** — required: `over`, `under`, `band`
|
|
319
319
|
- **assemble.require_hidden_extent[i]** — required: `part`, `occluder`
|
|
320
|
-
- **assemble.occluders[i]** — required: `image`, `sha256`, `under`, `rgb_within` (
|
|
320
|
+
- **assemble.occluders[i]** — required: `image`, `sha256`, `under`, `rgb_within`; optional: `over`, `plate` (issues #1230, #1237, #1241)
|
|
321
321
|
- **assemble.alternates[i]** — required: `name`; optional: `source`, `full`, `head`, `parts`, `hides`, `head_box`, `cuts`, `skeleton`, `anchor`, `base_anchor`, `drawn`, `tips`, `front`, `layers`, `focus` (issues #454, #465, #543, #652, #664, #666, #719, #780). `focus` is an authored finite `[x, y]` in painting pixels, within its canvas (edges included), refused as CONFIG_SET_FOCUS before assemble output when invalid; only when present, `parts.json` records it with focus_source_size and `sets.json` emits it in setup-world coordinates through the actual rig resize and `src/coords.ts`. Absent focus emits no field or inferred value; changing/removing it requires reassembly
|
|
322
322
|
- **assemble.extend_below_crop[i]** — required: `part`, `run`, `tag`; optional: `edges` (left, right, top, bottom; explicit edges require a head-run part and the full-run layer of the same tag)
|
|
323
323
|
- **assemble.extend_painting[i]** — required: `part`, `band`, `max_distance`; optional: `min_held_alpha`, `order` (issues #848, #854, #855; explicit final layer-derived part, half-open rig band and positive four-neighbour path bound; base painting only). The optional integer floor 1–255 admits exact original alpha-over coverage strictly below it; absent or 1 blocks every nonzero holder. Only selected target samples below the floor may take painting RGBA; target samples at/above the floor and every non-target holder remain exact. By default overlapping reachable claims refuse. With `order` on every entry (unique nonnegative safe integers), lower values claim first and their gains block later candidates and paths; array order never breaks ties or supplies missing precedence
|
|
@@ -549,7 +549,7 @@ resolution before resizing; it can differ for non-opaque paintings.
|
|
|
549
549
|
| file | written by | what is stable |
|
|
550
550
|
| --- | --- | --- |
|
|
551
551
|
| `stage-map.json` | `assemble`, `build`, under `assemble.stage_map: true` | `rig-parts-stage-map/1`, cropped last-writer and pre-seam RLE maps with writer dictionaries and excluded counts. See [Per-pixel stage map](AUTHORING.md#per-pixel-stage-map). |
|
|
552
|
-
| `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`, `short_px` (`left`, `right`) after it only when `missing_px` is above 0 (issue #557, additive), `excluded_px` after them only on a subset set's limb part whose cap the set exclusion took a pixel of (issue #603, additive: each pixel taken out of the count it was in, so the cap's counts are the written PNG's), then `shape` and `upper_px` under the segment's `cap_shape` — `upper_px` without the shape only when the upper segment gave a pixel (issue #557, additive) — and after them `lower_px`, `lower_kept_px` and `lower_missing_px` under `cap_shape: "ball"` (issue #579, additive), 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` — on a subset set's limb part counted after the set exclusion, issue #603 — `seam_override_px`, and `fringe_pushed_back` when not empty); per-part `provenance` (`unchanged_layer_px`, `hand_px`, `automatic_px`, `edits`, `automatic`, additive, issue #823); optional top-level `motion_seams`, `alternates` and `cut_ownership` (one row per cut, independent of RGBA equality, issue #823); `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), and the same bytes beside `parts.json` when the two directories differ (issue #1177); `single_run_pad` (`file_size`, `side`, `left`, `top`) last, only for one run whose file is not the `seethrough.resolution` square (issue #366) |
|
|
552
|
+
| `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`, `short_px` (`left`, `right`) after it only when `missing_px` is above 0 (issue #557, additive), `excluded_px` after them only on a subset set's limb part whose cap the set exclusion took a pixel of (issue #603, additive: each pixel taken out of the count it was in, so the cap's counts are the written PNG's), then `shape` and `upper_px` under the segment's `cap_shape` — `upper_px` without the shape only when the upper segment gave a pixel (issue #557, additive) — and after them `lower_px`, `lower_kept_px` and `lower_missing_px` under `cap_shape: "ball"` (issue #579, additive), 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` — on a subset set's limb part counted after the set exclusion, issue #603 — `seam_override_px`, and `fringe_pushed_back` when not empty); per-part `provenance` (`unchanged_layer_px`, `hand_px`, `automatic_px`, `edits`, `automatic`, additive, issue #823); optional top-level `motion_seams`, `occluder_plates` (one record per `assemble.occluders` entry declaring `plate` — `receipt`, `receipt_sha256`, `occluder_sha256`, `painting_sha256`, `output_sha256`, `mask_sha256`, additive, issue #1237), `alternates` and `cut_ownership` (one row per cut, independent of RGBA equality, issue #823); `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), and the same bytes beside `parts.json` when the two directories differ (issue #1177); `single_run_pad` (`file_size`, `side`, `left`, `top`) last, only for one run whose file is not the `seethrough.resolution` square (issue #366) |
|
|
553
553
|
| `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) |
|
|
554
554
|
| `rig/mesh_report.json` | `rig`, `build` | one row per mesh: `part`, `vertices`, `triangles`, `hull`, `bones` (the sorted names the attachment's weights bind in the written `rig.json`, in every mode — since 1.49.1 (issue #536) a rig with `turn` or `stops` names the twins and `<link>_d` bones there, where the row named the segment bones they replace: a fix of a wrong name, not a format change; a rig with neither writes the bytes it wrote), `max_influences`, `mean_influences`, `art_coverage`, then `grid` (a lattice); or `mode` "explicit" with `image_sha256` and `region_sha256` (the verified guards; counts and coverage are measured from the supplied mesh, no legacy generator report is adopted); `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` "influence" with `influence` (as declared), `reach` (`farthest`, `at`, `nearest`, `capped`, `widest`) and `lattice` (rig-c's `SegmentsLatticeReport`: `cols`, `rows`, `artCells`, `keptCells`, `passes`, `islands`) (issue #378); 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) |
|
|
555
555
|
| `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`, `environment` after it under `--environment` only (issue #538, additive: `path` as given, `sha256`, `steps`), `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 (issues #320, #363: `status`, `animations`, `fps`, `physics_left_out`, `folding` — each `animation`, `slot`, `attachment`, `frames`, `worst_frame`, `worst_triangles`, `triangles`, `physics_on`, `physics_off`, `physics_constraints`, `declared`, `line` — `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 `step_px` (`left`, `right`) only on a joint whose cap record carries `short_px` (issue #557, additive) — and `unread` on a joint not read), `SEAM_OVER_MOTION` after it when `parts.json` holds a limb segment or `--requirements` a `seam` (issue #493 retains existing pair warnings; issue #686 gates GAP on proven body-root pairs only (gap-only; mixed ghost remains INFO until rig-c/core#1555 supplies owners): `status` — `WARN`, `CLEAR`, `SKIP` or `FAIL` — `reason` on a SKIP only, `fps`, `floor`, `pairs` — each `pair`, `a`, `b`, `declared`, optional `root` (`limb`, `bone`, `parent`) on a proven body-root pair, and `unread` on a pair not read — `animations`, `warnings`, `rows` — each `pair`, `animation`, `status`, `drawn`, `banded`, `opens`, `px`, `max_px`, `under_floor`, and only on new-root rows stock `gapOpen` plus UNDER-owned `ghostA`/`ghostB` cells selected by resolved per-frame draw order gate their summed count against the unchanged strict one-cell floor on the original raw kind boxes (their union when both kinds contribute), never narrowed partition boxes, while `gapCovered` and OVER-owned ghost cells are excluded (issue #711); `cells` retains partition counts, UNDER owner and counted total, `worst` retains frame/count/cell/box, and `roots` retains status, mode `gap-open+under-ghost`, ghost_owner `resolved-draw-order`, pairs, failed, reason and optional unmeasured bindings; eligible candidates whose valid setup bands are all zero retain a named unmeasured root and SKIP bar, including when no pair is selected; measured root FAIL wins over SKIP, while measured PASS plus an unmeasured root remains SKIP; every eligible body drawing with stock setup `banded > 0` is selected, including both when a parent is shared; issue #708 resolves a body slot on its exact generated turn child to the same named carrier only after unique identity-bone/control/per-part-transform proof, without changing pair identity, setup selection or the direct-carrier path; setup-only observation preserves the authored motion and default drawing, root-free inputs add no setup compile/render, and no animation remains SKIP rather than a measured zero; existing internal pair warnings and their exits are unchanged; issue #941 adds optional `required` only under the requirements file's `seam_over_motion.required: true` — `status` (`PASS` or `FAIL`), `mode` `gap-open`, `bar_px` 0, `pairs` (each `pair`, `class` — `body-root`, `internal-joint` or `explicit` — `frames`, `background_frames`, `max_px`) and `failed` — and with it the key is written even when no pair is declared; issue #591 adds optional `worlds` on physics rigs with readable declared pairs and animations: `default` and `still`, each `wind`, `gravity`, `status` (`REPORTED` or `SKIP`), `reason` on SKIP, `dir` only when rendered (relative to check.json: `seam_motion/default` or `seam_motion/still`, the complete retained render with frames.json and each animation's raw seam.json), and `rows` — pair, animation, status, drawn, banded, `gap` and `ghost`, each `max_px` and `worst` only; worst carries `index`, `px`, `cell`, `box`. Per-frame hits stay in the raw sidecars. These raw reference readings add no bar or warning and leave the custom environment reading unchanged), `CLOTH_SETTLES` after it when the rig declares a physics constraint and has an idle (issue #501, a warning and not a bar: `status` — `WARN` or `CLEAR` — `fps`, `frames`, `duration`, `floor_rig_px_per_s`, `floor`, `levers`, `warnings`, `rows` — each `tip`, `root`, `links`, `point`, `settles_at`, `max_rig_px_per_s`, `min_rig_px_per_s`), `RECOMPOSITE_HOLES` (its first figure `declared_scene` when `parts.json` declares a scene), `SETUP_POSE_VS_SOURCE`, `WIND_BAND` after it under `--wind-band` only (issue #590, additive: `status` `"REPORTED"`, `spec` `"rig-parts-wind-band/1"`, `path` as given, `sha256`, `steady_wind_only` `true`, `gravity` `[0, 1]`, `min`, `max`, `step`, `steps`, `fps`, `animations`, `max_gap`, `max_ghost`, `holds_from`, `holds_to`, `pairs_holding_all`, and `pairs` — each `pair`, `a`, `b`, `holds_all`, `holds_from`, `holds_to`, `first_break_below`, `first_break_above`, `worst_gap`, `worst_ghost`, `steps`), `skipped`, `config` under `build` only (issue #607, additive: `path` as `--config` was typed, `sha256` of the bytes the build read; `check` and `compose` read no config and write none), a `requirements` block under `--requirements` (or `build`'s `config.requirements`) — `file` first from issue #556, additive: `path` as typed or declared, `sha256`, `keys` — and `PASS`; `check/build/skeleton.json`, `.atlas` and `.png` are the packed artifact rig-c writes. Missing stock partitions or resolved owner are named refusals, never zero. No whole-box exemption or consumer compositor remains; internal warnings and reference raw readings are unchanged. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spine-parts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.33.0",
|
|
4
4
|
"description": "AI-authored 2D character parts from one anime painting and its See-through layer decomposition: measured parts, weighted-mesh rig specs, verified through rig-c before anything is written. A CLI for agents that cannot see the image.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/build.ts
CHANGED
|
@@ -15,7 +15,7 @@ import { CUT_MATERIAL_LINE, CUT_MATERIAL_SOURCES, materialLines } from './cutmat
|
|
|
15
15
|
import { ART_JOINT_LINE, artJointLines } from './artjoints.ts';
|
|
16
16
|
import { applyTakenLayers } from './takelayers.ts';
|
|
17
17
|
import { applyTakenRegions } from './takeregion.ts';
|
|
18
|
-
import { occluderStageWarnings } from './occluderstage.ts';
|
|
18
|
+
import { bindOccluderPlates, occluderStageWarnings } from './occluderstage.ts';
|
|
19
19
|
import { ownershipLines, provenanceLines } from './provenance.ts';
|
|
20
20
|
import { readSourceDepth } from './depthsheets.ts';
|
|
21
21
|
import { orderedBaseAnchor } from './baseanchor.ts';
|
|
@@ -390,9 +390,12 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
390
390
|
const result = assemble({ allocationEvent: input.allocationEvent === undefined ? undefined : event => input.allocationEvent!(event, null), source: src, full: runs.full, head: runs.head, depth: cfg.depth, depthBase: dirname(resolve(input.config)), ...fields, under, ...(declaredFigure === undefined ? {} : { declaredFigure }),
|
|
391
391
|
...((cfg.assemble.take ?? []).some(t => 'part' in t) ? { regionTake: { full: takenRuns.full, head: takenRuns.head, targets: (cfg.assemble.take ?? []).flatMap(t => 'part' in t ? [t.part] : []) } } : {}), ...(caps === undefined ? {} : { caps }), seamRule: seam, projectRule: project });
|
|
392
392
|
|
|
393
|
-
// Issue #1230: copied occluder colour in a declared occluder's under parts is named, never kept silent;
|
|
393
|
+
// Issue #1230 / #1237: copied occluder colour in a declared occluder's under parts is named, never kept silent;
|
|
394
|
+
// when `plate` is declared on an occluder entry, its receipt is verified and bound to occluder, painting and base run.
|
|
394
395
|
if (cfg.assemble.occluders !== undefined) {
|
|
395
396
|
for (const line of occluderStageWarnings({ occluders: cfg.assemble.occluders, configPath: input.config, source: src, runs, plan: fields.plan, resolution: fields.resolution, headBox: fields.headBox, rigScale: fields.rigScale })) log(line);
|
|
397
|
+
const boundPlates = bindOccluderPlates({ occluders: cfg.assemble.occluders, configPath: input.config, sourcePath: input.source, fullPath: input.full });
|
|
398
|
+
if (boundPlates.length > 0) result.parts.occluder_plates = boundPlates;
|
|
396
399
|
}
|
|
397
400
|
|
|
398
401
|
const sourceCoverSets = [sourceCoverSet(result, null, input.source, read)];
|
package/src/config.ts
CHANGED
|
@@ -1482,12 +1482,17 @@ export function configFileReferences(raw: unknown): ConfigFileReference[] {
|
|
|
1482
1482
|
const target = parent;
|
|
1483
1483
|
out.push({ at: field.path.join('.'), value, set: (next) => { target[key] = next; } });
|
|
1484
1484
|
}
|
|
1485
|
-
// Issue #1230: each declared occluder's image,
|
|
1485
|
+
// Issue #1230 / #1237: each declared occluder's image and optional plate directory, array fields the single-path table above cannot name.
|
|
1486
1486
|
const assemble = isPlainObject(raw) ? raw.assemble : undefined;
|
|
1487
1487
|
const occluders = isPlainObject(assemble) && Array.isArray(assemble.occluders) ? assemble.occluders : [];
|
|
1488
1488
|
occluders.forEach((entry: unknown, i: number) => {
|
|
1489
|
-
if (!isPlainObject(entry)
|
|
1490
|
-
|
|
1489
|
+
if (!isPlainObject(entry)) return;
|
|
1490
|
+
if (typeof entry.image === 'string' && entry.image !== '') {
|
|
1491
|
+
out.push({ at: `assemble.occluders[${i}].image`, value: entry.image, set: (next) => { entry.image = next; } });
|
|
1492
|
+
}
|
|
1493
|
+
if (typeof entry.plate === 'string' && entry.plate !== '') {
|
|
1494
|
+
out.push({ at: `assemble.occluders[${i}].plate`, value: entry.plate, set: (next) => { entry.plate = next; } });
|
|
1495
|
+
}
|
|
1491
1496
|
});
|
|
1492
1497
|
return out;
|
|
1493
1498
|
}
|
|
@@ -2567,8 +2572,8 @@ function checkRequiredHiddenExtent(c: Check, a: Record<string, Json>, names: rea
|
|
|
2567
2572
|
}
|
|
2568
2573
|
|
|
2569
2574
|
/**
|
|
2570
|
-
* Issue #1230: `config.assemble.occluders`, `[{image, sha256, under, rgb_within}]`. Shape at every door; `under`
|
|
2571
|
-
* resolved against the plan where the door reads it; the file and its sha256 where the door knows the config's
|
|
2575
|
+
* Issue #1230 / #1241: `config.assemble.occluders`, `[{image, sha256, under, over?, rgb_within}]`. Shape at every door; `under`
|
|
2576
|
+
* and `over` resolved against the plan where the door reads it; the file and its sha256 where the door knows the config's
|
|
2572
2577
|
* directory (`checkOccluderFiles`).
|
|
2573
2578
|
*/
|
|
2574
2579
|
function checkOccluders(c: Check, a: Record<string, Json>, names: readonly string[] | null, base: string | null): void {
|
|
@@ -2578,16 +2583,24 @@ function checkOccluders(c: Check, a: Record<string, Json>, names: readonly strin
|
|
|
2578
2583
|
const declarations: OccluderDeclaration[] = [];
|
|
2579
2584
|
(a.occluders as Json[]).forEach((value, i) => {
|
|
2580
2585
|
const p = `${at}[${i}]`;
|
|
2581
|
-
const row = c.object(p, value, ['image', 'sha256', 'under', 'rgb_within'], []);
|
|
2586
|
+
const row = c.object(p, value, ['image', 'sha256', 'under', 'rgb_within'], ['over', 'plate']);
|
|
2582
2587
|
if (row === null) return;
|
|
2583
2588
|
const imageOk = c.string(`${p}.image`, row.image);
|
|
2584
2589
|
const shaOk = typeof row.sha256 === 'string' && SHA256_PATTERN.test(row.sha256);
|
|
2585
2590
|
if (!shaOk) c.fail('CONFIG_FIELD_TYPE', `${p}.sha256`, `is ${show(row.sha256)}; ${SHA256_RULE} is required`);
|
|
2586
2591
|
let underOk = c.array(`${p}.under`, row.under, true);
|
|
2587
2592
|
if (underOk) (row.under as Json[]).forEach((name, j) => { if (!c.string(`${p}.under[${j}]`, name)) underOk = false; });
|
|
2593
|
+
let overOk = true;
|
|
2594
|
+
if ('over' in row) {
|
|
2595
|
+
overOk = c.array(`${p}.over`, row.over, true);
|
|
2596
|
+
if (overOk) (row.over as Json[]).forEach((name, j) => { if (!c.string(`${p}.over[${j}]`, name)) overOk = false; });
|
|
2597
|
+
}
|
|
2588
2598
|
const rgbOk = typeof row.rgb_within === 'number' && Number.isInteger(row.rgb_within) && row.rgb_within >= 0 && row.rgb_within <= 255;
|
|
2589
2599
|
if (!rgbOk) c.fail('CONFIG_FIELD_TYPE', `${p}.rgb_within`, `is ${show(row.rgb_within)}; an integer from 0 to 255 is required`);
|
|
2590
|
-
|
|
2600
|
+
const plateOk = !('plate' in row) || c.string(`${p}.plate`, row.plate);
|
|
2601
|
+
if (imageOk && shaOk && underOk && overOk && rgbOk && plateOk) {
|
|
2602
|
+
declarations.push({ image: row.image as string, sha256: row.sha256 as string, under: row.under as string[], ...('over' in row ? { over: row.over as string[] } : {}), rgb_within: row.rgb_within as number, ...('plate' in row ? { plate: row.plate as string } : {}) });
|
|
2603
|
+
}
|
|
2591
2604
|
});
|
|
2592
2605
|
c.problems.push(...occluderNameProblems(declarations, names));
|
|
2593
2606
|
if (base !== null) c.problems.push(...occluderFileProblems(declarations, base));
|
|
@@ -2596,7 +2609,11 @@ function checkOccluders(c: Check, a: Record<string, Json>, names: readonly strin
|
|
|
2596
2609
|
/** The occluder files, at the doors that know the config's directory but read the plan elsewhere. */
|
|
2597
2610
|
function checkOccluderFiles(c: Check, assemble: Json, base: string | null): void {
|
|
2598
2611
|
if (base === null || !isPlainObject(assemble) || !Array.isArray(assemble.occluders)) return;
|
|
2599
|
-
const declarations = (assemble.occluders as Json[]).
|
|
2612
|
+
const declarations = (assemble.occluders as Json[]).flatMap((d): OccluderDeclaration[] => {
|
|
2613
|
+
if (!isPlainObject(d) || typeof d.image !== 'string' || d.image === '' || typeof d.sha256 !== 'string' || !SHA256_PATTERN.test(d.sha256)) return [];
|
|
2614
|
+
const plate = 'plate' in d && typeof d.plate === 'string' && d.plate !== '' ? { plate: d.plate } : {};
|
|
2615
|
+
return [{ image: d.image, sha256: d.sha256, under: [], rgb_within: 0, ...plate }];
|
|
2616
|
+
});
|
|
2600
2617
|
c.problems.push(...occluderFileProblems(declarations, base));
|
|
2601
2618
|
}
|
|
2602
2619
|
|
package/src/occluders.ts
CHANGED
|
@@ -28,38 +28,203 @@ export interface OccluderDeclaration {
|
|
|
28
28
|
sha256: string;
|
|
29
29
|
/** Plan parts the occluder stands in front of. */
|
|
30
30
|
under: string[];
|
|
31
|
+
/** Plan parts that draw this occluder, in front of `under` (#1241). */
|
|
32
|
+
over?: string[];
|
|
31
33
|
/** Max absolute channel difference from the painting at which an `under` pixel reads as the occluder's colour. */
|
|
32
34
|
rgb_within: number;
|
|
35
|
+
/** An optional comfy plate --mode occluder output directory, relative to the config's directory (issue #1237). */
|
|
36
|
+
plate?: string;
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
export const OCCLUDER_COLOUR_COPIED = 'ASSEMBLE_OCCLUDER_COLOUR_COPIED';
|
|
40
|
+
export const OCCLUDER_DRAW_ORDER = 'ASSEMBLE_OCCLUDER_DRAW_ORDER';
|
|
41
|
+
export const OCCLUDER_DRAW_CYCLE = 'ASSEMBLE_OCCLUDER_DRAW_CYCLE';
|
|
42
|
+
export const OCCLUDER_OVER_TAKEN = 'ASSEMBLE_OCCLUDER_OVER_TAKEN';
|
|
43
|
+
export const OCCLUDER_PLATE_OCCLUDER = 'ASSEMBLE_OCCLUDER_PLATE_OCCLUDER';
|
|
44
|
+
export const OCCLUDER_PLATE_PAINTING = 'ASSEMBLE_OCCLUDER_PLATE_PAINTING';
|
|
45
|
+
export const OCCLUDER_PLATE_BASE_RUN = 'ASSEMBLE_OCCLUDER_PLATE_BASE_RUN';
|
|
36
46
|
/** An `under` layer pixel counts at alpha above this: the half-opaque floor `deriveTakenRegion` reads. */
|
|
37
47
|
export const COPIED_ALPHA_ABOVE = 128;
|
|
38
48
|
|
|
39
49
|
const AT = 'config.assemble.occluders';
|
|
40
50
|
|
|
41
|
-
/**
|
|
51
|
+
/** Contradictory `over` / `under` draw order across occluder entries (`ASSEMBLE_OCCLUDER_DRAW_CYCLE`). */
|
|
52
|
+
export function occluderDrawCycleProblems(declarations: readonly OccluderDeclaration[]): Problem[] {
|
|
53
|
+
const problems: Problem[] = [];
|
|
54
|
+
const edges = new Map<string, Map<string, number>>();
|
|
55
|
+
const vertices: string[] = [];
|
|
56
|
+
const addVertex = (name: string): void => {
|
|
57
|
+
if (!vertices.includes(name)) vertices.push(name);
|
|
58
|
+
};
|
|
59
|
+
declarations.forEach((d, i) => {
|
|
60
|
+
if (d.over === undefined) return;
|
|
61
|
+
for (const u of d.over) {
|
|
62
|
+
for (const v of d.under) {
|
|
63
|
+
if (u === v) {
|
|
64
|
+
problems.push({
|
|
65
|
+
code: OCCLUDER_DRAW_CYCLE,
|
|
66
|
+
object: `${AT}[${i}]`,
|
|
67
|
+
detail: `cycle ${u} -> ${u}: "${u}" is in both over and under of occluders[${i}]; a part cannot draw in front of itself`,
|
|
68
|
+
});
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
addVertex(u);
|
|
72
|
+
addVertex(v);
|
|
73
|
+
let row = edges.get(u);
|
|
74
|
+
if (row === undefined) {
|
|
75
|
+
row = new Map<string, number>();
|
|
76
|
+
edges.set(u, row);
|
|
77
|
+
}
|
|
78
|
+
if (!row.has(v)) row.set(v, i);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
vertices.forEach((start, startIndex) => {
|
|
83
|
+
const startEdges = edges.get(start);
|
|
84
|
+
if (startEdges === undefined) return;
|
|
85
|
+
const visited = new Set<string>();
|
|
86
|
+
const queue: Array<{ node: string; path: string[]; steps: Array<[string, string, number]> }> = [];
|
|
87
|
+
for (const [next, ei] of startEdges) {
|
|
88
|
+
if (vertices.indexOf(next) > startIndex) {
|
|
89
|
+
visited.add(next);
|
|
90
|
+
queue.push({ node: next, path: [start, next], steps: [[start, next, ei]] });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
while (queue.length > 0) {
|
|
94
|
+
const current = queue.shift()!;
|
|
95
|
+
const nextEdges = edges.get(current.node);
|
|
96
|
+
if (nextEdges === undefined) continue;
|
|
97
|
+
const back = nextEdges.get(start);
|
|
98
|
+
if (back !== undefined) {
|
|
99
|
+
const cycle = [...current.path, start];
|
|
100
|
+
const steps = [...current.steps, [current.node, start, back] as [string, string, number]];
|
|
101
|
+
problems.push({
|
|
102
|
+
code: OCCLUDER_DRAW_CYCLE,
|
|
103
|
+
object: AT,
|
|
104
|
+
detail: `cycle ${cycle.join(' -> ')} (${steps.map(([from, to, idx]) => `"${from}" over "${to}" in occluders[${idx}]`).join(', ')}); declared over/under draw order must be acyclic`,
|
|
105
|
+
});
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
for (const [next, ei] of nextEdges) {
|
|
109
|
+
if (vertices.indexOf(next) > startIndex && !visited.has(next)) {
|
|
110
|
+
visited.add(next);
|
|
111
|
+
queue.push({ node: next, path: [...current.path, next], steps: [...current.steps, [current.node, next, ei]] });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
return problems;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface DeclaredOccluderPair {
|
|
120
|
+
index: number;
|
|
121
|
+
over: string;
|
|
122
|
+
under: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** First occluder entry declaring `(a, b)` or `(b, a)` as an `(over, under)` pair, or null when undeclared. */
|
|
126
|
+
export function declaredOccluderPair(declarations: readonly OccluderDeclaration[], a: string, b: string): DeclaredOccluderPair | null {
|
|
127
|
+
for (let i = 0; i < declarations.length; i++) {
|
|
128
|
+
const d = declarations[i];
|
|
129
|
+
if (d.over === undefined) continue;
|
|
130
|
+
if (d.over.includes(a) && d.under.includes(b)) return { index: i, over: a, under: b };
|
|
131
|
+
if (d.over.includes(b) && d.under.includes(a)) return { index: i, over: b, under: a };
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Every declared `(over, under)` pair in `config.assemble.occluders` must draw `over` after `under`
|
|
138
|
+
* in the combined `config.assemble.plan` (back to front, `ASSEMBLE_OCCLUDER_DRAW_ORDER`).
|
|
139
|
+
*/
|
|
140
|
+
export function occluderDrawOrderProblems(
|
|
141
|
+
declarations: readonly OccluderDeclaration[],
|
|
142
|
+
plan: ReadonlyArray<readonly [string, string, string]>,
|
|
143
|
+
): Problem[] {
|
|
144
|
+
const problems: Problem[] = [];
|
|
145
|
+
for (let i = 0; i < plan.length; i++) {
|
|
146
|
+
for (let j = i + 1; j < plan.length; j++) {
|
|
147
|
+
const [partA, runA] = plan[i];
|
|
148
|
+
const [partB, runB] = plan[j];
|
|
149
|
+
const declared = declaredOccluderPair(declarations, partA, partB);
|
|
150
|
+
if (declared !== null && declared.over === partA) {
|
|
151
|
+
problems.push({
|
|
152
|
+
code: OCCLUDER_DRAW_ORDER,
|
|
153
|
+
object: runA === runB ? `${runA} plan parts "${partA}" / "${partB}"` : `plan parts "${partA}" (${runA}) / "${partB}" (${runB})`,
|
|
154
|
+
detail: `${AT}[${declared.index}] declares "${partA}" in over and "${partB}" in under, but config.assemble.plan draws "${partA}" behind "${partB}"; put "${partA}" after "${partB}" in config.assemble.plan (back to front)`,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return problems;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Every `over` part's plan layer (`run:tag`) must be taken by a whole-layer `assemble.take` declaration (`ASSEMBLE_OCCLUDER_OVER_TAKEN`). */
|
|
163
|
+
export function occluderOverTakenProblems(
|
|
164
|
+
declarations: readonly OccluderDeclaration[],
|
|
165
|
+
plan: ReadonlyArray<readonly [string, string, string]>,
|
|
166
|
+
taken: ReadonlyArray<{ run: string; tags: readonly string[] }>,
|
|
167
|
+
): Problem[] {
|
|
168
|
+
const problems: Problem[] = [];
|
|
169
|
+
declarations.forEach((d, i) => {
|
|
170
|
+
d.over?.forEach((name, j) => {
|
|
171
|
+
const row = plan.find(([part]) => part === name);
|
|
172
|
+
if (row === undefined) return;
|
|
173
|
+
const [, run, tag] = row;
|
|
174
|
+
if (!taken.some((t) => t.run === run && t.tags.includes(tag))) {
|
|
175
|
+
problems.push({
|
|
176
|
+
code: OCCLUDER_OVER_TAKEN,
|
|
177
|
+
object: `${AT}[${i}].over[${j}]`,
|
|
178
|
+
detail: `part "${name}" (${run}:${tag}) is not taken by config.assemble.take; declare a whole-layer take for ${run}:${tag} or omit "${name}" from over`,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
return problems;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Every `under` and `over` entry names a plan part (`CONFIG_NAME_RESOLVES`, with `over` entries distinct per occluder, `CONFIG_PART_UNIQUE`); `names` null skips the plan-membership check (a door without the plan). */
|
|
42
187
|
export function occluderNameProblems(declarations: readonly OccluderDeclaration[], names: readonly string[] | null): Problem[] {
|
|
43
|
-
if (names === null) return [];
|
|
44
188
|
const problems: Problem[] = [];
|
|
45
|
-
declarations.forEach((d, i) =>
|
|
46
|
-
if (
|
|
47
|
-
|
|
189
|
+
declarations.forEach((d, i) => {
|
|
190
|
+
if (d.over !== undefined) {
|
|
191
|
+
const seen = new Set<string>();
|
|
192
|
+
d.over.forEach((name, j) => {
|
|
193
|
+
if (seen.has(name)) problems.push({ code: 'CONFIG_PART_UNIQUE', object: `${AT}[${i}].over[${j}]`, detail: `names "${name}" again; each part is named once` });
|
|
194
|
+
seen.add(name);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
if (names === null) return;
|
|
198
|
+
d.under.forEach((name, j) => {
|
|
199
|
+
if (!names.includes(name)) problems.push({ code: 'CONFIG_NAME_RESOLVES', object: `${AT}[${i}].under[${j}]`, detail: `names "${name}"; a part in config.assemble.plan is required` });
|
|
200
|
+
});
|
|
201
|
+
d.over?.forEach((name, j) => {
|
|
202
|
+
if (!names.includes(name)) problems.push({ code: 'CONFIG_NAME_RESOLVES', object: `${AT}[${i}].over[${j}]`, detail: `names "${name}"; a part in config.assemble.plan is required` });
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
problems.push(...occluderDrawCycleProblems(declarations));
|
|
48
206
|
return problems;
|
|
49
207
|
}
|
|
50
208
|
|
|
51
|
-
/** The image is a file beside the config (`CONFIG_FILE_PRESENT`) whose bytes hash to `sha256` (`CONFIG_OCCLUDER_SHA256`). */
|
|
209
|
+
/** The image is a file beside the config (`CONFIG_FILE_PRESENT`) whose bytes hash to `sha256` (`CONFIG_OCCLUDER_SHA256`), and an optional `plate` names a plate output directory holding `receipt.json`. */
|
|
52
210
|
export function occluderFileProblems(declarations: readonly OccluderDeclaration[], base: string): Problem[] {
|
|
53
211
|
const problems: Problem[] = [];
|
|
54
212
|
declarations.forEach((d, i) => {
|
|
55
213
|
const path = resolve(base, d.image);
|
|
56
214
|
if (!existsSync(path) || !statSync(path).isFile()) {
|
|
57
215
|
problems.push({ code: 'CONFIG_FILE_PRESENT', object: `${AT}[${i}].image`, detail: `names ${d.image}, which is no such file; an RGBA PNG of the occluder on the painting's grid, relative to the config's directory, is required` });
|
|
58
|
-
|
|
216
|
+
} else {
|
|
217
|
+
const found = fileSha256(path);
|
|
218
|
+
if (SHA256_PATTERN.test(d.sha256) && found !== d.sha256) {
|
|
219
|
+
problems.push({ code: 'CONFIG_OCCLUDER_SHA256', object: `${AT}[${i}].sha256`, detail: `is ${d.sha256}; ${d.image} has sha256 ${found} — declare the bytes the occluder image holds` });
|
|
220
|
+
}
|
|
59
221
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
222
|
+
if (d.plate !== undefined) {
|
|
223
|
+
const plateDir = resolve(base, d.plate);
|
|
224
|
+
const receiptPath = resolve(plateDir, 'receipt.json');
|
|
225
|
+
if (!existsSync(plateDir) || !statSync(plateDir).isDirectory() || !existsSync(receiptPath) || !statSync(receiptPath).isFile()) {
|
|
226
|
+
problems.push({ code: 'CONFIG_FILE_PRESENT', object: `${AT}[${i}].plate`, detail: `names ${d.plate} (${plateDir}), which holds no receipt.json; a comfy plate --mode occluder output directory relative to the config's directory is required` });
|
|
227
|
+
}
|
|
63
228
|
}
|
|
64
229
|
});
|
|
65
230
|
return problems;
|
package/src/occluderstage.ts
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The assemble stage's reading of `config.assemble.occluders` (
|
|
2
|
+
* The assemble stage's reading of `config.assemble.occluders` (issues #1230, #1237):
|
|
3
3
|
* each declaration's image read and held to its sha256 and to the painting's
|
|
4
4
|
* size, each `under` part's selected source layer placed on the rig grid the
|
|
5
5
|
* way the hidden-extent reading places it (after any take, before projection
|
|
6
|
-
* or cleanup),
|
|
7
|
-
*
|
|
6
|
+
* or cleanup), every copied-colour pixel counted ({@link occluderColourCopies}),
|
|
7
|
+
* and each declared `plate` receipt verified and bound to the occluder, the
|
|
8
|
+
* `--source` painting and the base (`--full`) See-through run's input image.
|
|
8
9
|
*/
|
|
9
10
|
import { createHash } from 'node:crypto';
|
|
10
|
-
import { readFileSync } from 'node:fs';
|
|
11
|
-
import { dirname, resolve } from 'node:path';
|
|
11
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
12
|
+
import { dirname, join, resolve } from 'node:path';
|
|
12
13
|
import { checkGeometry, layerToRig, padSingleRun, placeLayer, sourceInRig } from './assemble.ts';
|
|
13
14
|
import type { PlanEntry } from './config.ts';
|
|
15
|
+
import { SHA256_PATTERN } from './editreceipt.ts';
|
|
14
16
|
import { PartsError } from './errors.ts';
|
|
15
17
|
import type { LayerSet } from './layers.ts';
|
|
16
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
type OccluderDeclaration,
|
|
20
|
+
OCCLUDER_PLATE_BASE_RUN,
|
|
21
|
+
OCCLUDER_PLATE_OCCLUDER,
|
|
22
|
+
OCCLUDER_PLATE_PAINTING,
|
|
23
|
+
occluderColourCopies,
|
|
24
|
+
occluderColourWarning,
|
|
25
|
+
} from './occluders.ts';
|
|
26
|
+
import type { OccluderPlateRecord } from './parts.ts';
|
|
27
|
+
import { PLATE_RECEIPT_FILE, type PlateReceipt, sha256, verifyPlateReceipt } from './plate.ts';
|
|
17
28
|
import { decodePngBytes } from './raster/png.ts';
|
|
18
29
|
import type { Raster } from './raster/types.ts';
|
|
19
30
|
|
|
@@ -32,6 +43,13 @@ export interface OccluderStageInput {
|
|
|
32
43
|
rigScale: number;
|
|
33
44
|
}
|
|
34
45
|
|
|
46
|
+
export interface OccluderPlateBindInput {
|
|
47
|
+
occluders: readonly OccluderDeclaration[];
|
|
48
|
+
configPath: string;
|
|
49
|
+
sourcePath: string;
|
|
50
|
+
fullPath: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
35
53
|
export function occluderStageWarnings(input: OccluderStageInput): string[] {
|
|
36
54
|
const { source, runs } = input;
|
|
37
55
|
const frame = checkGeometry({ sourceW: source.width, sourceH: source.height, resolution: input.resolution, headBox: input.headBox, rigScale: input.rigScale, ...(runs.single ? { single: true } : {}) }, { full: runs.full, head: runs.head });
|
|
@@ -62,3 +80,64 @@ export function occluderStageWarnings(input: OccluderStageInput): string[] {
|
|
|
62
80
|
});
|
|
63
81
|
return lines;
|
|
64
82
|
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Verify and bind each declared `config.assemble.occluders[i].plate` (issue #1237):
|
|
86
|
+
* 1. `verifyPlateReceipt` holds the receipt's own schema and sibling files (`plate.png`, `mask.png`).
|
|
87
|
+
* 2. `receipt.occluder.sha256` must equal `config.assemble.occluders[i].sha256` (`ASSEMBLE_OCCLUDER_PLATE_OCCLUDER`).
|
|
88
|
+
* 3. `receipt.painting.sha256` must equal the `--source` painting's sha256 (`ASSEMBLE_OCCLUDER_PLATE_PAINTING`).
|
|
89
|
+
* 4. `receipt.output.sha256` must equal the base (`--full`) See-through run's `meta.json` `image_sha256` (`ASSEMBLE_OCCLUDER_PLATE_BASE_RUN`).
|
|
90
|
+
*/
|
|
91
|
+
export function bindOccluderPlates(input: OccluderPlateBindInput): OccluderPlateRecord[] {
|
|
92
|
+
const withPlates = input.occluders.map((d, i) => ({ d, i })).filter((x) => x.d.plate !== undefined);
|
|
93
|
+
if (withPlates.length === 0) return [];
|
|
94
|
+
const configDir = dirname(resolve(input.configPath));
|
|
95
|
+
const paintingSha = sha256(new Uint8Array(readFileSync(resolve(input.sourcePath))));
|
|
96
|
+
const fullDir = resolve(input.fullPath);
|
|
97
|
+
const metaPath = existsSync(fullDir) && statSync(fullDir).isDirectory() ? join(fullDir, 'meta.json') : join(dirname(fullDir), 'meta.json');
|
|
98
|
+
const out: OccluderPlateRecord[] = [];
|
|
99
|
+
for (const { d, i } of withPlates) {
|
|
100
|
+
const at = `config.assemble.occluders[${i}].plate`;
|
|
101
|
+
const plateRel = d.plate as string;
|
|
102
|
+
const plateDir = resolve(configDir, plateRel);
|
|
103
|
+
const receiptFile = join(plateDir, PLATE_RECEIPT_FILE);
|
|
104
|
+
if (!existsSync(plateDir) || !statSync(plateDir).isDirectory() || !existsSync(receiptFile) || !statSync(receiptFile).isFile()) {
|
|
105
|
+
refuse('CONFIG_FILE_PRESENT', at, `names ${plateRel} (${plateDir}), which holds no ${PLATE_RECEIPT_FILE}; a comfy plate --mode occluder output directory relative to the config's directory is required`);
|
|
106
|
+
}
|
|
107
|
+
const problems = verifyPlateReceipt(receiptFile);
|
|
108
|
+
if (problems.length > 0) throw new PartsError(problems);
|
|
109
|
+
const receiptBytes = new Uint8Array(readFileSync(receiptFile));
|
|
110
|
+
const receiptSha = sha256(receiptBytes);
|
|
111
|
+
const receipt = JSON.parse(Buffer.from(receiptBytes).toString('utf8')) as PlateReceipt;
|
|
112
|
+
if (receipt.mode !== 'occluder' || receipt.occluder === undefined) {
|
|
113
|
+
refuse('PLATE_RECEIPT_KEYS', at, `names ${receiptFile} with mode ${JSON.stringify(receipt.mode)}; an occluder plate receipt (mode "occluder") is required`);
|
|
114
|
+
}
|
|
115
|
+
if (receipt.occluder.sha256 !== d.sha256) {
|
|
116
|
+
refuse(OCCLUDER_PLATE_OCCLUDER, at, `receipt ${receiptFile} binds occluder.sha256 ${receipt.occluder.sha256}; config.assemble.occluders[${i}].sha256 is ${d.sha256}`);
|
|
117
|
+
}
|
|
118
|
+
if (receipt.painting.sha256 !== paintingSha) {
|
|
119
|
+
refuse(OCCLUDER_PLATE_PAINTING, at, `receipt ${receiptFile} binds painting.sha256 ${receipt.painting.sha256}; --source ${input.sourcePath} has sha256 ${paintingSha}`);
|
|
120
|
+
}
|
|
121
|
+
if (!existsSync(metaPath) || !statSync(metaPath).isFile()) {
|
|
122
|
+
refuse(OCCLUDER_PLATE_BASE_RUN, at, `receipt ${receiptFile} binds output.sha256 ${receipt.output.sha256}, but base run ${input.fullPath} has no meta.json (${metaPath}) to bind image_sha256`);
|
|
123
|
+
}
|
|
124
|
+
let baseRunSha: unknown;
|
|
125
|
+
try {
|
|
126
|
+
baseRunSha = (JSON.parse(readFileSync(metaPath, 'utf8')) as { image_sha256?: unknown }).image_sha256;
|
|
127
|
+
} catch (err) {
|
|
128
|
+
refuse(OCCLUDER_PLATE_BASE_RUN, at, `base run meta.json (${metaPath}) does not parse as JSON: ${(err as Error).message}`);
|
|
129
|
+
}
|
|
130
|
+
if (typeof baseRunSha !== 'string' || !SHA256_PATTERN.test(baseRunSha) || receipt.output.sha256 !== baseRunSha) {
|
|
131
|
+
refuse(OCCLUDER_PLATE_BASE_RUN, at, `receipt ${receiptFile} binds output.sha256 ${receipt.output.sha256}; base (--full) See-through run ${metaPath} image_sha256 is ${typeof baseRunSha === 'string' ? baseRunSha : JSON.stringify(baseRunSha)}`);
|
|
132
|
+
}
|
|
133
|
+
out.push({
|
|
134
|
+
receipt: `${plateRel.replace(/\\/g, '/').replace(/\/+$/, '')}/${PLATE_RECEIPT_FILE}`,
|
|
135
|
+
receipt_sha256: receiptSha,
|
|
136
|
+
occluder_sha256: receipt.occluder.sha256,
|
|
137
|
+
painting_sha256: receipt.painting.sha256,
|
|
138
|
+
output_sha256: receipt.output.sha256,
|
|
139
|
+
mask_sha256: receipt.mask.sha256,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
package/src/parts.ts
CHANGED
|
@@ -377,6 +377,21 @@ export interface PaintingInRig {
|
|
|
377
377
|
resample: 'lanczos3-rgb-opaque';
|
|
378
378
|
}
|
|
379
379
|
|
|
380
|
+
export interface OccluderPlateRecord {
|
|
381
|
+
/** The plate receipt's path as declared (`<plate>/receipt.json`, POSIX separators). */
|
|
382
|
+
receipt: string;
|
|
383
|
+
/** SHA-256 of `receipt.json` bytes on disk. */
|
|
384
|
+
receipt_sha256: string;
|
|
385
|
+
/** `receipt.occluder.sha256` (bound to `config.assemble.occluders[i].sha256`). */
|
|
386
|
+
occluder_sha256: string;
|
|
387
|
+
/** `receipt.painting.sha256` (bound to `--source` painting bytes). */
|
|
388
|
+
painting_sha256: string;
|
|
389
|
+
/** `receipt.output.sha256` (bound to the base `--full` See-through run's `meta.json` `image_sha256`). */
|
|
390
|
+
output_sha256: string;
|
|
391
|
+
/** `receipt.mask.sha256` (from the verified plate receipt). */
|
|
392
|
+
mask_sha256: string;
|
|
393
|
+
}
|
|
394
|
+
|
|
380
395
|
export interface PartsFile {
|
|
381
396
|
/** Optional on legacy packages; binds the opaque RGB raster assemble actually read. */
|
|
382
397
|
painting_in_rig?: PaintingInRig;
|
|
@@ -394,6 +409,8 @@ export interface PartsFile {
|
|
|
394
409
|
scene?: SceneRecord;
|
|
395
410
|
/** Written only for one run whose file is not the resolution square (issue #366): where the file sat on the run's square; absent otherwise. */
|
|
396
411
|
single_run_pad?: SingleRunPad;
|
|
412
|
+
/** Written only when an `assemble.occluders` entry declares `plate` (issue #1237); absent otherwise. */
|
|
413
|
+
occluder_plates?: OccluderPlateRecord[];
|
|
397
414
|
/** Written only when alternate painting sets were assembled (issue #454); absent otherwise. */
|
|
398
415
|
alternates?: AlternatePartsRecord[];
|
|
399
416
|
}
|
|
@@ -430,8 +447,9 @@ export interface SceneRecord {
|
|
|
430
447
|
figure_mask: string;
|
|
431
448
|
}
|
|
432
449
|
|
|
433
|
-
const TOP_KEYS = ['painting_in_rig', 'rig_size', 'scale_rig_per_source', 'parts', 'ghost_px', 'recomposite', 'scene', 'single_run_pad', 'alternates', 'motion_seams', 'cut_ownership'] as const;
|
|
434
|
-
const REQUIRED_TOP_KEYS = TOP_KEYS.filter((k) => k !== 'painting_in_rig' && k !== 'recomposite' && k !== 'scene' && k !== 'single_run_pad' && k !== 'alternates' && k !== 'motion_seams' && k !== 'cut_ownership');
|
|
450
|
+
const TOP_KEYS = ['painting_in_rig', 'rig_size', 'scale_rig_per_source', 'parts', 'ghost_px', 'recomposite', 'scene', 'occluder_plates', 'single_run_pad', 'alternates', 'motion_seams', 'cut_ownership'] as const;
|
|
451
|
+
const REQUIRED_TOP_KEYS = TOP_KEYS.filter((k) => k !== 'painting_in_rig' && k !== 'recomposite' && k !== 'scene' && k !== 'single_run_pad' && k !== 'occluder_plates' && k !== 'alternates' && k !== 'motion_seams' && k !== 'cut_ownership');
|
|
452
|
+
export const OCCLUDER_PLATE_KEYS = ['receipt', 'receipt_sha256', 'occluder_sha256', 'painting_sha256', 'output_sha256', 'mask_sha256'] as const;
|
|
435
453
|
export const SINGLE_RUN_PAD_KEYS = ['file_size', 'side', 'left', 'top'] as const;
|
|
436
454
|
export const SCENE_KEYS = ['figure_alpha_above', 'figure_px', 'figure_mask'] as const;
|
|
437
455
|
export const RECOMPOSITE_KEYS = ['mean_abs', 'within_limit', 'within_share', 'error_limit', 'error_px', 'covered_alpha', 'uncovered_error_px', 'hole_count', 'holes_listed', 'holes'] as const;
|
|
@@ -563,6 +581,7 @@ export function serializeParts(file: PartsFile): string {
|
|
|
563
581
|
ghost_px: Object.fromEntries(Object.keys(file.ghost_px).sort().map((k) => [k, file.ghost_px[k]])),
|
|
564
582
|
...(file.recomposite === undefined ? {} : { recomposite: serializeRecomposite(file.recomposite) }),
|
|
565
583
|
...(file.scene === undefined ? {} : { scene: Object.fromEntries(SCENE_KEYS.map((k) => [k, (file.scene as SceneRecord)[k]])) }),
|
|
584
|
+
...(file.occluder_plates === undefined ? {} : { occluder_plates: file.occluder_plates.map((p) => Object.fromEntries(OCCLUDER_PLATE_KEYS.map((k) => [k, p[k]]))) }),
|
|
566
585
|
...(file.single_run_pad === undefined ? {} : { single_run_pad: Object.fromEntries(SINGLE_RUN_PAD_KEYS.map((k) => [k, (file.single_run_pad as SingleRunPad)[k]])) }),
|
|
567
586
|
...(file.alternates === undefined
|
|
568
587
|
? {}
|
|
@@ -902,6 +921,28 @@ function checkParts(raw: unknown, path: string): PartsFile {
|
|
|
902
921
|
}
|
|
903
922
|
if ('cut_ownership' in o) checkOwnership(o.cut_ownership, `${path} cut_ownership`, fail);
|
|
904
923
|
if ('single_run_pad' in o) checkSingleRunPad(o.single_run_pad, path, sizeOk ? (size as [number, number]) : null, typeof scale === 'number' ? scale : null, fail);
|
|
924
|
+
if ('occluder_plates' in o) {
|
|
925
|
+
if (!Array.isArray(o.occluder_plates) || o.occluder_plates.length === 0) {
|
|
926
|
+
fail('PARTS_FIELD_TYPE', `${path} field "occluder_plates"`, `is ${show(o.occluder_plates)}; a non-empty array of occluder plate records is required`);
|
|
927
|
+
} else {
|
|
928
|
+
o.occluder_plates.forEach((entry, i) => {
|
|
929
|
+
const at = `${path} occluder_plates[${i}]`;
|
|
930
|
+
if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
|
|
931
|
+
fail('PARTS_FIELD_TYPE', at, `is ${show(entry)}; an object is required`);
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
const r = entry as Record<string, unknown>;
|
|
935
|
+
for (const k of Object.keys(r)) if (!(OCCLUDER_PLATE_KEYS as readonly string[]).includes(k)) fail('PARTS_KEY_KNOWN', `${at} key "${k}"`, `is not an occluder_plates field; known: ${OCCLUDER_PLATE_KEYS.join(', ')}`);
|
|
936
|
+
for (const k of OCCLUDER_PLATE_KEYS) if (!(k in r)) fail('PARTS_FIELD_PRESENT', `${at} field "${k}"`, 'is absent and required');
|
|
937
|
+
if ('receipt' in r && (typeof r.receipt !== 'string' || r.receipt.length === 0)) fail('PARTS_FIELD_TYPE', `${at} field "receipt"`, `is ${show(r.receipt)}; a non-empty string path is required`);
|
|
938
|
+
for (const k of ['receipt_sha256', 'occluder_sha256', 'painting_sha256', 'output_sha256', 'mask_sha256'] as const) {
|
|
939
|
+
if (k in r && (typeof r[k] !== 'string' || !/^[a-f0-9]{64}$/.test(r[k] as string))) {
|
|
940
|
+
fail('PARTS_FIELD_TYPE', `${at} field "${k}"`, `is ${show(r[k])}; 64 lowercase hex characters are required`);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
}
|
|
905
946
|
if ('recomposite' in o && sizeOk) {
|
|
906
947
|
const names = Array.isArray(o.parts) ? new Set(o.parts.map((p) => (typeof p === 'object' && p !== null ? (p as Record<string, unknown>).name : undefined)).filter((n): n is string => typeof n === 'string')) : new Set<string>();
|
|
907
948
|
checkRecomposite(o.recomposite, path, size as [number, number], names, fail);
|
package/src/takelayers.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { CORE_KERNEL, fullPlanBand } from './assemble.ts';
|
|
|
7
7
|
import { makeInputs, squarePad } from './inputs.ts';
|
|
8
8
|
import { OPAQUE_ALPHA_ABOVE, readLayers, type Layer, type LayerSet } from './layers.ts';
|
|
9
9
|
import { PartsError, refuseIfAny, type Problem } from './errors.ts';
|
|
10
|
+
import { declaredOccluderPair, occluderDrawCycleProblems, occluderDrawOrderProblems, occluderOverTakenProblems, type OccluderDeclaration } from './occluders.ts';
|
|
10
11
|
import { dilate } from './raster/morph.ts';
|
|
11
12
|
import { newMask, newRaster, newFloatImage, type Raster } from './raster/types.ts';
|
|
12
13
|
import { readPng } from './raster/png.ts';
|
|
@@ -154,8 +155,21 @@ function supportOverlap(a: Layer, b: Layer): number {
|
|
|
154
155
|
return px;
|
|
155
156
|
}
|
|
156
157
|
/** Apply every declaration together, so replacing all tied layers from one run can retain its known order. */
|
|
157
|
-
export function applyTakenLayers(runs: { full: LayerSet; head: LayerSet; single: boolean }, painting: Raster, cfg: Pick<EarlyConfig, 'seethrough' | 'depth'> & { assemble: { take?: TakeDeclaration[]; plan?: PlanEntry[] } }, configPath: string): { full: LayerSet; head: LayerSet; single: boolean; notes: string[] } {
|
|
158
|
+
export function applyTakenLayers(runs: { full: LayerSet; head: LayerSet; single: boolean }, painting: Raster, cfg: Pick<EarlyConfig, 'seethrough' | 'depth'> & { assemble: { take?: TakeDeclaration[]; plan?: PlanEntry[]; occluders?: OccluderDeclaration[] } }, configPath: string): { full: LayerSet; head: LayerSet; single: boolean; notes: string[] } {
|
|
158
159
|
const declarations = (cfg.assemble.take ?? []).filter((item): item is TakeLayers => 'tags' in item);
|
|
160
|
+
const occluders = cfg.assemble.occluders ?? [];
|
|
161
|
+
if (occluders.length > 0) {
|
|
162
|
+
const cycles = occluderDrawCycleProblems(occluders);
|
|
163
|
+
refuseIfAny([
|
|
164
|
+
...cycles,
|
|
165
|
+
...(cfg.assemble.plan === undefined
|
|
166
|
+
? []
|
|
167
|
+
: [
|
|
168
|
+
...occluderOverTakenProblems(occluders, cfg.assemble.plan, declarations),
|
|
169
|
+
...(cycles.length > 0 ? [] : occluderDrawOrderProblems(occluders, cfg.assemble.plan)),
|
|
170
|
+
]),
|
|
171
|
+
]);
|
|
172
|
+
}
|
|
159
173
|
if (declarations.length === 0) return { ...runs, notes: [] };
|
|
160
174
|
if (cfg.depth !== undefined || [...runs.full.layers, ...runs.head.layers].some(l => l.depthSheet !== undefined)) return refuse('ASSEMBLE_TAKE_DEPTH_SHEET', 'config.assemble.take', 'active scalar depth sheets have no mixed-run binding; disable the depth opt-in or assemble a separately bound run before taking layers (numeric depth_median ordering is retained)');
|
|
161
175
|
const inputs = makeInputs(painting, cfg, 'take target painting');
|
|
@@ -206,7 +220,9 @@ export function applyTakenLayers(runs: { full: LayerSet; head: LayerSet; single:
|
|
|
206
220
|
const selected = (cfg.assemble.plan ?? []).filter(p => p[1] === run).map(p => ({ part: p[0], layer: list.find(l => l.name === p[2]) }));
|
|
207
221
|
for (let i = 0; i < selected.length; i++) for (let j = i + 1; j < selected.length; j++) {
|
|
208
222
|
const a = selected[i], b = selected[j];
|
|
209
|
-
if (a.layer === undefined || b.layer === undefined
|
|
223
|
+
if (a.layer === undefined || b.layer === undefined) continue;
|
|
224
|
+
if (declaredOccluderPair(occluders, a.part, b.part) !== null) continue;
|
|
225
|
+
if (origin(a.layer) === origin(b.layer)) continue;
|
|
210
226
|
const overlap = supportOverlap(a.layer, b.layer);
|
|
211
227
|
if (overlap === 0) continue;
|
|
212
228
|
// Only full rows in a two-run plan have the proposer's fallback roles.
|