@ikijs/mcp 0.29.0 → 0.31.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.
@@ -966,6 +966,7 @@ import {
966
966
  } from "@ikijs/format";
967
967
 
968
968
  // ../engine/src/land.ts
969
+ var UNIT_QUAD = [-0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5];
969
970
  function staticDeformers(model) {
970
971
  return (model.deformers ?? []).map(
971
972
  (d) => d.kind === "warp" ? { ...d, warps: void 0, warp2d: void 0 } : { ...d, bindings: void 0 }
@@ -1018,6 +1019,28 @@ function landPart(landing, store, { worlds, grids }) {
1018
1019
  }
1019
1020
  return landed;
1020
1021
  }
1022
+ function landParts(model, values, partIds) {
1023
+ const deformers = model.deformers ?? [];
1024
+ const restStore = new ParameterStore(model.parameters);
1025
+ const store = new ParameterStore(model.parameters);
1026
+ for (const [id, value] of Object.entries(values)) store.set(id, value);
1027
+ const { worlds } = resolveDeformers(staticDeformers(model), restStore);
1028
+ const resolved = resolveDeformers(deformers, store);
1029
+ const out = /* @__PURE__ */ new Map();
1030
+ for (const id of partIds) {
1031
+ const part = model.parts.find((p) => p.id === id);
1032
+ if (!part) continue;
1033
+ const landing = landedPart(
1034
+ part,
1035
+ part.mesh?.vertices ?? UNIT_QUAD,
1036
+ deformers,
1037
+ worlds,
1038
+ restStore
1039
+ );
1040
+ out.set(id, Float32Array.from(landPart(landing, store, resolved)));
1041
+ }
1042
+ return out;
1043
+ }
1021
1044
 
1022
1045
  // ../engine/src/folds.ts
1023
1046
  var FLIP = 0;
@@ -1421,7 +1444,6 @@ function stopsOf(model, parameter) {
1421
1444
  var DISPLACEMENT_PX = 1;
1422
1445
  var PINNED_FRAMES = 60;
1423
1446
  var TOLERANCE = 1e-9;
1424
- var UNIT_QUAD = [-0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5];
1425
1447
  function checkPhysics(model) {
1426
1448
  const idle = idleRun(model);
1427
1449
  const displace = displacer(model);
@@ -1706,14 +1728,133 @@ function ratioText(ratio) {
1706
1728
  return Math.abs(ratio) < 0.01 ? ratio.toExponential(1) : ratio.toFixed(2);
1707
1729
  }
1708
1730
 
1709
- // src/render-poses.ts
1710
- import { readFileSync } from "fs";
1711
- import path3 from "path";
1712
- import {
1713
- IkiFormatError,
1714
- StandardParameter as StandardParameter3,
1715
- loadIkiModel
1716
- } from "@ikijs/format";
1731
+ // src/sweep-report.ts
1732
+ var LADDER_MIN = -30;
1733
+ var LADDER_MAX = 30;
1734
+ var ZERO = -LADDER_MIN;
1735
+ var FLAT_SLOPE = 1e-4;
1736
+ var PARTS = ["face", "eye_L", "eye_R", "nose"];
1737
+ function box(pts, fw) {
1738
+ let x0 = Infinity;
1739
+ let x1 = -Infinity;
1740
+ let y0 = Infinity;
1741
+ let y1 = -Infinity;
1742
+ for (let i = 0; i < pts.length; i += 2) {
1743
+ x0 = Math.min(x0, pts[i]);
1744
+ x1 = Math.max(x1, pts[i]);
1745
+ y0 = Math.min(y0, pts[i + 1]);
1746
+ y1 = Math.max(y1, pts[i + 1]);
1747
+ }
1748
+ return {
1749
+ x: (x0 + x1) / 2 / fw,
1750
+ width: (x1 - x0) / fw,
1751
+ y: (y0 + y1) / 2 / fw
1752
+ };
1753
+ }
1754
+ function nearestVertex(face, fw, x, y) {
1755
+ let best = 0;
1756
+ let bestD = Infinity;
1757
+ for (let i = 0; i < face.length; i += 2) {
1758
+ const d = (face[i] / fw - x) ** 2 + (face[i + 1] / fw - y) ** 2;
1759
+ if (d < bestD) {
1760
+ bestD = d;
1761
+ best = i / 2;
1762
+ }
1763
+ }
1764
+ return best;
1765
+ }
1766
+ function kink(v) {
1767
+ const sMinus = (v[ZERO] - v[ZERO - 5]) / 5;
1768
+ const sPlus = (v[ZERO + 5] - v[ZERO]) / 5;
1769
+ const big = Math.max(Math.abs(sMinus), Math.abs(sPlus));
1770
+ if (big < FLAT_SLOPE) return null;
1771
+ return Math.abs(sPlus - sMinus) / big;
1772
+ }
1773
+ function pop(v) {
1774
+ let steps = 0;
1775
+ for (let i = 0; i + 1 < v.length; i++) steps += Math.abs(v[i + 1] - v[i]);
1776
+ const mean = steps / (v.length - 1);
1777
+ if (mean < 1e-9) return null;
1778
+ let most = 0;
1779
+ for (let i = 1; i + 1 < v.length; i++) {
1780
+ if (Math.abs(i - ZERO) <= 1) continue;
1781
+ most = Math.max(most, Math.abs(v[i + 1] - 2 * v[i] + v[i - 1]));
1782
+ }
1783
+ return most / mean;
1784
+ }
1785
+ function checkSweep(model) {
1786
+ const face = model.parts.find((p) => p.id === "face");
1787
+ if (!face) return { preset: "turn", unavailable: "no face part" };
1788
+ const hasEyes = ["eye_L", "eye_R"].every(
1789
+ (id) => model.parts.some((p) => p.id === id)
1790
+ );
1791
+ if (!hasEyes) {
1792
+ return { preset: "turn", unavailable: "no eye_L and eye_R parts" };
1793
+ }
1794
+ const fw = face.width;
1795
+ const ladder = Array.from(
1796
+ { length: LADDER_MAX - LADDER_MIN + 1 },
1797
+ (_, i) => landParts(model, { ParamAngleX: LADDER_MIN + i }, PARTS)
1798
+ );
1799
+ const at = (id, i) => ladder[i].get(id);
1800
+ const ids = ["eye_L", "eye_R", ...ladder[0].has("nose") ? ["nose"] : []];
1801
+ const landmarks = ids.map((id) => {
1802
+ const boxes = ladder.map((_, i) => box(at(id, i), fw));
1803
+ const xs = boxes.map((b) => b.x);
1804
+ const plateIndex2 = nearestVertex(
1805
+ at("face", ZERO),
1806
+ fw,
1807
+ boxes[ZERO].x,
1808
+ boxes[ZERO].y
1809
+ );
1810
+ const plate = ladder.map((_, i) => at("face", i)[plateIndex2 * 2] / fw);
1811
+ const lead = (i) => xs[i] - plate[i] - (xs[ZERO] - plate[ZERO]);
1812
+ return {
1813
+ id,
1814
+ amplitude: xs[xs.length - 1] - xs[0],
1815
+ xKink: kink(xs),
1816
+ widthKink: id === "nose" ? null : kink(boxes.map((b) => b.width)),
1817
+ lead: { m30: lead(0), p30: lead(xs.length - 1) },
1818
+ pop: pop(xs)
1819
+ };
1820
+ });
1821
+ const eyes = ["eye_L", "eye_R"].map((id) => box(at(id, ZERO), fw));
1822
+ const plateIndex = nearestVertex(
1823
+ at("face", ZERO),
1824
+ fw,
1825
+ (eyes[0].x + eyes[1].x) / 2,
1826
+ (eyes[0].y + eyes[1].y) / 2
1827
+ );
1828
+ const plateX = (i) => at("face", i)[plateIndex * 2] / fw;
1829
+ return {
1830
+ preset: "turn",
1831
+ unit: "fw",
1832
+ faceWidth: fw,
1833
+ plateAmplitude: plateX(ladder.length - 1) - plateX(0),
1834
+ landmarks
1835
+ };
1836
+ }
1837
+ var fw3 = (v) => {
1838
+ const s = v.toFixed(3);
1839
+ return s === "-0.000" ? "0.000" : s;
1840
+ };
1841
+ var signed = (v) => fw3(v).startsWith("-") ? fw3(v) : `+${fw3(v)}`;
1842
+ var two = (v) => v === null ? "n/a" : v.toFixed(2);
1843
+ function formatSweepReport(report) {
1844
+ if ("unavailable" in report) {
1845
+ return [`SWEEP: unavailable \u2014 ${report.unavailable}`];
1846
+ }
1847
+ return [
1848
+ ...report.landmarks.map(
1849
+ (l) => `SWEEP turn ${l.id}: amplitude ${fw3(l.amplitude)} fw, x kink ${two(l.xKink)}, width kink ${two(l.widthKink)}, lead -30 ${signed(l.lead.m30)} fw / +30 ${signed(l.lead.p30)} fw, pop ${two(l.pop)}`
1850
+ ),
1851
+ `SWEEP turn plate: amplitude ${fw3(report.plateAmplitude)} fw`
1852
+ ];
1853
+ }
1854
+
1855
+ // src/sweep.ts
1856
+ import fs3 from "fs";
1857
+ import path4 from "path";
1717
1858
 
1718
1859
  // src/limits.ts
1719
1860
  import fs from "fs";
@@ -1845,6 +1986,15 @@ function writeFileAtomic(outPath, data) {
1845
1986
  }
1846
1987
  }
1847
1988
 
1989
+ // src/render-poses.ts
1990
+ import { readFileSync } from "fs";
1991
+ import path3 from "path";
1992
+ import {
1993
+ IkiFormatError,
1994
+ StandardParameter as StandardParameter3,
1995
+ loadIkiModel
1996
+ } from "@ikijs/format";
1997
+
1848
1998
  // src/render-browser.ts
1849
1999
  import { spawn } from "child_process";
1850
2000
  import fs2 from "fs";
@@ -2144,10 +2294,11 @@ var BUST_SIZE = 560;
2144
2294
  var CROP_WIDTH = 720;
2145
2295
  var CROP_MAX_HEIGHT = 8192;
2146
2296
  var POSE_NAME = /^[A-Za-z0-9_.-]+$/;
2297
+ var SWEEP_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
2147
2298
  function bustPadY(width, height) {
2148
2299
  return Math.max(0, (BUST_SIZE - BUST_SIZE * height / width) / 2);
2149
2300
  }
2150
- function planRenders(model, requested) {
2301
+ function planRenders(model, requested, sweep) {
2151
2302
  const { width: W, height: H } = model.canvas;
2152
2303
  const fullBody = H > W;
2153
2304
  const canvas = fullBody ? {
@@ -2177,40 +2328,49 @@ function planRenders(model, requested) {
2177
2328
  name,
2178
2329
  values
2179
2330
  });
2331
+ const toRenderCrop = (crop, label) => {
2332
+ const left = Math.max(crop.x, 0);
2333
+ const top = Math.max(crop.y, 0);
2334
+ const w = Math.min(crop.x + crop.w, W) - left;
2335
+ const h = Math.min(crop.y + crop.h, H) - top;
2336
+ if (!(w > 0 && h > 0)) {
2337
+ throw new AutoRigInputError(
2338
+ `${label} does not overlap the model's ${W}x${H} canvas`
2339
+ );
2340
+ }
2341
+ const dh = Math.round(CROP_WIDTH * h / w);
2342
+ if (dh < 1 || dh > CROP_MAX_HEIGHT) {
2343
+ throw new AutoRigInputError(
2344
+ `${label} meets the canvas in ${w}x${h} model px, which ${CROP_WIDTH} px wide draws ${dh} px tall, outside 1..${CROP_MAX_HEIGHT}`
2345
+ );
2346
+ }
2347
+ return {
2348
+ sx: x0 + left * s,
2349
+ sy: y0 + top * s,
2350
+ sw: w * s,
2351
+ sh: h * s,
2352
+ dw: CROP_WIDTH,
2353
+ dh
2354
+ };
2355
+ };
2356
+ if (sweep && !SWEEP_NAME.test(sweep.name)) {
2357
+ throw new AutoRigInputError(
2358
+ `sweep.name must match ${SWEEP_NAME.source} (it names <outDir>/<name>/): ${JSON.stringify(sweep.name)}`
2359
+ );
2360
+ }
2361
+ const sweepCrop = sweep ? sweep.crop ? toRenderCrop(sweep.crop, "sweep.crop") : squareCrop : void 0;
2180
2362
  if (requested) {
2181
2363
  if (requested.length === 0) throw new AutoRigInputError("poses is empty");
2182
2364
  const poses2 = requested.map((pose, i) => {
2183
2365
  checkRequest(requested, i);
2184
2366
  if (!pose.crop) return square(pose.name, pose.values);
2185
- const left = Math.max(pose.crop.x, 0);
2186
- const top = Math.max(pose.crop.y, 0);
2187
- const w = Math.min(pose.crop.x + pose.crop.w, W) - left;
2188
- const h = Math.min(pose.crop.y + pose.crop.h, H) - top;
2189
- if (!(w > 0 && h > 0)) {
2190
- throw new AutoRigInputError(
2191
- `poses[${i}].crop does not overlap the model's ${W}x${H} canvas`
2192
- );
2193
- }
2194
- const dh = Math.round(CROP_WIDTH * h / w);
2195
- if (dh < 1 || dh > CROP_MAX_HEIGHT) {
2196
- throw new AutoRigInputError(
2197
- `poses[${i}].crop meets the canvas in ${w}x${h} model px, which ${CROP_WIDTH} px wide draws ${dh} px tall, outside 1..${CROP_MAX_HEIGHT}`
2198
- );
2199
- }
2200
2367
  return {
2201
2368
  name: pose.name,
2202
2369
  values: pose.values,
2203
- crop: {
2204
- sx: x0 + left * s,
2205
- sy: y0 + top * s,
2206
- sw: w * s,
2207
- sh: h * s,
2208
- dw: CROP_WIDTH,
2209
- dh
2210
- }
2370
+ crop: toRenderCrop(pose.crop, `poses[${i}].crop`)
2211
2371
  };
2212
2372
  });
2213
- return { canvas, view, fullBody, mouth, poses: poses2 };
2373
+ return { canvas, view, fullBody, mouth, poses: poses2, sweepCrop };
2214
2374
  }
2215
2375
  const bodyAngles = Object.fromEntries(
2216
2376
  [
@@ -2318,7 +2478,7 @@ function planRenders(model, requested) {
2318
2478
  );
2319
2479
  }
2320
2480
  }
2321
- return { canvas, view, fullBody, mouth, poses };
2481
+ return { canvas, view, fullBody, mouth, poses, sweepCrop };
2322
2482
  }
2323
2483
  function checkRequest(requested, i) {
2324
2484
  const { name, values } = requested[i];
@@ -2358,6 +2518,86 @@ function readPageScript() {
2358
2518
  );
2359
2519
  }
2360
2520
  }
2521
+ async function captureSweep(evaluate, model, plan, requested, dir, report) {
2522
+ const spec = sweepSpec(model, plan.sweepCrop);
2523
+ await evaluate(
2524
+ `window.__ikiRender.sweepBegin(${JSON.stringify(spec)})`,
2525
+ CAPTURE_MS
2526
+ );
2527
+ const frames = [];
2528
+ for (let k = 0; k < spec.frames; k++) {
2529
+ const { png, values } = await evaluate(
2530
+ "window.__ikiRender.sweepFrame()",
2531
+ CAPTURE_MS
2532
+ );
2533
+ if (typeof png !== "string" || !png.startsWith(PNG_PREFIX)) {
2534
+ throw new Error(
2535
+ `sweep ${requested.name} frame ${k}: the page returned no PNG`
2536
+ );
2537
+ }
2538
+ const file = `f${String(k).padStart(3, "0")}.png`;
2539
+ writeFileAtomic(
2540
+ path3.join(dir, file),
2541
+ Buffer.from(png.slice(PNG_PREFIX.length), "base64")
2542
+ );
2543
+ frames.push({
2544
+ i: k,
2545
+ file,
2546
+ t: k / SWEEP_FPS,
2547
+ theta: spec.thetas[spec.captureEvery * k],
2548
+ values
2549
+ });
2550
+ }
2551
+ const end = await evaluate("window.__ikiRender.sweepEnd()", CAPTURE_MS);
2552
+ for (const [what, url] of Object.entries(end)) {
2553
+ if (typeof url !== "string" || !url.startsWith(PNG_PREFIX)) {
2554
+ throw new Error(
2555
+ `sweep ${requested.name} ${what}: the page returned no PNG`
2556
+ );
2557
+ }
2558
+ }
2559
+ const sheet = path3.join(dir, "sheet.png");
2560
+ const kymograph = path3.join(dir, "kymograph.png");
2561
+ writeFileAtomic(
2562
+ sheet,
2563
+ Buffer.from(end.sheet.slice(PNG_PREFIX.length), "base64")
2564
+ );
2565
+ writeFileAtomic(
2566
+ kymograph,
2567
+ Buffer.from(end.kymograph.slice(PNG_PREFIX.length), "base64")
2568
+ );
2569
+ const manifest = {
2570
+ version: 1,
2571
+ preset: requested.preset,
2572
+ parameter: spec.parameter,
2573
+ fps: SWEEP_FPS,
2574
+ clockHz: SWEEP_CLOCK_HZ,
2575
+ warmupS: SWEEP_WARMUP_S,
2576
+ durationS: SWEEP_DURATION_S,
2577
+ crop: requested.crop ?? null,
2578
+ frame: spec.frame,
2579
+ kymographRow: { row: spec.kymograph.row, at: spec.kymograph.at },
2580
+ sheet: { frames: spec.sheet.frames, cell: spec.sheet.cell },
2581
+ physicsOutputs: spec.physicsOutputs,
2582
+ frames
2583
+ };
2584
+ const manifestPath = path3.join(dir, "manifest.json");
2585
+ const flipbook = path3.join(dir, "index.html");
2586
+ writeFileAtomic(manifestPath, JSON.stringify(manifest, null, 2) + "\n");
2587
+ writeFileAtomic(flipbook, flipbookHtml(manifest));
2588
+ return {
2589
+ name: requested.name,
2590
+ preset: requested.preset,
2591
+ dir,
2592
+ fps: SWEEP_FPS,
2593
+ frames: spec.frames,
2594
+ manifest: manifestPath,
2595
+ sheet,
2596
+ kymograph,
2597
+ flipbook,
2598
+ report
2599
+ };
2600
+ }
2361
2601
  async function renderPoses(input) {
2362
2602
  try {
2363
2603
  const modelFile = confineToWorkingDirectory(
@@ -2368,7 +2608,7 @@ async function renderPoses(input) {
2368
2608
  );
2369
2609
  const outDir = resolveOutputDir(input.outDir);
2370
2610
  const model = loadIkiModel(readFileSync(modelFile, "utf8"));
2371
- const plan = planRenders(model, input.poses);
2611
+ const plan = planRenders(model, input.poses, input.sweep);
2372
2612
  const browser = findBrowser();
2373
2613
  if (!browser) return { ok: false, error: NO_BROWSER_MESSAGE };
2374
2614
  const pageScript = readPageScript();
@@ -2377,7 +2617,9 @@ async function renderPoses(input) {
2377
2617
  input.poses?.map((p) => p.values)
2378
2618
  );
2379
2619
  const physics = checkPhysics(model);
2380
- const { failedTextures, poses } = await withBrowser(
2620
+ const sweepDir = input.sweep ? prepareSweepDir(outDir, input.sweep.name) : void 0;
2621
+ const sweepReport = input.sweep ? checkSweep(model) : void 0;
2622
+ const { failedTextures, poses, sweep } = await withBrowser(
2381
2623
  browser,
2382
2624
  async (evaluate) => {
2383
2625
  await evaluate(pageScript, PAGE_SCRIPT_MS);
@@ -2401,7 +2643,15 @@ async function renderPoses(input) {
2401
2643
  );
2402
2644
  written.push({ name: pose.name, path: file });
2403
2645
  }
2404
- return { failedTextures: loaded.failedTextures, poses: written };
2646
+ const sweep2 = input.sweep && sweepDir && sweepReport ? await captureSweep(
2647
+ evaluate,
2648
+ model,
2649
+ plan,
2650
+ input.sweep,
2651
+ sweepDir,
2652
+ sweepReport
2653
+ ) : void 0;
2654
+ return { failedTextures: loaded.failedTextures, poses: written, sweep: sweep2 };
2405
2655
  }
2406
2656
  );
2407
2657
  return {
@@ -2414,7 +2664,8 @@ async function renderPoses(input) {
2414
2664
  poses,
2415
2665
  modelCanvas: model.canvas,
2416
2666
  folds,
2417
- physics
2667
+ physics,
2668
+ sweep
2418
2669
  };
2419
2670
  } catch (error) {
2420
2671
  if (error instanceof AutoRigInputError || error instanceof IkiFormatError) {
@@ -2424,9 +2675,217 @@ async function renderPoses(input) {
2424
2675
  }
2425
2676
  }
2426
2677
 
2678
+ // src/sweep.ts
2679
+ var SWEEP_CLOCK_HZ = 60;
2680
+ var SWEEP_FPS = 30;
2681
+ var SWEEP_DURATION_S = 3;
2682
+ var SWEEP_WARMUP_S = 0.5;
2683
+ var SWEEP_FRAME_MS = 1e3 / SWEEP_CLOCK_HZ * (1 + 1e-9);
2684
+ var SHEET_THETAS = [-30, -20, -10, -5, 0, 5, 10, 20, 30];
2685
+ var SHEET_MAX_SIDE = 2e3;
2686
+ var SHEET_MARGIN = 8;
2687
+ var SHEET_LABEL_BAND = 24;
2688
+ var KYMOGRAPH_BAND = 3;
2689
+ var SWEEP_PARAMETER = "ParamAngleX";
2690
+ var STEPS = SWEEP_CLOCK_HZ * SWEEP_DURATION_S;
2691
+ var CAPTURE_EVERY = SWEEP_CLOCK_HZ / SWEEP_FPS;
2692
+ var FRAMES = STEPS / CAPTURE_EVERY;
2693
+ var LEG_FROM_S = 0.75;
2694
+ var LEG_TO_S = 2.25;
2695
+ var AMPLITUDE_DEG = 30;
2696
+ function turnTheta(t) {
2697
+ return -AMPLITUDE_DEG * Math.sin(2 * Math.PI * t / SWEEP_DURATION_S);
2698
+ }
2699
+ function eyeRowModelPx(model) {
2700
+ const landed = landParts(model, {}, ["eye_L", "eye_R"]);
2701
+ const l = landed.get("eye_L");
2702
+ const r = landed.get("eye_R");
2703
+ if (!l || !r) return void 0;
2704
+ const centreY = (pts) => {
2705
+ let lo = Infinity;
2706
+ let hi = -Infinity;
2707
+ for (let i = 1; i < pts.length; i += 2) {
2708
+ lo = Math.min(lo, pts[i]);
2709
+ hi = Math.max(hi, pts[i]);
2710
+ }
2711
+ return (lo + hi) / 2;
2712
+ };
2713
+ return model.canvas.height / 2 - (centreY(l) + centreY(r)) / 2;
2714
+ }
2715
+ function physicsOutputIds(model) {
2716
+ const ids = /* @__PURE__ */ new Set();
2717
+ for (const rig of model.physics ?? []) ids.add(rig.output.parameter);
2718
+ for (const chain of model.physicsChains ?? []) {
2719
+ for (const seg of chain.segments) ids.add(seg.output.parameter);
2720
+ }
2721
+ return [...ids];
2722
+ }
2723
+ function sheetFrames(thetas) {
2724
+ const onLeg = [];
2725
+ for (let k = 0; k < FRAMES; k++) {
2726
+ const t = k / SWEEP_FPS;
2727
+ if (t >= LEG_FROM_S && t <= LEG_TO_S) onLeg.push(k);
2728
+ }
2729
+ const picked = [];
2730
+ for (const target2 of SHEET_THETAS) {
2731
+ let best = onLeg[0];
2732
+ for (const k of onLeg) {
2733
+ if (Math.abs(thetas[CAPTURE_EVERY * k] - target2) < Math.abs(thetas[CAPTURE_EVERY * best] - target2)) {
2734
+ best = k;
2735
+ }
2736
+ }
2737
+ if (!picked.includes(best)) picked.push(best);
2738
+ }
2739
+ return picked.sort((a, b) => a - b);
2740
+ }
2741
+ function sheetLabel(theta, t) {
2742
+ const rounded = Math.round(theta * 10) / 10 + 0;
2743
+ const deg = rounded.toFixed(1);
2744
+ const signed2 = rounded > 0 ? `+${deg}` : deg.replace("-", "\u2212");
2745
+ return `\u03B8 ${signed2}\xB0 t ${t.toFixed(2)} s`;
2746
+ }
2747
+ function sweepSpec(model, crop) {
2748
+ const thetas = Array.from(
2749
+ { length: STEPS },
2750
+ (_, j) => turnTheta(j / SWEEP_CLOCK_HZ)
2751
+ );
2752
+ const dw = crop ? crop.dw : BUST_SIZE;
2753
+ const dh = crop ? crop.dh : BUST_SIZE;
2754
+ const m = SHEET_MARGIN;
2755
+ const b = SHEET_LABEL_BAND;
2756
+ const scale2 = Math.min(
2757
+ 1,
2758
+ (SHEET_MAX_SIDE - 2 * m) / (3 * dw),
2759
+ (SHEET_MAX_SIDE - 2 * m - 3 * b) / (3 * dh)
2760
+ );
2761
+ const frames = sheetFrames(thetas);
2762
+ const { width: W, height: H } = model.canvas;
2763
+ const yModel = eyeRowModelPx(model);
2764
+ let row = Math.round(dh / 2);
2765
+ let at = "middle";
2766
+ if (yModel !== void 0) {
2767
+ const y0 = bustPadY(W, H);
2768
+ const s = BUST_SIZE / W;
2769
+ const eyeRow = Math.round(
2770
+ crop ? (y0 + yModel * s - crop.sy) * crop.dh / crop.sh : y0 + yModel * s
2771
+ );
2772
+ if (eyeRow >= 1 && eyeRow <= dh - 2) {
2773
+ row = eyeRow;
2774
+ at = "eye row";
2775
+ }
2776
+ }
2777
+ return {
2778
+ parameter: SWEEP_PARAMETER,
2779
+ frameMs: SWEEP_FRAME_MS,
2780
+ warmup: SWEEP_WARMUP_S * SWEEP_CLOCK_HZ,
2781
+ thetas,
2782
+ captureEvery: CAPTURE_EVERY,
2783
+ frames: FRAMES,
2784
+ frame: { width: dw, height: dh },
2785
+ physicsOutputs: physicsOutputIds(model),
2786
+ sheet: {
2787
+ frames,
2788
+ cell: {
2789
+ w: Math.max(1, Math.floor(dw * scale2)),
2790
+ h: Math.max(1, Math.floor(dh * scale2))
2791
+ },
2792
+ margin: m,
2793
+ labelBand: b,
2794
+ labels: frames.map(
2795
+ (k) => sheetLabel(thetas[CAPTURE_EVERY * k], k / SWEEP_FPS)
2796
+ )
2797
+ },
2798
+ kymograph: { row, band: KYMOGRAPH_BAND, at },
2799
+ crop
2800
+ };
2801
+ }
2802
+ function flipbookHtml(manifest) {
2803
+ const json = JSON.stringify(manifest).replace(/</g, "\\u003c");
2804
+ return `<!doctype html>
2805
+ <html lang="en">
2806
+ <head>
2807
+ <meta charset="utf-8">
2808
+ <title>turn sweep</title>
2809
+ <style>
2810
+ body { font: 14px system-ui, sans-serif; margin: 16px; background: #222; color: #eee; }
2811
+ .row { display: flex; gap: 16px; align-items: flex-start; }
2812
+ img { max-width: 48vw; height: auto; background: #444; }
2813
+ #b { display: none; }
2814
+ #controls { margin: 12px 0; display: flex; gap: 12px; align-items: center; }
2815
+ #scrub { flex: 1; max-width: 640px; }
2816
+ </style>
2817
+ </head>
2818
+ <body>
2819
+ <div class="row"><img id="a" alt="A"><img id="b" alt="B"></div>
2820
+ <div id="controls">
2821
+ <button id="play" type="button">pause</button>
2822
+ <input id="scrub" type="range" min="0" value="0" step="1">
2823
+ <span id="readout"></span>
2824
+ </div>
2825
+ <p>Add <code>?b=&lt;relative dir&gt;</code> to the address to show another sweep beside this one; it must be a sweep of the same preset, since frames are matched by file name.</p>
2826
+ <script id="manifest" type="application/json">${json}</script>
2827
+ <script>
2828
+ (function () {
2829
+ var m = JSON.parse(document.getElementById("manifest").textContent);
2830
+ var b = new URLSearchParams(location.search).get("b");
2831
+ var a = document.getElementById("a");
2832
+ var bi = document.getElementById("b");
2833
+ var scrub = document.getElementById("scrub");
2834
+ var readout = document.getElementById("readout");
2835
+ var play = document.getElementById("play");
2836
+ var n = m.frames.length;
2837
+ var i = 0;
2838
+ var playing = true;
2839
+ scrub.max = String(n - 1);
2840
+ if (b) { bi.style.display = "block"; }
2841
+ function show(k) {
2842
+ i = k;
2843
+ var f = m.frames[k];
2844
+ a.src = f.file;
2845
+ if (b) { bi.src = b.replace(/\\/$/, "") + "/" + f.file; }
2846
+ scrub.value = String(k);
2847
+ readout.textContent = "frame " + k + " \\u03b8 " + f.theta.toFixed(1) + "\\u00b0 t " + f.t.toFixed(2) + " s";
2848
+ }
2849
+ play.addEventListener("click", function () {
2850
+ playing = !playing;
2851
+ play.textContent = playing ? "pause" : "play";
2852
+ });
2853
+ scrub.addEventListener("input", function () {
2854
+ playing = false;
2855
+ play.textContent = "play";
2856
+ show(Number(scrub.value));
2857
+ });
2858
+ setInterval(function () { if (playing) { show((i + 1) % n); } }, 1000 / m.fps);
2859
+ show(0);
2860
+ })();
2861
+ </script>
2862
+ </body>
2863
+ </html>
2864
+ `;
2865
+ }
2866
+ function prepareSweepDir(outDir, name) {
2867
+ const dir = path4.join(outDir, name);
2868
+ try {
2869
+ fs3.mkdirSync(dir);
2870
+ } catch (e) {
2871
+ if (e.code !== "EEXIST") {
2872
+ throw new AutoRigInputError(`sweep dir: ${e.message}`);
2873
+ }
2874
+ }
2875
+ const stat = fs3.lstatSync(dir);
2876
+ if (stat.isSymbolicLink()) {
2877
+ throw new AutoRigInputError(`sweep.name names ${dir}, a symbolic link`);
2878
+ }
2879
+ if (!stat.isDirectory()) {
2880
+ throw new AutoRigInputError(`sweep.name names ${dir}, not a directory`);
2881
+ }
2882
+ const real = confineToWorkingDirectory(process.cwd(), dir, "sweep dir", name);
2883
+ return real;
2884
+ }
2885
+
2427
2886
  // src/tools.ts
2428
2887
  import { readFileSync as readFileSync2 } from "fs";
2429
- import path4 from "path";
2888
+ import path5 from "path";
2430
2889
  import {
2431
2890
  parseIkiModel,
2432
2891
  loadIkiModel as loadIkiModel2,
@@ -2443,6 +2902,9 @@ import {
2443
2902
  partIdsOfRole,
2444
2903
  LayerGeometryError,
2445
2904
  PatchError,
2905
+ RigPlanError,
2906
+ RIG_PLAN_FIELDS,
2907
+ styleRemovedMessage,
2446
2908
  TurnTargetError
2447
2909
  } from "@ikijs/editor";
2448
2910
 
@@ -2544,7 +3006,7 @@ function describeIki(model) {
2544
3006
  const padY = bustPadY(W, H);
2545
3007
  const tenth = (n) => Math.round(n * 10) / 10;
2546
3008
  const parts = m.parts.map((p) => {
2547
- const box = {
3009
+ const box2 = {
2548
3010
  x: W / 2 + p.transform.x - p.width / 2,
2549
3011
  y: H / 2 - p.transform.y - p.height / 2,
2550
3012
  w: p.width,
@@ -2553,12 +3015,12 @@ function describeIki(model) {
2553
3015
  const entry = {
2554
3016
  id: p.id,
2555
3017
  order: p.order,
2556
- box,
3018
+ box: box2,
2557
3019
  bustBox: {
2558
- x: tenth(box.x * bustScale),
2559
- y: tenth(padY + box.y * bustScale),
2560
- w: tenth(box.w * bustScale),
2561
- h: tenth(box.h * bustScale)
3020
+ x: tenth(box2.x * bustScale),
3021
+ y: tenth(padY + box2.y * bustScale),
3022
+ w: tenth(box2.w * bustScale),
3023
+ h: tenth(box2.h * bustScale)
2562
3024
  }
2563
3025
  };
2564
3026
  if (p.deformer !== void 0) entry.deformer = p.deformer;
@@ -2759,6 +3221,22 @@ var STANDARD_PARAMETER_INFO = [
2759
3221
  function listStandardParameters() {
2760
3222
  return STANDARD_PARAMETER_INFO.map((p) => ({ ...p }));
2761
3223
  }
3224
+ function describeRigPlan() {
3225
+ return { fields: [...RIG_PLAN_FIELDS] };
3226
+ }
3227
+ function formatRigPlanReport(r) {
3228
+ const fields = RIG_PLAN_FIELDS.map((f) => {
3229
+ const value = `${f.path}=${r.effective[f.path]}`;
3230
+ const clamp2 = r.clamped.find((c) => c.field === f.path);
3231
+ if (clamp2 !== void 0) {
3232
+ const asked = r.requested[f.group]?.[f.key] ?? f.default;
3233
+ return `${value} (requested ${asked}, clamped at ${clamp2.bound})`;
3234
+ }
3235
+ const cue = r.overriddenBy[f.path];
3236
+ return cue === void 0 ? value : `${value} (fitted by ${cue})`;
3237
+ });
3238
+ return `RIGPLAN: ${fields.join(" ")}`;
3239
+ }
2762
3240
  function expectInput(label, fn) {
2763
3241
  try {
2764
3242
  return fn();
@@ -2807,6 +3285,9 @@ async function autoRigFromLayers(input) {
2807
3285
  `quantizeColors must be an integer in 2..256, got ${String(quantizeColors)}`
2808
3286
  );
2809
3287
  }
3288
+ if (input.style !== void 0) {
3289
+ throw new AutoRigInputError(styleRemovedMessage("style"));
3290
+ }
2810
3291
  const turnTargets = input.turnTargets;
2811
3292
  if (turnTargets !== void 0) {
2812
3293
  if (typeof turnTargets !== "object" || turnTargets === null || Array.isArray(turnTargets)) {
@@ -2820,7 +3301,7 @@ async function autoRigFromLayers(input) {
2820
3301
  }
2821
3302
  const resolvedLayers = layers.map((layer) => {
2822
3303
  const resolved = resolveInputPath(layer.path);
2823
- return { resolved, fileName: layer.fileName ?? path4.basename(resolved) };
3304
+ return { resolved, fileName: layer.fileName ?? path5.basename(resolved) };
2824
3305
  });
2825
3306
  const rolePairs = expectInput(
2826
3307
  "role parsing",
@@ -2882,6 +3363,7 @@ async function autoRigFromLayers(input) {
2882
3363
  )?.denseCore;
2883
3364
  let turn;
2884
3365
  let patches;
3366
+ let rigPlan;
2885
3367
  let model;
2886
3368
  try {
2887
3369
  model = generateIkiFromLayerSet(
@@ -2895,7 +3377,10 @@ async function autoRigFromLayers(input) {
2895
3377
  onTurnSolved: (report) => {
2896
3378
  turn = report;
2897
3379
  },
2898
- ...input.style === void 0 ? {} : { style: input.style },
3380
+ ...input.rigPlan === void 0 ? {} : { rigPlan: input.rigPlan },
3381
+ onRigPlanResolved: (report) => {
3382
+ rigPlan = report;
3383
+ },
2899
3384
  ...input.patches === void 0 ? {} : {
2900
3385
  patches: input.patches,
2901
3386
  onPatchesApplied: (reports) => {
@@ -2907,7 +3392,7 @@ async function autoRigFromLayers(input) {
2907
3392
  }
2908
3393
  );
2909
3394
  } catch (e) {
2910
- if (!(e instanceof TurnTargetError || e instanceof LayerGeometryError || e instanceof PatchError)) {
3395
+ if (!(e instanceof TurnTargetError || e instanceof LayerGeometryError || e instanceof PatchError || e instanceof RigPlanError)) {
2911
3396
  throw e;
2912
3397
  }
2913
3398
  throw new AutoRigInputError(e.message);
@@ -2970,7 +3455,8 @@ async function autoRigFromLayers(input) {
2970
3455
  ...turn === void 0 ? {} : { turn },
2971
3456
  folds,
2972
3457
  physics,
2973
- ...patches === void 0 ? {} : { patches }
3458
+ ...patches === void 0 ? {} : { patches },
3459
+ rigPlan
2974
3460
  };
2975
3461
  } catch (err) {
2976
3462
  if (err instanceof AutoRigInputError)
@@ -2980,7 +3466,7 @@ async function autoRigFromLayers(input) {
2980
3466
  }
2981
3467
 
2982
3468
  // src/measure-turn.ts
2983
- import path5 from "path";
3469
+ import path6 from "path";
2984
3470
  import {
2985
3471
  ALPHA_OPAQUE,
2986
3472
  HEAD_BAND,
@@ -3258,14 +3744,14 @@ function farNearWidths(m, turnSign) {
3258
3744
  return turnSign < 0 ? { far: m.irisL.w, near: m.irisR.w } : { far: m.irisR.w, near: m.irisL.w };
3259
3745
  }
3260
3746
  function overlaySvg(m) {
3261
- const box = (b, stroke) => `<rect x="${b.x0}" y="${b.y0}" width="${b.w}" height="${b.h}" fill="none" stroke="${stroke}" stroke-width="3"/>`;
3747
+ const box2 = (b, stroke) => `<rect x="${b.x0}" y="${b.y0}" width="${b.w}" height="${b.h}" fill="none" stroke="${stroke}" stroke-width="3"/>`;
3262
3748
  const tick = (x, half, stroke) => `<line x1="${x}" y1="${m.eyeRow - half}" x2="${x}" y2="${m.eyeRow + half}" stroke="${stroke}" stroke-width="3"/>`;
3263
- return `<svg width="${m.width}" height="${m.height}">` + box(m.irisL, "#ff0000") + box(m.irisR, "#00c000") + tick(m.head.left, 40, "#0000ff") + tick(m.head.right, 40, "#0000ff") + tick(m.head.cx, 60, "#ff8800") + tick(m.pairCx, 60, "#ff00ff") + "</svg>";
3749
+ return `<svg width="${m.width}" height="${m.height}">` + box2(m.irisL, "#ff0000") + box2(m.irisR, "#00c000") + tick(m.head.left, 40, "#0000ff") + tick(m.head.right, 40, "#0000ff") + tick(m.head.cx, 60, "#ff8800") + tick(m.pairCx, 60, "#ff00ff") + "</svg>";
3264
3750
  }
3265
3751
  async function writeOverlay(debugDir, label, m) {
3266
- const outPath = path5.join(
3752
+ const outPath = path6.join(
3267
3753
  debugDir,
3268
- `${label}-${path5.basename(m.file, ".png")}.debug.png`
3754
+ `${label}-${path6.basename(m.file, ".png")}.debug.png`
3269
3755
  );
3270
3756
  writeFileAtomic(outPath, await encodeOverlayPng(m.file, overlaySvg(m)));
3271
3757
  return outPath;
@@ -3342,11 +3828,11 @@ function formatTurnReport(result) {
3342
3828
  }
3343
3829
 
3344
3830
  // src/measure.ts
3345
- import fs3 from "fs";
3346
- import path8 from "path";
3831
+ import fs4 from "fs";
3832
+ import path9 from "path";
3347
3833
 
3348
3834
  // src/measure-arms.ts
3349
- import path6 from "path";
3835
+ import path7 from "path";
3350
3836
  import {
3351
3837
  LayerGeometryError as LayerGeometryError2,
3352
3838
  armGeometry,
@@ -3357,7 +3843,7 @@ var CAP_OVERLAP = 0.5;
3357
3843
  var px = (v) => `${Number(v.toFixed(1))}`;
3358
3844
  async function measured(measurer, absDir, role) {
3359
3845
  const fileName = `${role}.png`;
3360
- const { rgba } = await decodePng(path6.join(absDir, fileName));
3846
+ const { rgba } = await decodePng(path7.join(absDir, fileName));
3361
3847
  return measurer.add({ role, fileName, rgba });
3362
3848
  }
3363
3849
  async function armWarnings(absDir, layers) {
@@ -3512,7 +3998,7 @@ function jointWarnings(pose, arm, stats, a, armLayer, b) {
3512
3998
  }
3513
3999
 
3514
4000
  // src/measure-lips.ts
3515
- import path7 from "path";
4001
+ import path8 from "path";
3516
4002
  import {
3517
4003
  ALPHA_OPAQUE as ALPHA_OPAQUE4,
3518
4004
  LIP_INSIDE_ROLES,
@@ -3629,7 +4115,7 @@ function components2(mask, W, H) {
3629
4115
  for (let start = 0; start < n; start++) {
3630
4116
  if (!mask[start] || label[start] >= 0) continue;
3631
4117
  const id = sizes.length;
3632
- const box = { x0: W, y0: H, x1: -1, y1: -1 };
4118
+ const box2 = { x0: W, y0: H, x1: -1, y1: -1 };
3633
4119
  let size = 0;
3634
4120
  let depth = 0;
3635
4121
  label[start] = id;
@@ -3639,10 +4125,10 @@ function components2(mask, W, H) {
3639
4125
  size++;
3640
4126
  const px2 = p % W;
3641
4127
  const py = (p - px2) / W;
3642
- box.x0 = Math.min(box.x0, px2);
3643
- box.x1 = Math.max(box.x1, px2);
3644
- box.y0 = Math.min(box.y0, py);
3645
- box.y1 = Math.max(box.y1, py);
4128
+ box2.x0 = Math.min(box2.x0, px2);
4129
+ box2.x1 = Math.max(box2.x1, px2);
4130
+ box2.y0 = Math.min(box2.y0, py);
4131
+ box2.y1 = Math.max(box2.y1, py);
3646
4132
  for (let y = Math.max(0, py - 1); y <= Math.min(H - 1, py + 1); y++) {
3647
4133
  for (let x = Math.max(0, px2 - 1); x <= Math.min(W - 1, px2 + 1); x++) {
3648
4134
  if (x !== px2 && y !== py) continue;
@@ -3655,7 +4141,7 @@ function components2(mask, W, H) {
3655
4141
  }
3656
4142
  }
3657
4143
  sizes.push(size);
3658
- boxes.push(box);
4144
+ boxes.push(box2);
3659
4145
  }
3660
4146
  return { label, sizes, boxes };
3661
4147
  }
@@ -3892,14 +4378,14 @@ async function prepInterior(rgba, W, H) {
3892
4378
  for (let p = 0; p < cw * ch; p++) {
3893
4379
  if (label[p] >= 0 && rim[label[p]]) crop[p * 4 + 3] = 0;
3894
4380
  }
3895
- const box = drawingBox(crop, cw, ch);
3896
- if (box === null) throw empty;
4381
+ const box2 = drawingBox(crop, cw, ch);
4382
+ if (box2 === null) throw empty;
3897
4383
  const sum = [0, 0, 0];
3898
4384
  const all = [0, 0, 0];
3899
4385
  let dark = 0;
3900
4386
  let count = 0;
3901
- for (let y = box.y; y < box.y + box.h; y++) {
3902
- for (let x = box.x; x < box.x + box.w; x++) {
4387
+ for (let y = box2.y; y < box2.y + box2.h; y++) {
4388
+ for (let x = box2.x; x < box2.x + box2.w; x++) {
3903
4389
  const i = (y * cw + x) * 4;
3904
4390
  if (crop[i + 3] < ALPHA_OPAQUE3) continue;
3905
4391
  count++;
@@ -3913,7 +4399,7 @@ async function prepInterior(rgba, W, H) {
3913
4399
  if (count === 0) throw empty;
3914
4400
  const [from, over] = dark > 0 ? [sum, dark] : [all, count];
3915
4401
  const cavity = from.map((v) => Math.round(v / over));
3916
- return { png: await cropToBuffer(crop, cw, ch, box), cavity };
4402
+ return { png: await cropToBuffer(crop, cw, ch, box2), cavity };
3917
4403
  }
3918
4404
  var rawOf = async (png) => sharp2(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
3919
4405
  var encode = (rgba, w, h) => sharp2(rgba, { raw: { width: w, height: h, channels: 4 } }).png().toBuffer();
@@ -3956,8 +4442,8 @@ function enclosedHole(frame, w, h) {
3956
4442
  `${KEYED_SRC}: the outline is not closed round the opening (the key reached the outside, or the line is broken or too thin at this size) \u2014 regenerate with ONE closed, bolder outline`
3957
4443
  );
3958
4444
  }
3959
- const box = boxes[main];
3960
- const holeW = box.x1 - box.x0 + 1;
4445
+ const box2 = boxes[main];
4446
+ const holeW = box2.x1 - box2.x0 + 1;
3961
4447
  if (holeW < MIN_OPENING_WIDTH * w) {
3962
4448
  throw new AutoRigInputError(
3963
4449
  `${KEYED_SRC}: the opening is only ${holeW} px wide of the mouth's ${w} \u2014 too small to fold; regenerate with the mouth open wider, or, if its outline is broken (only a small pocket of the opening was enclosed), with ONE closed, bolder outline`
@@ -3971,7 +4457,7 @@ function enclosedHole(frame, w, h) {
3971
4457
  `${KEYED_SRC}: the opening is not one connected region (${others.length + 1} holes: teeth or tongue drawn into the green?) \u2014 regenerate with nothing drawn inside the green`
3972
4458
  );
3973
4459
  }
3974
- return { label, main, box };
4460
+ return { label, main, box: box2 };
3975
4461
  }
3976
4462
  function measureLips(layers, w, h) {
3977
4463
  const measurer = createLayerSetMeasurer4({ width: w, height: h });
@@ -4239,15 +4725,15 @@ async function lipWarnings(absDir, layers) {
4239
4725
  return { warnings };
4240
4726
  }
4241
4727
  }
4242
- const box = (m) => ({
4728
+ const box2 = (m) => ({
4243
4729
  x0: m.bboxCx - m.w / 2,
4244
4730
  x1: m.bboxCx + m.w / 2,
4245
4731
  y0: m.bboxCy - m.h / 2,
4246
4732
  y1: m.bboxCy + m.h / 2
4247
4733
  });
4248
- const cavity = box(inner);
4734
+ const cavity = box2(inner);
4249
4735
  for (const role of inside) {
4250
- const b = box(layers[role]);
4736
+ const b = box2(layers[role]);
4251
4737
  if (b.x0 < cavity.x0 || b.x1 > cavity.x1 || b.y0 < cavity.y0 || b.y1 > cavity.y1) {
4252
4738
  warnings.push(
4253
4739
  `${role}: its box leaves mouth_inner's \u2014 the cavity clips it away there. Recompose from mouth_keyed.png + mouth_interior.png (free).`
@@ -4262,7 +4748,7 @@ async function lipWarnings(absDir, layers) {
4262
4748
  const green = [];
4263
4749
  for (const role of LIP_ROLES) {
4264
4750
  const fileName = `${role}.png`;
4265
- const { rgba } = await decodePng(path7.join(absDir, fileName));
4751
+ const { rgba } = await decodePng(path8.join(absDir, fileName));
4266
4752
  set.set(role, measurer.add({ role, fileName, rgba }));
4267
4753
  for (let i = 0; i < rgba.length; i += 4) {
4268
4754
  if (rgba[i + 3] >= ALPHA_OPAQUE4 && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > GREEN_EXCESS) {
@@ -4481,7 +4967,7 @@ async function lashOffSclera(eyePath, lashPath) {
4481
4967
  return { opaque, off };
4482
4968
  }
4483
4969
  async function measureDir(absDir, noseSpeck) {
4484
- const files = fs3.readdirSync(absDir).filter((f) => f.endsWith(".png") && !f.startsWith("preview")).sort();
4970
+ const files = fs4.readdirSync(absDir).filter((f) => f.endsWith(".png") && !f.startsWith("preview")).sort();
4485
4971
  if (files.length === 0) {
4486
4972
  throw new AutoRigInputError(`no role layers in ${absDir}`);
4487
4973
  }
@@ -4493,8 +4979,8 @@ async function measureDir(absDir, noseSpeck) {
4493
4979
  const layers = {};
4494
4980
  const empty = [];
4495
4981
  for (const f of files) {
4496
- const role = path8.basename(f, ".png");
4497
- const m = await layerStats(path8.join(absDir, f));
4982
+ const role = path9.basename(f, ".png");
4983
+ const m = await layerStats(path9.join(absDir, f));
4498
4984
  if (!m) {
4499
4985
  empty.push(role);
4500
4986
  continue;
@@ -4572,8 +5058,8 @@ async function measureDir(absDir, noseSpeck) {
4572
5058
  }
4573
5059
  if (lash) {
4574
5060
  const { opaque, off } = await lashOffSclera(
4575
- path8.join(absDir, `eye_${side}.png`),
4576
- path8.join(absDir, `lash_${side}.png`)
5061
+ path9.join(absDir, `eye_${side}.png`),
5062
+ path9.join(absDir, `lash_${side}.png`)
4577
5063
  );
4578
5064
  const dTop = lash.marginTop - eye.marginTop;
4579
5065
  const faults = [
@@ -4599,7 +5085,7 @@ async function measureDir(absDir, noseSpeck) {
4599
5085
  if (noseSpeck !== void 0) {
4600
5086
  warnings.push(noseSpeckWarning(noseSpeck, "compose"));
4601
5087
  } else if (layers.nose !== void 0) {
4602
- const nose = await decodePng(path8.join(absDir, "nose.png"));
5088
+ const nose = await decodePng(path9.join(absDir, "nose.png"));
4603
5089
  const core = denseCoreOf(nose.rgba, nose.width, nose.height);
4604
5090
  if (core !== null) {
4605
5091
  const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
@@ -4673,8 +5159,8 @@ function formatMeasureReport(result) {
4673
5159
  }
4674
5160
 
4675
5161
  // src/compose.ts
4676
- import fs4 from "fs";
4677
- import path9 from "path";
5162
+ import fs5 from "fs";
5163
+ import path10 from "path";
4678
5164
  import sharp4 from "sharp";
4679
5165
  import {
4680
5166
  ALPHA_OPAQUE as ALPHA_OPAQUE5,
@@ -5049,8 +5535,8 @@ async function trimmedPart(role, cfg, partsDir, inMemory, flipSource) {
5049
5535
  if (inMemory !== void 0) {
5050
5536
  img = sharp4(inMemory);
5051
5537
  } else {
5052
- const srcPath = path9.join(partsDir, cfg.src);
5053
- if (!fs4.existsSync(srcPath)) {
5538
+ const srcPath = path10.join(partsDir, cfg.src);
5539
+ if (!fs5.existsSync(srcPath)) {
5054
5540
  if (cfg.optional) return null;
5055
5541
  throw new AutoRigInputError(
5056
5542
  `missing part source for role "${role}": ${srcPath}` + (role === "mouth" ? " \u2014 draw mouth.png (with mouth_open.png), or the lip set's mouth_keyed.png + mouth_interior.png" : "")
@@ -5067,8 +5553,8 @@ async function trimmedPart(role, cfg, partsDir, inMemory, flipSource) {
5067
5553
  img = sharp4(kept.data, {
5068
5554
  raw: { width: keptW, height: keptH, channels: 4 }
5069
5555
  });
5070
- const box = boxWithoutStraySpecks(kept.data, keptW, keptH);
5071
- if (box !== null) img = img.extract(box);
5556
+ const box2 = boxWithoutStraySpecks(kept.data, keptW, keptH);
5557
+ if (box2 !== null) img = img.extract(box2);
5072
5558
  }
5073
5559
  if ((cfg.mirror ?? false) !== flipSource) img = img.flop();
5074
5560
  const trimmed = await img.png().toBuffer({ resolveWithObject: true });
@@ -5115,18 +5601,18 @@ function placement2(role, cfg, w, h, canvas) {
5115
5601
  assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top, canvas);
5116
5602
  return { left, top };
5117
5603
  }
5118
- function nosePlacement(layout, mouthKey, box, w, h, canvas) {
5604
+ function nosePlacement(layout, mouthKey, box2, w, h, canvas) {
5119
5605
  const { cx, cy } = layout.nose;
5120
- const left = Math.round(cx - (box.x + box.w / 2));
5606
+ const left = Math.round(cx - (box2.x + box2.w / 2));
5121
5607
  let top;
5122
5608
  if (cy !== void 0) {
5123
- top = Math.round(cy - (box.y + box.h / 2));
5609
+ top = Math.round(cy - (box2.y + box2.h / 2));
5124
5610
  } else {
5125
5611
  const eyeRow = (layout.eye_L.cy + layout.eye_R.cy) / 2;
5126
5612
  const tipRow = Math.round(
5127
5613
  eyeRow + NOSE_TIP_AT * (layout[mouthKey].cy - eyeRow)
5128
5614
  );
5129
- top = tipRow - (box.y + box.h - 1);
5615
+ top = tipRow - (box2.y + box2.h - 1);
5130
5616
  }
5131
5617
  assertOnCanvas(
5132
5618
  cy !== void 0 ? "layout.nose.cx/cy" : `layout.nose.cx/cy (cy unset: its tip row comes from layout.eye_L/eye_R/${mouthKey}.cy)`,
@@ -5234,8 +5720,8 @@ function detachedAboveWhite(rgba, W, H) {
5234
5720
  return detached;
5235
5721
  }
5236
5722
  async function prepEyeSplit(partsDir) {
5237
- const srcPath = path9.join(partsDir, EYEWHITE_SRC);
5238
- if (!fs4.existsSync(srcPath)) {
5723
+ const srcPath = path10.join(partsDir, EYEWHITE_SRC);
5724
+ if (!fs5.existsSync(srcPath)) {
5239
5725
  throw new AutoRigInputError(`missing eyewhite source: ${srcPath}`);
5240
5726
  }
5241
5727
  const { width: W, height: H, rgba: data } = await decodePng(srcPath);
@@ -5322,7 +5808,7 @@ function hasTransparency(rgba) {
5322
5808
  return false;
5323
5809
  }
5324
5810
  async function prepLipSources(partsDir, mirrored) {
5325
- const has = (name) => fs4.existsSync(path9.join(partsDir, name));
5811
+ const has = (name) => fs5.existsSync(path10.join(partsDir, name));
5326
5812
  const keyed = has(KEYED_SRC);
5327
5813
  const interior = has(INTERIOR_SRC);
5328
5814
  if (keyed && !interior) {
@@ -5342,13 +5828,13 @@ async function prepLipSources(partsDir, mirrored) {
5342
5828
  `${KEYED_SRC}/${INTERIOR_SRC} cannot be composed beside mouth.png/mouth_open.png (the lip set replaces the mouth drawings, and auto_rig_from_layers refuses the mix) \u2014 remove ${legacy.join(" and ")}`
5343
5829
  );
5344
5830
  }
5345
- const k = await decodePng(path9.join(partsDir, KEYED_SRC));
5831
+ const k = await decodePng(path10.join(partsDir, KEYED_SRC));
5346
5832
  const keyedRgba = keyGreen(
5347
5833
  hasTransparency(k.rgba) ? k.rgba : keyWhiteToAlpha(k.rgba),
5348
5834
  k.width,
5349
5835
  k.height
5350
5836
  );
5351
- const i = await decodePng(path9.join(partsDir, INTERIOR_SRC));
5837
+ const i = await decodePng(path10.join(partsDir, INTERIOR_SRC));
5352
5838
  const prepared = await prepInterior(
5353
5839
  hasTransparency(i.rgba) ? i.rgba : keyBorderWhite(i.rgba, i.width, i.height),
5354
5840
  i.width,
@@ -5365,7 +5851,7 @@ async function composeLayersFromParts(input) {
5365
5851
  try {
5366
5852
  const outDir = resolveOutputDir(input.outDir);
5367
5853
  const partsDir = resolveInputDir(input.partsDir);
5368
- if (fs4.realpathSync(partsDir) === outDir) {
5854
+ if (fs5.realpathSync(partsDir) === outDir) {
5369
5855
  throw new AutoRigInputError(
5370
5856
  `partsDir and outDir resolve to the same directory (${outDir}): composing would overwrite the source parts`
5371
5857
  );
@@ -5444,7 +5930,7 @@ async function composeLayersFromParts(input) {
5444
5930
  }
5445
5931
  if (key === "arm_L" || key === "arm_R") {
5446
5932
  const arm = layout[key];
5447
- if (!fs4.existsSync(path9.join(partsDir, arm.src))) continue;
5933
+ if (!fs5.existsSync(path10.join(partsDir, arm.src))) continue;
5448
5934
  const body = placed.find((p) => p.role === "body");
5449
5935
  if (body === void 0) {
5450
5936
  throw new AutoRigInputError(
@@ -5487,7 +5973,7 @@ async function composeLayersFromParts(input) {
5487
5973
  }
5488
5974
  if (key === "forearm_pose_L" || key === "forearm_pose_R") {
5489
5975
  const pose = layout[key];
5490
- if (!fs4.existsSync(path9.join(partsDir, pose.src))) continue;
5976
+ if (!fs5.existsSync(path10.join(partsDir, pose.src))) continue;
5491
5977
  const armRole = key === "forearm_pose_L" ? "arm_L" : "arm_R";
5492
5978
  const arm = placed.find((p) => p.role === armRole);
5493
5979
  if (arm?.elbow === void 0 || arm.elbowRun === void 0) {
@@ -5557,11 +6043,11 @@ async function composeLayersFromParts(input) {
5557
6043
  if (key === "nose") {
5558
6044
  noseSpeck = part.nose?.speck;
5559
6045
  const { core, bounds } = await coreAndBoundsOf(part.buf);
5560
- const box = part.nose?.whole ? bounds : core ?? bounds;
6046
+ const box2 = part.nose?.whole ? bounds : core ?? bounds;
5561
6047
  ({ left, top } = nosePlacement(
5562
6048
  layout,
5563
6049
  lips === void 0 ? "mouth" : "mouth_inner",
5564
- box,
6050
+ box2,
5565
6051
  part.w,
5566
6052
  part.h,
5567
6053
  canvas
@@ -5604,15 +6090,15 @@ async function composeLayersFromParts(input) {
5604
6090
  );
5605
6091
  for (const role of ORDER) {
5606
6092
  if (placed.some((p) => p.role === role)) continue;
5607
- fs4.rmSync(path9.join(outDir, `${role}.png`), { force: true });
6093
+ fs5.rmSync(path10.join(outDir, `${role}.png`), { force: true });
5608
6094
  }
5609
6095
  const posed = (role) => role === "forearm_pose_L" || role === "forearm_pose_R";
5610
6096
  if (!placed.some((p) => posed(p.role))) {
5611
- fs4.rmSync(path9.join(outDir, "preview-pose.png"), { force: true });
6097
+ fs5.rmSync(path10.join(outDir, "preview-pose.png"), { force: true });
5612
6098
  }
5613
6099
  const layers = [];
5614
6100
  for (const { role, part, left, top } of placed) {
5615
- const outPath = path9.join(outDir, `${role}.png`);
6101
+ const outPath = path10.join(outDir, `${role}.png`);
5616
6102
  writeFileAtomic(outPath, built.get(role));
5617
6103
  layers.push({
5618
6104
  role,
@@ -5643,7 +6129,7 @@ async function composeLayersFromParts(input) {
5643
6129
  background: { r: 245, g: 245, b: 248, alpha: 1 }
5644
6130
  }
5645
6131
  }).composite(preview).png().toBuffer();
5646
- const previewPath = path9.join(outDir, "preview.png");
6132
+ const previewPath = path10.join(outDir, "preview.png");
5647
6133
  writeFileAtomic(previewPath, previewPng);
5648
6134
  let previewPosePath;
5649
6135
  if (placed.some((p) => posed(p.role))) {
@@ -5672,7 +6158,7 @@ async function composeLayersFromParts(input) {
5672
6158
  background: { r: 245, g: 245, b: 248, alpha: 1 }
5673
6159
  }
5674
6160
  }).composite(pose).png().toBuffer();
5675
- previewPosePath = path9.join(outDir, "preview-pose.png");
6161
+ previewPosePath = path10.join(outDir, "preview-pose.png");
5676
6162
  writeFileAtomic(previewPosePath, posePng);
5677
6163
  }
5678
6164
  return {
@@ -5718,7 +6204,7 @@ function formatPatchReports(reports) {
5718
6204
  });
5719
6205
  }
5720
6206
  function createIkiMcpServer() {
5721
- const server = new McpServer({ name: "iki", version: "0.29.0" });
6207
+ const server = new McpServer({ name: "iki", version: "0.31.0" });
5722
6208
  server.registerTool(
5723
6209
  "validate_iki",
5724
6210
  {
@@ -5790,10 +6276,27 @@ function createIkiMcpServer() {
5790
6276
  };
5791
6277
  }
5792
6278
  );
6279
+ server.registerTool(
6280
+ "describe_rig_plan",
6281
+ {
6282
+ description: "Lists the fields of the `rigPlan` input of auto_rig_from_layers: each one's path, default, range, recommended span, step, unit, the poses it shows at, the report reading that shows it and the `turnTargets` cue that fits it when given. The one source of those numbers.",
6283
+ inputSchema: {}
6284
+ },
6285
+ async () => {
6286
+ const { fields } = describeRigPlan();
6287
+ const text = fields.map(
6288
+ (f) => `${f.path} default ${f.default} range ${f.range[0]}..${f.range[1]} recommended ${f.recommended[0]}..${f.recommended[1]} step ${f.step} ${f.unit} \u2014 ${f.what}; shows at ${f.poses.map((p) => JSON.stringify(p)).join(" ")}; cue ${f.cue ?? "none"}; fitted by ${f.fitBy ?? "none"}${f.provisional ? "; provisional" : ""}`
6289
+ ).join("\n");
6290
+ return {
6291
+ content: [{ type: "text", text }],
6292
+ structuredContent: { fields }
6293
+ };
6294
+ }
6295
+ );
5793
6296
  server.registerTool(
5794
6297
  "auto_rig_from_layers",
5795
6298
  {
5796
- description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R and either mouth or the lip set (mouth_inner + lip_lower + lip_upper, a mouth that folds open instead of crossfading) required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, forearm_pose_L/forearm_pose_R, mouth_tongue/mouth_teeth (only with the lip set: drawn under its lips and clipped to mouth_inner), etc. optional; an arm needs the body, a pose forearm needs its arm, and a partial lip set, one mixed with mouth/mouth_open, or mouth_tongue/mouth_teeth without it is refused) into a renderable .iki written to disk. Pass full-canvas PNG file paths; returns the output path + summary (the model is NOT inlined). Filenames map to roles unless `fileName` is given. The result's `folds` is the written rig's fold report, printed after the path the way render_poses prints it, and report-only: a fold never refuses the rig. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output \u2014 a spring's, or each chain segment's \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. `patches` (see its field) adds displacements to existing keyform stops of the freshly generated rig; each op then prints one line between the path and the fold report \u2014 `PATCH <i> <target> at <Param=v \u2026>: <moved> of <of> points (cols a-b, rows c-d), largest move <maxPx> model px`, with `(vertices)` in place of the columns and rows for a mesh part \u2014 and the result's `patches` carries the same reports (`index`, `target`, `at`, `moved`, `of`, `cols`/`rows` for a grid, `maxPx`), present whenever `patches` was passed, `[]` included. An op the input schema accepts but the rig refuses comes back as `INVALID: patches[i]\u2026` and nothing is written; an op with a missing field or a field of the wrong type is the SDK's input validation error.",
6299
+ description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R and either mouth or the lip set (mouth_inner + lip_lower + lip_upper, a mouth that folds open instead of crossfading) required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, forearm_pose_L/forearm_pose_R, mouth_tongue/mouth_teeth (only with the lip set: drawn under its lips and clipped to mouth_inner), etc. optional; an arm needs the body, a pose forearm needs its arm, and a partial lip set, one mixed with mouth/mouth_open, or mouth_tongue/mouth_teeth without it is refused) into a renderable .iki written to disk. Pass full-canvas PNG file paths; returns the output path + summary (the model is NOT inlined). Filenames map to roles unless `fileName` is given. The result's `folds` is the written rig's fold report, printed after the path the way render_poses prints it, and report-only: a fold never refuses the rig. The `RIGPLAN:` line (the result's `rigPlan`: `effective`, `clamped`, `overriddenBy`) follows the path and precedes the `PATCH` lines. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output \u2014 a spring's, or each chain segment's \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. `patches` (see its field) adds displacements to existing keyform stops of the freshly generated rig; each op then prints one line between the path and the fold report \u2014 `PATCH <i> <target> at <Param=v \u2026>: <moved> of <of> points (cols a-b, rows c-d), largest move <maxPx> model px`, with `(vertices)` in place of the columns and rows for a mesh part \u2014 and the result's `patches` carries the same reports (`index`, `target`, `at`, `moved`, `of`, `cols`/`rows` for a grid, `maxPx`), present whenever `patches` was passed, `[]` included. An op the input schema accepts but the rig refuses comes back as `INVALID: patches[i]\u2026` and nothing is written; an op with a missing field or a field of the wrong type is the SDK's input validation error.",
5797
6300
  inputSchema: {
5798
6301
  layers: z.array(
5799
6302
  z.object({
@@ -5818,15 +6321,24 @@ function createIkiMcpServer() {
5818
6321
  }).passthrough().optional().describe(
5819
6322
  "What the head turn is fitted to, as `measure_turn_reference` reports it off a front/turned reference pair. `eyeShift` (and the optional `noseShift`/`mouthShift`) is how far that feature slides across the head at full turn, as a fraction of the head's half-width \u2014 a MAGNITUDE: the rig turns both ways, so the sign is ignored. `farEyeRatio` is the far/near eye width at full turn over that same ratio at rest, `silhouetteRatio` the head's half-width turned over at rest. The half-width the shifts are fractions of is measured off the layers themselves, so it is not an input. An omitted field leaves that part of the turn at the profile the rig defaults to. A passed `eyeShift` is fitted by the turn's amount and clamped to the room the art leaves the far eye \u2014 the face plate's edge, or the bangs' side strand over the far iris (the result's `turn.clamped` lists every clamped field, `turn.achieved` what the rig reaches, and `turn.strandOverlap` how much of a far iris the bangs still cover). A passed `silhouetteRatio` is clamped too, only on a face drawn without hair and with ear islands, where narrowing the head that far would no longer cover the far ear's slide. Any other passed target this layer set cannot reach comes back as `INVALID: \u2026` naming the field and the attainable range, since it is a measurement rather than a preference. A field not named here is refused the same way."
5820
6323
  ),
5821
- style: z.object({
5822
- turn: z.number().optional(),
5823
- featureLead: z.number().optional(),
5824
- hairFollow: z.number().optional(),
5825
- outlineFollow: z.number().optional(),
5826
- blink: z.number().optional(),
5827
- sway: z.number().optional()
6324
+ style: z.unknown().optional().describe(
6325
+ "Removed in @ikijs/mcp 0.30.0: pass `rigPlan`. Any value here is refused with the field map."
6326
+ ),
6327
+ rigPlan: z.object({
6328
+ turn: z.object({
6329
+ amount: z.number().optional(),
6330
+ featureLead: z.number().optional(),
6331
+ eyeForeshorten: z.number().optional(),
6332
+ noseLead: z.number().optional()
6333
+ }).passthrough().optional(),
6334
+ hair: z.object({
6335
+ follow: z.number().optional(),
6336
+ outlineFollow: z.number().optional(),
6337
+ sway: z.number().optional()
6338
+ }).passthrough().optional(),
6339
+ eyes: z.object({ blink: z.number().optional() }).passthrough().optional()
5828
6340
  }).passthrough().optional().describe(
5829
- "Per-character tuning from the profile the rig defaults to: `turn` scales the whole head turn (plate, features, hair and the eyes' foreshortening; 0..3, 1 = the profile; ignored when `turnTargets.eyeShift` is given), `featureLead` how far the features lead the face plate (0..3, 1 = the profile), `hairFollow` the front hair's share of the face's turn (0..2, profile 1), `outlineFollow` its outer edge's share where the front hair draws the head's outline (0..2, profile 0: the outline holds), `blink` how far the upper lid comes down over the eye's height (0.1..1, profile 0.6), `sway` the hair sway amplitude (0..5, 1 = the profile). A value out of range, or a knob not named here, comes back as `INVALID: \u2026`."
6341
+ "Per-character tuning from the profile the rig defaults to, in three groups: `turn` (`amount`, `featureLead`, `eyeForeshorten`, `noseLead`: the last two turn only, the nod untouched, and fitted by `turnTargets.farEyeRatio` / `turnTargets.noseShift` when those are given, which the `RIGPLAN:` line then reports as overridden), `hair` (`follow`, `outlineFollow`, `sway`) and `eyes` (`blink`). `describe_rig_plan` lists every field's default, range, recommended span, step and poses. A value out of range, or a group or key not named there, comes back as `INVALID: rigPlan.<path> \u2026`; an object left out or `{}` is the profile. The result reports what the rig built with as `rigPlan` and a `RIGPLAN:` line."
5830
6342
  ),
5831
6343
  patches: z.array(
5832
6344
  z.object({
@@ -5844,7 +6356,7 @@ function createIkiMcpServer() {
5844
6356
  why: z.string().optional()
5845
6357
  }).passthrough()
5846
6358
  ).optional().describe(
5847
- "Displacements ADDED to EXISTING keyform stops of the freshly generated rig, each op `{ target, at, region, by, falloff?, why? }`. They are replayed on every rig of these inputs, over whatever the rig now bakes, so they hold through a layout or `style` retune; ops on one stop add up, whatever their order. `target` is a feature grid \u2014 `eyeWarp_L`, `eyeWarp_R`, `browWarp_L`, `browWarp_R`, `noseWarp`, `mouthWarp`, whose `at` names both `ParamAngleX` and `ParamAngleY`, each -30, 0 or 30, never both 0 \u2014 or a mesh part with warps (`face`, `hair_front`, \u2026), whose `at` names exactly one parameter at one of that part's warp keyform values, never the parameter's default nor the stop where the rig shuts the part on purpose (`eye_*` and `lash_lower_*` at their `ParamEye*Open` 0, the lip set and its tongue and teeth at `ParamMouthOpenY` 0), which the fold check exempts, nor a `ParamAngleZ` or `ParamBodyAngleZ` stop (they roll the deformers the part hangs under, so a displacement there is turned off the screen axes). The rest pose is the drawn art and no patch changes it. `bodyWarp` and the matrix deformers are not targets, and a patch adds no stop and changes no parameter range. `region` `{ role, x: [from, to], y: [from, to] }` is a rectangle in fractions of the REST layer box (the opaque crop) of `role`, origin top-left, x right, y DOWN, and may reach past the box: the target's points whose REST position lies inside take the whole of `by`, those within `falloff` of it a smooth share, the rest nothing. `by` `{ dx, dy }` and `falloff` are in face widths (the `face` layer's crop width), on screen axes: +dx toward the viewer's right (a character's `_L` side), +dy DOWN. Between stops the engine blends linearly, so a fix at ParamAngleX -30 shows at half strength at -15 and none at rest. `why` is a note the rig ignores. An op this schema accepts but the rig refuses \u2014 an unknown key, target, role or stop, the rest stop or a shut stop, a region running backwards or catching none of the target's points \u2014 comes back as `INVALID: patches[i]\u2026`, listing the keys, targets, stops or roles there are, or where the target's points lie in the role's box, and nothing is written; a missing field or one of the wrong type is refused by the schema itself, as the SDK's input validation error."
6359
+ "Displacements ADDED to EXISTING keyform stops of the freshly generated rig, each op `{ target, at, region, by, falloff?, why? }`. They are replayed on every rig of these inputs, over whatever the rig now bakes, so they hold through a layout or `rigPlan` retune; ops on one stop add up, whatever their order. `target` is a feature grid \u2014 `eyeWarp_L`, `eyeWarp_R`, `browWarp_L`, `browWarp_R`, `noseWarp`, `mouthWarp`, whose `at` names both `ParamAngleX` and `ParamAngleY`, each -30, 0 or 30, never both 0 \u2014 or a mesh part with warps (`face`, `hair_front`, \u2026), whose `at` names exactly one parameter at one of that part's warp keyform values, never the parameter's default nor the stop where the rig shuts the part on purpose (`eye_*` and `lash_lower_*` at their `ParamEye*Open` 0, the lip set and its tongue and teeth at `ParamMouthOpenY` 0), which the fold check exempts, nor a `ParamAngleZ` or `ParamBodyAngleZ` stop (they roll the deformers the part hangs under, so a displacement there is turned off the screen axes). The rest pose is the drawn art and no patch changes it. `bodyWarp` and the matrix deformers are not targets, and a patch adds no stop and changes no parameter range. `region` `{ role, x: [from, to], y: [from, to] }` is a rectangle in fractions of the REST layer box (the opaque crop) of `role`, origin top-left, x right, y DOWN, and may reach past the box: the target's points whose REST position lies inside take the whole of `by`, those within `falloff` of it a smooth share, the rest nothing. `by` `{ dx, dy }` and `falloff` are in face widths (the `face` layer's crop width), on screen axes: +dx toward the viewer's right (a character's `_L` side), +dy DOWN. Between stops the engine blends linearly, so a fix at ParamAngleX -30 shows at half strength at -15 and none at rest. `why` is a note the rig ignores. An op this schema accepts but the rig refuses \u2014 an unknown key, target, role or stop, the rest stop or a shut stop, a region running backwards or catching none of the target's points \u2014 comes back as `INVALID: patches[i]\u2026`, listing the keys, targets, stops or roles there are, or where the target's points lie in the role's box, and nothing is written; a missing field or one of the wrong type is refused by the schema itself, as the SDK's input validation error."
5848
6360
  )
5849
6361
  }
5850
6362
  },
@@ -5858,6 +6370,7 @@ function createIkiMcpServer() {
5858
6370
  });
5859
6371
  const text = r.ok ? [
5860
6372
  r.path,
6373
+ formatRigPlanReport(r.rigPlan),
5861
6374
  ...formatPatchReports(r.patches ?? []),
5862
6375
  ...formatFoldReport(r.folds, r.canvas),
5863
6376
  ...formatPhysicsReport(r.physics)
@@ -5989,7 +6502,7 @@ function createIkiMcpServer() {
5989
6502
  server.registerTool(
5990
6503
  "render_poses",
5991
6504
  {
5992
- description: "Renders a rigged .iki into the character loop's pose PNGs with the real engine, through the installed Chrome, Edge or Chromium run headless (set CHROME_PATH to pick one). The model decides the set: a bust gets 560x560 shots (rest, turns, nod, blinks, gaze, combined \u2014 ParamAngleX/Y/Z all at 30 \u2014 and stress: ParamAngleX/Y/Z all at -30, ParamMouthOpenY 1, both eyes at 0.5, the brows at opposite extremes (ParamBrowLY -1, ParamBrowRY 1, ParamBrowLAngle 1, ParamBrowRAngle -1) and each body angle the model declares at -10); a mouth adds 720x480 mouth crops; a full body (taller than wide) adds the full-canvas body, arm and elbow poses on a 1400-wide canvas, and a model with a pose forearm adds the full-pose-* shots. Given `poses` (see its field), the standard set is not rendered: only those poses are, each crop clamped to the model's canvas. Writes <pose>.png files into outDir, overwriting same-named files in place; returns the written paths one per line, then the model's fold report (the result's `folds`), checked by the engine over its own pose set plus any `poses`, each of which a `FOLD` line names by its settings, not its PNG name: a `FOLD` line per warp deformer or mesh part that flips (ratio <= 0) or collapses (under 0.1) at some pose \u2014 its cell or triangle, the ratio of its area there to at rest, the pose as its parameter settings (`rest` for none) and where it rests, in model space and in model px from the top-left (the layer PNGs' own pixels, not a render's) \u2014 or `FOLDS: none over N poses`, then a `FOLDS expected:` line naming the closures the rig draws on purpose (an eye or the mouth shut), each by part id, ratio and the parameter that shuts it. Report-only: a fold never fails the render. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output of the model's own rigs \u2014 `poses` do not enter it \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. Fails with INVALID when no browser is found or an input is refused; a browser that cannot start is a tool error.",
6505
+ description: "Renders a rigged .iki into the character loop's pose PNGs with the real engine, through the installed Chrome, Edge or Chromium run headless (set CHROME_PATH to pick one). The model decides the set: a bust gets 560x560 shots (rest, turns, nod, blinks, gaze, combined \u2014 ParamAngleX/Y/Z all at 30 \u2014 and stress: ParamAngleX/Y/Z all at -30, ParamMouthOpenY 1, both eyes at 0.5, the brows at opposite extremes (ParamBrowLY -1, ParamBrowRY 1, ParamBrowLAngle 1, ParamBrowRAngle -1) and each body angle the model declares at -10); a mouth adds 720x480 mouth crops; a full body (taller than wide) adds the full-canvas body, arm and elbow poses on a 1400-wide canvas, and a model with a pose forearm adds the full-pose-* shots. Given `poses` (see its field), the standard set is not rendered: only those poses are, each crop clamped to the model's canvas. Writes <pose>.png files into outDir, overwriting same-named files in place; returns the written paths one per line, then the model's fold report (the result's `folds`), checked by the engine over its own pose set plus any `poses`, each of which a `FOLD` line names by its settings, not its PNG name: a `FOLD` line per warp deformer or mesh part that flips (ratio <= 0) or collapses (under 0.1) at some pose \u2014 its cell or triangle, the ratio of its area there to at rest, the pose as its parameter settings (`rest` for none) and where it rests, in model space and in model px from the top-left (the layer PNGs' own pixels, not a render's) \u2014 or `FOLDS: none over N poses`, then a `FOLDS expected:` line naming the closures the rig draws on purpose (an eye or the mouth shut), each by part id, ratio and the parameter that shuts it. Report-only: a fold never fails the render. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output of the model's own rigs \u2014 `poses` do not enter it \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. Given `sweep`, also renders an eased turn of the head (see its field) and prints its paths and `SWEEP` lines. Fails with INVALID when no browser is found or an input is refused; a browser that cannot start is a tool error.",
5993
6506
  inputSchema: {
5994
6507
  modelPath: z.string().describe(
5995
6508
  "Rigged .iki file path (resolved against cwd; must sit under the working directory)."
@@ -6010,6 +6523,18 @@ function createIkiMcpServer() {
6010
6523
  })
6011
6524
  ).optional().describe(
6012
6525
  "Caller-named poses rendered INSTEAD of the standard set, each `{ name, values, crop? }`, in order. `name` becomes `<outDir>/<name>.png` and the result's pose name: letters, digits, `_`, `.` and `-` only, unique in the list ignoring case. `values` are parameter settings (every other parameter at its default; an id the model lacks is ignored). `crop` `{ x, y, w, h }` is a rectangle in model px from the top-left \u2014 the frame of describe_iki's boxes and of the `FOLD` lines \u2014 clamped to the model's canvas, then drawn 720 px wide at its own aspect; without one a pose is framed as the standard shots (560x560, the middle square on a full body). Each pose is also added to the fold sweep, after the engine's own poses. An empty list, a bad or repeated name, a non-finite value, or a crop that misses the canvas or would draw under 1 or over 8192 px tall comes back as `INVALID: poses\u2026` and nothing is rendered."
6526
+ ),
6527
+ sweep: z.object({
6528
+ name: z.string(),
6529
+ preset: z.literal("turn"),
6530
+ crop: z.object({
6531
+ x: z.number(),
6532
+ y: z.number(),
6533
+ w: z.number(),
6534
+ h: z.number()
6535
+ }).optional()
6536
+ }).optional().describe(
6537
+ "A turn sweep rendered IN ADDITION to the poses, `{ name, preset: \"turn\", crop? }`: an eased `ParamAngleX` turn (0 to -30 to +30 to 0 over 3 s, sinusoidal) at 30 fps on a 60 Hz physics clock, with the hair physics running and the idle off, every other parameter at its default. `crop` is a rectangle in model px as a pose's, fixed for every frame; without one the frames are framed as the standard shots. Written into `<outDir>/<name>/` (created; `name` starts with a letter or digit, then letters, digits, `_`, `.`, `-`): `fNNN.png` (90 frames), `manifest.json` (each frame's time, angle and effective values), `sheet.png` (nine frames of the -30 to +30 leg, labelled with angle and time, at most 2000 px a side), `kymograph.png` (the eye row of every frame stacked over time), `index.html` (a flipbook to open from disk; add `?b=<relative dir of another sweep>` for two side by side). The text then lists the paths and, after the `PHYSICS` lines, a `SWEEP turn` line per landmark (eyes, nose) from the engine's geometry: amplitude in face widths, the kink of x and of the eye width through angle 0, the lead over the local face plate at each end, and the pop \u2014 report-only, like `FOLD` and `PHYSICS`."
6013
6538
  )
6014
6539
  }
6015
6540
  },
@@ -6018,8 +6543,16 @@ function createIkiMcpServer() {
6018
6543
  const r = await renderPoses(args);
6019
6544
  const text = r.ok ? [
6020
6545
  ...r.poses.map((p) => p.path),
6546
+ ...r.sweep ? [
6547
+ r.sweep.dir,
6548
+ r.sweep.sheet,
6549
+ r.sweep.kymograph,
6550
+ r.sweep.flipbook,
6551
+ r.sweep.manifest
6552
+ ] : [],
6021
6553
  ...formatFoldReport(r.folds, r.modelCanvas),
6022
- ...formatPhysicsReport(r.physics)
6554
+ ...formatPhysicsReport(r.physics),
6555
+ ...r.sweep ? formatSweepReport(r.sweep.report) : []
6023
6556
  ].join("\n") : `INVALID: ${r.error}`;
6024
6557
  return { content: [{ type: "text", text }], structuredContent: r };
6025
6558
  } catch (err) {
@@ -6038,11 +6571,15 @@ function createIkiMcpServer() {
6038
6571
  export {
6039
6572
  checkModelFolds,
6040
6573
  formatFoldReport,
6574
+ checkSweep,
6575
+ formatSweepReport,
6041
6576
  renderPoses,
6042
6577
  validateIki,
6043
6578
  describeIki,
6044
6579
  describeIkiAt,
6045
6580
  listStandardParameters,
6581
+ describeRigPlan,
6582
+ formatRigPlanReport,
6046
6583
  autoRigFromLayers,
6047
6584
  measureTurnReference,
6048
6585
  formatTurnReport,
@@ -6052,4 +6589,4 @@ export {
6052
6589
  formatPhysicsReport,
6053
6590
  createIkiMcpServer
6054
6591
  };
6055
- //# sourceMappingURL=chunk-IG2FZKTW.mjs.map
6592
+ //# sourceMappingURL=chunk-RLBRIAVN.mjs.map