@ikijs/mcp 0.30.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -32,6 +32,7 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  autoRigFromLayers: () => autoRigFromLayers,
34
34
  checkModelFolds: () => checkModelFolds,
35
+ checkSweep: () => checkSweep,
35
36
  composeLayersFromParts: () => composeLayersFromParts,
36
37
  createIkiMcpServer: () => createIkiMcpServer,
37
38
  describeIki: () => describeIki,
@@ -41,6 +42,7 @@ __export(index_exports, {
41
42
  formatMeasureReport: () => formatMeasureReport,
42
43
  formatPhysicsReport: () => formatPhysicsReport,
43
44
  formatRigPlanReport: () => formatRigPlanReport,
45
+ formatSweepReport: () => formatSweepReport,
44
46
  formatTurnReport: () => formatTurnReport,
45
47
  listStandardParameters: () => listStandardParameters,
46
48
  measureLayers: () => measureLayers,
@@ -55,8 +57,8 @@ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${_
55
57
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
56
58
 
57
59
  // src/tools.ts
58
- var import_node_fs4 = require("fs");
59
- var import_node_path4 = __toESM(require("path"));
60
+ var import_node_fs5 = require("fs");
61
+ var import_node_path5 = __toESM(require("path"));
60
62
  var import_format9 = require("@ikijs/format");
61
63
  var import_editor3 = require("@ikijs/editor");
62
64
 
@@ -1016,6 +1018,7 @@ var HEAD_AND_GAZE = /* @__PURE__ */ new Set([
1016
1018
  var import_format6 = require("@ikijs/format");
1017
1019
 
1018
1020
  // ../engine/src/land.ts
1021
+ var UNIT_QUAD = [-0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5];
1019
1022
  function staticDeformers(model) {
1020
1023
  return (model.deformers ?? []).map(
1021
1024
  (d) => d.kind === "warp" ? { ...d, warps: void 0, warp2d: void 0 } : { ...d, bindings: void 0 }
@@ -1068,6 +1071,28 @@ function landPart(landing, store, { worlds, grids }) {
1068
1071
  }
1069
1072
  return landed;
1070
1073
  }
1074
+ function landParts(model, values, partIds) {
1075
+ const deformers = model.deformers ?? [];
1076
+ const restStore = new ParameterStore(model.parameters);
1077
+ const store = new ParameterStore(model.parameters);
1078
+ for (const [id, value] of Object.entries(values)) store.set(id, value);
1079
+ const { worlds } = resolveDeformers(staticDeformers(model), restStore);
1080
+ const resolved = resolveDeformers(deformers, store);
1081
+ const out = /* @__PURE__ */ new Map();
1082
+ for (const id of partIds) {
1083
+ const part = model.parts.find((p) => p.id === id);
1084
+ if (!part) continue;
1085
+ const landing = landedPart(
1086
+ part,
1087
+ part.mesh?.vertices ?? UNIT_QUAD,
1088
+ deformers,
1089
+ worlds,
1090
+ restStore
1091
+ );
1092
+ out.set(id, Float32Array.from(landPart(landing, store, resolved)));
1093
+ }
1094
+ return out;
1095
+ }
1071
1096
 
1072
1097
  // ../engine/src/folds.ts
1073
1098
  var FLIP = 0;
@@ -1469,7 +1494,6 @@ function stopsOf(model, parameter) {
1469
1494
  var DISPLACEMENT_PX = 1;
1470
1495
  var PINNED_FRAMES = 60;
1471
1496
  var TOLERANCE = 1e-9;
1472
- var UNIT_QUAD = [-0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5];
1473
1497
  function checkPhysics(model) {
1474
1498
  const idle = idleRun(model);
1475
1499
  const displace = displacer(model);
@@ -1756,8 +1780,8 @@ function ratioText(ratio) {
1756
1780
  }
1757
1781
 
1758
1782
  // src/render-poses.ts
1759
- var import_node_fs3 = require("fs");
1760
- var import_node_path3 = __toESM(require("path"));
1783
+ var import_node_fs4 = require("fs");
1784
+ var import_node_path4 = __toESM(require("path"));
1761
1785
  var import_format8 = require("@ikijs/format");
1762
1786
 
1763
1787
  // src/limits.ts
@@ -2183,16 +2207,351 @@ async function withBrowser(executable, fn) {
2183
2207
  }
2184
2208
  }
2185
2209
 
2210
+ // src/sweep-report.ts
2211
+ var LADDER_MIN = -30;
2212
+ var LADDER_MAX = 30;
2213
+ var ZERO = -LADDER_MIN;
2214
+ var FLAT_SLOPE = 1e-4;
2215
+ var PARTS = ["face", "eye_L", "eye_R", "nose"];
2216
+ function box(pts, fw) {
2217
+ let x0 = Infinity;
2218
+ let x1 = -Infinity;
2219
+ let y0 = Infinity;
2220
+ let y1 = -Infinity;
2221
+ for (let i = 0; i < pts.length; i += 2) {
2222
+ x0 = Math.min(x0, pts[i]);
2223
+ x1 = Math.max(x1, pts[i]);
2224
+ y0 = Math.min(y0, pts[i + 1]);
2225
+ y1 = Math.max(y1, pts[i + 1]);
2226
+ }
2227
+ return {
2228
+ x: (x0 + x1) / 2 / fw,
2229
+ width: (x1 - x0) / fw,
2230
+ y: (y0 + y1) / 2 / fw
2231
+ };
2232
+ }
2233
+ function nearestVertex(face, fw, x, y) {
2234
+ let best = 0;
2235
+ let bestD = Infinity;
2236
+ for (let i = 0; i < face.length; i += 2) {
2237
+ const d = (face[i] / fw - x) ** 2 + (face[i + 1] / fw - y) ** 2;
2238
+ if (d < bestD) {
2239
+ bestD = d;
2240
+ best = i / 2;
2241
+ }
2242
+ }
2243
+ return best;
2244
+ }
2245
+ function kink(v) {
2246
+ const sMinus = (v[ZERO] - v[ZERO - 5]) / 5;
2247
+ const sPlus = (v[ZERO + 5] - v[ZERO]) / 5;
2248
+ const big = Math.max(Math.abs(sMinus), Math.abs(sPlus));
2249
+ if (big < FLAT_SLOPE) return null;
2250
+ return Math.abs(sPlus - sMinus) / big;
2251
+ }
2252
+ function pop(v) {
2253
+ let steps = 0;
2254
+ for (let i = 0; i + 1 < v.length; i++) steps += Math.abs(v[i + 1] - v[i]);
2255
+ const mean = steps / (v.length - 1);
2256
+ if (mean < 1e-9) return null;
2257
+ let most = 0;
2258
+ for (let i = 1; i + 1 < v.length; i++) {
2259
+ if (Math.abs(i - ZERO) <= 1) continue;
2260
+ most = Math.max(most, Math.abs(v[i + 1] - 2 * v[i] + v[i - 1]));
2261
+ }
2262
+ return most / mean;
2263
+ }
2264
+ function checkSweep(model) {
2265
+ const face = model.parts.find((p) => p.id === "face");
2266
+ if (!face) return { preset: "turn", unavailable: "no face part" };
2267
+ const hasEyes = ["eye_L", "eye_R"].every(
2268
+ (id) => model.parts.some((p) => p.id === id)
2269
+ );
2270
+ if (!hasEyes) {
2271
+ return { preset: "turn", unavailable: "no eye_L and eye_R parts" };
2272
+ }
2273
+ const fw = face.width;
2274
+ const ladder = Array.from(
2275
+ { length: LADDER_MAX - LADDER_MIN + 1 },
2276
+ (_, i) => landParts(model, { ParamAngleX: LADDER_MIN + i }, PARTS)
2277
+ );
2278
+ const at = (id, i) => ladder[i].get(id);
2279
+ const ids = ["eye_L", "eye_R", ...ladder[0].has("nose") ? ["nose"] : []];
2280
+ const landmarks = ids.map((id) => {
2281
+ const boxes = ladder.map((_, i) => box(at(id, i), fw));
2282
+ const xs = boxes.map((b) => b.x);
2283
+ const plateIndex2 = nearestVertex(
2284
+ at("face", ZERO),
2285
+ fw,
2286
+ boxes[ZERO].x,
2287
+ boxes[ZERO].y
2288
+ );
2289
+ const plate = ladder.map((_, i) => at("face", i)[plateIndex2 * 2] / fw);
2290
+ const lead = (i) => xs[i] - plate[i] - (xs[ZERO] - plate[ZERO]);
2291
+ return {
2292
+ id,
2293
+ amplitude: xs[xs.length - 1] - xs[0],
2294
+ xKink: kink(xs),
2295
+ widthKink: id === "nose" ? null : kink(boxes.map((b) => b.width)),
2296
+ lead: { m30: lead(0), p30: lead(xs.length - 1) },
2297
+ pop: pop(xs)
2298
+ };
2299
+ });
2300
+ const eyes = ["eye_L", "eye_R"].map((id) => box(at(id, ZERO), fw));
2301
+ const plateIndex = nearestVertex(
2302
+ at("face", ZERO),
2303
+ fw,
2304
+ (eyes[0].x + eyes[1].x) / 2,
2305
+ (eyes[0].y + eyes[1].y) / 2
2306
+ );
2307
+ const plateX = (i) => at("face", i)[plateIndex * 2] / fw;
2308
+ return {
2309
+ preset: "turn",
2310
+ unit: "fw",
2311
+ faceWidth: fw,
2312
+ plateAmplitude: plateX(ladder.length - 1) - plateX(0),
2313
+ landmarks
2314
+ };
2315
+ }
2316
+ var fw3 = (v) => {
2317
+ const s = v.toFixed(3);
2318
+ return s === "-0.000" ? "0.000" : s;
2319
+ };
2320
+ var signed = (v) => fw3(v).startsWith("-") ? fw3(v) : `+${fw3(v)}`;
2321
+ var two = (v) => v === null ? "n/a" : v.toFixed(2);
2322
+ function formatSweepReport(report) {
2323
+ if ("unavailable" in report) {
2324
+ return [`SWEEP: unavailable \u2014 ${report.unavailable}`];
2325
+ }
2326
+ return [
2327
+ ...report.landmarks.map(
2328
+ (l) => `SWEEP turn ${l.id}: amplitude ${fw3(l.amplitude)} fw, x kink ${two(l.xKink)}, width kink ${two(l.widthKink)}, lead -30 ${signed(l.lead.m30)} fw / +30 ${signed(l.lead.p30)} fw, pop ${two(l.pop)}`
2329
+ ),
2330
+ `SWEEP turn plate: amplitude ${fw3(report.plateAmplitude)} fw`
2331
+ ];
2332
+ }
2333
+
2334
+ // src/sweep.ts
2335
+ var import_node_fs3 = __toESM(require("fs"));
2336
+ var import_node_path3 = __toESM(require("path"));
2337
+ var SWEEP_CLOCK_HZ = 60;
2338
+ var SWEEP_FPS = 30;
2339
+ var SWEEP_DURATION_S = 3;
2340
+ var SWEEP_WARMUP_S = 0.5;
2341
+ var SWEEP_FRAME_MS = 1e3 / SWEEP_CLOCK_HZ * (1 + 1e-9);
2342
+ var SHEET_THETAS = [-30, -20, -10, -5, 0, 5, 10, 20, 30];
2343
+ var SHEET_MAX_SIDE = 2e3;
2344
+ var SHEET_MARGIN = 8;
2345
+ var SHEET_LABEL_BAND = 24;
2346
+ var KYMOGRAPH_BAND = 3;
2347
+ var SWEEP_PARAMETER = "ParamAngleX";
2348
+ var STEPS = SWEEP_CLOCK_HZ * SWEEP_DURATION_S;
2349
+ var CAPTURE_EVERY = SWEEP_CLOCK_HZ / SWEEP_FPS;
2350
+ var FRAMES = STEPS / CAPTURE_EVERY;
2351
+ var LEG_FROM_S = 0.75;
2352
+ var LEG_TO_S = 2.25;
2353
+ var AMPLITUDE_DEG = 30;
2354
+ function turnTheta(t) {
2355
+ return -AMPLITUDE_DEG * Math.sin(2 * Math.PI * t / SWEEP_DURATION_S);
2356
+ }
2357
+ function eyeRowModelPx(model) {
2358
+ const landed = landParts(model, {}, ["eye_L", "eye_R"]);
2359
+ const l = landed.get("eye_L");
2360
+ const r = landed.get("eye_R");
2361
+ if (!l || !r) return void 0;
2362
+ const centreY = (pts) => {
2363
+ let lo = Infinity;
2364
+ let hi = -Infinity;
2365
+ for (let i = 1; i < pts.length; i += 2) {
2366
+ lo = Math.min(lo, pts[i]);
2367
+ hi = Math.max(hi, pts[i]);
2368
+ }
2369
+ return (lo + hi) / 2;
2370
+ };
2371
+ return model.canvas.height / 2 - (centreY(l) + centreY(r)) / 2;
2372
+ }
2373
+ function physicsOutputIds(model) {
2374
+ const ids = /* @__PURE__ */ new Set();
2375
+ for (const rig of model.physics ?? []) ids.add(rig.output.parameter);
2376
+ for (const chain of model.physicsChains ?? []) {
2377
+ for (const seg of chain.segments) ids.add(seg.output.parameter);
2378
+ }
2379
+ return [...ids];
2380
+ }
2381
+ function sheetFrames(thetas) {
2382
+ const onLeg = [];
2383
+ for (let k = 0; k < FRAMES; k++) {
2384
+ const t = k / SWEEP_FPS;
2385
+ if (t >= LEG_FROM_S && t <= LEG_TO_S) onLeg.push(k);
2386
+ }
2387
+ const picked = [];
2388
+ for (const target2 of SHEET_THETAS) {
2389
+ let best = onLeg[0];
2390
+ 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
+ }
2394
+ }
2395
+ if (!picked.includes(best)) picked.push(best);
2396
+ }
2397
+ return picked.sort((a, b) => a - b);
2398
+ }
2399
+ function sheetLabel(theta, t) {
2400
+ const rounded = Math.round(theta * 10) / 10 + 0;
2401
+ const deg = rounded.toFixed(1);
2402
+ const signed2 = rounded > 0 ? `+${deg}` : deg.replace("-", "\u2212");
2403
+ return `\u03B8 ${signed2}\xB0 t ${t.toFixed(2)} s`;
2404
+ }
2405
+ function sweepSpec(model, crop) {
2406
+ const thetas = Array.from(
2407
+ { length: STEPS },
2408
+ (_, j) => turnTheta(j / SWEEP_CLOCK_HZ)
2409
+ );
2410
+ const dw = crop ? crop.dw : BUST_SIZE;
2411
+ const dh = crop ? crop.dh : BUST_SIZE;
2412
+ const m = SHEET_MARGIN;
2413
+ const b = SHEET_LABEL_BAND;
2414
+ const scale2 = Math.min(
2415
+ 1,
2416
+ (SHEET_MAX_SIDE - 2 * m) / (3 * dw),
2417
+ (SHEET_MAX_SIDE - 2 * m - 3 * b) / (3 * dh)
2418
+ );
2419
+ const frames = sheetFrames(thetas);
2420
+ 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";
2433
+ }
2434
+ }
2435
+ return {
2436
+ parameter: SWEEP_PARAMETER,
2437
+ frameMs: SWEEP_FRAME_MS,
2438
+ warmup: SWEEP_WARMUP_S * SWEEP_CLOCK_HZ,
2439
+ thetas,
2440
+ captureEvery: CAPTURE_EVERY,
2441
+ frames: FRAMES,
2442
+ frame: { width: dw, height: dh },
2443
+ physicsOutputs: physicsOutputIds(model),
2444
+ sheet: {
2445
+ frames,
2446
+ cell: {
2447
+ w: Math.max(1, Math.floor(dw * scale2)),
2448
+ h: Math.max(1, Math.floor(dh * scale2))
2449
+ },
2450
+ margin: m,
2451
+ labelBand: b,
2452
+ labels: frames.map(
2453
+ (k) => sheetLabel(thetas[CAPTURE_EVERY * k], k / SWEEP_FPS)
2454
+ )
2455
+ },
2456
+ kymograph: { row, band: KYMOGRAPH_BAND, at },
2457
+ crop
2458
+ };
2459
+ }
2460
+ function flipbookHtml(manifest) {
2461
+ const json = JSON.stringify(manifest).replace(/</g, "\\u003c");
2462
+ return `<!doctype html>
2463
+ <html lang="en">
2464
+ <head>
2465
+ <meta charset="utf-8">
2466
+ <title>turn sweep</title>
2467
+ <style>
2468
+ body { font: 14px system-ui, sans-serif; margin: 16px; background: #222; color: #eee; }
2469
+ .row { display: flex; gap: 16px; align-items: flex-start; }
2470
+ img { max-width: 48vw; height: auto; background: #444; }
2471
+ #b { display: none; }
2472
+ #controls { margin: 12px 0; display: flex; gap: 12px; align-items: center; }
2473
+ #scrub { flex: 1; max-width: 640px; }
2474
+ </style>
2475
+ </head>
2476
+ <body>
2477
+ <div class="row"><img id="a" alt="A"><img id="b" alt="B"></div>
2478
+ <div id="controls">
2479
+ <button id="play" type="button">pause</button>
2480
+ <input id="scrub" type="range" min="0" value="0" step="1">
2481
+ <span id="readout"></span>
2482
+ </div>
2483
+ <p>Add <code>?b=&lt;relative dir&gt;</code> to the address to show another sweep beside this one; it must be a sweep of the same preset, since frames are matched by file name.</p>
2484
+ <script id="manifest" type="application/json">${json}</script>
2485
+ <script>
2486
+ (function () {
2487
+ var m = JSON.parse(document.getElementById("manifest").textContent);
2488
+ var b = new URLSearchParams(location.search).get("b");
2489
+ var a = document.getElementById("a");
2490
+ var bi = document.getElementById("b");
2491
+ var scrub = document.getElementById("scrub");
2492
+ var readout = document.getElementById("readout");
2493
+ var play = document.getElementById("play");
2494
+ var n = m.frames.length;
2495
+ var i = 0;
2496
+ var playing = true;
2497
+ scrub.max = String(n - 1);
2498
+ if (b) { bi.style.display = "block"; }
2499
+ function show(k) {
2500
+ i = k;
2501
+ var f = m.frames[k];
2502
+ a.src = f.file;
2503
+ if (b) { bi.src = b.replace(/\\/$/, "") + "/" + f.file; }
2504
+ scrub.value = String(k);
2505
+ readout.textContent = "frame " + k + " \\u03b8 " + f.theta.toFixed(1) + "\\u00b0 t " + f.t.toFixed(2) + " s";
2506
+ }
2507
+ play.addEventListener("click", function () {
2508
+ playing = !playing;
2509
+ play.textContent = playing ? "pause" : "play";
2510
+ });
2511
+ scrub.addEventListener("input", function () {
2512
+ playing = false;
2513
+ play.textContent = "play";
2514
+ show(Number(scrub.value));
2515
+ });
2516
+ setInterval(function () { if (playing) { show((i + 1) % n); } }, 1000 / m.fps);
2517
+ show(0);
2518
+ })();
2519
+ </script>
2520
+ </body>
2521
+ </html>
2522
+ `;
2523
+ }
2524
+ function prepareSweepDir(outDir, name) {
2525
+ const dir = import_node_path3.default.join(outDir, name);
2526
+ try {
2527
+ import_node_fs3.default.mkdirSync(dir);
2528
+ } catch (e) {
2529
+ if (e.code !== "EEXIST") {
2530
+ throw new AutoRigInputError(`sweep dir: ${e.message}`);
2531
+ }
2532
+ }
2533
+ const stat = import_node_fs3.default.lstatSync(dir);
2534
+ if (stat.isSymbolicLink()) {
2535
+ throw new AutoRigInputError(`sweep.name names ${dir}, a symbolic link`);
2536
+ }
2537
+ if (!stat.isDirectory()) {
2538
+ throw new AutoRigInputError(`sweep.name names ${dir}, not a directory`);
2539
+ }
2540
+ const real = confineToWorkingDirectory(process.cwd(), dir, "sweep dir", name);
2541
+ return real;
2542
+ }
2543
+
2186
2544
  // src/render-poses.ts
2187
2545
  var FULL_BODY_VIEW_WIDTH = 2.5;
2188
2546
  var BUST_SIZE = 560;
2189
2547
  var CROP_WIDTH = 720;
2190
2548
  var CROP_MAX_HEIGHT = 8192;
2191
2549
  var POSE_NAME = /^[A-Za-z0-9_.-]+$/;
2550
+ var SWEEP_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
2192
2551
  function bustPadY(width, height) {
2193
2552
  return Math.max(0, (BUST_SIZE - BUST_SIZE * height / width) / 2);
2194
2553
  }
2195
- function planRenders(model, requested) {
2554
+ function planRenders(model, requested, sweep) {
2196
2555
  const { width: W, height: H } = model.canvas;
2197
2556
  const fullBody = H > W;
2198
2557
  const canvas = fullBody ? {
@@ -2222,40 +2581,49 @@ function planRenders(model, requested) {
2222
2581
  name,
2223
2582
  values
2224
2583
  });
2584
+ const toRenderCrop = (crop, label) => {
2585
+ const left = Math.max(crop.x, 0);
2586
+ const top = Math.max(crop.y, 0);
2587
+ const w = Math.min(crop.x + crop.w, W) - left;
2588
+ const h = Math.min(crop.y + crop.h, H) - top;
2589
+ if (!(w > 0 && h > 0)) {
2590
+ throw new AutoRigInputError(
2591
+ `${label} does not overlap the model's ${W}x${H} canvas`
2592
+ );
2593
+ }
2594
+ const dh = Math.round(CROP_WIDTH * h / w);
2595
+ if (dh < 1 || dh > CROP_MAX_HEIGHT) {
2596
+ throw new AutoRigInputError(
2597
+ `${label} meets the canvas in ${w}x${h} model px, which ${CROP_WIDTH} px wide draws ${dh} px tall, outside 1..${CROP_MAX_HEIGHT}`
2598
+ );
2599
+ }
2600
+ return {
2601
+ sx: x0 + left * s,
2602
+ sy: y0 + top * s,
2603
+ sw: w * s,
2604
+ sh: h * s,
2605
+ dw: CROP_WIDTH,
2606
+ dh
2607
+ };
2608
+ };
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
+ );
2613
+ }
2614
+ const sweepCrop = sweep ? sweep.crop ? toRenderCrop(sweep.crop, "sweep.crop") : squareCrop : void 0;
2225
2615
  if (requested) {
2226
2616
  if (requested.length === 0) throw new AutoRigInputError("poses is empty");
2227
2617
  const poses2 = requested.map((pose, i) => {
2228
2618
  checkRequest(requested, i);
2229
2619
  if (!pose.crop) return square(pose.name, pose.values);
2230
- const left = Math.max(pose.crop.x, 0);
2231
- const top = Math.max(pose.crop.y, 0);
2232
- const w = Math.min(pose.crop.x + pose.crop.w, W) - left;
2233
- const h = Math.min(pose.crop.y + pose.crop.h, H) - top;
2234
- if (!(w > 0 && h > 0)) {
2235
- throw new AutoRigInputError(
2236
- `poses[${i}].crop does not overlap the model's ${W}x${H} canvas`
2237
- );
2238
- }
2239
- const dh = Math.round(CROP_WIDTH * h / w);
2240
- if (dh < 1 || dh > CROP_MAX_HEIGHT) {
2241
- throw new AutoRigInputError(
2242
- `poses[${i}].crop meets the canvas in ${w}x${h} model px, which ${CROP_WIDTH} px wide draws ${dh} px tall, outside 1..${CROP_MAX_HEIGHT}`
2243
- );
2244
- }
2245
2620
  return {
2246
2621
  name: pose.name,
2247
2622
  values: pose.values,
2248
- crop: {
2249
- sx: x0 + left * s,
2250
- sy: y0 + top * s,
2251
- sw: w * s,
2252
- sh: h * s,
2253
- dw: CROP_WIDTH,
2254
- dh
2255
- }
2623
+ crop: toRenderCrop(pose.crop, `poses[${i}].crop`)
2256
2624
  };
2257
2625
  });
2258
- return { canvas, view, fullBody, mouth, poses: poses2 };
2626
+ return { canvas, view, fullBody, mouth, poses: poses2, sweepCrop };
2259
2627
  }
2260
2628
  const bodyAngles = Object.fromEntries(
2261
2629
  [
@@ -2363,7 +2731,7 @@ function planRenders(model, requested) {
2363
2731
  );
2364
2732
  }
2365
2733
  }
2366
- return { canvas, view, fullBody, mouth, poses };
2734
+ return { canvas, view, fullBody, mouth, poses, sweepCrop };
2367
2735
  }
2368
2736
  function checkRequest(requested, i) {
2369
2737
  const { name, values } = requested[i];
@@ -2395,7 +2763,7 @@ var CAPTURE_MS = 15e3;
2395
2763
  function readPageScript() {
2396
2764
  const url = new URL("../dist/render-page.global.js", importMetaUrl);
2397
2765
  try {
2398
- return (0, import_node_fs3.readFileSync)(url, "utf8");
2766
+ return (0, import_node_fs4.readFileSync)(url, "utf8");
2399
2767
  } catch (cause) {
2400
2768
  throw new Error(
2401
2769
  "could not read the render page script; run `pnpm build` in packages/mcp",
@@ -2403,6 +2771,86 @@ function readPageScript() {
2403
2771
  );
2404
2772
  }
2405
2773
  }
2774
+ async function captureSweep(evaluate, model, plan, requested, dir, report) {
2775
+ const spec = sweepSpec(model, plan.sweepCrop);
2776
+ await evaluate(
2777
+ `window.__ikiRender.sweepBegin(${JSON.stringify(spec)})`,
2778
+ CAPTURE_MS
2779
+ );
2780
+ const frames = [];
2781
+ for (let k = 0; k < spec.frames; k++) {
2782
+ const { png, values } = await evaluate(
2783
+ "window.__ikiRender.sweepFrame()",
2784
+ CAPTURE_MS
2785
+ );
2786
+ if (typeof png !== "string" || !png.startsWith(PNG_PREFIX)) {
2787
+ throw new Error(
2788
+ `sweep ${requested.name} frame ${k}: the page returned no PNG`
2789
+ );
2790
+ }
2791
+ const file = `f${String(k).padStart(3, "0")}.png`;
2792
+ writeFileAtomic(
2793
+ import_node_path4.default.join(dir, file),
2794
+ Buffer.from(png.slice(PNG_PREFIX.length), "base64")
2795
+ );
2796
+ frames.push({
2797
+ i: k,
2798
+ file,
2799
+ t: k / SWEEP_FPS,
2800
+ theta: spec.thetas[spec.captureEvery * k],
2801
+ values
2802
+ });
2803
+ }
2804
+ const end = await evaluate("window.__ikiRender.sweepEnd()", CAPTURE_MS);
2805
+ for (const [what, url] of Object.entries(end)) {
2806
+ if (typeof url !== "string" || !url.startsWith(PNG_PREFIX)) {
2807
+ throw new Error(
2808
+ `sweep ${requested.name} ${what}: the page returned no PNG`
2809
+ );
2810
+ }
2811
+ }
2812
+ const sheet = import_node_path4.default.join(dir, "sheet.png");
2813
+ const kymograph = import_node_path4.default.join(dir, "kymograph.png");
2814
+ writeFileAtomic(
2815
+ sheet,
2816
+ Buffer.from(end.sheet.slice(PNG_PREFIX.length), "base64")
2817
+ );
2818
+ writeFileAtomic(
2819
+ kymograph,
2820
+ Buffer.from(end.kymograph.slice(PNG_PREFIX.length), "base64")
2821
+ );
2822
+ const manifest = {
2823
+ version: 1,
2824
+ preset: requested.preset,
2825
+ parameter: spec.parameter,
2826
+ fps: SWEEP_FPS,
2827
+ clockHz: SWEEP_CLOCK_HZ,
2828
+ warmupS: SWEEP_WARMUP_S,
2829
+ durationS: SWEEP_DURATION_S,
2830
+ crop: requested.crop ?? null,
2831
+ frame: spec.frame,
2832
+ kymographRow: { row: spec.kymograph.row, at: spec.kymograph.at },
2833
+ sheet: { frames: spec.sheet.frames, cell: spec.sheet.cell },
2834
+ physicsOutputs: spec.physicsOutputs,
2835
+ frames
2836
+ };
2837
+ const manifestPath = import_node_path4.default.join(dir, "manifest.json");
2838
+ const flipbook = import_node_path4.default.join(dir, "index.html");
2839
+ writeFileAtomic(manifestPath, JSON.stringify(manifest, null, 2) + "\n");
2840
+ writeFileAtomic(flipbook, flipbookHtml(manifest));
2841
+ return {
2842
+ name: requested.name,
2843
+ preset: requested.preset,
2844
+ dir,
2845
+ fps: SWEEP_FPS,
2846
+ frames: spec.frames,
2847
+ manifest: manifestPath,
2848
+ sheet,
2849
+ kymograph,
2850
+ flipbook,
2851
+ report
2852
+ };
2853
+ }
2406
2854
  async function renderPoses(input) {
2407
2855
  try {
2408
2856
  const modelFile = confineToWorkingDirectory(
@@ -2412,8 +2860,8 @@ async function renderPoses(input) {
2412
2860
  input.modelPath
2413
2861
  );
2414
2862
  const outDir = resolveOutputDir(input.outDir);
2415
- const model = (0, import_format8.loadIkiModel)((0, import_node_fs3.readFileSync)(modelFile, "utf8"));
2416
- const plan = planRenders(model, input.poses);
2863
+ const model = (0, import_format8.loadIkiModel)((0, import_node_fs4.readFileSync)(modelFile, "utf8"));
2864
+ const plan = planRenders(model, input.poses, input.sweep);
2417
2865
  const browser = findBrowser();
2418
2866
  if (!browser) return { ok: false, error: NO_BROWSER_MESSAGE };
2419
2867
  const pageScript = readPageScript();
@@ -2422,7 +2870,9 @@ async function renderPoses(input) {
2422
2870
  input.poses?.map((p) => p.values)
2423
2871
  );
2424
2872
  const physics = checkPhysics(model);
2425
- const { failedTextures, poses } = await withBrowser(
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(
2426
2876
  browser,
2427
2877
  async (evaluate) => {
2428
2878
  await evaluate(pageScript, PAGE_SCRIPT_MS);
@@ -2439,14 +2889,22 @@ async function renderPoses(input) {
2439
2889
  if (typeof url !== "string" || !url.startsWith(PNG_PREFIX)) {
2440
2890
  throw new Error(`pose ${pose.name}: the page returned no PNG`);
2441
2891
  }
2442
- const file = import_node_path3.default.join(outDir, `${pose.name}.png`);
2892
+ const file = import_node_path4.default.join(outDir, `${pose.name}.png`);
2443
2893
  writeFileAtomic(
2444
2894
  file,
2445
2895
  Buffer.from(url.slice(PNG_PREFIX.length), "base64")
2446
2896
  );
2447
2897
  written.push({ name: pose.name, path: file });
2448
2898
  }
2449
- return { failedTextures: loaded.failedTextures, poses: written };
2899
+ const sweep2 = input.sweep && sweepDir && sweepReport ? await captureSweep(
2900
+ evaluate,
2901
+ model,
2902
+ plan,
2903
+ input.sweep,
2904
+ sweepDir,
2905
+ sweepReport
2906
+ ) : void 0;
2907
+ return { failedTextures: loaded.failedTextures, poses: written, sweep: sweep2 };
2450
2908
  }
2451
2909
  );
2452
2910
  return {
@@ -2459,7 +2917,8 @@ async function renderPoses(input) {
2459
2917
  poses,
2460
2918
  modelCanvas: model.canvas,
2461
2919
  folds,
2462
- physics
2920
+ physics,
2921
+ sweep
2463
2922
  };
2464
2923
  } catch (error) {
2465
2924
  if (error instanceof AutoRigInputError || error instanceof import_format8.IkiFormatError) {
@@ -2567,7 +3026,7 @@ function describeIki(model) {
2567
3026
  const padY = bustPadY(W, H);
2568
3027
  const tenth = (n) => Math.round(n * 10) / 10;
2569
3028
  const parts = m.parts.map((p) => {
2570
- const box = {
3029
+ const box2 = {
2571
3030
  x: W / 2 + p.transform.x - p.width / 2,
2572
3031
  y: H / 2 - p.transform.y - p.height / 2,
2573
3032
  w: p.width,
@@ -2576,12 +3035,12 @@ function describeIki(model) {
2576
3035
  const entry = {
2577
3036
  id: p.id,
2578
3037
  order: p.order,
2579
- box,
3038
+ box: box2,
2580
3039
  bustBox: {
2581
- x: tenth(box.x * bustScale),
2582
- y: tenth(padY + box.y * bustScale),
2583
- w: tenth(box.w * bustScale),
2584
- h: tenth(box.h * bustScale)
3040
+ x: tenth(box2.x * bustScale),
3041
+ y: tenth(padY + box2.y * bustScale),
3042
+ w: tenth(box2.w * bustScale),
3043
+ h: tenth(box2.h * bustScale)
2585
3044
  }
2586
3045
  };
2587
3046
  if (p.deformer !== void 0) entry.deformer = p.deformer;
@@ -2651,7 +3110,7 @@ function describeIkiAt(modelPath) {
2651
3110
  "model path",
2652
3111
  modelPath
2653
3112
  );
2654
- return describeIki((0, import_node_fs4.readFileSync)(modelFile, "utf8"));
3113
+ return describeIki((0, import_node_fs5.readFileSync)(modelFile, "utf8"));
2655
3114
  } catch (e) {
2656
3115
  if (e instanceof AutoRigInputError) return { ok: false, error: e.message };
2657
3116
  throw e;
@@ -2862,7 +3321,7 @@ async function autoRigFromLayers(input) {
2862
3321
  }
2863
3322
  const resolvedLayers = layers.map((layer) => {
2864
3323
  const resolved = resolveInputPath(layer.path);
2865
- return { resolved, fileName: layer.fileName ?? import_node_path4.default.basename(resolved) };
3324
+ return { resolved, fileName: layer.fileName ?? import_node_path5.default.basename(resolved) };
2866
3325
  });
2867
3326
  const rolePairs = expectInput(
2868
3327
  "role parsing",
@@ -3027,8 +3486,8 @@ async function autoRigFromLayers(input) {
3027
3486
  }
3028
3487
 
3029
3488
  // src/compose.ts
3030
- var import_node_fs6 = __toESM(require("fs"));
3031
- var import_node_path9 = __toESM(require("path"));
3489
+ var import_node_fs7 = __toESM(require("fs"));
3490
+ var import_node_path10 = __toESM(require("path"));
3032
3491
  var import_sharp4 = __toESM(require("sharp"));
3033
3492
  var import_editor12 = require("@ikijs/editor");
3034
3493
 
@@ -3099,18 +3558,18 @@ function boxWithoutStraySpecks(rgba, W, H) {
3099
3558
  }
3100
3559
 
3101
3560
  // src/measure.ts
3102
- var import_node_fs5 = __toESM(require("fs"));
3103
- var import_node_path8 = __toESM(require("path"));
3561
+ var import_node_fs6 = __toESM(require("fs"));
3562
+ var import_node_path9 = __toESM(require("path"));
3104
3563
 
3105
3564
  // src/measure-arms.ts
3106
- var import_node_path5 = __toESM(require("path"));
3565
+ var import_node_path6 = __toESM(require("path"));
3107
3566
  var import_editor5 = require("@ikijs/editor");
3108
3567
  var ARM_ROLES = ["arm_L", "arm_R"];
3109
3568
  var CAP_OVERLAP = 0.5;
3110
3569
  var px = (v) => `${Number(v.toFixed(1))}`;
3111
3570
  async function measured(measurer, absDir, role) {
3112
3571
  const fileName = `${role}.png`;
3113
- const { rgba } = await decodePng(import_node_path5.default.join(absDir, fileName));
3572
+ const { rgba } = await decodePng(import_node_path6.default.join(absDir, fileName));
3114
3573
  return measurer.add({ role, fileName, rgba });
3115
3574
  }
3116
3575
  async function armWarnings(absDir, layers) {
@@ -3260,7 +3719,7 @@ function jointWarnings(pose, arm, stats, a, armLayer, b) {
3260
3719
  }
3261
3720
 
3262
3721
  // src/measure-lips.ts
3263
- var import_node_path6 = __toESM(require("path"));
3722
+ var import_node_path7 = __toESM(require("path"));
3264
3723
  var import_editor8 = require("@ikijs/editor");
3265
3724
 
3266
3725
  // src/compose-lips.ts
@@ -3294,7 +3753,7 @@ function components(mask, W, H) {
3294
3753
  for (let start = 0; start < n; start++) {
3295
3754
  if (!mask[start] || label[start] >= 0) continue;
3296
3755
  const id = sizes.length;
3297
- const box = { x0: W, y0: H, x1: -1, y1: -1 };
3756
+ const box2 = { x0: W, y0: H, x1: -1, y1: -1 };
3298
3757
  let size = 0;
3299
3758
  let depth = 0;
3300
3759
  label[start] = id;
@@ -3304,10 +3763,10 @@ function components(mask, W, H) {
3304
3763
  size++;
3305
3764
  const px2 = p % W;
3306
3765
  const py = (p - px2) / W;
3307
- box.x0 = Math.min(box.x0, px2);
3308
- box.x1 = Math.max(box.x1, px2);
3309
- box.y0 = Math.min(box.y0, py);
3310
- box.y1 = Math.max(box.y1, py);
3766
+ box2.x0 = Math.min(box2.x0, px2);
3767
+ box2.x1 = Math.max(box2.x1, px2);
3768
+ box2.y0 = Math.min(box2.y0, py);
3769
+ box2.y1 = Math.max(box2.y1, py);
3311
3770
  for (let y = Math.max(0, py - 1); y <= Math.min(H - 1, py + 1); y++) {
3312
3771
  for (let x = Math.max(0, px2 - 1); x <= Math.min(W - 1, px2 + 1); x++) {
3313
3772
  if (x !== px2 && y !== py) continue;
@@ -3320,7 +3779,7 @@ function components(mask, W, H) {
3320
3779
  }
3321
3780
  }
3322
3781
  sizes.push(size);
3323
- boxes.push(box);
3782
+ boxes.push(box2);
3324
3783
  }
3325
3784
  return { label, sizes, boxes };
3326
3785
  }
@@ -3557,14 +4016,14 @@ async function prepInterior(rgba, W, H) {
3557
4016
  for (let p = 0; p < cw * ch; p++) {
3558
4017
  if (label[p] >= 0 && rim[label[p]]) crop[p * 4 + 3] = 0;
3559
4018
  }
3560
- const box = drawingBox(crop, cw, ch);
3561
- if (box === null) throw empty;
4019
+ const box2 = drawingBox(crop, cw, ch);
4020
+ if (box2 === null) throw empty;
3562
4021
  const sum = [0, 0, 0];
3563
4022
  const all = [0, 0, 0];
3564
4023
  let dark = 0;
3565
4024
  let count = 0;
3566
- for (let y = box.y; y < box.y + box.h; y++) {
3567
- for (let x = box.x; x < box.x + box.w; x++) {
4025
+ for (let y = box2.y; y < box2.y + box2.h; y++) {
4026
+ for (let x = box2.x; x < box2.x + box2.w; x++) {
3568
4027
  const i = (y * cw + x) * 4;
3569
4028
  if (crop[i + 3] < import_editor7.ALPHA_OPAQUE) continue;
3570
4029
  count++;
@@ -3578,7 +4037,7 @@ async function prepInterior(rgba, W, H) {
3578
4037
  if (count === 0) throw empty;
3579
4038
  const [from, over] = dark > 0 ? [sum, dark] : [all, count];
3580
4039
  const cavity = from.map((v) => Math.round(v / over));
3581
- return { png: await cropToBuffer(crop, cw, ch, box), cavity };
4040
+ return { png: await cropToBuffer(crop, cw, ch, box2), cavity };
3582
4041
  }
3583
4042
  var rawOf = async (png) => (0, import_sharp2.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
3584
4043
  var encode = (rgba, w, h) => (0, import_sharp2.default)(rgba, { raw: { width: w, height: h, channels: 4 } }).png().toBuffer();
@@ -3621,8 +4080,8 @@ function enclosedHole(frame, w, h) {
3621
4080
  `${KEYED_SRC}: the outline is not closed round the opening (the key reached the outside, or the line is broken or too thin at this size) \u2014 regenerate with ONE closed, bolder outline`
3622
4081
  );
3623
4082
  }
3624
- const box = boxes[main];
3625
- const holeW = box.x1 - box.x0 + 1;
4083
+ const box2 = boxes[main];
4084
+ const holeW = box2.x1 - box2.x0 + 1;
3626
4085
  if (holeW < MIN_OPENING_WIDTH * w) {
3627
4086
  throw new AutoRigInputError(
3628
4087
  `${KEYED_SRC}: the opening is only ${holeW} px wide of the mouth's ${w} \u2014 too small to fold; regenerate with the mouth open wider, or, if its outline is broken (only a small pocket of the opening was enclosed), with ONE closed, bolder outline`
@@ -3636,7 +4095,7 @@ function enclosedHole(frame, w, h) {
3636
4095
  `${KEYED_SRC}: the opening is not one connected region (${others.length + 1} holes: teeth or tongue drawn into the green?) \u2014 regenerate with nothing drawn inside the green`
3637
4096
  );
3638
4097
  }
3639
- return { label, main, box };
4098
+ return { label, main, box: box2 };
3640
4099
  }
3641
4100
  function measureLips(layers, w, h) {
3642
4101
  const measurer = (0, import_editor7.createLayerSetMeasurer)({ width: w, height: h });
@@ -3904,15 +4363,15 @@ async function lipWarnings(absDir, layers) {
3904
4363
  return { warnings };
3905
4364
  }
3906
4365
  }
3907
- const box = (m) => ({
4366
+ const box2 = (m) => ({
3908
4367
  x0: m.bboxCx - m.w / 2,
3909
4368
  x1: m.bboxCx + m.w / 2,
3910
4369
  y0: m.bboxCy - m.h / 2,
3911
4370
  y1: m.bboxCy + m.h / 2
3912
4371
  });
3913
- const cavity = box(inner);
4372
+ const cavity = box2(inner);
3914
4373
  for (const role of inside) {
3915
- const b = box(layers[role]);
4374
+ const b = box2(layers[role]);
3916
4375
  if (b.x0 < cavity.x0 || b.x1 > cavity.x1 || b.y0 < cavity.y0 || b.y1 > cavity.y1) {
3917
4376
  warnings.push(
3918
4377
  `${role}: its box leaves mouth_inner's \u2014 the cavity clips it away there. Recompose from mouth_keyed.png + mouth_interior.png (free).`
@@ -3927,7 +4386,7 @@ async function lipWarnings(absDir, layers) {
3927
4386
  const green = [];
3928
4387
  for (const role of import_editor8.LIP_ROLES) {
3929
4388
  const fileName = `${role}.png`;
3930
- const { rgba } = await decodePng(import_node_path6.default.join(absDir, fileName));
4389
+ const { rgba } = await decodePng(import_node_path7.default.join(absDir, fileName));
3931
4390
  set.set(role, measurer.add({ role, fileName, rgba }));
3932
4391
  for (let i = 0; i < rgba.length; i += 4) {
3933
4392
  if (rgba[i + 3] >= import_editor8.ALPHA_OPAQUE && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > GREEN_EXCESS) {
@@ -4031,7 +4490,7 @@ async function lipWarnings(absDir, layers) {
4031
4490
  }
4032
4491
 
4033
4492
  // src/measure-turn.ts
4034
- var import_node_path7 = __toESM(require("path"));
4493
+ var import_node_path8 = __toESM(require("path"));
4035
4494
  var import_editor9 = require("@ikijs/editor");
4036
4495
  var import_editor10 = require("@ikijs/editor");
4037
4496
  var DEFAULT_IRIS = { hueMin: 230, hueMax: 300, satMin: 0.22 };
@@ -4299,14 +4758,14 @@ function farNearWidths(m, turnSign) {
4299
4758
  return turnSign < 0 ? { far: m.irisL.w, near: m.irisR.w } : { far: m.irisR.w, near: m.irisL.w };
4300
4759
  }
4301
4760
  function overlaySvg(m) {
4302
- const box = (b, stroke) => `<rect x="${b.x0}" y="${b.y0}" width="${b.w}" height="${b.h}" fill="none" stroke="${stroke}" stroke-width="3"/>`;
4761
+ const box2 = (b, stroke) => `<rect x="${b.x0}" y="${b.y0}" width="${b.w}" height="${b.h}" fill="none" stroke="${stroke}" stroke-width="3"/>`;
4303
4762
  const tick = (x, half, stroke) => `<line x1="${x}" y1="${m.eyeRow - half}" x2="${x}" y2="${m.eyeRow + half}" stroke="${stroke}" stroke-width="3"/>`;
4304
- return `<svg width="${m.width}" height="${m.height}">` + box(m.irisL, "#ff0000") + box(m.irisR, "#00c000") + tick(m.head.left, 40, "#0000ff") + tick(m.head.right, 40, "#0000ff") + tick(m.head.cx, 60, "#ff8800") + tick(m.pairCx, 60, "#ff00ff") + "</svg>";
4763
+ return `<svg width="${m.width}" height="${m.height}">` + box2(m.irisL, "#ff0000") + box2(m.irisR, "#00c000") + tick(m.head.left, 40, "#0000ff") + tick(m.head.right, 40, "#0000ff") + tick(m.head.cx, 60, "#ff8800") + tick(m.pairCx, 60, "#ff00ff") + "</svg>";
4305
4764
  }
4306
4765
  async function writeOverlay(debugDir, label, m) {
4307
- const outPath = import_node_path7.default.join(
4766
+ const outPath = import_node_path8.default.join(
4308
4767
  debugDir,
4309
- `${label}-${import_node_path7.default.basename(m.file, ".png")}.debug.png`
4768
+ `${label}-${import_node_path8.default.basename(m.file, ".png")}.debug.png`
4310
4769
  );
4311
4770
  writeFileAtomic(outPath, await encodeOverlayPng(m.file, overlaySvg(m)));
4312
4771
  return outPath;
@@ -4498,7 +4957,7 @@ async function lashOffSclera(eyePath, lashPath) {
4498
4957
  return { opaque, off };
4499
4958
  }
4500
4959
  async function measureDir(absDir, noseSpeck) {
4501
- const files = import_node_fs5.default.readdirSync(absDir).filter((f) => f.endsWith(".png") && !f.startsWith("preview")).sort();
4960
+ const files = import_node_fs6.default.readdirSync(absDir).filter((f) => f.endsWith(".png") && !f.startsWith("preview")).sort();
4502
4961
  if (files.length === 0) {
4503
4962
  throw new AutoRigInputError(`no role layers in ${absDir}`);
4504
4963
  }
@@ -4510,8 +4969,8 @@ async function measureDir(absDir, noseSpeck) {
4510
4969
  const layers = {};
4511
4970
  const empty = [];
4512
4971
  for (const f of files) {
4513
- const role = import_node_path8.default.basename(f, ".png");
4514
- const m = await layerStats(import_node_path8.default.join(absDir, f));
4972
+ const role = import_node_path9.default.basename(f, ".png");
4973
+ const m = await layerStats(import_node_path9.default.join(absDir, f));
4515
4974
  if (!m) {
4516
4975
  empty.push(role);
4517
4976
  continue;
@@ -4589,8 +5048,8 @@ async function measureDir(absDir, noseSpeck) {
4589
5048
  }
4590
5049
  if (lash) {
4591
5050
  const { opaque, off } = await lashOffSclera(
4592
- import_node_path8.default.join(absDir, `eye_${side}.png`),
4593
- import_node_path8.default.join(absDir, `lash_${side}.png`)
5051
+ import_node_path9.default.join(absDir, `eye_${side}.png`),
5052
+ import_node_path9.default.join(absDir, `lash_${side}.png`)
4594
5053
  );
4595
5054
  const dTop = lash.marginTop - eye.marginTop;
4596
5055
  const faults = [
@@ -4616,7 +5075,7 @@ async function measureDir(absDir, noseSpeck) {
4616
5075
  if (noseSpeck !== void 0) {
4617
5076
  warnings.push(noseSpeckWarning(noseSpeck, "compose"));
4618
5077
  } else if (layers.nose !== void 0) {
4619
- const nose = await decodePng(import_node_path8.default.join(absDir, "nose.png"));
5078
+ const nose = await decodePng(import_node_path9.default.join(absDir, "nose.png"));
4620
5079
  const core = (0, import_editor10.denseCoreOf)(nose.rgba, nose.width, nose.height);
4621
5080
  if (core !== null) {
4622
5081
  const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
@@ -5051,8 +5510,8 @@ async function trimmedPart(role, cfg, partsDir, inMemory, flipSource) {
5051
5510
  if (inMemory !== void 0) {
5052
5511
  img = (0, import_sharp4.default)(inMemory);
5053
5512
  } else {
5054
- const srcPath = import_node_path9.default.join(partsDir, cfg.src);
5055
- if (!import_node_fs6.default.existsSync(srcPath)) {
5513
+ const srcPath = import_node_path10.default.join(partsDir, cfg.src);
5514
+ if (!import_node_fs7.default.existsSync(srcPath)) {
5056
5515
  if (cfg.optional) return null;
5057
5516
  throw new AutoRigInputError(
5058
5517
  `missing part source for role "${role}": ${srcPath}` + (role === "mouth" ? " \u2014 draw mouth.png (with mouth_open.png), or the lip set's mouth_keyed.png + mouth_interior.png" : "")
@@ -5069,8 +5528,8 @@ async function trimmedPart(role, cfg, partsDir, inMemory, flipSource) {
5069
5528
  img = (0, import_sharp4.default)(kept.data, {
5070
5529
  raw: { width: keptW, height: keptH, channels: 4 }
5071
5530
  });
5072
- const box = boxWithoutStraySpecks(kept.data, keptW, keptH);
5073
- if (box !== null) img = img.extract(box);
5531
+ const box2 = boxWithoutStraySpecks(kept.data, keptW, keptH);
5532
+ if (box2 !== null) img = img.extract(box2);
5074
5533
  }
5075
5534
  if ((cfg.mirror ?? false) !== flipSource) img = img.flop();
5076
5535
  const trimmed = await img.png().toBuffer({ resolveWithObject: true });
@@ -5117,18 +5576,18 @@ function placement2(role, cfg, w, h, canvas) {
5117
5576
  assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top, canvas);
5118
5577
  return { left, top };
5119
5578
  }
5120
- function nosePlacement(layout, mouthKey, box, w, h, canvas) {
5579
+ function nosePlacement(layout, mouthKey, box2, w, h, canvas) {
5121
5580
  const { cx, cy } = layout.nose;
5122
- const left = Math.round(cx - (box.x + box.w / 2));
5581
+ const left = Math.round(cx - (box2.x + box2.w / 2));
5123
5582
  let top;
5124
5583
  if (cy !== void 0) {
5125
- top = Math.round(cy - (box.y + box.h / 2));
5584
+ top = Math.round(cy - (box2.y + box2.h / 2));
5126
5585
  } else {
5127
5586
  const eyeRow = (layout.eye_L.cy + layout.eye_R.cy) / 2;
5128
5587
  const tipRow = Math.round(
5129
5588
  eyeRow + NOSE_TIP_AT * (layout[mouthKey].cy - eyeRow)
5130
5589
  );
5131
- top = tipRow - (box.y + box.h - 1);
5590
+ top = tipRow - (box2.y + box2.h - 1);
5132
5591
  }
5133
5592
  assertOnCanvas(
5134
5593
  cy !== void 0 ? "layout.nose.cx/cy" : `layout.nose.cx/cy (cy unset: its tip row comes from layout.eye_L/eye_R/${mouthKey}.cy)`,
@@ -5236,8 +5695,8 @@ function detachedAboveWhite(rgba, W, H) {
5236
5695
  return detached;
5237
5696
  }
5238
5697
  async function prepEyeSplit(partsDir) {
5239
- const srcPath = import_node_path9.default.join(partsDir, EYEWHITE_SRC);
5240
- if (!import_node_fs6.default.existsSync(srcPath)) {
5698
+ const srcPath = import_node_path10.default.join(partsDir, EYEWHITE_SRC);
5699
+ if (!import_node_fs7.default.existsSync(srcPath)) {
5241
5700
  throw new AutoRigInputError(`missing eyewhite source: ${srcPath}`);
5242
5701
  }
5243
5702
  const { width: W, height: H, rgba: data } = await decodePng(srcPath);
@@ -5324,7 +5783,7 @@ function hasTransparency(rgba) {
5324
5783
  return false;
5325
5784
  }
5326
5785
  async function prepLipSources(partsDir, mirrored) {
5327
- const has = (name) => import_node_fs6.default.existsSync(import_node_path9.default.join(partsDir, name));
5786
+ const has = (name) => import_node_fs7.default.existsSync(import_node_path10.default.join(partsDir, name));
5328
5787
  const keyed = has(KEYED_SRC);
5329
5788
  const interior = has(INTERIOR_SRC);
5330
5789
  if (keyed && !interior) {
@@ -5344,13 +5803,13 @@ async function prepLipSources(partsDir, mirrored) {
5344
5803
  `${KEYED_SRC}/${INTERIOR_SRC} cannot be composed beside mouth.png/mouth_open.png (the lip set replaces the mouth drawings, and auto_rig_from_layers refuses the mix) \u2014 remove ${legacy.join(" and ")}`
5345
5804
  );
5346
5805
  }
5347
- const k = await decodePng(import_node_path9.default.join(partsDir, KEYED_SRC));
5806
+ const k = await decodePng(import_node_path10.default.join(partsDir, KEYED_SRC));
5348
5807
  const keyedRgba = keyGreen(
5349
5808
  hasTransparency(k.rgba) ? k.rgba : keyWhiteToAlpha(k.rgba),
5350
5809
  k.width,
5351
5810
  k.height
5352
5811
  );
5353
- const i = await decodePng(import_node_path9.default.join(partsDir, INTERIOR_SRC));
5812
+ const i = await decodePng(import_node_path10.default.join(partsDir, INTERIOR_SRC));
5354
5813
  const prepared = await prepInterior(
5355
5814
  hasTransparency(i.rgba) ? i.rgba : keyBorderWhite(i.rgba, i.width, i.height),
5356
5815
  i.width,
@@ -5367,7 +5826,7 @@ async function composeLayersFromParts(input) {
5367
5826
  try {
5368
5827
  const outDir = resolveOutputDir(input.outDir);
5369
5828
  const partsDir = resolveInputDir(input.partsDir);
5370
- if (import_node_fs6.default.realpathSync(partsDir) === outDir) {
5829
+ if (import_node_fs7.default.realpathSync(partsDir) === outDir) {
5371
5830
  throw new AutoRigInputError(
5372
5831
  `partsDir and outDir resolve to the same directory (${outDir}): composing would overwrite the source parts`
5373
5832
  );
@@ -5446,7 +5905,7 @@ async function composeLayersFromParts(input) {
5446
5905
  }
5447
5906
  if (key === "arm_L" || key === "arm_R") {
5448
5907
  const arm = layout[key];
5449
- if (!import_node_fs6.default.existsSync(import_node_path9.default.join(partsDir, arm.src))) continue;
5908
+ if (!import_node_fs7.default.existsSync(import_node_path10.default.join(partsDir, arm.src))) continue;
5450
5909
  const body = placed.find((p) => p.role === "body");
5451
5910
  if (body === void 0) {
5452
5911
  throw new AutoRigInputError(
@@ -5489,7 +5948,7 @@ async function composeLayersFromParts(input) {
5489
5948
  }
5490
5949
  if (key === "forearm_pose_L" || key === "forearm_pose_R") {
5491
5950
  const pose = layout[key];
5492
- if (!import_node_fs6.default.existsSync(import_node_path9.default.join(partsDir, pose.src))) continue;
5951
+ if (!import_node_fs7.default.existsSync(import_node_path10.default.join(partsDir, pose.src))) continue;
5493
5952
  const armRole = key === "forearm_pose_L" ? "arm_L" : "arm_R";
5494
5953
  const arm = placed.find((p) => p.role === armRole);
5495
5954
  if (arm?.elbow === void 0 || arm.elbowRun === void 0) {
@@ -5559,11 +6018,11 @@ async function composeLayersFromParts(input) {
5559
6018
  if (key === "nose") {
5560
6019
  noseSpeck = part.nose?.speck;
5561
6020
  const { core, bounds } = await coreAndBoundsOf(part.buf);
5562
- const box = part.nose?.whole ? bounds : core ?? bounds;
6021
+ const box2 = part.nose?.whole ? bounds : core ?? bounds;
5563
6022
  ({ left, top } = nosePlacement(
5564
6023
  layout,
5565
6024
  lips === void 0 ? "mouth" : "mouth_inner",
5566
- box,
6025
+ box2,
5567
6026
  part.w,
5568
6027
  part.h,
5569
6028
  canvas
@@ -5606,15 +6065,15 @@ async function composeLayersFromParts(input) {
5606
6065
  );
5607
6066
  for (const role of ORDER) {
5608
6067
  if (placed.some((p) => p.role === role)) continue;
5609
- import_node_fs6.default.rmSync(import_node_path9.default.join(outDir, `${role}.png`), { force: true });
6068
+ import_node_fs7.default.rmSync(import_node_path10.default.join(outDir, `${role}.png`), { force: true });
5610
6069
  }
5611
6070
  const posed = (role) => role === "forearm_pose_L" || role === "forearm_pose_R";
5612
6071
  if (!placed.some((p) => posed(p.role))) {
5613
- import_node_fs6.default.rmSync(import_node_path9.default.join(outDir, "preview-pose.png"), { force: true });
6072
+ import_node_fs7.default.rmSync(import_node_path10.default.join(outDir, "preview-pose.png"), { force: true });
5614
6073
  }
5615
6074
  const layers = [];
5616
6075
  for (const { role, part, left, top } of placed) {
5617
- const outPath = import_node_path9.default.join(outDir, `${role}.png`);
6076
+ const outPath = import_node_path10.default.join(outDir, `${role}.png`);
5618
6077
  writeFileAtomic(outPath, built.get(role));
5619
6078
  layers.push({
5620
6079
  role,
@@ -5645,7 +6104,7 @@ async function composeLayersFromParts(input) {
5645
6104
  background: { r: 245, g: 245, b: 248, alpha: 1 }
5646
6105
  }
5647
6106
  }).composite(preview).png().toBuffer();
5648
- const previewPath = import_node_path9.default.join(outDir, "preview.png");
6107
+ const previewPath = import_node_path10.default.join(outDir, "preview.png");
5649
6108
  writeFileAtomic(previewPath, previewPng);
5650
6109
  let previewPosePath;
5651
6110
  if (placed.some((p) => posed(p.role))) {
@@ -5674,7 +6133,7 @@ async function composeLayersFromParts(input) {
5674
6133
  background: { r: 245, g: 245, b: 248, alpha: 1 }
5675
6134
  }
5676
6135
  }).composite(pose).png().toBuffer();
5677
- previewPosePath = import_node_path9.default.join(outDir, "preview-pose.png");
6136
+ previewPosePath = import_node_path10.default.join(outDir, "preview-pose.png");
5678
6137
  writeFileAtomic(previewPosePath, posePng);
5679
6138
  }
5680
6139
  return {
@@ -5720,7 +6179,7 @@ function formatPatchReports(reports) {
5720
6179
  });
5721
6180
  }
5722
6181
  function createIkiMcpServer() {
5723
- const server = new import_mcp.McpServer({ name: "iki", version: "0.30.0" });
6182
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.31.0" });
5724
6183
  server.registerTool(
5725
6184
  "validate_iki",
5726
6185
  {
@@ -6018,7 +6477,7 @@ function createIkiMcpServer() {
6018
6477
  server.registerTool(
6019
6478
  "render_poses",
6020
6479
  {
6021
- description: "Renders a rigged .iki into the character loop's pose PNGs with the real engine, through the installed Chrome, Edge or Chromium run headless (set CHROME_PATH to pick one). The model decides the set: a bust gets 560x560 shots (rest, turns, nod, blinks, gaze, combined \u2014 ParamAngleX/Y/Z all at 30 \u2014 and stress: ParamAngleX/Y/Z all at -30, ParamMouthOpenY 1, both eyes at 0.5, the brows at opposite extremes (ParamBrowLY -1, ParamBrowRY 1, ParamBrowLAngle 1, ParamBrowRAngle -1) and each body angle the model declares at -10); a mouth adds 720x480 mouth crops; a full body (taller than wide) adds the full-canvas body, arm and elbow poses on a 1400-wide canvas, and a model with a pose forearm adds the full-pose-* shots. Given `poses` (see its field), the standard set is not rendered: only those poses are, each crop clamped to the model's canvas. Writes <pose>.png files into outDir, overwriting same-named files in place; returns the written paths one per line, then the model's fold report (the result's `folds`), checked by the engine over its own pose set plus any `poses`, each of which a `FOLD` line names by its settings, not its PNG name: a `FOLD` line per warp deformer or mesh part that flips (ratio <= 0) or collapses (under 0.1) at some pose \u2014 its cell or triangle, the ratio of its area there to at rest, the pose as its parameter settings (`rest` for none) and where it rests, in model space and in model px from the top-left (the layer PNGs' own pixels, not a render's) \u2014 or `FOLDS: none over N poses`, then a `FOLDS expected:` line naming the closures the rig draws on purpose (an eye or the mouth shut), each by part id, ratio and the parameter that shuts it. Report-only: a fold never fails the render. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output of the model's own rigs \u2014 `poses` do not enter it \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. Fails with INVALID when no browser is found or an input is refused; a browser that cannot start is a tool error.",
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.",
6022
6481
  inputSchema: {
6023
6482
  modelPath: import_zod.z.string().describe(
6024
6483
  "Rigged .iki file path (resolved against cwd; must sit under the working directory)."
@@ -6039,6 +6498,18 @@ function createIkiMcpServer() {
6039
6498
  })
6040
6499
  ).optional().describe(
6041
6500
  "Caller-named poses rendered INSTEAD of the standard set, each `{ name, values, crop? }`, in order. `name` becomes `<outDir>/<name>.png` and the result's pose name: letters, digits, `_`, `.` and `-` only, unique in the list ignoring case. `values` are parameter settings (every other parameter at its default; an id the model lacks is ignored). `crop` `{ x, y, w, h }` is a rectangle in model px from the top-left \u2014 the frame of describe_iki's boxes and of the `FOLD` lines \u2014 clamped to the model's canvas, then drawn 720 px wide at its own aspect; without one a pose is framed as the standard shots (560x560, the middle square on a full body). Each pose is also added to the fold sweep, after the engine's own poses. An empty list, a bad or repeated name, a non-finite value, or a crop that misses the canvas or would draw under 1 or over 8192 px tall comes back as `INVALID: poses\u2026` and nothing is rendered."
6501
+ ),
6502
+ sweep: import_zod.z.object({
6503
+ name: import_zod.z.string(),
6504
+ preset: import_zod.z.literal("turn"),
6505
+ crop: import_zod.z.object({
6506
+ x: import_zod.z.number(),
6507
+ y: import_zod.z.number(),
6508
+ w: import_zod.z.number(),
6509
+ h: import_zod.z.number()
6510
+ }).optional()
6511
+ }).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`."
6042
6513
  )
6043
6514
  }
6044
6515
  },
@@ -6047,8 +6518,16 @@ function createIkiMcpServer() {
6047
6518
  const r = await renderPoses(args);
6048
6519
  const text = r.ok ? [
6049
6520
  ...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
+ ] : [],
6050
6528
  ...formatFoldReport(r.folds, r.modelCanvas),
6051
- ...formatPhysicsReport(r.physics)
6529
+ ...formatPhysicsReport(r.physics),
6530
+ ...r.sweep ? formatSweepReport(r.sweep.report) : []
6052
6531
  ].join("\n") : `INVALID: ${r.error}`;
6053
6532
  return { content: [{ type: "text", text }], structuredContent: r };
6054
6533
  } catch (err) {
@@ -6067,6 +6546,7 @@ function createIkiMcpServer() {
6067
6546
  0 && (module.exports = {
6068
6547
  autoRigFromLayers,
6069
6548
  checkModelFolds,
6549
+ checkSweep,
6070
6550
  composeLayersFromParts,
6071
6551
  createIkiMcpServer,
6072
6552
  describeIki,
@@ -6076,6 +6556,7 @@ function createIkiMcpServer() {
6076
6556
  formatMeasureReport,
6077
6557
  formatPhysicsReport,
6078
6558
  formatRigPlanReport,
6559
+ formatSweepReport,
6079
6560
  formatTurnReport,
6080
6561
  listStandardParameters,
6081
6562
  measureLayers,