@rig-c/parts 1.62.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 +86 -3
- package/docs/STABILITY.md +6 -3
- package/package.json +2 -2
- package/skills/rig-parts/SKILL.md +1 -1
- package/src/check.ts +257 -18
- package/src/config.ts +120 -27
- package/src/diagnostics.ts +2 -2
- package/src/explicitmesh.ts +108 -12
- package/src/limblayout.ts +53 -11
- package/src/propose.ts +2 -2
- package/src/rig.ts +78 -11
- package/src/scene.ts +6 -2
- package/src/structure.ts +2 -2
package/src/config.ts
CHANGED
|
@@ -360,24 +360,55 @@ export type MeshSpec = (LatticeMeshSpec | ContourMeshSpec | AutoMeshSpec | Influ
|
|
|
360
360
|
* `hold_tip: true` (issue #615, optional, written by `propose --cloth` from the recipe's `split.hold_tip`) smooths the
|
|
361
361
|
* pulled shares by the lattice's held-fork passes, capped at `max`; absent, the shares are rig-c's as pulled.
|
|
362
362
|
*/
|
|
363
|
-
/**
|
|
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). */
|
|
364
375
|
export interface ExplicitMeshSpec {
|
|
365
|
-
/** Direct bone names: the first is the slot bone; all weighted bones must be declared here. No segment geometry is regenerated. */
|
|
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. */
|
|
366
377
|
segments: Segment[];
|
|
367
378
|
explicit: {
|
|
368
379
|
/** SHA-256 over the unpadded part's decoded RGBA bytes. */
|
|
369
380
|
image_sha256: string;
|
|
370
381
|
/** SHA-256 of JSON.stringify([rig width, rig height, x, y, w, h]). */
|
|
371
382
|
region_sha256: string;
|
|
372
|
-
/** Normalized UVs over the ordinary PAD-padded rig image, as rig-c reads them. */
|
|
373
|
-
uvs
|
|
374
|
-
triangles
|
|
375
|
-
hull
|
|
376
|
-
/** rig-c by-name weights, in bone-local Spine pixels, copied without rounding. */
|
|
377
|
-
weights
|
|
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[];
|
|
378
391
|
};
|
|
379
392
|
}
|
|
380
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
|
+
|
|
381
412
|
export interface InfluenceMeshSpec {
|
|
382
413
|
influence: { cell: number; radius: number; across: boolean; max: number; shape: 'linear' | 'smooth'; hold_tip?: true };
|
|
383
414
|
segments: Segment[];
|
|
@@ -764,7 +795,8 @@ export function partBoundBones(b: PartBinding): Map<string, string[]> {
|
|
|
764
795
|
};
|
|
765
796
|
for (const [part, m] of Object.entries(b.meshes)) {
|
|
766
797
|
if ('explicit' in m) {
|
|
767
|
-
for (const row of 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);
|
|
768
800
|
continue;
|
|
769
801
|
}
|
|
770
802
|
for (const sg of m.segments) {
|
|
@@ -1635,7 +1667,8 @@ function parseConfigFrom(raw: Json, base: string | null): { config: CharacterCon
|
|
|
1635
1667
|
const animations = base !== null && typeof from === 'string' && from !== '' ? readAnimationsFrom(c, base, from) : null;
|
|
1636
1668
|
if (animations !== null) {
|
|
1637
1669
|
checkFaceAnimationBand(c, animations, hasAltFace, t.turn, attached);
|
|
1638
|
-
|
|
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)]));
|
|
1639
1672
|
}
|
|
1640
1673
|
const pose = base === null ? null : poseBeside(c, t.generation, base);
|
|
1641
1674
|
refuseIfAny(c.problems);
|
|
@@ -2177,6 +2210,20 @@ function checkCuts(c: Check, v: Json, plan: string[], patches: string[], p = 'co
|
|
|
2177
2210
|
return names;
|
|
2178
2211
|
}
|
|
2179
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
|
+
|
|
2180
2227
|
function checkAlternates(
|
|
2181
2228
|
c: Check,
|
|
2182
2229
|
v: Json,
|
|
@@ -2189,12 +2236,16 @@ function checkAlternates(
|
|
|
2189
2236
|
): void {
|
|
2190
2237
|
const p = 'config.assemble.alternates';
|
|
2191
2238
|
if (!c.array(p, v, true)) return;
|
|
2192
|
-
const
|
|
2239
|
+
const baseSlots = new Set<string>([
|
|
2193
2240
|
...made.parts.filter((n) => !(limbs?.consumed.has(n) ?? false)),
|
|
2194
2241
|
...made.patches,
|
|
2195
2242
|
...made.cuts,
|
|
2196
2243
|
...(limbs?.parts.keys() ?? []),
|
|
2197
2244
|
]);
|
|
2245
|
+
const allSlots = new Set<string>([
|
|
2246
|
+
...baseSlots,
|
|
2247
|
+
...explicitIslandSlotNames(baseSlots, meshes),
|
|
2248
|
+
]);
|
|
2198
2249
|
const seenNames = new Map<string, number>();
|
|
2199
2250
|
(v as Json[]).forEach((entry, i) => {
|
|
2200
2251
|
const at = `${p}[${i}]`;
|
|
@@ -2572,7 +2623,7 @@ function checkMeshes(c: Check, v: Json, bones: Set<string>, chains: Map<string,
|
|
|
2572
2623
|
if (m === null) continue;
|
|
2573
2624
|
checkGather(c, at, m);
|
|
2574
2625
|
if ('explicit' in m) {
|
|
2575
|
-
checkExplicit(c, at, m, explicitBoneNames(bones, chains, stops));
|
|
2626
|
+
checkExplicit(c, at, m, explicitBoneNames(bones, chains, stops), part);
|
|
2576
2627
|
continue;
|
|
2577
2628
|
}
|
|
2578
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
|
|
@@ -2625,21 +2676,8 @@ function checkMeshes(c: Check, v: Json, bones: Set<string>, chains: Map<string,
|
|
|
2625
2676
|
}
|
|
2626
2677
|
}
|
|
2627
2678
|
|
|
2628
|
-
/**
|
|
2629
|
-
function
|
|
2630
|
-
for (const k of ['grid', 'r', 'contour', 'auto', 'exponent', 'rule', 'ribs', 'influences', 'stray', 'influence']) {
|
|
2631
|
-
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');
|
|
2632
|
-
}
|
|
2633
|
-
if (!('segments' in m)) c.fail('CONFIG_FIELD_PRESENT', `${at}.segments`, 'is absent and required: direct bone names, first the slot bone');
|
|
2634
|
-
else if (c.array(`${at}.segments`, m.segments, true)) m.segments.forEach((bone, i) => {
|
|
2635
|
-
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`);
|
|
2636
|
-
});
|
|
2637
|
-
const where = `${at}.explicit`;
|
|
2638
|
-
const o = c.object(where, m.explicit, ['image_sha256', 'region_sha256', 'uvs', 'triangles', 'hull', 'weights'], []);
|
|
2639
|
-
if (o === null) return;
|
|
2640
|
-
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))) {
|
|
2641
|
-
c.fail('CONFIG_EXPLICIT_HASH', `${where}.${k}`, 'requires exactly 64 lowercase hexadecimal SHA-256 digits; derive it from the accepted part image and region');
|
|
2642
|
-
}
|
|
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 {
|
|
2643
2681
|
const uvs = Array.isArray(o.uvs) ? o.uvs : [];
|
|
2644
2682
|
if ('uvs' in o && c.array(`${where}.uvs`, o.uvs, true)) {
|
|
2645
2683
|
uvs.forEach((v, i) => c.number(`${where}.uvs[${i}]`, v));
|
|
@@ -2670,6 +2708,57 @@ function checkExplicit(c: Check, at: string, m: Record<string, Json>, bones: Set
|
|
|
2670
2708
|
}
|
|
2671
2709
|
}
|
|
2672
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
|
+
|
|
2673
2762
|
/** The fields of the distance rule and of the other modes, which an influence mesh does not read (issue #378). */
|
|
2674
2763
|
export const INFLUENCE_FOREIGN_FIELDS = ['r', 'exponent', 'rule', 'influences', 'stray', 'ribs'] as const;
|
|
2675
2764
|
|
|
@@ -4147,6 +4236,10 @@ function checkAnimationSetKeys(
|
|
|
4147
4236
|
const hides = new Set<string>(
|
|
4148
4237
|
Array.isArray(alt.hides) ? alt.hides.filter((h): h is string => typeof h === 'string') : [],
|
|
4149
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
|
+
}
|
|
4150
4243
|
const altCuts = Array.isArray(alt.cuts)
|
|
4151
4244
|
? alt.cuts.filter(isPlainObject).map((cu) => cu.into).filter((s): s is string => typeof s === 'string')
|
|
4152
4245
|
: [];
|
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,7 +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 (mesh.
|
|
209
|
+
if ('explicit' in mesh) { if (explicitWeightRows(mesh).some(row => row.some(w => links.has(w.bone)))) bound(part); continue; }
|
|
210
210
|
if (mesh.segments.some((s) => typeof s === 'string' ? s === entry.chain || links.has(s) : links.has(s[0]))) bound(part);
|
|
211
211
|
}
|
|
212
212
|
for (const [part, bone] of Object.entries(spec.regions ?? {})) if (links.has(regionBone(bone))) bound(part);
|
package/src/explicitmesh.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/** Immutable accepted-mesh transfer (issue #658). No generator or topology repair runs here. */
|
|
1
|
+
/** Immutable accepted-mesh transfer (issue #658, #734). No generator or topology repair runs here. */
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import type { ExplicitMeshSpec } from './config.ts';
|
|
4
4
|
import type { Problem } from './errors.ts';
|
|
5
|
-
import { ART_ALPHA, artCoverage } from './mesh.ts';
|
|
5
|
+
import { ART_ALPHA, artCoverage, isDust } from './mesh.ts';
|
|
6
6
|
import type { PartRecord } from './parts.ts';
|
|
7
|
-
import { alphaAbove, pad } from './raster/index.ts';
|
|
7
|
+
import { alphaAbove, connectedComponents, pad } from './raster/index.ts';
|
|
8
8
|
import type { Raster } from './raster/types.ts';
|
|
9
9
|
import { PAD, type MeshAttachment } from './rig.ts';
|
|
10
10
|
import { pyRound } from './round.ts';
|
|
@@ -33,21 +33,117 @@ export interface ExplicitMeshReport {
|
|
|
33
33
|
region_sha256: string;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
export interface ExplicitIslandAttachment {
|
|
37
|
+
slot: string;
|
|
38
|
+
bone: string;
|
|
39
|
+
before?: string;
|
|
40
|
+
attachment: MeshAttachment;
|
|
41
|
+
}
|
|
42
|
+
|
|
36
43
|
/** Guard before constructing output; clone only named payload fields, retaining every supplied number. */
|
|
37
|
-
export function explicitAttachment(
|
|
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[] {
|
|
38
50
|
const input = spec.explicit, problems: Problem[] = [];
|
|
39
51
|
const hashes = { image_sha256: explicitImageHash(image), region_sha256: explicitRegionHash(size, part) };
|
|
40
52
|
for (const [field, code] of [['image_sha256', 'RIG_EXPLICIT_IMAGE_HASH'], ['region_sha256', 'RIG_EXPLICIT_REGION_HASH']] as const) {
|
|
41
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` });
|
|
42
54
|
}
|
|
43
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
|
+
}
|
|
44
82
|
const padded = pad(image, PAD, PAD, PAD, PAD, [0, 0, 0, 0]);
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
+
};
|
|
53
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/propose.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
|
* The propose stage: bone origins, mesh candidate lists, regions and a default
|
|
4
4
|
* idle, read off the assembled parts — and the overlay a person or an agent
|
|
@@ -5428,7 +5428,7 @@ function lintCoverage(
|
|
|
5428
5428
|
const partless: string[] = [];
|
|
5429
5429
|
for (const [mname, m] of Object.entries(spec.meshes)) {
|
|
5430
5430
|
if ('explicit' in m) {
|
|
5431
|
-
if (m.
|
|
5431
|
+
if (explicitWeightRows(m).some(row => row.some(w => w.bone === bone))) why.push(`bound by meshes.${mname}.explicit.weights: the segment-origin checks do not read an accepted payload`);
|
|
5432
5432
|
continue;
|
|
5433
5433
|
}
|
|
5434
5434
|
m.segments.forEach((sp, i) => {
|