@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/README.md +14 -12
- package/dist/{chunk-5WHM63CL.mjs → chunk-RLBRIAVN.mjs} +591 -110
- package/dist/chunk-RLBRIAVN.mjs.map +1 -0
- package/dist/cli.js +585 -108
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +126 -1
- package/dist/index.d.ts +126 -1
- package/dist/index.js +589 -108
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -1
- package/dist/render-page.global.js +1085 -13
- package/package.json +2 -2
- package/dist/chunk-5WHM63CL.mjs.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -32,8 +32,8 @@ var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
|
32
32
|
var import_zod = require("zod");
|
|
33
33
|
|
|
34
34
|
// src/tools.ts
|
|
35
|
-
var
|
|
36
|
-
var
|
|
35
|
+
var import_node_fs5 = require("fs");
|
|
36
|
+
var import_node_path5 = __toESM(require("path"));
|
|
37
37
|
var import_format9 = require("@ikijs/format");
|
|
38
38
|
var import_editor3 = require("@ikijs/editor");
|
|
39
39
|
|
|
@@ -993,6 +993,7 @@ var HEAD_AND_GAZE = /* @__PURE__ */ new Set([
|
|
|
993
993
|
var import_format6 = require("@ikijs/format");
|
|
994
994
|
|
|
995
995
|
// ../engine/src/land.ts
|
|
996
|
+
var UNIT_QUAD = [-0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5];
|
|
996
997
|
function staticDeformers(model) {
|
|
997
998
|
return (model.deformers ?? []).map(
|
|
998
999
|
(d) => d.kind === "warp" ? { ...d, warps: void 0, warp2d: void 0 } : { ...d, bindings: void 0 }
|
|
@@ -1045,6 +1046,28 @@ function landPart(landing, store, { worlds, grids }) {
|
|
|
1045
1046
|
}
|
|
1046
1047
|
return landed;
|
|
1047
1048
|
}
|
|
1049
|
+
function landParts(model, values, partIds) {
|
|
1050
|
+
const deformers = model.deformers ?? [];
|
|
1051
|
+
const restStore = new ParameterStore(model.parameters);
|
|
1052
|
+
const store = new ParameterStore(model.parameters);
|
|
1053
|
+
for (const [id, value] of Object.entries(values)) store.set(id, value);
|
|
1054
|
+
const { worlds } = resolveDeformers(staticDeformers(model), restStore);
|
|
1055
|
+
const resolved = resolveDeformers(deformers, store);
|
|
1056
|
+
const out = /* @__PURE__ */ new Map();
|
|
1057
|
+
for (const id of partIds) {
|
|
1058
|
+
const part = model.parts.find((p) => p.id === id);
|
|
1059
|
+
if (!part) continue;
|
|
1060
|
+
const landing = landedPart(
|
|
1061
|
+
part,
|
|
1062
|
+
part.mesh?.vertices ?? UNIT_QUAD,
|
|
1063
|
+
deformers,
|
|
1064
|
+
worlds,
|
|
1065
|
+
restStore
|
|
1066
|
+
);
|
|
1067
|
+
out.set(id, Float32Array.from(landPart(landing, store, resolved)));
|
|
1068
|
+
}
|
|
1069
|
+
return out;
|
|
1070
|
+
}
|
|
1048
1071
|
|
|
1049
1072
|
// ../engine/src/folds.ts
|
|
1050
1073
|
var FLIP = 0;
|
|
@@ -1446,7 +1469,6 @@ function stopsOf(model, parameter) {
|
|
|
1446
1469
|
var DISPLACEMENT_PX = 1;
|
|
1447
1470
|
var PINNED_FRAMES = 60;
|
|
1448
1471
|
var TOLERANCE = 1e-9;
|
|
1449
|
-
var UNIT_QUAD = [-0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5];
|
|
1450
1472
|
function checkPhysics(model) {
|
|
1451
1473
|
const idle = idleRun(model);
|
|
1452
1474
|
const displace = displacer(model);
|
|
@@ -1733,8 +1755,8 @@ function ratioText(ratio) {
|
|
|
1733
1755
|
}
|
|
1734
1756
|
|
|
1735
1757
|
// src/render-poses.ts
|
|
1736
|
-
var
|
|
1737
|
-
var
|
|
1758
|
+
var import_node_fs4 = require("fs");
|
|
1759
|
+
var import_node_path4 = __toESM(require("path"));
|
|
1738
1760
|
var import_format8 = require("@ikijs/format");
|
|
1739
1761
|
|
|
1740
1762
|
// src/limits.ts
|
|
@@ -2160,16 +2182,351 @@ async function withBrowser(executable, fn) {
|
|
|
2160
2182
|
}
|
|
2161
2183
|
}
|
|
2162
2184
|
|
|
2185
|
+
// src/sweep-report.ts
|
|
2186
|
+
var LADDER_MIN = -30;
|
|
2187
|
+
var LADDER_MAX = 30;
|
|
2188
|
+
var ZERO = -LADDER_MIN;
|
|
2189
|
+
var FLAT_SLOPE = 1e-4;
|
|
2190
|
+
var PARTS = ["face", "eye_L", "eye_R", "nose"];
|
|
2191
|
+
function box(pts, fw) {
|
|
2192
|
+
let x0 = Infinity;
|
|
2193
|
+
let x1 = -Infinity;
|
|
2194
|
+
let y0 = Infinity;
|
|
2195
|
+
let y1 = -Infinity;
|
|
2196
|
+
for (let i = 0; i < pts.length; i += 2) {
|
|
2197
|
+
x0 = Math.min(x0, pts[i]);
|
|
2198
|
+
x1 = Math.max(x1, pts[i]);
|
|
2199
|
+
y0 = Math.min(y0, pts[i + 1]);
|
|
2200
|
+
y1 = Math.max(y1, pts[i + 1]);
|
|
2201
|
+
}
|
|
2202
|
+
return {
|
|
2203
|
+
x: (x0 + x1) / 2 / fw,
|
|
2204
|
+
width: (x1 - x0) / fw,
|
|
2205
|
+
y: (y0 + y1) / 2 / fw
|
|
2206
|
+
};
|
|
2207
|
+
}
|
|
2208
|
+
function nearestVertex(face, fw, x, y) {
|
|
2209
|
+
let best = 0;
|
|
2210
|
+
let bestD = Infinity;
|
|
2211
|
+
for (let i = 0; i < face.length; i += 2) {
|
|
2212
|
+
const d = (face[i] / fw - x) ** 2 + (face[i + 1] / fw - y) ** 2;
|
|
2213
|
+
if (d < bestD) {
|
|
2214
|
+
bestD = d;
|
|
2215
|
+
best = i / 2;
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
return best;
|
|
2219
|
+
}
|
|
2220
|
+
function kink(v) {
|
|
2221
|
+
const sMinus = (v[ZERO] - v[ZERO - 5]) / 5;
|
|
2222
|
+
const sPlus = (v[ZERO + 5] - v[ZERO]) / 5;
|
|
2223
|
+
const big = Math.max(Math.abs(sMinus), Math.abs(sPlus));
|
|
2224
|
+
if (big < FLAT_SLOPE) return null;
|
|
2225
|
+
return Math.abs(sPlus - sMinus) / big;
|
|
2226
|
+
}
|
|
2227
|
+
function pop(v) {
|
|
2228
|
+
let steps = 0;
|
|
2229
|
+
for (let i = 0; i + 1 < v.length; i++) steps += Math.abs(v[i + 1] - v[i]);
|
|
2230
|
+
const mean = steps / (v.length - 1);
|
|
2231
|
+
if (mean < 1e-9) return null;
|
|
2232
|
+
let most = 0;
|
|
2233
|
+
for (let i = 1; i + 1 < v.length; i++) {
|
|
2234
|
+
if (Math.abs(i - ZERO) <= 1) continue;
|
|
2235
|
+
most = Math.max(most, Math.abs(v[i + 1] - 2 * v[i] + v[i - 1]));
|
|
2236
|
+
}
|
|
2237
|
+
return most / mean;
|
|
2238
|
+
}
|
|
2239
|
+
function checkSweep(model) {
|
|
2240
|
+
const face = model.parts.find((p) => p.id === "face");
|
|
2241
|
+
if (!face) return { preset: "turn", unavailable: "no face part" };
|
|
2242
|
+
const hasEyes = ["eye_L", "eye_R"].every(
|
|
2243
|
+
(id) => model.parts.some((p) => p.id === id)
|
|
2244
|
+
);
|
|
2245
|
+
if (!hasEyes) {
|
|
2246
|
+
return { preset: "turn", unavailable: "no eye_L and eye_R parts" };
|
|
2247
|
+
}
|
|
2248
|
+
const fw = face.width;
|
|
2249
|
+
const ladder = Array.from(
|
|
2250
|
+
{ length: LADDER_MAX - LADDER_MIN + 1 },
|
|
2251
|
+
(_, i) => landParts(model, { ParamAngleX: LADDER_MIN + i }, PARTS)
|
|
2252
|
+
);
|
|
2253
|
+
const at = (id, i) => ladder[i].get(id);
|
|
2254
|
+
const ids = ["eye_L", "eye_R", ...ladder[0].has("nose") ? ["nose"] : []];
|
|
2255
|
+
const landmarks = ids.map((id) => {
|
|
2256
|
+
const boxes = ladder.map((_, i) => box(at(id, i), fw));
|
|
2257
|
+
const xs = boxes.map((b) => b.x);
|
|
2258
|
+
const plateIndex2 = nearestVertex(
|
|
2259
|
+
at("face", ZERO),
|
|
2260
|
+
fw,
|
|
2261
|
+
boxes[ZERO].x,
|
|
2262
|
+
boxes[ZERO].y
|
|
2263
|
+
);
|
|
2264
|
+
const plate = ladder.map((_, i) => at("face", i)[plateIndex2 * 2] / fw);
|
|
2265
|
+
const lead = (i) => xs[i] - plate[i] - (xs[ZERO] - plate[ZERO]);
|
|
2266
|
+
return {
|
|
2267
|
+
id,
|
|
2268
|
+
amplitude: xs[xs.length - 1] - xs[0],
|
|
2269
|
+
xKink: kink(xs),
|
|
2270
|
+
widthKink: id === "nose" ? null : kink(boxes.map((b) => b.width)),
|
|
2271
|
+
lead: { m30: lead(0), p30: lead(xs.length - 1) },
|
|
2272
|
+
pop: pop(xs)
|
|
2273
|
+
};
|
|
2274
|
+
});
|
|
2275
|
+
const eyes = ["eye_L", "eye_R"].map((id) => box(at(id, ZERO), fw));
|
|
2276
|
+
const plateIndex = nearestVertex(
|
|
2277
|
+
at("face", ZERO),
|
|
2278
|
+
fw,
|
|
2279
|
+
(eyes[0].x + eyes[1].x) / 2,
|
|
2280
|
+
(eyes[0].y + eyes[1].y) / 2
|
|
2281
|
+
);
|
|
2282
|
+
const plateX = (i) => at("face", i)[plateIndex * 2] / fw;
|
|
2283
|
+
return {
|
|
2284
|
+
preset: "turn",
|
|
2285
|
+
unit: "fw",
|
|
2286
|
+
faceWidth: fw,
|
|
2287
|
+
plateAmplitude: plateX(ladder.length - 1) - plateX(0),
|
|
2288
|
+
landmarks
|
|
2289
|
+
};
|
|
2290
|
+
}
|
|
2291
|
+
var fw3 = (v) => {
|
|
2292
|
+
const s = v.toFixed(3);
|
|
2293
|
+
return s === "-0.000" ? "0.000" : s;
|
|
2294
|
+
};
|
|
2295
|
+
var signed = (v) => fw3(v).startsWith("-") ? fw3(v) : `+${fw3(v)}`;
|
|
2296
|
+
var two = (v) => v === null ? "n/a" : v.toFixed(2);
|
|
2297
|
+
function formatSweepReport(report) {
|
|
2298
|
+
if ("unavailable" in report) {
|
|
2299
|
+
return [`SWEEP: unavailable \u2014 ${report.unavailable}`];
|
|
2300
|
+
}
|
|
2301
|
+
return [
|
|
2302
|
+
...report.landmarks.map(
|
|
2303
|
+
(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)}`
|
|
2304
|
+
),
|
|
2305
|
+
`SWEEP turn plate: amplitude ${fw3(report.plateAmplitude)} fw`
|
|
2306
|
+
];
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2309
|
+
// src/sweep.ts
|
|
2310
|
+
var import_node_fs3 = __toESM(require("fs"));
|
|
2311
|
+
var import_node_path3 = __toESM(require("path"));
|
|
2312
|
+
var SWEEP_CLOCK_HZ = 60;
|
|
2313
|
+
var SWEEP_FPS = 30;
|
|
2314
|
+
var SWEEP_DURATION_S = 3;
|
|
2315
|
+
var SWEEP_WARMUP_S = 0.5;
|
|
2316
|
+
var SWEEP_FRAME_MS = 1e3 / SWEEP_CLOCK_HZ * (1 + 1e-9);
|
|
2317
|
+
var SHEET_THETAS = [-30, -20, -10, -5, 0, 5, 10, 20, 30];
|
|
2318
|
+
var SHEET_MAX_SIDE = 2e3;
|
|
2319
|
+
var SHEET_MARGIN = 8;
|
|
2320
|
+
var SHEET_LABEL_BAND = 24;
|
|
2321
|
+
var KYMOGRAPH_BAND = 3;
|
|
2322
|
+
var SWEEP_PARAMETER = "ParamAngleX";
|
|
2323
|
+
var STEPS = SWEEP_CLOCK_HZ * SWEEP_DURATION_S;
|
|
2324
|
+
var CAPTURE_EVERY = SWEEP_CLOCK_HZ / SWEEP_FPS;
|
|
2325
|
+
var FRAMES = STEPS / CAPTURE_EVERY;
|
|
2326
|
+
var LEG_FROM_S = 0.75;
|
|
2327
|
+
var LEG_TO_S = 2.25;
|
|
2328
|
+
var AMPLITUDE_DEG = 30;
|
|
2329
|
+
function turnTheta(t) {
|
|
2330
|
+
return -AMPLITUDE_DEG * Math.sin(2 * Math.PI * t / SWEEP_DURATION_S);
|
|
2331
|
+
}
|
|
2332
|
+
function eyeRowModelPx(model) {
|
|
2333
|
+
const landed = landParts(model, {}, ["eye_L", "eye_R"]);
|
|
2334
|
+
const l = landed.get("eye_L");
|
|
2335
|
+
const r = landed.get("eye_R");
|
|
2336
|
+
if (!l || !r) return void 0;
|
|
2337
|
+
const centreY = (pts) => {
|
|
2338
|
+
let lo = Infinity;
|
|
2339
|
+
let hi = -Infinity;
|
|
2340
|
+
for (let i = 1; i < pts.length; i += 2) {
|
|
2341
|
+
lo = Math.min(lo, pts[i]);
|
|
2342
|
+
hi = Math.max(hi, pts[i]);
|
|
2343
|
+
}
|
|
2344
|
+
return (lo + hi) / 2;
|
|
2345
|
+
};
|
|
2346
|
+
return model.canvas.height / 2 - (centreY(l) + centreY(r)) / 2;
|
|
2347
|
+
}
|
|
2348
|
+
function physicsOutputIds(model) {
|
|
2349
|
+
const ids = /* @__PURE__ */ new Set();
|
|
2350
|
+
for (const rig of model.physics ?? []) ids.add(rig.output.parameter);
|
|
2351
|
+
for (const chain of model.physicsChains ?? []) {
|
|
2352
|
+
for (const seg of chain.segments) ids.add(seg.output.parameter);
|
|
2353
|
+
}
|
|
2354
|
+
return [...ids];
|
|
2355
|
+
}
|
|
2356
|
+
function sheetFrames(thetas) {
|
|
2357
|
+
const onLeg = [];
|
|
2358
|
+
for (let k = 0; k < FRAMES; k++) {
|
|
2359
|
+
const t = k / SWEEP_FPS;
|
|
2360
|
+
if (t >= LEG_FROM_S && t <= LEG_TO_S) onLeg.push(k);
|
|
2361
|
+
}
|
|
2362
|
+
const picked = [];
|
|
2363
|
+
for (const target2 of SHEET_THETAS) {
|
|
2364
|
+
let best = onLeg[0];
|
|
2365
|
+
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
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
if (!picked.includes(best)) picked.push(best);
|
|
2371
|
+
}
|
|
2372
|
+
return picked.sort((a, b) => a - b);
|
|
2373
|
+
}
|
|
2374
|
+
function sheetLabel(theta, t) {
|
|
2375
|
+
const rounded = Math.round(theta * 10) / 10 + 0;
|
|
2376
|
+
const deg = rounded.toFixed(1);
|
|
2377
|
+
const signed2 = rounded > 0 ? `+${deg}` : deg.replace("-", "\u2212");
|
|
2378
|
+
return `\u03B8 ${signed2}\xB0 t ${t.toFixed(2)} s`;
|
|
2379
|
+
}
|
|
2380
|
+
function sweepSpec(model, crop) {
|
|
2381
|
+
const thetas = Array.from(
|
|
2382
|
+
{ length: STEPS },
|
|
2383
|
+
(_, j) => turnTheta(j / SWEEP_CLOCK_HZ)
|
|
2384
|
+
);
|
|
2385
|
+
const dw = crop ? crop.dw : BUST_SIZE;
|
|
2386
|
+
const dh = crop ? crop.dh : BUST_SIZE;
|
|
2387
|
+
const m = SHEET_MARGIN;
|
|
2388
|
+
const b = SHEET_LABEL_BAND;
|
|
2389
|
+
const scale2 = Math.min(
|
|
2390
|
+
1,
|
|
2391
|
+
(SHEET_MAX_SIDE - 2 * m) / (3 * dw),
|
|
2392
|
+
(SHEET_MAX_SIDE - 2 * m - 3 * b) / (3 * dh)
|
|
2393
|
+
);
|
|
2394
|
+
const frames = sheetFrames(thetas);
|
|
2395
|
+
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";
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
return {
|
|
2411
|
+
parameter: SWEEP_PARAMETER,
|
|
2412
|
+
frameMs: SWEEP_FRAME_MS,
|
|
2413
|
+
warmup: SWEEP_WARMUP_S * SWEEP_CLOCK_HZ,
|
|
2414
|
+
thetas,
|
|
2415
|
+
captureEvery: CAPTURE_EVERY,
|
|
2416
|
+
frames: FRAMES,
|
|
2417
|
+
frame: { width: dw, height: dh },
|
|
2418
|
+
physicsOutputs: physicsOutputIds(model),
|
|
2419
|
+
sheet: {
|
|
2420
|
+
frames,
|
|
2421
|
+
cell: {
|
|
2422
|
+
w: Math.max(1, Math.floor(dw * scale2)),
|
|
2423
|
+
h: Math.max(1, Math.floor(dh * scale2))
|
|
2424
|
+
},
|
|
2425
|
+
margin: m,
|
|
2426
|
+
labelBand: b,
|
|
2427
|
+
labels: frames.map(
|
|
2428
|
+
(k) => sheetLabel(thetas[CAPTURE_EVERY * k], k / SWEEP_FPS)
|
|
2429
|
+
)
|
|
2430
|
+
},
|
|
2431
|
+
kymograph: { row, band: KYMOGRAPH_BAND, at },
|
|
2432
|
+
crop
|
|
2433
|
+
};
|
|
2434
|
+
}
|
|
2435
|
+
function flipbookHtml(manifest) {
|
|
2436
|
+
const json = JSON.stringify(manifest).replace(/</g, "\\u003c");
|
|
2437
|
+
return `<!doctype html>
|
|
2438
|
+
<html lang="en">
|
|
2439
|
+
<head>
|
|
2440
|
+
<meta charset="utf-8">
|
|
2441
|
+
<title>turn sweep</title>
|
|
2442
|
+
<style>
|
|
2443
|
+
body { font: 14px system-ui, sans-serif; margin: 16px; background: #222; color: #eee; }
|
|
2444
|
+
.row { display: flex; gap: 16px; align-items: flex-start; }
|
|
2445
|
+
img { max-width: 48vw; height: auto; background: #444; }
|
|
2446
|
+
#b { display: none; }
|
|
2447
|
+
#controls { margin: 12px 0; display: flex; gap: 12px; align-items: center; }
|
|
2448
|
+
#scrub { flex: 1; max-width: 640px; }
|
|
2449
|
+
</style>
|
|
2450
|
+
</head>
|
|
2451
|
+
<body>
|
|
2452
|
+
<div class="row"><img id="a" alt="A"><img id="b" alt="B"></div>
|
|
2453
|
+
<div id="controls">
|
|
2454
|
+
<button id="play" type="button">pause</button>
|
|
2455
|
+
<input id="scrub" type="range" min="0" value="0" step="1">
|
|
2456
|
+
<span id="readout"></span>
|
|
2457
|
+
</div>
|
|
2458
|
+
<p>Add <code>?b=<relative dir></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>
|
|
2459
|
+
<script id="manifest" type="application/json">${json}</script>
|
|
2460
|
+
<script>
|
|
2461
|
+
(function () {
|
|
2462
|
+
var m = JSON.parse(document.getElementById("manifest").textContent);
|
|
2463
|
+
var b = new URLSearchParams(location.search).get("b");
|
|
2464
|
+
var a = document.getElementById("a");
|
|
2465
|
+
var bi = document.getElementById("b");
|
|
2466
|
+
var scrub = document.getElementById("scrub");
|
|
2467
|
+
var readout = document.getElementById("readout");
|
|
2468
|
+
var play = document.getElementById("play");
|
|
2469
|
+
var n = m.frames.length;
|
|
2470
|
+
var i = 0;
|
|
2471
|
+
var playing = true;
|
|
2472
|
+
scrub.max = String(n - 1);
|
|
2473
|
+
if (b) { bi.style.display = "block"; }
|
|
2474
|
+
function show(k) {
|
|
2475
|
+
i = k;
|
|
2476
|
+
var f = m.frames[k];
|
|
2477
|
+
a.src = f.file;
|
|
2478
|
+
if (b) { bi.src = b.replace(/\\/$/, "") + "/" + f.file; }
|
|
2479
|
+
scrub.value = String(k);
|
|
2480
|
+
readout.textContent = "frame " + k + " \\u03b8 " + f.theta.toFixed(1) + "\\u00b0 t " + f.t.toFixed(2) + " s";
|
|
2481
|
+
}
|
|
2482
|
+
play.addEventListener("click", function () {
|
|
2483
|
+
playing = !playing;
|
|
2484
|
+
play.textContent = playing ? "pause" : "play";
|
|
2485
|
+
});
|
|
2486
|
+
scrub.addEventListener("input", function () {
|
|
2487
|
+
playing = false;
|
|
2488
|
+
play.textContent = "play";
|
|
2489
|
+
show(Number(scrub.value));
|
|
2490
|
+
});
|
|
2491
|
+
setInterval(function () { if (playing) { show((i + 1) % n); } }, 1000 / m.fps);
|
|
2492
|
+
show(0);
|
|
2493
|
+
})();
|
|
2494
|
+
</script>
|
|
2495
|
+
</body>
|
|
2496
|
+
</html>
|
|
2497
|
+
`;
|
|
2498
|
+
}
|
|
2499
|
+
function prepareSweepDir(outDir, name) {
|
|
2500
|
+
const dir = import_node_path3.default.join(outDir, name);
|
|
2501
|
+
try {
|
|
2502
|
+
import_node_fs3.default.mkdirSync(dir);
|
|
2503
|
+
} catch (e) {
|
|
2504
|
+
if (e.code !== "EEXIST") {
|
|
2505
|
+
throw new AutoRigInputError(`sweep dir: ${e.message}`);
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
const stat = import_node_fs3.default.lstatSync(dir);
|
|
2509
|
+
if (stat.isSymbolicLink()) {
|
|
2510
|
+
throw new AutoRigInputError(`sweep.name names ${dir}, a symbolic link`);
|
|
2511
|
+
}
|
|
2512
|
+
if (!stat.isDirectory()) {
|
|
2513
|
+
throw new AutoRigInputError(`sweep.name names ${dir}, not a directory`);
|
|
2514
|
+
}
|
|
2515
|
+
const real = confineToWorkingDirectory(process.cwd(), dir, "sweep dir", name);
|
|
2516
|
+
return real;
|
|
2517
|
+
}
|
|
2518
|
+
|
|
2163
2519
|
// src/render-poses.ts
|
|
2164
2520
|
var FULL_BODY_VIEW_WIDTH = 2.5;
|
|
2165
2521
|
var BUST_SIZE = 560;
|
|
2166
2522
|
var CROP_WIDTH = 720;
|
|
2167
2523
|
var CROP_MAX_HEIGHT = 8192;
|
|
2168
2524
|
var POSE_NAME = /^[A-Za-z0-9_.-]+$/;
|
|
2525
|
+
var SWEEP_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
|
|
2169
2526
|
function bustPadY(width, height) {
|
|
2170
2527
|
return Math.max(0, (BUST_SIZE - BUST_SIZE * height / width) / 2);
|
|
2171
2528
|
}
|
|
2172
|
-
function planRenders(model, requested) {
|
|
2529
|
+
function planRenders(model, requested, sweep) {
|
|
2173
2530
|
const { width: W, height: H } = model.canvas;
|
|
2174
2531
|
const fullBody = H > W;
|
|
2175
2532
|
const canvas = fullBody ? {
|
|
@@ -2199,40 +2556,49 @@ function planRenders(model, requested) {
|
|
|
2199
2556
|
name,
|
|
2200
2557
|
values
|
|
2201
2558
|
});
|
|
2559
|
+
const toRenderCrop = (crop, label) => {
|
|
2560
|
+
const left = Math.max(crop.x, 0);
|
|
2561
|
+
const top = Math.max(crop.y, 0);
|
|
2562
|
+
const w = Math.min(crop.x + crop.w, W) - left;
|
|
2563
|
+
const h = Math.min(crop.y + crop.h, H) - top;
|
|
2564
|
+
if (!(w > 0 && h > 0)) {
|
|
2565
|
+
throw new AutoRigInputError(
|
|
2566
|
+
`${label} does not overlap the model's ${W}x${H} canvas`
|
|
2567
|
+
);
|
|
2568
|
+
}
|
|
2569
|
+
const dh = Math.round(CROP_WIDTH * h / w);
|
|
2570
|
+
if (dh < 1 || dh > CROP_MAX_HEIGHT) {
|
|
2571
|
+
throw new AutoRigInputError(
|
|
2572
|
+
`${label} meets the canvas in ${w}x${h} model px, which ${CROP_WIDTH} px wide draws ${dh} px tall, outside 1..${CROP_MAX_HEIGHT}`
|
|
2573
|
+
);
|
|
2574
|
+
}
|
|
2575
|
+
return {
|
|
2576
|
+
sx: x0 + left * s,
|
|
2577
|
+
sy: y0 + top * s,
|
|
2578
|
+
sw: w * s,
|
|
2579
|
+
sh: h * s,
|
|
2580
|
+
dw: CROP_WIDTH,
|
|
2581
|
+
dh
|
|
2582
|
+
};
|
|
2583
|
+
};
|
|
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
|
+
);
|
|
2588
|
+
}
|
|
2589
|
+
const sweepCrop = sweep ? sweep.crop ? toRenderCrop(sweep.crop, "sweep.crop") : squareCrop : void 0;
|
|
2202
2590
|
if (requested) {
|
|
2203
2591
|
if (requested.length === 0) throw new AutoRigInputError("poses is empty");
|
|
2204
2592
|
const poses2 = requested.map((pose, i) => {
|
|
2205
2593
|
checkRequest(requested, i);
|
|
2206
2594
|
if (!pose.crop) return square(pose.name, pose.values);
|
|
2207
|
-
const left = Math.max(pose.crop.x, 0);
|
|
2208
|
-
const top = Math.max(pose.crop.y, 0);
|
|
2209
|
-
const w = Math.min(pose.crop.x + pose.crop.w, W) - left;
|
|
2210
|
-
const h = Math.min(pose.crop.y + pose.crop.h, H) - top;
|
|
2211
|
-
if (!(w > 0 && h > 0)) {
|
|
2212
|
-
throw new AutoRigInputError(
|
|
2213
|
-
`poses[${i}].crop does not overlap the model's ${W}x${H} canvas`
|
|
2214
|
-
);
|
|
2215
|
-
}
|
|
2216
|
-
const dh = Math.round(CROP_WIDTH * h / w);
|
|
2217
|
-
if (dh < 1 || dh > CROP_MAX_HEIGHT) {
|
|
2218
|
-
throw new AutoRigInputError(
|
|
2219
|
-
`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}`
|
|
2220
|
-
);
|
|
2221
|
-
}
|
|
2222
2595
|
return {
|
|
2223
2596
|
name: pose.name,
|
|
2224
2597
|
values: pose.values,
|
|
2225
|
-
crop: {
|
|
2226
|
-
sx: x0 + left * s,
|
|
2227
|
-
sy: y0 + top * s,
|
|
2228
|
-
sw: w * s,
|
|
2229
|
-
sh: h * s,
|
|
2230
|
-
dw: CROP_WIDTH,
|
|
2231
|
-
dh
|
|
2232
|
-
}
|
|
2598
|
+
crop: toRenderCrop(pose.crop, `poses[${i}].crop`)
|
|
2233
2599
|
};
|
|
2234
2600
|
});
|
|
2235
|
-
return { canvas, view, fullBody, mouth, poses: poses2 };
|
|
2601
|
+
return { canvas, view, fullBody, mouth, poses: poses2, sweepCrop };
|
|
2236
2602
|
}
|
|
2237
2603
|
const bodyAngles = Object.fromEntries(
|
|
2238
2604
|
[
|
|
@@ -2340,7 +2706,7 @@ function planRenders(model, requested) {
|
|
|
2340
2706
|
);
|
|
2341
2707
|
}
|
|
2342
2708
|
}
|
|
2343
|
-
return { canvas, view, fullBody, mouth, poses };
|
|
2709
|
+
return { canvas, view, fullBody, mouth, poses, sweepCrop };
|
|
2344
2710
|
}
|
|
2345
2711
|
function checkRequest(requested, i) {
|
|
2346
2712
|
const { name, values } = requested[i];
|
|
@@ -2372,7 +2738,7 @@ var CAPTURE_MS = 15e3;
|
|
|
2372
2738
|
function readPageScript() {
|
|
2373
2739
|
const url = new URL("../dist/render-page.global.js", importMetaUrl);
|
|
2374
2740
|
try {
|
|
2375
|
-
return (0,
|
|
2741
|
+
return (0, import_node_fs4.readFileSync)(url, "utf8");
|
|
2376
2742
|
} catch (cause) {
|
|
2377
2743
|
throw new Error(
|
|
2378
2744
|
"could not read the render page script; run `pnpm build` in packages/mcp",
|
|
@@ -2380,6 +2746,86 @@ function readPageScript() {
|
|
|
2380
2746
|
);
|
|
2381
2747
|
}
|
|
2382
2748
|
}
|
|
2749
|
+
async function captureSweep(evaluate, model, plan, requested, dir, report) {
|
|
2750
|
+
const spec = sweepSpec(model, plan.sweepCrop);
|
|
2751
|
+
await evaluate(
|
|
2752
|
+
`window.__ikiRender.sweepBegin(${JSON.stringify(spec)})`,
|
|
2753
|
+
CAPTURE_MS
|
|
2754
|
+
);
|
|
2755
|
+
const frames = [];
|
|
2756
|
+
for (let k = 0; k < spec.frames; k++) {
|
|
2757
|
+
const { png, values } = await evaluate(
|
|
2758
|
+
"window.__ikiRender.sweepFrame()",
|
|
2759
|
+
CAPTURE_MS
|
|
2760
|
+
);
|
|
2761
|
+
if (typeof png !== "string" || !png.startsWith(PNG_PREFIX)) {
|
|
2762
|
+
throw new Error(
|
|
2763
|
+
`sweep ${requested.name} frame ${k}: the page returned no PNG`
|
|
2764
|
+
);
|
|
2765
|
+
}
|
|
2766
|
+
const file = `f${String(k).padStart(3, "0")}.png`;
|
|
2767
|
+
writeFileAtomic(
|
|
2768
|
+
import_node_path4.default.join(dir, file),
|
|
2769
|
+
Buffer.from(png.slice(PNG_PREFIX.length), "base64")
|
|
2770
|
+
);
|
|
2771
|
+
frames.push({
|
|
2772
|
+
i: k,
|
|
2773
|
+
file,
|
|
2774
|
+
t: k / SWEEP_FPS,
|
|
2775
|
+
theta: spec.thetas[spec.captureEvery * k],
|
|
2776
|
+
values
|
|
2777
|
+
});
|
|
2778
|
+
}
|
|
2779
|
+
const end = await evaluate("window.__ikiRender.sweepEnd()", CAPTURE_MS);
|
|
2780
|
+
for (const [what, url] of Object.entries(end)) {
|
|
2781
|
+
if (typeof url !== "string" || !url.startsWith(PNG_PREFIX)) {
|
|
2782
|
+
throw new Error(
|
|
2783
|
+
`sweep ${requested.name} ${what}: the page returned no PNG`
|
|
2784
|
+
);
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
const sheet = import_node_path4.default.join(dir, "sheet.png");
|
|
2788
|
+
const kymograph = import_node_path4.default.join(dir, "kymograph.png");
|
|
2789
|
+
writeFileAtomic(
|
|
2790
|
+
sheet,
|
|
2791
|
+
Buffer.from(end.sheet.slice(PNG_PREFIX.length), "base64")
|
|
2792
|
+
);
|
|
2793
|
+
writeFileAtomic(
|
|
2794
|
+
kymograph,
|
|
2795
|
+
Buffer.from(end.kymograph.slice(PNG_PREFIX.length), "base64")
|
|
2796
|
+
);
|
|
2797
|
+
const manifest = {
|
|
2798
|
+
version: 1,
|
|
2799
|
+
preset: requested.preset,
|
|
2800
|
+
parameter: spec.parameter,
|
|
2801
|
+
fps: SWEEP_FPS,
|
|
2802
|
+
clockHz: SWEEP_CLOCK_HZ,
|
|
2803
|
+
warmupS: SWEEP_WARMUP_S,
|
|
2804
|
+
durationS: SWEEP_DURATION_S,
|
|
2805
|
+
crop: requested.crop ?? null,
|
|
2806
|
+
frame: spec.frame,
|
|
2807
|
+
kymographRow: { row: spec.kymograph.row, at: spec.kymograph.at },
|
|
2808
|
+
sheet: { frames: spec.sheet.frames, cell: spec.sheet.cell },
|
|
2809
|
+
physicsOutputs: spec.physicsOutputs,
|
|
2810
|
+
frames
|
|
2811
|
+
};
|
|
2812
|
+
const manifestPath = import_node_path4.default.join(dir, "manifest.json");
|
|
2813
|
+
const flipbook = import_node_path4.default.join(dir, "index.html");
|
|
2814
|
+
writeFileAtomic(manifestPath, JSON.stringify(manifest, null, 2) + "\n");
|
|
2815
|
+
writeFileAtomic(flipbook, flipbookHtml(manifest));
|
|
2816
|
+
return {
|
|
2817
|
+
name: requested.name,
|
|
2818
|
+
preset: requested.preset,
|
|
2819
|
+
dir,
|
|
2820
|
+
fps: SWEEP_FPS,
|
|
2821
|
+
frames: spec.frames,
|
|
2822
|
+
manifest: manifestPath,
|
|
2823
|
+
sheet,
|
|
2824
|
+
kymograph,
|
|
2825
|
+
flipbook,
|
|
2826
|
+
report
|
|
2827
|
+
};
|
|
2828
|
+
}
|
|
2383
2829
|
async function renderPoses(input) {
|
|
2384
2830
|
try {
|
|
2385
2831
|
const modelFile = confineToWorkingDirectory(
|
|
@@ -2389,8 +2835,8 @@ async function renderPoses(input) {
|
|
|
2389
2835
|
input.modelPath
|
|
2390
2836
|
);
|
|
2391
2837
|
const outDir = resolveOutputDir(input.outDir);
|
|
2392
|
-
const model = (0, import_format8.loadIkiModel)((0,
|
|
2393
|
-
const plan = planRenders(model, input.poses);
|
|
2838
|
+
const model = (0, import_format8.loadIkiModel)((0, import_node_fs4.readFileSync)(modelFile, "utf8"));
|
|
2839
|
+
const plan = planRenders(model, input.poses, input.sweep);
|
|
2394
2840
|
const browser = findBrowser();
|
|
2395
2841
|
if (!browser) return { ok: false, error: NO_BROWSER_MESSAGE };
|
|
2396
2842
|
const pageScript = readPageScript();
|
|
@@ -2399,7 +2845,9 @@ async function renderPoses(input) {
|
|
|
2399
2845
|
input.poses?.map((p) => p.values)
|
|
2400
2846
|
);
|
|
2401
2847
|
const physics = checkPhysics(model);
|
|
2402
|
-
const
|
|
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(
|
|
2403
2851
|
browser,
|
|
2404
2852
|
async (evaluate) => {
|
|
2405
2853
|
await evaluate(pageScript, PAGE_SCRIPT_MS);
|
|
@@ -2416,14 +2864,22 @@ async function renderPoses(input) {
|
|
|
2416
2864
|
if (typeof url !== "string" || !url.startsWith(PNG_PREFIX)) {
|
|
2417
2865
|
throw new Error(`pose ${pose.name}: the page returned no PNG`);
|
|
2418
2866
|
}
|
|
2419
|
-
const file =
|
|
2867
|
+
const file = import_node_path4.default.join(outDir, `${pose.name}.png`);
|
|
2420
2868
|
writeFileAtomic(
|
|
2421
2869
|
file,
|
|
2422
2870
|
Buffer.from(url.slice(PNG_PREFIX.length), "base64")
|
|
2423
2871
|
);
|
|
2424
2872
|
written.push({ name: pose.name, path: file });
|
|
2425
2873
|
}
|
|
2426
|
-
|
|
2874
|
+
const sweep2 = input.sweep && sweepDir && sweepReport ? await captureSweep(
|
|
2875
|
+
evaluate,
|
|
2876
|
+
model,
|
|
2877
|
+
plan,
|
|
2878
|
+
input.sweep,
|
|
2879
|
+
sweepDir,
|
|
2880
|
+
sweepReport
|
|
2881
|
+
) : void 0;
|
|
2882
|
+
return { failedTextures: loaded.failedTextures, poses: written, sweep: sweep2 };
|
|
2427
2883
|
}
|
|
2428
2884
|
);
|
|
2429
2885
|
return {
|
|
@@ -2436,7 +2892,8 @@ async function renderPoses(input) {
|
|
|
2436
2892
|
poses,
|
|
2437
2893
|
modelCanvas: model.canvas,
|
|
2438
2894
|
folds,
|
|
2439
|
-
physics
|
|
2895
|
+
physics,
|
|
2896
|
+
sweep
|
|
2440
2897
|
};
|
|
2441
2898
|
} catch (error) {
|
|
2442
2899
|
if (error instanceof AutoRigInputError || error instanceof import_format8.IkiFormatError) {
|
|
@@ -2544,7 +3001,7 @@ function describeIki(model) {
|
|
|
2544
3001
|
const padY = bustPadY(W, H);
|
|
2545
3002
|
const tenth = (n) => Math.round(n * 10) / 10;
|
|
2546
3003
|
const parts = m.parts.map((p) => {
|
|
2547
|
-
const
|
|
3004
|
+
const box2 = {
|
|
2548
3005
|
x: W / 2 + p.transform.x - p.width / 2,
|
|
2549
3006
|
y: H / 2 - p.transform.y - p.height / 2,
|
|
2550
3007
|
w: p.width,
|
|
@@ -2553,12 +3010,12 @@ function describeIki(model) {
|
|
|
2553
3010
|
const entry = {
|
|
2554
3011
|
id: p.id,
|
|
2555
3012
|
order: p.order,
|
|
2556
|
-
box,
|
|
3013
|
+
box: box2,
|
|
2557
3014
|
bustBox: {
|
|
2558
|
-
x: tenth(
|
|
2559
|
-
y: tenth(padY +
|
|
2560
|
-
w: tenth(
|
|
2561
|
-
h: tenth(
|
|
3015
|
+
x: tenth(box2.x * bustScale),
|
|
3016
|
+
y: tenth(padY + box2.y * bustScale),
|
|
3017
|
+
w: tenth(box2.w * bustScale),
|
|
3018
|
+
h: tenth(box2.h * bustScale)
|
|
2562
3019
|
}
|
|
2563
3020
|
};
|
|
2564
3021
|
if (p.deformer !== void 0) entry.deformer = p.deformer;
|
|
@@ -2628,7 +3085,7 @@ function describeIkiAt(modelPath) {
|
|
|
2628
3085
|
"model path",
|
|
2629
3086
|
modelPath
|
|
2630
3087
|
);
|
|
2631
|
-
return describeIki((0,
|
|
3088
|
+
return describeIki((0, import_node_fs5.readFileSync)(modelFile, "utf8"));
|
|
2632
3089
|
} catch (e) {
|
|
2633
3090
|
if (e instanceof AutoRigInputError) return { ok: false, error: e.message };
|
|
2634
3091
|
throw e;
|
|
@@ -2839,7 +3296,7 @@ async function autoRigFromLayers(input) {
|
|
|
2839
3296
|
}
|
|
2840
3297
|
const resolvedLayers = layers.map((layer) => {
|
|
2841
3298
|
const resolved = resolveInputPath(layer.path);
|
|
2842
|
-
return { resolved, fileName: layer.fileName ??
|
|
3299
|
+
return { resolved, fileName: layer.fileName ?? import_node_path5.default.basename(resolved) };
|
|
2843
3300
|
});
|
|
2844
3301
|
const rolePairs = expectInput(
|
|
2845
3302
|
"role parsing",
|
|
@@ -3004,8 +3461,8 @@ async function autoRigFromLayers(input) {
|
|
|
3004
3461
|
}
|
|
3005
3462
|
|
|
3006
3463
|
// src/compose.ts
|
|
3007
|
-
var
|
|
3008
|
-
var
|
|
3464
|
+
var import_node_fs7 = __toESM(require("fs"));
|
|
3465
|
+
var import_node_path10 = __toESM(require("path"));
|
|
3009
3466
|
var import_sharp4 = __toESM(require("sharp"));
|
|
3010
3467
|
var import_editor12 = require("@ikijs/editor");
|
|
3011
3468
|
|
|
@@ -3076,18 +3533,18 @@ function boxWithoutStraySpecks(rgba, W, H) {
|
|
|
3076
3533
|
}
|
|
3077
3534
|
|
|
3078
3535
|
// src/measure.ts
|
|
3079
|
-
var
|
|
3080
|
-
var
|
|
3536
|
+
var import_node_fs6 = __toESM(require("fs"));
|
|
3537
|
+
var import_node_path9 = __toESM(require("path"));
|
|
3081
3538
|
|
|
3082
3539
|
// src/measure-arms.ts
|
|
3083
|
-
var
|
|
3540
|
+
var import_node_path6 = __toESM(require("path"));
|
|
3084
3541
|
var import_editor5 = require("@ikijs/editor");
|
|
3085
3542
|
var ARM_ROLES = ["arm_L", "arm_R"];
|
|
3086
3543
|
var CAP_OVERLAP = 0.5;
|
|
3087
3544
|
var px = (v) => `${Number(v.toFixed(1))}`;
|
|
3088
3545
|
async function measured(measurer, absDir, role) {
|
|
3089
3546
|
const fileName = `${role}.png`;
|
|
3090
|
-
const { rgba } = await decodePng(
|
|
3547
|
+
const { rgba } = await decodePng(import_node_path6.default.join(absDir, fileName));
|
|
3091
3548
|
return measurer.add({ role, fileName, rgba });
|
|
3092
3549
|
}
|
|
3093
3550
|
async function armWarnings(absDir, layers) {
|
|
@@ -3237,7 +3694,7 @@ function jointWarnings(pose, arm, stats, a, armLayer, b) {
|
|
|
3237
3694
|
}
|
|
3238
3695
|
|
|
3239
3696
|
// src/measure-lips.ts
|
|
3240
|
-
var
|
|
3697
|
+
var import_node_path7 = __toESM(require("path"));
|
|
3241
3698
|
var import_editor8 = require("@ikijs/editor");
|
|
3242
3699
|
|
|
3243
3700
|
// src/compose-lips.ts
|
|
@@ -3271,7 +3728,7 @@ function components(mask, W, H) {
|
|
|
3271
3728
|
for (let start = 0; start < n; start++) {
|
|
3272
3729
|
if (!mask[start] || label[start] >= 0) continue;
|
|
3273
3730
|
const id = sizes.length;
|
|
3274
|
-
const
|
|
3731
|
+
const box2 = { x0: W, y0: H, x1: -1, y1: -1 };
|
|
3275
3732
|
let size = 0;
|
|
3276
3733
|
let depth = 0;
|
|
3277
3734
|
label[start] = id;
|
|
@@ -3281,10 +3738,10 @@ function components(mask, W, H) {
|
|
|
3281
3738
|
size++;
|
|
3282
3739
|
const px2 = p % W;
|
|
3283
3740
|
const py = (p - px2) / W;
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3741
|
+
box2.x0 = Math.min(box2.x0, px2);
|
|
3742
|
+
box2.x1 = Math.max(box2.x1, px2);
|
|
3743
|
+
box2.y0 = Math.min(box2.y0, py);
|
|
3744
|
+
box2.y1 = Math.max(box2.y1, py);
|
|
3288
3745
|
for (let y = Math.max(0, py - 1); y <= Math.min(H - 1, py + 1); y++) {
|
|
3289
3746
|
for (let x = Math.max(0, px2 - 1); x <= Math.min(W - 1, px2 + 1); x++) {
|
|
3290
3747
|
if (x !== px2 && y !== py) continue;
|
|
@@ -3297,7 +3754,7 @@ function components(mask, W, H) {
|
|
|
3297
3754
|
}
|
|
3298
3755
|
}
|
|
3299
3756
|
sizes.push(size);
|
|
3300
|
-
boxes.push(
|
|
3757
|
+
boxes.push(box2);
|
|
3301
3758
|
}
|
|
3302
3759
|
return { label, sizes, boxes };
|
|
3303
3760
|
}
|
|
@@ -3534,14 +3991,14 @@ async function prepInterior(rgba, W, H) {
|
|
|
3534
3991
|
for (let p = 0; p < cw * ch; p++) {
|
|
3535
3992
|
if (label[p] >= 0 && rim[label[p]]) crop[p * 4 + 3] = 0;
|
|
3536
3993
|
}
|
|
3537
|
-
const
|
|
3538
|
-
if (
|
|
3994
|
+
const box2 = drawingBox(crop, cw, ch);
|
|
3995
|
+
if (box2 === null) throw empty;
|
|
3539
3996
|
const sum = [0, 0, 0];
|
|
3540
3997
|
const all = [0, 0, 0];
|
|
3541
3998
|
let dark = 0;
|
|
3542
3999
|
let count = 0;
|
|
3543
|
-
for (let y =
|
|
3544
|
-
for (let x =
|
|
4000
|
+
for (let y = box2.y; y < box2.y + box2.h; y++) {
|
|
4001
|
+
for (let x = box2.x; x < box2.x + box2.w; x++) {
|
|
3545
4002
|
const i = (y * cw + x) * 4;
|
|
3546
4003
|
if (crop[i + 3] < import_editor7.ALPHA_OPAQUE) continue;
|
|
3547
4004
|
count++;
|
|
@@ -3555,7 +4012,7 @@ async function prepInterior(rgba, W, H) {
|
|
|
3555
4012
|
if (count === 0) throw empty;
|
|
3556
4013
|
const [from, over] = dark > 0 ? [sum, dark] : [all, count];
|
|
3557
4014
|
const cavity = from.map((v) => Math.round(v / over));
|
|
3558
|
-
return { png: await cropToBuffer(crop, cw, ch,
|
|
4015
|
+
return { png: await cropToBuffer(crop, cw, ch, box2), cavity };
|
|
3559
4016
|
}
|
|
3560
4017
|
var rawOf = async (png) => (0, import_sharp2.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
3561
4018
|
var encode = (rgba, w, h) => (0, import_sharp2.default)(rgba, { raw: { width: w, height: h, channels: 4 } }).png().toBuffer();
|
|
@@ -3598,8 +4055,8 @@ function enclosedHole(frame, w, h) {
|
|
|
3598
4055
|
`${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`
|
|
3599
4056
|
);
|
|
3600
4057
|
}
|
|
3601
|
-
const
|
|
3602
|
-
const holeW =
|
|
4058
|
+
const box2 = boxes[main2];
|
|
4059
|
+
const holeW = box2.x1 - box2.x0 + 1;
|
|
3603
4060
|
if (holeW < MIN_OPENING_WIDTH * w) {
|
|
3604
4061
|
throw new AutoRigInputError(
|
|
3605
4062
|
`${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`
|
|
@@ -3613,7 +4070,7 @@ function enclosedHole(frame, w, h) {
|
|
|
3613
4070
|
`${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`
|
|
3614
4071
|
);
|
|
3615
4072
|
}
|
|
3616
|
-
return { label, main: main2, box };
|
|
4073
|
+
return { label, main: main2, box: box2 };
|
|
3617
4074
|
}
|
|
3618
4075
|
function measureLips(layers, w, h) {
|
|
3619
4076
|
const measurer = (0, import_editor7.createLayerSetMeasurer)({ width: w, height: h });
|
|
@@ -3881,15 +4338,15 @@ async function lipWarnings(absDir, layers) {
|
|
|
3881
4338
|
return { warnings };
|
|
3882
4339
|
}
|
|
3883
4340
|
}
|
|
3884
|
-
const
|
|
4341
|
+
const box2 = (m) => ({
|
|
3885
4342
|
x0: m.bboxCx - m.w / 2,
|
|
3886
4343
|
x1: m.bboxCx + m.w / 2,
|
|
3887
4344
|
y0: m.bboxCy - m.h / 2,
|
|
3888
4345
|
y1: m.bboxCy + m.h / 2
|
|
3889
4346
|
});
|
|
3890
|
-
const cavity =
|
|
4347
|
+
const cavity = box2(inner);
|
|
3891
4348
|
for (const role of inside) {
|
|
3892
|
-
const b =
|
|
4349
|
+
const b = box2(layers[role]);
|
|
3893
4350
|
if (b.x0 < cavity.x0 || b.x1 > cavity.x1 || b.y0 < cavity.y0 || b.y1 > cavity.y1) {
|
|
3894
4351
|
warnings.push(
|
|
3895
4352
|
`${role}: its box leaves mouth_inner's \u2014 the cavity clips it away there. Recompose from mouth_keyed.png + mouth_interior.png (free).`
|
|
@@ -3904,7 +4361,7 @@ async function lipWarnings(absDir, layers) {
|
|
|
3904
4361
|
const green = [];
|
|
3905
4362
|
for (const role of import_editor8.LIP_ROLES) {
|
|
3906
4363
|
const fileName = `${role}.png`;
|
|
3907
|
-
const { rgba } = await decodePng(
|
|
4364
|
+
const { rgba } = await decodePng(import_node_path7.default.join(absDir, fileName));
|
|
3908
4365
|
set.set(role, measurer.add({ role, fileName, rgba }));
|
|
3909
4366
|
for (let i = 0; i < rgba.length; i += 4) {
|
|
3910
4367
|
if (rgba[i + 3] >= import_editor8.ALPHA_OPAQUE && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > GREEN_EXCESS) {
|
|
@@ -4008,7 +4465,7 @@ async function lipWarnings(absDir, layers) {
|
|
|
4008
4465
|
}
|
|
4009
4466
|
|
|
4010
4467
|
// src/measure-turn.ts
|
|
4011
|
-
var
|
|
4468
|
+
var import_node_path8 = __toESM(require("path"));
|
|
4012
4469
|
var import_editor9 = require("@ikijs/editor");
|
|
4013
4470
|
var import_editor10 = require("@ikijs/editor");
|
|
4014
4471
|
var DEFAULT_IRIS = { hueMin: 230, hueMax: 300, satMin: 0.22 };
|
|
@@ -4276,14 +4733,14 @@ function farNearWidths(m, turnSign) {
|
|
|
4276
4733
|
return turnSign < 0 ? { far: m.irisL.w, near: m.irisR.w } : { far: m.irisR.w, near: m.irisL.w };
|
|
4277
4734
|
}
|
|
4278
4735
|
function overlaySvg(m) {
|
|
4279
|
-
const
|
|
4736
|
+
const box2 = (b, stroke) => `<rect x="${b.x0}" y="${b.y0}" width="${b.w}" height="${b.h}" fill="none" stroke="${stroke}" stroke-width="3"/>`;
|
|
4280
4737
|
const tick = (x, half, stroke) => `<line x1="${x}" y1="${m.eyeRow - half}" x2="${x}" y2="${m.eyeRow + half}" stroke="${stroke}" stroke-width="3"/>`;
|
|
4281
|
-
return `<svg width="${m.width}" height="${m.height}">` +
|
|
4738
|
+
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>";
|
|
4282
4739
|
}
|
|
4283
4740
|
async function writeOverlay(debugDir, label, m) {
|
|
4284
|
-
const outPath =
|
|
4741
|
+
const outPath = import_node_path8.default.join(
|
|
4285
4742
|
debugDir,
|
|
4286
|
-
`${label}-${
|
|
4743
|
+
`${label}-${import_node_path8.default.basename(m.file, ".png")}.debug.png`
|
|
4287
4744
|
);
|
|
4288
4745
|
writeFileAtomic(outPath, await encodeOverlayPng(m.file, overlaySvg(m)));
|
|
4289
4746
|
return outPath;
|
|
@@ -4475,7 +4932,7 @@ async function lashOffSclera(eyePath, lashPath) {
|
|
|
4475
4932
|
return { opaque, off };
|
|
4476
4933
|
}
|
|
4477
4934
|
async function measureDir(absDir, noseSpeck) {
|
|
4478
|
-
const files =
|
|
4935
|
+
const files = import_node_fs6.default.readdirSync(absDir).filter((f) => f.endsWith(".png") && !f.startsWith("preview")).sort();
|
|
4479
4936
|
if (files.length === 0) {
|
|
4480
4937
|
throw new AutoRigInputError(`no role layers in ${absDir}`);
|
|
4481
4938
|
}
|
|
@@ -4487,8 +4944,8 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
4487
4944
|
const layers = {};
|
|
4488
4945
|
const empty = [];
|
|
4489
4946
|
for (const f of files) {
|
|
4490
|
-
const role =
|
|
4491
|
-
const m = await layerStats(
|
|
4947
|
+
const role = import_node_path9.default.basename(f, ".png");
|
|
4948
|
+
const m = await layerStats(import_node_path9.default.join(absDir, f));
|
|
4492
4949
|
if (!m) {
|
|
4493
4950
|
empty.push(role);
|
|
4494
4951
|
continue;
|
|
@@ -4566,8 +5023,8 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
4566
5023
|
}
|
|
4567
5024
|
if (lash) {
|
|
4568
5025
|
const { opaque, off } = await lashOffSclera(
|
|
4569
|
-
|
|
4570
|
-
|
|
5026
|
+
import_node_path9.default.join(absDir, `eye_${side}.png`),
|
|
5027
|
+
import_node_path9.default.join(absDir, `lash_${side}.png`)
|
|
4571
5028
|
);
|
|
4572
5029
|
const dTop = lash.marginTop - eye.marginTop;
|
|
4573
5030
|
const faults = [
|
|
@@ -4593,7 +5050,7 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
4593
5050
|
if (noseSpeck !== void 0) {
|
|
4594
5051
|
warnings.push(noseSpeckWarning(noseSpeck, "compose"));
|
|
4595
5052
|
} else if (layers.nose !== void 0) {
|
|
4596
|
-
const nose = await decodePng(
|
|
5053
|
+
const nose = await decodePng(import_node_path9.default.join(absDir, "nose.png"));
|
|
4597
5054
|
const core = (0, import_editor10.denseCoreOf)(nose.rgba, nose.width, nose.height);
|
|
4598
5055
|
if (core !== null) {
|
|
4599
5056
|
const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
|
|
@@ -5028,8 +5485,8 @@ async function trimmedPart(role, cfg, partsDir, inMemory, flipSource) {
|
|
|
5028
5485
|
if (inMemory !== void 0) {
|
|
5029
5486
|
img = (0, import_sharp4.default)(inMemory);
|
|
5030
5487
|
} else {
|
|
5031
|
-
const srcPath =
|
|
5032
|
-
if (!
|
|
5488
|
+
const srcPath = import_node_path10.default.join(partsDir, cfg.src);
|
|
5489
|
+
if (!import_node_fs7.default.existsSync(srcPath)) {
|
|
5033
5490
|
if (cfg.optional) return null;
|
|
5034
5491
|
throw new AutoRigInputError(
|
|
5035
5492
|
`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" : "")
|
|
@@ -5046,8 +5503,8 @@ async function trimmedPart(role, cfg, partsDir, inMemory, flipSource) {
|
|
|
5046
5503
|
img = (0, import_sharp4.default)(kept.data, {
|
|
5047
5504
|
raw: { width: keptW, height: keptH, channels: 4 }
|
|
5048
5505
|
});
|
|
5049
|
-
const
|
|
5050
|
-
if (
|
|
5506
|
+
const box2 = boxWithoutStraySpecks(kept.data, keptW, keptH);
|
|
5507
|
+
if (box2 !== null) img = img.extract(box2);
|
|
5051
5508
|
}
|
|
5052
5509
|
if ((cfg.mirror ?? false) !== flipSource) img = img.flop();
|
|
5053
5510
|
const trimmed = await img.png().toBuffer({ resolveWithObject: true });
|
|
@@ -5094,18 +5551,18 @@ function placement2(role, cfg, w, h, canvas) {
|
|
|
5094
5551
|
assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top, canvas);
|
|
5095
5552
|
return { left, top };
|
|
5096
5553
|
}
|
|
5097
|
-
function nosePlacement(layout, mouthKey,
|
|
5554
|
+
function nosePlacement(layout, mouthKey, box2, w, h, canvas) {
|
|
5098
5555
|
const { cx, cy } = layout.nose;
|
|
5099
|
-
const left = Math.round(cx - (
|
|
5556
|
+
const left = Math.round(cx - (box2.x + box2.w / 2));
|
|
5100
5557
|
let top;
|
|
5101
5558
|
if (cy !== void 0) {
|
|
5102
|
-
top = Math.round(cy - (
|
|
5559
|
+
top = Math.round(cy - (box2.y + box2.h / 2));
|
|
5103
5560
|
} else {
|
|
5104
5561
|
const eyeRow = (layout.eye_L.cy + layout.eye_R.cy) / 2;
|
|
5105
5562
|
const tipRow = Math.round(
|
|
5106
5563
|
eyeRow + NOSE_TIP_AT * (layout[mouthKey].cy - eyeRow)
|
|
5107
5564
|
);
|
|
5108
|
-
top = tipRow - (
|
|
5565
|
+
top = tipRow - (box2.y + box2.h - 1);
|
|
5109
5566
|
}
|
|
5110
5567
|
assertOnCanvas(
|
|
5111
5568
|
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)`,
|
|
@@ -5213,8 +5670,8 @@ function detachedAboveWhite(rgba, W, H) {
|
|
|
5213
5670
|
return detached;
|
|
5214
5671
|
}
|
|
5215
5672
|
async function prepEyeSplit(partsDir) {
|
|
5216
|
-
const srcPath =
|
|
5217
|
-
if (!
|
|
5673
|
+
const srcPath = import_node_path10.default.join(partsDir, EYEWHITE_SRC);
|
|
5674
|
+
if (!import_node_fs7.default.existsSync(srcPath)) {
|
|
5218
5675
|
throw new AutoRigInputError(`missing eyewhite source: ${srcPath}`);
|
|
5219
5676
|
}
|
|
5220
5677
|
const { width: W, height: H, rgba: data } = await decodePng(srcPath);
|
|
@@ -5301,7 +5758,7 @@ function hasTransparency(rgba) {
|
|
|
5301
5758
|
return false;
|
|
5302
5759
|
}
|
|
5303
5760
|
async function prepLipSources(partsDir, mirrored) {
|
|
5304
|
-
const has = (name) =>
|
|
5761
|
+
const has = (name) => import_node_fs7.default.existsSync(import_node_path10.default.join(partsDir, name));
|
|
5305
5762
|
const keyed = has(KEYED_SRC);
|
|
5306
5763
|
const interior = has(INTERIOR_SRC);
|
|
5307
5764
|
if (keyed && !interior) {
|
|
@@ -5321,13 +5778,13 @@ async function prepLipSources(partsDir, mirrored) {
|
|
|
5321
5778
|
`${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 ")}`
|
|
5322
5779
|
);
|
|
5323
5780
|
}
|
|
5324
|
-
const k = await decodePng(
|
|
5781
|
+
const k = await decodePng(import_node_path10.default.join(partsDir, KEYED_SRC));
|
|
5325
5782
|
const keyedRgba = keyGreen(
|
|
5326
5783
|
hasTransparency(k.rgba) ? k.rgba : keyWhiteToAlpha(k.rgba),
|
|
5327
5784
|
k.width,
|
|
5328
5785
|
k.height
|
|
5329
5786
|
);
|
|
5330
|
-
const i = await decodePng(
|
|
5787
|
+
const i = await decodePng(import_node_path10.default.join(partsDir, INTERIOR_SRC));
|
|
5331
5788
|
const prepared = await prepInterior(
|
|
5332
5789
|
hasTransparency(i.rgba) ? i.rgba : keyBorderWhite(i.rgba, i.width, i.height),
|
|
5333
5790
|
i.width,
|
|
@@ -5344,7 +5801,7 @@ async function composeLayersFromParts(input) {
|
|
|
5344
5801
|
try {
|
|
5345
5802
|
const outDir = resolveOutputDir(input.outDir);
|
|
5346
5803
|
const partsDir = resolveInputDir(input.partsDir);
|
|
5347
|
-
if (
|
|
5804
|
+
if (import_node_fs7.default.realpathSync(partsDir) === outDir) {
|
|
5348
5805
|
throw new AutoRigInputError(
|
|
5349
5806
|
`partsDir and outDir resolve to the same directory (${outDir}): composing would overwrite the source parts`
|
|
5350
5807
|
);
|
|
@@ -5423,7 +5880,7 @@ async function composeLayersFromParts(input) {
|
|
|
5423
5880
|
}
|
|
5424
5881
|
if (key === "arm_L" || key === "arm_R") {
|
|
5425
5882
|
const arm = layout[key];
|
|
5426
|
-
if (!
|
|
5883
|
+
if (!import_node_fs7.default.existsSync(import_node_path10.default.join(partsDir, arm.src))) continue;
|
|
5427
5884
|
const body = placed.find((p) => p.role === "body");
|
|
5428
5885
|
if (body === void 0) {
|
|
5429
5886
|
throw new AutoRigInputError(
|
|
@@ -5466,7 +5923,7 @@ async function composeLayersFromParts(input) {
|
|
|
5466
5923
|
}
|
|
5467
5924
|
if (key === "forearm_pose_L" || key === "forearm_pose_R") {
|
|
5468
5925
|
const pose = layout[key];
|
|
5469
|
-
if (!
|
|
5926
|
+
if (!import_node_fs7.default.existsSync(import_node_path10.default.join(partsDir, pose.src))) continue;
|
|
5470
5927
|
const armRole = key === "forearm_pose_L" ? "arm_L" : "arm_R";
|
|
5471
5928
|
const arm = placed.find((p) => p.role === armRole);
|
|
5472
5929
|
if (arm?.elbow === void 0 || arm.elbowRun === void 0) {
|
|
@@ -5536,11 +5993,11 @@ async function composeLayersFromParts(input) {
|
|
|
5536
5993
|
if (key === "nose") {
|
|
5537
5994
|
noseSpeck = part.nose?.speck;
|
|
5538
5995
|
const { core, bounds } = await coreAndBoundsOf(part.buf);
|
|
5539
|
-
const
|
|
5996
|
+
const box2 = part.nose?.whole ? bounds : core ?? bounds;
|
|
5540
5997
|
({ left, top } = nosePlacement(
|
|
5541
5998
|
layout,
|
|
5542
5999
|
lips === void 0 ? "mouth" : "mouth_inner",
|
|
5543
|
-
|
|
6000
|
+
box2,
|
|
5544
6001
|
part.w,
|
|
5545
6002
|
part.h,
|
|
5546
6003
|
canvas
|
|
@@ -5583,15 +6040,15 @@ async function composeLayersFromParts(input) {
|
|
|
5583
6040
|
);
|
|
5584
6041
|
for (const role of ORDER) {
|
|
5585
6042
|
if (placed.some((p) => p.role === role)) continue;
|
|
5586
|
-
|
|
6043
|
+
import_node_fs7.default.rmSync(import_node_path10.default.join(outDir, `${role}.png`), { force: true });
|
|
5587
6044
|
}
|
|
5588
6045
|
const posed = (role) => role === "forearm_pose_L" || role === "forearm_pose_R";
|
|
5589
6046
|
if (!placed.some((p) => posed(p.role))) {
|
|
5590
|
-
|
|
6047
|
+
import_node_fs7.default.rmSync(import_node_path10.default.join(outDir, "preview-pose.png"), { force: true });
|
|
5591
6048
|
}
|
|
5592
6049
|
const layers = [];
|
|
5593
6050
|
for (const { role, part, left, top } of placed) {
|
|
5594
|
-
const outPath =
|
|
6051
|
+
const outPath = import_node_path10.default.join(outDir, `${role}.png`);
|
|
5595
6052
|
writeFileAtomic(outPath, built.get(role));
|
|
5596
6053
|
layers.push({
|
|
5597
6054
|
role,
|
|
@@ -5622,7 +6079,7 @@ async function composeLayersFromParts(input) {
|
|
|
5622
6079
|
background: { r: 245, g: 245, b: 248, alpha: 1 }
|
|
5623
6080
|
}
|
|
5624
6081
|
}).composite(preview).png().toBuffer();
|
|
5625
|
-
const previewPath =
|
|
6082
|
+
const previewPath = import_node_path10.default.join(outDir, "preview.png");
|
|
5626
6083
|
writeFileAtomic(previewPath, previewPng);
|
|
5627
6084
|
let previewPosePath;
|
|
5628
6085
|
if (placed.some((p) => posed(p.role))) {
|
|
@@ -5651,7 +6108,7 @@ async function composeLayersFromParts(input) {
|
|
|
5651
6108
|
background: { r: 245, g: 245, b: 248, alpha: 1 }
|
|
5652
6109
|
}
|
|
5653
6110
|
}).composite(pose).png().toBuffer();
|
|
5654
|
-
previewPosePath =
|
|
6111
|
+
previewPosePath = import_node_path10.default.join(outDir, "preview-pose.png");
|
|
5655
6112
|
writeFileAtomic(previewPosePath, posePng);
|
|
5656
6113
|
}
|
|
5657
6114
|
return {
|
|
@@ -5695,7 +6152,7 @@ function formatPatchReports(reports) {
|
|
|
5695
6152
|
});
|
|
5696
6153
|
}
|
|
5697
6154
|
function createIkiMcpServer() {
|
|
5698
|
-
const server = new import_mcp.McpServer({ name: "iki", version: "0.
|
|
6155
|
+
const server = new import_mcp.McpServer({ name: "iki", version: "0.31.0" });
|
|
5699
6156
|
server.registerTool(
|
|
5700
6157
|
"validate_iki",
|
|
5701
6158
|
{
|
|
@@ -5993,7 +6450,7 @@ function createIkiMcpServer() {
|
|
|
5993
6450
|
server.registerTool(
|
|
5994
6451
|
"render_poses",
|
|
5995
6452
|
{
|
|
5996
|
-
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.",
|
|
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.",
|
|
5997
6454
|
inputSchema: {
|
|
5998
6455
|
modelPath: import_zod.z.string().describe(
|
|
5999
6456
|
"Rigged .iki file path (resolved against cwd; must sit under the working directory)."
|
|
@@ -6014,6 +6471,18 @@ function createIkiMcpServer() {
|
|
|
6014
6471
|
})
|
|
6015
6472
|
).optional().describe(
|
|
6016
6473
|
"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."
|
|
6474
|
+
),
|
|
6475
|
+
sweep: import_zod.z.object({
|
|
6476
|
+
name: import_zod.z.string(),
|
|
6477
|
+
preset: import_zod.z.literal("turn"),
|
|
6478
|
+
crop: import_zod.z.object({
|
|
6479
|
+
x: import_zod.z.number(),
|
|
6480
|
+
y: import_zod.z.number(),
|
|
6481
|
+
w: import_zod.z.number(),
|
|
6482
|
+
h: import_zod.z.number()
|
|
6483
|
+
}).optional()
|
|
6484
|
+
}).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`."
|
|
6017
6486
|
)
|
|
6018
6487
|
}
|
|
6019
6488
|
},
|
|
@@ -6022,8 +6491,16 @@ function createIkiMcpServer() {
|
|
|
6022
6491
|
const r = await renderPoses(args);
|
|
6023
6492
|
const text = r.ok ? [
|
|
6024
6493
|
...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
|
+
] : [],
|
|
6025
6501
|
...formatFoldReport(r.folds, r.modelCanvas),
|
|
6026
|
-
...formatPhysicsReport(r.physics)
|
|
6502
|
+
...formatPhysicsReport(r.physics),
|
|
6503
|
+
...r.sweep ? formatSweepReport(r.sweep.report) : []
|
|
6027
6504
|
].join("\n") : `INVALID: ${r.error}`;
|
|
6028
6505
|
return { content: [{ type: "text", text }], structuredContent: r };
|
|
6029
6506
|
} catch (err) {
|