@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/src/parts.ts CHANGED
@@ -89,6 +89,7 @@ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
89
89
  import { type Problem, refuseIfAny } from './errors.ts';
90
90
  import { KEYPOINT_NAMES, type PosePoints } from './skeleton.ts';
91
91
  import { readLayerTag } from './tags.ts';
92
+ import { recordedFocusProblems } from './setfocus.ts';
92
93
 
93
94
  export interface PartRecord {
94
95
  name: string;
@@ -283,6 +284,8 @@ export interface RecompositeRecord {
283
284
  }
284
285
 
285
286
  export interface AlternateSetMap {
287
+ /** Authored point in setup-world coordinates, only when supplied (issue #719). */
288
+ focus?: [number, number];
286
289
  slots: Record<string, string>;
287
290
  hides?: string[];
288
291
  drawn?: Record<string, number>;
@@ -301,6 +304,9 @@ export const FRONT_SUFFIX = '_front';
301
304
 
302
305
  export interface AlternatePartsRecord {
303
306
  name: string;
307
+ /** Original authored painting point and its source size, only when supplied. */
308
+ focus?: [number, number];
309
+ focus_source_size?: [number, number];
304
310
  parts?: string[];
305
311
  hides?: string[];
306
312
  /**
@@ -472,6 +478,8 @@ export function serializeParts(file: PartsFile): string {
472
478
  ...(a.single_run_pad === undefined ? {} : { single_run_pad: Object.fromEntries(SINGLE_RUN_PAD_KEYS.map((k) => [k, (a.single_run_pad as SingleRunPad)[k]])) }),
473
479
  ...(a.skeleton === undefined ? {} : { skeleton: Object.fromEntries(KEYPOINT_NAMES.map((k) => [k, (a.skeleton as PosePoints)[k]])) }),
474
480
  ...(a.drawn === undefined ? {} : { drawn: a.drawn }),
481
+ ...(a.focus === undefined ? {} : { focus: a.focus }),
482
+ ...(a.focus_source_size === undefined ? {} : { focus_source_size: a.focus_source_size }),
475
483
  ...(a.tips_source_size === undefined ? {} : { tips_source_size: a.tips_source_size }),
476
484
  ...(a.tips === undefined ? {} : { tips: Object.fromEntries(Object.keys(a.tips).sort().map((bone) => [bone, (a.tips as Record<string, [number, number]>)[bone]])) }),
477
485
  ...(a.drawnLength === undefined ? {} : { drawnLength: a.drawnLength }),
@@ -692,6 +700,7 @@ function checkParts(raw: unknown, path: string): PartsFile {
692
700
  if (typeof a !== 'object' || a === null || Array.isArray(a)) return;
693
701
  const set = a as Record<string, unknown>;
694
702
  const at = `${path} alternates[${i}]${typeof set.name === 'string' ? ` (set "${set.name}")` : ''}`;
703
+ if (sizeOk && typeof scale === 'number') problems.push(...recordedFocusProblems(set, `${at}.focus`, size as number[], scale));
695
704
  if ('tips' in set || 'tips_source_size' in set) {
696
705
  const sourceSize = set.tips_source_size;
697
706
  if (!('tips' in set) || !Array.isArray(sourceSize) || sourceSize.length !== 2 || !sourceSize.every((n) => typeof n === 'number' && Number.isInteger(n) && n > 0)) {
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
@@ -4908,6 +4908,7 @@ export function lint(
4908
4908
  unknownMeshes.push(mname);
4909
4909
  continue;
4910
4910
  }
4911
+ if ('explicit' in m) continue;
4911
4912
  const mask = dilate(P.alpha(part), 31);
4912
4913
  const names: string[] = [];
4913
4914
  for (const sp of m.segments) {
@@ -4932,7 +4933,7 @@ export function lint(
4932
4933
  return part !== undefined && splitFrom(part.from)[0] === 'head' && splitFrom(part.from)[1] === 'front hair';
4933
4934
  });
4934
4935
  const lockChains = lockMeshes.flatMap(([mname, m]) =>
4935
- m.segments.flatMap((sp) => {
4936
+ ('explicit' in m ? [] : m.segments).flatMap((sp) => {
4936
4937
  if (typeof sp !== 'string') return [];
4937
4938
  const e = spec.bones.find((b) => 'chain' in b && b.chain === sp);
4938
4939
  return e !== undefined && 'chain' in e && e.parent === 'head' ? [{ mesh: mname, entry: e }] : [];
@@ -5426,6 +5427,10 @@ function lintCoverage(
5426
5427
  const single: string[] = [];
5427
5428
  const partless: string[] = [];
5428
5429
  for (const [mname, m] of Object.entries(spec.meshes)) {
5430
+ if ('explicit' in 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
+ continue;
5433
+ }
5429
5434
  m.segments.forEach((sp, i) => {
5430
5435
  const at = `meshes.${mname}.segments[${i}]`;
5431
5436
  if (typeof sp !== 'string') {
package/src/rig.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { regionBone } from './config.ts';
1
+ import { explicitBoneNames, explicitSlotBones, explicitWeightRows, regionBone } from './config.ts';
2
+ import { explicitAttachment, type ExplicitMeshReport } from './explicitmesh.ts';
2
3
  /**
3
4
  * The rig stage: a character config and its assembled parts in, a rig spec
4
5
  * and a motion spec in rig-c's format out.
@@ -135,8 +136,9 @@ import { regionBone } from './config.ts';
135
136
  * order the objects are built in, and every number is rounded by `pyRound`).
136
137
  */
137
138
  import { type AutoSpec, type BoneEntry, type InfluenceMeshSpec, type WeightRule, type CharacterConfig, type ConfigConstraint, type ConfigStop, CONSTRAINT_FOLLOWS, constraintForRig, contourRegionsOf, type ContourSpec, DEFAULT_BUST_BONE_L, DEFAULT_BUST_BONE_R, type Point, type RibsSpec, ROOT_BONE, stopForRig, turnRidersByBone, weightsABone } from './config.ts';
138
- import { type BoneTransform, computeExactFrameTransforms, cropToSpineY, normaliseDegrees, toBoneLocal, toWorld } from './coords.ts';
139
+ import { type BoneTransform, computeExactFrameTransforms, cropToSpineY, normaliseDegrees, paintingToSetupPoint, toBoneLocal, toWorld } from './coords.ts';
139
140
  import { type Problem, refuseIfAny } from './errors.ts';
141
+ import { recordedFocusProblems } from './setfocus.ts';
140
142
  import { eyeLineDegrees } from './headframe.ts';
141
143
  import type { RigBoneInherit, RigStop } from 'rig-c/src/rig.ts';
142
144
  import { f32 } from 'rig-c/compile';
@@ -490,6 +492,7 @@ export interface WeightEntry {
490
492
 
491
493
  export interface MeshAttachment {
492
494
  type: 'mesh';
495
+ path?: string;
493
496
  image: string;
494
497
  width: number;
495
498
  height: number;
@@ -677,6 +680,7 @@ function applyTurn(
677
680
  skin: RigSpec['skins']['default'],
678
681
  constraints: readonly ConfigConstraint[],
679
682
  frontSlots: ReadonlySet<string> = new Set(),
683
+ slotFamilies: ReadonlyMap<string, readonly string[]> = new Map(),
680
684
  ): { constraints: Array<Record<string, unknown>>; detached: DetachedRule[]; rows: TurnRow[] } {
681
685
  const problems: Problem[] = [];
682
686
  const taken = new Set(bones.map((b) => b.name));
@@ -687,8 +691,9 @@ function applyTurn(
687
691
  const row: TurnRow = { ...f, twins: [] };
688
692
  rows.push(row);
689
693
  if (f.fraction === 0) continue;
694
+ const family = new Set(slotFamilies.get(f.part) ?? [f.part]);
690
695
  // A declared front slot (issue #664) rides its part; a part merely named `<part>_front` is a part of its own.
691
- const mine = slots.filter((sl) => sl.name === f.part || sl.name === `${f.part}${STILL_SUFFIX}` || (sl.name === `${f.part}${FRONT_SUFFIX}` && frontSlots.has(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)));
692
697
  const bound: string[] = [];
693
698
  const bind = (b: string): void => {
694
699
  if (!bound.includes(b)) bound.push(b);
@@ -712,10 +717,11 @@ function applyTurn(
712
717
  const detached: DetachedRule[] = [];
713
718
  for (const row of rows) {
714
719
  if (row.twins.length === 0) continue;
720
+ const family = new Set(slotFamilies.get(row.part) ?? [row.part]);
715
721
  const twinOf = new Map(row.twins.map((t) => [t.bone, t.twin]));
716
722
  for (const t of row.twins) bones.push({ name: t.twin, parent: t.bone, x: 0, y: 0 });
717
723
  for (const sl of slots) {
718
- if (sl.name !== row.part && sl.name !== `${row.part}${STILL_SUFFIX}` && !(sl.name === `${row.part}${FRONT_SUFFIX}` && frontSlots.has(sl.name))) continue;
724
+ if (!family.has(sl.name) && sl.name !== `${row.part}${STILL_SUFFIX}` && !(sl.name === `${row.part}${FRONT_SUFFIX}` && frontSlots.has(sl.name))) continue;
719
725
  sl.bone = twinOf.get(sl.bone) as string;
720
726
  const atts = skin[sl.name] ?? {};
721
727
  for (const [k, att] of Object.entries(atts)) {
@@ -795,7 +801,7 @@ export function meshBoundBones(att: Pick<MeshAttachment, 'weights'>): string[] {
795
801
  }
796
802
 
797
803
  /** One row of `mesh_report.json`: a lattice mesh's row is as it always was; a contour mesh's says so. */
798
- export type MeshReport = LatticeMeshReport | ContourMeshReport | AutoMeshReport | InfluenceMeshReport;
804
+ export type MeshReport = LatticeMeshReport | ContourMeshReport | AutoMeshReport | InfluenceMeshReport | ExplicitMeshReport;
799
805
 
800
806
  /**
801
807
  * An influence mesh's row (issue #378): the lattice's counts and coverage as every row has them, the block as declared,
@@ -1253,6 +1259,18 @@ export function buildRig(
1253
1259
  const CX = W / 2;
1254
1260
  const byPart = new Map(parts.parts.map((p) => [p.name, p]));
1255
1261
 
1262
+ for (const a of parts.alternates ?? []) {
1263
+ problems.push(...recordedFocusProblems(a, `parts.json alternate set "${a.name}".focus`, parts.rig_size, parts.scale_rig_per_source));
1264
+ }
1265
+ for (const a of cfg.assemble.alternates ?? cfg.alternates ?? []) {
1266
+ const record = parts.alternates?.find((p) => p.name === a.name);
1267
+ if ((a.focus !== undefined || record?.focus !== undefined)
1268
+ && JSON.stringify(a.focus) !== JSON.stringify(record?.focus)) {
1269
+ fail('CONFIG_SET_FOCUS', `config.assemble alternate set "${a.name}".focus`, 'does not match the assembled painting point; re-run assemble after changing or removing focus');
1270
+ }
1271
+ }
1272
+ refuseIfAny(problems);
1273
+
1256
1274
  // Standalone rig checks source-bound normalization, never reconstructing
1257
1275
  // original dimensions from nominal scale or treating source points as rig points.
1258
1276
  for (const a of parts.alternates ?? []) {
@@ -1364,7 +1382,14 @@ export function buildRig(
1364
1382
  // issue #378: which `segments` entry each resolved segment came from — rig-c's `bones` entries, which an influence
1365
1383
  // mesh's `across: false` keeps apart. Every mode resolves them; only the influence mode reads this.
1366
1384
  const meshSegmentEntries = new Map<string, number[]>();
1385
+ const explicitNames = explicitBoneNames(new Set(B.keys()), new Map([...chains].map(([k, v]) => [k, v.length])), cfg.stops);
1367
1386
  for (const [part, m] of Object.entries(cfg.meshes)) {
1387
+ if ('explicit' in 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))]) {
1389
+ if (!explicitNames.has(bone)) fail('RIG_NAME_RESOLVES', `config.meshes.${part}.explicit`, `names the bone "${bone}", which config.bones does not declare`);
1390
+ }
1391
+ continue;
1392
+ }
1368
1393
  if ('contour' in m) {
1369
1394
  (m.contour.regions ?? []).forEach((rg, i) => {
1370
1395
  if (!B.has(rg.bone)) fail('RIG_NAME_RESOLVES', `config.meshes.${part}.contour.regions[${i}].bone`, `names the bone "${rg.bone}", which config.bones does not declare`);
@@ -1499,6 +1524,11 @@ export function buildRig(
1499
1524
  // to its control under `ctl` as theirs do. A config with no contour region adds nothing here.
1500
1525
  for (const m of Object.values(cfg.meshes)) if ('contour' in m) for (const rg of contourRegionsOf(m.contour)) meshBones.add(rg.bone);
1501
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);
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);
1528
+ // Accepted final bindings may already name a stop's drawn link. Its source link still needs the idle control.
1529
+ for (const stop of cfg.stops ?? []) for (const link of stop.links ?? chains.get(stop.chain) ?? []) {
1530
+ if (meshBones.has(`${link}_d`)) meshBones.add(link);
1531
+ }
1502
1532
  const meshKeyed = controlledBones(motion, meshBones);
1503
1533
  const controls = idleKeys === 'ctl' ? meshKeyed : [];
1504
1534
  for (const k of controls) {
@@ -1751,6 +1781,7 @@ export function buildRig(
1751
1781
  // ---- attachments -------------------------------------------------------
1752
1782
  const slots: RigSpec['slots'] = [];
1753
1783
  const slotFamilies = new Map<string, string[]>();
1784
+ const pendingIslandSlots: Array<{ part: string; index: number; prevSlot: string; before?: string; row: RigSpec['slots'][number] }> = [];
1754
1785
  const addSlots = (part: string, ...rows: RigSpec['slots']): void => {
1755
1786
  slots.push(...rows);
1756
1787
  slotFamilies.set(part, [...(slotFamilies.get(part) ?? []), ...rows.map((s) => s.name)]);
@@ -2289,6 +2320,25 @@ export function buildRig(
2289
2320
  addSlots(p.name, { name: p.name, bone: bone.name, attachment: p.name });
2290
2321
  continue;
2291
2322
  }
2323
+ if ('explicit' in mesh) {
2324
+ const row = explicitAttachment(p, images.get(p.name) as Raster, parts.rig_size, mesh);
2325
+ if (Array.isArray(row)) { problems.push(...row); continue; }
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
+ }
2339
+ meshReport.push(row.report);
2340
+ continue;
2341
+ }
2292
2342
  const segs = meshSegments.get(p.name) as Segment[];
2293
2343
  if ('auto' in mesh) {
2294
2344
  const row = autoAttachment(p, img, file, mesh.auto, mesh.r, mesh.exponent, segs, mesh.rule ?? 'distance', mesh, problems);
@@ -2408,6 +2458,25 @@ export function buildRig(
2408
2458
  ...(heat === null ? {} : { heat: heatRow(heat) }),
2409
2459
  });
2410
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
+ }
2411
2480
  refuseIfAny(problems);
2412
2481
  // ---- front slots (issue #664) ------------------------------------------
2413
2482
  // Only when a limb declares `front`: each named segment part gets `<part>_front` on its base slot's bone, showing
@@ -2469,6 +2538,10 @@ export function buildRig(
2469
2538
  for (const s of meshSegments.get(pName) ?? []) coveredBones.add(s.bone);
2470
2539
  const m = cfg.meshes[pName];
2471
2540
  if (m !== undefined) {
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
+ }
2472
2545
  if ('contour' in m) for (const rg of contourRegionsOf(m.contour)) coveredBones.add(rg.bone);
2473
2546
  if ('auto' in m) for (const rg of m.auto.regions ?? []) if (weightsABone(rg)) coveredBones.add(rg.bone);
2474
2547
  }
@@ -2534,6 +2607,10 @@ export function buildRig(
2534
2607
  skin[skinSlot][attName] = altRegion(file, bone.name, p.x + p.w / 2, p.y + p.h / 2);
2535
2608
  continue;
2536
2609
  }
2610
+ if ('explicit' in mesh) {
2611
+ fail('RIG_EXPLICIT_ALTERNATE', `config.meshes.${p.name}.explicit`, `set "${alt.name}" replaces this part; an accepted payload is bound to one image and region, not alternate artwork or bind poses — use a generated mesh for this alternate part`);
2612
+ continue;
2613
+ }
2537
2614
  const fullSegs = meshSegments.get(p.name) as Segment[];
2538
2615
  const explicitSegments = new Map(fullSegs.map((s, k) => [s, typeof mesh.segments[(meshSegmentEntries.get(p.name) as number[])[k]] !== 'string']));
2539
2616
  const baseAtt = skin[p.name]?.[p.name];
@@ -2652,7 +2729,9 @@ export function buildRig(
2652
2729
  for (const [slotName, att] of Object.entries(alt.slots)) slotMap[slotName] = att;
2653
2730
  const hideList: string[] = [];
2654
2731
  for (const h of alt.hides ?? []) {
2655
- if (!hideList.includes(h)) hideList.push(h);
2732
+ for (const member of slotFamilies.get(h) ?? [h]) {
2733
+ if (!hideList.includes(member)) hideList.push(member);
2734
+ }
2656
2735
  if (stills[h] !== undefined && !hideList.includes(`${h}${STILL_SUFFIX}`)) hideList.push(`${h}${STILL_SUFFIX}`);
2657
2736
  }
2658
2737
  for (const slotName of Object.keys(alt.slots)) {
@@ -2661,6 +2740,7 @@ export function buildRig(
2661
2740
  const coversFace = Object.hasOwn(slotMap, 'face');
2662
2741
  setEntries[alt.name] = {
2663
2742
  slots: slotMap,
2743
+ ...(alt.focus === undefined ? {} : { focus: paintingToSetupPoint(alt.focus, alt.focus_source_size as [number, number], parts.rig_size) }),
2664
2744
  ...(hideList.length > 0 ? { hides: hideList } : {}),
2665
2745
  ...(drawn === undefined ? {} : { drawn }),
2666
2746
  ...(alt.drawnLength === undefined ? {} : { drawnLength: { ...alt.drawnLength } }),
@@ -2682,8 +2762,13 @@ export function buildRig(
2682
2762
  ...Object.entries(cfg.meshes).filter(([, spec]) => spec.gather === false).map(([part]) => ({ part, object: `config.meshes.${part}.gather`, slots: slotFamilies.get(part) ?? [part] })),
2683
2763
  ...Object.entries(cfg.regions).filter(([, spec]) => typeof spec !== 'string' && spec.gather === false).map(([part]) => ({ part, object: `config.regions.${part}.gather`, slots: slotFamilies.get(part) ?? [part] })),
2684
2764
  ];
2685
- const limbLayout = coalesceLimbSlots(cfg.limbs, bones, slots, skin, ungathered);
2686
- const explicitLayout = placeLimbLayouts(cfg.limbs, bones, limbLayout, skin, slotFamilies);
2765
+ // Accepted explicit weights already name drawn stop links. Resolve only the
2766
+ // declared aliases for ownership before applyStops, without rebinding them
2767
+ // or adding these lookup-only entries to the emitted bone graph.
2768
+ const ownershipBones = cfg.stops === undefined ? bones : [...bones, ...cfg.stops.flatMap(s =>
2769
+ (s.links ?? chains.get(s.chain) ?? []).map(link => ({ name: `${link}_d`, parent: link, x: 0, y: 0 })))];
2770
+ const limbLayout = coalesceLimbSlots(cfg.limbs, ownershipBones, slots, skin, ungathered);
2771
+ const explicitLayout = placeLimbLayouts(cfg.limbs, ownershipBones, limbLayout, skin, slotFamilies);
2687
2772
  // ---- leg stops (issue #404) --------------------------------------------
2688
2773
  // Only when the config has `stops`: each link after the first (and any bone hanging from a stopped link) hangs
2689
2774
  // from the drawn link `<link>_d` above it, and slots and weights on a stopped link bind `<link>_d`.
@@ -2692,15 +2777,49 @@ export function buildRig(
2692
2777
  // ---- the turn control (issue #251) -------------------------------------
2693
2778
  // Only when the config has `turn`: every other build adds nothing here, so no byte moves.
2694
2779
  if (cfg.turn !== undefined) refuseIfAny(turnRiderProblems(cfg.turn, cfg, parts.parts));
2695
- const turned = cfg.turn === undefined ? null : applyTurn(cfg.turn, parts.parts.map((p) => p.name), bones, rebound, skin, cfg.constraints ?? [], declaredFront);
2780
+ const turned = cfg.turn === undefined ? null : applyTurn(cfg.turn, parts.parts.map((p) => p.name), bones, rebound, skin, cfg.constraints ?? [], declaredFront, slotFamilies);
2696
2781
  for (const row of turned?.rows ?? []) for (const t of row.twins) layoutAlias(explicitLayout.plan, t.bone, t.twin);
2697
2782
  // issue #536: every row names the bones the emitted attachment binds, read once the turn and the stops have
2698
2783
  // rebound the weights; a rig with neither rebinds nothing, so this reads back the names each row already holds.
2699
2784
  for (const row of meshReport) {
2785
+ const m = cfg.meshes[row.part];
2786
+ if (m !== undefined && 'explicit' in m && m.explicit.islands !== undefined) {
2787
+ const bound = new Set<string>();
2788
+ for (const isl of m.explicit.islands) {
2789
+ const att = skin[isl.slot]?.[isl.slot];
2790
+ if (att !== undefined && 'type' in att) for (const b of meshBoundBones(att)) bound.add(b);
2791
+ }
2792
+ row.bones = [...bound].sort();
2793
+ continue;
2794
+ }
2700
2795
  const att = skin[row.part]?.[row.part];
2701
2796
  if (att !== undefined && 'type' in att) row.bones = meshBoundBones(att);
2702
2797
  }
2703
2798
 
2799
+ for (const [part, mesh] of Object.entries(cfg.meshes)) if ('explicit' in mesh) {
2800
+ const defaultBone = typeof mesh.segments[0] === 'string' ? mesh.segments[0] : mesh.segments[0][0];
2801
+ if (mesh.explicit.islands !== undefined) {
2802
+ mesh.explicit.islands.forEach((isl, i) => {
2803
+ const att = skin[isl.slot]?.[isl.slot];
2804
+ const slotEntry = slots.find((s) => s.name === isl.slot);
2805
+ const expectedBone = isl.bone ?? defaultBone;
2806
+ const weightsChanged =
2807
+ att !== undefined &&
2808
+ 'type' in att &&
2809
+ 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 }))));
2810
+ const boneChanged = slotEntry !== undefined && slotEntry.bone !== expectedBone;
2811
+ if (weightsChanged || boneChanged) {
2812
+ fail('RIG_EXPLICIT_BINDING', `config.meshes.${part}.explicit.islands[${i}].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');
2813
+ }
2814
+ });
2815
+ continue;
2816
+ }
2817
+ const att = skin[part]?.[part];
2818
+ 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 }))))) {
2819
+ 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');
2820
+ }
2821
+ }
2822
+ refuseIfAny(problems);
2704
2823
  const name = `${cfg.key}_painting`;
2705
2824
  const rig: RigSpec = {
2706
2825
  spec: 'rigc-rig/1',
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 = { ...att, image: imageName(id, att.image as string) };
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) =>
@@ -0,0 +1,21 @@
1
+ /** Issue #719: authored painting points, never inferred from geometry. */
2
+ import type { Problem } from './errors.ts';
3
+
4
+ export function setFocusProblems(value: unknown, object: string, size?: readonly number[]): Problem[] {
5
+ if (!Array.isArray(value) || value.length !== 2 || !value.every((n) => typeof n === 'number' && Number.isFinite(n))
6
+ || value.some((n) => n < 0) || (size !== undefined && value.some((n, i) => n > size[i]))) {
7
+ return [{ code: 'CONFIG_SET_FOCUS', object, detail: `is ${Array.isArray(value) ? '[' + value.map((n) => typeof n === 'number' ? String(n) : JSON.stringify(n)).join(', ') + ']' : String(JSON.stringify(value))}; exactly two finite painting-pixel coordinates [x, y]${size === undefined ? ', both non-negative' : ` inside the ${size[0]}x${size[1]} painting (edges included)`} are required; author the point or omit focus` }];
8
+ }
9
+ return [];
10
+ }
11
+
12
+ /** The conditional parts record retains the actual painting size, not a size guessed from rig_scale. */
13
+ export function recordedFocusProblems(record: { focus?: unknown; focus_source_size?: unknown }, object: string, rigSize: readonly number[], scale: number): Problem[] {
14
+ if (!('focus' in record) && !('focus_source_size' in record)) return [];
15
+ const size = record.focus_source_size;
16
+ if (!('focus' in record) || !Array.isArray(size) || size.length !== 2 || !size.every((n) => typeof n === 'number' && Number.isInteger(n) && n > 0)
17
+ || size.some((n, i) => Math.trunc(n * scale) !== rigSize[i])) {
18
+ return [{ code: 'CONFIG_SET_FOCUS', object, detail: 'requires focus with its original positive integer focus_source_size [width, height] producing rig_size at scale_rig_per_source; re-run assemble' }];
19
+ }
20
+ return setFocusProblems(record.focus, object, size);
21
+ }
package/src/squeeze.ts CHANGED
@@ -182,6 +182,7 @@ export function chainSqueezes(
182
182
  const times = frameTimes(motion.duration);
183
183
 
184
184
  for (const [mname, m] of Object.entries(spec.meshes)) {
185
+ if ('explicit' in m) { unread.push(`mesh ${JSON.stringify(mname)} is an explicit payload; the lattice squeeze is not read`); continue; }
185
186
  const keyed = m.segments.filter((s): s is string => typeof s === 'string' && chains.has(s) && tracks.has(s));
186
187
  if (keyed.length < 2) continue;
187
188
  const pairs: Array<[string, string]> = [];
@@ -318,7 +319,7 @@ export function branchSqueezes(
318
319
  }
319
320
 
320
321
  for (const [mname, m] of Object.entries(spec.meshes)) {
321
- if ('contour' in m || 'auto' in m || 'influence' in m || m.rule === 'heat' || m.r >= m.grid) continue;
322
+ if ('explicit' in m || 'contour' in m || 'auto' in m || 'influence' in m || m.rule === 'heat' || m.r >= m.grid) continue;
322
323
  const byFork = new Map<string, string[]>();
323
324
  for (const sp of m.segments) {
324
325
  if (typeof sp !== 'string') continue;
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
  *
@@ -179,6 +179,10 @@ export function configRoles(s: SkeletonSections & { constraints?: readonly Confi
179
179
  }
180
180
  const bound = new Map<string, string[]>();
181
181
  for (const [part, m] of Object.entries(s.meshes)) {
182
+ if ('explicit' in m) {
183
+ for (const row of explicitWeightRows(m)) for (const w of row) push(bound, w.bone, `meshes.${part}.explicit.weights`);
184
+ continue;
185
+ }
182
186
  m.segments.forEach((sp, i) => {
183
187
  const at = `meshes.${part}.segments[${i}]`;
184
188
  if (typeof sp === 'string') for (const b of chains.get(sp) ?? [sp]) push(bound, b, at);