@rig-c/parts 1.61.0 → 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 +77 -5
- package/docs/STABILITY.md +26 -9
- package/package.json +1 -1
- package/src/build.ts +14 -6
- package/src/check.ts +261 -276
- package/src/config.ts +95 -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
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
*/
|
|
80
80
|
import { createHash } from 'node:crypto';
|
|
81
81
|
import { createRequire } from 'node:module';
|
|
82
|
-
import type {
|
|
82
|
+
import type { Viewport as RootCoverageViewport } from 'rig-c/render-shared';
|
|
83
83
|
import { copyFileSync, cpSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
84
84
|
import { basename, delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
85
85
|
import { measureRecomposite, type RecompositeFigures, recompositeRecord, scenePhrase, sourceInRig } from './assemble.ts';
|
|
@@ -1461,6 +1461,7 @@ export function seamFigures(
|
|
|
1461
1461
|
scene = false,
|
|
1462
1462
|
effect?: Uint8Array,
|
|
1463
1463
|
sourceGrid = false,
|
|
1464
|
+
observe?: (pixel: number, map: ScaleTranslate) => void,
|
|
1464
1465
|
): SeamFigures {
|
|
1465
1466
|
const [W, H] = [composite.width, composite.height];
|
|
1466
1467
|
const src = newFloatImage(W, H, 3);
|
|
@@ -1497,16 +1498,17 @@ export function seamFigures(
|
|
|
1497
1498
|
const edgeCol = scene ? Array.from({ length: vp.pixelWidth }, (_, x) => onEdge(x, map.tx, map.sx, W)) : null;
|
|
1498
1499
|
const edgeRow = scene ? Array.from({ length: vp.pixelHeight }, (_, y) => onEdge(y, map.ty, map.sy, H)) : null;
|
|
1499
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);
|
|
1500
1506
|
let m = 0;
|
|
1501
1507
|
for (let c = 0; c < 3; c++) {
|
|
1502
1508
|
const w = Math.fround(warped.data[p * 3 + c] + background[c]);
|
|
1503
1509
|
const d = Math.abs(w - frame.data[p * 4 + c]);
|
|
1504
1510
|
if (d > m) m = d;
|
|
1505
1511
|
}
|
|
1506
|
-
const u = p % vp.pixelWidth - map.tx, v = Math.floor(p / vp.pixelWidth) - map.ty;
|
|
1507
|
-
const excluded = sourceGrid && scene
|
|
1508
|
-
? u < 0 || v < 0 || u >= W || v >= H || onEdge(u, 0, 1, W) || onEdge(v, 0, 1, H)
|
|
1509
|
-
: edgeCol !== null && edgeRow !== null && (edgeCol[p % vp.pixelWidth] || edgeRow[Math.floor(p / vp.pixelWidth)]);
|
|
1510
1512
|
if (excluded) {
|
|
1511
1513
|
borderPx++;
|
|
1512
1514
|
if (m > SEAM_PX_LEVEL) borderOver40++;
|
|
@@ -1851,6 +1853,8 @@ export interface SeamScope {
|
|
|
1851
1853
|
effects?: SeamEffects['reasons'];
|
|
1852
1854
|
changes?: SeamEffects['changes'];
|
|
1853
1855
|
unavailable?: SeamSupportUnavailable;
|
|
1856
|
+
/** Every actually observed pre-threshold reference contributor category, not error-only rows. */
|
|
1857
|
+
population?: SeamPopulation;
|
|
1854
1858
|
whole_pairs?: Array<Omit<SeamPairRow, 'picture'>>;
|
|
1855
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']> }>;
|
|
1856
1860
|
}
|
|
@@ -1936,13 +1940,30 @@ export interface PlacedAlpha {
|
|
|
1936
1940
|
image: Raster;
|
|
1937
1941
|
}
|
|
1938
1942
|
|
|
1939
|
-
/**
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
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) {
|
|
1946
1967
|
const [W, H] = rigSize;
|
|
1947
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.
|
|
1948
1969
|
const top = new Int32Array(W * H).fill(-1);
|
|
@@ -1961,7 +1982,93 @@ export function seamPairRows(seam: SeamFigures, parts: readonly PlacedAlpha[], r
|
|
|
1961
1982
|
}
|
|
1962
1983
|
}
|
|
1963
1984
|
});
|
|
1964
|
-
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;
|
|
1965
2072
|
// A part's pixel at rig (u, v) as an offset into its image, or -1 where it holds no art.
|
|
1966
2073
|
const at = (k: number, u: number, v: number): number => {
|
|
1967
2074
|
const part = parts[k];
|
|
@@ -1984,39 +2091,7 @@ export function seamPairRows(seam: SeamFigures, parts: readonly PlacedAlpha[], r
|
|
|
1984
2091
|
seam.counted.forEach((p, idx) => {
|
|
1985
2092
|
const fx = p % vp.pixelWidth;
|
|
1986
2093
|
const fy = Math.floor(p / vp.pixelWidth);
|
|
1987
|
-
const u0 =
|
|
1988
|
-
const v0 = Math.floor((fy - ty) / sy);
|
|
1989
|
-
let first = -1;
|
|
1990
|
-
let second = -1;
|
|
1991
|
-
const read: Array<[number, number]> = [];
|
|
1992
|
-
let rx0 = Infinity;
|
|
1993
|
-
let ry0 = Infinity;
|
|
1994
|
-
let rx1 = -Infinity;
|
|
1995
|
-
let ry1 = -Infinity;
|
|
1996
|
-
for (let dv = 0; dv < 2; dv++) {
|
|
1997
|
-
for (let du = 0; du < 2; du++) {
|
|
1998
|
-
const u = u0 + du;
|
|
1999
|
-
const v = v0 + dv;
|
|
2000
|
-
if (u < 0 || u >= W || v < 0 || v >= H) continue;
|
|
2001
|
-
read.push([u, v]);
|
|
2002
|
-
rx0 = Math.min(rx0, u);
|
|
2003
|
-
ry0 = Math.min(ry0, v);
|
|
2004
|
-
rx1 = Math.max(rx1, u);
|
|
2005
|
-
ry1 = Math.max(ry1, v);
|
|
2006
|
-
for (const k of [top[v * W + u], next[v * W + u]]) {
|
|
2007
|
-
if (k < 0 || k === first || k === second) continue;
|
|
2008
|
-
if (k > first) {
|
|
2009
|
-
second = first;
|
|
2010
|
-
first = k;
|
|
2011
|
-
} else if (k > second) second = k;
|
|
2012
|
-
}
|
|
2013
|
-
}
|
|
2014
|
-
}
|
|
2015
|
-
// A sample wholly outside the rig reads no rig pixel; its rig box is the nearest rig pixel.
|
|
2016
|
-
if (rx1 < rx0) {
|
|
2017
|
-
rx0 = rx1 = Math.min(Math.max(u0, 0), W - 1);
|
|
2018
|
-
ry0 = ry1 = Math.min(Math.max(v0, 0), H - 1);
|
|
2019
|
-
}
|
|
2094
|
+
const { u0, v0, first, second, read, rx0, ry0, rx1, ry1 } = attribution(p, seam.map, true);
|
|
2020
2095
|
const a = second;
|
|
2021
2096
|
const b = first;
|
|
2022
2097
|
const key = `${a},${b}`;
|
|
@@ -3981,18 +4056,16 @@ export interface MotionSeamRow {
|
|
|
3981
4056
|
banded: number;
|
|
3982
4057
|
/** The frames over the floor, ascending: the warning's frames. */
|
|
3983
4058
|
opens: number[];
|
|
3984
|
-
/** Beside `opens`:
|
|
4059
|
+
/** Beside `opens`: gapOpen plus UNDER-owned ghost on roots; legacy maximum elsewhere. */
|
|
3985
4060
|
px: number[];
|
|
3986
|
-
/** Maximum gated/warned count over the
|
|
4061
|
+
/** Maximum gated/warned count over the unchanged one-cell floor. */
|
|
3987
4062
|
max_px: number;
|
|
3988
4063
|
/** The frames rigc names open whose every opening is one cell thick: under the floor, not reported. */
|
|
3989
4064
|
under_floor: number[];
|
|
3990
4065
|
/** New roots only: the worst above-floor hit, retaining rigc's cell and world box. */
|
|
3991
|
-
worst?: MotionSeamHit & { kind: 'gap' | 'ghost' };
|
|
3992
|
-
/**
|
|
3993
|
-
|
|
3994
|
-
/** Roots only, above-floor raw GAP hits: sufficient whole-box proof, never a GAP mask. */
|
|
3995
|
-
coverage?: RootGapCoverage[];
|
|
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[];
|
|
3996
4069
|
}
|
|
3997
4070
|
|
|
3998
4071
|
/** Existing pairs warn; new body roots alone can FAIL. Unavailable readings are named SKIP, never measured zero. */
|
|
@@ -4009,7 +4082,7 @@ export interface MotionSeamLine {
|
|
|
4009
4082
|
/** Physics-only reference worlds (issue #591); do not participate in warnings or bars. */
|
|
4010
4083
|
worlds?: MotionSeamWorlds;
|
|
4011
4084
|
/** Selected body-root pairs and named zero-band roots; existing internal seams remain warnings. */
|
|
4012
|
-
roots?: { status: 'PASS' | 'FAIL' | 'SKIP'; mode: 'gap-
|
|
4085
|
+
roots?: { status: 'PASS' | 'FAIL' | 'SKIP'; mode: 'gap-open+under-ghost'; ghost_owner: 'resolved-draw-order'; pairs: string[]; failed: number; reason?: string; unmeasured?: MotionUnmeasuredRoot[] };
|
|
4013
4086
|
}
|
|
4014
4087
|
|
|
4015
4088
|
/**
|
|
@@ -4217,193 +4290,57 @@ export interface MotionSeamHit {
|
|
|
4217
4290
|
box: [number, number, number, number];
|
|
4218
4291
|
}
|
|
4219
4292
|
|
|
4220
|
-
/**
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
if (!Number.isFinite(hit.cell) || hit.cell <= 0 || !hit.box.every(Number.isFinite) ||
|
|
4264
|
-
!Number.isSafeInteger(width * height) || width <= 0 || height <= 0 ||
|
|
4265
|
-
!integerExtent(hit.box[0], hit.box[2], width) || !integerExtent(hit.box[1], hit.box[3], height) ||
|
|
4266
|
-
alpha === null || alpha.length !== width * height || alpha.some(a => !Number.isFinite(a) || a < 0 || a > 255)) return unavailable();
|
|
4267
|
-
const covered = alpha.filter(a => a >= ROOT_DRAWN_ALPHA).length;
|
|
4268
|
-
return { ...hit, status: covered === alpha.length ? 'exempt' : 'conservative',
|
|
4269
|
-
reason: covered === alpha.length ? 'whole world-cell box covered at DRAWN_ALPHA 128' : 'uncovered box cells: retain the entire original GAP count; exact GAP subset unavailable',
|
|
4270
|
-
box_cells: alpha.length, covered_cells: covered };
|
|
4271
|
-
}
|
|
4272
|
-
|
|
4273
|
-
/**
|
|
4274
|
-
* Root-only lazy reader. The render already made by runCheck supplies every
|
|
4275
|
-
* used world vertex, tint, frame time and draw order. The public renderer entry
|
|
4276
|
-
* supplies packed UV/page metadata and rasterisation, not a second seam metric.
|
|
4277
|
-
* Unsupported clipping/binding or even one replay pixel mismatch retains raw.
|
|
4278
|
-
*/
|
|
4279
|
-
export function motionRootCoverageReader(build: string, rendered: string, out: string): RootGapCoverageReader {
|
|
4280
|
-
type Renderer = OfficialRenderer;
|
|
4281
|
-
type PoseAttachment = NonNullable<RootCoverageFrame['attachments']>[number];
|
|
4282
|
-
interface Prepared { api: Renderer; pages: ReturnType<Renderer['loadCandidate']>['pages']; pieces: RootCoveragePiece[]; attachments: PoseAttachment[] }
|
|
4283
|
-
interface Animation { frames: Map<number, { frame: RootCoverageFrame; alphaReplayExact: boolean }>; restMagnitude: number }
|
|
4284
|
-
let prepared: Prepared | undefined;
|
|
4285
|
-
const animations = new Map<string, Animation>();
|
|
4286
|
-
const read = (path: string): unknown => JSON.parse(readFileSync(path, 'utf8')) as unknown;
|
|
4287
|
-
const same = (a: unknown, b: unknown): boolean => JSON.stringify(a) === JSON.stringify(b);
|
|
4288
|
-
class CoverageUnavailable extends Error {}
|
|
4289
|
-
const requireFact = (condition: unknown, reason: string): void => { if (!condition) throw new CoverageUnavailable(reason); };
|
|
4290
|
-
const attachments = (value: unknown): PoseAttachment[] => {
|
|
4291
|
-
requireFact(Array.isArray(value), 'geometry attachment roster unavailable');
|
|
4292
|
-
return (value as unknown[]).map(a => {
|
|
4293
|
-
if (!isRecord(a) || typeof a.slot !== 'string' || typeof a.attachment !== 'string' ||
|
|
4294
|
-
!Array.isArray(a.vertices) || a.vertices.length % 2 !== 0 || !a.vertices.every(v => typeof v === 'number' && Number.isFinite(v)) ||
|
|
4295
|
-
!Array.isArray(a.color) || a.color.length !== 4 || !a.color.every(v => typeof v === 'number' && Number.isFinite(v) && v >= 0 && v <= 1)) throw new CoverageUnavailable('geometry attachment fields unavailable');
|
|
4296
|
-
return { slot: a.slot, attachment: a.attachment, vertices: a.vertices as number[], color: a.color as [number, number, number, number] };
|
|
4297
|
-
});
|
|
4298
|
-
};
|
|
4299
|
-
const prepare = (): Prepared => {
|
|
4300
|
-
if (prepared !== undefined) return prepared;
|
|
4301
|
-
// Node's module loader is called only here, never for a root-free reading.
|
|
4302
|
-
const loaded: unknown = officialRenderer();
|
|
4303
|
-
requireFact(isRecord(loaded) && ['loadCandidate', 'throughPoser', 'sampleSetupPose', 'renderFrame'].every(k => typeof loaded[k] === 'function'), 'official renderer exports unavailable');
|
|
4304
|
-
const api = loaded as Renderer;
|
|
4305
|
-
const skeleton = join(build, 'skeleton.json'), atlas = join(build, 'skeleton.atlas');
|
|
4306
|
-
const text = readFileSync(skeleton, 'utf8'), document: unknown = JSON.parse(text);
|
|
4307
|
-
const unsupported = (v: unknown): boolean => Array.isArray(v) ? v.some(unsupported) : isRecord(v) &&
|
|
4308
|
-
(v.type === 'clipping' || Object.keys(v).some(k => k === 'dark' || k === 'rgba2' || k === 'rgb2' || unsupported(v[k])));
|
|
4309
|
-
requireFact(!unsupported(document), 'clipping or dark-tint metadata is not replayable from this geometry');
|
|
4310
|
-
const candidate = api.loadCandidate({ skeletonText: text, atlasText: readFileSync(atlas, 'utf8'), atlasDir: build, label: 'root GAP composite' }, { skeleton, atlas }, undefined);
|
|
4311
|
-
const metadata = api.throughPoser(candidate.choice, p => api.sampleSetupPose(p, { geometry: true, bones: true })).value[0];
|
|
4312
|
-
requireFact(metadata !== undefined && metadata.attachments !== undefined && metadata.pieces.every(p => !('source' in p) && p.dark === undefined), 'unclipped packed metadata unavailable');
|
|
4313
|
-
prepared = { api, pages: candidate.pages, pieces: metadata.pieces, attachments: metadata.attachments ?? [] };
|
|
4314
|
-
return prepared;
|
|
4315
|
-
};
|
|
4316
|
-
return (pair, animation, hit, time) => {
|
|
4317
|
-
let result = rootGapBoxCoverage(hit, null);
|
|
4318
|
-
let alpha: number[] | null = null;
|
|
4319
|
-
let frameTime: number | null = null;
|
|
4320
|
-
const reason = 'official composite metadata or pixel replay unavailable';
|
|
4321
|
-
try {
|
|
4322
|
-
requireFact(Number.isInteger(hit.index) && hit.index >= 0 && typeof time === 'number' && Number.isFinite(time), 'actual raw frame time unavailable');
|
|
4323
|
-
const { api, pages, pieces, attachments: metadataAttachments } = prepare();
|
|
4324
|
-
const sidecar = read(join(rendered, 'frames.json'));
|
|
4325
|
-
requireFact(isRecord(sidecar) && Array.isArray(sidecar.sets) && isRecord(sidecar.viewport), 'render viewport unavailable');
|
|
4326
|
-
// requireFact deliberately does not narrow unknown values: each reader
|
|
4327
|
-
// checks again at its own boundary rather than using an unchecked cast.
|
|
4328
|
-
if (!isRecord(sidecar) || !Array.isArray(sidecar.sets) || !isRecord(sidecar.viewport)) throw new CoverageUnavailable(reason);
|
|
4329
|
-
const set = sidecar.sets.find(s => isRecord(s) && s.animation === animation);
|
|
4330
|
-
requireFact(isRecord(set) && typeof set.dir === 'string' && !isAbsolute(set.dir) && !set.dir.split(/[\\/]/).includes('..'), 'local animation directory unavailable');
|
|
4331
|
-
if (!isRecord(set) || typeof set.dir !== 'string') throw new CoverageUnavailable(reason);
|
|
4332
|
-
const v = sidecar.viewport;
|
|
4333
|
-
requireFact(['x', 'y', 'width', 'height', 'scale', 'pixelWidth', 'pixelHeight'].every(k => typeof v[k] === 'number' && Number.isFinite(v[k])) &&
|
|
4334
|
-
Number(v.scale) > 0 && Number.isSafeInteger(v.pixelWidth) && Number(v.pixelWidth) > 0 && Number.isSafeInteger(v.pixelHeight) && Number(v.pixelHeight) > 0, 'finite render viewport unavailable');
|
|
4335
|
-
const viewport: RootCoverageViewport = { minX: Number(v.x), minY: Number(v.y), maxX: Number(v.x) + Number(v.width), maxY: Number(v.y) + Number(v.height), scale: Number(v.scale), width: Number(v.pixelWidth), height: Number(v.pixelHeight) };
|
|
4336
|
-
requireFact(Array.isArray(sidecar.background) && sidecar.background.length === 4 && sidecar.background.every(x => typeof x === 'number' && Number.isInteger(x) && x >= 0 && x <= 255), 'render background unavailable');
|
|
4337
|
-
const background = sidecar.background as [number, number, number, number];
|
|
4338
|
-
let state = animations.get(animation);
|
|
4339
|
-
if (state === undefined) {
|
|
4340
|
-
const geometry = read(join(rendered, set.dir, GEOMETRY_FILE));
|
|
4341
|
-
requireFact(isRecord(geometry) && isRecord(geometry.setup) && Array.isArray(geometry.rest) && Array.isArray(geometry.frames) && geometry.animation === animation, 'same-animation geometry unavailable');
|
|
4342
|
-
if (!isRecord(geometry) || !isRecord(geometry.setup) || !Array.isArray(geometry.rest) || !Array.isArray(geometry.frames)) throw new CoverageUnavailable(reason);
|
|
4343
|
-
const setup = attachments(geometry.setup.attachments);
|
|
4344
|
-
requireFact(setup.length === pieces.length && new Set(setup.map(a => a.slot)).size === setup.length, 'setup draw roster unavailable');
|
|
4345
|
-
for (const p of pieces) {
|
|
4346
|
-
const a = setup.find(a => a.slot === p.slot);
|
|
4347
|
-
const rest = geometry.rest.find(r => isRecord(r) && r.slot === p.slot && r.attachment === a?.attachment);
|
|
4348
|
-
requireFact(a !== undefined && isRecord(rest) && rest.kind === p.kind && a.vertices.length === p.world.length && same(a.color, p.tint) &&
|
|
4349
|
-
(p.kind !== 'mesh' || same(rest.triangles, Array.from(p.triangles))), 'packed metadata topology or tint differs');
|
|
4350
|
-
}
|
|
4351
|
-
// The metadata poser supplies attachment identity, never world positions.
|
|
4352
|
-
// Match it explicitly to the captured setup, including default skin.
|
|
4353
|
-
requireFact(setup.every(a => metadataAttachments.some(b => a.slot === b.slot && a.attachment === b.attachment)), 'default attachment identity differs');
|
|
4354
|
-
let restMagnitude = 0;
|
|
4355
|
-
for (const r of geometry.rest) {
|
|
4356
|
-
if (!isRecord(r) || !Array.isArray(r.vertices) || !r.vertices.every(v => typeof v === 'number' && Number.isFinite(v))) throw new CoverageUnavailable('rest coordinate bound unavailable');
|
|
4357
|
-
for (const v of r.vertices as number[]) restMagnitude = Math.max(restMagnitude, Math.abs(v));
|
|
4358
|
-
}
|
|
4359
|
-
state = { restMagnitude, frames: new Map() };
|
|
4360
|
-
for (const f of geometry.frames) {
|
|
4361
|
-
if (!isRecord(f) || !Number.isInteger(f.index) || typeof f.time !== 'number' || !Number.isFinite(f.time)) throw new CoverageUnavailable('frame identity unavailable');
|
|
4362
|
-
const posed = attachments(f.attachments);
|
|
4363
|
-
requireFact(posed.length === pieces.length && new Set(posed.map(a => a.slot)).size === posed.length, 'frame draw roster differs');
|
|
4364
|
-
const drawn = posed.map(a => {
|
|
4365
|
-
const p = pieces.find(p => p.slot === a.slot), original = setup.find(p => p.slot === a.slot);
|
|
4366
|
-
if (p === undefined || original?.attachment !== a.attachment || p.world.length !== a.vertices.length) throw new CoverageUnavailable('frame attachment binding differs');
|
|
4367
|
-
return { ...p, world: a.vertices, tint: a.color };
|
|
4368
|
-
});
|
|
4369
|
-
requireFact(!state.frames.has(Number(f.index)), 'duplicate frame index');
|
|
4370
|
-
state.frames.set(Number(f.index), { frame: { index: Number(f.index), time: f.time, pieces: drawn }, alphaReplayExact: false });
|
|
4371
|
-
}
|
|
4372
|
-
animations.set(animation, state);
|
|
4373
|
-
}
|
|
4374
|
-
const captured = state.frames.get(hit.index);
|
|
4375
|
-
frameTime = captured?.frame.time ?? null;
|
|
4376
|
-
requireFact(captured !== undefined && captured.frame.time === time, 'raw and geometry frame time differ');
|
|
4377
|
-
if (captured === undefined) throw new CoverageUnavailable(reason);
|
|
4378
|
-
frameTime = captured.frame.time;
|
|
4379
|
-
if (!captured.alphaReplayExact) {
|
|
4380
|
-
const png = readPng(join(rendered, set.dir, 'f' + String(hit.index).padStart(4, '0') + '.png'));
|
|
4381
|
-
const replay = api.renderFrame(captured.frame, pages, viewport, background);
|
|
4382
|
-
requireFact(png.width === replay.width && png.height === replay.height && Buffer.from(png.data).equals(Buffer.from(replay.data)), 'official frame RGBA pixel replay differs');
|
|
4383
|
-
captured.alphaReplayExact = true;
|
|
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 });
|
|
4384
4336
|
}
|
|
4385
|
-
|
|
4386
|
-
requireFact(Number.isSafeInteger(width * height) && width > 0 && height > 0 && Number.isFinite(hit.cell) && hit.cell > 0, 'world cell box unavailable');
|
|
4387
|
-
const grid = { minX: hit.box[0], minY: hit.box[1], maxX: hit.box[2], maxY: hit.box[3], width, height, scale: 1 / hit.cell };
|
|
4388
|
-
const composite = api.renderFrame(captured.frame, pages, grid, [0, 0, 0, 0]);
|
|
4389
|
-
alpha = Array.from({ length: width * height }, (_, i) => composite.data[i * 4 + 3]);
|
|
4390
|
-
let worldMagnitude = state.restMagnitude;
|
|
4391
|
-
for (const p of captured.frame.pieces) for (const v of p.world) worldMagnitude = Math.max(worldMagnitude, Math.abs(v));
|
|
4392
|
-
// All drawings' magnitude bounds either pair without selecting an owner.
|
|
4393
|
-
result = rootGapBoxCoverage(hit, alpha, 'world cell box grid unavailable', worldMagnitude);
|
|
4394
|
-
} catch (error) {
|
|
4395
|
-
// No guessed coverage and no absolute paths from an upstream exception.
|
|
4396
|
-
result = rootGapBoxCoverage(hit, null, error instanceof CoverageUnavailable ? error.message : reason);
|
|
4337
|
+
animations.set(animation, frames);
|
|
4397
4338
|
}
|
|
4398
|
-
const
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
scope: 'whole world-cell box centres; not an exact GAP-cell mask',
|
|
4404
|
-
grid: { minX: hit.box[0], minY: hit.box[1], maxX: hit.box[2], maxY: hit.box[3], cell: hit.cell, rows: 'top to bottom' },
|
|
4405
|
-
alpha, exact_rgba_replay: alpha !== null, followup: 'rig-c/core#1556' }, null, 1) + '\n');
|
|
4406
|
-
return { ...result, evidence };
|
|
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';
|
|
4407
4344
|
};
|
|
4408
4345
|
}
|
|
4409
4346
|
export interface MotionSeamWorldKind {
|
|
@@ -4451,7 +4388,7 @@ export function motionSeamWorlds(physics: boolean, answersWind: boolean, read: (
|
|
|
4451
4388
|
/** The same validated sidecars as the warning, retaining the raw gap and ghost cells. */
|
|
4452
4389
|
export function readMotionSeamWorldRows(dir: string, animations: readonly string[], fps: number, pairs: readonly MotionSeamPair[]): MotionSeamWorldRow[] {
|
|
4453
4390
|
const rows: MotionSeamWorldRow[] = [];
|
|
4454
|
-
readMotionSeams(dir, animations, fps, pairs, {}, rows);
|
|
4391
|
+
readMotionSeams(dir, animations, fps, pairs.map(({ root: _root, ...pair }) => pair), {}, rows);
|
|
4455
4392
|
return rows;
|
|
4456
4393
|
}
|
|
4457
4394
|
|
|
@@ -4509,8 +4446,8 @@ type SeamHitRead = MotionSeamHit;
|
|
|
4509
4446
|
* file that is missing, a file that is not the animation's or not at the rate
|
|
4510
4447
|
* asked, a pair out of the flag's order, and a field of the wrong shape.
|
|
4511
4448
|
*/
|
|
4512
|
-
export function readMotionSeams(dir: string, animations: readonly string[], fps: number, pairs: readonly MotionSeamPair[], plant: MotionSeamPlant = {}, worldRows?: MotionSeamWorldRow[],
|
|
4513
|
-
return readSeamRows(dir, animations, fps, pairs, plant, worldRows, false,
|
|
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);
|
|
4514
4451
|
}
|
|
4515
4452
|
|
|
4516
4453
|
/** The same stock seam reader, restricted to one canonical setup-only frame. */
|
|
@@ -4535,7 +4472,7 @@ export function readMotionRootSetup(dir: string, fps: number, pairs: readonly Mo
|
|
|
4535
4472
|
return rows.map(({ pair, drawn, banded, status }) => ({ pair, drawn, banded, status }));
|
|
4536
4473
|
}
|
|
4537
4474
|
|
|
4538
|
-
function readSeamRows(dir: string, animations: readonly string[], fps: number, pairs: readonly MotionSeamPair[], plant: MotionSeamPlant = {}, worldRows?: MotionSeamWorldRow[], setup = false,
|
|
4475
|
+
function readSeamRows(dir: string, animations: readonly string[], fps: number, pairs: readonly MotionSeamPair[], plant: MotionSeamPlant = {}, worldRows?: MotionSeamWorldRow[], setup = false, drawOrderReader?: RootDrawOrderReader): MotionSeamRow[] {
|
|
4539
4476
|
const problems: Problem[] = [];
|
|
4540
4477
|
const bad = (object: string, detail: string): void => {
|
|
4541
4478
|
problems.push({ code: 'FRAMES_SIDECAR', object, detail });
|
|
@@ -4574,10 +4511,8 @@ function readSeamRows(dir: string, animations: readonly string[], fps: number, p
|
|
|
4574
4511
|
}
|
|
4575
4512
|
const over = new Map<number, number>();
|
|
4576
4513
|
let rootWorst: MotionSeamRow['worst'];
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
const coverage: RootGapCoverage[] = [];
|
|
4580
|
-
const exempt = new Set<number>();
|
|
4514
|
+
const rootFrames = new Set<number>();
|
|
4515
|
+
const cells: MotionRootCells[] = [];
|
|
4581
4516
|
const kinds: Record<'gap' | 'ghost', MotionSeamWorldKind> = { gap: { max_px: 0, worst: null }, ghost: { max_px: 0, worst: null } };
|
|
4582
4517
|
for (const kind of ['gap', 'ghost'] as const) {
|
|
4583
4518
|
const k = p[kind];
|
|
@@ -4587,22 +4522,72 @@ function readSeamRows(dir: string, animations: readonly string[], fps: number, p
|
|
|
4587
4522
|
return;
|
|
4588
4523
|
}
|
|
4589
4524
|
const hits = frames as SeamHitRead[];
|
|
4590
|
-
|
|
4591
|
-
else ghostFrames = hits.length;
|
|
4525
|
+
|
|
4592
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);
|
|
4593
4527
|
kinds[kind] = { max_px: worst?.px ?? 0, worst };
|
|
4594
|
-
//
|
|
4595
|
-
|
|
4596
|
-
for (const h of hits) if ((want.root === undefined || kind === 'gap') && (plant.noFloor === true || openingOverFloor(h))) {
|
|
4597
|
-
if (want.root !== undefined) {
|
|
4598
|
-
const raw = isRecord(k) && Array.isArray(k.frames) ? k.frames.find(v => isRecord(v) && v.index === h.index) : undefined;
|
|
4599
|
-
const time = isRecord(raw) && typeof raw.time === 'number' ? raw.time : undefined;
|
|
4600
|
-
const proof = coverageReader?.(want, animation, h, time) ?? rootGapBoxCoverage(h, null);
|
|
4601
|
-
coverage.push(proof);
|
|
4602
|
-
if (proof.status === 'exempt') { exempt.add(h.index); continue; }
|
|
4603
|
-
}
|
|
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))) {
|
|
4604
4530
|
over.set(h.index, Math.max(over.get(h.index) ?? 0, h.px));
|
|
4605
|
-
|
|
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
|
+
}
|
|
4606
4591
|
}
|
|
4607
4592
|
}
|
|
4608
4593
|
worldRows?.push({ pair: want.pair, animation, status: p.status, drawn: p.drawn, banded: p.banded, gap: kinds.gap, ghost: kinds.ghost });
|
|
@@ -4616,10 +4601,9 @@ function readSeamRows(dir: string, animations: readonly string[], fps: number, p
|
|
|
4616
4601
|
opens,
|
|
4617
4602
|
px: opens.map((f) => over.get(f) ?? 0),
|
|
4618
4603
|
max_px: opens.reduce((m, f) => Math.max(m, over.get(f) ?? 0), 0),
|
|
4619
|
-
under_floor: (want.root === undefined ? p.opens :
|
|
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)),
|
|
4620
4605
|
...(rootWorst === undefined ? {} : { worst: rootWorst }),
|
|
4621
|
-
...(
|
|
4622
|
-
...(want.root === undefined ? {} : { ghost_info: { ...kinds.ghost, owner: 'unavailable' as const, frames: ghostFrames } }),
|
|
4606
|
+
...(want.root === undefined ? {} : { cells }),
|
|
4623
4607
|
});
|
|
4624
4608
|
});
|
|
4625
4609
|
}
|
|
@@ -4627,7 +4611,7 @@ function readSeamRows(dir: string, animations: readonly string[], fps: number, p
|
|
|
4627
4611
|
return rows;
|
|
4628
4612
|
}
|
|
4629
4613
|
|
|
4630
|
-
/** Only active proven
|
|
4614
|
+
/** Only active proven roots gate gapOpen plus UNDER-owned ghost; existing warnings/floor are unchanged. */
|
|
4631
4615
|
export function motionSeamLine(pairs: MotionSeamPair[], animations: string[], fps: number, rows: MotionSeamRow[], reason?: string, problems: Problem[] = [], unmeasuredRoots: readonly MotionUnmeasuredRoot[] = []): MotionSeamLine {
|
|
4632
4616
|
const roots = pairs.filter(p => p.root !== undefined);
|
|
4633
4617
|
const rootNames = new Set(roots.map(p => p.pair));
|
|
@@ -4635,11 +4619,10 @@ export function motionSeamLine(pairs: MotionSeamPair[], animations: string[], fp
|
|
|
4635
4619
|
const failed = rows.filter(r => rootNames.has(r.pair) && r.status === 'read' && r.banded > 0 && r.opens.length > 0);
|
|
4636
4620
|
for (const row of failed) {
|
|
4637
4621
|
const h = row.worst;
|
|
4638
|
-
const proof = row.coverage?.find(p => p.index === h?.index);
|
|
4639
4622
|
problems.push({ code: 'CHECK_SEAM_OVER_MOTION', object: 'body-root seam "' + row.pair + '" in "' + row.animation + '"',
|
|
4640
4623
|
detail: h === undefined
|
|
4641
4624
|
? 'opens on frames ' + frameRuns(row.opens) + ', max ' + row.max_px + ' cells; no above-floor root hit metadata was returned'
|
|
4642
|
-
: 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'
|
|
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' });
|
|
4643
4626
|
}
|
|
4644
4627
|
const missing = roots.flatMap(p => animations.length === 0 ? ['"' + p.pair + '": no animation'] : animations.flatMap(a => {
|
|
4645
4628
|
const row = rows.find(r => r.pair === p.pair && r.animation === a);
|
|
@@ -4649,7 +4632,7 @@ export function motionSeamLine(pairs: MotionSeamPair[], animations: string[], fp
|
|
|
4649
4632
|
const rootReasons = [...missing, ...unmeasured.map(root => 'root pair for ' + root.limb + ': ' + root.reason)];
|
|
4650
4633
|
const rootGate: MotionSeamLine['roots'] = roots.length === 0 && unmeasured.length === 0 ? undefined : {
|
|
4651
4634
|
status: failed.length > 0 ? 'FAIL' : rootReasons.length > 0 || reason !== undefined ? 'SKIP' : 'PASS',
|
|
4652
|
-
mode: 'gap-
|
|
4635
|
+
mode: 'gap-open+under-ghost', ghost_owner: 'resolved-draw-order',
|
|
4653
4636
|
pairs: roots.map(p => p.pair), failed: failed.length,
|
|
4654
4637
|
...(rootReasons.length === 0 && reason === undefined ? {} : { reason: unmeasured.length === 0 ? (reason ?? missing.join('; ')) : [reason, ...rootReasons].filter(r => r !== undefined).join('; ') }),
|
|
4655
4638
|
...(unmeasured.length === 0 ? {} : { unmeasured }),
|
|
@@ -5011,7 +4994,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
5011
4994
|
const keptDir = join(out, STILL_DIR);
|
|
5012
4995
|
const foldDir = join(out, FOLD_SCRATCH);
|
|
5013
4996
|
const seamMotionDir = join(out, MOTION_SEAM_SCRATCH);
|
|
5014
|
-
for (const d of [buildDir, idleDir, stillDir, isoDir, loopDir, seamDir, keptDir, join(out, 'setup_still_auto'), foldDir, seamMotionDir
|
|
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 });
|
|
5015
4998
|
const written: string[] = [];
|
|
5016
4999
|
const write = (name: string, data: string): void => {
|
|
5017
5000
|
writeFileSync(join(out, name), data);
|
|
@@ -5419,7 +5402,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
5419
5402
|
const r = measured(['render', '--candidate', buildDir, '--seam', list, '--fps', String(fps), '--max', String(FOLD_RENDER_MAX), ...(hasRoots ? ['--geometry'] : []), '--out', activeDest]);
|
|
5420
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:'))));
|
|
5421
5404
|
const activeWorldRows: MotionSeamWorldRow[] = [];
|
|
5422
|
-
motionSeam = motionSeamLine(pairs, animationNames, fps, readMotionSeams(activeDest, animationNames, fps, read, {}, stripped !== null && env === null ? activeWorldRows : undefined, hasRoots ?
|
|
5405
|
+
motionSeam = motionSeamLine(pairs, animationNames, fps, readMotionSeams(activeDest, animationNames, fps, read, {}, stripped !== null && env === null ? activeWorldRows : undefined, hasRoots ? motionRootDrawOrderReader(activeDest) : undefined), undefined, motionRootProblems, unmeasuredRoots);
|
|
5423
5406
|
if (stripped !== null) {
|
|
5424
5407
|
const response = environmentResponse(readFileSync(join(buildDir, 'skeleton.json'), 'utf8'));
|
|
5425
5408
|
motionSeam.worlds = motionSeamWorlds(true, response.wind.length > 0, world => {
|
|
@@ -5545,10 +5528,11 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
5545
5528
|
if (keepStills) cpSync(join(stillDir, 'seam'), keptDir, { recursive: true });
|
|
5546
5529
|
const composite = flatComposite(inp.parts, inp.partsDir, stillSet.background);
|
|
5547
5530
|
const autoSeam = seamFigures(composite, stillSet.frames[0].image, inp.stage, stillSet.viewport, stillSet.background, undefined, inp.parts.scene !== undefined);
|
|
5548
|
-
seam = seamFigures(composite, canonicalSet.frames[0].image, inp.stage, canonicalSet.viewport, canonicalSet.background, undefined, inp.parts.scene !== undefined, undefined, true);
|
|
5549
|
-
seamScope = { mode: 'source-grid/base', domain, denominator_px: canonicalDenominator(seam), auto_frame_raw: seamReading(autoSeam, stillSet.viewport), whole: seamReading(seam, canonicalSet.viewport) };
|
|
5550
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`)) }));
|
|
5551
|
-
const
|
|
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);
|
|
5552
5536
|
seamScope.whole_pairs = baseRows.map(({ row: { picture: _picture, ...raw } }) => raw);
|
|
5553
5537
|
if (seamPairsAsked || seamFails(round3(seam.mean), seam.over40, 1)) {
|
|
5554
5538
|
const split = baseRows;
|
|
@@ -5571,11 +5555,12 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
5571
5555
|
const altSupport = seamSupport(join(setDir, 'build'), join(setDir, 'rig.json'), altCanonical, altPlaced, seamStacks, inp.stage);
|
|
5572
5556
|
const effects = seamEffectSelection(baseSupport, altSupport);
|
|
5573
5557
|
const autoAltSeam = seamFigures(altComposite, altStillSet.frames[0].image, inp.stage, altStillSet.viewport, altStillSet.background, undefined, alt.scene !== undefined);
|
|
5574
|
-
const
|
|
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);
|
|
5575
5560
|
const altSeam = seamFigures(altComposite, altCanonical.frames[0].image, inp.stage, altCanonical.viewport, altCanonical.background, undefined, inp.parts.scene !== undefined, effects.mask, true);
|
|
5576
|
-
const wholeRows =
|
|
5561
|
+
const wholeRows = population.rows(wholeAltSeam);
|
|
5577
5562
|
const altScope: SeamScope = {
|
|
5578
|
-
mode: 'source-grid/affected-set', domain, denominator_px: canonicalDenominator(altSeam),
|
|
5563
|
+
mode: 'source-grid/affected-set', domain, denominator_px: canonicalDenominator(altSeam), population: population.finish(),
|
|
5579
5564
|
auto_frame_raw: seamReading(autoAltSeam, altStillSet.viewport), whole: seamReading(wholeAltSeam, altCanonical.viewport), effects: effects.reasons, changes: effects.changes,
|
|
5580
5565
|
...((baseSupport.unavailable ?? altSupport.unavailable) === undefined ? {} : { unavailable: baseSupport.unavailable ?? altSupport.unavailable }),
|
|
5581
5566
|
// Raw rows retain every original field except an unwritten picture.
|
|
@@ -5596,7 +5581,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
5596
5581
|
}
|
|
5597
5582
|
let altPairs: SeamPairRow[] | null = null;
|
|
5598
5583
|
if (seamPairsAsked || altFailed) {
|
|
5599
|
-
const split =
|
|
5584
|
+
const split = population.rows(altSeam);
|
|
5600
5585
|
const altSeamDir = join(seamDir, alt.name);
|
|
5601
5586
|
mkdirSync(altSeamDir, { recursive: true });
|
|
5602
5587
|
for (const { row, pixels } of split) {
|