rig-parts 2.63.1 → 2.65.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/cli.ts +38 -15
- package/docs/AUTHORING.md +194 -36
- package/docs/STABILITY.md +7 -3
- package/package.json +1 -1
- package/src/build.ts +6 -4
- package/src/check.ts +24 -10
- package/src/runstamp.ts +2 -1
- package/src/scene.ts +246 -27
- package/src/sceneclips.ts +195 -45
- package/src/scenerepeat.ts +82 -14
package/src/scene.ts
CHANGED
|
@@ -82,6 +82,9 @@
|
|
|
82
82
|
* `generated`, `unknown`) is copied into `scene.json` and nothing reads it.
|
|
83
83
|
* - **The idle**: one `idle` holding every character's tracks. It can play
|
|
84
84
|
* whole source periods per character when the scene declares `idle_repeats`.
|
|
85
|
+
* A physics-only clip needs a `with_idle` count at scale 1 or an explicit
|
|
86
|
+
* `false` at any scale that the character supports.
|
|
87
|
+
* `scene.repeats` splices scene-authored animation and camera keys.
|
|
85
88
|
* - **A failing bar, by name (issue #203).** A build whose own check is not
|
|
86
89
|
* green is refused (`SCENE_BUILD_GREEN`) unless every bar it failed is named
|
|
87
90
|
* in `compose --accept` or the character's `accept` — the two lists are
|
|
@@ -109,7 +112,7 @@ import { documentPageLookup, readModel, type ModelPageRegion } from '@rig-c/core
|
|
|
109
112
|
import { CandidateAtlasError, CandidatePairError, CoreInputError, loadCandidate, PoserChoiceError, projector, renderFrame, SpineRuntimeError, throughPoser, type Piece, type Quad, type Viewport } from '@rig-c/core/render-shared';
|
|
110
113
|
import { deformSliderCombinationProblem, type RigStop } from '@rig-c/core/rig';
|
|
111
114
|
import { checkStage, gateThroughRigc, type Log } from './build.ts';
|
|
112
|
-
import { ACCEPTABLE_BARS, barsNotMet, CHECK_SPEC, type CheckReport, DEFAULT_PACK_SHAPE, DEFAULT_PAGE_EDGES, IDLE_FPS, LOOP_SEAM_BAR_UNMET, type LoopSeamRequest, type PackMode, parsePageSize, requirementsNotPass, type RigcRunner } from './check.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';
|
|
113
116
|
import { CONSTRAINT_BONE_FIELDS, editorReceiptProblems, ROOT_BONE } from './config.ts';
|
|
114
117
|
import { cropToSpineY } from './coords.ts';
|
|
115
118
|
import { failLine, PartsError, type Problem, refuseIfAny } from './errors.ts';
|
|
@@ -123,8 +126,8 @@ import { clearComposeRun, COMPOSE_RUN_FILE, COMPOSE_RUN_SPEC, type ComposeRun, t
|
|
|
123
126
|
import { readRequirements, type RequirementsFile } from './requirements.ts';
|
|
124
127
|
import { OFFSET_PLACES, rigJsonText, type RigSpec } from './rig.ts';
|
|
125
128
|
import { pyRound } from './round.ts';
|
|
126
|
-
import { mergeSceneAnimations, readSceneAnimations, readSceneCamera, resolveSceneCamera, sceneBoneContext, sceneClipLoopProblems, sceneRepeatSourceLoopProblems, type ResolvedSceneCamera, type ResolvedSceneCameraTrack, type SceneAnimations, type SceneCamera, type SceneCameraSample, type ScenePlacementPivot } from './sceneclips.ts';
|
|
127
|
-
import { repeatSceneKeys } from './scenerepeat.ts';
|
|
129
|
+
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 { repeatSceneKeys, type SceneRepeatSeam } from './scenerepeat.ts';
|
|
128
131
|
|
|
129
132
|
/** The scene file's `spec`. */
|
|
130
133
|
export const SCENE_SPEC = 'spine-parts-scene/1';
|
|
@@ -183,6 +186,8 @@ export interface SceneCharacter {
|
|
|
183
186
|
placement_pivot?: true;
|
|
184
187
|
/** Total number of source idle periods within the declared scene idle. */
|
|
185
188
|
idle_repeats?: number;
|
|
189
|
+
/** Physics-only clips carried into idle by whole periods, or explicitly left beside it. */
|
|
190
|
+
with_idle?: Record<string, number | false>;
|
|
186
191
|
/** The bars this character's own check may have failed and still be taken (issue #203), as the file lists them; empty when it lists none. */
|
|
187
192
|
accept: string[];
|
|
188
193
|
}
|
|
@@ -215,6 +220,7 @@ export interface SceneFile {
|
|
|
215
220
|
plate: ScenePlate | null;
|
|
216
221
|
plates?: NamedScenePlate[];
|
|
217
222
|
animations?: SceneAnimations;
|
|
223
|
+
repeats?: Record<string, number>;
|
|
218
224
|
camera?: SceneCamera;
|
|
219
225
|
characters: SceneCharacter[];
|
|
220
226
|
order: string[];
|
|
@@ -300,7 +306,9 @@ export function loadScene(path: string): SceneFile {
|
|
|
300
306
|
if (!keys.includes(k) && !freeKey(k, v)) fail('SCENE_KEY_KNOWN', `${where}.${k}`, `is a key ${SCENE_SPEC} does not read; it reads ${keys.join(', ')} (and "note", "…_note" strings and "x-…" records, which nothing reads)`);
|
|
301
307
|
}
|
|
302
308
|
};
|
|
303
|
-
|
|
309
|
+
const sceneKeys = ['spec', 'canvas', 'plate', 'plates', 'characters', 'order', 'animations'];
|
|
310
|
+
if ('repeats' in o) sceneKeys.push('repeats');
|
|
311
|
+
known(fields, 'scene', sceneKeys);
|
|
304
312
|
if (o.spec !== SCENE_SPEC) fail('SCENE_SPEC', 'scene.spec', `is ${show(o.spec)}; "${SCENE_SPEC}" is required`);
|
|
305
313
|
|
|
306
314
|
// canvas
|
|
@@ -388,6 +396,7 @@ export function loadScene(path: string): SceneFile {
|
|
|
388
396
|
const keys = ['id', 'build', 'offset', 'scale', 'accept', 'canvas_clip'];
|
|
389
397
|
if ('placement_pivot' in c) keys.push('placement_pivot'); // Keep the default unknown-key diagnostic byte-stable.
|
|
390
398
|
if ('idle_repeats' in c) keys.push('idle_repeats');
|
|
399
|
+
if ('with_idle' in c) keys.push('with_idle');
|
|
391
400
|
known(c, where, keys);
|
|
392
401
|
let ok = true;
|
|
393
402
|
for (const k of ['id', 'build', 'offset']) {
|
|
@@ -439,6 +448,23 @@ export function loadScene(path: string): SceneFile {
|
|
|
439
448
|
fail('SCENE_REPEAT_COUNT', `${where}.idle_repeats`, `is ${show(repeats)}. Declare a safe integer of 2 or more, or omit the field to use one source period`);
|
|
440
449
|
ok = false;
|
|
441
450
|
}
|
|
451
|
+
let withIdle: SceneCharacter['with_idle'];
|
|
452
|
+
if ('with_idle' in c) {
|
|
453
|
+
if (!isRecord(c.with_idle)) {
|
|
454
|
+
fail('SCENE_FIELD_TYPE', `${where}.with_idle`, `is ${show(c.with_idle)}. An object mapping physics-only clip names to repeat counts or false is required`);
|
|
455
|
+
ok = false;
|
|
456
|
+
} else {
|
|
457
|
+
const entries: Array<[string, number | false]> = [];
|
|
458
|
+
for (const [clip, count] of Object.entries(c.with_idle)) {
|
|
459
|
+
if (count === false || (typeof count === 'number' && Number.isSafeInteger(count) && count >= 1)) entries.push([clip, count]);
|
|
460
|
+
else {
|
|
461
|
+
fail('SCENE_REPEAT_COUNT', `${where}.with_idle[${show(clip)}]`, `is ${show(count)}. A safe integer of 1 or more, or false, is required`);
|
|
462
|
+
ok = false;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
withIdle = Object.fromEntries(entries);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
442
468
|
const acc = c.accept;
|
|
443
469
|
if ('accept' in c) {
|
|
444
470
|
if (!(Array.isArray(acc) && acc.every((v) => typeof v === 'string'))) {
|
|
@@ -460,6 +486,7 @@ export function loadScene(path: string): SceneFile {
|
|
|
460
486
|
...(c.canvas_clip === true ? { canvas_clip: true } : {}),
|
|
461
487
|
...(c.placement_pivot === true ? { placement_pivot: true } : {}),
|
|
462
488
|
...(typeof repeats === 'number' ? { idle_repeats: repeats } : {}),
|
|
489
|
+
...(withIdle === undefined ? {} : { with_idle: withIdle }),
|
|
463
490
|
});
|
|
464
491
|
});
|
|
465
492
|
}
|
|
@@ -490,13 +517,26 @@ export function loadScene(path: string): SceneFile {
|
|
|
490
517
|
problems.push(...err.problems);
|
|
491
518
|
}
|
|
492
519
|
}
|
|
520
|
+
let repeats: SceneFile['repeats'];
|
|
521
|
+
if ('repeats' in o) {
|
|
522
|
+
if (!isRecord(o.repeats)) fail('SCENE_FIELD_TYPE', 'scene.repeats', `is ${show(o.repeats)}. An object mapping take names to repeat counts is required`);
|
|
523
|
+
else {
|
|
524
|
+
const entries: Array<[string, number]> = [];
|
|
525
|
+
for (const [take, count] of Object.entries(o.repeats)) {
|
|
526
|
+
if (typeof count === 'number' && Number.isSafeInteger(count) && count >= 2) entries.push([take, count]);
|
|
527
|
+
else fail('SCENE_REPEAT_COUNT', `scene.repeats[${show(take)}]`, `is ${show(count)}. A safe integer of 2 or more is required`);
|
|
528
|
+
}
|
|
529
|
+
repeats = Object.fromEntries(entries);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
493
532
|
if (!(isRecord(o.animations) && Object.hasOwn(o.animations, 'idle'))) {
|
|
494
533
|
for (const c of characters) if (c.idle_repeats !== undefined) {
|
|
495
534
|
fail('SCENE_REPEAT_IDLE_REQUIRED', 'scene.animations.idle', `is absent for character ${show(c.id)} with idle_repeats ${c.idle_repeats}. Declare the scene idle and its duration`);
|
|
496
535
|
}
|
|
497
536
|
}
|
|
498
537
|
refuseIfAny(problems);
|
|
499
|
-
return { path: at, sha256, canvas, plate, ...('plates' in o ? { plates } : {}), ...(animations === undefined ? {} : { animations }),
|
|
538
|
+
return { path: at, sha256, canvas, plate, ...('plates' in o ? { plates } : {}), ...(animations === undefined ? {} : { animations }),
|
|
539
|
+
...(repeats === undefined ? {} : { repeats }), ...(camera === undefined ? {} : { camera }), characters, order };
|
|
500
540
|
}
|
|
501
541
|
|
|
502
542
|
// ---------------------------------------------------------------------------
|
|
@@ -549,6 +589,45 @@ function animationsOf(motion: MotionSpec): Record<string, SceneAnimation> {
|
|
|
549
589
|
return motion.animations as unknown as Record<string, SceneAnimation>;
|
|
550
590
|
}
|
|
551
591
|
|
|
592
|
+
function physicsClipTargets(clip: SceneAnimation): ReadonlySet<string> | undefined {
|
|
593
|
+
if (clip.tracks.length === 0 || Object.entries(clip).some(([key, value]) =>
|
|
594
|
+
!['duration', 'loop', 'note', 'tracks'].includes(key) && value !== undefined && !(Array.isArray(value) && value.length === 0))) return undefined;
|
|
595
|
+
const targets = new Set<string>();
|
|
596
|
+
for (const track of clip.tracks) {
|
|
597
|
+
if (typeof track.physics !== 'string' || track.physics === '' ||
|
|
598
|
+
['bone', 'group', 'slot', 'path', 'slider'].some(key => Object.hasOwn(track, key))) return undefined;
|
|
599
|
+
targets.add(track.physics);
|
|
600
|
+
}
|
|
601
|
+
return targets;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/** Maximum copies of each source searched for a diagnostic hint. Acceptance compares the declared counts directly. */
|
|
605
|
+
const WITH_IDLE_DIAGNOSTIC_COPY_LIMIT = 10_000;
|
|
606
|
+
|
|
607
|
+
function compareRepeatDurations(left: number, right: number): -1 | 0 | 1 {
|
|
608
|
+
return left === right ? 0 : left < right ? -1 : 1;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
function idleRepeatAdvice(idlePeriod: number, clipPeriod: number): string {
|
|
612
|
+
if (Number.isFinite(idlePeriod) && idlePeriod > 0 && Number.isFinite(clipPeriod) && clipPeriod > 0) {
|
|
613
|
+
let idleCount = 1;
|
|
614
|
+
let clipCount = 1;
|
|
615
|
+
while (idleCount <= WITH_IDLE_DIAGNOSTIC_COPY_LIMIT && clipCount <= WITH_IDLE_DIAGNOSTIC_COPY_LIMIT) {
|
|
616
|
+
const idleDuration = idleCount * idlePeriod;
|
|
617
|
+
const clipDuration = clipCount * clipPeriod;
|
|
618
|
+
if (!Number.isFinite(idleDuration) || !Number.isFinite(clipDuration)) break;
|
|
619
|
+
// Only the smaller product can catch the other, so the first match has the least idle count and then clip count.
|
|
620
|
+
const order = compareRepeatDurations(idleDuration, clipDuration);
|
|
621
|
+
if (order === 0) return `Smallest exact counts: idle ${idleCount}, clip ${clipCount} (${idleDuration} s).`;
|
|
622
|
+
if (order < 0) idleCount++;
|
|
623
|
+
else clipCount++;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
const limit = String(WITH_IDLE_DIAGNOSTIC_COPY_LIMIT).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
627
|
+
return `No pair within ${limit} copies of each for source idle ${idlePeriod} s and source clip ${clipPeriod} s. ` +
|
|
628
|
+
'Retime the clip at its source in motion.animations_from, change the source idle\'s motion.duration, or declare false.';
|
|
629
|
+
}
|
|
630
|
+
|
|
552
631
|
function readJson(path: string, what: string, problems: Problem[], consumed: (bytes: Uint8Array) => void): unknown {
|
|
553
632
|
if (!existsSync(path)) {
|
|
554
633
|
problems.push({ code: 'SCENE_BUILD_PRESENT', object: path, detail: `no such file; ${what}` });
|
|
@@ -1296,6 +1375,7 @@ export interface SceneCharacterReport {
|
|
|
1296
1375
|
constraints: number;
|
|
1297
1376
|
idle_duration: number;
|
|
1298
1377
|
idle_repeats?: number;
|
|
1378
|
+
with_idle?: Record<string, number | false>;
|
|
1299
1379
|
/** The bars the character's own check failed that `--accept` or its `accept` took (issue #203); written only when there are any, so a scene of green builds writes the bytes it wrote before the field existed. */
|
|
1300
1380
|
accepted?: string[];
|
|
1301
1381
|
}
|
|
@@ -1327,6 +1407,8 @@ export interface ComposedScene {
|
|
|
1327
1407
|
report: SceneReport;
|
|
1328
1408
|
/** Opt-in declaration retained for pre-emission pose measurement; never serialized. */
|
|
1329
1409
|
sceneAnimations?: SceneAnimations;
|
|
1410
|
+
/** Compiled timeline addresses checked at the final gate; never serialized. */
|
|
1411
|
+
repeatSeams: SceneRepeatSeam[];
|
|
1330
1412
|
sceneCamera?: ResolvedSceneCamera;
|
|
1331
1413
|
}
|
|
1332
1414
|
|
|
@@ -1406,6 +1488,11 @@ function measureSceneCamera(build: string, composed: ComposedScene, camera: Reso
|
|
|
1406
1488
|
// Keep authored ticks exact, including keys on that grid. Both the camera
|
|
1407
1489
|
// and the packed pose read the same phase at their own clock precision.
|
|
1408
1490
|
const times = authoredTimes.map(time => time === track.duration ? compiledDuration : time / track.duration * compiledDuration);
|
|
1491
|
+
const { period } = track;
|
|
1492
|
+
const periodTicks = period === undefined ? 0 : Math.round(period * IDLE_FPS);
|
|
1493
|
+
const totalTicks = Math.round(track.duration * IDLE_FPS);
|
|
1494
|
+
const samplePeriod = periodTicks > 0 && periodTicks / IDLE_FPS === period && totalTicks / IDLE_FPS === track.duration &&
|
|
1495
|
+
totalTicks % periodTicks === 0 ? track.samplePeriod : undefined;
|
|
1409
1496
|
const frames: CameraFrameReport[] = [];
|
|
1410
1497
|
// The track remains unwrapped through the closing pose, with one
|
|
1411
1498
|
// physics clock stepping the entire schedule, including a short end step.
|
|
@@ -1415,7 +1502,12 @@ function measureSceneCamera(build: string, composed: ComposedScene, camera: Reso
|
|
|
1415
1502
|
object = `${field} frame ${index} (t=${time} s, authored ${authored} s)`;
|
|
1416
1503
|
const fail = (code: string, detail: string): void => { problems.push({ code, object, detail }); };
|
|
1417
1504
|
let sample: SceneCameraSample;
|
|
1418
|
-
try {
|
|
1505
|
+
try {
|
|
1506
|
+
// The player still reads the global i/fps grid. Exact frame phase
|
|
1507
|
+
// avoids subtracting two rounded global times on each tiled copy.
|
|
1508
|
+
sample = samplePeriod === undefined ? track.sample(authored) :
|
|
1509
|
+
samplePeriod(index === times.length - 1 ? periodTicks / IDLE_FPS : (index % periodTicks) / IDLE_FPS);
|
|
1510
|
+
}
|
|
1419
1511
|
catch (err) {
|
|
1420
1512
|
if (!(err instanceof PartsError)) throw err;
|
|
1421
1513
|
for (const problem of err.problems) fail(problem.code, problem.detail);
|
|
@@ -1599,6 +1691,10 @@ export function composeScene(
|
|
|
1599
1691
|
const hasRepeats = scene.characters.some(c => c.idle_repeats !== undefined);
|
|
1600
1692
|
const clip = scene.animations?.idle;
|
|
1601
1693
|
const idleDuration = hasRepeats ? clip?.duration ?? 0 : durations[0];
|
|
1694
|
+
const sceneIdleRepeat = scene.repeats !== undefined && Object.hasOwn(scene.repeats, 'idle') ? scene.repeats.idle : undefined;
|
|
1695
|
+
const sceneIdleClock = sceneIdleRepeat === undefined ? 'scene.animations.idle.duration' : `scene.animations.idle.duration for scene.repeats["idle"]: ${sceneIdleRepeat}`;
|
|
1696
|
+
const idleClockFields: string[] = [];
|
|
1697
|
+
const importedIdleMismatches: Array<{ field: string; found: number; problem: Problem }> = [];
|
|
1602
1698
|
if (hasRepeats) scene.characters.forEach((c, i) => {
|
|
1603
1699
|
if (clip === undefined) {
|
|
1604
1700
|
if (c.idle_repeats !== undefined) fail('SCENE_REPEAT_IDLE_REQUIRED', 'scene.animations.idle', `is absent for character ${show(c.id)} with idle_repeats ${c.idle_repeats}. Declare the scene idle and its duration`);
|
|
@@ -1608,8 +1704,13 @@ export function composeScene(
|
|
|
1608
1704
|
if (idle === undefined) return;
|
|
1609
1705
|
const count = c.idle_repeats ?? 1;
|
|
1610
1706
|
const period = idle.duration;
|
|
1611
|
-
|
|
1612
|
-
|
|
1707
|
+
const field = `scene.characters[${i}].idle_repeats`;
|
|
1708
|
+
if (c.idle_repeats !== undefined) idleClockFields.push(`${field} for character ${show(c.id)} implies ${count * period} s (${count} × ${period} s)`);
|
|
1709
|
+
if (!Number.isFinite(period) || period <= 0 || !Number.isFinite(idleDuration) || idleDuration <= 0 || compareRepeatDurations(idleDuration, count * period) !== 0) {
|
|
1710
|
+
const problem = { code: 'SCENE_REPEAT_DURATION', object: 'scene.animations.idle.duration',
|
|
1711
|
+
detail: `is ${idleDuration} s for character ${show(c.id)}. Its ${period} s idle repeated ${count} times requires exactly ${count * period} s (tolerance 0 s)` };
|
|
1712
|
+
problems.push(problem);
|
|
1713
|
+
importedIdleMismatches.push({ field, found: count * period, problem });
|
|
1613
1714
|
}
|
|
1614
1715
|
if (c.idle_repeats !== undefined && idle.loop !== true) {
|
|
1615
1716
|
fail('SCENE_REPEAT_SOURCE_LOOP_CLOSES', `scene.characters[${i}] motion.json animations.idle`, `loop is ${show(idle.loop)}; repeating requires a closed source idle with loop: true`);
|
|
@@ -1619,6 +1720,61 @@ export function composeScene(
|
|
|
1619
1720
|
fail('SCENE_DURATION_AGREES', 'scene.characters', `have idles of ${ready.map((b, i) => `"${b.id}" ${durations[i]} s`).join(', ')}; one idle holds every character's tracks, so one duration is required — rebuild with one motion.duration`);
|
|
1620
1721
|
}
|
|
1621
1722
|
|
|
1723
|
+
const foldedClips = new Map<string, Map<string, SceneAnimation>>();
|
|
1724
|
+
const withIdleClockFields: string[] = [];
|
|
1725
|
+
for (const [i, c] of scene.characters.entries()) {
|
|
1726
|
+
const character = `scene.characters[${i}]`;
|
|
1727
|
+
const declarations = c.with_idle ?? {};
|
|
1728
|
+
if (c.scale !== 1 && Object.values(declarations).some(count => typeof count === 'number')) {
|
|
1729
|
+
fail('SCENE_SCALE_EXACT', `${character}.with_idle`, `character ${show(c.id)} has scale ${c.scale}. with_idle applies at scale 1 only`);
|
|
1730
|
+
}
|
|
1731
|
+
const b = byId.get(c.id);
|
|
1732
|
+
if (b === undefined) continue;
|
|
1733
|
+
const animations = animationsOf(b.motion);
|
|
1734
|
+
const clips = new Map<string, SceneAnimation>();
|
|
1735
|
+
for (const [name, source] of Object.entries(animations)) {
|
|
1736
|
+
if (name === 'idle') continue;
|
|
1737
|
+
const targets = physicsClipTargets(source);
|
|
1738
|
+
if (targets !== undefined && !Object.hasOwn(declarations, name)) {
|
|
1739
|
+
const count = targets.size;
|
|
1740
|
+
const advice = c.scale === 1
|
|
1741
|
+
? 'Declare its whole-period repeat count to carry it into idle or false to play idle without it'
|
|
1742
|
+
: `At scale ${c.scale}, declare false to play idle without it. A repeat count applies at scale 1 only`;
|
|
1743
|
+
fail('SCENE_PHYSICS_CLIP_DECLARED', `${character}.with_idle[${JSON.stringify(name)}]`,
|
|
1744
|
+
`character ${show(c.id)} carries physics-only clip ${show(name)} keying ${count} physics constraint${count === 1 ? '' : 's'}. ${advice}`);
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
for (const [name, count] of Object.entries(declarations)) {
|
|
1748
|
+
const object = `${character}.with_idle[${JSON.stringify(name)}]`;
|
|
1749
|
+
const source = name !== 'idle' && Object.hasOwn(animations, name) ? animations[name] : undefined;
|
|
1750
|
+
if (source === undefined || physicsClipTargets(source) === undefined) {
|
|
1751
|
+
fail('SCENE_PHYSICS_CLIP_ONLY', object, `character ${show(c.id)} ${source === undefined ? 'has no clip beside idle named' : 'has a clip with other timelines or no physics keys named'} ${show(name)}. Name a clip beside idle with only physics-constraint tracks`);
|
|
1752
|
+
continue;
|
|
1753
|
+
}
|
|
1754
|
+
if (count === false || c.scale !== 1) continue;
|
|
1755
|
+
const period = source.duration;
|
|
1756
|
+
const foldedDuration = count * period;
|
|
1757
|
+
if (Number.isFinite(foldedDuration)) withIdleClockFields.push(`${object} for character ${show(c.id)} implies ${foldedDuration} s (${count} × ${period} s)`);
|
|
1758
|
+
const sourceIdle = animations.idle.duration;
|
|
1759
|
+
if (!Number.isFinite(foldedDuration) || foldedDuration <= 0 || compareRepeatDurations(idleDuration, foldedDuration) !== 0) {
|
|
1760
|
+
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)`;
|
|
1761
|
+
const sceneField = clip === undefined ? '' : ` ${sceneIdleClock} declares ${clip.duration} s.`;
|
|
1762
|
+
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} ${idleRepeatAdvice(sourceIdle, period)}`);
|
|
1763
|
+
continue;
|
|
1764
|
+
}
|
|
1765
|
+
clips.set(name, source);
|
|
1766
|
+
}
|
|
1767
|
+
foldedClips.set(c.id, clips);
|
|
1768
|
+
}
|
|
1769
|
+
for (const mismatch of importedIdleMismatches) {
|
|
1770
|
+
const opts = [
|
|
1771
|
+
...(sceneIdleRepeat === undefined ? [] : [`${sceneIdleClock} declares ${idleDuration} s`]),
|
|
1772
|
+
...withIdleClockFields,
|
|
1773
|
+
];
|
|
1774
|
+
if (opts.length > 0) mismatch.problem.detail += `. ${mismatch.field} implies ${mismatch.found} s. ${opts.join('. ')}.`;
|
|
1775
|
+
}
|
|
1776
|
+
idleClockFields.push(...withIdleClockFields);
|
|
1777
|
+
|
|
1622
1778
|
// ---- placed bounds --------------------------------------------------------
|
|
1623
1779
|
const rows: SceneCharacterReport[] = [];
|
|
1624
1780
|
scene.characters.forEach((c, i) => {
|
|
@@ -1679,6 +1835,7 @@ export function composeScene(
|
|
|
1679
1835
|
constraints: b.rig.constraints?.length ?? 0,
|
|
1680
1836
|
idle_duration: b.motion.animations.idle.duration,
|
|
1681
1837
|
...(c.idle_repeats === undefined ? {} : { idle_repeats: c.idle_repeats }),
|
|
1838
|
+
...(c.with_idle === undefined ? {} : { with_idle: { ...c.with_idle } }),
|
|
1682
1839
|
...(b.accepted.length === 0 ? {} : { accepted: [...b.accepted] }),
|
|
1683
1840
|
});
|
|
1684
1841
|
});
|
|
@@ -2083,8 +2240,9 @@ export function composeScene(
|
|
|
2083
2240
|
const groups: MotionSpec['groups'] = {};
|
|
2084
2241
|
const tracks: MotionSpec['animations']['idle']['tracks'] = [];
|
|
2085
2242
|
const idleDeform: SceneDeform[] = [];
|
|
2086
|
-
|
|
2087
|
-
//
|
|
2243
|
+
const repeatSeams: SceneRepeatSeam[] = [];
|
|
2244
|
+
// Every animation beside a character's idle rides along under its character's prefix (issue #183).
|
|
2245
|
+
// A with_idle count also folds the declared physics clip into the composed idle (#1615).
|
|
2088
2246
|
const beside: Record<string, SceneAnimation> = {};
|
|
2089
2247
|
const notes = new Set(ready.map((b) => b.motion.animations.idle.note));
|
|
2090
2248
|
for (const [i, c] of scene.characters.entries()) {
|
|
@@ -2092,7 +2250,7 @@ export function composeScene(
|
|
|
2092
2250
|
const id = c.id;
|
|
2093
2251
|
for (const [k, v] of Object.entries(b.motion.easings)) easings[prefixed(id, k)] = v;
|
|
2094
2252
|
for (const [k, v] of Object.entries(b.motion.groups)) groups[prefixed(id, k)] = v.map((n) => P(id, n));
|
|
2095
|
-
const prefixTrack = (t: MotionSpec['animations']['idle']['tracks'][number],
|
|
2253
|
+
const prefixTrack = (t: MotionSpec['animations']['idle']['tracks'][number], literalStepped = false): MotionSpec['animations']['idle']['tracks'][number] => {
|
|
2096
2254
|
const tr = { ...t } as Record<string, unknown>;
|
|
2097
2255
|
if (typeof tr.bone === 'string') tr.bone = P(id, tr.bone);
|
|
2098
2256
|
if (typeof tr.group === 'string') tr.group = prefixed(id, tr.group);
|
|
@@ -2100,7 +2258,7 @@ export function composeScene(
|
|
|
2100
2258
|
const memberMap = (v: Record<string, unknown>): Record<string, unknown> => Object.fromEntries(Object.entries(v).map(([n, value]) => [P(id, n), value]));
|
|
2101
2259
|
tr.keys = (t.keys as unknown as Array<Record<string, unknown>>).map((k) => ({
|
|
2102
2260
|
...k,
|
|
2103
|
-
...(typeof k.ease === 'string' && !(
|
|
2261
|
+
...(typeof k.ease === 'string' && !(literalStepped && k.ease === 'stepped') ? { ease: prefixed(id, k.ease) } : {}),
|
|
2104
2262
|
...(isRecord(k.v) ? { v: memberMap(k.v) } : {}),
|
|
2105
2263
|
...(isRecord(k.derive) ? { derive: { ...k.derive, ...(isRecord(k.derive.depth) ? { depth: memberMap(k.derive.depth) } : {}) } } : {}),
|
|
2106
2264
|
}));
|
|
@@ -2124,7 +2282,18 @@ export function composeScene(
|
|
|
2124
2282
|
}
|
|
2125
2283
|
for (const t of idle.tracks) tracks.push(scaledTrack(prefixTrack(t, repeats !== undefined), c.scale));
|
|
2126
2284
|
idleDeform.push(...(deforms(idle, repeats !== undefined).deform ?? []));
|
|
2127
|
-
for (const [n, a] of Object.entries(animations)) if (n !== 'idle')
|
|
2285
|
+
for (const [n, a] of Object.entries(animations)) if (n !== 'idle') {
|
|
2286
|
+
const source = foldedClips.get(id)?.get(n);
|
|
2287
|
+
const count = c.with_idle?.[n];
|
|
2288
|
+
const declared = c.with_idle !== undefined && Object.hasOwn(c.with_idle, n);
|
|
2289
|
+
beside[prefixed(id, n)] = { ...a, tracks: a.tracks.map(t => scaledTrack(prefixTrack(t, declared), c.scale)), ...deforms(a) };
|
|
2290
|
+
if (source === undefined || typeof count !== 'number') continue;
|
|
2291
|
+
const object = `scene.characters[${i}].with_idle[${JSON.stringify(n)}]`;
|
|
2292
|
+
const folded = repeatSceneKeys(source, count, idleDuration, b.motion.groups, object, undefined, {
|
|
2293
|
+
take: 'idle', into: repeatSeams, mapTarget: name => prefixed(id, name),
|
|
2294
|
+
});
|
|
2295
|
+
for (const t of folded.tracks) tracks.push(prefixTrack(t, true));
|
|
2296
|
+
}
|
|
2128
2297
|
}
|
|
2129
2298
|
const note = notes.size === 1 ? [...notes][0] : ready.map((b) => `${b.id}: ${b.motion.animations.idle.note}`).join(' | ');
|
|
2130
2299
|
const motion: MotionSpec = { spec: 'rigc-motion/1', archetype: name, cut: name, easings, groups, animations: { idle: { duration: idleDuration, loop: true, note, tracks, ...(idleDeform.length === 0 ? {} : { deform: idleDeform }) }, ...beside } };
|
|
@@ -2150,8 +2319,23 @@ export function composeScene(
|
|
|
2150
2319
|
}
|
|
2151
2320
|
refuseIfAny(problems);
|
|
2152
2321
|
}
|
|
2153
|
-
|
|
2154
|
-
|
|
2322
|
+
let sceneAnimations = scene.animations;
|
|
2323
|
+
let sceneCamera: ResolvedSceneCamera | undefined;
|
|
2324
|
+
try {
|
|
2325
|
+
if (scene.repeats !== undefined) {
|
|
2326
|
+
const repeated = repeatSceneAnimations(scene.animations, motion.groups, scene.repeats, repeatSeams);
|
|
2327
|
+
if (scene.animations !== undefined) sceneAnimations = repeated;
|
|
2328
|
+
}
|
|
2329
|
+
if (sceneAnimations !== undefined || pivots.size > 0) mergeSceneAnimations(rig, motion, sceneAnimations ?? {}, [...pivots.values()]);
|
|
2330
|
+
if (scene.camera !== undefined) sceneCamera = resolveSceneCamera(scene.camera, motion, scene.repeats);
|
|
2331
|
+
} catch (err) {
|
|
2332
|
+
if (!(err instanceof PartsError) || sceneIdleRepeat === undefined || idleClockFields.length === 0) throw err;
|
|
2333
|
+
throw new PartsError(err.problems.map(problem => {
|
|
2334
|
+
if (!['SCENE_REPEAT_DURATION', 'SCENE_CAMERA_TRACK', 'SCENE_DURATION_AGREES'].includes(problem.code) ||
|
|
2335
|
+
!['scene.animations.idle', 'scene.animations["idle"]', 'scene.camera.tracks["idle"]', 'scene.repeats["idle"]'].some(field => problem.object.startsWith(field))) return problem;
|
|
2336
|
+
return { ...problem, detail: `${problem.detail} ${idleClockFields.join('. ')}.` };
|
|
2337
|
+
}));
|
|
2338
|
+
}
|
|
2155
2339
|
if (sceneCamera !== undefined) {
|
|
2156
2340
|
for (const [name, track] of sceneCamera.tracks) for (const key of track.keys) {
|
|
2157
2341
|
if (cameraViewport(stage, key) === null) fail('SCENE_CAMERA_TRACK', `scene.camera.tracks[${show(name)}]`,
|
|
@@ -2175,7 +2359,7 @@ export function composeScene(
|
|
|
2175
2359
|
order: { declared: [...scene.order], slots: slots.map((s) => s.name), judged_by: 'nothing' },
|
|
2176
2360
|
idle_duration: idleDuration,
|
|
2177
2361
|
};
|
|
2178
|
-
return { rig, motion, images, report, ...(
|
|
2362
|
+
return { rig, motion, images, report, repeatSeams, ...(sceneAnimations === undefined ? {} : { sceneAnimations }), ...(sceneCamera === undefined ? {} : { sceneCamera }) };
|
|
2179
2363
|
}
|
|
2180
2364
|
|
|
2181
2365
|
// ---------------------------------------------------------------------------
|
|
@@ -2414,6 +2598,8 @@ export interface ComposeInput {
|
|
|
2414
2598
|
requirements?: string;
|
|
2415
2599
|
/** Declared RGBA loop seam bar and warm-up cap for the composed idle render (issue #1590). */
|
|
2416
2600
|
loopSeam?: LoopSeamRequest;
|
|
2601
|
+
/** The selected output profile, absent for the full diagnostics (issue #1610). */
|
|
2602
|
+
outputProfile?: ComposeRun['output_profile'];
|
|
2417
2603
|
/** `--accept`: the bars every character's own check may fail and still be composed (issue #203). */
|
|
2418
2604
|
accept?: readonly string[];
|
|
2419
2605
|
}
|
|
@@ -2434,6 +2620,17 @@ export interface ComposeResult {
|
|
|
2434
2620
|
check: CheckReport | null;
|
|
2435
2621
|
}
|
|
2436
2622
|
|
|
2623
|
+
/** Refuse before resolving rigc in the CLI, and before the gate for direct stage callers. */
|
|
2624
|
+
export function refusePreviewLoopSeam(input: ComposeInput): void {
|
|
2625
|
+
if (input.outputProfile !== 'preview' || input.loopSeam === undefined) return;
|
|
2626
|
+
for (const p of COMPOSE_OWNS) rmSync(join(input.out, p), { recursive: true, force: true });
|
|
2627
|
+
throw new PartsError([{
|
|
2628
|
+
code: 'COMPOSE_PREVIEW_REQUIRED_CHECK',
|
|
2629
|
+
object: '--loop-seam-bar',
|
|
2630
|
+
detail: COMPOSE_PREVIEW_LOOP_SEAM_DETAIL,
|
|
2631
|
+
}]);
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2437
2634
|
/**
|
|
2438
2635
|
* Load the scene and every build, compose, gate the result through rig-c
|
|
2439
2636
|
* exactly as `rig` and `build` gate theirs ({@link gateThroughRigc}: `build
|
|
@@ -2461,6 +2658,11 @@ export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log)
|
|
|
2461
2658
|
return { stoppedAt: stage, composed, check: null };
|
|
2462
2659
|
};
|
|
2463
2660
|
const pageSize = parsePageSize(input.pageSize);
|
|
2661
|
+
try {
|
|
2662
|
+
refusePreviewLoopSeam(input);
|
|
2663
|
+
} catch (err) {
|
|
2664
|
+
return refused('compose', err);
|
|
2665
|
+
}
|
|
2464
2666
|
mkdirSync(input.out, { recursive: true });
|
|
2465
2667
|
for (const p of COMPOSE_OWNS) rmSync(join(input.out, p), { recursive: true, force: true });
|
|
2466
2668
|
const mode: PackMode = { pageEdges: DEFAULT_PAGE_EDGES, packShape: DEFAULT_PACK_SHAPE, ...(pageSize === undefined ? {} : { pageSize }) };
|
|
@@ -2495,6 +2697,9 @@ export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log)
|
|
|
2495
2697
|
for (const c of r.characters) {
|
|
2496
2698
|
const clipped = c.clipped_bounds === undefined ? '' : `; clipped bounds [${c.clipped_bounds.join(', ')}]`;
|
|
2497
2699
|
say(` ${c.id}: ${c.build} at offset [${c.offset.join(', ')}], scale ${c.scale ?? 1}, bounds [${c.bounds.join(', ')}], shift [${c.shift.join(', ')}] on ${c.shifted.bones.length} first-level bone(s), ${c.shifted.root_regions.length} region(s) on root and ${c.shifted.root_weights} weight(s) bound to root; ${c.bones} bone(s), ${c.slots} slot(s), ${c.tracks} track(s), ${c.constraints} constraint(s), rig_scale ${c.rig_scale}, idle ${c.idle_duration} s${c.accepted === undefined ? '' : `; its own check FAILED ${c.accepted.join(', ')}, accepted — the scene is for looking, not shipping`}${clipped}`);
|
|
2700
|
+
for (const [clip, count] of Object.entries(c.with_idle ?? {})) {
|
|
2701
|
+
say(` ${prefixed(c.id, clip)} ${count === false ? 'plays beside idle only (with_idle: false)' : `carried into idle for ${count} source period${count === 1 ? '' : 's'} and retained beside it`}`);
|
|
2702
|
+
}
|
|
2498
2703
|
}
|
|
2499
2704
|
say(` order (declared, judged by nothing): ${r.order.declared.join(', ')} -> ${r.order.slots.length} slot(s), back to front`);
|
|
2500
2705
|
const texts: Array<[string, string]> = [
|
|
@@ -2505,13 +2710,15 @@ export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log)
|
|
|
2505
2710
|
const gated: { camera?: CameraEvidence } = {};
|
|
2506
2711
|
let gate: ReturnType<typeof gateThroughRigc>;
|
|
2507
2712
|
try {
|
|
2508
|
-
const clips = composed
|
|
2509
|
-
const
|
|
2510
|
-
if (clips === undefined) return;
|
|
2511
|
-
|
|
2713
|
+
const { sceneAnimations: clips, repeatSeams } = composed;
|
|
2714
|
+
const checkMotion = (build: string): void => {
|
|
2715
|
+
if (clips === undefined && repeatSeams.length === 0) return;
|
|
2716
|
+
const modelText = readFileSync(join(build, CAMERA_MODEL), 'utf8');
|
|
2717
|
+
refuseIfAny(sceneRepeatCurveProblems(modelText, repeatSeams));
|
|
2718
|
+
if (clips !== undefined) refuseIfAny(sceneClipLoopProblems(modelText, clips, r.characters.some(c => c.idle_repeats !== undefined)));
|
|
2512
2719
|
};
|
|
2513
2720
|
if (camera === undefined) {
|
|
2514
|
-
gate = gateThroughRigc(composed.images, texts, run.rig, run.scratch, mode, clips === undefined ? undefined :
|
|
2721
|
+
gate = gateThroughRigc(composed.images, texts, run.rig, run.scratch, mode, clips === undefined && repeatSeams.length === 0 ? undefined : checkMotion);
|
|
2515
2722
|
} else {
|
|
2516
2723
|
// Core binds the model to skeleton.json, whose image path is relative
|
|
2517
2724
|
// to the build. Mirror check's rig/ and check/build/ in gate scratch.
|
|
@@ -2521,7 +2728,7 @@ export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log)
|
|
|
2521
2728
|
try {
|
|
2522
2729
|
const packed: RigcRunner = args => run.rig(args.map((arg, i) => args[i - 1] === '--out' ? build : arg));
|
|
2523
2730
|
gate = gateThroughRigc(composed.images, texts, packed, scratch, mode, () => {
|
|
2524
|
-
|
|
2731
|
+
checkMotion(build);
|
|
2525
2732
|
gated.camera = measureSceneCamera(build, composed, camera);
|
|
2526
2733
|
});
|
|
2527
2734
|
} finally {
|
|
@@ -2559,9 +2766,9 @@ export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log)
|
|
|
2559
2766
|
writeFileSync(reportPath, rigJsonText(r));
|
|
2560
2767
|
say(`${wroteRig}, and ${reportPath}`);
|
|
2561
2768
|
}
|
|
2769
|
+
const stage = r.characters.some(c => c.canvas_clip === true) ? composed.rig.skeleton : undefined;
|
|
2562
2770
|
let checkRigc = run.check;
|
|
2563
|
-
if (
|
|
2564
|
-
const stage = composed.rig.skeleton;
|
|
2771
|
+
if (stage !== undefined) {
|
|
2565
2772
|
const viewport = [stage.x, stage.y, stage.width, stage.height].join(',');
|
|
2566
2773
|
checkRigc = args => run.check(args[0] === 'render' && !args.includes('--viewport') && !args.includes('--viewport-from')
|
|
2567
2774
|
? [...args, '--viewport', viewport]
|
|
@@ -2592,6 +2799,14 @@ export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log)
|
|
|
2592
2799
|
writeFileSync(reportPath, rigJsonText(composed.report));
|
|
2593
2800
|
say(`${wroteRig}, and ${reportPath}`);
|
|
2594
2801
|
};
|
|
2802
|
+
const preview = input.outputProfile === 'preview';
|
|
2803
|
+
const noExtremes = input.outputProfile !== undefined;
|
|
2804
|
+
const checkLog = prefix('check');
|
|
2805
|
+
if (noExtremes) {
|
|
2806
|
+
const flag = preview ? '--output-profile preview' : '--no-extremes';
|
|
2807
|
+
checkLog(` extremes: SKIP — ${flag} omits the extra diagnostic renders`);
|
|
2808
|
+
}
|
|
2809
|
+
if (preview) checkLog(' idle diagnostics: SKIP — --output-profile preview omits idle_frames/, contact.png and motion_heat.png');
|
|
2595
2810
|
let report: CheckReport;
|
|
2596
2811
|
try {
|
|
2597
2812
|
report = checkStage({
|
|
@@ -2599,7 +2814,9 @@ export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log)
|
|
|
2599
2814
|
...(pageSize === undefined ? {} : { pageSize }),
|
|
2600
2815
|
...(input.requirements === undefined ? {} : { requirements: input.requirements }),
|
|
2601
2816
|
...(input.loopSeam === undefined ? {} : { loopSeam: input.loopSeam }),
|
|
2602
|
-
|
|
2817
|
+
...(noExtremes ? { noExtremes: true } : {}),
|
|
2818
|
+
...(preview ? { previewIdle: true } : {}),
|
|
2819
|
+
}, checkRigc, run.checkBin, checkLog);
|
|
2603
2820
|
} catch (err) {
|
|
2604
2821
|
if (cameraBindingFailed) {
|
|
2605
2822
|
for (const p of COMPOSE_OWNS) rmSync(join(input.out, p), { recursive: true, force: true });
|
|
@@ -2625,8 +2842,10 @@ export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log)
|
|
|
2625
2842
|
log(`compose: stopped at check; the composed rig's check is PASS${acceptedLine} (the composed rig and scene.json are written; the scene is for looking, not shipping)`);
|
|
2626
2843
|
return { stoppedAt: 'check', composed, check: report };
|
|
2627
2844
|
}
|
|
2628
|
-
|
|
2629
|
-
|
|
2845
|
+
const runRecord = input.outputProfile === undefined ? composed.runRecord : { ...composed.runRecord, output_profile: input.outputProfile };
|
|
2846
|
+
writeFileSync(join(input.out, COMPOSE_RUN_FILE), rigJsonText(runRecord));
|
|
2847
|
+
const verdict = preview ? 'PREVIEW — checks met;' : noExtremes ? 'NO EXTREMES — checks met;' : 'PASS —';
|
|
2848
|
+
log(`compose: ${verdict} ${report.bars.measured.length} of ${report.bars.measured.length + report.bars.skipped.length} bar(s) measured; the packed atlas under ${join(input.out, 'check', 'build')} is the artifact`);
|
|
2630
2849
|
return { stoppedAt: null, composed, check: report };
|
|
2631
2850
|
}
|
|
2632
2851
|
|