@rig-c/parts 1.60.1 → 1.61.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/build.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { alternateLayerSources, alternateLayerIslands, alternateLayerOthers } from './alternatelayers.ts';
1
2
  /**
2
3
  * The stages as callable units, and `build`, which runs three of them in a row.
3
4
  *
@@ -334,10 +335,12 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
334
335
  full?: string;
335
336
  head?: string;
336
337
  parts?: string[];
338
+ layers?: Record<string, string>;
337
339
  hides?: string[];
338
340
  head_box?: [number, number, number, number];
339
341
  cuts?: Cut[];
340
342
  skeleton?: string;
343
+ anchor?: NonNullable<typeof cfg.assemble.alternates>[number]['anchor'];
341
344
  drawn?: Record<string, number>;
342
345
  tips?: Record<string, [number, number]>;
343
346
  front?: string[];
@@ -351,10 +354,12 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
351
354
  full: cli?.full ?? (a.full === undefined ? undefined : resolve(configDir, a.full)),
352
355
  head: cli !== undefined ? cli.head : a.head === undefined ? undefined : resolve(configDir, a.head),
353
356
  parts: a.parts,
357
+ layers: a.layers,
354
358
  hides: a.hides,
355
359
  head_box: a.head_box,
356
360
  cuts: a.cuts,
357
361
  skeleton: a.skeleton === undefined ? undefined : resolve(configDir, a.skeleton),
362
+ anchor: a.anchor,
358
363
  drawn: a.drawn,
359
364
  tips: a.tips,
360
365
  front: a.front,
@@ -464,8 +469,8 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
464
469
  const hidesSet = new Set(alt.hides ?? []);
465
470
  const declaredSlots = alt.parts !== undefined ? alt.parts.filter((p) => !hidesSet.has(p)) : baseSlots.filter((p) => !hidesSet.has(p));
466
471
  const coveredSet = new Set(declaredSlots);
467
- const rawCuts = alt.cuts !== undefined ? alt.cuts : fields.cuts.filter((c) => coveredSet.has(c.into) && coveredSet.has(c.from)).map((c) => ({ ...c, under: undefined }));
468
- const altLimbs: Record<string, Limb> = {};
472
+ let rawCuts = alt.cuts !== undefined ? alt.cuts : fields.cuts.filter((c) => coveredSet.has(c.into) && coveredSet.has(c.from)).map((c) => ({ ...c, under: undefined }));
473
+ let altLimbs: Record<string, Limb> = {};
469
474
  if (fields.limbs !== undefined) {
470
475
  for (const [ln, limb] of Object.entries(fields.limbs)) {
471
476
  if (limb.segments.every((sg) => coveredSet.has(sg.part))) {
@@ -483,11 +488,21 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
483
488
  neededPlan.add(name);
484
489
  }
485
490
  }
486
- const altPlan: PlanEntry[] = fields.plan
491
+ let altPlan: PlanEntry[] = fields.plan
487
492
  .filter(([name]) => neededPlan.has(name))
488
493
  .map(([name, run, tag]): PlanEntry => (altRuns.single ? [name, 'full', tag] : [name, run, tag]));
494
+ const originalAltLimbs = altLimbs;
495
+ const selectedLayers = alternateLayerSources(altPlan, rawCuts, altLimbs, coveredSet, alt.layers);
496
+ altPlan = selectedLayers.plan;
497
+ rawCuts = selectedLayers.cuts;
498
+ altLimbs = selectedLayers.limbs;
489
499
  let missingLayer = false;
490
- for (const [name, run, tag] of altPlan) {
500
+ const selectedCutLayers: PlanEntry[] = rawCuts.flatMap(c => {
501
+ const tag = selectedLayers.cutLayers.get(c.into);
502
+ const parent = altPlan.find(([name]) => name === c.from);
503
+ return tag === undefined || parent === undefined ? [] : [[c.into, parent[1], tag]];
504
+ });
505
+ for (const [name, run, tag] of [...altPlan, ...selectedCutLayers]) {
491
506
  const l = altRuns[run].layers.find((x) => x.name === tag);
492
507
  if (l === undefined || l.opaquePx === 0) {
493
508
  altProblems.push({
@@ -518,12 +533,13 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
518
533
  let altDrawnLength: Record<string, number> | undefined;
519
534
  let altRegistration: { offset: [number, number]; scale: number } | undefined;
520
535
  // Issue #588: a subset set that names one limb side keeps, of a layer that holds more than one island, the one its joints fall on.
521
- const altIslands = alt.parts === undefined || input.setIslands === 'all' ? [] : setIslandSources(fields.limbs ?? {}, altLimbs);
536
+ const originalIslands = alt.parts === undefined || input.setIslands === 'all' ? [] : setIslandSources(fields.limbs ?? {}, originalAltLimbs);
537
+ const altIslands = alternateLayerIslands(originalIslands, selectedLayers.groups);
522
538
  // Issue #609: the limbs of those layers the set does not carry — the other leg of a two-leg layer.
523
539
  const otherLimbs: Record<string, Limb> =
524
540
  input.setSplit === 'connectivity'
525
541
  ? {}
526
- : Object.fromEntries(Object.entries(fields.limbs ?? {}).filter(([ln, l]) => !(ln in altLimbs) && l.segments.some((sg) => altIslands.includes(sg.from))));
542
+ : Object.fromEntries(Object.entries(fields.limbs ?? {}).filter(([ln, l]) => !(ln in altLimbs) && l.segments.some((sg) => originalIslands.includes(sg.from))));
527
543
  const otherBones = new Set(Object.values(otherLimbs).flatMap((l) => l.segments.map((sg) => sg.bone)));
528
544
  // The bones the set places: by its skeleton, or by the angles it states; every other bone keeps the base's place unless an ancestor moved.
529
545
  const setPlaced = new Set<string>();
@@ -544,7 +560,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
544
560
  const placedBySkeleton = altSkeleton !== undefined && input.altPlacement !== 'angles' && SKELETON_LIMB_BONES.some(([b]) => coveredLimbBones.has(b));
545
561
  if (placedBySkeleton && altSkeleton !== undefined) {
546
562
  // Issue #539: the painting must sit where the base figure sits before its own joints are cut at.
547
- const reg = registerSkeleton(fields.bones, altSkeleton);
563
+ const reg = registerSkeleton(fields.bones, altSkeleton, alt.anchor);
548
564
  if (!reg.ok) {
549
565
  const read = reg.anchors.map((a) => `${a.keypoint} on "${a.bone}"`).join(', ') || 'none';
550
566
  altProblems.push({
@@ -617,9 +633,11 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
617
633
  headBox: altHeadBox,
618
634
  rigScale: fields.rigScale,
619
635
  plan: altPlan,
636
+ ...(selectedLayers.groups.size === 0 ? {} : { limbSourceGroups: selectedLayers.groups }),
620
637
  extend: altExtend,
621
638
  patches: altPatches,
622
639
  cuts: altCuts,
640
+ ...(selectedLayers.cutLayers.size === 0 ? {} : { cutLayers: selectedLayers.cutLayers }),
623
641
  under: altUnder,
624
642
  ...(Object.keys(altLimbs).length > 0 ? { limbs: altLimbs, bones: altBones } : {}),
625
643
  ...(fields.scene === undefined ? {} : { scene: fields.scene }),
@@ -629,7 +647,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
629
647
  projectRule: input.project,
630
648
  ...(altExclude.length === 0 ? {} : { exclude: altExclude }),
631
649
  ...(altIslands.length === 0 ? {} : { limbIslands: altIslands }),
632
- ...(altOthers === undefined ? {} : { otherLimbs: altOthers }),
650
+ ...(altOthers === undefined ? {} : { otherLimbs: alternateLayerOthers(altOthers, selectedLayers.groups) }),
633
651
  });
634
652
  } catch (err) {
635
653
  if (err instanceof PartsError) {
@@ -1719,17 +1737,26 @@ export function sweepCheckLines(line: SweepLine, steps: ReadonlyMap<string, { le
1719
1737
  * read nothing of (its SKIP) or the line could not read. A SKIP with nothing declared prints its reason alone.
1720
1738
  */
1721
1739
  export function motionSeamLines(line: MotionSeamLine, plant: MotionSeamPlant = {}): string[] {
1722
- if (line.worlds === undefined && line.status === 'SKIP' && line.rows.length === 0 && line.pairs.every((p) => p.unread === undefined)) return [`${MOTION_SEAM_LINE}: SKIP — ${String(line.reason)}`];
1740
+ const unmeasured = (line.roots?.unmeasured ?? []).map(root => `root pair for ${root.limb} (${root.part}, bone "${root.bone}", parent "${root.parent}", candidates ${root.candidates.join('/')}): SKIP — ${root.reason}`);
1741
+ const rootStatus = line.roots === undefined ? '' : '; body-root gap-only gate ' + line.roots.status + ' (' + line.roots.pairs.length + ' pair(s)); ghost ownership unavailable' + (line.roots.reason === undefined ? '' : ' — ' + line.roots.reason);
1742
+ if (line.worlds === undefined && line.status === 'SKIP' && line.rows.length === 0 && line.pairs.every((p) => p.unread === undefined)) return [`${MOTION_SEAM_LINE}: SKIP — ${String(line.reason)}${unmeasured.length === 0 ? '' : rootStatus}`, ...unmeasured];
1723
1743
  const read = `${line.pairs.length} declared pair(s) in ${line.animations.length} animation(s) (${line.animations.join(', ')}), read by rigc render --seam at ${line.fps} fps on the build as played`;
1724
1744
  const head =
1725
1745
  line.status === 'SKIP'
1726
- ? `${MOTION_SEAM_LINE}: SKIP — ${String(line.reason)}; ${read}`
1727
- : `${MOTION_SEAM_LINE}: ${line.status} — ${read}: ${line.warnings} warning(s), never a bar; ${line.floor}`;
1746
+ ? `${MOTION_SEAM_LINE}: SKIP — ${String(line.reason)}; ${read}${unmeasured.length === 0 ? '' : rootStatus}`
1747
+ : `${MOTION_SEAM_LINE}: ${line.status} — ${read}: ${line.warnings} warning(s), never a bar${rootStatus}; ${line.floor}`;
1728
1748
  return [
1729
1749
  head,
1750
+ ...unmeasured,
1730
1751
  ...line.pairs.filter((p) => p.unread !== undefined).map((p) => `seam "${p.pair}" (${p.declared.join('; ')}): not read — ${String(p.unread)}`),
1731
1752
  ...line.rows.filter((r) => r.status === 'skip').map((r) => `seam "${r.pair}" in "${r.animation}": SKIP — rigc read no band on any of the ${r.drawn} frame(s) both slots draw, so there is no seam to read`),
1732
- ...(plant.silent === true ? [] : line.rows.filter((r) => r.opens.length > 0).map(motionSeamWarnText)),
1753
+ ...(plant.silent === true ? [] : line.rows.filter((r) => r.opens.length > 0).map(r => line.pairs.some(p => p.pair === r.pair && p.root !== undefined)
1754
+ ? `FAIL seam "${r.pair}" opens on ${r.opens.length} frame(s) ${frameRuns(r.opens)} max ${r.max_px} px in "${r.animation}" — body-root GAP over the one-cell floor (gap-only)`
1755
+ : motionSeamWarnText(r))),
1756
+ ...line.rows.flatMap(r => (r.coverage ?? []).map(h =>
1757
+ `INFO seam "${r.pair}" in "${r.animation}" frame ${h.index}: root GAP raw ${h.px}; whole-box ${h.status} — ${h.reason}${h.status === 'exempt' ? '; not gated' : '; entire original GAP count retained'}${h.evidence === undefined ? '' : '; evidence: ' + h.evidence}; exact GAP partition deferred to rig-c/core#1556`)),
1758
+ ...line.rows.filter(r => r.ghost_info !== undefined && r.ghost_info.frames > 0).map(r =>
1759
+ `INFO seam "${r.pair}" in "${r.animation}": ghost ${r.ghost_info?.max_px} cells on ${r.ghost_info?.frames} frame(s); owner unavailable in this rigc-seam/1 reading; see rig-c/core#1555; not gated (gap-only)`),
1733
1760
  ...line.rows.filter((r) => r.opens.length === 0 && r.under_floor.length > 0).map((r) => `seam "${r.pair}" in "${r.animation}": under the floor — rigc names ${r.under_floor.length} frame(s) open ${frameRuns(r.under_floor)}, each opening one cell thick`),
1734
1761
  ...(line.worlds === undefined ? [] : (['default', 'still'] as const).flatMap(name => {
1735
1762
  const w = line.worlds?.[name];
@@ -1798,6 +1825,7 @@ export function checkStage(input: CheckStageInput, rigc: RigcRunner, bin: string
1798
1825
  ` seam${fig.seam_border === undefined ? '' : ` (config.scene: ${fig.seam_border.frame_px_left_out} frame px on the painting's border rows and columns left out, ${fig.seam_border.px_over_40_left_out} of them over ${SEAM_PX_LEVEL})`}: setup pose at ${r.seamViewport.pixelWidth}x${r.seamViewport.pixelHeight}, scale ${r.seamViewport.scale.toFixed(4)}: mean |d| ${fig.seam_mean} (<= ${SEAM_MEAN_BAR.toFixed(1)}), ` +
1799
1826
  `${fig.seam_px_over_40} px over ${SEAM_PX_LEVEL}, ${fig.seam_frame_scale === null || fig.seam_px_over_40 === null ? '' : seamRigPxText(fig.seam_px_over_40, fig.seam_frame_scale)} rig px (the count / s²; <= ${SEAM_PX_BAR}), ${fig.seam_px_over_80} px over ${SEAM_PX_LEVEL_HIGH} (reported)`,
1800
1827
  );
1828
+ if (fig.seam_scope !== undefined) log(` seam scope: ${fig.seam_scope.mode}, denominator ${fig.seam_scope.denominator_px} source cells; union ${fig.seam_scope.domain?.viewport.pixelWidth}x${fig.seam_scope.domain?.viewport.pixelHeight}, numerator ${fig.seam_scope.domain?.numerator}; auto-frame raw mean ${fig.seam_scope.auto_frame_raw.mean}, ${fig.seam_scope.auto_frame_raw.px_over_40} px over ${SEAM_PX_LEVEL} at scale ${fig.seam_scope.auto_frame_raw.frame_scale} (diagnostic only)`);
1801
1829
  const pairs = fig.seam_pairs ?? [];
1802
1830
  pairs.forEach((row, i) => log(` seam pair ${i + 1} of ${pairs.length}: ${seamPairText(row)}`));
1803
1831
  if (fig.sets !== undefined) {
@@ -1806,6 +1834,11 @@ export function checkStage(input: CheckStageInput, rigc: RigcRunner, bin: string
1806
1834
  ` seam (${setName})${setFig.seam_border === undefined ? '' : ` (config.scene: ${setFig.seam_border.frame_px_left_out} frame px on the painting's border rows and columns left out, ${setFig.seam_border.px_over_40_left_out} of them over ${SEAM_PX_LEVEL})`}: setup pose at ${setFig.render_px}, scale ${setFig.seam_frame_scale.toFixed(4)}: mean |d| ${setFig.seam_mean} (<= ${SEAM_MEAN_BAR.toFixed(1)}), ` +
1807
1835
  `${setFig.seam_px_over_40} px over ${SEAM_PX_LEVEL}, ${seamRigPxText(setFig.seam_px_over_40, setFig.seam_frame_scale)} rig px (the count / s²; <= ${SEAM_PX_BAR}), ${setFig.seam_px_over_80} px over ${SEAM_PX_LEVEL_HIGH} (reported)`,
1808
1836
  );
1837
+ if (setFig.seam_scope !== undefined) {
1838
+ const scope = setFig.seam_scope;
1839
+ log(` seam scope (${setName}): ${scope.mode}, denominator ${scope.denominator_px} base source cells; union ${scope.domain?.viewport.pixelWidth}x${scope.domain?.viewport.pixelHeight}, numerator ${scope.domain?.numerator}; whole canonical ${scope.whole.px_over_40} px over ${SEAM_PX_LEVEL}, mean ${scope.whole.mean}; auto-frame raw ${scope.auto_frame_raw.px_over_40} at scale ${scope.auto_frame_raw.frame_scale} (diagnostic only); effects ${JSON.stringify(scope.effects)}, changes ${JSON.stringify(scope.changes)}${scope.unavailable === undefined ? '' : `; ${JSON.stringify(scope.unavailable)}`}`);
1840
+ for (const pair of scope.pairs ?? []) log(` seam inheritance (${setName}): ${JSON.stringify(pair.parts)}, whole ${pair.whole_px_over_40}, affected ${pair.affected_px_over_40}, inherited from base ${pair.inherited_px_over_40} px over ${SEAM_PX_LEVEL}`);
1841
+ }
1809
1842
  const setPairs = setFig.seam_pairs ?? [];
1810
1843
  setPairs.forEach((row, i) => log(` seam pair (${setName}) ${i + 1} of ${setPairs.length}: ${seamPairText(row)}`));
1811
1844
  }
@@ -2195,9 +2228,18 @@ export function suppliedCheckFlag(flag: string): string | null {
2195
2228
  * rig-c's launcher answers for; they are two fields so a caller can tell
2196
2229
  * the stages' calls apart (the selftest counts them).
2197
2230
  */
2231
+ /** Stage implementations may run outside this process; only check has a returned value the driver reads. */
2232
+ export interface BuildStages {
2233
+ assemble: (input: AssembleStageInput, outputs: AssembleOutputs, log: Log) => void;
2234
+ rig: (input: RigStageInput, rigc: RigcRunner, scratch: string, log: Log) => void;
2235
+ check: typeof checkStage;
2236
+ }
2237
+
2198
2238
  export interface BuildRunners {
2199
2239
  rig: RigcRunner;
2200
2240
  check: RigcRunner;
2241
+ /** The CLI isolates stages; API callers keep the same in-process functions by default. */
2242
+ stages?: BuildStages;
2201
2243
  /** Where the check's rigc binary is, for its header line. */
2202
2244
  checkBin: string;
2203
2245
  /** A directory the rig stage may stage its gate in, and the loop its lead-in render after it; emptied before and after each. */
@@ -2248,6 +2290,7 @@ export function artifactPaths(buildDir: string, pack: readonly PackLine[]): stri
2248
2290
  * rethrown: it is not a stage's message and must not be printed as one.
2249
2291
  */
2250
2292
  export function build(input: BuildInput, run: BuildRunners, log: Log): BuildResult {
2293
+ const stages: BuildStages = run.stages ?? { assemble: assembleStage, rig: rigStage, check: checkStage };
2251
2294
  const prefixed = (stage: BuildStage): Log => (line) => log(`[${stage}] ${line}`);
2252
2295
  const refused = (stage: BuildStage, err: unknown, check: CheckReport | null = null): BuildResult => {
2253
2296
  if (!(err instanceof PartsError)) throw err;
@@ -2282,7 +2325,7 @@ export function build(input: BuildInput, run: BuildRunners, log: Log): BuildResu
2282
2325
  if (req !== null) readRequirements(req.read);
2283
2326
  // And the schedule (issue #538), by rigc's own reader, as check reads it.
2284
2327
  if (input.environment !== undefined) readCheckEnvironment(input.environment);
2285
- assembleStage(
2328
+ stages.assemble(
2286
2329
  { source: input.source, full: input.full, head: input.head, config: input.config, seam: input.seam, project: input.project, ...(input.alts === undefined ? {} : { alts: input.alts }) },
2287
2330
  { partsJson: join(out, 'parts.json'), partsDir: join(out, 'parts'), recomposite: join(out, 'recomposite_rig.png'), errorMap: join(out, ERROR_MAP_FILE) },
2288
2331
  prefixed('assemble'),
@@ -2292,14 +2335,14 @@ export function build(input: BuildInput, run: BuildRunners, log: Log): BuildResu
2292
2335
  }
2293
2336
 
2294
2337
  try {
2295
- rigStage({ config: input.config, parts: out, out: join(out, 'rig'), idleKeys, pageEdges: input.pageEdges, packShape: input.packShape, command: 'build' }, run.rig, run.scratch, prefixed('rig'));
2338
+ stages.rig({ config: input.config, parts: out, out: join(out, 'rig'), idleKeys, pageEdges: input.pageEdges, packShape: input.packShape, command: 'build' }, run.rig, run.scratch, prefixed('rig'));
2296
2339
  } catch (err) {
2297
2340
  return refused('rig', err);
2298
2341
  }
2299
2342
 
2300
2343
  let report: CheckReport;
2301
2344
  try {
2302
- report = checkStage({ rig: join(out, 'rig'), parts: out, out: join(out, 'check'), pageEdges: input.pageEdges, packShape: input.packShape, ...(req === null ? {} : { requirements: req.read, requirementsAs: req.recorded }), seamPairs: input.seamPairs === true, keepStills: input.keepStills === true, ...(input.set === undefined ? {} : { set: input.set }), allSets: input.allSets === true, ...(input.environment === undefined ? {} : { environment: input.environment }), ...(configRecord === null ? {} : { config: configRecord }) }, run.check, run.checkBin, prefixed('check'));
2345
+ report = stages.check({ rig: join(out, 'rig'), parts: out, out: join(out, 'check'), pageEdges: input.pageEdges, packShape: input.packShape, ...(req === null ? {} : { requirements: req.read, requirementsAs: req.recorded }), seamPairs: input.seamPairs === true, keepStills: input.keepStills === true, ...(input.set === undefined ? {} : { set: input.set }), allSets: input.allSets === true, ...(input.environment === undefined ? {} : { environment: input.environment }), ...(configRecord === null ? {} : { config: configRecord }) }, run.check, run.checkBin, prefixed('check'));
2303
2346
  } catch (err) {
2304
2347
  return refused('check', err);
2305
2348
  }