@rig-c/parts 1.84.0 → 1.86.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.ts +5 -2
- package/docs/AUTHORING.md +176 -0
- package/docs/STABILITY.md +25 -1
- package/package.json +2 -2
- package/src/assemble.ts +42 -3
- package/src/build.ts +19 -3
- package/src/check.ts +85 -10
- package/src/cutmaterial.ts +285 -0
- package/src/cutmaterialio.ts +63 -0
- package/src/jointcontact.ts +59 -0
- package/src/requirements.ts +10 -2
- package/src/setuppainting.ts +126 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** Report core's material connectivity; no count here participates in a bar. */
|
|
2
|
+
import { PartsError, type Problem } from './errors.ts';
|
|
3
|
+
|
|
4
|
+
export interface JointContactReading {
|
|
5
|
+
status: 'REPORTED' | 'SKIP';
|
|
6
|
+
joints: string[];
|
|
7
|
+
joined?: number;
|
|
8
|
+
separated?: number;
|
|
9
|
+
unavailable?: number;
|
|
10
|
+
reasons: Array<{ reason: string; frames?: number[] }>;
|
|
11
|
+
reason?: string;
|
|
12
|
+
}
|
|
13
|
+
const record = (v: unknown): v is Record<string, unknown> => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
14
|
+
|
|
15
|
+
/** Count only producer observations; invalid input adds a problem and yields no reading when a collector is supplied. */
|
|
16
|
+
export function jointContactReading(raw: unknown, joints: readonly string[], sampled: unknown, object: string, problems?: Problem[]): JointContactReading | null {
|
|
17
|
+
const names = [...new Set(joints)];
|
|
18
|
+
const fail = (detail: string): null => {
|
|
19
|
+
const problem = { code: 'FRAMES_SIDECAR', object, detail: 'jointContact: ' + detail };
|
|
20
|
+
if (problems === undefined) throw new PartsError([problem]);
|
|
21
|
+
problems.push(problem);
|
|
22
|
+
return null;
|
|
23
|
+
};
|
|
24
|
+
const knownCount = typeof sampled === 'number' && Number.isSafeInteger(sampled) && sampled >= 0 ? sampled : undefined;
|
|
25
|
+
if (raw === undefined) {
|
|
26
|
+
const reason = names.length === 0 ? 'pair has no declared named joint' : 'core seam reading has no jointContact.frames';
|
|
27
|
+
return knownCount === undefined || knownCount === 0
|
|
28
|
+
? { status: 'SKIP', joints: names, reasons: [], reason: knownCount === 0 ? 'no sampled frames' : 'sample count unavailable: ' + reason }
|
|
29
|
+
: { status: 'REPORTED', joints: names, joined: 0, separated: 0, unavailable: knownCount, reasons: [{ reason }] };
|
|
30
|
+
}
|
|
31
|
+
if (!record(raw) || !Array.isArray(raw.frames)) return fail('requires { frames: [...] }');
|
|
32
|
+
if (knownCount !== undefined && raw.frames.length !== knownCount) return fail('has ' + raw.frames.length + ' frame(s); frames.json records ' + knownCount);
|
|
33
|
+
const frames: Array<{ index: number; time: number; status: 'joined' | 'separated' | 'unavailable'; reason: string | null }> = [];
|
|
34
|
+
for (const f of raw.frames) {
|
|
35
|
+
if (!record(f) || typeof f.index !== 'number' || !Number.isSafeInteger(f.index) || f.index < 0 ||
|
|
36
|
+
typeof f.time !== 'number' || !Number.isFinite(f.time) || f.time < 0 ||
|
|
37
|
+
(f.status !== 'joined' && f.status !== 'separated' && f.status !== 'unavailable') ||
|
|
38
|
+
(f.status === 'unavailable' ? typeof f.reason !== 'string' || f.reason.trim() === '' : f.reason !== null)) return fail('requires nonnegative index/time, joined/separated with null reason, or unavailable with a nonempty reason');
|
|
39
|
+
const previous = frames.at(-1);
|
|
40
|
+
if (previous !== undefined && (f.index <= previous.index || f.time <= previous.time)) return fail('frame indices and times must increase strictly');
|
|
41
|
+
frames.push({ index: f.index, time: f.time, status: f.status, reason: f.reason as string | null });
|
|
42
|
+
}
|
|
43
|
+
if (frames.length === 0) return { status: 'SKIP', joints: names, reasons: [], reason: 'no sampled frames' };
|
|
44
|
+
const out: JointContactReading = { status: 'REPORTED', joints: names, joined: 0, separated: 0, unavailable: 0, reasons: [] };
|
|
45
|
+
for (const f of frames) {
|
|
46
|
+
const status = names.length === 0 ? 'unavailable' : f.status;
|
|
47
|
+
const reason = names.length === 0 ? 'pair has no declared named joint' : f.reason;
|
|
48
|
+
if (status === 'joined') out.joined = (out.joined ?? 0) + 1;
|
|
49
|
+
else if (status === 'separated') out.separated = (out.separated ?? 0) + 1;
|
|
50
|
+
else {
|
|
51
|
+
out.unavailable = (out.unavailable ?? 0) + 1;
|
|
52
|
+
const why = reason as string;
|
|
53
|
+
let hit = out.reasons.find(r => r.reason === why);
|
|
54
|
+
if (hit === undefined) { hit = { reason: why, frames: [] }; out.reasons.push(hit); }
|
|
55
|
+
hit.frames?.push(f.index);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
package/src/requirements.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { setupPaintingProblems, type SetupPainting } from './setuppainting.ts';
|
|
2
|
+
import { jointMaterialProblems, type JointMaterial } from './cutmaterial.ts';
|
|
1
3
|
import { fixedSkeletonProblems, type FixedSkeleton } from './artjoints.ts';
|
|
2
4
|
/**
|
|
3
5
|
* What a scene requires of a rig's motion, declared in a file `check` is given
|
|
@@ -193,6 +195,10 @@ export interface RequirementsFile {
|
|
|
193
195
|
may_fold: MayFold[];
|
|
194
196
|
/** Issue #880: an explicit fixed-skeleton art comparison, absent on other rigs. */
|
|
195
197
|
fixed_skeleton?: FixedSkeleton;
|
|
198
|
+
/** Issue #887: authored source-painting limits over native renderer setup. */
|
|
199
|
+
setup_painting?: SetupPainting;
|
|
200
|
+
/** Explicit source-support declarations (#888), absent otherwise. */
|
|
201
|
+
cut_material?: JointMaterial[];
|
|
196
202
|
}
|
|
197
203
|
|
|
198
204
|
/** One declared fold (issue #320): a slot, a named animation, and why the fold is the art's. */
|
|
@@ -283,7 +289,9 @@ export function readRequirements(path: string): RequirementsFile {
|
|
|
283
289
|
problems.push({ code: 'REQUIREMENTS_SELF_TARGET', object: `${label} field "target"`, detail });
|
|
284
290
|
};
|
|
285
291
|
if (raw.spec !== REQUIREMENTS_SPEC) field(`${at} field "spec"`, `is ${JSON.stringify(raw.spec)}; ${JSON.stringify(REQUIREMENTS_SPEC)} is required`);
|
|
286
|
-
for (const k of Object.keys(raw)) if (!['spec', 'fps', 'targets', 'requirements', ...EXCEPTION_LISTS, 'may_fold', 'fixed_skeleton'].includes(k) && !freeKey(k, raw[k])) field(`${at} field "${k}"`, 'is not a field this format reads (spec, fps, targets, requirements, not_planted, not_swinging, rises, rests, may_fold, fixed_skeleton; note or *_note as a string; x-<name> as a record)');
|
|
292
|
+
for (const k of Object.keys(raw)) if (!['spec', 'fps', 'targets', 'requirements', ...EXCEPTION_LISTS, 'may_fold', 'fixed_skeleton', 'cut_material', 'setup_painting'].includes(k) && !freeKey(k, raw[k])) field(`${at} field "${k}"`, 'is not a field this format reads (spec, fps, targets, requirements, not_planted, not_swinging, rises, rests, may_fold, fixed_skeleton, cut_material, setup_painting; note or *_note as a string; x-<name> as a record)');
|
|
293
|
+
if ('setup_painting' in raw) problems.push(...setupPaintingProblems(raw.setup_painting, `${at} setup_painting`));
|
|
294
|
+
if ('cut_material' in raw) problems.push(...jointMaterialProblems(raw.cut_material, `${at} cut_material`));
|
|
287
295
|
if ('fixed_skeleton' in raw) problems.push(...fixedSkeletonProblems(raw.fixed_skeleton, `${at} fixed_skeleton`));
|
|
288
296
|
let fps = NaN;
|
|
289
297
|
if (!(finite(raw.fps) && raw.fps > 0)) field(`${at} field "fps"`, `is ${JSON.stringify(raw.fps)}; a positive number of frames per second is required — every named animation is sampled at it, and there is no default`);
|
|
@@ -468,7 +476,7 @@ export function readRequirements(path: string): RequirementsFile {
|
|
|
468
476
|
}
|
|
469
477
|
}
|
|
470
478
|
refuseIfAny(problems);
|
|
471
|
-
return { path: at, fps, targets, requirements, not_planted: lists.not_planted, not_swinging: lists.not_swinging, rises: lists.rises, rests: lists.rests, may_fold: mayFold, ...(raw.fixed_skeleton === undefined ? {} : { fixed_skeleton: raw.fixed_skeleton as FixedSkeleton }) };
|
|
479
|
+
return { path: at, fps, targets, requirements, not_planted: lists.not_planted, not_swinging: lists.not_swinging, rises: lists.rises, rests: lists.rests, may_fold: mayFold, ...(raw.fixed_skeleton === undefined ? {} : { fixed_skeleton: raw.fixed_skeleton as FixedSkeleton }), ...(raw.cut_material === undefined ? {} : { cut_material: raw.cut_material as JointMaterial[] }), ...(raw.setup_painting === undefined ? {} : { setup_painting: raw.setup_painting as SetupPainting }) };
|
|
472
480
|
}
|
|
473
481
|
|
|
474
482
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/** Authored source-painting limits over actual renderer setup pixels (#887). */
|
|
2
|
+
import { refuseIfAny, type Problem } from './errors.ts';
|
|
3
|
+
import type { Raster } from './raster/types.ts';
|
|
4
|
+
|
|
5
|
+
export const SETUP_PAINTING_LINE = 'SETUP_MATCHES_PAINTING';
|
|
6
|
+
export interface SetupPaintingRegion {
|
|
7
|
+
name: string;
|
|
8
|
+
/** Stage pixels, x right/y down: [x, y, width, height], exclusive far edge. */
|
|
9
|
+
box: [number, number, number, number];
|
|
10
|
+
/** Maximum count over the entire named region. Absent means SKIP. */
|
|
11
|
+
max_pixels?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface SetupPainting {
|
|
14
|
+
/** A pixel counts when its maximum RGB difference is strictly greater. */
|
|
15
|
+
rgb_tolerance: number;
|
|
16
|
+
regions: SetupPaintingRegion[];
|
|
17
|
+
}
|
|
18
|
+
const object = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
19
|
+
const integer = (v: unknown): v is number => typeof v === 'number' && Number.isSafeInteger(v);
|
|
20
|
+
const free = (k: string, v: unknown): boolean => (k.startsWith('x-') && k.length > 2) || ((k === 'note' || k.endsWith('_note')) && typeof v === 'string');
|
|
21
|
+
|
|
22
|
+
/** Shape only: no default limit, inferred box, art alignment or slot name. */
|
|
23
|
+
export function setupPaintingProblems(value: unknown, at: string): Problem[] {
|
|
24
|
+
const problems: Problem[] = [];
|
|
25
|
+
const fail = (where: string, detail: string): void => { problems.push({ code: 'REQUIREMENTS_FIELD', object: where, detail }); };
|
|
26
|
+
const keys = (v: Record<string, unknown>, allowed: string[], where: string): void => {
|
|
27
|
+
for (const k of Object.keys(v)) if (!allowed.includes(k) && !free(k, v[k])) fail(`${where}.${k}`, `is unknown; fields are ${allowed.join(', ')}`);
|
|
28
|
+
};
|
|
29
|
+
if (!object(value)) return [{ code: 'REQUIREMENTS_FIELD', object: at, detail: 'requires {rgb_tolerance, regions: [{name, box, max_pixels?}]}' }];
|
|
30
|
+
keys(value, ['rgb_tolerance', 'regions'], at);
|
|
31
|
+
if (!integer(value.rgb_tolerance) || value.rgb_tolerance < 0 || value.rgb_tolerance > 255) fail(`${at}.rgb_tolerance`, 'requires an authored integer from 0 through 255; difference strictly above it counts');
|
|
32
|
+
if (!Array.isArray(value.regions) || value.regions.length === 0) fail(`${at}.regions`, 'requires a nonempty list of named source-grid regions');
|
|
33
|
+
else {
|
|
34
|
+
const names = new Set<string>();
|
|
35
|
+
value.regions.forEach((r, i) => {
|
|
36
|
+
const where = `${at}.regions[${i}]`;
|
|
37
|
+
if (!object(r)) { fail(where, 'requires {name, box, max_pixels?}'); return; }
|
|
38
|
+
keys(r, ['name', 'box', 'max_pixels'], where);
|
|
39
|
+
if (typeof r.name !== 'string' || r.name.trim() === '') fail(`${where}.name`, 'requires a nonempty region name');
|
|
40
|
+
else { if (names.has(r.name)) fail(`${where}.name`, `declares region "${r.name}" twice`); names.add(r.name); }
|
|
41
|
+
if (!Array.isArray(r.box) || r.box.length !== 4 || !r.box.every(integer) || r.box[0] < 0 || r.box[1] < 0 || r.box[2] <= 0 || r.box[3] <= 0 || !Number.isSafeInteger(r.box[0] + r.box[2]) || !Number.isSafeInteger(r.box[1] + r.box[3])) fail(`${where}.box`, 'requires nonnegative integer x/y and positive integer width/height in stage pixels, with finite integer far edges');
|
|
42
|
+
if ('max_pixels' in r && (!integer(r.max_pixels) || r.max_pixels < 0)) fail(`${where}.max_pixels`, 'requires a nonnegative authored integer pixel count, or omission for SKIP');
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return problems;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function setupPaintingBounds(value: SetupPainting, width: number, height: number): Problem[] {
|
|
49
|
+
return value.regions.flatMap(r => r.box[0] + r.box[2] > width || r.box[1] + r.box[3] > height
|
|
50
|
+
? [{ code: 'REQUIREMENTS_FIELD', object: `setup_painting region "${r.name}" box`, detail: `[${r.box.join(', ')}] exceeds the declared ${width}x${height} stage; regions use its native pixel grid, not a fitted render` }] : []);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface SetupPaintingSlot {
|
|
54
|
+
slot: string;
|
|
55
|
+
/** Bounding box of failing pixel centres, in stage-grid pixels. */
|
|
56
|
+
box: [number, number, number, number];
|
|
57
|
+
pixel_count: number;
|
|
58
|
+
}
|
|
59
|
+
export interface SetupPaintingReading extends SetupPaintingRegion {
|
|
60
|
+
status: 'PASS' | 'FAIL' | 'SKIP';
|
|
61
|
+
pixel_count: number;
|
|
62
|
+
limit: number | null;
|
|
63
|
+
slots: SetupPaintingSlot[];
|
|
64
|
+
}
|
|
65
|
+
export interface SetupPaintingLine {
|
|
66
|
+
status: 'PASS' | 'FAIL' | 'SKIP';
|
|
67
|
+
instrument: 'rigc renderer setup textured pieces';
|
|
68
|
+
registration: 'declared stage grid, scale 1, no fitting';
|
|
69
|
+
compositing: 'source-over white, RGBA8';
|
|
70
|
+
figure: 'source figureSilhouette union rendered alpha > 0';
|
|
71
|
+
ownership: 'last actual drawn piece with sampled alpha > 0; uncovered explicit';
|
|
72
|
+
rgb_tolerance: number;
|
|
73
|
+
regions: SetupPaintingReading[];
|
|
74
|
+
reason?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Pixel metric only. Caller supplies the actual renderer's textured setup and
|
|
78
|
+
* its per-pixel drawn-piece owners on precisely the source grid. RGB under
|
|
79
|
+
* zero alpha is ignored: both observations are source-over white first.
|
|
80
|
+
* Region totals count each pixel once, even with translucent contributors.
|
|
81
|
+
*/
|
|
82
|
+
export function setupPaintingLine(
|
|
83
|
+
declared: SetupPainting, source: Raster, setup: Raster, figure: Uint8Array,
|
|
84
|
+
owners: Int32Array, slots: readonly string[], problems: Problem[],
|
|
85
|
+
): SetupPaintingLine {
|
|
86
|
+
refuseIfAny(setupPaintingProblems(declared, 'setup_painting'));
|
|
87
|
+
refuseIfAny(setupPaintingBounds(declared, source.width, source.height));
|
|
88
|
+
const W = source.width, H = source.height, n = W * H;
|
|
89
|
+
if (setup.width !== W || setup.height !== H || figure.length !== n || owners.length !== n || source.data.length !== n * 4 || setup.data.length !== n * 4 || owners.some(i => i < -1 || i >= slots.length)) {
|
|
90
|
+
refuseIfAny([{ code: 'CHECK_SETUP_PAINTING_MEASURED', object: SETUP_PAINTING_LINE, detail: 'requires actual setup pixels, figure domain and renderer owners on the declared native source grid; no fitted registration or guessed owner is substituted' }]);
|
|
91
|
+
}
|
|
92
|
+
const regions = declared.regions.map<SetupPaintingReading>(r => {
|
|
93
|
+
const rows = new Map<string, { pixels: number; x0: number; y0: number; x1: number; y1: number }>();
|
|
94
|
+
let count = 0;
|
|
95
|
+
for (let y = r.box[1]; y < r.box[1] + r.box[3]; y++) for (let x = r.box[0]; x < r.box[0] + r.box[2]; x++) {
|
|
96
|
+
const p = y * W + x, q = p * 4;
|
|
97
|
+
if (figure[p] === 0 && setup.data[q + 3] === 0) continue;
|
|
98
|
+
let delta = 0;
|
|
99
|
+
for (let c = 0; c < 3; c++) {
|
|
100
|
+
const white = (image: Raster): number => Math.round(image.data[q + c] * image.data[q + 3] / 255 + 255 * (1 - image.data[q + 3] / 255));
|
|
101
|
+
delta = Math.max(delta, Math.abs(white(source) - white(setup)));
|
|
102
|
+
}
|
|
103
|
+
if (delta <= declared.rgb_tolerance) continue;
|
|
104
|
+
count++;
|
|
105
|
+
const slot = owners[p] < 0 ? '(uncovered)' : slots[owners[p]], row = rows.get(slot);
|
|
106
|
+
if (row === undefined) rows.set(slot, { pixels: 1, x0: x, y0: y, x1: x + 1, y1: y + 1 });
|
|
107
|
+
else { row.pixels++; row.x0 = Math.min(row.x0, x); row.y0 = Math.min(row.y0, y); row.x1 = Math.max(row.x1, x + 1); row.y1 = Math.max(row.y1, y + 1); }
|
|
108
|
+
}
|
|
109
|
+
const status = r.max_pixels === undefined ? 'SKIP' : count > r.max_pixels ? 'FAIL' : 'PASS';
|
|
110
|
+
const result: SetupPaintingReading = { ...r, status, pixel_count: count, limit: r.max_pixels ?? null,
|
|
111
|
+
slots: [...rows].map(([slot, row]) => ({ slot, box: [row.x0, row.y0, row.x1 - row.x0, row.y1 - row.y0], pixel_count: row.pixels })) };
|
|
112
|
+
if (status === 'FAIL') {
|
|
113
|
+
for (const row of result.slots) problems.push({ code: 'CHECK_SETUP_MATCHES_PAINTING', object: `region "${r.name}" slot "${row.slot}"`, detail: `box [${row.box.join(', ')}], pixelcount ${row.pixel_count}; region pixelcount ${count} > declared limit ${r.max_pixels}, RGB tolerance ${declared.rgb_tolerance}; compare the actual setup to the source painting on the declared stage grid` });
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
});
|
|
117
|
+
const noLimit = regions.some(r => r.status === 'SKIP');
|
|
118
|
+
return { status: regions.some(r => r.status === 'FAIL') ? 'FAIL' : noLimit ? 'SKIP' : 'PASS', instrument: 'rigc renderer setup textured pieces', registration: 'declared stage grid, scale 1, no fitting', compositing: 'source-over white, RGBA8', figure: 'source figureSilhouette union rendered alpha > 0', ownership: 'last actual drawn piece with sampled alpha > 0; uncovered explicit', rgb_tolerance: declared.rgb_tolerance, regions,
|
|
119
|
+
...(noLimit ? { reason: 'a region has no declared max_pixels; it is measured as SKIP, never PASS' } : {}) };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function setupPaintingLines(line: SetupPaintingLine): string[] {
|
|
123
|
+
return [`${SETUP_PAINTING_LINE}: ${line.status}${line.reason === undefined ? '' : ` — ${line.reason}`}; ${line.registration}; ${line.compositing}`,
|
|
124
|
+
...line.regions.flatMap(r => [`${SETUP_PAINTING_LINE}: region "${r.name}" ${r.status} — box [${r.box.join(', ')}], pixelcount ${r.pixel_count}, limit ${r.limit ?? 'undeclared (SKIP)'}, RGB tolerance ${line.rgb_tolerance}`,
|
|
125
|
+
...r.slots.map(s => `${SETUP_PAINTING_LINE}: slot "${s.slot}" region "${r.name}" — box [${s.box.join(', ')}], pixelcount ${s.pixel_count}; region total ${r.pixel_count}, limit ${r.limit ?? 'undeclared (SKIP)'}`)])];
|
|
126
|
+
}
|