@rig-c/parts 1.60.2 → 1.62.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,5 @@
1
+ import { alternateLayerSources, alternateLayerIslands, alternateLayerOthers } from './alternatelayers.ts';
2
+ import { setFocusProblems } from './setfocus.ts';
1
3
  /**
2
4
  * The stages as callable units, and `build`, which runs three of them in a row.
3
5
  *
@@ -334,6 +336,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
334
336
  full?: string;
335
337
  head?: string;
336
338
  parts?: string[];
339
+ layers?: Record<string, string>;
337
340
  hides?: string[];
338
341
  head_box?: [number, number, number, number];
339
342
  cuts?: Cut[];
@@ -341,6 +344,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
341
344
  anchor?: NonNullable<typeof cfg.assemble.alternates>[number]['anchor'];
342
345
  drawn?: Record<string, number>;
343
346
  tips?: Record<string, [number, number]>;
347
+ focus?: [number, number];
344
348
  front?: string[];
345
349
  }> = cfgAlts.map((a, i) => {
346
350
  const cli = cliByName.get(a.name);
@@ -352,6 +356,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
352
356
  full: cli?.full ?? (a.full === undefined ? undefined : resolve(configDir, a.full)),
353
357
  head: cli !== undefined ? cli.head : a.head === undefined ? undefined : resolve(configDir, a.head),
354
358
  parts: a.parts,
359
+ layers: a.layers,
355
360
  hides: a.hides,
356
361
  head_box: a.head_box,
357
362
  cuts: a.cuts,
@@ -359,6 +364,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
359
364
  anchor: a.anchor,
360
365
  drawn: a.drawn,
361
366
  tips: a.tips,
367
+ focus: a.focus,
362
368
  front: a.front,
363
369
  };
364
370
  });
@@ -462,12 +468,16 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
462
468
  });
463
469
  continue;
464
470
  }
471
+ if (alt.focus !== undefined) {
472
+ const invalidFocus = setFocusProblems(alt.focus, `${alt.at}.focus`, [altSrc.width, altSrc.height]);
473
+ if (invalidFocus.length > 0) { altProblems.push(...invalidFocus); continue; }
474
+ }
465
475
  const altRuns = readRuns(alt.full, alt.head ?? null);
466
476
  const hidesSet = new Set(alt.hides ?? []);
467
477
  const declaredSlots = alt.parts !== undefined ? alt.parts.filter((p) => !hidesSet.has(p)) : baseSlots.filter((p) => !hidesSet.has(p));
468
478
  const coveredSet = new Set(declaredSlots);
469
- const rawCuts = alt.cuts !== undefined ? alt.cuts : fields.cuts.filter((c) => coveredSet.has(c.into) && coveredSet.has(c.from)).map((c) => ({ ...c, under: undefined }));
470
- const altLimbs: Record<string, Limb> = {};
479
+ let rawCuts = alt.cuts !== undefined ? alt.cuts : fields.cuts.filter((c) => coveredSet.has(c.into) && coveredSet.has(c.from)).map((c) => ({ ...c, under: undefined }));
480
+ let altLimbs: Record<string, Limb> = {};
471
481
  if (fields.limbs !== undefined) {
472
482
  for (const [ln, limb] of Object.entries(fields.limbs)) {
473
483
  if (limb.segments.every((sg) => coveredSet.has(sg.part))) {
@@ -485,11 +495,21 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
485
495
  neededPlan.add(name);
486
496
  }
487
497
  }
488
- const altPlan: PlanEntry[] = fields.plan
498
+ let altPlan: PlanEntry[] = fields.plan
489
499
  .filter(([name]) => neededPlan.has(name))
490
500
  .map(([name, run, tag]): PlanEntry => (altRuns.single ? [name, 'full', tag] : [name, run, tag]));
501
+ const originalAltLimbs = altLimbs;
502
+ const selectedLayers = alternateLayerSources(altPlan, rawCuts, altLimbs, coveredSet, alt.layers);
503
+ altPlan = selectedLayers.plan;
504
+ rawCuts = selectedLayers.cuts;
505
+ altLimbs = selectedLayers.limbs;
491
506
  let missingLayer = false;
492
- for (const [name, run, tag] of altPlan) {
507
+ const selectedCutLayers: PlanEntry[] = rawCuts.flatMap(c => {
508
+ const tag = selectedLayers.cutLayers.get(c.into);
509
+ const parent = altPlan.find(([name]) => name === c.from);
510
+ return tag === undefined || parent === undefined ? [] : [[c.into, parent[1], tag]];
511
+ });
512
+ for (const [name, run, tag] of [...altPlan, ...selectedCutLayers]) {
493
513
  const l = altRuns[run].layers.find((x) => x.name === tag);
494
514
  if (l === undefined || l.opaquePx === 0) {
495
515
  altProblems.push({
@@ -520,12 +540,13 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
520
540
  let altDrawnLength: Record<string, number> | undefined;
521
541
  let altRegistration: { offset: [number, number]; scale: number } | undefined;
522
542
  // 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.
523
- const altIslands = alt.parts === undefined || input.setIslands === 'all' ? [] : setIslandSources(fields.limbs ?? {}, altLimbs);
543
+ const originalIslands = alt.parts === undefined || input.setIslands === 'all' ? [] : setIslandSources(fields.limbs ?? {}, originalAltLimbs);
544
+ const altIslands = alternateLayerIslands(originalIslands, selectedLayers.groups);
524
545
  // Issue #609: the limbs of those layers the set does not carry — the other leg of a two-leg layer.
525
546
  const otherLimbs: Record<string, Limb> =
526
547
  input.setSplit === 'connectivity'
527
548
  ? {}
528
- : Object.fromEntries(Object.entries(fields.limbs ?? {}).filter(([ln, l]) => !(ln in altLimbs) && l.segments.some((sg) => altIslands.includes(sg.from))));
549
+ : Object.fromEntries(Object.entries(fields.limbs ?? {}).filter(([ln, l]) => !(ln in altLimbs) && l.segments.some((sg) => originalIslands.includes(sg.from))));
529
550
  const otherBones = new Set(Object.values(otherLimbs).flatMap((l) => l.segments.map((sg) => sg.bone)));
530
551
  // 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.
531
552
  const setPlaced = new Set<string>();
@@ -619,9 +640,11 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
619
640
  headBox: altHeadBox,
620
641
  rigScale: fields.rigScale,
621
642
  plan: altPlan,
643
+ ...(selectedLayers.groups.size === 0 ? {} : { limbSourceGroups: selectedLayers.groups }),
622
644
  extend: altExtend,
623
645
  patches: altPatches,
624
646
  cuts: altCuts,
647
+ ...(selectedLayers.cutLayers.size === 0 ? {} : { cutLayers: selectedLayers.cutLayers }),
625
648
  under: altUnder,
626
649
  ...(Object.keys(altLimbs).length > 0 ? { limbs: altLimbs, bones: altBones } : {}),
627
650
  ...(fields.scene === undefined ? {} : { scene: fields.scene }),
@@ -631,7 +654,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
631
654
  projectRule: input.project,
632
655
  ...(altExclude.length === 0 ? {} : { exclude: altExclude }),
633
656
  ...(altIslands.length === 0 ? {} : { limbIslands: altIslands }),
634
- ...(altOthers === undefined ? {} : { otherLimbs: altOthers }),
657
+ ...(altOthers === undefined ? {} : { otherLimbs: alternateLayerOthers(altOthers, selectedLayers.groups) }),
635
658
  });
636
659
  } catch (err) {
637
660
  if (err instanceof PartsError) {
@@ -677,6 +700,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
677
700
  ...(altSkeleton === undefined ? {} : { skeleton: altSkeleton }),
678
701
  ...(alt.drawn === undefined ? {} : { drawn: { ...alt.drawn } }),
679
702
  ...(altTips === undefined ? {} : { tips_source_size: [altSrc.width, altSrc.height], tips: altTips }),
703
+ ...(alt.focus === undefined ? {} : { focus: [...alt.focus], focus_source_size: [altSrc.width, altSrc.height] }),
680
704
  ...(altDrawnLength === undefined ? {} : { drawnLength: altDrawnLength }),
681
705
  ...(altRegistration === undefined ? {} : { registration: altRegistration }),
682
706
  },
@@ -1432,6 +1456,8 @@ export function rigStage(input: RigStageInput, rigc: RigcRunner, scratch: string
1432
1456
  ? ''
1433
1457
  : `; replayed to accepted step ${rp.chosen_step} of ${rp.accepted_steps} after ${rp.replays} replay(s); selection ${readingText(rp.selection, roleReadings(run.report).bound)}; held out ${readingText(rp.held_out, roleReadings(run.report).bound)}`;
1434
1458
  log(`${head}auto ${from} -> ${r.boundaryVertices}+${r.interiorVertices} (hull+interior) bindings ${r.bindings} ${infl} ${t.reason}${tried}; worst ${worst}${unboundedClause(m.residuals, m.settings.targets.artFit)}${allocationClause(m.residuals)}${stageBClause(m.settings, m.result)}${residualClause(m.skinning_residual)}${strayClause(m.stray_cleared)}; ${moved}${replayed}`);
1459
+ } else if ('mode' in m && m.mode === 'explicit') {
1460
+ log(`${head}explicit ${infl} image sha256 ${m.image_sha256} region sha256 ${m.region_sha256}`);
1435
1461
  } else if ('mode' in m && m.mode === 'influence') {
1436
1462
  // issue #378: rig-c's segments lattice and pull, the figures its own build prints for the generator (AUTHORING §3.4.7).
1437
1463
  const i = m.influence;
@@ -1721,17 +1747,24 @@ export function sweepCheckLines(line: SweepLine, steps: ReadonlyMap<string, { le
1721
1747
  * read nothing of (its SKIP) or the line could not read. A SKIP with nothing declared prints its reason alone.
1722
1748
  */
1723
1749
  export function motionSeamLines(line: MotionSeamLine, plant: MotionSeamPlant = {}): string[] {
1724
- 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)}`];
1750
+ 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}`);
1751
+ const rootStatus = line.roots === undefined ? '' : '; body-root gap-open+under-ghost gate ' + line.roots.status + ' (' + line.roots.pairs.length + ' pair(s)); ghost ownership from resolved draw order' + (line.roots.reason === undefined ? '' : ' — ' + line.roots.reason);
1752
+ 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];
1725
1753
  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`;
1726
1754
  const head =
1727
1755
  line.status === 'SKIP'
1728
- ? `${MOTION_SEAM_LINE}: SKIP — ${String(line.reason)}; ${read}`
1729
- : `${MOTION_SEAM_LINE}: ${line.status} — ${read}: ${line.warnings} warning(s), never a bar; ${line.floor}`;
1756
+ ? `${MOTION_SEAM_LINE}: SKIP — ${String(line.reason)}; ${read}${unmeasured.length === 0 ? '' : rootStatus}`
1757
+ : `${MOTION_SEAM_LINE}: ${line.status} — ${read}: ${line.warnings} warning(s), never a bar${rootStatus}; ${line.floor}`;
1730
1758
  return [
1731
1759
  head,
1760
+ ...unmeasured,
1732
1761
  ...line.pairs.filter((p) => p.unread !== undefined).map((p) => `seam "${p.pair}" (${p.declared.join('; ')}): not read — ${String(p.unread)}`),
1733
1762
  ...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`),
1734
- ...(plant.silent === true ? [] : line.rows.filter((r) => r.opens.length > 0).map(motionSeamWarnText)),
1763
+ ...(plant.silent === true ? [] : line.rows.filter((r) => r.opens.length > 0).map(r => line.pairs.some(p => p.pair === r.pair && p.root !== undefined)
1764
+ ? `FAIL seam "${r.pair}" opens on ${r.opens.length} frame(s) ${frameRuns(r.opens)} max ${r.max_px} px in "${r.animation}" — body-root gapOpen + UNDER-owned ghost over the one-cell floor`
1765
+ : motionSeamWarnText(r))),
1766
+ ...line.rows.flatMap(r => (r.cells ?? []).map(h =>
1767
+ `INFO seam "${r.pair}" in "${r.animation}" frame ${h.index}: gapOpen ${h.gapOpen}, gapCovered ${h.gapCovered}, ghost ${h.ghostA + h.ghostB}; UNDER ${h.under ?? 'none'} ghost ${h.underGhost}, OVER ghost ${h.overGhost}; counted ${h.counted}`)),
1735
1768
  ...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`),
1736
1769
  ...(line.worlds === undefined ? [] : (['default', 'still'] as const).flatMap(name => {
1737
1770
  const w = line.worlds?.[name];
@@ -1800,6 +1833,7 @@ export function checkStage(input: CheckStageInput, rigc: RigcRunner, bin: string
1800
1833
  ` 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)}), ` +
1801
1834
  `${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)`,
1802
1835
  );
1836
+ 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)`);
1803
1837
  const pairs = fig.seam_pairs ?? [];
1804
1838
  pairs.forEach((row, i) => log(` seam pair ${i + 1} of ${pairs.length}: ${seamPairText(row)}`));
1805
1839
  if (fig.sets !== undefined) {
@@ -1808,6 +1842,11 @@ export function checkStage(input: CheckStageInput, rigc: RigcRunner, bin: string
1808
1842
  ` 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)}), ` +
1809
1843
  `${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)`,
1810
1844
  );
1845
+ if (setFig.seam_scope !== undefined) {
1846
+ const scope = setFig.seam_scope;
1847
+ 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)}`}`);
1848
+ 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}`);
1849
+ }
1811
1850
  const setPairs = setFig.seam_pairs ?? [];
1812
1851
  setPairs.forEach((row, i) => log(` seam pair (${setName}) ${i + 1} of ${setPairs.length}: ${seamPairText(row)}`));
1813
1852
  }