@ikijs/mcp 0.31.0 → 0.32.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.
@@ -1782,6 +1782,83 @@ function pop(v) {
1782
1782
  }
1783
1783
  return most / mean;
1784
1784
  }
1785
+ var NOD_TURNS = [-30, 0, 30];
1786
+ var NOD_PARTS = [
1787
+ "face",
1788
+ "eye_L",
1789
+ "eye_R",
1790
+ "iris_L",
1791
+ "iris_R",
1792
+ "nose",
1793
+ "lip_upper",
1794
+ "mouth"
1795
+ ];
1796
+ var NOD_ENDS = [0, -LADDER_MIN, LADDER_MAX - LADDER_MIN];
1797
+ function checkNod(model) {
1798
+ const face = model.parts.find((p) => p.id === "face");
1799
+ if (!face) return { unavailable: "no face part" };
1800
+ const hasEyes = ["eye_L", "eye_R"].every(
1801
+ (id) => model.parts.some((p) => p.id === id)
1802
+ );
1803
+ if (!hasEyes) return { unavailable: "no eye_L and eye_R parts" };
1804
+ const fw = face.width;
1805
+ const ladders = NOD_TURNS.map(
1806
+ (x) => Array.from(
1807
+ { length: LADDER_MAX - LADDER_MIN + 1 },
1808
+ (_, i) => landParts(
1809
+ model,
1810
+ { ParamAngleX: x, ParamAngleY: LADDER_MIN + i },
1811
+ NOD_PARTS
1812
+ )
1813
+ )
1814
+ );
1815
+ const has = (id) => ladders[0][0].has(id);
1816
+ const boxes = (id) => ladders.map((ladder) => ladder.map((l) => box(l.get(id), fw)));
1817
+ const spread = (v) => Math.max(...v) - Math.min(...v);
1818
+ const ranges = (values) => {
1819
+ const [m30, zero, p30] = NOD_TURNS.map(
1820
+ (_, b) => spread(
1821
+ Array.from(
1822
+ { length: LADDER_MAX - LADDER_MIN + 1 },
1823
+ (_2, i) => values(b, i)
1824
+ )
1825
+ )
1826
+ );
1827
+ return { m30, zero, p30 };
1828
+ };
1829
+ const gap = (l, r) => {
1830
+ const bl = boxes(l);
1831
+ const br = boxes(r);
1832
+ return ranges((b, i) => br[b][i].x - bl[b][i].x);
1833
+ };
1834
+ const nod = [{ id: "eyes", range: gap("eye_L", "eye_R") }];
1835
+ if (has("iris_L") && has("iris_R")) {
1836
+ nod.push({ id: "irises", range: gap("iris_L", "iris_R") });
1837
+ }
1838
+ const mouthId = has("lip_upper") ? "lip_upper" : has("mouth") ? "mouth" : null;
1839
+ if (mouthId) {
1840
+ const bm = boxes(mouthId);
1841
+ nod.push({ id: "mouth", range: ranges((b, i) => bm[b][i].width) });
1842
+ }
1843
+ const corner = ["eye_L", "eye_R", "nose"].filter(has).map((id) => {
1844
+ const b = boxes(id);
1845
+ const at = (t, j) => b[t][NOD_ENDS[j]];
1846
+ const residual = (t, j) => {
1847
+ const r = (axis) => at(t, j)[axis] - at(t, 1)[axis] - at(1, j)[axis] + at(1, 1)[axis];
1848
+ return Math.max(Math.abs(r("x")), Math.abs(r("y")));
1849
+ };
1850
+ return {
1851
+ id,
1852
+ residual: {
1853
+ mm: residual(0, 0),
1854
+ mp: residual(0, 2),
1855
+ pm: residual(2, 0),
1856
+ pp: residual(2, 2)
1857
+ }
1858
+ };
1859
+ });
1860
+ return { unit: "fw", faceWidth: fw, nod, corner };
1861
+ }
1785
1862
  function checkSweep(model) {
1786
1863
  const face = model.parts.find((p) => p.id === "face");
1787
1864
  if (!face) return { preset: "turn", unavailable: "no face part" };
@@ -1851,6 +1928,19 @@ function formatSweepReport(report) {
1851
1928
  `SWEEP turn plate: amplitude ${fw3(report.plateAmplitude)} fw`
1852
1929
  ];
1853
1930
  }
1931
+ function formatNodReport(report) {
1932
+ if ("unavailable" in report) {
1933
+ return [`SWEEP nod: unavailable \u2014 ${report.unavailable}`];
1934
+ }
1935
+ return [
1936
+ ...report.nod.map(
1937
+ ({ id, range: r }) => `SWEEP nod ${id}: ${id === "mouth" ? "width" : "gap"} range X -30 ${fw3(r.m30)} / 0 ${fw3(r.zero)} / +30 ${fw3(r.p30)} fw`
1938
+ ),
1939
+ ...report.corner.map(
1940
+ ({ id, residual: r }) => `SWEEP corner ${id}: residual (-30,-30) ${fw3(r.mm)} / (-30,+30) ${fw3(r.mp)} / (+30,-30) ${fw3(r.pm)} / (+30,+30) ${fw3(r.pp)} fw`
1941
+ )
1942
+ ];
1943
+ }
1854
1944
 
1855
1945
  // src/sweep.ts
1856
1946
  import fs3 from "fs";
@@ -2298,7 +2388,7 @@ var SWEEP_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
2298
2388
  function bustPadY(width, height) {
2299
2389
  return Math.max(0, (BUST_SIZE - BUST_SIZE * height / width) / 2);
2300
2390
  }
2301
- function planRenders(model, requested, sweep) {
2391
+ function planRenders(model, requested, sweep, sweeps) {
2302
2392
  const { width: W, height: H } = model.canvas;
2303
2393
  const fullBody = H > W;
2304
2394
  const canvas = fullBody ? {
@@ -2353,12 +2443,37 @@ function planRenders(model, requested, sweep) {
2353
2443
  dh
2354
2444
  };
2355
2445
  };
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
- );
2446
+ if (sweeps && sweeps.length === 0) {
2447
+ throw new AutoRigInputError("sweeps is empty");
2360
2448
  }
2361
- const sweepCrop = sweep ? sweep.crop ? toRenderCrop(sweep.crop, "sweep.crop") : squareCrop : void 0;
2449
+ const asked = [
2450
+ ...sweep ? [{ label: "sweep", entry: sweep }] : [],
2451
+ ...(sweeps ?? []).map((entry, i) => ({ label: `sweeps[${i}]`, entry }))
2452
+ ];
2453
+ asked.forEach(({ label, entry }, i) => {
2454
+ if (!SWEEP_NAME.test(entry.name)) {
2455
+ throw new AutoRigInputError(
2456
+ `${label}.name must match ${SWEEP_NAME.source} (it names <outDir>/<name>/): ${JSON.stringify(entry.name)}`
2457
+ );
2458
+ }
2459
+ const sameName = asked.findIndex(
2460
+ (a) => a.entry.name.toLowerCase() === entry.name.toLowerCase()
2461
+ );
2462
+ if (sameName < i) {
2463
+ throw new AutoRigInputError(
2464
+ `${label}.name ${JSON.stringify(entry.name)} repeats ${asked[sameName].label}.name ${JSON.stringify(asked[sameName].entry.name)} (ignoring case: one directory on a case-insensitive disk)`
2465
+ );
2466
+ }
2467
+ const samePreset = asked.findIndex((a) => a.entry.preset === entry.preset);
2468
+ if (samePreset < i) {
2469
+ throw new AutoRigInputError(
2470
+ `${label}.preset ${JSON.stringify(entry.preset)} repeats ${asked[samePreset].label}.preset (the same frames twice)`
2471
+ );
2472
+ }
2473
+ });
2474
+ const cropOf = (entry, label) => entry.crop ? toRenderCrop(entry.crop, `${label}.crop`) : squareCrop;
2475
+ const sweepCrop = sweep ? cropOf(sweep, "sweep") : void 0;
2476
+ const sweepsCrops = sweeps?.map((entry, i) => cropOf(entry, `sweeps[${i}]`));
2362
2477
  if (requested) {
2363
2478
  if (requested.length === 0) throw new AutoRigInputError("poses is empty");
2364
2479
  const poses2 = requested.map((pose, i) => {
@@ -2370,7 +2485,7 @@ function planRenders(model, requested, sweep) {
2370
2485
  crop: toRenderCrop(pose.crop, `poses[${i}].crop`)
2371
2486
  };
2372
2487
  });
2373
- return { canvas, view, fullBody, mouth, poses: poses2, sweepCrop };
2488
+ return { canvas, view, fullBody, mouth, poses: poses2, sweepCrop, sweepsCrops };
2374
2489
  }
2375
2490
  const bodyAngles = Object.fromEntries(
2376
2491
  [
@@ -2478,7 +2593,7 @@ function planRenders(model, requested, sweep) {
2478
2593
  );
2479
2594
  }
2480
2595
  }
2481
- return { canvas, view, fullBody, mouth, poses, sweepCrop };
2596
+ return { canvas, view, fullBody, mouth, poses, sweepCrop, sweepsCrops };
2482
2597
  }
2483
2598
  function checkRequest(requested, i) {
2484
2599
  const { name, values } = requested[i];
@@ -2518,8 +2633,8 @@ function readPageScript() {
2518
2633
  );
2519
2634
  }
2520
2635
  }
2521
- async function captureSweep(evaluate, model, plan, requested, dir, report) {
2522
- const spec = sweepSpec(model, plan.sweepCrop);
2636
+ async function captureSweep(evaluate, model, requested, crop, dir, report, nod) {
2637
+ const spec = sweepSpec(model, requested.preset, crop);
2523
2638
  await evaluate(
2524
2639
  `window.__ikiRender.sweepBegin(${JSON.stringify(spec)})`,
2525
2640
  CAPTURE_MS
@@ -2544,12 +2659,12 @@ async function captureSweep(evaluate, model, plan, requested, dir, report) {
2544
2659
  i: k,
2545
2660
  file,
2546
2661
  t: k / SWEEP_FPS,
2547
- theta: spec.thetas[spec.captureEvery * k],
2548
2662
  values
2549
2663
  });
2550
2664
  }
2551
2665
  const end = await evaluate("window.__ikiRender.sweepEnd()", CAPTURE_MS);
2552
2666
  for (const [what, url] of Object.entries(end)) {
2667
+ if (url === void 0) continue;
2553
2668
  if (typeof url !== "string" || !url.startsWith(PNG_PREFIX)) {
2554
2669
  throw new Error(
2555
2670
  `sweep ${requested.name} ${what}: the page returned no PNG`
@@ -2557,26 +2672,29 @@ async function captureSweep(evaluate, model, plan, requested, dir, report) {
2557
2672
  }
2558
2673
  }
2559
2674
  const sheet = path3.join(dir, "sheet.png");
2560
- const kymograph = path3.join(dir, "kymograph.png");
2561
2675
  writeFileAtomic(
2562
2676
  sheet,
2563
2677
  Buffer.from(end.sheet.slice(PNG_PREFIX.length), "base64")
2564
2678
  );
2565
- writeFileAtomic(
2566
- kymograph,
2567
- Buffer.from(end.kymograph.slice(PNG_PREFIX.length), "base64")
2568
- );
2679
+ let kymograph;
2680
+ if (end.kymograph !== void 0) {
2681
+ kymograph = path3.join(dir, "kymograph.png");
2682
+ writeFileAtomic(
2683
+ kymograph,
2684
+ Buffer.from(end.kymograph.slice(PNG_PREFIX.length), "base64")
2685
+ );
2686
+ }
2569
2687
  const manifest = {
2570
- version: 1,
2688
+ version: 2,
2571
2689
  preset: requested.preset,
2572
- parameter: spec.parameter,
2690
+ parameters: spec.parameters,
2573
2691
  fps: SWEEP_FPS,
2574
2692
  clockHz: SWEEP_CLOCK_HZ,
2575
2693
  warmupS: SWEEP_WARMUP_S,
2576
- durationS: SWEEP_DURATION_S,
2694
+ durationS: sweepDurationS(requested.preset),
2577
2695
  crop: requested.crop ?? null,
2578
2696
  frame: spec.frame,
2579
- kymographRow: { row: spec.kymograph.row, at: spec.kymograph.at },
2697
+ kymographRow: spec.kymograph ? { row: spec.kymograph.row, at: spec.kymograph.at } : null,
2580
2698
  sheet: { frames: spec.sheet.frames, cell: spec.sheet.cell },
2581
2699
  physicsOutputs: spec.physicsOutputs,
2582
2700
  frames
@@ -2593,9 +2711,10 @@ async function captureSweep(evaluate, model, plan, requested, dir, report) {
2593
2711
  frames: spec.frames,
2594
2712
  manifest: manifestPath,
2595
2713
  sheet,
2596
- kymograph,
2714
+ ...kymograph ? { kymograph } : {},
2597
2715
  flipbook,
2598
- report
2716
+ report,
2717
+ nod
2599
2718
  };
2600
2719
  }
2601
2720
  async function renderPoses(input) {
@@ -2608,7 +2727,7 @@ async function renderPoses(input) {
2608
2727
  );
2609
2728
  const outDir = resolveOutputDir(input.outDir);
2610
2729
  const model = loadIkiModel(readFileSync(modelFile, "utf8"));
2611
- const plan = planRenders(model, input.poses, input.sweep);
2730
+ const plan = planRenders(model, input.poses, input.sweep, input.sweeps);
2612
2731
  const browser = findBrowser();
2613
2732
  if (!browser) return { ok: false, error: NO_BROWSER_MESSAGE };
2614
2733
  const pageScript = readPageScript();
@@ -2617,9 +2736,16 @@ async function renderPoses(input) {
2617
2736
  input.poses?.map((p) => p.values)
2618
2737
  );
2619
2738
  const physics = checkPhysics(model);
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(
2739
+ const sweepDir = input.sweep ? prepareSweepDir(outDir, input.sweep.name, "sweep") : void 0;
2740
+ const sweepsDirs = input.sweeps?.map(
2741
+ (s, i) => prepareSweepDir(outDir, s.name, `sweeps[${i}]`)
2742
+ );
2743
+ for (const d of [sweepDir, ...sweepsDirs ?? []]) {
2744
+ if (d) clearSweepDir(d);
2745
+ }
2746
+ const sweepReport = input.sweep || input.sweeps ? checkSweep(model) : void 0;
2747
+ const nodReport = input.sweep || input.sweeps ? checkNod(model) : void 0;
2748
+ const { failedTextures, poses, sweep, sweeps } = await withBrowser(
2623
2749
  browser,
2624
2750
  async (evaluate) => {
2625
2751
  await evaluate(pageScript, PAGE_SCRIPT_MS);
@@ -2643,15 +2769,38 @@ async function renderPoses(input) {
2643
2769
  );
2644
2770
  written.push({ name: pose.name, path: file });
2645
2771
  }
2646
- const sweep2 = input.sweep && sweepDir && sweepReport ? await captureSweep(
2772
+ const sweep2 = input.sweep && sweepDir && sweepReport && nodReport ? await captureSweep(
2647
2773
  evaluate,
2648
2774
  model,
2649
- plan,
2650
2775
  input.sweep,
2776
+ plan.sweepCrop,
2651
2777
  sweepDir,
2652
- sweepReport
2778
+ sweepReport,
2779
+ nodReport
2653
2780
  ) : void 0;
2654
- return { failedTextures: loaded.failedTextures, poses: written, sweep: sweep2 };
2781
+ let sweeps2;
2782
+ if (input.sweeps && sweepsDirs && sweepReport && nodReport) {
2783
+ sweeps2 = [];
2784
+ for (const [i, requested] of input.sweeps.entries()) {
2785
+ sweeps2.push(
2786
+ await captureSweep(
2787
+ evaluate,
2788
+ model,
2789
+ requested,
2790
+ plan.sweepsCrops?.[i],
2791
+ sweepsDirs[i],
2792
+ sweepReport,
2793
+ nodReport
2794
+ )
2795
+ );
2796
+ }
2797
+ }
2798
+ return {
2799
+ failedTextures: loaded.failedTextures,
2800
+ poses: written,
2801
+ sweep: sweep2,
2802
+ sweeps: sweeps2
2803
+ };
2655
2804
  }
2656
2805
  );
2657
2806
  return {
@@ -2665,7 +2814,8 @@ async function renderPoses(input) {
2665
2814
  modelCanvas: model.canvas,
2666
2815
  folds,
2667
2816
  physics,
2668
- sweep
2817
+ sweep,
2818
+ sweeps
2669
2819
  };
2670
2820
  } catch (error) {
2671
2821
  if (error instanceof AutoRigInputError || error instanceof IkiFormatError) {
@@ -2679,6 +2829,8 @@ async function renderPoses(input) {
2679
2829
  var SWEEP_CLOCK_HZ = 60;
2680
2830
  var SWEEP_FPS = 30;
2681
2831
  var SWEEP_DURATION_S = 3;
2832
+ var BOX_DURATION_S = 6;
2833
+ var SWEEP_PRESETS = ["turn", "turn-nod"];
2682
2834
  var SWEEP_WARMUP_S = 0.5;
2683
2835
  var SWEEP_FRAME_MS = 1e3 / SWEEP_CLOCK_HZ * (1 + 1e-9);
2684
2836
  var SHEET_THETAS = [-30, -20, -10, -5, 0, 5, 10, 20, 30];
@@ -2686,16 +2838,75 @@ var SHEET_MAX_SIDE = 2e3;
2686
2838
  var SHEET_MARGIN = 8;
2687
2839
  var SHEET_LABEL_BAND = 24;
2688
2840
  var KYMOGRAPH_BAND = 3;
2689
- var SWEEP_PARAMETER = "ParamAngleX";
2690
- var STEPS = SWEEP_CLOCK_HZ * SWEEP_DURATION_S;
2691
2841
  var CAPTURE_EVERY = SWEEP_CLOCK_HZ / SWEEP_FPS;
2692
- var FRAMES = STEPS / CAPTURE_EVERY;
2693
2842
  var LEG_FROM_S = 0.75;
2694
2843
  var LEG_TO_S = 2.25;
2695
2844
  var AMPLITUDE_DEG = 30;
2845
+ var BOX_CORNERS = [
2846
+ [0, 0],
2847
+ [0, -30],
2848
+ [-30, -30],
2849
+ [-30, 30],
2850
+ [30, 30],
2851
+ [30, -30],
2852
+ [0, -30],
2853
+ [0, 0]
2854
+ ];
2855
+ var BOX_SPEED_DEG_S = 50;
2856
+ var BOX_SHEET_STOPS = [
2857
+ [-30, 30],
2858
+ [0, 30],
2859
+ [30, 30],
2860
+ [-30, 0],
2861
+ [0, 0],
2862
+ [30, 0],
2863
+ [-30, -30],
2864
+ [0, -30],
2865
+ [30, -30]
2866
+ ];
2696
2867
  function turnTheta(t) {
2697
2868
  return -AMPLITUDE_DEG * Math.sin(2 * Math.PI * t / SWEEP_DURATION_S);
2698
2869
  }
2870
+ function boxAngles(t) {
2871
+ let start = 0;
2872
+ for (let i = 0; i + 1 < BOX_CORNERS.length; i++) {
2873
+ const [fx, fy] = BOX_CORNERS[i];
2874
+ const [tx, ty] = BOX_CORNERS[i + 1];
2875
+ const len = Math.max(Math.abs(tx - fx), Math.abs(ty - fy));
2876
+ const dur = len / BOX_SPEED_DEG_S;
2877
+ if (t < start + dur) {
2878
+ const u = (t - start) / dur;
2879
+ const e = (1 - Math.cos(Math.PI * u)) / 2;
2880
+ return { x: fx + (tx - fx) * e, y: fy + (ty - fy) * e };
2881
+ }
2882
+ start += dur;
2883
+ }
2884
+ return { x: 0, y: 0 };
2885
+ }
2886
+ function sweepDurationS(preset) {
2887
+ return preset === "turn" ? SWEEP_DURATION_S : BOX_DURATION_S;
2888
+ }
2889
+ function schedule(preset) {
2890
+ const durationS = sweepDurationS(preset);
2891
+ const n = SWEEP_CLOCK_HZ * durationS;
2892
+ if (preset === "turn") {
2893
+ return {
2894
+ parameters: ["ParamAngleX"],
2895
+ steps: Array.from({ length: n }, (_, j) => ({
2896
+ ParamAngleX: turnTheta(j / SWEEP_CLOCK_HZ)
2897
+ })),
2898
+ durationS
2899
+ };
2900
+ }
2901
+ return {
2902
+ parameters: ["ParamAngleX", "ParamAngleY"],
2903
+ steps: Array.from({ length: n }, (_, j) => {
2904
+ const { x, y } = boxAngles(j / SWEEP_CLOCK_HZ);
2905
+ return { ParamAngleX: x, ParamAngleY: y };
2906
+ }),
2907
+ durationS
2908
+ };
2909
+ }
2699
2910
  function eyeRowModelPx(model) {
2700
2911
  const landed = landParts(model, {}, ["eye_L", "eye_R"]);
2701
2912
  const l = landed.get("eye_L");
@@ -2720,35 +2931,44 @@ function physicsOutputIds(model) {
2720
2931
  }
2721
2932
  return [...ids];
2722
2933
  }
2723
- function sheetFrames(thetas) {
2934
+ function turnSheetFrames(steps, frames) {
2724
2935
  const onLeg = [];
2725
- for (let k = 0; k < FRAMES; k++) {
2936
+ for (let k = 0; k < frames; k++) {
2726
2937
  const t = k / SWEEP_FPS;
2727
2938
  if (t >= LEG_FROM_S && t <= LEG_TO_S) onLeg.push(k);
2728
2939
  }
2940
+ const x = (k) => steps[CAPTURE_EVERY * k].ParamAngleX;
2729
2941
  const picked = [];
2730
2942
  for (const target2 of SHEET_THETAS) {
2731
2943
  let best = onLeg[0];
2732
2944
  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
- }
2945
+ if (Math.abs(x(k) - target2) < Math.abs(x(best) - target2)) best = k;
2736
2946
  }
2737
2947
  if (!picked.includes(best)) picked.push(best);
2738
2948
  }
2739
2949
  return picked.sort((a, b) => a - b);
2740
2950
  }
2741
- function sheetLabel(theta, t) {
2742
- const rounded = Math.round(theta * 10) / 10 + 0;
2951
+ function boxSheetFrames(steps, frames) {
2952
+ return BOX_SHEET_STOPS.map(([sx, sy]) => {
2953
+ const miss = (k) => {
2954
+ const s = steps[CAPTURE_EVERY * k];
2955
+ return Math.abs(s.ParamAngleX - sx) + Math.abs(s.ParamAngleY - sy);
2956
+ };
2957
+ let best = 0;
2958
+ for (let k = 1; k < frames; k++) {
2959
+ if (miss(k) < miss(best)) best = k;
2960
+ }
2961
+ return best;
2962
+ });
2963
+ }
2964
+ function signedDeg(angle) {
2965
+ const rounded = Math.round(angle * 10) / 10 + 0;
2743
2966
  const deg = rounded.toFixed(1);
2744
- const signed2 = rounded > 0 ? `+${deg}` : deg.replace("-", "\u2212");
2745
- return `\u03B8 ${signed2}\xB0 t ${t.toFixed(2)} s`;
2967
+ return rounded > 0 ? `+${deg}` : deg.replace("-", "\u2212");
2746
2968
  }
2747
- function sweepSpec(model, crop) {
2748
- const thetas = Array.from(
2749
- { length: STEPS },
2750
- (_, j) => turnTheta(j / SWEEP_CLOCK_HZ)
2751
- );
2969
+ function sweepSpec(model, preset, crop) {
2970
+ const { parameters, steps, durationS } = schedule(preset);
2971
+ const frameCount = durationS * SWEEP_FPS;
2752
2972
  const dw = crop ? crop.dw : BUST_SIZE;
2753
2973
  const dh = crop ? crop.dh : BUST_SIZE;
2754
2974
  const m = SHEET_MARGIN;
@@ -2758,29 +2978,38 @@ function sweepSpec(model, crop) {
2758
2978
  (SHEET_MAX_SIDE - 2 * m) / (3 * dw),
2759
2979
  (SHEET_MAX_SIDE - 2 * m - 3 * b) / (3 * dh)
2760
2980
  );
2761
- const frames = sheetFrames(thetas);
2981
+ const frames = preset === "turn" ? turnSheetFrames(steps, frameCount) : boxSheetFrames(steps, frameCount);
2982
+ const labelOf = (k) => {
2983
+ const s = steps[CAPTURE_EVERY * k];
2984
+ const t = (k / SWEEP_FPS).toFixed(2);
2985
+ return preset === "turn" ? `\u03B8 ${signedDeg(s.ParamAngleX)}\xB0 t ${t} s` : `X ${signedDeg(s.ParamAngleX)}\xB0 Y ${signedDeg(s.ParamAngleY)}\xB0 t ${t} s`;
2986
+ };
2762
2987
  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";
2988
+ let kymograph;
2989
+ if (preset === "turn") {
2990
+ const yModel = eyeRowModelPx(model);
2991
+ let row = Math.round(dh / 2);
2992
+ let at = "middle";
2993
+ if (yModel !== void 0) {
2994
+ const y0 = bustPadY(W, H);
2995
+ const s = BUST_SIZE / W;
2996
+ const eyeRow = Math.round(
2997
+ crop ? (y0 + yModel * s - crop.sy) * crop.dh / crop.sh : y0 + yModel * s
2998
+ );
2999
+ if (eyeRow >= 1 && eyeRow <= dh - 2) {
3000
+ row = eyeRow;
3001
+ at = "eye row";
3002
+ }
2775
3003
  }
3004
+ kymograph = { row, band: KYMOGRAPH_BAND, at };
2776
3005
  }
2777
3006
  return {
2778
- parameter: SWEEP_PARAMETER,
3007
+ parameters,
2779
3008
  frameMs: SWEEP_FRAME_MS,
2780
3009
  warmup: SWEEP_WARMUP_S * SWEEP_CLOCK_HZ,
2781
- thetas,
3010
+ steps,
2782
3011
  captureEvery: CAPTURE_EVERY,
2783
- frames: FRAMES,
3012
+ frames: frameCount,
2784
3013
  frame: { width: dw, height: dh },
2785
3014
  physicsOutputs: physicsOutputIds(model),
2786
3015
  sheet: {
@@ -2791,11 +3020,9 @@ function sweepSpec(model, crop) {
2791
3020
  },
2792
3021
  margin: m,
2793
3022
  labelBand: b,
2794
- labels: frames.map(
2795
- (k) => sheetLabel(thetas[CAPTURE_EVERY * k], k / SWEEP_FPS)
2796
- )
3023
+ labels: frames.map(labelOf)
2797
3024
  },
2798
- kymograph: { row, band: KYMOGRAPH_BAND, at },
3025
+ kymograph,
2799
3026
  crop
2800
3027
  };
2801
3028
  }
@@ -2805,7 +3032,7 @@ function flipbookHtml(manifest) {
2805
3032
  <html lang="en">
2806
3033
  <head>
2807
3034
  <meta charset="utf-8">
2808
- <title>turn sweep</title>
3035
+ <title>${manifest.preset} sweep</title>
2809
3036
  <style>
2810
3037
  body { font: 14px system-ui, sans-serif; margin: 16px; background: #222; color: #eee; }
2811
3038
  .row { display: flex; gap: 16px; align-items: flex-start; }
@@ -2838,13 +3065,18 @@ img { max-width: 48vw; height: auto; background: #444; }
2838
3065
  var playing = true;
2839
3066
  scrub.max = String(n - 1);
2840
3067
  if (b) { bi.style.display = "block"; }
3068
+ function short(id) {
3069
+ return id === "ParamAngleX" ? "X" : id === "ParamAngleY" ? "Y" : id;
3070
+ }
2841
3071
  function show(k) {
2842
3072
  i = k;
2843
3073
  var f = m.frames[k];
2844
3074
  a.src = f.file;
2845
3075
  if (b) { bi.src = b.replace(/\\/$/, "") + "/" + f.file; }
2846
3076
  scrub.value = String(k);
2847
- readout.textContent = "frame " + k + " \\u03b8 " + f.theta.toFixed(1) + "\\u00b0 t " + f.t.toFixed(2) + " s";
3077
+ readout.textContent = "frame " + k + m.parameters.map(function (id) {
3078
+ return " " + short(id) + " " + f.values[id].toFixed(1) + "\\u00b0";
3079
+ }).join("") + " t " + f.t.toFixed(2) + " s";
2848
3080
  }
2849
3081
  play.addEventListener("click", function () {
2850
3082
  playing = !playing;
@@ -2863,7 +3095,14 @@ img { max-width: 48vw; height: auto; background: #444; }
2863
3095
  </html>
2864
3096
  `;
2865
3097
  }
2866
- function prepareSweepDir(outDir, name) {
3098
+ var STALE_FILE = /^f\d{3}\.png$/;
3099
+ var STALE_NAMES = [
3100
+ "kymograph.png",
3101
+ "sheet.png",
3102
+ "manifest.json",
3103
+ "index.html"
3104
+ ];
3105
+ function prepareSweepDir(outDir, name, label) {
2867
3106
  const dir = path4.join(outDir, name);
2868
3107
  try {
2869
3108
  fs3.mkdirSync(dir);
@@ -2874,13 +3113,19 @@ function prepareSweepDir(outDir, name) {
2874
3113
  }
2875
3114
  const stat = fs3.lstatSync(dir);
2876
3115
  if (stat.isSymbolicLink()) {
2877
- throw new AutoRigInputError(`sweep.name names ${dir}, a symbolic link`);
3116
+ throw new AutoRigInputError(`${label}.name names ${dir}, a symbolic link`);
2878
3117
  }
2879
3118
  if (!stat.isDirectory()) {
2880
- throw new AutoRigInputError(`sweep.name names ${dir}, not a directory`);
3119
+ throw new AutoRigInputError(`${label}.name names ${dir}, not a directory`);
3120
+ }
3121
+ return confineToWorkingDirectory(process.cwd(), dir, "sweep dir", name);
3122
+ }
3123
+ function clearSweepDir(real) {
3124
+ for (const entry of fs3.readdirSync(real)) {
3125
+ if (STALE_FILE.test(entry) || STALE_NAMES.includes(entry)) {
3126
+ fs3.rmSync(path4.join(real, entry));
3127
+ }
2881
3128
  }
2882
- const real = confineToWorkingDirectory(process.cwd(), dir, "sweep dir", name);
2883
- return real;
2884
3129
  }
2885
3130
 
2886
3131
  // src/tools.ts
@@ -6204,7 +6449,7 @@ function formatPatchReports(reports) {
6204
6449
  });
6205
6450
  }
6206
6451
  function createIkiMcpServer() {
6207
- const server = new McpServer({ name: "iki", version: "0.31.0" });
6452
+ const server = new McpServer({ name: "iki", version: "0.32.0" });
6208
6453
  server.registerTool(
6209
6454
  "validate_iki",
6210
6455
  {
@@ -6502,7 +6747,7 @@ function createIkiMcpServer() {
6502
6747
  server.registerTool(
6503
6748
  "render_poses",
6504
6749
  {
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.",
6750
+ 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 (and, with `sweeps`, the turn-and-nod box). Fails with INVALID when no browser is found or an input is refused; a browser that cannot start is a tool error.",
6506
6751
  inputSchema: {
6507
6752
  modelPath: z.string().describe(
6508
6753
  "Rigged .iki file path (resolved against cwd; must sit under the working directory)."
@@ -6534,7 +6779,21 @@ function createIkiMcpServer() {
6534
6779
  h: z.number()
6535
6780
  }).optional()
6536
6781
  }).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`."
6782
+ "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`. `sweeps` renders more sweeps beside this one. The `SWEEP nod` and `SWEEP corner` lines follow the `SWEEP turn` ones."
6783
+ ),
6784
+ sweeps: z.array(
6785
+ z.object({
6786
+ name: z.string(),
6787
+ preset: z.enum(SWEEP_PRESETS),
6788
+ crop: z.object({
6789
+ x: z.number(),
6790
+ y: z.number(),
6791
+ w: z.number(),
6792
+ h: z.number()
6793
+ }).optional()
6794
+ })
6795
+ ).optional().describe(
6796
+ "More sweeps rendered after `sweep`, each `{ name, preset, crop? }` into its own `<outDir>/<name>/` (files and `crop` as `sweep`'s). Names are distinct from `sweep`'s and from each other's ignoring case, and presets are distinct (at most one of each). `turn` is `sweep`'s. `turn-nod` is the box (0,0) -> (0,-30) -> (-30,-30) -> (-30,+30) -> (+30,+30) -> (+30,-30) -> (0,-30) -> (0,0) of `ParamAngleX` x `ParamAngleY`, each leg eased, 6 s, 180 frames; its `sheet.png` is a 3 x 3 grid BY ANGLE (columns AngleX -30/0/+30, rows AngleY +30/0/-30, rest in the centre, cells labelled X, Y and t) and it has no kymograph. `manifest.json` is version 2 (`parameters`, and per frame `t` and `values`). A sweep dir's earlier frames, sheet, kymograph, manifest and flipbook are cleared first. An empty list, a repeated name or preset, or a bad crop comes back as `INVALID: sweeps...`. A server before 0.32.0 strips `sweeps` and renders the rest. The `SWEEP nod` lines (the eye-pair and iris-pair gap range and the mouth width range along the nod at each turn, in face widths) and `SWEEP corner` lines (the additivity residual per landmark at the four corners, the rest term included; 0 on an additive rig) print once per call whenever `sweep` or `sweeps` was asked for, report-only like `FOLD` and `PHYSICS`."
6538
6797
  )
6539
6798
  }
6540
6799
  },
@@ -6543,16 +6802,21 @@ function createIkiMcpServer() {
6543
6802
  const r = await renderPoses(args);
6544
6803
  const text = r.ok ? [
6545
6804
  ...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
- ] : [],
6805
+ ...[...r.sweep ? [r.sweep] : [], ...r.sweeps ?? []].flatMap(
6806
+ (w) => [
6807
+ w.dir,
6808
+ w.sheet,
6809
+ ...w.kymograph ? [w.kymograph] : [],
6810
+ w.flipbook,
6811
+ w.manifest
6812
+ ]
6813
+ ),
6553
6814
  ...formatFoldReport(r.folds, r.modelCanvas),
6554
6815
  ...formatPhysicsReport(r.physics),
6555
- ...r.sweep ? formatSweepReport(r.sweep.report) : []
6816
+ ...r.sweep ?? r.sweeps?.[0] ? [
6817
+ ...formatSweepReport((r.sweep ?? r.sweeps[0]).report),
6818
+ ...formatNodReport((r.sweep ?? r.sweeps[0]).nod)
6819
+ ] : []
6556
6820
  ].join("\n") : `INVALID: ${r.error}`;
6557
6821
  return { content: [{ type: "text", text }], structuredContent: r };
6558
6822
  } catch (err) {
@@ -6571,8 +6835,11 @@ function createIkiMcpServer() {
6571
6835
  export {
6572
6836
  checkModelFolds,
6573
6837
  formatFoldReport,
6838
+ checkNod,
6574
6839
  checkSweep,
6575
6840
  formatSweepReport,
6841
+ formatNodReport,
6842
+ SWEEP_PRESETS,
6576
6843
  renderPoses,
6577
6844
  validateIki,
6578
6845
  describeIki,
@@ -6589,4 +6856,4 @@ export {
6589
6856
  formatPhysicsReport,
6590
6857
  createIkiMcpServer
6591
6858
  };
6592
- //# sourceMappingURL=chunk-RLBRIAVN.mjs.map
6859
+ //# sourceMappingURL=chunk-576N2JWR.mjs.map