@rig-c/parts 2.49.0 → 2.50.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/README.md +1 -0
- package/cli.ts +129 -6
- package/docs/AUTHORING.md +192 -21
- package/docs/STABILITY.md +68 -9
- package/package.json +1 -1
- package/src/behindseams.ts +164 -11
- package/src/build.ts +27 -14
- package/src/bustlandmarks.ts +600 -0
- package/src/check.ts +255 -30
- package/src/configwrite.ts +64 -3
- package/src/setuppainting.ts +44 -1
package/src/check.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { readSetupFigureMask } from './setupfiguremask.ts';
|
|
|
4
4
|
import { readSetupBackdrop } from './setupbackdrop.ts';
|
|
5
5
|
import { COINCIDE_LINE, type SupportReport } from './coincide.ts';
|
|
6
6
|
import { observeSupport } from './coincideio.ts';
|
|
7
|
-
import { SETUP_PAINTING_LINE, UNDECLARED_SETUP_PAINTING_REASON, setupPaintingBounds, setupPaintingLine, type SetupPainting, type SetupPaintingLine, type SetupPaintingObservation } from './setuppainting.ts';
|
|
7
|
+
import { SETUP_PAINTING_LINE, SETUP_PAINTING_UNCOVERED_WARNING, UNDECLARED_SETUP_PAINTING_REASON, setupPaintingBounds, setupPaintingLine, setupPaintingWarningCount, type SetupPainting, type SetupPaintingLine, type SetupPaintingObservation } from './setuppainting.ts';
|
|
8
8
|
import { readMaterialSources } from './cutmaterialio.ts';
|
|
9
9
|
import { CUT_MATERIAL_LINE, checkJointMaterial, type MaterialLine } from './cutmaterial.ts';
|
|
10
10
|
import { ART_JOINT_LINE, artJointLine, type ArtJointLine } from './artjoints.ts';
|
|
@@ -96,7 +96,7 @@ import { createHash } from 'node:crypto';
|
|
|
96
96
|
import { createRequire } from 'node:module';
|
|
97
97
|
import type { Candidate, Piece, Viewport as RootCoverageViewport } from '@rig-c/core/render-shared';
|
|
98
98
|
import { fillHoles } from './raster/morph.ts';
|
|
99
|
-
import { copyFileSync, cpSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
99
|
+
import { closeSync, copyFileSync, cpSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, readSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from 'node:fs';
|
|
100
100
|
import { diagnosticSegment, diagnosticSiblings } from './outputpaths.ts';
|
|
101
101
|
import { basename, delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
102
102
|
import { measureRecomposite, type RecompositeFigures, recompositeRecord, scenePhrase, sourceInRig, figureSilhouette } from './assemble.ts';
|
|
@@ -3289,9 +3289,9 @@ export function barsSummary(r: Pick<CheckReport, 'bars'>): string {
|
|
|
3289
3289
|
return `${measured.length} of ${measured.length + skipped.length} bar(s) measured, ${skipped.length} skipped${skipped.length === 0 ? '' : ` (${skipped.map((s) => s.bar).join(', ')})`}`;
|
|
3290
3290
|
}
|
|
3291
3291
|
|
|
3292
|
-
/** The summary's warning clause: each warning line that read something, named, with the warnings they printed together; empty when none read. */
|
|
3293
|
-
export function warningsClause(r: Pick<CheckReport, 'motionSeam' | 'cloth'>): string {
|
|
3294
|
-
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 }])];
|
|
3292
|
+
/** The summary's warning clause: each warning line that read something, named, with the warnings they printed together, and `SETUP_PAINTING_MOSTLY_UNCOVERED` only when it printed one (issue #1421); empty when none read. */
|
|
3293
|
+
export function warningsClause(r: Pick<CheckReport, 'motionSeam' | 'cloth' | 'figures'>): string {
|
|
3294
|
+
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 }]), ...(setupPaintingWarningCount(r.figures[SETUP_PAINTING_LINE]) === 0 ? [] : [{ name: SETUP_PAINTING_UNCOVERED_WARNING, n: setupPaintingWarningCount(r.figures[SETUP_PAINTING_LINE]) }])];
|
|
3295
3295
|
if (read.length === 0) return '';
|
|
3296
3296
|
return `; ${read.reduce((a, x) => a + x.n, 0)} warning(s) (${read.map((x) => x.name).join(', ')}, not a bar)`;
|
|
3297
3297
|
}
|
|
@@ -4862,7 +4862,7 @@ export function motionSeamRequired(line: MotionSeamLine, rows: readonly MotionBa
|
|
|
4862
4862
|
}
|
|
4863
4863
|
const failed = problems.length - before;
|
|
4864
4864
|
return { status: failed === 0 ? 'PASS' : 'FAIL', mode: 'gap-open', bar_px: 0, pairs: out, failed,
|
|
4865
|
-
...(cellEvidence.frames.length === 0 ? {} : { cells: { path: MOTION_CELLS_FILE, sha256:
|
|
4865
|
+
...(cellEvidence.frames.length === 0 ? {} : { cells: { path: MOTION_CELLS_FILE, sha256: hashMotionSeamCellSidecar(cellEvidence) } }) };
|
|
4866
4866
|
}
|
|
4867
4867
|
|
|
4868
4868
|
/** The inline partition counts the same cells as the sidecar, including unresolved setup slots. */
|
|
@@ -4873,7 +4873,7 @@ function motionCellClasses(cells: readonly MotionOpenCell[]): MotionOpenFrame['c
|
|
|
4873
4873
|
}
|
|
4874
4874
|
|
|
4875
4875
|
/** Refuse broken evidence links and partitions rather than silently consuming partial evidence. */
|
|
4876
|
-
export function readMotionSeamCellSidecar(dir: string, required: MotionSeamRequired): MotionCellSidecar | null {
|
|
4876
|
+
export function readMotionSeamCellSidecar(dir: string, required: MotionSeamRequired, chunkBytes = 8 * 1024 * 1024): MotionCellSidecar | null {
|
|
4877
4877
|
if (required.cells === undefined) return null;
|
|
4878
4878
|
const bad = (object: string, detail: string): never => {
|
|
4879
4879
|
refuseIfAny([{ code: 'FRAMES_SIDECAR', object, detail }]);
|
|
@@ -4882,53 +4882,53 @@ export function readMotionSeamCellSidecar(dir: string, required: MotionSeamRequi
|
|
|
4882
4882
|
const reference = required.cells;
|
|
4883
4883
|
if (reference.path !== MOTION_CELLS_FILE || !/^[a-f0-9]{64}$/.test(reference.sha256)) bad('SEAM_OVER_MOTION.required.cells', 'requires relative seam-cells.json path and a SHA-256 digest');
|
|
4884
4884
|
const path = join(dir, reference.path);
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
const
|
|
4889
|
-
if (digest !== reference.sha256) bad(path, `SHA-256 is ${digest}; required ${reference.sha256}`);
|
|
4890
|
-
let value: unknown;
|
|
4891
|
-
try { value = JSON.parse(bytes.toString('utf8')) as unknown; }
|
|
4892
|
-
catch { return bad(path, 'requires a JSON rig-parts-seam-cells/1 document'); }
|
|
4893
|
-
if (!isRecord(value) || value.spec !== 'rig-parts-seam-cells/1' || !Array.isArray(value.frames)) return bad(path, 'requires rig-parts-seam-cells/1 frames');
|
|
4885
|
+
// Streamed frame-by-frame scan: hashes file chunks without building one whole-file
|
|
4886
|
+
// string, verifies the canonical rig-parts-seam-cells/1 frame layout, and summarizes
|
|
4887
|
+
// each frame's cells as it streams through the file.
|
|
4888
|
+
const summaries = scanMotionSeamCellSidecarFile(path, reference.sha256, bad, chunkBytes);
|
|
4894
4889
|
const seen = new Set<number>();
|
|
4895
4890
|
for (const pair of required.pairs) for (const frame of pair.open_frames ?? []) {
|
|
4896
4891
|
const at = `${path} frames[${frame.cells_index}]`;
|
|
4897
|
-
const
|
|
4898
|
-
|
|
4892
|
+
const summary = Number.isSafeInteger(frame.cells_index) && frame.cells_index >= 0 ? summaries[frame.cells_index] : undefined;
|
|
4893
|
+
const read = summary?.frame;
|
|
4894
|
+
if (summary === undefined || read === undefined || seen.has(frame.cells_index) ||
|
|
4899
4895
|
read.pair !== pair.pair || read.animation !== frame.animation || read.index !== frame.index || read.time !== frame.time || read.px !== frame.px || read.cell !== frame.cell ||
|
|
4900
|
-
JSON.stringify(read.box) !== JSON.stringify(frame.box) ||
|
|
4896
|
+
JSON.stringify(read.box) !== JSON.stringify(frame.box) || summary.cellsLength !== frame.px) {
|
|
4901
4897
|
bad(at, 'requires one matching pair-frame with cells.length === gapOpen px; unavailable is not zero');
|
|
4902
4898
|
continue;
|
|
4903
4899
|
}
|
|
4904
4900
|
seen.add(frame.cells_index);
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
if (!isRecord(cell) || typeof cell.x !== 'number' || !Number.isFinite(cell.x) || typeof cell.y !== 'number' || !Number.isFinite(cell.y) ||
|
|
4908
|
-
!(cell.setupTop === null || typeof cell.setupTop === 'string' && cell.setupTop.length > 0) ||
|
|
4909
|
-
!(cell.setupUnder === null || typeof cell.setupUnder === 'string' && cell.setupUnder.length > 0) ||
|
|
4910
|
-
!['figure', 'background', 'other'].includes(String(cell.class))) bad(at, 'requires finite world centres, setup names and figure/background/other classes');
|
|
4911
|
-
else classes[cell.class as MotionOpenCell['class']]++;
|
|
4901
|
+
if (!summary.cellsValid) {
|
|
4902
|
+
bad(at, 'requires finite world centres, setup names and figure/background/other classes');
|
|
4912
4903
|
}
|
|
4904
|
+
const classes = summary.classes;
|
|
4905
|
+
// Every cell in the sidecar frame was checked and tallied during the streamed
|
|
4906
|
+
// scan before its cell array was replaced by an on-demand slice reader, so
|
|
4907
|
+
// peak string length and retained heap stay bounded by a single frame.
|
|
4913
4908
|
if (!frame.classes || !Object.values(frame.classes).every(n => Number.isSafeInteger(n) && n >= 0) ||
|
|
4914
4909
|
frame.classes.figure + frame.classes.background + frame.classes.other !== frame.px ||
|
|
4915
4910
|
frame.classes.figure !== classes.figure || frame.classes.background !== classes.background || frame.classes.other !== classes.other) {
|
|
4916
4911
|
bad(at, `inline figure/background/other counts ${JSON.stringify(frame.classes)} must sum to gapOpen px ${frame.px} and match sidecar ${JSON.stringify(classes)}`);
|
|
4917
4912
|
}
|
|
4918
4913
|
}
|
|
4919
|
-
if (seen.size !==
|
|
4914
|
+
if (seen.size !== summaries.length) {
|
|
4915
|
+
bad(path, `has ${summaries.length} frame(s); inline rows reference ${seen.size} distinct frame(s)`);
|
|
4916
|
+
}
|
|
4920
4917
|
// Every cell and its pair/frame identity was checked above after the digest matched.
|
|
4921
|
-
return
|
|
4918
|
+
return {
|
|
4919
|
+
spec: 'rig-parts-seam-cells/1',
|
|
4920
|
+
frames: summaries.map(s => s.frame),
|
|
4921
|
+
};
|
|
4922
4922
|
}
|
|
4923
4923
|
|
|
4924
4924
|
/** Publish check.json and its cell evidence together, restoring previous bytes on refusal. */
|
|
4925
|
-
export function publishMotionSeamCells(dir: string, required: MotionSeamRequired | undefined, evidence: MotionCellSidecar, publish: () => void): void {
|
|
4925
|
+
export function publishMotionSeamCells(dir: string, required: MotionSeamRequired | undefined, evidence: MotionCellSidecar, publish: () => void, onChunk?: (chunk: string, index: number) => void): void {
|
|
4926
4926
|
const path = join(dir, MOTION_CELLS_FILE), check = join(dir, 'check.json');
|
|
4927
4927
|
const previous = existsSync(path) ? readFileSync(path) : null;
|
|
4928
4928
|
const previousCheck = existsSync(check) ? readFileSync(check) : null;
|
|
4929
4929
|
try {
|
|
4930
4930
|
if (required?.cells !== undefined) {
|
|
4931
|
-
|
|
4931
|
+
writeMotionSeamCellSidecar(path, evidence, onChunk);
|
|
4932
4932
|
readMotionSeamCellSidecar(dir, required);
|
|
4933
4933
|
}
|
|
4934
4934
|
publish();
|
|
@@ -9973,3 +9973,228 @@ export function stretchLine(geo: IdleGeometry | null, path: string, problems: Pr
|
|
|
9973
9973
|
|
|
9974
9974
|
/** The compiler's `build-report/1` (`--report`) written beside `build/` on the primary packed compile (issue #1394). */
|
|
9975
9975
|
export const BUILD_REPORT_FILE = 'build-report.json';
|
|
9976
|
+
|
|
9977
|
+
/**
|
|
9978
|
+
* Issue #1406: stream `seam-cells.json` (`rig-parts-seam-cells/1`) frame by frame so peak
|
|
9979
|
+
* JS string length is a single frame while emitting the exact bytes `serializeCheckRows` writes.
|
|
9980
|
+
*/
|
|
9981
|
+
export function streamMotionSeamCellSidecar(evidence: MotionCellSidecar, sink: (chunk: string) => void): void {
|
|
9982
|
+
if (evidence.frames.length === 0) {
|
|
9983
|
+
sink(`{\n "spec": ${JSON.stringify(evidence.spec)},\n "frames": [`);
|
|
9984
|
+
sink(']\n}\n');
|
|
9985
|
+
return;
|
|
9986
|
+
}
|
|
9987
|
+
sink(`{\n "spec": ${JSON.stringify(evidence.spec)},\n "frames": [\n`);
|
|
9988
|
+
for (let i = 0; i < evidence.frames.length; i++) {
|
|
9989
|
+
const suffix = i + 1 < evidence.frames.length ? ',\n' : '\n';
|
|
9990
|
+
sink(` ${JSON.stringify(evidence.frames[i], null, 1).replaceAll('\n', '\n ')}${suffix}`);
|
|
9991
|
+
}
|
|
9992
|
+
sink(' ]\n}\n');
|
|
9993
|
+
}
|
|
9994
|
+
|
|
9995
|
+
/** Compute the SHA-256 of the streamed `seam-cells.json` chunks without building a whole-document string. */
|
|
9996
|
+
export function hashMotionSeamCellSidecar(evidence: MotionCellSidecar): string {
|
|
9997
|
+
const hash = createHash('sha256');
|
|
9998
|
+
streamMotionSeamCellSidecar(evidence, (chunk) => { hash.update(chunk); });
|
|
9999
|
+
return hash.digest('hex');
|
|
10000
|
+
}
|
|
10001
|
+
|
|
10002
|
+
/** Write `seam-cells.json` chunk by chunk through one file descriptor; `onChunk` supports mid-stream failure controls. */
|
|
10003
|
+
export function writeMotionSeamCellSidecar(path: string, evidence: MotionCellSidecar, onChunk?: (chunk: string, index: number) => void): void {
|
|
10004
|
+
const fd = openSync(path, 'w');
|
|
10005
|
+
let index = 0;
|
|
10006
|
+
try {
|
|
10007
|
+
streamMotionSeamCellSidecar(evidence, (chunk) => {
|
|
10008
|
+
writeSync(fd, chunk);
|
|
10009
|
+
onChunk?.(chunk, index++);
|
|
10010
|
+
});
|
|
10011
|
+
} finally {
|
|
10012
|
+
closeSync(fd);
|
|
10013
|
+
}
|
|
10014
|
+
}
|
|
10015
|
+
|
|
10016
|
+
interface StreamedSidecarFrameSummary {
|
|
10017
|
+
frame: MotionCellFrame;
|
|
10018
|
+
cellsLength: number | null;
|
|
10019
|
+
cellsValid: boolean;
|
|
10020
|
+
classes: { figure: number; background: number; other: number };
|
|
10021
|
+
}
|
|
10022
|
+
|
|
10023
|
+
function summarizeStreamedFrame(path: string, parsed: Record<string, unknown>, startOffset: number, endOffset: number): StreamedSidecarFrameSummary {
|
|
10024
|
+
const cells = Array.isArray(parsed.cells) ? parsed.cells : null;
|
|
10025
|
+
let cellsValid = cells !== null;
|
|
10026
|
+
const classes = { figure: 0, background: 0, other: 0 };
|
|
10027
|
+
if (cells !== null) {
|
|
10028
|
+
for (const cell of cells) {
|
|
10029
|
+
if (!isRecord(cell) || typeof cell.x !== 'number' || !Number.isFinite(cell.x) || typeof cell.y !== 'number' || !Number.isFinite(cell.y) ||
|
|
10030
|
+
!(cell.setupTop === null || typeof cell.setupTop === 'string' && cell.setupTop.length > 0) ||
|
|
10031
|
+
!(cell.setupUnder === null || typeof cell.setupUnder === 'string' && cell.setupUnder.length > 0) ||
|
|
10032
|
+
!['figure', 'background', 'other'].includes(String(cell.class))) cellsValid = false;
|
|
10033
|
+
else classes[cell.class as MotionOpenCell['class']]++;
|
|
10034
|
+
}
|
|
10035
|
+
}
|
|
10036
|
+
const frame = { ...parsed } as unknown as MotionCellFrame;
|
|
10037
|
+
Object.defineProperty(frame, 'cells', {
|
|
10038
|
+
enumerable: true,
|
|
10039
|
+
configurable: true,
|
|
10040
|
+
get(): MotionOpenCell[] {
|
|
10041
|
+
const slice = Buffer.allocUnsafe(endOffset - startOffset);
|
|
10042
|
+
const fd = openSync(path, 'r');
|
|
10043
|
+
try { readSync(fd, slice, 0, slice.length, startOffset); }
|
|
10044
|
+
finally { closeSync(fd); }
|
|
10045
|
+
const loaded = (JSON.parse(slice.toString('utf8')) as { cells: MotionOpenCell[] }).cells;
|
|
10046
|
+
Object.defineProperty(frame, 'cells', { value: loaded, enumerable: true, configurable: true, writable: true });
|
|
10047
|
+
return loaded;
|
|
10048
|
+
},
|
|
10049
|
+
});
|
|
10050
|
+
return { frame, cellsLength: cells === null ? null : cells.length, cellsValid, classes };
|
|
10051
|
+
}
|
|
10052
|
+
|
|
10053
|
+
/**
|
|
10054
|
+
* Single-pass streamed reader for `seam-cells.json`: hashes raw byte chunks without allocating
|
|
10055
|
+
* a whole-file string or buffer, verifies the canonical streamed frame layout, and summarizes
|
|
10056
|
+
* each frame's cells one frame at a time.
|
|
10057
|
+
*/
|
|
10058
|
+
function scanMotionSeamCellSidecarFile(path: string, expectedSha256: string, bad: (object: string, detail: string) => never, chunkBytes = 8 * 1024 * 1024): StreamedSidecarFrameSummary[] {
|
|
10059
|
+
let fd: number;
|
|
10060
|
+
try { fd = openSync(path, 'r'); }
|
|
10061
|
+
catch { return bad(path, 'referenced cell sidecar is missing or unreadable; unavailable is not zero'); }
|
|
10062
|
+
const hash = createHash('sha256');
|
|
10063
|
+
const step = Math.max(1, Math.floor(chunkBytes));
|
|
10064
|
+
const buf = Buffer.allocUnsafe(step);
|
|
10065
|
+
let totalBytes = 0;
|
|
10066
|
+
let state: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 = 0;
|
|
10067
|
+
let failure: 'json' | 'layout' | null = null;
|
|
10068
|
+
let carry: Buffer = Buffer.alloc(0);
|
|
10069
|
+
let carryStartOffset = 0;
|
|
10070
|
+
let frameChunks: Buffer[] = [];
|
|
10071
|
+
let frameStartOffset = 0;
|
|
10072
|
+
let frameBytes = 0;
|
|
10073
|
+
const summaries: StreamedSidecarFrameSummary[] = [];
|
|
10074
|
+
try {
|
|
10075
|
+
for (;;) {
|
|
10076
|
+
let n: number;
|
|
10077
|
+
try { n = readSync(fd, buf, 0, buf.length, totalBytes); }
|
|
10078
|
+
catch { return bad(path, 'referenced cell sidecar is missing or unreadable; unavailable is not zero'); }
|
|
10079
|
+
if (n === 0) break;
|
|
10080
|
+
const raw = buf.subarray(0, n);
|
|
10081
|
+
hash.update(raw);
|
|
10082
|
+
const rawStartOffset = totalBytes;
|
|
10083
|
+
totalBytes += n;
|
|
10084
|
+
if (failure !== null) continue;
|
|
10085
|
+
const chunk = carry.length === 0 ? raw : Buffer.concat([carry, raw]);
|
|
10086
|
+
const chunkBaseOffset = carry.length === 0 ? rawStartOffset : carryStartOffset;
|
|
10087
|
+
let lineStart = 0;
|
|
10088
|
+
while (lineStart < chunk.length && failure === null) {
|
|
10089
|
+
if (state === 4) {
|
|
10090
|
+
const runStart = lineStart;
|
|
10091
|
+
let closedFrame = false;
|
|
10092
|
+
while (lineStart < chunk.length) {
|
|
10093
|
+
const nl = chunk.indexOf(0x0a, lineStart);
|
|
10094
|
+
if (nl === -1) break;
|
|
10095
|
+
if (nl - lineStart >= 3 && chunk[lineStart] === 0x20 && chunk[lineStart + 1] === 0x20 && chunk[lineStart + 2] === 0x20) {
|
|
10096
|
+
if (frameBytes + (nl + 1 - runStart) > 0x7fff_ff00) { failure = 'layout'; closedFrame = true; break; }
|
|
10097
|
+
lineStart = nl + 1;
|
|
10098
|
+
continue;
|
|
10099
|
+
}
|
|
10100
|
+
if (lineStart > runStart) {
|
|
10101
|
+
const piece = Buffer.from(chunk.subarray(runStart, lineStart));
|
|
10102
|
+
frameChunks.push(piece);
|
|
10103
|
+
frameBytes += piece.length;
|
|
10104
|
+
}
|
|
10105
|
+
const closeLine = chunk.subarray(lineStart, nl).toString('utf8');
|
|
10106
|
+
const closeLineFileOffset = chunkBaseOffset + lineStart;
|
|
10107
|
+
lineStart = nl + 1;
|
|
10108
|
+
if (closeLine !== ' },' && closeLine !== ' }') { failure = 'layout'; closedFrame = true; break; }
|
|
10109
|
+
frameChunks.push(Buffer.from(' }'));
|
|
10110
|
+
const frameEndOffset = closeLineFileOffset + 3;
|
|
10111
|
+
const frameText = Buffer.concat(frameChunks).toString('utf8');
|
|
10112
|
+
frameChunks = [];
|
|
10113
|
+
frameBytes = 0;
|
|
10114
|
+
let parsed: unknown;
|
|
10115
|
+
try { parsed = JSON.parse(frameText) as unknown; }
|
|
10116
|
+
catch { failure = 'json'; closedFrame = true; break; }
|
|
10117
|
+
if (!isRecord(parsed) || ` ${JSON.stringify(parsed, null, 1).replaceAll('\n', '\n ')}` !== frameText) {
|
|
10118
|
+
failure = 'layout';
|
|
10119
|
+
closedFrame = true;
|
|
10120
|
+
break;
|
|
10121
|
+
}
|
|
10122
|
+
summaries.push(summarizeStreamedFrame(path, parsed, frameStartOffset, frameEndOffset));
|
|
10123
|
+
state = closeLine === ' },' ? 3 : 5;
|
|
10124
|
+
closedFrame = true;
|
|
10125
|
+
break;
|
|
10126
|
+
}
|
|
10127
|
+
if (!closedFrame) {
|
|
10128
|
+
if (lineStart > runStart) {
|
|
10129
|
+
const piece = Buffer.from(chunk.subarray(runStart, lineStart));
|
|
10130
|
+
frameChunks.push(piece);
|
|
10131
|
+
frameBytes += piece.length;
|
|
10132
|
+
if (frameBytes > 0x7fff_ff00) failure = 'layout';
|
|
10133
|
+
}
|
|
10134
|
+
break;
|
|
10135
|
+
}
|
|
10136
|
+
} else {
|
|
10137
|
+
const nl = chunk.indexOf(0x0a, lineStart);
|
|
10138
|
+
if (nl === -1) break;
|
|
10139
|
+
const lineFileOffset = chunkBaseOffset + lineStart;
|
|
10140
|
+
const line = chunk.subarray(lineStart, nl).toString('utf8');
|
|
10141
|
+
lineStart = nl + 1;
|
|
10142
|
+
if (state === 0) {
|
|
10143
|
+
if (line === '{') state = 1;
|
|
10144
|
+
else failure = 'layout';
|
|
10145
|
+
} else if (state === 1) {
|
|
10146
|
+
if (line === ' "spec": "rig-parts-seam-cells/1",') state = 2;
|
|
10147
|
+
else failure = 'layout';
|
|
10148
|
+
} else if (state === 2) {
|
|
10149
|
+
if (line === ' "frames": []') state = 6;
|
|
10150
|
+
else if (line === ' "frames": [') state = 3;
|
|
10151
|
+
else failure = 'layout';
|
|
10152
|
+
} else if (state === 3) {
|
|
10153
|
+
if (line === ' {') {
|
|
10154
|
+
frameChunks = [Buffer.from(' {\n')];
|
|
10155
|
+
frameBytes = 4;
|
|
10156
|
+
frameStartOffset = lineFileOffset;
|
|
10157
|
+
state = 4;
|
|
10158
|
+
} else failure = 'layout';
|
|
10159
|
+
} else if (state === 5) {
|
|
10160
|
+
if (line === ' ]') state = 6;
|
|
10161
|
+
else failure = 'layout';
|
|
10162
|
+
} else if (state === 6) {
|
|
10163
|
+
if (line === '}') state = 7;
|
|
10164
|
+
else failure = 'layout';
|
|
10165
|
+
} else {
|
|
10166
|
+
failure = 'layout';
|
|
10167
|
+
}
|
|
10168
|
+
}
|
|
10169
|
+
}
|
|
10170
|
+
if (failure === null) {
|
|
10171
|
+
if (lineStart < chunk.length) {
|
|
10172
|
+
carry = Buffer.from(chunk.subarray(lineStart));
|
|
10173
|
+
carryStartOffset = chunkBaseOffset + lineStart;
|
|
10174
|
+
if (carry.length > 4 * 1024 * 1024) failure = 'layout';
|
|
10175
|
+
} else {
|
|
10176
|
+
carry = Buffer.alloc(0);
|
|
10177
|
+
carryStartOffset = totalBytes;
|
|
10178
|
+
}
|
|
10179
|
+
}
|
|
10180
|
+
}
|
|
10181
|
+
} finally {
|
|
10182
|
+
closeSync(fd);
|
|
10183
|
+
}
|
|
10184
|
+
const digest = hash.digest('hex');
|
|
10185
|
+
if (digest !== expectedSha256) bad(path, `SHA-256 is ${digest}; required ${expectedSha256}`);
|
|
10186
|
+
if (failure !== null || state !== 7 || carry.length !== 0) {
|
|
10187
|
+
if (totalBytes <= 4 * 1024 * 1024) {
|
|
10188
|
+
let value: unknown;
|
|
10189
|
+
try { value = JSON.parse(readFileSync(path, 'utf8')) as unknown; }
|
|
10190
|
+
catch { return bad(path, 'requires a JSON rig-parts-seam-cells/1 document'); }
|
|
10191
|
+
if (!isRecord(value) || value.spec !== 'rig-parts-seam-cells/1' || !Array.isArray(value.frames)) {
|
|
10192
|
+
return bad(path, 'requires rig-parts-seam-cells/1 frames');
|
|
10193
|
+
}
|
|
10194
|
+
return bad(path, 'requires canonical rig-parts-seam-cells/1 streamed frame layout');
|
|
10195
|
+
}
|
|
10196
|
+
if (failure === 'json') return bad(path, 'requires a JSON rig-parts-seam-cells/1 document');
|
|
10197
|
+
return bad(path, 'requires canonical rig-parts-seam-cells/1 streamed frame layout');
|
|
10198
|
+
}
|
|
10199
|
+
return summaries;
|
|
10200
|
+
}
|
package/src/configwrite.ts
CHANGED
|
@@ -17,6 +17,10 @@ import { PartsError } from './errors.ts';
|
|
|
17
17
|
import { parseConfig, parseEarlyConfig, parseProposalSections } from './config.ts';
|
|
18
18
|
import type { ConfigEdit } from './meshdraft.ts';
|
|
19
19
|
|
|
20
|
+
/** Required point fields and optional shape fields of `meshes.<part>.contour.bust`, in the shorthand order `src/config.ts` validates (issues #475, #1428). */
|
|
21
|
+
const BUST_LANDMARK_FIELDS = ['apex_r', 'apex_l', 'cleavage'] as const;
|
|
22
|
+
export const BUST_SHAPE_FIELDS = ['alpha', 'clearance', 'bone_r', 'bone_l', 'spacing'] as const;
|
|
23
|
+
|
|
20
24
|
export type ConfigJson = null | boolean | number | string | ConfigJson[] | ConfigObject;
|
|
21
25
|
export interface ConfigObject { [key: string]: ConfigJson }
|
|
22
26
|
export type ConfigWritePatch =
|
|
@@ -24,9 +28,17 @@ export type ConfigWritePatch =
|
|
|
24
28
|
| { kind: 'neck-unit'; config: CharacterConfig }
|
|
25
29
|
| { kind: 'head-box'; head_box: HeadBoxProposal['head_box'] }
|
|
26
30
|
| { kind: 'assemble-plan'; plan: PlanProposal['plan']; extend_below_crop: PlanProposal['extend_below_crop'] }
|
|
27
|
-
| { kind: 'proposal'; proposal: Proposal; sections: typeof PROPOSAL_CONFIG_SECTIONS }
|
|
31
|
+
| { kind: 'proposal'; proposal: Proposal; sections: typeof PROPOSAL_CONFIG_SECTIONS; bustShape?: PendingBustShape }
|
|
28
32
|
/** Issues #671/#679: add unattached, resolvable entries; append skip explanations to the proposal's notes for the caller to print. */
|
|
29
|
-
| { kind: 'proposal-missing'; proposal: Proposal; parts: ReadonlyArray<{ name: string; from: string }> }
|
|
33
|
+
| { kind: 'proposal-missing'; proposal: Proposal; parts: ReadonlyArray<{ name: string; from: string }> }
|
|
34
|
+
/** `bust-landmarks --write-config` (issue #1382): set or remove named shape fields of one part's existing
|
|
35
|
+
* `meshes.<part>.contour.bust`; a field with no value is removed, every other key is kept where it is. */
|
|
36
|
+
| { kind: 'bust-shape'; part: string; fields: ReadonlyArray<{ key: BustShapeKey; value?: number | string }> };
|
|
37
|
+
/** The `contour.bust` fields the landmarks file does not carry, the only ones a `bust-shape` patch writes. */
|
|
38
|
+
export type BustShapeKey = (typeof BUST_SHAPE_FIELDS)[number];
|
|
39
|
+
/** A reviewed shape `bust-landmarks` left pending in its sidecar (issue #1382): `propose --write-config` writes it
|
|
40
|
+
* onto the drafted chest carrier's `contour.bust`, after the three points, in the shorthand's key order. */
|
|
41
|
+
export interface PendingBustShape { part: string; fields: Partial<Record<BustShapeKey, number | string>> }
|
|
30
42
|
export interface ConfigWriteChange {
|
|
31
43
|
path: string;
|
|
32
44
|
kind: 'added' | 'replaced' | 'removed';
|
|
@@ -148,6 +160,38 @@ export function mergeConfigProposal(raw: unknown, patch: ConfigWritePatch, recei
|
|
|
148
160
|
if (patch.proposal[key] !== undefined) {
|
|
149
161
|
const previous = config[key];
|
|
150
162
|
config[key] = clone(patch.proposal[key], `proposal.${key}`);
|
|
163
|
+
if (key === 'meshes' && (object(previous) || patch.bustShape !== undefined) && object(config.meshes)) {
|
|
164
|
+
const carriers: string[] = [];
|
|
165
|
+
for (const [part, mesh] of Object.entries(config.meshes)) {
|
|
166
|
+
if (!object(mesh) || !object(mesh.contour) || !object(mesh.contour.bust)) continue;
|
|
167
|
+
carriers.push(part);
|
|
168
|
+
const draftedBust = mesh.contour.bust;
|
|
169
|
+
const prevMesh = object(previous) && own(previous, part) ? previous[part] : undefined;
|
|
170
|
+
const prevBust = object(prevMesh) && object(prevMesh.contour) && object(prevMesh.contour.bust) ? prevMesh.contour.bust : null;
|
|
171
|
+
const mergedBust: ConfigObject = {};
|
|
172
|
+
for (const k of BUST_LANDMARK_FIELDS) if (own(draftedBust, k)) mergedBust[k] = draftedBust[k];
|
|
173
|
+
// A pending reviewed shape (issue #1382) is the act's value for its fields; the rest keep what the config declares.
|
|
174
|
+
const pending = patch.bustShape?.part === part ? patch.bustShape.fields : undefined;
|
|
175
|
+
for (const k of BUST_SHAPE_FIELDS) {
|
|
176
|
+
const value = pending?.[k];
|
|
177
|
+
if (value !== undefined) mergedBust[k] = value;
|
|
178
|
+
else if (prevBust !== null && own(prevBust, k)) mergedBust[k] = prevBust[k];
|
|
179
|
+
}
|
|
180
|
+
mesh.contour.bust = mergedBust;
|
|
181
|
+
}
|
|
182
|
+
for (const [oldPart, prevMesh] of Object.entries(object(previous) ? previous : {})) {
|
|
183
|
+
if (carriers.includes(oldPart) || !object(prevMesh) || !object(prevMesh.contour) || !object(prevMesh.contour.bust)) continue;
|
|
184
|
+
const prevBust = prevMesh.contour.bust;
|
|
185
|
+
const dropped = BUST_SHAPE_FIELDS.filter((k) => own(prevBust, k));
|
|
186
|
+
if (dropped.length === 0) continue;
|
|
187
|
+
if (Array.isArray(patch.proposal.notes) && patch.proposal.notes.some((n) => n.startsWith(`${oldPart}: contour bust omitted for the declared reason: `))) continue;
|
|
188
|
+
const why = carriers.length > 0 ? `chest carrier is now ${carriers.join(', ')}` : `${oldPart} is no longer the chest carrier`;
|
|
189
|
+
const line = `${oldPart}: contour.bust shape field(s) ${dropped.join(', ')} dropped — ${why}`;
|
|
190
|
+
if (Array.isArray(patch.proposal.notes) && !Object.isFrozen(patch.proposal.notes) && !patch.proposal.notes.includes(line)) {
|
|
191
|
+
patch.proposal.notes.push(line);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
151
195
|
if (!equal(previous, config[key])) edits.push({ path: [key], value: config[key] });
|
|
152
196
|
}
|
|
153
197
|
}
|
|
@@ -231,7 +275,24 @@ export function mergeConfigProposal(raw: unknown, patch: ConfigWritePatch, recei
|
|
|
231
275
|
}
|
|
232
276
|
return { config, changes: added, edits };
|
|
233
277
|
}
|
|
234
|
-
|
|
278
|
+
case 'bust-shape': {
|
|
279
|
+
const at = `${field('config.meshes', patch.part)}.contour.bust`;
|
|
280
|
+
const meshes = config.meshes;
|
|
281
|
+
const mesh = object(meshes) && own(meshes, patch.part) ? meshes[patch.part] : undefined;
|
|
282
|
+
const contour = object(mesh) ? mesh.contour : undefined;
|
|
283
|
+
const bust = object(contour) ? contour.bust : undefined;
|
|
284
|
+
if (!object(contour) || !object(bust)) return refuse(at, 'is absent or not an object; an existing contour.bust is required before its shape fields are written');
|
|
285
|
+
const next = clone(bust, at) as ConfigObject;
|
|
286
|
+
for (const { key, value } of patch.fields) {
|
|
287
|
+
if (value === undefined) delete next[key];
|
|
288
|
+
else next[key] = value;
|
|
289
|
+
}
|
|
290
|
+
contour.bust = next;
|
|
291
|
+
// This patch owns the one bust object, never the mesh or its other contour fields.
|
|
292
|
+
if (!equal(bust as ConfigObject, next)) edits.push({ path: ['meshes', patch.part, 'contour', 'bust'], value: next });
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
default: return refuse('write-config', 'has no supported operation; edited-part-receipt, neck-unit, head-box, assemble-plan, proposal, proposal-missing or bust-shape is required');
|
|
235
296
|
}
|
|
236
297
|
return { config, changes: changes(before, config), edits };
|
|
237
298
|
}
|
package/src/setuppainting.ts
CHANGED
|
@@ -184,13 +184,56 @@ export function setupPaintingLine(
|
|
|
184
184
|
...(noLimit ? { reason: 'a region has no declared max_pixels; it is measured as SKIP, never PASS' } : {}) };
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
+
/** Issue #1421: the named warning for a region whose count is mostly pixels no setup piece draws. A warning, never a bar. */
|
|
188
|
+
export const SETUP_PAINTING_UNCOVERED_WARNING = 'SETUP_PAINTING_MOSTLY_UNCOVERED';
|
|
189
|
+
export interface SetupPaintingUncovered {
|
|
190
|
+
region: string;
|
|
191
|
+
/** The region's `(uncovered)` slot row: counted pixels no setup piece draws (0 when the row is absent). */
|
|
192
|
+
uncovered: number;
|
|
193
|
+
/** The region's `pixel_count`: every counted pixel, owned or uncovered. */
|
|
194
|
+
counted: number;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Issue #1421: the regions whose counted pixels are mostly uncovered, read off
|
|
199
|
+
* the line alone, so every figure it names is already in check.json
|
|
200
|
+
* (`regions[].pixel_count` and the `(uncovered)` row of `regions[].slots`).
|
|
201
|
+
* "Mostly" is a strict majority, `2 * uncovered > counted`: exactly half does
|
|
202
|
+
* not warn, and a region that counts no pixel does not warn. It applies only
|
|
203
|
+
* when neither `figure_mask` nor `backdrop` is declared. With a figure mask a
|
|
204
|
+
* region counts mask pixels only, so its uncovered pixels are missing figure;
|
|
205
|
+
* with a backdrop a painted background within `rgb_tolerance` of the plate is
|
|
206
|
+
* not counted, so its uncovered pixels are painting that differs from the
|
|
207
|
+
* plate. Without either the count cannot tell painted background from missing
|
|
208
|
+
* figure, and that is what the warning says. The verdict never reads it.
|
|
209
|
+
*/
|
|
210
|
+
export function setupPaintingUncovered(line: SetupPaintingLine): SetupPaintingUncovered[] {
|
|
211
|
+
if (line.figure_mask !== undefined || line.backdrop !== undefined) return [];
|
|
212
|
+
return line.regions.flatMap(r => {
|
|
213
|
+
const uncovered = r.slots.find(s => s.slot === '(uncovered)')?.pixel_count ?? 0;
|
|
214
|
+
return 2 * uncovered > r.pixel_count ? [{ region: r.name, uncovered, counted: r.pixel_count }] : [];
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** How many regions {@link setupPaintingUncovered} warns about; 0 for an observation without regions. */
|
|
219
|
+
export function setupPaintingWarningCount(line: SetupPaintingObservation | undefined): number {
|
|
220
|
+
return line === undefined || !('regions' in line) ? 0 : setupPaintingUncovered(line).length;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** The console line for one {@link SetupPaintingUncovered}: the rule, the region, uncovered of counted, and the two declarations that make the limit bind the figure. */
|
|
224
|
+
export function setupPaintingUncoveredText(w: SetupPaintingUncovered): string {
|
|
225
|
+
return `${SETUP_PAINTING_LINE}: WARN ${SETUP_PAINTING_UNCOVERED_WARNING} region "${w.region}" — ${w.uncovered} of ${w.counted} counted pixels are uncovered (no setup piece draws them), more than half; without a figure mask or a backdrop this count cannot tell painted background from missing figure, so the region's limit mostly measures pixels the rig does not draw. To make it bind the figure, declare setup_painting.figure_mask (the figure's support on the painting grid) or setup_painting.backdrop (the opaque plate behind the figure); a warning, not a bar`;
|
|
226
|
+
}
|
|
227
|
+
|
|
187
228
|
export function setupPaintingLines(line: SetupPaintingObservation): string[] {
|
|
188
229
|
if (!('regions' in line)) return [`${SETUP_PAINTING_LINE}: SKIP — ${line.reason}`];
|
|
230
|
+
const warned = setupPaintingUncovered(line);
|
|
189
231
|
return [`${SETUP_PAINTING_LINE}: ${line.status}${line.reason === undefined ? '' : ` — ${line.reason}`}; ${line.registration}; ${line.compositing}`,
|
|
190
232
|
...(line.outside_figure === undefined ? [] : [`${SETUP_PAINTING_LINE}: slot "(uncovered)" outside figure mask — pixelcount ${line.outside_figure.pixel_count}; UNBARRED, outside every region limit`]),
|
|
191
233
|
...(line.outside_figure_owned === undefined ? [] : [`${SETUP_PAINTING_LINE}: owned pixels outside figure mask — pixelcount ${line.outside_figure_owned.pixel_count}; UNBARRED, outside every region limit`]),
|
|
192
234
|
...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}`,
|
|
193
|
-
...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)'}`)
|
|
235
|
+
...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)'}`),
|
|
236
|
+
...warned.filter(w => w.region === r.name).map(setupPaintingUncoveredText)])];
|
|
194
237
|
}
|
|
195
238
|
|
|
196
239
|
/** Resolve an authored setup image against the requirements file that names it. */
|