@ikijs/mcp 0.36.1 → 0.37.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/README.md CHANGED
@@ -30,7 +30,7 @@ Turns a set of role-named, full-canvas transparent PNG layers into a renderable,
30
30
  - **`turnTargets`** — optional head-turn cues to fit the rig to, in the units `measure_turn_reference` reports off a front/turned reference pair: `eyeShift` (plus `noseShift` and `mouthShift`) is how far that feature slides across the head at full turn, as a fraction of the head's half-width — a **magnitude**, since the rig turns both ways and the sign is the turn's own business; `farEyeRatio` is the far/near eye width at full turn over that same ratio at rest; `silhouetteRatio` the head's half-width turned over at rest. An omitted field leaves that part of the turn at the profile the rig defaults to. An `eyeShift` you pass is fitted by the turn's amount and _clamped_ when it runs past the room the art leaves the far eye — the face plate's edge, or the bangs' side strand over the far iris — since that room is a fact about these layers, not about the reference. Any other target you **do** pass that it cannot reach is refused, because that number is a measurement rather than a preference. A layer set without a `nose` still turns its head, on the profile, but fits no target: `turnTargets` is then inert and the result carries no `turn`. A pair with a custom part crossing the eye row reads a wider head than the rig fits to: measure a pair drawn without them.
31
31
  - **`rigPlan`** — optional per-character tuning from the profile the rig defaults to, in three groups: `turn` (`amount`: the whole head turn, ignored when `turnTargets.eyeShift` is given; `featureLead`: how far the features lead the face plate; `eyeForeshorten`: how much the far eye narrows on the turn, ignored when `turnTargets.farEyeRatio` is given; `noseLead`: how far the nose leads the plate on the turn, never the nod, ignored when `turnTargets.noseShift` is given — the last two have provisional recommended spans; `farEar`: how far the far ear's outer edge follows the face on the turn, 0 holding it under the face), `hair` (`follow`: the front hair's share of the face's turn; `outlineFollow`: its outer edge's share where it draws the head's outline; `sway`: the hair sway amplitude) and `eyes` (`blink`: how far the upper lid comes down over the eye's height). Call `describe_rig_plan` for each field's default, range, recommended span, step and poses. A value out of range, or a group or key not in the catalog, is refused as `INVALID: rigPlan.<path> …`. The old `style` input was removed in 0.30.0 and is refused with the map from each old knob to its `rigPlan` path.
32
32
  - **`patches`** — optional displacements added to existing keyform stops of the freshly generated rig, each `{ target, at, region, by, falloff?, why? }` (`RigPatch` in `@ikijs/editor`). `target` is a feature grid (`eyeWarp_L`/`_R`, `browWarp_L`/`_R`, `noseWarp`, `mouthWarp`; `at` names `ParamAngleX` and `ParamAngleY`, each −30, 0 or 30, never both 0) or a mesh part with warps (`face`, `hair_front`, …; `at` names one parameter at one of its warp stops). `region` is a rectangle in fractions of a role's rest layer box (top-left origin, y down); `by` and `falloff` are in face widths on screen axes (+dx right, +dy down). They are replayed on every rig of these inputs, so they hold through a layout or `rigPlan` retune, and they never touch the rest stop or a stop where the rig shuts a part on purpose; `bodyWarp` and the matrix deformers are not targets. Aim them with `describe_iki`.
33
- - **`customParts`** — optional parts the auto-rigger has no role for (a twin tail, a hairpin), each `{ id, path, anchor, tie, after, deformer?, rigid?, occlusion? }` (`CustomPart` in `@ikijs/editor`, with `path` in place of `layer`). `rigid: true` marks art that does not bend (a hairpin, a ribbon): a bake that bends it by more than 0.0025 face widths at a stop is refused. `occlusion: { by, parameter, stops: [{ value, amount }] }` hides the part where the roles in `by` (a non-empty list, no role repeated, each a role of the set; one with a clipped or meshless part, `iris_L` or `forearm_pose_L`, is refused) cover it, by an amount linear between the stops (ascending `value`, inside the parameter's range; `amount` 0 to 1) on a declared `parameter` that is not a physics output; the cover is where a role's drawn alpha is at least 0.5, a hard edge. Use the stops as a short switch starting a degree or more past the idle sway (amount 1 about one degree after 0), the hiding's progress coming from the part's baked motion; a long band turns the covered art translucent. The result's part then carries `occlusion` (`by` as the part ids written) and its `CUSTOM <id>:` line ends `, hidden by <id>,<id>… on <parameter> at <value>:<amount> <value>:<amount>…`; other parts' lines are unchanged. `occlusion` needs 0.35.0: an older server refuses the key as `INVALID: customParts[i]…`. `path` is a PNG the size of the role layers, drawn alone and whole on a transparent ground; the tool takes its box from the layer's alpha. `anchor` is the role the part is fixed against, `tie` is `[x, y]` canvas px where it meets the anchor (inside both layers' boxes), `after` is a role of the set: the part is drawn right after that role's last part. `deformer` accepts only `headDeformer`, the default. The part goes into the model as an unrigged mesh on `headDeformer`. A custom layer is never role-parsed or measured, so its name is free and it does not widen the head the turn is fitted to (`headHalfWidth`, `headEdges` and `turn` are those of the role layers alone), but it counts toward the layer and pixel limits. All custom parts share one extra atlas page, the last, rendered with the call's `quantizeColors` on a palette of its own, so the role pages keep their bytes; `atlasBytes` includes it. A rig with `customParts: []` is the rig without the field. An empty or wrong-size layer, or an entry the rig refuses, comes back as `INVALID: customParts[i]…` and nothing is written. Needs 0.34.0: an older server drops the field and returns no `customParts`.
33
+ - **`customParts`** — optional parts the auto-rigger has no role for (a twin tail, a hairpin), each `{ id, path, anchor, tie, after, deformer?, rigid?, occlusion? }` (`CustomPart` in `@ikijs/editor`, with `path` in place of `layer`). `rigid: true` marks art that does not bend (a hairpin, a ribbon): a bake that bends it by more than 0.0025 face widths at a stop is refused. `occlusion: { by, parameter, stops: [{ value, amount }] }` hides the part where the roles in `by` (a non-empty list, no role repeated, each a role of the set; one with a clipped or meshless part, `iris_L` or `forearm_pose_L`, is refused) cover it, by an amount linear between the stops (ascending `value`, inside the parameter's range; `amount` 0 to 1) on a declared `parameter` that is not a physics output; the cover is where a role's drawn alpha is at least 0.5, a hard edge. Use the stops as a short switch starting a degree or more off rest, so the rest pose never sits on it and the idle turns the head through it (amount 1 about one degree after 0), the hiding's progress coming from the part's baked motion; a long band turns the covered art translucent. The result's part then carries `occlusion` (`by` as the part ids written) and its `CUSTOM <id>:` line ends `, hidden by <id>,<id>… on <parameter> at <value>:<amount> <value>:<amount>…`; other parts' lines are unchanged. `occlusion` needs 0.35.0: an older server refuses the key as `INVALID: customParts[i]…`. `path` is a PNG the size of the role layers, drawn alone and whole on a transparent ground; the tool takes its box from the layer's alpha. `anchor` is the role the part is fixed against, `tie` is `[x, y]` canvas px where it meets the anchor (inside both layers' boxes), `after` is a role of the set: the part is drawn right after that role's last part. `deformer` accepts only `headDeformer`, the default. The part goes into the model as an unrigged mesh on `headDeformer`. A custom layer is never role-parsed or measured, so its name is free and it does not widen the head the turn is fitted to (`headHalfWidth`, `headEdges` and `turn` are those of the role layers alone), but it counts toward the layer and pixel limits. All custom parts share one extra atlas page, the last, rendered with the call's `quantizeColors` on a palette of its own, so the role pages keep their bytes; `atlasBytes` includes it. A rig with `customParts: []` is the rig without the field. An empty or wrong-size layer, or an entry the rig refuses, comes back as `INVALID: customParts[i]…` and nothing is written. Needs 0.34.0: an older server drops the field and returns no `customParts`.
34
34
  - **`bakes`** — optional lattices that move the custom parts when a parameter does, which an unrigged custom part otherwise does not: `{ targets, meshes? }` (`RigBakes` in `@ikijs/editor`; it needs `customParts` and names no other part). A target `{ id?, param, parts, box?, grid: { cols, rows }, stops, mirror?, why? }` is `(cols + 1) x (rows + 1)` control points laid evenly over `box` (canvas px; absent, the union of the parts' rest boxes grown by 2 px), listed row-major from the top-left, with a `[dx, dy]` per point at each stop. Every position and displacement is in canvas px, origin top-left, y down. A stop is the part's TOTAL landed displacement from rest when `param` alone is at that value and every other parameter is at its default, so the head's own carry is inside it and a neighbour's displacement as `probe_rig` measures it is written as it is. Stop keys are values of `param` inside its range, never its default. The landing is exact at rest, at each stop and at one end key the rig writes at the range end on a side whose outermost stop is inside the range (it holds that stop's displacement); a side with no stop is not moved. Between two keys the part's offsets are blended linearly, so under the head's roll the path bows off the line (about 1 px midway over 15°): put a stop where the path matters. Each vertex takes the bilinear value of the lattice at its rest position, and a vertex outside `box` takes the nearest edge's value. `mirror: true` fills a missing stop from the one at the mirrored value, when that value is inside the parameter's range (the lattice reflected about the box's vertical centre line, `dx` negated). Targets that name the same part and parameter sum. `meshes` re-meshes a custom part first (`{ rows, cols }` or `{ cellPx }`). The written model is landed through the engine at every stop and at the range end each side holds its outermost stop to, and compared with the displacement the generator was asked for; a stop off by 0.1 px or more is `INVALID: BAKE ERROR <part> <param>=<value>: …`, and a part the bake moves at rest by as much is `INVALID: BAKE ERROR <part> at rest: …`; both mean the rig and the engine disagree (a bug in the packages, not in the input), and nothing is written, and an input the rig refuses is `INVALID: bakes…` with its path (`bakes.targets[2].stops["30"][7]`), nothing written either. Needs 0.34.0.
35
35
  - **The custom gate** — whenever `customParts` is passed the written model is also measured, per custom part, over a pose set: the engine's fold poses, each of the part's own stops alone, and for every pair of parameters it is baked on every combination of their stops (the stops of a part's `occlusion` on its key parameter count as its stops here). Lengths are in face widths (the `face` part's width), so no limit is tied to one canvas; the values are the experiment's over a 402 px face. Lines: `FOLDS` (the part's least triangle area ratio, ≥ 0.1, the engine's collapse); `TIE` (at the tie and a ring around it (5 px on a 402 px face, scaled with the face width), the part's displacement less the anchor's, the largest over the poses where `ParamAngleX` is at its default, ≤ 0.005); `SLIDE` (the same length over the poses that turn the head, ≤ 0.1; and the distance from where the part lands its tie to the nearest painted point of the anchor as the anchor lands it, ≤ 0.015); `EXPOSED` (the canvas pixels within 0.15 face widths of the tie that the part and its anchor both paint: of the two, the one drawn below has art the other hides at rest; at a pose each such pixel is landed through the lower part and counted as showing when no painted point of the upper one lands there; the largest count over the poses where the head does not turn, ≤ 0.0009 face widths², with the largest over the poses that turn it printed beside it, reported and not limited, since a tie allowed to slide uncovers what lies under it; draw order is the model's one `order` per part, so only the pair is read, and cover from any other part does not count unless the part declares an occlusion, below; rest counts 0); `RIGID` (rigid parts only: the least-squares rigid residual of the landed vertices against rest, over the pose set and the midpoint of each neighbouring pair of the part's stops, ≤ 0.0025); `HIDDEN` (only for a part that declares `occlusion`: the occluders, which of them give cover, the key parameter, the amount at rest, where the amount leaves its rest value and where it first reaches 1 on each side of the parameter's default, and how many of the part's poses `TIE` and `SLIDE` left out; reported, no limit, printed after `EXPOSED`); and `TIP` (per baked parameter, at the parameter's ends: where the part's free end lands, where it lands with the part's warps removed, the distance between and the travel end to end; reported, no limit). **What an occlusion excuses.** The gate excuses a reading only where it can establish that the player hides what the reading measures, and keeps the check everywhere else. Cover is an occluder's layer paint as that occluder lands at the pose, and only from an occluder the player draws at full alpha in every pose: colour alpha 1, no transform opacity under 1 and no `opacity` binding, so `mouth_open`, a blush and a pose forearm give none. A pose is left out only when the part is fully hidden across the stretches to the neighbouring sampled values of the key parameter on both sides (the amount is 1 at the pose, at both neighbours and at every occlusion stop between them; the sampled values are the ones the part's pose set takes, the default, its bake stops and its occlusion's stops included): a reading between two samples is bounded by the readings at its ends, so a stretch where the part is drawn keeps both poses it bounds in. For a left-out pose, `TIE` and `SLIDE` leave it out when every ring point lies on the part's mesh and under cover (it is then not counted among `SLIDE`'s turning poses; a line whose every pose is left out says so); `EXPOSED` does not count a hidden-art pixel whose landed spot is under cover, and counts every other pixel as before. An amount under 1 is judged in full, and so is a part whose tie is not under cover. `FOLDS`, `RIGID` and `TIP` read every pose, and the occlusion's stops are sampled like bake stops, so a bake key at one changes no verdict. Each line gives the worst value in px and face widths and its pose, then `pass` or `FAIL: <reason>`; the text ends with `CUSTOM GATE pass` or `CUSTOM GATE FAIL: <part LINE, …>`, always the text's last line. `FOLDS`, `TIE`, `SLIDE`, `EXPOSED` and `RIGID` each fail the gate, `TIP` never does; a tie no ring point of which lies on both the part and its anchor fails `TIE` with that reason. The model is written either way, and the folds and physics reports for the rest of the model stay report-only. `HIDDEN` needs 0.35.0. Needs 0.34.0: from then on `customParts` always carries `gate`, so a result without `customParts` is from an older server and was never gated. A gate that throws still writes the file and returns the path, with `gate.ok` false, `gate.failed` `["gate error: <message>"]` and the text ending `CUSTOM GATE FAIL: gate error: <message>`.
36
36
  - **Result** — on success the result text is the written file path, then one `RIGPLAN: turn.amount=1 …` line (every plan field's effective value, each annotated with `(requested …, clamped at …)` where the art's room cut it or `(fitted by turnTargets.…)` where a cue fitted it), then one `PATCH <i> <target> at <Param=v …>: <moved> of <of> points (cols a-b, rows c-d), largest move <maxPx> model px` line per patch op (`(vertices)` in place of the columns and rows for a mesh part), then the rig's fold report lines and its `PHYSICS` lines (as `render_poses` prints them), then, with side locks and a `nose` (which `turn` needs), the `HAIRSIDE` lines, then one `CUSTOM <id>: box x,y WxH px, mesh N vertices M triangles, order O, atlas page P` line per custom part, then, with `bakes`, one `BAKE <part> <param>: N vertices, stops …, error E px` line per part and parameter (E: the engine's landing against the asked displacement, under 0.1 px; carried as `customParts.bakes`), then, with `customParts`, the custom gate's `CUSTOM <id> <LINE>: …` lines and `CUSTOM GATE pass` or `CUSTOM GATE FAIL: …` last (carried as `customParts.gate`: `ok`, `limits`, `parts` with each measure, `failed`), and `structuredContent` carries `{ ok: true, path, canvas, partCount, atlasBytes, headHalfWidth?, headHalfWidthApplied, headEdges?, strandEdges?, noseCore?, turn?, patches?, folds, physics, rigPlan, customParts? }`. `rigPlan` is `{ requested, effective, clamped, overriddenBy }` — the plan as passed, every field's value the rig built with, the plan-owned fields the room cut (`{ field, bound }`) and the fields a `turnTargets` cue fitted instead (path to cue); it is always present on a rigged model, and a result without it comes from a server before 0.30.0. `patches` is what each op moved (`index`, `target`, `at`, `moved`, `of`, `cols`/`rows` for a grid, `maxPx`) and is present whenever `patches` was passed, `[]` included. `customParts` is `{ parts, bakes?, gate }`, each part `{ id, box, mesh: { vertices, triangles }, order, page }` (`box` the layer's alpha box in canvas px, `page` the last atlas page), present whenever `customParts` was passed, `[]` included; `bakes` (`{ part, param, vertices, stops, errorPx }` per baked part and parameter) is present only when `bakes` was passed. `atlasBytes` is the embedded atlas's data-URI length, summed over every page: the nose's own, when it has one, and the custom parts' page. `headHalfWidth` is the head measured here rather than asked for: the layers' own opaque union at the eye row, under the same `alpha >= 128` rule and ±10-row band `measure_turn_reference` spans a render with, so the rig's own rest render measures that span back; it is **absent** when that union has no span there at all (translucent art painted below alpha 128 — still a valid layer set, just with nothing to measure). `headHalfWidthApplied` is `false` when the measured value is absent, or no wider than the face plate (a hairless set, or one widest at the plate itself) — the generator will not take such a head, so the plate stands in for it and the rig is still produced either way. `headEdges` is a companion to a measured, applied `headHalfWidth` (absent otherwise): every role with an opaque pixel in that same eye-row band, per side, each with its own rest x there — passed straight to the generator's own `options.headEdges` so it can tell which part's own deformation actually carries the union's outermost pixel through the turn. `strandEdges` is each side's iris and the `hair_front` run it would slide under on the turn, measured whenever the layers include `hair_front`, `iris_L` and `iris_R`: the iris's opaque span and the run's outer and face-side ends as pixel edges on the row holding the iris's centre (a run that reaches the other iris's centre, a fringe spanning the face, has `runFace: null`; a run narrower than half the iris's painted width on that row is hair detail the iris may cross, and is skipped as if clear) — passed straight to the generator's own `options.strandEdges`, which keeps the far iris from sliding under the bangs any further than it is painted. `turn` is what the solve settled on — `{ radius, holdBase, depths, achieved: { eyeShift, farEyeRatio, silhouetteRatio }, clamped, strandOverlap? }`, where `achieved` is what the rig does reach and `clamped` names every target the rig cut down: the turn (`eyeShift`, passed or the profile's own) where the face plate's edge or the strand cut it short, and a profile `noseShift` / `mouthShift` past its room. `strandOverlap` gives, per side whose far iris the bangs still cover at some far stop, the covered width — how much of the iris's painted row the run covers where that is largest (`deg`, `px`, and `hh` in head half-widths), how much it covers at rest (`restPx`), and whether the bound held (`held`: `true` means the iris is kept no deeper under the run than it is painted; `false` means the art left no room to — always so for a fringe spanning the face — and `px` is what stays covered); it is absent when nothing is covered. `noseCore` is the nose's dense core in canvas px — its pixels at alpha >= 128, not grown, the box handed to the generator as the nose layer's `denseCore` and its turn landmark — absent without a `nose` layer, when it has no pixel at that threshold (painted wholly translucent), or when that core is a speck of the nose's crop (under a quarter of its width or height, such as a lone nostril mark), and in both of the last two cases the crop stands in for it. `hairSide` (inside `turn`, present only with a side lock) is `{ left?, right? }` by screen side — `left` the lock at −x (`hair_side_R`), `right` at +x — each `{ role, cover?, tail?, unavailable? }`, report-only, measured as the far lock at its side's far stops (−15 and −30 on the left, 15 and 30 on the right), px, every x landed through the rendered rig: `cover` is `{ deg, px, y, rest }`, the least over the lock's rows on the face plate that cover the head's edge at rest (a root under the bangs, or the rows an ear shows beside the lock, lie inside it by design and do not count) and over the far stops of the lock's outer edge minus the head's edge (the plate's painted edge, with any ear replaced by the head's edge beneath it, so an ear does not count as cheek the lock covers), positive still covering it and negative the turn baring cheek the lock hides at rest, `rest` that row's cover at rest (≥ 0, read off the geometry; `px` may exceed it), `y` the row where it is least in model space (the canvas centre the origin, +y up — the line also gives it as model px from the top, the row of the layer PNG); `tail` is `{ deg, eyeToLock, lashToLock?, eyeToPlate }` for the far eye's outer corner on the eye's centre row at the stop where `eyeToLock` is least — the corner against the lock's face-side edge, positive a gap and negative under the lock (intended), `lashToLock` the same for the lash box with a `lash_*` layer, and `eyeToPlate` the corner's signed distance from that head edge (positive: inside it; negative: past it). A metric that cannot be read is omitted; a lock measured without `rowRuns` (never the case through this tool) carries `unavailable` (a reason) and nothing else. The result text prints them as `HAIRSIDE cover <role>: …` / `HAIRSIDE tail <role>: …` lines, one per metric present, the lock named by its role (`hair_side_R` hangs on the screen left), the pose as the setting that reproduces it (`ParamAngleX=-30`) and every edge distance signed to one decimal in model px (`+0.0` for zero); a lock with neither prints `HAIRSIDE <role>: no cover or tail row`, one carrying `unavailable` prints `HAIRSIDE <role>: unavailable — <why>`; a set with no side lock prints none. `turn` is absent without a `nose` layer. `folds` is the written model's fold report, the engine's `checkFolds` over its own pose set (`{ poses, thresholds, targets, offenders }`, described under `render_poses`); it never refuses a rig — a model that folds is still written and returned — and each fold names its pose by its parameter settings, which a host reproduces by setting those parameters on a player (`IkiPlayer.setParameter`). `physics` is the written model's physics report, the engine's `checkPhysics` over its rigs (`{ thresholds, targets, offenders }`, described under `render_poses`) — the hair springs a `hair_front` layer brings (two for the front hair and, with `hair_back`, one for the back), or none — and never refuses a rig either. The (potentially multi-MB) model is written to disk, not inlined. Invalid input (a `patches` op the rig refuses — `INVALID: patches[i]…`, naming the stops, targets or roles there are; unknown/missing role, an arm without a `body`, empty layer, mismatched sizes, bad path, an atlas page over 4096 px on a side, or an atlas over 12 MiB; art the rig cannot build on, such as a body's hips with no room under its pivots for a row line or for the body's motion, or an arm too short to hang an elbow under its shoulder; a `turnTargets` field that is unknown or that this layer set cannot reach — any passed field other than an `eyeShift` past the art's room; a `rigPlan` field out of range or unknown, or the removed `style` input; the message names the field and the attainable range) returns `{ ok: false, error }` with a `INVALID: …` text — not a protocol error. An argument the tool's input schema refuses — a `turnTargets` or `rigPlan` that is not an object, or one of their named fields that is not a number — never reaches the tool: the MCP SDK answers with an `isError` result whose text is `MCP error -32602: Input validation error: …`, and no `structuredContent`.
@@ -484,19 +484,33 @@ var BLINK_CLOSE_MS = 60;
484
484
  var BLINK_HOLD_MS = 20;
485
485
  var BLINK_OPEN_MS = 100;
486
486
  var BLINK_DURATION_MS = BLINK_CLOSE_MS + BLINK_HOLD_MS + BLINK_OPEN_MS;
487
- var BREATH_PERIOD_MS = 3500;
488
- var GAZE_RADIUS = 0.3;
489
- var GAZE_RETARGET_MIN_MS = 1200;
490
- var GAZE_RETARGET_MAX_MS = 3e3;
491
- var GAZE_EASE_RATE = 1e-3;
492
- var SWAY_X_AMP_A_DEG = 2.2;
493
- var SWAY_X_PERIOD_A_MS = 6100;
494
- var SWAY_X_AMP_B_DEG = 1.3;
495
- var SWAY_X_PERIOD_B_MS = 9700;
496
- var SWAY_Y_AMP_DEG = 1.6;
497
- var SWAY_Y_PERIOD_MS = 7300;
498
- var SWAY_Z_AMP_DEG = 1.1;
499
- var SWAY_Z_PERIOD_MS = 11300;
487
+ var DOUBLE_BLINK_P = 0.18;
488
+ var DOUBLE_BLINK_GAP_MS = 70;
489
+ var BROW_BLINK_DIP = 0.06;
490
+ var BREATH_IN_END = 0.4;
491
+ var BREATH_OUT_END = 0.88;
492
+ var BREATH_PERIOD_MIN_MS = 3200;
493
+ var BREATH_PERIOD_MAX_MS = 4600;
494
+ var BREATH_PITCH_DEG = 1;
495
+ var GAZE_RETARGET_MIN_MS = 800;
496
+ var GAZE_RETARGET_MAX_MS = 3300;
497
+ var GAZE_EYE_CONTACT_P = 0.4;
498
+ var GAZE_X_MAX = 0.8;
499
+ var GAZE_Y_MAX = 0.5;
500
+ var EYE_SPRING_OMEGA = 16;
501
+ var EYE_SPRING_ZETA = 0.9;
502
+ var HEAD_FOLLOW_X_DEG = 10;
503
+ var HEAD_FOLLOW_Y_DEG = 10;
504
+ var HEAD_NOISE_AMP_X_DEG = 6;
505
+ var HEAD_NOISE_AMP_Y_DEG = 4;
506
+ var HEAD_NOISE_AMP_Z_DEG = 4;
507
+ var HEAD_NOISE_RATE_X_HZ = 0.18;
508
+ var HEAD_NOISE_RATE_Y_HZ = 0.15;
509
+ var HEAD_NOISE_RATE_Z_HZ = 0.12;
510
+ var HEAD_SPRING_OMEGA = 7.4;
511
+ var HEAD_SPRING_ZETA = 0.72;
512
+ var HEAD_NOISE_EASE_IN_MS = 4e3;
513
+ var SPRING_SUBSTEP_MS = 8;
500
514
  var AMBIENT_AMP_A = 0.6;
501
515
  var AMBIENT_PERIOD_A_MS = 2900;
502
516
  var AMBIENT_AMP_B = 0.4;
@@ -512,11 +526,51 @@ function blinkEnvelope(phase) {
512
526
  }
513
527
  return 1;
514
528
  }
515
- function randomInDisk(rng, radius) {
516
- const r = Math.sqrt(rng()) * radius;
517
- const theta = rng() * 2 * Math.PI;
518
- return [r * Math.cos(theta), r * Math.sin(theta)];
529
+ function breathEnvelope(phase) {
530
+ if (phase < BREATH_IN_END) return smoothstep(phase / BREATH_IN_END);
531
+ return 1 - smoothstep((phase - BREATH_IN_END) / (BREATH_OUT_END - BREATH_IN_END));
532
+ }
533
+ function drawSeed(rng) {
534
+ return Math.floor(rng() * 4294967296) | 0;
535
+ }
536
+ function latticeValue(seed, i) {
537
+ let h = Math.imul(i, 668265261) ^ seed;
538
+ h = Math.imul(h ^ h >>> 15, 739982445);
539
+ h = Math.imul(h ^ h >>> 12, 695872825);
540
+ h ^= h >>> 15;
541
+ return (h >>> 0) / 2147483648 - 1;
542
+ }
543
+ function valueNoise(seed, x) {
544
+ const i = Math.floor(x);
545
+ return lerp(
546
+ latticeValue(seed, i),
547
+ latticeValue(seed, i + 1),
548
+ smoothstep(x - i)
549
+ );
550
+ }
551
+ function fbm(seed, x) {
552
+ return (valueNoise(seed, x) + 0.5 * valueNoise(seed ^ 1540483477, 2 * x)) / 1.5;
519
553
  }
554
+ var Spring = class {
555
+ constructor(omega, zeta) {
556
+ this.omega = omega;
557
+ this.zeta = zeta;
558
+ }
559
+ omega;
560
+ zeta;
561
+ value = 0;
562
+ velocity = 0;
563
+ /** Advance `dtMs` toward `target` by semi-implicit Euler in short slices. */
564
+ step(target2, dtMs) {
565
+ const slices = Math.ceil(dtMs / SPRING_SUBSTEP_MS);
566
+ const h = dtMs / slices / 1e3;
567
+ for (let s = 0; s < slices; s++) {
568
+ const accel = this.omega * this.omega * (target2 - this.value) - 2 * this.zeta * this.omega * this.velocity;
569
+ this.velocity += accel * h;
570
+ this.value += this.velocity * h;
571
+ }
572
+ }
573
+ };
520
574
  var IdleMotion = class {
521
575
  /**
522
576
  * Every parameter id {@link update} and `emitRestingPose` write, in write
@@ -524,19 +578,11 @@ var IdleMotion = class {
524
578
  * stops driving — keep in step with those two methods; the test suite
525
579
  * pins this list to the actual emissions.
526
580
  */
527
- drivenParameterIds = [
528
- StandardParameter.EyeOpenLeft,
529
- StandardParameter.EyeOpenRight,
530
- StandardParameter.Breath,
531
- StandardParameter.EyeballX,
532
- StandardParameter.EyeballY,
533
- StandardParameter.AngleX,
534
- StandardParameter.AngleY,
535
- StandardParameter.AngleZ,
536
- StandardParameter.AmbientSway
537
- ];
581
+ drivenParameterIds;
538
582
  sink;
539
583
  rng;
584
+ /** The declared brow Y ids the blink dip writes, with their resting values. */
585
+ brows;
540
586
  // Internal clock: advances by clamped dt, NOT by raw wall-clock jumps.
541
587
  // This is the only clock blink/breath/gaze scheduling reads.
542
588
  clockMs = 0;
@@ -545,15 +591,43 @@ var IdleMotion = class {
545
591
  nextBlinkAtMs;
546
592
  blinkStartMs = -1;
547
593
  // -1 means not currently blinking
548
- // Gaze state
549
- gazeCurrentX = 0;
550
- gazeCurrentY = 0;
594
+ // Whether the blink scheduled (or running) is the second of a pair.
595
+ blinkIsSecond = false;
596
+ // Gaze state: the scheduled pick starts at eye contact, (0, 0), until the
597
+ // first retarget. A host target, while set, replaces the pick as what the
598
+ // eyes and head chase; the schedule keeps picking underneath it.
599
+ eyeX = new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
600
+ eyeY = new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
551
601
  gazeTargetX = 0;
552
602
  gazeTargetY = 0;
553
603
  nextGazeRetargetMs;
604
+ hostGaze = void 0;
605
+ // Breath state: the current cycle's start and length on the internal clock.
606
+ breathStartMs = 0;
607
+ breathPeriodMs;
608
+ // Head state: one noise seed and one spring per axis (X turn, Y nod, Z roll).
609
+ headSeedX;
610
+ headSeedY;
611
+ headSeedZ;
612
+ headX = new Spring(HEAD_SPRING_OMEGA, HEAD_SPRING_ZETA);
613
+ headY = new Spring(HEAD_SPRING_OMEGA, HEAD_SPRING_ZETA);
614
+ headZ = new Spring(HEAD_SPRING_OMEGA, HEAD_SPRING_ZETA);
554
615
  constructor(sink, options) {
555
616
  this.sink = sink;
556
617
  this.rng = options?.rng ?? Math.random;
618
+ this.brows = [StandardParameter.BrowLeftY, StandardParameter.BrowRightY].map((id) => options?.parameters?.find((p) => p.id === id)).filter((p) => p !== void 0).map((p) => ({ id: p.id, rest: clamp(p.default, p.min, p.max) }));
619
+ this.drivenParameterIds = [
620
+ StandardParameter.EyeOpenLeft,
621
+ StandardParameter.EyeOpenRight,
622
+ ...this.brows.map((b) => b.id),
623
+ StandardParameter.Breath,
624
+ StandardParameter.EyeballX,
625
+ StandardParameter.EyeballY,
626
+ StandardParameter.AngleX,
627
+ StandardParameter.AngleY,
628
+ StandardParameter.AngleZ,
629
+ StandardParameter.AmbientSway
630
+ ];
557
631
  this.nextBlinkAtMs = lerp(
558
632
  BLINK_INTERVAL_MIN_MS,
559
633
  BLINK_INTERVAL_MAX_MS,
@@ -564,6 +638,10 @@ var IdleMotion = class {
564
638
  GAZE_RETARGET_MAX_MS,
565
639
  this.rng()
566
640
  );
641
+ this.headSeedX = drawSeed(this.rng);
642
+ this.headSeedY = drawSeed(this.rng);
643
+ this.headSeedZ = drawSeed(this.rng);
644
+ this.breathPeriodMs = this.drawBreathPeriod();
567
645
  }
568
646
  /**
569
647
  * Advance the idle animation to the given wall-clock timestamp (milliseconds).
@@ -589,23 +667,52 @@ var IdleMotion = class {
589
667
  const eyeVal = this.advanceBlink();
590
668
  this.sink(StandardParameter.EyeOpenLeft, eyeVal);
591
669
  this.sink(StandardParameter.EyeOpenRight, eyeVal);
670
+ for (const { id, rest } of this.brows) {
671
+ this.sink(id, rest + BROW_BLINK_DIP * (eyeVal - 1));
672
+ }
592
673
  const breath = this.advanceBreath();
593
674
  this.advanceGaze(dt);
594
675
  this.sink(StandardParameter.Breath, breath);
595
- this.sink(StandardParameter.EyeballX, this.gazeCurrentX);
596
- this.sink(StandardParameter.EyeballY, this.gazeCurrentY);
597
- this.sink(StandardParameter.AngleX, this.swayX());
598
- this.sink(StandardParameter.AngleY, this.swayY());
599
- this.sink(StandardParameter.AngleZ, this.swayZ());
676
+ this.sink(StandardParameter.EyeballX, this.eyeX.value);
677
+ this.sink(StandardParameter.EyeballY, this.eyeY.value);
678
+ this.advanceHead(dt, breath);
679
+ this.sink(StandardParameter.AngleX, this.headX.value);
680
+ this.sink(StandardParameter.AngleY, this.headY.value);
681
+ this.sink(StandardParameter.AngleZ, this.headZ.value);
600
682
  this.sink(StandardParameter.AmbientSway, this.ambientSway());
601
683
  }
684
+ /**
685
+ * Hold the gaze on (`x`, `y`), in EyeballX/Y units (+ is the viewer's right
686
+ * and up), until {@link clearGazeTarget}: the eyes chase it on their stiff
687
+ * springs and the head follows it on the turn and nod, as it follows a
688
+ * scheduled pick. Each value is clamped to [-1, 1], so the follow can reach
689
+ * past the scheduled picks' ±0.8 / ±0.5 box. A pair with a non-finite value
690
+ * is ignored and changes nothing, the same boundary rule as
691
+ * ParameterStore.set.
692
+ *
693
+ * The scheduled retargets keep running and drawing from the rng while a host
694
+ * target is set, so the rng sequence does not depend on host calls.
695
+ */
696
+ setGazeTarget(x, y) {
697
+ if (!Number.isFinite(x) || !Number.isFinite(y)) return;
698
+ this.hostGaze = { x: clamp(x, -1, 1), y: clamp(y, -1, 1) };
699
+ }
700
+ /**
701
+ * Drop the host target: the eyes and head turn back to the current
702
+ * scheduled pick at once (a pointer leaving does not leave the eyes frozen
703
+ * until the next retarget), and later picks drive them as before.
704
+ */
705
+ clearGazeTarget() {
706
+ this.hostGaze = void 0;
707
+ }
602
708
  // ---------------------------------------------------------------------------
603
709
  // Private helpers
604
710
  // ---------------------------------------------------------------------------
605
711
  emitRestingPose() {
606
712
  this.sink(StandardParameter.EyeOpenLeft, 1);
607
713
  this.sink(StandardParameter.EyeOpenRight, 1);
608
- this.sink(StandardParameter.Breath, 0.5);
714
+ for (const { id, rest } of this.brows) this.sink(id, rest);
715
+ this.sink(StandardParameter.Breath, 0);
609
716
  this.sink(StandardParameter.EyeballX, 0);
610
717
  this.sink(StandardParameter.EyeballY, 0);
611
718
  this.sink(StandardParameter.AngleX, 0);
@@ -620,7 +727,8 @@ var IdleMotion = class {
620
727
  const phase = (clockMs - this.blinkStartMs) / BLINK_DURATION_MS;
621
728
  if (phase >= 1) {
622
729
  this.blinkStartMs = -1;
623
- this.nextBlinkAtMs = clockMs + lerp(BLINK_INTERVAL_MIN_MS, BLINK_INTERVAL_MAX_MS, this.rng());
730
+ this.blinkIsSecond = !this.blinkIsSecond && this.rng() < DOUBLE_BLINK_P;
731
+ this.nextBlinkAtMs = clockMs + (this.blinkIsSecond ? DOUBLE_BLINK_GAP_MS : lerp(BLINK_INTERVAL_MIN_MS, BLINK_INTERVAL_MAX_MS, this.rng()));
624
732
  return 1;
625
733
  }
626
734
  return blinkEnvelope(phase);
@@ -631,38 +739,68 @@ var IdleMotion = class {
631
739
  }
632
740
  return 1;
633
741
  }
742
+ /**
743
+ * Returns the breath value (0..1), starting the next cycle, with a freshly
744
+ * drawn length, once the current one has run out. One clamped dt (≤ 100 ms)
745
+ * is far shorter than any cycle, so a step crosses at most one boundary.
746
+ */
634
747
  advanceBreath() {
635
- return 0.5 + 0.5 * Math.sin(2 * Math.PI * this.clockMs / BREATH_PERIOD_MS);
636
- }
637
- /** Horizontal head sway in degrees, pure function of the internal clock. */
638
- swayX() {
639
- const t = 2 * Math.PI * this.clockMs;
640
- return SWAY_X_AMP_A_DEG * Math.sin(t / SWAY_X_PERIOD_A_MS) + SWAY_X_AMP_B_DEG * Math.sin(t / SWAY_X_PERIOD_B_MS);
748
+ if (this.clockMs - this.breathStartMs >= this.breathPeriodMs) {
749
+ this.breathStartMs += this.breathPeriodMs;
750
+ this.breathPeriodMs = this.drawBreathPeriod();
751
+ }
752
+ return breathEnvelope(
753
+ (this.clockMs - this.breathStartMs) / this.breathPeriodMs
754
+ );
641
755
  }
642
- /** Vertical head sway in degrees, pure function of the internal clock. */
643
- swayY() {
644
- return SWAY_Y_AMP_DEG * Math.sin(2 * Math.PI * this.clockMs / SWAY_Y_PERIOD_MS);
756
+ drawBreathPeriod() {
757
+ return lerp(BREATH_PERIOD_MIN_MS, BREATH_PERIOD_MAX_MS, this.rng());
645
758
  }
646
- /** Head roll sway in degrees, pure function of the internal clock. */
647
- swayZ() {
648
- return SWAY_Z_AMP_DEG * Math.sin(2 * Math.PI * this.clockMs / SWAY_Z_PERIOD_MS);
759
+ /**
760
+ * Step each head spring toward its axis noise at the internal clock, plus,
761
+ * on the turn and nod, the gaze target scaled to degrees, and on the nod the
762
+ * breath's lift. Only the noise fades in: the scheduled pick starts at
763
+ * (0, 0), so it has no start value to lurch to, and its first jump is no
764
+ * larger than any later one; the breath starts empty, at 0.
765
+ */
766
+ advanceHead(dt, breath) {
767
+ const seconds = this.clockMs / 1e3;
768
+ const easeIn = smoothstep(this.clockMs / HEAD_NOISE_EASE_IN_MS);
769
+ this.headX.step(
770
+ easeIn * HEAD_NOISE_AMP_X_DEG * fbm(this.headSeedX, seconds * HEAD_NOISE_RATE_X_HZ) + HEAD_FOLLOW_X_DEG * (this.hostGaze?.x ?? this.gazeTargetX),
771
+ dt
772
+ );
773
+ this.headY.step(
774
+ easeIn * HEAD_NOISE_AMP_Y_DEG * fbm(this.headSeedY, seconds * HEAD_NOISE_RATE_Y_HZ) + HEAD_FOLLOW_Y_DEG * (this.hostGaze?.y ?? this.gazeTargetY) + BREATH_PITCH_DEG * breath,
775
+ dt
776
+ );
777
+ this.headZ.step(
778
+ easeIn * HEAD_NOISE_AMP_Z_DEG * fbm(this.headSeedZ, seconds * HEAD_NOISE_RATE_Z_HZ),
779
+ dt
780
+ );
649
781
  }
650
782
  /** Ambient sway (-1..1), pure function of the internal clock. */
651
783
  ambientSway() {
652
784
  const t = 2 * Math.PI * this.clockMs;
653
785
  return AMBIENT_AMP_A * Math.sin(t / AMBIENT_PERIOD_A_MS) + AMBIENT_AMP_B * Math.sin(t / AMBIENT_PERIOD_B_MS);
654
786
  }
655
- /** Ease gaze current toward target; pick a new target on the internal clock. */
787
+ /**
788
+ * Step the eye springs toward the gaze target, the host's while set, else
789
+ * the scheduled pick; retarget on the internal clock either way.
790
+ */
656
791
  advanceGaze(dt) {
657
792
  if (this.clockMs >= this.nextGazeRetargetMs) {
658
- const [tx, ty] = randomInDisk(this.rng, GAZE_RADIUS);
659
- this.gazeTargetX = tx;
660
- this.gazeTargetY = ty;
793
+ if (this.rng() < GAZE_EYE_CONTACT_P) {
794
+ this.gazeTargetX = 0;
795
+ this.gazeTargetY = 0;
796
+ } else {
797
+ this.gazeTargetX = lerp(-GAZE_X_MAX, GAZE_X_MAX, this.rng());
798
+ this.gazeTargetY = lerp(-GAZE_Y_MAX, GAZE_Y_MAX, this.rng());
799
+ }
661
800
  this.nextGazeRetargetMs = this.clockMs + lerp(GAZE_RETARGET_MIN_MS, GAZE_RETARGET_MAX_MS, this.rng());
662
801
  }
663
- const factor = 1 - Math.pow(1 - GAZE_EASE_RATE, dt);
664
- this.gazeCurrentX = lerp(this.gazeCurrentX, this.gazeTargetX, factor);
665
- this.gazeCurrentY = lerp(this.gazeCurrentY, this.gazeTargetY, factor);
802
+ this.eyeX.step(this.hostGaze?.x ?? this.gazeTargetX, dt);
803
+ this.eyeY.step(this.hostGaze?.y ?? this.gazeTargetY, dt);
666
804
  }
667
805
  };
668
806
 
@@ -1389,7 +1527,8 @@ function stepRun(model, rigs, chains, values) {
1389
1527
  function idleRun(model) {
1390
1528
  const store = new ParameterStore(model.parameters);
1391
1529
  const idle = new IdleMotion((id, v) => store.set(id, v), {
1392
- rng: lcg(IDLE_SEED)
1530
+ rng: lcg(IDLE_SEED),
1531
+ parameters: model.parameters
1393
1532
  });
1394
1533
  return run(
1395
1534
  model,
@@ -7863,7 +8002,7 @@ function formatBakeChecks(bakes) {
7863
8002
  );
7864
8003
  }
7865
8004
  function createIkiMcpServer() {
7866
- const server = new McpServer({ name: "iki", version: "0.36.1" });
8005
+ const server = new McpServer({ name: "iki", version: "0.37.1" });
7867
8006
  server.registerTool(
7868
8007
  "validate_iki",
7869
8008
  {
@@ -8039,7 +8178,7 @@ function createIkiMcpServer() {
8039
8178
  "At least one, `value` strictly ascending and inside the parameter's range. The amount is linear between stops and held before the first and after the last."
8040
8179
  )
8041
8180
  }).passthrough().optional().describe(
8042
- "Hide the part where the named roles' paint covers it, by an amount keyed on a parameter: `{ by, parameter, stops: [{ value, amount }] }`. Cover is where a role's drawn alpha at that pose is at least 0.5, a hard edge; a role that fades (`mouth_open`, a blush, a pose forearm) covers only while drawn at half strength or more. Use the stops as a short switch starting a degree or more past the idle sway, the hiding's progress coming from the part's baked motion. Needs @ikijs/mcp 0.35.0; an older server refuses the key as an unknown key (`INVALID: customParts[i]\u2026`). An unknown key, a bad stop or a part the key cannot be written for comes back as `INVALID: customParts[i].occlusion\u2026` with nothing written."
8181
+ "Hide the part where the named roles' paint covers it, by an amount keyed on a parameter: `{ by, parameter, stops: [{ value, amount }] }`. Cover is where a role's drawn alpha at that pose is at least 0.5, a hard edge; a role that fades (`mouth_open`, a blush, a pose forearm) covers only while drawn at half strength or more. Use the stops as a short switch starting a degree or more off rest (so the rest pose never sits on it; the idle turns the head through the switch), the hiding's progress coming from the part's baked motion. Needs @ikijs/mcp 0.35.0; an older server refuses the key as an unknown key (`INVALID: customParts[i]\u2026`). An unknown key, a bad stop or a part the key cannot be written for comes back as `INVALID: customParts[i].occlusion\u2026` with nothing written."
8043
8182
  )
8044
8183
  }).passthrough()
8045
8184
  ).optional().describe(
@@ -8413,4 +8552,4 @@ export {
8413
8552
  formatPhysicsReport,
8414
8553
  createIkiMcpServer
8415
8554
  };
8416
- //# sourceMappingURL=chunk-VZIH3JF4.mjs.map
8555
+ //# sourceMappingURL=chunk-N6KPV7FC.mjs.map