@rig-c/parts 1.62.0 → 1.64.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 +88 -5
- 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 +89 -17
- package/src/scene.ts +6 -2
- package/src/structure.ts +2 -2
package/src/rig.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { explicitBoneNames, regionBone } from './config.ts';
|
|
1
|
+
import { explicitBoneNames, explicitSlotBones, explicitWeightRows, regionBone } from './config.ts';
|
|
2
2
|
import { explicitAttachment, type ExplicitMeshReport } from './explicitmesh.ts';
|
|
3
3
|
/**
|
|
4
4
|
* The rig stage: a character config and its assembled parts in, a rig spec
|
|
@@ -492,6 +492,7 @@ export interface WeightEntry {
|
|
|
492
492
|
|
|
493
493
|
export interface MeshAttachment {
|
|
494
494
|
type: 'mesh';
|
|
495
|
+
path?: string;
|
|
495
496
|
image: string;
|
|
496
497
|
width: number;
|
|
497
498
|
height: number;
|
|
@@ -679,6 +680,7 @@ function applyTurn(
|
|
|
679
680
|
skin: RigSpec['skins']['default'],
|
|
680
681
|
constraints: readonly ConfigConstraint[],
|
|
681
682
|
frontSlots: ReadonlySet<string> = new Set(),
|
|
683
|
+
slotFamilies: ReadonlyMap<string, readonly string[]> = new Map(),
|
|
682
684
|
): { constraints: Array<Record<string, unknown>>; detached: DetachedRule[]; rows: TurnRow[] } {
|
|
683
685
|
const problems: Problem[] = [];
|
|
684
686
|
const taken = new Set(bones.map((b) => b.name));
|
|
@@ -689,8 +691,9 @@ function applyTurn(
|
|
|
689
691
|
const row: TurnRow = { ...f, twins: [] };
|
|
690
692
|
rows.push(row);
|
|
691
693
|
if (f.fraction === 0) continue;
|
|
694
|
+
const family = new Set(slotFamilies.get(f.part) ?? [f.part]);
|
|
692
695
|
// A declared front slot (issue #664) rides its part; a part merely named `<part>_front` is a part of its own.
|
|
693
|
-
const mine = slots.filter((sl) => sl.name
|
|
696
|
+
const mine = slots.filter((sl) => family.has(sl.name) || sl.name === `${f.part}${STILL_SUFFIX}` || (sl.name === `${f.part}${FRONT_SUFFIX}` && frontSlots.has(sl.name)));
|
|
694
697
|
const bound: string[] = [];
|
|
695
698
|
const bind = (b: string): void => {
|
|
696
699
|
if (!bound.includes(b)) bound.push(b);
|
|
@@ -714,10 +717,11 @@ function applyTurn(
|
|
|
714
717
|
const detached: DetachedRule[] = [];
|
|
715
718
|
for (const row of rows) {
|
|
716
719
|
if (row.twins.length === 0) continue;
|
|
720
|
+
const family = new Set(slotFamilies.get(row.part) ?? [row.part]);
|
|
717
721
|
const twinOf = new Map(row.twins.map((t) => [t.bone, t.twin]));
|
|
718
722
|
for (const t of row.twins) bones.push({ name: t.twin, parent: t.bone, x: 0, y: 0 });
|
|
719
723
|
for (const sl of slots) {
|
|
720
|
-
if (sl.name
|
|
724
|
+
if (!family.has(sl.name) && sl.name !== `${row.part}${STILL_SUFFIX}` && !(sl.name === `${row.part}${FRONT_SUFFIX}` && frontSlots.has(sl.name))) continue;
|
|
721
725
|
sl.bone = twinOf.get(sl.bone) as string;
|
|
722
726
|
const atts = skin[sl.name] ?? {};
|
|
723
727
|
for (const [k, att] of Object.entries(atts)) {
|
|
@@ -1381,7 +1385,7 @@ export function buildRig(
|
|
|
1381
1385
|
const explicitNames = explicitBoneNames(new Set(B.keys()), new Map([...chains].map(([k, v]) => [k, v.length])), cfg.stops);
|
|
1382
1386
|
for (const [part, m] of Object.entries(cfg.meshes)) {
|
|
1383
1387
|
if ('explicit' in m) {
|
|
1384
|
-
for (const bone of [...m.segments.map(s => typeof s === 'string' ? s : s[0]), ...m.
|
|
1388
|
+
for (const bone of [...m.segments.map(s => typeof s === 'string' ? s : s[0]), ...explicitSlotBones(m), ...explicitWeightRows(m).flatMap(row => row.map(w => w.bone))]) {
|
|
1385
1389
|
if (!explicitNames.has(bone)) fail('RIG_NAME_RESOLVES', `config.meshes.${part}.explicit`, `names the bone "${bone}", which config.bones does not declare`);
|
|
1386
1390
|
}
|
|
1387
1391
|
continue;
|
|
@@ -1520,7 +1524,7 @@ export function buildRig(
|
|
|
1520
1524
|
// to its control under `ctl` as theirs do. A config with no contour region adds nothing here.
|
|
1521
1525
|
for (const m of Object.values(cfg.meshes)) if ('contour' in m) for (const rg of contourRegionsOf(m.contour)) meshBones.add(rg.bone);
|
|
1522
1526
|
for (const m of Object.values(cfg.meshes)) if ('auto' in m) for (const rg of m.auto.regions ?? []) if (weightsABone(rg)) meshBones.add(rg.bone);
|
|
1523
|
-
for (const m of Object.values(cfg.meshes)) if ('explicit' in m) for (const row of m
|
|
1527
|
+
for (const m of Object.values(cfg.meshes)) if ('explicit' in m) for (const row of explicitWeightRows(m)) for (const w of row) meshBones.add(w.bone);
|
|
1524
1528
|
// Accepted final bindings may already name a stop's drawn link. Its source link still needs the idle control.
|
|
1525
1529
|
for (const stop of cfg.stops ?? []) for (const link of stop.links ?? chains.get(stop.chain) ?? []) {
|
|
1526
1530
|
if (meshBones.has(`${link}_d`)) meshBones.add(link);
|
|
@@ -1777,6 +1781,7 @@ export function buildRig(
|
|
|
1777
1781
|
// ---- attachments -------------------------------------------------------
|
|
1778
1782
|
const slots: RigSpec['slots'] = [];
|
|
1779
1783
|
const slotFamilies = new Map<string, string[]>();
|
|
1784
|
+
const pendingIslandSlots: Array<{ part: string; index: number; prevSlot: string; before?: string; row: RigSpec['slots'][number] }> = [];
|
|
1780
1785
|
const addSlots = (part: string, ...rows: RigSpec['slots']): void => {
|
|
1781
1786
|
slots.push(...rows);
|
|
1782
1787
|
slotFamilies.set(part, [...(slotFamilies.get(part) ?? []), ...rows.map((s) => s.name)]);
|
|
@@ -2318,8 +2323,19 @@ export function buildRig(
|
|
|
2318
2323
|
if ('explicit' in mesh) {
|
|
2319
2324
|
const row = explicitAttachment(p, images.get(p.name) as Raster, parts.rig_size, mesh);
|
|
2320
2325
|
if (Array.isArray(row)) { problems.push(...row); continue; }
|
|
2321
|
-
skin[
|
|
2322
|
-
|
|
2326
|
+
for (const isl of row.islandSlots) skin[isl.slot] = { [isl.slot]: isl.attachment };
|
|
2327
|
+
const first = row.islandSlots[0];
|
|
2328
|
+
addSlots(p.name, { name: first.slot, bone: first.bone, attachment: first.slot });
|
|
2329
|
+
for (let i = 1; i < row.islandSlots.length; i++) {
|
|
2330
|
+
const isl = row.islandSlots[i];
|
|
2331
|
+
pendingIslandSlots.push({
|
|
2332
|
+
part: p.name,
|
|
2333
|
+
index: i,
|
|
2334
|
+
prevSlot: row.islandSlots[i - 1].slot,
|
|
2335
|
+
before: isl.before,
|
|
2336
|
+
row: { name: isl.slot, bone: isl.bone, attachment: isl.slot },
|
|
2337
|
+
});
|
|
2338
|
+
}
|
|
2323
2339
|
meshReport.push(row.report);
|
|
2324
2340
|
continue;
|
|
2325
2341
|
}
|
|
@@ -2442,6 +2458,25 @@ export function buildRig(
|
|
|
2442
2458
|
...(heat === null ? {} : { heat: heatRow(heat) }),
|
|
2443
2459
|
});
|
|
2444
2460
|
}
|
|
2461
|
+
const basePartNames = new Set(parts.parts.map((p) => p.name));
|
|
2462
|
+
for (const item of pendingIslandSlots) {
|
|
2463
|
+
if (item.before !== undefined) {
|
|
2464
|
+
if (item.before === item.part || !basePartNames.has(item.before)) {
|
|
2465
|
+
fail(
|
|
2466
|
+
'RIG_NAME_RESOLVES',
|
|
2467
|
+
`config.meshes.${item.part}.explicit.islands[${item.index}].before`,
|
|
2468
|
+
`names "${item.before}", which is ${item.before === item.part ? `the part "${item.part}" itself` : 'not a part slot in the rig'}; name another part slot in the rig`,
|
|
2469
|
+
);
|
|
2470
|
+
continue;
|
|
2471
|
+
}
|
|
2472
|
+
const targetIdx = slots.findIndex((s) => s.name === item.before);
|
|
2473
|
+
slots.splice(targetIdx, 0, item.row);
|
|
2474
|
+
} else {
|
|
2475
|
+
const prevIdx = slots.findIndex((s) => s.name === item.prevSlot);
|
|
2476
|
+
slots.splice(prevIdx + 1, 0, item.row);
|
|
2477
|
+
}
|
|
2478
|
+
slotFamilies.set(item.part, [...(slotFamilies.get(item.part) ?? []), item.row.name]);
|
|
2479
|
+
}
|
|
2445
2480
|
refuseIfAny(problems);
|
|
2446
2481
|
// ---- front slots (issue #664) ------------------------------------------
|
|
2447
2482
|
// Only when a limb declares `front`: each named segment part gets `<part>_front` on its base slot's bone, showing
|
|
@@ -2503,7 +2538,10 @@ export function buildRig(
|
|
|
2503
2538
|
for (const s of meshSegments.get(pName) ?? []) coveredBones.add(s.bone);
|
|
2504
2539
|
const m = cfg.meshes[pName];
|
|
2505
2540
|
if (m !== undefined) {
|
|
2506
|
-
if ('explicit' in m)
|
|
2541
|
+
if ('explicit' in m) {
|
|
2542
|
+
if (m.explicit.islands !== undefined) for (const bName of explicitSlotBones(m)) coveredBones.add(bName);
|
|
2543
|
+
for (const row of explicitWeightRows(m)) for (const w of row) coveredBones.add(w.bone);
|
|
2544
|
+
}
|
|
2507
2545
|
if ('contour' in m) for (const rg of contourRegionsOf(m.contour)) coveredBones.add(rg.bone);
|
|
2508
2546
|
if ('auto' in m) for (const rg of m.auto.regions ?? []) if (weightsABone(rg)) coveredBones.add(rg.bone);
|
|
2509
2547
|
}
|
|
@@ -2691,7 +2729,9 @@ export function buildRig(
|
|
|
2691
2729
|
for (const [slotName, att] of Object.entries(alt.slots)) slotMap[slotName] = att;
|
|
2692
2730
|
const hideList: string[] = [];
|
|
2693
2731
|
for (const h of alt.hides ?? []) {
|
|
2694
|
-
|
|
2732
|
+
for (const member of slotFamilies.get(h) ?? [h]) {
|
|
2733
|
+
if (!hideList.includes(member)) hideList.push(member);
|
|
2734
|
+
}
|
|
2695
2735
|
if (stills[h] !== undefined && !hideList.includes(`${h}${STILL_SUFFIX}`)) hideList.push(`${h}${STILL_SUFFIX}`);
|
|
2696
2736
|
}
|
|
2697
2737
|
for (const slotName of Object.keys(alt.slots)) {
|
|
@@ -2734,24 +2774,56 @@ export function buildRig(
|
|
|
2734
2774
|
// from the drawn link `<link>_d` above it, and slots and weights on a stopped link bind `<link>_d`.
|
|
2735
2775
|
const rebound = frontSlots.length === 0 ? slots : [...slots, ...frontSlots];
|
|
2736
2776
|
const stops = cfg.stops === undefined ? null : applyStops(cfg.stops, chains, bones, rebound, skin, (original, emitted) => layoutAlias(explicitLayout.plan, original, emitted));
|
|
2777
|
+
for (const [part, mesh] of Object.entries(cfg.meshes)) if ('explicit' in mesh) {
|
|
2778
|
+
const defaultBone = typeof mesh.segments[0] === 'string' ? mesh.segments[0] : mesh.segments[0][0];
|
|
2779
|
+
if (mesh.explicit.islands !== undefined) {
|
|
2780
|
+
mesh.explicit.islands.forEach((isl, i) => {
|
|
2781
|
+
const att = skin[isl.slot]?.[isl.slot];
|
|
2782
|
+
const slotEntry = slots.find((s) => s.name === isl.slot);
|
|
2783
|
+
const expectedBone = isl.bone ?? defaultBone;
|
|
2784
|
+
const weightsChanged =
|
|
2785
|
+
att !== undefined &&
|
|
2786
|
+
'type' in att &&
|
|
2787
|
+
JSON.stringify(att.weights) !== JSON.stringify(isl.weights.map(row => row.map(w => ({ bone: w.bone, x: w.x, y: w.y, weight: w.weight }))));
|
|
2788
|
+
const boneChanged = slotEntry !== undefined && slotEntry.bone !== expectedBone;
|
|
2789
|
+
if (weightsChanged || boneChanged) {
|
|
2790
|
+
fail('RIG_EXPLICIT_BINDING', `config.meshes.${part}.explicit.islands[${i}].weights`, 'the declared stops would change these accepted bindings; supply the accepted final emitted bone names and bind coordinates, or use a generated mesh; no payload is normalized');
|
|
2791
|
+
}
|
|
2792
|
+
});
|
|
2793
|
+
continue;
|
|
2794
|
+
}
|
|
2795
|
+
const att = skin[part]?.[part];
|
|
2796
|
+
const slotEntry = slots.find((s) => s.name === part);
|
|
2797
|
+
const weightsChanged =
|
|
2798
|
+
att !== undefined &&
|
|
2799
|
+
'type' in att &&
|
|
2800
|
+
JSON.stringify(att.weights) !== JSON.stringify((mesh.explicit.weights ?? []).map(row => row.map(w => ({ bone: w.bone, x: w.x, y: w.y, weight: w.weight }))));
|
|
2801
|
+
const boneChanged = slotEntry !== undefined && slotEntry.bone !== defaultBone;
|
|
2802
|
+
if (weightsChanged || boneChanged) {
|
|
2803
|
+
fail('RIG_EXPLICIT_BINDING', `config.meshes.${part}.explicit.weights`, 'the declared stops would change these accepted bindings; supply the accepted final emitted bone names and bind coordinates, or use a generated mesh; no payload is normalized');
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2737
2806
|
// ---- the turn control (issue #251) -------------------------------------
|
|
2738
2807
|
// Only when the config has `turn`: every other build adds nothing here, so no byte moves.
|
|
2739
2808
|
if (cfg.turn !== undefined) refuseIfAny(turnRiderProblems(cfg.turn, cfg, parts.parts));
|
|
2740
|
-
const turned = cfg.turn === undefined ? null : applyTurn(cfg.turn, parts.parts.map((p) => p.name), bones, rebound, skin, cfg.constraints ?? [], declaredFront);
|
|
2809
|
+
const turned = cfg.turn === undefined ? null : applyTurn(cfg.turn, parts.parts.map((p) => p.name), bones, rebound, skin, cfg.constraints ?? [], declaredFront, slotFamilies);
|
|
2741
2810
|
for (const row of turned?.rows ?? []) for (const t of row.twins) layoutAlias(explicitLayout.plan, t.bone, t.twin);
|
|
2742
2811
|
// issue #536: every row names the bones the emitted attachment binds, read once the turn and the stops have
|
|
2743
2812
|
// rebound the weights; a rig with neither rebinds nothing, so this reads back the names each row already holds.
|
|
2744
2813
|
for (const row of meshReport) {
|
|
2814
|
+
const m = cfg.meshes[row.part];
|
|
2815
|
+
if (m !== undefined && 'explicit' in m && m.explicit.islands !== undefined) {
|
|
2816
|
+
const bound = new Set<string>();
|
|
2817
|
+
for (const isl of m.explicit.islands) {
|
|
2818
|
+
const att = skin[isl.slot]?.[isl.slot];
|
|
2819
|
+
if (att !== undefined && 'type' in att) for (const b of meshBoundBones(att)) bound.add(b);
|
|
2820
|
+
}
|
|
2821
|
+
row.bones = [...bound].sort();
|
|
2822
|
+
continue;
|
|
2823
|
+
}
|
|
2745
2824
|
const att = skin[row.part]?.[row.part];
|
|
2746
2825
|
if (att !== undefined && 'type' in att) row.bones = meshBoundBones(att);
|
|
2747
2826
|
}
|
|
2748
|
-
|
|
2749
|
-
for (const [part, mesh] of Object.entries(cfg.meshes)) if ('explicit' in mesh) {
|
|
2750
|
-
const att = skin[part]?.[part];
|
|
2751
|
-
if (att !== undefined && 'type' in att && JSON.stringify(att.weights) !== JSON.stringify(mesh.explicit.weights.map(row => row.map(w => ({ bone: w.bone, x: w.x, y: w.y, weight: w.weight }))))) {
|
|
2752
|
-
fail('RIG_EXPLICIT_BINDING', `config.meshes.${part}.explicit.weights`, 'the declared stops or turn would change these accepted bindings; supply the accepted final emitted bone names and bind coordinates, or use a generated mesh; no payload is normalized');
|
|
2753
|
-
}
|
|
2754
|
-
}
|
|
2755
2827
|
refuseIfAny(problems);
|
|
2756
2828
|
const name = `${cfg.key}_painting`;
|
|
2757
2829
|
const rig: RigSpec = {
|
package/src/scene.ts
CHANGED
|
@@ -384,7 +384,7 @@ export interface CharacterBuild {
|
|
|
384
384
|
|
|
385
385
|
const BONE_KEYS = ['name', 'parent', 'length', 'rotation', 'x', 'y'];
|
|
386
386
|
const SLOT_KEYS = ['name', 'bone', 'attachment'];
|
|
387
|
-
const ATTACHMENT_KEYS = ['type', 'image', 'width', 'height', 'uvs', 'triangles', 'hull', 'weights', 'x', 'y', 'rotation'];
|
|
387
|
+
const ATTACHMENT_KEYS = ['type', 'path', 'image', 'width', 'height', 'uvs', 'triangles', 'hull', 'weights', 'x', 'y', 'rotation'];
|
|
388
388
|
const RIG_KEYS = ['spec', 'name', 'images', 'skeleton', 'bones', 'slots', 'skins', 'constraints', 'stops', 'invariants'];
|
|
389
389
|
const STOP_KEYS = ['chain', 'links', 'against', 'at', 'inward', 'outward', 'lower'];
|
|
390
390
|
const STOP_LOWER_KEYS = ['inward', 'outward'];
|
|
@@ -1123,7 +1123,11 @@ export function composeScene(
|
|
|
1123
1123
|
const out: Record<string, Attachment> = {};
|
|
1124
1124
|
const onRoot = slotBone.get(slot) === ROOT_BONE;
|
|
1125
1125
|
for (const [name, att] of Object.entries(atts as unknown as Record<string, Attachment>)) {
|
|
1126
|
-
const a: Attachment = {
|
|
1126
|
+
const a: Attachment = {
|
|
1127
|
+
...att,
|
|
1128
|
+
...(typeof att.path === 'string' ? { path: imageName(id, att.path) } : {}),
|
|
1129
|
+
image: imageName(id, att.image as string),
|
|
1130
|
+
};
|
|
1127
1131
|
if (Array.isArray(att.weights)) {
|
|
1128
1132
|
a.weights = (att.weights as Array<Array<Record<string, unknown>>>).map((v) =>
|
|
1129
1133
|
v.map((w) =>
|
package/src/structure.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { regionBone } from './config.ts';
|
|
1
|
+
import { explicitWeightRows, regionBone } from './config.ts';
|
|
2
2
|
/**
|
|
3
3
|
* A structural comparison of two skeletons (issue #85).
|
|
4
4
|
*
|
|
@@ -180,7 +180,7 @@ export function configRoles(s: SkeletonSections & { constraints?: readonly Confi
|
|
|
180
180
|
const bound = new Map<string, string[]>();
|
|
181
181
|
for (const [part, m] of Object.entries(s.meshes)) {
|
|
182
182
|
if ('explicit' in m) {
|
|
183
|
-
for (const row of m
|
|
183
|
+
for (const row of explicitWeightRows(m)) for (const w of row) push(bound, w.bone, `meshes.${part}.explicit.weights`);
|
|
184
184
|
continue;
|
|
185
185
|
}
|
|
186
186
|
m.segments.forEach((sp, i) => {
|