@ikijs/mcp 0.31.1 → 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.
package/dist/index.js CHANGED
@@ -30,8 +30,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ SWEEP_PRESETS: () => SWEEP_PRESETS,
33
34
  autoRigFromLayers: () => autoRigFromLayers,
34
35
  checkModelFolds: () => checkModelFolds,
36
+ checkNod: () => checkNod,
35
37
  checkSweep: () => checkSweep,
36
38
  composeLayersFromParts: () => composeLayersFromParts,
37
39
  createIkiMcpServer: () => createIkiMcpServer,
@@ -40,6 +42,7 @@ __export(index_exports, {
40
42
  describeRigPlan: () => describeRigPlan,
41
43
  formatFoldReport: () => formatFoldReport,
42
44
  formatMeasureReport: () => formatMeasureReport,
45
+ formatNodReport: () => formatNodReport,
43
46
  formatPhysicsReport: () => formatPhysicsReport,
44
47
  formatRigPlanReport: () => formatRigPlanReport,
45
48
  formatSweepReport: () => formatSweepReport,
@@ -2261,6 +2264,83 @@ function pop(v) {
2261
2264
  }
2262
2265
  return most / mean;
2263
2266
  }
2267
+ var NOD_TURNS = [-30, 0, 30];
2268
+ var NOD_PARTS = [
2269
+ "face",
2270
+ "eye_L",
2271
+ "eye_R",
2272
+ "iris_L",
2273
+ "iris_R",
2274
+ "nose",
2275
+ "lip_upper",
2276
+ "mouth"
2277
+ ];
2278
+ var NOD_ENDS = [0, -LADDER_MIN, LADDER_MAX - LADDER_MIN];
2279
+ function checkNod(model) {
2280
+ const face = model.parts.find((p) => p.id === "face");
2281
+ if (!face) return { unavailable: "no face part" };
2282
+ const hasEyes = ["eye_L", "eye_R"].every(
2283
+ (id) => model.parts.some((p) => p.id === id)
2284
+ );
2285
+ if (!hasEyes) return { unavailable: "no eye_L and eye_R parts" };
2286
+ const fw = face.width;
2287
+ const ladders = NOD_TURNS.map(
2288
+ (x) => Array.from(
2289
+ { length: LADDER_MAX - LADDER_MIN + 1 },
2290
+ (_, i) => landParts(
2291
+ model,
2292
+ { ParamAngleX: x, ParamAngleY: LADDER_MIN + i },
2293
+ NOD_PARTS
2294
+ )
2295
+ )
2296
+ );
2297
+ const has = (id) => ladders[0][0].has(id);
2298
+ const boxes = (id) => ladders.map((ladder) => ladder.map((l) => box(l.get(id), fw)));
2299
+ const spread = (v) => Math.max(...v) - Math.min(...v);
2300
+ const ranges = (values) => {
2301
+ const [m30, zero, p30] = NOD_TURNS.map(
2302
+ (_, b) => spread(
2303
+ Array.from(
2304
+ { length: LADDER_MAX - LADDER_MIN + 1 },
2305
+ (_2, i) => values(b, i)
2306
+ )
2307
+ )
2308
+ );
2309
+ return { m30, zero, p30 };
2310
+ };
2311
+ const gap = (l, r) => {
2312
+ const bl = boxes(l);
2313
+ const br = boxes(r);
2314
+ return ranges((b, i) => br[b][i].x - bl[b][i].x);
2315
+ };
2316
+ const nod = [{ id: "eyes", range: gap("eye_L", "eye_R") }];
2317
+ if (has("iris_L") && has("iris_R")) {
2318
+ nod.push({ id: "irises", range: gap("iris_L", "iris_R") });
2319
+ }
2320
+ const mouthId = has("lip_upper") ? "lip_upper" : has("mouth") ? "mouth" : null;
2321
+ if (mouthId) {
2322
+ const bm = boxes(mouthId);
2323
+ nod.push({ id: "mouth", range: ranges((b, i) => bm[b][i].width) });
2324
+ }
2325
+ const corner = ["eye_L", "eye_R", "nose"].filter(has).map((id) => {
2326
+ const b = boxes(id);
2327
+ const at = (t, j) => b[t][NOD_ENDS[j]];
2328
+ const residual = (t, j) => {
2329
+ const r = (axis) => at(t, j)[axis] - at(t, 1)[axis] - at(1, j)[axis] + at(1, 1)[axis];
2330
+ return Math.max(Math.abs(r("x")), Math.abs(r("y")));
2331
+ };
2332
+ return {
2333
+ id,
2334
+ residual: {
2335
+ mm: residual(0, 0),
2336
+ mp: residual(0, 2),
2337
+ pm: residual(2, 0),
2338
+ pp: residual(2, 2)
2339
+ }
2340
+ };
2341
+ });
2342
+ return { unit: "fw", faceWidth: fw, nod, corner };
2343
+ }
2264
2344
  function checkSweep(model) {
2265
2345
  const face = model.parts.find((p) => p.id === "face");
2266
2346
  if (!face) return { preset: "turn", unavailable: "no face part" };
@@ -2330,6 +2410,19 @@ function formatSweepReport(report) {
2330
2410
  `SWEEP turn plate: amplitude ${fw3(report.plateAmplitude)} fw`
2331
2411
  ];
2332
2412
  }
2413
+ function formatNodReport(report) {
2414
+ if ("unavailable" in report) {
2415
+ return [`SWEEP nod: unavailable \u2014 ${report.unavailable}`];
2416
+ }
2417
+ return [
2418
+ ...report.nod.map(
2419
+ ({ 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`
2420
+ ),
2421
+ ...report.corner.map(
2422
+ ({ 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`
2423
+ )
2424
+ ];
2425
+ }
2333
2426
 
2334
2427
  // src/sweep.ts
2335
2428
  var import_node_fs3 = __toESM(require("fs"));
@@ -2337,6 +2430,8 @@ var import_node_path3 = __toESM(require("path"));
2337
2430
  var SWEEP_CLOCK_HZ = 60;
2338
2431
  var SWEEP_FPS = 30;
2339
2432
  var SWEEP_DURATION_S = 3;
2433
+ var BOX_DURATION_S = 6;
2434
+ var SWEEP_PRESETS = ["turn", "turn-nod"];
2340
2435
  var SWEEP_WARMUP_S = 0.5;
2341
2436
  var SWEEP_FRAME_MS = 1e3 / SWEEP_CLOCK_HZ * (1 + 1e-9);
2342
2437
  var SHEET_THETAS = [-30, -20, -10, -5, 0, 5, 10, 20, 30];
@@ -2344,16 +2439,75 @@ var SHEET_MAX_SIDE = 2e3;
2344
2439
  var SHEET_MARGIN = 8;
2345
2440
  var SHEET_LABEL_BAND = 24;
2346
2441
  var KYMOGRAPH_BAND = 3;
2347
- var SWEEP_PARAMETER = "ParamAngleX";
2348
- var STEPS = SWEEP_CLOCK_HZ * SWEEP_DURATION_S;
2349
2442
  var CAPTURE_EVERY = SWEEP_CLOCK_HZ / SWEEP_FPS;
2350
- var FRAMES = STEPS / CAPTURE_EVERY;
2351
2443
  var LEG_FROM_S = 0.75;
2352
2444
  var LEG_TO_S = 2.25;
2353
2445
  var AMPLITUDE_DEG = 30;
2446
+ var BOX_CORNERS = [
2447
+ [0, 0],
2448
+ [0, -30],
2449
+ [-30, -30],
2450
+ [-30, 30],
2451
+ [30, 30],
2452
+ [30, -30],
2453
+ [0, -30],
2454
+ [0, 0]
2455
+ ];
2456
+ var BOX_SPEED_DEG_S = 50;
2457
+ var BOX_SHEET_STOPS = [
2458
+ [-30, 30],
2459
+ [0, 30],
2460
+ [30, 30],
2461
+ [-30, 0],
2462
+ [0, 0],
2463
+ [30, 0],
2464
+ [-30, -30],
2465
+ [0, -30],
2466
+ [30, -30]
2467
+ ];
2354
2468
  function turnTheta(t) {
2355
2469
  return -AMPLITUDE_DEG * Math.sin(2 * Math.PI * t / SWEEP_DURATION_S);
2356
2470
  }
2471
+ function boxAngles(t) {
2472
+ let start = 0;
2473
+ for (let i = 0; i + 1 < BOX_CORNERS.length; i++) {
2474
+ const [fx, fy] = BOX_CORNERS[i];
2475
+ const [tx, ty] = BOX_CORNERS[i + 1];
2476
+ const len = Math.max(Math.abs(tx - fx), Math.abs(ty - fy));
2477
+ const dur = len / BOX_SPEED_DEG_S;
2478
+ if (t < start + dur) {
2479
+ const u = (t - start) / dur;
2480
+ const e = (1 - Math.cos(Math.PI * u)) / 2;
2481
+ return { x: fx + (tx - fx) * e, y: fy + (ty - fy) * e };
2482
+ }
2483
+ start += dur;
2484
+ }
2485
+ return { x: 0, y: 0 };
2486
+ }
2487
+ function sweepDurationS(preset) {
2488
+ return preset === "turn" ? SWEEP_DURATION_S : BOX_DURATION_S;
2489
+ }
2490
+ function schedule(preset) {
2491
+ const durationS = sweepDurationS(preset);
2492
+ const n = SWEEP_CLOCK_HZ * durationS;
2493
+ if (preset === "turn") {
2494
+ return {
2495
+ parameters: ["ParamAngleX"],
2496
+ steps: Array.from({ length: n }, (_, j) => ({
2497
+ ParamAngleX: turnTheta(j / SWEEP_CLOCK_HZ)
2498
+ })),
2499
+ durationS
2500
+ };
2501
+ }
2502
+ return {
2503
+ parameters: ["ParamAngleX", "ParamAngleY"],
2504
+ steps: Array.from({ length: n }, (_, j) => {
2505
+ const { x, y } = boxAngles(j / SWEEP_CLOCK_HZ);
2506
+ return { ParamAngleX: x, ParamAngleY: y };
2507
+ }),
2508
+ durationS
2509
+ };
2510
+ }
2357
2511
  function eyeRowModelPx(model) {
2358
2512
  const landed = landParts(model, {}, ["eye_L", "eye_R"]);
2359
2513
  const l = landed.get("eye_L");
@@ -2378,35 +2532,44 @@ function physicsOutputIds(model) {
2378
2532
  }
2379
2533
  return [...ids];
2380
2534
  }
2381
- function sheetFrames(thetas) {
2535
+ function turnSheetFrames(steps, frames) {
2382
2536
  const onLeg = [];
2383
- for (let k = 0; k < FRAMES; k++) {
2537
+ for (let k = 0; k < frames; k++) {
2384
2538
  const t = k / SWEEP_FPS;
2385
2539
  if (t >= LEG_FROM_S && t <= LEG_TO_S) onLeg.push(k);
2386
2540
  }
2541
+ const x = (k) => steps[CAPTURE_EVERY * k].ParamAngleX;
2387
2542
  const picked = [];
2388
2543
  for (const target2 of SHEET_THETAS) {
2389
2544
  let best = onLeg[0];
2390
2545
  for (const k of onLeg) {
2391
- if (Math.abs(thetas[CAPTURE_EVERY * k] - target2) < Math.abs(thetas[CAPTURE_EVERY * best] - target2)) {
2392
- best = k;
2393
- }
2546
+ if (Math.abs(x(k) - target2) < Math.abs(x(best) - target2)) best = k;
2394
2547
  }
2395
2548
  if (!picked.includes(best)) picked.push(best);
2396
2549
  }
2397
2550
  return picked.sort((a, b) => a - b);
2398
2551
  }
2399
- function sheetLabel(theta, t) {
2400
- const rounded = Math.round(theta * 10) / 10 + 0;
2552
+ function boxSheetFrames(steps, frames) {
2553
+ return BOX_SHEET_STOPS.map(([sx, sy]) => {
2554
+ const miss = (k) => {
2555
+ const s = steps[CAPTURE_EVERY * k];
2556
+ return Math.abs(s.ParamAngleX - sx) + Math.abs(s.ParamAngleY - sy);
2557
+ };
2558
+ let best = 0;
2559
+ for (let k = 1; k < frames; k++) {
2560
+ if (miss(k) < miss(best)) best = k;
2561
+ }
2562
+ return best;
2563
+ });
2564
+ }
2565
+ function signedDeg(angle) {
2566
+ const rounded = Math.round(angle * 10) / 10 + 0;
2401
2567
  const deg = rounded.toFixed(1);
2402
- const signed2 = rounded > 0 ? `+${deg}` : deg.replace("-", "\u2212");
2403
- return `\u03B8 ${signed2}\xB0 t ${t.toFixed(2)} s`;
2568
+ return rounded > 0 ? `+${deg}` : deg.replace("-", "\u2212");
2404
2569
  }
2405
- function sweepSpec(model, crop) {
2406
- const thetas = Array.from(
2407
- { length: STEPS },
2408
- (_, j) => turnTheta(j / SWEEP_CLOCK_HZ)
2409
- );
2570
+ function sweepSpec(model, preset, crop) {
2571
+ const { parameters, steps, durationS } = schedule(preset);
2572
+ const frameCount = durationS * SWEEP_FPS;
2410
2573
  const dw = crop ? crop.dw : BUST_SIZE;
2411
2574
  const dh = crop ? crop.dh : BUST_SIZE;
2412
2575
  const m = SHEET_MARGIN;
@@ -2416,29 +2579,38 @@ function sweepSpec(model, crop) {
2416
2579
  (SHEET_MAX_SIDE - 2 * m) / (3 * dw),
2417
2580
  (SHEET_MAX_SIDE - 2 * m - 3 * b) / (3 * dh)
2418
2581
  );
2419
- const frames = sheetFrames(thetas);
2582
+ const frames = preset === "turn" ? turnSheetFrames(steps, frameCount) : boxSheetFrames(steps, frameCount);
2583
+ const labelOf = (k) => {
2584
+ const s = steps[CAPTURE_EVERY * k];
2585
+ const t = (k / SWEEP_FPS).toFixed(2);
2586
+ return preset === "turn" ? `\u03B8 ${signedDeg(s.ParamAngleX)}\xB0 t ${t} s` : `X ${signedDeg(s.ParamAngleX)}\xB0 Y ${signedDeg(s.ParamAngleY)}\xB0 t ${t} s`;
2587
+ };
2420
2588
  const { width: W, height: H } = model.canvas;
2421
- const yModel = eyeRowModelPx(model);
2422
- let row = Math.round(dh / 2);
2423
- let at = "middle";
2424
- if (yModel !== void 0) {
2425
- const y0 = bustPadY(W, H);
2426
- const s = BUST_SIZE / W;
2427
- const eyeRow = Math.round(
2428
- crop ? (y0 + yModel * s - crop.sy) * crop.dh / crop.sh : y0 + yModel * s
2429
- );
2430
- if (eyeRow >= 1 && eyeRow <= dh - 2) {
2431
- row = eyeRow;
2432
- at = "eye row";
2589
+ let kymograph;
2590
+ if (preset === "turn") {
2591
+ const yModel = eyeRowModelPx(model);
2592
+ let row = Math.round(dh / 2);
2593
+ let at = "middle";
2594
+ if (yModel !== void 0) {
2595
+ const y0 = bustPadY(W, H);
2596
+ const s = BUST_SIZE / W;
2597
+ const eyeRow = Math.round(
2598
+ crop ? (y0 + yModel * s - crop.sy) * crop.dh / crop.sh : y0 + yModel * s
2599
+ );
2600
+ if (eyeRow >= 1 && eyeRow <= dh - 2) {
2601
+ row = eyeRow;
2602
+ at = "eye row";
2603
+ }
2433
2604
  }
2605
+ kymograph = { row, band: KYMOGRAPH_BAND, at };
2434
2606
  }
2435
2607
  return {
2436
- parameter: SWEEP_PARAMETER,
2608
+ parameters,
2437
2609
  frameMs: SWEEP_FRAME_MS,
2438
2610
  warmup: SWEEP_WARMUP_S * SWEEP_CLOCK_HZ,
2439
- thetas,
2611
+ steps,
2440
2612
  captureEvery: CAPTURE_EVERY,
2441
- frames: FRAMES,
2613
+ frames: frameCount,
2442
2614
  frame: { width: dw, height: dh },
2443
2615
  physicsOutputs: physicsOutputIds(model),
2444
2616
  sheet: {
@@ -2449,11 +2621,9 @@ function sweepSpec(model, crop) {
2449
2621
  },
2450
2622
  margin: m,
2451
2623
  labelBand: b,
2452
- labels: frames.map(
2453
- (k) => sheetLabel(thetas[CAPTURE_EVERY * k], k / SWEEP_FPS)
2454
- )
2624
+ labels: frames.map(labelOf)
2455
2625
  },
2456
- kymograph: { row, band: KYMOGRAPH_BAND, at },
2626
+ kymograph,
2457
2627
  crop
2458
2628
  };
2459
2629
  }
@@ -2463,7 +2633,7 @@ function flipbookHtml(manifest) {
2463
2633
  <html lang="en">
2464
2634
  <head>
2465
2635
  <meta charset="utf-8">
2466
- <title>turn sweep</title>
2636
+ <title>${manifest.preset} sweep</title>
2467
2637
  <style>
2468
2638
  body { font: 14px system-ui, sans-serif; margin: 16px; background: #222; color: #eee; }
2469
2639
  .row { display: flex; gap: 16px; align-items: flex-start; }
@@ -2496,13 +2666,18 @@ img { max-width: 48vw; height: auto; background: #444; }
2496
2666
  var playing = true;
2497
2667
  scrub.max = String(n - 1);
2498
2668
  if (b) { bi.style.display = "block"; }
2669
+ function short(id) {
2670
+ return id === "ParamAngleX" ? "X" : id === "ParamAngleY" ? "Y" : id;
2671
+ }
2499
2672
  function show(k) {
2500
2673
  i = k;
2501
2674
  var f = m.frames[k];
2502
2675
  a.src = f.file;
2503
2676
  if (b) { bi.src = b.replace(/\\/$/, "") + "/" + f.file; }
2504
2677
  scrub.value = String(k);
2505
- readout.textContent = "frame " + k + " \\u03b8 " + f.theta.toFixed(1) + "\\u00b0 t " + f.t.toFixed(2) + " s";
2678
+ readout.textContent = "frame " + k + m.parameters.map(function (id) {
2679
+ return " " + short(id) + " " + f.values[id].toFixed(1) + "\\u00b0";
2680
+ }).join("") + " t " + f.t.toFixed(2) + " s";
2506
2681
  }
2507
2682
  play.addEventListener("click", function () {
2508
2683
  playing = !playing;
@@ -2521,7 +2696,14 @@ img { max-width: 48vw; height: auto; background: #444; }
2521
2696
  </html>
2522
2697
  `;
2523
2698
  }
2524
- function prepareSweepDir(outDir, name) {
2699
+ var STALE_FILE = /^f\d{3}\.png$/;
2700
+ var STALE_NAMES = [
2701
+ "kymograph.png",
2702
+ "sheet.png",
2703
+ "manifest.json",
2704
+ "index.html"
2705
+ ];
2706
+ function prepareSweepDir(outDir, name, label) {
2525
2707
  const dir = import_node_path3.default.join(outDir, name);
2526
2708
  try {
2527
2709
  import_node_fs3.default.mkdirSync(dir);
@@ -2532,13 +2714,19 @@ function prepareSweepDir(outDir, name) {
2532
2714
  }
2533
2715
  const stat = import_node_fs3.default.lstatSync(dir);
2534
2716
  if (stat.isSymbolicLink()) {
2535
- throw new AutoRigInputError(`sweep.name names ${dir}, a symbolic link`);
2717
+ throw new AutoRigInputError(`${label}.name names ${dir}, a symbolic link`);
2536
2718
  }
2537
2719
  if (!stat.isDirectory()) {
2538
- throw new AutoRigInputError(`sweep.name names ${dir}, not a directory`);
2720
+ throw new AutoRigInputError(`${label}.name names ${dir}, not a directory`);
2721
+ }
2722
+ return confineToWorkingDirectory(process.cwd(), dir, "sweep dir", name);
2723
+ }
2724
+ function clearSweepDir(real) {
2725
+ for (const entry of import_node_fs3.default.readdirSync(real)) {
2726
+ if (STALE_FILE.test(entry) || STALE_NAMES.includes(entry)) {
2727
+ import_node_fs3.default.rmSync(import_node_path3.default.join(real, entry));
2728
+ }
2539
2729
  }
2540
- const real = confineToWorkingDirectory(process.cwd(), dir, "sweep dir", name);
2541
- return real;
2542
2730
  }
2543
2731
 
2544
2732
  // src/render-poses.ts
@@ -2551,7 +2739,7 @@ var SWEEP_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
2551
2739
  function bustPadY(width, height) {
2552
2740
  return Math.max(0, (BUST_SIZE - BUST_SIZE * height / width) / 2);
2553
2741
  }
2554
- function planRenders(model, requested, sweep) {
2742
+ function planRenders(model, requested, sweep, sweeps) {
2555
2743
  const { width: W, height: H } = model.canvas;
2556
2744
  const fullBody = H > W;
2557
2745
  const canvas = fullBody ? {
@@ -2606,12 +2794,37 @@ function planRenders(model, requested, sweep) {
2606
2794
  dh
2607
2795
  };
2608
2796
  };
2609
- if (sweep && !SWEEP_NAME.test(sweep.name)) {
2610
- throw new AutoRigInputError(
2611
- `sweep.name must match ${SWEEP_NAME.source} (it names <outDir>/<name>/): ${JSON.stringify(sweep.name)}`
2612
- );
2797
+ if (sweeps && sweeps.length === 0) {
2798
+ throw new AutoRigInputError("sweeps is empty");
2613
2799
  }
2614
- const sweepCrop = sweep ? sweep.crop ? toRenderCrop(sweep.crop, "sweep.crop") : squareCrop : void 0;
2800
+ const asked = [
2801
+ ...sweep ? [{ label: "sweep", entry: sweep }] : [],
2802
+ ...(sweeps ?? []).map((entry, i) => ({ label: `sweeps[${i}]`, entry }))
2803
+ ];
2804
+ asked.forEach(({ label, entry }, i) => {
2805
+ if (!SWEEP_NAME.test(entry.name)) {
2806
+ throw new AutoRigInputError(
2807
+ `${label}.name must match ${SWEEP_NAME.source} (it names <outDir>/<name>/): ${JSON.stringify(entry.name)}`
2808
+ );
2809
+ }
2810
+ const sameName = asked.findIndex(
2811
+ (a) => a.entry.name.toLowerCase() === entry.name.toLowerCase()
2812
+ );
2813
+ if (sameName < i) {
2814
+ throw new AutoRigInputError(
2815
+ `${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)`
2816
+ );
2817
+ }
2818
+ const samePreset = asked.findIndex((a) => a.entry.preset === entry.preset);
2819
+ if (samePreset < i) {
2820
+ throw new AutoRigInputError(
2821
+ `${label}.preset ${JSON.stringify(entry.preset)} repeats ${asked[samePreset].label}.preset (the same frames twice)`
2822
+ );
2823
+ }
2824
+ });
2825
+ const cropOf = (entry, label) => entry.crop ? toRenderCrop(entry.crop, `${label}.crop`) : squareCrop;
2826
+ const sweepCrop = sweep ? cropOf(sweep, "sweep") : void 0;
2827
+ const sweepsCrops = sweeps?.map((entry, i) => cropOf(entry, `sweeps[${i}]`));
2615
2828
  if (requested) {
2616
2829
  if (requested.length === 0) throw new AutoRigInputError("poses is empty");
2617
2830
  const poses2 = requested.map((pose, i) => {
@@ -2623,7 +2836,7 @@ function planRenders(model, requested, sweep) {
2623
2836
  crop: toRenderCrop(pose.crop, `poses[${i}].crop`)
2624
2837
  };
2625
2838
  });
2626
- return { canvas, view, fullBody, mouth, poses: poses2, sweepCrop };
2839
+ return { canvas, view, fullBody, mouth, poses: poses2, sweepCrop, sweepsCrops };
2627
2840
  }
2628
2841
  const bodyAngles = Object.fromEntries(
2629
2842
  [
@@ -2731,7 +2944,7 @@ function planRenders(model, requested, sweep) {
2731
2944
  );
2732
2945
  }
2733
2946
  }
2734
- return { canvas, view, fullBody, mouth, poses, sweepCrop };
2947
+ return { canvas, view, fullBody, mouth, poses, sweepCrop, sweepsCrops };
2735
2948
  }
2736
2949
  function checkRequest(requested, i) {
2737
2950
  const { name, values } = requested[i];
@@ -2771,8 +2984,8 @@ function readPageScript() {
2771
2984
  );
2772
2985
  }
2773
2986
  }
2774
- async function captureSweep(evaluate, model, plan, requested, dir, report) {
2775
- const spec = sweepSpec(model, plan.sweepCrop);
2987
+ async function captureSweep(evaluate, model, requested, crop, dir, report, nod) {
2988
+ const spec = sweepSpec(model, requested.preset, crop);
2776
2989
  await evaluate(
2777
2990
  `window.__ikiRender.sweepBegin(${JSON.stringify(spec)})`,
2778
2991
  CAPTURE_MS
@@ -2797,12 +3010,12 @@ async function captureSweep(evaluate, model, plan, requested, dir, report) {
2797
3010
  i: k,
2798
3011
  file,
2799
3012
  t: k / SWEEP_FPS,
2800
- theta: spec.thetas[spec.captureEvery * k],
2801
3013
  values
2802
3014
  });
2803
3015
  }
2804
3016
  const end = await evaluate("window.__ikiRender.sweepEnd()", CAPTURE_MS);
2805
3017
  for (const [what, url] of Object.entries(end)) {
3018
+ if (url === void 0) continue;
2806
3019
  if (typeof url !== "string" || !url.startsWith(PNG_PREFIX)) {
2807
3020
  throw new Error(
2808
3021
  `sweep ${requested.name} ${what}: the page returned no PNG`
@@ -2810,26 +3023,29 @@ async function captureSweep(evaluate, model, plan, requested, dir, report) {
2810
3023
  }
2811
3024
  }
2812
3025
  const sheet = import_node_path4.default.join(dir, "sheet.png");
2813
- const kymograph = import_node_path4.default.join(dir, "kymograph.png");
2814
3026
  writeFileAtomic(
2815
3027
  sheet,
2816
3028
  Buffer.from(end.sheet.slice(PNG_PREFIX.length), "base64")
2817
3029
  );
2818
- writeFileAtomic(
2819
- kymograph,
2820
- Buffer.from(end.kymograph.slice(PNG_PREFIX.length), "base64")
2821
- );
3030
+ let kymograph;
3031
+ if (end.kymograph !== void 0) {
3032
+ kymograph = import_node_path4.default.join(dir, "kymograph.png");
3033
+ writeFileAtomic(
3034
+ kymograph,
3035
+ Buffer.from(end.kymograph.slice(PNG_PREFIX.length), "base64")
3036
+ );
3037
+ }
2822
3038
  const manifest = {
2823
- version: 1,
3039
+ version: 2,
2824
3040
  preset: requested.preset,
2825
- parameter: spec.parameter,
3041
+ parameters: spec.parameters,
2826
3042
  fps: SWEEP_FPS,
2827
3043
  clockHz: SWEEP_CLOCK_HZ,
2828
3044
  warmupS: SWEEP_WARMUP_S,
2829
- durationS: SWEEP_DURATION_S,
3045
+ durationS: sweepDurationS(requested.preset),
2830
3046
  crop: requested.crop ?? null,
2831
3047
  frame: spec.frame,
2832
- kymographRow: { row: spec.kymograph.row, at: spec.kymograph.at },
3048
+ kymographRow: spec.kymograph ? { row: spec.kymograph.row, at: spec.kymograph.at } : null,
2833
3049
  sheet: { frames: spec.sheet.frames, cell: spec.sheet.cell },
2834
3050
  physicsOutputs: spec.physicsOutputs,
2835
3051
  frames
@@ -2846,9 +3062,10 @@ async function captureSweep(evaluate, model, plan, requested, dir, report) {
2846
3062
  frames: spec.frames,
2847
3063
  manifest: manifestPath,
2848
3064
  sheet,
2849
- kymograph,
3065
+ ...kymograph ? { kymograph } : {},
2850
3066
  flipbook,
2851
- report
3067
+ report,
3068
+ nod
2852
3069
  };
2853
3070
  }
2854
3071
  async function renderPoses(input) {
@@ -2861,7 +3078,7 @@ async function renderPoses(input) {
2861
3078
  );
2862
3079
  const outDir = resolveOutputDir(input.outDir);
2863
3080
  const model = (0, import_format8.loadIkiModel)((0, import_node_fs4.readFileSync)(modelFile, "utf8"));
2864
- const plan = planRenders(model, input.poses, input.sweep);
3081
+ const plan = planRenders(model, input.poses, input.sweep, input.sweeps);
2865
3082
  const browser = findBrowser();
2866
3083
  if (!browser) return { ok: false, error: NO_BROWSER_MESSAGE };
2867
3084
  const pageScript = readPageScript();
@@ -2870,9 +3087,16 @@ async function renderPoses(input) {
2870
3087
  input.poses?.map((p) => p.values)
2871
3088
  );
2872
3089
  const physics = checkPhysics(model);
2873
- const sweepDir = input.sweep ? prepareSweepDir(outDir, input.sweep.name) : void 0;
2874
- const sweepReport = input.sweep ? checkSweep(model) : void 0;
2875
- const { failedTextures, poses, sweep } = await withBrowser(
3090
+ const sweepDir = input.sweep ? prepareSweepDir(outDir, input.sweep.name, "sweep") : void 0;
3091
+ const sweepsDirs = input.sweeps?.map(
3092
+ (s, i) => prepareSweepDir(outDir, s.name, `sweeps[${i}]`)
3093
+ );
3094
+ for (const d of [sweepDir, ...sweepsDirs ?? []]) {
3095
+ if (d) clearSweepDir(d);
3096
+ }
3097
+ const sweepReport = input.sweep || input.sweeps ? checkSweep(model) : void 0;
3098
+ const nodReport = input.sweep || input.sweeps ? checkNod(model) : void 0;
3099
+ const { failedTextures, poses, sweep, sweeps } = await withBrowser(
2876
3100
  browser,
2877
3101
  async (evaluate) => {
2878
3102
  await evaluate(pageScript, PAGE_SCRIPT_MS);
@@ -2896,15 +3120,38 @@ async function renderPoses(input) {
2896
3120
  );
2897
3121
  written.push({ name: pose.name, path: file });
2898
3122
  }
2899
- const sweep2 = input.sweep && sweepDir && sweepReport ? await captureSweep(
3123
+ const sweep2 = input.sweep && sweepDir && sweepReport && nodReport ? await captureSweep(
2900
3124
  evaluate,
2901
3125
  model,
2902
- plan,
2903
3126
  input.sweep,
3127
+ plan.sweepCrop,
2904
3128
  sweepDir,
2905
- sweepReport
3129
+ sweepReport,
3130
+ nodReport
2906
3131
  ) : void 0;
2907
- return { failedTextures: loaded.failedTextures, poses: written, sweep: sweep2 };
3132
+ let sweeps2;
3133
+ if (input.sweeps && sweepsDirs && sweepReport && nodReport) {
3134
+ sweeps2 = [];
3135
+ for (const [i, requested] of input.sweeps.entries()) {
3136
+ sweeps2.push(
3137
+ await captureSweep(
3138
+ evaluate,
3139
+ model,
3140
+ requested,
3141
+ plan.sweepsCrops?.[i],
3142
+ sweepsDirs[i],
3143
+ sweepReport,
3144
+ nodReport
3145
+ )
3146
+ );
3147
+ }
3148
+ }
3149
+ return {
3150
+ failedTextures: loaded.failedTextures,
3151
+ poses: written,
3152
+ sweep: sweep2,
3153
+ sweeps: sweeps2
3154
+ };
2908
3155
  }
2909
3156
  );
2910
3157
  return {
@@ -2918,7 +3165,8 @@ async function renderPoses(input) {
2918
3165
  modelCanvas: model.canvas,
2919
3166
  folds,
2920
3167
  physics,
2921
- sweep
3168
+ sweep,
3169
+ sweeps
2922
3170
  };
2923
3171
  } catch (error) {
2924
3172
  if (error instanceof AutoRigInputError || error instanceof import_format8.IkiFormatError) {
@@ -6179,7 +6427,7 @@ function formatPatchReports(reports) {
6179
6427
  });
6180
6428
  }
6181
6429
  function createIkiMcpServer() {
6182
- const server = new import_mcp.McpServer({ name: "iki", version: "0.31.1" });
6430
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.32.0" });
6183
6431
  server.registerTool(
6184
6432
  "validate_iki",
6185
6433
  {
@@ -6477,7 +6725,7 @@ function createIkiMcpServer() {
6477
6725
  server.registerTool(
6478
6726
  "render_poses",
6479
6727
  {
6480
- 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.",
6728
+ 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.",
6481
6729
  inputSchema: {
6482
6730
  modelPath: import_zod.z.string().describe(
6483
6731
  "Rigged .iki file path (resolved against cwd; must sit under the working directory)."
@@ -6509,7 +6757,21 @@ function createIkiMcpServer() {
6509
6757
  h: import_zod.z.number()
6510
6758
  }).optional()
6511
6759
  }).optional().describe(
6512
- "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`."
6760
+ "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."
6761
+ ),
6762
+ sweeps: import_zod.z.array(
6763
+ import_zod.z.object({
6764
+ name: import_zod.z.string(),
6765
+ preset: import_zod.z.enum(SWEEP_PRESETS),
6766
+ crop: import_zod.z.object({
6767
+ x: import_zod.z.number(),
6768
+ y: import_zod.z.number(),
6769
+ w: import_zod.z.number(),
6770
+ h: import_zod.z.number()
6771
+ }).optional()
6772
+ })
6773
+ ).optional().describe(
6774
+ "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`."
6513
6775
  )
6514
6776
  }
6515
6777
  },
@@ -6518,16 +6780,21 @@ function createIkiMcpServer() {
6518
6780
  const r = await renderPoses(args);
6519
6781
  const text = r.ok ? [
6520
6782
  ...r.poses.map((p) => p.path),
6521
- ...r.sweep ? [
6522
- r.sweep.dir,
6523
- r.sweep.sheet,
6524
- r.sweep.kymograph,
6525
- r.sweep.flipbook,
6526
- r.sweep.manifest
6527
- ] : [],
6783
+ ...[...r.sweep ? [r.sweep] : [], ...r.sweeps ?? []].flatMap(
6784
+ (w) => [
6785
+ w.dir,
6786
+ w.sheet,
6787
+ ...w.kymograph ? [w.kymograph] : [],
6788
+ w.flipbook,
6789
+ w.manifest
6790
+ ]
6791
+ ),
6528
6792
  ...formatFoldReport(r.folds, r.modelCanvas),
6529
6793
  ...formatPhysicsReport(r.physics),
6530
- ...r.sweep ? formatSweepReport(r.sweep.report) : []
6794
+ ...r.sweep ?? r.sweeps?.[0] ? [
6795
+ ...formatSweepReport((r.sweep ?? r.sweeps[0]).report),
6796
+ ...formatNodReport((r.sweep ?? r.sweeps[0]).nod)
6797
+ ] : []
6531
6798
  ].join("\n") : `INVALID: ${r.error}`;
6532
6799
  return { content: [{ type: "text", text }], structuredContent: r };
6533
6800
  } catch (err) {
@@ -6544,8 +6811,10 @@ function createIkiMcpServer() {
6544
6811
  }
6545
6812
  // Annotate the CommonJS export names for ESM import in node:
6546
6813
  0 && (module.exports = {
6814
+ SWEEP_PRESETS,
6547
6815
  autoRigFromLayers,
6548
6816
  checkModelFolds,
6817
+ checkNod,
6549
6818
  checkSweep,
6550
6819
  composeLayersFromParts,
6551
6820
  createIkiMcpServer,
@@ -6554,6 +6823,7 @@ function createIkiMcpServer() {
6554
6823
  describeRigPlan,
6555
6824
  formatFoldReport,
6556
6825
  formatMeasureReport,
6826
+ formatNodReport,
6557
6827
  formatPhysicsReport,
6558
6828
  formatRigPlanReport,
6559
6829
  formatSweepReport,