@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/cli.js CHANGED
@@ -2236,6 +2236,83 @@ function pop(v) {
2236
2236
  }
2237
2237
  return most / mean;
2238
2238
  }
2239
+ var NOD_TURNS = [-30, 0, 30];
2240
+ var NOD_PARTS = [
2241
+ "face",
2242
+ "eye_L",
2243
+ "eye_R",
2244
+ "iris_L",
2245
+ "iris_R",
2246
+ "nose",
2247
+ "lip_upper",
2248
+ "mouth"
2249
+ ];
2250
+ var NOD_ENDS = [0, -LADDER_MIN, LADDER_MAX - LADDER_MIN];
2251
+ function checkNod(model) {
2252
+ const face = model.parts.find((p) => p.id === "face");
2253
+ if (!face) return { unavailable: "no face part" };
2254
+ const hasEyes = ["eye_L", "eye_R"].every(
2255
+ (id) => model.parts.some((p) => p.id === id)
2256
+ );
2257
+ if (!hasEyes) return { unavailable: "no eye_L and eye_R parts" };
2258
+ const fw = face.width;
2259
+ const ladders = NOD_TURNS.map(
2260
+ (x) => Array.from(
2261
+ { length: LADDER_MAX - LADDER_MIN + 1 },
2262
+ (_, i) => landParts(
2263
+ model,
2264
+ { ParamAngleX: x, ParamAngleY: LADDER_MIN + i },
2265
+ NOD_PARTS
2266
+ )
2267
+ )
2268
+ );
2269
+ const has = (id) => ladders[0][0].has(id);
2270
+ const boxes = (id) => ladders.map((ladder) => ladder.map((l) => box(l.get(id), fw)));
2271
+ const spread = (v) => Math.max(...v) - Math.min(...v);
2272
+ const ranges = (values) => {
2273
+ const [m30, zero, p30] = NOD_TURNS.map(
2274
+ (_, b) => spread(
2275
+ Array.from(
2276
+ { length: LADDER_MAX - LADDER_MIN + 1 },
2277
+ (_2, i) => values(b, i)
2278
+ )
2279
+ )
2280
+ );
2281
+ return { m30, zero, p30 };
2282
+ };
2283
+ const gap = (l, r) => {
2284
+ const bl = boxes(l);
2285
+ const br = boxes(r);
2286
+ return ranges((b, i) => br[b][i].x - bl[b][i].x);
2287
+ };
2288
+ const nod = [{ id: "eyes", range: gap("eye_L", "eye_R") }];
2289
+ if (has("iris_L") && has("iris_R")) {
2290
+ nod.push({ id: "irises", range: gap("iris_L", "iris_R") });
2291
+ }
2292
+ const mouthId = has("lip_upper") ? "lip_upper" : has("mouth") ? "mouth" : null;
2293
+ if (mouthId) {
2294
+ const bm = boxes(mouthId);
2295
+ nod.push({ id: "mouth", range: ranges((b, i) => bm[b][i].width) });
2296
+ }
2297
+ const corner = ["eye_L", "eye_R", "nose"].filter(has).map((id) => {
2298
+ const b = boxes(id);
2299
+ const at = (t, j) => b[t][NOD_ENDS[j]];
2300
+ const residual = (t, j) => {
2301
+ const r = (axis) => at(t, j)[axis] - at(t, 1)[axis] - at(1, j)[axis] + at(1, 1)[axis];
2302
+ return Math.max(Math.abs(r("x")), Math.abs(r("y")));
2303
+ };
2304
+ return {
2305
+ id,
2306
+ residual: {
2307
+ mm: residual(0, 0),
2308
+ mp: residual(0, 2),
2309
+ pm: residual(2, 0),
2310
+ pp: residual(2, 2)
2311
+ }
2312
+ };
2313
+ });
2314
+ return { unit: "fw", faceWidth: fw, nod, corner };
2315
+ }
2239
2316
  function checkSweep(model) {
2240
2317
  const face = model.parts.find((p) => p.id === "face");
2241
2318
  if (!face) return { preset: "turn", unavailable: "no face part" };
@@ -2305,6 +2382,19 @@ function formatSweepReport(report) {
2305
2382
  `SWEEP turn plate: amplitude ${fw3(report.plateAmplitude)} fw`
2306
2383
  ];
2307
2384
  }
2385
+ function formatNodReport(report) {
2386
+ if ("unavailable" in report) {
2387
+ return [`SWEEP nod: unavailable \u2014 ${report.unavailable}`];
2388
+ }
2389
+ return [
2390
+ ...report.nod.map(
2391
+ ({ 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`
2392
+ ),
2393
+ ...report.corner.map(
2394
+ ({ 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`
2395
+ )
2396
+ ];
2397
+ }
2308
2398
 
2309
2399
  // src/sweep.ts
2310
2400
  var import_node_fs3 = __toESM(require("fs"));
@@ -2312,6 +2402,8 @@ var import_node_path3 = __toESM(require("path"));
2312
2402
  var SWEEP_CLOCK_HZ = 60;
2313
2403
  var SWEEP_FPS = 30;
2314
2404
  var SWEEP_DURATION_S = 3;
2405
+ var BOX_DURATION_S = 6;
2406
+ var SWEEP_PRESETS = ["turn", "turn-nod"];
2315
2407
  var SWEEP_WARMUP_S = 0.5;
2316
2408
  var SWEEP_FRAME_MS = 1e3 / SWEEP_CLOCK_HZ * (1 + 1e-9);
2317
2409
  var SHEET_THETAS = [-30, -20, -10, -5, 0, 5, 10, 20, 30];
@@ -2319,16 +2411,75 @@ var SHEET_MAX_SIDE = 2e3;
2319
2411
  var SHEET_MARGIN = 8;
2320
2412
  var SHEET_LABEL_BAND = 24;
2321
2413
  var KYMOGRAPH_BAND = 3;
2322
- var SWEEP_PARAMETER = "ParamAngleX";
2323
- var STEPS = SWEEP_CLOCK_HZ * SWEEP_DURATION_S;
2324
2414
  var CAPTURE_EVERY = SWEEP_CLOCK_HZ / SWEEP_FPS;
2325
- var FRAMES = STEPS / CAPTURE_EVERY;
2326
2415
  var LEG_FROM_S = 0.75;
2327
2416
  var LEG_TO_S = 2.25;
2328
2417
  var AMPLITUDE_DEG = 30;
2418
+ var BOX_CORNERS = [
2419
+ [0, 0],
2420
+ [0, -30],
2421
+ [-30, -30],
2422
+ [-30, 30],
2423
+ [30, 30],
2424
+ [30, -30],
2425
+ [0, -30],
2426
+ [0, 0]
2427
+ ];
2428
+ var BOX_SPEED_DEG_S = 50;
2429
+ var BOX_SHEET_STOPS = [
2430
+ [-30, 30],
2431
+ [0, 30],
2432
+ [30, 30],
2433
+ [-30, 0],
2434
+ [0, 0],
2435
+ [30, 0],
2436
+ [-30, -30],
2437
+ [0, -30],
2438
+ [30, -30]
2439
+ ];
2329
2440
  function turnTheta(t) {
2330
2441
  return -AMPLITUDE_DEG * Math.sin(2 * Math.PI * t / SWEEP_DURATION_S);
2331
2442
  }
2443
+ function boxAngles(t) {
2444
+ let start = 0;
2445
+ for (let i = 0; i + 1 < BOX_CORNERS.length; i++) {
2446
+ const [fx, fy] = BOX_CORNERS[i];
2447
+ const [tx, ty] = BOX_CORNERS[i + 1];
2448
+ const len = Math.max(Math.abs(tx - fx), Math.abs(ty - fy));
2449
+ const dur = len / BOX_SPEED_DEG_S;
2450
+ if (t < start + dur) {
2451
+ const u = (t - start) / dur;
2452
+ const e = (1 - Math.cos(Math.PI * u)) / 2;
2453
+ return { x: fx + (tx - fx) * e, y: fy + (ty - fy) * e };
2454
+ }
2455
+ start += dur;
2456
+ }
2457
+ return { x: 0, y: 0 };
2458
+ }
2459
+ function sweepDurationS(preset) {
2460
+ return preset === "turn" ? SWEEP_DURATION_S : BOX_DURATION_S;
2461
+ }
2462
+ function schedule(preset) {
2463
+ const durationS = sweepDurationS(preset);
2464
+ const n = SWEEP_CLOCK_HZ * durationS;
2465
+ if (preset === "turn") {
2466
+ return {
2467
+ parameters: ["ParamAngleX"],
2468
+ steps: Array.from({ length: n }, (_, j) => ({
2469
+ ParamAngleX: turnTheta(j / SWEEP_CLOCK_HZ)
2470
+ })),
2471
+ durationS
2472
+ };
2473
+ }
2474
+ return {
2475
+ parameters: ["ParamAngleX", "ParamAngleY"],
2476
+ steps: Array.from({ length: n }, (_, j) => {
2477
+ const { x, y } = boxAngles(j / SWEEP_CLOCK_HZ);
2478
+ return { ParamAngleX: x, ParamAngleY: y };
2479
+ }),
2480
+ durationS
2481
+ };
2482
+ }
2332
2483
  function eyeRowModelPx(model) {
2333
2484
  const landed = landParts(model, {}, ["eye_L", "eye_R"]);
2334
2485
  const l = landed.get("eye_L");
@@ -2353,35 +2504,44 @@ function physicsOutputIds(model) {
2353
2504
  }
2354
2505
  return [...ids];
2355
2506
  }
2356
- function sheetFrames(thetas) {
2507
+ function turnSheetFrames(steps, frames) {
2357
2508
  const onLeg = [];
2358
- for (let k = 0; k < FRAMES; k++) {
2509
+ for (let k = 0; k < frames; k++) {
2359
2510
  const t = k / SWEEP_FPS;
2360
2511
  if (t >= LEG_FROM_S && t <= LEG_TO_S) onLeg.push(k);
2361
2512
  }
2513
+ const x = (k) => steps[CAPTURE_EVERY * k].ParamAngleX;
2362
2514
  const picked = [];
2363
2515
  for (const target2 of SHEET_THETAS) {
2364
2516
  let best = onLeg[0];
2365
2517
  for (const k of onLeg) {
2366
- if (Math.abs(thetas[CAPTURE_EVERY * k] - target2) < Math.abs(thetas[CAPTURE_EVERY * best] - target2)) {
2367
- best = k;
2368
- }
2518
+ if (Math.abs(x(k) - target2) < Math.abs(x(best) - target2)) best = k;
2369
2519
  }
2370
2520
  if (!picked.includes(best)) picked.push(best);
2371
2521
  }
2372
2522
  return picked.sort((a, b) => a - b);
2373
2523
  }
2374
- function sheetLabel(theta, t) {
2375
- const rounded = Math.round(theta * 10) / 10 + 0;
2524
+ function boxSheetFrames(steps, frames) {
2525
+ return BOX_SHEET_STOPS.map(([sx, sy]) => {
2526
+ const miss = (k) => {
2527
+ const s = steps[CAPTURE_EVERY * k];
2528
+ return Math.abs(s.ParamAngleX - sx) + Math.abs(s.ParamAngleY - sy);
2529
+ };
2530
+ let best = 0;
2531
+ for (let k = 1; k < frames; k++) {
2532
+ if (miss(k) < miss(best)) best = k;
2533
+ }
2534
+ return best;
2535
+ });
2536
+ }
2537
+ function signedDeg(angle) {
2538
+ const rounded = Math.round(angle * 10) / 10 + 0;
2376
2539
  const deg = rounded.toFixed(1);
2377
- const signed2 = rounded > 0 ? `+${deg}` : deg.replace("-", "\u2212");
2378
- return `\u03B8 ${signed2}\xB0 t ${t.toFixed(2)} s`;
2540
+ return rounded > 0 ? `+${deg}` : deg.replace("-", "\u2212");
2379
2541
  }
2380
- function sweepSpec(model, crop) {
2381
- const thetas = Array.from(
2382
- { length: STEPS },
2383
- (_, j) => turnTheta(j / SWEEP_CLOCK_HZ)
2384
- );
2542
+ function sweepSpec(model, preset, crop) {
2543
+ const { parameters, steps, durationS } = schedule(preset);
2544
+ const frameCount = durationS * SWEEP_FPS;
2385
2545
  const dw = crop ? crop.dw : BUST_SIZE;
2386
2546
  const dh = crop ? crop.dh : BUST_SIZE;
2387
2547
  const m = SHEET_MARGIN;
@@ -2391,29 +2551,38 @@ function sweepSpec(model, crop) {
2391
2551
  (SHEET_MAX_SIDE - 2 * m) / (3 * dw),
2392
2552
  (SHEET_MAX_SIDE - 2 * m - 3 * b) / (3 * dh)
2393
2553
  );
2394
- const frames = sheetFrames(thetas);
2554
+ const frames = preset === "turn" ? turnSheetFrames(steps, frameCount) : boxSheetFrames(steps, frameCount);
2555
+ const labelOf = (k) => {
2556
+ const s = steps[CAPTURE_EVERY * k];
2557
+ const t = (k / SWEEP_FPS).toFixed(2);
2558
+ return preset === "turn" ? `\u03B8 ${signedDeg(s.ParamAngleX)}\xB0 t ${t} s` : `X ${signedDeg(s.ParamAngleX)}\xB0 Y ${signedDeg(s.ParamAngleY)}\xB0 t ${t} s`;
2559
+ };
2395
2560
  const { width: W, height: H } = model.canvas;
2396
- const yModel = eyeRowModelPx(model);
2397
- let row = Math.round(dh / 2);
2398
- let at = "middle";
2399
- if (yModel !== void 0) {
2400
- const y0 = bustPadY(W, H);
2401
- const s = BUST_SIZE / W;
2402
- const eyeRow = Math.round(
2403
- crop ? (y0 + yModel * s - crop.sy) * crop.dh / crop.sh : y0 + yModel * s
2404
- );
2405
- if (eyeRow >= 1 && eyeRow <= dh - 2) {
2406
- row = eyeRow;
2407
- at = "eye row";
2561
+ let kymograph;
2562
+ if (preset === "turn") {
2563
+ const yModel = eyeRowModelPx(model);
2564
+ let row = Math.round(dh / 2);
2565
+ let at = "middle";
2566
+ if (yModel !== void 0) {
2567
+ const y0 = bustPadY(W, H);
2568
+ const s = BUST_SIZE / W;
2569
+ const eyeRow = Math.round(
2570
+ crop ? (y0 + yModel * s - crop.sy) * crop.dh / crop.sh : y0 + yModel * s
2571
+ );
2572
+ if (eyeRow >= 1 && eyeRow <= dh - 2) {
2573
+ row = eyeRow;
2574
+ at = "eye row";
2575
+ }
2408
2576
  }
2577
+ kymograph = { row, band: KYMOGRAPH_BAND, at };
2409
2578
  }
2410
2579
  return {
2411
- parameter: SWEEP_PARAMETER,
2580
+ parameters,
2412
2581
  frameMs: SWEEP_FRAME_MS,
2413
2582
  warmup: SWEEP_WARMUP_S * SWEEP_CLOCK_HZ,
2414
- thetas,
2583
+ steps,
2415
2584
  captureEvery: CAPTURE_EVERY,
2416
- frames: FRAMES,
2585
+ frames: frameCount,
2417
2586
  frame: { width: dw, height: dh },
2418
2587
  physicsOutputs: physicsOutputIds(model),
2419
2588
  sheet: {
@@ -2424,11 +2593,9 @@ function sweepSpec(model, crop) {
2424
2593
  },
2425
2594
  margin: m,
2426
2595
  labelBand: b,
2427
- labels: frames.map(
2428
- (k) => sheetLabel(thetas[CAPTURE_EVERY * k], k / SWEEP_FPS)
2429
- )
2596
+ labels: frames.map(labelOf)
2430
2597
  },
2431
- kymograph: { row, band: KYMOGRAPH_BAND, at },
2598
+ kymograph,
2432
2599
  crop
2433
2600
  };
2434
2601
  }
@@ -2438,7 +2605,7 @@ function flipbookHtml(manifest) {
2438
2605
  <html lang="en">
2439
2606
  <head>
2440
2607
  <meta charset="utf-8">
2441
- <title>turn sweep</title>
2608
+ <title>${manifest.preset} sweep</title>
2442
2609
  <style>
2443
2610
  body { font: 14px system-ui, sans-serif; margin: 16px; background: #222; color: #eee; }
2444
2611
  .row { display: flex; gap: 16px; align-items: flex-start; }
@@ -2471,13 +2638,18 @@ img { max-width: 48vw; height: auto; background: #444; }
2471
2638
  var playing = true;
2472
2639
  scrub.max = String(n - 1);
2473
2640
  if (b) { bi.style.display = "block"; }
2641
+ function short(id) {
2642
+ return id === "ParamAngleX" ? "X" : id === "ParamAngleY" ? "Y" : id;
2643
+ }
2474
2644
  function show(k) {
2475
2645
  i = k;
2476
2646
  var f = m.frames[k];
2477
2647
  a.src = f.file;
2478
2648
  if (b) { bi.src = b.replace(/\\/$/, "") + "/" + f.file; }
2479
2649
  scrub.value = String(k);
2480
- readout.textContent = "frame " + k + " \\u03b8 " + f.theta.toFixed(1) + "\\u00b0 t " + f.t.toFixed(2) + " s";
2650
+ readout.textContent = "frame " + k + m.parameters.map(function (id) {
2651
+ return " " + short(id) + " " + f.values[id].toFixed(1) + "\\u00b0";
2652
+ }).join("") + " t " + f.t.toFixed(2) + " s";
2481
2653
  }
2482
2654
  play.addEventListener("click", function () {
2483
2655
  playing = !playing;
@@ -2496,7 +2668,14 @@ img { max-width: 48vw; height: auto; background: #444; }
2496
2668
  </html>
2497
2669
  `;
2498
2670
  }
2499
- function prepareSweepDir(outDir, name) {
2671
+ var STALE_FILE = /^f\d{3}\.png$/;
2672
+ var STALE_NAMES = [
2673
+ "kymograph.png",
2674
+ "sheet.png",
2675
+ "manifest.json",
2676
+ "index.html"
2677
+ ];
2678
+ function prepareSweepDir(outDir, name, label) {
2500
2679
  const dir = import_node_path3.default.join(outDir, name);
2501
2680
  try {
2502
2681
  import_node_fs3.default.mkdirSync(dir);
@@ -2507,13 +2686,19 @@ function prepareSweepDir(outDir, name) {
2507
2686
  }
2508
2687
  const stat = import_node_fs3.default.lstatSync(dir);
2509
2688
  if (stat.isSymbolicLink()) {
2510
- throw new AutoRigInputError(`sweep.name names ${dir}, a symbolic link`);
2689
+ throw new AutoRigInputError(`${label}.name names ${dir}, a symbolic link`);
2511
2690
  }
2512
2691
  if (!stat.isDirectory()) {
2513
- throw new AutoRigInputError(`sweep.name names ${dir}, not a directory`);
2692
+ throw new AutoRigInputError(`${label}.name names ${dir}, not a directory`);
2693
+ }
2694
+ return confineToWorkingDirectory(process.cwd(), dir, "sweep dir", name);
2695
+ }
2696
+ function clearSweepDir(real) {
2697
+ for (const entry of import_node_fs3.default.readdirSync(real)) {
2698
+ if (STALE_FILE.test(entry) || STALE_NAMES.includes(entry)) {
2699
+ import_node_fs3.default.rmSync(import_node_path3.default.join(real, entry));
2700
+ }
2514
2701
  }
2515
- const real = confineToWorkingDirectory(process.cwd(), dir, "sweep dir", name);
2516
- return real;
2517
2702
  }
2518
2703
 
2519
2704
  // src/render-poses.ts
@@ -2526,7 +2711,7 @@ var SWEEP_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
2526
2711
  function bustPadY(width, height) {
2527
2712
  return Math.max(0, (BUST_SIZE - BUST_SIZE * height / width) / 2);
2528
2713
  }
2529
- function planRenders(model, requested, sweep) {
2714
+ function planRenders(model, requested, sweep, sweeps) {
2530
2715
  const { width: W, height: H } = model.canvas;
2531
2716
  const fullBody = H > W;
2532
2717
  const canvas = fullBody ? {
@@ -2581,12 +2766,37 @@ function planRenders(model, requested, sweep) {
2581
2766
  dh
2582
2767
  };
2583
2768
  };
2584
- if (sweep && !SWEEP_NAME.test(sweep.name)) {
2585
- throw new AutoRigInputError(
2586
- `sweep.name must match ${SWEEP_NAME.source} (it names <outDir>/<name>/): ${JSON.stringify(sweep.name)}`
2587
- );
2769
+ if (sweeps && sweeps.length === 0) {
2770
+ throw new AutoRigInputError("sweeps is empty");
2588
2771
  }
2589
- const sweepCrop = sweep ? sweep.crop ? toRenderCrop(sweep.crop, "sweep.crop") : squareCrop : void 0;
2772
+ const asked = [
2773
+ ...sweep ? [{ label: "sweep", entry: sweep }] : [],
2774
+ ...(sweeps ?? []).map((entry, i) => ({ label: `sweeps[${i}]`, entry }))
2775
+ ];
2776
+ asked.forEach(({ label, entry }, i) => {
2777
+ if (!SWEEP_NAME.test(entry.name)) {
2778
+ throw new AutoRigInputError(
2779
+ `${label}.name must match ${SWEEP_NAME.source} (it names <outDir>/<name>/): ${JSON.stringify(entry.name)}`
2780
+ );
2781
+ }
2782
+ const sameName = asked.findIndex(
2783
+ (a) => a.entry.name.toLowerCase() === entry.name.toLowerCase()
2784
+ );
2785
+ if (sameName < i) {
2786
+ throw new AutoRigInputError(
2787
+ `${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)`
2788
+ );
2789
+ }
2790
+ const samePreset = asked.findIndex((a) => a.entry.preset === entry.preset);
2791
+ if (samePreset < i) {
2792
+ throw new AutoRigInputError(
2793
+ `${label}.preset ${JSON.stringify(entry.preset)} repeats ${asked[samePreset].label}.preset (the same frames twice)`
2794
+ );
2795
+ }
2796
+ });
2797
+ const cropOf = (entry, label) => entry.crop ? toRenderCrop(entry.crop, `${label}.crop`) : squareCrop;
2798
+ const sweepCrop = sweep ? cropOf(sweep, "sweep") : void 0;
2799
+ const sweepsCrops = sweeps?.map((entry, i) => cropOf(entry, `sweeps[${i}]`));
2590
2800
  if (requested) {
2591
2801
  if (requested.length === 0) throw new AutoRigInputError("poses is empty");
2592
2802
  const poses2 = requested.map((pose, i) => {
@@ -2598,7 +2808,7 @@ function planRenders(model, requested, sweep) {
2598
2808
  crop: toRenderCrop(pose.crop, `poses[${i}].crop`)
2599
2809
  };
2600
2810
  });
2601
- return { canvas, view, fullBody, mouth, poses: poses2, sweepCrop };
2811
+ return { canvas, view, fullBody, mouth, poses: poses2, sweepCrop, sweepsCrops };
2602
2812
  }
2603
2813
  const bodyAngles = Object.fromEntries(
2604
2814
  [
@@ -2706,7 +2916,7 @@ function planRenders(model, requested, sweep) {
2706
2916
  );
2707
2917
  }
2708
2918
  }
2709
- return { canvas, view, fullBody, mouth, poses, sweepCrop };
2919
+ return { canvas, view, fullBody, mouth, poses, sweepCrop, sweepsCrops };
2710
2920
  }
2711
2921
  function checkRequest(requested, i) {
2712
2922
  const { name, values } = requested[i];
@@ -2746,8 +2956,8 @@ function readPageScript() {
2746
2956
  );
2747
2957
  }
2748
2958
  }
2749
- async function captureSweep(evaluate, model, plan, requested, dir, report) {
2750
- const spec = sweepSpec(model, plan.sweepCrop);
2959
+ async function captureSweep(evaluate, model, requested, crop, dir, report, nod) {
2960
+ const spec = sweepSpec(model, requested.preset, crop);
2751
2961
  await evaluate(
2752
2962
  `window.__ikiRender.sweepBegin(${JSON.stringify(spec)})`,
2753
2963
  CAPTURE_MS
@@ -2772,12 +2982,12 @@ async function captureSweep(evaluate, model, plan, requested, dir, report) {
2772
2982
  i: k,
2773
2983
  file,
2774
2984
  t: k / SWEEP_FPS,
2775
- theta: spec.thetas[spec.captureEvery * k],
2776
2985
  values
2777
2986
  });
2778
2987
  }
2779
2988
  const end = await evaluate("window.__ikiRender.sweepEnd()", CAPTURE_MS);
2780
2989
  for (const [what, url] of Object.entries(end)) {
2990
+ if (url === void 0) continue;
2781
2991
  if (typeof url !== "string" || !url.startsWith(PNG_PREFIX)) {
2782
2992
  throw new Error(
2783
2993
  `sweep ${requested.name} ${what}: the page returned no PNG`
@@ -2785,26 +2995,29 @@ async function captureSweep(evaluate, model, plan, requested, dir, report) {
2785
2995
  }
2786
2996
  }
2787
2997
  const sheet = import_node_path4.default.join(dir, "sheet.png");
2788
- const kymograph = import_node_path4.default.join(dir, "kymograph.png");
2789
2998
  writeFileAtomic(
2790
2999
  sheet,
2791
3000
  Buffer.from(end.sheet.slice(PNG_PREFIX.length), "base64")
2792
3001
  );
2793
- writeFileAtomic(
2794
- kymograph,
2795
- Buffer.from(end.kymograph.slice(PNG_PREFIX.length), "base64")
2796
- );
3002
+ let kymograph;
3003
+ if (end.kymograph !== void 0) {
3004
+ kymograph = import_node_path4.default.join(dir, "kymograph.png");
3005
+ writeFileAtomic(
3006
+ kymograph,
3007
+ Buffer.from(end.kymograph.slice(PNG_PREFIX.length), "base64")
3008
+ );
3009
+ }
2797
3010
  const manifest = {
2798
- version: 1,
3011
+ version: 2,
2799
3012
  preset: requested.preset,
2800
- parameter: spec.parameter,
3013
+ parameters: spec.parameters,
2801
3014
  fps: SWEEP_FPS,
2802
3015
  clockHz: SWEEP_CLOCK_HZ,
2803
3016
  warmupS: SWEEP_WARMUP_S,
2804
- durationS: SWEEP_DURATION_S,
3017
+ durationS: sweepDurationS(requested.preset),
2805
3018
  crop: requested.crop ?? null,
2806
3019
  frame: spec.frame,
2807
- kymographRow: { row: spec.kymograph.row, at: spec.kymograph.at },
3020
+ kymographRow: spec.kymograph ? { row: spec.kymograph.row, at: spec.kymograph.at } : null,
2808
3021
  sheet: { frames: spec.sheet.frames, cell: spec.sheet.cell },
2809
3022
  physicsOutputs: spec.physicsOutputs,
2810
3023
  frames
@@ -2821,9 +3034,10 @@ async function captureSweep(evaluate, model, plan, requested, dir, report) {
2821
3034
  frames: spec.frames,
2822
3035
  manifest: manifestPath,
2823
3036
  sheet,
2824
- kymograph,
3037
+ ...kymograph ? { kymograph } : {},
2825
3038
  flipbook,
2826
- report
3039
+ report,
3040
+ nod
2827
3041
  };
2828
3042
  }
2829
3043
  async function renderPoses(input) {
@@ -2836,7 +3050,7 @@ async function renderPoses(input) {
2836
3050
  );
2837
3051
  const outDir = resolveOutputDir(input.outDir);
2838
3052
  const model = (0, import_format8.loadIkiModel)((0, import_node_fs4.readFileSync)(modelFile, "utf8"));
2839
- const plan = planRenders(model, input.poses, input.sweep);
3053
+ const plan = planRenders(model, input.poses, input.sweep, input.sweeps);
2840
3054
  const browser = findBrowser();
2841
3055
  if (!browser) return { ok: false, error: NO_BROWSER_MESSAGE };
2842
3056
  const pageScript = readPageScript();
@@ -2845,9 +3059,16 @@ async function renderPoses(input) {
2845
3059
  input.poses?.map((p) => p.values)
2846
3060
  );
2847
3061
  const physics = checkPhysics(model);
2848
- const sweepDir = input.sweep ? prepareSweepDir(outDir, input.sweep.name) : void 0;
2849
- const sweepReport = input.sweep ? checkSweep(model) : void 0;
2850
- const { failedTextures, poses, sweep } = await withBrowser(
3062
+ const sweepDir = input.sweep ? prepareSweepDir(outDir, input.sweep.name, "sweep") : void 0;
3063
+ const sweepsDirs = input.sweeps?.map(
3064
+ (s, i) => prepareSweepDir(outDir, s.name, `sweeps[${i}]`)
3065
+ );
3066
+ for (const d of [sweepDir, ...sweepsDirs ?? []]) {
3067
+ if (d) clearSweepDir(d);
3068
+ }
3069
+ const sweepReport = input.sweep || input.sweeps ? checkSweep(model) : void 0;
3070
+ const nodReport = input.sweep || input.sweeps ? checkNod(model) : void 0;
3071
+ const { failedTextures, poses, sweep, sweeps } = await withBrowser(
2851
3072
  browser,
2852
3073
  async (evaluate) => {
2853
3074
  await evaluate(pageScript, PAGE_SCRIPT_MS);
@@ -2871,15 +3092,38 @@ async function renderPoses(input) {
2871
3092
  );
2872
3093
  written.push({ name: pose.name, path: file });
2873
3094
  }
2874
- const sweep2 = input.sweep && sweepDir && sweepReport ? await captureSweep(
3095
+ const sweep2 = input.sweep && sweepDir && sweepReport && nodReport ? await captureSweep(
2875
3096
  evaluate,
2876
3097
  model,
2877
- plan,
2878
3098
  input.sweep,
3099
+ plan.sweepCrop,
2879
3100
  sweepDir,
2880
- sweepReport
3101
+ sweepReport,
3102
+ nodReport
2881
3103
  ) : void 0;
2882
- return { failedTextures: loaded.failedTextures, poses: written, sweep: sweep2 };
3104
+ let sweeps2;
3105
+ if (input.sweeps && sweepsDirs && sweepReport && nodReport) {
3106
+ sweeps2 = [];
3107
+ for (const [i, requested] of input.sweeps.entries()) {
3108
+ sweeps2.push(
3109
+ await captureSweep(
3110
+ evaluate,
3111
+ model,
3112
+ requested,
3113
+ plan.sweepsCrops?.[i],
3114
+ sweepsDirs[i],
3115
+ sweepReport,
3116
+ nodReport
3117
+ )
3118
+ );
3119
+ }
3120
+ }
3121
+ return {
3122
+ failedTextures: loaded.failedTextures,
3123
+ poses: written,
3124
+ sweep: sweep2,
3125
+ sweeps: sweeps2
3126
+ };
2883
3127
  }
2884
3128
  );
2885
3129
  return {
@@ -2893,7 +3137,8 @@ async function renderPoses(input) {
2893
3137
  modelCanvas: model.canvas,
2894
3138
  folds,
2895
3139
  physics,
2896
- sweep
3140
+ sweep,
3141
+ sweeps
2897
3142
  };
2898
3143
  } catch (error) {
2899
3144
  if (error instanceof AutoRigInputError || error instanceof import_format8.IkiFormatError) {
@@ -6152,7 +6397,7 @@ function formatPatchReports(reports) {
6152
6397
  });
6153
6398
  }
6154
6399
  function createIkiMcpServer() {
6155
- const server = new import_mcp.McpServer({ name: "iki", version: "0.31.1" });
6400
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.32.0" });
6156
6401
  server.registerTool(
6157
6402
  "validate_iki",
6158
6403
  {
@@ -6450,7 +6695,7 @@ function createIkiMcpServer() {
6450
6695
  server.registerTool(
6451
6696
  "render_poses",
6452
6697
  {
6453
- 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.",
6698
+ 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.",
6454
6699
  inputSchema: {
6455
6700
  modelPath: import_zod.z.string().describe(
6456
6701
  "Rigged .iki file path (resolved against cwd; must sit under the working directory)."
@@ -6482,7 +6727,21 @@ function createIkiMcpServer() {
6482
6727
  h: import_zod.z.number()
6483
6728
  }).optional()
6484
6729
  }).optional().describe(
6485
- "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`."
6730
+ "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."
6731
+ ),
6732
+ sweeps: import_zod.z.array(
6733
+ import_zod.z.object({
6734
+ name: import_zod.z.string(),
6735
+ preset: import_zod.z.enum(SWEEP_PRESETS),
6736
+ crop: import_zod.z.object({
6737
+ x: import_zod.z.number(),
6738
+ y: import_zod.z.number(),
6739
+ w: import_zod.z.number(),
6740
+ h: import_zod.z.number()
6741
+ }).optional()
6742
+ })
6743
+ ).optional().describe(
6744
+ "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`."
6486
6745
  )
6487
6746
  }
6488
6747
  },
@@ -6491,16 +6750,21 @@ function createIkiMcpServer() {
6491
6750
  const r = await renderPoses(args);
6492
6751
  const text = r.ok ? [
6493
6752
  ...r.poses.map((p) => p.path),
6494
- ...r.sweep ? [
6495
- r.sweep.dir,
6496
- r.sweep.sheet,
6497
- r.sweep.kymograph,
6498
- r.sweep.flipbook,
6499
- r.sweep.manifest
6500
- ] : [],
6753
+ ...[...r.sweep ? [r.sweep] : [], ...r.sweeps ?? []].flatMap(
6754
+ (w) => [
6755
+ w.dir,
6756
+ w.sheet,
6757
+ ...w.kymograph ? [w.kymograph] : [],
6758
+ w.flipbook,
6759
+ w.manifest
6760
+ ]
6761
+ ),
6501
6762
  ...formatFoldReport(r.folds, r.modelCanvas),
6502
6763
  ...formatPhysicsReport(r.physics),
6503
- ...r.sweep ? formatSweepReport(r.sweep.report) : []
6764
+ ...r.sweep ?? r.sweeps?.[0] ? [
6765
+ ...formatSweepReport((r.sweep ?? r.sweeps[0]).report),
6766
+ ...formatNodReport((r.sweep ?? r.sweeps[0]).nod)
6767
+ ] : []
6504
6768
  ].join("\n") : `INVALID: ${r.error}`;
6505
6769
  return { content: [{ type: "text", text }], structuredContent: r };
6506
6770
  } catch (err) {