@ikijs/mcp 0.30.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,
@@ -2547,7 +3006,7 @@ function describeIki(model) {
2547
3006
  const padY = bustPadY(W, H);
2548
3007
  const tenth = (n) => Math.round(n * 10) / 10;
2549
3008
  const parts = m.parts.map((p) => {
2550
- const box = {
3009
+ const box2 = {
2551
3010
  x: W / 2 + p.transform.x - p.width / 2,
2552
3011
  y: H / 2 - p.transform.y - p.height / 2,
2553
3012
  w: p.width,
@@ -2556,12 +3015,12 @@ function describeIki(model) {
2556
3015
  const entry = {
2557
3016
  id: p.id,
2558
3017
  order: p.order,
2559
- box,
3018
+ box: box2,
2560
3019
  bustBox: {
2561
- x: tenth(box.x * bustScale),
2562
- y: tenth(padY + box.y * bustScale),
2563
- w: tenth(box.w * bustScale),
2564
- 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)
2565
3024
  }
2566
3025
  };
2567
3026
  if (p.deformer !== void 0) entry.deformer = p.deformer;
@@ -2842,7 +3301,7 @@ async function autoRigFromLayers(input) {
2842
3301
  }
2843
3302
  const resolvedLayers = layers.map((layer) => {
2844
3303
  const resolved = resolveInputPath(layer.path);
2845
- return { resolved, fileName: layer.fileName ?? path4.basename(resolved) };
3304
+ return { resolved, fileName: layer.fileName ?? path5.basename(resolved) };
2846
3305
  });
2847
3306
  const rolePairs = expectInput(
2848
3307
  "role parsing",
@@ -3007,7 +3466,7 @@ async function autoRigFromLayers(input) {
3007
3466
  }
3008
3467
 
3009
3468
  // src/measure-turn.ts
3010
- import path5 from "path";
3469
+ import path6 from "path";
3011
3470
  import {
3012
3471
  ALPHA_OPAQUE,
3013
3472
  HEAD_BAND,
@@ -3285,14 +3744,14 @@ function farNearWidths(m, turnSign) {
3285
3744
  return turnSign < 0 ? { far: m.irisL.w, near: m.irisR.w } : { far: m.irisR.w, near: m.irisL.w };
3286
3745
  }
3287
3746
  function overlaySvg(m) {
3288
- 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"/>`;
3289
3748
  const tick = (x, half, stroke) => `<line x1="${x}" y1="${m.eyeRow - half}" x2="${x}" y2="${m.eyeRow + half}" stroke="${stroke}" stroke-width="3"/>`;
3290
- 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>";
3291
3750
  }
3292
3751
  async function writeOverlay(debugDir, label, m) {
3293
- const outPath = path5.join(
3752
+ const outPath = path6.join(
3294
3753
  debugDir,
3295
- `${label}-${path5.basename(m.file, ".png")}.debug.png`
3754
+ `${label}-${path6.basename(m.file, ".png")}.debug.png`
3296
3755
  );
3297
3756
  writeFileAtomic(outPath, await encodeOverlayPng(m.file, overlaySvg(m)));
3298
3757
  return outPath;
@@ -3369,11 +3828,11 @@ function formatTurnReport(result) {
3369
3828
  }
3370
3829
 
3371
3830
  // src/measure.ts
3372
- import fs3 from "fs";
3373
- import path8 from "path";
3831
+ import fs4 from "fs";
3832
+ import path9 from "path";
3374
3833
 
3375
3834
  // src/measure-arms.ts
3376
- import path6 from "path";
3835
+ import path7 from "path";
3377
3836
  import {
3378
3837
  LayerGeometryError as LayerGeometryError2,
3379
3838
  armGeometry,
@@ -3384,7 +3843,7 @@ var CAP_OVERLAP = 0.5;
3384
3843
  var px = (v) => `${Number(v.toFixed(1))}`;
3385
3844
  async function measured(measurer, absDir, role) {
3386
3845
  const fileName = `${role}.png`;
3387
- const { rgba } = await decodePng(path6.join(absDir, fileName));
3846
+ const { rgba } = await decodePng(path7.join(absDir, fileName));
3388
3847
  return measurer.add({ role, fileName, rgba });
3389
3848
  }
3390
3849
  async function armWarnings(absDir, layers) {
@@ -3539,7 +3998,7 @@ function jointWarnings(pose, arm, stats, a, armLayer, b) {
3539
3998
  }
3540
3999
 
3541
4000
  // src/measure-lips.ts
3542
- import path7 from "path";
4001
+ import path8 from "path";
3543
4002
  import {
3544
4003
  ALPHA_OPAQUE as ALPHA_OPAQUE4,
3545
4004
  LIP_INSIDE_ROLES,
@@ -3656,7 +4115,7 @@ function components2(mask, W, H) {
3656
4115
  for (let start = 0; start < n; start++) {
3657
4116
  if (!mask[start] || label[start] >= 0) continue;
3658
4117
  const id = sizes.length;
3659
- const box = { x0: W, y0: H, x1: -1, y1: -1 };
4118
+ const box2 = { x0: W, y0: H, x1: -1, y1: -1 };
3660
4119
  let size = 0;
3661
4120
  let depth = 0;
3662
4121
  label[start] = id;
@@ -3666,10 +4125,10 @@ function components2(mask, W, H) {
3666
4125
  size++;
3667
4126
  const px2 = p % W;
3668
4127
  const py = (p - px2) / W;
3669
- box.x0 = Math.min(box.x0, px2);
3670
- box.x1 = Math.max(box.x1, px2);
3671
- box.y0 = Math.min(box.y0, py);
3672
- 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);
3673
4132
  for (let y = Math.max(0, py - 1); y <= Math.min(H - 1, py + 1); y++) {
3674
4133
  for (let x = Math.max(0, px2 - 1); x <= Math.min(W - 1, px2 + 1); x++) {
3675
4134
  if (x !== px2 && y !== py) continue;
@@ -3682,7 +4141,7 @@ function components2(mask, W, H) {
3682
4141
  }
3683
4142
  }
3684
4143
  sizes.push(size);
3685
- boxes.push(box);
4144
+ boxes.push(box2);
3686
4145
  }
3687
4146
  return { label, sizes, boxes };
3688
4147
  }
@@ -3919,14 +4378,14 @@ async function prepInterior(rgba, W, H) {
3919
4378
  for (let p = 0; p < cw * ch; p++) {
3920
4379
  if (label[p] >= 0 && rim[label[p]]) crop[p * 4 + 3] = 0;
3921
4380
  }
3922
- const box = drawingBox(crop, cw, ch);
3923
- if (box === null) throw empty;
4381
+ const box2 = drawingBox(crop, cw, ch);
4382
+ if (box2 === null) throw empty;
3924
4383
  const sum = [0, 0, 0];
3925
4384
  const all = [0, 0, 0];
3926
4385
  let dark = 0;
3927
4386
  let count = 0;
3928
- for (let y = box.y; y < box.y + box.h; y++) {
3929
- 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++) {
3930
4389
  const i = (y * cw + x) * 4;
3931
4390
  if (crop[i + 3] < ALPHA_OPAQUE3) continue;
3932
4391
  count++;
@@ -3940,7 +4399,7 @@ async function prepInterior(rgba, W, H) {
3940
4399
  if (count === 0) throw empty;
3941
4400
  const [from, over] = dark > 0 ? [sum, dark] : [all, count];
3942
4401
  const cavity = from.map((v) => Math.round(v / over));
3943
- return { png: await cropToBuffer(crop, cw, ch, box), cavity };
4402
+ return { png: await cropToBuffer(crop, cw, ch, box2), cavity };
3944
4403
  }
3945
4404
  var rawOf = async (png) => sharp2(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
3946
4405
  var encode = (rgba, w, h) => sharp2(rgba, { raw: { width: w, height: h, channels: 4 } }).png().toBuffer();
@@ -3983,8 +4442,8 @@ function enclosedHole(frame, w, h) {
3983
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`
3984
4443
  );
3985
4444
  }
3986
- const box = boxes[main];
3987
- const holeW = box.x1 - box.x0 + 1;
4445
+ const box2 = boxes[main];
4446
+ const holeW = box2.x1 - box2.x0 + 1;
3988
4447
  if (holeW < MIN_OPENING_WIDTH * w) {
3989
4448
  throw new AutoRigInputError(
3990
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`
@@ -3998,7 +4457,7 @@ function enclosedHole(frame, w, h) {
3998
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`
3999
4458
  );
4000
4459
  }
4001
- return { label, main, box };
4460
+ return { label, main, box: box2 };
4002
4461
  }
4003
4462
  function measureLips(layers, w, h) {
4004
4463
  const measurer = createLayerSetMeasurer4({ width: w, height: h });
@@ -4266,15 +4725,15 @@ async function lipWarnings(absDir, layers) {
4266
4725
  return { warnings };
4267
4726
  }
4268
4727
  }
4269
- const box = (m) => ({
4728
+ const box2 = (m) => ({
4270
4729
  x0: m.bboxCx - m.w / 2,
4271
4730
  x1: m.bboxCx + m.w / 2,
4272
4731
  y0: m.bboxCy - m.h / 2,
4273
4732
  y1: m.bboxCy + m.h / 2
4274
4733
  });
4275
- const cavity = box(inner);
4734
+ const cavity = box2(inner);
4276
4735
  for (const role of inside) {
4277
- const b = box(layers[role]);
4736
+ const b = box2(layers[role]);
4278
4737
  if (b.x0 < cavity.x0 || b.x1 > cavity.x1 || b.y0 < cavity.y0 || b.y1 > cavity.y1) {
4279
4738
  warnings.push(
4280
4739
  `${role}: its box leaves mouth_inner's \u2014 the cavity clips it away there. Recompose from mouth_keyed.png + mouth_interior.png (free).`
@@ -4289,7 +4748,7 @@ async function lipWarnings(absDir, layers) {
4289
4748
  const green = [];
4290
4749
  for (const role of LIP_ROLES) {
4291
4750
  const fileName = `${role}.png`;
4292
- const { rgba } = await decodePng(path7.join(absDir, fileName));
4751
+ const { rgba } = await decodePng(path8.join(absDir, fileName));
4293
4752
  set.set(role, measurer.add({ role, fileName, rgba }));
4294
4753
  for (let i = 0; i < rgba.length; i += 4) {
4295
4754
  if (rgba[i + 3] >= ALPHA_OPAQUE4 && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > GREEN_EXCESS) {
@@ -4508,7 +4967,7 @@ async function lashOffSclera(eyePath, lashPath) {
4508
4967
  return { opaque, off };
4509
4968
  }
4510
4969
  async function measureDir(absDir, noseSpeck) {
4511
- 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();
4512
4971
  if (files.length === 0) {
4513
4972
  throw new AutoRigInputError(`no role layers in ${absDir}`);
4514
4973
  }
@@ -4520,8 +4979,8 @@ async function measureDir(absDir, noseSpeck) {
4520
4979
  const layers = {};
4521
4980
  const empty = [];
4522
4981
  for (const f of files) {
4523
- const role = path8.basename(f, ".png");
4524
- const m = await layerStats(path8.join(absDir, f));
4982
+ const role = path9.basename(f, ".png");
4983
+ const m = await layerStats(path9.join(absDir, f));
4525
4984
  if (!m) {
4526
4985
  empty.push(role);
4527
4986
  continue;
@@ -4599,8 +5058,8 @@ async function measureDir(absDir, noseSpeck) {
4599
5058
  }
4600
5059
  if (lash) {
4601
5060
  const { opaque, off } = await lashOffSclera(
4602
- path8.join(absDir, `eye_${side}.png`),
4603
- path8.join(absDir, `lash_${side}.png`)
5061
+ path9.join(absDir, `eye_${side}.png`),
5062
+ path9.join(absDir, `lash_${side}.png`)
4604
5063
  );
4605
5064
  const dTop = lash.marginTop - eye.marginTop;
4606
5065
  const faults = [
@@ -4626,7 +5085,7 @@ async function measureDir(absDir, noseSpeck) {
4626
5085
  if (noseSpeck !== void 0) {
4627
5086
  warnings.push(noseSpeckWarning(noseSpeck, "compose"));
4628
5087
  } else if (layers.nose !== void 0) {
4629
- const nose = await decodePng(path8.join(absDir, "nose.png"));
5088
+ const nose = await decodePng(path9.join(absDir, "nose.png"));
4630
5089
  const core = denseCoreOf(nose.rgba, nose.width, nose.height);
4631
5090
  if (core !== null) {
4632
5091
  const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
@@ -4700,8 +5159,8 @@ function formatMeasureReport(result) {
4700
5159
  }
4701
5160
 
4702
5161
  // src/compose.ts
4703
- import fs4 from "fs";
4704
- import path9 from "path";
5162
+ import fs5 from "fs";
5163
+ import path10 from "path";
4705
5164
  import sharp4 from "sharp";
4706
5165
  import {
4707
5166
  ALPHA_OPAQUE as ALPHA_OPAQUE5,
@@ -5076,8 +5535,8 @@ async function trimmedPart(role, cfg, partsDir, inMemory, flipSource) {
5076
5535
  if (inMemory !== void 0) {
5077
5536
  img = sharp4(inMemory);
5078
5537
  } else {
5079
- const srcPath = path9.join(partsDir, cfg.src);
5080
- if (!fs4.existsSync(srcPath)) {
5538
+ const srcPath = path10.join(partsDir, cfg.src);
5539
+ if (!fs5.existsSync(srcPath)) {
5081
5540
  if (cfg.optional) return null;
5082
5541
  throw new AutoRigInputError(
5083
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" : "")
@@ -5094,8 +5553,8 @@ async function trimmedPart(role, cfg, partsDir, inMemory, flipSource) {
5094
5553
  img = sharp4(kept.data, {
5095
5554
  raw: { width: keptW, height: keptH, channels: 4 }
5096
5555
  });
5097
- const box = boxWithoutStraySpecks(kept.data, keptW, keptH);
5098
- if (box !== null) img = img.extract(box);
5556
+ const box2 = boxWithoutStraySpecks(kept.data, keptW, keptH);
5557
+ if (box2 !== null) img = img.extract(box2);
5099
5558
  }
5100
5559
  if ((cfg.mirror ?? false) !== flipSource) img = img.flop();
5101
5560
  const trimmed = await img.png().toBuffer({ resolveWithObject: true });
@@ -5142,18 +5601,18 @@ function placement2(role, cfg, w, h, canvas) {
5142
5601
  assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top, canvas);
5143
5602
  return { left, top };
5144
5603
  }
5145
- function nosePlacement(layout, mouthKey, box, w, h, canvas) {
5604
+ function nosePlacement(layout, mouthKey, box2, w, h, canvas) {
5146
5605
  const { cx, cy } = layout.nose;
5147
- const left = Math.round(cx - (box.x + box.w / 2));
5606
+ const left = Math.round(cx - (box2.x + box2.w / 2));
5148
5607
  let top;
5149
5608
  if (cy !== void 0) {
5150
- top = Math.round(cy - (box.y + box.h / 2));
5609
+ top = Math.round(cy - (box2.y + box2.h / 2));
5151
5610
  } else {
5152
5611
  const eyeRow = (layout.eye_L.cy + layout.eye_R.cy) / 2;
5153
5612
  const tipRow = Math.round(
5154
5613
  eyeRow + NOSE_TIP_AT * (layout[mouthKey].cy - eyeRow)
5155
5614
  );
5156
- top = tipRow - (box.y + box.h - 1);
5615
+ top = tipRow - (box2.y + box2.h - 1);
5157
5616
  }
5158
5617
  assertOnCanvas(
5159
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)`,
@@ -5261,8 +5720,8 @@ function detachedAboveWhite(rgba, W, H) {
5261
5720
  return detached;
5262
5721
  }
5263
5722
  async function prepEyeSplit(partsDir) {
5264
- const srcPath = path9.join(partsDir, EYEWHITE_SRC);
5265
- if (!fs4.existsSync(srcPath)) {
5723
+ const srcPath = path10.join(partsDir, EYEWHITE_SRC);
5724
+ if (!fs5.existsSync(srcPath)) {
5266
5725
  throw new AutoRigInputError(`missing eyewhite source: ${srcPath}`);
5267
5726
  }
5268
5727
  const { width: W, height: H, rgba: data } = await decodePng(srcPath);
@@ -5349,7 +5808,7 @@ function hasTransparency(rgba) {
5349
5808
  return false;
5350
5809
  }
5351
5810
  async function prepLipSources(partsDir, mirrored) {
5352
- const has = (name) => fs4.existsSync(path9.join(partsDir, name));
5811
+ const has = (name) => fs5.existsSync(path10.join(partsDir, name));
5353
5812
  const keyed = has(KEYED_SRC);
5354
5813
  const interior = has(INTERIOR_SRC);
5355
5814
  if (keyed && !interior) {
@@ -5369,13 +5828,13 @@ async function prepLipSources(partsDir, mirrored) {
5369
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 ")}`
5370
5829
  );
5371
5830
  }
5372
- const k = await decodePng(path9.join(partsDir, KEYED_SRC));
5831
+ const k = await decodePng(path10.join(partsDir, KEYED_SRC));
5373
5832
  const keyedRgba = keyGreen(
5374
5833
  hasTransparency(k.rgba) ? k.rgba : keyWhiteToAlpha(k.rgba),
5375
5834
  k.width,
5376
5835
  k.height
5377
5836
  );
5378
- const i = await decodePng(path9.join(partsDir, INTERIOR_SRC));
5837
+ const i = await decodePng(path10.join(partsDir, INTERIOR_SRC));
5379
5838
  const prepared = await prepInterior(
5380
5839
  hasTransparency(i.rgba) ? i.rgba : keyBorderWhite(i.rgba, i.width, i.height),
5381
5840
  i.width,
@@ -5392,7 +5851,7 @@ async function composeLayersFromParts(input) {
5392
5851
  try {
5393
5852
  const outDir = resolveOutputDir(input.outDir);
5394
5853
  const partsDir = resolveInputDir(input.partsDir);
5395
- if (fs4.realpathSync(partsDir) === outDir) {
5854
+ if (fs5.realpathSync(partsDir) === outDir) {
5396
5855
  throw new AutoRigInputError(
5397
5856
  `partsDir and outDir resolve to the same directory (${outDir}): composing would overwrite the source parts`
5398
5857
  );
@@ -5471,7 +5930,7 @@ async function composeLayersFromParts(input) {
5471
5930
  }
5472
5931
  if (key === "arm_L" || key === "arm_R") {
5473
5932
  const arm = layout[key];
5474
- if (!fs4.existsSync(path9.join(partsDir, arm.src))) continue;
5933
+ if (!fs5.existsSync(path10.join(partsDir, arm.src))) continue;
5475
5934
  const body = placed.find((p) => p.role === "body");
5476
5935
  if (body === void 0) {
5477
5936
  throw new AutoRigInputError(
@@ -5514,7 +5973,7 @@ async function composeLayersFromParts(input) {
5514
5973
  }
5515
5974
  if (key === "forearm_pose_L" || key === "forearm_pose_R") {
5516
5975
  const pose = layout[key];
5517
- if (!fs4.existsSync(path9.join(partsDir, pose.src))) continue;
5976
+ if (!fs5.existsSync(path10.join(partsDir, pose.src))) continue;
5518
5977
  const armRole = key === "forearm_pose_L" ? "arm_L" : "arm_R";
5519
5978
  const arm = placed.find((p) => p.role === armRole);
5520
5979
  if (arm?.elbow === void 0 || arm.elbowRun === void 0) {
@@ -5584,11 +6043,11 @@ async function composeLayersFromParts(input) {
5584
6043
  if (key === "nose") {
5585
6044
  noseSpeck = part.nose?.speck;
5586
6045
  const { core, bounds } = await coreAndBoundsOf(part.buf);
5587
- const box = part.nose?.whole ? bounds : core ?? bounds;
6046
+ const box2 = part.nose?.whole ? bounds : core ?? bounds;
5588
6047
  ({ left, top } = nosePlacement(
5589
6048
  layout,
5590
6049
  lips === void 0 ? "mouth" : "mouth_inner",
5591
- box,
6050
+ box2,
5592
6051
  part.w,
5593
6052
  part.h,
5594
6053
  canvas
@@ -5631,15 +6090,15 @@ async function composeLayersFromParts(input) {
5631
6090
  );
5632
6091
  for (const role of ORDER) {
5633
6092
  if (placed.some((p) => p.role === role)) continue;
5634
- fs4.rmSync(path9.join(outDir, `${role}.png`), { force: true });
6093
+ fs5.rmSync(path10.join(outDir, `${role}.png`), { force: true });
5635
6094
  }
5636
6095
  const posed = (role) => role === "forearm_pose_L" || role === "forearm_pose_R";
5637
6096
  if (!placed.some((p) => posed(p.role))) {
5638
- fs4.rmSync(path9.join(outDir, "preview-pose.png"), { force: true });
6097
+ fs5.rmSync(path10.join(outDir, "preview-pose.png"), { force: true });
5639
6098
  }
5640
6099
  const layers = [];
5641
6100
  for (const { role, part, left, top } of placed) {
5642
- const outPath = path9.join(outDir, `${role}.png`);
6101
+ const outPath = path10.join(outDir, `${role}.png`);
5643
6102
  writeFileAtomic(outPath, built.get(role));
5644
6103
  layers.push({
5645
6104
  role,
@@ -5670,7 +6129,7 @@ async function composeLayersFromParts(input) {
5670
6129
  background: { r: 245, g: 245, b: 248, alpha: 1 }
5671
6130
  }
5672
6131
  }).composite(preview).png().toBuffer();
5673
- const previewPath = path9.join(outDir, "preview.png");
6132
+ const previewPath = path10.join(outDir, "preview.png");
5674
6133
  writeFileAtomic(previewPath, previewPng);
5675
6134
  let previewPosePath;
5676
6135
  if (placed.some((p) => posed(p.role))) {
@@ -5699,7 +6158,7 @@ async function composeLayersFromParts(input) {
5699
6158
  background: { r: 245, g: 245, b: 248, alpha: 1 }
5700
6159
  }
5701
6160
  }).composite(pose).png().toBuffer();
5702
- previewPosePath = path9.join(outDir, "preview-pose.png");
6161
+ previewPosePath = path10.join(outDir, "preview-pose.png");
5703
6162
  writeFileAtomic(previewPosePath, posePng);
5704
6163
  }
5705
6164
  return {
@@ -5745,7 +6204,7 @@ function formatPatchReports(reports) {
5745
6204
  });
5746
6205
  }
5747
6206
  function createIkiMcpServer() {
5748
- const server = new McpServer({ name: "iki", version: "0.30.0" });
6207
+ const server = new McpServer({ name: "iki", version: "0.31.0" });
5749
6208
  server.registerTool(
5750
6209
  "validate_iki",
5751
6210
  {
@@ -6043,7 +6502,7 @@ function createIkiMcpServer() {
6043
6502
  server.registerTool(
6044
6503
  "render_poses",
6045
6504
  {
6046
- 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.",
6047
6506
  inputSchema: {
6048
6507
  modelPath: z.string().describe(
6049
6508
  "Rigged .iki file path (resolved against cwd; must sit under the working directory)."
@@ -6064,6 +6523,18 @@ function createIkiMcpServer() {
6064
6523
  })
6065
6524
  ).optional().describe(
6066
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`."
6067
6538
  )
6068
6539
  }
6069
6540
  },
@@ -6072,8 +6543,16 @@ function createIkiMcpServer() {
6072
6543
  const r = await renderPoses(args);
6073
6544
  const text = r.ok ? [
6074
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
+ ] : [],
6075
6553
  ...formatFoldReport(r.folds, r.modelCanvas),
6076
- ...formatPhysicsReport(r.physics)
6554
+ ...formatPhysicsReport(r.physics),
6555
+ ...r.sweep ? formatSweepReport(r.sweep.report) : []
6077
6556
  ].join("\n") : `INVALID: ${r.error}`;
6078
6557
  return { content: [{ type: "text", text }], structuredContent: r };
6079
6558
  } catch (err) {
@@ -6092,6 +6571,8 @@ function createIkiMcpServer() {
6092
6571
  export {
6093
6572
  checkModelFolds,
6094
6573
  formatFoldReport,
6574
+ checkSweep,
6575
+ formatSweepReport,
6095
6576
  renderPoses,
6096
6577
  validateIki,
6097
6578
  describeIki,
@@ -6108,4 +6589,4 @@ export {
6108
6589
  formatPhysicsReport,
6109
6590
  createIkiMcpServer
6110
6591
  };
6111
- //# sourceMappingURL=chunk-5WHM63CL.mjs.map
6592
+ //# sourceMappingURL=chunk-RLBRIAVN.mjs.map