@ikijs/mcp 0.39.0 → 0.39.1
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/{chunk-KLZ6EOMG.mjs → chunk-3XQLLYUF.mjs} +92 -12
- package/dist/chunk-3XQLLYUF.mjs.map +1 -0
- package/dist/cli.js +91 -11
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.js +91 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/render-page.global.js +132 -17
- package/package.json +2 -2
- package/dist/chunk-KLZ6EOMG.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -520,7 +520,10 @@
|
|
|
520
520
|
rafId;
|
|
521
521
|
/** Uploaded textures, index-aligned with `model.textures`; `null` = unusable. */
|
|
522
522
|
textures = [];
|
|
523
|
-
/**
|
|
523
|
+
/**
|
|
524
|
+
* Bumped by every `load`, `cancelLoad` and `destroy`; lets a stale async
|
|
525
|
+
* load bail.
|
|
526
|
+
*/
|
|
524
527
|
loadGeneration = 0;
|
|
525
528
|
/** True from the moment `load()` is entered until it resolves or throws. */
|
|
526
529
|
loadPending = false;
|
|
@@ -573,6 +576,16 @@
|
|
|
573
576
|
this.loadPending = false;
|
|
574
577
|
}
|
|
575
578
|
}
|
|
579
|
+
/**
|
|
580
|
+
* Supersede any in-flight {@link load} as a newer one would: it resolves
|
|
581
|
+
* `{ superseded: true, failedTextures: [] }` and adopts nothing. The
|
|
582
|
+
* installed model stays and keeps rendering. For a host whose next request
|
|
583
|
+
* failed before it reached `load()` (its fetch errored), which would
|
|
584
|
+
* otherwise let the older load land after it. A no-op with no load pending.
|
|
585
|
+
*/
|
|
586
|
+
cancelLoad() {
|
|
587
|
+
++this.loadGeneration;
|
|
588
|
+
}
|
|
576
589
|
async adoptModel(model) {
|
|
577
590
|
const { gl } = this;
|
|
578
591
|
const generation = ++this.loadGeneration;
|
|
@@ -1420,6 +1433,9 @@ void main() {
|
|
|
1420
1433
|
}
|
|
1421
1434
|
}
|
|
1422
1435
|
};
|
|
1436
|
+
function eyeSpring() {
|
|
1437
|
+
return new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
|
|
1438
|
+
}
|
|
1423
1439
|
var IdleMotion = class {
|
|
1424
1440
|
/**
|
|
1425
1441
|
* Every parameter id {@link update} and `emitRestingPose` write, in write
|
|
@@ -1445,8 +1461,8 @@ void main() {
|
|
|
1445
1461
|
// Gaze state: the scheduled pick starts at eye contact, (0, 0), until the
|
|
1446
1462
|
// first retarget. A host target, while set, replaces the pick as what the
|
|
1447
1463
|
// eyes and head chase; the schedule keeps picking underneath it.
|
|
1448
|
-
eyeX =
|
|
1449
|
-
eyeY =
|
|
1464
|
+
eyeX = eyeSpring();
|
|
1465
|
+
eyeY = eyeSpring();
|
|
1450
1466
|
gazeTargetX = 0;
|
|
1451
1467
|
gazeTargetY = 0;
|
|
1452
1468
|
nextGazeRetargetMs;
|
|
@@ -2018,9 +2034,18 @@ void main() {
|
|
|
2018
2034
|
return false;
|
|
2019
2035
|
}
|
|
2020
2036
|
const from = this.slot?.last ?? /* @__PURE__ */ new Map();
|
|
2021
|
-
this.slot = { clip: clips[index], t: 0, from, last: from };
|
|
2037
|
+
this.slot = { group, index, clip: clips[index], t: 0, from, last: from };
|
|
2022
2038
|
return true;
|
|
2023
2039
|
}
|
|
2040
|
+
/**
|
|
2041
|
+
* The one-shot in the slot, or null once it has ended. It ends in the
|
|
2042
|
+
* {@link applyOneShot} that carries it past its duration, so it is still
|
|
2043
|
+
* reported after a frame gap longer than the clip: the clip advances by the
|
|
2044
|
+
* dt it is given, which the caller clamps.
|
|
2045
|
+
*/
|
|
2046
|
+
active() {
|
|
2047
|
+
return this.slot ? { group: this.slot.group, index: this.slot.index } : null;
|
|
2048
|
+
}
|
|
2024
2049
|
/**
|
|
2025
2050
|
* Advance `dtS` seconds and write into `frame`: the Idle loop layer, then
|
|
2026
2051
|
* the one-shot slot over it.
|
|
@@ -2031,7 +2056,18 @@ void main() {
|
|
|
2031
2056
|
* so a clip cannot accumulate across frames.
|
|
2032
2057
|
*/
|
|
2033
2058
|
apply(dtS, frame, rest) {
|
|
2059
|
+
this.applyLoop(dtS, frame);
|
|
2060
|
+
this.applyOneShot(dtS, frame, rest);
|
|
2061
|
+
}
|
|
2062
|
+
/**
|
|
2063
|
+
* {@link apply}'s first layer alone, for a caller that writes a stage of
|
|
2064
|
+
* its own between the Idle loop and the one-shot.
|
|
2065
|
+
*/
|
|
2066
|
+
applyLoop(dtS, frame) {
|
|
2034
2067
|
if (this.hasIdleLoop) this.applyIdle(dtS, frame);
|
|
2068
|
+
}
|
|
2069
|
+
/** {@link apply}'s second layer alone; see {@link applyLoop}. */
|
|
2070
|
+
applyOneShot(dtS, frame, rest) {
|
|
2035
2071
|
if (this.slot) this.applySlot(this.slot, dtS, frame, rest);
|
|
2036
2072
|
}
|
|
2037
2073
|
/**
|
|
@@ -2277,10 +2313,57 @@ void main() {
|
|
|
2277
2313
|
StandardParameter.EyeballX,
|
|
2278
2314
|
StandardParameter.EyeballY
|
|
2279
2315
|
]);
|
|
2316
|
+
var GAZE_SETTLED = 1e-3;
|
|
2317
|
+
var HostGaze = class {
|
|
2318
|
+
target = void 0;
|
|
2319
|
+
/** From the first update with a target until the eyes are back on base. */
|
|
2320
|
+
active = false;
|
|
2321
|
+
/** The springs carry the value (target held), else the offset from base. */
|
|
2322
|
+
absolute = false;
|
|
2323
|
+
x = eyeSpring();
|
|
2324
|
+
y = eyeSpring();
|
|
2325
|
+
apply(dtMs, frame, rest) {
|
|
2326
|
+
if (!this.target && !this.active) return;
|
|
2327
|
+
const baseX = frame.get(StandardParameter.EyeballX) ?? rest(StandardParameter.EyeballX);
|
|
2328
|
+
const baseY = frame.get(StandardParameter.EyeballY) ?? rest(StandardParameter.EyeballY);
|
|
2329
|
+
if (!this.active) {
|
|
2330
|
+
this.active = true;
|
|
2331
|
+
this.absolute = true;
|
|
2332
|
+
this.x.value = baseX;
|
|
2333
|
+
this.y.value = baseY;
|
|
2334
|
+
} else if (this.absolute !== (this.target !== void 0)) {
|
|
2335
|
+
const sign = this.absolute ? -1 : 1;
|
|
2336
|
+
this.x.value += sign * baseX;
|
|
2337
|
+
this.y.value += sign * baseY;
|
|
2338
|
+
this.absolute = !this.absolute;
|
|
2339
|
+
}
|
|
2340
|
+
if (this.target) {
|
|
2341
|
+
this.x.step(this.target.x, dtMs);
|
|
2342
|
+
this.y.step(this.target.y, dtMs);
|
|
2343
|
+
frame.set(StandardParameter.EyeballX, this.x.value);
|
|
2344
|
+
frame.set(StandardParameter.EyeballY, this.y.value);
|
|
2345
|
+
return;
|
|
2346
|
+
}
|
|
2347
|
+
this.x.step(0, dtMs);
|
|
2348
|
+
this.y.step(0, dtMs);
|
|
2349
|
+
const settled = (s) => Math.abs(s.value) < GAZE_SETTLED && Math.abs(s.velocity) < GAZE_SETTLED;
|
|
2350
|
+
if (settled(this.x) && settled(this.y)) {
|
|
2351
|
+
this.active = false;
|
|
2352
|
+
this.x.value = this.x.velocity = 0;
|
|
2353
|
+
this.y.value = this.y.velocity = 0;
|
|
2354
|
+
frame.set(StandardParameter.EyeballX, baseX);
|
|
2355
|
+
frame.set(StandardParameter.EyeballY, baseY);
|
|
2356
|
+
return;
|
|
2357
|
+
}
|
|
2358
|
+
frame.set(StandardParameter.EyeballX, baseX + this.x.value);
|
|
2359
|
+
frame.set(StandardParameter.EyeballY, baseY + this.y.value);
|
|
2360
|
+
}
|
|
2361
|
+
};
|
|
2280
2362
|
var IkiMotion = class {
|
|
2281
2363
|
/**
|
|
2282
2364
|
* Everything {@link update} may write, deduplicated, in this order: idle ids
|
|
2283
|
-
* (without head and gaze when the model declares an `Idle` group
|
|
2365
|
+
* (without head and gaze when the model declares an `Idle` group, with
|
|
2366
|
+
* EyeballX/Y then listed after them for {@link setGazeTarget}), the curve
|
|
2284
2367
|
* parameters of every motion group, expression parameters, rig outputs,
|
|
2285
2368
|
* then chain-segment outputs. May name ids the model lacks (idle writes the
|
|
2286
2369
|
* standard ids regardless, and the player silently drops writes to unknown
|
|
@@ -2294,6 +2377,8 @@ void main() {
|
|
|
2294
2377
|
expressions;
|
|
2295
2378
|
physics;
|
|
2296
2379
|
chains;
|
|
2380
|
+
/** The host gaze's own eye stage; only under a declared Idle group. */
|
|
2381
|
+
hostGaze;
|
|
2297
2382
|
/** Resting value per id; 0 for an undeclared id. */
|
|
2298
2383
|
rest;
|
|
2299
2384
|
/** This update's idle, clip and expression writes, in first-write order. */
|
|
@@ -2319,6 +2404,7 @@ void main() {
|
|
|
2319
2404
|
},
|
|
2320
2405
|
{ parameters: model.parameters }
|
|
2321
2406
|
);
|
|
2407
|
+
this.hostGaze = this.clips.hasIdleLoop ? new HostGaze() : void 0;
|
|
2322
2408
|
this.physics = new PhysicsMotion(rigs, model.parameters, read, sink);
|
|
2323
2409
|
this.chains = new HairChainMotion(
|
|
2324
2410
|
chains,
|
|
@@ -2330,6 +2416,7 @@ void main() {
|
|
|
2330
2416
|
this.drivenParameterIds = [
|
|
2331
2417
|
.../* @__PURE__ */ new Set([
|
|
2332
2418
|
...this.idle.drivenParameterIds.filter(idleKeeps),
|
|
2419
|
+
...this.hostGaze ? [StandardParameter.EyeballX, StandardParameter.EyeballY] : [],
|
|
2333
2420
|
...this.clips.parameterIds,
|
|
2334
2421
|
...this.expressions.parameterIds,
|
|
2335
2422
|
...this.physics.drivenParameterIds,
|
|
@@ -2363,21 +2450,46 @@ void main() {
|
|
|
2363
2450
|
return this.clips.play(group, index);
|
|
2364
2451
|
}
|
|
2365
2452
|
/**
|
|
2366
|
-
*
|
|
2367
|
-
*
|
|
2368
|
-
*
|
|
2369
|
-
*
|
|
2453
|
+
* The one-shot {@link playMotion} started, while it runs: null before any
|
|
2454
|
+
* and from the {@link update} that carries it past its duration on. It runs
|
|
2455
|
+
* on the clips' clock, which advances at most `MAX_DT_MS` per update, so
|
|
2456
|
+
* after a long frame gap it is still reported until it has really played
|
|
2457
|
+
* out. A rejected playMotion leaves it as it was. The engine only reports;
|
|
2458
|
+
* which clip may interrupt which is the host's call.
|
|
2459
|
+
*/
|
|
2460
|
+
activeMotion() {
|
|
2461
|
+
return this.clips.active();
|
|
2462
|
+
}
|
|
2463
|
+
/**
|
|
2464
|
+
* Hold the gaze on (`x`, `y`), in EyeballX/Y units, until
|
|
2465
|
+
* {@link clearGazeTarget}. Each value is clamped to [-1, 1]; a pair with a
|
|
2466
|
+
* non-finite value is ignored and changes nothing.
|
|
2467
|
+
*
|
|
2468
|
+
* Without an `Idle` motion group the idle gaze holds it: the eyes go there
|
|
2469
|
+
* and the head follows on the turn and nod, as
|
|
2470
|
+
* {@link IdleMotion.setGazeTarget} describes.
|
|
2370
2471
|
*
|
|
2371
|
-
* Under a declared `Idle`
|
|
2372
|
-
*
|
|
2373
|
-
* EyeballX/Y
|
|
2472
|
+
* Under a declared `Idle` group the eyes go there on springs as stiff as
|
|
2473
|
+
* the idle eyes', and the head stays the Idle clips'. While a target is
|
|
2474
|
+
* set it wins over any EyeballX/Y the Idle clips animate; a one-shot or an
|
|
2475
|
+
* expression still composes over it, as over any base. With no target the
|
|
2476
|
+
* Idle clips' eyes play untouched.
|
|
2374
2477
|
*/
|
|
2375
2478
|
setGazeTarget(x, y) {
|
|
2376
2479
|
this.idle.setGazeTarget(x, y);
|
|
2480
|
+
if (this.hostGaze && Number.isFinite(x) && Number.isFinite(y)) {
|
|
2481
|
+
this.hostGaze.target = { x: clamp(x, -1, 1), y: clamp(y, -1, 1) };
|
|
2482
|
+
}
|
|
2377
2483
|
}
|
|
2378
|
-
/**
|
|
2484
|
+
/**
|
|
2485
|
+
* Drop the host gaze target; the idle's own gaze resumes. Under a declared
|
|
2486
|
+
* `Idle` group the eyes spring back to what the Idle clips write, else to
|
|
2487
|
+
* their resting values, and are left there: nothing of the target stays in
|
|
2488
|
+
* the store.
|
|
2489
|
+
*/
|
|
2379
2490
|
clearGazeTarget() {
|
|
2380
2491
|
this.idle.clearGazeTarget();
|
|
2492
|
+
if (this.hostGaze) this.hostGaze.target = void 0;
|
|
2381
2493
|
}
|
|
2382
2494
|
/**
|
|
2383
2495
|
* Advance everything to the same wall-clock timestamp (milliseconds), in
|
|
@@ -2385,7 +2497,9 @@ void main() {
|
|
|
2385
2497
|
*
|
|
2386
2498
|
* 1. Idle writes blink, the declared brows' blink dip, breath, the ambient
|
|
2387
2499
|
* sway (and head and gaze, unless replaced) into this update's frame.
|
|
2388
|
-
* 2. The clip stage writes the `Idle` loop, then
|
|
2500
|
+
* 2. The clip stage writes the `Idle` loop, then, under a declared `Idle`
|
|
2501
|
+
* group, the host gaze's eyes ({@link setGazeTarget}), then the one-shot
|
|
2502
|
+
* over both.
|
|
2389
2503
|
* 3. The expression stage writes the active expression, fading in from the
|
|
2390
2504
|
* pose it replaced, or a stop fading back to base.
|
|
2391
2505
|
* 4. The frame goes to `sink`, each id exactly once, in the order its first
|
|
@@ -2400,8 +2514,7 @@ void main() {
|
|
|
2400
2514
|
* itself) AFTER update(); the last write wins. That is how lip-sync beats
|
|
2401
2515
|
* an expression that opens the mouth, and how a host's brow beats idle's
|
|
2402
2516
|
* blink dip. A host pointer goes through {@link setGazeTarget} instead, so
|
|
2403
|
-
* the head follows it
|
|
2404
|
-
* moves nothing, does the host write EyeballX/Y itself after update().
|
|
2517
|
+
* the head follows it (the eyes alone under an `Idle` group).
|
|
2405
2518
|
*
|
|
2406
2519
|
* The clips and expressions advance by `clamp(now − prev, 0, MAX_DT_MS)`,
|
|
2407
2520
|
* 0 on the first update. A non-finite `nowMs` is a dropped frame: idle and
|
|
@@ -2415,7 +2528,9 @@ void main() {
|
|
|
2415
2528
|
if (Number.isFinite(nowMs)) {
|
|
2416
2529
|
const dtS = this.prevNowMs === void 0 ? 0 : clamp(nowMs - this.prevNowMs, 0, MAX_DT_MS) / 1e3;
|
|
2417
2530
|
this.prevNowMs = nowMs;
|
|
2418
|
-
this.clips.
|
|
2531
|
+
this.clips.applyLoop(dtS, this.frame);
|
|
2532
|
+
this.hostGaze?.apply(dtS * 1e3, this.frame, this.rest);
|
|
2533
|
+
this.clips.applyOneShot(dtS, this.frame, this.rest);
|
|
2419
2534
|
this.expressions.apply(dtS, this.frame, this.rest);
|
|
2420
2535
|
}
|
|
2421
2536
|
this.frame.forEach(this.flush);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikijs/mcp",
|
|
3
|
-
"version": "0.39.
|
|
3
|
+
"version": "0.39.1",
|
|
4
4
|
"description": "MCP server that lets AI agents build 2D puppet characters: compose AI-drawn part images, or cut one finished illustration into layers, check their geometry and auto-rig them into an open .iki model — Iki, the free Live2D alternative.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-rigging",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"zod": "^3.25"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@ikijs/engine": "^0.
|
|
54
|
+
"@ikijs/engine": "^0.13.0",
|
|
55
55
|
"tsup": "^8.5.0",
|
|
56
56
|
"typescript": "^5.9.2"
|
|
57
57
|
},
|