spine-parts 2.13.0 → 2.14.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 CHANGED
@@ -875,6 +875,9 @@ Final recomposite and error measurements use those retained parts together with
875
875
  the taken targets. The counterfactual is never written. A take adds this extra
876
876
  assembly evaluation. Builds without region takes follow the existing single
877
877
  assembly path. Target filter halos are reported separately and have no bar.
878
+ The core-mode guard bounds projection-first changes by the exact warp-tap footprint dilated by the erosion reach plus both closing-pass reaches from `CORE_KERNEL` plus the Gaussian reach from `FEATHER_SIGMA`, and every other first writer by the footprint itself.
879
+ The current generated controls' observed projection-first changes remain within the blur support.
880
+ Visible-mode edge plans can change outside a take's exact warp-tap footprint; this is tracked on [#1033](https://github.com/rig-c/parts/issues/1033).
878
881
 
879
882
  No polygon, rectangle or brush input is accepted. A drawn bound is scissors.
880
883
  The log reports the derived pixel count, run-grid `[left, top, width, height]`
@@ -4989,6 +4992,7 @@ row in this page's `rule` and `line` tables; the selftest holds that (`TY16`).
4989
4992
  | <a id="PARTS_HYBRID_PAIR"></a>`PARTS_HYBRID_PAIR` | a rigid joint references a missing or inconsistent generated band | re-run assemble; keep source, joint, carriers and measured geometry together |
4990
4993
  | <a id="RIG_HYBRID_SOURCE"></a>`RIG_HYBRID_SOURCE` | an assembled band no longer matches its config declaration | re-run assemble with the current config |
4991
4994
  | <a id="RIG_HYBRID_RIGID"></a>`RIG_HYBRID_RIGID` | a band neighbour is not a rigid region | attach the upper and lower pieces as regions on their own carriers |
4995
+ | <a id="ASSEMBLE_ALT_FIGURE_MASK_OMITTED"></a>`ASSEMBLE_ALT_FIGURE_MASK_OMITTED` | informational line naming an alternate whose painting file has different bytes from the primary painting, so its assembly omits the primary figure mask | supply the same painting bytes to share the verified declaration; different-painting alternates keep their omitted-mask assembly path |
4992
4996
  | <a id="ASSEMBLE_ALT_TIP_NAME"></a>`ASSEMBLE_ALT_TIP_NAME` | an explicit endpoint names no supplied bone | declare the single bone or expanded link |
4993
4997
  | <a id="ASSEMBLE_ALT_TIP_POINT"></a>`ASSEMBLE_ALT_TIP_POINT` | an explicit endpoint is not finite after normalization onto the accepted rig canvas | correct the source-crop pair and scale |
4994
4998
  | <a id="PARTS_ALT_TIPS"></a>`PARTS_ALT_TIPS` | alternate endpoints are not a non-empty bone-name map of finite rig-crop pairs | re-run assemble with valid source-crop tips |
package/docs/STABILITY.md CHANGED
@@ -556,7 +556,7 @@ The separate ordering scalar is unchanged. No-image outputs retain legacy bytes.
556
556
 
557
557
  | Optional field | Additive contract |
558
558
  | --- | --- |
559
- | `setup_painting.figure_mask` | Verified source-grid alpha support restricts region counts; omission preserves the shipped domain and output bytes. |
559
+ | `setup_painting.figure_mask` | Verified source-grid alpha support restricts region counts and opts busy-ground visible assembly into bounded hole and interior-translucency restoration; omission preserves the shipped domain and output bytes. |
560
560
 
561
561
  The optional `setup_painting.figure_mask` (issue #974, additive) declares a
562
562
  `path` and byte `sha256` for independent figure alpha support on the original
@@ -565,7 +565,13 @@ sampled at nearest source pixel centres onto the stage, with empty support
565
565
  refused. Region limits count only inside that support. Outside-mask uncovered
566
566
  mismatches have their own unbarred stage-wide row. The verified declaration is
567
567
  recorded in the report. Omitting it preserves existing output bytes and the
568
- shipped domain predicate.
568
+ shipped domain predicate. Assemble reads the same requirements declaration through
569
+ the explicit requirements flag or config.requirements. Busy-ground visible
570
+ restoration requires pre-step and assembled four-neighbour support, prefers the
571
+ frontmost pre-step holder, then nearest pre-step owner with frontmost ties.
572
+ Keep, feather, locked and moving-pair boundaries remain excluded. Plain-ground
573
+ assembly keeps its existing path.
574
+ Busy-ground visible assembly validates config.requirements and its flag correspondence, refusing malformed requirements or unverifiable figure masks before writing.
569
575
 
570
576
  The optional `setup_painting` key in `spine-parts-requirements/1` adds a
571
577
  `SETUP_MATCHES_PAINTING` measurement when declared. It requires authored
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spine-parts",
3
- "version": "2.13.0",
3
+ "version": "2.14.0",
4
4
  "description": "AI-authored 2D character parts from one anime painting and its See-through layer decomposition: measured parts, weighted-mesh rig specs, verified through rig-c before anything is written. A CLI for agents that cannot see the image.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/assemble.ts CHANGED
@@ -337,6 +337,8 @@ export interface AssembleInput {
337
337
  projectRule: ProjectRule;
338
338
  /** `config.assemble.ground` (issue #996), read by `paintingEdges` under `visible` only; absent, `plain`. */
339
339
  ground?: Ground;
340
+ /** Verified requirements figure support on the rig grid, for busy visible restoration. */
341
+ declaredFigure?: Mask;
340
342
  /** `config.scene` (issue #242): the painting is a scene, so the recomposite is read inside the figure ({@link sceneFigure}). Absent or false: nothing changes. */
341
343
  scene?: boolean;
342
344
  /** `config.limbs` (issue #349): the parts cut at their joints ({@link LimbCount}). Absent or empty: nothing changes. */
@@ -5735,6 +5737,7 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
5735
5737
  const e = paintingEdges(stack.map(onRig), srcr, {
5736
5738
  painted: supportPainted,
5737
5739
  figure: visibleFigure,
5740
+ ...(input.declaredFigure === undefined ? {} : { declaredFigure: input.declaredFigure }),
5738
5741
  ...(input.ground === undefined ? {} : { ground: input.ground }),
5739
5742
  editable: order.map((d) => !('patch' in d)),
5740
5743
  keep: keepInOrder,
package/src/build.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { readSetupFigureMask } from './setupfiguremask.ts';
1
2
  import { EDGE_RESIDUAL_FILE, edgeResidualLines } from './edgeresidual.ts';
2
3
  import { SUPPORT_DOMAINS_FILE, writeSupportDomains } from './supportdomains.ts';
3
4
  import { COINCIDE_LINE, supportLines } from './coincide.ts';
@@ -340,10 +341,12 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
340
341
  const pinholesAsked = requirementsFile !== null && pinholesRequired(requirementsFile);
341
342
  // The early door: assemble runs before propose has drafted bones, meshes,
342
343
  // regions and motion, so it requires only what it reads (issue #20).
343
- const cfg = loadEarlyConfig(input.config, 'assemble');
344
+ const cfg = loadEarlyConfig(input.config, 'assemble', input.project);
344
345
  const supportDeclarations = JSON.stringify(cfg.assemble.cuts ?? []);
345
346
  const seam = input.seam ?? cfg.assemble.seam ?? DEFAULT_SEAM_RULE;
346
347
  const project = input.project ?? cfg.assemble.project ?? DEFAULT_PROJECT_RULE;
348
+ const requirements = cfg.assemble.ground === 'busy' && project === 'visible'
349
+ ? buildRequirements(input.requirements, cfg.requirements, input.config) : null;
347
350
  const src = readSource(input.source);
348
351
  const read = readRuns(input.full, input.head);
349
352
  // Issue #946: every declared receipt is held to its file, and under `required` every edited image needs one, before anything is assembled.
@@ -354,9 +357,14 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
354
357
  const runs = applyTakenRegions(takenRuns, src, cfg, input.config, requirementsFile?.setup_painting, receipts, input.source);
355
358
  for (const note of runs.notes) log(note.startsWith('WARN ') ? note : `note: ${note}`);
356
359
  const fields = stageFields(cfg, runs.single ? { w: src.width, h: src.height } : null);
360
+ const setupPainting = requirements === null || fields.ground !== 'busy' || project !== 'visible' ? undefined
361
+ : readRequirements(requirements.read).setup_painting;
362
+ const figureSupport = setupPainting === undefined ? undefined
363
+ : readSetupFigureMask(setupPainting, requirements!.read, src, Math.trunc(src.width * fields.rigScale), Math.trunc(src.height * fields.rigScale));
364
+ const declaredFigure = figureSupport === undefined ? undefined : { width: Math.trunc(src.width * fields.rigScale), height: Math.trunc(src.height * fields.rigScale), data: figureSupport };
357
365
  const under = readUnders(input.config, fields.cuts);
358
366
  const caps = fields.limbs === undefined ? undefined : readCaps(input.config, fields.limbs);
359
- const result = assemble({ source: src, full: runs.full, head: runs.head, depth: cfg.depth, depthBase: dirname(resolve(input.config)), ...fields, under,
367
+ const result = assemble({ source: src, full: runs.full, head: runs.head, depth: cfg.depth, depthBase: dirname(resolve(input.config)), ...fields, under, ...(declaredFigure === undefined ? {} : { declaredFigure }),
360
368
  ...((cfg.assemble.take ?? []).some(t => 'part' in t) ? { regionTake: { full: takenRuns.full, head: takenRuns.head, targets: (cfg.assemble.take ?? []).flatMap(t => 'part' in t ? [t.part] : []) } } : {}), ...(caps === undefined ? {} : { caps }), seamRule: seam, projectRule: project });
361
369
 
362
370
  // Issue #454: alternate painting sets, assembled before any file is written.
@@ -422,6 +430,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
422
430
  // Issue #664: each limb segment part with a declared front slot -> the part its front slot follows.
423
431
  const frontAfter = new Map<string, string>();
424
432
  for (const limb of Object.values(fields.limbs ?? {})) for (const p of limb.front?.parts ?? []) frontAfter.set(p, (limb.front as { after: string }).after);
433
+ const primaryPaintingHash = declaredFigure === undefined ? null : createHash('sha256').update(readFileSync(input.source)).digest('hex');
425
434
  for (const alt of mergedAlts) {
426
435
  if (alt.source === undefined || alt.full === undefined) {
427
436
  altProblems.push({
@@ -670,6 +679,16 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
670
679
  : altFront.size === 0
671
680
  ? setExclusions(result.images, exW, exH, altSegParts, replacedSet)
672
681
  : altSegParts.flatMap((sp) => setExclusions(altFront.has(sp) ? frontOrdered(result.images, new Set([sp]), frontAfter) : result.images, exW, exH, [sp], replacedSet));
682
+ const alternateFigure = declaredFigure !== undefined &&
683
+ createHash('sha256').update(readFileSync(alt.source)).digest('hex') === primaryPaintingHash ? declaredFigure : undefined;
684
+ if (declaredFigure !== undefined && alternateFigure === undefined) {
685
+ const notice = {
686
+ code: 'ASSEMBLE_ALT_FIGURE_MASK_OMITTED',
687
+ object: `alternate "${alt.name}"`,
688
+ detail: 'has different painting bytes; the primary figure mask is omitted',
689
+ };
690
+ log(`${notice.code}: ${notice.object} ${notice.detail}`);
691
+ }
673
692
  let altRes: ReturnType<typeof assemble>;
674
693
  try {
675
694
  altRes = assemble({
@@ -697,6 +716,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
697
716
  ...(fields.headFaceUnderfill === undefined ? {} : { headFaceUnderfill: fields.headFaceUnderfill }),
698
717
  ...(fields.yieldRefused === undefined ? {} : { yieldRefused: fields.yieldRefused }),
699
718
  ...(fields.ground === undefined ? {} : { ground: fields.ground }),
719
+ ...(alternateFigure === undefined ? {} : { declaredFigure: alternateFigure }),
700
720
  ...(fields.turnMovingPair === undefined ? {} : { turnMovingPair: fields.turnMovingPair }),
701
721
  ...(fields.turn === undefined ? {} : { turn: fields.turn, regions: fields.regions, meshes: fields.meshes, motion: fields.motion }),
702
722
  seamRule: seam,
package/src/config.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SEAM_RULES, type SeamRule } from './seamrule.ts';
2
- import { GROUNDS, type Ground, PROJECT_RULES, type ProjectRule } from './projectrule.ts';
2
+ import { DEFAULT_PROJECT_RULE, GROUNDS, type Ground, PROJECT_RULES, type ProjectRule } from './projectrule.ts';
3
3
  import type { TakeDeclaration } from './takeregion.ts';
4
4
  import { paintingExtensionProblems, type PaintingExtension } from './paintingextension.ts';
5
5
  import { baseAnchorProblems, type BaseAnchor } from './baseanchor.ts';
@@ -1671,6 +1671,8 @@ export interface EarlyConfig {
1671
1671
 
1672
1672
  /** What plain `assemble` reads: the early config plus the plan `--propose-plan` printed. */
1673
1673
  export interface AssembleConfig {
1674
+ /** Existing requirements declaration, shared by standalone assemble and build. */
1675
+ requirements?: string;
1674
1676
  depth?: DepthConfig;
1675
1677
  key: string;
1676
1678
  seethrough: SeeThrough;
@@ -1719,7 +1721,7 @@ export function parseEarlyConfig(raw: Json, door: EarlyDoor): PaintConfig | Earl
1719
1721
  }
1720
1722
 
1721
1723
  /** The early loader with, when `base` is the config's directory, the pose file `generation.control.skeleton` names read beside it. */
1722
- function parseEarlyConfigFrom(raw: Json, door: EarlyDoor, base: string | null): { config: PaintConfig | EarlyConfig | AssembleConfig; pose: ControlPose | null } {
1724
+ function parseEarlyConfigFrom(raw: Json, door: EarlyDoor, base: string | null, project?: ProjectRule): { config: PaintConfig | EarlyConfig | AssembleConfig; pose: ControlPose | null } {
1723
1725
  const c = new Check();
1724
1726
  // `generation` is taken out of the generic presence check so its absence can
1725
1727
  // say what the block has to hold, rather than only that it is missing.
@@ -1760,6 +1762,9 @@ function parseEarlyConfigFrom(raw: Json, door: EarlyDoor, base: string | null):
1760
1762
  }
1761
1763
  }
1762
1764
  if (door === 'assemble') {
1765
+ const busyVisible = isPlainObject(t.assemble) && t.assemble.ground === 'busy' &&
1766
+ (project ?? t.assemble.project ?? DEFAULT_PROJECT_RULE) === 'visible';
1767
+ if (busyVisible && 'requirements' in t && c.string('config.requirements', t.requirements) && base !== null) checkRequirementsFile(c, configFilePath('requirements', base, t.requirements) as string);
1763
1768
  if ('seethrough' in t) checkSeeThrough(c, t.seethrough);
1764
1769
  const made = 'assemble' in t ? checkAssemble(c, t.assemble, door) : { parts: [], patches: [], cuts: [] };
1765
1770
  checkProposedRigScale(c, t);
@@ -1810,9 +1815,9 @@ function parseEarlyConfigFrom(raw: Json, door: EarlyDoor, base: string | null):
1810
1815
 
1811
1816
  export function loadEarlyConfig(path: string, door: 'paint'): PaintConfig;
1812
1817
  export function loadEarlyConfig(path: string, door: 'layers'): EarlyConfig;
1813
- export function loadEarlyConfig(path: string, door: 'assemble'): AssembleConfig;
1814
- export function loadEarlyConfig(path: string, door: EarlyDoor): PaintConfig | EarlyConfig | AssembleConfig {
1815
- return parseEarlyConfigFrom(readConfigFile(path), door, dirname(resolve(path))).config;
1818
+ export function loadEarlyConfig(path: string, door: 'assemble', project?: ProjectRule): AssembleConfig;
1819
+ export function loadEarlyConfig(path: string, door: EarlyDoor, project?: ProjectRule): PaintConfig | EarlyConfig | AssembleConfig {
1820
+ return parseEarlyConfigFrom(readConfigFile(path), door, dirname(resolve(path)), project).config;
1816
1821
  }
1817
1822
 
1818
1823
  /**
@@ -175,6 +175,8 @@ export interface PaintingEdgeOptions {
175
175
  painted: Uint8Array;
176
176
  /** Canonical painted figure domain for completing allocated gaps and interior translucency. */
177
177
  figure?: Mask;
178
+ /** Independently declared support, consumed only on busy ground. */
179
+ declaredFigure?: Mask;
178
180
  /** Per part: whether the step may write it (false for a painting patch). */
179
181
  editable: readonly boolean[];
180
182
  keep?: ReadonlyArray<Mask | null>;
@@ -257,6 +259,12 @@ export function paintingEdges(parts: Raster[], srcr: Raster, options: PaintingEd
257
259
  const R = EDGE_RADIUS;
258
260
  const cap = 2 * R + 2;
259
261
  const busy = options.ground === 'busy';
262
+ const declaredFigure = busy ? options.declaredFigure : undefined;
263
+ const preSupport = declaredFigure === undefined ? undefined : parts.map(part => {
264
+ const support = new Uint8Array(W * H);
265
+ for (let p = 0; p < W * H; p++) support[p] = part.data[p * 4 + 3] > 0 ? 1 : 0;
266
+ return support;
267
+ });
260
268
  /** A part's support before the step: where its own alpha is above 0. */
261
269
  const supports = (i: number, p: number): boolean => parts[i].data[p * 4 + 3] > 0;
262
270
  const owner = new Int16Array(W * H).fill(-1);
@@ -674,6 +682,39 @@ export function paintingEdges(parts: Raster[], srcr: Raster, options: PaintingEd
674
682
  }
675
683
  }
676
684
  }
685
+ // Busy restoration reads frozen pre-step support and pre-restoration art.
686
+ // Neither owner allocation nor a newly restored pixel supplies a witness.
687
+ if (declaredFigure !== undefined && preSupport !== undefined) {
688
+ for (let p = 0; p < W * H; p++) {
689
+ if (declaredFigure.data[p] !== 1 || srcr.data[p * 4 + 3] === 0 || locked[p] === 1 ||
690
+ options.keep?.some(m => m?.data[p] === 1) || options.feathered?.some(m => m?.data[p] === 1)) continue;
691
+ const x = p % W;
692
+ const neighbours = [
693
+ ...(x > 0 ? [p - 1] : []), ...(x + 1 < W ? [p + 1] : []),
694
+ ...(p >= W ? [p - W] : []), ...(p + W < W * H ? [p + W] : []),
695
+ ];
696
+ let alpha = 0;
697
+ for (const part of parts) {
698
+ const a = part.data[p * 4 + 3];
699
+ const t = a * 255 + alpha * (255 - a) + 128;
700
+ alpha = ((t >>> 8) + t) >>> 8;
701
+ }
702
+ if (alpha >= 128 || (alpha > 0 && (neighbours.length !== 4 ||
703
+ !neighbours.every(q => declaredFigure.data[q] === 1 && srcr.data[q * 4 + 3] > 0)))) continue;
704
+ const qualifies = (k: number): boolean => options.editable[k] &&
705
+ neighbours.some(q => preSupport[k][q] === 1) && neighbours.some(q => parts[k].data[q * 4 + 3] > 0);
706
+ let front = -1;
707
+ let distance = cap;
708
+ for (let k = n - 1; k >= 0; k--) {
709
+ if (!qualifies(k)) continue;
710
+ if (preSupport[k][p] === 1) { front = k; break; }
711
+ if (near[k][p] < distance) { front = k; distance = near[k][p]; }
712
+ }
713
+ if (front < 0 || parts.some((part, k) => k !== front &&
714
+ (preSupport[k][p] === 1 || part.data[p * 4 + 3] > 0) && options.movingPair?.(front, k) === true)) continue;
715
+ restore.push([p, front]);
716
+ }
717
+ }
677
718
  for (const [p, front] of restore) {
678
719
  const s = p * 4;
679
720
  parts[front].data.set([srcr.data[s], srcr.data[s + 1], srcr.data[s + 2], 255], s);