@ikijs/mcp 0.27.0 → 0.29.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 CHANGED
@@ -28,7 +28,7 @@ Turns a set of role-named, full-canvas transparent PNG layers into a renderable,
28
28
  - **`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`.
29
29
  - **`style`** — optional per-character tuning from the profile the rig defaults to: `turn` (the whole head turn, the eyes' foreshortening with it, 0..3, 1 = the profile; ignored when `turnTargets.eyeShift` is given), `featureLead` (how far the features lead the face plate, 0..3), `hairFollow` (the front hair's share of the face's turn, 0..2, profile 1), `outlineFollow` (its outer edge's share where it draws the head's outline, 0..2, profile 0: the outline holds), `blink` (how far the upper lid comes down over the eye's height, 0.1..1, profile 0.6) and `sway` (the hair sway amplitude, 0..5). A value out of range, or a knob not named here, is refused.
30
30
  - **`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 `style` 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`.
31
- - **Result** — on success the result text is the written file path, 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), and `structuredContent` carries `{ ok: true, path, canvas, partCount, atlasBytes, headHalfWidth?, headHalfWidthApplied, headEdges?, strandEdges?, noseCore?, turn?, patches?, folds, physics }`. `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. `atlasBytes` is the embedded atlas's data-URI length, summed over both pages when the nose has one of its own. `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. `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 two hair-sway springs a `hair_front` layer brings, 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 `style` knob out of range or unknown; 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 `style` 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`.
31
+ - **Result** — on success the result text is the written file path, 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), and `structuredContent` carries `{ ok: true, path, canvas, partCount, atlasBytes, headHalfWidth?, headHalfWidthApplied, headEdges?, strandEdges?, noseCore?, turn?, patches?, folds, physics }`. `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. `atlasBytes` is the embedded atlas's data-URI length, summed over both pages when the nose has one of its own. `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. `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 `style` knob out of range or unknown; 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 `style` 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`.
32
32
 
33
33
  The decode/atlas pipeline runs in Node via `sharp` (a native dependency confined to this package); it mirrors the browser editor app's import flow and reuses the pure `@ikijs/editor` model + atlas math, so both paths produce the same rig. The fold and physics checks run the workspace `@ikijs/engine`, inlined into this package's Node build (as it already is into the `render_poses` page script), while `@ikijs/format` stays an external dependency.
34
34
 
@@ -86,7 +86,7 @@ Renders a rigged `.iki` into the pose PNGs the character loop reviews, with the
86
86
  - **What is written** — the model decides the set. A bust gets 560 × 560 shots: `rest`, `turn-m30`, `turn-p30`, `turn-15`, `nod-15`, `blink`, `blink-half`, `gaze`, `combined` (`ParamAngleX`/`Y`/`Z` all at 30), `stress` (`ParamAngleX`/`Y`/`Z` all at −30, `ParamMouthOpenY` 1, `ParamEyeLOpen` and `ParamEyeROpen` 0.5, `ParamBrowLY` −1, `ParamBrowRY` 1, `ParamBrowLAngle` 1, `ParamBrowRAngle` −1, and each of `ParamBodyAngleX`/`Y`/`Z` the model declares at −10: moves that each look fine alone, stacked). A model with a `mouth` or `mouth_inner` adds 720 × 480 mouth crops (`mouth-open-*-form-*`, `mouth-laugh`, `mouth-surprised`, `mouth-turn-p30-half`). A full body (canvas taller than wide) shoots the same squares from the model's top (the head), centred horizontally, and adds whole-canvas `full-*` shots (body, arm and elbow poses) at 1400 px wide; one with a pose forearm (`ParamArmPoseR`) adds the `full-pose-*` shots.
87
87
  - **Result** — the text is the written paths, one per line, then the model's fold report, then its physics report. `failedTextures` lists the atlas pages the engine could not load; their parts are missing from the renders. `structuredContent` is `{ ok: true, outDir, canvas, fullBody, mouth?, failedTextures, poses: [{ name, path }], modelCanvas, folds, physics }`. A missing model, an `outDir` that is missing or outside the working directory, or a file that is not a valid model returns `{ ok: false, error }` with `INVALID: …` text.
88
88
  - **Folds** — `folds` is the engine's `checkFolds` over its own pose set (`foldPoses`: rest, each parameter alone at its min and max, and the corners of the head and body angles crossed with the eyes, the mouth, the arms and the elbows), not over the rendered shots: `{ poses, thresholds: { flip: 0, collapse: 0.1 }, targets, offenders }`, one target per warp deformer (its grid cells) and per mesh part (its triangles), each `{ target: { kind, id }, kind, worst?, expected? }`: `worst` and `expected` are the least ratio of an area at a pose to the same at rest over the poses that are not, and that are, a by-design closure (below), each with its cell or triangle, its pose and its rest point; `kind` (`flip`, `collapse` or `ok`) is read off `worst` alone, and `offenders` are the targets that are not `ok`. The text prints one `FOLD` line per offender, worst first — `flip` (ratio ≤ 0) or `collapse` (under 0.1), `deformer` or `part`, its id, `cell (col,row)` or `triangle i`, the ratio (two significant figures under 0.01, so a flip never reads `-0.00`), the pose in brackets as its sorted `id=value` settings (`rest` for none), and where it sits at rest in model space and in model px from the top-left of `modelCanvas` (the layer PNGs' own pixels, not a render's) — or `FOLDS: none over N poses`. Then, when one folds, a `FOLDS expected:` line names the closures the auto-rig draws on purpose, each by part id, ratio and the parameter that shuts it: `eye_L` and `lash_lower_L` while `ParamEyeLOpen` is 0, `eye_R` and `lash_lower_R` while `ParamEyeROpen` is 0, and the lip set (`mouth_inner`, `mouth_tongue`, `mouth_teeth`, `lip_lower`, `lip_upper`) while `ParamMouthOpenY` is 0, read as each pose's effective value, its default included. The sweep covers the engine's pose set plus the caller's `poses`; a caller's pose is named in the `FOLD` lines by its sorted `id=value` settings (`rest` when empty), never by its PNG name, so a host reproduces any fold by setting those parameters on a player. Report-only: a fold never fails the render.
89
- - **Physics** — `physics` is the engine's `checkPhysics` over the model's own rigs (`poses` do not enter it): `{ thresholds: { displacementPx: 1, pinnedFrames: 60 }, targets, offenders }`, one target per `model.physics` rig, then one per chain segment, in model order, each `{ rig, input, output, drives, kind, why?, step, idle }`. `rig` is `{ kind: "spring", id }` or `{ kind: "chain", id, segment }`; `input` is the spring's input parameter, or every parameter that turns the chain's anchor; `output` is the driven parameter; `drives` lists what reads it, the parts then the deformers (`{ kind, id }`); `kind` is `ok`, `frozen` or `unstable`, and `why`, present when it is not `ok`, is one phrase naming the window it came from; `offenders` are the targets that are not `ok`, unstable first. Each output is excited through the engine's real drivers on a 60 Hz clock. The step holds a fresh rig's input at its far end — the end farther from its default — for 5 s; a chain steps each parameter that turns its anchor alone, in its own run, and reports the run moving the parts most among those that are not unstable. The idle runs every rig and chain together behind the procedural idle, on a seeded rng, for 30 s. `step` is `{ values, peak, at, final, displacementPx }`: the setting held, the output's largest signed displacement from rest and when, in seconds, its value at the end of the window, and the largest vertex move of any part in model px with the output alone at every value the step emitted. `idle` is `{ peak, at, displacementPx }`, its peak a size, since the sway goes both ways, and its move taken at every value the idle emitted. A target is `unstable` when a spring's one-sub-step map has a spectral radius over 1 (exact, in closed form) or sits on its undamped boundary `dt²k/m = 4`, when a driver's finiteness guard fires (`why` says how often), or when the raw output stays outside its range for 60 consecutive frames (1 s), in either window. A chain's update is nonlinear, so it gets no radius verdict: a chain that grows yet stays finite and inside its range trips none of these, which is deferred to a later slice, and shows in the numbers only. A target is `frozen` when it drives nothing, its input has no range, nothing turns its chain's anchor, or the step moves the parts under 1 model px. The amplitudes are numbers only: however little the idle moves an output, that never flags. The text prints one `PHYSICS` line per target after the fold lines — its kind, the rig (`id`, or `id/segment [inputs]` for a chain segment) and `input -> output`; then `step`, its setting as sorted `id=value` pairs (`rest` for none), the peak and when, the final value and the move, with the ids it drives in parentheses; then `idle`, its peak, when and move; and ` — <why>` when it is not `ok` — or `PHYSICS: no rigs`. Parameter values and seconds print to two decimals and px to one, rounded down, so a frozen 0.96 px never reads 1.0. Report-only: nothing here refuses a rig or fails a render.
89
+ - **Physics** — `physics` is the engine's `checkPhysics` over the model's own rigs (`poses` do not enter it): `{ thresholds: { displacementPx: 1, pinnedFrames: 60 }, targets, offenders }`, one target per `model.physics` rig, then one per chain segment, in model order, each `{ rig, input, output, drives, kind, why?, step, idle }`. `rig` is `{ kind: "spring", id }` or `{ kind: "chain", id, segment }`; `input` is every input parameter of the spring, in rig order, or every parameter that turns the chain's anchor; `output` is the driven parameter; `drives` lists what reads it, the parts then the deformers (`{ kind, id }`); `kind` is `ok`, `frozen` or `unstable`, and `why`, present when it is not `ok`, is one phrase naming the window it came from; `offenders` are the targets that are not `ok`, unstable first. Each output is excited through the engine's real drivers on a 60 Hz clock. The step holds a fresh rig's input at its far end — the end farther from its default — for 5 s; a spring steps each input that has a range alone, in its own run, and a chain each parameter that turns its anchor, and either reports the run moving the parts most among those that are not unstable. A `lag` input's step peaks at once at its bound, −scale × weight (less one sub-step), and its `final` reads rest: the bound is what a one-frame step shows, and a gradual turn swings less. The idle runs every rig and chain together behind the procedural idle, on a seeded rng, for 30 s. `step` is `{ values, peak, at, final, displacementPx }`: the setting held, the output's largest signed displacement from rest and when, in seconds, its value at the end of the window, and the largest vertex move of any part in model px with the output alone at every value the step emitted. `idle` is `{ peak, at, displacementPx }`, its peak a size, since the sway goes both ways, and its move taken at every value the idle emitted. A target is `unstable` when a spring's one-sub-step map has a spectral radius over 1 (exact, in closed form) or sits on its undamped boundary `dt²k/m = 4`, when a driver's finiteness guard fires (`why` says how often), or when the raw output stays outside its range for 60 consecutive frames (1 s), in either window. A chain's update is nonlinear, so it gets no radius verdict: a chain that grows yet stays finite and inside its range trips none of these, which is deferred to a later slice, and shows in the numbers only. A target is `frozen` when it drives nothing, none of its spring's inputs has a range, nothing turns its chain's anchor, or the step moves the parts under 1 model px. The amplitudes are numbers only: however little the idle moves an output, that never flags. The text prints one `PHYSICS` line per target after the fold lines — its kind, the rig (`id`, or `id/segment [inputs]` for a chain segment) and `input -> output`; then `step`, its setting as sorted `id=value` pairs (`rest` for none), the peak and when, the final value and the move, with the ids it drives in parentheses; then `idle`, its peak, when and move; and ` — <why>` when it is not `ok` — or `PHYSICS: no rigs`. Parameter values and seconds print to two decimals and px to one, rounded down, so a frozen 0.96 px never reads 1.0. Report-only: nothing here refuses a rig or fails a render.
90
90
 
91
91
  ## Usage
92
92
 
@@ -430,6 +430,14 @@ var FixedStepClock = class {
430
430
  get isSeedFrame() {
431
431
  return this.prevNowMs === void 0;
432
432
  }
433
+ /**
434
+ * Time carried in the accumulator, in seconds: how far the frame's timestamp is
435
+ * past the last whole sub-step. Drivers extrapolate their state by it so what
436
+ * they emit is the state at the frame's time, not at the last sub-step.
437
+ */
438
+ get remainderS() {
439
+ return this.accumulatorS;
440
+ }
433
441
  /**
434
442
  * Fold `nowMs` into the accumulator and return how many {@link FIXED_DT_S}
435
443
  * sub-steps to run this frame. On the seed frame it only records the
@@ -473,6 +481,10 @@ var SWAY_Y_AMP_DEG = 1.6;
473
481
  var SWAY_Y_PERIOD_MS = 7300;
474
482
  var SWAY_Z_AMP_DEG = 1.1;
475
483
  var SWAY_Z_PERIOD_MS = 11300;
484
+ var AMBIENT_AMP_A = 0.6;
485
+ var AMBIENT_PERIOD_A_MS = 2900;
486
+ var AMBIENT_AMP_B = 0.4;
487
+ var AMBIENT_PERIOD_B_MS = 4300;
476
488
  function blinkEnvelope(phase) {
477
489
  const ms = phase * BLINK_DURATION_MS;
478
490
  if (ms <= 0) return 1;
@@ -504,7 +516,8 @@ var IdleMotion = class {
504
516
  StandardParameter.EyeballY,
505
517
  StandardParameter.AngleX,
506
518
  StandardParameter.AngleY,
507
- StandardParameter.AngleZ
519
+ StandardParameter.AngleZ,
520
+ StandardParameter.AmbientSway
508
521
  ];
509
522
  sink;
510
523
  rng;
@@ -568,6 +581,7 @@ var IdleMotion = class {
568
581
  this.sink(StandardParameter.AngleX, this.swayX());
569
582
  this.sink(StandardParameter.AngleY, this.swayY());
570
583
  this.sink(StandardParameter.AngleZ, this.swayZ());
584
+ this.sink(StandardParameter.AmbientSway, this.ambientSway());
571
585
  }
572
586
  // ---------------------------------------------------------------------------
573
587
  // Private helpers
@@ -581,6 +595,7 @@ var IdleMotion = class {
581
595
  this.sink(StandardParameter.AngleX, 0);
582
596
  this.sink(StandardParameter.AngleY, 0);
583
597
  this.sink(StandardParameter.AngleZ, 0);
598
+ this.sink(StandardParameter.AmbientSway, 0);
584
599
  }
585
600
  /** Returns the current eye-open value (0..1) and advances blink state. */
586
601
  advanceBlink() {
@@ -616,6 +631,11 @@ var IdleMotion = class {
616
631
  swayZ() {
617
632
  return SWAY_Z_AMP_DEG * Math.sin(2 * Math.PI * this.clockMs / SWAY_Z_PERIOD_MS);
618
633
  }
634
+ /** Ambient sway (-1..1), pure function of the internal clock. */
635
+ ambientSway() {
636
+ const t = 2 * Math.PI * this.clockMs;
637
+ return AMBIENT_AMP_A * Math.sin(t / AMBIENT_PERIOD_A_MS) + AMBIENT_AMP_B * Math.sin(t / AMBIENT_PERIOD_B_MS);
638
+ }
619
639
  /** Ease gaze current toward target; pick a new target on the internal clock. */
620
640
  advanceGaze(dt) {
621
641
  if (this.clockMs >= this.nextGazeRetargetMs) {
@@ -631,6 +651,9 @@ var IdleMotion = class {
631
651
  };
632
652
 
633
653
  // ../engine/src/physics-motion.ts
654
+ import {
655
+ physicsInputs
656
+ } from "@ikijs/format";
634
657
  function signedNormalized(value, param) {
635
658
  const rest = clamp(param.default, param.min, param.max);
636
659
  const den = Math.max(Math.abs(param.max - rest), Math.abs(rest - param.min));
@@ -648,6 +671,7 @@ var PhysicsMotion = class {
648
671
  resets;
649
672
  resetCounts;
650
673
  rigs;
674
+ inputs;
651
675
  read;
652
676
  sink;
653
677
  params;
@@ -656,10 +680,17 @@ var PhysicsMotion = class {
656
680
  clock = new FixedStepClock();
657
681
  constructor(rigs, params, read, sink) {
658
682
  this.rigs = rigs;
683
+ this.inputs = rigs.map(
684
+ (rig) => physicsInputs(rig).map(({ parameter, weight, mode }) => ({
685
+ parameter,
686
+ weight,
687
+ lag: mode === "lag"
688
+ }))
689
+ );
659
690
  this.read = read;
660
691
  this.sink = sink;
661
692
  this.params = new Map(params.map((p) => [p.id, p]));
662
- this.state = rigs.map(() => ({ x: 0, v: 0 }));
693
+ this.state = rigs.map(() => ({ x: 0, v: 0, lag: 0 }));
663
694
  this.drivenParameterIds = rigs.map((rig) => rig.output.parameter);
664
695
  this.resetCounts = rigs.map(() => 0);
665
696
  this.resets = this.resetCounts;
@@ -668,8 +699,12 @@ var PhysicsMotion = class {
668
699
  * Advance every rig to the given wall-clock timestamp (milliseconds).
669
700
  *
670
701
  * First call: seed each spring to rest AT its current target (so a model
671
- * loaded with a nonzero input does not kick), emit the resting output, and
672
- * return without integrating — mirroring IdleMotion's first-frame behavior.
702
+ * loaded with a nonzero input does not kick: a lag input emits rest, a follow
703
+ * input its value), emit that output, and return without integrating —
704
+ * mirroring IdleMotion's first-frame behavior.
705
+ *
706
+ * A non-finite `nowMs` after that is a dropped frame: every rig re-emits its
707
+ * last output from its stored state without reading its inputs.
673
708
  *
674
709
  * Subsequent calls: {@link FixedStepClock} folds the clamped frame delta into
675
710
  * its accumulator and returns how many {@link FIXED_DT_S} sub-steps are due;
@@ -682,35 +717,52 @@ var PhysicsMotion = class {
682
717
  this.clock.advance(nowMs);
683
718
  for (let i = 0; i < this.rigs.length; i++) {
684
719
  const st = this.state[i];
685
- st.x = this.targetFor(this.rigs[i]);
720
+ const { target: target2, lag } = this.targetFor(i);
721
+ st.x = target2;
686
722
  st.v = 0;
723
+ st.lag = lag;
687
724
  this.emit(i, st);
688
725
  }
689
726
  return;
690
727
  }
728
+ if (!Number.isFinite(nowMs)) {
729
+ for (let i = 0; i < this.rigs.length; i++) this.emit(i, this.state[i]);
730
+ return;
731
+ }
691
732
  const steps = this.clock.advance(nowMs);
692
- const targets = this.rigs.map((rig) => this.targetFor(rig));
733
+ const targets = this.rigs.map((_, i) => this.targetFor(i));
693
734
  for (let s = 0; s < steps; s++) {
694
735
  for (let i = 0; i < this.rigs.length; i++) {
695
- this.step(this.rigs[i], this.state[i], targets[i]);
736
+ this.step(this.rigs[i], this.state[i], targets[i].target);
696
737
  }
697
738
  }
698
739
  for (let i = 0; i < this.rigs.length; i++) {
699
740
  const st = this.state[i];
741
+ const { target: target2, lag } = targets[i];
700
742
  if (!Number.isFinite(st.x) || !Number.isFinite(st.v)) {
701
- st.x = Number.isFinite(targets[i]) ? targets[i] : 0;
743
+ st.x = Number.isFinite(target2) ? target2 : 0;
702
744
  st.v = 0;
703
745
  this.resetCounts[i]++;
704
746
  }
747
+ st.lag = lag;
705
748
  this.emit(i, st);
706
749
  }
707
750
  }
708
- /** Spring target = signed-normalized input value × weight. */
709
- targetFor(rig) {
710
- const param = this.params.get(rig.input.parameter);
711
- const value = this.read(rig.input.parameter);
712
- const norm = param ? signedNormalized(value, param) : 0;
713
- return norm * rig.input.weight;
751
+ /**
752
+ * Rig `index`'s spring target `T` = Σ signed-normalized input value × weight,
753
+ * and `L`, the lag inputs' share of it. Reads each input once.
754
+ */
755
+ targetFor(index) {
756
+ let target2 = 0;
757
+ let lag = 0;
758
+ for (const input of this.inputs[index]) {
759
+ const param = this.params.get(input.parameter);
760
+ const value = this.read(input.parameter);
761
+ const share = (param ? signedNormalized(value, param) : 0) * input.weight;
762
+ target2 += share;
763
+ if (input.lag) lag += share;
764
+ }
765
+ return { target: target2, lag };
714
766
  }
715
767
  /** One semi-implicit (symplectic) Euler sub-step of FIXED_DT_S seconds. */
716
768
  step(rig, st, target2) {
@@ -718,12 +770,13 @@ var PhysicsMotion = class {
718
770
  st.v += accel * FIXED_DT_S;
719
771
  st.x += st.v * FIXED_DT_S;
720
772
  }
721
- /** Write outputDefault + x * scale onto the output param via the sink. */
773
+ /** Write outputDefault + (x − L) * scale onto the output param via the sink. */
722
774
  emit(index, st) {
723
775
  const rig = this.rigs[index];
724
776
  const outParam = this.params.get(rig.output.parameter);
725
777
  const outDefault = outParam ? clamp(outParam.default, outParam.min, outParam.max) : 0;
726
- const value = outDefault + st.x * rig.output.scale;
778
+ const x = st.x + st.v * this.clock.remainderS;
779
+ const value = outDefault + (x - st.lag) * rig.output.scale;
727
780
  const finite = Number.isFinite(value);
728
781
  if (!finite) this.resetCounts[index]++;
729
782
  this.sink(rig.output.parameter, finite ? value : outDefault);
@@ -1199,6 +1252,11 @@ function classify(worst) {
1199
1252
  return "ok";
1200
1253
  }
1201
1254
 
1255
+ // ../engine/src/physics-check.ts
1256
+ import {
1257
+ physicsInputs as physicsInputs2
1258
+ } from "@ikijs/format";
1259
+
1202
1260
  // ../engine/src/physics-runs.ts
1203
1261
  var FRAME_MS = FIXED_DT_S * 1e3 * (1 + 1e-9);
1204
1262
  var STEP_FRAMES = 300;
@@ -1377,26 +1435,34 @@ function checkPhysics(model) {
1377
1435
  };
1378
1436
  const param = (id) => model.parameters.find((p) => p.id === id);
1379
1437
  const springs = (model.physics ?? []).map((rig) => {
1380
- const input = param(rig.input.parameter);
1438
+ const inputs = physicsInputs2(rig).map((i) => param(i.parameter));
1439
+ const ids = inputs.map((p) => p.id);
1381
1440
  const output = param(rig.output.parameter);
1382
- const far = farEnd(input);
1383
- const values = far === void 0 ? {} : { [input.id]: far };
1384
- const reading = stepRun(model, [rig], [], values).get(output.id);
1385
- const step = {
1386
- name: "the step",
1387
- reading,
1388
- displacementPx: displace(output, reading.values),
1389
- values
1390
- };
1441
+ const ranged = inputs.flatMap((input) => {
1442
+ const far = farEnd(input);
1443
+ return far === void 0 ? [] : [{ [input.id]: far }];
1444
+ });
1445
+ const settings = ranged.length === 0 ? [{}] : ranged;
1446
+ const steps = settings.map((values) => {
1447
+ const reading = stepRun(model, [rig], [], values).get(output.id);
1448
+ const setting = inputs.length === 1 ? [] : Object.entries(values).map(([id, v]) => `${id}=${v}`);
1449
+ return {
1450
+ name: ["the step", ...setting].join(" "),
1451
+ reading,
1452
+ displacementPx: displace(output, reading.values),
1453
+ values
1454
+ };
1455
+ });
1391
1456
  const atIdle = idleExcitation(output);
1457
+ const clean = steps.filter((s) => !unstableWhy(output, [s]));
1392
1458
  return target(model, {
1393
1459
  rig: { kind: "spring", id: rig.id },
1394
- input: [input.id],
1460
+ input: ids,
1395
1461
  output,
1396
- step,
1462
+ step: mostMoving(clean.length > 0 ? clean : steps),
1397
1463
  idle: atIdle,
1398
- unstable: springWhy(rig) ?? unstableWhy(output, [step, atIdle]),
1399
- inert: far === void 0 ? `${input.id} has no range` : void 0
1464
+ unstable: springWhy(rig) ?? unstableWhy(output, [...steps, atIdle]),
1465
+ inert: ranged.length === 0 ? `${ids.join(", ")} ${ids.length === 1 ? "has" : "have"} no range` : void 0
1400
1466
  });
1401
1467
  });
1402
1468
  const chains = (model.physicsChains ?? []).flatMap((chain) => {
@@ -2621,6 +2687,10 @@ var STANDARD_PARAMETER_INFO = [
2621
2687
  id: StandardParameter4.Breath,
2622
2688
  description: "Idle breath (0 .. 1), cycled by the host."
2623
2689
  },
2690
+ {
2691
+ id: StandardParameter4.AmbientSway,
2692
+ description: "Ambient sway (-1 .. 1): a slow zero-mean drift the idle writes for physics rigs to follow (the auto-rig's hair in idle). Not a wind: no bias. Stays procedural under a declared Idle group, as Breath does."
2693
+ },
2624
2694
  {
2625
2695
  id: StandardParameter4.BrowLeftY,
2626
2696
  description: "Left brow raise/lower (-1 .. 1)."
@@ -2643,11 +2713,15 @@ var STANDARD_PARAMETER_INFO = [
2643
2713
  },
2644
2714
  {
2645
2715
  id: StandardParameter4.HairSwayX,
2646
- description: "Horizontal hair-sway driver. Physics OUTPUT \u2014 driven by the spring, hosts should not set it directly."
2716
+ description: "Front hair's horizontal sway driver. Physics OUTPUT \u2014 driven by the spring, hosts should not set it directly."
2647
2717
  },
2648
2718
  {
2649
2719
  id: StandardParameter4.HairSwayZ,
2650
- description: "Hair-sway driver behind a head tilt. Physics OUTPUT \u2014 driven by the spring, hosts should not set it directly."
2720
+ description: "Front hair's sway driver behind a head tilt. Physics OUTPUT \u2014 driven by the spring, hosts should not set it directly."
2721
+ },
2722
+ {
2723
+ id: StandardParameter4.HairBackSway,
2724
+ description: "Back hair's sway driver behind the head turn, tilt and ambient drift, one spring slower than the front hair's so the two swing out of phase. Physics OUTPUT \u2014 driven by the spring, hosts should not set it directly."
2651
2725
  },
2652
2726
  {
2653
2727
  id: StandardParameter4.ArmLeft,
@@ -5644,7 +5718,7 @@ function formatPatchReports(reports) {
5644
5718
  });
5645
5719
  }
5646
5720
  function createIkiMcpServer() {
5647
- const server = new McpServer({ name: "iki", version: "0.27.0" });
5721
+ const server = new McpServer({ name: "iki", version: "0.29.0" });
5648
5722
  server.registerTool(
5649
5723
  "validate_iki",
5650
5724
  {
@@ -5978,4 +6052,4 @@ export {
5978
6052
  formatPhysicsReport,
5979
6053
  createIkiMcpServer
5980
6054
  };
5981
- //# sourceMappingURL=chunk-7POOGY7U.mjs.map
6055
+ //# sourceMappingURL=chunk-IG2FZKTW.mjs.map