@rig-c/parts 1.61.0 → 1.63.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 +3 -0
- package/docs/AUTHORING.md +163 -8
- package/docs/STABILITY.md +30 -10
- package/package.json +2 -2
- package/skills/rig-parts/SKILL.md +1 -1
- package/src/build.ts +14 -6
- package/src/check.ts +518 -294
- package/src/config.ts +190 -8
- package/src/coords.ts +12 -0
- package/src/diagnostics.ts +2 -1
- package/src/explicitmesh.ts +149 -0
- package/src/limblayout.ts +53 -11
- package/src/meshdraft.ts +2 -2
- package/src/meshstats.ts +1 -1
- package/src/parts.ts +9 -0
- package/src/propose.ts +7 -2
- package/src/rig.ts +128 -9
- package/src/scene.ts +6 -2
- package/src/setfocus.ts +21 -0
- package/src/squeeze.ts +2 -1
- package/src/structure.ts +5 -1
package/src/config.ts
CHANGED
|
@@ -93,6 +93,7 @@ import { CLOTH_TARGETS, type ClothRecipes, RECIPE_STRENGTH, RIGC_DEFAULT_DAMPING
|
|
|
93
93
|
import { GRID, MAX_SIDE } from './contour.ts';
|
|
94
94
|
import { type Problem, refuseIfAny } from './errors.ts';
|
|
95
95
|
import { edgeLength } from './length.ts';
|
|
96
|
+
import { setFocusProblems } from './setfocus.ts';
|
|
96
97
|
import { isSkeletonName, KEYPOINT_NAMES, type KeypointName, type PosePoints, scaledPoints, SKELETON_NAMES, type SkeletonName } from './skeleton.ts';
|
|
97
98
|
import { acceptedTagNames, AUTHOR_LABEL_RULE, AUTHOR_PREFIX, readLayerTag } from './tags.ts';
|
|
98
99
|
import { EAR_DEPTH_RANGE, FACE_DEFORM_FRACTIONS, FACE_DEFORM_RANGES, type FaceDeformKey, FACE_RATED_PITCH_BAND, FACE_RATED_YAW_BAND, TURN_BONE, type TurnSpec, turnNearest } from './turn.ts';
|
|
@@ -264,6 +265,8 @@ export interface Cut {
|
|
|
264
265
|
|
|
265
266
|
export interface AlternateSetConfig {
|
|
266
267
|
name: string;
|
|
268
|
+
/** Authored point on this painting, x right/y down; omitted means no focus. */
|
|
269
|
+
focus?: Point;
|
|
267
270
|
source?: string;
|
|
268
271
|
full?: string;
|
|
269
272
|
head?: string;
|
|
@@ -346,7 +349,7 @@ export type Segment = string | [string, Point, Point];
|
|
|
346
349
|
* locally refined by rig-c's `reduceMesh` under the author's declared
|
|
347
350
|
* bounds (`src/automesh.ts`).
|
|
348
351
|
*/
|
|
349
|
-
export type MeshSpec = (LatticeMeshSpec | ContourMeshSpec | AutoMeshSpec | InfluenceMeshSpec) & { gather?: false };
|
|
352
|
+
export type MeshSpec = (LatticeMeshSpec | ContourMeshSpec | AutoMeshSpec | InfluenceMeshSpec | ExplicitMeshSpec) & { gather?: false };
|
|
350
353
|
|
|
351
354
|
/**
|
|
352
355
|
* One mesh in the influence mode (issue #378): rig-c's `segments` lattice over the part at `cell` px, every vertex
|
|
@@ -357,6 +360,55 @@ export type MeshSpec = (LatticeMeshSpec | ContourMeshSpec | AutoMeshSpec | Influ
|
|
|
357
360
|
* `hold_tip: true` (issue #615, optional, written by `propose --cloth` from the recipe's `split.hold_tip`) smooths the
|
|
358
361
|
* pulled shares by the lattice's held-fork passes, capped at `max`; absent, the shares are rig-c's as pulled.
|
|
359
362
|
*/
|
|
363
|
+
/** One island slot of a multi-island explicit mesh payload (issue #734). */
|
|
364
|
+
export interface ExplicitMeshIslandSpec {
|
|
365
|
+
slot: string;
|
|
366
|
+
bone?: string;
|
|
367
|
+
before?: string;
|
|
368
|
+
uvs: number[];
|
|
369
|
+
triangles: number[];
|
|
370
|
+
hull: number;
|
|
371
|
+
weights: Array<Array<{ bone: string; x: number; y: number; weight: number }>>;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** An accepted mesh transferred without regenerating topology or bone-local bind positions (issue #658, #734). */
|
|
375
|
+
export interface ExplicitMeshSpec {
|
|
376
|
+
/** Direct bone names: the first is the default slot bone; all weighted and island slot bones must be declared here. No segment geometry is regenerated. */
|
|
377
|
+
segments: Segment[];
|
|
378
|
+
explicit: {
|
|
379
|
+
/** SHA-256 over the unpadded part's decoded RGBA bytes. */
|
|
380
|
+
image_sha256: string;
|
|
381
|
+
/** SHA-256 of JSON.stringify([rig width, rig height, x, y, w, h]). */
|
|
382
|
+
region_sha256: string;
|
|
383
|
+
/** Normalized UVs over the ordinary PAD-padded rig image, as rig-c reads them (single-slot payload). */
|
|
384
|
+
uvs?: number[];
|
|
385
|
+
triangles?: number[];
|
|
386
|
+
hull?: number;
|
|
387
|
+
/** rig-c by-name weights, in bone-local Spine pixels, copied without rounding (single-slot payload). */
|
|
388
|
+
weights?: Array<Array<{ bone: string; x: number; y: number; weight: number }>>;
|
|
389
|
+
/** Per-island payloads when a part splits across <part> and <part>__island2..<part>__island<N> (issue #734). */
|
|
390
|
+
islands?: ExplicitMeshIslandSpec[];
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/** Every vertex weight row of an explicit mesh, across either its single-slot payload or its `islands` (issue #734). */
|
|
395
|
+
export function explicitWeightRows(m: ExplicitMeshSpec): Array<Array<{ bone: string; x: number; y: number; weight: number }>> {
|
|
396
|
+
if (m.explicit.islands !== undefined) return m.explicit.islands.flatMap((isl) => isl.weights);
|
|
397
|
+
return m.explicit.weights ?? [];
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/** Every slot bone an explicit mesh attaches to: `segments[0]` when single-slot, or each island's `bone ?? segments[0]` (issue #734). */
|
|
401
|
+
export function explicitSlotBones(m: ExplicitMeshSpec): string[] {
|
|
402
|
+
const seg0 = typeof m.segments[0] === 'string' ? m.segments[0] : m.segments[0][0];
|
|
403
|
+
if (m.explicit.islands === undefined) return [seg0];
|
|
404
|
+
const out: string[] = [];
|
|
405
|
+
for (const isl of m.explicit.islands) {
|
|
406
|
+
const b = isl.bone ?? seg0;
|
|
407
|
+
if (!out.includes(b)) out.push(b);
|
|
408
|
+
}
|
|
409
|
+
return out;
|
|
410
|
+
}
|
|
411
|
+
|
|
360
412
|
export interface InfluenceMeshSpec {
|
|
361
413
|
influence: { cell: number; radius: number; across: boolean; max: number; shape: 'linear' | 'smooth'; hold_tip?: true };
|
|
362
414
|
segments: Segment[];
|
|
@@ -742,6 +794,11 @@ export function partBoundBones(b: PartBinding): Map<string, string[]> {
|
|
|
742
794
|
out.set(part, list);
|
|
743
795
|
};
|
|
744
796
|
for (const [part, m] of Object.entries(b.meshes)) {
|
|
797
|
+
if ('explicit' in m) {
|
|
798
|
+
for (const row of explicitWeightRows(m)) for (const w of row) bind(part, w.bone);
|
|
799
|
+
if (m.explicit.islands !== undefined) for (const bName of explicitSlotBones(m)) bind(part, bName);
|
|
800
|
+
continue;
|
|
801
|
+
}
|
|
745
802
|
for (const sg of m.segments) {
|
|
746
803
|
if (typeof sg !== 'string') bind(part, sg[0]);
|
|
747
804
|
else for (const l of chains.get(sg) ?? [sg]) bind(part, l);
|
|
@@ -1594,7 +1651,7 @@ function parseConfigFrom(raw: Json, base: string | null): { config: CharacterCon
|
|
|
1594
1651
|
if (isPlainObject(t.assemble) && 'alternates' in t.assemble) {
|
|
1595
1652
|
checkAlternates(c, t.assemble.alternates, { parts, patches, cuts }, limbs, names.bones, names.chains, t.regions, t.meshes);
|
|
1596
1653
|
}
|
|
1597
|
-
if ('meshes' in t) checkMeshes(c, t.meshes, names.bones, names.chains);
|
|
1654
|
+
if ('meshes' in t) checkMeshes(c, t.meshes, names.bones, names.chains, t.stops);
|
|
1598
1655
|
if ('regions' in t) checkRegions(c, t.regions, names.bones);
|
|
1599
1656
|
if ('meshes' in t && 'regions' in t && 'assemble' in t) checkCoverage(c, [...parts, ...cuts], patches, t.meshes, t.regions, limbs);
|
|
1600
1657
|
if ('motion' in t) checkMotion(c, t.motion, names.bones, names.chains, 'regions' in t ? t.regions : undefined);
|
|
@@ -1610,7 +1667,8 @@ function parseConfigFrom(raw: Json, base: string | null): { config: CharacterCon
|
|
|
1610
1667
|
const animations = base !== null && typeof from === 'string' && from !== '' ? readAnimationsFrom(c, base, from) : null;
|
|
1611
1668
|
if (animations !== null) {
|
|
1612
1669
|
checkFaceAnimationBand(c, animations, hasAltFace, t.turn, attached);
|
|
1613
|
-
|
|
1670
|
+
const baseSlots = new Set<string>([...parts.filter((n) => !(limbs?.consumed.has(n) ?? false)), ...patches, ...cuts, ...(limbs?.parts.keys() ?? [])]);
|
|
1671
|
+
checkAnimationSetKeys(c, animations, t.assemble, new Set<string>([...parts, ...patches, ...cuts, ...(limbs?.parts.keys() ?? []), ...explicitIslandSlotNames(baseSlots, t.meshes)]));
|
|
1614
1672
|
}
|
|
1615
1673
|
const pose = base === null ? null : poseBeside(c, t.generation, base);
|
|
1616
1674
|
refuseIfAny(c.problems);
|
|
@@ -1841,7 +1899,7 @@ export function parseProposalSections(raw: Json): SkeletonSections & { limbs?: R
|
|
|
1841
1899
|
: [];
|
|
1842
1900
|
checkLimbs(c, top.limbs, { parts: [...new Set(taken)], patches: [], cuts: [] }, names, false);
|
|
1843
1901
|
}
|
|
1844
|
-
if ('meshes' in top) checkMeshes(c, top.meshes, names.bones, names.chains);
|
|
1902
|
+
if ('meshes' in top) checkMeshes(c, top.meshes, names.bones, names.chains, top.stops);
|
|
1845
1903
|
if ('regions' in top) checkRegions(c, top.regions, names.bones);
|
|
1846
1904
|
if ('motion' in top) checkMotion(c, top.motion, names.bones, names.chains, 'regions' in top ? top.regions : undefined);
|
|
1847
1905
|
if ('constraints' in top) checkConstraints(c, top.constraints, names.bones, names.parents);
|
|
@@ -2152,6 +2210,20 @@ function checkCuts(c: Check, v: Json, plan: string[], patches: string[], p = 'co
|
|
|
2152
2210
|
return names;
|
|
2153
2211
|
}
|
|
2154
2212
|
|
|
2213
|
+
function explicitIslandSlotNames(baseSlots: ReadonlySet<string>, meshes: Json): string[] {
|
|
2214
|
+
if (!isPlainObject(meshes)) return [];
|
|
2215
|
+
const out: string[] = [];
|
|
2216
|
+
for (const [part, spec] of Object.entries(meshes)) {
|
|
2217
|
+
if (!baseSlots.has(part) || !isPlainObject(spec) || !isPlainObject(spec.explicit) || !Array.isArray(spec.explicit.islands)) continue;
|
|
2218
|
+
for (let i = 1; i < spec.explicit.islands.length; i++) {
|
|
2219
|
+
const isl = spec.explicit.islands[i];
|
|
2220
|
+
const slot = isPlainObject(isl) && typeof isl.slot === 'string' && isl.slot !== '' ? isl.slot : `${part}__island${i + 1}`;
|
|
2221
|
+
out.push(slot);
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
return out;
|
|
2225
|
+
}
|
|
2226
|
+
|
|
2155
2227
|
function checkAlternates(
|
|
2156
2228
|
c: Check,
|
|
2157
2229
|
v: Json,
|
|
@@ -2164,16 +2236,20 @@ function checkAlternates(
|
|
|
2164
2236
|
): void {
|
|
2165
2237
|
const p = 'config.assemble.alternates';
|
|
2166
2238
|
if (!c.array(p, v, true)) return;
|
|
2167
|
-
const
|
|
2239
|
+
const baseSlots = new Set<string>([
|
|
2168
2240
|
...made.parts.filter((n) => !(limbs?.consumed.has(n) ?? false)),
|
|
2169
2241
|
...made.patches,
|
|
2170
2242
|
...made.cuts,
|
|
2171
2243
|
...(limbs?.parts.keys() ?? []),
|
|
2172
2244
|
]);
|
|
2245
|
+
const allSlots = new Set<string>([
|
|
2246
|
+
...baseSlots,
|
|
2247
|
+
...explicitIslandSlotNames(baseSlots, meshes),
|
|
2248
|
+
]);
|
|
2173
2249
|
const seenNames = new Map<string, number>();
|
|
2174
2250
|
(v as Json[]).forEach((entry, i) => {
|
|
2175
2251
|
const at = `${p}[${i}]`;
|
|
2176
|
-
const e = c.object(at, entry, ['name'], ['source', 'full', 'head', 'parts', 'hides', 'head_box', 'cuts', 'skeleton', 'anchor', 'drawn', 'tips', 'front', 'layers']);
|
|
2252
|
+
const e = c.object(at, entry, ['name'], ['source', 'full', 'head', 'parts', 'hides', 'head_box', 'cuts', 'skeleton', 'anchor', 'drawn', 'tips', 'front', 'layers', 'focus']);
|
|
2177
2253
|
if (e === null) return;
|
|
2178
2254
|
if ('name' in e && c.string(`${at}.name`, e.name)) {
|
|
2179
2255
|
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`);
|
|
@@ -2183,6 +2259,7 @@ function checkAlternates(
|
|
|
2183
2259
|
for (const k of ['source', 'full', 'head', 'skeleton'] as const) {
|
|
2184
2260
|
if (k in e) c.string(`${at}.${k}`, e[k]);
|
|
2185
2261
|
}
|
|
2262
|
+
if ('focus' in e) c.problems.push(...setFocusProblems(e.focus, `${at} (set ${show(e.name)}).focus`));
|
|
2186
2263
|
if ('anchor' in e) {
|
|
2187
2264
|
if (!('skeleton' in e)) c.fail('CONFIG_FIELD_PRESENT', `${at}.skeleton`, 'is absent; anchor registers a skeleton set and requires its skeleton file');
|
|
2188
2265
|
const a = e.anchor;
|
|
@@ -2519,7 +2596,21 @@ function checkBones(c: Check, v: Json): { bones: Set<string>; chains: Map<string
|
|
|
2519
2596
|
return { bones, chains, parents };
|
|
2520
2597
|
}
|
|
2521
2598
|
|
|
2522
|
-
|
|
2599
|
+
/** Only drawn names generated by the declared, valid stopped links are additional explicit bindings. */
|
|
2600
|
+
export function explicitBoneNames(bones: ReadonlySet<string>, chains: ReadonlyMap<string, number>, stops: unknown): Set<string> {
|
|
2601
|
+
const out = new Set(bones);
|
|
2602
|
+
if (!Array.isArray(stops)) return out;
|
|
2603
|
+
for (const stop of stops) {
|
|
2604
|
+
if (!isPlainObject(stop) || typeof stop.chain !== 'string') continue;
|
|
2605
|
+
const count = chains.get(stop.chain);
|
|
2606
|
+
if (count === undefined) continue;
|
|
2607
|
+
const links = Array.from({ length: count }, (_, i) => `${stop.chain}${i}`);
|
|
2608
|
+
for (const link of Array.isArray(stop.links) ? stop.links : links) if (typeof link === 'string' && links.includes(link)) out.add(`${link}_d`);
|
|
2609
|
+
}
|
|
2610
|
+
return out;
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2613
|
+
function checkMeshes(c: Check, v: Json, bones: Set<string>, chains: Map<string, number>, stops: Json): void {
|
|
2523
2614
|
if (typeof v !== 'object' || v === null || Array.isArray(v)) {
|
|
2524
2615
|
c.fail('CONFIG_FIELD_TYPE', 'config.meshes', `is ${show(v)}; an object of part name -> mesh is required`);
|
|
2525
2616
|
return;
|
|
@@ -2528,9 +2619,13 @@ function checkMeshes(c: Check, v: Json, bones: Set<string>, chains: Map<string,
|
|
|
2528
2619
|
const at = `config.meshes.${part}`;
|
|
2529
2620
|
// The known keys keep their old order (grid, r, segments) with contour after them, and `r` and `segments` are
|
|
2530
2621
|
// required in the place and words the object check uses, so a lattice mesh's refusals read as they did.
|
|
2531
|
-
const m = c.object(at, spec, [], ['grid', 'r', 'segments', 'contour', 'auto', 'exponent', 'rule', 'ribs', 'influences', 'stray', 'influence', 'gather']);
|
|
2622
|
+
const m = c.object(at, spec, [], ['grid', 'r', 'segments', 'contour', 'auto', 'exponent', 'rule', 'ribs', 'influences', 'stray', 'influence', 'gather', 'explicit']);
|
|
2532
2623
|
if (m === null) continue;
|
|
2533
2624
|
checkGather(c, at, m);
|
|
2625
|
+
if ('explicit' in m) {
|
|
2626
|
+
checkExplicit(c, at, m, explicitBoneNames(bones, chains, stops), part);
|
|
2627
|
+
continue;
|
|
2628
|
+
}
|
|
2534
2629
|
// issue #378: the influence mode weights by rig-c's own pull, so `r` (the distance rule's softening) is not one of its
|
|
2535
2630
|
// fields — it is refused there below, and required in every other mode as it always was.
|
|
2536
2631
|
for (const key of 'influence' in m ? ['segments'] : ['r', 'segments']) if (!(key in m)) c.fail('CONFIG_FIELD_PRESENT', `${at}.${key}`, 'is absent and required');
|
|
@@ -2581,6 +2676,89 @@ function checkMeshes(c: Check, v: Json, bones: Set<string>, chains: Map<string,
|
|
|
2581
2676
|
}
|
|
2582
2677
|
}
|
|
2583
2678
|
|
|
2679
|
+
/** Checks one explicit mesh payload (`uvs`, `triangles`, `hull`, `weights`), either on `explicit` or on `explicit.islands[i]`. */
|
|
2680
|
+
function checkExplicitPayload(c: Check, where: string, o: Record<string, Json>, m: Record<string, Json>, bones: Set<string>): void {
|
|
2681
|
+
const uvs = Array.isArray(o.uvs) ? o.uvs : [];
|
|
2682
|
+
if ('uvs' in o && c.array(`${where}.uvs`, o.uvs, true)) {
|
|
2683
|
+
uvs.forEach((v, i) => c.number(`${where}.uvs[${i}]`, v));
|
|
2684
|
+
if (uvs.length % 2 !== 0) c.fail('CONFIG_EXPLICIT_SHAPE', `${where}.uvs`, `has ${uvs.length} numbers; x/y pairs are required`);
|
|
2685
|
+
}
|
|
2686
|
+
if ('triangles' in o && c.array(`${where}.triangles`, o.triangles, true)) {
|
|
2687
|
+
o.triangles.forEach((v, i) => {
|
|
2688
|
+
if (c.int(`${where}.triangles[${i}]`, v, 0) && v >= uvs.length / 2) c.fail('CONFIG_EXPLICIT_SHAPE', `${where}.triangles[${i}]`, `is ${v}; the payload has ${uvs.length / 2} vertices`);
|
|
2689
|
+
});
|
|
2690
|
+
if (o.triangles.length % 3 !== 0) c.fail('CONFIG_EXPLICIT_SHAPE', `${where}.triangles`, `has ${o.triangles.length} indices; triples are required`);
|
|
2691
|
+
}
|
|
2692
|
+
if ('hull' in o && c.int(`${where}.hull`, o.hull, 1) && o.hull > uvs.length / 2) c.fail('CONFIG_EXPLICIT_SHAPE', `${where}.hull`, `is ${o.hull}; the payload has ${uvs.length / 2} vertices`);
|
|
2693
|
+
if ('weights' in o && c.array(`${where}.weights`, o.weights, true)) {
|
|
2694
|
+
if (o.weights.length !== uvs.length / 2) c.fail('CONFIG_EXPLICIT_SHAPE', `${where}.weights`, `has ${o.weights.length} rows for ${uvs.length / 2} vertices; one row per vertex is required`);
|
|
2695
|
+
o.weights.forEach((row, i) => {
|
|
2696
|
+
const atRow = `${where}.weights[${i}]`;
|
|
2697
|
+
if (!c.array(atRow, row, true)) return;
|
|
2698
|
+
row.forEach((v, j) => {
|
|
2699
|
+
const atWeight = `${atRow}[${j}]`, w = c.object(atWeight, v, ['bone', 'x', 'y', 'weight'], []);
|
|
2700
|
+
if (w === null) return;
|
|
2701
|
+
if ('bone' in w && c.string(`${atWeight}.bone`, w.bone)) {
|
|
2702
|
+
if (!bones.has(w.bone)) c.fail('CONFIG_NAME_RESOLVES', `${atWeight}.bone`, `names "${w.bone}", which is not a bone`);
|
|
2703
|
+
else if (Array.isArray(m.segments) && !m.segments.includes(w.bone)) c.fail('CONFIG_NAME_RESOLVES', `${atWeight}.bone`, `names "${w.bone}", which this explicit mesh's segments do not declare`);
|
|
2704
|
+
}
|
|
2705
|
+
for (const k of ['x', 'y', 'weight']) if (k in w) c.number(`${atWeight}.${k}`, w[k]);
|
|
2706
|
+
});
|
|
2707
|
+
});
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
|
|
2711
|
+
/** The loader checks the payload's shape and names; rig-c's mandatory gate owns mesh validity. */
|
|
2712
|
+
function checkExplicit(c: Check, at: string, m: Record<string, Json>, bones: Set<string>, part: string): void {
|
|
2713
|
+
for (const k of ['grid', 'r', 'contour', 'auto', 'exponent', 'rule', 'ribs', 'influences', 'stray', 'influence']) {
|
|
2714
|
+
if (k in m) c.fail('CONFIG_EXPLICIT_MODE', `${at}.${k}`, 'is declared beside explicit, which transfers an accepted payload without generation; remove the generator field');
|
|
2715
|
+
}
|
|
2716
|
+
if (!('segments' in m)) c.fail('CONFIG_FIELD_PRESENT', `${at}.segments`, 'is absent and required: direct bone names, first the slot bone');
|
|
2717
|
+
else if (c.array(`${at}.segments`, m.segments, true)) m.segments.forEach((bone, i) => {
|
|
2718
|
+
if (c.string(`${at}.segments[${i}]`, bone) && !bones.has(bone)) c.fail('CONFIG_NAME_RESOLVES', `${at}.segments[${i}]`, `names "${bone}", which is not a bone; explicit segments name bones directly, not chains`);
|
|
2719
|
+
});
|
|
2720
|
+
const where = `${at}.explicit`;
|
|
2721
|
+
const o = c.object(where, m.explicit, ['image_sha256', 'region_sha256'], ['uvs', 'triangles', 'hull', 'weights', 'islands']);
|
|
2722
|
+
if (o === null) return;
|
|
2723
|
+
for (const k of ['image_sha256', 'region_sha256']) if (k in o && !(typeof o[k] === 'string' && /^[0-9a-f]{64}$/.test(o[k] as string))) {
|
|
2724
|
+
c.fail('CONFIG_EXPLICIT_HASH', `${where}.${k}`, 'requires exactly 64 lowercase hexadecimal SHA-256 digits; derive it from the accepted part image and region');
|
|
2725
|
+
}
|
|
2726
|
+
const singleKeys = ['uvs', 'triangles', 'hull', 'weights'].filter((k) => k in o);
|
|
2727
|
+
if ('islands' in o) {
|
|
2728
|
+
for (const k of singleKeys) {
|
|
2729
|
+
c.fail('CONFIG_EXPLICIT_ISLANDS', `${where}.${k}`, 'is declared beside islands; state either a single-slot payload (uvs, triangles, hull, weights) or islands, not both');
|
|
2730
|
+
}
|
|
2731
|
+
if (!Array.isArray(o.islands)) {
|
|
2732
|
+
c.fail('CONFIG_FIELD_TYPE', `${where}.islands`, `is ${show(o.islands)}; an array of at least 2 island payloads is required`);
|
|
2733
|
+
return;
|
|
2734
|
+
}
|
|
2735
|
+
if (o.islands.length < 2) {
|
|
2736
|
+
c.fail('CONFIG_EXPLICIT_ISLANDS', `${where}.islands`, `has ${o.islands.length} entry; at least 2 islands ("${part}", "${part}__island2", ...) are required — use uvs, triangles, hull, weights directly for a single-slot part`);
|
|
2737
|
+
}
|
|
2738
|
+
o.islands.forEach((entry, i) => {
|
|
2739
|
+
const atIsl = `${where}.islands[${i}]`;
|
|
2740
|
+
const isl = c.object(atIsl, entry, ['slot', 'uvs', 'triangles', 'hull', 'weights'], ['bone', 'before']);
|
|
2741
|
+
if (isl === null) return;
|
|
2742
|
+
const expectedSlot = i === 0 ? part : `${part}__island${i + 1}`;
|
|
2743
|
+
if ('slot' in isl && c.string(`${atIsl}.slot`, isl.slot) && isl.slot !== expectedSlot) {
|
|
2744
|
+
c.fail('CONFIG_EXPLICIT_ISLAND_SLOT', `${atIsl}.slot`, `is "${isl.slot}"; island ${i + 1} of "${part}" must be named "${expectedSlot}"`);
|
|
2745
|
+
}
|
|
2746
|
+
if ('bone' in isl && c.string(`${atIsl}.bone`, isl.bone)) {
|
|
2747
|
+
if (!bones.has(isl.bone)) c.fail('CONFIG_NAME_RESOLVES', `${atIsl}.bone`, `names "${isl.bone}", which is not a bone`);
|
|
2748
|
+
else if (Array.isArray(m.segments) && !m.segments.includes(isl.bone)) c.fail('CONFIG_NAME_RESOLVES', `${atIsl}.bone`, `names "${isl.bone}", which this explicit mesh's segments do not declare`);
|
|
2749
|
+
}
|
|
2750
|
+
if ('before' in isl) {
|
|
2751
|
+
if (i === 0) c.fail('CONFIG_EXPLICIT_ISLANDS', `${atIsl}.before`, `is declared on island 1 ("${part}"), which takes its draw position from assemble.plan; only "${part}__island2" and later may declare before`);
|
|
2752
|
+
else c.string(`${atIsl}.before`, isl.before);
|
|
2753
|
+
}
|
|
2754
|
+
checkExplicitPayload(c, atIsl, isl, m, bones);
|
|
2755
|
+
});
|
|
2756
|
+
return;
|
|
2757
|
+
}
|
|
2758
|
+
for (const k of ['uvs', 'triangles', 'hull', 'weights']) if (!(k in o)) c.fail('CONFIG_FIELD_PRESENT', `${where}.${k}`, 'is absent and required');
|
|
2759
|
+
checkExplicitPayload(c, where, o, m, bones);
|
|
2760
|
+
}
|
|
2761
|
+
|
|
2584
2762
|
/** The fields of the distance rule and of the other modes, which an influence mesh does not read (issue #378). */
|
|
2585
2763
|
export const INFLUENCE_FOREIGN_FIELDS = ['r', 'exponent', 'rule', 'influences', 'stray', 'ribs'] as const;
|
|
2586
2764
|
|
|
@@ -4058,6 +4236,10 @@ function checkAnimationSetKeys(
|
|
|
4058
4236
|
const hides = new Set<string>(
|
|
4059
4237
|
Array.isArray(alt.hides) ? alt.hides.filter((h): h is string => typeof h === 'string') : [],
|
|
4060
4238
|
);
|
|
4239
|
+
for (const sl of allSlots) {
|
|
4240
|
+
const m = /^(.+)__island[2-9]\d*$/.exec(sl);
|
|
4241
|
+
if (m !== null && hides.has(m[1])) hides.add(sl);
|
|
4242
|
+
}
|
|
4061
4243
|
const altCuts = Array.isArray(alt.cuts)
|
|
4062
4244
|
? alt.cuts.filter(isPlainObject).map((cu) => cu.into).filter((s): s is string => typeof s === 'string')
|
|
4063
4245
|
: [];
|
package/src/coords.ts
CHANGED
|
@@ -22,5 +22,17 @@
|
|
|
22
22
|
* `flattenRig` goes back through `toWorld`. No rotation matrix is written out
|
|
23
23
|
* by hand in this package.
|
|
24
24
|
*/
|
|
25
|
+
import { cropToSpineY } from 'rig-c/src/transform.ts';
|
|
26
|
+
|
|
27
|
+
/** A painting point on the accepted integer rig canvas, in setup-world coordinates. */
|
|
28
|
+
export function paintingToSetupPoint(point: readonly number[], sourceSize: readonly number[], rigSize: readonly number[]): [number, number] {
|
|
29
|
+
return [point[0] * (rigSize[0] / sourceSize[0]) - rigSize[0] / 2, cropToSpineY(point[1] * (rigSize[1] / sourceSize[1]), rigSize[1])];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Inverse of paintingToSetupPoint; cropToSpineY is its own inverse. */
|
|
33
|
+
export function setupToPaintingPoint(point: readonly number[], sourceSize: readonly number[], rigSize: readonly number[]): [number, number] {
|
|
34
|
+
return [(point[0] + rigSize[0] / 2) / (rigSize[0] / sourceSize[0]), cropToSpineY(point[1], rigSize[1]) / (rigSize[1] / sourceSize[1])];
|
|
35
|
+
}
|
|
36
|
+
|
|
25
37
|
export { computeExactFrameTransforms, computeWorldTransforms, cropToSpineY, normaliseDegrees, toBoneLocal, toBoneLocalVector, toWorld } from 'rig-c/src/transform.ts';
|
|
26
38
|
export type { BoneTransform } from 'rig-c/src/transform.ts';
|
package/src/diagnostics.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { regionBone, type RegionSpec } from './config.ts';
|
|
1
|
+
import { explicitWeightRows, regionBone, type RegionSpec } from './config.ts';
|
|
2
2
|
/**
|
|
3
3
|
* What `propose` looked at, said (issue #86): the coverage lines lint's
|
|
4
4
|
* per-bone record prints, and the basis file written beside the proposal.
|
|
@@ -206,6 +206,7 @@ export function legChainChoice(P: PartSet, spec: { bones: readonly BoneEntry[];
|
|
|
206
206
|
if (!hasSourceBinding && P.recs.some((p) => p.name === part)) sources.add(part);
|
|
207
207
|
};
|
|
208
208
|
for (const [part, mesh] of Object.entries(spec.meshes)) {
|
|
209
|
+
if ('explicit' in mesh) { if (explicitWeightRows(mesh).some(row => row.some(w => links.has(w.bone)))) bound(part); continue; }
|
|
209
210
|
if (mesh.segments.some((s) => typeof s === 'string' ? s === entry.chain || links.has(s) : links.has(s[0]))) bound(part);
|
|
210
211
|
}
|
|
211
212
|
for (const [part, bone] of Object.entries(spec.regions ?? {})) if (links.has(regionBone(bone))) bound(part);
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/** Immutable accepted-mesh transfer (issue #658, #734). No generator or topology repair runs here. */
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import type { ExplicitMeshSpec } from './config.ts';
|
|
4
|
+
import type { Problem } from './errors.ts';
|
|
5
|
+
import { ART_ALPHA, artCoverage, isDust } from './mesh.ts';
|
|
6
|
+
import type { PartRecord } from './parts.ts';
|
|
7
|
+
import { alphaAbove, connectedComponents, pad } from './raster/index.ts';
|
|
8
|
+
import type { Raster } from './raster/types.ts';
|
|
9
|
+
import { PAD, type MeshAttachment } from './rig.ts';
|
|
10
|
+
import { pyRound } from './round.ts';
|
|
11
|
+
|
|
12
|
+
/** SHA-256 over unpadded decoded RGBA, with its size bound by explicitRegionHash. */
|
|
13
|
+
export function explicitImageHash(image: Raster): string {
|
|
14
|
+
return createHash('sha256').update(image.data).digest('hex');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The canvas and placed unpadded part rectangle, in the parts reader's field order. */
|
|
18
|
+
export function explicitRegionHash(size: readonly number[], part: Pick<PartRecord, 'x' | 'y' | 'w' | 'h'>): string {
|
|
19
|
+
return createHash('sha256').update(JSON.stringify([size[0], size[1], part.x, part.y, part.w, part.h])).digest('hex');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ExplicitMeshReport {
|
|
23
|
+
part: string;
|
|
24
|
+
vertices: number;
|
|
25
|
+
triangles: number;
|
|
26
|
+
hull: number;
|
|
27
|
+
bones: string[];
|
|
28
|
+
max_influences: number;
|
|
29
|
+
mean_influences: number;
|
|
30
|
+
art_coverage: number;
|
|
31
|
+
mode: 'explicit';
|
|
32
|
+
image_sha256: string;
|
|
33
|
+
region_sha256: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ExplicitIslandAttachment {
|
|
37
|
+
slot: string;
|
|
38
|
+
bone: string;
|
|
39
|
+
before?: string;
|
|
40
|
+
attachment: MeshAttachment;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Guard before constructing output; clone only named payload fields, retaining every supplied number. */
|
|
44
|
+
export function explicitAttachment(
|
|
45
|
+
part: PartRecord,
|
|
46
|
+
image: Raster,
|
|
47
|
+
size: readonly number[],
|
|
48
|
+
spec: ExplicitMeshSpec,
|
|
49
|
+
): { attachment: MeshAttachment; islandSlots: ExplicitIslandAttachment[]; report: ExplicitMeshReport } | Problem[] {
|
|
50
|
+
const input = spec.explicit, problems: Problem[] = [];
|
|
51
|
+
const hashes = { image_sha256: explicitImageHash(image), region_sha256: explicitRegionHash(size, part) };
|
|
52
|
+
for (const [field, code] of [['image_sha256', 'RIG_EXPLICIT_IMAGE_HASH'], ['region_sha256', 'RIG_EXPLICIT_REGION_HASH']] as const) {
|
|
53
|
+
if (input[field] !== hashes[field]) problems.push({ code, object: `config.meshes.${part.name}.explicit.${field}`, detail: `declares ${input[field]}; the current part has ${hashes[field]} — restore the accepted part image and region, or supply its matching accepted payload; nothing is written` });
|
|
54
|
+
}
|
|
55
|
+
if (problems.length > 0) return problems;
|
|
56
|
+
const comp = connectedComponents(alphaAbove(image, ART_ALPHA), 4);
|
|
57
|
+
const allIslands = comp.stats.slice(1).map((s) => s.area).sort((a, b) => b - a);
|
|
58
|
+
const totalArt = allIslands.reduce((a, b) => a + b, 0);
|
|
59
|
+
const islandAreas = allIslands.filter((n) => n === allIslands[0] || !isDust(n, totalArt));
|
|
60
|
+
const actualCount = islandAreas.length;
|
|
61
|
+
const areaList = islandAreas.map((px) => `${px} px`).join(', ') || '0 px';
|
|
62
|
+
if (input.islands !== undefined) {
|
|
63
|
+
const declaredSlots = input.islands.map((isl) => isl.slot);
|
|
64
|
+
const declaredCount = declaredSlots.length;
|
|
65
|
+
if (declaredCount < actualCount) {
|
|
66
|
+
const missing = Array.from({ length: actualCount - declaredCount }, (_, k) => `"${part.name}__island${declaredCount + k + 1}"`).join(', ');
|
|
67
|
+
return [{
|
|
68
|
+
code: 'RIG_EXPLICIT_ISLAND_COUNT',
|
|
69
|
+
object: `config.meshes.${part.name}.explicit.islands`,
|
|
70
|
+
detail: `declares ${declaredCount} island slot(s) (${declaredSlots.map((s) => `"${s}"`).join(', ')}), but parts/${part.name}.png has ${actualCount} art island(s) (${areaList}); missing ${missing} — nothing is written`,
|
|
71
|
+
}];
|
|
72
|
+
}
|
|
73
|
+
if (declaredCount > actualCount) {
|
|
74
|
+
const extra = declaredSlots.slice(actualCount).map((s) => `"${s}"`).join(', ');
|
|
75
|
+
return [{
|
|
76
|
+
code: 'RIG_EXPLICIT_ISLAND_COUNT',
|
|
77
|
+
object: `config.meshes.${part.name}.explicit.islands`,
|
|
78
|
+
detail: `declares ${declaredCount} island slot(s) (${declaredSlots.map((s) => `"${s}"`).join(', ')}), but parts/${part.name}.png has ${actualCount} art island(s) (${areaList}); extra ${extra} — nothing is written`,
|
|
79
|
+
}];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const padded = pad(image, PAD, PAD, PAD, PAD, [0, 0, 0, 0]);
|
|
83
|
+
const defaultBone = typeof spec.segments[0] === 'string' ? spec.segments[0] : spec.segments[0][0];
|
|
84
|
+
const entries = input.islands !== undefined
|
|
85
|
+
? input.islands.map((isl, idx) => ({
|
|
86
|
+
slot: isl.slot,
|
|
87
|
+
bone: isl.bone ?? defaultBone,
|
|
88
|
+
...(isl.before !== undefined ? { before: isl.before } : {}),
|
|
89
|
+
uvs: isl.uvs,
|
|
90
|
+
triangles: isl.triangles,
|
|
91
|
+
hull: isl.hull,
|
|
92
|
+
weights: isl.weights,
|
|
93
|
+
withPath: idx > 0,
|
|
94
|
+
}))
|
|
95
|
+
: [{
|
|
96
|
+
slot: part.name,
|
|
97
|
+
bone: defaultBone,
|
|
98
|
+
uvs: input.uvs ?? [],
|
|
99
|
+
triangles: input.triangles ?? [],
|
|
100
|
+
hull: input.hull ?? 0,
|
|
101
|
+
weights: input.weights ?? [],
|
|
102
|
+
withPath: false,
|
|
103
|
+
}];
|
|
104
|
+
const allVertices: Array<[number, number]> = [];
|
|
105
|
+
const allTriangles: number[] = [];
|
|
106
|
+
const allWeights: Array<Array<{ bone: string; x: number; y: number; weight: number }>> = [];
|
|
107
|
+
let totalHull = 0;
|
|
108
|
+
const islandSlots: ExplicitIslandAttachment[] = entries.map((e) => {
|
|
109
|
+
const weights = e.weights.map((row) => row.map((w) => ({ bone: w.bone, x: w.x, y: w.y, weight: w.weight })));
|
|
110
|
+
const vOffset = allVertices.length;
|
|
111
|
+
for (let i = 0; i < e.uvs.length; i += 2) allVertices.push([e.uvs[i] * padded.width, e.uvs[i + 1] * padded.height]);
|
|
112
|
+
for (const t of e.triangles) allTriangles.push(vOffset + t);
|
|
113
|
+
allWeights.push(...weights);
|
|
114
|
+
totalHull += e.hull;
|
|
115
|
+
const attachment: MeshAttachment = {
|
|
116
|
+
type: 'mesh',
|
|
117
|
+
...(e.withPath ? { path: part.name } : {}),
|
|
118
|
+
image: `${part.name}.png`,
|
|
119
|
+
width: padded.width,
|
|
120
|
+
height: padded.height,
|
|
121
|
+
uvs: [...e.uvs],
|
|
122
|
+
triangles: [...e.triangles],
|
|
123
|
+
hull: e.hull,
|
|
124
|
+
weights,
|
|
125
|
+
};
|
|
126
|
+
return {
|
|
127
|
+
slot: e.slot,
|
|
128
|
+
bone: e.bone,
|
|
129
|
+
...(e.before !== undefined ? { before: e.before } : {}),
|
|
130
|
+
attachment,
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
return {
|
|
134
|
+
attachment: islandSlots[0].attachment,
|
|
135
|
+
islandSlots,
|
|
136
|
+
report: {
|
|
137
|
+
part: part.name,
|
|
138
|
+
vertices: allWeights.length,
|
|
139
|
+
triangles: allTriangles.length / 3,
|
|
140
|
+
hull: totalHull,
|
|
141
|
+
bones: [...new Set(allWeights.flatMap((row) => row.map((w) => w.bone)))].sort(),
|
|
142
|
+
max_influences: allWeights.reduce((n, row) => Math.max(n, row.length), 0),
|
|
143
|
+
mean_influences: pyRound(allWeights.reduce((n, row) => n + row.length, 0) / allWeights.length, 2),
|
|
144
|
+
art_coverage: pyRound(artCoverage({ vertices: allVertices, triangles: allTriangles }, alphaAbove(padded, ART_ALPHA)), 5),
|
|
145
|
+
mode: 'explicit',
|
|
146
|
+
...hashes,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
package/src/limblayout.ts
CHANGED
|
@@ -55,11 +55,12 @@ function bindings(slot: RigSpec['slots'][number], skin: RigSpec['skins']['defaul
|
|
|
55
55
|
function bindingDetail(slots: RigSpec['slots'], skin: RigSpec['skins']['default'], sources: LayoutPlan['sources']): string {
|
|
56
56
|
return JSON.stringify(slots.map((s) => ({ slot: s.name, attachments: Object.entries(skin[s.name] ?? {}).map(([attachment, a]) => ({ attachment, bones: ('type' in a ? a.weights.flatMap((v) => v.map((w) => w.bone)) : [s.bone]).map((bone) => ({ bone, sources: sources.get(bone) ?? [] })) })) })));
|
|
57
57
|
}
|
|
58
|
-
function owned(slot: RigSpec['slots'][number], skin: RigSpec['skins']['default'], sources: LayoutPlan['sources'], limb: string, parts: readonly string[]): boolean {
|
|
58
|
+
function owned(slot: RigSpec['slots'][number], skin: RigSpec['skins']['default'], sources: LayoutPlan['sources'], limb: string, parts: readonly string[], moving?: ReadonlyMap<string, readonly string[]>): boolean {
|
|
59
59
|
const bs = bindings(slot, skin);
|
|
60
60
|
return bs.length > 0 && bs.every((b) => b.length > 0 && b.every((n) => {
|
|
61
61
|
const s = sources.get(n) ?? [];
|
|
62
|
-
|
|
62
|
+
if (s.length === 1) return s[0].limb === limb && parts.includes(s[0].part);
|
|
63
|
+
return moving !== undefined && s.some((x) => x.limb === limb && parts.includes(x.part)) && s.every((x) => moving.get(x.limb)?.includes(x.part) === true);
|
|
63
64
|
}));
|
|
64
65
|
}
|
|
65
66
|
/** A crossing target may be outside every limb, but may not mix owners. */
|
|
@@ -86,11 +87,15 @@ export function placeLimbLayouts(limbs: Readonly<Record<string, Limb>> | undefin
|
|
|
86
87
|
if (limbs === undefined || !Object.values(limbs).some((l) => l.layout !== undefined)) return { slots: base.slots };
|
|
87
88
|
const sources = inheritedSources ?? segmentSources(limbs, bones), problems: Problem[] = [], placements: LayoutPlacement[] = [];
|
|
88
89
|
const names = base.slots.map((s) => s.name);
|
|
90
|
+
const movingByLimb = new Map<string, string[]>();
|
|
91
|
+
for (const [limb, l] of Object.entries(limbs)) {
|
|
92
|
+
if (l.layout !== undefined) movingByLimb.set(limb, l.segments.map((s) => s.part).filter((p) => l.layout?.parts === undefined || l.layout.parts.includes(p)));
|
|
93
|
+
}
|
|
89
94
|
for (const [limb, l] of Object.entries(limbs)) {
|
|
90
95
|
const d = l.layout;
|
|
91
96
|
if (d === undefined) continue;
|
|
92
|
-
const at = `config.limbs.${limb}.layout`, parts =
|
|
93
|
-
const subject = base.slots.filter((s) => !base.ungathered?.includes(s.name) && owned(s, skin, sources, limb, parts));
|
|
97
|
+
const at = `config.limbs.${limb}.layout`, parts = movingByLimb.get(limb) ?? [];
|
|
98
|
+
const subject = base.slots.filter((s) => !base.ungathered?.includes(s.name) && owned(s, skin, sources, limb, parts, movingByLimb));
|
|
94
99
|
const authored = d.before ?? d.after as LimbLayoutTarget;
|
|
95
100
|
const target: LimbLayoutTarget = authored.limb === undefined ? { part: authored.part } : { limb: authored.limb };
|
|
96
101
|
let targets: RigSpec['slots'];
|
|
@@ -114,14 +119,37 @@ export function placeLimbLayouts(limbs: Readonly<Record<string, Limb>> | undefin
|
|
|
114
119
|
if (idx.some((v, i) => i > 0 && v !== idx[i - 1] + 1)) problems.push({ code: 'RIG_LAYOUT_UNREPRESENTABLE', object: at, detail: `target slots ${targets.map((s) => s.name).join(', ')} do not form one contiguous block; no unrelated slot is absorbed` });
|
|
115
120
|
placements.push({ limb, parts, ...(d.before === undefined ? { after: target } : { before: target }), slots: subject.map((s) => s.name), target_slots: targets.map((s) => s.name) });
|
|
116
121
|
}
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
+
const movedBy = new Map<string, string>();
|
|
123
|
+
const targetedBy = new Map<string, { at: string; targetKey: string; targetSlots: readonly string[] }>();
|
|
124
|
+
for (const p of placements) {
|
|
125
|
+
const at = `config.limbs.${p.limb}.layout`, targetKey = p.target_slots.join('\u0000');
|
|
126
|
+
const localTargets = new Set(p.target_slots);
|
|
127
|
+
for (const n of p.slots) {
|
|
128
|
+
const otherMover = movedBy.get(n), otherTarget = targetedBy.get(n);
|
|
129
|
+
if (localTargets.has(n)) {
|
|
130
|
+
problems.push({ code: 'RIG_LAYOUT_CONFLICT', object: at, detail: `slot "${n}" is both a moving slot and a target in ${at}; self, reciprocal, chained and mover-as-target declarations are refused — only a stationary target may be shared` });
|
|
131
|
+
} else if (otherMover !== undefined) {
|
|
132
|
+
problems.push({ code: 'RIG_LAYOUT_CONFLICT', object: at, detail: `slot "${n}" is a moving slot in both ${otherMover} and ${at}; a slot may move in only one placement — only a stationary target may be shared` });
|
|
133
|
+
} else if (otherTarget !== undefined) {
|
|
134
|
+
problems.push({ code: 'RIG_LAYOUT_CONFLICT', object: at, detail: `slot "${n}" is a moving slot in ${at} and a target in ${otherTarget.at}; self, reciprocal, chained and mover-as-target declarations are refused — only a stationary target may be shared` });
|
|
135
|
+
} else {
|
|
136
|
+
movedBy.set(n, at);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
for (const n of p.target_slots) {
|
|
140
|
+
if (localTargets.has(n) && p.slots.includes(n)) continue;
|
|
141
|
+
const otherMover = movedBy.get(n), otherTarget = targetedBy.get(n);
|
|
142
|
+
if (otherMover !== undefined) {
|
|
143
|
+
problems.push({ code: 'RIG_LAYOUT_CONFLICT', object: at, detail: `slot "${n}" is a target in ${at} and a moving slot in ${otherMover}; self, reciprocal, chained and mover-as-target declarations are refused — only a stationary target may be shared` });
|
|
144
|
+
} else if (otherTarget !== undefined && otherTarget.targetKey !== targetKey) {
|
|
145
|
+
problems.push({ code: 'RIG_LAYOUT_CONFLICT', object: at, detail: `target slot "${n}" in ${at} ([${p.target_slots.join(', ')}]) partially overlaps ${otherTarget.at} ([${otherTarget.targetSlots.join(', ')}]); shared targets must resolve to the same target slot block` });
|
|
146
|
+
} else if (otherTarget === undefined) {
|
|
147
|
+
targetedBy.set(n, { at, targetKey, targetSlots: p.target_slots });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
122
150
|
}
|
|
123
151
|
refuseIfAny(problems);
|
|
124
|
-
placements.sort((a, b) => names.indexOf(a.target_slots[0]) - names.indexOf(b.target_slots[0]));
|
|
152
|
+
placements.sort((a, b) => names.indexOf(a.target_slots[0]) - names.indexOf(b.target_slots[0]) || names.indexOf(a.slots[0]) - names.indexOf(b.slots[0]));
|
|
125
153
|
const moving = new Set(placements.flatMap((p) => p.slots));
|
|
126
154
|
const result: RigSpec['slots'] = [];
|
|
127
155
|
for (const s of base.slots) {
|
|
@@ -157,8 +185,22 @@ export function validateLimbLayout(plan: LayoutPlan, rig: Pick<RigSpec, 'slots'
|
|
|
157
185
|
const at = `config.limbs.${p.limb}.layout`, target = p.before ?? p.after as LimbLayoutTarget;
|
|
158
186
|
const read = (ns: readonly string[]) => rig.slots.filter((s) => ns.includes(s.name));
|
|
159
187
|
const ss = read(p.slots), ts = read(p.target_slots);
|
|
188
|
+
const targetKey = p.target_slots.join('\u0000');
|
|
189
|
+
const coMovers = plan.placements
|
|
190
|
+
.filter((q) => (q.before !== undefined) === (p.before !== undefined) && q.target_slots.join('\u0000') === targetKey)
|
|
191
|
+
.sort((a, b) => plan.originalOrder.indexOf(a.slots[0]) - plan.originalOrder.indexOf(b.slots[0]));
|
|
192
|
+
const groupSlots = coMovers.flatMap((q) => q.slots);
|
|
160
193
|
const contiguous = (ns: string[]) => ns.length > 0 && ns.every((n, i) => i === 0 || names.indexOf(n) === names.indexOf(ns[i - 1]) + 1);
|
|
161
|
-
if (
|
|
194
|
+
if (
|
|
195
|
+
ss.length !== p.slots.length ||
|
|
196
|
+
ts.length !== p.target_slots.length ||
|
|
197
|
+
!contiguous(p.slots) ||
|
|
198
|
+
!contiguous(p.target_slots) ||
|
|
199
|
+
!contiguous(groupSlots) ||
|
|
200
|
+
(p.before !== undefined
|
|
201
|
+
? names.indexOf(groupSlots[groupSlots.length - 1]) + 1 !== names.indexOf(p.target_slots[0])
|
|
202
|
+
: names.indexOf(p.target_slots[p.target_slots.length - 1]) + 1 !== names.indexOf(groupSlots[0]))
|
|
203
|
+
) {
|
|
162
204
|
problems.push({ code: 'RIG_LAYOUT_UNREPRESENTABLE', object: at, detail: `accepted setup slots do not preserve the exact declared adjacency: ${JSON.stringify(p)}` });
|
|
163
205
|
}
|
|
164
206
|
if (ss.some((s) => !owned(s, rig.skins.default, plan.sources, p.limb, p.parts)) || !targetSafe(ts, rig.skins.default, plan.sources) || (target.limb !== undefined && ts.some((s) => !owned(s, rig.skins.default, plan.sources, target.limb as string, plan.limbs[target.limb as string].segments.map((s) => s.part))))) {
|
package/src/meshdraft.ts
CHANGED
|
@@ -133,7 +133,7 @@ export const NOT_COMPARED_SENTENCE = 'mesh-draft drafts lattice entries only, so
|
|
|
133
133
|
/** A config entry `mesh-draft` did not draft because it is not a lattice (issue #307), in config order. */
|
|
134
134
|
export interface NotCompared {
|
|
135
135
|
part: string;
|
|
136
|
-
mode: 'contour' | 'auto' | 'influence';
|
|
136
|
+
mode: 'contour' | 'auto' | 'influence' | 'explicit';
|
|
137
137
|
note: string;
|
|
138
138
|
}
|
|
139
139
|
|
|
@@ -142,7 +142,7 @@ export function notCompared(meshes: CharacterConfig['meshes']): NotCompared[] {
|
|
|
142
142
|
const out: NotCompared[] = [];
|
|
143
143
|
for (const [part, spec] of Object.entries(meshes)) {
|
|
144
144
|
if ('grid' in spec) continue;
|
|
145
|
-
const mode = 'auto' in spec ? 'auto' : 'influence' in spec ? 'influence' : 'contour';
|
|
145
|
+
const mode = 'explicit' in spec ? 'explicit' : 'auto' in spec ? 'auto' : 'influence' in spec ? 'influence' : 'contour';
|
|
146
146
|
out.push({ part, mode, note: `its entry is "${mode}", not a lattice: ${NOT_COMPARED_SENTENCE}` });
|
|
147
147
|
}
|
|
148
148
|
return out;
|
package/src/meshstats.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { buildRig, DEFAULT_IDLE_KEYS, type MeshReport } from './rig.ts';
|
|
|
16
16
|
/** One mesh's counts, as the rig stage's `mesh_report.json` row holds them; `mode` is `lattice` for a `grid` entry, whose row carries no mode. */
|
|
17
17
|
export interface MeshStatsRow {
|
|
18
18
|
part: string;
|
|
19
|
-
mode: 'lattice' | 'contour' | 'auto' | 'influence';
|
|
19
|
+
mode: 'lattice' | 'contour' | 'auto' | 'influence' | 'explicit';
|
|
20
20
|
vertices: number;
|
|
21
21
|
triangles: number;
|
|
22
22
|
}
|