@rig-c/parts 1.58.0 → 1.60.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 +12 -1
- package/cli.ts +36 -2
- package/docs/AUTHORING.md +71 -4
- package/docs/MIGRATION.md +70 -0
- package/docs/STABILITY.md +5 -4
- package/package.json +1 -1
- package/src/build.ts +40 -5
- package/src/check.ts +83 -26
- package/src/config.ts +101 -6
- package/src/configwrite.ts +51 -3
- package/src/meshdraft.ts +17 -4
- package/src/parts.ts +27 -0
- package/src/rig.ts +102 -12
- package/src/scene.ts +3 -2
- package/tools/configwrite.ts +1 -1
package/src/check.ts
CHANGED
|
@@ -127,8 +127,8 @@ import {
|
|
|
127
127
|
type ChainEdge,
|
|
128
128
|
type WorldBox,
|
|
129
129
|
} from './instruments.ts';
|
|
130
|
-
import { type AlternatePartsRecord, type LimbRecord, type PartRecord, type PartsFile, readParts } from './parts.ts';
|
|
131
|
-
import { poseRigBonesForDrawn, type RigBone, SETS_FILE } from './rig.ts';
|
|
130
|
+
import { type AlternatePartsRecord, FRONT_SUFFIX, type LimbRecord, type PartRecord, type PartsFile, readParts } from './parts.ts';
|
|
131
|
+
import { ARM_SPLIT_MIGRATION, poseRigBonesForDrawn, type RigBone, SETS_FILE } from './rig.ts';
|
|
132
132
|
import { turnTwin } from './turn.ts';
|
|
133
133
|
import {
|
|
134
134
|
aimLine,
|
|
@@ -1238,23 +1238,81 @@ export function flatComposite(parts: PartsFile, partsDir: string, background: re
|
|
|
1238
1238
|
}
|
|
1239
1239
|
|
|
1240
1240
|
/**
|
|
1241
|
-
*
|
|
1242
|
-
*
|
|
1243
|
-
*
|
|
1241
|
+
* What an alternate set draws, in draw order (issues #454, #664): `parts.parts`
|
|
1242
|
+
* order, hidden slots skipped, covered slots drawn from `alt.records` at their
|
|
1243
|
+
* box, uncovered base slots at their base box. A part the set draws on its front
|
|
1244
|
+
* slot (`alt.front`) is drawn from its record although `alt.hides` names it (the
|
|
1245
|
+
* hide is its base slot's) — with `slotOrder`, the rig's final setup slot names,
|
|
1246
|
+
* right after the nearest part slot before `<part>_front` there; without it (or
|
|
1247
|
+
* with no such slot), in its own place, as the base slot would draw it.
|
|
1244
1248
|
*/
|
|
1245
|
-
export function
|
|
1246
|
-
const [W, H] = parts.rig_size;
|
|
1247
|
-
let canvas = newRaster(W, H);
|
|
1248
|
-
for (let i = 0; i < W * H; i++) canvas.data.set(background, i * 4);
|
|
1249
|
+
export function setPlacements(parts: PartsFile, alt: AlternatePartsRecord, slotOrder?: readonly string[]): Array<{ name: string; png: string; box: PartRecord }> {
|
|
1249
1250
|
const hides = new Set(alt.hides ?? []);
|
|
1251
|
+
const front = new Set(alt.front ?? []);
|
|
1250
1252
|
const byName = new Map(alt.records.map((r) => [r.name, r]));
|
|
1253
|
+
const partNames = new Set(parts.parts.map((p) => p.name));
|
|
1254
|
+
// Each front part the slot order places -> the part it is drawn after.
|
|
1255
|
+
const after = new Map<string, string>();
|
|
1256
|
+
if (slotOrder !== undefined) {
|
|
1257
|
+
for (const p of front) {
|
|
1258
|
+
const at = slotOrder.indexOf(`${p}${FRONT_SUFFIX}`);
|
|
1259
|
+
for (let j = at - 1; j >= 0; j--) {
|
|
1260
|
+
if (partNames.has(slotOrder[j]) && !front.has(slotOrder[j])) {
|
|
1261
|
+
after.set(p, slotOrder[j]);
|
|
1262
|
+
break;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
const moved = [...after.keys()].sort((a, b) => (slotOrder as readonly string[]).indexOf(`${a}${FRONT_SUFFIX}`) - (slotOrder as readonly string[]).indexOf(`${b}${FRONT_SUFFIX}`));
|
|
1268
|
+
const out: Array<{ name: string; png: string; box: PartRecord }> = [];
|
|
1269
|
+
const draw = (name: string, base: PartRecord): void => {
|
|
1270
|
+
if (hides.has(name) && !front.has(name)) return;
|
|
1271
|
+
const rec = byName.get(name);
|
|
1272
|
+
out.push({ name, png: rec === undefined ? name : `${alt.name}_${rec.name}`, box: rec ?? base });
|
|
1273
|
+
};
|
|
1274
|
+
const baseOf = new Map(parts.parts.map((p) => [p.name, p]));
|
|
1251
1275
|
for (const p of parts.parts) {
|
|
1252
|
-
if (
|
|
1253
|
-
|
|
1254
|
-
const
|
|
1255
|
-
|
|
1256
|
-
|
|
1276
|
+
if (after.has(p.name)) continue;
|
|
1277
|
+
draw(p.name, p);
|
|
1278
|
+
for (const m of moved) if (after.get(m) === p.name) draw(m, baseOf.get(m) as PartRecord);
|
|
1279
|
+
}
|
|
1280
|
+
return out;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
/**
|
|
1284
|
+
* Issue #671: why a set made before 1.37.0 can fail its seam after #490's arm
|
|
1285
|
+
* split. The set covers a side's sleeve (a part from `full:handwear-<s>`), and
|
|
1286
|
+
* the split made that side's `hand_<s>` / `drape_<s>` parts of their own, which
|
|
1287
|
+
* the set neither covers nor hides, so the base hand is drawn as well as the
|
|
1288
|
+
* hand inside the set's own sleeve art. Returns the hint for the set's seam
|
|
1289
|
+
* refusal, or null when nothing of the kind applies.
|
|
1290
|
+
*/
|
|
1291
|
+
export function armSplitSetHint(parts: PartsFile, alt: AlternatePartsRecord): string | null {
|
|
1292
|
+
const from = new Map(parts.parts.map((p) => [p.name, p.from]));
|
|
1293
|
+
const covered = new Set(Object.keys(alt.slots).map((n) => (n.endsWith(FRONT_SUFFIX) ? n.slice(0, -FRONT_SUFFIX.length) : n)));
|
|
1294
|
+
const hidden = new Set(alt.hides ?? []);
|
|
1295
|
+
const open: string[] = [];
|
|
1296
|
+
for (const side of ['r', 'l']) {
|
|
1297
|
+
if (![...covered].some((n) => from.get(n) === `full:handwear-${side}`)) continue;
|
|
1298
|
+
for (const p of parts.parts) {
|
|
1299
|
+
if ((p.from === `full:hand-${side}` || p.from === `full:drape-${side}`) && !covered.has(p.name) && !hidden.has(p.name)) open.push(p.name);
|
|
1300
|
+
}
|
|
1257
1301
|
}
|
|
1302
|
+
if (open.length === 0) return null;
|
|
1303
|
+
return ` — the set covers a sleeve whose merged arm layer 1.37.0 split (issue #490), and it neither covers nor hides ${open.map((n) => `"${n}"`).join(', ')}, so the base draws ${open.length === 1 ? 'that part' : 'those parts'} beside the set's own art; a set made before 1.37.0 hides it: add ${open.map((n) => `"${n}"`).join(', ')} to the set's hides (see ${ARM_SPLIT_MIGRATION})`;
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
/**
|
|
1307
|
+
* The flat stack of parts for an alternate set (issue #454), in the order
|
|
1308
|
+
* {@link setPlacements} gives: with `slotOrder`, a front part (issue #664) is
|
|
1309
|
+
* stacked where its front slot draws it.
|
|
1310
|
+
*/
|
|
1311
|
+
export function flatCompositeForSet(parts: PartsFile, alt: AlternatePartsRecord, partsDir: string, background: readonly [number, number, number, number], slotOrder?: readonly string[]): Raster {
|
|
1312
|
+
const [W, H] = parts.rig_size;
|
|
1313
|
+
let canvas = newRaster(W, H);
|
|
1314
|
+
for (let i = 0; i < W * H; i++) canvas.data.set(background, i * 4);
|
|
1315
|
+
for (const { png, box } of setPlacements(parts, alt, slotOrder)) canvas = alphaComposite(canvas, readPng(join(partsDir, `${png}.png`)), box.x, box.y);
|
|
1258
1316
|
return canvas;
|
|
1259
1317
|
}
|
|
1260
1318
|
|
|
@@ -4412,6 +4470,8 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
4412
4470
|
let blink: JudgementLine = skip(lacking);
|
|
4413
4471
|
let sourceRead: ReportedLine | null = null;
|
|
4414
4472
|
const setsFigures: Record<string, SetCheckFigures> = {};
|
|
4473
|
+
// Issue #671: a failing set's hint, read with its seam; never written to check.json.
|
|
4474
|
+
const setHints = new Map<string, string>();
|
|
4415
4475
|
if (inp.parts !== null || inp.source !== null) {
|
|
4416
4476
|
try {
|
|
4417
4477
|
mkdirSync(stillDir, { recursive: true });
|
|
@@ -4477,23 +4537,19 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
4477
4537
|
if (asr.status !== 0) refuseIfAny(rigcFailed(`render (the setup-pose still of set "${alt.name}")`, asr, asr.out.split('\n').filter((l) => l.includes('FAIL'))));
|
|
4478
4538
|
const altStillSet = readFrameSet(join(setDir, 'render'));
|
|
4479
4539
|
if (keepStills) cpSync(join(setDir, 'render'), join(keptDir, alt.name), { recursive: true });
|
|
4480
|
-
const
|
|
4540
|
+
const rigSlotOrder = (Array.isArray(inp.rig.slots) ? inp.rig.slots : []).filter(isRecord).map((sl) => String(sl.name));
|
|
4541
|
+
const altComposite = flatCompositeForSet(inp.parts, alt, inp.partsDir, altStillSet.background, rigSlotOrder);
|
|
4481
4542
|
const altSeam = seamFigures(altComposite, altStillSet.frames[0].image, inp.stage, altStillSet.viewport, altStillSet.background, undefined, alt.scene !== undefined);
|
|
4482
4543
|
const altMean = round3(altSeam.mean);
|
|
4483
4544
|
const altScale = round6(altStillSet.viewport.scale);
|
|
4484
4545
|
const altFailed = seamFails(altMean, altSeam.over40, altScale);
|
|
4546
|
+
if (altFailed) {
|
|
4547
|
+
const hint = armSplitSetHint(inp.parts, alt);
|
|
4548
|
+
if (hint !== null) setHints.set(alt.name, hint);
|
|
4549
|
+
}
|
|
4485
4550
|
let altPairs: SeamPairRow[] | null = null;
|
|
4486
4551
|
if (seamPairsAsked || altFailed) {
|
|
4487
|
-
const
|
|
4488
|
-
const byName = new Map(alt.records.map((r) => [r.name, r]));
|
|
4489
|
-
const placed = inp.parts.parts
|
|
4490
|
-
.filter((p) => !hides.has(p.name))
|
|
4491
|
-
.map((p) => {
|
|
4492
|
-
const rec = byName.get(p.name);
|
|
4493
|
-
const pngName = rec === undefined ? p.name : `${alt.name}_${rec.name}`;
|
|
4494
|
-
const box = rec ?? p;
|
|
4495
|
-
return { name: p.name, from: box.from, x: box.x, y: box.y, image: readPng(join(inp.partsDir, `${pngName}.png`)) };
|
|
4496
|
-
});
|
|
4552
|
+
const placed = setPlacements(inp.parts, alt, rigSlotOrder).map(({ name, png, box }) => ({ name, from: box.from, x: box.x, y: box.y, image: readPng(join(inp.partsDir, `${png}.png`)) }));
|
|
4497
4553
|
const split = seamPairRows(altSeam, placed, inp.parts.rig_size, altStillSet.viewport);
|
|
4498
4554
|
const altSeamDir = join(seamDir, alt.name);
|
|
4499
4555
|
mkdirSync(altSeamDir, { recursive: true });
|
|
@@ -4626,7 +4682,8 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
4626
4682
|
`mean |d| ${setFig.seam_mean}/255 and ${setFig.seam_px_over_40} frame px over ${SEAM_PX_LEVEL} (${setFig.seam_px_over_80} over ${SEAM_PX_LEVEL_HIGH}) at frame scale ${setFig.seam_frame_scale}, ${seamRigPxText(setFig.seam_px_over_40, setFig.seam_frame_scale)} rig px (the count / s²); mean <= ${SEAM_MEAN_BAR.toFixed(1)} and <= ${SEAM_PX_BAR} rig px over ${SEAM_PX_LEVEL} are required` +
|
|
4627
4683
|
(worst === null
|
|
4628
4684
|
? `; no pixel is over ${SEAM_PX_LEVEL}, so the mean alone fails and there is no pair to name`
|
|
4629
|
-
: `; worst of ${(setFig.seam_pairs as SeamPairRow[]).length} pair(s): ${seamPairText(worst)}`)
|
|
4685
|
+
: `; worst of ${(setFig.seam_pairs as SeamPairRow[]).length} pair(s): ${seamPairText(worst)}`) +
|
|
4686
|
+
(setHints.get(setName) ?? ''),
|
|
4630
4687
|
});
|
|
4631
4688
|
}
|
|
4632
4689
|
}
|
package/src/config.ts
CHANGED
|
@@ -262,6 +262,13 @@ export interface AlternateSetConfig {
|
|
|
262
262
|
drawn?: Record<string, number>;
|
|
263
263
|
/** Explicit bone endpoints on this alternate painting, full source-crop pixels, x right/y down. */
|
|
264
264
|
tips?: Record<string, Point>;
|
|
265
|
+
/**
|
|
266
|
+
* Issue #664: covered limb segment parts this set draws on their front slot
|
|
267
|
+
* (`<part>_front`, declared by `config.limbs.<limb>.front`) instead of the
|
|
268
|
+
* base slot, which the set hides. Absent, the set draws every covered part
|
|
269
|
+
* in its base slot.
|
|
270
|
+
*/
|
|
271
|
+
front?: string[];
|
|
265
272
|
}
|
|
266
273
|
|
|
267
274
|
export interface Assemble {
|
|
@@ -935,6 +942,18 @@ export interface Limb {
|
|
|
935
942
|
split?: LimbSplit;
|
|
936
943
|
/** Explicit rig-stage adjacency; absent, the existing limb closure is unchanged. */
|
|
937
944
|
layout?: LimbLayout;
|
|
945
|
+
/** Issue #664: a second, empty-at-setup slot per named segment part; absent, no slot is added and no byte moves. */
|
|
946
|
+
front?: LimbFront;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* Issue #664: `parts` are this limb's own segment parts; each gets a slot
|
|
951
|
+
* `<part>_front` on its base slot's bone with no setup attachment, placed in the
|
|
952
|
+
* final setup slot order immediately after `after`'s whole slot family.
|
|
953
|
+
*/
|
|
954
|
+
export interface LimbFront {
|
|
955
|
+
parts: string[];
|
|
956
|
+
after: string;
|
|
938
957
|
}
|
|
939
958
|
|
|
940
959
|
export type LimbLayoutTarget = { limb: string; part?: never } | { part: string; limb?: never };
|
|
@@ -2137,7 +2156,7 @@ function checkAlternates(
|
|
|
2137
2156
|
const seenNames = new Map<string, number>();
|
|
2138
2157
|
(v as Json[]).forEach((entry, i) => {
|
|
2139
2158
|
const at = `${p}[${i}]`;
|
|
2140
|
-
const e = c.object(at, entry, ['name'], ['source', 'full', 'head', 'parts', 'hides', 'head_box', 'cuts', 'skeleton', 'drawn', 'tips']);
|
|
2159
|
+
const e = c.object(at, entry, ['name'], ['source', 'full', 'head', 'parts', 'hides', 'head_box', 'cuts', 'skeleton', 'drawn', 'tips', 'front']);
|
|
2141
2160
|
if (e === null) return;
|
|
2142
2161
|
if ('name' in e && c.string(`${at}.name`, e.name)) {
|
|
2143
2162
|
if (!partNameOk(e.name)) c.fail('CONFIG_PART_NAME', `${at}.name`, `names the set ${show(e.name)}; a set name is a file prefix, so it may not be empty, start with "." or hold a slash`);
|
|
@@ -2228,6 +2247,27 @@ function checkAlternates(
|
|
|
2228
2247
|
} else seenHides.add(hn);
|
|
2229
2248
|
});
|
|
2230
2249
|
}
|
|
2250
|
+
// Issue #664: a part the set draws on its front slot is one the set covers and a limb declares a front slot for.
|
|
2251
|
+
if ('front' in e) {
|
|
2252
|
+
if (!Array.isArray(e.front) || e.front.length === 0) {
|
|
2253
|
+
c.fail('CONFIG_SET_FRONT', `${at}.front`, `is ${show(e.front)}; a nonempty list of covered limb segment parts with a declared front slot is required`);
|
|
2254
|
+
} else {
|
|
2255
|
+
const seenFront = new Set<string>();
|
|
2256
|
+
(e.front as Json[]).forEach((fn, k) => {
|
|
2257
|
+
if (!c.string(`${at}.front[${k}]`, fn)) return;
|
|
2258
|
+
const declaredBy = limbs?.front.get(fn);
|
|
2259
|
+
const covered = 'parts' in e && seenParts.has(fn) && !seenHides.has(fn);
|
|
2260
|
+
if (seenFront.has(fn)) c.fail('CONFIG_SET_FRONT', `${at}.front[${k}]`, `repeats "${fn}"; each front part is named once`);
|
|
2261
|
+
else if (!covered) {
|
|
2262
|
+
c.fail('CONFIG_SET_FRONT', `${at}.front[${k}]`, `names "${fn}", which this set does not cover${'parts' in e ? ` (its parts less its hides: ${[...seenParts].filter((q) => !seenHides.has(q)).map((q) => `"${q}"`).join(', ') || 'none'})` : ' (a set without parts is a full set; front slots are for a subset set over a limb)'}; a set draws on a front slot only the parts it covers`);
|
|
2263
|
+
} else if (declaredBy === undefined) {
|
|
2264
|
+
const declared = [...(limbs?.front.keys() ?? [])].map((q) => `"${q}"`).join(', ') || 'none';
|
|
2265
|
+
c.fail('CONFIG_SET_FRONT', `${at}.front[${k}]`, `names "${fn}", which no config.limbs.<limb>.front.parts lists (front slots declared: ${declared}); declare the front slot on its limb first`);
|
|
2266
|
+
}
|
|
2267
|
+
seenFront.add(fn);
|
|
2268
|
+
});
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2231
2271
|
if ('parts' in e && limbs !== null) {
|
|
2232
2272
|
for (const [limbName, chain] of limbs.chains) {
|
|
2233
2273
|
const coveredSegs = chain.parts.filter((sp) => seenParts.has(sp) && !seenHides.has(sp));
|
|
@@ -2957,9 +2997,10 @@ function checkRegions(c: Check, v: Json, bones: Set<string>): void {
|
|
|
2957
2997
|
return;
|
|
2958
2998
|
}
|
|
2959
2999
|
for (const [part, bone] of Object.entries(v as Record<string, Json>)) {
|
|
2960
|
-
if (typeof bone !== 'string'
|
|
2961
|
-
|
|
2962
|
-
|
|
3000
|
+
if (typeof bone !== 'string') c.fail('CONFIG_NAME_RESOLVES', `config.regions.${part}`, `is ${show(bone)}; a bone name is required`);
|
|
3001
|
+
// Issue #671: the part and the bone by name, so an entry `propose --only-missing` drafted on a bone the config
|
|
3002
|
+
// does not declare says which.
|
|
3003
|
+
else if (!bones.has(bone)) c.fail('CONFIG_NAME_RESOLVES', `config.regions.${part}`, `names the bone ${show(bone)} for the part "${part}", which config.bones does not declare; a declared bone is required`);
|
|
2963
3004
|
}
|
|
2964
3005
|
}
|
|
2965
3006
|
|
|
@@ -2968,6 +3009,8 @@ interface LimbNames {
|
|
|
2968
3009
|
parts: Map<string, { bone: string; at: string }>;
|
|
2969
3010
|
consumed: Map<string, string>;
|
|
2970
3011
|
chains: Map<string, { parts: string[]; bones: string[]; froms: string[] }>;
|
|
3012
|
+
/** Issue #664: each segment part a limb's `front.parts` names -> that limb. */
|
|
3013
|
+
front: Map<string, string>;
|
|
2971
3014
|
}
|
|
2972
3015
|
|
|
2973
3016
|
/**
|
|
@@ -2993,7 +3036,7 @@ interface LimbNames {
|
|
|
2993
3036
|
* resolved. Returns the limb parts and the parts the limbs take.
|
|
2994
3037
|
*/
|
|
2995
3038
|
function checkLimbs(c: Check, v: Json, made: { parts: string[]; patches: string[]; cuts: string[] }, names: { bones: Set<string>; parents: Map<string, string> } | null, resolveLayoutParts = true): LimbNames {
|
|
2996
|
-
const out: LimbNames = { parts: new Map(), consumed: new Map(), chains: new Map() };
|
|
3039
|
+
const out: LimbNames = { parts: new Map(), consumed: new Map(), chains: new Map(), front: new Map() };
|
|
2997
3040
|
if (!isPlainObject(v)) {
|
|
2998
3041
|
c.fail('CONFIG_FIELD_TYPE', 'config.limbs', `is ${show(v)}; an object of limb name -> {"segments": [...]} is required`);
|
|
2999
3042
|
return out;
|
|
@@ -3004,7 +3047,7 @@ function checkLimbs(c: Check, v: Json, made: { parts: string[]; patches: string[
|
|
|
3004
3047
|
const splitLimbs: string[] = [];
|
|
3005
3048
|
for (const [limb, spec] of Object.entries(v)) {
|
|
3006
3049
|
const at = `config.limbs.${limb}`;
|
|
3007
|
-
const o = c.object(at, spec, ['segments'], ['split', 'layout']);
|
|
3050
|
+
const o = c.object(at, spec, ['segments'], ['split', 'layout', 'front']);
|
|
3008
3051
|
if (o === null) continue;
|
|
3009
3052
|
if ('split' in o) {
|
|
3010
3053
|
const sp = c.object(`${at}.split`, o.split, [], ['line', 'edge']);
|
|
@@ -3143,9 +3186,61 @@ function checkLimbs(c: Check, v: Json, made: { parts: string[]; patches: string[
|
|
|
3143
3186
|
}
|
|
3144
3187
|
}
|
|
3145
3188
|
checkLimbLayouts(c, v, made, out, resolveLayoutParts);
|
|
3189
|
+
checkLimbFronts(c, v, made, out, resolveLayoutParts);
|
|
3146
3190
|
return out;
|
|
3147
3191
|
}
|
|
3148
3192
|
|
|
3193
|
+
/**
|
|
3194
|
+
* Issue #664: `config.limbs.<limb>.front` — `parts` a nonempty list of this
|
|
3195
|
+
* limb's own segment parts, each once (`CONFIG_FRONT_SCOPE`); `after` one
|
|
3196
|
+
* produced part, the same notion {@link checkLimbLayouts} holds a part target
|
|
3197
|
+
* to, and not a part of this limb (`CONFIG_FRONT_NAME`). A front slot and an
|
|
3198
|
+
* explicit layout are not composed: a config declaring both, on one limb or on
|
|
3199
|
+
* two, is refused (`CONFIG_FRONT_LAYOUT`).
|
|
3200
|
+
*/
|
|
3201
|
+
function checkLimbFronts(c: Check, limbs: Record<string, Json>, made: { parts: string[]; patches: string[]; cuts: string[] }, names: LimbNames, resolveParts: boolean): void {
|
|
3202
|
+
const produced = new Set([...made.parts, ...made.patches, ...made.cuts].filter((n) => !names.consumed.has(n)));
|
|
3203
|
+
for (const n of names.parts.keys()) produced.add(n);
|
|
3204
|
+
const layouts = Object.entries(limbs).filter(([, raw]) => isPlainObject(raw) && 'layout' in raw).map(([l]) => l);
|
|
3205
|
+
for (const [limb, raw] of Object.entries(limbs)) {
|
|
3206
|
+
if (!isPlainObject(raw) || !('front' in raw)) continue;
|
|
3207
|
+
const at = `config.limbs.${limb}.front`;
|
|
3208
|
+
if (layouts.length > 0) {
|
|
3209
|
+
c.fail(
|
|
3210
|
+
'CONFIG_FRONT_LAYOUT',
|
|
3211
|
+
at,
|
|
3212
|
+
`is declared while ${layouts.map((l) => `config.limbs.${l}.layout`).join(', ')} ${layouts.length === 1 ? 'is' : 'are'} declared; version 1 of front slots does not compose with an explicit limb layout (issue #647) — the layout's adjacency proof would have to move the front slots too — so declare one or the other on a rig`,
|
|
3213
|
+
);
|
|
3214
|
+
}
|
|
3215
|
+
const f = c.object(at, raw.front, ['parts', 'after'], []);
|
|
3216
|
+
if (f === null) continue;
|
|
3217
|
+
const own = names.chains.get(limb)?.parts ?? [];
|
|
3218
|
+
if ('parts' in f) {
|
|
3219
|
+
const ps = f.parts;
|
|
3220
|
+
if (!Array.isArray(ps) || ps.length === 0 || !ps.every((p) => typeof p === 'string' && own.includes(p))) {
|
|
3221
|
+
c.fail('CONFIG_FRONT_SCOPE', `${at}.parts`, `is ${show(ps)}; a nonempty list of this limb's own segment parts (${own.join(', ')}) is required — a front slot is a second slot for one of its segments`);
|
|
3222
|
+
} else if (new Set(ps).size !== ps.length) {
|
|
3223
|
+
c.fail('CONFIG_FRONT_SCOPE', `${at}.parts`, `is ${show(ps)}; each segment part is named once`);
|
|
3224
|
+
} else {
|
|
3225
|
+
for (const p of ps as string[]) {
|
|
3226
|
+
names.front.set(p, limb);
|
|
3227
|
+
// The front slot is named <part>_front; a part already made under that name would take the same slot name.
|
|
3228
|
+
if (produced.has(`${p}_front`)) c.fail('CONFIG_FRONT_NAME', `${at}.parts`, `names "${p}", whose front slot "${p}_front" is the name of a part this config already makes; rename that part, since a slot name is held once`);
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3231
|
+
}
|
|
3232
|
+
if ('after' in f && c.string(`${at}.after`, f.after)) {
|
|
3233
|
+
const n = f.after;
|
|
3234
|
+
if (own.includes(n)) {
|
|
3235
|
+
c.fail('CONFIG_FRONT_NAME', `${at}.after`, `names "${n}", a segment part of this same limb; a front slot is placed after a part the limb is drawn behind, never after its own segment`);
|
|
3236
|
+
} else if (resolveParts && !produced.has(n)) {
|
|
3237
|
+
const consumed = names.consumed.get(n);
|
|
3238
|
+
c.fail('CONFIG_FRONT_NAME', `${at}.after`, `names "${n}"; a produced part (${[...produced].join(', ')}) is required${consumed === undefined ? '' : `; "${n}" is consumed by limb "${consumed}" into ${names.chains.get(consumed)?.parts.join(', ')}`}`);
|
|
3239
|
+
}
|
|
3240
|
+
}
|
|
3241
|
+
}
|
|
3242
|
+
}
|
|
3243
|
+
|
|
3149
3244
|
/** Validate after every limb is known; a declaration may refer forward by name. */
|
|
3150
3245
|
function checkLimbLayouts(c: Check, limbs: Record<string, Json>, made: { parts: string[]; patches: string[]; cuts: string[] }, names: LimbNames, resolveParts: boolean): void {
|
|
3151
3246
|
const produced = new Set([...made.parts, ...made.patches, ...made.cuts].filter((n) => !names.consumed.has(n)));
|
package/src/configwrite.ts
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* The three config updates proposed by the CLI (issue #356). Pure JSON merge:
|
|
3
3
|
* no file reads/writes and no substitute for the stage's existing validator.
|
|
4
4
|
* A present proposal section replaces that whole field; an absent optional
|
|
5
|
-
* section is retained.
|
|
5
|
+
* section is retained. `proposal-missing` (issue #671, `--only-missing`) instead
|
|
6
|
+
* adds only the `meshes` / `regions` entries of proposed parts the config attaches
|
|
7
|
+
* by neither, one edit per entry, and leaves every existing entry as it is. The caller supplies the proposer's own section tuple,
|
|
6
8
|
* avoiding a second policy list or a runtime import of the proposer graph.
|
|
7
9
|
*/
|
|
8
10
|
import type { PlanProposal } from './assemble.ts';
|
|
@@ -16,10 +18,14 @@ export interface ConfigObject { [key: string]: ConfigJson }
|
|
|
16
18
|
export type ConfigWritePatch =
|
|
17
19
|
| { kind: 'head-box'; head_box: HeadBoxProposal['head_box'] }
|
|
18
20
|
| { kind: 'assemble-plan'; plan: PlanProposal['plan']; extend_below_crop: PlanProposal['extend_below_crop'] }
|
|
19
|
-
| { kind: 'proposal'; proposal: Proposal; sections: typeof PROPOSAL_CONFIG_SECTIONS }
|
|
21
|
+
| { kind: 'proposal'; proposal: Proposal; sections: typeof PROPOSAL_CONFIG_SECTIONS }
|
|
22
|
+
/** Issue #671 (`--only-missing`): only `meshes.<part>` / `regions.<part>` for a proposed part the config attaches by neither. */
|
|
23
|
+
| { kind: 'proposal-missing'; proposal: Proposal; parts: ReadonlyArray<{ name: string; from: string }> };
|
|
20
24
|
export interface ConfigWriteChange {
|
|
21
25
|
path: string;
|
|
22
26
|
kind: 'added' | 'replaced' | 'removed';
|
|
27
|
+
/** The value written, where the path alone does not say it (an array element added, issue #671). */
|
|
28
|
+
value?: string;
|
|
23
29
|
}
|
|
24
30
|
export interface ConfigWriteResult {
|
|
25
31
|
config: ConfigObject;
|
|
@@ -111,7 +117,49 @@ export function mergeConfigProposal(raw: unknown, patch: ConfigWritePatch): Conf
|
|
|
111
117
|
}
|
|
112
118
|
break;
|
|
113
119
|
}
|
|
114
|
-
|
|
120
|
+
case 'proposal-missing': {
|
|
121
|
+
// Issue #671: a config proposed before a part existed (the #490 arm split's drape_<s> and hand_<s>) gains its
|
|
122
|
+
// plan row (split parts only) and an entry for that part alone, entry by entry, in the section the proposal drafts
|
|
123
|
+
// it in. A part the config already attaches, by either section, keeps its entry as written; nothing else of the
|
|
124
|
+
// proposal is read.
|
|
125
|
+
const attached = (part: string): boolean => (object(config.meshes) && own(config.meshes, part)) || (object(config.regions) && own(config.regions, part));
|
|
126
|
+
for (const section of ['meshes', 'regions'] as const) {
|
|
127
|
+
if (config[section] !== undefined && !object(config[section])) return refuse(`config.${section}`, 'is not an object; an object of part entries is required before an entry is added to it');
|
|
128
|
+
}
|
|
129
|
+
const added: ConfigWriteChange[] = [];
|
|
130
|
+
// The #490 split's parts the plan does not name, each row where `mergedArmSplitPlan` puts it: the drape just
|
|
131
|
+
// before the full run's handwear-<s> row, the hand just after it. A part of any other origin is not planned here.
|
|
132
|
+
const assemble = config.assemble;
|
|
133
|
+
const plan = object(assemble) && Array.isArray(assemble.plan) ? assemble.plan : null;
|
|
134
|
+
if (plan !== null) {
|
|
135
|
+
const row = (e: ConfigJson): [string, string, string] | null =>
|
|
136
|
+
Array.isArray(e) && e.length === 3 && e.every((x) => typeof x === 'string') ? (e as [string, string, string]) : null;
|
|
137
|
+
for (const part of patch.parts) {
|
|
138
|
+
const m = /^full:(drape|hand)-([rl])$/.exec(part.from);
|
|
139
|
+
if (m === null) continue;
|
|
140
|
+
if (plan.some((e) => { const r = row(e); return r !== null && (r[0] === part.name || (r[1] === 'full' && r[2] === `${m[1]}-${m[2]}`)); })) continue;
|
|
141
|
+
const arm = plan.findIndex((e) => { const r = row(e); return r !== null && r[1] === 'full' && r[2] === `handwear-${m[2]}`; });
|
|
142
|
+
if (arm < 0) continue;
|
|
143
|
+
const at = m[1] === 'drape' ? arm : arm + 1;
|
|
144
|
+
const value: ConfigJson = [part.name, 'full', `${m[1]}-${m[2]}`];
|
|
145
|
+
plan.splice(at, 0, value);
|
|
146
|
+
edits.push({ path: ['assemble', 'plan', at], value, insert: true, inline: true });
|
|
147
|
+
added.push({ path: `assemble.plan[${at}]`, kind: 'added', value: JSON.stringify(value) });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
for (const section of ['meshes', 'regions'] as const) {
|
|
151
|
+
for (const [part, entry] of Object.entries(patch.proposal[section])) {
|
|
152
|
+
if (attached(part)) continue;
|
|
153
|
+
const value = clone(entry, field(`proposal.${section}`, part));
|
|
154
|
+
if (!object(config[section])) config[section] = {};
|
|
155
|
+
(config[section] as ConfigObject)[part] = value;
|
|
156
|
+
edits.push({ path: [section, part], value });
|
|
157
|
+
added.push({ path: field(section, part), kind: 'added' });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return { config, changes: added, edits };
|
|
161
|
+
}
|
|
162
|
+
default: return refuse('write-config', 'has no supported operation; head-box, assemble-plan, proposal or proposal-missing is required');
|
|
115
163
|
}
|
|
116
164
|
return { config, changes: changes(before, config), edits };
|
|
117
165
|
}
|
package/src/meshdraft.ts
CHANGED
|
@@ -589,6 +589,11 @@ export interface ConfigEdit {
|
|
|
589
589
|
path: readonly (string | number)[];
|
|
590
590
|
value: unknown;
|
|
591
591
|
insert?: boolean;
|
|
592
|
+
/**
|
|
593
|
+
* With `insert` (issue #671): in an array written on one line, the element goes in as `JSON.stringify(value)`
|
|
594
|
+
* beside its neighbours on that line, so a one-line plan stays one line; elsewhere it changes nothing.
|
|
595
|
+
*/
|
|
596
|
+
inline?: boolean;
|
|
592
597
|
}
|
|
593
598
|
|
|
594
599
|
/** The span at `path`, or null where the path does not resolve (a key absent, or a step that is not an object). */
|
|
@@ -607,10 +612,18 @@ function indentAt(text: string, at: number): string {
|
|
|
607
612
|
}
|
|
608
613
|
|
|
609
614
|
/** An element inserted into the array at `arrayPath` before its element `index` (at its length: after the last). */
|
|
610
|
-
function insertElement(text: string, arrayPath: readonly (string | number)[], index: number, value: unknown): string {
|
|
615
|
+
function insertElement(text: string, arrayPath: readonly (string | number)[], index: number, value: unknown, inline = false): string {
|
|
611
616
|
const arr = spanOrNull(text, arrayPath);
|
|
612
617
|
if (arr === null || text[arr.start] !== '[') throw new Error(`splicedEdits: ${arrayPath.join('.') || 'the document'} is not an array`);
|
|
613
618
|
const next = spanOrNull(text, [...arrayPath, index]);
|
|
619
|
+
if (inline && !text.slice(arr.start, arr.end).includes('\n')) {
|
|
620
|
+
const body = JSON.stringify(value);
|
|
621
|
+
if (next !== null) return `${text.slice(0, next.start)}${body},${text.slice(next.start)}`;
|
|
622
|
+
const last = index > 0 ? spanOrNull(text, [...arrayPath, index - 1]) : null;
|
|
623
|
+
if (index > 0 && last === null) throw new Error(`splicedEdits: ${arrayPath.join('.')} has no element ${index - 1}`);
|
|
624
|
+
if (last === null) return `${text.slice(0, arr.start + 1)}${body}${text.slice(arr.end - 1)}`;
|
|
625
|
+
return `${text.slice(0, last.end)},${body}${text.slice(last.end)}`;
|
|
626
|
+
}
|
|
614
627
|
if (next !== null) {
|
|
615
628
|
// Before the element: the new one takes its line, and the old one follows on a line of its own at the same indent.
|
|
616
629
|
const indent = indentAt(text, next.start);
|
|
@@ -626,11 +639,11 @@ function insertElement(text: string, arrayPath: readonly (string | number)[], in
|
|
|
626
639
|
}
|
|
627
640
|
|
|
628
641
|
/** One edit on `text`; every byte it does not name is the input's. */
|
|
629
|
-
function spliceOne(text: string, path: readonly (string | number)[], value: unknown, insert = false): string {
|
|
642
|
+
function spliceOne(text: string, path: readonly (string | number)[], value: unknown, insert = false, inline = false): string {
|
|
630
643
|
const step = path[path.length - 1];
|
|
631
644
|
if (insert) {
|
|
632
645
|
if (typeof step !== 'number') throw new Error(`splicedEdits: an insert names an array index; ${path.join('.')} does not`);
|
|
633
|
-
return insertElement(text, path.slice(0, -1), step, value);
|
|
646
|
+
return insertElement(text, path.slice(0, -1), step, value, inline);
|
|
634
647
|
}
|
|
635
648
|
const at = spanOrNull(text, path);
|
|
636
649
|
if (value === undefined) {
|
|
@@ -694,7 +707,7 @@ function firstMoved(got: unknown, want: unknown, path: readonly string[]): strin
|
|
|
694
707
|
*/
|
|
695
708
|
export function splicedEdits(text: string, edits: readonly ConfigEdit[]): { text: string; moved: string | null } {
|
|
696
709
|
let out = text;
|
|
697
|
-
for (const e of edits) out = spliceOne(out, e.path, e.value, e.insert === true);
|
|
710
|
+
for (const e of edits) out = spliceOne(out, e.path, e.value, e.insert === true, e.inline === true);
|
|
698
711
|
const want = JSON.parse(text) as Record<string, unknown>;
|
|
699
712
|
for (const e of edits) {
|
|
700
713
|
let o: Record<string | number, unknown> | unknown[] = want;
|
package/src/parts.ts
CHANGED
|
@@ -293,10 +293,22 @@ export interface AlternateSetMap {
|
|
|
293
293
|
threshold?: { yaw: number; pitch: number };
|
|
294
294
|
}
|
|
295
295
|
|
|
296
|
+
/**
|
|
297
|
+
* Issue #664: the suffix of a limb segment part's front slot — a second slot on
|
|
298
|
+
* the segment's bone, empty at setup, that a gesture set draws the part on.
|
|
299
|
+
*/
|
|
300
|
+
export const FRONT_SUFFIX = '_front';
|
|
301
|
+
|
|
296
302
|
export interface AlternatePartsRecord {
|
|
297
303
|
name: string;
|
|
298
304
|
parts?: string[];
|
|
299
305
|
hides?: string[];
|
|
306
|
+
/**
|
|
307
|
+
* Issue #664: the covered parts this set draws on their front slot: each `p`
|
|
308
|
+
* is mapped as `slots["<p>_front"]` (never `slots[p]`) and listed in `hides`.
|
|
309
|
+
* Written only when the set declares `front`.
|
|
310
|
+
*/
|
|
311
|
+
front?: string[];
|
|
300
312
|
slots: Record<string, string>;
|
|
301
313
|
records: PartRecord[];
|
|
302
314
|
ghost_px: Record<string, number>;
|
|
@@ -451,6 +463,7 @@ export function serializeParts(file: PartsFile): string {
|
|
|
451
463
|
name: a.name,
|
|
452
464
|
...(a.parts === undefined ? {} : { parts: a.parts }),
|
|
453
465
|
...(a.hides === undefined ? {} : { hides: a.hides }),
|
|
466
|
+
...(a.front === undefined ? {} : { front: a.front }),
|
|
454
467
|
slots: a.slots,
|
|
455
468
|
records: serializePartList(a.records),
|
|
456
469
|
ghost_px: Object.fromEntries(Object.keys(a.ghost_px).sort().map((k) => [k, a.ghost_px[k]])),
|
|
@@ -697,6 +710,20 @@ function checkParts(raw: unknown, path: string): PartsFile {
|
|
|
697
710
|
}
|
|
698
711
|
}
|
|
699
712
|
}
|
|
713
|
+
// Issue #664: each front part is drawn on its front slot and hidden on its base slot, never both.
|
|
714
|
+
if ('front' in set) {
|
|
715
|
+
const slots = typeof set.slots === 'object' && set.slots !== null && !Array.isArray(set.slots) ? (set.slots as Record<string, unknown>) : {};
|
|
716
|
+
const hides = Array.isArray(set.hides) ? set.hides : [];
|
|
717
|
+
if (!Array.isArray(set.front) || set.front.length === 0 || !set.front.every((p) => typeof p === 'string')) {
|
|
718
|
+
fail('PARTS_FIELD_TYPE', `${at} front`, `is ${show(set.front)}; a nonempty array of part names is required`);
|
|
719
|
+
} else {
|
|
720
|
+
for (const p of set.front as string[]) {
|
|
721
|
+
if (!Object.hasOwn(slots, `${p}${FRONT_SUFFIX}`) || !hides.includes(p)) {
|
|
722
|
+
fail('PARTS_FIELD_TYPE', `${at} front "${p}"`, `requires slots."${p}${FRONT_SUFFIX}" and "${p}" in hides; re-run assemble`);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
700
727
|
if (!Array.isArray(set.records)) return;
|
|
701
728
|
set.records.forEach((p, j) => {
|
|
702
729
|
if (typeof p !== 'object' || p === null || Array.isArray(p)) return;
|