rig-parts 2.66.0 → 2.68.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
@@ -127,7 +127,13 @@ import { clearComposeRun, COMPOSE_RUN_FILE, COMPOSE_RUN_SPEC, type ComposeRun, t
127
127
  import { readRequirements, type RequirementsFile } from './requirements.ts';
128
128
  import { OFFSET_PLACES, rigJsonText, type RigSpec } from './rig.ts';
129
129
  import { pyRound } from './round.ts';
130
- import { mergeSceneAnimations, readSceneAnimations, readSceneCamera, repeatSceneAnimations, resolveSceneCamera, sceneBoneContext, sceneClipLoopProblems, sceneRepeatCurveProblems, sceneRepeatSourceLoopProblems, type ResolvedSceneCamera, type ResolvedSceneCameraTrack, type SceneAnimations, type SceneCamera, type SceneCameraSample, type ScenePlacementPivot } from './sceneclips.ts';
130
+ import {
131
+ FORCE_PHYSICS_TRACK_PROPERTIES, isSceneBoneProperty, mergeSceneAnimations, readSceneAnimations, readSceneCamera, repeatSceneAnimations, resolveSceneCamera,
132
+ sceneBoneContext, sceneClipLoopProblems, sceneDrivenTakes, sceneRepeatCurveProblems, sceneRepeatSourceLoopProblems,
133
+ UNSCALED_PHYSICS_TRACK_PROPERTIES,
134
+ type ResolvedSceneCamera, type ResolvedSceneCameraTrack, type SceneAnimations, type SceneCamera, type SceneCameraSample,
135
+ type SceneChannelAudit, type SceneDrivenTake, type ScenePlacementPivot,
136
+ } from './sceneclips.ts';
131
137
  import { repeatSceneKeys, type SceneRepeatSeam } from './scenerepeat.ts';
132
138
 
133
139
  /** The scene file's `spec`. */
@@ -679,7 +685,7 @@ export function checkBarsFailed(ck: Readonly<Record<string, unknown>>): string[]
679
685
  * from {@link barsNotMet}. Without an accept list the refusal reads as it
680
686
  * always did.
681
687
  */
682
- export function readCharacterBuild(c: SceneCharacter, problems: Problem[], accept: readonly string[] = []): CharacterBuild | null {
688
+ export function readCharacterBuild(c: SceneCharacter, problems: Problem[], accept: readonly string[] = [], checkBuild = true): CharacterBuild | null {
683
689
  const before = problems.length;
684
690
  const dir = c.buildDir;
685
691
  const who = `character "${c.id}" (${c.build})`;
@@ -696,10 +702,11 @@ export function readCharacterBuild(c: SceneCharacter, problems: Problem[], accep
696
702
  };
697
703
  const json = (path: string, what: string): unknown => readJson(join(dir, path), what, problems, bytes => consumed(path, bytes));
698
704
  if (!existsSync(dir) || !statSync(dir).isDirectory()) {
699
- problems.push({ code: 'SCENE_BUILD_PRESENT', object: who, detail: `${dir} is not a directory; the --out of a green \`rig-parts build\` is required` });
705
+ const required = checkBuild ? 'the --out of a green `rig-parts build`' : 'a directory holding parts.json and rig/';
706
+ problems.push({ code: 'SCENE_BUILD_PRESENT', object: who, detail: `${dir} is not a directory; ${required} is required` });
700
707
  return null;
701
708
  }
702
- const check = json('check/check.json', "the build's own check; a build that ran its check writes it");
709
+ const check = checkBuild ? json('check/check.json', "the build's own check; a build that ran its check writes it") : undefined;
703
710
  const joined = new Set([...accept, ...c.accept]);
704
711
  let accepted: string[] = [];
705
712
  if (check !== undefined) {
@@ -1008,8 +1015,7 @@ export const UNSCALED_TRACK_PROPERTIES: readonly string[] = ['rotate', 'scale',
1008
1015
  * character cannot be reproduced by a single timeline value when the constraint drives
1009
1016
  * both or when `referenceScale` is shared across characters (issue #1485; see {@link physicsForce}).
1010
1017
  */
1011
- export const UNSCALED_PHYSICS_TRACK_PROPERTIES: readonly string[] = ['inertia', 'strength', 'damping', 'mass', 'mix', 'reset'];
1012
- export const FORCE_PHYSICS_TRACK_PROPERTIES: readonly string[] = ['wind', 'gravity'];
1018
+ export { UNSCALED_PHYSICS_TRACK_PROPERTIES, FORCE_PHYSICS_TRACK_PROPERTIES };
1013
1019
 
1014
1020
  /** The two properties a transform constraint or a slider reads or drives in length (`propertyScale` in `SkeletonJson.js`). */
1015
1021
  function lengthProperty(name: string): boolean {
@@ -1167,6 +1173,7 @@ export function scaledConstraint(con: Record<string, unknown>, s: number): Recor
1167
1173
  case 'slider':
1168
1174
  if (sliderInputIsLength(con)) {
1169
1175
  len('from');
1176
+ len('max');
1170
1177
  out.scale = scaledBy(typeof con.scale === 'number' ? con.scale : SPINE_SLIDER_SCALE_DEFAULT, 1 / s);
1171
1178
  }
1172
1179
  break;
@@ -1395,6 +1402,7 @@ interface SceneReportV1 {
1395
1402
  characters: SceneCharacterReport[];
1396
1403
  order: { declared: string[]; slots: string[]; judged_by: 'nothing' };
1397
1404
  idle_duration: number;
1405
+ scene_driven: Record<string, SceneDrivenTake>;
1398
1406
  repeats?: Record<string, number>;
1399
1407
  }
1400
1408
 
@@ -1411,6 +1419,8 @@ export interface ComposedScene {
1411
1419
  report: SceneReport;
1412
1420
  /** Opt-in declaration retained for pre-emission pose measurement; never serialized. */
1413
1421
  sceneAnimations?: SceneAnimations;
1422
+ /** Ownership verdict awaiting Core's validation. */
1423
+ sceneChannels?: SceneChannelAudit;
1414
1424
  /** Compiled timeline addresses checked at the final gate; never serialized. */
1415
1425
  repeatSeams: SceneRepeatSeam[];
1416
1426
  sceneCamera?: ResolvedSceneCamera;
@@ -1935,10 +1945,9 @@ export function composeScene(
1935
1945
  };
1936
1946
  // A generated pivot must not resolve an undeclared source bone reference.
1937
1947
  // Group members can also be slots or physics constraints, depending on the property.
1938
- const isBoneProperty = (property: string): boolean => SCALED_TRACK_PROPERTIES.includes(property) || UNSCALED_TRACK_PROPERTIES.includes(property);
1939
1948
  const sceneBoneGroups = new Set<string>();
1940
1949
  if (pivots.size > 0) for (const clip of Object.values(scene.animations ?? {})) for (const track of clip.tracks) {
1941
- if (track.group !== undefined && isBoneProperty(track.property)) sceneBoneGroups.add(track.group);
1950
+ if (track.group !== undefined && isSceneBoneProperty(track.property)) sceneBoneGroups.add(track.group);
1942
1951
  }
1943
1952
  for (const b of ready) if (pivots.has(b.id) && !bonesOf.get(b.id)?.has(PLACEMENT_BONE)) {
1944
1953
  const check = (name: unknown, where: string): void => {
@@ -1954,7 +1963,7 @@ export function composeScene(
1954
1963
  const boneGroups = new Set(Object.keys(b.motion.groups).filter(group => sceneBoneGroups.has(prefixed(b.id, group))));
1955
1964
  for (const [name, anim] of Object.entries(animationsOf(b.motion))) for (const [i, track] of anim.tracks.entries()) {
1956
1965
  check(track.bone, `motion.json animations.${name}.tracks[${i}].bone`);
1957
- if (track.group !== undefined && isBoneProperty(track.property)) boneGroups.add(track.group);
1966
+ if (track.group !== undefined && isSceneBoneProperty(track.property)) boneGroups.add(track.group);
1958
1967
  }
1959
1968
  for (const group of boneGroups) {
1960
1969
  if (b.motion.groups[group]?.includes(PLACEMENT_BONE)) check(PLACEMENT_BONE, `motion.json groups.${group}`);
@@ -2312,7 +2321,7 @@ export function composeScene(
2312
2321
  }
2313
2322
  for (const [animation, clip] of Object.entries(scene.animations)) for (const [i, track] of clip.tracks.entries()) {
2314
2323
  const group = track.group;
2315
- const members = group !== undefined && isBoneProperty(track.property) && Object.hasOwn(groups, group) ? groups[group] : [];
2324
+ const members = group !== undefined && isSceneBoneProperty(track.property) && Object.hasOwn(groups, group) ? groups[group] : [];
2316
2325
  const targets = track.bone === undefined ? members : [track.bone];
2317
2326
  for (const bone of new Set(targets)) {
2318
2327
  const id = undeclaredPivots.get(bone);
@@ -2326,12 +2335,13 @@ export function composeScene(
2326
2335
  }
2327
2336
  let sceneAnimations = scene.animations;
2328
2337
  let sceneCamera: ResolvedSceneCamera | undefined;
2338
+ let sceneChannels: SceneChannelAudit | undefined;
2329
2339
  try {
2330
2340
  if (scene.repeats !== undefined) {
2331
2341
  const repeated = repeatSceneAnimations(scene.animations, motion.groups, scene.repeats, repeatSeams);
2332
2342
  if (scene.animations !== undefined) sceneAnimations = repeated;
2333
2343
  }
2334
- if (sceneAnimations !== undefined || pivots.size > 0) mergeSceneAnimations(rig, motion, sceneAnimations ?? {}, [...pivots.values()]);
2344
+ if (sceneAnimations !== undefined || pivots.size > 0) sceneChannels = mergeSceneAnimations(rig, motion, sceneAnimations ?? {}, [...pivots.values()]);
2335
2345
  if (scene.camera !== undefined) sceneCamera = resolveSceneCamera(scene.camera, motion, scene.repeats);
2336
2346
  } catch (err) {
2337
2347
  if (!(err instanceof PartsError) || sceneIdleRepeat === undefined || idleClockFields.length === 0) throw err;
@@ -2363,9 +2373,15 @@ export function composeScene(
2363
2373
  characters: rows,
2364
2374
  order: { declared: [...scene.order], slots: slots.map((s) => s.name), judged_by: 'nothing' },
2365
2375
  idle_duration: idleDuration,
2376
+ scene_driven: sceneDrivenTakes(motion, sceneAnimations, sceneCamera),
2366
2377
  ...(scene.repeats === undefined ? {} : { repeats: { ...scene.repeats } }),
2367
2378
  };
2368
- return { rig, motion, images, report, repeatSeams, ...(sceneAnimations === undefined ? {} : { sceneAnimations }), ...(sceneCamera === undefined ? {} : { sceneCamera }) };
2379
+ return {
2380
+ rig, motion, images, report, repeatSeams,
2381
+ ...(sceneAnimations === undefined ? {} : { sceneAnimations }),
2382
+ ...(sceneCamera === undefined ? {} : { sceneCamera }),
2383
+ ...(sceneChannels === undefined ? {} : { sceneChannels }),
2384
+ };
2369
2385
  }
2370
2386
 
2371
2387
  // ---------------------------------------------------------------------------
@@ -2522,17 +2538,10 @@ export function unprefixedNames(rig: RigSpec, motion: MotionSpec, ids: readonly
2522
2538
  // the stage
2523
2539
  // ---------------------------------------------------------------------------
2524
2540
 
2525
- /**
2526
- * Everything before the gate, from the files: the scene, every character's
2527
- * build (with `accept`, `compose --accept`, issue #203), the plate and the
2528
- * `--requirements` file, each read with its problems collected, then
2529
- * {@link composeScene} — one refusal naming every problem the
2530
- * files hold. Pure but for the reads.
2531
- */
2532
- 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 } {
2541
+ function readSceneComposition(scenePath: string, mode: PackMode, accept: readonly string[], checkBuilds: boolean, requirementsPath?: string, verifyRepeatSource?: (build: CharacterBuild, object: string) => void) {
2533
2542
  const scene = loadScene(scenePath);
2534
2543
  const problems: Problem[] = acceptProblems(accept, '--accept');
2535
- const builds = scene.characters.map((c) => readCharacterBuild(c, problems, accept));
2544
+ const builds = scene.characters.map((c) => readCharacterBuild(c, problems, accept, checkBuilds));
2536
2545
  let plate: PlateImage | null = null;
2537
2546
  if (scene.plate !== null) {
2538
2547
  const ledger = readEditorReceipts(scene.plate.editor_receipts, scene.path, 'scene.plate.editor_receipts', 'scene file');
@@ -2579,6 +2588,27 @@ export function composeFromFiles(scenePath: string, requirementsPath?: string, m
2579
2588
  }
2580
2589
  }
2581
2590
  const composed = composeScene(scene, builds, plate, problems, mode, req, plateLayers, verifyRepeatSource);
2591
+ return { scene, builds, plate, plateLayers, composed };
2592
+ }
2593
+
2594
+ /** Read the declared composition before character checks. The diagnostic gates its own scratch candidate. */
2595
+ export function readSceneForClipStretch(scenePath: string, mode: PackMode):
2596
+ Pick<ComposedScene, 'rig' | 'motion' | 'images'> & { explicitlyPlayed: ReadonlySet<string> } {
2597
+ const { scene, composed: { rig, motion, images } } = readSceneComposition(scenePath, mode, [], false);
2598
+ const explicitlyPlayed = new Set([...Object.keys(scene.animations ?? {}), ...Object.keys(scene.camera?.tracks ?? {})]);
2599
+ for (const character of scene.characters) {
2600
+ for (const clip of Object.keys(character.with_idle ?? {})) explicitlyPlayed.add(prefixed(character.id, clip));
2601
+ }
2602
+ return { rig, motion, images, explicitlyPlayed };
2603
+ }
2604
+
2605
+ /**
2606
+ * Everything before the compose gate: read the scene, every character's
2607
+ * checked build (with `compose --accept`, issue #203), plates and requirements,
2608
+ * then compose the scene and bind the inputs in the run record.
2609
+ */
2610
+ 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 } {
2611
+ const { scene, builds, plate, plateLayers, composed } = readSceneComposition(scenePath, mode, accept, true, requirementsPath, verifyRepeatSource);
2582
2612
  const runRecord: ComposeRun = {
2583
2613
  spec: COMPOSE_RUN_SPEC,
2584
2614
  scene: { path: scenePath, sha256: scene.sha256 },
@@ -2716,8 +2746,9 @@ export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log)
2716
2746
  const gated: { camera?: CameraEvidence } = {};
2717
2747
  let gate: ReturnType<typeof gateThroughRigc>;
2718
2748
  try {
2719
- const { sceneAnimations: clips, repeatSeams } = composed;
2749
+ const { sceneAnimations: clips, repeatSeams, sceneChannels } = composed;
2720
2750
  const checkMotion = (build: string): void => {
2751
+ refuseIfAny(sceneChannels?.problems ?? []);
2721
2752
  if (clips === undefined && repeatSeams.length === 0) return;
2722
2753
  const modelText = readFileSync(join(build, CAMERA_MODEL), 'utf8');
2723
2754
  refuseIfAny(sceneRepeatCurveProblems(modelText, repeatSeams));
package/src/sceneclips.ts CHANGED
@@ -43,6 +43,79 @@ export interface ResolvedSceneCamera {
43
43
  tracks: ReadonlyMap<string, ResolvedSceneCameraTrack>;
44
44
  }
45
45
 
46
+ export interface SceneDrivenTake {
47
+ view: boolean;
48
+ timelines: string[];
49
+ }
50
+
51
+ /** Local bone axes written by each Spine 4.x timeline property. */
52
+ export const SCENE_BONE_AXES: Readonly<Record<string, readonly string[]>> = {
53
+ translate: ['x', 'y'],
54
+ translatex: ['x'],
55
+ translatey: ['y'],
56
+ scale: ['scaleX', 'scaleY'],
57
+ scalex: ['scaleX'],
58
+ scaley: ['scaleY'],
59
+ shear: ['shearX', 'shearY'],
60
+ shearx: ['shearX'],
61
+ sheary: ['shearY'],
62
+ rotate: ['rotation'],
63
+ inherit: ['inherit'],
64
+ };
65
+
66
+ export function isSceneBoneProperty(property: string): boolean {
67
+ return Object.hasOwn(SCENE_BONE_AXES, property);
68
+ }
69
+
70
+ type SceneTrack = SceneAnimations[string]['tracks'][number];
71
+
72
+ export const UNSCALED_PHYSICS_TRACK_PROPERTIES: readonly string[] = ['inertia', 'strength', 'damping', 'mass', 'mix', 'reset'];
73
+ export const FORCE_PHYSICS_TRACK_PROPERTIES: readonly string[] = ['wind', 'gravity'];
74
+
75
+ function trackTargets(track: SceneTrack, groups: MotionSpec['groups']): string[] {
76
+ const direct = track.bone ?? track.slot ?? track.physics ?? track.path ?? track.slider;
77
+ if (direct !== undefined) return [direct];
78
+ return track.group !== undefined && Object.hasOwn(groups, track.group) ? groups[track.group] : [];
79
+ }
80
+
81
+ function trackFamily(track: SceneTrack): 'bone' | 'slot' | 'physics' | 'path' | 'slider' {
82
+ if (track.physics !== undefined) return 'physics';
83
+ if (track.path !== undefined) return 'path';
84
+ if (track.slider !== undefined) return 'slider';
85
+ if (track.group !== undefined && (UNSCALED_PHYSICS_TRACK_PROPERTIES.includes(track.property) ||
86
+ FORCE_PHYSICS_TRACK_PROPERTIES.includes(track.property))) return 'physics';
87
+ if (track.bone !== undefined) return 'bone';
88
+ if (isSceneBoneProperty(track.property)) return 'bone';
89
+ return 'slot'; // Core validates that the property belongs to this family.
90
+ }
91
+
92
+ function timelineName(name: string): string {
93
+ return name.replaceAll('%', '%25').replaceAll(' ', '%20').replaceAll('.', '%2E').replaceAll('/', '%2F');
94
+ }
95
+
96
+ /** Report authored scene addresses on the composed clock. Core validates the targets at the gate. */
97
+ export function sceneDrivenTakes(motion: MotionSpec, clips?: SceneAnimations, camera?: ResolvedSceneCamera): Record<string, SceneDrivenTake> {
98
+ return Object.fromEntries(Object.keys(motion.animations).sort().map(name => {
99
+ const clip = clips !== undefined && Object.hasOwn(clips, name) ? clips[name] : undefined;
100
+ const timelines: string[] = [];
101
+ for (const track of clip?.tracks ?? []) {
102
+ const family = trackFamily(track);
103
+ for (const target of trackTargets(track, motion.groups)) timelines.push(`${family} ${timelineName(target)}.${track.property}`);
104
+ }
105
+ for (const family of ['ik', 'transform'] as const) {
106
+ for (const track of clip?.[family] ?? []) timelines.push(`${family} ${timelineName(track.constraint)}`);
107
+ }
108
+ for (const family of ['deform', 'sequence'] as const) {
109
+ for (const track of clip?.[family] ?? []) {
110
+ const target = [track.skin ?? 'default', track.slot, track.attachment].map(timelineName).join('/');
111
+ timelines.push(`${family} ${target}`);
112
+ }
113
+ }
114
+ if (clip?.drawOrder?.length) timelines.push('drawOrder');
115
+ return [name, { view: camera?.tracks.has(name) ?? false, timelines: timelines.sort() }];
116
+ }));
117
+ }
118
+
46
119
  const CAMERA_TRACK = 'SCENE_CAMERA_TRACK';
47
120
  const CAMERA_LOOP = 'SCENE_CAMERA_LOOP_CLOSES';
48
121
  const CAMERA_PAN_CURVE_LENGTH = 8;
@@ -445,8 +518,9 @@ function sliderInputChannel(source: unknown, property: string): number | null {
445
518
  }
446
519
 
447
520
  /** Append timelines without changing existing idle payloads or character physics. */
448
- export function mergeSceneAnimations(rig: RigSpec, motion: MotionSpec, clips: SceneAnimations, pivots: readonly ScenePlacementPivot[] = []): void {
521
+ export function mergeSceneAnimations(rig: RigSpec, motion: MotionSpec, clips: SceneAnimations, pivots: readonly ScenePlacementPivot[] = []): SceneChannelAudit {
449
522
  const problems = placementTrackProblems(clips, pivots);
523
+ const audit: SceneChannelAudit = { problems: [] };
450
524
  const animations = motion.animations as unknown as SceneAnimations;
451
525
  for (const [name, clip] of Object.entries(clips)) {
452
526
  const existing = Object.hasOwn(animations, name) ? animations[name] : undefined;
@@ -459,21 +533,21 @@ export function mergeSceneAnimations(rig: RigSpec, motion: MotionSpec, clips: Sc
459
533
  continue;
460
534
  }
461
535
  // Bounds belong to the actual final slider, never to a guessed dial-name list.
462
- // `from` is the declared bottom and `max` the editor's declared top (Core's RigSliderConstraint).
536
+ // Core resolves an omitted `from` to zero. The editor's `max` is authored.
463
537
  for (const track of clip.tracks) {
464
538
  if (track.group !== undefined && (!Object.hasOwn(motion.groups, track.group) || !Array.isArray(motion.groups[track.group]))) {
465
539
  problems.push({ code: 'CE_COMPILE_ANIMATION_GROUP_UNKNOWN', object: `scene.animations.${name}`,
466
540
  detail: `animation "${name}": unknown group "${track.group}"; an own declared group is required` });
467
541
  continue;
468
542
  }
469
- const targets = track.bone === undefined ? (track.group === undefined ? [] : motion.groups[track.group]) : [track.bone];
543
+ const targets = trackFamily(track) === 'bone' ? trackTargets(track, motion.groups) : [];
470
544
  for (const bone of targets) for (const slider of rig.constraints ?? []) {
471
545
  if (slider.type !== 'slider' || slider.bone !== bone) continue;
472
546
  const channel = sliderInputChannel(slider.property, track.property);
473
547
  if (channel === null) continue;
474
- const from = slider.from, max = slider.max;
548
+ const from = slider.from === undefined ? 0 : slider.from, max = slider.max;
475
549
  if (typeof from !== 'number' || !Number.isFinite(from) || typeof max !== 'number' || !Number.isFinite(max) || from > max) {
476
- problems.push({ code: 'SCENE_DIAL_RANGE_DECLARED', object: `scene.animations.${name} bone "${bone}" slider "${String(slider.name)}"`, detail: `has no readable declared range: from ${String(from)}, max ${String(max)}; declare both bounds before keying this dial` });
550
+ problems.push({ code: 'SCENE_DIAL_RANGE_DECLARED', object: `scene.animations.${name} bone "${bone}" slider "${String(slider.name)}"`, detail: `has no readable declared range: from ${String(from)}, max ${String(max)}; declare an ordered range with finite max before keying this dial` });
477
551
  continue;
478
552
  }
479
553
  for (const key of track.keys) {
@@ -492,6 +566,7 @@ export function mergeSceneAnimations(rig: RigSpec, motion: MotionSpec, clips: Sc
492
566
  }
493
567
  }
494
568
  }
569
+ audit.problems.push(...sharedBoneAxes(name, clip, existing, motion.groups));
495
570
  if (existing === undefined) Object.defineProperty(animations, name, { value: structuredClone(clip), enumerable: true, configurable: true, writable: true });
496
571
  else {
497
572
  // Core rejects overlapping property claims after expansion, including group/bone collisions.
@@ -503,6 +578,92 @@ export function mergeSceneAnimations(rig: RigSpec, motion: MotionSpec, clips: Sc
503
578
  }
504
579
  }
505
580
  refuseIfAny(problems);
581
+ const writers = characterConstraintWriters(rig, motion.groups, animations);
582
+ for (const [name, clip] of Object.entries(clips)) {
583
+ const bones = boneProperties(clip, motion.groups);
584
+ for (const [bone, properties] of bones) for (const constraint of writers.get(bone) ?? []) {
585
+ const keys = [...properties].map(p => JSON.stringify(p)).join(', ');
586
+ audit.problems.push({
587
+ code: 'SCENE_CHANNEL_SHARED', object: `scene.animations.${name} bone ${JSON.stringify(bone)}`,
588
+ detail: `the scene producer keys ${keys}; the character producer's ${constraint} writes this bone`,
589
+ });
590
+ }
591
+ }
592
+ return audit;
593
+ }
594
+
595
+ /** Check after Core's gate so its existing property and input refusals take precedence. */
596
+ export interface SceneChannelAudit {
597
+ problems: Problem[];
598
+ }
599
+
600
+ function boneProperties(clip: SceneAnimations[string] | undefined, groups: MotionSpec['groups']): Map<string, Set<string>> {
601
+ const bones = new Map<string, Set<string>>();
602
+ for (const track of clip?.tracks ?? []) {
603
+ if (trackFamily(track) !== 'bone') continue;
604
+ for (const bone of trackTargets(track, groups)) {
605
+ const properties = bones.get(bone) ?? new Set<string>();
606
+ properties.add(track.property);
607
+ bones.set(bone, properties);
608
+ }
609
+ }
610
+ return bones;
611
+ }
612
+
613
+ function sharedBoneAxes(name: string, clip: SceneAnimations[string], existing: SceneAnimations[string] | undefined,
614
+ groups: MotionSpec['groups']): Problem[] {
615
+ const problems: Problem[] = [];
616
+ const character = boneProperties(existing, groups);
617
+ for (const [bone, properties] of boneProperties(clip, groups)) {
618
+ const object = `scene.animations.${name} bone ${JSON.stringify(bone)}`;
619
+ for (const scene of properties) {
620
+ if (!isSceneBoneProperty(scene)) {
621
+ problems.push({ code: 'SCENE_BONE_PROPERTY_UNKNOWN', object,
622
+ detail: `the scene producer keys ${JSON.stringify(scene)}; the Spine 4.x axes table covers ${Object.keys(SCENE_BONE_AXES).join(', ')}` });
623
+ continue;
624
+ }
625
+ for (const other of character.get(bone) ?? []) {
626
+ if (scene === other || !isSceneBoneProperty(other)) continue;
627
+ const axes = SCENE_BONE_AXES[scene].filter(axis => SCENE_BONE_AXES[other].includes(axis));
628
+ if (axes.length > 0) problems.push({
629
+ code: 'SCENE_CHANNEL_SHARED', object,
630
+ detail: `the scene producer's ${JSON.stringify(scene)} and the character producer's ${JSON.stringify(other)} both key ${axes.join(', ')}`,
631
+ });
632
+ }
633
+ }
634
+ }
635
+ return problems;
636
+ }
637
+
638
+ function characterConstraintWriters(rig: RigSpec, groups: MotionSpec['groups'], animations: SceneAnimations): Map<string, string[]> {
639
+ const writers = new Map<string, string[]>();
640
+ const register = (family: string, name: unknown, bones: readonly unknown[]): void => {
641
+ for (const bone of bones) {
642
+ if (typeof bone !== 'string') continue;
643
+ const constraints = writers.get(bone) ?? [];
644
+ constraints.push(`${family} constraint ${JSON.stringify(name)}`);
645
+ writers.set(bone, constraints);
646
+ }
647
+ };
648
+ for (const constraint of rig.constraints ?? []) {
649
+ switch (constraint.type) {
650
+ case 'ik': case 'transform': case 'path':
651
+ if (Array.isArray(constraint.bones)) register(constraint.type, constraint.name, constraint.bones);
652
+ break;
653
+ case 'physics':
654
+ register('physics', constraint.name, [constraint.bone]);
655
+ break;
656
+ case 'slider': {
657
+ // The dial is an input. The slider writes the bones keyed by its referenced animation.
658
+ const name = constraint.animation;
659
+ if (typeof name === 'string' && Object.hasOwn(animations, name)) {
660
+ register('slider', constraint.name, [...boneProperties(animations[name], groups).keys()]);
661
+ }
662
+ break;
663
+ }
664
+ }
665
+ }
666
+ return writers;
506
667
  }
507
668
 
508
669
  /** Add character context to Core's existing unknown-bone sentence, without changing its code. */