@rig-c/parts 1.74.1 → 1.76.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/src/assemble.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { AUTOMATIC_WRITERS as AW, compactValueBaseline, pixelProvenance, rgbaEqual, type ValueBaseline } from './provenance.ts';
1
2
  import { bindDepthRun, copyDepthMaterial, registerDepthRun, transportPartDepth, type DepthConfig, type RegisteredDepth } from './depthsheets.ts';
2
3
  /**
3
4
  * The assemble stage: two See-through runs over one painting — a FULL-body run
@@ -240,6 +241,8 @@ export interface Geometry {
240
241
  keySkeleton?: ControlSkeleton;
241
242
  /** `assemble.head_face_underfill` (issue #492): composite `full:face` under `head:face` on the head canvas to fill transparent bare-skin holes. */
242
243
  headFaceUnderfill?: boolean;
244
+ /** `assemble.yield_refused`, default false; alpha-only ownership transfer from original refused core pixels. */
245
+ yieldRefused?: boolean;
243
246
  }
244
247
 
245
248
  /**
@@ -357,6 +360,8 @@ export interface AssembleInput {
357
360
  keySkeleton?: ControlSkeleton;
358
361
  /** `assemble.head_face_underfill` (issue #492): composite `full:face` under `head:face` on the head canvas to fill transparent bare-skin holes. */
359
362
  headFaceUnderfill?: boolean;
363
+ /** `assemble.yield_refused`, default false; alpha-only ownership transfer from original refused core pixels. */
364
+ yieldRefused?: boolean;
360
365
  /**
361
366
  * Issue #587: rig pixels taken out of named parts once the cuts and the limbs are made, before the fringe pass and
362
367
  * every figure a part's record holds — each entry clears `part`'s pixels (alpha, colour and region) where `mask` is
@@ -2253,7 +2258,7 @@ export function pixelOwners(rigLayers: readonly Raster[], rank: readonly number[
2253
2258
  * masks mark own-layer art under a subset set's actual cover (alpha above 8);
2254
2259
  * those pixels are occluded, outside every projection core, and never recoloured.
2255
2260
  */
2256
- 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[] {
2261
+ 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, changed?: (layer: number, rigPixel: number) => void): ProjectionStats[] {
2257
2262
  const { W, H } = frame;
2258
2263
  const owner = pixelOwners(rigLayers, rank);
2259
2264
  const inFront = (o: number, i: number): boolean => frontOf(o, i, rank);
@@ -2316,10 +2321,14 @@ export function projectSource(rigLayers: Raster[], srcr: Raster, frame: Frame, r
2316
2321
  if (core.data[p] === 0) continue;
2317
2322
  const w = blurred.data[p];
2318
2323
  const rest = f32(1 - w);
2324
+ let different = false;
2319
2325
  for (let c = 0; c < 3; c++) {
2320
2326
  const v = f32(f32(w * srcr.data[p * 4 + c]) + f32(rest * r.data[p * 4 + c]));
2321
- r.data[p * 4 + c] = Math.trunc(v < 0 ? 0 : v > 255 ? 255 : v);
2327
+ const next = Math.trunc(v < 0 ? 0 : v > 255 ? 255 : v);
2328
+ different ||= next !== r.data[p * 4 + c];
2329
+ r.data[p * 4 + c] = next;
2322
2330
  }
2331
+ if (different) changed?.(i, p);
2323
2332
  }
2324
2333
  return { core: coreN, taken, refused, clear, takenMask, coreMask: core, refusedMask };
2325
2334
  });
@@ -2433,7 +2442,7 @@ export function growRim(part: Raster, sel: Mask, srcr: Raster, front: Mask | nul
2433
2442
  * overwriting an earlier one — the layer whose run says whether the pixel is
2434
2443
  * visible — and `trace.ring` set when the last write was the ring's.
2435
2444
  */
2436
- export function mergeBelowCrop(part: Raster, extras: Raster[], front: Mask, srcr: Raster, headBottom: number, trace?: MergeTrace): number {
2445
+ export function mergeBelowCrop(part: Raster, extras: Raster[], front: Mask, srcr: Raster, headBottom: number, trace?: MergeTrace, changed?: (rigPixel: number, stage: 'extend' | 'growRim') => void): number {
2437
2446
  let merged = 0;
2438
2447
  extras.forEach((extra, e) => {
2439
2448
  const sel = belowCrop(part, extra, headBottom);
@@ -2441,6 +2450,7 @@ export function mergeBelowCrop(part: Raster, extras: Raster[], front: Mask, srcr
2441
2450
  for (let p = 0; p < sel.data.length; p++) {
2442
2451
  if (sel.data[p] === 0) continue;
2443
2452
  copied++;
2453
+ if (!rgbaEqual(part.data, p * 4, extra.data, p * 4)) changed?.(p, 'extend');
2444
2454
  part.data.set(extra.data.subarray(p * 4, p * 4 + 4), p * 4);
2445
2455
  if (trace !== undefined) {
2446
2456
  trace.from[p] = e;
@@ -2454,6 +2464,7 @@ export function mergeBelowCrop(part: Raster, extras: Raster[], front: Mask, srcr
2454
2464
  trace.lastRing = ring;
2455
2465
  for (let p = 0; p < ring.data.length; p++) {
2456
2466
  if (ring.data[p] === 1) {
2467
+ changed?.(p, 'growRim');
2457
2468
  trace.from[p] = e;
2458
2469
  trace.ring.data[p] = 1;
2459
2470
  }
@@ -2801,6 +2812,7 @@ export function pushBackFringe(
2801
2812
  feathered: ReadonlyArray<Mask | null> | null = null,
2802
2813
  keep: ReadonlyArray<Mask | null> | null = null,
2803
2814
  turnMovingPair: ((a: string, b: string) => boolean) | null = null,
2815
+ restored?: (part: number, rigPixel: number) => void,
2804
2816
  ): FringePushed[][] {
2805
2817
  const { width: W } = srcr;
2806
2818
  const { holder, cand } = seamCandidates(parts, srcr, rule, silhouette);
@@ -2836,7 +2848,10 @@ export function pushBackFringe(
2836
2848
  }));
2837
2849
  const counts: Array<Map<number, number>> = parts.map(() => new Map());
2838
2850
  cleared.forEach((list, i) => {
2839
- for (const c of list) if (c.on) counts[i].set(c.h, (counts[i].get(c.h) ?? 0) + 1);
2851
+ for (const c of list) {
2852
+ if (c.on) counts[i].set(c.h, (counts[i].get(c.h) ?? 0) + 1);
2853
+ else restored?.(i, (parts[i].record.y + Math.floor(c.q / parts[i].record.w)) * W + parts[i].record.x + c.q % parts[i].record.w);
2854
+ }
2840
2855
  });
2841
2856
  return counts.map((m) =>
2842
2857
  [...m.entries()]
@@ -2874,6 +2889,7 @@ export function seamOverride(
2874
2889
  silhouette: Mask | null,
2875
2890
  keep: ReadonlyArray<Mask | null> | null = null,
2876
2891
  turnMovingPair: ((a: string, b: string) => boolean) | null = null,
2892
+ written?: (part: number, rigPixel: number) => void,
2877
2893
  ): void {
2878
2894
  const { width: W } = srcr;
2879
2895
  const { top, cand } = seamCandidates(parts, srcr, rule, silhouette);
@@ -2909,9 +2925,11 @@ export function seamOverride(
2909
2925
  ) {
2910
2926
  continue;
2911
2927
  }
2928
+ const different = image.data[s] !== srcr.data[d * 4] || image.data[s + 1] !== srcr.data[d * 4 + 1] || image.data[s + 2] !== srcr.data[d * 4 + 2];
2912
2929
  image.data[s] = srcr.data[d * 4];
2913
2930
  image.data[s + 1] = srcr.data[d * 4 + 1];
2914
2931
  image.data[s + 2] = srcr.data[d * 4 + 2];
2932
+ if (different) written?.(i, d);
2915
2933
  n++;
2916
2934
  }
2917
2935
  }
@@ -3411,6 +3429,8 @@ export interface CutCount {
3411
3429
  band: number;
3412
3430
  /** With `under` only (issue #193): the base pixels filled from the under image (`fillUnder`); absent without it. */
3413
3431
  under?: number;
3432
+ /** Filled pixels with final alpha above the opaque threshold (report-only). */
3433
+ underOpaque?: number;
3414
3434
  /** With `under` only: the removed pixels the image left empty (its alpha below the alpha removed); `under + underEmpty` is the removed count. */
3415
3435
  underEmpty?: number;
3416
3436
  /** With `under_fill: "colour"` only (issue #360): the `under` pixels took the image's colour at the alpha the cut removed; absent without it. */
@@ -3514,6 +3534,8 @@ export function cutBand(polygonMask: Mask, overlap: number): Mask {
3514
3534
 
3515
3535
  /** One layer's part as the stage builds it, before it is placed: its key, pixels, projection figures, merge trace and, when the layer is cut, the rig pixels it owns. */
3516
3536
  interface Built {
3537
+ /** Report-only last writer at each rig coordinate; never read by raster arithmetic. */
3538
+ writers?: Int32Array;
3517
3539
  key: string;
3518
3540
  r: Raster;
3519
3541
  st: ProjectionStats;
@@ -4027,7 +4049,8 @@ function cutLimbs(
4027
4049
  problems.push({ code: 'ASSEMBLE_COUNTS_ADD_UP', object: `part "${src}" (config.limbs)`, detail: `opaque px: ${before} before the limbs, ${sum} over their parts; equal is required (a bug in the assembler, not in the inputs)` });
4028
4050
  }
4029
4051
  for (const { q, i } of shares) {
4030
- pieces[i] = { ...b, r: rasters[i], region: regions[i], merged: mergedIn(b, regions[i]) };
4052
+ const writers = b.writers?.slice();
4053
+ pieces[i] = { ...b, writers, r: rasters[i], region: regions[i], merged: mergedIn(b, regions[i]) };
4031
4054
  if (count(regions[i], regions[i]) === 0 && opaqueOf(rasters[i]) === 0) {
4032
4055
  problems.push({
4033
4056
  code: 'ASSEMBLE_LIMB_PIXELS',
@@ -4121,6 +4144,10 @@ function cutLimbs(
4121
4144
  return;
4122
4145
  }
4123
4146
  const lower = rasters[at];
4147
+ const capWrite = (p: number, data: Uint8ClampedArray, offset: number): void => {
4148
+ const ids = (pieces[at] as Built).writers;
4149
+ if (ids !== undefined && !rgbaEqual(lower.data, p * 4, data, offset)) ids[p] = AW.limbCap;
4150
+ };
4124
4151
  const lowerSrc = builtOf(sg.from) as Built;
4125
4152
  // Issue #360 (cut_band): the cap's pixels are the disc's on the upper side of the cut, wherever it was placed.
4126
4153
  const cut = (cutLines.get(l) as Array<JointLine | null>)[k] as JointLine;
@@ -4143,6 +4170,7 @@ function cutLimbs(
4143
4170
  const from: CapFrom = { box, codes: new Uint8Array(Math.max(0, box[2]) * Math.max(0, box[3])) };
4144
4171
  const mark = (x: number, y: number, code: number): void => {
4145
4172
  from.codes[(y - box[1]) * box[2] + (x - box[0])] = code;
4173
+
4146
4174
  };
4147
4175
  for (let y = Math.max(0, box[1]); y < Math.min(H, box[1] + box[3]); y++) {
4148
4176
  for (let x = Math.max(0, box[0]); x < Math.min(W, box[0] + box[2]); x++) {
@@ -4157,6 +4185,7 @@ function cutLimbs(
4157
4185
  lowerKept++;
4158
4186
  mark(x, y, CAP_FROM_LOWER_KEPT);
4159
4187
  } else if (img !== null && img.data[u + 3] > 0) {
4188
+ capWrite(p, img.data, u);
4160
4189
  lower.data.set(img.data.subarray(u, u + 4), p * 4);
4161
4190
  lowerPx++;
4162
4191
  mark(x, y, CAP_FROM_LOWER);
@@ -4169,10 +4198,12 @@ function cutLimbs(
4169
4198
  continue;
4170
4199
  }
4171
4200
  if (img !== null && img.data[u + 3] > 0) {
4172
- lower.data.set(img.data.subarray(u, u + 4), p * 4);
4201
+ capWrite(p, img.data, u);
4202
+ lower.data.set(img.data.subarray(u, u + 4), p * 4);
4173
4203
  imagePx++;
4174
4204
  mark(x, y, CAP_FROM_IMAGE);
4175
4205
  } else if (ownLower[p] === li && lowerSrc.r.data[p * 4 + 3] > 0) {
4206
+ capWrite(p, lowerSrc.r.data, p * 4);
4176
4207
  lower.data.set(lowerSrc.r.data.subarray(p * 4, p * 4 + 4), p * 4);
4177
4208
  layerPx++;
4178
4209
  mark(x, y, CAP_FROM_LAYER);
@@ -4180,6 +4211,7 @@ function cutLimbs(
4180
4211
  // Issue #360: the disc is filled from the art — the upper segment's, where the lower's layer has none.
4181
4212
  // Issue #557: under either shape — the half-disc too takes the neighbouring segment's pixels, so a cap is
4182
4213
  // short only where no layer of the limb gives a pixel.
4214
+ capWrite(p, upper.data, p * 4);
4183
4215
  lower.data.set(upper.data.subarray(p * 4, p * 4 + 4), p * 4);
4184
4216
  upperPx++;
4185
4217
  mark(x, y, CAP_FROM_UPPER);
@@ -4226,6 +4258,7 @@ function cutLimbs(
4226
4258
  // piece's region and its remaining ramp is marked feathered so pushBackFringe does not clear the fade.
4227
4259
  if (na <= OPAQUE_ALPHA_ABOVE) upperRegion.data[p] = 0;
4228
4260
  else featheredMask.data[p] = 1;
4261
+ if (upPiece.writers !== undefined) upPiece.writers[p] = AW.limbFeather;
4229
4262
  featheredPx++;
4230
4263
  }
4231
4264
  }
@@ -4330,7 +4363,8 @@ function cutLimbs(
4330
4363
  base.hybrid = { part: sg.hybrid.part, ...geometry };
4331
4364
  capFrom[loAt] = null;
4332
4365
  parts.push({ limb: l, segment: k, part: sg.hybrid.part, of: sg.from, record: { name: l, segment: k, of: base.of, bone: sg.bone, joint: sg.joint, band: geometry } });
4333
- pieces.push({ ...source, r, region, merged: mergedIn(source, region) });
4366
+ const writers = source.writers?.slice();
4367
+ pieces.push({ ...source, writers, r, region, merged: mergedIn(source, region) });
4334
4368
  capFrom.push(null);
4335
4369
  // Existing piece objects refer to the same raster and mask.
4336
4370
  for (const i of [upAt, loAt]) (pieces[i] as Built).merged = mergedIn(pieces[i] as Built, regions[i]);
@@ -4344,6 +4378,21 @@ function cutLimbs(
4344
4378
  // the stage
4345
4379
  // ---------------------------------------------------------------------------
4346
4380
 
4381
+ /** Opt-in ownership accounting, separate from source projection and authored provenance. */
4382
+ export interface DriftYieldReading {
4383
+ part: string;
4384
+ from: string;
4385
+ refusedCandidates: number;
4386
+ yielded: number;
4387
+ /** Yielded refusals also accepted by projection closing; removed from the written projected count. */
4388
+ yieldedTaken: number;
4389
+ skipped: { merge: number; ring: number; notOpaque: number; noMatchingBehind: number };
4390
+ /** Informational only: no fixed global-holder eligibility guard is used. */
4391
+ originalGlobalHolderWouldSkip: number;
4392
+ originalHolders: Array<{ part: string | null; px: number }>;
4393
+ finalHolders: Array<{ part: string | null; px: number }>;
4394
+ }
4395
+
4347
4396
  export interface AssembleResult {
4348
4397
  parts: PartsFile;
4349
4398
  /** In plan order, each cropped to its record's box. */
@@ -4364,6 +4413,8 @@ export interface AssembleResult {
4364
4413
  holeKinds: HoleKinds;
4365
4414
  /** The parts whose `DRIFT_LIMIT` refusals hold a body another part holds in the draw order (`driftBodies`), in draw order; empty otherwise. */
4366
4415
  drift: DriftBodies[];
4416
+ /** Present only under the opt-in; includes skipped original-source populations and actual holders. */
4417
+ yieldReadings?: DriftYieldReading[];
4367
4418
  /** Every hidden-art layer of the runs read (issue #359) and what read it (`hiddenLines`); empty when the runs hold none. */
4368
4419
  hidden: HiddenArtUse[];
4369
4420
  seamRule: SeamRule;
@@ -4600,6 +4651,19 @@ export function assemble(input: AssembleInput): AssembleResult {
4600
4651
  const coverFootprints = new Map<string, Mask>();
4601
4652
  const limbSources = new Set(Object.values(input.limbs ?? {}).flatMap((l) => l.segments.map((sg) => sg.from)));
4602
4653
  const limbPlans = new Set([...limbSources, ...cuts.filter((c) => limbSources.has(c.into)).map((c) => c.from)]);
4654
+ const editNames: string[] = [];
4655
+ const editId = (name: string): number => {
4656
+ const old = editNames.indexOf(name);
4657
+ if (old >= 0) return old + 1;
4658
+ editNames.push(name);
4659
+ return editNames.length;
4660
+ };
4661
+ const cutIds = cuts.map((_, i) => editId(`cuts[${i}]`));
4662
+ const patchIds = patches.map((_, i) => editId(`patches[${i}]`));
4663
+ const layerWriters = new Map<string, Int32Array>();
4664
+ const valueBaselines = new Map<string, ValueBaseline | null>();
4665
+ // Extend-only rasters are still projected/merged, but are never emitted as own sources.
4666
+ const readKeys = new Set(sourcePlan.map(([, run, tag]) => `${run}:${tag}`));
4603
4667
  const rig = new Map<string, Raster>();
4604
4668
  const stats = new Map<string, ProjectionStats>();
4605
4669
  const ghost: Record<string, number> = {};
@@ -4624,7 +4688,59 @@ export function assemble(input: AssembleInput): AssembleResult {
4624
4688
  coverFootprints.set(`${run}:${l.tag}`, cover);
4625
4689
  return mask;
4626
4690
  });
4627
- const st = projectSource(rigLayers, srcr, frame, run, projectRule, rank, keep);
4691
+ // Normalize the unedited input to the same rig grid. Cleanup effects on
4692
+ // retained samples are named; split/underfill outputs are prepared writes.
4693
+ const writes = layers.map((l, i): Int32Array | null => {
4694
+ const key = `${run}:${l.tag}`;
4695
+ if (!readKeys.has(key)) return null;
4696
+ const ids = new Int32Array(W * H);
4697
+ const originalSet = run === 'full' ? fullPadded : depthHeadInput;
4698
+ const original = originalSet.layers.find(q => q.name === l.tag);
4699
+ const prepared = set.layers.find(q => q.name === l.tag);
4700
+ let preparedWriter = 0;
4701
+ if (run === 'head' && prepared?.pixels !== original?.pixels) preparedWriter = AW.headFaceUnderfill;
4702
+ if (run === 'full') {
4703
+ const arm = fullArmSplit.layers.find(q => q.name === l.tag);
4704
+ if (prepared?.pixels !== arm?.pixels || arm?.pixels !== original?.pixels) preparedWriter = AW.armSplit;
4705
+ }
4706
+ const author = l.tag.startsWith('author:') ? editId(key) : 0;
4707
+ // Split-generated tags retain their actual original run contributors,
4708
+ // never the prepared/split raster as their baseline. arm_split copies
4709
+ // hand layers in input order; the merged-arm split inherits that source.
4710
+ const splitTag = /^(handwear|drape|hand)-[rl]$/.test(l.tag);
4711
+ const parentTag = l.tag.replace(/^(drape|hand)-/, 'handwear-');
4712
+ const sourceLayers = run === 'full' && splitTag && preparedWriter === AW.armSplit
4713
+ ? input.armSplit === undefined ? fullPadded.layers.filter(q => q.name === parentTag) : fullPadded.layers.filter(q => q.name === 'handwear-r' || q.name === 'handwear-l')
4714
+ : original === undefined ? [] : [original];
4715
+ let raw: Raster | null = null;
4716
+ if (author === 0 && sourceLayers.length > 0) {
4717
+ // A sole layer needs no composite copy: layerToRig premultiplies,
4718
+ // so discarded RGB at alpha 0 has exactly the same float32 input.
4719
+ const canvas = sourceLayers.length === 1 ? placeLayer(sourceLayers[0], input.resolution) : newRaster(input.resolution, input.resolution);
4720
+ if (sourceLayers.length > 1) for (const originalLayer of sourceLayers) {
4721
+ const sourceCanvas = placeLayer(originalLayer, input.resolution);
4722
+ for (let p = 0; p < input.resolution * input.resolution; p++) if (sourceCanvas.data[p * 4 + 3] > 0) canvas.data.set(sourceCanvas.data.subarray(p * 4, p * 4 + 4), p * 4);
4723
+ }
4724
+ raw = layerToRig(canvas, frame, run);
4725
+ }
4726
+ // Reuse only a proved identical placed input, never wrapper identity.
4727
+ const samePlacedSource = raw !== null && sourceLayers.length === 1 && prepared !== undefined &&
4728
+ sourceLayers[0].pixels === prepared.pixels && sourceLayers[0].left === prepared.left && sourceLayers[0].top === prepared.top;
4729
+ const preparedRig = samePlacedSource ? raw : prepared === undefined ? null : layerToRig(placeLayer(prepared, input.resolution), frame, run);
4730
+ for (let p = 0; p < W * H; p++) {
4731
+ if (rigLayers[i].data[p * 4 + 3] === 0) continue;
4732
+ ids[p] = author;
4733
+ if (preparedWriter !== 0 && (raw === null || preparedRig !== null && !rgbaEqual(raw.data, p * 4, preparedRig.data, p * 4))) ids[p] = preparedWriter;
4734
+ if (preparedRig !== null && !rgbaEqual(preparedRig.data, p * 4, rigLayers[i].data, p * 4)) ids[p] = AW.ghostCleanup;
4735
+ }
4736
+ // Keep only samples that could equal a final opaque pixel; full raw and
4737
+ // prepared normalization temporaries end with this layer's callback.
4738
+ valueBaselines.set(key, raw === null ? null : compactValueBaseline(raw));
4739
+ return ids;
4740
+ });
4741
+ const st = projectSource(rigLayers, srcr, frame, run, projectRule, rank, keep, (i, p) => { if (writes[i] !== null) (writes[i] as Int32Array)[p] = AW.sourceProjection; });
4742
+ writes.forEach((ids, i) => { if (ids !== null) layerWriters.set(`${run}:${layers[i].tag}`, ids); });
4743
+ writes.length = 0;
4628
4744
  layers.forEach((l, i) => {
4629
4745
  rig.set(`${run}:${l.tag}`, rigLayers[i]);
4630
4746
  stats.set(`${run}:${l.tag}`, st[i]);
@@ -4754,6 +4870,7 @@ export function assemble(input: AssembleInput): AssembleResult {
4754
4870
  const extendKeys = extend.filter((e) => e.part === name).map((e) => `${e.run}:${e.tag}`);
4755
4871
  const extras = extendKeys.map((k) => rig.get(k) as Raster);
4756
4872
  let merged = 0;
4873
+ const writers = (layerWriters.get(key) as Int32Array).slice();
4757
4874
  const trace: MergeTrace = { from: new Int32Array(W * H).fill(-1), ring: newMask(W, H) };
4758
4875
  if (extras.length > 0) {
4759
4876
  const front = newMask(W, H);
@@ -4761,7 +4878,7 @@ export function assemble(input: AssembleInput): AssembleResult {
4761
4878
  const f = rig.get(`${run2}:${tag2}`) as Raster;
4762
4879
  for (let p = 0; p < W * H; p++) if (f.data[p * 4 + 3] >= FRONT_ALPHA) front.data[p] = 1;
4763
4880
  }
4764
- merged = mergeBelowCrop(r, extras, front, srcr, frame.headBottom, trace);
4881
+ merged = mergeBelowCrop(r, extras, front, srcr, frame.headBottom, trace, (p, stage) => { writers[p] = AW[stage]; });
4765
4882
  }
4766
4883
  const { x1, opaque } = measureBox(r);
4767
4884
  if (opaque === 0) {
@@ -4772,7 +4889,7 @@ export function assemble(input: AssembleInput): AssembleResult {
4772
4889
  });
4773
4890
  return null;
4774
4891
  }
4775
- return { key, r, st, extendKeys, trace, merged, region: null };
4892
+ return { key, r, st, extendKeys, trace, merged, region: null, writers };
4776
4893
  };
4777
4894
  plan.forEach(([name, run, tag], pi) => { built[pi] = buildSource(name, run, tag, pi); });
4778
4895
  // Snapshot independent piece pixels before any parent's subtraction or under fill.
@@ -4781,6 +4898,9 @@ export function assemble(input: AssembleInput): AssembleResult {
4781
4898
  const row = plan[pi], tag = input.cutLayers?.get(c.into);
4782
4899
  return tag === undefined ? null : buildSource(c.from, row[1], tag, pi);
4783
4900
  });
4901
+ // Every Built owns its writer slice. No source-map lookup follows this
4902
+ // last cut-layer build; drop originals before cut/limb working sets grow.
4903
+ layerWriters.clear();
4784
4904
  const silhouette = seamRule === 'silhouette' || patches.some((q) => q.alpha === 'silhouette') ? figureSilhouette(srcr) : null;
4785
4905
  const cut = patches.map((q, i) => {
4786
4906
  const c = cutPatch(q, srcr, silhouette);
@@ -4842,7 +4962,9 @@ export function assemble(input: AssembleInput): AssembleResult {
4842
4962
  if (band.data[p] === 1) nb++;
4843
4963
  }
4844
4964
  }
4845
- pieces[i] = { ...b, r, region: m, merged: mergedIn(b, m) };
4965
+ const writers = (b.writers as Int32Array).slice();
4966
+ // A retained base band is not written: it keeps its earlier writer.
4967
+ pieces[i] = { ...b, r, writers, region: m, merged: mergedIn(b, m) };
4846
4968
  bands.push(nb);
4847
4969
  return n;
4848
4970
  });
@@ -4891,6 +5013,10 @@ export function assemble(input: AssembleInput): AssembleResult {
4891
5013
  // Filled where the image is at least as opaque as the layer was; left empty elsewhere (`fillUnder`).
4892
5014
  // With under_fill "colour" (issue #360) a filled pixel keeps the alpha the cut removed and takes the image's colour only.
4893
5015
  const f = fillUnder(b.r, (pieces[i] as Built).r, cutBand(cutMasks[i], cuts[i].overlap), u, underBox(cuts[i].polygon), cuts[i].under_fill);
5016
+ const band = cutBand(cutMasks[i], cuts[i].overlap);
5017
+ let opaqueFilled = 0;
5018
+ // The under operation wrote only removed pixels it actually filled.
5019
+ for (let p = 0; p < W * H; p++) if (cutMasks[i].data[p] === 1 && band.data[p] === 0 && (pieces[i] as Built).r.data[p * 4 + 3] > 0 && b.r.data[p * 4 + 3] > 0) { (b.writers as Int32Array)[p] = cutIds[i]; if (b.r.data[p * 4 + 3] > OPAQUE_ALPHA_ABOVE) opaqueFilled++; }
4894
5020
  // A hidden-art layer (issue #359) is the whole layer's covered art, read by every cut of its part: a cut it holds nothing
4895
5021
  // under fills 0, which the cut line counts, and is not refused as a file made for this one cut would be.
4896
5022
  if (f.filled === 0 && input.cuts[i].under !== undefined) {
@@ -4900,13 +5026,14 @@ export function assemble(input: AssembleInput): AssembleResult {
4900
5026
  detail: `${cuts[i].under} fills 0 of the ${f.empty} pixel(s) the cut removed from "${name}": at every one its alpha is below the alpha removed (an all-transparent image, or another file); an image that fills at least one is required — to leave the whole hole, drop under`,
4901
5027
  });
4902
5028
  }
4903
- return f;
5029
+ return { ...f, opaqueFilled };
4904
5030
  });
4905
5031
  mine.forEach((i, k) => {
4906
5032
  const c: CutCount = { from: name, into: cuts[i].into, before, kept, taken: taken[k], band: bands[k] };
4907
5033
  const f = filled[k];
4908
5034
  if (f !== undefined) {
4909
5035
  c.under = f.filled;
5036
+ c.underOpaque = f.opaqueFilled;
4910
5037
  c.underEmpty = f.empty;
4911
5038
  if (cuts[i].under_fill === 'colour') c.underFill = 'colour';
4912
5039
  }
@@ -4920,7 +5047,8 @@ export function assemble(input: AssembleInput): AssembleResult {
4920
5047
  const m = cutMasks[i], r = newRaster(W, H);
4921
5048
  for (let p = 0; p < W * H; p++) if (m.data[p] === 1) r.data.set(source.r.data.subarray(p * 4, p * 4 + 4), p * 4);
4922
5049
  if (opaqueOf(r) === 0) empty.push({ code: 'ASSEMBLE_CUT_PIXELS', object: `config.assemble.cuts[${i}] (part "${cuts[i].into}")`, detail: `takes 0 opaque pixels from selected ${source.key}; draw its polygon over that layer's art` });
4923
- pieces[i] = { ...source, r, region: m, merged: mergedIn(source, m) };
5050
+ const writers = (source.writers as Int32Array).slice();
5051
+ pieces[i] = { ...source, r, writers, region: m, merged: mergedIn(source, m) };
4924
5052
  });
4925
5053
  refuseIfAny(empty);
4926
5054
  // In cut order, as the config lists them.
@@ -5043,15 +5171,18 @@ export function assemble(input: AssembleInput): AssembleResult {
5043
5171
  });
5044
5172
  const featheredInOrder: Array<Mask | null> = order.map((d) => ('patch' in d ? null : (pieceAt(d).b.feathered ?? null)));
5045
5173
  const keepInOrder = order.map((d) => ('limb' in d ? limbKeep[d.limb] : null));
5046
- const pushedBy = pushBackFringe(stack, srcr, seamRule, seamRule === 'silhouette' ? silhouette : null, featheredInOrder, keepInOrder, input.turnMovingPair ?? null);
5174
+ const patchWriters = patches.map((_, i) => new Int32Array(W * H).fill(patchIds[i]));
5175
+ const writersInOrder = order.map(d => 'patch' in d ? patchWriters[d.patch] : pieceAt(d).b.writers as Int32Array);
5176
+ const pushedBy = pushBackFringe(stack, srcr, seamRule, seamRule === 'silhouette' ? silhouette : null, featheredInOrder, keepInOrder, input.turnMovingPair ?? null, (i, p) => { writersInOrder[i][p] = AW.fringeRestore; });
5047
5177
  // Issue #255: a part's drift refusals in a body, and who holds the body in the draw order (the push-back clears
5048
- // only fringe below CORE_ALPHA, and the seam override only recolours, so the holders read here are final).
5178
+ // only fringe below CORE_ALPHA; these are the holders before the opt-in yield, and the seam override only recolours).
5049
5179
  const holderAt = new Int32Array(W * H).fill(-1);
5050
5180
  stack.forEach(({ image }, i) => {
5051
5181
  for (let p = 0; p < W * H; p++) if (image.data[p * 4 + 3] >= CORE_ALPHA) holderAt[p] = i;
5052
5182
  });
5053
5183
  const stackNames = stack.map((q) => q.record.name);
5054
5184
  const drift: DriftBodies[] = [];
5185
+ const yields = new Map<string, { mask: Mask; reading: DriftYieldReading }>();
5055
5186
  order.forEach((d, orderIdx) => {
5056
5187
  if ('patch' in d) return;
5057
5188
  const { name, b } = pieceAt(d);
@@ -5063,6 +5194,9 @@ export function assemble(input: AssembleInput): AssembleResult {
5063
5194
  const under = stack[j].image.data;
5064
5195
  for (let p = 0; p < W * H; p++) {
5065
5196
  if (under[p * 4 + 3] < CORE_ALPHA) continue;
5197
+ // The opt-in resolves the actual exposed opaque holder before comparing its colour.
5198
+ // Keep the legacy matching-holder diagnostic unchanged when the setting is off.
5199
+ if (input.yieldRefused === true) { behindAt[p] = j; continue; }
5066
5200
  const dMax = Math.max(
5067
5201
  Math.abs(under[p * 4] - srcr.data[p * 4]),
5068
5202
  Math.abs(under[p * 4 + 1] - srcr.data[p * 4 + 1]),
@@ -5071,9 +5205,59 @@ export function assemble(input: AssembleInput): AssembleResult {
5071
5205
  if (dMax <= DRIFT_LIMIT) behindAt[p] = j;
5072
5206
  }
5073
5207
  }
5074
- const found = driftBodies(name, b.key, refused, bodyMinPx(frame), holderAt, stackNames, behindAt);
5208
+ if (input.yieldRefused === true) {
5209
+ for (let p = 0; p < W * H; p++) {
5210
+ if (behindAt[p] < 0) continue;
5211
+ const under = stack[behindAt[p]].image.data;
5212
+ const dMax = Math.max(
5213
+ Math.abs(under[p * 4] - srcr.data[p * 4]),
5214
+ Math.abs(under[p * 4 + 1] - srcr.data[p * 4 + 1]),
5215
+ Math.abs(under[p * 4 + 2] - srcr.data[p * 4 + 2]),
5216
+ );
5217
+ if (dMax > DRIFT_LIMIT) behindAt[p] = -1;
5218
+ }
5219
+ }
5220
+ // The refusal belongs to b.key. A copied/ring replacement cannot inherit that source's refusal.
5221
+ // "Front" is relative to behindAt, not the fixed global top holder: another run may cover this source.
5222
+ let yielded = 0;
5223
+ if (input.yieldRefused === true) {
5224
+ const mask = newMask(W, H);
5225
+ const reading: DriftYieldReading = { part: name, from: b.key, refusedCandidates: 0, yielded: 0, yieldedTaken: 0, skipped: { merge: 0, ring: 0, notOpaque: 0, noMatchingBehind: 0 }, originalGlobalHolderWouldSkip: 0, originalHolders: [], finalHolders: [] };
5226
+ const holders = new Map<string | null, number>();
5227
+ for (let p = 0; p < W * H; p++) {
5228
+ if (refused.data[p] !== 1) continue;
5229
+ reading.refusedCandidates++;
5230
+ if (b.trace.from[p] >= 0) { reading.skipped.merge++; continue; }
5231
+ if (b.trace.ring.data[p] !== 0) { reading.skipped.ring++; continue; }
5232
+ if (b.r.data[p * 4 + 3] < CORE_ALPHA) { reading.skipped.notOpaque++; continue; }
5233
+ if (behindAt[p] < 0) { reading.skipped.noMatchingBehind++; continue; }
5234
+ if (holderAt[p] !== orderIdx) reading.originalGlobalHolderWouldSkip++;
5235
+ const holder = holderAt[p] < 0 ? null : stackNames[holderAt[p]];
5236
+ holders.set(holder, (holders.get(holder) ?? 0) + 1);
5237
+ mask.data[p] = 1;
5238
+ if (b.st.takenMask.data[p] === 1) reading.yieldedTaken++;
5239
+ b.r.data[p * 4 + 3] = 0;
5240
+ yielded++;
5241
+ }
5242
+ reading.yielded = yielded;
5243
+ reading.originalHolders = [...holders].map(([part, px]) => ({ part, px }));
5244
+ yields.set(name, { mask, reading });
5245
+ }
5246
+ const found = driftBodies(name, b.key, refused, bodyMinPx(frame), holderAt, stackNames, behindAt, input.yieldRefused === true ? yielded : undefined);
5075
5247
  if (found !== null) drift.push(found);
5076
5248
  });
5249
+ if (input.yieldRefused === true) {
5250
+ const finalAt = new Int32Array(W * H).fill(-1);
5251
+ stack.forEach(({ image }, i) => { for (let p = 0; p < W * H; p++) if (image.data[p * 4 + 3] >= CORE_ALPHA) finalAt[p] = i; });
5252
+ for (const { mask, reading } of yields.values()) {
5253
+ const holders = new Map<string | null, number>();
5254
+ for (let p = 0; p < W * H; p++) if (mask.data[p] === 1) {
5255
+ const part = finalAt[p] < 0 ? null : stackNames[finalAt[p]];
5256
+ holders.set(part, (holders.get(part) ?? 0) + 1);
5257
+ }
5258
+ reading.finalHolders = [...holders].map(([part, px]) => ({ part, px }));
5259
+ }
5260
+ }
5077
5261
  const pushedOf: FringePushed[][] = plan.map(() => []);
5078
5262
  const pushedOfCut: FringePushed[][] = cuts.map(() => []);
5079
5263
  const pushedOfLimb: FringePushed[][] = lim.parts.map(() => []);
@@ -5109,7 +5293,7 @@ export function assemble(input: AssembleInput): AssembleResult {
5109
5293
  const own = e < 0 ? st : (stats.get(extendKeys[e]) as ProjectionStats);
5110
5294
  // A pixel outside the piece's region is a base pixel filled from a cut's under image (issue #193): occluded, never visible.
5111
5295
  if (r.data[p * 4 + 3] > OPAQUE_ALPHA_ABOVE && own.clear.data[p] === 1 && (region === null || region.data[p] === 1)) visible.data[p] = 1;
5112
- if (trace.ring.data[p] === 0 && own.takenMask.data[p] === 1 && (region === null || region.data[p] === 1)) projected.data[p] = 1;
5296
+ if (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;
5113
5297
  }
5114
5298
  const { x0, y0, x1, y1, opaque } = measureBox(r);
5115
5299
  if (opaque === 0) {
@@ -5134,7 +5318,7 @@ export function assemble(input: AssembleInput): AssembleResult {
5134
5318
  visible_px: vc.visible_px,
5135
5319
  occluded_px: vc.occluded_px,
5136
5320
  projected_core_px: region === null ? st.core : count(st.coreMask, region),
5137
- source_px_taken: region === null ? st.taken : count(st.takenMask, region),
5321
+ source_px_taken: (region === null ? st.taken : count(st.takenMask, region)) - (yields.get(name)?.reading.yieldedTaken ?? 0),
5138
5322
  visible_not_projected_px: vc.visible_not_projected_px,
5139
5323
  refused_drift_px: region === null ? st.refused : count(st.refusedMask, region),
5140
5324
  merged_px: merged,
@@ -5167,7 +5351,14 @@ export function assemble(input: AssembleInput): AssembleResult {
5167
5351
  for (const p of placed) if (p.record.depth !== undefined && artFiles.has(p.record.depth.image)) refuseIfAny([{ code: 'DEPTH_SHEET_UNAMBIGUOUS', object: p.record.depth.image, detail: 'collides with a part artwork filename; choose noncolliding part names before sheet emission' }]);
5168
5352
 
5169
5353
 
5170
- seamOverride(placed, srcr, seamRule, seamRule === 'silhouette' ? silhouette : null, keepInOrder, input.turnMovingPair ?? null);
5354
+ seamOverride(placed, srcr, seamRule, seamRule === 'silhouette' ? silhouette : null, keepInOrder, input.turnMovingPair ?? null, (i, p) => { writersInOrder[i][p] = AW.seamOverride; });
5355
+ placed.forEach((p, i) => { p.record.provenance = pixelProvenance(p.image, p.record.x, p.record.y, W, writersInOrder[i], editNames, 0, valueBaselines.get(p.record.from) ?? null); });
5356
+ // Provenance is now numbers/labels only. No later raster/figure operation
5357
+ // reads report buffers; release all aliases before recomposite/error work.
5358
+ valueBaselines.clear();
5359
+ writersInOrder.length = 0;
5360
+ patchWriters.length = 0;
5361
+ for (const group of [built, pieces, cutSources, limbPieces]) for (const b of group) if (b !== null) b.writers = undefined;
5171
5362
  const can = recomposite(placed, W, H);
5172
5363
  // Issue #242: on a scene painting the figure is read off the full run, and every recomposite figure inside it.
5173
5364
  const inside = input.scene === true ? sceneFigure([...rig.entries()].filter(([k]) => k.startsWith('full:')).map(([, r]) => r), W, H) : null;
@@ -5197,6 +5388,9 @@ export function assemble(input: AssembleInput): AssembleResult {
5197
5388
  scale_rig_per_source: frame.S,
5198
5389
  ...(input.motion_seams === undefined ? {} : { motion_seams: input.motion_seams.map(({ part, neighbour }) => ({ part, neighbour })) }),
5199
5390
  parts: placed.map((p) => p.record),
5391
+ ...(cutCounts.length === 0 ? {} : { cut_ownership: cutCounts.map((c, i) => ({ edit: `cuts[${i}]`, from: c.from, into: c.into, moved_in_opaque_px: c.taken,
5392
+ retained_band_opaque_px: c.band, cleared_opaque_px: c.taken - c.band, under_filled_px: c.under ?? 0,
5393
+ under_filled_opaque_px: c.underOpaque ?? 0, net_cleared_opaque_px: c.taken - c.band - (c.underOpaque ?? 0) })) }),
5200
5394
  ghost_px: ghost,
5201
5395
  recomposite: recompositeRecord(figures),
5202
5396
  ...(sceneRecord === null ? {} : { scene: sceneRecord }),
@@ -5213,6 +5407,7 @@ export function assemble(input: AssembleInput): AssembleResult {
5213
5407
  uncovered,
5214
5408
  holeKinds: kinds,
5215
5409
  drift,
5410
+ ...(input.yieldRefused === true ? { yieldReadings: [...yields.values()].map(q => q.reading) } : {}),
5216
5411
  hidden: [...hiddenUses].map(([layer, readBy]) => ({ layer, readBy })),
5217
5412
  seamRule,
5218
5413
  projectRule,
@@ -5235,6 +5430,8 @@ export interface DriftBodies {
5235
5430
  from: string;
5236
5431
  /** The part's `refused_drift_px`, in a body or not. */
5237
5432
  refusedPx: number;
5433
+ /** Original refused front pixels cleared under the opt-in; absent when it is off. */
5434
+ yieldedPx?: number;
5238
5435
  /** The bar the bodies were held to (`bodyMinPx`, the uncovered line's). */
5239
5436
  minPx: number;
5240
5437
  /** The bodies, largest first (`bodiesOf`). */
@@ -5269,15 +5466,15 @@ export interface DriftBodies {
5269
5466
  * holder. `behindAt` (optional) is, per rig pixel, the index into `names` of
5270
5467
  * the top-most part drawn behind `part` at alpha >= `CORE_ALPHA` whose colour
5271
5468
  * is within `DRIFT_LIMIT` of the painting (-1: none). The result is non-null
5272
- * exactly when the bodies hold a pixel whose holder is another part or whose
5469
+ * also retained for a nonzero opt-in `yieldedPx`, including refusals smaller than the body bar; otherwise exactly when the bodies hold a pixel whose holder is another part or whose
5273
5470
  * `behindAt` names a part drawn behind `part` that matches the painting.
5274
5471
  */
5275
- export function driftBodies(part: string, from: string, refused: Mask, minPx: number, holderAt: Int32Array, names: readonly string[], behindAt?: Int32Array): DriftBodies | null {
5472
+ export function driftBodies(part: string, from: string, refused: Mask, minPx: number, holderAt: Int32Array, names: readonly string[], behindAt?: Int32Array, yieldedPx?: number): DriftBodies | null {
5276
5473
  let refusedPx = 0;
5277
5474
  for (let p = 0; p < refused.data.length; p++) refusedPx += refused.data[p];
5278
5475
  if (refusedPx === 0) return null;
5279
5476
  const { bodies, pixels } = bodiesWithPixels(refused, minPx);
5280
- if (bodies.length === 0) return null;
5477
+ if (bodies.length === 0 && (yieldedPx ?? 0) === 0) return null;
5281
5478
  const count = new Map<string, number>();
5282
5479
  const behindCount = new Map<string, number>();
5283
5480
  for (let p = 0; p < pixels.data.length; p++) {
@@ -5292,10 +5489,10 @@ export function driftBodies(part: string, from: string, refused: Mask, minPx: nu
5292
5489
  }
5293
5490
  }
5294
5491
  const hasFront = [...count.keys()].some((n) => n !== part);
5295
- if (!hasFront && behindCount.size === 0) return null;
5492
+ if (!hasFront && behindCount.size === 0 && (yieldedPx ?? 0) === 0) return null;
5296
5493
  const holders = [...count.entries()].map(([q, px]) => ({ part: q, px })).sort((a, b) => b.px - a.px || (a.part < b.part ? -1 : a.part > b.part ? 1 : 0));
5297
5494
  const behind = [...behindCount.entries()].map(([q, px]) => ({ part: q, px })).sort((a, b) => b.px - a.px || (a.part < b.part ? -1 : a.part > b.part ? 1 : 0));
5298
- return { part, from, refusedPx, minPx, bodies, holders, ...(behind.length > 0 ? { behind } : {}) };
5495
+ return { part, from, refusedPx, minPx, bodies, holders, ...(behind.length > 0 ? { behind } : {}), ...(yieldedPx === undefined ? {} : { yieldedPx }) };
5299
5496
  }
5300
5497
 
5301
5498
  /**
@@ -5317,7 +5514,7 @@ export function driftBodies(part: string, from: string, refused: Mask, minPx: nu
5317
5514
  export function driftLine(d: DriftBodies): string {
5318
5515
  const total = d.bodies.reduce((a, b) => a + b.px, 0);
5319
5516
  const big = d.bodies[0];
5320
- const held = d.bodies.length > 1 ? `${d.bodies.length} bodies of ${total} px, the largest ${big.px} px at ${bodyBox(big)}` : `a body of ${big.px} px at ${bodyBox(big)}`;
5517
+ const held = d.bodies.length === 0 ? 'no body at this bar' : d.bodies.length > 1 ? `${d.bodies.length} bodies of ${total} px, the largest ${big.px} px at ${bodyBox(big)}` : `a body of ${big.px} px at ${bodyBox(big)}`;
5321
5518
  const others = d.holders.filter((h) => h.part !== d.part).map((h) => `"${h.part}"`);
5322
5519
  const frontClause = others.length > 0 ? `, ${others.join(', ')} drawn in front of "${d.part}"` : '';
5323
5520
  const behindClause =
@@ -5327,7 +5524,10 @@ export function driftLine(d: DriftBodies): string {
5327
5524
  return (
5328
5525
  `drift: "${d.part}" refuses ${d.refusedPx} px of ${d.from} (its colour more than ${DRIFT_LIMIT} off the painting, max channel), in ${held} (at least ${fmtPx(d.minPx)} px past a ${BODY_KERNEL}x${BODY_KERNEL} opening); ` +
5329
5526
  `by the plan's draw order ${d.holders.map((h) => `"${h.part}" holds ${h.px} px`).join(', ')} of it (the top-most part at alpha >= ${CORE_ALPHA})${frontClause}${behindClause}; ` +
5330
- "informational: no gate reads this. Swapping the plan order of the parts named here can clear it (when only the front one differs from the painting) or move it to the other part (when both do): swap, rebuild and read this line again; if it moves, removing it needs different input layers. At rest, the seam pass repaints the holder's pixels that pass its rule from the painting"
5527
+ "informational: no gate reads this. Swapping the plan order of the parts named here can clear it (when only the front one differs from the painting) or move it to the other part (when both do): swap, rebuild and read this line again; if it moves, removing it needs different input layers. At rest, the seam pass repaints the holder's pixels that pass its rule from the painting" +
5528
+ (d.yieldedPx === undefined
5529
+ ? '; set assemble.yield_refused: true to yield original refused front pixels only where the top-most opaque behind holder matches the painting, before considering a cut'
5530
+ : `; yielded ${d.yieldedPx} px to top-most opaque behind holders matching the painting (assemble.yield_refused: true; alpha only)`)
5331
5531
  );
5332
5532
  }
5333
5533
 
@@ -5992,6 +6192,8 @@ export function stageFields(
5992
6192
  armSplit?: ArmSplit;
5993
6193
  keySkeleton?: ControlSkeleton;
5994
6194
  headFaceUnderfill?: boolean;
6195
+ /** `assemble.yield_refused`, default false; alpha-only ownership transfer from original refused core pixels. */
6196
+ yieldRefused?: boolean;
5995
6197
  turnMovingPair?: (a: string, b: string) => boolean;
5996
6198
  } {
5997
6199
  const problems: Problem[] = [];
@@ -6012,6 +6214,7 @@ export function stageFields(
6012
6214
  ...(st.arm_split === undefined ? {} : { armSplit: st.arm_split }),
6013
6215
  ...(keySkeleton === undefined ? {} : { keySkeleton }),
6014
6216
  ...(cfg.assemble.head_face_underfill === undefined ? {} : { headFaceUnderfill: cfg.assemble.head_face_underfill }),
6217
+ ...(cfg.assemble.yield_refused === undefined ? {} : { yieldRefused: cfg.assemble.yield_refused }),
6015
6218
  ...(turnMovingPair === null ? {} : { turnMovingPair }),
6016
6219
  rigScale: cfg.assemble.rig_scale,
6017
6220
  plan: cfg.assemble.plan,
package/src/build.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ownershipLines, provenanceLines } from './provenance.ts';
1
2
  import { readSourceDepth } from './depthsheets.ts';
2
3
  import { orderedBaseAnchor } from './baseanchor.ts';
3
4
  import { alternateLayerSources, alternateLayerIslands, alternateLayerOthers } from './alternatelayers.ts';
@@ -659,6 +660,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
659
660
  ...(fields.scene === undefined ? {} : { scene: fields.scene }),
660
661
  ...(fields.armSplit !== undefined && altPlan.some((e) => e[1] === 'full' && (e[2] === 'handwear-r' || e[2] === 'handwear-l')) ? { armSplit: fields.armSplit } : {}),
661
662
  ...(fields.headFaceUnderfill === undefined ? {} : { headFaceUnderfill: fields.headFaceUnderfill }),
663
+ ...(fields.yieldRefused === undefined ? {} : { yieldRefused: fields.yieldRefused }),
662
664
  ...(fields.turnMovingPair === undefined ? {} : { turnMovingPair: fields.turnMovingPair }),
663
665
  seamRule: input.seam,
664
666
  projectRule: input.project,
@@ -704,6 +706,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
704
706
  ...(altFront.size === 0 ? {} : { front: [...altFront] }),
705
707
  slots,
706
708
  records: keptRecords,
709
+ ...(altRes.parts.cut_ownership === undefined ? {} : { cut_ownership: altRes.parts.cut_ownership }),
707
710
  ghost_px: altRes.parts.ghost_px,
708
711
  recomposite: altRecomposite,
709
712
  ...(altRes.parts.scene === undefined ? {} : { scene: altRes.parts.scene }),
@@ -781,6 +784,9 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
781
784
  `unproj=${String(p.visible_not_projected_px).padStart(5)} drift=${String(p.refused_drift_px).padStart(5)} ${driftShare(p.refused_drift_px, p.projected_core_px)} merged=${p.merged_px} seam=${p.seam_override_px}${underfillSuffix}`,
782
785
  );
783
786
  }
787
+ for (const line of provenanceLines(result.parts.parts)) log(line);
788
+ for (const line of ownershipLines(result.parts.cut_ownership ?? [])) log(line);
789
+ for (const alt of altBuilt) for (const line of [...provenanceLines(alt.record.records), ...ownershipLines(alt.record.cut_ownership ?? [])]) log(` set "${alt.record.name}" ${line.trimStart()}`);
784
790
  // Issue #256: one line per part from an author-made layer, so it never reads as See-through's. None without one.
785
791
  for (const l of authorPartLines(result.parts.parts)) log(l);
786
792
  // One line per plan part an assemble.cuts entry cut, before the fringe lines: the cut is made first. None without cuts.