@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/docs/AUTHORING.md +218 -21
- package/docs/STABILITY.md +48 -9
- package/package.json +2 -2
- package/src/alternatelayers.ts +115 -0
- package/src/assemble.ts +71 -20
- package/src/build.ts +50 -11
- package/src/check.ts +1035 -147
- package/src/config.ts +107 -6
- package/src/coords.ts +12 -0
- package/src/diagnostics.ts +1 -0
- package/src/explicitmesh.ts +53 -0
- package/src/meshdraft.ts +2 -2
- package/src/meshstats.ts +1 -1
- package/src/parts.ts +9 -0
- package/src/propose.ts +6 -1
- package/src/rig.ts +57 -5
- package/src/setfocus.ts +21 -0
- package/src/squeeze.ts +2 -1
- package/src/structure.ts +4 -0
package/src/check.ts
CHANGED
|
@@ -78,6 +78,8 @@
|
|
|
78
78
|
* `TIME_SLACK`, issue #244).
|
|
79
79
|
*/
|
|
80
80
|
import { createHash } from 'node:crypto';
|
|
81
|
+
import { createRequire } from 'node:module';
|
|
82
|
+
import type { Viewport as RootCoverageViewport } from 'rig-c/render-shared';
|
|
81
83
|
import { copyFileSync, cpSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
82
84
|
import { basename, delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
83
85
|
import { measureRecomposite, type RecompositeFigures, recompositeRecord, scenePhrase, sourceInRig } from './assemble.ts';
|
|
@@ -129,7 +131,8 @@ import {
|
|
|
129
131
|
} from './instruments.ts';
|
|
130
132
|
import { type AlternatePartsRecord, FRONT_SUFFIX, type LimbRecord, type PartRecord, type PartsFile, readParts } from './parts.ts';
|
|
131
133
|
import { ARM_SPLIT_MIGRATION, poseRigBonesForDrawn, type RigBone, SETS_FILE } from './rig.ts';
|
|
132
|
-
import { turnTwin } from './turn.ts';
|
|
134
|
+
import { TURN_BONE, turnConstraintName, turnTwin } from './turn.ts';
|
|
135
|
+
import { ROOT_BONE } from './config.ts';
|
|
133
136
|
import {
|
|
134
137
|
aimLine,
|
|
135
138
|
contactLine,
|
|
@@ -1219,6 +1222,8 @@ export function motionHeat(frames: readonly Raster[]): Raster {
|
|
|
1219
1222
|
}
|
|
1220
1223
|
|
|
1221
1224
|
export interface SeamFigures {
|
|
1225
|
+
/** Authored support size for a canonical union; absent for the unchanged auto reading. */
|
|
1226
|
+
denominator?: number;
|
|
1222
1227
|
mean: number;
|
|
1223
1228
|
over40: number;
|
|
1224
1229
|
over80: number;
|
|
@@ -1454,6 +1459,9 @@ export function seamFigures(
|
|
|
1454
1459
|
background: readonly [number, number, number, number],
|
|
1455
1460
|
map: ScaleTranslate = rigToFrameMap(stage, composite.height, vp),
|
|
1456
1461
|
scene = false,
|
|
1462
|
+
effect?: Uint8Array,
|
|
1463
|
+
sourceGrid = false,
|
|
1464
|
+
observe?: (pixel: number, map: ScaleTranslate) => void,
|
|
1457
1465
|
): SeamFigures {
|
|
1458
1466
|
const [W, H] = [composite.width, composite.height];
|
|
1459
1467
|
const src = newFloatImage(W, H, 3);
|
|
@@ -1470,25 +1478,43 @@ export function seamFigures(
|
|
|
1470
1478
|
const counted: number[] = [];
|
|
1471
1479
|
const countedDiff: number[] = [];
|
|
1472
1480
|
const n = vp.pixelWidth * vp.pixelHeight;
|
|
1481
|
+
if (effect !== undefined && effect.length !== n) refuseIfAny([{ code: 'CHECK_SEAM_SUPPORT', object: 'the effect mask', detail: 'does not have the source grid size' }]);
|
|
1473
1482
|
// Issue #242: on a scene, the frame columns and rows whose composite sample reaches the painting's border.
|
|
1474
1483
|
const onEdge = (i: number, t: number, s: number, size: number): boolean => {
|
|
1475
1484
|
const k = Math.floor((i - t) / s);
|
|
1476
1485
|
return k <= 0 || k + 1 >= size - 1;
|
|
1477
1486
|
};
|
|
1487
|
+
// Original authored border, evaluated on its own cells, not on union padding.
|
|
1488
|
+
let authoredA = W * H;
|
|
1489
|
+
if (sourceGrid) {
|
|
1490
|
+
if (vp.scale !== 1 || ![map.tx, map.ty].every(x => Number.isSafeInteger(x) && Math.fround(x) === x))
|
|
1491
|
+
refuseIfAny([{ code: 'CHECK_SEAM_DOMAIN', object: 'the source-grid sample map', detail: 'requires exact integer offsets at scale 1' }]);
|
|
1492
|
+
if (scene) {
|
|
1493
|
+
authoredA = 0;
|
|
1494
|
+
for (let v = 0; v < H; v++) for (let u = 0; u < W; u++)
|
|
1495
|
+
if (!onEdge(u, 0, 1, W) && !onEdge(v, 0, 1, H)) authoredA++;
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1478
1498
|
const edgeCol = scene ? Array.from({ length: vp.pixelWidth }, (_, x) => onEdge(x, map.tx, map.sx, W)) : null;
|
|
1479
1499
|
const edgeRow = scene ? Array.from({ length: vp.pixelHeight }, (_, y) => onEdge(y, map.ty, map.sy, H)) : null;
|
|
1480
1500
|
for (let p = 0; p < n; p++) {
|
|
1501
|
+
const u = p % vp.pixelWidth - map.tx, v = Math.floor(p / vp.pixelWidth) - map.ty;
|
|
1502
|
+
const excluded = sourceGrid && scene
|
|
1503
|
+
? u < 0 || v < 0 || u >= W || v >= H || onEdge(u, 0, 1, W) || onEdge(v, 0, 1, H)
|
|
1504
|
+
: edgeCol !== null && edgeRow !== null && (edgeCol[p % vp.pixelWidth] || edgeRow[Math.floor(p / vp.pixelWidth)]);
|
|
1505
|
+
if (!excluded && (effect === undefined || effect[p] !== 0)) observe?.(p, map);
|
|
1481
1506
|
let m = 0;
|
|
1482
1507
|
for (let c = 0; c < 3; c++) {
|
|
1483
1508
|
const w = Math.fround(warped.data[p * 3 + c] + background[c]);
|
|
1484
1509
|
const d = Math.abs(w - frame.data[p * 4 + c]);
|
|
1485
1510
|
if (d > m) m = d;
|
|
1486
1511
|
}
|
|
1487
|
-
if (
|
|
1512
|
+
if (excluded) {
|
|
1488
1513
|
borderPx++;
|
|
1489
1514
|
if (m > SEAM_PX_LEVEL) borderOver40++;
|
|
1490
1515
|
continue;
|
|
1491
1516
|
}
|
|
1517
|
+
if (effect !== undefined && effect[p] === 0) continue;
|
|
1492
1518
|
sum += m;
|
|
1493
1519
|
if (m > SEAM_PX_LEVEL) {
|
|
1494
1520
|
over40++;
|
|
@@ -1497,13 +1523,359 @@ export function seamFigures(
|
|
|
1497
1523
|
}
|
|
1498
1524
|
if (m > SEAM_PX_LEVEL_HIGH) over80++;
|
|
1499
1525
|
}
|
|
1500
|
-
|
|
1526
|
+
const denominator = sourceGrid ? authoredA : n - borderPx;
|
|
1527
|
+
if (denominator <= 0) refuseIfAny([{ code: 'CHECK_SEAM_SUPPORT', object: 'the seam mean denominator', detail: 'has no source cells after the declared scene-border exclusion' }]);
|
|
1528
|
+
return { ...(sourceGrid ? { denominator } : {}), mean: sum / denominator, over40, over80, border: scene ? { framePx: borderPx, over40: borderOver40 } : null, counted, countedDiff, map };
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
export interface SeamSupportUnavailable {
|
|
1532
|
+
code: 'RENDERER_API_UNAVAILABLE' | 'SOURCE_RIG_UNREADABLE' | 'SOURCE_SKIN_UNSUPPORTED' |
|
|
1533
|
+
'SOURCE_ATTACHMENT_MISSING' | 'SOURCE_ATTACHMENT_AMBIGUOUS' | 'SOURCE_MAPPING_UNSUPPORTED' |
|
|
1534
|
+
'SOURCE_IMAGE_UNREADABLE' | 'POSE_EXPORT_UNREADABLE' | 'POSE_MISMATCH' |
|
|
1535
|
+
'POSE_ATTACHMENT_MISSING' | 'RASTER_READ_UNAVAILABLE';
|
|
1536
|
+
slot?: string;
|
|
1537
|
+
attachment?: string;
|
|
1538
|
+
feature?: 'clipping' | 'sequence-or-non-image-attachment';
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
class SeamSupportError extends Error {
|
|
1542
|
+
constructor(readonly reason: SeamSupportUnavailable) { super(reason.code); }
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
/** Sort object keys only; array order is part of UV/topology/weight semantics. */
|
|
1546
|
+
function seamSourceValue(value: unknown): unknown {
|
|
1547
|
+
if (Array.isArray(value)) return value.map(seamSourceValue);
|
|
1548
|
+
if (isRecord(value)) return Object.fromEntries(Object.keys(value).sort().map(k => [k, seamSourceValue(value[k])]));
|
|
1549
|
+
return value;
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
/**
|
|
1553
|
+
* One semantic drawing identity, never an atlas or a frame ordinal. Source
|
|
1554
|
+
* UVs, triangles, weights and all other declared attachment fields stay in the
|
|
1555
|
+
* signature. Only the image path is replaced by its resolved OWN image content;
|
|
1556
|
+
* page UVs, packed page bytes, and piece bookkeeping are not arguments.
|
|
1557
|
+
*/
|
|
1558
|
+
export function seamDrawingSignature(input: {
|
|
1559
|
+
slot: string; attachment: string; source: Record<string, unknown>;
|
|
1560
|
+
image: { width: number; height: number; rgba_sha256: string };
|
|
1561
|
+
vertices: readonly number[]; color: readonly number[];
|
|
1562
|
+
}): string {
|
|
1563
|
+
const source = Object.fromEntries(Object.entries(input.source).filter(([key]) => key !== 'image'));
|
|
1564
|
+
return JSON.stringify(seamSourceValue({ slot: input.slot, attachment: input.attachment, source, image: input.image, vertices: input.vertices, color: input.color }));
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
/** Resolve only the actually selected default-skin identity, not a filename suffix. */
|
|
1568
|
+
export function seamSourceAttachment(rig: Record<string, unknown>, slot: string, attachment: string): Record<string, unknown> {
|
|
1569
|
+
const skins = isRecord(rig.skins) ? rig.skins : null;
|
|
1570
|
+
const skin = skins !== null && isRecord(skins.default) ? skins.default : null;
|
|
1571
|
+
if (skin === null) throw new SeamSupportError({ code: 'SOURCE_SKIN_UNSUPPORTED', slot, attachment });
|
|
1572
|
+
const drawings = isRecord(skin[slot]) ? skin[slot] : {};
|
|
1573
|
+
const matches = Object.entries(drawings).filter(([key, value]) => isRecord(value) && (typeof value.name === 'string' ? value.name : key) === attachment);
|
|
1574
|
+
if (matches.length !== 1) throw new SeamSupportError({ code: matches.length === 0 ? 'SOURCE_ATTACHMENT_MISSING' : 'SOURCE_ATTACHMENT_AMBIGUOUS', slot, attachment });
|
|
1575
|
+
const source = matches[0][1];
|
|
1576
|
+
if (!isRecord(source) || !['region', 'mesh'].includes(typeof source.type === 'string' ? source.type : 'region') || typeof source.image !== 'string' || source.image.length === 0 || source.sequence !== undefined) {
|
|
1577
|
+
throw new SeamSupportError({ code: 'SOURCE_MAPPING_UNSUPPORTED', slot, attachment, feature: 'sequence-or-non-image-attachment' });
|
|
1578
|
+
}
|
|
1579
|
+
return source;
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
/** #705: ordered contributor identities on the fixed source grid, before residuals. */
|
|
1583
|
+
export interface SeamSupport {
|
|
1584
|
+
reference: Int32Array;
|
|
1585
|
+
posed: Int32Array;
|
|
1586
|
+
referenceDepth: Uint8Array;
|
|
1587
|
+
posedDepth: Uint8Array;
|
|
1588
|
+
unavailable?: SeamSupportUnavailable;
|
|
1589
|
+
drawings?: Array<{ scope: 'reference' | 'posed'; name: string; identity: string; order: number; geometry: string; art: string; source_png_sha256?: string }>;
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
export interface SeamEffects {
|
|
1593
|
+
mask: Uint8Array;
|
|
1594
|
+
/** Indices into SEAM_EFFECT_REASONS, used only for the raw pair audit. */
|
|
1595
|
+
cellReasons: Uint8Array;
|
|
1596
|
+
reasons: { reference_changed: number; posed_changed: number; no_art_or_singleton: number; unavailable: number; inherited: number };
|
|
1597
|
+
changes: Array<{ scope: 'reference' | 'posed'; drawing: string; reasons: string[] }>;
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
const SEAM_EFFECT_REASONS = ['reference_changed', 'posed_changed', 'no_art_or_singleton', 'unavailable', 'inherited'] as const;
|
|
1601
|
+
|
|
1602
|
+
/** Exact stack equality proves inheritance; missing/singleton provenance never proves exclusion. */
|
|
1603
|
+
export function seamEffectSelection(base: SeamSupport, selected: SeamSupport): SeamEffects {
|
|
1604
|
+
const n = base.reference.length;
|
|
1605
|
+
if ([base.posed, base.referenceDepth, base.posedDepth, selected.reference, selected.posed, selected.referenceDepth, selected.posedDepth].some(a => a.length !== n)) {
|
|
1606
|
+
refuseIfAny([{ code: 'CHECK_SEAM_SUPPORT', object: 'the alternate effect grid', detail: 'does not have the base source grid size' }]);
|
|
1607
|
+
}
|
|
1608
|
+
const mask = new Uint8Array(n), cellReasons = new Uint8Array(n);
|
|
1609
|
+
const reasons: SeamEffects['reasons'] = { reference_changed: 0, posed_changed: 0, no_art_or_singleton: 0, unavailable: 0, inherited: 0 };
|
|
1610
|
+
for (let q = 0; q < n; q++) {
|
|
1611
|
+
const reason: keyof typeof reasons = base.unavailable !== undefined || selected.unavailable !== undefined ? 'unavailable'
|
|
1612
|
+
: base.reference[q] !== selected.reference[q] ? 'reference_changed'
|
|
1613
|
+
: base.posed[q] !== selected.posed[q] ? 'posed_changed'
|
|
1614
|
+
: Math.min(base.referenceDepth[q], selected.referenceDepth[q]) < 2 ? 'no_art_or_singleton' : 'inherited';
|
|
1615
|
+
reasons[reason]++;
|
|
1616
|
+
cellReasons[q] = SEAM_EFFECT_REASONS.indexOf(reason);
|
|
1617
|
+
if (reason !== 'inherited') mask[q] = 1;
|
|
1618
|
+
}
|
|
1619
|
+
const changes: SeamEffects['changes'] = [];
|
|
1620
|
+
const before = base.drawings ?? [], after = selected.drawings ?? [];
|
|
1621
|
+
for (const scope of ['reference', 'posed'] as const) {
|
|
1622
|
+
const names = [...new Set([...before, ...after].filter(d => d.scope === scope).map(d => d.name))];
|
|
1623
|
+
for (const name of names) {
|
|
1624
|
+
const b = before.find(d => d.scope === scope && d.name === name), a = after.find(d => d.scope === scope && d.name === name);
|
|
1625
|
+
const fields = b === undefined ? ['added'] : a === undefined ? ['hidden/removed'] :
|
|
1626
|
+
(['identity', 'order', 'geometry', 'art'] as const).filter(k => b[k] !== a[k]);
|
|
1627
|
+
if (fields.length > 0) changes.push({ scope, drawing: name, reasons: fields });
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
return { mask, cellReasons, reasons, changes };
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
/** Public state evidence excludes raw candidate bytes: compiler image paths vary with output location. */
|
|
1634
|
+
export interface SeamStateBounds {
|
|
1635
|
+
state: string;
|
|
1636
|
+
frames: number;
|
|
1637
|
+
pieces: number;
|
|
1638
|
+
bounds: { minX: number; minY: number; maxX: number; maxY: number } | null;
|
|
1639
|
+
pose_sha256: string;
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
/** The promised read facade (rig-c >=2.69.0 <3); optional Spine registration
|
|
1643
|
+
* follows rigc's own package-root resolution. No candidate error selects a
|
|
1644
|
+
* different API. Importing check, or constructing a root-free reader, loads none.
|
|
1645
|
+
*/
|
|
1646
|
+
type OfficialRenderer = typeof import('rig-c/render-shared');
|
|
1647
|
+
function officialRenderer(): OfficialRenderer {
|
|
1648
|
+
const require = createRequire(import.meta.url);
|
|
1649
|
+
const coreRoot = dirname(require.resolve('rig-c/package.json'));
|
|
1650
|
+
let runtimePresent = false;
|
|
1651
|
+
try { require.resolve('@esotericsoftware/spine-core/package.json', { paths: [coreRoot] }); runtimePresent = true; } catch { /* Optional runtime is absent, as in rigc's launcher. */ }
|
|
1652
|
+
if (runtimePresent) require('rig-c/render');
|
|
1653
|
+
return require('rig-c/render-shared') as OfficialRenderer;
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
/** One decoder/poser lifetime per state; retain only finite bounds and identities, never atlas pages or rasters. */
|
|
1657
|
+
export function seamStateBounds(build: string, state: string): SeamStateBounds {
|
|
1658
|
+
try {
|
|
1659
|
+
type Renderer = OfficialRenderer;
|
|
1660
|
+
const api = officialRenderer();
|
|
1661
|
+
if (['loadCandidate', 'throughPoser', 'sampleAnimation'].some(k => typeof api[k as keyof Renderer] !== 'function')) throw new Error('official posed-piece API unavailable');
|
|
1662
|
+
const skeleton = join(build, 'skeleton.json'), atlas = join(build, 'skeleton.atlas');
|
|
1663
|
+
const skeletonText = readFileSync(skeleton, 'utf8'), atlasText = readFileSync(atlas, 'utf8');
|
|
1664
|
+
const loaded = api.loadCandidate({ skeletonText, atlasText, atlasDir: build, label: 'setup seam union' }, { skeleton, atlas }, undefined);
|
|
1665
|
+
const frames = api.throughPoser(loaded.choice, poser => api.sampleAnimation(poser, 'still', STILL_FPS, { geometry: true })).value;
|
|
1666
|
+
if (frames.length === 0) throw new Error('no actual still frames');
|
|
1667
|
+
let bounds: SeamStateBounds['bounds'] = null, pieces = 0;
|
|
1668
|
+
const digest = createHash('sha256');
|
|
1669
|
+
for (const frame of frames) {
|
|
1670
|
+
if (!Number.isSafeInteger(frame.index) || !Number.isFinite(frame.time)) throw new Error('unreadable still identity');
|
|
1671
|
+
digest.update(JSON.stringify([frame.index, frame.time]));
|
|
1672
|
+
for (const piece of frame.pieces) {
|
|
1673
|
+
if (piece.world.length === 0 || piece.world.length % 2 !== 0 || !piece.world.every(Number.isFinite)) throw new Error('unreadable drawn vertices');
|
|
1674
|
+
pieces++;
|
|
1675
|
+
digest.update(JSON.stringify([piece.slot, piece.world, piece.tint]));
|
|
1676
|
+
for (let i = 0; i < piece.world.length; i += 2) {
|
|
1677
|
+
const x = piece.world[i], y = piece.world[i + 1];
|
|
1678
|
+
if (bounds === null) bounds = { minX: x, minY: y, maxX: x, maxY: y };
|
|
1679
|
+
else { bounds.minX = Math.min(bounds.minX, x); bounds.minY = Math.min(bounds.minY, y); bounds.maxX = Math.max(bounds.maxX, x); bounds.maxY = Math.max(bounds.maxY, y); }
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
return { state, frames: frames.length, pieces, bounds,
|
|
1684
|
+
pose_sha256: digest.digest('hex') };
|
|
1685
|
+
} catch {
|
|
1686
|
+
refuseIfAny([{ code: 'CHECK_SEAM_DOMAIN', object: 'setup seam union state ' + JSON.stringify(state), detail: 'official selected candidate/still drawn-piece bounds are unavailable; no guessed or empty bounds are substituted' }]);
|
|
1687
|
+
throw new Error('unreachable');
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
/** Source-relative integer lattice: odd-width canvases keep their half-integer world origin. */
|
|
1692
|
+
export function seamUnionViewport(stage: StageBox, states: readonly Pick<SeamStateBounds, 'state' | 'bounds'>[]): Viewport {
|
|
1693
|
+
const bad = (detail: string): never => { refuseIfAny([{ code: 'CHECK_SEAM_DOMAIN', object: 'the common setup-seam union', detail }]); throw new Error('unreachable'); };
|
|
1694
|
+
if (![stage.x, stage.y, stage.width, stage.height].every(Number.isFinite) ||
|
|
1695
|
+
!Number.isSafeInteger(stage.width) || !Number.isSafeInteger(stage.height) || stage.width <= 0 || stage.height <= 0 || states.length === 0) return bad('requires finite authored bounds and actual state readings');
|
|
1696
|
+
let minX = stage.x, minY = stage.y, maxX = stage.x + stage.width, maxY = stage.y + stage.height;
|
|
1697
|
+
if (![maxX, maxY].every(Number.isFinite)) return bad('authored endpoints are not finite');
|
|
1698
|
+
for (const state of states) {
|
|
1699
|
+
const b = state.bounds;
|
|
1700
|
+
if (b === null) continue; // Actual empty drawn roster; the authored stage remains in U.
|
|
1701
|
+
if (![b.minX, b.minY, b.maxX, b.maxY].every(Number.isFinite) || b.maxX < b.minX || b.maxY < b.minY) return bad('state ' + JSON.stringify(state.state) + ' has unavailable finite bounds');
|
|
1702
|
+
minX = Math.min(minX, b.minX); minY = Math.min(minY, b.minY); maxX = Math.max(maxX, b.maxX); maxY = Math.max(maxY, b.maxY);
|
|
1703
|
+
}
|
|
1704
|
+
const left = Math.floor(minX - stage.x), bottom = Math.floor(minY - stage.y);
|
|
1705
|
+
const right = Math.ceil(maxX - stage.x), top = Math.ceil(maxY - stage.y);
|
|
1706
|
+
const width = right - left, height = top - bottom;
|
|
1707
|
+
const x = stage.x + left, y = stage.y + bottom;
|
|
1708
|
+
if (![left, bottom, right, top, width, height, -left, top - stage.height].every(n => Number.isSafeInteger(n) && Math.fround(n) === n) ||
|
|
1709
|
+
width <= 0 || height <= 0 || x > minX || y > minY || x + width < maxX || y + height < maxY ||
|
|
1710
|
+
x - stage.x !== left || y - stage.y !== bottom || x + width - stage.x !== right || y + height - stage.y !== top) return bad('union endpoints/offsets cannot preserve the exact finite source-relative float32 sample map');
|
|
1711
|
+
const cells = width * height, authored = stage.width * stage.height;
|
|
1712
|
+
// Known live lower bound: two RGBA still frames (8U), RGB Float32 warp (12U),
|
|
1713
|
+
// RGB Float32 source (12D). Refuse before these alone exceed the existing6GiB
|
|
1714
|
+
// execution guard (#677/#705); this is not a claim that other heap/atlas work fits that guard.
|
|
1715
|
+
const knownBytes = 20 * cells + 12 * authored;
|
|
1716
|
+
if (!Number.isSafeInteger(cells) || !Number.isSafeInteger(knownBytes) || knownBytes > 6 * 1024 ** 3) return bad('union ' + width + 'x' + height + ' requires at least ' + knownBytes + ' known raster bytes, beyond the existing 6 GiB execution budget');
|
|
1717
|
+
return { x, y, width, height, scale: 1, pixelWidth: width, pixelHeight: height };
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
/** U is a picture, not the mean denominator. Strict outside metadata checks every actual still frame. */
|
|
1721
|
+
export function seamCanonicalViewport(stage: StageBox, vp: Viewport, sidecar: unknown, expected: Viewport = { ...stage, scale: 1, pixelWidth: stage.width, pixelHeight: stage.height }): Viewport {
|
|
1722
|
+
const pinned = isRecord(sidecar) && isRecord(sidecar.pinned) ? sidecar.pinned : null;
|
|
1723
|
+
const map = rigToFrameMap(stage, stage.height, expected);
|
|
1724
|
+
if (![map.tx, map.ty].every(n => Number.isSafeInteger(n) && Math.fround(n) === n) ||
|
|
1725
|
+
Object.keys(expected).some(k => vp[k as keyof Viewport] !== expected[k as keyof Viewport]) || pinned?.by !== '--viewport' || !Array.isArray(pinned.outside) || pinned.outside.length !== 0) {
|
|
1726
|
+
refuseIfAny([{ code: 'CHECK_SEAM_DOMAIN', object: 'the source-anchored setup seam', detail: `requires the fixed common union at scale1 and official pinned.outside=[]; viewport ${JSON.stringify(vp)}, pinned ${JSON.stringify(pinned)}; an incomplete or unavailable union cannot pass` }]);
|
|
1727
|
+
}
|
|
1728
|
+
return expected;
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
/** Collision-free interning: a stack is its exact preceding stack and drawing identity. */
|
|
1732
|
+
class SeamStacks {
|
|
1733
|
+
private readonly signatures = new Map<string, number>();
|
|
1734
|
+
private readonly links = new Map<string, number>();
|
|
1735
|
+
append(previous: number, signature: string): number {
|
|
1736
|
+
let drawing = this.signatures.get(signature);
|
|
1737
|
+
if (drawing === undefined) { drawing = this.signatures.size + 1; this.signatures.set(signature, drawing); }
|
|
1738
|
+
const key = `${previous},${drawing}`;
|
|
1739
|
+
let id = this.links.get(key);
|
|
1740
|
+
if (id === undefined) {
|
|
1741
|
+
id = this.links.size + 1;
|
|
1742
|
+
if (id > 0x7fffffff) refuseIfAny([{ code: 'CHECK_SEAM_SUPPORT', object: 'the contributor stack', detail: 'exceeds the signed 32-bit index domain' }]);
|
|
1743
|
+
this.links.set(key, id);
|
|
1744
|
+
}
|
|
1745
|
+
return id;
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
type SeamPlaced = PlacedAlpha & { png?: string };
|
|
1750
|
+
|
|
1751
|
+
/**
|
|
1752
|
+
* Reference alpha uses the same 2x2 gather as seamPairRows. Actual support is
|
|
1753
|
+
* rasterised by the official renderer, never by a copied triangle algorithm.
|
|
1754
|
+
* Full ordered stacks retain third-party occlusion and gathering dependencies,
|
|
1755
|
+
* including translucent layers; unchanged names alone cannot establish inheritance.
|
|
1756
|
+
*/
|
|
1757
|
+
function seamSupport(build: string, rigPath: string, set: FrameSet, placed: readonly SeamPlaced[], stacks: SeamStacks, stage: StageBox): SeamSupport {
|
|
1758
|
+
const [W, H] = [set.viewport.pixelWidth, set.viewport.pixelHeight];
|
|
1759
|
+
const n = W * H;
|
|
1760
|
+
const support: SeamSupport = { reference: new Int32Array(n), posed: new Int32Array(n), referenceDepth: new Uint8Array(n), posedDepth: new Uint8Array(n), drawings: [] };
|
|
1761
|
+
const touched = new Int32Array(n);
|
|
1762
|
+
const map = rigToFrameMap(stage, stage.height, set.viewport);
|
|
1763
|
+
placed.forEach((p, i) => {
|
|
1764
|
+
const art = createHash('sha256').update(p.image.data).digest('hex');
|
|
1765
|
+
const shape = [p.x, p.y, p.image.width, p.image.height];
|
|
1766
|
+
const signature = JSON.stringify(['reference', p.name, shape, art]);
|
|
1767
|
+
support.drawings?.push({ scope: 'reference', name: p.name, identity: p.name, order: i, geometry: createHash('sha256').update(JSON.stringify(shape)).digest('hex'), art });
|
|
1768
|
+
for (let y = 0; y < p.image.height; y++) for (let x = 0; x < p.image.width; x++) {
|
|
1769
|
+
if (p.image.data[(y * p.image.width + x) * 4 + 3] === 0) continue;
|
|
1770
|
+
// Each integer source sample gathers its own and the next row/column.
|
|
1771
|
+
for (const v of [p.y + y - 1, p.y + y]) for (const u of [p.x + x - 1, p.x + x]) {
|
|
1772
|
+
if (u < 0 || v < 0 || u >= stage.width || v >= stage.height) continue;
|
|
1773
|
+
const fx = u + map.tx, fy = v + map.ty;
|
|
1774
|
+
if (fx < 0 || fy < 0 || fx >= W || fy >= H) continue;
|
|
1775
|
+
const q = fy * W + fx;
|
|
1776
|
+
if (touched[q] === i + 1) continue;
|
|
1777
|
+
touched[q] = i + 1;
|
|
1778
|
+
support.reference[q] = stacks.append(support.reference[q], signature);
|
|
1779
|
+
support.referenceDepth[q] = Math.min(255, support.referenceDepth[q] + 1);
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
});
|
|
1783
|
+
let boundary: SeamSupportUnavailable = { code: 'RENDERER_API_UNAVAILABLE' };
|
|
1784
|
+
try {
|
|
1785
|
+
type Renderer = OfficialRenderer;
|
|
1786
|
+
const api = officialRenderer();
|
|
1787
|
+
if (['loadCandidate', 'throughPoser', 'sampleAnimation', 'pageFor', 'projector', 'rasterisePiece'].some(k => typeof api[k as keyof Renderer] !== 'function')) throw new SeamSupportError(boundary);
|
|
1788
|
+
boundary = { code: 'SOURCE_RIG_UNREADABLE' };
|
|
1789
|
+
const sourceRig: unknown = JSON.parse(readFileSync(rigPath, 'utf8'));
|
|
1790
|
+
if (!isRecord(sourceRig) || (sourceRig.images !== undefined && typeof sourceRig.images !== 'string')) throw new SeamSupportError(boundary);
|
|
1791
|
+
const imageHome = resolve(dirname(rigPath), typeof sourceRig.images === 'string' ? sourceRig.images : '.');
|
|
1792
|
+
boundary = { code: 'RASTER_READ_UNAVAILABLE' };
|
|
1793
|
+
const skeleton = join(build, 'skeleton.json'), atlas = join(build, 'skeleton.atlas');
|
|
1794
|
+
const candidate = api.loadCandidate({ skeletonText: readFileSync(skeleton, 'utf8'), atlasText: readFileSync(atlas, 'utf8'), atlasDir: build, label: 'setup seam effects' }, { skeleton, atlas }, undefined);
|
|
1795
|
+
const pose = api.throughPoser(candidate.choice, p => api.sampleAnimation(p, 'still', STILL_FPS, { geometry: true })).value[0];
|
|
1796
|
+
boundary = { code: 'POSE_EXPORT_UNREADABLE' };
|
|
1797
|
+
const geometry: unknown = JSON.parse(readFileSync(join(set.dir, GEOMETRY_FILE), 'utf8'));
|
|
1798
|
+
const captured = isRecord(geometry) && Array.isArray(geometry.frames) ? geometry.frames[0] : null;
|
|
1799
|
+
if (pose === undefined || !isRecord(captured) || captured.index !== pose.index || captured.time !== pose.time || JSON.stringify(captured.attachments) !== JSON.stringify(pose.attachments)) throw new SeamSupportError({ code: 'POSE_MISMATCH' });
|
|
1800
|
+
const vp: RootCoverageViewport = { minX: set.viewport.x, minY: set.viewport.y, maxX: set.viewport.x + W, maxY: set.viewport.y + H, scale: 1, width: W, height: H };
|
|
1801
|
+
const project = api.projector(vp);
|
|
1802
|
+
pose.pieces.forEach((piece, i) => {
|
|
1803
|
+
if ('source' in piece) throw new SeamSupportError({ code: 'SOURCE_MAPPING_UNSUPPORTED', slot: piece.slot, feature: 'clipping' });
|
|
1804
|
+
const page = api.pageFor(candidate.pages, piece);
|
|
1805
|
+
const matches = pose.attachments?.filter(a => a.slot === piece.slot) ?? [];
|
|
1806
|
+
if (matches.length !== 1) throw new SeamSupportError({ code: 'POSE_ATTACHMENT_MISSING', slot: piece.slot });
|
|
1807
|
+
const posed = matches[0], identity = posed.attachment;
|
|
1808
|
+
const source = seamSourceAttachment(sourceRig, piece.slot, identity);
|
|
1809
|
+
boundary = { code: 'SOURCE_IMAGE_UNREADABLE', slot: piece.slot, attachment: identity };
|
|
1810
|
+
const imagePath = resolve(imageHome, String(source.image));
|
|
1811
|
+
const own = readPng(imagePath);
|
|
1812
|
+
const art = createHash('sha256').update(own.data).digest('hex');
|
|
1813
|
+
const signature = seamDrawingSignature({ slot: piece.slot, attachment: identity, source,
|
|
1814
|
+
image: { width: own.width, height: own.height, rgba_sha256: art }, vertices: posed.vertices, color: posed.color });
|
|
1815
|
+
// Reporting may name a global draw index; it never enters the signature.
|
|
1816
|
+
support.drawings?.push({ scope: 'posed', name: piece.slot, identity, order: i,
|
|
1817
|
+
geometry: createHash('sha256').update(JSON.stringify(seamSourceValue({ source: Object.fromEntries(Object.entries(source).filter(([key]) => key !== 'image')), vertices: posed.vertices, color: posed.color }))).digest('hex'), art, source_png_sha256: createHash('sha256').update(readFileSync(imagePath)).digest('hex') });
|
|
1818
|
+
boundary = { code: 'RASTER_READ_UNAVAILABLE', slot: piece.slot, attachment: identity };
|
|
1819
|
+
api.rasterisePiece(page, piece, project, vp, (x, y, _r, _g, _b, alpha) => {
|
|
1820
|
+
if (alpha <= 0) return;
|
|
1821
|
+
const q = y * W + x;
|
|
1822
|
+
// A mesh may emit more than one clipped triangle from the same drawing.
|
|
1823
|
+
if (touched[q] === -(i + 1)) return;
|
|
1824
|
+
touched[q] = -(i + 1);
|
|
1825
|
+
support.posed[q] = stacks.append(support.posed[q], signature);
|
|
1826
|
+
support.posedDepth[q] = Math.min(255, support.posedDepth[q] + 1);
|
|
1827
|
+
});
|
|
1828
|
+
});
|
|
1829
|
+
} catch (error) {
|
|
1830
|
+
support.unavailable = error instanceof SeamSupportError ? error.reason : boundary;
|
|
1831
|
+
}
|
|
1832
|
+
return support;
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
export interface SeamReading {
|
|
1836
|
+
mean: number;
|
|
1837
|
+
display_mean: number;
|
|
1838
|
+
denominator_px: number;
|
|
1839
|
+
px_over_40: number;
|
|
1840
|
+
px_over_80: number;
|
|
1841
|
+
frame_scale: number;
|
|
1842
|
+
viewport: Viewport;
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
export interface SeamScope {
|
|
1846
|
+
mode: 'source-grid/base' | 'source-grid/affected-set';
|
|
1847
|
+
domain?: { viewport: Viewport; authored: StageBox; numerator: 'whole-union' | 'authored-scene-interior'; states: SeamStateBounds[] };
|
|
1848
|
+
denominator_px: number;
|
|
1849
|
+
/** The unchanged auto-fitted reading is diagnostic, never another acceptance bar. */
|
|
1850
|
+
auto_frame_raw: SeamReading;
|
|
1851
|
+
/** All canonical residuals, including inherited ones, before selecting effects. */
|
|
1852
|
+
whole: SeamReading;
|
|
1853
|
+
effects?: SeamEffects['reasons'];
|
|
1854
|
+
changes?: SeamEffects['changes'];
|
|
1855
|
+
unavailable?: SeamSupportUnavailable;
|
|
1856
|
+
/** Every actually observed pre-threshold reference contributor category, not error-only rows. */
|
|
1857
|
+
population?: SeamPopulation;
|
|
1858
|
+
whole_pairs?: Array<Omit<SeamPairRow, 'picture'>>;
|
|
1859
|
+
pairs?: Array<{ parts: [string, string]; whole_px_over_40: number; affected_px_over_40: number; inherited_px_over_40: number; reasons: Partial<SeamEffects['reasons']> }>;
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1862
|
+
function canonicalDenominator(seam: SeamFigures): number {
|
|
1863
|
+
const denominator = seam.denominator;
|
|
1864
|
+
if (denominator === undefined) {
|
|
1865
|
+
refuseIfAny([{ code: 'CHECK_SEAM_SUPPORT', object: 'the canonical seam denominator', detail: 'the fixed authored support was not read' }]);
|
|
1866
|
+
throw new Error('unreachable');
|
|
1867
|
+
}
|
|
1868
|
+
return denominator;
|
|
1869
|
+
}
|
|
1870
|
+
|
|
1871
|
+
function seamReading(seam: SeamFigures, viewport: Viewport): SeamReading {
|
|
1872
|
+
return { mean: seam.mean, display_mean: round3(seam.mean), denominator_px: seam.denominator ?? viewport.pixelWidth * viewport.pixelHeight - (seam.border?.framePx ?? 0), px_over_40: seam.over40, px_over_80: seam.over80, frame_scale: viewport.scale, viewport };
|
|
1501
1873
|
}
|
|
1502
1874
|
|
|
1503
1875
|
/**
|
|
1504
1876
|
* Where `check --keep-stills` leaves the setup-pose still under `--out`
|
|
1505
1877
|
* (issue #209): rigc's own render directory as `render` wrote it —
|
|
1506
|
-
* `frames.json` (the viewport the seam
|
|
1878
|
+
* `frames.json` (the canonical viewport the seam maps by, and the
|
|
1507
1879
|
* background) and the set directory beside it — so a reader compares against
|
|
1508
1880
|
* the frame the bars read rather than rebuilding it. Removed at the start of
|
|
1509
1881
|
* every run, so it is on disk only after a run that asked for it.
|
|
@@ -1554,6 +1926,8 @@ export interface SeamPairRow {
|
|
|
1554
1926
|
frame_box: [number, number, number, number];
|
|
1555
1927
|
rig_box: [number, number, number, number];
|
|
1556
1928
|
cut?: { from: string; differing_copies_px: number };
|
|
1929
|
+
/** Counted sample centres outside the authored source; clamped rig_box is not source provenance there. */
|
|
1930
|
+
outside_authored_px?: number;
|
|
1557
1931
|
picture: string;
|
|
1558
1932
|
}
|
|
1559
1933
|
|
|
@@ -1566,13 +1940,30 @@ export interface PlacedAlpha {
|
|
|
1566
1940
|
image: Raster;
|
|
1567
1941
|
}
|
|
1568
1942
|
|
|
1569
|
-
/**
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1943
|
+
/** Actual included source-grid sample support, independent of RGB error. */
|
|
1944
|
+
export interface SeamPopulationCounts {
|
|
1945
|
+
whole_sample_px: number;
|
|
1946
|
+
scope_sample_px: number;
|
|
1947
|
+
inherited_sample_px: number;
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
export interface SeamPopulation {
|
|
1951
|
+
basis: 'reference-alpha/top-two-of-2x2';
|
|
1952
|
+
measured_sample_px: number;
|
|
1953
|
+
pair_count: number;
|
|
1954
|
+
pairs: Array<SeamPopulationCounts & { parts: [string, string] }>;
|
|
1955
|
+
single_art: Array<SeamPopulationCounts & { part: string }>;
|
|
1956
|
+
no_reference_art: SeamPopulationCounts;
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
interface SeamReferenceSample {
|
|
1960
|
+
first: number; second: number; u0: number; v0: number;
|
|
1961
|
+
rx0: number; ry0: number; rx1: number; ry1: number;
|
|
1962
|
+
read: Array<[number, number]>;
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
/** The existing 2x2 reference attribution; no posed ownership or anatomical pair is inferred. */
|
|
1966
|
+
function seamReferenceAttribution(parts: readonly PlacedAlpha[], rigSize: readonly [number, number], vp: Viewport) {
|
|
1576
1967
|
const [W, H] = rigSize;
|
|
1577
1968
|
// Each rig pixel's two topmost parts with art there (-1 for none): the top two of a union of pixels are among each pixel's own top two.
|
|
1578
1969
|
const top = new Int32Array(W * H).fill(-1);
|
|
@@ -1591,7 +1982,93 @@ export function seamPairRows(seam: SeamFigures, parts: readonly PlacedAlpha[], r
|
|
|
1591
1982
|
}
|
|
1592
1983
|
}
|
|
1593
1984
|
});
|
|
1594
|
-
const {
|
|
1985
|
+
const sample: SeamReferenceSample = { first: -1, second: -1, u0: 0, v0: 0, rx0: 0, ry0: 0, rx1: 0, ry1: 0, read: [] };
|
|
1986
|
+
return (p: number, map: ScaleTranslate, details = false): SeamReferenceSample => {
|
|
1987
|
+
const fx = p % vp.pixelWidth, fy = Math.floor(p / vp.pixelWidth);
|
|
1988
|
+
const { sx, sy, tx, ty } = map;
|
|
1989
|
+
const u0 = Math.floor((fx - tx) / sx), v0 = Math.floor((fy - ty) / sy);
|
|
1990
|
+
let first = -1, second = -1;
|
|
1991
|
+
const read = sample.read; read.length = 0;
|
|
1992
|
+
let rx0 = Infinity, ry0 = Infinity, rx1 = -Infinity, ry1 = -Infinity;
|
|
1993
|
+
for (let dv = 0; dv < 2; dv++) {
|
|
1994
|
+
for (let du = 0; du < 2; du++) {
|
|
1995
|
+
const u = u0 + du, v = v0 + dv;
|
|
1996
|
+
if (u < 0 || u >= W || v < 0 || v >= H) continue;
|
|
1997
|
+
if (details) read.push([u, v]);
|
|
1998
|
+
rx0 = Math.min(rx0, u); ry0 = Math.min(ry0, v);
|
|
1999
|
+
rx1 = Math.max(rx1, u); ry1 = Math.max(ry1, v);
|
|
2000
|
+
for (let layer = 0; layer < 2; layer++) {
|
|
2001
|
+
const k = layer === 0 ? top[v * W + u] : next[v * W + u];
|
|
2002
|
+
if (k < 0 || k === first || k === second) continue;
|
|
2003
|
+
if (k > first) { second = first; first = k; }
|
|
2004
|
+
else if (k > second) second = k;
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
if (rx1 < rx0) {
|
|
2009
|
+
rx0 = rx1 = Math.min(Math.max(u0, 0), W - 1);
|
|
2010
|
+
ry0 = ry1 = Math.min(Math.max(v0, 0), H - 1);
|
|
2011
|
+
}
|
|
2012
|
+
sample.first = first; sample.second = second; sample.u0 = u0; sample.v0 = v0;
|
|
2013
|
+
sample.rx0 = rx0; sample.ry0 = ry0; sample.rx1 = rx1; sample.ry1 = ry1;
|
|
2014
|
+
return sample;
|
|
2015
|
+
};
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
/**
|
|
2019
|
+
* Observe only cells the existing seam loop actually includes. The callback has
|
|
2020
|
+
* no RGB argument: membership cannot be selected from threshold-error pixels.
|
|
2021
|
+
* Source-grid background is a bucket, not a fabricated two-part pair. Counted
|
|
2022
|
+
* residuals still use their old NO_ART attribution, boxes and pictures.
|
|
2023
|
+
*/
|
|
2024
|
+
export function createSeamPopulation(parts: readonly PlacedAlpha[], rigSize: readonly [number, number], vp: Viewport, scope?: Uint8Array) {
|
|
2025
|
+
const at = seamReferenceAttribution(parts, rigSize, vp);
|
|
2026
|
+
const counts = (): SeamPopulationCounts => ({ whole_sample_px: 0, scope_sample_px: 0, inherited_sample_px: 0 });
|
|
2027
|
+
const pairs = new Map<number, Map<number, SeamPopulationCounts & { parts: [string, string] }>>();
|
|
2028
|
+
const singles = new Map<number, SeamPopulationCounts & { part: string }>();
|
|
2029
|
+
const noArt = counts();
|
|
2030
|
+
let measured = 0;
|
|
2031
|
+
return {
|
|
2032
|
+
observe: (p: number, map: ScaleTranslate): void => {
|
|
2033
|
+
const { first: b, second: a } = at(p, map);
|
|
2034
|
+
let row: SeamPopulationCounts;
|
|
2035
|
+
if (a >= 0) {
|
|
2036
|
+
let lower = pairs.get(b);
|
|
2037
|
+
if (lower === undefined) { lower = new Map(); pairs.set(b, lower); }
|
|
2038
|
+
let pair = lower.get(a);
|
|
2039
|
+
if (pair === undefined) { pair = { parts: [parts[a].name, parts[b].name], ...counts() }; lower.set(a, pair); }
|
|
2040
|
+
row = pair;
|
|
2041
|
+
} else if (b >= 0) {
|
|
2042
|
+
let single = singles.get(b);
|
|
2043
|
+
if (single === undefined) { single = { part: parts[b].name, ...counts() }; singles.set(b, single); }
|
|
2044
|
+
row = single;
|
|
2045
|
+
} else row = noArt;
|
|
2046
|
+
measured++; row.whole_sample_px++;
|
|
2047
|
+
if (scope === undefined || scope[p] !== 0) row.scope_sample_px++;
|
|
2048
|
+
else row.inherited_sample_px++;
|
|
2049
|
+
},
|
|
2050
|
+
finish: (): SeamPopulation => {
|
|
2051
|
+
const rows = [...pairs.entries()].sort(([a], [b]) => a - b)
|
|
2052
|
+
.flatMap(([, lower]) => [...lower.entries()].sort(([a], [b]) => a - b).map(([, row]) => ({ ...row })));
|
|
2053
|
+
return { basis: 'reference-alpha/top-two-of-2x2', measured_sample_px: measured,
|
|
2054
|
+
pair_count: rows.length, pairs: rows,
|
|
2055
|
+
single_art: [...singles.entries()].sort(([a], [b]) => a - b).map(([, row]) => ({ ...row })),
|
|
2056
|
+
no_reference_art: { ...noArt } };
|
|
2057
|
+
},
|
|
2058
|
+
rows: (seam: SeamFigures) => seamPairRowsFrom(seam, parts, rigSize, vp, at),
|
|
2059
|
+
};
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
/**
|
|
2063
|
+
* Split only counted error pixels into the existing diagnostic rows, worst
|
|
2064
|
+
* first; population metadata does not create zero-error boxes or pictures.
|
|
2065
|
+
*/
|
|
2066
|
+
export function seamPairRows(seam: SeamFigures, parts: readonly PlacedAlpha[], rigSize: readonly [number, number], vp: Viewport): Array<{ row: SeamPairRow; pixels: number[] }> {
|
|
2067
|
+
return seamPairRowsFrom(seam, parts, rigSize, vp, seamReferenceAttribution(parts, rigSize, vp));
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
function seamPairRowsFrom(seam: SeamFigures, parts: readonly PlacedAlpha[], rigSize: readonly [number, number], vp: Viewport, attribution: ReturnType<typeof seamReferenceAttribution>): Array<{ row: SeamPairRow; pixels: number[] }> {
|
|
2071
|
+
const [W, H] = rigSize;
|
|
1595
2072
|
// A part's pixel at rig (u, v) as an offset into its image, or -1 where it holds no art.
|
|
1596
2073
|
const at = (k: number, u: number, v: number): number => {
|
|
1597
2074
|
const part = parts[k];
|
|
@@ -1609,54 +2086,23 @@ export function seamPairRows(seam: SeamFigures, parts: readonly PlacedAlpha[], r
|
|
|
1609
2086
|
const db = parts[b].image.data;
|
|
1610
2087
|
return da[oa] !== db[ob] || da[oa + 1] !== db[ob + 1] || da[oa + 2] !== db[ob + 2];
|
|
1611
2088
|
};
|
|
1612
|
-
interface Acc { a: number; b: number; over40: number; over80: number; f: [number, number, number, number]; r: [number, number, number, number]; pixels: number[]; differing: number }
|
|
2089
|
+
interface Acc { a: number; b: number; over40: number; over80: number; f: [number, number, number, number]; r: [number, number, number, number]; pixels: number[]; differing: number; outside: number }
|
|
1613
2090
|
const byPair = new Map<string, Acc>();
|
|
1614
2091
|
seam.counted.forEach((p, idx) => {
|
|
1615
2092
|
const fx = p % vp.pixelWidth;
|
|
1616
2093
|
const fy = Math.floor(p / vp.pixelWidth);
|
|
1617
|
-
const u0 =
|
|
1618
|
-
const v0 = Math.floor((fy - ty) / sy);
|
|
1619
|
-
let first = -1;
|
|
1620
|
-
let second = -1;
|
|
1621
|
-
const read: Array<[number, number]> = [];
|
|
1622
|
-
let rx0 = Infinity;
|
|
1623
|
-
let ry0 = Infinity;
|
|
1624
|
-
let rx1 = -Infinity;
|
|
1625
|
-
let ry1 = -Infinity;
|
|
1626
|
-
for (let dv = 0; dv < 2; dv++) {
|
|
1627
|
-
for (let du = 0; du < 2; du++) {
|
|
1628
|
-
const u = u0 + du;
|
|
1629
|
-
const v = v0 + dv;
|
|
1630
|
-
if (u < 0 || u >= W || v < 0 || v >= H) continue;
|
|
1631
|
-
read.push([u, v]);
|
|
1632
|
-
rx0 = Math.min(rx0, u);
|
|
1633
|
-
ry0 = Math.min(ry0, v);
|
|
1634
|
-
rx1 = Math.max(rx1, u);
|
|
1635
|
-
ry1 = Math.max(ry1, v);
|
|
1636
|
-
for (const k of [top[v * W + u], next[v * W + u]]) {
|
|
1637
|
-
if (k < 0 || k === first || k === second) continue;
|
|
1638
|
-
if (k > first) {
|
|
1639
|
-
second = first;
|
|
1640
|
-
first = k;
|
|
1641
|
-
} else if (k > second) second = k;
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
// A sample wholly outside the rig reads no rig pixel; its rig box is the nearest rig pixel.
|
|
1646
|
-
if (rx1 < rx0) {
|
|
1647
|
-
rx0 = rx1 = Math.min(Math.max(u0, 0), W - 1);
|
|
1648
|
-
ry0 = ry1 = Math.min(Math.max(v0, 0), H - 1);
|
|
1649
|
-
}
|
|
2094
|
+
const { u0, v0, first, second, read, rx0, ry0, rx1, ry1 } = attribution(p, seam.map, true);
|
|
1650
2095
|
const a = second;
|
|
1651
2096
|
const b = first;
|
|
1652
2097
|
const key = `${a},${b}`;
|
|
1653
2098
|
let acc = byPair.get(key);
|
|
1654
2099
|
if (acc === undefined) {
|
|
1655
|
-
acc = { a, b, over40: 0, over80: 0, f: [fx, fy, fx, fy], r: [rx0, ry0, rx1, ry1], pixels: [], differing: 0 };
|
|
2100
|
+
acc = { a, b, over40: 0, over80: 0, f: [fx, fy, fx, fy], r: [rx0, ry0, rx1, ry1], pixels: [], differing: 0, outside: 0 };
|
|
1656
2101
|
byPair.set(key, acc);
|
|
1657
2102
|
}
|
|
1658
2103
|
if (a >= 0 && parts[a].from === parts[b].from && read.some(([u, v]) => differ(a, b, u, v))) acc.differing++;
|
|
1659
2104
|
acc.over40++;
|
|
2105
|
+
if (u0 < 0 || v0 < 0 || u0 >= W || v0 >= H) acc.outside++;
|
|
1660
2106
|
acc.pixels.push(p);
|
|
1661
2107
|
if (seam.countedDiff[idx] > SEAM_PX_LEVEL_HIGH) acc.over80++;
|
|
1662
2108
|
acc.f = [Math.min(acc.f[0], fx), Math.min(acc.f[1], fy), Math.max(acc.f[2], fx), Math.max(acc.f[3], fy)];
|
|
@@ -1670,7 +2116,8 @@ export function seamPairRows(seam: SeamFigures, parts: readonly PlacedAlpha[], r
|
|
|
1670
2116
|
const pair: [string, string] = acc.a < 0 ? [name(acc.b), SEAM_NO_ART] : [name(acc.a), name(acc.b)];
|
|
1671
2117
|
const file = `${String(i + 1).padStart(Math.max(2, width), '0')}_${pair.map((n) => (n === SEAM_NO_ART ? 'no-art' : n)).join('_')}.png`;
|
|
1672
2118
|
const cut = acc.a >= 0 && parts[acc.a].from === parts[acc.b].from ? { cut: { from: parts[acc.a].from, differing_copies_px: acc.differing } } : {};
|
|
1673
|
-
return { row: { parts: pair, px_over_40: acc.over40,
|
|
2119
|
+
return { row: { parts: pair, px_over_40: acc.over40,
|
|
2120
|
+
...(acc.outside > 0 ? { outside_authored_px: acc.outside } : {}), px_over_80: acc.over80, frame_box: acc.f, rig_box: acc.r, ...cut, picture: `${SEAM_DIR}/${file}` }, pixels: acc.pixels };
|
|
1674
2121
|
});
|
|
1675
2122
|
}
|
|
1676
2123
|
|
|
@@ -1911,6 +2358,8 @@ export interface CheckFigures {
|
|
|
1911
2358
|
* divided by its square ({@link seamRigPx}). Null with the other three.
|
|
1912
2359
|
*/
|
|
1913
2360
|
seam_frame_scale: number | null;
|
|
2361
|
+
/** Canonical acceptance scope and separately labelled diagnostic/raw readings (#705). */
|
|
2362
|
+
seam_scope?: SeamScope;
|
|
1914
2363
|
/**
|
|
1915
2364
|
* Written only when `parts.json` declares a scene (issue #242): the frame pixels
|
|
1916
2365
|
* on the painting's border that the seam figures above leave out, and how many
|
|
@@ -1976,6 +2425,7 @@ export interface SetCheckFigures {
|
|
|
1976
2425
|
seam_px_over_40: number;
|
|
1977
2426
|
seam_px_over_80: number;
|
|
1978
2427
|
seam_frame_scale: number;
|
|
2428
|
+
seam_scope?: SeamScope;
|
|
1979
2429
|
seam_border?: { frame_px_left_out: number; px_over_40_left_out: number };
|
|
1980
2430
|
seam_pairs?: SeamPairRow[];
|
|
1981
2431
|
RECOMPOSITE_HOLES: ReportedLine;
|
|
@@ -2151,13 +2601,44 @@ export const STRESS_LINE = 'STRESS_OFF_CHAIN';
|
|
|
2151
2601
|
/** The bars `PASS` reads, in the order the summary counts them: the gate, the reference's two, then the judgement lines. */
|
|
2152
2602
|
export const BARS = ['gate', 'loop', 'seam', ...JUDGEMENT_LINES] as const;
|
|
2153
2603
|
|
|
2604
|
+
/**
|
|
2605
|
+
* `SEAM_OVER_MOTION` (issue #493): every declared neighbour pair read in every
|
|
2606
|
+
* animation `motion.json` holds, the idle included, by rig-c's seam reading
|
|
2607
|
+
* (`rigc render --seam`, rig-c 2.60.0). Existing internal-joint and explicit-seam pairs remain **warnings, never bars**. Proven body-root pairs are the exception (issue #686): an active-reading tear fails a counted bar. The
|
|
2608
|
+
* owner's ruling (2026-10-18): a seam opening in motion may be intentional, so
|
|
2609
|
+
* the line names the pair, the animation, the frames and the cells, and moves
|
|
2610
|
+
* neither the exit status nor `check: PASS` for those existing pairs; the summary counts their warnings apart from the bars.
|
|
2611
|
+
*
|
|
2612
|
+
* The pairs are the ones the inputs declare and nothing else: each limb's
|
|
2613
|
+
* consecutive segments in `parts.json` (`config.limbs`, the upper and the
|
|
2614
|
+
* segment below each joint) and, under `--requirements`, each `seam`
|
|
2615
|
+
* requirement's part and neighbour, then proven body-to-segment-zero pairs resolved from hierarchy, slots and provenance. None declared, the line is a SKIP naming
|
|
2616
|
+
* why, never a pass, and `check.json` carries no key for it.
|
|
2617
|
+
*
|
|
2618
|
+
* **The floor** ({@link openingOverFloor}): a frame's gap or ghost is reported
|
|
2619
|
+
* when it holds more cells than its box is long — when it is thicker than one
|
|
2620
|
+
* cell. rigc counts a cell drawn when the renderer paints its centre at half
|
|
2621
|
+
* opacity or more, so a boundary that moves by less than a cell flips the
|
|
2622
|
+
* cells along it in or out: a line of cells one deep, scattered or joined,
|
|
2623
|
+
* holds at most as many cells as its box's longer side. A hole of any area
|
|
2624
|
+
* holds more. The rule types no number; it is read off rigc's own cell and
|
|
2625
|
+
* box, and measured, not chosen: on `examples/wind`'s idle rigc names 43
|
|
2626
|
+
* openings over its six limb pairs (28 and 15 frames of the two elbows, 1 to
|
|
2627
|
+
* 5 cells, boxes up to 17 cells long) and every one is one cell thick; on
|
|
2628
|
+
* rig-c's `gallery/walk` its 13 joint cracks of 1 to 3 cells are too; the
|
|
2629
|
+
* ghost rig-c's own reading names on a skirt swung clear of a leg (1564 cells
|
|
2630
|
+
* in a box 92 long) is far over it.
|
|
2631
|
+
*/
|
|
2632
|
+
export const MOTION_SEAM_LINE = 'SEAM_OVER_MOTION';
|
|
2633
|
+
|
|
2154
2634
|
/**
|
|
2155
2635
|
* The bars a character's own check may have failed and `compose --accept`
|
|
2156
2636
|
* still take (issue #203): every bar of {@link BARS} but the gate, which is
|
|
2157
2637
|
* rig-c's and never accepted, {@link FOLD_LINE} (issue #320) and
|
|
2158
|
-
* {@link STRESS_LINE} (issue #347)
|
|
2638
|
+
* {@link STRESS_LINE} (issue #347), and the failing body-root bar of
|
|
2639
|
+
* {@link MOTION_SEAM_LINE} (issue #686).
|
|
2159
2640
|
*/
|
|
2160
|
-
export const ACCEPTABLE_BARS: readonly string[] = [...BARS.filter((b) => b !== 'gate'), FOLD_LINE, LEVEL_LINE, STRESS_LINE, LIMB_LINE, SWEEP_LINE];
|
|
2641
|
+
export const ACCEPTABLE_BARS: readonly string[] = [...BARS.filter((b) => b !== 'gate'), FOLD_LINE, LEVEL_LINE, STRESS_LINE, LIMB_LINE, SWEEP_LINE, MOTION_SEAM_LINE];
|
|
2161
2642
|
|
|
2162
2643
|
/**
|
|
2163
2644
|
* The bars a `check.json`, as `check` writes it, says were not met, in
|
|
@@ -2184,6 +2665,8 @@ export function barsNotMet(fig: Readonly<Record<string, unknown>>): string[] {
|
|
|
2184
2665
|
const l = fig[n];
|
|
2185
2666
|
if (typeof l === 'object' && l !== null && (l as { status?: unknown }).status === 'FAIL') out.push(n);
|
|
2186
2667
|
}
|
|
2668
|
+
const motion = fig[MOTION_SEAM_LINE];
|
|
2669
|
+
if (isRecord(motion) && isRecord(motion.roots) && motion.roots.status === 'FAIL') out.push(MOTION_SEAM_LINE);
|
|
2187
2670
|
return out;
|
|
2188
2671
|
}
|
|
2189
2672
|
|
|
@@ -2208,7 +2691,7 @@ export interface CheckReport {
|
|
|
2208
2691
|
idle: { frames: number; fps: number; duration: number; lastIndex: number; loopAt: { x: number; y: number } } | null;
|
|
2209
2692
|
/** The physics line ({@link loopPhysicsLine}); null when the rig declares no physics constraint or has no idle. */
|
|
2210
2693
|
loopPhysics: string | null;
|
|
2211
|
-
/** The
|
|
2694
|
+
/** The canonical seam grid with parts; otherwise the source-only fitted still grid. Null when neither was read. */
|
|
2212
2695
|
seamViewport: Viewport | null;
|
|
2213
2696
|
/** Every bar in {@link BARS} that measured, and every one that did not with its reason. */
|
|
2214
2697
|
bars: { measured: string[]; skipped: Array<{ bar: string; reason: string }> };
|
|
@@ -2248,7 +2731,7 @@ export function barsSummary(r: Pick<CheckReport, 'bars'>): string {
|
|
|
2248
2731
|
|
|
2249
2732
|
/** The summary's warning clause: each warning line that read something, named, with the warnings they printed together; empty when none read. */
|
|
2250
2733
|
export function warningsClause(r: Pick<CheckReport, 'motionSeam' | 'cloth'>): string {
|
|
2251
|
-
const read = [...(r.motionSeam.status === 'SKIP' ? [] : [{ name: MOTION_SEAM_LINE, n: r.motionSeam.warnings }]), ...(r.cloth.status === 'SKIP' ? [] : [{ name: CLOTH_LINE, n: r.cloth.warnings }])];
|
|
2734
|
+
const read = [...(r.motionSeam.status === 'SKIP' || (r.motionSeam.roots !== undefined && r.motionSeam.pairs.every(p => p.root !== undefined)) ? [] : [{ name: MOTION_SEAM_LINE, n: r.motionSeam.warnings }]), ...(r.cloth.status === 'SKIP' ? [] : [{ name: CLOTH_LINE, n: r.cloth.warnings }])];
|
|
2252
2735
|
if (read.length === 0) return '';
|
|
2253
2736
|
return `; ${read.reduce((a, x) => a + x.n, 0)} warning(s) (${read.map((x) => x.name).join(', ')}, not a bar)`;
|
|
2254
2737
|
}
|
|
@@ -3513,36 +3996,7 @@ export function sweepLine(
|
|
|
3513
3996
|
// the seam over every animation (issue #493; the line is {@link MOTION_SEAM_LINE}'s)
|
|
3514
3997
|
// ---------------------------------------------------------------------------
|
|
3515
3998
|
|
|
3516
|
-
|
|
3517
|
-
* `SEAM_OVER_MOTION` (issue #493): every declared neighbour pair read in every
|
|
3518
|
-
* animation `motion.json` holds, the idle included, by rig-c's seam reading
|
|
3519
|
-
* (`rigc render --seam`, rig-c 2.60.0) — a **warning, never a bar**. The
|
|
3520
|
-
* owner's ruling (2026-10-18): a seam opening in motion may be intentional, so
|
|
3521
|
-
* the line names the pair, the animation, the frames and the cells, and moves
|
|
3522
|
-
* neither the exit status nor `check: PASS`; the summary counts it apart from
|
|
3523
|
-
* the bars.
|
|
3524
|
-
*
|
|
3525
|
-
* The pairs are the ones the inputs declare and nothing else: each limb's
|
|
3526
|
-
* consecutive segments in `parts.json` (`config.limbs`, the upper and the
|
|
3527
|
-
* segment below each joint) and, under `--requirements`, each `seam`
|
|
3528
|
-
* requirement's part and neighbour. None declared, the line is a SKIP naming
|
|
3529
|
-
* why, never a pass, and `check.json` carries no key for it.
|
|
3530
|
-
*
|
|
3531
|
-
* **The floor** ({@link openingOverFloor}): a frame's gap or ghost is reported
|
|
3532
|
-
* when it holds more cells than its box is long — when it is thicker than one
|
|
3533
|
-
* cell. rigc counts a cell drawn when the renderer paints its centre at half
|
|
3534
|
-
* opacity or more, so a boundary that moves by less than a cell flips the
|
|
3535
|
-
* cells along it in or out: a line of cells one deep, scattered or joined,
|
|
3536
|
-
* holds at most as many cells as its box's longer side. A hole of any area
|
|
3537
|
-
* holds more. The rule types no number; it is read off rigc's own cell and
|
|
3538
|
-
* box, and measured, not chosen: on `examples/wind`'s idle rigc names 43
|
|
3539
|
-
* openings over its six limb pairs (28 and 15 frames of the two elbows, 1 to
|
|
3540
|
-
* 5 cells, boxes up to 17 cells long) and every one is one cell thick; on
|
|
3541
|
-
* rig-c's `gallery/walk` its 13 joint cracks of 1 to 3 cells are too; the
|
|
3542
|
-
* ghost rig-c's own reading names on a skirt swung clear of a leg (1564 cells
|
|
3543
|
-
* in a box 92 long) is far over it.
|
|
3544
|
-
*/
|
|
3545
|
-
export const MOTION_SEAM_LINE = 'SEAM_OVER_MOTION';
|
|
3999
|
+
|
|
3546
4000
|
|
|
3547
4001
|
/** The seam reading's scratch build and renders, under `--out`; removed before the stage returns. */
|
|
3548
4002
|
const MOTION_SEAM_SCRATCH = '_seam_motion';
|
|
@@ -3564,6 +4018,31 @@ export interface MotionSeamPair {
|
|
|
3564
4018
|
declared: string[];
|
|
3565
4019
|
/** Why the pair is not read: a slot `rig.json` does not have. */
|
|
3566
4020
|
unread?: string;
|
|
4021
|
+
/** Issue #686: segment-zero provenance and its immediate named body carrier. */
|
|
4022
|
+
root?: { limb: string; bone: string; parent: string };
|
|
4023
|
+
}
|
|
4024
|
+
|
|
4025
|
+
/** Stock setup-only seam rows: banded > 0, not distance or mesh influence, proves alpha overlap. */
|
|
4026
|
+
export interface MotionRootSetupRow {
|
|
4027
|
+
pair: string;
|
|
4028
|
+
drawn: number;
|
|
4029
|
+
banded: number;
|
|
4030
|
+
status: 'read' | 'skip';
|
|
4031
|
+
}
|
|
4032
|
+
|
|
4033
|
+
/** Eligible, readable setup drawings with no overlap band: not a measured root. */
|
|
4034
|
+
export interface MotionUnmeasuredRoot {
|
|
4035
|
+
limb: string;
|
|
4036
|
+
bone: string;
|
|
4037
|
+
parent: string;
|
|
4038
|
+
part: string;
|
|
4039
|
+
candidates: string[];
|
|
4040
|
+
reason: string;
|
|
4041
|
+
}
|
|
4042
|
+
|
|
4043
|
+
export interface MotionSeamSelection {
|
|
4044
|
+
pairs: MotionSeamPair[];
|
|
4045
|
+
unmeasuredRoots: MotionUnmeasuredRoot[];
|
|
3567
4046
|
}
|
|
3568
4047
|
|
|
3569
4048
|
/** One pair in one animation, as the floor reads rigc's file. */
|
|
@@ -3577,37 +4056,49 @@ export interface MotionSeamRow {
|
|
|
3577
4056
|
banded: number;
|
|
3578
4057
|
/** The frames over the floor, ascending: the warning's frames. */
|
|
3579
4058
|
opens: number[];
|
|
3580
|
-
/** Beside `opens
|
|
4059
|
+
/** Beside `opens`: gapOpen plus UNDER-owned ghost on roots; legacy maximum elsewhere. */
|
|
3581
4060
|
px: number[];
|
|
3582
|
-
/**
|
|
4061
|
+
/** Maximum gated/warned count over the unchanged one-cell floor. */
|
|
3583
4062
|
max_px: number;
|
|
3584
4063
|
/** The frames rigc names open whose every opening is one cell thick: under the floor, not reported. */
|
|
3585
4064
|
under_floor: number[];
|
|
4065
|
+
/** New roots only: the worst above-floor hit, retaining rigc's cell and world box. */
|
|
4066
|
+
worst?: MotionSeamHit & { kind: 'gap' | 'ghost' | 'gapOpen' | 'underGhost' | 'gapOpen+underGhost' };
|
|
4067
|
+
/** Exact stock partitions and the resolved UNDER owner, retained even below the floor. */
|
|
4068
|
+
cells?: MotionRootCells[];
|
|
3586
4069
|
}
|
|
3587
4070
|
|
|
3588
|
-
/**
|
|
4071
|
+
/** Existing pairs warn; new body roots alone can FAIL. Unavailable readings are named SKIP, never measured zero. */
|
|
3589
4072
|
export interface MotionSeamLine {
|
|
3590
|
-
status: 'WARN' | 'CLEAR' | 'SKIP';
|
|
4073
|
+
status: 'WARN' | 'CLEAR' | 'SKIP' | 'FAIL';
|
|
3591
4074
|
reason?: string;
|
|
3592
4075
|
fps: number;
|
|
3593
4076
|
floor: string;
|
|
3594
4077
|
pairs: MotionSeamPair[];
|
|
3595
4078
|
animations: string[];
|
|
3596
|
-
/**
|
|
4079
|
+
/** Existing non-root rows with a frame over the floor: the WARN lines. */
|
|
3597
4080
|
warnings: number;
|
|
3598
4081
|
rows: MotionSeamRow[];
|
|
3599
4082
|
/** Physics-only reference worlds (issue #591); do not participate in warnings or bars. */
|
|
3600
4083
|
worlds?: MotionSeamWorlds;
|
|
4084
|
+
/** Selected body-root pairs and named zero-band roots; existing internal seams remain warnings. */
|
|
4085
|
+
roots?: { status: 'PASS' | 'FAIL' | 'SKIP'; mode: 'gap-open+under-ghost'; ghost_owner: 'resolved-draw-order'; pairs: string[]; failed: number; reason?: string; unmeasured?: MotionUnmeasuredRoot[] };
|
|
3601
4086
|
}
|
|
3602
4087
|
|
|
3603
4088
|
/**
|
|
3604
4089
|
* The neighbour pairs the inputs declare, in their order: each limb's
|
|
3605
4090
|
* consecutive segments (`parts.json`'s limb records, by segment), then each
|
|
3606
|
-
* `seam` requirement's part and neighbour. A pair named twice, in either
|
|
4091
|
+
* `seam` requirement's part and neighbour, then proven roots when rig.json is supplied. A pair named twice, in either
|
|
3607
4092
|
* order, is one pair with both declarations.
|
|
3608
4093
|
*/
|
|
3609
|
-
export function motionSeamPairs(parts: PartsFile, seams: ReadonlyArray<{ name: string; part: string; neighbour: string }
|
|
4094
|
+
export function motionSeamPairs(parts: PartsFile, seams: ReadonlyArray<{ name: string; part: string; neighbour: string }>, rig?: Record<string, unknown>, readSetup?: (candidates: readonly MotionSeamPair[]) => readonly MotionRootSetupRow[]): MotionSeamPair[] {
|
|
4095
|
+
return motionSeamSelection(parts, seams, rig, readSetup).pairs;
|
|
4096
|
+
}
|
|
4097
|
+
|
|
4098
|
+
/** Complete selection: a valid zero setup band is named separately, never a fabricated pair or PASS. */
|
|
4099
|
+
export function motionSeamSelection(parts: PartsFile, seams: ReadonlyArray<{ name: string; part: string; neighbour: string }>, rig?: Record<string, unknown>, readSetup?: (candidates: readonly MotionSeamPair[]) => readonly MotionRootSetupRow[]): MotionSeamSelection {
|
|
3610
4100
|
const out: MotionSeamPair[] = [];
|
|
4101
|
+
const unmeasuredRoots: MotionUnmeasuredRoot[] = [];
|
|
3611
4102
|
const add = (a: string, b: string, declared: string): void => {
|
|
3612
4103
|
const hit = out.find((p) => (p.a === a && p.b === b) || (p.a === b && p.b === a));
|
|
3613
4104
|
if (hit !== undefined) hit.declared.push(declared);
|
|
@@ -3623,6 +4114,142 @@ export function motionSeamPairs(parts: PartsFile, seams: ReadonlyArray<{ name: s
|
|
|
3623
4114
|
}
|
|
3624
4115
|
}
|
|
3625
4116
|
for (const r of seams) add(r.part, r.neighbour, `requirement "${r.name}" (seam)`);
|
|
4117
|
+
const candidates = rig === undefined ? [] : motionRootCandidates(parts, rig);
|
|
4118
|
+
const selected: MotionSeamPair[] = [];
|
|
4119
|
+
if (candidates.length > 0) {
|
|
4120
|
+
const rows = readSetup?.(candidates);
|
|
4121
|
+
const problems: Problem[] = [];
|
|
4122
|
+
const bad = (object: string, detail: string): void => { problems.push({ code: 'CHECK_MOTION_SEAM_ROOT', object, detail }); };
|
|
4123
|
+
if (rows === undefined || rows.length !== candidates.length) {
|
|
4124
|
+
bad('body-root setup reading', 'requires one stock setup-only seam row per eligible candidate; found ' + (rows === undefined ? 'no reader' : rows.length) + ', required ' + candidates.length + '; unavailable is not zero overlap');
|
|
4125
|
+
} else {
|
|
4126
|
+
for (const candidate of candidates) {
|
|
4127
|
+
const matches = rows.filter(row => row.pair === candidate.pair);
|
|
4128
|
+
const row = matches[0];
|
|
4129
|
+
if (matches.length !== 1 || row.drawn !== 1 || (row.banded !== 0 && row.banded !== 1) || row.status !== (row.banded === 1 ? 'read' : 'skip')) {
|
|
4130
|
+
bad(candidate.pair, 'requires one setup frame with both drawings present and banded 0/1 matching status skip/read; the stock reading is missing, duplicate or unreadable');
|
|
4131
|
+
} else if (row.banded > 0) selected.push(candidate);
|
|
4132
|
+
}
|
|
4133
|
+
}
|
|
4134
|
+
// Missing, duplicate or undrawn data must refuse before a zero-band result exists.
|
|
4135
|
+
refuseIfAny(problems);
|
|
4136
|
+
for (const candidate of candidates) {
|
|
4137
|
+
const root = candidate.root;
|
|
4138
|
+
if (root === undefined || selected.some(p => p.root?.limb === root.limb) || unmeasuredRoots.some(p => p.limb === root.limb)) continue;
|
|
4139
|
+
const names = candidates.filter(p => p.root?.limb === root.limb).map(p => p.a);
|
|
4140
|
+
unmeasuredRoots.push({ ...root, part: candidate.b, candidates: names,
|
|
4141
|
+
reason: 'no setup band with ' + names.join('/') + ' — not measured' });
|
|
4142
|
+
}
|
|
4143
|
+
}
|
|
4144
|
+
for (const root of selected) {
|
|
4145
|
+
add(root.a, root.b, root.declared[0]);
|
|
4146
|
+
const pair = out.find(p => (p.a === root.a && p.b === root.b) || (p.a === root.b && p.b === root.a));
|
|
4147
|
+
if (pair !== undefined) pair.root = root.root;
|
|
4148
|
+
}
|
|
4149
|
+
return { pairs: out, unmeasuredRoots };
|
|
4150
|
+
}
|
|
4151
|
+
|
|
4152
|
+
|
|
4153
|
+
/**
|
|
4154
|
+
* Only the immediate named carrier is eligible. Slot binding and source provenance
|
|
4155
|
+
* establish candidates; stock setup alpha overlap selects all matching drawings.
|
|
4156
|
+
* No body provenance means legacy input, not proof of closed body-root seams.
|
|
4157
|
+
*/
|
|
4158
|
+
function motionRootCandidates(parts: PartsFile, rig: Record<string, unknown>): MotionSeamPair[] {
|
|
4159
|
+
const limbs = [...new Set(parts.parts.flatMap(p => p.limb === undefined ? [] : [p.limb.name]))];
|
|
4160
|
+
// Root-free inputs keep the old selector without inspecting irrelevant body bindings.
|
|
4161
|
+
if (limbs.length === 0) return [];
|
|
4162
|
+
const bodies = partsTagged(parts, ['topwear', 'bottomwear']).filter(p => p.limb === undefined);
|
|
4163
|
+
if (bodies.length === 0) return [];
|
|
4164
|
+
const problems: Problem[] = [];
|
|
4165
|
+
const bad = (object: string, detail: string): void => { problems.push({ code: 'CHECK_MOTION_SEAM_ROOT', object, detail }); };
|
|
4166
|
+
const bones = (Array.isArray(rig.bones) ? rig.bones : []).filter(isRecord);
|
|
4167
|
+
const slots = (Array.isArray(rig.slots) ? rig.slots : []).filter(isRecord);
|
|
4168
|
+
const skin = isRecord(rig.skins) && isRecord(rig.skins.default) ? rig.skins.default : {};
|
|
4169
|
+
const binding = (part: PartRecord): Record<string, unknown> | null => {
|
|
4170
|
+
const matches = slots.filter(s => s.name === part.name);
|
|
4171
|
+
const on = skin[part.name];
|
|
4172
|
+
const slot = matches.length === 1 ? matches[0] : null;
|
|
4173
|
+
const attachment = slot !== null && typeof slot.attachment === 'string' && isRecord(on) ? on[slot.attachment] : undefined;
|
|
4174
|
+
if (parts.parts.filter(p => p.name === part.name).length !== 1 || slot === null || typeof slot.bone !== 'string' || !isRecord(attachment)) {
|
|
4175
|
+
bad('part "' + part.name + '"', 'requires one part, one slot of that name and its named setup attachment in the default skin; found ' + matches.length + ' slot(s)');
|
|
4176
|
+
return null;
|
|
4177
|
+
}
|
|
4178
|
+
return slot;
|
|
4179
|
+
};
|
|
4180
|
+
const carriers = bodies.map(part => ({ part, slot: binding(part) }));
|
|
4181
|
+
// Match applyTurn's emitted structure, not a name prefix or a nearby ancestor.
|
|
4182
|
+
// Its leaf/control bones have exactly these fields; no transform tolerance is introduced.
|
|
4183
|
+
const keys = (record: Record<string, unknown>, wanted: readonly string[]): boolean =>
|
|
4184
|
+
Object.keys(record).sort().join(',') === [...wanted].sort().join(',');
|
|
4185
|
+
const identity = (bone: Record<string, unknown>, parent: string): boolean =>
|
|
4186
|
+
keys(bone, ['name', 'parent', 'x', 'y']) && bone.parent === parent && bone.x === 0 && bone.y === 0;
|
|
4187
|
+
const generatedBodyTurn = (part: PartRecord, slot: Record<string, unknown>, parent: string): boolean => {
|
|
4188
|
+
const twin = turnTwin(part.name, parent);
|
|
4189
|
+
if (slot.bone !== twin) return false;
|
|
4190
|
+
const children = bones.filter(bone => bone.name === twin);
|
|
4191
|
+
const controls = bones.filter(bone => bone.name === TURN_BONE);
|
|
4192
|
+
if (children.length !== 1 || !identity(children[0], parent) ||
|
|
4193
|
+
controls.length !== 1 || !identity(controls[0], ROOT_BONE)) return false;
|
|
4194
|
+
const constraints = (Array.isArray(rig.constraints) ? rig.constraints : []).filter(isRecord)
|
|
4195
|
+
.filter(constraint => constraint.name === turnConstraintName(part.name));
|
|
4196
|
+
if (constraints.length !== 1) return false;
|
|
4197
|
+
const constraint = constraints[0];
|
|
4198
|
+
if (!keys(constraint, ['type', 'name', 'bones', 'source', 'localSource', 'additive', 'properties']) ||
|
|
4199
|
+
constraint.type !== 'transform' || constraint.source !== TURN_BONE ||
|
|
4200
|
+
constraint.localSource !== true || constraint.additive !== true || !Array.isArray(constraint.bones) ||
|
|
4201
|
+
constraint.bones.length === 0 || constraint.bones.some(name => typeof name !== 'string') ||
|
|
4202
|
+
new Set(constraint.bones).size !== constraint.bones.length || !constraint.bones.includes(twin)) return false;
|
|
4203
|
+
// Every target belongs to this part's generated row, even on a multi-bone body mesh.
|
|
4204
|
+
if (!constraint.bones.every(name => {
|
|
4205
|
+
const targets = bones.filter(bone => bone.name === name);
|
|
4206
|
+
if (targets.length !== 1 || typeof targets[0].parent !== 'string') return false;
|
|
4207
|
+
const carrier = targets[0].parent;
|
|
4208
|
+
return targets[0].name === turnTwin(part.name, carrier) && identity(targets[0], carrier) &&
|
|
4209
|
+
bones.filter(bone => bone.name === carrier).length === 1;
|
|
4210
|
+
})) return false;
|
|
4211
|
+
const properties = constraint.properties;
|
|
4212
|
+
if (!isRecord(properties) || !keys(properties, ['x']) || !isRecord(properties.x) ||
|
|
4213
|
+
!keys(properties.x, ['to']) || !isRecord(properties.x.to) || !keys(properties.x.to, ['x']) ||
|
|
4214
|
+
!isRecord(properties.x.to.x) || !keys(properties.x.to.x, ['scale'])) return false;
|
|
4215
|
+
const fraction = properties.x.to.x.scale;
|
|
4216
|
+
// applyTurn emits no row/twin at fraction0; its nonzero fraction is finite, not guessed here.
|
|
4217
|
+
return typeof fraction === 'number' && Number.isFinite(fraction) && fraction !== 0;
|
|
4218
|
+
};
|
|
4219
|
+
const out: MotionSeamPair[] = [];
|
|
4220
|
+
for (const limb of limbs) {
|
|
4221
|
+
const roots = parts.parts.filter(p => p.limb?.name === limb && p.limb.segment === 0);
|
|
4222
|
+
if (roots.length !== 1) {
|
|
4223
|
+
bad('config.limbs.' + limb, 'has ' + roots.length + ' segment-zero part(s); exactly one is required to identify its body-root seam');
|
|
4224
|
+
continue;
|
|
4225
|
+
}
|
|
4226
|
+
const root = roots[0];
|
|
4227
|
+
const l = root.limb as LimbRecord;
|
|
4228
|
+
const object = 'root part "' + root.name + '" (config.limbs.' + limb + ', bone "' + l.bone + '")';
|
|
4229
|
+
const named = bones.filter(b => b.name === l.bone);
|
|
4230
|
+
if (named.length !== 1 || typeof named[0].parent !== 'string' || bones.filter(b => b.name === named[0].parent).length !== 1) {
|
|
4231
|
+
bad(object, 'requires one declared bone and its one named immediate parent in rig.json; found ' + named.length + ' bone(s), parent ' + JSON.stringify(named[0]?.parent));
|
|
4232
|
+
continue;
|
|
4233
|
+
}
|
|
4234
|
+
const parent = named[0].parent;
|
|
4235
|
+
const slot = binding(root);
|
|
4236
|
+
if (slot === null) continue;
|
|
4237
|
+
const twin = turnTwin(root.name, l.bone);
|
|
4238
|
+
const twinBones = bones.filter(b => b.name === twin);
|
|
4239
|
+
if (slot.bone !== l.bone && !(slot.bone === twin && twinBones.length === 1 && twinBones[0].parent === l.bone)) {
|
|
4240
|
+
bad(object, 'slot binds "' + String(slot.bone) + '"; the declared bone "' + l.bone + '" or its named turn child is required');
|
|
4241
|
+
continue;
|
|
4242
|
+
}
|
|
4243
|
+
const eligible = carriers.filter(c => c.slot !== null && (c.slot.bone === parent || generatedBodyTurn(c.part, c.slot, parent)));
|
|
4244
|
+
if (eligible.length === 0) {
|
|
4245
|
+
bad(object, 'requires a topwear/bottomwear body drawing whose slot binds its immediate parent "' + parent + '" directly or through its verified generated turn child; found none; no nearest, name or mesh-influence fallback');
|
|
4246
|
+
continue;
|
|
4247
|
+
}
|
|
4248
|
+
for (const { part: body } of eligible) out.push({ pair: body.name + '|' + root.name, a: body.name, b: root.name,
|
|
4249
|
+
declared: ['config.limbs.' + limb + ' segment 0, body carrier "' + parent + '" from ' + body.from],
|
|
4250
|
+
root: { limb, bone: l.bone, parent } });
|
|
4251
|
+
}
|
|
4252
|
+
refuseIfAny(problems);
|
|
3626
4253
|
return out;
|
|
3627
4254
|
}
|
|
3628
4255
|
|
|
@@ -3655,13 +4282,67 @@ export interface MotionSeamPlant {
|
|
|
3655
4282
|
}
|
|
3656
4283
|
|
|
3657
4284
|
|
|
3658
|
-
/** One raw opening
|
|
4285
|
+
/** One raw opening in rigc cells; actual raw frame time is read separately for coverage. */
|
|
3659
4286
|
export interface MotionSeamHit {
|
|
3660
4287
|
index: number;
|
|
3661
4288
|
px: number;
|
|
3662
4289
|
cell: number;
|
|
3663
4290
|
box: [number, number, number, number];
|
|
3664
4291
|
}
|
|
4292
|
+
|
|
4293
|
+
/** Per-frame body-root metric, using only stock partition counts. */
|
|
4294
|
+
export interface MotionRootCells {
|
|
4295
|
+
index: number;
|
|
4296
|
+
gap: number;
|
|
4297
|
+
gapOpen: number;
|
|
4298
|
+
gapCovered: number;
|
|
4299
|
+
ghostA: number;
|
|
4300
|
+
ghostB: number;
|
|
4301
|
+
under: 'a' | 'b' | null;
|
|
4302
|
+
underGhost: number;
|
|
4303
|
+
overGhost: number;
|
|
4304
|
+
counted: number;
|
|
4305
|
+
/** Original raw-kind box floor, never the narrowed partition box. */
|
|
4306
|
+
floor?: number;
|
|
4307
|
+
floor_box?: MotionSeamHit['box'];
|
|
4308
|
+
}
|
|
4309
|
+
export type RootDrawOrderReader = (pair: MotionSeamPair, animation: string, index: number, time: number | undefined) => 'a' | 'b';
|
|
4310
|
+
|
|
4311
|
+
/** Geometry attachments are the stock poser's resolved draw order on that frame, back to front. */
|
|
4312
|
+
export function motionRootDrawOrderReader(rendered: string): RootDrawOrderReader {
|
|
4313
|
+
const animations = new Map<string, Map<number, { time: number; slots: string[] }>>();
|
|
4314
|
+
return (pair, animation, index, time) => {
|
|
4315
|
+
const fail = (detail: string): never => {
|
|
4316
|
+
refuseIfAny([{ code: 'FRAMES_SIDECAR', object: pair.pair + ' in ' + animation + ' frame ' + index,
|
|
4317
|
+
detail: 'body-root resolved draw order unavailable: ' + detail }]);
|
|
4318
|
+
throw new Error('unreachable');
|
|
4319
|
+
};
|
|
4320
|
+
let frames = animations.get(animation);
|
|
4321
|
+
if (frames === undefined) {
|
|
4322
|
+
const problems: Problem[] = [];
|
|
4323
|
+
const sidecar = readJson(join(rendered, 'frames.json'), problems);
|
|
4324
|
+
const set = Array.isArray(sidecar?.sets) ? sidecar.sets.find(v => isRecord(v) && v.animation === animation) : undefined;
|
|
4325
|
+
if (!isRecord(set) || typeof set.dir !== 'string' || isAbsolute(set.dir) || set.dir.split(/[\\/]/).includes('..')) return fail('local animation directory required');
|
|
4326
|
+
const geometry = readJson(join(rendered, set.dir, GEOMETRY_FILE), problems);
|
|
4327
|
+
refuseIfAny(problems);
|
|
4328
|
+
if (geometry?.animation !== animation || !Array.isArray(geometry.frames)) return fail('same-animation geometry required');
|
|
4329
|
+
frames = new Map();
|
|
4330
|
+
for (const value of geometry.frames) {
|
|
4331
|
+
if (!isRecord(value) || !Number.isInteger(value.index) || typeof value.time !== 'number' || !Number.isFinite(value.time) ||
|
|
4332
|
+
!Array.isArray(value.attachments) || value.attachments.some(v => !isRecord(v) || typeof v.slot !== 'string')) return fail('finite frame identity and attachment roster required');
|
|
4333
|
+
const slots = value.attachments.map(v => String((v as Record<string, unknown>).slot));
|
|
4334
|
+
if (new Set(slots).size !== slots.length || frames.has(Number(value.index))) return fail('duplicate frame or slot');
|
|
4335
|
+
frames.set(Number(value.index), { time: value.time, slots });
|
|
4336
|
+
}
|
|
4337
|
+
animations.set(animation, frames);
|
|
4338
|
+
}
|
|
4339
|
+
const frame = frames.get(index);
|
|
4340
|
+
if (frame === undefined || frame.time !== time) return fail('raw and geometry frame time differ');
|
|
4341
|
+
const a = frame.slots.indexOf(pair.a), b = frame.slots.indexOf(pair.b);
|
|
4342
|
+
if (a < 0 || b < 0 || a === b) return fail('both named pair slots required exactly once');
|
|
4343
|
+
return a < b ? 'a' : 'b';
|
|
4344
|
+
};
|
|
4345
|
+
}
|
|
3665
4346
|
export interface MotionSeamWorldKind {
|
|
3666
4347
|
max_px: number;
|
|
3667
4348
|
worst: MotionSeamHit | null;
|
|
@@ -3707,7 +4388,7 @@ export function motionSeamWorlds(physics: boolean, answersWind: boolean, read: (
|
|
|
3707
4388
|
/** The same validated sidecars as the warning, retaining the raw gap and ghost cells. */
|
|
3708
4389
|
export function readMotionSeamWorldRows(dir: string, animations: readonly string[], fps: number, pairs: readonly MotionSeamPair[]): MotionSeamWorldRow[] {
|
|
3709
4390
|
const rows: MotionSeamWorldRow[] = [];
|
|
3710
|
-
readMotionSeams(dir, animations, fps, pairs, {}, rows);
|
|
4391
|
+
readMotionSeams(dir, animations, fps, pairs.map(({ root: _root, ...pair }) => pair), {}, rows);
|
|
3711
4392
|
return rows;
|
|
3712
4393
|
}
|
|
3713
4394
|
|
|
@@ -3765,7 +4446,33 @@ type SeamHitRead = MotionSeamHit;
|
|
|
3765
4446
|
* file that is missing, a file that is not the animation's or not at the rate
|
|
3766
4447
|
* asked, a pair out of the flag's order, and a field of the wrong shape.
|
|
3767
4448
|
*/
|
|
3768
|
-
export function readMotionSeams(dir: string, animations: readonly string[], fps: number, pairs: readonly MotionSeamPair[], plant: MotionSeamPlant = {}, worldRows?: MotionSeamWorldRow[]): MotionSeamRow[] {
|
|
4449
|
+
export function readMotionSeams(dir: string, animations: readonly string[], fps: number, pairs: readonly MotionSeamPair[], plant: MotionSeamPlant = {}, worldRows?: MotionSeamWorldRow[], drawOrderReader?: RootDrawOrderReader): MotionSeamRow[] {
|
|
4450
|
+
return readSeamRows(dir, animations, fps, pairs, plant, worldRows, false, drawOrderReader);
|
|
4451
|
+
}
|
|
4452
|
+
|
|
4453
|
+
/** The same stock seam reader, restricted to one canonical setup-only frame. */
|
|
4454
|
+
export function readMotionRootSetup(dir: string, fps: number, pairs: readonly MotionSeamPair[]): MotionRootSetupRow[] {
|
|
4455
|
+
const problems: Problem[] = [];
|
|
4456
|
+
const sidecar = readJson(join(dir, 'frames.json'), problems);
|
|
4457
|
+
const sets = sidecar !== null && Array.isArray(sidecar.sets) ? sidecar.sets.filter(isRecord) : [];
|
|
4458
|
+
const set = sets[0];
|
|
4459
|
+
if (sidecar?.spec !== 'rigc-frames/1' || sets.length !== 1 || set.animation !== null || set.fps !== fps ||
|
|
4460
|
+
set.sampled !== 1 || set.written !== 1 || set.stride !== 1 || set.duration !== 0 || typeof set.dir !== 'string' ||
|
|
4461
|
+
isAbsolute(set.dir) || set.dir.split(/[\\/]/).includes('..')) {
|
|
4462
|
+
problems.push({ code: 'FRAMES_SIDECAR', object: join(dir, 'frames.json'),
|
|
4463
|
+
detail: 'requires exactly one stock setup-only set: animation null, sampled/written/stride 1, duration 0, the requested fps and a local directory; unavailable is not zero overlap' });
|
|
4464
|
+
}
|
|
4465
|
+
refuseIfAny(problems);
|
|
4466
|
+
const rows = readSeamRows(dir, ['setup'], fps, pairs, {}, undefined, true);
|
|
4467
|
+
for (const row of rows) if (row.drawn !== 1 || (row.banded !== 0 && row.banded !== 1) || row.status !== (row.banded === 1 ? 'read' : 'skip')) {
|
|
4468
|
+
problems.push({ code: 'FRAMES_SIDECAR', object: row.pair,
|
|
4469
|
+
detail: 'setup seam requires both drawings on its one frame, banded 0/1 and matching skip/read; an absent drawing is not zero overlap' });
|
|
4470
|
+
}
|
|
4471
|
+
refuseIfAny(problems);
|
|
4472
|
+
return rows.map(({ pair, drawn, banded, status }) => ({ pair, drawn, banded, status }));
|
|
4473
|
+
}
|
|
4474
|
+
|
|
4475
|
+
function readSeamRows(dir: string, animations: readonly string[], fps: number, pairs: readonly MotionSeamPair[], plant: MotionSeamPlant = {}, worldRows?: MotionSeamWorldRow[], setup = false, drawOrderReader?: RootDrawOrderReader): MotionSeamRow[] {
|
|
3769
4476
|
const problems: Problem[] = [];
|
|
3770
4477
|
const bad = (object: string, detail: string): void => {
|
|
3771
4478
|
problems.push({ code: 'FRAMES_SIDECAR', object, detail });
|
|
@@ -3777,7 +4484,8 @@ export function readMotionSeams(dir: string, animations: readonly string[], fps:
|
|
|
3777
4484
|
const hitOf = (h: unknown): SeamHitRead | null =>
|
|
3778
4485
|
isRecord(h) && typeof h.index === 'number' && typeof h.px === 'number' && typeof h.cell === 'number' && h.cell > 0 && nums(h.box) && h.box.length === 4 ? { index: h.index, px: h.px, cell: h.cell, box: [h.box[0], h.box[1], h.box[2], h.box[3]] } : null;
|
|
3779
4486
|
for (const animation of animations) {
|
|
3780
|
-
const
|
|
4487
|
+
const rawAnimation = setup ? null : animation;
|
|
4488
|
+
const set = sets.find((x) => x.animation === rawAnimation);
|
|
3781
4489
|
if (set === undefined || typeof set.dir !== 'string') {
|
|
3782
4490
|
bad(join(dir, 'frames.json'), `names no frame set for animation ${JSON.stringify(animation)}; \`rigc render --seam\` over the build writes one per animation`);
|
|
3783
4491
|
continue;
|
|
@@ -3786,7 +4494,7 @@ export function readMotionSeams(dir: string, animations: readonly string[], fps:
|
|
|
3786
4494
|
const file = readJson(path, problems);
|
|
3787
4495
|
if (file === null) continue;
|
|
3788
4496
|
if (file.spec !== SEAM_READING_SPEC) bad(path, `spec is ${JSON.stringify(file.spec)}; "${SEAM_READING_SPEC}" is required`);
|
|
3789
|
-
if (file.animation !==
|
|
4497
|
+
if (file.animation !== rawAnimation) bad(path, `animation is ${JSON.stringify(file.animation)}; ${JSON.stringify(rawAnimation)} is required`);
|
|
3790
4498
|
if (file.fps !== fps) bad(path, `fps is ${JSON.stringify(file.fps)}; ${fps}, the rate asked for, is required`);
|
|
3791
4499
|
const read = Array.isArray(file.pairs) ? file.pairs : [];
|
|
3792
4500
|
if (read.length !== pairs.length) bad(path, `holds ${read.length} pair(s); the ${pairs.length} asked for, in the flag's order, are required`);
|
|
@@ -3802,6 +4510,9 @@ export function readMotionSeams(dir: string, animations: readonly string[], fps:
|
|
|
3802
4510
|
return;
|
|
3803
4511
|
}
|
|
3804
4512
|
const over = new Map<number, number>();
|
|
4513
|
+
let rootWorst: MotionSeamRow['worst'];
|
|
4514
|
+
const rootFrames = new Set<number>();
|
|
4515
|
+
const cells: MotionRootCells[] = [];
|
|
3805
4516
|
const kinds: Record<'gap' | 'ghost', MotionSeamWorldKind> = { gap: { max_px: 0, worst: null }, ghost: { max_px: 0, worst: null } };
|
|
3806
4517
|
for (const kind of ['gap', 'ghost'] as const) {
|
|
3807
4518
|
const k = p[kind];
|
|
@@ -3811,9 +4522,73 @@ export function readMotionSeams(dir: string, animations: readonly string[], fps:
|
|
|
3811
4522
|
return;
|
|
3812
4523
|
}
|
|
3813
4524
|
const hits = frames as SeamHitRead[];
|
|
4525
|
+
|
|
3814
4526
|
const worst = hits.reduce<MotionSeamHit | null>((best, h) => best === null || h.px > best.px || (h.px === best.px && h.index < best.index) ? h : best, null);
|
|
3815
4527
|
kinds[kind] = { max_px: worst?.px ?? 0, worst };
|
|
3816
|
-
|
|
4528
|
+
// Existing internal pairs retain their original maximum-kind warning and floor.
|
|
4529
|
+
for (const h of hits) if (want.root === undefined && (plant.noFloor === true || openingOverFloor(h))) {
|
|
4530
|
+
over.set(h.index, Math.max(over.get(h.index) ?? 0, h.px));
|
|
4531
|
+
}
|
|
4532
|
+
}
|
|
4533
|
+
if (want.root !== undefined && !setup) {
|
|
4534
|
+
const partitions = new Map<string, SeamHitRead[]>();
|
|
4535
|
+
for (const name of ['gap', 'ghost', 'gapOpen', 'gapCovered', 'ghostA', 'ghostB']) {
|
|
4536
|
+
const value = p[name];
|
|
4537
|
+
const hits = isRecord(value) && Array.isArray(value.frames) ? value.frames.map(hitOf) : null;
|
|
4538
|
+
if (hits === null || hits.some(h => h === null)) { bad(at + ' ' + name, 'requires stock per-frame cell partitions from rig-c >=2.69.0'); return; }
|
|
4539
|
+
if (new Set(hits.map(h => h?.index)).size !== hits.length || hits.some(h => h === null || !Number.isSafeInteger(h.index) || h.index < 0 || !Number.isSafeInteger(h.px) || h.px <= 0 || !Number.isFinite(h.cell) || !h.box.every(Number.isFinite) || h.box[2] <= h.box[0] || h.box[3] <= h.box[1])) {
|
|
4540
|
+
bad(at + ' ' + name, 'requires unique nonnegative frame indices, positive whole counts and finite boxes'); return;
|
|
4541
|
+
}
|
|
4542
|
+
if (!isRecord(value) || !Array.isArray(value.frames) || value.frames.some(v => !isRecord(v) || typeof v.time !== 'number' || !Number.isFinite(v.time) || v.time < 0)) {
|
|
4543
|
+
bad(at + ' ' + name, 'requires the actual finite stock frame time'); return;
|
|
4544
|
+
}
|
|
4545
|
+
partitions.set(name, hits as SeamHitRead[]);
|
|
4546
|
+
}
|
|
4547
|
+
const rawHits = (name: string): SeamHitRead[] => {
|
|
4548
|
+
const value = p[name];
|
|
4549
|
+
return isRecord(value) && Array.isArray(value.frames) ? value.frames.map(hitOf).filter((h): h is SeamHitRead => h !== null) : [];
|
|
4550
|
+
};
|
|
4551
|
+
for (const hits of partitions.values()) for (const h of hits) rootFrames.add(h.index);
|
|
4552
|
+
for (const index of [...rootFrames].sort((a, b) => a - b)) {
|
|
4553
|
+
const hit = (name: string): SeamHitRead | undefined => partitions.get(name)?.find(h => h.index === index);
|
|
4554
|
+
const count = (name: string): number => hit(name)?.px ?? 0;
|
|
4555
|
+
if (count('gapOpen') + count('gapCovered') !== count('gap') || count('ghostA') + count('ghostB') !== count('ghost')) {
|
|
4556
|
+
bad(at + ' frame ' + index, 'gapOpen + gapCovered must equal gap and ghostA + ghostB must equal ghost'); continue;
|
|
4557
|
+
}
|
|
4558
|
+
const raw = [...rawHits('gap'), ...rawHits('ghost')].find(h => h.index === index);
|
|
4559
|
+
const source = ['gap', 'ghost'].flatMap(name => {
|
|
4560
|
+
const value = p[name]; return isRecord(value) && Array.isArray(value.frames) ? value.frames.filter(v => isRecord(v) && v.index === index) : [];
|
|
4561
|
+
})[0];
|
|
4562
|
+
const time = isRecord(source) && typeof source.time === 'number' ? source.time : undefined;
|
|
4563
|
+
const coherent = [...partitions].every(([name, hits]) => {
|
|
4564
|
+
const h = hits.find(h => h.index === index);
|
|
4565
|
+
if (h === undefined) return true;
|
|
4566
|
+
const value = p[name];
|
|
4567
|
+
const record = isRecord(value) && Array.isArray(value.frames) ? value.frames.find(v => isRecord(v) && v.index === index) : undefined;
|
|
4568
|
+
return isRecord(record) && record.time === time && h.cell === raw?.cell;
|
|
4569
|
+
});
|
|
4570
|
+
if (!coherent) { bad(at + ' frame ' + index, 'all raw and partition hits must share the actual frame time and stock cell size'); continue; }
|
|
4571
|
+
|
|
4572
|
+
if (count('ghost') > 0 && drawOrderReader === undefined) { bad(at + ' frame ' + index, 'resolved per-frame draw-order reader required for ghost ownership'); continue; }
|
|
4573
|
+
const under = count('ghost') > 0 ? drawOrderReader?.(want, animation, index, time) ?? null : null;
|
|
4574
|
+
const underHit = under === null ? undefined : hit(under === 'a' ? 'ghostA' : 'ghostB');
|
|
4575
|
+
// Visibility changes the count, not the existing raw kind's floor.
|
|
4576
|
+
// With both kinds contributing, their original raw boxes are united.
|
|
4577
|
+
const counted = count('gapOpen') + (underHit?.px ?? 0);
|
|
4578
|
+
const bounds = [count('gapOpen') > 0 ? hit('gap') : undefined, underHit === undefined ? undefined : hit('ghost')].filter((h): h is SeamHitRead => h !== undefined);
|
|
4579
|
+
const cell = raw?.cell ?? 0;
|
|
4580
|
+
const box: MotionSeamHit['box'] | undefined = bounds.length === 0 ? undefined : [Math.min(...bounds.map(h => h.box[0])), Math.min(...bounds.map(h => h.box[1])), Math.max(...bounds.map(h => h.box[2])), Math.max(...bounds.map(h => h.box[3]))];
|
|
4581
|
+
const floor = box === undefined ? undefined : Math.round(Math.max(box[2] - box[0], box[3] - box[1]) / cell);
|
|
4582
|
+
cells.push({ index, gap: count('gap'), gapOpen: count('gapOpen'), gapCovered: count('gapCovered'), ghostA: count('ghostA'), ghostB: count('ghostB'),
|
|
4583
|
+
under, underGhost: underHit?.px ?? 0, overGhost: count('ghost') - (underHit?.px ?? 0), counted,
|
|
4584
|
+
...(box === undefined ? {} : { floor, floor_box: box }) });
|
|
4585
|
+
if (box === undefined || raw === undefined) continue;
|
|
4586
|
+
const h = { index, px: counted, cell, box };
|
|
4587
|
+
if (plant.noFloor === true || openingOverFloor(h)) {
|
|
4588
|
+
over.set(index, counted);
|
|
4589
|
+
if (rootWorst === undefined || counted > rootWorst.px || (counted === rootWorst.px && index < rootWorst.index)) rootWorst = { ...h, kind: underHit === undefined ? 'gapOpen' : hit('gapOpen') === undefined ? 'underGhost' : 'gapOpen+underGhost' };
|
|
4590
|
+
}
|
|
4591
|
+
}
|
|
3817
4592
|
}
|
|
3818
4593
|
worldRows?.push({ pair: want.pair, animation, status: p.status, drawn: p.drawn, banded: p.banded, gap: kinds.gap, ghost: kinds.ghost });
|
|
3819
4594
|
const opens = [...over.keys()].sort((x, y) => x - y);
|
|
@@ -3826,7 +4601,9 @@ export function readMotionSeams(dir: string, animations: readonly string[], fps:
|
|
|
3826
4601
|
opens,
|
|
3827
4602
|
px: opens.map((f) => over.get(f) ?? 0),
|
|
3828
4603
|
max_px: opens.reduce((m, f) => Math.max(m, over.get(f) ?? 0), 0),
|
|
3829
|
-
under_floor: p.opens.filter((f) => !over.has(f)),
|
|
4604
|
+
under_floor: (want.root === undefined ? p.opens : [...rootFrames].filter(f => cells.some(c => c.index === f && c.counted > 0))).filter((f) => !over.has(f)),
|
|
4605
|
+
...(rootWorst === undefined ? {} : { worst: rootWorst }),
|
|
4606
|
+
...(want.root === undefined ? {} : { cells }),
|
|
3830
4607
|
});
|
|
3831
4608
|
});
|
|
3832
4609
|
}
|
|
@@ -3834,19 +4611,43 @@ export function readMotionSeams(dir: string, animations: readonly string[], fps:
|
|
|
3834
4611
|
return rows;
|
|
3835
4612
|
}
|
|
3836
4613
|
|
|
3837
|
-
/**
|
|
3838
|
-
export function motionSeamLine(pairs: MotionSeamPair[], animations: string[], fps: number, rows: MotionSeamRow[], reason?: string): MotionSeamLine {
|
|
3839
|
-
const
|
|
4614
|
+
/** Only active proven roots gate gapOpen plus UNDER-owned ghost; existing warnings/floor are unchanged. */
|
|
4615
|
+
export function motionSeamLine(pairs: MotionSeamPair[], animations: string[], fps: number, rows: MotionSeamRow[], reason?: string, problems: Problem[] = [], unmeasuredRoots: readonly MotionUnmeasuredRoot[] = []): MotionSeamLine {
|
|
4616
|
+
const roots = pairs.filter(p => p.root !== undefined);
|
|
4617
|
+
const rootNames = new Set(roots.map(p => p.pair));
|
|
4618
|
+
const warnings = rows.filter((r) => !rootNames.has(r.pair) && r.opens.length > 0).length;
|
|
4619
|
+
const failed = rows.filter(r => rootNames.has(r.pair) && r.status === 'read' && r.banded > 0 && r.opens.length > 0);
|
|
4620
|
+
for (const row of failed) {
|
|
4621
|
+
const h = row.worst;
|
|
4622
|
+
problems.push({ code: 'CHECK_SEAM_OVER_MOTION', object: 'body-root seam "' + row.pair + '" in "' + row.animation + '"',
|
|
4623
|
+
detail: h === undefined
|
|
4624
|
+
? 'opens on frames ' + frameRuns(row.opens) + ', max ' + row.max_px + ' cells; no above-floor root hit metadata was returned'
|
|
4625
|
+
: h.kind + ' at frame ' + h.index + ' (t = ' + h.index / fps + 's): ' + h.px + ' cells, cell ' + h.cell + ', world box [' + h.box.join(', ') + ']; at most ' + Math.round(Math.max(h.box[2] - h.box[0], h.box[3] - h.box[1]) / h.cell) + ' cells, the unchanged one-cell floor, is required' });
|
|
4626
|
+
}
|
|
4627
|
+
const missing = roots.flatMap(p => animations.length === 0 ? ['"' + p.pair + '": no animation'] : animations.flatMap(a => {
|
|
4628
|
+
const row = rows.find(r => r.pair === p.pair && r.animation === a);
|
|
4629
|
+
return row?.status === 'read' && row.banded > 0 ? [] : ['"' + p.pair + '" in "' + a + '": ' + (p.unread ?? (row === undefined ? 'no returned reading' : 'no band on any frame'))];
|
|
4630
|
+
}));
|
|
4631
|
+
const unmeasured = unmeasuredRoots.map(root => ({ ...root, candidates: [...root.candidates] }));
|
|
4632
|
+
const rootReasons = [...missing, ...unmeasured.map(root => 'root pair for ' + root.limb + ': ' + root.reason)];
|
|
4633
|
+
const rootGate: MotionSeamLine['roots'] = roots.length === 0 && unmeasured.length === 0 ? undefined : {
|
|
4634
|
+
status: failed.length > 0 ? 'FAIL' : rootReasons.length > 0 || reason !== undefined ? 'SKIP' : 'PASS',
|
|
4635
|
+
mode: 'gap-open+under-ghost', ghost_owner: 'resolved-draw-order',
|
|
4636
|
+
pairs: roots.map(p => p.pair), failed: failed.length,
|
|
4637
|
+
...(rootReasons.length === 0 && reason === undefined ? {} : { reason: unmeasured.length === 0 ? (reason ?? missing.join('; ')) : [reason, ...rootReasons].filter(r => r !== undefined).join('; ') }),
|
|
4638
|
+
...(unmeasured.length === 0 ? {} : { unmeasured }),
|
|
4639
|
+
};
|
|
3840
4640
|
const read = rows.some((r) => r.status === 'read');
|
|
3841
4641
|
const skipWhy =
|
|
3842
4642
|
reason ??
|
|
4643
|
+
(pairs.length === 0 && unmeasured.length > 0 ? rootGate?.reason : undefined) ??
|
|
3843
4644
|
(read
|
|
3844
4645
|
? undefined
|
|
3845
4646
|
: pairs.every((p) => p.unread !== undefined)
|
|
3846
4647
|
? `no declared pair is read: ${pairs.map((p) => `"${p.pair}" ${String(p.unread)}`).join('; ')}`
|
|
3847
4648
|
: `rigc read no band on any frame of any declared pair in any animation — nothing measured, which is not a seam that held`);
|
|
3848
4649
|
return {
|
|
3849
|
-
status: skipWhy !== undefined ? 'SKIP' : warnings > 0 ? 'WARN' : 'CLEAR',
|
|
4650
|
+
status: rootGate?.status === 'FAIL' ? 'FAIL' : skipWhy !== undefined ? 'SKIP' : warnings > 0 ? 'WARN' : 'CLEAR',
|
|
3850
4651
|
...(skipWhy === undefined ? {} : { reason: skipWhy }),
|
|
3851
4652
|
fps,
|
|
3852
4653
|
floor: MOTION_SEAM_FLOOR,
|
|
@@ -3854,6 +4655,7 @@ export function motionSeamLine(pairs: MotionSeamPair[], animations: string[], fp
|
|
|
3854
4655
|
animations,
|
|
3855
4656
|
warnings,
|
|
3856
4657
|
rows,
|
|
4658
|
+
...(rootGate === undefined ? {} : { roots: rootGate }),
|
|
3857
4659
|
};
|
|
3858
4660
|
}
|
|
3859
4661
|
|
|
@@ -4192,7 +4994,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
4192
4994
|
const keptDir = join(out, STILL_DIR);
|
|
4193
4995
|
const foldDir = join(out, FOLD_SCRATCH);
|
|
4194
4996
|
const seamMotionDir = join(out, MOTION_SEAM_SCRATCH);
|
|
4195
|
-
for (const d of [buildDir, idleDir, stillDir, isoDir, loopDir, seamDir, keptDir, foldDir, seamMotionDir]) rmSync(d, { recursive: true, force: true });
|
|
4997
|
+
for (const d of [buildDir, idleDir, stillDir, isoDir, loopDir, seamDir, keptDir, join(out, 'setup_still_auto'), foldDir, seamMotionDir]) rmSync(d, { recursive: true, force: true });
|
|
4196
4998
|
const written: string[] = [];
|
|
4197
4999
|
const write = (name: string, data: string): void => {
|
|
4198
5000
|
writeFileSync(join(out, name), data);
|
|
@@ -4534,13 +5336,50 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
4534
5336
|
}
|
|
4535
5337
|
}
|
|
4536
5338
|
|
|
4537
|
-
// 3e.
|
|
4538
|
-
//
|
|
5339
|
+
// 3e. Existing neighbour pairs warn (issue #493); proven body-root tears alone gate (issue #686).
|
|
5340
|
+
// Read the build as played at the idle's rate; unavailable data is named SKIP.
|
|
4539
5341
|
let motionSeam: MotionSeamLine;
|
|
5342
|
+
const motionRootProblems: Problem[] = [];
|
|
4540
5343
|
{
|
|
4541
5344
|
const fps = IDLE_FPS;
|
|
4542
5345
|
const seamReqs = reqFile === null || seams === null ? [] : reqFile.requirements.flatMap((r) => (r.kind === 'seam' && seams?.has(r.name) === true ? [{ name: r.name, part: r.part, neighbour: r.neighbour }] : []));
|
|
4543
|
-
const
|
|
5346
|
+
const selection: MotionSeamSelection = inp.parts === null ? { pairs: [], unmeasuredRoots: [] } : motionSeamSelection(inp.parts, seamReqs, inp.rig, candidates => {
|
|
5347
|
+
// The stock reader's band is setup alpha overlap, not an inferred distance.
|
|
5348
|
+
// A static motion copy changes only animations; the accepted candidate and
|
|
5349
|
+
// authored motion remain intact. Root-free inputs never enter this path.
|
|
5350
|
+
const setupDir = join(out, '_seam_root_setup');
|
|
5351
|
+
rmSync(setupDir, { recursive: true, force: true });
|
|
5352
|
+
mkdirSync(setupDir, { recursive: true });
|
|
5353
|
+
try {
|
|
5354
|
+
let candidate = buildDir;
|
|
5355
|
+
if (isRecord(inp.motion.animations) && Object.keys(inp.motion.animations).length > 0) {
|
|
5356
|
+
const motion = join(setupDir, 'motion.json');
|
|
5357
|
+
writeFileSync(motion, JSON.stringify({ ...inp.motion, animations: {} }));
|
|
5358
|
+
candidate = join(setupDir, 'build');
|
|
5359
|
+
const compiled = rigc(['build', '--rig', inp.rigPath, '--motion', motion, '--out', candidate, ...packedBuildArgs(mode)]);
|
|
5360
|
+
if (compiled.status !== 0) refuseIfAny(rigcFailed('build (body-root setup observation)', compiled, buildGateLines(compiled.out)));
|
|
5361
|
+
const problems: Problem[] = [];
|
|
5362
|
+
const original = readJson(join(buildDir, 'skeleton.json'), problems);
|
|
5363
|
+
const setup = readJson(join(candidate, 'skeleton.json'), problems);
|
|
5364
|
+
const changed = ['bones', 'slots', 'skins', 'ik', 'transform', 'path', 'physics'].filter(key =>
|
|
5365
|
+
JSON.stringify(original?.[key]) !== JSON.stringify(setup?.[key]));
|
|
5366
|
+
const pages = parsePackLines(compiled.out.split('\n')).map(page => page.page);
|
|
5367
|
+
if (original === null || setup === null || !isRecord(setup.animations) || Object.keys(setup.animations).length > 0 || changed.length > 0 ||
|
|
5368
|
+
JSON.stringify(pages) !== JSON.stringify(pack.map(page => page.page)) ||
|
|
5369
|
+
pages.some(page => !existsSync(join(candidate, page)) || !readFileSync(join(buildDir, page)).equals(readFileSync(join(candidate, page))))) {
|
|
5370
|
+
problems.push({ code: 'CHECK_MOTION_SEAM_ROOT', object: 'stock setup observation',
|
|
5371
|
+
detail: 'requires unchanged default bones/slots/skins/constraints and atlas PNG bytes, with no animation; differing default fields: ' + changed.join(', ') });
|
|
5372
|
+
}
|
|
5373
|
+
refuseIfAny(problems);
|
|
5374
|
+
}
|
|
5375
|
+
const renderDir = join(setupDir, 'render');
|
|
5376
|
+
const list = candidates.map(pair => pair.a + ':' + pair.b).join(',');
|
|
5377
|
+
const rendered = rigc(['render', '--candidate', candidate, '--seam', list, '--fps', String(fps), '--max', String(FOLD_RENDER_MAX), '--out', renderDir]);
|
|
5378
|
+
if (rendered.status !== 0) refuseIfAny(rigcFailed('render --seam (body-root setup observation)', rendered, rendered.out.split('\n').filter(line => line.includes('FAIL') || line.includes('rigc:'))));
|
|
5379
|
+
return readMotionRootSetup(renderDir, fps, candidates);
|
|
5380
|
+
} finally { rmSync(setupDir, { recursive: true, force: true }); }
|
|
5381
|
+
});
|
|
5382
|
+
const { pairs, unmeasuredRoots } = selection;
|
|
4544
5383
|
const slotNames = new Set((Array.isArray(inp.rig.slots) ? inp.rig.slots : []).filter(isRecord).map((sl) => String(sl.name)));
|
|
4545
5384
|
for (const p of pairs) {
|
|
4546
5385
|
const missing = [p.a, p.b].filter((n) => !slotNames.has(n));
|
|
@@ -4548,19 +5387,22 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
4548
5387
|
}
|
|
4549
5388
|
const read = pairs.filter((p) => p.unread === undefined);
|
|
4550
5389
|
if (inp.parts === null) motionSeam = motionSeamLine([], animationNames, fps, [], inp.noParts ?? 'no parts.json');
|
|
4551
|
-
else if (pairs.length === 0) motionSeam = motionSeamLine([], animationNames, fps, [],
|
|
4552
|
-
|
|
4553
|
-
|
|
5390
|
+
else if (pairs.length === 0) motionSeam = motionSeamLine([], animationNames, fps, [], unmeasuredRoots.length === 0
|
|
5391
|
+
? 'no neighbour pair is declared: parts.json holds no limb segment below a joint (config.limbs) and no --requirements seam names two parts'
|
|
5392
|
+
: undefined, motionRootProblems, unmeasuredRoots);
|
|
5393
|
+
else if (animationNames.length === 0) motionSeam = motionSeamLine(pairs, [], fps, [], 'motion.json holds no animation to read the declared pairs in', motionRootProblems, unmeasuredRoots);
|
|
5394
|
+
else if (read.length === 0) motionSeam = motionSeamLine(pairs, animationNames, fps, [], undefined, motionRootProblems, unmeasuredRoots);
|
|
4554
5395
|
else {
|
|
4555
5396
|
rmSync(seamMotionDir, { recursive: true, force: true });
|
|
4556
5397
|
{
|
|
4557
5398
|
const list = read.map((p) => `${p.a}:${p.b}`).join(',');
|
|
4558
5399
|
const activeDest = stripped === null ? seamMotionDir : join(seamMotionDir, env === null ? 'default' : 'active');
|
|
4559
5400
|
const renderedWorlds = new Set<'default' | 'still'>();
|
|
4560
|
-
const
|
|
5401
|
+
const hasRoots = read.some(p => p.root !== undefined);
|
|
5402
|
+
const r = measured(['render', '--candidate', buildDir, '--seam', list, '--fps', String(fps), '--max', String(FOLD_RENDER_MAX), ...(hasRoots ? ['--geometry'] : []), '--out', activeDest]);
|
|
4561
5403
|
if (r.status !== 0) refuseIfAny(rigcFailed(`render --seam ${list} --fps ${fps}`, r, r.out.split('\n').filter((l) => l.includes('FAIL') || l.includes('rigc:'))));
|
|
4562
5404
|
const activeWorldRows: MotionSeamWorldRow[] = [];
|
|
4563
|
-
motionSeam = motionSeamLine(pairs, animationNames, fps, readMotionSeams(activeDest, animationNames, fps, read, {}, stripped !== null && env === null ? activeWorldRows : undefined));
|
|
5405
|
+
motionSeam = motionSeamLine(pairs, animationNames, fps, readMotionSeams(activeDest, animationNames, fps, read, {}, stripped !== null && env === null ? activeWorldRows : undefined, hasRoots ? motionRootDrawOrderReader(activeDest) : undefined), undefined, motionRootProblems, unmeasuredRoots);
|
|
4564
5406
|
if (stripped !== null) {
|
|
4565
5407
|
const response = environmentResponse(readFileSync(join(buildDir, 'skeleton.json'), 'utf8'));
|
|
4566
5408
|
motionSeam.worlds = motionSeamWorlds(true, response.wind.length > 0, world => {
|
|
@@ -4611,6 +5453,8 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
4611
5453
|
// 4. the setup pose as a one-key throwaway animation — the seam reads it against the parts, the source line against
|
|
4612
5454
|
// the painting — and, beside it, the same pose with the eyes shut
|
|
4613
5455
|
let seam: SeamFigures | null = null;
|
|
5456
|
+
let seamScope: SeamScope | undefined;
|
|
5457
|
+
const seamStacks = new SeamStacks();
|
|
4614
5458
|
let seamPairs: SeamPairRow[] | null = null;
|
|
4615
5459
|
let seamViewport: Viewport | null = null;
|
|
4616
5460
|
let blink: JudgementLine = skip(lacking);
|
|
@@ -4646,48 +5490,90 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
4646
5490
|
if (sr.status !== 0) refuseIfAny(rigcFailed('render (the setup-pose still)', sr, sr.out.split('\n').filter((l) => l.includes('FAIL'))));
|
|
4647
5491
|
const stillSet = readFrameSet(join(stillDir, 'render'));
|
|
4648
5492
|
seamViewport = stillSet.viewport;
|
|
4649
|
-
if (keepStills) cpSync(join(stillDir, 'render'), keptDir, { recursive: true });
|
|
5493
|
+
if (keepStills) cpSync(join(stillDir, 'render'), inp.parts === null ? keptDir : join(out, 'setup_still_auto'), { recursive: true });
|
|
4650
5494
|
if (inp.parts !== null) {
|
|
5495
|
+
// Stage existing gated files, not decoded pages/poses. No second build or gate.
|
|
5496
|
+
const selectedAlts = set !== undefined || allSets
|
|
5497
|
+
? (allSets ? (inp.parts.alternates ?? []) : (inp.parts.alternates ?? []).filter(a => a.name === set)) : [];
|
|
5498
|
+
const setStillAnimations: Record<string, unknown> = { still: animations.still };
|
|
5499
|
+
const setStillBase = { ...withoutSliders(inp.rig, setStillAnimations), images };
|
|
5500
|
+
const setsJsonPath = join(inp.rigDir, SETS_FILE);
|
|
5501
|
+
const setsJsonRaw = existsSync(setsJsonPath) ? readJson(setsJsonPath, []) : null;
|
|
5502
|
+
const setsMap = setsJsonRaw !== null && isRecord(setsJsonRaw.sets) ? setsJsonRaw.sets : null;
|
|
5503
|
+
const staged = selectedAlts.map(alt => {
|
|
5504
|
+
const entry = setsMap !== null && isRecord(setsMap[alt.name]) ? setsMap[alt.name] as Record<string, unknown> : null;
|
|
5505
|
+
const drawn = entry !== null && isRecord(entry.drawn)
|
|
5506
|
+
? Object.fromEntries(Object.entries(entry.drawn).filter((e): e is [string, number] => typeof e[1] === 'number' && Number.isFinite(e[1]))) : alt.drawn;
|
|
5507
|
+
const dir = join(stillDir, 'set_' + alt.name);
|
|
5508
|
+
mkdirSync(dir, { recursive: true });
|
|
5509
|
+
writeFileSync(join(dir, 'rig.json'), JSON.stringify(stillRigForSet(setStillBase, alt, drawn)));
|
|
5510
|
+
writeFileSync(join(dir, 'motion.json'), JSON.stringify({ ...inp.motion, animations: setStillAnimations }));
|
|
5511
|
+
const built = rigc(['build', '--rig', join(dir, 'rig.json'), '--motion', join(dir, 'motion.json'), '--out', join(dir, 'build'), '--profile', 'spine']);
|
|
5512
|
+
if (built.status !== 0) refuseIfAny(rigcFailed(`build (the setup-pose still of set "${alt.name}")`, built, buildGateLines(built.out)));
|
|
5513
|
+
return { alt, dir };
|
|
5514
|
+
});
|
|
5515
|
+
const states: SeamStateBounds[] = [seamStateBounds(join(stillDir, 'build'), 'base')];
|
|
5516
|
+
for (const { alt, dir } of staged) states.push(seamStateBounds(join(dir, 'build'), alt.name));
|
|
5517
|
+
const union = seamUnionViewport(inp.stage, states);
|
|
5518
|
+
const domain = { viewport: union, authored: inp.stage, numerator: inp.parts.scene === undefined ? 'whole-union' as const : 'authored-scene-interior' as const, states };
|
|
5519
|
+
const canonical = (build: string, dir: string): FrameSet => {
|
|
5520
|
+
const cr = rigc(['render', '--candidate', build, '--animation', 'still', '--fps', String(STILL_FPS), '--max', String(Math.max(union.width, union.height)), '--viewport', [union.x, union.y, union.width, union.height].join(','), '--geometry', '--out', dir]);
|
|
5521
|
+
if (cr.status !== 0) refuseIfAny(rigcFailed('render (the source-grid setup seam)', cr, cr.out.split('\n').filter(l => l.includes('FAIL'))));
|
|
5522
|
+
const reading = readFrameSet(dir);
|
|
5523
|
+
seamCanonicalViewport(inp.stage, reading.viewport, JSON.parse(readFileSync(join(dir, 'frames.json'), 'utf8')) as unknown, union);
|
|
5524
|
+
return reading;
|
|
5525
|
+
};
|
|
5526
|
+
const canonicalSet = canonical(join(stillDir, 'build'), join(stillDir, 'seam'));
|
|
5527
|
+
seamViewport = canonicalSet.viewport;
|
|
5528
|
+
if (keepStills) cpSync(join(stillDir, 'seam'), keptDir, { recursive: true });
|
|
4651
5529
|
const composite = flatComposite(inp.parts, inp.partsDir, stillSet.background);
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
5530
|
+
const autoSeam = seamFigures(composite, stillSet.frames[0].image, inp.stage, stillSet.viewport, stillSet.background, undefined, inp.parts.scene !== undefined);
|
|
5531
|
+
const placed = inp.parts.parts.map(p => ({ name: p.name, from: p.from, x: p.x, y: p.y, image: readPng(join(inp.partsDir, `${p.name}.png`)) }));
|
|
5532
|
+
const basePopulation = createSeamPopulation(placed, inp.parts.rig_size, canonicalSet.viewport);
|
|
5533
|
+
seam = seamFigures(composite, canonicalSet.frames[0].image, inp.stage, canonicalSet.viewport, canonicalSet.background, undefined, inp.parts.scene !== undefined, undefined, true, basePopulation.observe);
|
|
5534
|
+
seamScope = { mode: 'source-grid/base', domain, denominator_px: canonicalDenominator(seam), auto_frame_raw: seamReading(autoSeam, stillSet.viewport), whole: seamReading(seam, canonicalSet.viewport), population: basePopulation.finish() };
|
|
5535
|
+
const baseRows = basePopulation.rows(seam);
|
|
5536
|
+
seamScope.whole_pairs = baseRows.map(({ row: { picture: _picture, ...raw } }) => raw);
|
|
5537
|
+
if (seamPairsAsked || seamFails(round3(seam.mean), seam.over40, 1)) {
|
|
5538
|
+
const split = baseRows;
|
|
4656
5539
|
mkdirSync(seamDir, { recursive: true });
|
|
4657
|
-
for (const { row, pixels } of split) writePng(join(out, row.picture), seamPicture(
|
|
5540
|
+
for (const { row, pixels } of split) writePng(join(out, row.picture), seamPicture(canonicalSet.frames[0].image, row, pixels));
|
|
4658
5541
|
seamPairs = split.map((x) => x.row);
|
|
4659
5542
|
}
|
|
4660
5543
|
if (set !== undefined || allSets) {
|
|
4661
|
-
const
|
|
4662
|
-
const
|
|
4663
|
-
const setStillBase = { ...withoutSliders(inp.rig, setStillAnimations), images };
|
|
4664
|
-
const setsJsonPath = join(inp.rigDir, SETS_FILE);
|
|
4665
|
-
const setsJsonRaw = existsSync(setsJsonPath) ? readJson(setsJsonPath, []) : null;
|
|
4666
|
-
const setsMap = setsJsonRaw !== null && isRecord(setsJsonRaw.sets) ? setsJsonRaw.sets : null;
|
|
4667
|
-
for (const alt of alts) {
|
|
4668
|
-
const setEntry: Record<string, unknown> | null =
|
|
4669
|
-
setsMap !== null && isRecord(setsMap[alt.name]) ? (setsMap[alt.name] as Record<string, unknown>) : null;
|
|
4670
|
-
const setDrawn: Record<string, number> | undefined =
|
|
4671
|
-
setEntry !== null && isRecord(setEntry.drawn)
|
|
4672
|
-
? Object.fromEntries(
|
|
4673
|
-
Object.entries(setEntry.drawn).filter((entry): entry is [string, number] => typeof entry[1] === 'number' && Number.isFinite(entry[1])),
|
|
4674
|
-
)
|
|
4675
|
-
: alt.drawn;
|
|
4676
|
-
const setDir = join(stillDir, `set_${alt.name}`);
|
|
4677
|
-
mkdirSync(setDir, { recursive: true });
|
|
4678
|
-
writeFileSync(join(setDir, 'rig.json'), JSON.stringify(stillRigForSet(setStillBase, alt, setDrawn)));
|
|
4679
|
-
writeFileSync(join(setDir, 'motion.json'), JSON.stringify({ ...inp.motion, animations: setStillAnimations }));
|
|
4680
|
-
const asb = rigc(['build', '--rig', join(setDir, 'rig.json'), '--motion', join(setDir, 'motion.json'), '--out', join(setDir, 'build'), '--profile', 'spine']);
|
|
4681
|
-
if (asb.status !== 0) refuseIfAny(rigcFailed(`build (the setup-pose still of set "${alt.name}")`, asb, buildGateLines(asb.out)));
|
|
5544
|
+
const baseSupport = seamSupport(join(stillDir, 'build'), join(stillDir, 'rig.json'), canonicalSet, placed, seamStacks, inp.stage);
|
|
5545
|
+
for (const { alt, dir: setDir } of staged) {
|
|
4682
5546
|
const asr = rigc(['render', '--candidate', join(setDir, 'build'), '--animation', 'still', '--fps', String(STILL_FPS), '--max', String(maxSide), '--out', join(setDir, 'render')]);
|
|
4683
5547
|
if (asr.status !== 0) refuseIfAny(rigcFailed(`render (the setup-pose still of set "${alt.name}")`, asr, asr.out.split('\n').filter((l) => l.includes('FAIL'))));
|
|
4684
5548
|
const altStillSet = readFrameSet(join(setDir, 'render'));
|
|
4685
|
-
if (keepStills) cpSync(join(setDir, 'render'), join(
|
|
5549
|
+
if (keepStills) cpSync(join(setDir, 'render'), join(out, 'setup_still_auto', alt.name), { recursive: true });
|
|
4686
5550
|
const rigSlotOrder = (Array.isArray(inp.rig.slots) ? inp.rig.slots : []).filter(isRecord).map((sl) => String(sl.name));
|
|
4687
5551
|
const altComposite = flatCompositeForSet(inp.parts, alt, inp.partsDir, altStillSet.background, rigSlotOrder);
|
|
4688
|
-
const
|
|
5552
|
+
const altCanonical = canonical(join(setDir, 'build'), join(setDir, 'seam'));
|
|
5553
|
+
if (keepStills) cpSync(join(setDir, 'seam'), join(keptDir, alt.name), { recursive: true });
|
|
5554
|
+
const altPlaced = setPlacements(inp.parts, alt, rigSlotOrder).map(({ name, png, box }) => ({ name, from: box.from, x: box.x, y: box.y, image: readPng(join(inp.partsDir, `${png}.png`)) }));
|
|
5555
|
+
const altSupport = seamSupport(join(setDir, 'build'), join(setDir, 'rig.json'), altCanonical, altPlaced, seamStacks, inp.stage);
|
|
5556
|
+
const effects = seamEffectSelection(baseSupport, altSupport);
|
|
5557
|
+
const autoAltSeam = seamFigures(altComposite, altStillSet.frames[0].image, inp.stage, altStillSet.viewport, altStillSet.background, undefined, alt.scene !== undefined);
|
|
5558
|
+
const population = createSeamPopulation(altPlaced, inp.parts.rig_size, altCanonical.viewport, effects.mask);
|
|
5559
|
+
const wholeAltSeam = seamFigures(altComposite, altCanonical.frames[0].image, inp.stage, altCanonical.viewport, altCanonical.background, undefined, inp.parts.scene !== undefined, undefined, true, population.observe);
|
|
5560
|
+
const altSeam = seamFigures(altComposite, altCanonical.frames[0].image, inp.stage, altCanonical.viewport, altCanonical.background, undefined, inp.parts.scene !== undefined, effects.mask, true);
|
|
5561
|
+
const wholeRows = population.rows(wholeAltSeam);
|
|
5562
|
+
const altScope: SeamScope = {
|
|
5563
|
+
mode: 'source-grid/affected-set', domain, denominator_px: canonicalDenominator(altSeam), population: population.finish(),
|
|
5564
|
+
auto_frame_raw: seamReading(autoAltSeam, altStillSet.viewport), whole: seamReading(wholeAltSeam, altCanonical.viewport), effects: effects.reasons, changes: effects.changes,
|
|
5565
|
+
...((baseSupport.unavailable ?? altSupport.unavailable) === undefined ? {} : { unavailable: baseSupport.unavailable ?? altSupport.unavailable }),
|
|
5566
|
+
// Raw rows retain every original field except an unwritten picture.
|
|
5567
|
+
whole_pairs: wholeRows.map(({ row: { picture: _picture, ...raw } }) => raw),
|
|
5568
|
+
pairs: wholeRows.map(({ row, pixels }) => {
|
|
5569
|
+
const affected = pixels.filter(q => effects.mask[q] !== 0).length;
|
|
5570
|
+
const reasons: Partial<SeamEffects['reasons']> = {};
|
|
5571
|
+
for (const q of pixels) { const reason = SEAM_EFFECT_REASONS[effects.cellReasons[q]]; reasons[reason] = (reasons[reason] ?? 0) + 1; }
|
|
5572
|
+
return { parts: row.parts, whole_px_over_40: row.px_over_40, affected_px_over_40: affected, inherited_px_over_40: row.px_over_40 - affected, reasons };
|
|
5573
|
+
}),
|
|
5574
|
+
};
|
|
4689
5575
|
const altMean = round3(altSeam.mean);
|
|
4690
|
-
const altScale =
|
|
5576
|
+
const altScale = 1;
|
|
4691
5577
|
const altFailed = seamFails(altMean, altSeam.over40, altScale);
|
|
4692
5578
|
if (altFailed) {
|
|
4693
5579
|
const hint = armSplitSetHint(inp.parts, alt);
|
|
@@ -4695,22 +5581,22 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
4695
5581
|
}
|
|
4696
5582
|
let altPairs: SeamPairRow[] | null = null;
|
|
4697
5583
|
if (seamPairsAsked || altFailed) {
|
|
4698
|
-
const
|
|
4699
|
-
const split = seamPairRows(altSeam, placed, inp.parts.rig_size, altStillSet.viewport);
|
|
5584
|
+
const split = population.rows(altSeam);
|
|
4700
5585
|
const altSeamDir = join(seamDir, alt.name);
|
|
4701
5586
|
mkdirSync(altSeamDir, { recursive: true });
|
|
4702
5587
|
for (const { row, pixels } of split) {
|
|
4703
5588
|
row.picture = `${SEAM_DIR}/${alt.name}/${basename(row.picture)}`;
|
|
4704
|
-
writePng(join(out, row.picture), seamPicture(
|
|
5589
|
+
writePng(join(out, row.picture), seamPicture(altCanonical.frames[0].image, row, pixels));
|
|
4705
5590
|
}
|
|
4706
5591
|
altPairs = split.map((x) => x.row);
|
|
4707
5592
|
}
|
|
4708
5593
|
setsFigures[alt.name] = {
|
|
4709
|
-
render_px: `${
|
|
5594
|
+
render_px: `${altCanonical.viewport.pixelWidth}x${altCanonical.viewport.pixelHeight}`,
|
|
4710
5595
|
seam_mean: altMean,
|
|
4711
5596
|
seam_px_over_40: altSeam.over40,
|
|
4712
5597
|
seam_px_over_80: altSeam.over80,
|
|
4713
5598
|
seam_frame_scale: altScale,
|
|
5599
|
+
seam_scope: altScope,
|
|
4714
5600
|
...(altSeam.border === null ? {} : { seam_border: { frame_px_left_out: altSeam.border.framePx, px_over_40_left_out: altSeam.border.over40 } }),
|
|
4715
5601
|
...(altPairs === null ? {} : { seam_pairs: altPairs }),
|
|
4716
5602
|
RECOMPOSITE_HOLES: altHolesLine(inp.parts, alt),
|
|
@@ -4773,6 +5659,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
4773
5659
|
seam_px_over_40: seam === null ? null : seam.over40,
|
|
4774
5660
|
seam_px_over_80: seam === null ? null : seam.over80,
|
|
4775
5661
|
seam_frame_scale: seam === null || seamViewport === null ? null : round6(seamViewport.scale),
|
|
5662
|
+
...(seamScope === undefined ? {} : { seam_scope: seamScope }),
|
|
4776
5663
|
...(seam === null || seam.border === null ? {} : { seam_border: { frame_px_left_out: seam.border.framePx, px_over_40_left_out: seam.border.over40 } }),
|
|
4777
5664
|
...(seamPairs === null ? {} : { seam_pairs: seamPairs }),
|
|
4778
5665
|
BREATH_VISIBLE: breath,
|
|
@@ -4786,7 +5673,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
4786
5673
|
...(stress === null ? {} : { [STRESS_LINE]: stress }),
|
|
4787
5674
|
...(limbs === null ? {} : { [LIMB_LINE]: limbs }),
|
|
4788
5675
|
...(sweep === null ? {} : { [SWEEP_LINE]: sweep }),
|
|
4789
|
-
...(motionSeam.pairs.length === 0 ? {} : { [MOTION_SEAM_LINE]: motionSeam }),
|
|
5676
|
+
...(motionSeam.pairs.length === 0 && motionSeam.roots === undefined ? {} : { [MOTION_SEAM_LINE]: motionSeam }),
|
|
4790
5677
|
...(stripped === null || idle === null ? {} : { [CLOTH_LINE]: cloth }),
|
|
4791
5678
|
RECOMPOSITE_HOLES: inp.parts === null ? { status: 'SKIP', reason: inp.noParts ?? '' } : holesLine(inp.parts),
|
|
4792
5679
|
...(sourceRead === null ? {} : { [SOURCE_LINE]: sourceRead }),
|
|
@@ -4810,7 +5697,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
4810
5697
|
const worst = seamPairs === null || seamPairs.length === 0 ? null : seamPairs[0];
|
|
4811
5698
|
barProblems.push({
|
|
4812
5699
|
code: 'CHECK_SEAM_WITHIN_BAR',
|
|
4813
|
-
object: 'the setup-pose render vs the flat composite of parts/',
|
|
5700
|
+
object: 'the source-grid setup-pose render vs the flat composite of parts/ (base, judged once)',
|
|
4814
5701
|
detail:
|
|
4815
5702
|
`mean |d| ${figures.seam_mean}/255 and ${figures.seam_px_over_40} frame px over ${SEAM_PX_LEVEL} (${figures.seam_px_over_80} over ${SEAM_PX_LEVEL_HIGH}) at frame scale ${figures.seam_frame_scale}, ${seamRigPxText(figures.seam_px_over_40, figures.seam_frame_scale)} rig px (the count / s²); mean <= ${SEAM_MEAN_BAR.toFixed(1)} and <= ${SEAM_PX_BAR} rig px over ${SEAM_PX_LEVEL} are required` +
|
|
4816
5703
|
(worst === null
|
|
@@ -4823,7 +5710,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
4823
5710
|
const worst = setFig.seam_pairs === undefined || setFig.seam_pairs.length === 0 ? null : setFig.seam_pairs[0];
|
|
4824
5711
|
barProblems.push({
|
|
4825
5712
|
code: 'CHECK_SEAM_WITHIN_BAR',
|
|
4826
|
-
object: `the setup-pose render of set "${setName}" vs the flat composite of parts
|
|
5713
|
+
object: `the source-grid setup-pose render of set "${setName}" vs the flat composite of parts/ (affected cells only, base denominator retained)`,
|
|
4827
5714
|
detail:
|
|
4828
5715
|
`mean |d| ${setFig.seam_mean}/255 and ${setFig.seam_px_over_40} frame px over ${SEAM_PX_LEVEL} (${setFig.seam_px_over_80} over ${SEAM_PX_LEVEL_HIGH}) at frame scale ${setFig.seam_frame_scale}, ${seamRigPxText(setFig.seam_px_over_40, setFig.seam_frame_scale)} rig px (the count / s²); mean <= ${SEAM_MEAN_BAR.toFixed(1)} and <= ${SEAM_PX_BAR} rig px over ${SEAM_PX_LEVEL} are required` +
|
|
4829
5716
|
(worst === null
|
|
@@ -4836,7 +5723,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
4836
5723
|
const rank = (q: Problem): number => JUDGEMENT_LINES.findIndex((n) => q.code === `CHECK_${n}`);
|
|
4837
5724
|
problems.sort((a, b) => rank(a) - rank(b));
|
|
4838
5725
|
problems.unshift(...barProblems);
|
|
4839
|
-
problems.push(...foldProblems, ...levelProblems, ...stressProblems, ...limbProblems, ...sweepProblems, ...reqProblems);
|
|
5726
|
+
problems.push(...foldProblems, ...levelProblems, ...stressProblems, ...limbProblems, ...sweepProblems, ...motionRootProblems, ...reqProblems);
|
|
4840
5727
|
figures.PASS = problems.length === 0;
|
|
4841
5728
|
const publishCheck = (): void => write('check.json', `${JSON.stringify(figures, null, 1)}\n`);
|
|
4842
5729
|
if (motionSeam.worlds === undefined) publishCheck();
|
|
@@ -4862,6 +5749,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
4862
5749
|
if (limbs !== null) tally(LIMB_LINE, null);
|
|
4863
5750
|
// Issue #360: the range bar where it is written; a joint it cannot read fails, so it always measures.
|
|
4864
5751
|
if (sweep !== null) tally(SWEEP_LINE, null);
|
|
5752
|
+
if (motionSeam.roots !== undefined) tally(MOTION_SEAM_LINE, motionSeam.roots.status === 'SKIP' ? (motionSeam.roots.reason ?? 'no body-root reading') : null);
|
|
4865
5753
|
return {
|
|
4866
5754
|
figures,
|
|
4867
5755
|
gateHtml,
|