@rig-c/parts 2.32.0 → 2.34.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 +64 -2
- package/docs/STABILITY.md +3 -3
- package/package.json +1 -1
- package/src/assemble.ts +247 -32
- package/src/build.ts +8 -3
- package/src/config.ts +97 -22
- package/src/occluders.ts +231 -10
- package/src/occluderstage.ts +104 -14
- package/src/paintingowner.ts +7 -4
- package/src/parts.ts +48 -2
- package/src/takelayers.ts +130 -7
- package/src/takeregion.ts +16 -3
- package/src/takesource.ts +20 -1
package/src/assemble.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { paintingExtensionMasks, paintingExtensionProblems, type PaintingExtensi
|
|
|
15
15
|
import { applyEdgeSplits, edgeSplitLines, edgeSplitProblems, type EdgeSplit, type EdgeSplitReading } from './edgesplit.ts';
|
|
16
16
|
import { AUTOMATIC_WRITERS as AW, compactValueBaseline, pixelProvenance, rgbaEqual, type ValueBaseline, type StageMap } from './provenance.ts';
|
|
17
17
|
import { bindDepthRun, copyDepthMaterial, registerDepthRun, transportPartDepth, type DepthConfig, type RegisteredDepth } from './depthsheets.ts';
|
|
18
|
+
import { COPIED_ALPHA_ABOVE, OCCLUDER_EMPTY, occluderDrawCycleProblems, type OccluderDeclaration, occluderUnheldWarning, orderPlanForOccluders } from './occluders.ts';
|
|
18
19
|
/**
|
|
19
20
|
* The assemble stage: two See-through runs over one painting — a FULL-body run
|
|
20
21
|
* and a HEAD-crop run — merged into one set of rig-space parts, each part one
|
|
@@ -237,6 +238,8 @@ export interface Geometry {
|
|
|
237
238
|
yieldRefused?: boolean;
|
|
238
239
|
/** Plan parts whose own samples survive source re-take beneath soft front cover. */
|
|
239
240
|
keepUnderOccluders?: readonly string[];
|
|
241
|
+
/** `assemble.occluders` as declared (issue #1247; `AssembleInput.occluders` carries the decoded images): declared occluder entries whose `over` parts sit after their `under` parts in a proposed plan. */
|
|
242
|
+
occluderDeclarations?: readonly OccluderDeclaration[];
|
|
240
243
|
}
|
|
241
244
|
|
|
242
245
|
/**
|
|
@@ -422,6 +425,8 @@ export interface AssembleInput {
|
|
|
422
425
|
capOwnership?: 'target' | 'source';
|
|
423
426
|
/** Issue #791: pairs of parts a turn moves relative to each other, whose fringe and seam colour stay untouched. */
|
|
424
427
|
turnMovingPair?: ((a: string, b: string) => boolean) | null;
|
|
428
|
+
/** Issue #1246: declared occluders with their decoded source-grid RGBA images. */
|
|
429
|
+
occluders?: ReadonlyArray<{ declaration: OccluderDeclaration; image: Raster }>;
|
|
425
430
|
}
|
|
426
431
|
|
|
427
432
|
/**
|
|
@@ -4793,6 +4798,8 @@ export interface AssembleResult {
|
|
|
4793
4798
|
capSplits: SplitCount[];
|
|
4794
4799
|
/** Issue #1231: what each `edge_splits` entry moved before projection; empty without one. */
|
|
4795
4800
|
edgeSplits: EdgeSplitReading[];
|
|
4801
|
+
/** Issue #1246: `ASSEMBLE_OCCLUDER_UNHELD` WARN lines when `part` is omitted and occluder px are unheld at rest. */
|
|
4802
|
+
occluderUnheldWarnings?: string[];
|
|
4796
4803
|
}
|
|
4797
4804
|
|
|
4798
4805
|
/** Issue #953: the edge pixels `paintingEdges` resolved, the part pixels it changed, and the edge pixels it left, by reason. */
|
|
@@ -5064,6 +5071,35 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
5064
5071
|
const srcr = sourceInRig(source, W, H);
|
|
5065
5072
|
const supportPainted = paintedFigure(srcr);
|
|
5066
5073
|
const groundShare = groundRingShare(srcr, supportPainted);
|
|
5074
|
+
const occSx = (x: number): number => Math.min(source.width - 1, Math.floor((x + 0.5) * source.width / W));
|
|
5075
|
+
const occSy = (y: number): number => Math.min(source.height - 1, Math.floor((y + 0.5) * source.height / H));
|
|
5076
|
+
const occluderEntries = (input.occluders ?? []).map(({ declaration, image }, index) => {
|
|
5077
|
+
const opaqueMask = newMask(W, H);
|
|
5078
|
+
const copiedMask = newMask(W, H);
|
|
5079
|
+
for (let y = 0; y < H; y++) {
|
|
5080
|
+
const srcY = occSy(y);
|
|
5081
|
+
for (let x = 0; x < W; x++) {
|
|
5082
|
+
const a = image.data[(srcY * source.width + occSx(x)) * 4 + 3];
|
|
5083
|
+
const p = y * W + x;
|
|
5084
|
+
if (a > OPAQUE_ALPHA_ABOVE) opaqueMask.data[p] = 1;
|
|
5085
|
+
if (a > COPIED_ALPHA_ABOVE) copiedMask.data[p] = 1;
|
|
5086
|
+
}
|
|
5087
|
+
}
|
|
5088
|
+
return { index, declaration, opaqueMask, copiedMask };
|
|
5089
|
+
});
|
|
5090
|
+
const occluderUnderKeepByPlanPart = new Map<string, Mask>();
|
|
5091
|
+
if (projectRule === 'visible') {
|
|
5092
|
+
for (const { declaration, copiedMask } of occluderEntries) {
|
|
5093
|
+
for (const u of declaration.under) {
|
|
5094
|
+
let m = occluderUnderKeepByPlanPart.get(u);
|
|
5095
|
+
if (m === undefined) {
|
|
5096
|
+
m = newMask(W, H);
|
|
5097
|
+
occluderUnderKeepByPlanPart.set(u, m);
|
|
5098
|
+
}
|
|
5099
|
+
for (let p = 0; p < W * H; p++) if (copiedMask.data[p] === 1) m.data[p] = 1;
|
|
5100
|
+
}
|
|
5101
|
+
}
|
|
5102
|
+
}
|
|
5067
5103
|
// Issue #359: a part's hidden-art layer is the under of a cut that names none — and, with one named, a refusal, since
|
|
5068
5104
|
// reading either would be a guess. Its uses are counted for `hiddenLines`.
|
|
5069
5105
|
const hiddenArt = hiddenArtByPart(plan, input.cuts, { full, head }, frame, input.resolution);
|
|
@@ -5138,16 +5174,31 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
5138
5174
|
const rigLayers = layers.map((l) => layerToRig(l.canvas, frame, run));
|
|
5139
5175
|
const rank = planRanks(layers.map((l) => l.tag), run, sourcePlan);
|
|
5140
5176
|
const keep = layers.map((l, i): Mask | null => {
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5177
|
+
let mask: Mask | null = null;
|
|
5178
|
+
if (input.limbUnderCover === true && [...plan, ...cutLayerPlan].some(([name, ru, tag]) => (limbPlans.has(name) || limbSources.has(name)) && ru === run && tag === l.tag)) {
|
|
5179
|
+
mask = newMask(W, H);
|
|
5180
|
+
const cover = newMask(W, H);
|
|
5181
|
+
for (let p = 0; p < W * H; p++) {
|
|
5182
|
+
if (!rigLayers.some((r, j) => frontOf(j, i, rank) && r.data[p * 4 + 3] > OPAQUE_ALPHA_ABOVE)) continue;
|
|
5183
|
+
cover.data[p] = 1;
|
|
5184
|
+
if (rigLayers[i].data[p * 4 + 3] > OPAQUE_ALPHA_ABOVE) mask.data[p] = 1;
|
|
5185
|
+
}
|
|
5186
|
+
underCover.set(`${run}:${l.tag}`, mask);
|
|
5187
|
+
coverFootprints.set(`${run}:${l.tag}`, cover);
|
|
5188
|
+
}
|
|
5189
|
+
const occParts = [
|
|
5190
|
+
...sourcePlan.filter(([, ru, tag]) => ru === run && tag === l.tag).map(([name]) => name),
|
|
5191
|
+
...extend.filter((e) => e.run === run && e.tag === l.tag).map((e) => e.part),
|
|
5192
|
+
].filter((name) => occluderUnderKeepByPlanPart.has(name));
|
|
5193
|
+
if (occParts.length > 0) {
|
|
5194
|
+
if (mask === null) mask = newMask(W, H);
|
|
5195
|
+
for (const name of occParts) {
|
|
5196
|
+
const occKeep = occluderUnderKeepByPlanPart.get(name)!;
|
|
5197
|
+
for (let p = 0; p < W * H; p++) {
|
|
5198
|
+
if (occKeep.data[p] === 1 && rigLayers[i].data[p * 4 + 3] > OPAQUE_ALPHA_ABOVE) mask.data[p] = 1;
|
|
5199
|
+
}
|
|
5200
|
+
}
|
|
5148
5201
|
}
|
|
5149
|
-
underCover.set(`${run}:${l.tag}`, mask);
|
|
5150
|
-
coverFootprints.set(`${run}:${l.tag}`, cover);
|
|
5151
5202
|
return mask;
|
|
5152
5203
|
});
|
|
5153
5204
|
// Normalize the unedited input to the same rig grid. Cleanup effects on
|
|
@@ -5385,6 +5436,10 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
5385
5436
|
const f = rig.get(`${run2}:${tag2}`) as Raster;
|
|
5386
5437
|
for (let p = 0; p < W * H; p++) if (f.data[p * 4 + 3] >= FRONT_ALPHA) front.data[p] = 1;
|
|
5387
5438
|
}
|
|
5439
|
+
const occKeep = occluderUnderKeepByPlanPart.get(name);
|
|
5440
|
+
if (occKeep !== undefined) {
|
|
5441
|
+
for (let p = 0; p < W * H; p++) if (occKeep.data[p] === 1) front.data[p] = 1;
|
|
5442
|
+
}
|
|
5388
5443
|
merged = mergeCropEntries(r, extras, front, srcr, frame, extend.filter(e => e.part === name), trace, (p, stage) => { writers[p] = AW[stage]; });
|
|
5389
5444
|
}
|
|
5390
5445
|
const { x1, opaque } = measureBox(r);
|
|
@@ -5593,6 +5648,16 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
5593
5648
|
const order = limbOrder(order0, plan, cuts, lim.parts);
|
|
5594
5649
|
const pieceAt = (d: { plan: number } | { cut: number } | { limb: number }): { name: string; b: Built } =>
|
|
5595
5650
|
'plan' in d ? { name: plan[d.plan][0], b: built[d.plan] as Built } : 'cut' in d ? { name: cuts[d.cut].into, b: pieces[d.cut] as Built } : { name: lim.parts[d.limb].part, b: limbPieces[d.limb] as Built };
|
|
5651
|
+
const rootPlanPartOfSlot = (d: DrawSlot): string | null => {
|
|
5652
|
+
if ('plan' in d) return plan[d.plan][0];
|
|
5653
|
+
if ('cut' in d) return cuts[d.cut].from;
|
|
5654
|
+
if ('limb' in d) {
|
|
5655
|
+
const ofName = lim.parts[d.limb].of;
|
|
5656
|
+
const cutParent = cuts.find((c) => c.into === ofName);
|
|
5657
|
+
return cutParent !== undefined ? cutParent.from : ofName;
|
|
5658
|
+
}
|
|
5659
|
+
return null;
|
|
5660
|
+
};
|
|
5596
5661
|
|
|
5597
5662
|
// Issue #588: a set that names one limb side keeps, in each part cut from a layer of more than one island, the island its joints fall on.
|
|
5598
5663
|
// Issue #609: on a layer of one island that also holds a limb the set does not carry, by the nearest segment line.
|
|
@@ -5695,10 +5760,19 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
5695
5760
|
const keptRetake: Array<Mask | null> = order.map(() => null);
|
|
5696
5761
|
const softOcclusion: SoftOcclusionReading[] = [];
|
|
5697
5762
|
const keepInOrder = order.map((d, i): Mask | null => {
|
|
5763
|
+
const rootPart = rootPlanPartOfSlot(d);
|
|
5764
|
+
const occKeep = rootPart === null ? undefined : occluderUnderKeepByPlanPart.get(rootPart);
|
|
5765
|
+
const withOccKeep = (base: Mask | null): Mask | null => {
|
|
5766
|
+
if (occKeep === undefined) return base;
|
|
5767
|
+
const out = newMask(W, H);
|
|
5768
|
+
if (base !== null) out.data.set(base.data);
|
|
5769
|
+
for (let p = 0; p < W * H; p++) if (occKeep.data[p] === 1) out.data[p] = 1;
|
|
5770
|
+
return out;
|
|
5771
|
+
};
|
|
5698
5772
|
const limb = 'limb' in d ? limbKeep[d.limb] : null;
|
|
5699
|
-
if ('patch' in d) return limb;
|
|
5773
|
+
if ('patch' in d) return withOccKeep(limb);
|
|
5700
5774
|
const b = pieceAt(d).b, baseline = valueBaselines.get(b.key);
|
|
5701
|
-
if (baseline === undefined || baseline === null) return limb;
|
|
5775
|
+
if (baseline === undefined || baseline === null) return withOccKeep(limb);
|
|
5702
5776
|
const enabled = sourceKeys.has(b.key);
|
|
5703
5777
|
const mask = enabled ? newMask(W, H) : limb;
|
|
5704
5778
|
if (enabled && limb !== null) mask!.data.set(limb.data);
|
|
@@ -5738,7 +5812,7 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
5738
5812
|
reading.front = [...holders].map(([part, px]) => ({ part, px }));
|
|
5739
5813
|
softOcclusion.push(reading);
|
|
5740
5814
|
}
|
|
5741
|
-
return mask;
|
|
5815
|
+
return withOccKeep(mask);
|
|
5742
5816
|
});
|
|
5743
5817
|
const retakeByName = new Map(order.flatMap((d, i) => 'patch' in d ? [] : [[pieceAt(d).name, keptRetake[i]] as const]));
|
|
5744
5818
|
const patchWriters = patches.map((_, i) => new Int32Array(W * H).fill(patchIds[i]));
|
|
@@ -5898,29 +5972,29 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
5898
5972
|
const visibleFigure = projectRule === 'visible' ? sourceSupportFigure(source, W, H, srcr) : undefined;
|
|
5899
5973
|
const edged = new Map<string, Mask>();
|
|
5900
5974
|
let edgeReading: PaintingEdgeReading | null = null;
|
|
5975
|
+
const onRig = (q: PlacedPart): Raster => {
|
|
5976
|
+
const { image, record } = q;
|
|
5977
|
+
if (image.width === W && image.height === H && record.x === 0 && record.y === 0) return image;
|
|
5978
|
+
const whole = newRaster(W, H);
|
|
5979
|
+
for (let y = 0; y < image.height; y++) {
|
|
5980
|
+
const ry = record.y + y;
|
|
5981
|
+
if (ry < 0 || ry >= H) continue;
|
|
5982
|
+
for (let x = 0; x < image.width; x++) {
|
|
5983
|
+
const rx = record.x + x;
|
|
5984
|
+
if (rx < 0 || rx >= W) continue;
|
|
5985
|
+
const s = (y * image.width + x) * 4;
|
|
5986
|
+
whole.data.set(image.data.subarray(s, s + 4), (ry * W + rx) * 4);
|
|
5987
|
+
}
|
|
5988
|
+
}
|
|
5989
|
+
return whole;
|
|
5990
|
+
};
|
|
5901
5991
|
if (projectRule === 'visible') {
|
|
5902
5992
|
// paintingEdges reads every image as the whole rig canvas. A plan part's image already is one; a patch is its cut,
|
|
5903
5993
|
// placed at record.x / record.y, so it is placed on a canvas here. The step never writes a patch, so a copy is enough.
|
|
5904
|
-
const onRig = (q: PlacedPart): Raster => {
|
|
5905
|
-
const { image, record } = q;
|
|
5906
|
-
if (image.width === W && image.height === H && record.x === 0 && record.y === 0) return image;
|
|
5907
|
-
const whole = newRaster(W, H);
|
|
5908
|
-
for (let y = 0; y < image.height; y++) {
|
|
5909
|
-
const ry = record.y + y;
|
|
5910
|
-
if (ry < 0 || ry >= H) continue;
|
|
5911
|
-
for (let x = 0; x < image.width; x++) {
|
|
5912
|
-
const rx = record.x + x;
|
|
5913
|
-
if (rx < 0 || rx >= W) continue;
|
|
5914
|
-
const s = (y * image.width + x) * 4;
|
|
5915
|
-
whole.data.set(image.data.subarray(s, s + 4), (ry * W + rx) * 4);
|
|
5916
|
-
}
|
|
5917
|
-
}
|
|
5918
|
-
return whole;
|
|
5919
|
-
};
|
|
5920
5994
|
const canvases = stack.map(onRig);
|
|
5921
5995
|
const rawPlan = input.plan.map(([name, run, tag]) => {
|
|
5922
5996
|
const layer = input[run].layers.find(l => l.name === tag)!;
|
|
5923
|
-
return { name, raster: layerToRig(placeLayer(layer, input.resolution), frame, run) };
|
|
5997
|
+
return { name, raster: layerToRig(placeLayer(layer, input.resolution), frame, run), keep: occluderUnderKeepByPlanPart.get(name) ?? null };
|
|
5924
5998
|
});
|
|
5925
5999
|
if ((input.edgeSplits?.length ?? 0) > 0) applyEdgeSplits(input.edgeSplits!, new Map(rawPlan.map(p => [p.name, p.raster])), srcr);
|
|
5926
6000
|
const owner = rawPaintingOwner(rawPlan, W * H);
|
|
@@ -5993,6 +6067,96 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
5993
6067
|
}
|
|
5994
6068
|
return k;
|
|
5995
6069
|
};
|
|
6070
|
+
const stackCanvases = occluderEntries.length === 0 ? [] : stack.map(onRig);
|
|
6071
|
+
const occluderWithSlot = occluderEntries.map((entry) => {
|
|
6072
|
+
let lastUnderIdx = -1;
|
|
6073
|
+
order.forEach((d, idx) => {
|
|
6074
|
+
const root = rootPlanPartOfSlot(d);
|
|
6075
|
+
if (root !== null && entry.declaration.under.includes(root)) lastUnderIdx = idx;
|
|
6076
|
+
});
|
|
6077
|
+
return { ...entry, lastUnderIdx };
|
|
6078
|
+
});
|
|
6079
|
+
const builtOccluderParts: Array<{ index: number; lastUnderIdx: number; canvas: Raster; placed: PlacedPart }> = [];
|
|
6080
|
+
for (const entry of [...occluderWithSlot].filter((e) => e.declaration.part !== undefined).sort((a, b) => b.lastUnderIdx - a.lastUnderIdx || b.index - a.index)) {
|
|
6081
|
+
const partName = entry.declaration.part!;
|
|
6082
|
+
const occCanvas = newRaster(W, H);
|
|
6083
|
+
const occVisible = newMask(W, H);
|
|
6084
|
+
const occProjected = newMask(W, H);
|
|
6085
|
+
for (let p = 0; p < W * H; p++) {
|
|
6086
|
+
if (entry.opaqueMask.data[p] !== 1) continue;
|
|
6087
|
+
let heldInFront = false;
|
|
6088
|
+
for (let j = entry.lastUnderIdx + 1; j < stackCanvases.length; j++) {
|
|
6089
|
+
if (stackCanvases[j].data[p * 4 + 3] > COPIED_ALPHA_ABOVE) {
|
|
6090
|
+
heldInFront = true;
|
|
6091
|
+
break;
|
|
6092
|
+
}
|
|
6093
|
+
}
|
|
6094
|
+
if (!heldInFront) {
|
|
6095
|
+
for (const frontOcc of builtOccluderParts) {
|
|
6096
|
+
if ((frontOcc.lastUnderIdx > entry.lastUnderIdx || (frontOcc.lastUnderIdx === entry.lastUnderIdx && frontOcc.index > entry.index)) && frontOcc.canvas.data[p * 4 + 3] > COPIED_ALPHA_ABOVE) {
|
|
6097
|
+
heldInFront = true;
|
|
6098
|
+
break;
|
|
6099
|
+
}
|
|
6100
|
+
}
|
|
6101
|
+
}
|
|
6102
|
+
if (heldInFront) continue;
|
|
6103
|
+
occCanvas.data.set(srcr.data.subarray(p * 4, p * 4 + 3), p * 4);
|
|
6104
|
+
occCanvas.data[p * 4 + 3] = 255;
|
|
6105
|
+
occVisible.data[p] = 1;
|
|
6106
|
+
occProjected.data[p] = 1;
|
|
6107
|
+
}
|
|
6108
|
+
const { x0, y0, x1, y1, opaque } = measureBox(occCanvas);
|
|
6109
|
+
if (opaque === 0 && emptyTargets?.has(partName)) {
|
|
6110
|
+
builtOccluderParts.push({
|
|
6111
|
+
index: entry.index,
|
|
6112
|
+
lastUnderIdx: entry.lastUnderIdx,
|
|
6113
|
+
canvas: occCanvas,
|
|
6114
|
+
placed: {
|
|
6115
|
+
record: {
|
|
6116
|
+
name: partName, from: `${PAINTING_RUN}:${partName}`, x: 0, y: 0, w: 1, h: 1,
|
|
6117
|
+
opaque_px: 0, visible_px: 0, occluded_px: 0, projected_core_px: 0,
|
|
6118
|
+
source_px_taken: 0, visible_not_projected_px: 0, refused_drift_px: 0,
|
|
6119
|
+
merged_px: 0, seam_override_px: 0,
|
|
6120
|
+
},
|
|
6121
|
+
image: newRaster(1, 1),
|
|
6122
|
+
},
|
|
6123
|
+
});
|
|
6124
|
+
continue;
|
|
6125
|
+
}
|
|
6126
|
+
if (opaque === 0) {
|
|
6127
|
+
empty.push({
|
|
6128
|
+
code: OCCLUDER_EMPTY,
|
|
6129
|
+
object: `config.assemble.occluders[${entry.index}].part (part "${partName}")`,
|
|
6130
|
+
detail: `has 0 rig pixels of occluder "${entry.declaration.image}" (alpha > ${OPAQUE_ALPHA_ABOVE}) after excluding the rest support (alpha > ${COPIED_ALPHA_ABOVE}) of parts drawn in front of it; omit config.assemble.occluders[${entry.index}].part when front parts already hold the entire occluder at rest`,
|
|
6131
|
+
});
|
|
6132
|
+
continue;
|
|
6133
|
+
}
|
|
6134
|
+
const vc = visibilityCounts(`part "${partName}" (${PAINTING_RUN}:${partName})`, occCanvas, occVisible, occProjected);
|
|
6135
|
+
const record: PartRecord = {
|
|
6136
|
+
name: partName,
|
|
6137
|
+
from: `${PAINTING_RUN}:${partName}`,
|
|
6138
|
+
x: x0,
|
|
6139
|
+
y: y0,
|
|
6140
|
+
w: x1 - x0 + 1,
|
|
6141
|
+
h: y1 - y0 + 1,
|
|
6142
|
+
opaque_px: opaque,
|
|
6143
|
+
visible_px: vc.visible_px,
|
|
6144
|
+
occluded_px: vc.occluded_px,
|
|
6145
|
+
projected_core_px: opaque,
|
|
6146
|
+
source_px_taken: opaque,
|
|
6147
|
+
visible_not_projected_px: vc.visible_not_projected_px,
|
|
6148
|
+
refused_drift_px: 0,
|
|
6149
|
+
merged_px: 0,
|
|
6150
|
+
seam_override_px: 0,
|
|
6151
|
+
};
|
|
6152
|
+
builtOccluderParts.push({
|
|
6153
|
+
index: entry.index,
|
|
6154
|
+
lastUnderIdx: entry.lastUnderIdx,
|
|
6155
|
+
canvas: occCanvas,
|
|
6156
|
+
placed: { record, image: crop(occCanvas, x0, y0, record.w, record.h) },
|
|
6157
|
+
});
|
|
6158
|
+
}
|
|
6159
|
+
builtOccluderParts.sort((a, b) => a.lastUnderIdx - b.lastUnderIdx || a.index - b.index);
|
|
5996
6160
|
pieceList.forEach(({ name, b, pushed: pushedHere, at, cutFrom, limb, set }) => {
|
|
5997
6161
|
const { key, r, st, extendKeys, trace, merged, region } = b;
|
|
5998
6162
|
// A pixel the merge wrote is judged in the extend layer's run, every other
|
|
@@ -6002,6 +6166,7 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
6002
6166
|
// is growRim's, counted in merged_px, and is not projection.
|
|
6003
6167
|
const visible = newMask(W, H);
|
|
6004
6168
|
const projected = newMask(W, H);
|
|
6169
|
+
const slotIdx = builtOccluderParts.length === 0 ? -1 : order.findIndex((d) => !('patch' in d) && pieceAt(d).name === name);
|
|
6005
6170
|
for (let p = 0; p < W * H; p++) {
|
|
6006
6171
|
const e = trace.from[p];
|
|
6007
6172
|
const own = e < 0 ? st : (stats.get(extendKeys[e]) as ProjectionStats);
|
|
@@ -6009,6 +6174,15 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
6009
6174
|
if (r.data[p * 4 + 3] > OPAQUE_ALPHA_ABOVE && own.clear.data[p] === 1 && (region === null || region.data[p] === 1)) visible.data[p] = 1;
|
|
6010
6175
|
if (paintingGains.get(name)?.data[p] === 1) visible.data[p] = 1;
|
|
6011
6176
|
if (edged.get(name)?.data[p] !== 1 && paintingGains.get(name)?.data[p] !== 1 && retakeByName.get(name)?.data[p] !== 1 && yields.get(name)?.mask.data[p] !== 1 && trace.ring.data[p] === 0 && own.takenMask.data[p] === 1 && (region === null || region.data[p] === 1)) projected.data[p] = 1;
|
|
6177
|
+
if (slotIdx >= 0) {
|
|
6178
|
+
for (const occPart of builtOccluderParts) {
|
|
6179
|
+
if (occPart.lastUnderIdx >= slotIdx && occPart.canvas.data[p * 4 + 3] >= CORE_ALPHA) {
|
|
6180
|
+
visible.data[p] = 0;
|
|
6181
|
+
projected.data[p] = 0;
|
|
6182
|
+
break;
|
|
6183
|
+
}
|
|
6184
|
+
}
|
|
6185
|
+
}
|
|
6012
6186
|
}
|
|
6013
6187
|
const { x0, y0, x1, y1, opaque } = measureBox(r);
|
|
6014
6188
|
if (opaque === 0 && emptyTargets?.has(name)) {
|
|
@@ -6094,6 +6268,41 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
6094
6268
|
});
|
|
6095
6269
|
refuseIfAny(empty);
|
|
6096
6270
|
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);
|
|
6271
|
+
let spliceOffset = 0;
|
|
6272
|
+
for (const occPart of builtOccluderParts) {
|
|
6273
|
+
const insertAt = occPart.lastUnderIdx + 1 + spliceOffset;
|
|
6274
|
+
placed.splice(insertAt, 0, occPart.placed);
|
|
6275
|
+
keepInOrder.splice(insertAt, 0, null);
|
|
6276
|
+
writersInOrder.splice(insertAt, 0, new Int32Array(W * H).fill(AW.sourceProjection));
|
|
6277
|
+
spliceOffset++;
|
|
6278
|
+
}
|
|
6279
|
+
const occluderUnheldWarnings: string[] = [];
|
|
6280
|
+
if (beforeTake === null && occluderWithSlot.some((e) => e.declaration.part === undefined)) {
|
|
6281
|
+
const placedCanvases = placed.map(onRig);
|
|
6282
|
+
for (const entry of occluderWithSlot) {
|
|
6283
|
+
if (entry.declaration.part !== undefined) continue;
|
|
6284
|
+
const frontStart = entry.lastUnderIdx + 1 + builtOccluderParts.filter((o) => o.lastUnderIdx < entry.lastUnderIdx || (o.lastUnderIdx === entry.lastUnderIdx && o.index < entry.index)).length;
|
|
6285
|
+
let unheldPx = 0;
|
|
6286
|
+
let firstP = -1;
|
|
6287
|
+
for (let p = 0; p < W * H; p++) {
|
|
6288
|
+
if (entry.opaqueMask.data[p] !== 1) continue;
|
|
6289
|
+
let held = false;
|
|
6290
|
+
for (let j = frontStart; j < placedCanvases.length; j++) {
|
|
6291
|
+
if (placedCanvases[j].data[p * 4 + 3] >= CORE_ALPHA) {
|
|
6292
|
+
held = true;
|
|
6293
|
+
break;
|
|
6294
|
+
}
|
|
6295
|
+
}
|
|
6296
|
+
if (!held) {
|
|
6297
|
+
if (firstP < 0) firstP = p;
|
|
6298
|
+
unheldPx++;
|
|
6299
|
+
}
|
|
6300
|
+
}
|
|
6301
|
+
if (unheldPx > 0) {
|
|
6302
|
+
occluderUnheldWarnings.push(occluderUnheldWarning(entry.index, entry.declaration.image, entry.declaration.under, unheldPx, [firstP % W, Math.floor(firstP / W)]));
|
|
6303
|
+
}
|
|
6304
|
+
}
|
|
6305
|
+
}
|
|
6097
6306
|
const artFiles = new Map<string, string>(); for (const p of placed) { const k = foldName(`${p.record.name}.png`), prev = artFiles.get(k); if (prev !== undefined) refuseIfAny([{ code: 'DEPTH_SHEET_UNAMBIGUOUS', object: `${p.record.name}.png`, detail: `part "${prev}" ("${prev}.png") and part "${p.record.name}" ("${p.record.name}.png") collides with a part artwork filename; choose noncolliding part names before sheet emission` }]); artFiles.set(k, p.record.name); }
|
|
6098
6307
|
for (const p of placed) if (p.record.depth !== undefined && artFiles.has(foldName(p.record.depth.image))) refuseIfAny([{ code: 'DEPTH_SHEET_UNAMBIGUOUS', object: p.record.depth.image, detail: `part "${p.record.name}" sheet "${p.record.depth.image}" and part "${artFiles.get(foldName(p.record.depth.image))}" ("${artFiles.get(foldName(p.record.depth.image))}.png") collides with a part artwork filename; choose noncolliding part names before sheet emission` }]);
|
|
6099
6308
|
|
|
@@ -6217,6 +6426,7 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
6217
6426
|
holeKinds: kinds,
|
|
6218
6427
|
drift,
|
|
6219
6428
|
...(input.yieldRefused === true ? { yieldReadings: [...yields.values()].map(q => q.reading) } : {}),
|
|
6429
|
+
...(occluderUnheldWarnings.length === 0 ? {} : { occluderUnheldWarnings }),
|
|
6220
6430
|
hidden: [...hiddenUses].map(([layer, readBy]) => ({ layer, readBy })),
|
|
6221
6431
|
seamRule,
|
|
6222
6432
|
projectRule,
|
|
@@ -6794,6 +7004,9 @@ export function headGarmentWarning(w: HeadGarmentOverlap): string {
|
|
|
6794
7004
|
|
|
6795
7005
|
export function proposePlan(full0: LayerSet, head0: LayerSet, g: Geometry, minPx = PROPOSE_MIN_PX): PlanProposal {
|
|
6796
7006
|
const frame = checkGeometry(g, { full: full0, head: head0 });
|
|
7007
|
+
if (g.occluderDeclarations !== undefined && g.occluderDeclarations.length > 0) {
|
|
7008
|
+
refuseIfAny(occluderDrawCycleProblems(g.occluderDeclarations));
|
|
7009
|
+
}
|
|
6797
7010
|
// Issue #366: one run's file, padded to the resolution square as the stage pads it.
|
|
6798
7011
|
const fullPadded = g.single === true ? padSingleRun(full0, frame, g.resolution) : full0;
|
|
6799
7012
|
// Issue #439: when seethrough.arm_split is declared, split the full run's overlapping handwear into handwear-r and handwear-l.
|
|
@@ -6901,6 +7114,7 @@ export function proposePlan(full0: LayerSet, head0: LayerSet, g: Geometry, minPx
|
|
|
6901
7114
|
}
|
|
6902
7115
|
}
|
|
6903
7116
|
for (const t of heads) plan.push([aliasOf(t), headRun(t), t]);
|
|
7117
|
+
orderPlanForOccluders(plan, g.occluderDeclarations);
|
|
6904
7118
|
for (const [part, run, tag] of plan) {
|
|
6905
7119
|
if (readAuthorTag(tag) !== null) notes.push(`${tag}: ${AUTHOR_NO_ROLE}; proposed as "${part}" from the ${run} run, at its place in that run's draw order`);
|
|
6906
7120
|
}
|
|
@@ -7193,19 +7407,20 @@ export function stageFields(
|
|
|
7193
7407
|
export function proposeFields(
|
|
7194
7408
|
cfg: EarlyConfig,
|
|
7195
7409
|
single: { w: number; h: number } | null = null,
|
|
7196
|
-
): { resolution: number; headBox: [number, number, number, number]; rigScale: number; single?: boolean; armSplit?: ArmSplit; keySkeleton?: ControlSkeleton; headFaceUnderfill?: boolean } {
|
|
7410
|
+
): { resolution: number; headBox: [number, number, number, number]; rigScale: number; single?: boolean; armSplit?: ArmSplit; keySkeleton?: ControlSkeleton; headFaceUnderfill?: boolean; occluderDeclarations?: readonly OccluderDeclaration[] } {
|
|
7197
7411
|
const armSplit = cfg.seethrough.arm_split === undefined ? {} : { armSplit: cfg.seethrough.arm_split };
|
|
7198
7412
|
const keySkeleton = controlSkeletonOf(cfg);
|
|
7199
7413
|
const skelField = keySkeleton === undefined ? {} : { keySkeleton };
|
|
7200
7414
|
const underfillField = cfg.assemble.head_face_underfill === undefined ? {} : { headFaceUnderfill: cfg.assemble.head_face_underfill };
|
|
7415
|
+
const occludersField = cfg.assemble.occluders === undefined ? {} : { occluderDeclarations: cfg.assemble.occluders };
|
|
7201
7416
|
if (single !== null) {
|
|
7202
7417
|
refuseIfAny(singleRunHeadBoxProblems(cfg.seethrough));
|
|
7203
|
-
return { resolution: cfg.seethrough.resolution, headBox: singleRunHeadBox(single.w, single.h, cfg.seethrough.resolution), rigScale: cfg.assemble.rig_scale, single: true, ...armSplit, ...skelField, ...underfillField };
|
|
7418
|
+
return { resolution: cfg.seethrough.resolution, headBox: singleRunHeadBox(single.w, single.h, cfg.seethrough.resolution), rigScale: cfg.assemble.rig_scale, single: true, ...armSplit, ...skelField, ...underfillField, ...occludersField };
|
|
7204
7419
|
}
|
|
7205
7420
|
if (cfg.seethrough.head_box === undefined) {
|
|
7206
7421
|
refuseIfAny([{ code: 'ASSEMBLE_FIELD_PRESENT', object: 'config.seethrough.head_box', detail: 'is absent; the plan is proposed from both runs, and the head run cannot be placed on the painting without the box it was cropped from — run `propose --head-box` first' }]);
|
|
7207
7422
|
}
|
|
7208
|
-
return { resolution: cfg.seethrough.resolution, headBox: cfg.seethrough.head_box as [number, number, number, number], rigScale: cfg.assemble.rig_scale, ...armSplit, ...skelField, ...underfillField };
|
|
7423
|
+
return { resolution: cfg.seethrough.resolution, headBox: cfg.seethrough.head_box as [number, number, number, number], rigScale: cfg.assemble.rig_scale, ...armSplit, ...skelField, ...underfillField, ...occludersField };
|
|
7209
7424
|
}
|
|
7210
7425
|
|
|
7211
7426
|
/**
|
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, readOccluderInputs } 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';
|
|
@@ -387,12 +387,17 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
387
387
|
const declaredFigure = figureSupport === undefined ? undefined : { width: Math.trunc(src.width * fields.rigScale), height: Math.trunc(src.height * fields.rigScale), data: figureSupport };
|
|
388
388
|
const under = readUnders(input.config, fields.cuts);
|
|
389
389
|
const caps = fields.limbs === undefined ? undefined : readCaps(input.config, fields.limbs);
|
|
390
|
+
const occluders = cfg.assemble.occluders === undefined ? undefined : readOccluderInputs(cfg.assemble.occluders, input.config, src);
|
|
390
391
|
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
|
-
...((cfg.assemble.take ?? []).some(t => '
|
|
392
|
+
...((cfg.assemble.take ?? []).some(t => 'seed' in t) ? { regionTake: { full: takenRuns.full, head: takenRuns.head, targets: (cfg.assemble.take ?? []).flatMap(t => 'seed' in t ? [t.part] : []) } } : {}), ...(caps === undefined ? {} : { caps }), ...(occluders === undefined ? {} : { occluders }), seamRule: seam, projectRule: project });
|
|
392
393
|
|
|
393
|
-
// Issue #1230: copied occluder colour in a declared occluder's under parts
|
|
394
|
+
// Issue #1230 / #1237 / #1246: copied occluder colour in a declared occluder's under parts and unheld occluder px are named, never kept silent;
|
|
395
|
+
// when `plate` is declared on an occluder entry, its receipt is verified and bound to occluder, painting and base run.
|
|
394
396
|
if (cfg.assemble.occluders !== undefined) {
|
|
395
397
|
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);
|
|
398
|
+
for (const line of result.occluderUnheldWarnings ?? []) log(line);
|
|
399
|
+
const boundPlates = bindOccluderPlates({ occluders: cfg.assemble.occluders, configPath: input.config, sourcePath: input.source, fullPath: input.full });
|
|
400
|
+
if (boundPlates.length > 0) result.parts.occluder_plates = boundPlates;
|
|
396
401
|
}
|
|
397
402
|
|
|
398
403
|
const sourceCoverSets = [sourceCoverSet(result, null, input.source, read)];
|