@rig-c/parts 1.54.0 → 1.55.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 +40 -7
- package/docs/AUTHORING.md +60 -11
- package/docs/STABILITY.md +6 -5
- package/package.json +1 -1
- package/src/assemble.ts +568 -51
- package/src/build.ts +91 -11
- package/src/check.ts +43 -12
- package/src/cloth.ts +10 -3
- package/src/config.ts +27 -6
- package/src/parts.ts +83 -45
- package/src/propose.ts +10 -2
- package/src/remesh.ts +306 -6
- package/src/retune.ts +25 -3
- package/src/rig.ts +18 -6
package/src/build.ts
CHANGED
|
@@ -71,8 +71,8 @@ import {
|
|
|
71
71
|
splitSchedule,
|
|
72
72
|
untestedIntervals,
|
|
73
73
|
} from './autoreplay.ts';
|
|
74
|
-
import { besideIdleLine, checkSummaryLine, CLOTH_LINE, type ClothLine, clothWarnText, frameRuns, MOTION_SEAM_LINE, type MotionSeamLine, type MotionSeamPlant, motionSeamWarnText, FOLD_LINE, type FoldsLine, LEVEL_LINE, type LevelLine, LIMB_LINE, type LimbLine, STRESS_LINE, SWEEP_LINE, type SweepLine, buildGateLines, causeLines, environmentLine, IDLE_FPS, IDLE_MAX_PX, maxRgbDiff, REQUIREMENTS_DIR, type CheckReport, type PackLine, DEFAULT_PACK_SHAPE, DEFAULT_PAGE_EDGES, GATE_PROFILE, JUDGEMENT_LINES, type JudgementLine, packedBuildArgs, packedBuildLabel, type PackMode, readCheckEnvironment, type PackShape, type PageEdges, readFrameSet, rigcFailed, rigcIdentity, rigcRanClause, REPORTED_LINES, type ReportedLine, type RigcRunner, runCheck, SEAM_DIR, SEAM_MEAN_BAR, seamPairText, seamRigPxText, SOURCE_LINE, SEAM_PX_BAR, SEAM_PX_LEVEL, SEAM_PX_LEVEL_HIGH, SPINEBOY_YARDSTICK, STILL_DIR } from './check.ts';
|
|
75
|
-
import { type Cut, type Extend, type Limb,
|
|
74
|
+
import { besideIdleLine, checkSummaryLine, inputFileRecord, type InputFileRecord, CLOTH_LINE, type ClothLine, clothWarnText, frameRuns, MOTION_SEAM_LINE, type MotionSeamLine, type MotionSeamPlant, motionSeamWarnText, FOLD_LINE, type FoldsLine, LEVEL_LINE, type LevelLine, LIMB_LINE, type LimbLine, STRESS_LINE, SWEEP_LINE, type SweepLine, buildGateLines, causeLines, environmentLine, IDLE_FPS, IDLE_MAX_PX, maxRgbDiff, REQUIREMENTS_DIR, type CheckReport, type PackLine, DEFAULT_PACK_SHAPE, DEFAULT_PAGE_EDGES, GATE_PROFILE, JUDGEMENT_LINES, type JudgementLine, packedBuildArgs, packedBuildLabel, type PackMode, readCheckEnvironment, type PackShape, type PageEdges, readFrameSet, rigcFailed, rigcIdentity, rigcRanClause, REPORTED_LINES, type ReportedLine, type RigcRunner, runCheck, SEAM_DIR, SEAM_MEAN_BAR, seamPairText, seamRigPxText, SOURCE_LINE, SEAM_PX_BAR, SEAM_PX_LEVEL, SEAM_PX_LEVEL_HIGH, SPINEBOY_YARDSTICK, STILL_DIR } from './check.ts';
|
|
75
|
+
import { type Cut, type Extend, type Limb, loadConfigAndAnimations, loadConfigWithBytes, loadEarlyConfig, type Patch, type PlanEntry } from './config.ts';
|
|
76
76
|
import { failLine, PartsError, type Problem, refuseIfAny } from './errors.ts';
|
|
77
77
|
import type { MeshQualityReport, MotionSchedule } from 'rig-c/mesh';
|
|
78
78
|
import { encodeGif } from './gif.ts';
|
|
@@ -83,6 +83,10 @@ import { placeBoneEntriesForSkeleton, poseBoneEntriesForDrawn, REGISTER_OFFSET_B
|
|
|
83
83
|
import { type AlternatePartsRecord, type PartRecord, readParts, type RecompositeRecord, type SingleRunPad, tagOf, writeParts } from './parts.ts';
|
|
84
84
|
import { encodePngBytes, readPng, writePng } from './raster/png.ts';
|
|
85
85
|
import type { Raster } from './raster/types.ts';
|
|
86
|
+
import { type Mask, newMask } from './raster/types.ts';
|
|
87
|
+
import { type OtherLimbs, splitLines, type SplitCount } from './assemble.ts';
|
|
88
|
+
import type { BoneEntry } from './config.ts';
|
|
89
|
+
import { OPAQUE_ALPHA_ABOVE } from './layers.ts';
|
|
86
90
|
import { readRequirements, type RequirementLine, summaryText } from './requirements.ts';
|
|
87
91
|
import { type AutoMeshReport, buildRig, DEFAULT_IDLE_KEYS, type FaceAxis, type IdleKeys, type MeshReport, type RigCommand, rigJsonText, type RigOutput, type RigSpec, SETS_FILE, type StrayCleared, type TurnRow } from './rig.ts';
|
|
88
92
|
import { KEYPOINT_NAMES, type KeypointName, type PosePoints } from './skeleton.ts';
|
|
@@ -172,6 +176,13 @@ export interface AssembleStageInput {
|
|
|
172
176
|
* shows the island count go red under it.
|
|
173
177
|
*/
|
|
174
178
|
setIslands?: 'joints' | 'all';
|
|
179
|
+
/**
|
|
180
|
+
* How a subset set's limb parts share a layer of one island with a limb the set does not carry (issue #609):
|
|
181
|
+
* `"nearest"` (the default, the only one the CLI runs) by the nearest segment line in the set's pose, the other limb
|
|
182
|
+
* placed by the set's skeleton ({@link OtherLimbs}); `"connectivity"` every pixel on the set's limb, the rule before
|
|
183
|
+
* #609 — kept for the selftest's control that shows the second-limb share go red under it.
|
|
184
|
+
*/
|
|
185
|
+
setSplit?: 'nearest' | 'connectivity';
|
|
175
186
|
}
|
|
176
187
|
|
|
177
188
|
/** Where the assemble stage writes: `parts.json`, the directory of part PNGs, the recomposite, and its error map. */
|
|
@@ -327,7 +338,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
327
338
|
}
|
|
328
339
|
|
|
329
340
|
const altProblems: Problem[] = [];
|
|
330
|
-
const altBuilt: Array<{ record: AlternatePartsRecord; images: Array<{ name: string; image: Raster }>; excluded: ExcludedCount[]; islands: IslandCount[] }> = [];
|
|
341
|
+
const altBuilt: Array<{ record: AlternatePartsRecord; images: Array<{ name: string; image: Raster }>; excluded: ExcludedCount[]; islands: IslandCount[]; splits: SplitCount[] }> = [];
|
|
331
342
|
const baseSlots = result.parts.parts.map((p) => p.name);
|
|
332
343
|
for (const alt of mergedAlts) {
|
|
333
344
|
if (alt.source === undefined || alt.full === undefined) {
|
|
@@ -470,6 +481,16 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
470
481
|
let altBones = fields.bones;
|
|
471
482
|
let altDrawnLength: Record<string, number> | undefined;
|
|
472
483
|
let altRegistration: { offset: [number, number]; scale: number } | undefined;
|
|
484
|
+
// Issue #588: a subset set that names one limb side keeps, of a layer that holds more than one island, the one its joints fall on.
|
|
485
|
+
const altIslands = alt.parts === undefined || input.setIslands === 'all' ? [] : setIslandSources(fields.limbs ?? {}, altLimbs);
|
|
486
|
+
// Issue #609: the limbs of those layers the set does not carry — the other leg of a two-leg layer.
|
|
487
|
+
const otherLimbs: Record<string, Limb> =
|
|
488
|
+
input.setSplit === 'connectivity'
|
|
489
|
+
? {}
|
|
490
|
+
: Object.fromEntries(Object.entries(fields.limbs ?? {}).filter(([ln, l]) => !(ln in altLimbs) && l.segments.some((sg) => altIslands.includes(sg.from))));
|
|
491
|
+
const otherBones = new Set(Object.values(otherLimbs).flatMap((l) => l.segments.map((sg) => sg.bone)));
|
|
492
|
+
// The bones the set places: by its skeleton, or by the angles it states; every other bone keeps the base's place unless an ancestor moved.
|
|
493
|
+
const setPlaced = new Set<string>();
|
|
473
494
|
if (Object.keys(altLimbs).length > 0 && fields.bones !== undefined && (altSkeleton !== undefined || alt.drawn !== undefined)) {
|
|
474
495
|
const coveredLimbBones = new Set(Object.values(altLimbs).flatMap((l) => l.segments.map((sg) => sg.bone)));
|
|
475
496
|
const limbDrawn: Record<string, number> = {};
|
|
@@ -510,19 +531,23 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
510
531
|
}
|
|
511
532
|
altRegistration = { offset: [reg.offset[0], reg.offset[1]], scale: reg.scale };
|
|
512
533
|
altDrawnLength = skeletonDrawnLength(fields.bones, coveredLimbBones, joints);
|
|
513
|
-
|
|
534
|
+
// Issue #609: the other limb of a shared layer stands at the set's own keypoints too, so its segment line is the
|
|
535
|
+
// set's; the skeleton file holds them. Only its place widens: drawn and drawnLength stay the covered bones'.
|
|
536
|
+
const placed = new Set([...coveredLimbBones, ...[...otherBones].filter((b) => SKELETON_LIMB_BONES.some(([t]) => t === b))]);
|
|
537
|
+
for (const b of placed) if (SKELETON_LIMB_BONES.some(([t]) => t === b)) setPlaced.add(b);
|
|
538
|
+
altBones = placeBoneEntriesForSkeleton(fields.bones, placed, joints, limbDrawn);
|
|
514
539
|
} else {
|
|
515
540
|
altBones = poseBoneEntriesForDrawn(fields.bones, limbDrawn);
|
|
516
541
|
}
|
|
542
|
+
for (const b of Object.keys(limbDrawn)) setPlaced.add(b);
|
|
517
543
|
}
|
|
544
|
+
const altOthers = Object.keys(otherLimbs).length === 0 ? undefined : otherLimbsOf(otherLimbs, setPlaced, fields.bones ?? [], result.images, result.parts.rig_size, altSkeleton !== undefined ? 'skeleton' : alt.drawn !== undefined ? 'drawn' : 'none');
|
|
518
545
|
// Issue #587: a subset set's limb part takes nothing a base part it does not replace covers at setup.
|
|
519
546
|
const [exW, exH] = result.parts.rig_size;
|
|
520
547
|
const altExclude =
|
|
521
548
|
alt.parts === undefined || input.setExclusion === 'none'
|
|
522
549
|
? []
|
|
523
550
|
: setExclusions(result.images, exW, exH, Object.values(altLimbs).flatMap((l) => l.segments.map((sg) => sg.part)), new Set([...coveredSet, ...hidesSet]));
|
|
524
|
-
// Issue #588: a subset set that names one limb side keeps, of a layer that holds more than one island, the one its joints fall on.
|
|
525
|
-
const altIslands = alt.parts === undefined || input.setIslands === 'all' ? [] : setIslandSources(fields.limbs ?? {}, altLimbs);
|
|
526
551
|
let altRes: ReturnType<typeof assemble>;
|
|
527
552
|
try {
|
|
528
553
|
altRes = assemble({
|
|
@@ -545,6 +570,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
545
570
|
projectRule: input.project,
|
|
546
571
|
...(altExclude.length === 0 ? {} : { exclude: altExclude }),
|
|
547
572
|
...(altIslands.length === 0 ? {} : { limbIslands: altIslands }),
|
|
573
|
+
...(altOthers === undefined ? {} : { otherLimbs: altOthers }),
|
|
548
574
|
});
|
|
549
575
|
} catch (err) {
|
|
550
576
|
if (err instanceof PartsError) {
|
|
@@ -594,6 +620,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
594
620
|
images: keptImages,
|
|
595
621
|
excluded: altRes.excluded,
|
|
596
622
|
islands: altRes.islands,
|
|
623
|
+
splits: altRes.splits,
|
|
597
624
|
});
|
|
598
625
|
}
|
|
599
626
|
refuseIfAny(altProblems);
|
|
@@ -657,11 +684,58 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
657
684
|
for (const d of result.drift) log(driftLine(d));
|
|
658
685
|
// Issue #588: per subset set, one line per limb part cut from a layer of more than one island, then (issue #587) one
|
|
659
686
|
// per limb part and base part over it that took a pixel. None otherwise.
|
|
660
|
-
|
|
687
|
+
// Issue #609: then one per limb part cut from a layer of one island that also holds a limb the set does not carry.
|
|
688
|
+
for (const b of altBuilt) for (const l of [...islandLines(b.record.name, b.islands), ...splitLines(b.record.name, b.splits), ...excludedLines(b.record.name, b.excluded)]) log(l);
|
|
661
689
|
log(`wrote ${outs.partsJson}, ${result.images.length} PNG(s) in ${outs.partsDir}, ${outs.recomposite}, ${outs.errorMap} (uncovered error px red, covered error px blue, the painting grey)${figurePath === null ? '' : `, ${figurePath} (the figure, white, the recomposite was read inside)`}`);
|
|
662
690
|
return result;
|
|
663
691
|
}
|
|
664
692
|
|
|
693
|
+
/**
|
|
694
|
+
* Issue #609: what a subset set says of the limbs of its shared layers it does not carry ({@link OtherLimbs}). A bone
|
|
695
|
+
* is placed by the set when the set places it (`setPlaced`: its skeleton's table bones, its drawn bones) or an
|
|
696
|
+
* ancestor of it — the rule `placeBoneEntriesForSkeleton` and `poseBoneEntriesForDrawn` move a child by; any other
|
|
697
|
+
* bone keeps the base's place, which is not the set's, so a limb with one is `unposed`. The base art is each limb's
|
|
698
|
+
* base parts at alpha above `OPAQUE_ALPHA_ABOVE`, at their `parts.json` x, y.
|
|
699
|
+
*/
|
|
700
|
+
function otherLimbsOf(
|
|
701
|
+
limbs: Readonly<Record<string, Limb>>,
|
|
702
|
+
setPlaced: ReadonlySet<string>,
|
|
703
|
+
bones: readonly BoneEntry[],
|
|
704
|
+
base: ReadonlyArray<{ record: PartRecord; image: Raster }>,
|
|
705
|
+
rigSize: readonly [number, number],
|
|
706
|
+
pose: OtherLimbs['pose'],
|
|
707
|
+
): OtherLimbs {
|
|
708
|
+
const parent = new Map<string, string>();
|
|
709
|
+
for (const b of bones) {
|
|
710
|
+
if ('chain' in b) b.points.forEach((_, k) => parent.set(`${b.chain}${k}`, k === 0 ? b.parent : `${b.chain}${k - 1}`));
|
|
711
|
+
else parent.set(b.name, b.parent);
|
|
712
|
+
}
|
|
713
|
+
const placed = (b: string): boolean => {
|
|
714
|
+
for (let at: string | undefined = b, n = 0; at !== undefined && n <= parent.size; at = parent.get(at), n++) if (setPlaced.has(at)) return true;
|
|
715
|
+
return false;
|
|
716
|
+
};
|
|
717
|
+
const [W, H] = rigSize;
|
|
718
|
+
const unposed: Record<string, string[]> = {};
|
|
719
|
+
const baseArt: Record<string, Mask> = {};
|
|
720
|
+
for (const [ln, l] of Object.entries(limbs)) {
|
|
721
|
+
unposed[ln] = l.segments.map((sg) => sg.bone).filter((b) => !placed(b));
|
|
722
|
+
const names = new Set(l.segments.map((sg) => sg.part));
|
|
723
|
+
const m = newMask(W, H);
|
|
724
|
+
for (const { record, image } of base) {
|
|
725
|
+
if (!names.has(record.name)) continue;
|
|
726
|
+
for (let y = 0; y < image.height; y++) {
|
|
727
|
+
for (let x = 0; x < image.width; x++) {
|
|
728
|
+
const rx = record.x + x;
|
|
729
|
+
const ry = record.y + y;
|
|
730
|
+
if (rx >= 0 && ry >= 0 && rx < W && ry < H && image.data[(y * image.width + x) * 4 + 3] > OPAQUE_ALPHA_ABOVE) m.data[ry * W + rx] = 1;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
baseArt[ln] = m;
|
|
735
|
+
}
|
|
736
|
+
return { limbs, unposed, baseArt, drawOrder: base.map((q) => q.record.name), pose };
|
|
737
|
+
}
|
|
738
|
+
|
|
665
739
|
/**
|
|
666
740
|
* The line `assemble` prints under `one run:` when the file was padded (issue
|
|
667
741
|
* #366): its size, the square and the four margins, and that `parts.json`'s
|
|
@@ -1396,6 +1470,8 @@ export interface CheckStageInput {
|
|
|
1396
1470
|
requirements?: string;
|
|
1397
1471
|
/** The path `check.json`'s `requirements.file` records (issue #556): `config.requirements` as declared when build read it from the config; absent, `requirements` as given. */
|
|
1398
1472
|
requirementsAs?: string;
|
|
1473
|
+
/** The config `build` read (issue #607), recorded as `check.json`'s `config`; absent, no key is written, as `check` alone writes none. */
|
|
1474
|
+
config?: InputFileRecord;
|
|
1399
1475
|
/**
|
|
1400
1476
|
* `check --seam-pairs` (issue #202): split the seam's counted pixels by pair
|
|
1401
1477
|
* and draw each pair's picture even when the bar passes. A failing seam is
|
|
@@ -1555,7 +1631,7 @@ export function sweepCheckLines(line: SweepLine, steps: ReadonlyMap<string, { le
|
|
|
1555
1631
|
return [
|
|
1556
1632
|
`${SWEEP_LINE}: ${line.status} — ${line.joints.length} joint(s) bent to their declared range's ends and middle${line.physics_left_out === 0 ? '' : `, ${line.physics_left_out} physics constraint(s) left out`}; at each, the pose against the same pose with the joint's own art drawn under the limb, on the rest-pose seam's bar (mean |d| <= ${line.bar.mean.toFixed(1)}, <= ${line.bar.rig_px_over_40} rig px over ${line.bar.level})${s === null ? '' : ` at frame scale ${s}`}`,
|
|
1557
1633
|
...line.joints.flatMap((j) => {
|
|
1558
|
-
const head = `joint "${j.joint}" (${j.limb}, "${j.part}" on "${j.bone}", range [${j.range.join(', ')}]${j.shape === '
|
|
1634
|
+
const head = `joint "${j.joint}" (${j.limb}, "${j.part}" on "${j.bone}", range [${j.range.join(', ')}]${j.shape === undefined ? '' : `, cap_shape "${j.shape}": no pixel over ${line.bar.level} in the disc`})`;
|
|
1559
1635
|
if (j.unread !== undefined) return [`${head}: FAIL — not read: ${j.unread}`];
|
|
1560
1636
|
// Issue #557: the contour step, a reading on every row (check.json carries it only for a short cap).
|
|
1561
1637
|
return j.poses.map((p) => {
|
|
@@ -1620,7 +1696,7 @@ export function checkStage(input: CheckStageInput, rigc: RigcRunner, bin: string
|
|
|
1620
1696
|
const entryLine = versionLines.find((l) => l.startsWith('entry:'));
|
|
1621
1697
|
log(` ${rigcIdentity(bin, v)}${entryLine === undefined ? '' : `; ${entryLine}`}`);
|
|
1622
1698
|
const mode: PackMode = { pageEdges: input.pageEdges ?? DEFAULT_PAGE_EDGES, packShape: input.packShape ?? DEFAULT_PACK_SHAPE };
|
|
1623
|
-
const r = runCheck(input.rig, input.out, rigc, input.parts, mode, input.source, input.requirements, input.seamPairs === true, input.keepStills === true, input.set, input.allSets === true, input.environment, input.requirementsAs);
|
|
1699
|
+
const r = runCheck(input.rig, input.out, rigc, input.parts, mode, input.source, input.requirements, input.seamPairs === true, input.keepStills === true, input.set, input.allSets === true, input.environment, input.requirementsAs, input.config);
|
|
1624
1700
|
if (r.figures.environment !== undefined) log(` ${environmentLine(r.figures.environment)}`);
|
|
1625
1701
|
log(` gate rig-play (rigc ${packedBuildLabel(mode)}), verbatim:`);
|
|
1626
1702
|
for (const l of r.gateHtml) log(l);
|
|
@@ -2106,13 +2182,17 @@ export function build(input: BuildInput, run: BuildRunners, log: Log): BuildResu
|
|
|
2106
2182
|
log(`rig-parts build: ${input.config} -> ${out}, seam rule ${input.seam}, projection rule ${input.project}, page edges ${input.pageEdges}, pack shape ${input.packShape ?? DEFAULT_PACK_SHAPE}${idleKeys === DEFAULT_IDLE_KEYS ? '' : `, idle keys ${idleKeys}`}${input.loop ? `, with the idle loop${input.leadIn === undefined ? '' : ` after a lead-in of ${input.leadIn} period(s)`}` : ''}`);
|
|
2107
2183
|
|
|
2108
2184
|
let req: BuildRequirements | null = null;
|
|
2185
|
+
let configRecord: InputFileRecord | null = null;
|
|
2109
2186
|
try {
|
|
2110
2187
|
// build runs rig next, which needs the whole config, so the full loader is
|
|
2111
2188
|
// asked first: a config rig would refuse is refused before assemble writes
|
|
2112
2189
|
// anything, and under [assemble], as it was before the stage had its own
|
|
2113
2190
|
// narrower door.
|
|
2114
2191
|
// Issue #556: the flag, or the config's declaration when there is none; both naming other bytes is refused here.
|
|
2115
|
-
|
|
2192
|
+
// Issue #607: the bytes this read parsed are the ones check.json's config record hashes, under the path as typed.
|
|
2193
|
+
const loaded = loadConfigWithBytes(input.config);
|
|
2194
|
+
configRecord = inputFileRecord(loaded.bytes, input.config);
|
|
2195
|
+
req = buildRequirements(input.requirements, loaded.config.requirements, input.config);
|
|
2116
2196
|
// The same for the requirements file's own shape; its names resolve against the rig, in the check, before it builds.
|
|
2117
2197
|
if (req !== null) readRequirements(req.read);
|
|
2118
2198
|
// And the schedule (issue #538), by rigc's own reader, as check reads it.
|
|
@@ -2134,7 +2214,7 @@ export function build(input: BuildInput, run: BuildRunners, log: Log): BuildResu
|
|
|
2134
2214
|
|
|
2135
2215
|
let report: CheckReport;
|
|
2136
2216
|
try {
|
|
2137
|
-
report = checkStage({ rig: join(out, 'rig'), parts: out, out: join(out, 'check'), pageEdges: input.pageEdges, packShape: input.packShape, ...(req === null ? {} : { requirements: req.read, requirementsAs: req.recorded }), seamPairs: input.seamPairs === true, keepStills: input.keepStills === true, ...(input.set === undefined ? {} : { set: input.set }), allSets: input.allSets === true, ...(input.environment === undefined ? {} : { environment: input.environment }) }, run.check, run.checkBin, prefixed('check'));
|
|
2217
|
+
report = checkStage({ rig: join(out, 'rig'), parts: out, out: join(out, 'check'), pageEdges: input.pageEdges, packShape: input.packShape, ...(req === null ? {} : { requirements: req.read, requirementsAs: req.recorded }), seamPairs: input.seamPairs === true, keepStills: input.keepStills === true, ...(input.set === undefined ? {} : { set: input.set }), allSets: input.allSets === true, ...(input.environment === undefined ? {} : { environment: input.environment }), ...(configRecord === null ? {} : { config: configRecord }) }, run.check, run.checkBin, prefixed('check'));
|
|
2138
2218
|
} catch (err) {
|
|
2139
2219
|
return refused('check', err);
|
|
2140
2220
|
}
|
package/src/check.ts
CHANGED
|
@@ -1888,6 +1888,12 @@ export interface CheckFigures {
|
|
|
1888
1888
|
skipped?: { loop?: string; seam?: string };
|
|
1889
1889
|
/** Written only under `--set` or `--all-sets` (issue #454): each checked alternate set's setup-pose seam and recomposite figures, keyed by set name. */
|
|
1890
1890
|
sets?: Record<string, SetCheckFigures>;
|
|
1891
|
+
/**
|
|
1892
|
+
* Written only by `build` (issue #607): the config it read, the path as `--config` was typed and the sha256 of the
|
|
1893
|
+
* bytes its full loader parsed ({@link inputFileRecord}), just before the requirements block. Provenance, not a
|
|
1894
|
+
* bar; `check` and `compose` read no config and write no key.
|
|
1895
|
+
*/
|
|
1896
|
+
config?: InputFileRecord;
|
|
1891
1897
|
/** Written only under `--requirements` (issue #93): the file's fps, the summary, and one line per declared requirement, by name. */
|
|
1892
1898
|
requirements?: RequirementsBlock;
|
|
1893
1899
|
PASS: boolean;
|
|
@@ -2018,7 +2024,15 @@ export const LIMB_LINE = 'LIMB_ONE_BONE';
|
|
|
2018
2024
|
* {@link SEAM_PX_LEVEL}: the disc is the cap's whole claim, so one uncovered
|
|
2019
2025
|
* pixel of it is one too many. The level is the seam's; the count's bar is
|
|
2020
2026
|
* the card's ("the joint disc holds no background pixel"), not a figure
|
|
2021
|
-
* measured here. Its row says `shape: "disc"
|
|
2027
|
+
* measured here. Its row says `shape: "disc"`.
|
|
2028
|
+
* - **So is a ball** (issue #598). A joint whose cap record says
|
|
2029
|
+
* `shape: "ball"` (`cap_shape: "ball"`, issue #579) is held to the same
|
|
2030
|
+
* rule over the same comparison, and its row says `shape: "ball"`. The
|
|
2031
|
+
* comparison already reads the whole disc — the underlay is the limb's art
|
|
2032
|
+
* at rest inside the disc on both sides of the joint line — and the whole
|
|
2033
|
+
* disc is what a ball writes (its lower half into the lower piece), so the
|
|
2034
|
+
* rule reads both halves: a ball whose lower half the art does not give
|
|
2035
|
+
* shows it at a bend. No row of a rig without `"disc"` or `"ball"` changes.
|
|
2022
2036
|
* - **Opt-in by construction.** Written only when `parts.json` holds a limb
|
|
2023
2037
|
* record with a `range`; a rig without one renders nothing more and writes
|
|
2024
2038
|
* what it wrote.
|
|
@@ -3070,8 +3084,8 @@ export interface SweepJoint {
|
|
|
3070
3084
|
range: [number, number];
|
|
3071
3085
|
at: [number, number];
|
|
3072
3086
|
radius: number;
|
|
3073
|
-
/**
|
|
3074
|
-
|
|
3087
|
+
/** Issues #360 and #598: the cap's record says `shape: "disc"` or `"ball"` — the disc is held to no pixel uncovered ({@link sweepLine}). */
|
|
3088
|
+
shape?: 'disc' | 'ball';
|
|
3075
3089
|
/** Issue #557: the upper segment's bone (the limb record one segment up), whose direction the contour step is read across; null when parts.json has none. */
|
|
3076
3090
|
upperBone?: string | null;
|
|
3077
3091
|
/** Issue #557: the cap's record carries `short_px` — the step is then written into check.json ({@link SweepPose}). */
|
|
@@ -3094,7 +3108,7 @@ export function sweepJoints(parts: PartsFile): SweepJoint[] {
|
|
|
3094
3108
|
range: [l.range[0], l.range[1]],
|
|
3095
3109
|
at: [l.cap.at[0], l.cap.at[1]],
|
|
3096
3110
|
radius: l.cap.radius,
|
|
3097
|
-
...(l.cap.shape ===
|
|
3111
|
+
...(l.cap.shape === undefined ? {} : { shape: l.cap.shape }),
|
|
3098
3112
|
upperBone: up,
|
|
3099
3113
|
...(l.cap.short_px === undefined ? {} : { short: { left: l.cap.short_px.left, right: l.cap.short_px.right } }),
|
|
3100
3114
|
});
|
|
@@ -3325,8 +3339,8 @@ export interface SweepRow {
|
|
|
3325
3339
|
range: [number, number];
|
|
3326
3340
|
at: [number, number];
|
|
3327
3341
|
radius: number;
|
|
3328
|
-
/**
|
|
3329
|
-
shape?: 'disc';
|
|
3342
|
+
/** Issues #360 and #598: written only for a joint whose cap is `cap_shape: "disc"` or `"ball"`, held to no pixel over the level in its disc. */
|
|
3343
|
+
shape?: 'disc' | 'ball';
|
|
3330
3344
|
under_px: number;
|
|
3331
3345
|
status: 'PASS' | 'FAIL';
|
|
3332
3346
|
poses: SweepPose[];
|
|
@@ -3363,7 +3377,7 @@ export function sweepLine(
|
|
|
3363
3377
|
const seen: { grid: FrameSet | null } = { grid: null };
|
|
3364
3378
|
const rows: SweepRow[] = joints.map((j, i) => {
|
|
3365
3379
|
const object = (at: string): string => `joint "${j.joint}" (config.limbs.${j.limb} segment ${j.segment}, part "${j.part}", bone "${j.bone}") ${at}`;
|
|
3366
|
-
const head = { part: j.part, limb: j.limb, segment: j.segment, joint: j.joint, bone: j.bone, range: j.range, at: j.at, radius: j.radius, ...(j.
|
|
3380
|
+
const head = { part: j.part, limb: j.limb, segment: j.segment, joint: j.joint, bone: j.bone, range: j.range, at: j.at, radius: j.radius, ...(j.shape === undefined ? {} : { shape: j.shape }), under_px: underPx[i] };
|
|
3367
3381
|
const why = unread[i];
|
|
3368
3382
|
if (why !== null) {
|
|
3369
3383
|
problems.push({ code: `CHECK_${SWEEP_LINE}`, object: object(`over its range [${j.range.join(', ')}]`), detail: `is not read: ${why}; a joint not read is not a pass` });
|
|
@@ -3388,8 +3402,8 @@ export function sweepLine(
|
|
|
3388
3402
|
const f = seamFigures(under.frames[0].image, bare.frames[0].image, { x: 0, y: 0, width: vp.pixelWidth, height: vp.pixelHeight }, vp, bare.background, { sx: 1, sy: 1, tx: 0, ty: 0 });
|
|
3389
3403
|
const mean = round3(f.mean);
|
|
3390
3404
|
const scale = round6(vp.scale);
|
|
3391
|
-
//
|
|
3392
|
-
const discFail = j.
|
|
3405
|
+
// Issues #360 and #598: a disc or ball cap promises the disc covered at every pose, so one pixel over the level there is a FAIL of its own.
|
|
3406
|
+
const discFail = j.shape !== undefined && f.over40 > 0 && !seamFails(mean, f.over40, scale);
|
|
3393
3407
|
const fail = seamFails(mean, f.over40, scale) || discFail;
|
|
3394
3408
|
if (discFail) {
|
|
3395
3409
|
problems.push({
|
|
@@ -3397,7 +3411,7 @@ export function sweepLine(
|
|
|
3397
3411
|
object: object(`bent ${a}°`),
|
|
3398
3412
|
detail:
|
|
3399
3413
|
`${f.over40} frame px over ${SEAM_PX_LEVEL} (${f.over80} over ${SEAM_PX_LEVEL_HIGH}) at frame scale ${scale}, mean |d| ${mean}/255, against the same pose with the joint's own art drawn under the limb (${underPx[i]} px, the disc of radius ${j.radius} px about [${j.at.join(', ')}]); ` +
|
|
3400
|
-
`the cap is cap_shape "
|
|
3414
|
+
`the cap is cap_shape "${j.shape}", which promises the disc covered at every pose${j.shape === 'ball' ? ', on both sides of the joint line' : ''} — no pixel of it over ${SEAM_PX_LEVEL}, under the rest-pose seam's bar as well — and the bend shows what lies behind the limb there: a cap pixel the art did not give ("limb cap:" counts them as missing), or a pixel cleared from "${j.part}" after assemble wrote it`,
|
|
3401
3415
|
});
|
|
3402
3416
|
} else if (fail) {
|
|
3403
3417
|
problems.push({
|
|
@@ -3922,7 +3936,7 @@ export function environmentLine(env: CheckEnvironment): string {
|
|
|
3922
3936
|
* MEASURABLE is a problem. Without it nothing here reads, writes or prints
|
|
3923
3937
|
* anything it did not before.
|
|
3924
3938
|
*/
|
|
3925
|
-
export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, partsHome?: string, mode: PackMode = DEFAULT_PACK_MODE, source?: string, requirements?: string, seamPairsAsked = false, keepStills = false, set?: string, allSets = false, environment?: string, requirementsAs: string | undefined = requirements): CheckReport {
|
|
3939
|
+
export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, partsHome?: string, mode: PackMode = DEFAULT_PACK_MODE, source?: string, requirements?: string, seamPairsAsked = false, keepStills = false, set?: string, allSets = false, environment?: string, requirementsAs: string | undefined = requirements, config?: InputFileRecord): CheckReport {
|
|
3926
3940
|
let inp: CheckInputs;
|
|
3927
3941
|
let reqFile: RequirementsFile | null = null;
|
|
3928
3942
|
let reqRecord: RequirementsFileRecord | null = null;
|
|
@@ -4575,6 +4589,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
4575
4589
|
...(sourceRead === null ? {} : { [SOURCE_LINE]: sourceRead }),
|
|
4576
4590
|
...(Object.keys(skipped).length === 0 ? {} : { skipped }),
|
|
4577
4591
|
...(Object.keys(setsFigures).length === 0 ? {} : { sets: setsFigures }),
|
|
4592
|
+
...(config === undefined ? {} : { config }),
|
|
4578
4593
|
...(reqBlock === null ? {} : { requirements: reqBlock }),
|
|
4579
4594
|
PASS: false,
|
|
4580
4595
|
};
|
|
@@ -4685,7 +4700,23 @@ export interface RequirementsFileRecord {
|
|
|
4685
4700
|
export function requirementsFileRecord(path: string, recorded: string): RequirementsFileRecord {
|
|
4686
4701
|
const bytes = readFileSync(resolve(path));
|
|
4687
4702
|
const raw = JSON.parse(bytes.toString('utf8')) as Record<string, unknown>;
|
|
4688
|
-
return {
|
|
4703
|
+
return { ...inputFileRecord(bytes, recorded), keys: Object.keys(raw) };
|
|
4704
|
+
}
|
|
4705
|
+
|
|
4706
|
+
/**
|
|
4707
|
+
* An input file as `check.json` records it — the path as the caller wrote it,
|
|
4708
|
+
* never resolved, then the sha256 of the bytes read — in the order the
|
|
4709
|
+
* requirements record (issue #556) opens with; `build`'s `config` record
|
|
4710
|
+
* (issue #607) is this and nothing more.
|
|
4711
|
+
*/
|
|
4712
|
+
export interface InputFileRecord {
|
|
4713
|
+
path: string;
|
|
4714
|
+
sha256: string;
|
|
4715
|
+
}
|
|
4716
|
+
|
|
4717
|
+
/** The {@link InputFileRecord} of `bytes`, recorded as `recorded`: the one place a record's digest is taken. */
|
|
4718
|
+
export function inputFileRecord(bytes: Uint8Array, recorded: string): InputFileRecord {
|
|
4719
|
+
return { path: recorded, sha256: createHash('sha256').update(bytes).digest('hex') };
|
|
4689
4720
|
}
|
|
4690
4721
|
|
|
4691
4722
|
/** The throwaway copies' specs and builds, under `--out`; removed before the stage returns. */
|
package/src/cloth.ts
CHANGED
|
@@ -105,7 +105,9 @@ export interface ClothRecipe {
|
|
|
105
105
|
* Issue #518: draft the parts this recipe meshes in the influence mode (`meshes.<part>.influence`, issue #378) rather
|
|
106
106
|
* than on a lattice: `across`, `max` and `shape` as declared (no default — the reading that fixed the radius did not
|
|
107
107
|
* vary them), `cell` the lattice cell the part would have had, and `radius` as declared or, absent, drafted as
|
|
108
|
-
* {@link INFLUENCE_RADIUS_CELLS} cells past the part's farthest lattice vertex from its nearest link.
|
|
108
|
+
* {@link INFLUENCE_RADIUS_CELLS} cells past the part's farthest lattice vertex from its nearest link. Issue #615:
|
|
109
|
+
* under `split.hold_tip: true` the drafted mesh also declares `hold_tip: true` and `max` at least 8 (the lattice's
|
|
110
|
+
* held-fork smoothing cap), so the rig stage smooths its shares as it smooths the lattice's.
|
|
109
111
|
*/
|
|
110
112
|
influence?: { across: boolean; max: number; shape: 'linear' | 'smooth'; radius?: number };
|
|
111
113
|
}
|
|
@@ -116,8 +118,13 @@ export interface ClothRecipe {
|
|
|
116
118
|
* cloth fixture and the public `wind` example (8 covered parts, `render --folds` with the physics on under wind
|
|
117
119
|
* +1 -> -1 -> calm and a hip sway of 8 and 30 degrees, max 6, across, smooth): farthest + 2 to + 6 cells read 0
|
|
118
120
|
* folded frames on every part, + 2 at the window's edge on one front-hair part, and a fold returned at 8-11 cells on
|
|
119
|
-
* another.
|
|
120
|
-
*
|
|
121
|
+
* another. That reading counted folds only. Read against `check` as well (the rig as built under the same wind
|
|
122
|
+
* schedule, the three covered `wind` parts at the same number of cells), + 4 is the ceiling: `wind` `bottomwear`'s
|
|
123
|
+
* `CHECK_TIP_OVER_ROOT` ratio is 1.898 on the lattice, 1.801 at + 2 cells, 1.590 at + 3 and 1.471 at + 4, under the
|
|
124
|
+
* floor 1.4725, and 1.351 at + 6 (#513, rig-parts 1.52.0, rigc 2.60.0; the lattice, + 3 and + 4 read again on
|
|
125
|
+
* rig-parts 1.54.0, rigc 2.60.0 with the same figures, #599). The window that holds both is + 2 to + 3 cells, and 3 is
|
|
126
|
+
* its upper edge: one cell inside the fold edge, one under the check ceiling. [Hypothesis until a third subject: each
|
|
127
|
+
* edge rests on one part.] Past the floor alone the mesh folds more than its lattice, and a larger radius is not safer.
|
|
121
128
|
*/
|
|
122
129
|
export const INFLUENCE_RADIUS_CELLS = 3;
|
|
123
130
|
|
package/src/config.ts
CHANGED
|
@@ -328,9 +328,11 @@ export type MeshSpec = LatticeMeshSpec | ContourMeshSpec | AutoMeshSpec | Influe
|
|
|
328
328
|
* `buildSegmentsLattice` and `influenceShares` from `rig-c/mesh`, promised for this call (rig-c/core#1450), so the
|
|
329
329
|
* rule is core's and the mesh is written with explicit weights like every other mode (`src/rig.ts`). `segments`
|
|
330
330
|
* names the links as in every mode; each entry is one of rig-c's `bones` entries, which `across: false` keeps apart.
|
|
331
|
+
* `hold_tip: true` (issue #615, optional, written by `propose --cloth` from the recipe's `split.hold_tip`) smooths the
|
|
332
|
+
* pulled shares by the lattice's held-fork passes, capped at `max`; absent, the shares are rig-c's as pulled.
|
|
331
333
|
*/
|
|
332
334
|
export interface InfluenceMeshSpec {
|
|
333
|
-
influence: { cell: number; radius: number; across: boolean; max: number; shape: 'linear' | 'smooth' };
|
|
335
|
+
influence: { cell: number; radius: number; across: boolean; max: number; shape: 'linear' | 'smooth'; hold_tip?: true };
|
|
334
336
|
segments: Segment[];
|
|
335
337
|
}
|
|
336
338
|
|
|
@@ -1159,22 +1161,38 @@ function partNameOk(name: string): boolean {
|
|
|
1159
1161
|
// the loader
|
|
1160
1162
|
// ---------------------------------------------------------------------------
|
|
1161
1163
|
|
|
1162
|
-
/** The file as parsed JSON, or a refusal naming why not.
|
|
1163
|
-
function
|
|
1164
|
+
/** The file's bytes as read and as parsed JSON, or a refusal naming why not. Every loader reads through it. */
|
|
1165
|
+
function readConfigBytes(path: string): { raw: Json; bytes: Buffer } {
|
|
1164
1166
|
if (!existsSync(path)) refuseIfAny([{ code: 'CONFIG_FILE_PRESENT', object: path, detail: 'no such file' }]);
|
|
1167
|
+
const bytes = readFileSync(path);
|
|
1165
1168
|
let raw: Json;
|
|
1166
1169
|
try {
|
|
1167
|
-
raw = JSON.parse(
|
|
1170
|
+
raw = JSON.parse(bytes.toString('utf8'));
|
|
1168
1171
|
} catch (err) {
|
|
1169
1172
|
refuseIfAny([{ code: 'CONFIG_IS_JSON', object: path, detail: `does not parse as JSON: ${(err as Error).message}` }]);
|
|
1170
1173
|
}
|
|
1171
|
-
return raw;
|
|
1174
|
+
return { raw, bytes };
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
/** The file as parsed JSON, or a refusal naming why not. */
|
|
1178
|
+
function readConfigFile(path: string): Json {
|
|
1179
|
+
return readConfigBytes(path).raw;
|
|
1172
1180
|
}
|
|
1173
1181
|
|
|
1174
1182
|
export function loadConfig(path: string): CharacterConfig {
|
|
1175
1183
|
return loadConfigAndAnimations(path).config;
|
|
1176
1184
|
}
|
|
1177
1185
|
|
|
1186
|
+
/**
|
|
1187
|
+
* The full loader, with the bytes it parsed (issue #607): `build` hashes these
|
|
1188
|
+
* into `check.json`'s `config` record, so the digest is of the bytes this read
|
|
1189
|
+
* took, not of a later read of the same path.
|
|
1190
|
+
*/
|
|
1191
|
+
export function loadConfigWithBytes(path: string): { config: CharacterConfig; bytes: Buffer } {
|
|
1192
|
+
const { raw, bytes } = readConfigBytes(path);
|
|
1193
|
+
return { config: parseConfigFrom(raw, dirname(resolve(path))).config, bytes };
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1178
1196
|
/**
|
|
1179
1197
|
* The full loader with the file `motion.animations_from` names read beside it,
|
|
1180
1198
|
* relative to the config's directory: every problem in either is one refusal.
|
|
@@ -2476,8 +2494,11 @@ function checkInfluence(c: Check, at: string, m: Record<string, Json>): void {
|
|
|
2476
2494
|
for (const k of INFLUENCE_FOREIGN_FIELDS) {
|
|
2477
2495
|
if (k in m) c.fail('CONFIG_INFLUENCE_MODE', `${at}.${k}`, `is ${show(m[k])} on an influence mesh; it pulls each vertex by rig-c's influence (radius, across, max, shape), which reads no ${k} — remove ${k}`);
|
|
2478
2496
|
}
|
|
2479
|
-
const o = c.object(`${at}.influence`, m.influence, ['cell', 'radius', 'across', 'max', 'shape'], []);
|
|
2497
|
+
const o = c.object(`${at}.influence`, m.influence, ['cell', 'radius', 'across', 'max', 'shape'], ['hold_tip']);
|
|
2480
2498
|
if (o === null) return;
|
|
2499
|
+
// Issue #615: one spelling — true smooths the held fork, absent leaves the shares as pulled; false would be a second
|
|
2500
|
+
// spelling of absent, and a mesh_report row that echoes it would differ from the one written before the field existed.
|
|
2501
|
+
if ('hold_tip' in o && o.hold_tip !== true) c.fail('CONFIG_FIELD_TYPE', `${at}.influence.hold_tip`, `is ${show(o.hold_tip)}; true (the pulled shares smoothed across the held fork, capped at max) is required — remove hold_tip to keep the shares as rig-c pulls them`);
|
|
2481
2502
|
if ('cell' in o) c.int(`${at}.influence.cell`, o.cell, 1);
|
|
2482
2503
|
if ('radius' in o) c.number(`${at}.influence.radius`, o.radius, 'positive');
|
|
2483
2504
|
if ('across' in o && typeof o.across !== 'boolean') c.fail('CONFIG_FIELD_TYPE', `${at}.influence.across`, `is ${show(o.across)}; true (every link within radius pulls, across the segments entries) or false (only the links of the entry nearest the vertex) is required`);
|
package/src/parts.ts
CHANGED
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
* - `refused_drift_px` — of those, the ones refused because See-through's
|
|
30
30
|
* pixel and the painting's disagreed by more than the drift limit;
|
|
31
31
|
* - `merged_px` — pixels brought in from the other run below the head crop;
|
|
32
|
+
* on a subset set's limb part, less those the set's exclusion (issue #587)
|
|
33
|
+
* cleared, so it counts the written PNG's (issue #603);
|
|
32
34
|
* - `seam_override_px` — pixels whose colour the seam pass replaced;
|
|
33
35
|
* - `fringe_pushed_back` — written only when not empty: the pixels of this
|
|
34
36
|
* part's fringe (alpha below 250) made transparent because the painting
|
|
@@ -163,6 +165,16 @@ export interface CapRecord {
|
|
|
163
165
|
* `right` the other; the two add up to `missing_px`. A full cap writes no key.
|
|
164
166
|
*/
|
|
165
167
|
short_px?: { left: number; right: number };
|
|
168
|
+
/**
|
|
169
|
+
* Issue #603, written only when above 0: the cap's pixels a subset set's
|
|
170
|
+
* exclusion (issue #587) cleared — pixels a base part the set does not
|
|
171
|
+
* replace covers at setup — each taken out of the count it was in
|
|
172
|
+
* (`layer_px`, `image_px`, `upper_px`, `lower_px`, `lower_kept_px`), so
|
|
173
|
+
* those counts are the written PNG's. The disc's pixels are then the
|
|
174
|
+
* counts above, `upper_px`, the lower half's and `excluded_px` together.
|
|
175
|
+
* A cap no exclusion touched writes no key.
|
|
176
|
+
*/
|
|
177
|
+
excluded_px?: number;
|
|
166
178
|
/**
|
|
167
179
|
* Issue #360, written only under the segment's `cap_shape: "disc"`: the
|
|
168
180
|
* shape; the cap's pixels taken from the upper segment's art where the
|
|
@@ -219,6 +231,7 @@ const CAP_KEYS = [
|
|
|
219
231
|
'image_layer',
|
|
220
232
|
'missing_px',
|
|
221
233
|
'short_px',
|
|
234
|
+
'excluded_px',
|
|
222
235
|
'shape',
|
|
223
236
|
'upper_px',
|
|
224
237
|
'lower_px',
|
|
@@ -631,51 +644,7 @@ function checkParts(raw: unknown, path: string): PartsFile {
|
|
|
631
644
|
fail('PARTS_FIELD_TYPE', `${object} "range"`, `is ${show(r)}; [min, max], two finite degrees from rest with min <= 0 <= max, is required — config.limbs' rule (CONFIG_LIMB_RANGE)`);
|
|
632
645
|
}
|
|
633
646
|
}
|
|
634
|
-
if ('cap' in q) {
|
|
635
|
-
const c = q.cap;
|
|
636
|
-
const co = typeof c === 'object' && c !== null && !Array.isArray(c) ? (c as Record<string, unknown>) : null;
|
|
637
|
-
const pt = (v: unknown, n: number): boolean => Array.isArray(v) && v.length === n && v.every((x) => typeof x === 'number' && Number.isFinite(x));
|
|
638
|
-
const ok =
|
|
639
|
-
co !== null &&
|
|
640
|
-
Object.keys(co).every((k) => (CAP_KEYS as readonly string[]).includes(k)) &&
|
|
641
|
-
pt(co.at, 2) &&
|
|
642
|
-
typeof co.width === 'number' &&
|
|
643
|
-
typeof co.radius === 'number' &&
|
|
644
|
-
pt(co.box, 4) &&
|
|
645
|
-
isCount(co.layer_px) &&
|
|
646
|
-
isCount(co.missing_px) &&
|
|
647
|
-
(!('image_px' in co) || isCount(co.image_px)) &&
|
|
648
|
-
(!('image_layer' in co) || ('image_px' in co && typeof co.image_layer === 'string' && co.image_layer !== '')) &&
|
|
649
|
-
// Issue #360: a disc cap carries its count, a feathered edge its band and count, and neither carries them alone.
|
|
650
|
-
('shape' in co ? (co.shape === 'disc' || co.shape === 'ball') && isCount(co.upper_px) : !('upper_px' in co) || (isCount(co.upper_px) && co.upper_px > 0)) &&
|
|
651
|
-
// Issue #579: a ball cap carries its lower half's three counts, its missing ones inside missing_px; no other cap carries them.
|
|
652
|
-
(co.shape === 'ball'
|
|
653
|
-
? isCount(co.lower_px) && isCount(co.lower_kept_px) && isCount(co.lower_missing_px) && isCount(co.missing_px) && co.lower_missing_px <= co.missing_px
|
|
654
|
-
: BALL_KEYS.every((k) => !(k in co))) &&
|
|
655
|
-
// Issue #557: the shortfall by side, when written, adds up to the missing pixels, and is never written for none.
|
|
656
|
-
(!('short_px' in co) || shortSides(co.short_px, co.missing_px)) &&
|
|
657
|
-
('edge' in co ? co.edge === 'feather' && typeof co.feather_radius === 'number' && Number.isFinite(co.feather_radius) && co.feather_radius >= 0 && isCount(co.feathered_px) : !('feather_radius' in co) && !('feathered_px' in co)) &&
|
|
658
|
-
// Issue #360 (item 14): a placed cut carries its band, line and counts, the line inside the band; none of them rides alone.
|
|
659
|
-
('cut_band' in co
|
|
660
|
-
? isCount(co.cut_band) &&
|
|
661
|
-
co.cut_band >= 1 &&
|
|
662
|
-
Number.isInteger(co.cut_offset) &&
|
|
663
|
-
Math.abs(co.cut_offset as number) <= co.cut_band &&
|
|
664
|
-
pt(co.cut_at, 2) &&
|
|
665
|
-
isCount(co.cut_crossed) &&
|
|
666
|
-
isCount(co.joint_crossed) &&
|
|
667
|
-
isCount(co.band_px) &&
|
|
668
|
-
(co.cut_crossed as number) <= (co.joint_crossed as number) &&
|
|
669
|
-
(!('stroke_luma_max' in co) || (isCount(co.stroke_luma_max) && co.stroke_luma_max <= 255))
|
|
670
|
-
: CUT_KEYS.every((k) => !(k in co)));
|
|
671
|
-
if (!ok) {
|
|
672
|
-
fail(
|
|
673
|
-
'PARTS_FIELD_TYPE',
|
|
674
|
-
`${object} "cap"`,
|
|
675
|
-
`is ${show(c)}; {at: [x, y], width, radius, box: [x, y, w, h], layer_px, image_px?, image_layer? (with image_px), missing_px, short_px? ({left, right}, adding up to missing_px, above 0), shape? ("disc" or "ball", with upper_px; "ball" with lower_px, lower_kept_px and lower_missing_px, at most missing_px; without it upper_px? above 0), edge? ("feather", with feather_radius and feathered_px), cut_band? (with cut_offset inside the band, cut_at, cut_crossed at most joint_crossed, band_px, stroke_luma_max? 0..255)} is required`,
|
|
676
|
-
);
|
|
677
|
-
}
|
|
678
|
-
}
|
|
647
|
+
if ('cap' in q) checkCap(q.cap, `${object} "cap"`, fail);
|
|
679
648
|
}
|
|
680
649
|
}
|
|
681
650
|
if ('scene' in o) {
|
|
@@ -698,11 +667,80 @@ function checkParts(raw: unknown, path: string): PartsFile {
|
|
|
698
667
|
if ('alternates' in o && !Array.isArray(o.alternates)) {
|
|
699
668
|
fail('PARTS_FIELD_TYPE', `${path} field "alternates"`, `is ${show(o.alternates)}; an array of alternate set records is required`);
|
|
700
669
|
}
|
|
670
|
+
if (Array.isArray(o.alternates)) {
|
|
671
|
+
// Issue #620: a set record's cap is a cap, so it is held to the base records' rule; the object names the set and the part.
|
|
672
|
+
o.alternates.forEach((a, i) => {
|
|
673
|
+
if (typeof a !== 'object' || a === null || Array.isArray(a)) return;
|
|
674
|
+
const set = a as Record<string, unknown>;
|
|
675
|
+
if (!Array.isArray(set.records)) return;
|
|
676
|
+
const at = `${path} alternates[${i}]${typeof set.name === 'string' ? ` (set "${set.name}")` : ''}`;
|
|
677
|
+
set.records.forEach((p, j) => {
|
|
678
|
+
if (typeof p !== 'object' || p === null || Array.isArray(p)) return;
|
|
679
|
+
const r = p as Record<string, unknown>;
|
|
680
|
+
const l = r[LIMB_KEY];
|
|
681
|
+
if (typeof l !== 'object' || l === null || Array.isArray(l) || !('cap' in l)) return;
|
|
682
|
+
const part = typeof r.name === 'string' ? `part "${r.name}"` : `records[${j}]`;
|
|
683
|
+
checkCap((l as Record<string, unknown>).cap, `${at} ${part} field "${LIMB_KEY}" "cap"`, fail);
|
|
684
|
+
});
|
|
685
|
+
});
|
|
686
|
+
}
|
|
701
687
|
refuseIfAny(problems);
|
|
702
688
|
return raw as PartsFile;
|
|
703
689
|
}
|
|
704
690
|
|
|
705
691
|
const isCount = (v: unknown): v is number => Number.isInteger(v) && (v as number) >= 0;
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* A limb segment's `cap` record (issue #349, with #360's disc, edge and band, #557's short_px and #579's ball): every key
|
|
695
|
+
* a cap key, its fields of their kinds, and its counts consistent — one refusal naming `object` when any is not. A base
|
|
696
|
+
* part's cap and a set record's cap (issue #620) are held to this one rule.
|
|
697
|
+
*/
|
|
698
|
+
function checkCap(c: unknown, object: string, fail: (code: string, object: string, detail: string) => void): void {
|
|
699
|
+
const co = typeof c === 'object' && c !== null && !Array.isArray(c) ? (c as Record<string, unknown>) : null;
|
|
700
|
+
const pt = (v: unknown, n: number): boolean => Array.isArray(v) && v.length === n && v.every((x) => typeof x === 'number' && Number.isFinite(x));
|
|
701
|
+
const ok =
|
|
702
|
+
co !== null &&
|
|
703
|
+
Object.keys(co).every((k) => (CAP_KEYS as readonly string[]).includes(k)) &&
|
|
704
|
+
pt(co.at, 2) &&
|
|
705
|
+
typeof co.width === 'number' &&
|
|
706
|
+
typeof co.radius === 'number' &&
|
|
707
|
+
pt(co.box, 4) &&
|
|
708
|
+
isCount(co.layer_px) &&
|
|
709
|
+
isCount(co.missing_px) &&
|
|
710
|
+
(!('image_px' in co) || isCount(co.image_px)) &&
|
|
711
|
+
(!('image_layer' in co) || ('image_px' in co && typeof co.image_layer === 'string' && co.image_layer !== '')) &&
|
|
712
|
+
// Issue #360: a disc cap carries its count, a feathered edge its band and count, and neither carries them alone.
|
|
713
|
+
('shape' in co ? (co.shape === 'disc' || co.shape === 'ball') && isCount(co.upper_px) : !('upper_px' in co) || (isCount(co.upper_px) && co.upper_px > 0)) &&
|
|
714
|
+
// Issue #579: a ball cap carries its lower half's three counts, its missing ones inside missing_px; no other cap carries them.
|
|
715
|
+
(co.shape === 'ball'
|
|
716
|
+
? isCount(co.lower_px) && isCount(co.lower_kept_px) && isCount(co.lower_missing_px) && isCount(co.missing_px) && co.lower_missing_px <= co.missing_px
|
|
717
|
+
: BALL_KEYS.every((k) => !(k in co))) &&
|
|
718
|
+
// Issue #557: the shortfall by side, when written, adds up to the missing pixels, and is never written for none.
|
|
719
|
+
(!('short_px' in co) || shortSides(co.short_px, co.missing_px)) &&
|
|
720
|
+
// Issue #603: the pixels a set's exclusion took from the cap, written only when it took one.
|
|
721
|
+
(!('excluded_px' in co) || (isCount(co.excluded_px) && co.excluded_px > 0)) &&
|
|
722
|
+
('edge' in co ? co.edge === 'feather' && typeof co.feather_radius === 'number' && Number.isFinite(co.feather_radius) && co.feather_radius >= 0 && isCount(co.feathered_px) : !('feather_radius' in co) && !('feathered_px' in co)) &&
|
|
723
|
+
// Issue #360 (item 14): a placed cut carries its band, line and counts, the line inside the band; none of them rides alone.
|
|
724
|
+
('cut_band' in co
|
|
725
|
+
? isCount(co.cut_band) &&
|
|
726
|
+
co.cut_band >= 1 &&
|
|
727
|
+
Number.isInteger(co.cut_offset) &&
|
|
728
|
+
Math.abs(co.cut_offset as number) <= co.cut_band &&
|
|
729
|
+
pt(co.cut_at, 2) &&
|
|
730
|
+
isCount(co.cut_crossed) &&
|
|
731
|
+
isCount(co.joint_crossed) &&
|
|
732
|
+
isCount(co.band_px) &&
|
|
733
|
+
(co.cut_crossed as number) <= (co.joint_crossed as number) &&
|
|
734
|
+
(!('stroke_luma_max' in co) || (isCount(co.stroke_luma_max) && co.stroke_luma_max <= 255))
|
|
735
|
+
: CUT_KEYS.every((k) => !(k in co)));
|
|
736
|
+
if (!ok) {
|
|
737
|
+
fail(
|
|
738
|
+
'PARTS_FIELD_TYPE',
|
|
739
|
+
object,
|
|
740
|
+
`is ${show(c)}; {at: [x, y], width, radius, box: [x, y, w, h], layer_px, image_px?, image_layer? (with image_px), missing_px, short_px? ({left, right}, adding up to missing_px, above 0), excluded_px? (above 0), shape? ("disc" or "ball", with upper_px; "ball" with lower_px, lower_kept_px and lower_missing_px, at most missing_px; without it upper_px? above 0), edge? ("feather", with feather_radius and feathered_px), cut_band? (with cut_offset inside the band, cut_at, cut_crossed at most joint_crossed, band_px, stroke_luma_max? 0..255)} is required`,
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
706
744
|
/** Issue #557: a cap's `short_px` — `{left, right}`, two counts and no other key, adding up to `missing`, above 0. */
|
|
707
745
|
function shortSides(v: unknown, missing: unknown): boolean {
|
|
708
746
|
if (typeof v !== 'object' || v === null || Array.isArray(v)) return false;
|