@rig-c/parts 2.33.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 +45 -1
- package/docs/STABILITY.md +3 -3
- package/package.json +1 -1
- package/src/assemble.ts +247 -32
- package/src/build.ts +5 -3
- package/src/config.ts +77 -19
- package/src/occluders.ts +57 -1
- package/src/occluderstage.ts +19 -8
- package/src/paintingowner.ts +7 -4
- package/src/parts.ts +5 -0
- package/src/takelayers.ts +114 -7
- package/src/takeregion.ts +16 -3
- package/src/takesource.ts +20 -1
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 { bindOccluderPlates, 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,13 +387,15 @@ 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 / #1237: 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;
|
|
394
395
|
// when `plate` is declared on an occluder entry, its receipt is verified and bound to occluder, painting and base run.
|
|
395
396
|
if (cfg.assemble.occluders !== undefined) {
|
|
396
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);
|
|
397
399
|
const boundPlates = bindOccluderPlates({ occluders: cfg.assemble.occluders, configPath: input.config, sourcePath: input.source, fullPath: input.full });
|
|
398
400
|
if (boundPlates.length > 0) result.parts.occluder_plates = boundPlates;
|
|
399
401
|
}
|
package/src/config.ts
CHANGED
|
@@ -1813,7 +1813,7 @@ function parseEarlyConfigFrom(raw: Json, door: EarlyDoor, base: string | null, p
|
|
|
1813
1813
|
checkOccluders(c, a, null, base);
|
|
1814
1814
|
if ('extend_painting' in a) checkPaintingExtensions(c, a.extend_painting);
|
|
1815
1815
|
if ('edge_splits' in a) checkEdgeSplits(c, a.edge_splits, Array.isArray(a.plan) ? new Set(a.plan.filter((r): r is Json[] => Array.isArray(r) && typeof r[0] === 'string').map(r => r[0] as string)) : null);
|
|
1816
|
-
if ('take' in a) checkTakeLayers(c, a.take);
|
|
1816
|
+
if ('take' in a) checkTakeLayers(c, a.take, null, a);
|
|
1817
1817
|
if ('editor_receipts' in a) checkEditorReceipts(c, a.editor_receipts);
|
|
1818
1818
|
if ('yield_refused' in a && typeof a.yield_refused !== 'boolean') {
|
|
1819
1819
|
c.fail('CONFIG_FIELD_TYPE', 'config.assemble.yield_refused', `is ${show(a.yield_refused)}; true or false is required`);
|
|
@@ -2572,18 +2572,19 @@ function checkRequiredHiddenExtent(c: Check, a: Record<string, Json>, names: rea
|
|
|
2572
2572
|
}
|
|
2573
2573
|
|
|
2574
2574
|
/**
|
|
2575
|
-
* Issue #1230 / #1241: `config.assemble.occluders`, `[{image, sha256, under, over?, rgb_within}]`.
|
|
2576
|
-
*
|
|
2577
|
-
* directory (`checkOccluderFiles`).
|
|
2575
|
+
* Issue #1230 / #1241 / #1246: `config.assemble.occluders`, `[{image, sha256, under, over?, rgb_within, plate?, part?}]`.
|
|
2576
|
+
* Shape at every door; `under`, `over` and `part` resolved against the plan where the door reads it; the file and its
|
|
2577
|
+
* sha256 where the door knows the config's directory (`checkOccluderFiles`). Returns the declared `part` names, in order.
|
|
2578
2578
|
*/
|
|
2579
|
-
function checkOccluders(c: Check, a: Record<string, Json>, names: readonly string[] | null, base: string | null):
|
|
2580
|
-
if (!('occluders' in a)) return;
|
|
2579
|
+
function checkOccluders(c: Check, a: Record<string, Json>, names: readonly string[] | null, base: string | null): string[] {
|
|
2580
|
+
if (!('occluders' in a)) return [];
|
|
2581
2581
|
const at = 'config.assemble.occluders';
|
|
2582
|
-
if (!c.array(at, a.occluders, false)) return;
|
|
2582
|
+
if (!c.array(at, a.occluders, false)) return [];
|
|
2583
2583
|
const declarations: OccluderDeclaration[] = [];
|
|
2584
|
+
const partNames: string[] = [];
|
|
2584
2585
|
(a.occluders as Json[]).forEach((value, i) => {
|
|
2585
2586
|
const p = `${at}[${i}]`;
|
|
2586
|
-
const row = c.object(p, value, ['image', 'sha256', 'under', 'rgb_within'], ['over', 'plate']);
|
|
2587
|
+
const row = c.object(p, value, ['image', 'sha256', 'under', 'rgb_within'], ['over', 'plate', 'part']);
|
|
2587
2588
|
if (row === null) return;
|
|
2588
2589
|
const imageOk = c.string(`${p}.image`, row.image);
|
|
2589
2590
|
const shaOk = typeof row.sha256 === 'string' && SHA256_PATTERN.test(row.sha256);
|
|
@@ -2598,12 +2599,27 @@ function checkOccluders(c: Check, a: Record<string, Json>, names: readonly strin
|
|
|
2598
2599
|
const rgbOk = typeof row.rgb_within === 'number' && Number.isInteger(row.rgb_within) && row.rgb_within >= 0 && row.rgb_within <= 255;
|
|
2599
2600
|
if (!rgbOk) c.fail('CONFIG_FIELD_TYPE', `${p}.rgb_within`, `is ${show(row.rgb_within)}; an integer from 0 to 255 is required`);
|
|
2600
2601
|
const plateOk = !('plate' in row) || c.string(`${p}.plate`, row.plate);
|
|
2601
|
-
|
|
2602
|
-
|
|
2602
|
+
let partOk = true;
|
|
2603
|
+
let partName: string | undefined;
|
|
2604
|
+
if ('part' in row) {
|
|
2605
|
+
partOk = c.string(`${p}.part`, row.part);
|
|
2606
|
+
if (partOk) {
|
|
2607
|
+
partName = row.part as string;
|
|
2608
|
+
if (!partNameOk(partName)) {
|
|
2609
|
+
c.fail('CONFIG_PART_NAME', `${p}.part`, `names the part ${show(partName)}; a part name is a file name, so it may not be empty, start with "." or hold a slash`);
|
|
2610
|
+
partOk = false;
|
|
2611
|
+
} else {
|
|
2612
|
+
partNames.push(partName);
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
if (imageOk && shaOk && underOk && overOk && rgbOk && plateOk && partOk) {
|
|
2617
|
+
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 } : {}), ...(partName !== undefined ? { part: partName } : {}) });
|
|
2603
2618
|
}
|
|
2604
2619
|
});
|
|
2605
2620
|
c.problems.push(...occluderNameProblems(declarations, names));
|
|
2606
2621
|
if (base !== null) c.problems.push(...occluderFileProblems(declarations, base));
|
|
2622
|
+
return partNames;
|
|
2607
2623
|
}
|
|
2608
2624
|
|
|
2609
2625
|
/** The occluder files, at the doors that know the config's directory but read the plan elsewhere. */
|
|
@@ -2630,16 +2646,19 @@ function checkKeepUnderOccluders(c: Check, a: Record<string, Json>, plan: readon
|
|
|
2630
2646
|
});
|
|
2631
2647
|
}
|
|
2632
2648
|
|
|
2633
|
-
function checkTakeLayers(c: Check, value: Json, plan: string[] | null = null): void {
|
|
2649
|
+
function checkTakeLayers(c: Check, value: Json, plan: string[] | null = null, assemble?: Record<string, Json>): void {
|
|
2634
2650
|
const at = 'config.assemble.take';
|
|
2635
2651
|
if (!c.array(at, value, false)) return;
|
|
2636
2652
|
const seen = new Set<string>();
|
|
2637
2653
|
(value as Json[]).forEach((v, i) => {
|
|
2638
2654
|
const p = `${at}[${i}]`;
|
|
2639
|
-
const
|
|
2640
|
-
const
|
|
2641
|
-
|
|
2642
|
-
|
|
2655
|
+
const split = isPlainObject(v) && ('occluder' in v || ('tag' in v && !('tags' in v)));
|
|
2656
|
+
const region = !split && isPlainObject(v) && ('part' in v || 'seed' in v);
|
|
2657
|
+
const o = split
|
|
2658
|
+
? c.object(p, v, ['run', 'run_dir', 'st_input', 'part', 'tag', 'occluder'], ['crop'])
|
|
2659
|
+
: region
|
|
2660
|
+
? c.object(p, v, ['run', 'run_dir', 'st_input', 'part', 'seed'], ['reference', 'crop'])
|
|
2661
|
+
: c.object(p, v, ['run', 'run_dir', 'st_input', 'tags'], ['crop']);
|
|
2643
2662
|
if (o === null) return;
|
|
2644
2663
|
if (o.run !== 'full' && o.run !== 'head') c.fail('CONFIG_FIELD_TYPE', p + '.run', '"full" or "head" is required');
|
|
2645
2664
|
for (const k of ['run_dir', 'st_input']) c.string(`${p}.${k}`, o[k]);
|
|
@@ -2651,6 +2670,44 @@ function checkTakeLayers(c: Check, value: Json, plan: string[] | null = null): v
|
|
|
2651
2670
|
if (crop.resample !== 'bilinear') c.fail('CONFIG_FIELD_TYPE', `${p}.crop.resample`, '"bilinear" is required explicitly');
|
|
2652
2671
|
}
|
|
2653
2672
|
}
|
|
2673
|
+
if (split) {
|
|
2674
|
+
const partName = c.string(`${p}.part`, o.part) ? o.part : null;
|
|
2675
|
+
if (partName !== null && plan !== null && !plan.includes(partName)) {
|
|
2676
|
+
c.fail('CONFIG_NAME_RESOLVES', `${p}.part`, `names "${partName}"; a part named in assemble.plan is required`);
|
|
2677
|
+
}
|
|
2678
|
+
const reading = typeof o.tag === 'string' ? readLayerTag(o.tag) : null;
|
|
2679
|
+
if (reading === null || reading.group === 'author') {
|
|
2680
|
+
c.fail('CONFIG_TAG_KNOWN', `${p}.tag`, 'a See-through tag is required; author layers do not carry a See-through role');
|
|
2681
|
+
} else if (partName !== null && plan !== null && plan.includes(partName) && Array.isArray(assemble?.plan)) {
|
|
2682
|
+
const row = assemble.plan.find((r): r is Json[] => Array.isArray(r) && r[0] === partName);
|
|
2683
|
+
if (row !== undefined && (row[1] !== o.run || row[2] !== o.tag)) {
|
|
2684
|
+
c.fail('CONFIG_NAME_RESOLVES', `${p}.tag`, `is "${String(o.run)}:${String(o.tag)}" for part "${partName}"; assemble.plan declares ["${partName}", "${String(row[1])}", "${String(row[2])}"]`);
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
const tagKey = `${String(o.run)}:${String(o.tag)}`;
|
|
2688
|
+
const partKey = `${String(o.run)}:part:${String(o.part)}`;
|
|
2689
|
+
if (seen.has(tagKey) || seen.has(partKey)) {
|
|
2690
|
+
c.fail('CONFIG_TAKE_UNIQUE', `${p}.tag`, `names ${tagKey} again; one donor per target tag is required`);
|
|
2691
|
+
}
|
|
2692
|
+
seen.add(tagKey);
|
|
2693
|
+
seen.add(partKey);
|
|
2694
|
+
const occOk = c.int(`${p}.occluder`, o.occluder, 0);
|
|
2695
|
+
if (occOk && partName !== null && assemble !== undefined) {
|
|
2696
|
+
const occluders = Array.isArray(assemble.occluders) ? assemble.occluders : [];
|
|
2697
|
+
const idx = o.occluder as number;
|
|
2698
|
+
const entry = occluders[idx];
|
|
2699
|
+
const under = isPlainObject(entry) && Array.isArray(entry.under) ? entry.under : null;
|
|
2700
|
+
const over = isPlainObject(entry) && Array.isArray(entry.over) ? entry.over : [];
|
|
2701
|
+
if (!isPlainObject(entry) || under === null) {
|
|
2702
|
+
c.fail('ASSEMBLE_TAKE_SPLIT_OCCLUDER', `${p}.occluder`, `index ${idx} does not exist in config.assemble.occluders (${occluders.length} declared); a valid occluder index is required`);
|
|
2703
|
+
} else if (over.includes(partName)) {
|
|
2704
|
+
c.fail('ASSEMBLE_TAKE_SPLIT_OCCLUDER', `${p}.part`, `names "${partName}", which is in config.assemble.occluders[${idx}].over; a split take is for a part under the occluder, not in its over`);
|
|
2705
|
+
} else if (!under.includes(partName)) {
|
|
2706
|
+
c.fail('ASSEMBLE_TAKE_SPLIT_OCCLUDER', `${p}.part`, `names "${partName}", which is not in config.assemble.occluders[${idx}].under; a part declared under that occluder is required`);
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2709
|
+
return;
|
|
2710
|
+
}
|
|
2654
2711
|
if (region) {
|
|
2655
2712
|
if (o.reference !== undefined) {
|
|
2656
2713
|
const r = c.object(`${p}.reference`, o.reference, ['sha256'], ['source', 'painting']);
|
|
@@ -2776,10 +2833,10 @@ function checkAssemble(c: Check, v: Json, door: 'assemble' | 'full'): { parts: s
|
|
|
2776
2833
|
}
|
|
2777
2834
|
checkKeepUnderOccluders(c, a, parts);
|
|
2778
2835
|
checkRequiredHiddenExtent(c, a, parts);
|
|
2779
|
-
checkOccluders(c, a, parts, null);
|
|
2836
|
+
const occluderParts = checkOccluders(c, a, parts, null);
|
|
2780
2837
|
if ('extend_painting' in a) checkPaintingExtensions(c, a.extend_painting);
|
|
2781
2838
|
if ('edge_splits' in a) checkEdgeSplits(c, a.edge_splits, new Set(parts));
|
|
2782
|
-
if ('take' in a) checkTakeLayers(c, a.take, parts);
|
|
2839
|
+
if ('take' in a) checkTakeLayers(c, a.take, parts, a);
|
|
2783
2840
|
if ('editor_receipts' in a) checkEditorReceipts(c, a.editor_receipts);
|
|
2784
2841
|
if ('extend_below_crop' in a && c.array(`${p}.extend_below_crop`, a.extend_below_crop, false)) {
|
|
2785
2842
|
(a.extend_below_crop as Json[]).forEach((entry, i) => {
|
|
@@ -2801,7 +2858,7 @@ function checkAssemble(c: Check, v: Json, door: 'assemble' | 'full'): { parts: s
|
|
|
2801
2858
|
}
|
|
2802
2859
|
});
|
|
2803
2860
|
}
|
|
2804
|
-
const patches = 'patches' in a ? checkPatches(c, a.patches, parts) : [];
|
|
2861
|
+
const patches = [...('patches' in a ? checkPatches(c, a.patches, parts, occluderParts) : []), ...occluderParts];
|
|
2805
2862
|
const cuts = 'cuts' in a ? checkCuts(c, a.cuts, parts, patches) : [];
|
|
2806
2863
|
return { parts, patches, cuts };
|
|
2807
2864
|
}
|
|
@@ -3129,7 +3186,7 @@ function checkAlternates(
|
|
|
3129
3186
|
* (`ASSEMBLE_PATCH_BOX_INSIDE`, `ASSEMBLE_PATCH_OPAQUE`). Returns the patch
|
|
3130
3187
|
* names, in order.
|
|
3131
3188
|
*/
|
|
3132
|
-
function checkPatches(c: Check, v: Json, plan: string[]): string[] {
|
|
3189
|
+
function checkPatches(c: Check, v: Json, plan: string[], occluderParts: readonly string[] = []): string[] {
|
|
3133
3190
|
const p = 'config.assemble.patches';
|
|
3134
3191
|
const names: string[] = [];
|
|
3135
3192
|
if (!c.array(p, v, false)) return names;
|
|
@@ -3150,6 +3207,7 @@ function checkPatches(c: Check, v: Json, plan: string[]): string[] {
|
|
|
3150
3207
|
const name = e.name;
|
|
3151
3208
|
if (!partNameOk(name)) c.fail('CONFIG_PART_NAME', `${at}.name`, `names the part ${show(name)}; a part name is a file name, so it may not be empty, start with "." or hold a slash`);
|
|
3152
3209
|
if (plan.includes(name)) c.fail('CONFIG_PART_UNIQUE', `${at}.name`, `names the part "${name}", which assemble.plan[${plan.indexOf(name)}] already makes; a patch is a part of its own`);
|
|
3210
|
+
else if (occluderParts.includes(name)) c.fail('CONFIG_PART_UNIQUE', `${at}.name`, `names the part "${name}", which assemble.occluders already makes; a patch is a part of its own`);
|
|
3153
3211
|
else if (seen.has(name)) c.fail('CONFIG_PART_UNIQUE', `${at}.name`, `names the part "${name}" again (first at patches[${seen.get(name)}])`);
|
|
3154
3212
|
else seen.set(name, i);
|
|
3155
3213
|
names.push(name);
|
package/src/occluders.ts
CHANGED
|
@@ -34,6 +34,8 @@ export interface OccluderDeclaration {
|
|
|
34
34
|
rgb_within: number;
|
|
35
35
|
/** An optional comfy plate --mode occluder output directory, relative to the config's directory (issue #1237). */
|
|
36
36
|
plate?: string;
|
|
37
|
+
/** An optional part name (`painting:<part>`) emitted from the painting for occluder pixels not held at rest by front parts (issue #1246). */
|
|
38
|
+
part?: string;
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
export const OCCLUDER_COLOUR_COPIED = 'ASSEMBLE_OCCLUDER_COLOUR_COPIED';
|
|
@@ -43,6 +45,8 @@ export const OCCLUDER_OVER_TAKEN = 'ASSEMBLE_OCCLUDER_OVER_TAKEN';
|
|
|
43
45
|
export const OCCLUDER_PLATE_OCCLUDER = 'ASSEMBLE_OCCLUDER_PLATE_OCCLUDER';
|
|
44
46
|
export const OCCLUDER_PLATE_PAINTING = 'ASSEMBLE_OCCLUDER_PLATE_PAINTING';
|
|
45
47
|
export const OCCLUDER_PLATE_BASE_RUN = 'ASSEMBLE_OCCLUDER_PLATE_BASE_RUN';
|
|
48
|
+
export const OCCLUDER_EMPTY = 'ASSEMBLE_OCCLUDER_EMPTY';
|
|
49
|
+
export const OCCLUDER_UNHELD = 'ASSEMBLE_OCCLUDER_UNHELD';
|
|
46
50
|
/** An `under` layer pixel counts at alpha above this: the half-opaque floor `deriveTakenRegion` reads. */
|
|
47
51
|
export const COPIED_ALPHA_ABOVE = 128;
|
|
48
52
|
|
|
@@ -183,9 +187,10 @@ export function occluderOverTakenProblems(
|
|
|
183
187
|
return problems;
|
|
184
188
|
}
|
|
185
189
|
|
|
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). */
|
|
190
|
+
/** Every `under` and `over` entry names a plan part (`CONFIG_NAME_RESOLVES`, with `over` entries distinct per occluder, `CONFIG_PART_UNIQUE`), and any declared `part` is distinct from plan parts and other occluder parts (`CONFIG_PART_UNIQUE`); `names` null skips the plan-membership check (a door without the plan). */
|
|
187
191
|
export function occluderNameProblems(declarations: readonly OccluderDeclaration[], names: readonly string[] | null): Problem[] {
|
|
188
192
|
const problems: Problem[] = [];
|
|
193
|
+
const seenParts = new Map<string, number>();
|
|
189
194
|
declarations.forEach((d, i) => {
|
|
190
195
|
if (d.over !== undefined) {
|
|
191
196
|
const seen = new Set<string>();
|
|
@@ -194,6 +199,17 @@ export function occluderNameProblems(declarations: readonly OccluderDeclaration[
|
|
|
194
199
|
seen.add(name);
|
|
195
200
|
});
|
|
196
201
|
}
|
|
202
|
+
if (d.part !== undefined && d.part !== '') {
|
|
203
|
+
if (names !== null && names.includes(d.part)) {
|
|
204
|
+
problems.push({ code: 'CONFIG_PART_UNIQUE', object: `${AT}[${i}].part`, detail: `names the part "${d.part}", which assemble.plan[${names.indexOf(d.part)}] already makes; an occluder part is a part of its own` });
|
|
205
|
+
} else if (names === null && (d.under.includes(d.part) || (d.over?.includes(d.part) ?? false))) {
|
|
206
|
+
problems.push({ code: 'CONFIG_PART_UNIQUE', object: `${AT}[${i}].part`, detail: `names the part "${d.part}", which occluders[${i}] also names in under/over; an occluder part is a part of its own` });
|
|
207
|
+
} else if (seenParts.has(d.part)) {
|
|
208
|
+
problems.push({ code: 'CONFIG_PART_UNIQUE', object: `${AT}[${i}].part`, detail: `names the part "${d.part}" again (first at occluders[${seenParts.get(d.part)}].part)` });
|
|
209
|
+
} else {
|
|
210
|
+
seenParts.set(d.part, i);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
197
213
|
if (names === null) return;
|
|
198
214
|
d.under.forEach((name, j) => {
|
|
199
215
|
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` });
|
|
@@ -230,6 +246,42 @@ export function occluderFileProblems(declarations: readonly OccluderDeclaration[
|
|
|
230
246
|
return problems;
|
|
231
247
|
}
|
|
232
248
|
|
|
249
|
+
/**
|
|
250
|
+
* Reorder a draft `assemble.plan` in place so each declared `occluders[i].over`
|
|
251
|
+
* part sits after every `under` part of the same entry across `full` and `head`
|
|
252
|
+
* rows, keeping every other row's relative order unchanged (issue #1247).
|
|
253
|
+
*/
|
|
254
|
+
export function orderPlanForOccluders<T extends readonly [string, ...unknown[]]>(
|
|
255
|
+
plan: T[],
|
|
256
|
+
declarations: readonly OccluderDeclaration[] | undefined,
|
|
257
|
+
): void {
|
|
258
|
+
if (declarations === undefined || declarations.length === 0) return;
|
|
259
|
+
for (let pass = 0; pass <= plan.length; pass++) {
|
|
260
|
+
let moved = false;
|
|
261
|
+
for (const d of declarations) {
|
|
262
|
+
if (d.over === undefined || d.over.length === 0) continue;
|
|
263
|
+
const underSet = new Set(d.under);
|
|
264
|
+
let lastUnder = -1;
|
|
265
|
+
for (let i = 0; i < plan.length; i++) {
|
|
266
|
+
if (underSet.has(plan[i][0])) lastUnder = i;
|
|
267
|
+
}
|
|
268
|
+
if (lastUnder < 0) continue;
|
|
269
|
+
const overSet = new Set(d.over);
|
|
270
|
+
const beforeOver: T[] = [];
|
|
271
|
+
const keptBefore: T[] = [];
|
|
272
|
+
for (let i = 0; i < lastUnder; i++) {
|
|
273
|
+
if (overSet.has(plan[i][0])) beforeOver.push(plan[i]);
|
|
274
|
+
else keptBefore.push(plan[i]);
|
|
275
|
+
}
|
|
276
|
+
if (beforeOver.length === 0) continue;
|
|
277
|
+
const after = plan.slice(lastUnder + 1);
|
|
278
|
+
plan.splice(0, plan.length, ...keptBefore, plan[lastUnder], ...beforeOver, ...after);
|
|
279
|
+
moved = true;
|
|
280
|
+
}
|
|
281
|
+
if (!moved) break;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
233
285
|
export interface OccluderCopy {
|
|
234
286
|
part: string;
|
|
235
287
|
px: number;
|
|
@@ -265,3 +317,7 @@ export function occluderColourCopies(parts: ReadonlyArray<{ name: string; image:
|
|
|
265
317
|
export function occluderColourWarning(index: number, copy: OccluderCopy, rgbWithin: number): string {
|
|
266
318
|
return `WARN ${OCCLUDER_COLOUR_COPIED}: ${AT}[${index}] part "${copy.part}" — ${copy.px} rig px of its selected layer at alpha > ${COPIED_ALPHA_ABOVE} under the occluder (alpha > 0) lie within ${rgbWithin} of the painting (max channel); first at ${copy.first[0]},${copy.first[1]}; the layer holds the occluder's own colour — take this part from a See-through run on the painting with the occluder removed (comfy plate --mode occluder)`;
|
|
267
319
|
}
|
|
320
|
+
|
|
321
|
+
export function occluderUnheldWarning(index: number, image: string, under: readonly string[], px: number, first: readonly [number, number]): string {
|
|
322
|
+
return `WARN ${OCCLUDER_UNHELD}: ${AT}[${index}] — ${px} rig px of occluder "${image}" (alpha > 8, first at ${first[0]},${first[1]}) are not held at alpha >= 250 by any part drawn in front of under [${under.map((u) => `"${u}"`).join(', ')}]; declare ${AT}[${index}].part to fill the unheld occluder pixels`;
|
|
323
|
+
}
|
package/src/occluderstage.ts
CHANGED
|
@@ -50,15 +50,15 @@ export interface OccluderPlateBindInput {
|
|
|
50
50
|
fullPath: string;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
export interface OccluderInput {
|
|
54
|
+
declaration: OccluderDeclaration;
|
|
55
|
+
image: Raster;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function readOccluderInputs(occluders: readonly OccluderDeclaration[], configPath: string, source: Raster): OccluderInput[] {
|
|
59
|
+
return occluders.map((d, i) => {
|
|
60
60
|
const at = `config.assemble.occluders[${i}]`;
|
|
61
|
-
const path = resolve(dirname(resolve(
|
|
61
|
+
const path = resolve(dirname(resolve(configPath)), d.image);
|
|
62
62
|
const bytes = new Uint8Array(readFileSync(path));
|
|
63
63
|
const found = createHash('sha256').update(bytes).digest('hex');
|
|
64
64
|
if (found !== d.sha256) refuse('CONFIG_OCCLUDER_SHA256', `${at}.sha256`, `is ${d.sha256}; ${d.image} has sha256 ${found} — declare the bytes the occluder image holds`);
|
|
@@ -66,6 +66,17 @@ export function occluderStageWarnings(input: OccluderStageInput): string[] {
|
|
|
66
66
|
if (image.width !== source.width || image.height !== source.height) {
|
|
67
67
|
refuse('ASSEMBLE_OCCLUDER_GRID', `${at}.image`, `is ${image.width}x${image.height}; the painting's ${source.width}x${source.height} is required — the occluder is read on the painting's grid and never fitted`);
|
|
68
68
|
}
|
|
69
|
+
return { declaration: d, image };
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function occluderStageWarnings(input: OccluderStageInput): string[] {
|
|
74
|
+
const { source, runs } = input;
|
|
75
|
+
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 });
|
|
76
|
+
const full = runs.single ? padSingleRun(runs.full, frame, input.resolution) : runs.full;
|
|
77
|
+
const painting = sourceInRig(source, frame.W, frame.H);
|
|
78
|
+
const lines: string[] = [];
|
|
79
|
+
readOccluderInputs(input.occluders, input.configPath, source).forEach(({ declaration: d, image }, i) => {
|
|
69
80
|
// A rig pixel reads the occluder at the source pixel its centre falls in.
|
|
70
81
|
const sx = (x: number): number => Math.min(source.width - 1, Math.floor((x + 0.5) * source.width / frame.W));
|
|
71
82
|
const sy = (y: number): number => Math.min(source.height - 1, Math.floor((y + 0.5) * source.height / frame.H));
|
package/src/paintingowner.ts
CHANGED
|
@@ -15,11 +15,14 @@ export interface PaintingReceivers extends PaintingOwner {
|
|
|
15
15
|
faults: Array<{ receiver: string; reason: string }>;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
/** Owner (a), the last raw plan layer at alpha >=128 on the rig canvas. */
|
|
19
|
-
export function rawPaintingOwner(raw: ReadonlyArray<{ name: string; raster: Raster }>, pixels: number): PaintingOwner {
|
|
18
|
+
/** Owner (a), the last raw plan layer at alpha >=128 on the rig canvas (cleared where an occluder keep mask holds). */
|
|
19
|
+
export function rawPaintingOwner(raw: ReadonlyArray<{ name: string; raster: Raster; keep?: Mask | null }>, pixels: number): PaintingOwner {
|
|
20
20
|
const owner = new Int32Array(pixels).fill(-1);
|
|
21
|
-
raw.forEach(({ raster }, i) => {
|
|
22
|
-
for (let p = 0; p < pixels; p++)
|
|
21
|
+
raw.forEach(({ raster, keep }, i) => {
|
|
22
|
+
for (let p = 0; p < pixels; p++) {
|
|
23
|
+
if (raster.data[p * 4 + 3] < 128) continue;
|
|
24
|
+
owner[p] = keep?.data[p] === 1 ? -1 : i;
|
|
25
|
+
}
|
|
23
26
|
});
|
|
24
27
|
return { supplier: 'owner-a/raw-plan-alpha>=128', names: raw.map(q => q.name), pixels: owner };
|
|
25
28
|
}
|
package/src/parts.ts
CHANGED
|
@@ -540,6 +540,7 @@ function orderedProvenance(p: PixelProvenance): PixelProvenance {
|
|
|
540
540
|
|
|
541
541
|
function orderedTakenSource(source: TakenLayerSource): TakenLayerSource {
|
|
542
542
|
const transport = source.transport;
|
|
543
|
+
const split = source.split;
|
|
543
544
|
return {
|
|
544
545
|
run: source.run, tag: source.tag, run_dir: source.run_dir, st_input: source.st_input,
|
|
545
546
|
prompt_id: source.prompt_id, seed: source.seed, support_px: source.support_px,
|
|
@@ -552,6 +553,10 @@ function orderedTakenSource(source: TakenLayerSource): TakenLayerSource {
|
|
|
552
553
|
before_rgba_sha256: transport.before_rgba_sha256,
|
|
553
554
|
after_rgba_sha256: transport.after_rgba_sha256,
|
|
554
555
|
} }),
|
|
556
|
+
...(split === undefined ? {} : { split: {
|
|
557
|
+
occluder: split.occluder, image: split.image, sha256: split.sha256,
|
|
558
|
+
covered_px: split.covered_px, visible_px: split.visible_px,
|
|
559
|
+
} }),
|
|
555
560
|
};
|
|
556
561
|
}
|
|
557
562
|
|
package/src/takelayers.ts
CHANGED
|
@@ -7,15 +7,18 @@ 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
|
+
import { COPIED_ALPHA_ABOVE, declaredOccluderPair, occluderDrawCycleProblems, occluderDrawOrderProblems, occluderOverTakenProblems, type OccluderDeclaration } from './occluders.ts';
|
|
11
11
|
import { dilate } from './raster/morph.ts';
|
|
12
12
|
import { newMask, newRaster, newFloatImage, type Raster } from './raster/types.ts';
|
|
13
13
|
import { readPng } from './raster/png.ts';
|
|
14
|
-
import type { TakeDeclaration } from './takeregion.ts';
|
|
14
|
+
import type { TakeDeclaration, TakeOccluderSplit } from './takeregion.ts';
|
|
15
15
|
import { crop, pad } from './raster/composite.ts';
|
|
16
16
|
import { warpAffine, type ScaleTranslate } from './raster/warp.ts';
|
|
17
17
|
import { takenTransportProblems, type TakenLayerSource, type TakenLayerTransport } from './takesource.ts';
|
|
18
18
|
|
|
19
|
+
export const TAKE_SPLIT_OCCLUDER = 'ASSEMBLE_TAKE_SPLIT_OCCLUDER';
|
|
20
|
+
export const TAKE_SPLIT_EMPTY = 'ASSEMBLE_TAKE_SPLIT_EMPTY';
|
|
21
|
+
|
|
19
22
|
export interface TakeLayers {
|
|
20
23
|
run: Run;
|
|
21
24
|
run_dir: string;
|
|
@@ -142,7 +145,10 @@ export function transportLayer(layer: Layer, donor: LayerSet, set: LayerSet, ima
|
|
|
142
145
|
}
|
|
143
146
|
|
|
144
147
|
export function takeLayerNote(source: TakenLayerSource): string {
|
|
145
|
-
|
|
148
|
+
const splitClause = source.split === undefined
|
|
149
|
+
? ''
|
|
150
|
+
: `; split occluder[${source.split.occluder}] ${source.split.image} (${source.split.sha256.slice(0, 12)}) covered ${source.split.covered_px} run px, visible ${source.split.visible_px} run px`;
|
|
151
|
+
return `take ${source.run}:${source.tag} from ${source.run_dir}; prompt_id ${source.prompt_id}; seed ${source.seed}; st_input ${source.st_input}; support ${source.support_px} run px; checked ${source.checked_px} input px; differing ${source.differing_px}; alpha > ${OPAQUE_ALPHA_ABOVE}, ${CORE_KERNEL}x${CORE_KERNEL} margin${splitClause}`;
|
|
146
152
|
}
|
|
147
153
|
/** Intersection of original alpha supports in the common target-run canvas; no bbox or dilation proxy. */
|
|
148
154
|
function supportOverlap(a: Layer, b: Layer): number {
|
|
@@ -156,8 +162,29 @@ function supportOverlap(a: Layer, b: Layer): number {
|
|
|
156
162
|
}
|
|
157
163
|
/** Apply every declaration together, so replacing all tied layers from one run can retain its known order. */
|
|
158
164
|
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[] } {
|
|
159
|
-
const
|
|
165
|
+
const wholeDeclarations = (cfg.assemble.take ?? []).filter((item): item is TakeLayers => 'tags' in item);
|
|
166
|
+
const declarations = (cfg.assemble.take ?? []).filter((item): item is TakeLayers | TakeOccluderSplit => 'tags' in item || 'occluder' in item);
|
|
160
167
|
const occluders = cfg.assemble.occluders ?? [];
|
|
168
|
+
for (const d of declarations) {
|
|
169
|
+
if ('occluder' in d) {
|
|
170
|
+
const partAt = `config.assemble.take run "${d.run_dir}" (${d.run}) part "${d.part}"`;
|
|
171
|
+
const occEntry = Number.isSafeInteger(d.occluder) && d.occluder >= 0 ? occluders[d.occluder] : undefined;
|
|
172
|
+
if (occEntry === undefined) {
|
|
173
|
+
return refuse(TAKE_SPLIT_OCCLUDER, partAt, `occluder index ${d.occluder} does not exist in config.assemble.occluders (${occluders.length} declared); a valid occluder index is required`);
|
|
174
|
+
}
|
|
175
|
+
if ((occEntry.over ?? []).includes(d.part)) {
|
|
176
|
+
return refuse(TAKE_SPLIT_OCCLUDER, partAt, `part "${d.part}" is in config.assemble.occluders[${d.occluder}].over; a split take is for a part under the occluder, not in its over`);
|
|
177
|
+
}
|
|
178
|
+
if (!occEntry.under.includes(d.part)) {
|
|
179
|
+
return refuse(TAKE_SPLIT_OCCLUDER, partAt, `part "${d.part}" is not in config.assemble.occluders[${d.occluder}].under; a part declared under that occluder is required`);
|
|
180
|
+
}
|
|
181
|
+
if (cfg.assemble.plan !== undefined) {
|
|
182
|
+
const row = cfg.assemble.plan.find(([part]) => part === d.part);
|
|
183
|
+
if (row === undefined) return refuse('CONFIG_NAME_RESOLVES', partAt, `names "${d.part}"; a part named in assemble.plan is required`);
|
|
184
|
+
if (row[1] !== d.run || row[2] !== d.tag) return refuse('CONFIG_NAME_RESOLVES', partAt, `declares ${d.run}:${d.tag} for part "${d.part}"; assemble.plan declares ["${row[0]}", "${row[1]}", "${row[2]}"]`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
161
188
|
if (occluders.length > 0) {
|
|
162
189
|
const cycles = occluderDrawCycleProblems(occluders);
|
|
163
190
|
refuseIfAny([
|
|
@@ -165,7 +192,7 @@ export function applyTakenLayers(runs: { full: LayerSet; head: LayerSet; single:
|
|
|
165
192
|
...(cfg.assemble.plan === undefined
|
|
166
193
|
? []
|
|
167
194
|
: [
|
|
168
|
-
...occluderOverTakenProblems(occluders, cfg.assemble.plan,
|
|
195
|
+
...occluderOverTakenProblems(occluders, cfg.assemble.plan, wholeDeclarations),
|
|
169
196
|
...(cycles.length > 0 ? [] : occluderDrawOrderProblems(occluders, cfg.assemble.plan)),
|
|
170
197
|
]),
|
|
171
198
|
]);
|
|
@@ -190,6 +217,85 @@ export function applyTakenLayers(runs: { full: LayerSet; head: LayerSet; single:
|
|
|
190
217
|
if (target === null) return refuse('ASSEMBLE_TAKE_CROP', at, 'a target input is required for a declared crop');
|
|
191
218
|
const geometry = d.crop === undefined ? undefined : cropGeometry(d, painting, target, donor, set, inputs, at);
|
|
192
219
|
if (geometry !== undefined && (image.width !== geometry.expected.width || image.height !== geometry.expected.height)) return refuse('ASSEMBLE_TAKE_CROP', at, `donor st_input ${image.width}x${image.height}; declared square-padded crop requires ${geometry.expected.width}x${geometry.expected.height}`);
|
|
220
|
+
if ('occluder' in d) {
|
|
221
|
+
const partAt = `${at} part "${d.part}"`;
|
|
222
|
+
const tagAt = `${at} tag "${d.tag}"`;
|
|
223
|
+
const key = `${d.run}:${d.tag}`;
|
|
224
|
+
if (seen.has(key)) return refuse('ASSEMBLE_TAKE_UNIQUE', at, `tag "${d.tag}" replaces ${key} twice; declare one donor per target tag`);
|
|
225
|
+
seen.add(key);
|
|
226
|
+
const baseLayer = lists[d.run].find(l => l.name === d.tag);
|
|
227
|
+
if (baseLayer === undefined) return refuse('ASSEMBLE_TAKE_TAG_IN_RUN', at, `tag "${d.tag}" is absent from the base ${d.run} run; both base and donor must hold the split tag`);
|
|
228
|
+
const donorLayer = donor.layers.find(l => l.name === d.tag);
|
|
229
|
+
if (donorLayer === undefined) return refuse('ASSEMBLE_TAKE_TAG_IN_RUN', at, `tag "${d.tag}" is absent; a named See-through tag held by that donor is required`);
|
|
230
|
+
const occEntry = occluders[d.occluder]!;
|
|
231
|
+
let occPng: Raster;
|
|
232
|
+
try { occPng = readPng(resolve(base, occEntry.image)); } catch { return refuse('CONFIG_FILE_PRESENT', `config.assemble.occluders[${d.occluder}].image`, `names "${occEntry.image}", which is not a readable PNG`); }
|
|
233
|
+
if (occPng.width !== painting.width || occPng.height !== painting.height) {
|
|
234
|
+
return refuse('ASSEMBLE_OCCLUDER_GRID', `config.assemble.occluders[${d.occluder}].image`, `is ${occPng.width}x${occPng.height}; the painting's dimensions ${painting.width}x${painting.height} are required`);
|
|
235
|
+
}
|
|
236
|
+
const occTarget = d.run === 'head'
|
|
237
|
+
? crop(occPng, inputs.headBox![0], inputs.headBox![1], inputs.headBox![2] - inputs.headBox![0], inputs.headBox![3] - inputs.headBox![1])
|
|
238
|
+
: target === painting
|
|
239
|
+
? occPng
|
|
240
|
+
: pad(occPng, inputs.padLeft, inputs.padTop, target.width - painting.width - inputs.padLeft, target.height - painting.height - inputs.padTop, [0, 0, 0, 0]);
|
|
241
|
+
const isCovered = (x: number, y: number): boolean => {
|
|
242
|
+
const ox = Math.min(occTarget.width - 1, Math.max(0, Math.floor((x + 0.5) * occTarget.width / set.canvas.w)));
|
|
243
|
+
const oy = Math.min(occTarget.height - 1, Math.max(0, Math.floor((y + 0.5) * occTarget.height / set.canvas.h)));
|
|
244
|
+
return occTarget.data[(oy * occTarget.width + ox) * 4 + 3] > COPIED_ALPHA_ABOVE;
|
|
245
|
+
};
|
|
246
|
+
const transported = geometry === undefined ? undefined : transportLayer(donorLayer, donor, set, image, d, geometry.map, geometry.exact, tagAt);
|
|
247
|
+
const donorOnSet = transported?.layer ?? donorLayer;
|
|
248
|
+
const merged = newRaster(set.canvas.w, set.canvas.h);
|
|
249
|
+
let coveredPx = 0, visiblePx = 0, opaquePx = 0;
|
|
250
|
+
for (let y = 0; y < set.canvas.h; y++) for (let x = 0; x < set.canvas.w; x++) {
|
|
251
|
+
const p = (y * set.canvas.w + x) * 4;
|
|
252
|
+
if (isCovered(x, y)) {
|
|
253
|
+
if (x >= baseLayer.left && x < baseLayer.right && y >= baseLayer.top && y < baseLayer.bottom) {
|
|
254
|
+
const bp = ((y - baseLayer.top) * baseLayer.pixels.width + (x - baseLayer.left)) * 4;
|
|
255
|
+
merged.data.set(baseLayer.pixels.data.subarray(bp, bp + 4), p);
|
|
256
|
+
if (baseLayer.pixels.data[bp + 3] > OPAQUE_ALPHA_ABOVE) { coveredPx++; opaquePx++; }
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
if (x >= donorOnSet.left && x < donorOnSet.right && y >= donorOnSet.top && y < donorOnSet.bottom) {
|
|
260
|
+
const dp = ((y - donorOnSet.top) * donorOnSet.pixels.width + (x - donorOnSet.left)) * 4;
|
|
261
|
+
merged.data.set(donorOnSet.pixels.data.subarray(dp, dp + 4), p);
|
|
262
|
+
if (donorOnSet.pixels.data[dp + 3] > OPAQUE_ALPHA_ABOVE) { visiblePx++; opaquePx++; }
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (coveredPx === 0 || visiblePx === 0) {
|
|
267
|
+
return refuse('ASSEMBLE_TAKE_SPLIT_EMPTY', partAt, `covered_px is ${coveredPx} (base ${d.run}:${d.tag} under occluder[${d.occluder}] alpha > ${COPIED_ALPHA_ABOVE}) and visible_px is ${visiblePx} (donor ${d.run}:${d.tag} outside occluder[${d.occluder}]); both regions require at least 1 pixel of alpha > ${OPAQUE_ALPHA_ABOVE}`);
|
|
268
|
+
}
|
|
269
|
+
const donorVisiblePixels = newRaster(donorLayer.pixels.width, donorLayer.pixels.height);
|
|
270
|
+
let donorVisibleOpaque = 0;
|
|
271
|
+
for (let y = 0; y < donorLayer.pixels.height; y++) for (let x = 0; x < donorLayer.pixels.width; x++) {
|
|
272
|
+
const dx = donorLayer.left + x, dy = donorLayer.top + y;
|
|
273
|
+
const tx = geometry === undefined ? dx : Math.floor(geometry.map.sx * dx + geometry.map.tx);
|
|
274
|
+
const ty = geometry === undefined ? dy : Math.floor(geometry.map.sy * dy + geometry.map.ty);
|
|
275
|
+
if (tx >= 0 && tx < set.canvas.w && ty >= 0 && ty < set.canvas.h && !isCovered(tx, ty)) {
|
|
276
|
+
const dp = (y * donorLayer.pixels.width + x) * 4;
|
|
277
|
+
donorVisiblePixels.data.set(donorLayer.pixels.data.subarray(dp, dp + 4), dp);
|
|
278
|
+
if (donorLayer.pixels.data[dp + 3] > OPAQUE_ALPHA_ABOVE) donorVisibleOpaque++;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const donorVisible: Layer = { ...donorLayer, pixels: donorVisiblePixels, opaquePx: donorVisibleOpaque };
|
|
282
|
+
const checked = identity(donorVisible, donor.canvas, image, geometry?.expected ?? target, tagAt);
|
|
283
|
+
const source: TakenLayerSource = {
|
|
284
|
+
run: d.run, tag: d.tag, run_dir: d.run_dir, st_input: d.st_input,
|
|
285
|
+
prompt_id: meta.prompt_id, seed: meta.seed,
|
|
286
|
+
support_px: checked.support,
|
|
287
|
+
checked_px: checked.checked.reduce((a, b) => a + b, 0),
|
|
288
|
+
differing_px: 0,
|
|
289
|
+
...(transported === undefined ? {} : { transport: transported.transport }),
|
|
290
|
+
split: { occluder: d.occluder, image: occEntry.image, sha256: occEntry.sha256, covered_px: coveredPx, visible_px: visiblePx },
|
|
291
|
+
};
|
|
292
|
+
const replacement: Layer = { ...baseLayer, left: 0, top: 0, right: set.canvas.w, bottom: set.canvas.h, pixels: merged, opaquePx, takenLayers: [source] };
|
|
293
|
+
lists[d.run] = [...lists[d.run].filter(l => l.name !== d.tag), replacement];
|
|
294
|
+
origins.set(replacement, resolve(base, d.run_dir));
|
|
295
|
+
notes.push(takeLayerNote(source));
|
|
296
|
+
notes.push(`take union ${d.run} from ${d.run_dir}: checked ${checked.checked.reduce((a, b) => a + b, 0)} input px; differing 0`);
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
193
299
|
const union = new Uint8Array(image.width * image.height);
|
|
194
300
|
for (const tag of d.tags) {
|
|
195
301
|
const key = `${d.run}:${tag}`;
|
|
@@ -232,8 +338,9 @@ export function applyTakenLayers(runs: { full: LayerSet; head: LayerSet; single:
|
|
|
232
338
|
if (reversed) problems.push({ code: 'ASSEMBLE_TAKE_PLAN_ORDER', object: `${run} plan parts "${a.part}" / "${b.part}"`, detail: `plan order reverses ${band === 0 ? `mixed-run depths ${a.layer.depth} / ${b.layer.depth}; put the larger depth behind` : `two-run full-layer roles "${a.layer.name}" / "${b.layer.name}"; order back hair, body, headwear/earwear, face, head details, front hair`}; supports overlap at ${overlap} run px (alpha > ${OPAQUE_ALPHA_ABOVE}); use assemble --propose-plan` });
|
|
233
339
|
}
|
|
234
340
|
refuseIfAny(problems);
|
|
235
|
-
const
|
|
236
|
-
|
|
341
|
+
const tagsOf = (d: TakeLayers | TakeOccluderSplit): readonly string[] => 'tags' in d ? d.tags : [d.tag];
|
|
342
|
+
const replaced = new Set(declarations.filter(d => d.run === run).flatMap(tagsOf));
|
|
343
|
+
if (runs[run].hidden.some(l => replaced.has(l.of)) || declarations.some(d => d.run === run && readLayers(resolve(base, d.run_dir)).hidden.some(l => tagsOf(d).includes(l.of)))) return refuse('ASSEMBLE_TAKE_HIDDEN', run, 'a replaced layer has hidden companion art; separate hidden provenance is not declared, so the combination is refused');
|
|
237
344
|
}
|
|
238
345
|
const full = { ...runs.full, layers: lists.full }, head = runs.single ? full : { ...runs.head, layers: lists.head };
|
|
239
346
|
return { full, head, single: runs.single, notes };
|
package/src/takeregion.ts
CHANGED
|
@@ -24,7 +24,20 @@ export interface TakeRegion {
|
|
|
24
24
|
/** PNG bytes, explicitly bound to the stage source or a separate painting. */
|
|
25
25
|
reference?: { source: true; sha256: string } | { painting: string; sha256: string };
|
|
26
26
|
}
|
|
27
|
-
export
|
|
27
|
+
export interface TakeOccluderSplit {
|
|
28
|
+
run: Run;
|
|
29
|
+
run_dir: string;
|
|
30
|
+
st_input: string;
|
|
31
|
+
/** Same painting-space crop and transport as a whole-layer take. */
|
|
32
|
+
crop?: TakeLayers['crop'];
|
|
33
|
+
/** Plan part on `run`; must be in `occluders[occluder].under`, not in `over`. */
|
|
34
|
+
part: string;
|
|
35
|
+
/** The plan row's See-through tag for `part` on `run`. */
|
|
36
|
+
tag: string;
|
|
37
|
+
/** Zero-based index into `config.assemble.occluders`; its image is the split mask. */
|
|
38
|
+
occluder: number;
|
|
39
|
+
}
|
|
40
|
+
export type TakeDeclaration = TakeLayers | TakeRegion | TakeOccluderSplit;
|
|
28
41
|
export interface RegionReading {
|
|
29
42
|
part: string;
|
|
30
43
|
run: Run;
|
|
@@ -106,7 +119,7 @@ export function deriveTakenRegion(base: Layer, donor: Layer, painting: Raster, s
|
|
|
106
119
|
|
|
107
120
|
/** Called beside whole-layer take, before assembly or any output emission. */
|
|
108
121
|
export function applyTakenRegions(runs: Runs, painting: Raster, cfg: AssembleConfig, configPath: string, setup: SetupPainting | undefined, receipts: ReceiptLedger, sourcePath?: string): Runs {
|
|
109
|
-
const declarations = (cfg.assemble.take ?? []).filter((item): item is TakeRegion => '
|
|
122
|
+
const declarations = (cfg.assemble.take ?? []).filter((item): item is TakeRegion => 'seed' in item);
|
|
110
123
|
if (declarations.length === 0) return runs;
|
|
111
124
|
const tolerance = setup?.rgb_tolerance;
|
|
112
125
|
if (typeof tolerance !== 'number' || !Number.isSafeInteger(tolerance) || tolerance < 0 || tolerance > 255) {
|
|
@@ -126,7 +139,7 @@ export function applyTakenRegions(runs: Runs, painting: Raster, cfg: AssembleCon
|
|
|
126
139
|
const plan = cfg.assemble.plan.find(entry => entry[0] === declaration.part && entry[1] === declaration.run);
|
|
127
140
|
if (plan === undefined) return refuse('ASSEMBLE_REGION_TAKE_PART', at, `requires a plan part named "${declaration.part}" in target run "${declaration.run}"`);
|
|
128
141
|
const key = `${plan[1]}:${plan[2]}`;
|
|
129
|
-
if (seen.has(key) || (cfg.assemble.take ?? []).some(item => 'tags' in item && item.run === plan[1] && item.tags.includes(plan[2]))) {
|
|
142
|
+
if (seen.has(key) || (cfg.assemble.take ?? []).some(item => ('tags' in item && item.run === plan[1] && item.tags.includes(plan[2])) || ('occluder' in item && item.run === plan[1] && (item.tag === plan[2] || item.part === declaration.part)))) {
|
|
130
143
|
return refuse('ASSEMBLE_REGION_TAKE_PART', at, `target ${key} is taken more than once; one region donor or whole-layer donor per target is required`);
|
|
131
144
|
}
|
|
132
145
|
seen.add(key);
|