@ikijs/mcp 0.37.0 → 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/dist/cli.js CHANGED
@@ -520,19 +520,33 @@ var BLINK_CLOSE_MS = 60;
520
520
  var BLINK_HOLD_MS = 20;
521
521
  var BLINK_OPEN_MS = 100;
522
522
  var BLINK_DURATION_MS = BLINK_CLOSE_MS + BLINK_HOLD_MS + BLINK_OPEN_MS;
523
- var BREATH_PERIOD_MS = 3500;
524
- var GAZE_RADIUS = 0.3;
525
- var GAZE_RETARGET_MIN_MS = 1200;
526
- var GAZE_RETARGET_MAX_MS = 3e3;
527
- var GAZE_EASE_RATE = 1e-3;
528
- var SWAY_X_AMP_A_DEG = 2.2;
529
- var SWAY_X_PERIOD_A_MS = 6100;
530
- var SWAY_X_AMP_B_DEG = 1.3;
531
- var SWAY_X_PERIOD_B_MS = 9700;
532
- var SWAY_Y_AMP_DEG = 1.6;
533
- var SWAY_Y_PERIOD_MS = 7300;
534
- var SWAY_Z_AMP_DEG = 1.1;
535
- var SWAY_Z_PERIOD_MS = 11300;
523
+ var DOUBLE_BLINK_P = 0.18;
524
+ var DOUBLE_BLINK_GAP_MS = 70;
525
+ var BROW_BLINK_DIP = 0.06;
526
+ var BREATH_IN_END = 0.4;
527
+ var BREATH_OUT_END = 0.88;
528
+ var BREATH_PERIOD_MIN_MS = 3200;
529
+ var BREATH_PERIOD_MAX_MS = 4600;
530
+ var BREATH_PITCH_DEG = 1;
531
+ var GAZE_RETARGET_MIN_MS = 800;
532
+ var GAZE_RETARGET_MAX_MS = 3300;
533
+ var GAZE_EYE_CONTACT_P = 0.4;
534
+ var GAZE_X_MAX = 0.8;
535
+ var GAZE_Y_MAX = 0.5;
536
+ var EYE_SPRING_OMEGA = 16;
537
+ var EYE_SPRING_ZETA = 0.9;
538
+ var HEAD_FOLLOW_X_DEG = 10;
539
+ var HEAD_FOLLOW_Y_DEG = 10;
540
+ var HEAD_NOISE_AMP_X_DEG = 6;
541
+ var HEAD_NOISE_AMP_Y_DEG = 4;
542
+ var HEAD_NOISE_AMP_Z_DEG = 4;
543
+ var HEAD_NOISE_RATE_X_HZ = 0.18;
544
+ var HEAD_NOISE_RATE_Y_HZ = 0.15;
545
+ var HEAD_NOISE_RATE_Z_HZ = 0.12;
546
+ var HEAD_SPRING_OMEGA = 7.4;
547
+ var HEAD_SPRING_ZETA = 0.72;
548
+ var HEAD_NOISE_EASE_IN_MS = 4e3;
549
+ var SPRING_SUBSTEP_MS = 8;
536
550
  var AMBIENT_AMP_A = 0.6;
537
551
  var AMBIENT_PERIOD_A_MS = 2900;
538
552
  var AMBIENT_AMP_B = 0.4;
@@ -548,11 +562,51 @@ function blinkEnvelope(phase) {
548
562
  }
549
563
  return 1;
550
564
  }
551
- function randomInDisk(rng, radius) {
552
- const r = Math.sqrt(rng()) * radius;
553
- const theta = rng() * 2 * Math.PI;
554
- return [r * Math.cos(theta), r * Math.sin(theta)];
565
+ function breathEnvelope(phase) {
566
+ if (phase < BREATH_IN_END) return smoothstep(phase / BREATH_IN_END);
567
+ return 1 - smoothstep((phase - BREATH_IN_END) / (BREATH_OUT_END - BREATH_IN_END));
568
+ }
569
+ function drawSeed(rng) {
570
+ return Math.floor(rng() * 4294967296) | 0;
571
+ }
572
+ function latticeValue(seed, i) {
573
+ let h = Math.imul(i, 668265261) ^ seed;
574
+ h = Math.imul(h ^ h >>> 15, 739982445);
575
+ h = Math.imul(h ^ h >>> 12, 695872825);
576
+ h ^= h >>> 15;
577
+ return (h >>> 0) / 2147483648 - 1;
578
+ }
579
+ function valueNoise(seed, x) {
580
+ const i = Math.floor(x);
581
+ return lerp(
582
+ latticeValue(seed, i),
583
+ latticeValue(seed, i + 1),
584
+ smoothstep(x - i)
585
+ );
586
+ }
587
+ function fbm(seed, x) {
588
+ return (valueNoise(seed, x) + 0.5 * valueNoise(seed ^ 1540483477, 2 * x)) / 1.5;
555
589
  }
590
+ var Spring = class {
591
+ constructor(omega, zeta) {
592
+ this.omega = omega;
593
+ this.zeta = zeta;
594
+ }
595
+ omega;
596
+ zeta;
597
+ value = 0;
598
+ velocity = 0;
599
+ /** Advance `dtMs` toward `target` by semi-implicit Euler in short slices. */
600
+ step(target2, dtMs) {
601
+ const slices = Math.ceil(dtMs / SPRING_SUBSTEP_MS);
602
+ const h = dtMs / slices / 1e3;
603
+ for (let s = 0; s < slices; s++) {
604
+ const accel = this.omega * this.omega * (target2 - this.value) - 2 * this.zeta * this.omega * this.velocity;
605
+ this.velocity += accel * h;
606
+ this.value += this.velocity * h;
607
+ }
608
+ }
609
+ };
556
610
  var IdleMotion = class {
557
611
  /**
558
612
  * Every parameter id {@link update} and `emitRestingPose` write, in write
@@ -560,19 +614,11 @@ var IdleMotion = class {
560
614
  * stops driving — keep in step with those two methods; the test suite
561
615
  * pins this list to the actual emissions.
562
616
  */
563
- drivenParameterIds = [
564
- import_format.StandardParameter.EyeOpenLeft,
565
- import_format.StandardParameter.EyeOpenRight,
566
- import_format.StandardParameter.Breath,
567
- import_format.StandardParameter.EyeballX,
568
- import_format.StandardParameter.EyeballY,
569
- import_format.StandardParameter.AngleX,
570
- import_format.StandardParameter.AngleY,
571
- import_format.StandardParameter.AngleZ,
572
- import_format.StandardParameter.AmbientSway
573
- ];
617
+ drivenParameterIds;
574
618
  sink;
575
619
  rng;
620
+ /** The declared brow Y ids the blink dip writes, with their resting values. */
621
+ brows;
576
622
  // Internal clock: advances by clamped dt, NOT by raw wall-clock jumps.
577
623
  // This is the only clock blink/breath/gaze scheduling reads.
578
624
  clockMs = 0;
@@ -581,15 +627,43 @@ var IdleMotion = class {
581
627
  nextBlinkAtMs;
582
628
  blinkStartMs = -1;
583
629
  // -1 means not currently blinking
584
- // Gaze state
585
- gazeCurrentX = 0;
586
- gazeCurrentY = 0;
630
+ // Whether the blink scheduled (or running) is the second of a pair.
631
+ blinkIsSecond = false;
632
+ // Gaze state: the scheduled pick starts at eye contact, (0, 0), until the
633
+ // first retarget. A host target, while set, replaces the pick as what the
634
+ // eyes and head chase; the schedule keeps picking underneath it.
635
+ eyeX = new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
636
+ eyeY = new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
587
637
  gazeTargetX = 0;
588
638
  gazeTargetY = 0;
589
639
  nextGazeRetargetMs;
640
+ hostGaze = void 0;
641
+ // Breath state: the current cycle's start and length on the internal clock.
642
+ breathStartMs = 0;
643
+ breathPeriodMs;
644
+ // Head state: one noise seed and one spring per axis (X turn, Y nod, Z roll).
645
+ headSeedX;
646
+ headSeedY;
647
+ headSeedZ;
648
+ headX = new Spring(HEAD_SPRING_OMEGA, HEAD_SPRING_ZETA);
649
+ headY = new Spring(HEAD_SPRING_OMEGA, HEAD_SPRING_ZETA);
650
+ headZ = new Spring(HEAD_SPRING_OMEGA, HEAD_SPRING_ZETA);
590
651
  constructor(sink, options) {
591
652
  this.sink = sink;
592
653
  this.rng = options?.rng ?? Math.random;
654
+ this.brows = [import_format.StandardParameter.BrowLeftY, import_format.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) }));
655
+ this.drivenParameterIds = [
656
+ import_format.StandardParameter.EyeOpenLeft,
657
+ import_format.StandardParameter.EyeOpenRight,
658
+ ...this.brows.map((b) => b.id),
659
+ import_format.StandardParameter.Breath,
660
+ import_format.StandardParameter.EyeballX,
661
+ import_format.StandardParameter.EyeballY,
662
+ import_format.StandardParameter.AngleX,
663
+ import_format.StandardParameter.AngleY,
664
+ import_format.StandardParameter.AngleZ,
665
+ import_format.StandardParameter.AmbientSway
666
+ ];
593
667
  this.nextBlinkAtMs = lerp(
594
668
  BLINK_INTERVAL_MIN_MS,
595
669
  BLINK_INTERVAL_MAX_MS,
@@ -600,6 +674,10 @@ var IdleMotion = class {
600
674
  GAZE_RETARGET_MAX_MS,
601
675
  this.rng()
602
676
  );
677
+ this.headSeedX = drawSeed(this.rng);
678
+ this.headSeedY = drawSeed(this.rng);
679
+ this.headSeedZ = drawSeed(this.rng);
680
+ this.breathPeriodMs = this.drawBreathPeriod();
603
681
  }
604
682
  /**
605
683
  * Advance the idle animation to the given wall-clock timestamp (milliseconds).
@@ -625,23 +703,52 @@ var IdleMotion = class {
625
703
  const eyeVal = this.advanceBlink();
626
704
  this.sink(import_format.StandardParameter.EyeOpenLeft, eyeVal);
627
705
  this.sink(import_format.StandardParameter.EyeOpenRight, eyeVal);
706
+ for (const { id, rest } of this.brows) {
707
+ this.sink(id, rest + BROW_BLINK_DIP * (eyeVal - 1));
708
+ }
628
709
  const breath = this.advanceBreath();
629
710
  this.advanceGaze(dt);
630
711
  this.sink(import_format.StandardParameter.Breath, breath);
631
- this.sink(import_format.StandardParameter.EyeballX, this.gazeCurrentX);
632
- this.sink(import_format.StandardParameter.EyeballY, this.gazeCurrentY);
633
- this.sink(import_format.StandardParameter.AngleX, this.swayX());
634
- this.sink(import_format.StandardParameter.AngleY, this.swayY());
635
- this.sink(import_format.StandardParameter.AngleZ, this.swayZ());
712
+ this.sink(import_format.StandardParameter.EyeballX, this.eyeX.value);
713
+ this.sink(import_format.StandardParameter.EyeballY, this.eyeY.value);
714
+ this.advanceHead(dt, breath);
715
+ this.sink(import_format.StandardParameter.AngleX, this.headX.value);
716
+ this.sink(import_format.StandardParameter.AngleY, this.headY.value);
717
+ this.sink(import_format.StandardParameter.AngleZ, this.headZ.value);
636
718
  this.sink(import_format.StandardParameter.AmbientSway, this.ambientSway());
637
719
  }
720
+ /**
721
+ * Hold the gaze on (`x`, `y`), in EyeballX/Y units (+ is the viewer's right
722
+ * and up), until {@link clearGazeTarget}: the eyes chase it on their stiff
723
+ * springs and the head follows it on the turn and nod, as it follows a
724
+ * scheduled pick. Each value is clamped to [-1, 1], so the follow can reach
725
+ * past the scheduled picks' ±0.8 / ±0.5 box. A pair with a non-finite value
726
+ * is ignored and changes nothing, the same boundary rule as
727
+ * ParameterStore.set.
728
+ *
729
+ * The scheduled retargets keep running and drawing from the rng while a host
730
+ * target is set, so the rng sequence does not depend on host calls.
731
+ */
732
+ setGazeTarget(x, y) {
733
+ if (!Number.isFinite(x) || !Number.isFinite(y)) return;
734
+ this.hostGaze = { x: clamp(x, -1, 1), y: clamp(y, -1, 1) };
735
+ }
736
+ /**
737
+ * Drop the host target: the eyes and head turn back to the current
738
+ * scheduled pick at once (a pointer leaving does not leave the eyes frozen
739
+ * until the next retarget), and later picks drive them as before.
740
+ */
741
+ clearGazeTarget() {
742
+ this.hostGaze = void 0;
743
+ }
638
744
  // ---------------------------------------------------------------------------
639
745
  // Private helpers
640
746
  // ---------------------------------------------------------------------------
641
747
  emitRestingPose() {
642
748
  this.sink(import_format.StandardParameter.EyeOpenLeft, 1);
643
749
  this.sink(import_format.StandardParameter.EyeOpenRight, 1);
644
- this.sink(import_format.StandardParameter.Breath, 0.5);
750
+ for (const { id, rest } of this.brows) this.sink(id, rest);
751
+ this.sink(import_format.StandardParameter.Breath, 0);
645
752
  this.sink(import_format.StandardParameter.EyeballX, 0);
646
753
  this.sink(import_format.StandardParameter.EyeballY, 0);
647
754
  this.sink(import_format.StandardParameter.AngleX, 0);
@@ -656,7 +763,8 @@ var IdleMotion = class {
656
763
  const phase = (clockMs - this.blinkStartMs) / BLINK_DURATION_MS;
657
764
  if (phase >= 1) {
658
765
  this.blinkStartMs = -1;
659
- this.nextBlinkAtMs = clockMs + lerp(BLINK_INTERVAL_MIN_MS, BLINK_INTERVAL_MAX_MS, this.rng());
766
+ this.blinkIsSecond = !this.blinkIsSecond && this.rng() < DOUBLE_BLINK_P;
767
+ this.nextBlinkAtMs = clockMs + (this.blinkIsSecond ? DOUBLE_BLINK_GAP_MS : lerp(BLINK_INTERVAL_MIN_MS, BLINK_INTERVAL_MAX_MS, this.rng()));
660
768
  return 1;
661
769
  }
662
770
  return blinkEnvelope(phase);
@@ -667,38 +775,68 @@ var IdleMotion = class {
667
775
  }
668
776
  return 1;
669
777
  }
778
+ /**
779
+ * Returns the breath value (0..1), starting the next cycle, with a freshly
780
+ * drawn length, once the current one has run out. One clamped dt (≤ 100 ms)
781
+ * is far shorter than any cycle, so a step crosses at most one boundary.
782
+ */
670
783
  advanceBreath() {
671
- return 0.5 + 0.5 * Math.sin(2 * Math.PI * this.clockMs / BREATH_PERIOD_MS);
672
- }
673
- /** Horizontal head sway in degrees, pure function of the internal clock. */
674
- swayX() {
675
- const t = 2 * Math.PI * this.clockMs;
676
- 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);
784
+ if (this.clockMs - this.breathStartMs >= this.breathPeriodMs) {
785
+ this.breathStartMs += this.breathPeriodMs;
786
+ this.breathPeriodMs = this.drawBreathPeriod();
787
+ }
788
+ return breathEnvelope(
789
+ (this.clockMs - this.breathStartMs) / this.breathPeriodMs
790
+ );
677
791
  }
678
- /** Vertical head sway in degrees, pure function of the internal clock. */
679
- swayY() {
680
- return SWAY_Y_AMP_DEG * Math.sin(2 * Math.PI * this.clockMs / SWAY_Y_PERIOD_MS);
792
+ drawBreathPeriod() {
793
+ return lerp(BREATH_PERIOD_MIN_MS, BREATH_PERIOD_MAX_MS, this.rng());
681
794
  }
682
- /** Head roll sway in degrees, pure function of the internal clock. */
683
- swayZ() {
684
- return SWAY_Z_AMP_DEG * Math.sin(2 * Math.PI * this.clockMs / SWAY_Z_PERIOD_MS);
795
+ /**
796
+ * Step each head spring toward its axis noise at the internal clock, plus,
797
+ * on the turn and nod, the gaze target scaled to degrees, and on the nod the
798
+ * breath's lift. Only the noise fades in: the scheduled pick starts at
799
+ * (0, 0), so it has no start value to lurch to, and its first jump is no
800
+ * larger than any later one; the breath starts empty, at 0.
801
+ */
802
+ advanceHead(dt, breath) {
803
+ const seconds = this.clockMs / 1e3;
804
+ const easeIn = smoothstep(this.clockMs / HEAD_NOISE_EASE_IN_MS);
805
+ this.headX.step(
806
+ easeIn * HEAD_NOISE_AMP_X_DEG * fbm(this.headSeedX, seconds * HEAD_NOISE_RATE_X_HZ) + HEAD_FOLLOW_X_DEG * (this.hostGaze?.x ?? this.gazeTargetX),
807
+ dt
808
+ );
809
+ this.headY.step(
810
+ 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,
811
+ dt
812
+ );
813
+ this.headZ.step(
814
+ easeIn * HEAD_NOISE_AMP_Z_DEG * fbm(this.headSeedZ, seconds * HEAD_NOISE_RATE_Z_HZ),
815
+ dt
816
+ );
685
817
  }
686
818
  /** Ambient sway (-1..1), pure function of the internal clock. */
687
819
  ambientSway() {
688
820
  const t = 2 * Math.PI * this.clockMs;
689
821
  return AMBIENT_AMP_A * Math.sin(t / AMBIENT_PERIOD_A_MS) + AMBIENT_AMP_B * Math.sin(t / AMBIENT_PERIOD_B_MS);
690
822
  }
691
- /** Ease gaze current toward target; pick a new target on the internal clock. */
823
+ /**
824
+ * Step the eye springs toward the gaze target, the host's while set, else
825
+ * the scheduled pick; retarget on the internal clock either way.
826
+ */
692
827
  advanceGaze(dt) {
693
828
  if (this.clockMs >= this.nextGazeRetargetMs) {
694
- const [tx, ty] = randomInDisk(this.rng, GAZE_RADIUS);
695
- this.gazeTargetX = tx;
696
- this.gazeTargetY = ty;
829
+ if (this.rng() < GAZE_EYE_CONTACT_P) {
830
+ this.gazeTargetX = 0;
831
+ this.gazeTargetY = 0;
832
+ } else {
833
+ this.gazeTargetX = lerp(-GAZE_X_MAX, GAZE_X_MAX, this.rng());
834
+ this.gazeTargetY = lerp(-GAZE_Y_MAX, GAZE_Y_MAX, this.rng());
835
+ }
697
836
  this.nextGazeRetargetMs = this.clockMs + lerp(GAZE_RETARGET_MIN_MS, GAZE_RETARGET_MAX_MS, this.rng());
698
837
  }
699
- const factor = 1 - Math.pow(1 - GAZE_EASE_RATE, dt);
700
- this.gazeCurrentX = lerp(this.gazeCurrentX, this.gazeTargetX, factor);
701
- this.gazeCurrentY = lerp(this.gazeCurrentY, this.gazeTargetY, factor);
838
+ this.eyeX.step(this.hostGaze?.x ?? this.gazeTargetX, dt);
839
+ this.eyeY.step(this.hostGaze?.y ?? this.gazeTargetY, dt);
702
840
  }
703
841
  };
704
842
 
@@ -1414,7 +1552,8 @@ function stepRun(model, rigs, chains, values) {
1414
1552
  function idleRun(model) {
1415
1553
  const store = new ParameterStore(model.parameters);
1416
1554
  const idle = new IdleMotion((id, v) => store.set(id, v), {
1417
- rng: lcg(IDLE_SEED)
1555
+ rng: lcg(IDLE_SEED),
1556
+ parameters: model.parameters
1418
1557
  });
1419
1558
  return run(
1420
1559
  model,
@@ -7808,7 +7947,7 @@ function formatBakeChecks(bakes) {
7808
7947
  );
7809
7948
  }
7810
7949
  function createIkiMcpServer() {
7811
- const server = new import_mcp.McpServer({ name: "iki", version: "0.37.0" });
7950
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.37.1" });
7812
7951
  server.registerTool(
7813
7952
  "validate_iki",
7814
7953
  {
@@ -7984,7 +8123,7 @@ function createIkiMcpServer() {
7984
8123
  "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."
7985
8124
  )
7986
8125
  }).passthrough().optional().describe(
7987
- "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."
8126
+ "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."
7988
8127
  )
7989
8128
  }).passthrough()
7990
8129
  ).optional().describe(