rig-parts 2.74.0 → 2.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/scene.ts CHANGED
@@ -111,8 +111,10 @@ import { dirname, join, resolve } from 'node:path';
111
111
  import { documentPageLookup, readModel, type ModelPageRegion } from '@rig-c/core/core';
112
112
  import { CandidateAtlasError, CandidatePairError, CoreInputError, loadCandidate, PoserChoiceError, projector, renderFrame, SpineRuntimeError, throughPoser, type Piece, type Quad, type Viewport } from '@rig-c/core/render-shared';
113
113
  import { deformSliderCombinationProblem, type RigStop } from '@rig-c/core/rig';
114
+ import partsPackage from '../package.json' with { type: 'json' };
114
115
  import { checkStage, gateThroughRigc, type Log } from './build.ts';
115
- import { ACCEPTABLE_BARS, barsNotMet, CHECK_SPEC, type CheckReport, COMPOSE_PREVIEW_LOOP_SEAM_DETAIL, DEFAULT_PACK_SHAPE, DEFAULT_PAGE_EDGES, IDLE_FPS, LOOP_SEAM_BAR_UNMET, type LoopSeamRequest, type PackMode, parsePageSize, requirementsNotPass, type RigcRunner } from './check.ts';
116
+ import { ACCEPTABLE_BARS, barsNotMet, CHECK_SPEC, type CheckReport, COMPOSE_PREVIEW_LOOP_SEAM_DETAIL, DEFAULT_PACK_SHAPE, DEFAULT_PAGE_EDGES, IDLE_FPS, LOOP_SEAM_BAR_UNMET, type LoopSeamRequest, MOTION_SEAM_LINE, type PackMode, parsePageSize, requirementsNotPass, type RigcRunner } from './check.ts';
117
+ import { COMPOSE_SEAMS_CORE, COMPOSE_SEAMS_DIR, COMPOSE_SEAMS_OFF, type ComposeSeamRequest, writeComposeSeams } from './compose-seams.ts';
116
118
  import { CONSTRAINT_BONE_FIELDS, editorReceiptProblems, ROOT_BONE } from './config.ts';
117
119
  import { cropToSpineY } from './coords.ts';
118
120
  import { failLine, PartsError, type Problem, refuseIfAny } from './errors.ts';
@@ -146,6 +148,9 @@ export const SCENE_CAMERA_REPORT_SPEC = 'spine-parts-scene-report/2';
146
148
  /** The file `compose` writes beside `rig/` and `check/`. */
147
149
  export const SCENE_REPORT_FILE = 'scene.json';
148
150
 
151
+ export const COMPOSE_REFUSAL_SPEC = 'rig-compose-refusal/1';
152
+ export const COMPOSE_REFUSAL_FILE = 'compose-refusal.json';
153
+
149
154
  /** Between a character's id and a name it owns. */
150
155
  export const PREFIX_SEP = ':';
151
156
 
@@ -163,7 +168,7 @@ export const PROVENANCES = ['observed', 'generated', 'unknown'] as const;
163
168
  export type Provenance = (typeof PROVENANCES)[number];
164
169
 
165
170
  /** Every path `compose` writes under `--out`, relative — and so every path it clears first. */
166
- export const COMPOSE_OWNS: readonly string[] = ['rig', 'check', SCENE_REPORT_FILE, COMPOSE_RUN_FILE];
171
+ export const COMPOSE_OWNS: readonly string[] = ['rig', 'check', SCENE_REPORT_FILE, COMPOSE_RUN_FILE, COMPOSE_REFUSAL_FILE, COMPOSE_SEAMS_DIR];
167
172
 
168
173
  /** `<id>:<name>`. */
169
174
  export function prefixed(id: string, name: string): string {
@@ -289,14 +294,31 @@ export function acceptProblems(names: readonly string[], where: string): Problem
289
294
  * names is {@link composeScene}'s, which has the builds.
290
295
  */
291
296
  export function loadScene(path: string): SceneFile {
297
+ return parseScene(readSceneSource(path));
298
+ }
299
+
300
+ type SceneSource = { at: string; bytes: Buffer; sha256: string } | { problem: Problem };
301
+
302
+ function readSceneSource(path: string): SceneSource {
292
303
  const at = resolve(path);
293
- if (!existsSync(at) || !statSync(at).isFile()) refuseIfAny([{ code: 'SCENE_FILE', object: at, detail: `no such file; a ${SCENE_SPEC} file is required` }]);
304
+ if (!existsSync(at) || !statSync(at).isFile()) {
305
+ return { problem: { code: 'SCENE_FILE', object: at, detail: `no such file; a ${SCENE_SPEC} file is required` } };
306
+ }
307
+ let bytes: Buffer;
308
+ try {
309
+ bytes = readFileSync(at);
310
+ } catch (err) {
311
+ return { problem: { code: 'SCENE_FILE', object: at, detail: `${(err as Error).message}; a JSON object is required` } };
312
+ }
313
+ return { at, bytes, sha256: createHash('sha256').update(bytes).digest('hex') };
314
+ }
315
+
316
+ function parseScene(source: SceneSource): SceneFile {
317
+ if ('problem' in source) throw new PartsError([source.problem]);
318
+ const { at, bytes, sha256 } = source;
294
319
  let raw: unknown;
295
- let sha256 = '';
296
320
  try {
297
- const bytes = readFileSync(at);
298
321
  raw = JSON.parse(bytes.toString('utf8'));
299
- sha256 = createHash('sha256').update(bytes).digest('hex');
300
322
  } catch (err) {
301
323
  refuseIfAny([{ code: 'SCENE_FILE', object: at, detail: `${(err as Error).message}; a JSON object is required` }]);
302
324
  }
@@ -614,40 +636,55 @@ function animationsOf(motion: MotionSpec): Record<string, SceneAnimation> {
614
636
  /** Maximum copies of each source searched for a diagnostic hint. Acceptance compares the declared counts directly. */
615
637
  const WITH_IDLE_DIAGNOSTIC_COPY_LIMIT = 10_000;
616
638
 
639
+ type IdleRepeatSearchResult = { found: { idle_repeats: number; with_idle: number } } | { none: 'limit' | 'non_finite' };
640
+
641
+ interface WithIdleDurationData {
642
+ idle_period: number;
643
+ clip_period: number;
644
+ search: { limit: typeof WITH_IDLE_DIAGNOSTIC_COPY_LIMIT; result: IdleRepeatSearchResult };
645
+ }
646
+
617
647
  function compareRepeatDurations(left: number, right: number): -1 | 0 | 1 {
618
648
  return left === right ? 0 : left < right ? -1 : 1;
619
649
  }
620
650
 
621
- function idleRepeatAdvice(name: string, idlePeriod: number, clipPeriod: number, scenePeriodMatchesIdle: boolean): string {
622
- if (Number.isFinite(idlePeriod) && idlePeriod > 0 && Number.isFinite(clipPeriod) && clipPeriod > 0) {
623
- let idleCount = 1;
624
- let clipCount = 1;
625
- while (idleCount <= WITH_IDLE_DIAGNOSTIC_COPY_LIMIT && clipCount <= WITH_IDLE_DIAGNOSTIC_COPY_LIMIT) {
626
- const idleDuration = idleCount * idlePeriod;
627
- const clipDuration = clipCount * clipPeriod;
628
- if (!Number.isFinite(idleDuration) || !Number.isFinite(clipDuration)) break;
629
- // Only the smaller product can catch the other, so the first match has the least idle count and then clip count.
630
- const order = compareRepeatDurations(idleDuration, clipDuration);
631
- if (order === 0) {
632
- const clipField = `with_idle.${name}: ${clipCount}`;
633
- const unknownScenePeriod = "Cannot name a scene.repeats count because the scene's own period is not declared.";
634
- if (idleCount === 1) {
635
- const sceneAdvice = scenePeriodMatchesIdle
636
- ? `Omit scene.repeats.idle and keep scene.animations.idle.duration: ${idleDuration} (camera terminal key ${idleDuration} s).`
637
- : unknownScenePeriod;
638
- return `Omit idle_repeats and write ${clipField} (${idleDuration} s). ${sceneAdvice}`;
639
- }
640
- if (scenePeriodMatchesIdle) {
641
- return `Write idle_repeats: ${idleCount}, ${clipField}, scene.repeats.idle: ${idleCount}, and scene.animations.idle.duration: ${idleDuration} ` +
642
- `(composed camera terminal key ${idleDuration} s, authored terminal key stays at ${idlePeriod} s).`;
643
- }
644
- return `Write idle_repeats: ${idleCount} and ${clipField} (${idleDuration} s). ${unknownScenePeriod}`;
645
- }
646
- if (order < 0) idleCount++;
647
- else clipCount++;
648
- }
649
- }
650
- const limit = String(WITH_IDLE_DIAGNOSTIC_COPY_LIMIT).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
651
+ function searchIdleRepeats(idlePeriod: number, clipPeriod: number): IdleRepeatSearchResult {
652
+ if (!(Number.isFinite(idlePeriod) && idlePeriod > 0 && Number.isFinite(clipPeriod) && clipPeriod > 0)) return { none: 'non_finite' };
653
+ let idleCount = 1;
654
+ let clipCount = 1;
655
+ while (idleCount <= WITH_IDLE_DIAGNOSTIC_COPY_LIMIT && clipCount <= WITH_IDLE_DIAGNOSTIC_COPY_LIMIT) {
656
+ const idleDuration = idleCount * idlePeriod;
657
+ const clipDuration = clipCount * clipPeriod;
658
+ if (!Number.isFinite(idleDuration) || !Number.isFinite(clipDuration)) return { none: 'non_finite' };
659
+ // Only the smaller product can catch the other, so the first match has the least idle count and then clip count.
660
+ const order = compareRepeatDurations(idleDuration, clipDuration);
661
+ if (order === 0) return { found: { idle_repeats: idleCount, with_idle: clipCount } };
662
+ if (order < 0) idleCount++;
663
+ else clipCount++;
664
+ }
665
+ return { none: 'limit' };
666
+ }
667
+
668
+ function idleRepeatAdvice(name: string, data: WithIdleDurationData, scenePeriodMatchesIdle: boolean): string {
669
+ const { idle_period: idlePeriod, clip_period: clipPeriod, search } = data;
670
+ if ('found' in search.result) {
671
+ const { idle_repeats: idleCount, with_idle: clipCount } = search.result.found;
672
+ const idleDuration = idleCount * idlePeriod;
673
+ const clipField = `with_idle.${name}: ${clipCount}`;
674
+ const unknownScenePeriod = "Cannot name a scene.repeats count because the scene's own period is not declared.";
675
+ if (idleCount === 1) {
676
+ const sceneAdvice = scenePeriodMatchesIdle
677
+ ? `Omit scene.repeats.idle and keep scene.animations.idle.duration: ${idleDuration} (camera terminal key ${idleDuration} s).`
678
+ : unknownScenePeriod;
679
+ return `Omit idle_repeats and write ${clipField} (${idleDuration} s). ${sceneAdvice}`;
680
+ }
681
+ if (scenePeriodMatchesIdle) {
682
+ return `Write idle_repeats: ${idleCount}, ${clipField}, scene.repeats.idle: ${idleCount}, and scene.animations.idle.duration: ${idleDuration} ` +
683
+ `(composed camera terminal key ${idleDuration} s, authored terminal key stays at ${idlePeriod} s).`;
684
+ }
685
+ return `Write idle_repeats: ${idleCount} and ${clipField} (${idleDuration} s). ${unknownScenePeriod}`;
686
+ }
687
+ const limit = String(search.limit).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
651
688
  return `No pair within ${limit} copies of each for source idle ${idlePeriod} s and source clip ${clipPeriod} s. ` +
652
689
  'Retime the clip at its source in motion.animations_from, change the source idle\'s motion.duration, or declare false.';
653
690
  }
@@ -1844,8 +1881,18 @@ export function composeScene(
1844
1881
  if (!Number.isFinite(foldedDuration) || foldedDuration <= 0 || compareRepeatDurations(idleDuration, foldedDuration) !== 0) {
1845
1882
  const idleField = c.idle_repeats === undefined ? `character ${show(c.id)}'s source idle` : `${character}.idle_repeats: ${c.idle_repeats} (implies ${c.idle_repeats * sourceIdle} s)`;
1846
1883
  const sceneField = clip === undefined ? '' : ` ${sceneIdleClock} declares ${clip.duration} s.`;
1847
- const advice = idleRepeatAdvice(name, sourceIdle, period, sceneIdleRepeat === undefined && clip?.duration === sourceIdle);
1848
- fail('SCENE_WITH_IDLE_DURATION', object, `character ${show(c.id)} clip ${show(name)} at ${count} × ${period} s implies ${foldedDuration} s. The played idle is ${idleDuration} s with ${idleField}.${sceneField} ${advice}`);
1884
+ const data: WithIdleDurationData = {
1885
+ idle_period: sourceIdle,
1886
+ clip_period: period,
1887
+ search: { limit: WITH_IDLE_DIAGNOSTIC_COPY_LIMIT, result: searchIdleRepeats(sourceIdle, period) },
1888
+ };
1889
+ const advice = idleRepeatAdvice(name, data, sceneIdleRepeat === undefined && clip?.duration === sourceIdle);
1890
+ const problem: Problem & { data: WithIdleDurationData } = {
1891
+ code: 'SCENE_WITH_IDLE_DURATION', object,
1892
+ detail: `character ${show(c.id)} clip ${show(name)} at ${count} × ${period} s implies ${foldedDuration} s. The played idle is ${idleDuration} s with ${idleField}.${sceneField} ${advice}`,
1893
+ data,
1894
+ };
1895
+ problems.push(problem);
1849
1896
  continue;
1850
1897
  }
1851
1898
  clips.set(name, source);
@@ -2633,8 +2680,7 @@ export function unprefixedNames(rig: RigSpec, motion: MotionSpec, ids: readonly
2633
2680
  // the stage
2634
2681
  // ---------------------------------------------------------------------------
2635
2682
 
2636
- function readSceneComposition(scenePath: string, mode: PackMode, accept: readonly string[], checkBuilds: boolean, requirementsPath?: string, verifyRepeatSource?: (build: CharacterBuild, object: string) => void) {
2637
- const scene = loadScene(scenePath);
2683
+ function readSceneComposition(scene: SceneFile, mode: PackMode, accept: readonly string[], checkBuilds: boolean, requirementsPath?: string, verifyRepeatSource?: (build: CharacterBuild, object: string) => void) {
2638
2684
  const problems: Problem[] = acceptProblems(accept, '--accept');
2639
2685
  const builds = scene.characters.map((c) => readCharacterBuild(c, problems, accept, checkBuilds));
2640
2686
  let plate: PlateImage | null = null;
@@ -2683,13 +2729,14 @@ function readSceneComposition(scenePath: string, mode: PackMode, accept: readonl
2683
2729
  }
2684
2730
  }
2685
2731
  const composed = composeScene(scene, builds, plate, problems, mode, req, plateLayers, verifyRepeatSource);
2686
- return { scene, builds, plate, plateLayers, composed };
2732
+ return { builds, plate, plateLayers, composed };
2687
2733
  }
2688
2734
 
2689
2735
  /** Read the declared composition before character checks. The diagnostic gates its own scratch candidate. */
2690
2736
  export function readSceneForClipStretch(scenePath: string, mode: PackMode):
2691
2737
  Pick<ComposedScene, 'rig' | 'motion' | 'images'> & { explicitlyPlayed: ReadonlySet<string> } {
2692
- const { scene, composed: { rig, motion, images } } = readSceneComposition(scenePath, mode, [], false);
2738
+ const scene = loadScene(scenePath);
2739
+ const { composed: { rig, motion, images } } = readSceneComposition(scene, mode, [], false);
2693
2740
  const explicitlyPlayed = new Set([...Object.keys(scene.animations ?? {}), ...Object.keys(scene.camera?.tracks ?? {})]);
2694
2741
  for (const character of scene.characters) {
2695
2742
  for (const clip of Object.keys(character.with_idle ?? {})) explicitlyPlayed.add(prefixed(character.id, clip));
@@ -2703,7 +2750,11 @@ export function readSceneForClipStretch(scenePath: string, mode: PackMode):
2703
2750
  * then compose the scene and bind the inputs in the run record.
2704
2751
  */
2705
2752
  export function composeFromFiles(scenePath: string, requirementsPath?: string, mode: PackMode = { pageEdges: DEFAULT_PAGE_EDGES, packShape: DEFAULT_PACK_SHAPE }, accept: readonly string[] = [], verifyRepeatSource?: (build: CharacterBuild, object: string) => void): ComposedScene & { runRecord: ComposeRun } {
2706
- const { scene, builds, plate, plateLayers, composed } = readSceneComposition(scenePath, mode, accept, true, requirementsPath, verifyRepeatSource);
2753
+ return composeLoadedScene(loadScene(scenePath), scenePath, mode, accept, requirementsPath, verifyRepeatSource);
2754
+ }
2755
+
2756
+ function composeLoadedScene(scene: SceneFile, scenePath: string, mode: PackMode, accept: readonly string[], requirementsPath?: string, verifyRepeatSource?: (build: CharacterBuild, object: string) => void): ComposedScene & { runRecord: ComposeRun } {
2757
+ const { builds, plate, plateLayers, composed } = readSceneComposition(scene, mode, accept, true, requirementsPath, verifyRepeatSource);
2707
2758
  const runRecord: ComposeRun = {
2708
2759
  spec: COMPOSE_RUN_SPEC,
2709
2760
  scene: { path: scenePath, sha256: scene.sha256 },
@@ -2729,6 +2780,8 @@ export interface ComposeInput {
2729
2780
  requirements?: string;
2730
2781
  /** Declared RGBA loop seam bar and warm-up cap for the composed idle render (issue #1590). */
2731
2782
  loopSeam?: LoopSeamRequest;
2783
+ /** Render and judge the same frames on the published, gated composed build. */
2784
+ motionSeams?: ComposeSeamRequest;
2732
2785
  /** The selected output profile, absent for the full diagnostics (issue #1610). */
2733
2786
  outputProfile?: ComposeRun['output_profile'];
2734
2787
  /** `--accept`: the bars every character's own check may fail and still be composed (issue #203). */
@@ -2743,7 +2796,7 @@ export interface ComposeRunners {
2743
2796
  scratch: string;
2744
2797
  }
2745
2798
 
2746
- export type ComposeStage = 'compose' | 'check';
2799
+ export type ComposeStage = 'compose' | 'check' | 'motion-seams';
2747
2800
 
2748
2801
  export interface ComposeResult {
2749
2802
  stoppedAt: ComposeStage | null;
@@ -2751,15 +2804,17 @@ export interface ComposeResult {
2751
2804
  check: CheckReport | null;
2752
2805
  }
2753
2806
 
2754
- /** Refuse before resolving rigc in the CLI, and before the gate for direct stage callers. */
2755
- export function refusePreviewLoopSeam(input: ComposeInput): void {
2756
- if (input.outputProfile !== 'preview' || input.loopSeam === undefined) return;
2757
- for (const p of COMPOSE_OWNS) rmSync(join(input.out, p), { recursive: true, force: true });
2758
- throw new PartsError([{
2759
- code: 'COMPOSE_PREVIEW_REQUIRED_CHECK',
2760
- object: '--loop-seam-bar',
2761
- detail: COMPOSE_PREVIEW_LOOP_SEAM_DETAIL,
2762
- }]);
2807
+ type ComposePreviewWithLoopSeam = ComposeInput & { outputProfile: 'preview'; loopSeam: LoopSeamRequest };
2808
+ type PreviewRefusalPrinter = (err: PartsError) => void;
2809
+
2810
+ /** This combination refuses before the CLI needs to resolve rigc. */
2811
+ export function isComposePreviewWithLoopSeam(input: ComposeInput): input is ComposePreviewWithLoopSeam {
2812
+ return input.outputProfile === 'preview' && input.loopSeam !== undefined;
2813
+ }
2814
+
2815
+ /** Clear prior refusal evidence before prevalidation or a new stage run. */
2816
+ export function clearComposeRefusal(out: string): void {
2817
+ rmSync(join(out, COMPOSE_REFUSAL_FILE), { force: true });
2763
2818
  }
2764
2819
 
2765
2820
  /**
@@ -2772,35 +2827,77 @@ export function refusePreviewLoopSeam(input: ComposeInput): void {
2772
2827
  * `build` prints its stages. The paths {@link COMPOSE_OWNS} names are cleared
2773
2828
  * first. A crash that is not a refusal is rethrown.
2774
2829
  */
2775
- export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log): ComposeResult {
2830
+ export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log): ComposeResult;
2831
+ /** CLI preview preflight uses its own refusal printer and needs no rigc runners. */
2832
+ export function composeStage(input: ComposePreviewWithLoopSeam, run: PreviewRefusalPrinter, log: Log): ComposeResult;
2833
+ export function composeStage(input: ComposeInput, run: ComposeRunners | PreviewRefusalPrinter, log: Log): ComposeResult {
2776
2834
  // Clear before even option validation: a refused rerun cannot retain an earlier receipt.
2777
2835
  clearComposeRun(input.out);
2836
+ clearComposeRefusal(input.out);
2778
2837
  const prefix = (stage: ComposeStage): Log => (line) => log(`[${stage}] ${line}`);
2779
2838
  const say = prefix('compose');
2780
- const refused = (stage: ComposeStage, err: unknown, composed: ComposedScene | null = null): ComposeResult => {
2839
+ // Keep the bytes read for parsing, including when parsing or a later gate refuses.
2840
+ let source: SceneSource | undefined;
2841
+ const readSource = (): SceneSource => source ??= readSceneSource(input.scene);
2842
+ const refused = (stage: ComposeStage, err: unknown, composed: ComposedScene | null = null, print?: PreviewRefusalPrinter): ComposeResult => {
2781
2843
  if (!(err instanceof PartsError)) throw err;
2782
- const p = prefix(stage);
2783
- for (const x of err.problems) {
2784
- if (x.code === LOOP_SEAM_BAR_UNMET) log(x.detail);
2785
- else p(failLine(x));
2844
+ const read = readSource();
2845
+ // A preflight refusal can precede the read. Keep it first and explain a missing digest in the same finding stream.
2846
+ const refusal = 'problem' in read && !err.problems.includes(read.problem)
2847
+ ? new PartsError([...err.problems, read.problem])
2848
+ : err;
2849
+ const count = refusal.problems.length;
2850
+ writeFileSync(join(input.out, COMPOSE_REFUSAL_FILE), rigJsonText({
2851
+ spec: COMPOSE_REFUSAL_SPEC,
2852
+ parts_version: partsPackage.version,
2853
+ scene: { path: input.scene, sha256: 'problem' in read ? null : read.sha256 },
2854
+ stage,
2855
+ count,
2856
+ findings: refusal.problems.map(problem => ({
2857
+ code: problem.code,
2858
+ object: problem.object,
2859
+ detail: problem.detail,
2860
+ data: problem.code === 'SCENE_WITH_IDLE_DURATION' && 'data' in problem ? problem.data ?? null : null,
2861
+ })),
2862
+ }));
2863
+ if (stage === 'motion-seams') {
2864
+ for (const problem of refusal.problems) say(failLine(problem));
2865
+ log('compose: stopped at motion-seams; the composed rig and its check were written');
2866
+ } else if (print !== undefined) print(refusal);
2867
+ else {
2868
+ const p = prefix(stage);
2869
+ for (const x of refusal.problems) {
2870
+ if (x.code === LOOP_SEAM_BAR_UNMET) log(x.detail);
2871
+ else p(failLine(x));
2872
+ }
2873
+ p(`refused: ${count} problem(s)`);
2874
+ log(`compose: stopped at ${stage}; nothing ${stage === 'compose' ? 'was written' : 'after the check was written'}`);
2786
2875
  }
2787
- p(`refused: ${err.problems.length} problem(s)`);
2788
- log(`compose: stopped at ${stage}; nothing ${stage === 'compose' ? 'was written' : 'after the check was written'}`);
2789
2876
  return { stoppedAt: stage, composed, check: null };
2790
2877
  };
2791
2878
  const pageSize = parsePageSize(input.pageSize);
2792
- try {
2793
- refusePreviewLoopSeam(input);
2794
- } catch (err) {
2795
- return refused('compose', err);
2796
- }
2797
2879
  mkdirSync(input.out, { recursive: true });
2798
2880
  for (const p of COMPOSE_OWNS) rmSync(join(input.out, p), { recursive: true, force: true });
2881
+ if (isComposePreviewWithLoopSeam(input)) {
2882
+ const err = new PartsError([{ code: 'COMPOSE_PREVIEW_REQUIRED_CHECK', object: '--loop-seam-bar', detail: COMPOSE_PREVIEW_LOOP_SEAM_DETAIL }]);
2883
+ return refused('compose', err, null, typeof run === 'function' ? run : undefined);
2884
+ }
2885
+ if (typeof run === 'function') throw new Error('composeStage requires rigc runners for this input');
2886
+ if (input.motionSeams !== undefined) {
2887
+ const version = run.rig(['--version']);
2888
+ const found = version.out.trim().split('\n')[0];
2889
+ if (version.status !== 0 || found !== COMPOSE_SEAMS_CORE) {
2890
+ return refused('compose', new PartsError([{
2891
+ code: 'COMPOSE_MOTION_SEAMS_CORE', object: 'rigc --version',
2892
+ detail: `exit ${version.status}, printed ${show(found)}; ${COMPOSE_SEAMS_CORE} is required to gate the bound render`,
2893
+ }]));
2894
+ }
2895
+ }
2799
2896
  const mode: PackMode = { pageEdges: DEFAULT_PAGE_EDGES, packShape: DEFAULT_PACK_SHAPE, ...(pageSize === undefined ? {} : { pageSize }) };
2800
2897
  log(`rig-parts compose: ${input.scene} -> ${input.out}, page edges ${mode.pageEdges}, pack shape ${mode.packShape}`);
2801
2898
  let composed: ReturnType<typeof composeFromFiles>;
2802
2899
  try {
2803
- composed = composeFromFiles(input.scene, input.requirements, mode, input.accept ?? [], (b, object) => {
2900
+ composed = composeLoadedScene(parseScene(readSource()), input.scene, mode, input.accept ?? [], input.requirements, (b, object) => {
2804
2901
  if (b.repeatSource === undefined) throw new Error(`${object}: missing source gate inputs`);
2805
2902
  const [source] = gateThroughRigc(b.images, b.repeatSource, run.rig, run.scratch, null, build => {
2806
2903
  refuseIfAny(sceneRepeatSourceLoopProblems(readFileSync(join(build, 'skeleton.model.json'), 'utf8'), object));
@@ -2935,7 +3032,10 @@ export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log)
2935
3032
  };
2936
3033
  const preview = input.outputProfile === 'preview';
2937
3034
  const noExtremes = input.outputProfile !== undefined;
2938
- const checkLog = prefix('check');
3035
+ const checkLog: Log = line => {
3036
+ const suffix = input.motionSeams === undefined && line.startsWith(` ${MOTION_SEAM_LINE}:`) ? `; ${COMPOSE_SEAMS_OFF}` : '';
3037
+ log(`[check] ${line}${suffix}`);
3038
+ };
2939
3039
  if (noExtremes) {
2940
3040
  const flag = preview ? '--output-profile preview' : '--no-extremes';
2941
3041
  checkLog(` extremes: SKIP — ${flag} omits the extra diagnostic renders`);
@@ -2965,6 +3065,29 @@ export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log)
2965
3065
  return refused('compose', new PartsError([{ code: 'SCENE_CAMERA_BACKDROP', object: 'check/build', detail: 'the checked model did not bind to the green camera audit; an exact packed artifact match is required' }]));
2966
3066
  }
2967
3067
  writeCameraReport();
3068
+ if (input.motionSeams !== undefined) {
3069
+ const request = input.motionSeams;
3070
+ const track = camera?.tracks.get(request.animation);
3071
+ const viewport = request.viewport;
3072
+ const canvas = composed.rig.skeleton;
3073
+ const frameView = (time: number, duration: number): Viewport => {
3074
+ if (viewport !== undefined) {
3075
+ const [x, y, width, height] = viewport;
3076
+ return { minX: x, minY: y, maxX: x + width, maxY: y + height, scale: 1, width, height };
3077
+ }
3078
+ const authored = duration === 0 || time >= duration ? track?.duration ?? 0 : time / duration * (track?.duration ?? 0);
3079
+ const view = cameraViewport(canvas, track?.sample(authored) ?? { pan: [0, 0], zoom: 1 });
3080
+ if (view === null) throw new PartsError([{ code: 'COMPOSE_MOTION_SEAMS_VIEWPORT', object: request.animation,
3081
+ detail: `frame at ${time}s requires a finite, positive view` }]);
3082
+ return view;
3083
+ };
3084
+ try {
3085
+ const { animation, fps, frame_count, verdict } = writeComposeSeams(input.out, request, report, frameView);
3086
+ say(` bound motion seams: ${verdict.status} — ${show(animation)} at ${fps} fps, ${frame_count} frame(s), ${verdict.measured} measured, ${verdict.skipped} skipped, ${verdict.failing_frames} failing pair/frame(s); wrote ${join(input.out, COMPOSE_SEAMS_DIR, 'report.json')}`);
3087
+ } catch (err) {
3088
+ return { ...refused('motion-seams', err, composed), check: report };
3089
+ }
3090
+ }
2968
3091
  // Issue #203: a character taken with an accepted failing bar never makes the scene green, even when the composed
2969
3092
  // rig's check passes or skips that bar.
2970
3093
  const taken = r.characters.filter((c) => c.accepted !== undefined).map((c) => `"${c.id}" (${(c.accepted as string[]).join(', ')})`);