@rig-c/parts 1.55.1 → 1.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/docs/AUTHORING.md +113 -5
- package/docs/STABILITY.md +3 -1
- package/package.json +1 -1
- package/src/assemble.ts +205 -23
- package/src/build.ts +30 -11
- package/src/config.ts +47 -3
- package/src/limblayout.ts +181 -0
- package/src/limbownership.ts +37 -0
- package/src/limbslots.ts +106 -0
- package/src/parts.ts +3 -3
- package/src/rig.ts +28 -11
package/src/assemble.ts
CHANGED
|
@@ -99,6 +99,7 @@
|
|
|
99
99
|
*
|
|
100
100
|
* Pure: no clock, no randomness, no file access. The CLI reads and writes.
|
|
101
101
|
*/
|
|
102
|
+
import { sourceLimbTarget, nearestTargetPart } from './limbownership.ts';
|
|
102
103
|
import { type ArmSplit, type BoneEntry, type CharacterConfig, type ControlSkeleton, controlSkeletonOf, type Cut, type EarlyConfig, type Extend, type Limb, type Patch, type PlanEntry, type Run, type SeeThrough } from './config.ts';
|
|
103
104
|
import { type Problem, refuseIfAny } from './errors.ts';
|
|
104
105
|
import { figuresPhrase, implausibleRules, type Layer, type LayerFigures, layerFigures, type LayerSet, NEAR_WHITE_MIN, OPAQUE_ALPHA_ABOVE, ruleSummary } from './layers.ts';
|
|
@@ -349,7 +350,8 @@ export interface AssembleInput {
|
|
|
349
350
|
/**
|
|
350
351
|
* Issue #587: rig pixels taken out of named parts once the cuts and the limbs are made, before the fringe pass and
|
|
351
352
|
* every figure a part's record holds — each entry clears `part`'s pixels (alpha, colour and region) where `mask` is
|
|
352
|
-
* 1
|
|
353
|
+
* 1 (except owned source/cap art protected by issue #637). {@link AssembleResult.excluded} counts the ones
|
|
354
|
+
* above `OPAQUE_ALPHA_ABOVE` it took, in entry order (a pixel
|
|
353
355
|
* an earlier entry cleared is not counted again). The set build passes {@link setExclusions}. An entry naming a part
|
|
354
356
|
* this run did not make clears nothing and counts 0. Absent or empty: nothing changes. Issue #603: the part's
|
|
355
357
|
* `merged_px` and, on a limb segment's part, its `cap` record are counted after it, so they add up to the PNG written
|
|
@@ -382,6 +384,10 @@ export interface AssembleInput {
|
|
|
382
384
|
* once the limbs are cut and in place of the island rule, which needs two islands. Absent: nothing changes.
|
|
383
385
|
*/
|
|
384
386
|
otherLimbs?: OtherLimbs;
|
|
387
|
+
/** Issue #637: preserve owned source/cap art under covers after limb assignment. Base builds omit it. */
|
|
388
|
+
limbUnderCover?: boolean;
|
|
389
|
+
/** Issue #637: `source` is the pre-fix test mutant that skips source-transparent cap ownership; stages use target. */
|
|
390
|
+
capOwnership?: 'target' | 'source';
|
|
385
391
|
}
|
|
386
392
|
|
|
387
393
|
/**
|
|
@@ -389,6 +395,8 @@ export interface AssembleInput {
|
|
|
389
395
|
* hands them to {@link assemble}.
|
|
390
396
|
*/
|
|
391
397
|
export interface OtherLimbs {
|
|
398
|
+
/** Issue #638's test-only pre-fix mutant; absent uses only segments taking the source. No CLI/config field. */
|
|
399
|
+
line?: 'whole-limb';
|
|
392
400
|
/** The config's limbs, by name, that the set does not carry and that take one of `limbIslands`. */
|
|
393
401
|
limbs: Readonly<Record<string, Limb>>;
|
|
394
402
|
/**
|
|
@@ -827,8 +835,9 @@ function skeletonsTooClose(own: readonly LinePt[], other: readonly LinePt[], hal
|
|
|
827
835
|
* Issue #609: on a layer of one island that the set's limbs take and `others`' limbs take too, give each pixel of the
|
|
828
836
|
* set's limb parts to the limb whose segment line is nearest it, in the set's pose, and keep the set's.
|
|
829
837
|
*
|
|
830
|
-
* ⚖️ Invariant: a limb's segment line is
|
|
831
|
-
*
|
|
838
|
+
* ⚖️ Invariant: a limb's segment line is the polyline of its segments taking this source ({@link limbPolyline}:
|
|
839
|
+
* those segments' bone origins, then the last bone's end or the next segment's joint) at `places`, the set's own
|
|
840
|
+
* bones — the set's limb where the set cut it, the other limb where the set
|
|
832
841
|
* placed it (its skeleton's keypoints). A pixel of a part (alpha above 0, where the layer has art) is nearer the
|
|
833
842
|
* other limb when its centre's distance to that limb's line is less than its distance to its own limb's by more than
|
|
834
843
|
* {@link OVERLAP_BAND_PX}; within it, in the overlap band, it goes to the limb whose part there (the part of the
|
|
@@ -887,7 +896,26 @@ function splitOneIsland(
|
|
|
887
896
|
refused = true;
|
|
888
897
|
}
|
|
889
898
|
if (refused || posed.length === 0) return;
|
|
890
|
-
|
|
899
|
+
// Issue #638: a separate footwear layer belongs to the ankle-to-toe segments, not to a nearby thigh or shin.
|
|
900
|
+
// The same source selection applies to every segment, without reading a part name or a layer tag.
|
|
901
|
+
const taking = (l: string, all: Readonly<Record<string, Limb>>): Limb => others.line === 'whole-limb'
|
|
902
|
+
? all[l]
|
|
903
|
+
: { ...all[l], segments: all[l].segments.filter((sg) => sg.from === src) };
|
|
904
|
+
const polyOf = (l: string, all: Readonly<Record<string, Limb>>): Array<[number, number]> =>
|
|
905
|
+
others.line === 'whole-limb' ? limbPolyline(all[l], places) : sourceLimbTarget(all[l], src, places).line;
|
|
906
|
+
for (const [l, all] of [...ownNames.map((l) => [l, limbs] as const), ...posed.map((l) => [l, others.limbs] as const)]) {
|
|
907
|
+
const selected = taking(l, all);
|
|
908
|
+
const line = polyOf(l, all);
|
|
909
|
+
if (line.length <= selected.segments.length) {
|
|
910
|
+
const bone = selected.segments[selected.segments.length - 1].bone;
|
|
911
|
+
problems.push({
|
|
912
|
+
code: 'ASSEMBLE_ALT_LIMB_POSE',
|
|
913
|
+
object: `config.limbs.${l} (part "${src}", bone "${bone}")`,
|
|
914
|
+
detail: `takes this shared one-island source on a segment with no end: "${bone}" has no tip, so its origin alone cannot place the segment line; an explicit bone tip in the set's pose is required to assign the pixels, never another layer's segment line`,
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
if (problems.length > problemsBefore) return;
|
|
891
919
|
// The too-close refusal, per own limb and other limb, on the own limb's half-width.
|
|
892
920
|
for (const own of ownNames) {
|
|
893
921
|
const radii = parts.filter((q) => q.limb === own && q.record.cap !== undefined).map((q) => (q.record.cap as CapRecord).radius);
|
|
@@ -914,7 +942,7 @@ function splitOneIsland(
|
|
|
914
942
|
if (problems.length > problemsBefore) return;
|
|
915
943
|
const drawAt = new Map(others.drawOrder.map((name, i) => [name, i]));
|
|
916
944
|
// Each other limb's pieces, and the part each piece's segment is.
|
|
917
|
-
const otherLines = posed.map((l) => ({ l, line: polyOf(l, others.limbs), segs: others.limbs
|
|
945
|
+
const otherLines = posed.map((l) => ({ l, line: polyOf(l, others.limbs), segs: taking(l, others.limbs).segments }));
|
|
918
946
|
for (const { q, i } of mine) {
|
|
919
947
|
const piece = pieces[i];
|
|
920
948
|
const ownLine = polyOf(q.limb, limbs);
|
|
@@ -971,6 +999,85 @@ function splitOneIsland(
|
|
|
971
999
|
}
|
|
972
1000
|
}
|
|
973
1001
|
|
|
1002
|
+
/**
|
|
1003
|
+
* Assign only live, source-transparent cap pixels after the existing source-art
|
|
1004
|
+
* assignment. Both the nearest-line and island doors leave such pixels without
|
|
1005
|
+
* a source verdict. Cap origin is provenance, never proof of ownership.
|
|
1006
|
+
*/
|
|
1007
|
+
function assignCapOwnership(
|
|
1008
|
+
sources: readonly string[], limbs: Readonly<Record<string, Limb>>, bones: readonly BoneEntry[],
|
|
1009
|
+
parts: readonly LimbPart[], pieces: readonly Built[], sourceOf: (name: string) => Built | null,
|
|
1010
|
+
capFrom: ReadonlyArray<CapFrom | null>, W: number, H: number, others?: OtherLimbs,
|
|
1011
|
+
): { counts: SplitCount[]; problems: Problem[] } {
|
|
1012
|
+
const counts: SplitCount[] = [], problems: Problem[] = [];
|
|
1013
|
+
if (others === undefined) return { counts, problems };
|
|
1014
|
+
const places = bonePlaces(bones);
|
|
1015
|
+
const drawAt = new Map(others.drawOrder.map((name, i) => [name, i]));
|
|
1016
|
+
parts.forEach((q, i) => {
|
|
1017
|
+
const from = capFrom[i], source = sourceOf(q.of), piece = pieces[i];
|
|
1018
|
+
if (from === null || source === null || !sources.includes(q.of)) return;
|
|
1019
|
+
const otherNames = Object.keys(others.limbs).filter((l) => others.limbs[l].segments.some((sg) => sg.from === q.of));
|
|
1020
|
+
if (otherNames.length === 0) return;
|
|
1021
|
+
const [bx, by, bw, bh] = from.box;
|
|
1022
|
+
const candidates: number[] = [];
|
|
1023
|
+
for (let y = Math.max(0, by); y < Math.min(H, by + bh); y++) for (let x = Math.max(0, bx); x < Math.min(W, bx + bw); x++) {
|
|
1024
|
+
const p = y * W + x;
|
|
1025
|
+
if (from.codes[(y - by) * bw + x - bx] !== 0 && piece.r.data[p * 4 + 3] > 0 && source.r.data[p * 4 + 3] === 0) candidates.push(p);
|
|
1026
|
+
}
|
|
1027
|
+
if (candidates.length === 0) return;
|
|
1028
|
+
const before = problems.length;
|
|
1029
|
+
const posed: string[] = [];
|
|
1030
|
+
for (const l of otherNames) {
|
|
1031
|
+
const unposed = others.unposed[l] ?? [];
|
|
1032
|
+
if (unposed.length === 0) { posed.push(l); continue; }
|
|
1033
|
+
// Same evidence boundary as #609: without a posed other limb, overlap
|
|
1034
|
+
// with its base art requires a pose. No overlap retains the compatible
|
|
1035
|
+
// path; the missing limb is never silently placed at its base bones.
|
|
1036
|
+
const on = candidates.filter((p) => piece.r.data[p * 4 + 3] > OPAQUE_ALPHA_ABOVE && others.baseArt[l]?.data[p] === 1).length;
|
|
1037
|
+
if (on > 0) problems.push({ code: 'ASSEMBLE_ALT_LIMB_POSE', object: `part "${q.part}" (config.limbs.${q.limb}, source-transparent cap, and config.limbs.${l})`,
|
|
1038
|
+
detail: `holds ${on} cap pixels where the base draws ${l}, but the set does not pose ${unposed.map((b) => `"${b}"`).join(', ')}; a supplied pose for the other limb is required to assign the cap by its target source segments, never its base place` });
|
|
1039
|
+
}
|
|
1040
|
+
if (problems.length > before || posed.length === 0) return;
|
|
1041
|
+
const own = sourceLimbTarget(limbs[q.limb], q.of, places);
|
|
1042
|
+
const other = posed.map((l) => ({ l, target: sourceLimbTarget(others.limbs[l], q.of, places) }));
|
|
1043
|
+
for (const { l, target } of [{ l: q.limb, target: own }, ...other]) {
|
|
1044
|
+
if (target.missingEndBone !== null) problems.push({ code: 'ASSEMBLE_ALT_LIMB_POSE', object: `config.limbs.${l} (part "${q.part}", source-transparent cap, bone "${target.missingEndBone}")`,
|
|
1045
|
+
detail: `takes "${q.of}" on a segment with no supplied end; an explicit bone tip or the following segment's joint in the set's pose is required to assign its cap, never an invented endpoint` });
|
|
1046
|
+
}
|
|
1047
|
+
if (problems.length > before) return;
|
|
1048
|
+
let kept = 0, bandKept = 0, bandGiven = 0;
|
|
1049
|
+
const given = new Map(posed.map((l) => [l, 0]));
|
|
1050
|
+
for (const p of candidates) {
|
|
1051
|
+
const x = p % W + 0.5, y = Math.floor(p / W) + 0.5;
|
|
1052
|
+
const dOwn = Math.sqrt(polylineDist2(own.line, x, y));
|
|
1053
|
+
let best: { l: string; distance: number; part: string } | null = null;
|
|
1054
|
+
for (const o of other) {
|
|
1055
|
+
const near = nearestTargetPart(o.target, x, y);
|
|
1056
|
+
if (best === null || near.distance < best.distance) best = { l: o.l, ...near };
|
|
1057
|
+
}
|
|
1058
|
+
if (best === null) continue;
|
|
1059
|
+
const inBand = Math.abs(best.distance - dOwn) <= OVERLAP_BAND_PX;
|
|
1060
|
+
const give = inBand ? (drawAt.get(best.part) ?? -1) > (drawAt.get(q.part) ?? -1) : best.distance < dOwn;
|
|
1061
|
+
const opaque = piece.r.data[p * 4 + 3] > OPAQUE_ALPHA_ABOVE;
|
|
1062
|
+
if (!give) {
|
|
1063
|
+
if (opaque) { kept++; if (inBand) bandKept++; }
|
|
1064
|
+
} else {
|
|
1065
|
+
if (opaque) { given.set(best.l, (given.get(best.l) ?? 0) + 1); if (inBand) bandGiven++; }
|
|
1066
|
+
piece.r.data.fill(0, p * 4, p * 4 + 4);
|
|
1067
|
+
if (piece.region !== null) piece.region.data[p] = 0;
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
counts.push({ part: q.part, of: q.of, limb: q.limb, kept, given: posed.map((l) => ({ limb: l, px: given.get(l) ?? 0 })), bandKept, bandGiven });
|
|
1071
|
+
});
|
|
1072
|
+
return { counts, problems };
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
/** Only actual cap reassignments are reported; source-art split counts remain their own stage's. */
|
|
1076
|
+
export function capOwnershipLines(set: string, counts: readonly SplitCount[]): string[] {
|
|
1077
|
+
return counts.filter((c) => c.given.some((g) => g.px > 0)).map((c) =>
|
|
1078
|
+
` LINT set "${set}" ${c.part}: source-transparent cap assigned by target source segments at the set's bones: kept ${c.kept} px, ${c.given.map((g) => `gave ${g.px} px to ${g.limb}`).join(', ')}; overlap band ${OVERLAP_BAND_PX} px, ${c.bandKept} kept and ${c.bandGiven} given by draw order`);
|
|
1079
|
+
}
|
|
1080
|
+
|
|
974
1081
|
/**
|
|
975
1082
|
* One `LINT` line per {@link SplitCount} (issue #609), in `config.limbs` order: the part's pixels kept and given to each
|
|
976
1083
|
* other limb, each with its share of the part's pixels before the split (3 places), and the overlap band's pixels and
|
|
@@ -2113,9 +2220,11 @@ export function pixelOwners(rigLayers: readonly Raster[], rank: readonly number[
|
|
|
2113
2220
|
*
|
|
2114
2221
|
* Both rules return `clear` (no layer in front of this one, by `frontOf`, is the owner) and `takenMask`, the
|
|
2115
2222
|
* masks the part counts in `parts.json` are derived from; `takenMask` is a
|
|
2116
|
-
* subset of the top-most set, and so of `clear`.
|
|
2223
|
+
* subset of the top-most set, and so of `clear`. Issue #637's optional `keep`
|
|
2224
|
+
* masks mark own-layer art under a subset set's actual cover (alpha above 8);
|
|
2225
|
+
* those pixels are occluded, outside every projection core, and never recoloured.
|
|
2117
2226
|
*/
|
|
2118
|
-
export function projectSource(rigLayers: Raster[], srcr: Raster, frame: Frame, run: Run, rule: ProjectRule = DEFAULT_PROJECT_RULE, rank: readonly number[] | null = null): ProjectionStats[] {
|
|
2227
|
+
export function projectSource(rigLayers: Raster[], srcr: Raster, frame: Frame, run: Run, rule: ProjectRule = DEFAULT_PROJECT_RULE, rank: readonly number[] | null = null, keep: ReadonlyArray<Mask | null> | null = null): ProjectionStats[] {
|
|
2119
2228
|
const { W, H } = frame;
|
|
2120
2229
|
const owner = pixelOwners(rigLayers, rank);
|
|
2121
2230
|
const inFront = (o: number, i: number): boolean => frontOf(o, i, rank);
|
|
@@ -2135,8 +2244,8 @@ export function projectSource(rigLayers: Raster[], srcr: Raster, frame: Frame, r
|
|
|
2135
2244
|
const takenMask = newMask(W, H);
|
|
2136
2245
|
let anyTop = false;
|
|
2137
2246
|
for (let p = 0; p < W * H; p++) {
|
|
2138
|
-
if (owner[p] === -1 || owner[p] === i || !inFront(owner[p], i)) clear.data[p] = 1;
|
|
2139
|
-
if (owner[p] === i && r.data[p * 4 + 3] >= CORE_ALPHA) {
|
|
2247
|
+
if (keep?.[i]?.data[p] !== 1 && (owner[p] === -1 || owner[p] === i || !inFront(owner[p], i))) clear.data[p] = 1;
|
|
2248
|
+
if (keep?.[i]?.data[p] !== 1 && owner[p] === i && r.data[p * 4 + 3] >= CORE_ALPHA) {
|
|
2140
2249
|
top.data[p] = 1;
|
|
2141
2250
|
anyTop = true;
|
|
2142
2251
|
}
|
|
@@ -2607,7 +2716,8 @@ function keepArtWhole(part: PlacedPart, cleared: Cleared[], holderAt: (q: number
|
|
|
2607
2716
|
|
|
2608
2717
|
/**
|
|
2609
2718
|
* Step 4b (issue #119), over every part in draw order, before the seam
|
|
2610
|
-
* override.
|
|
2719
|
+
* override. Issue #637's optional `keep` masks protect own-layer art under a set cover.
|
|
2720
|
+
* Modifies the part images in place and returns, per part, the
|
|
2611
2721
|
* pixels it cleared, by holder.
|
|
2612
2722
|
*
|
|
2613
2723
|
* ⚖️ Invariant: a pixel is PUSHED BACK in a part when, over the stack as it
|
|
@@ -2653,7 +2763,7 @@ function keepArtWhole(part: PlacedPart, cleared: Cleared[], holderAt: (q: number
|
|
|
2653
2763
|
* hold the pixel after it); and every pixel at alpha >= `CORE_ALPHA`, which
|
|
2654
2764
|
* is the seam override's.
|
|
2655
2765
|
*/
|
|
2656
|
-
export function pushBackFringe(parts: PlacedPart[], srcr: Raster, rule: SeamRule, silhouette: Mask | null, feathered: ReadonlyArray<Mask | null> | null = null): FringePushed[][] {
|
|
2766
|
+
export function pushBackFringe(parts: PlacedPart[], srcr: Raster, rule: SeamRule, silhouette: Mask | null, feathered: ReadonlyArray<Mask | null> | null = null, keep: ReadonlyArray<Mask | null> | null = null): FringePushed[][] {
|
|
2657
2767
|
const { width: W } = srcr;
|
|
2658
2768
|
const { holder, cand } = seamCandidates(parts, srcr, rule, silhouette);
|
|
2659
2769
|
const at = (i: number, d: number): number => {
|
|
@@ -2671,7 +2781,7 @@ export function pushBackFringe(parts: PlacedPart[], srcr: Raster, rule: SeamRule
|
|
|
2671
2781
|
// cover itself the loop below has nothing to clear, and the seam override acts on the pixel as before.
|
|
2672
2782
|
if (cand[d] === 0 || !shows(d)) continue;
|
|
2673
2783
|
for (let i = holder[d] + 1; i < parts.length; i++) {
|
|
2674
|
-
if (feathered?.[i]?.data[d] === 1) continue;
|
|
2784
|
+
if (feathered?.[i]?.data[d] === 1 || keep?.[i]?.data[d] === 1) continue;
|
|
2675
2785
|
const s = at(i, d);
|
|
2676
2786
|
if (s < 0) continue;
|
|
2677
2787
|
const img = parts[i].image.data;
|
|
@@ -2712,10 +2822,12 @@ export function pushBackFringe(parts: PlacedPart[], srcr: Raster, rule: SeamRule
|
|
|
2712
2822
|
* characters — ORACLE_assemble.md.)
|
|
2713
2823
|
* Each candidate is recoloured to the painting's colour in the TOP-MOST part
|
|
2714
2824
|
* covering it, and only where that part's alpha is >= 250; alpha never
|
|
2715
|
-
* changes. Candidates are chosen once, before any recolouring.
|
|
2825
|
+
* changes. Candidates are chosen once, before any recolouring. Issue #637's
|
|
2826
|
+
* optional `keep` masks, indexed by part in rig space, preserve own-layer art
|
|
2827
|
+
* under a subset set's actual cover instead of recolouring it to the painting.
|
|
2716
2828
|
* (`assemble_parts.py` `main`, "5. seam override".)
|
|
2717
2829
|
*/
|
|
2718
|
-
export function seamOverride(parts: PlacedPart[], srcr: Raster, rule: SeamRule, silhouette: Mask | null): void {
|
|
2830
|
+
export function seamOverride(parts: PlacedPart[], srcr: Raster, rule: SeamRule, silhouette: Mask | null, keep: ReadonlyArray<Mask | null> | null = null): void {
|
|
2719
2831
|
const { width: W } = srcr;
|
|
2720
2832
|
const { top, cand } = seamCandidates(parts, srcr, rule, silhouette);
|
|
2721
2833
|
parts.forEach(({ record: p, image }, i) => {
|
|
@@ -2724,7 +2836,7 @@ export function seamOverride(parts: PlacedPart[], srcr: Raster, rule: SeamRule,
|
|
|
2724
2836
|
for (let x = 0; x < p.w; x++) {
|
|
2725
2837
|
const d = (p.y + y) * W + p.x + x;
|
|
2726
2838
|
const s = (y * p.w + x) * 4;
|
|
2727
|
-
if (cand[d] === 0 || top[d] !== i || image.data[s + 3] < CORE_ALPHA) continue;
|
|
2839
|
+
if (keep?.[i]?.data[d] === 1 || cand[d] === 0 || top[d] !== i || image.data[s + 3] < CORE_ALPHA) continue;
|
|
2728
2840
|
image.data[s] = srcr.data[d * 4];
|
|
2729
2841
|
image.data[s + 1] = srcr.data[d * 4 + 1];
|
|
2730
2842
|
image.data[s + 2] = srcr.data[d * 4 + 2];
|
|
@@ -3375,7 +3487,7 @@ const CAP_FROM_LOWER = 4;
|
|
|
3375
3487
|
const CAP_FROM_LOWER_KEPT = 5;
|
|
3376
3488
|
|
|
3377
3489
|
/**
|
|
3378
|
-
*
|
|
3490
|
+
* Issues #603/#637: ownership or set exclusion cleared rig pixel `(x, y)` of a lower segment's part; when the cap wrote or kept it,
|
|
3379
3491
|
* move it from the count it was in to `excluded_px`, so the record's counts are the PNG's. A pixel off the cap's disc,
|
|
3380
3492
|
* or one the cap counted missing (it wrote none), changes nothing.
|
|
3381
3493
|
*/
|
|
@@ -4101,6 +4213,8 @@ export interface AssembleResult {
|
|
|
4101
4213
|
islands: IslandCount[];
|
|
4102
4214
|
/** Issue #609: what each limb segment part cut from a `limbIslands` part of one island that `otherLimbs` take kept; empty otherwise. */
|
|
4103
4215
|
splits: SplitCount[];
|
|
4216
|
+
/** Issue #637: source-transparent cap pixels assigned before preservation, in either source-art door. */
|
|
4217
|
+
capSplits: SplitCount[];
|
|
4104
4218
|
}
|
|
4105
4219
|
|
|
4106
4220
|
/** A hidden-art layer of a run (issue #359) and what read it: `cuts[i].under`, or a limb segment's cap; none is said. */
|
|
@@ -4297,6 +4411,13 @@ export function assemble(input: AssembleInput): AssembleResult {
|
|
|
4297
4411
|
});
|
|
4298
4412
|
refuseIfAny(hiddenProblems);
|
|
4299
4413
|
|
|
4414
|
+
// Issue #637: only subset limb sources, and only where a layer in front actually holds art.
|
|
4415
|
+
// Never extend an absent limb pixel or borrow a base layer's colour. The mask survives cuts by
|
|
4416
|
+
// the source key; only the resulting limb pieces read it, after #609 has assigned their pixels.
|
|
4417
|
+
const underCover = new Map<string, Mask>();
|
|
4418
|
+
const coverFootprints = new Map<string, Mask>();
|
|
4419
|
+
const limbSources = new Set(Object.values(input.limbs ?? {}).flatMap((l) => l.segments.map((sg) => sg.from)));
|
|
4420
|
+
const limbPlans = new Set([...limbSources, ...cuts.filter((c) => limbSources.has(c.into)).map((c) => c.from)]);
|
|
4300
4421
|
const rig = new Map<string, Raster>();
|
|
4301
4422
|
const stats = new Map<string, ProjectionStats>();
|
|
4302
4423
|
const ghost: Record<string, number> = {};
|
|
@@ -4307,7 +4428,21 @@ export function assemble(input: AssembleInput): AssembleResult {
|
|
|
4307
4428
|
const layers = runLayers(set, input.resolution);
|
|
4308
4429
|
if (run === 'full') fullTags.push(...layers.filter((l) => l.opaqueRunPx > 0).map((l) => l.tag));
|
|
4309
4430
|
const rigLayers = layers.map((l) => layerToRig(l.canvas, frame, run));
|
|
4310
|
-
const
|
|
4431
|
+
const rank = planRanks(layers.map((l) => l.tag), run, plan);
|
|
4432
|
+
const keep = layers.map((l, i): Mask | null => {
|
|
4433
|
+
if (input.limbUnderCover !== true || !plan.some(([name, ru, tag]) => limbPlans.has(name) && ru === run && tag === l.tag)) return null;
|
|
4434
|
+
const mask = newMask(W, H);
|
|
4435
|
+
const cover = newMask(W, H);
|
|
4436
|
+
for (let p = 0; p < W * H; p++) {
|
|
4437
|
+
if (!rigLayers.some((r, j) => frontOf(j, i, rank) && r.data[p * 4 + 3] > OPAQUE_ALPHA_ABOVE)) continue;
|
|
4438
|
+
cover.data[p] = 1;
|
|
4439
|
+
if (rigLayers[i].data[p * 4 + 3] > OPAQUE_ALPHA_ABOVE) mask.data[p] = 1;
|
|
4440
|
+
}
|
|
4441
|
+
underCover.set(`${run}:${l.tag}`, mask);
|
|
4442
|
+
coverFootprints.set(`${run}:${l.tag}`, cover);
|
|
4443
|
+
return mask;
|
|
4444
|
+
});
|
|
4445
|
+
const st = projectSource(rigLayers, srcr, frame, run, projectRule, rank, keep);
|
|
4311
4446
|
layers.forEach((l, i) => {
|
|
4312
4447
|
rig.set(`${run}:${l.tag}`, rigLayers[i]);
|
|
4313
4448
|
stats.set(`${run}:${l.tag}`, st[i]);
|
|
@@ -4624,16 +4759,61 @@ export function assemble(input: AssembleInput): AssembleResult {
|
|
|
4624
4759
|
? { counts: [], splits: [], problems: [] }
|
|
4625
4760
|
: keepJointIslands(input.limbIslands ?? [], input.limbs ?? {}, input.bones ?? [], lim.parts, limbPieces, limbSource, W, H, input.islandFloor ?? ISLAND_FLOOR_SHARE, input.otherLimbs);
|
|
4626
4761
|
refuseIfAny(islandKept.problems);
|
|
4762
|
+
const capAssigned = input.capOwnership === 'source' ? { counts: [], problems: [] }
|
|
4763
|
+
: assignCapOwnership(input.limbIslands ?? [], input.limbs ?? {}, input.bones ?? [], lim.parts, limbPieces, limbSource, lim.capFrom, W, H, input.otherLimbs);
|
|
4764
|
+
refuseIfAny(capAssigned.problems);
|
|
4627
4765
|
|
|
4628
|
-
|
|
4629
|
-
// Issue #
|
|
4630
|
-
|
|
4766
|
+
|
|
4767
|
+
// Issue #637: protection belongs to the assigned piece, never to a component guessed from
|
|
4768
|
+
// its size or colour. After target assignment, a retained upper-copy cap is the limb's connecting art beneath
|
|
4769
|
+
// its upper segment (limbOrder draws the upper over the lower). Other cap provenance is
|
|
4770
|
+
// protected only beneath an actual front layer, including where the lower source is
|
|
4771
|
+
// transparent. Source art still needs both its own alpha and that actual cover.
|
|
4772
|
+
// Read this after island/nearest-line assignment: a cleared pixel is never brought back.
|
|
4631
4773
|
const recount = input.exclusionCounts !== 'before';
|
|
4774
|
+
// Assignment owns its bookkeeping even when cover preservation is not requested
|
|
4775
|
+
// (for example a direct assemble caller). Only the explicit historical mutant
|
|
4776
|
+
// with neither protection nor target assignment retains the old count path.
|
|
4777
|
+
if (recount && (input.limbUnderCover === true || input.capOwnership !== 'source')) {
|
|
4778
|
+
limbPieces.forEach((b, i) => {
|
|
4779
|
+
if (b.region !== null) b.merged = mergedIn(b, b.region);
|
|
4780
|
+
const cap = lim.parts[i].record.cap, from = lim.capFrom[i];
|
|
4781
|
+
if (cap === undefined || from === null) return;
|
|
4782
|
+
const [bx, by, bw, bh] = from.box;
|
|
4783
|
+
for (let y = Math.max(0, by); y < Math.min(H, by + bh); y++) for (let x = Math.max(0, bx); x < Math.min(W, bx + bw); x++) {
|
|
4784
|
+
if (b.r.data[(y * W + x) * 4 + 3] === 0) excludeCapPixel(cap, from, x, y);
|
|
4785
|
+
}
|
|
4786
|
+
});
|
|
4787
|
+
}
|
|
4788
|
+
const limbKeep = limbPieces.map((b, i): Mask | null => {
|
|
4789
|
+
if (input.limbUnderCover !== true) return null;
|
|
4790
|
+
const keep = newMask(W, H);
|
|
4791
|
+
const sourceKeep = underCover.get(b.key);
|
|
4792
|
+
if (sourceKeep !== undefined) keep.data.set(sourceKeep.data);
|
|
4793
|
+
const cap = lim.parts[i].record.cap;
|
|
4794
|
+
const from = lim.capFrom[i];
|
|
4795
|
+
if (cap === undefined || from === null) return keep;
|
|
4796
|
+
const [bx, by, bw, bh] = from.box;
|
|
4797
|
+
for (let y = Math.max(0, by); y < Math.min(H, by + bh); y++) {
|
|
4798
|
+
for (let x = Math.max(0, bx); x < Math.min(W, bx + bw); x++) {
|
|
4799
|
+
const code = from.codes[(y - by) * bw + x - bx];
|
|
4800
|
+
if (code === 0) continue;
|
|
4801
|
+
const p = y * W + x;
|
|
4802
|
+
if (b.r.data[p * 4 + 3] > 0 && (code === CAP_FROM_UPPER || coverFootprints.get(b.key)?.data[p] === 1)) keep.data[p] = 1;
|
|
4803
|
+
}
|
|
4804
|
+
}
|
|
4805
|
+
return keep;
|
|
4806
|
+
});
|
|
4807
|
+
|
|
4808
|
+
// Issue #587: unprotected pixels under base parts not replaced by the set still leave.
|
|
4809
|
+
// Issue #603: merged_px and cap counts lose exactly the pixels cleared from the PNG.
|
|
4810
|
+
const excluded: ExcludedCount[] = [];
|
|
4632
4811
|
for (const ex of input.exclude ?? []) {
|
|
4633
4812
|
const d = order.find((q) => !('patch' in q) && pieceAt(q).name === ex.part);
|
|
4634
4813
|
const b = d === undefined || 'patch' in d ? null : pieceAt(d).b;
|
|
4635
4814
|
const capOf = d !== undefined && 'limb' in d ? lim.parts[d.limb].record.cap : undefined;
|
|
4636
4815
|
const from = d !== undefined && 'limb' in d ? lim.capFrom[d.limb] : null;
|
|
4816
|
+
const keep = d !== undefined && 'limb' in d ? limbKeep[d.limb] : null;
|
|
4637
4817
|
let px = 0;
|
|
4638
4818
|
if (b !== null) {
|
|
4639
4819
|
if (b.region === null) {
|
|
@@ -4642,7 +4822,7 @@ export function assemble(input: AssembleInput): AssembleResult {
|
|
|
4642
4822
|
}
|
|
4643
4823
|
let mergedOut = 0;
|
|
4644
4824
|
for (let p = 0; p < W * H; p++) {
|
|
4645
|
-
if (ex.mask.data[p] === 0 || b.r.data[p * 4 + 3] === 0) continue;
|
|
4825
|
+
if (ex.mask.data[p] === 0 || b.r.data[p * 4 + 3] === 0 || keep?.data[p] === 1) continue;
|
|
4646
4826
|
if (b.r.data[p * 4 + 3] > OPAQUE_ALPHA_ABOVE) px++;
|
|
4647
4827
|
// merged_px counts the last merge's copied pixels and its ring inside the part's region (`mergedIn`).
|
|
4648
4828
|
if (b.region.data[p] === 1) mergedOut += (b.trace.lastSel?.data[p] ?? 0) + (b.trace.lastRing?.data[p] ?? 0);
|
|
@@ -4664,7 +4844,8 @@ export function assemble(input: AssembleInput): AssembleResult {
|
|
|
4664
4844
|
return { record: whole, image: b.r };
|
|
4665
4845
|
});
|
|
4666
4846
|
const featheredInOrder: Array<Mask | null> = order.map((d) => ('patch' in d ? null : (pieceAt(d).b.feathered ?? null)));
|
|
4667
|
-
const
|
|
4847
|
+
const keepInOrder = order.map((d) => ('limb' in d ? limbKeep[d.limb] : null));
|
|
4848
|
+
const pushedBy = pushBackFringe(stack, srcr, seamRule, seamRule === 'silhouette' ? silhouette : null, featheredInOrder, keepInOrder);
|
|
4668
4849
|
// Issue #255: a part's drift refusals in a body, and who holds the body in the draw order (the push-back clears
|
|
4669
4850
|
// only fringe below CORE_ALPHA, and the seam override only recolours, so the holders read here are final).
|
|
4670
4851
|
const holderAt = new Int32Array(W * H).fill(-1);
|
|
@@ -4768,7 +4949,7 @@ export function assemble(input: AssembleInput): AssembleResult {
|
|
|
4768
4949
|
refuseIfAny(empty);
|
|
4769
4950
|
const placed: PlacedPart[] = order.map((d) => ('plan' in d ? planned[d.plan] : 'cut' in d ? cutPlaced[d.cut] : 'limb' in d ? limbPlaced[d.limb] : cut[d.patch]) as PlacedPart);
|
|
4770
4951
|
|
|
4771
|
-
seamOverride(placed, srcr, seamRule, seamRule === 'silhouette' ? silhouette : null);
|
|
4952
|
+
seamOverride(placed, srcr, seamRule, seamRule === 'silhouette' ? silhouette : null, keepInOrder);
|
|
4772
4953
|
const can = recomposite(placed, W, H);
|
|
4773
4954
|
// Issue #242: on a scene painting the figure is read off the full run, and every recomposite figure inside it.
|
|
4774
4955
|
const inside = input.scene === true ? sceneFigure([...rig.entries()].filter(([k]) => k.startsWith('full:')).map(([, r]) => r), W, H) : null;
|
|
@@ -4819,6 +5000,7 @@ export function assemble(input: AssembleInput): AssembleResult {
|
|
|
4819
5000
|
excluded,
|
|
4820
5001
|
islands: islandKept.counts,
|
|
4821
5002
|
splits: islandKept.splits,
|
|
5003
|
+
capSplits: capAssigned.counts,
|
|
4822
5004
|
};
|
|
4823
5005
|
}
|
|
4824
5006
|
|
package/src/build.ts
CHANGED
|
@@ -84,7 +84,7 @@ import { type AlternatePartsRecord, type PartRecord, readParts, type Recomposite
|
|
|
84
84
|
import { encodePngBytes, readPng, writePng } from './raster/png.ts';
|
|
85
85
|
import type { Raster } from './raster/types.ts';
|
|
86
86
|
import { type Mask, newMask } from './raster/types.ts';
|
|
87
|
-
import { type OtherLimbs, splitLines, type SplitCount } from './assemble.ts';
|
|
87
|
+
import { type OtherLimbs, splitLines, capOwnershipLines, type SplitCount } from './assemble.ts';
|
|
88
88
|
import type { BoneEntry } from './config.ts';
|
|
89
89
|
import { OPAQUE_ALPHA_ABOVE } from './layers.ts';
|
|
90
90
|
import { readRequirements, type RequirementLine, summaryText } from './requirements.ts';
|
|
@@ -93,6 +93,7 @@ import { KEYPOINT_NAMES, type KeypointName, type PosePoints } from './skeleton.t
|
|
|
93
93
|
import { AUTHOR_NO_ROLE, isAuthorTag } from './tags.ts';
|
|
94
94
|
import { TURN_BONE } from './turn.ts';
|
|
95
95
|
import { pyRound } from './round.ts';
|
|
96
|
+
import { LAYOUT_FILE, layoutCompanion, refreshLimbLayout } from './limblayout.ts';
|
|
96
97
|
|
|
97
98
|
/** Where a stage's lines go. The commands hand it `console.log`; `build` hands it a prefixing wrapper. */
|
|
98
99
|
export type Log = (line: string) => void;
|
|
@@ -169,6 +170,10 @@ export interface AssembleStageInput {
|
|
|
169
170
|
* `"none"` takes them, the rule before #587 — kept for the selftest's control that shows the count go red under it.
|
|
170
171
|
*/
|
|
171
172
|
setExclusion?: 'base' | 'none';
|
|
173
|
+
/** Issue #637: the CLI protects assigned source/cap art under covers; painting is the unprotected test mutant only. */
|
|
174
|
+
setCover?: 'layer' | 'painting';
|
|
175
|
+
/** Issue #637: source is the skipped-cap ownership test mutant, never a CLI/config option. */
|
|
176
|
+
setCapOwnership?: 'target' | 'source';
|
|
172
177
|
/**
|
|
173
178
|
* What a subset set's limb parts keep of a layer of more than one island when the set names one limb side (issue
|
|
174
179
|
* #588): `"joints"` (the default, the only one the CLI runs) the island the segment's joints fall on
|
|
@@ -180,9 +185,11 @@ export interface AssembleStageInput {
|
|
|
180
185
|
* How a subset set's limb parts share a layer of one island with a limb the set does not carry (issue #609):
|
|
181
186
|
* `"nearest"` (the default, the only one the CLI runs) by the nearest segment line in the set's pose, the other limb
|
|
182
187
|
* placed by the set's skeleton ({@link OtherLimbs}); `"connectivity"` every pixel on the set's limb, the rule before
|
|
183
|
-
* #609 — kept for the selftest's control that shows the second-limb share go red under it.
|
|
188
|
+
* #609 — kept for the selftest's control that shows the second-limb share go red under it. Issue #638's
|
|
189
|
+
* `"whole-limb"` mutant uses the pre-fix line, including segments taking other sources, to reproduce its measured
|
|
190
|
+
* default-cap case. Neither mutant is a CLI/config option or bypasses the rig-c gate.
|
|
184
191
|
*/
|
|
185
|
-
setSplit?: 'nearest' | 'connectivity';
|
|
192
|
+
setSplit?: 'nearest' | 'connectivity' | 'whole-limb';
|
|
186
193
|
}
|
|
187
194
|
|
|
188
195
|
/** Where the assemble stage writes: `parts.json`, the directory of part PNGs, the recomposite, and its error map. */
|
|
@@ -338,7 +345,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
338
345
|
}
|
|
339
346
|
|
|
340
347
|
const altProblems: Problem[] = [];
|
|
341
|
-
const altBuilt: Array<{ record: AlternatePartsRecord; images: Array<{ name: string; image: Raster }>; excluded: ExcludedCount[]; islands: IslandCount[]; splits: SplitCount[] }> = [];
|
|
348
|
+
const altBuilt: Array<{ record: AlternatePartsRecord; images: Array<{ name: string; image: Raster }>; excluded: ExcludedCount[]; islands: IslandCount[]; splits: SplitCount[]; capSplits: SplitCount[] }> = [];
|
|
342
349
|
const baseSlots = result.parts.parts.map((p) => p.name);
|
|
343
350
|
for (const alt of mergedAlts) {
|
|
344
351
|
if (alt.source === undefined || alt.full === undefined) {
|
|
@@ -542,6 +549,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
542
549
|
for (const b of Object.keys(limbDrawn)) setPlaced.add(b);
|
|
543
550
|
}
|
|
544
551
|
const altOthers = Object.keys(otherLimbs).length === 0 ? undefined : otherLimbsOf(otherLimbs, setPlaced, fields.bones ?? [], result.images, result.parts.rig_size, altSkeleton !== undefined ? 'skeleton' : alt.drawn !== undefined ? 'drawn' : 'none');
|
|
552
|
+
if (altOthers !== undefined && input.setSplit === 'whole-limb') altOthers.line = 'whole-limb';
|
|
545
553
|
// Issue #587: a subset set's limb part takes nothing a base part it does not replace covers at setup.
|
|
546
554
|
const [exW, exH] = result.parts.rig_size;
|
|
547
555
|
const altExclude =
|
|
@@ -552,6 +560,8 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
552
560
|
try {
|
|
553
561
|
altRes = assemble({
|
|
554
562
|
source: altSrc,
|
|
563
|
+
limbUnderCover: alt.parts !== undefined && input.setCover !== 'painting',
|
|
564
|
+
capOwnership: input.setCapOwnership ?? 'target',
|
|
555
565
|
full: altRuns.full,
|
|
556
566
|
head: altRuns.head,
|
|
557
567
|
resolution: fields.resolution,
|
|
@@ -621,6 +631,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
621
631
|
excluded: altRes.excluded,
|
|
622
632
|
islands: altRes.islands,
|
|
623
633
|
splits: altRes.splits,
|
|
634
|
+
capSplits: altRes.capSplits,
|
|
624
635
|
});
|
|
625
636
|
}
|
|
626
637
|
refuseIfAny(altProblems);
|
|
@@ -685,7 +696,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
685
696
|
// Issue #588: per subset set, one line per limb part cut from a layer of more than one island, then (issue #587) one
|
|
686
697
|
// per limb part and base part over it that took a pixel. None otherwise.
|
|
687
698
|
// Issue #609: then one per limb part cut from a layer of one island that also holds a limb the set does not carry.
|
|
688
|
-
for (const b of altBuilt) for (const l of [...islandLines(b.record.name, b.islands), ...splitLines(b.record.name, b.splits), ...excludedLines(b.record.name, b.excluded)]) log(l);
|
|
699
|
+
for (const b of altBuilt) for (const l of [...islandLines(b.record.name, b.islands), ...splitLines(b.record.name, b.splits), ...capOwnershipLines(b.record.name, b.capSplits), ...excludedLines(b.record.name, b.excluded)]) log(l);
|
|
689
700
|
log(`wrote ${outs.partsJson}, ${result.images.length} PNG(s) in ${outs.partsDir}, ${outs.recomposite}, ${outs.errorMap} (uncovered error px red, covered error px blue, the painting grey)${figurePath === null ? '' : `, ${figurePath} (the figure, white, the recomposite was read inside)`}`);
|
|
690
701
|
return result;
|
|
691
702
|
}
|
|
@@ -1279,18 +1290,22 @@ export function readRigInputs(config: string, partsDir: string): RigInputs {
|
|
|
1279
1290
|
return { cfg, from, parts, images };
|
|
1280
1291
|
}
|
|
1281
1292
|
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
const mergedMotion = withAnimations(r.motion, from === null ? null : from.table);
|
|
1293
|
+
/** Final candidate serialization shared by initial and settled motion replay. */
|
|
1294
|
+
export function rigOutputTexts(r: RigOutput, animations: Parameters<typeof withAnimations>[1]): Array<[string, string]> {
|
|
1295
|
+
const mergedMotion = withAnimations(r.motion, animations);
|
|
1296
|
+
if (r.layout !== undefined) r.layout = refreshLimbLayout(r.layout, r.rig);
|
|
1287
1297
|
return [
|
|
1288
1298
|
['rig.json', rigJsonText(r.rig)],
|
|
1289
1299
|
['motion.json', rigJsonText(mergedMotion)],
|
|
1290
1300
|
['mesh_report.json', rigJsonText(r.meshReport)],
|
|
1291
1301
|
...(r.sets === undefined ? [] : [[SETS_FILE, rigJsonText(r.sets)] as [string, string]]),
|
|
1292
1302
|
];
|
|
1293
|
-
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
export function rigStage(input: RigStageInput, rigc: RigcRunner, scratch: string, log: Log): RigOutput {
|
|
1306
|
+
const { cfg, from, parts, images } = readRigInputs(input.config, input.parts);
|
|
1307
|
+
const first = buildRig(cfg, parts, images, undefined, input.idleKeys ?? DEFAULT_IDLE_KEYS, input.reduce);
|
|
1308
|
+
const textsOf = (r: RigOutput): Array<[string, string]> => rigOutputTexts(r, from === null ? null : from.table);
|
|
1294
1309
|
const firstTexts = textsOf(first);
|
|
1295
1310
|
// The gate runs before the lines are printed, and its lines print where they always did: an automatic part's motion
|
|
1296
1311
|
// gate compares the model document of this very build, the one written (issue #126 item 3). mesh_report.json is staged
|
|
@@ -1439,9 +1454,13 @@ export function rigStage(input: RigStageInput, rigc: RigcRunner, scratch: string
|
|
|
1439
1454
|
rig.meshReport.splice(0, rig.meshReport.length, ...rows);
|
|
1440
1455
|
texts[2] = ['mesh_report.json', rigJsonText(rig.meshReport)];
|
|
1441
1456
|
}
|
|
1457
|
+
const layout = rig.layout === undefined ? undefined : layoutCompanion(rig.layout, rig.rig, texts[0][1], texts.find(([n]) => n === SETS_FILE)?.[1]);
|
|
1458
|
+
// This stage owns the companion. A red run reaches neither cleanup nor emit.
|
|
1459
|
+
if (layout === undefined) rmSync(join(input.out, LAYOUT_FILE), { force: true });
|
|
1442
1460
|
mkdirSync(join(input.out, 'images'), { recursive: true });
|
|
1443
1461
|
for (const [file, img] of rig.images) writePng(join(input.out, 'images', file), img);
|
|
1444
1462
|
for (const [file, text] of texts) writeFileSync(join(input.out, file), text);
|
|
1463
|
+
if (layout !== undefined) writeFileSync(join(input.out, LAYOUT_FILE), rigJsonText(layout));
|
|
1445
1464
|
log(`rig-parts rig: wrote ${join(input.out, 'rig.json')}, motion.json, mesh_report.json and ${rig.images.length} image(s) under ${join(input.out, 'images')}`);
|
|
1446
1465
|
return rig;
|
|
1447
1466
|
}
|
package/src/config.ts
CHANGED
|
@@ -931,8 +931,15 @@ export interface LimbSplit {
|
|
|
931
931
|
export interface Limb {
|
|
932
932
|
segments: LimbSegment[];
|
|
933
933
|
split?: LimbSplit;
|
|
934
|
+
/** Explicit rig-stage adjacency; absent, the existing limb closure is unchanged. */
|
|
935
|
+
layout?: LimbLayout;
|
|
934
936
|
}
|
|
935
937
|
|
|
938
|
+
export type LimbLayoutTarget = { limb: string; part?: never } | { part: string; limb?: never };
|
|
939
|
+
export type LimbLayout = { parts?: string[] } & (
|
|
940
|
+
{ before: LimbLayoutTarget; after?: never } | { after: LimbLayoutTarget; before?: never }
|
|
941
|
+
);
|
|
942
|
+
|
|
936
943
|
export interface CharacterConfig {
|
|
937
944
|
key: string;
|
|
938
945
|
note?: string;
|
|
@@ -1791,7 +1798,7 @@ export function parseProposalSections(raw: Json): SkeletonSections & { limbs?: R
|
|
|
1791
1798
|
const taken = isPlainObject(top.limbs)
|
|
1792
1799
|
? Object.values(top.limbs).flatMap((l) => (isPlainObject(l) && Array.isArray(l.segments) ? l.segments.flatMap((sg) => (isPlainObject(sg) && typeof sg.from === 'string' ? [sg.from] : [])) : []))
|
|
1793
1800
|
: [];
|
|
1794
|
-
checkLimbs(c, top.limbs, { parts: [...new Set(taken)], patches: [], cuts: [] }, names);
|
|
1801
|
+
checkLimbs(c, top.limbs, { parts: [...new Set(taken)], patches: [], cuts: [] }, names, false);
|
|
1795
1802
|
}
|
|
1796
1803
|
if ('meshes' in top) checkMeshes(c, top.meshes, names.bones, names.chains);
|
|
1797
1804
|
if ('regions' in top) checkRegions(c, top.regions, names.bones);
|
|
@@ -2969,7 +2976,7 @@ interface LimbNames {
|
|
|
2969
2976
|
* has two segments or more. With `names` null (no `bones`), bones are not
|
|
2970
2977
|
* resolved. Returns the limb parts and the parts the limbs take.
|
|
2971
2978
|
*/
|
|
2972
|
-
function checkLimbs(c: Check, v: Json, made: { parts: string[]; patches: string[]; cuts: string[] }, names: { bones: Set<string>; parents: Map<string, string> } | null): LimbNames {
|
|
2979
|
+
function checkLimbs(c: Check, v: Json, made: { parts: string[]; patches: string[]; cuts: string[] }, names: { bones: Set<string>; parents: Map<string, string> } | null, resolveLayoutParts = true): LimbNames {
|
|
2973
2980
|
const out: LimbNames = { parts: new Map(), consumed: new Map(), chains: new Map() };
|
|
2974
2981
|
if (!isPlainObject(v)) {
|
|
2975
2982
|
c.fail('CONFIG_FIELD_TYPE', 'config.limbs', `is ${show(v)}; an object of limb name -> {"segments": [...]} is required`);
|
|
@@ -2981,7 +2988,7 @@ function checkLimbs(c: Check, v: Json, made: { parts: string[]; patches: string[
|
|
|
2981
2988
|
const splitLimbs: string[] = [];
|
|
2982
2989
|
for (const [limb, spec] of Object.entries(v)) {
|
|
2983
2990
|
const at = `config.limbs.${limb}`;
|
|
2984
|
-
const o = c.object(at, spec, ['segments'], ['split']);
|
|
2991
|
+
const o = c.object(at, spec, ['segments'], ['split', 'layout']);
|
|
2985
2992
|
if (o === null) continue;
|
|
2986
2993
|
if ('split' in o) {
|
|
2987
2994
|
const sp = c.object(`${at}.split`, o.split, [], ['line', 'edge']);
|
|
@@ -3119,9 +3126,46 @@ function checkLimbs(c: Check, v: Json, made: { parts: string[]; patches: string[
|
|
|
3119
3126
|
}
|
|
3120
3127
|
}
|
|
3121
3128
|
}
|
|
3129
|
+
checkLimbLayouts(c, v, made, out, resolveLayoutParts);
|
|
3122
3130
|
return out;
|
|
3123
3131
|
}
|
|
3124
3132
|
|
|
3133
|
+
/** Validate after every limb is known; a declaration may refer forward by name. */
|
|
3134
|
+
function checkLimbLayouts(c: Check, limbs: Record<string, Json>, made: { parts: string[]; patches: string[]; cuts: string[] }, names: LimbNames, resolveParts: boolean): void {
|
|
3135
|
+
const produced = new Set([...made.parts, ...made.patches, ...made.cuts].filter((n) => !names.consumed.has(n)));
|
|
3136
|
+
for (const n of names.parts.keys()) produced.add(n);
|
|
3137
|
+
for (const [limb, raw] of Object.entries(limbs)) {
|
|
3138
|
+
if (!isPlainObject(raw) || !('layout' in raw)) continue;
|
|
3139
|
+
const at = `config.limbs.${limb}.layout`;
|
|
3140
|
+
const l = c.object(at, raw.layout, [], ['before', 'after', 'parts']);
|
|
3141
|
+
if (l === null) continue;
|
|
3142
|
+
const sides = ['before', 'after'].filter((s) => s in l);
|
|
3143
|
+
if (sides.length !== 1) c.fail('CONFIG_LAYOUT_TARGET', at, 'exactly one of before or after is required; it means immediate setup-slot adjacency');
|
|
3144
|
+
for (const side of sides) {
|
|
3145
|
+
const t = c.object(`${at}.${side}`, l[side], [], ['limb', 'part']);
|
|
3146
|
+
if (t === null) continue;
|
|
3147
|
+
const keys = ['limb', 'part'].filter((k) => k in t);
|
|
3148
|
+
if (keys.length !== 1) { c.fail('CONFIG_LAYOUT_TARGET', `${at}.${side}`, 'exactly one typed target, {limb: name} or {part: name}, is required'); continue; }
|
|
3149
|
+
const k = keys[0], n = t[k];
|
|
3150
|
+
if (!c.string(`${at}.${side}.${k}`, n)) continue;
|
|
3151
|
+
if (k === 'limb' ? !Object.hasOwn(limbs, n) : resolveParts && !produced.has(n)) {
|
|
3152
|
+
const consumed = names.consumed.get(n);
|
|
3153
|
+
c.fail('CONFIG_LAYOUT_NAME', `${at}.${side}.${k}`, `names "${n}"; ${k === 'limb' ? `a declared limb (${Object.keys(limbs).join(', ')})` : `a produced part (${[...produced].join(', ')})`} is required${consumed === undefined ? '' : `; "${n}" is consumed by limb "${consumed}" into ${names.chains.get(consumed)?.parts.join(', ')}`}`);
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
3156
|
+
if (!('parts' in l)) continue;
|
|
3157
|
+
const own = names.chains.get(limb)?.parts ?? [];
|
|
3158
|
+
if (!Array.isArray(l.parts) || l.parts.length === 0 || !l.parts.every((p) => typeof p === 'string' && own.includes(p))) {
|
|
3159
|
+
c.fail('CONFIG_LAYOUT_SCOPE', `${at}.parts`, `is ${show(l.parts)}; a nonempty list of this limb's source-bound segment parts (${own.join(', ')}) is required; rider names are not selectors`);
|
|
3160
|
+
continue;
|
|
3161
|
+
}
|
|
3162
|
+
const positions = l.parts.map((p) => own.indexOf(p as string)).sort((a, b) => a - b);
|
|
3163
|
+
if (new Set(positions).size !== positions.length || positions.some((p, i) => i > 0 && p !== positions[i - 1] + 1)) {
|
|
3164
|
+
c.fail('CONFIG_LAYOUT_SCOPE', `${at}.parts`, `is ${show(l.parts)}; distinct consecutive segment-part references in ${own.join(', ')} are required`);
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
|
|
3125
3169
|
/**
|
|
3126
3170
|
* Every plan part — and every cut's piece, which the caller lists with them —
|
|
3127
3171
|
* is exactly one of a mesh or a region, every patch is a region, and every
|