@ikijs/mcp 0.26.1 → 0.28.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 +4 -3
- package/dist/{chunk-GPEGV2AT.mjs → chunk-D2OLX5S7.mjs} +1014 -66
- package/dist/chunk-D2OLX5S7.mjs.map +1 -0
- package/dist/cli.js +1070 -129
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +91 -1
- package/dist/index.d.ts +91 -1
- package/dist/index.js +1074 -131
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -1
- package/dist/render-page.global.js +9 -1
- package/package.json +4 -4
- package/dist/chunk-GPEGV2AT.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -5,9 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (
|
|
8
|
+
var __export = (target2, all) => {
|
|
9
9
|
for (var name in all)
|
|
10
|
-
__defProp(
|
|
10
|
+
__defProp(target2, name, { get: all[name], enumerable: true });
|
|
11
11
|
};
|
|
12
12
|
var __copyProps = (to, from, except, desc) => {
|
|
13
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -17,12 +17,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode,
|
|
20
|
+
var __toESM = (mod, isNodeMode, target2) => (target2 = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
21
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
22
|
// file that has been converted to a CommonJS file using a Babel-
|
|
23
23
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
24
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target2, "default", { value: mod, enumerable: true }) : target2,
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
@@ -38,6 +38,7 @@ __export(index_exports, {
|
|
|
38
38
|
describeIkiAt: () => describeIkiAt,
|
|
39
39
|
formatFoldReport: () => formatFoldReport,
|
|
40
40
|
formatMeasureReport: () => formatMeasureReport,
|
|
41
|
+
formatPhysicsReport: () => formatPhysicsReport,
|
|
41
42
|
formatTurnReport: () => formatTurnReport,
|
|
42
43
|
listStandardParameters: () => listStandardParameters,
|
|
43
44
|
measureLayers: () => measureLayers,
|
|
@@ -54,12 +55,9 @@ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
|
54
55
|
// src/tools.ts
|
|
55
56
|
var import_node_fs4 = require("fs");
|
|
56
57
|
var import_node_path4 = __toESM(require("path"));
|
|
57
|
-
var
|
|
58
|
+
var import_format9 = require("@ikijs/format");
|
|
58
59
|
var import_editor3 = require("@ikijs/editor");
|
|
59
60
|
|
|
60
|
-
// src/fold-report.ts
|
|
61
|
-
var import_editor = require("@ikijs/editor");
|
|
62
|
-
|
|
63
61
|
// ../engine/src/math.ts
|
|
64
62
|
function clamp(value, min, max) {
|
|
65
63
|
return Math.max(min, Math.min(max, value));
|
|
@@ -67,6 +65,10 @@ function clamp(value, min, max) {
|
|
|
67
65
|
function lerp(a, b, t) {
|
|
68
66
|
return a + (b - a) * t;
|
|
69
67
|
}
|
|
68
|
+
function smoothstep(x) {
|
|
69
|
+
const t = clamp(x, 0, 1);
|
|
70
|
+
return t * t * (3 - 2 * t);
|
|
71
|
+
}
|
|
70
72
|
|
|
71
73
|
// ../engine/src/parameter-store.ts
|
|
72
74
|
var ParameterStore = class {
|
|
@@ -472,54 +474,607 @@ function resolveDeformers(deformers, params) {
|
|
|
472
474
|
var import_format = require("@ikijs/format");
|
|
473
475
|
|
|
474
476
|
// ../engine/src/frame-clock.ts
|
|
477
|
+
var MAX_DT_MS = 100;
|
|
475
478
|
var FIXED_DT_S = 1 / 60;
|
|
479
|
+
var MAX_SUBSTEPS = 6;
|
|
480
|
+
var FixedStepClock = class {
|
|
481
|
+
prevNowMs = void 0;
|
|
482
|
+
accumulatorS = 0;
|
|
483
|
+
/**
|
|
484
|
+
* True until the first {@link advance}. Drivers seed their rest pose on that
|
|
485
|
+
* frame and integrate nothing, so a model loaded mid-motion does not kick.
|
|
486
|
+
*/
|
|
487
|
+
get isSeedFrame() {
|
|
488
|
+
return this.prevNowMs === void 0;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Fold `nowMs` into the accumulator and return how many {@link FIXED_DT_S}
|
|
492
|
+
* sub-steps to run this frame. On the seed frame it only records the
|
|
493
|
+
* timestamp and returns 0. A non-monotonic `nowMs` floors to 0 — no rewind.
|
|
494
|
+
*/
|
|
495
|
+
advance(nowMs) {
|
|
496
|
+
if (!Number.isFinite(nowMs)) return 0;
|
|
497
|
+
if (this.prevNowMs === void 0) {
|
|
498
|
+
this.prevNowMs = nowMs;
|
|
499
|
+
return 0;
|
|
500
|
+
}
|
|
501
|
+
const dtMs = clamp(nowMs - this.prevNowMs, 0, MAX_DT_MS);
|
|
502
|
+
this.prevNowMs = nowMs;
|
|
503
|
+
this.accumulatorS += dtMs / 1e3;
|
|
504
|
+
let steps = 0;
|
|
505
|
+
while (this.accumulatorS >= FIXED_DT_S && steps < MAX_SUBSTEPS) {
|
|
506
|
+
this.accumulatorS -= FIXED_DT_S;
|
|
507
|
+
steps++;
|
|
508
|
+
}
|
|
509
|
+
return steps;
|
|
510
|
+
}
|
|
511
|
+
};
|
|
476
512
|
|
|
477
513
|
// ../engine/src/idle-motion.ts
|
|
514
|
+
var BLINK_INTERVAL_MIN_MS = 1500;
|
|
515
|
+
var BLINK_INTERVAL_MAX_MS = 6e3;
|
|
478
516
|
var BLINK_CLOSE_MS = 60;
|
|
479
517
|
var BLINK_HOLD_MS = 20;
|
|
480
518
|
var BLINK_OPEN_MS = 100;
|
|
481
519
|
var BLINK_DURATION_MS = BLINK_CLOSE_MS + BLINK_HOLD_MS + BLINK_OPEN_MS;
|
|
520
|
+
var BREATH_PERIOD_MS = 3500;
|
|
521
|
+
var GAZE_RADIUS = 0.3;
|
|
522
|
+
var GAZE_RETARGET_MIN_MS = 1200;
|
|
523
|
+
var GAZE_RETARGET_MAX_MS = 3e3;
|
|
524
|
+
var GAZE_EASE_RATE = 1e-3;
|
|
525
|
+
var SWAY_X_AMP_A_DEG = 2.2;
|
|
526
|
+
var SWAY_X_PERIOD_A_MS = 6100;
|
|
527
|
+
var SWAY_X_AMP_B_DEG = 1.3;
|
|
528
|
+
var SWAY_X_PERIOD_B_MS = 9700;
|
|
529
|
+
var SWAY_Y_AMP_DEG = 1.6;
|
|
530
|
+
var SWAY_Y_PERIOD_MS = 7300;
|
|
531
|
+
var SWAY_Z_AMP_DEG = 1.1;
|
|
532
|
+
var SWAY_Z_PERIOD_MS = 11300;
|
|
533
|
+
var AMBIENT_AMP_A = 0.6;
|
|
534
|
+
var AMBIENT_PERIOD_A_MS = 2900;
|
|
535
|
+
var AMBIENT_AMP_B = 0.4;
|
|
536
|
+
var AMBIENT_PERIOD_B_MS = 4300;
|
|
537
|
+
function blinkEnvelope(phase) {
|
|
538
|
+
const ms = phase * BLINK_DURATION_MS;
|
|
539
|
+
if (ms <= 0) return 1;
|
|
540
|
+
if (ms < BLINK_CLOSE_MS) return 1 - smoothstep(ms / BLINK_CLOSE_MS);
|
|
541
|
+
if (ms <= BLINK_CLOSE_MS + BLINK_HOLD_MS) return 0;
|
|
542
|
+
if (ms < BLINK_DURATION_MS) {
|
|
543
|
+
const t = (ms - BLINK_CLOSE_MS - BLINK_HOLD_MS) / BLINK_OPEN_MS;
|
|
544
|
+
return 1 - (1 - t) * (1 - t);
|
|
545
|
+
}
|
|
546
|
+
return 1;
|
|
547
|
+
}
|
|
548
|
+
function randomInDisk(rng, radius) {
|
|
549
|
+
const r = Math.sqrt(rng()) * radius;
|
|
550
|
+
const theta = rng() * 2 * Math.PI;
|
|
551
|
+
return [r * Math.cos(theta), r * Math.sin(theta)];
|
|
552
|
+
}
|
|
553
|
+
var IdleMotion = class {
|
|
554
|
+
/**
|
|
555
|
+
* Every parameter id {@link update} and `emitRestingPose` write, in write
|
|
556
|
+
* order. Published so a host (or IkiMotion) can restore them after it
|
|
557
|
+
* stops driving — keep in step with those two methods; the test suite
|
|
558
|
+
* pins this list to the actual emissions.
|
|
559
|
+
*/
|
|
560
|
+
drivenParameterIds = [
|
|
561
|
+
import_format.StandardParameter.EyeOpenLeft,
|
|
562
|
+
import_format.StandardParameter.EyeOpenRight,
|
|
563
|
+
import_format.StandardParameter.Breath,
|
|
564
|
+
import_format.StandardParameter.EyeballX,
|
|
565
|
+
import_format.StandardParameter.EyeballY,
|
|
566
|
+
import_format.StandardParameter.AngleX,
|
|
567
|
+
import_format.StandardParameter.AngleY,
|
|
568
|
+
import_format.StandardParameter.AngleZ,
|
|
569
|
+
import_format.StandardParameter.AmbientSway
|
|
570
|
+
];
|
|
571
|
+
sink;
|
|
572
|
+
rng;
|
|
573
|
+
// Internal clock: advances by clamped dt, NOT by raw wall-clock jumps.
|
|
574
|
+
// This is the only clock blink/breath/gaze scheduling reads.
|
|
575
|
+
clockMs = 0;
|
|
576
|
+
prevNowMs = void 0;
|
|
577
|
+
// Blink state
|
|
578
|
+
nextBlinkAtMs;
|
|
579
|
+
blinkStartMs = -1;
|
|
580
|
+
// -1 means not currently blinking
|
|
581
|
+
// Gaze state
|
|
582
|
+
gazeCurrentX = 0;
|
|
583
|
+
gazeCurrentY = 0;
|
|
584
|
+
gazeTargetX = 0;
|
|
585
|
+
gazeTargetY = 0;
|
|
586
|
+
nextGazeRetargetMs;
|
|
587
|
+
constructor(sink, options) {
|
|
588
|
+
this.sink = sink;
|
|
589
|
+
this.rng = options?.rng ?? Math.random;
|
|
590
|
+
this.nextBlinkAtMs = lerp(
|
|
591
|
+
BLINK_INTERVAL_MIN_MS,
|
|
592
|
+
BLINK_INTERVAL_MAX_MS,
|
|
593
|
+
this.rng()
|
|
594
|
+
);
|
|
595
|
+
this.nextGazeRetargetMs = lerp(
|
|
596
|
+
GAZE_RETARGET_MIN_MS,
|
|
597
|
+
GAZE_RETARGET_MAX_MS,
|
|
598
|
+
this.rng()
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Advance the idle animation to the given wall-clock timestamp (milliseconds).
|
|
603
|
+
*
|
|
604
|
+
* On the first call: record prevNowMs, emit the resting pose, and return —
|
|
605
|
+
* no animation advance happens so there is no jump from time 0.
|
|
606
|
+
*
|
|
607
|
+
* On subsequent calls: compute dt = clamp(nowMs - prevNowMs, 0, MAX_DT_MS)
|
|
608
|
+
* and advance the internal clock by dt. A non-monotonic nowMs produces a
|
|
609
|
+
* negative raw delta that the clamp floors to 0 — no rewind.
|
|
610
|
+
*/
|
|
611
|
+
update(nowMs) {
|
|
612
|
+
if (!Number.isFinite(nowMs)) return;
|
|
613
|
+
if (this.prevNowMs === void 0) {
|
|
614
|
+
this.prevNowMs = nowMs;
|
|
615
|
+
this.emitRestingPose();
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
const rawDt = nowMs - this.prevNowMs;
|
|
619
|
+
const dt = clamp(rawDt, 0, MAX_DT_MS);
|
|
620
|
+
this.prevNowMs = nowMs;
|
|
621
|
+
this.clockMs += dt;
|
|
622
|
+
const eyeVal = this.advanceBlink();
|
|
623
|
+
this.sink(import_format.StandardParameter.EyeOpenLeft, eyeVal);
|
|
624
|
+
this.sink(import_format.StandardParameter.EyeOpenRight, eyeVal);
|
|
625
|
+
const breath = this.advanceBreath();
|
|
626
|
+
this.advanceGaze(dt);
|
|
627
|
+
this.sink(import_format.StandardParameter.Breath, breath);
|
|
628
|
+
this.sink(import_format.StandardParameter.EyeballX, this.gazeCurrentX);
|
|
629
|
+
this.sink(import_format.StandardParameter.EyeballY, this.gazeCurrentY);
|
|
630
|
+
this.sink(import_format.StandardParameter.AngleX, this.swayX());
|
|
631
|
+
this.sink(import_format.StandardParameter.AngleY, this.swayY());
|
|
632
|
+
this.sink(import_format.StandardParameter.AngleZ, this.swayZ());
|
|
633
|
+
this.sink(import_format.StandardParameter.AmbientSway, this.ambientSway());
|
|
634
|
+
}
|
|
635
|
+
// ---------------------------------------------------------------------------
|
|
636
|
+
// Private helpers
|
|
637
|
+
// ---------------------------------------------------------------------------
|
|
638
|
+
emitRestingPose() {
|
|
639
|
+
this.sink(import_format.StandardParameter.EyeOpenLeft, 1);
|
|
640
|
+
this.sink(import_format.StandardParameter.EyeOpenRight, 1);
|
|
641
|
+
this.sink(import_format.StandardParameter.Breath, 0.5);
|
|
642
|
+
this.sink(import_format.StandardParameter.EyeballX, 0);
|
|
643
|
+
this.sink(import_format.StandardParameter.EyeballY, 0);
|
|
644
|
+
this.sink(import_format.StandardParameter.AngleX, 0);
|
|
645
|
+
this.sink(import_format.StandardParameter.AngleY, 0);
|
|
646
|
+
this.sink(import_format.StandardParameter.AngleZ, 0);
|
|
647
|
+
this.sink(import_format.StandardParameter.AmbientSway, 0);
|
|
648
|
+
}
|
|
649
|
+
/** Returns the current eye-open value (0..1) and advances blink state. */
|
|
650
|
+
advanceBlink() {
|
|
651
|
+
const { clockMs } = this;
|
|
652
|
+
if (this.blinkStartMs >= 0) {
|
|
653
|
+
const phase = (clockMs - this.blinkStartMs) / BLINK_DURATION_MS;
|
|
654
|
+
if (phase >= 1) {
|
|
655
|
+
this.blinkStartMs = -1;
|
|
656
|
+
this.nextBlinkAtMs = clockMs + lerp(BLINK_INTERVAL_MIN_MS, BLINK_INTERVAL_MAX_MS, this.rng());
|
|
657
|
+
return 1;
|
|
658
|
+
}
|
|
659
|
+
return blinkEnvelope(phase);
|
|
660
|
+
}
|
|
661
|
+
if (clockMs >= this.nextBlinkAtMs) {
|
|
662
|
+
this.blinkStartMs = clockMs;
|
|
663
|
+
return blinkEnvelope(0);
|
|
664
|
+
}
|
|
665
|
+
return 1;
|
|
666
|
+
}
|
|
667
|
+
advanceBreath() {
|
|
668
|
+
return 0.5 + 0.5 * Math.sin(2 * Math.PI * this.clockMs / BREATH_PERIOD_MS);
|
|
669
|
+
}
|
|
670
|
+
/** Horizontal head sway in degrees, pure function of the internal clock. */
|
|
671
|
+
swayX() {
|
|
672
|
+
const t = 2 * Math.PI * this.clockMs;
|
|
673
|
+
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);
|
|
674
|
+
}
|
|
675
|
+
/** Vertical head sway in degrees, pure function of the internal clock. */
|
|
676
|
+
swayY() {
|
|
677
|
+
return SWAY_Y_AMP_DEG * Math.sin(2 * Math.PI * this.clockMs / SWAY_Y_PERIOD_MS);
|
|
678
|
+
}
|
|
679
|
+
/** Head roll sway in degrees, pure function of the internal clock. */
|
|
680
|
+
swayZ() {
|
|
681
|
+
return SWAY_Z_AMP_DEG * Math.sin(2 * Math.PI * this.clockMs / SWAY_Z_PERIOD_MS);
|
|
682
|
+
}
|
|
683
|
+
/** Ambient sway (-1..1), pure function of the internal clock. */
|
|
684
|
+
ambientSway() {
|
|
685
|
+
const t = 2 * Math.PI * this.clockMs;
|
|
686
|
+
return AMBIENT_AMP_A * Math.sin(t / AMBIENT_PERIOD_A_MS) + AMBIENT_AMP_B * Math.sin(t / AMBIENT_PERIOD_B_MS);
|
|
687
|
+
}
|
|
688
|
+
/** Ease gaze current toward target; pick a new target on the internal clock. */
|
|
689
|
+
advanceGaze(dt) {
|
|
690
|
+
if (this.clockMs >= this.nextGazeRetargetMs) {
|
|
691
|
+
const [tx, ty] = randomInDisk(this.rng, GAZE_RADIUS);
|
|
692
|
+
this.gazeTargetX = tx;
|
|
693
|
+
this.gazeTargetY = ty;
|
|
694
|
+
this.nextGazeRetargetMs = this.clockMs + lerp(GAZE_RETARGET_MIN_MS, GAZE_RETARGET_MAX_MS, this.rng());
|
|
695
|
+
}
|
|
696
|
+
const factor = 1 - Math.pow(1 - GAZE_EASE_RATE, dt);
|
|
697
|
+
this.gazeCurrentX = lerp(this.gazeCurrentX, this.gazeTargetX, factor);
|
|
698
|
+
this.gazeCurrentY = lerp(this.gazeCurrentY, this.gazeTargetY, factor);
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
// ../engine/src/physics-motion.ts
|
|
703
|
+
var import_format2 = require("@ikijs/format");
|
|
704
|
+
function signedNormalized(value, param) {
|
|
705
|
+
const rest = clamp(param.default, param.min, param.max);
|
|
706
|
+
const den = Math.max(Math.abs(param.max - rest), Math.abs(rest - param.min));
|
|
707
|
+
if (den === 0) return 0;
|
|
708
|
+
return clamp((value - rest) / den, -1, 1);
|
|
709
|
+
}
|
|
710
|
+
var PhysicsMotion = class {
|
|
711
|
+
/** The output parameter of every rig, in rig order — what `emit` writes. */
|
|
712
|
+
drivenParameterIds;
|
|
713
|
+
/**
|
|
714
|
+
* Per rig: how many times the finiteness guard reset its state or `emit`
|
|
715
|
+
* replaced its non-finite product. Up to two per frame, so guard activations,
|
|
716
|
+
* not repaired frames. A diagnostic; emitted values are unchanged.
|
|
717
|
+
*/
|
|
718
|
+
resets;
|
|
719
|
+
resetCounts;
|
|
720
|
+
rigs;
|
|
721
|
+
inputs;
|
|
722
|
+
read;
|
|
723
|
+
sink;
|
|
724
|
+
params;
|
|
725
|
+
// Integrator state, owned here — never stored in a ParameterStore.
|
|
726
|
+
state;
|
|
727
|
+
clock = new FixedStepClock();
|
|
728
|
+
constructor(rigs, params, read, sink) {
|
|
729
|
+
this.rigs = rigs;
|
|
730
|
+
this.inputs = rigs.map(
|
|
731
|
+
(rig) => (0, import_format2.physicsInputs)(rig).map(({ parameter, weight, mode }) => ({
|
|
732
|
+
parameter,
|
|
733
|
+
weight,
|
|
734
|
+
lag: mode === "lag"
|
|
735
|
+
}))
|
|
736
|
+
);
|
|
737
|
+
this.read = read;
|
|
738
|
+
this.sink = sink;
|
|
739
|
+
this.params = new Map(params.map((p) => [p.id, p]));
|
|
740
|
+
this.state = rigs.map(() => ({ x: 0, v: 0, lag: 0 }));
|
|
741
|
+
this.drivenParameterIds = rigs.map((rig) => rig.output.parameter);
|
|
742
|
+
this.resetCounts = rigs.map(() => 0);
|
|
743
|
+
this.resets = this.resetCounts;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Advance every rig to the given wall-clock timestamp (milliseconds).
|
|
747
|
+
*
|
|
748
|
+
* First call: seed each spring to rest AT its current target (so a model
|
|
749
|
+
* loaded with a nonzero input does not kick: a lag input emits rest, a follow
|
|
750
|
+
* input its value), emit that output, and return without integrating —
|
|
751
|
+
* mirroring IdleMotion's first-frame behavior.
|
|
752
|
+
*
|
|
753
|
+
* A non-finite `nowMs` after that is a dropped frame: every rig re-emits its
|
|
754
|
+
* last output from its stored state without reading its inputs.
|
|
755
|
+
*
|
|
756
|
+
* Subsequent calls: {@link FixedStepClock} folds the clamped frame delta into
|
|
757
|
+
* its accumulator and returns how many {@link FIXED_DT_S} sub-steps are due;
|
|
758
|
+
* the spring advances that many semi-implicit Euler steps, then each rig emits
|
|
759
|
+
* its output once. The clock's dt clamp and sub-step cap plus the symplectic
|
|
760
|
+
* integrator are what keep it stable across hitches.
|
|
761
|
+
*/
|
|
762
|
+
update(nowMs) {
|
|
763
|
+
if (this.clock.isSeedFrame) {
|
|
764
|
+
this.clock.advance(nowMs);
|
|
765
|
+
for (let i = 0; i < this.rigs.length; i++) {
|
|
766
|
+
const st = this.state[i];
|
|
767
|
+
const { target: target2, lag } = this.targetFor(i);
|
|
768
|
+
st.x = target2;
|
|
769
|
+
st.v = 0;
|
|
770
|
+
st.lag = lag;
|
|
771
|
+
this.emit(i, st);
|
|
772
|
+
}
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
if (!Number.isFinite(nowMs)) {
|
|
776
|
+
for (let i = 0; i < this.rigs.length; i++) this.emit(i, this.state[i]);
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
const steps = this.clock.advance(nowMs);
|
|
780
|
+
const targets = this.rigs.map((_, i) => this.targetFor(i));
|
|
781
|
+
for (let s = 0; s < steps; s++) {
|
|
782
|
+
for (let i = 0; i < this.rigs.length; i++) {
|
|
783
|
+
this.step(this.rigs[i], this.state[i], targets[i].target);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
for (let i = 0; i < this.rigs.length; i++) {
|
|
787
|
+
const st = this.state[i];
|
|
788
|
+
const { target: target2, lag } = targets[i];
|
|
789
|
+
if (!Number.isFinite(st.x) || !Number.isFinite(st.v)) {
|
|
790
|
+
st.x = Number.isFinite(target2) ? target2 : 0;
|
|
791
|
+
st.v = 0;
|
|
792
|
+
this.resetCounts[i]++;
|
|
793
|
+
}
|
|
794
|
+
st.lag = lag;
|
|
795
|
+
this.emit(i, st);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Rig `index`'s spring target `T` = Σ signed-normalized input value × weight,
|
|
800
|
+
* and `L`, the lag inputs' share of it. Reads each input once.
|
|
801
|
+
*/
|
|
802
|
+
targetFor(index) {
|
|
803
|
+
let target2 = 0;
|
|
804
|
+
let lag = 0;
|
|
805
|
+
for (const input of this.inputs[index]) {
|
|
806
|
+
const param = this.params.get(input.parameter);
|
|
807
|
+
const value = this.read(input.parameter);
|
|
808
|
+
const share = (param ? signedNormalized(value, param) : 0) * input.weight;
|
|
809
|
+
target2 += share;
|
|
810
|
+
if (input.lag) lag += share;
|
|
811
|
+
}
|
|
812
|
+
return { target: target2, lag };
|
|
813
|
+
}
|
|
814
|
+
/** One semi-implicit (symplectic) Euler sub-step of FIXED_DT_S seconds. */
|
|
815
|
+
step(rig, st, target2) {
|
|
816
|
+
const accel = (rig.stiffness * (target2 - st.x) - rig.damping * st.v) / rig.mass;
|
|
817
|
+
st.v += accel * FIXED_DT_S;
|
|
818
|
+
st.x += st.v * FIXED_DT_S;
|
|
819
|
+
}
|
|
820
|
+
/** Write outputDefault + (x − L) * scale onto the output param via the sink. */
|
|
821
|
+
emit(index, st) {
|
|
822
|
+
const rig = this.rigs[index];
|
|
823
|
+
const outParam = this.params.get(rig.output.parameter);
|
|
824
|
+
const outDefault = outParam ? clamp(outParam.default, outParam.min, outParam.max) : 0;
|
|
825
|
+
const value = outDefault + (st.x - st.lag) * rig.output.scale;
|
|
826
|
+
const finite = Number.isFinite(value);
|
|
827
|
+
if (!finite) this.resetCounts[index]++;
|
|
828
|
+
this.sink(rig.output.parameter, finite ? value : outDefault);
|
|
829
|
+
}
|
|
830
|
+
};
|
|
482
831
|
|
|
483
832
|
// ../engine/src/hair-chain-motion.ts
|
|
484
833
|
var DEG2RAD = Math.PI / 180;
|
|
485
834
|
var RAD2DEG = 180 / Math.PI;
|
|
835
|
+
var HairChainMotion = class {
|
|
836
|
+
/** Every segment's output, chain by chain — what `emitSegment` writes. */
|
|
837
|
+
drivenParameterIds;
|
|
838
|
+
/**
|
|
839
|
+
* Per segment, in `drivenParameterIds` order: how many times the finiteness
|
|
840
|
+
* guard reset its state or `emitSegment` replaced its non-finite product. Up
|
|
841
|
+
* to two per frame, so guard activations, not repaired frames. A diagnostic;
|
|
842
|
+
* emitted values are unchanged.
|
|
843
|
+
*/
|
|
844
|
+
resets;
|
|
845
|
+
resetCounts;
|
|
846
|
+
chainData;
|
|
847
|
+
params;
|
|
848
|
+
deformers;
|
|
849
|
+
store;
|
|
850
|
+
read;
|
|
851
|
+
sink;
|
|
852
|
+
clock = new FixedStepClock();
|
|
853
|
+
constructor(chains, params, deformers, read, sink) {
|
|
854
|
+
this.params = new Map(params.map((p) => [p.id, p]));
|
|
855
|
+
this.deformers = deformers;
|
|
856
|
+
this.store = new ParameterStore(params);
|
|
857
|
+
this.read = read;
|
|
858
|
+
this.sink = sink;
|
|
859
|
+
this.chainData = chains.map((chain) => ({
|
|
860
|
+
chain,
|
|
861
|
+
restAnglesRad: chain.segments.map(
|
|
862
|
+
(seg) => seg.restAngle !== void 0 ? seg.restAngle * DEG2RAD : 0
|
|
863
|
+
),
|
|
864
|
+
state: chain.segments.map(() => ({ angle: 0, angularVelocity: 0 }))
|
|
865
|
+
}));
|
|
866
|
+
this.drivenParameterIds = chains.flatMap(
|
|
867
|
+
(c) => c.segments.map((s) => s.output.parameter)
|
|
868
|
+
);
|
|
869
|
+
this.resetCounts = this.drivenParameterIds.map(() => 0);
|
|
870
|
+
this.resets = this.resetCounts;
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Advance every chain to the given wall-clock timestamp (milliseconds).
|
|
874
|
+
*
|
|
875
|
+
* First call: seed every segment to θ=0/ω=0 (rest), emit the rest output
|
|
876
|
+
* (outDefault + 0), and return without integrating — mirrors PhysicsMotion's
|
|
877
|
+
* first-frame behavior so a model loaded in motion does not kick.
|
|
878
|
+
*
|
|
879
|
+
* Subsequent calls: dt = clamp(nowMs - prevNowMs, 0, MAX_DT_MS) → seconds into
|
|
880
|
+
* accumulator. The per-frame world snapshot (anchor world angles) is taken ONCE
|
|
881
|
+
* per update() — NOT per chain — so all chains share a consistent frame snapshot.
|
|
882
|
+
* Fixed FIXED_DT_S sub-steps are run root→tip, capped at MAX_SUBSTEPS; leftover
|
|
883
|
+
* time is carried to the next frame. Segments emit after substeps (even on zero
|
|
884
|
+
* substeps) with a non-finite guard.
|
|
885
|
+
*/
|
|
886
|
+
update(nowMs) {
|
|
887
|
+
if (this.chainData.length === 0) return;
|
|
888
|
+
if (this.clock.isSeedFrame) {
|
|
889
|
+
this.clock.advance(nowMs);
|
|
890
|
+
let flat2 = 0;
|
|
891
|
+
for (const cd of this.chainData) {
|
|
892
|
+
for (let i = 0; i < cd.chain.segments.length; i++) {
|
|
893
|
+
cd.state[i].angle = 0;
|
|
894
|
+
cd.state[i].angularVelocity = 0;
|
|
895
|
+
this.emitSegment(flat2++, cd.chain.segments[i], cd.state[i]);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
return;
|
|
899
|
+
}
|
|
900
|
+
const steps = this.clock.advance(nowMs);
|
|
901
|
+
for (const param of this.params.values()) {
|
|
902
|
+
this.store.set(param.id, this.read(param.id));
|
|
903
|
+
}
|
|
904
|
+
const worldMap = resolveDeformers(this.deformers, this.store).worlds;
|
|
905
|
+
const anchorAnglesRad = this.chainData.map(
|
|
906
|
+
(cd) => this.anchorWorldAngleRad(worldMap, cd.chain.anchorDeformer)
|
|
907
|
+
);
|
|
908
|
+
for (let s = 0; s < steps; s++) {
|
|
909
|
+
for (let c = 0; c < this.chainData.length; c++) {
|
|
910
|
+
this.stepChain(this.chainData[c], anchorAnglesRad[c]);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
let flat = 0;
|
|
914
|
+
for (const cd of this.chainData) {
|
|
915
|
+
for (let i = 0; i < cd.chain.segments.length; i++) {
|
|
916
|
+
const st = cd.state[i];
|
|
917
|
+
if (!Number.isFinite(st.angle) || !Number.isFinite(st.angularVelocity)) {
|
|
918
|
+
st.angle = 0;
|
|
919
|
+
st.angularVelocity = 0;
|
|
920
|
+
this.resetCounts[flat]++;
|
|
921
|
+
}
|
|
922
|
+
this.emitSegment(flat++, cd.chain.segments[i], st);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* Extract world rotation (radians) from the anchor's Affine tuple.
|
|
928
|
+
* Affine = [a,b,c,d,e,f]; rotation column = (a,b) → atan2(b,a).
|
|
929
|
+
*
|
|
930
|
+
* If the anchor id is absent from the map, THROWS an internal Error — the
|
|
931
|
+
* format validator guarantees the anchor exists, so absence is an invariant
|
|
932
|
+
* break (mirrors resolveDeformers' throw on an unresolved parent).
|
|
933
|
+
*/
|
|
934
|
+
anchorWorldAngleRad(worldMap, anchorId) {
|
|
935
|
+
const world = worldMap.get(anchorId);
|
|
936
|
+
if (!world) {
|
|
937
|
+
throw new Error(
|
|
938
|
+
`HairChainMotion: anchor deformer "${anchorId}" not found in resolved world map \u2014 model not validated?`
|
|
939
|
+
);
|
|
940
|
+
}
|
|
941
|
+
return Math.atan2(world[1], world[0]);
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* One fixed sub-step of FIXED_DT_S seconds for all segments in a chain.
|
|
945
|
+
*
|
|
946
|
+
* Segments are integrated ROOT→TIP so each segment can read its upstream
|
|
947
|
+
* neighbor's current-substep state when computing the world angle Φ_i.
|
|
948
|
+
* (The chain is causal root-to-tip; reversing the order would use stale θ
|
|
949
|
+
* values from the previous substep for Φ_i computation.)
|
|
950
|
+
*
|
|
951
|
+
* Per-segment semi-implicit (symplectic) Euler:
|
|
952
|
+
* Φ_i = anchorWorldAngleRad + Σ_{j≤i}(restAngle_j + θ_j)
|
|
953
|
+
* α_i = (−stiffness_i·θ_i − strength·sin(Φ_i − gravityAngle_rad) − damping_i·ω_i) / mass_i
|
|
954
|
+
* ω_i += α_i · FIXED_DT_S (velocity updated FIRST = semi-implicit)
|
|
955
|
+
* θ_i += ω_i · FIXED_DT_S (position updated from NEW velocity)
|
|
956
|
+
*
|
|
957
|
+
* The spring term is −stiffness·θ (restoring θ→0); restAngle does NOT appear
|
|
958
|
+
* in the spring term, only in Φ_i for the gravity torque.
|
|
959
|
+
*/
|
|
960
|
+
stepChain(cd, anchorAngleRad) {
|
|
961
|
+
const { chain, restAnglesRad, state } = cd;
|
|
962
|
+
const gravityAngleRad = chain.gravity.angle * DEG2RAD;
|
|
963
|
+
const strength = chain.gravity.strength;
|
|
964
|
+
let worldAngleAccumRad = anchorAngleRad;
|
|
965
|
+
for (let i = 0; i < chain.segments.length; i++) {
|
|
966
|
+
const seg = chain.segments[i];
|
|
967
|
+
const st = state[i];
|
|
968
|
+
worldAngleAccumRad += restAnglesRad[i] + st.angle;
|
|
969
|
+
const phi = worldAngleAccumRad;
|
|
970
|
+
const alpha = (-seg.stiffness * st.angle - strength * Math.sin(phi - gravityAngleRad) - seg.damping * st.angularVelocity) / seg.mass;
|
|
971
|
+
st.angularVelocity += alpha * FIXED_DT_S;
|
|
972
|
+
st.angle += st.angularVelocity * FIXED_DT_S;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
/** Emit outDefault + (θ_i · RAD2DEG) · scale for one segment. */
|
|
976
|
+
emitSegment(flat, seg, st) {
|
|
977
|
+
const outParam = this.params.get(seg.output.parameter);
|
|
978
|
+
const outDefault = outParam ? clamp(outParam.default, outParam.min, outParam.max) : 0;
|
|
979
|
+
const value = outDefault + st.angle * RAD2DEG * seg.output.scale;
|
|
980
|
+
const finite = Number.isFinite(value);
|
|
981
|
+
if (!finite) this.resetCounts[flat]++;
|
|
982
|
+
this.sink(seg.output.parameter, finite ? value : outDefault);
|
|
983
|
+
}
|
|
984
|
+
};
|
|
486
985
|
|
|
487
986
|
// ../engine/src/iki-motion.ts
|
|
488
|
-
var
|
|
987
|
+
var import_format5 = require("@ikijs/format");
|
|
489
988
|
|
|
490
989
|
// ../engine/src/clip-player.ts
|
|
491
|
-
var
|
|
990
|
+
var import_format3 = require("@ikijs/format");
|
|
492
991
|
|
|
493
992
|
// ../engine/src/expression-player.ts
|
|
494
|
-
var
|
|
993
|
+
var import_format4 = require("@ikijs/format");
|
|
495
994
|
|
|
496
995
|
// ../engine/src/iki-motion.ts
|
|
497
996
|
var HEAD_AND_GAZE = /* @__PURE__ */ new Set([
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
997
|
+
import_format5.StandardParameter.AngleX,
|
|
998
|
+
import_format5.StandardParameter.AngleY,
|
|
999
|
+
import_format5.StandardParameter.AngleZ,
|
|
1000
|
+
import_format5.StandardParameter.EyeballX,
|
|
1001
|
+
import_format5.StandardParameter.EyeballY
|
|
503
1002
|
]);
|
|
504
1003
|
|
|
505
1004
|
// ../engine/src/folds.ts
|
|
506
|
-
var
|
|
1005
|
+
var import_format6 = require("@ikijs/format");
|
|
1006
|
+
|
|
1007
|
+
// ../engine/src/land.ts
|
|
1008
|
+
function staticDeformers(model) {
|
|
1009
|
+
return (model.deformers ?? []).map(
|
|
1010
|
+
(d) => d.kind === "warp" ? { ...d, warps: void 0, warp2d: void 0 } : { ...d, bindings: void 0 }
|
|
1011
|
+
);
|
|
1012
|
+
}
|
|
1013
|
+
function placement(part, t) {
|
|
1014
|
+
return multiply(
|
|
1015
|
+
multiply(translate(t.x, t.y), rotate(t.rotation)),
|
|
1016
|
+
scale(part.width * t.scaleX, part.height * t.scaleY)
|
|
1017
|
+
);
|
|
1018
|
+
}
|
|
1019
|
+
function landedPart(part, vertices, deformers, worlds, store) {
|
|
1020
|
+
const warpDeformer = deformers.find(
|
|
1021
|
+
(d) => d.kind === "warp" && d.id === part.deformer
|
|
1022
|
+
);
|
|
1023
|
+
const frame = warpDeformer ? warpDeformer.parent : part.deformer;
|
|
1024
|
+
const placed = placement(
|
|
1025
|
+
part,
|
|
1026
|
+
evaluateTransform(part.transform, void 0, store)
|
|
1027
|
+
);
|
|
1028
|
+
const restPoints = transformGridPoints(
|
|
1029
|
+
vertices,
|
|
1030
|
+
frame === void 0 ? placed : multiply(worlds.get(frame), placed),
|
|
1031
|
+
new Float64Array(vertices.length)
|
|
1032
|
+
);
|
|
1033
|
+
return {
|
|
1034
|
+
part,
|
|
1035
|
+
warpDeformer,
|
|
1036
|
+
vertices: Float32Array.from(vertices),
|
|
1037
|
+
local: new Float32Array(vertices.length),
|
|
1038
|
+
landed: new Float32Array(vertices.length),
|
|
1039
|
+
restPoints
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
function landPart(landing, store, { worlds, grids }) {
|
|
1043
|
+
const { part, warpDeformer, local, landed } = landing;
|
|
1044
|
+
applyWarps(landing.vertices, part.warps, store, local);
|
|
1045
|
+
const placed = placement(
|
|
1046
|
+
part,
|
|
1047
|
+
evaluateTransform(part.transform, part.bindings, store)
|
|
1048
|
+
);
|
|
1049
|
+
if (warpDeformer) {
|
|
1050
|
+
const grid = grids.get(warpDeformer.id);
|
|
1051
|
+
applyWarpToChild(local, placed, warpDeformer.grid, grid, landed);
|
|
1052
|
+
} else if (part.deformer !== void 0) {
|
|
1053
|
+
const world = worlds.get(part.deformer);
|
|
1054
|
+
transformGridPoints(local, multiply(world, placed), landed);
|
|
1055
|
+
} else {
|
|
1056
|
+
transformGridPoints(local, placed, landed);
|
|
1057
|
+
}
|
|
1058
|
+
return landed;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
// ../engine/src/folds.ts
|
|
507
1062
|
var FLIP = 0;
|
|
508
1063
|
var COLLAPSE = 0.1;
|
|
509
1064
|
var ANGLES = [
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
1065
|
+
import_format6.StandardParameter.AngleX,
|
|
1066
|
+
import_format6.StandardParameter.AngleY,
|
|
1067
|
+
import_format6.StandardParameter.AngleZ,
|
|
1068
|
+
import_format6.StandardParameter.BodyAngleX,
|
|
1069
|
+
import_format6.StandardParameter.BodyAngleY,
|
|
1070
|
+
import_format6.StandardParameter.BodyAngleZ
|
|
516
1071
|
];
|
|
517
1072
|
var CROSSES = [
|
|
518
|
-
[
|
|
519
|
-
[
|
|
520
|
-
[
|
|
521
|
-
[
|
|
522
|
-
[
|
|
1073
|
+
[import_format6.StandardParameter.EyeOpenLeft],
|
|
1074
|
+
[import_format6.StandardParameter.EyeOpenRight],
|
|
1075
|
+
[import_format6.StandardParameter.MouthOpen],
|
|
1076
|
+
[import_format6.StandardParameter.ArmLeft, import_format6.StandardParameter.ArmRight],
|
|
1077
|
+
[import_format6.StandardParameter.ElbowLeft, import_format6.StandardParameter.ElbowRight]
|
|
523
1078
|
];
|
|
524
1079
|
function foldPoses(model) {
|
|
525
1080
|
const byId = new Map(
|
|
@@ -567,11 +1122,6 @@ function poseName(values) {
|
|
|
567
1122
|
if (ids.length === 0) return "rest";
|
|
568
1123
|
return ids.map((id) => `${id}=${values[id]}`).join(" ");
|
|
569
1124
|
}
|
|
570
|
-
function staticDeformers(model) {
|
|
571
|
-
return (model.deformers ?? []).map(
|
|
572
|
-
(d) => d.kind === "warp" ? { ...d, warps: void 0, warp2d: void 0 } : { ...d, bindings: void 0 }
|
|
573
|
-
);
|
|
574
|
-
}
|
|
575
1125
|
function cornerAreas(points, cols, rows) {
|
|
576
1126
|
const stride = cols + 1;
|
|
577
1127
|
const out = new Float64Array(cols * rows * 4);
|
|
@@ -603,12 +1153,6 @@ function triangleAreas(points, indices) {
|
|
|
603
1153
|
}
|
|
604
1154
|
return out;
|
|
605
1155
|
}
|
|
606
|
-
function placement(part, t) {
|
|
607
|
-
return multiply(
|
|
608
|
-
multiply(translate(t.x, t.y), rotate(t.rotation)),
|
|
609
|
-
scale(part.width * t.scaleX, part.height * t.scaleY)
|
|
610
|
-
);
|
|
611
|
-
}
|
|
612
1156
|
function keepLeast(sweep, areas, pose, expected) {
|
|
613
1157
|
const slot = expected(sweep.target) ? "expected" : "worst";
|
|
614
1158
|
for (let i = 0; i < areas.length; i++) {
|
|
@@ -621,50 +1165,15 @@ function keepLeast(sweep, areas, pose, expected) {
|
|
|
621
1165
|
}
|
|
622
1166
|
}
|
|
623
1167
|
function partSweep(part, mesh, deformers, worlds, store) {
|
|
624
|
-
const
|
|
625
|
-
(d) => d.kind === "warp" && d.id === part.deformer
|
|
626
|
-
);
|
|
627
|
-
const frame = warpDeformer ? warpDeformer.parent : part.deformer;
|
|
628
|
-
const placed = placement(
|
|
629
|
-
part,
|
|
630
|
-
evaluateTransform(part.transform, void 0, store)
|
|
631
|
-
);
|
|
632
|
-
const restPoints = transformGridPoints(
|
|
633
|
-
mesh.vertices,
|
|
634
|
-
frame === void 0 ? placed : multiply(worlds.get(frame), placed),
|
|
635
|
-
new Float64Array(mesh.vertices.length)
|
|
636
|
-
);
|
|
1168
|
+
const landing = landedPart(part, mesh.vertices, deformers, worlds, store);
|
|
637
1169
|
return {
|
|
1170
|
+
...landing,
|
|
638
1171
|
target: { kind: "part", id: part.id },
|
|
639
|
-
restAreas: triangleAreas(restPoints, mesh.indices),
|
|
1172
|
+
restAreas: triangleAreas(landing.restPoints, mesh.indices),
|
|
640
1173
|
tiny: 1e-9 * part.width * part.height,
|
|
641
|
-
|
|
642
|
-
indices: mesh.indices,
|
|
643
|
-
warpDeformer,
|
|
644
|
-
vertices: Float32Array.from(mesh.vertices),
|
|
645
|
-
local: new Float32Array(mesh.vertices.length),
|
|
646
|
-
landed: new Float32Array(mesh.vertices.length),
|
|
647
|
-
restPoints
|
|
1174
|
+
indices: mesh.indices
|
|
648
1175
|
};
|
|
649
1176
|
}
|
|
650
|
-
function landPart(sweep, store, { worlds, grids }) {
|
|
651
|
-
const { part, warpDeformer, local, landed } = sweep;
|
|
652
|
-
applyWarps(sweep.vertices, part.warps, store, local);
|
|
653
|
-
const placed = placement(
|
|
654
|
-
part,
|
|
655
|
-
evaluateTransform(part.transform, part.bindings, store)
|
|
656
|
-
);
|
|
657
|
-
if (warpDeformer) {
|
|
658
|
-
const grid = grids.get(warpDeformer.id);
|
|
659
|
-
applyWarpToChild(local, placed, warpDeformer.grid, grid, landed);
|
|
660
|
-
} else if (part.deformer !== void 0) {
|
|
661
|
-
const world = worlds.get(part.deformer);
|
|
662
|
-
transformGridPoints(local, multiply(world, placed), landed);
|
|
663
|
-
} else {
|
|
664
|
-
transformGridPoints(local, placed, landed);
|
|
665
|
-
}
|
|
666
|
-
return landed;
|
|
667
|
-
}
|
|
668
1177
|
function checkFolds(model, options = {}) {
|
|
669
1178
|
const poses = options.poses ?? foldPoses(model);
|
|
670
1179
|
const deformers = model.deformers ?? [];
|
|
@@ -691,7 +1200,7 @@ function checkFolds(model, options = {}) {
|
|
|
691
1200
|
const store = new ParameterStore(model.parameters);
|
|
692
1201
|
for (const [id, v] of Object.entries(pose.values)) store.set(id, v);
|
|
693
1202
|
const value = (id) => store.get(id);
|
|
694
|
-
const expected = (
|
|
1203
|
+
const expected = (target2) => options.expected?.(target2, pose, value) === true;
|
|
695
1204
|
for (const sweep of gridSweeps) {
|
|
696
1205
|
const { cols, rows } = sweep.deformer.grid;
|
|
697
1206
|
const areas = cornerAreas(
|
|
@@ -782,7 +1291,414 @@ function classify(worst) {
|
|
|
782
1291
|
return "ok";
|
|
783
1292
|
}
|
|
784
1293
|
|
|
1294
|
+
// ../engine/src/physics-check.ts
|
|
1295
|
+
var import_format7 = require("@ikijs/format");
|
|
1296
|
+
|
|
1297
|
+
// ../engine/src/physics-runs.ts
|
|
1298
|
+
var FRAME_MS = FIXED_DT_S * 1e3 * (1 + 1e-9);
|
|
1299
|
+
var STEP_FRAMES = 300;
|
|
1300
|
+
var IDLE_FRAMES = 1800;
|
|
1301
|
+
var IDLE_SEED = 1;
|
|
1302
|
+
var MIN_TURN = 1e-9;
|
|
1303
|
+
function run(model, store, rigs, chains, frames, excite) {
|
|
1304
|
+
const raw = /* @__PURE__ */ new Map();
|
|
1305
|
+
const read = (id) => store.get(id);
|
|
1306
|
+
const sink = (id, value) => {
|
|
1307
|
+
let trace = raw.get(id);
|
|
1308
|
+
if (trace === void 0) raw.set(id, trace = []);
|
|
1309
|
+
trace.push(value);
|
|
1310
|
+
store.set(id, value);
|
|
1311
|
+
};
|
|
1312
|
+
const { parameters } = model;
|
|
1313
|
+
const drivers = [
|
|
1314
|
+
new PhysicsMotion(rigs, parameters, read, sink),
|
|
1315
|
+
new HairChainMotion(chains, parameters, model.deformers ?? [], read, sink)
|
|
1316
|
+
];
|
|
1317
|
+
for (let frame = 0; frame <= frames; frame++) {
|
|
1318
|
+
const nowMs = frame * FRAME_MS;
|
|
1319
|
+
excite(frame, nowMs);
|
|
1320
|
+
for (const driver of drivers) driver.update(nowMs);
|
|
1321
|
+
}
|
|
1322
|
+
const readings = /* @__PURE__ */ new Map();
|
|
1323
|
+
for (const driver of drivers) {
|
|
1324
|
+
driver.drivenParameterIds.forEach((id, i) => {
|
|
1325
|
+
const param = parameters.find((p) => p.id === id);
|
|
1326
|
+
readings.set(id, readTrace(raw.get(id), param, driver.resets[i]));
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
return readings;
|
|
1330
|
+
}
|
|
1331
|
+
function readTrace(raw, param, resets) {
|
|
1332
|
+
const rest = clamp(param.default, param.min, param.max);
|
|
1333
|
+
const reading = {
|
|
1334
|
+
peak: 0,
|
|
1335
|
+
at: 0,
|
|
1336
|
+
final: rest,
|
|
1337
|
+
values: [],
|
|
1338
|
+
lo: rest,
|
|
1339
|
+
hi: rest,
|
|
1340
|
+
pinned: { frames: 0, end: "max" },
|
|
1341
|
+
resets
|
|
1342
|
+
};
|
|
1343
|
+
const seen = /* @__PURE__ */ new Set([rest]);
|
|
1344
|
+
let outside = 0;
|
|
1345
|
+
let end = "max";
|
|
1346
|
+
raw.forEach((value, frame) => {
|
|
1347
|
+
const held = clamp(value, param.min, param.max);
|
|
1348
|
+
if (Math.abs(held - rest) > Math.abs(reading.peak)) {
|
|
1349
|
+
reading.peak = held - rest;
|
|
1350
|
+
reading.at = frame * FIXED_DT_S;
|
|
1351
|
+
}
|
|
1352
|
+
if (!seen.has(held)) {
|
|
1353
|
+
seen.add(held);
|
|
1354
|
+
reading.values.push(held);
|
|
1355
|
+
}
|
|
1356
|
+
reading.lo = Math.min(reading.lo, held);
|
|
1357
|
+
reading.hi = Math.max(reading.hi, held);
|
|
1358
|
+
reading.final = held;
|
|
1359
|
+
if (value >= param.min && value <= param.max) {
|
|
1360
|
+
outside = 0;
|
|
1361
|
+
return;
|
|
1362
|
+
}
|
|
1363
|
+
const side = value < param.min ? "min" : "max";
|
|
1364
|
+
if (outside === 0 || side !== end) {
|
|
1365
|
+
outside = 0;
|
|
1366
|
+
end = side;
|
|
1367
|
+
}
|
|
1368
|
+
outside++;
|
|
1369
|
+
if (outside > reading.pinned.frames) {
|
|
1370
|
+
reading.pinned = { frames: outside, end };
|
|
1371
|
+
}
|
|
1372
|
+
});
|
|
1373
|
+
return reading;
|
|
1374
|
+
}
|
|
1375
|
+
function farEnd(param) {
|
|
1376
|
+
if (param.min === param.max) return void 0;
|
|
1377
|
+
const rest = clamp(param.default, param.min, param.max);
|
|
1378
|
+
return param.max - rest >= rest - param.min ? param.max : param.min;
|
|
1379
|
+
}
|
|
1380
|
+
function stepRun(model, rigs, chains, values) {
|
|
1381
|
+
const store = new ParameterStore(model.parameters);
|
|
1382
|
+
return run(model, store, rigs, chains, STEP_FRAMES, (frame) => {
|
|
1383
|
+
if (frame !== 1) return;
|
|
1384
|
+
for (const [id, v] of Object.entries(values)) store.set(id, v);
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
function idleRun(model) {
|
|
1388
|
+
const store = new ParameterStore(model.parameters);
|
|
1389
|
+
const idle = new IdleMotion((id, v) => store.set(id, v), {
|
|
1390
|
+
rng: lcg(IDLE_SEED)
|
|
1391
|
+
});
|
|
1392
|
+
return run(
|
|
1393
|
+
model,
|
|
1394
|
+
store,
|
|
1395
|
+
model.physics ?? [],
|
|
1396
|
+
model.physicsChains ?? [],
|
|
1397
|
+
IDLE_FRAMES,
|
|
1398
|
+
(_, nowMs) => idle.update(nowMs)
|
|
1399
|
+
);
|
|
1400
|
+
}
|
|
1401
|
+
function lcg(seed) {
|
|
1402
|
+
let state = seed >>> 0;
|
|
1403
|
+
return () => {
|
|
1404
|
+
state = Math.imul(state, 1664525) + 1013904223 >>> 0;
|
|
1405
|
+
return state / 2 ** 32;
|
|
1406
|
+
};
|
|
1407
|
+
}
|
|
1408
|
+
function anchorInputs(model, chain) {
|
|
1409
|
+
const store = new ParameterStore(model.parameters);
|
|
1410
|
+
const angle = () => {
|
|
1411
|
+
const { worlds } = resolveDeformers(model.deformers ?? [], store);
|
|
1412
|
+
const world = worlds.get(chain.anchorDeformer);
|
|
1413
|
+
return Math.atan2(world[1], world[0]);
|
|
1414
|
+
};
|
|
1415
|
+
const rest = angle();
|
|
1416
|
+
const found = [];
|
|
1417
|
+
for (const p of model.parameters) {
|
|
1418
|
+
const probes = new Set(
|
|
1419
|
+
[p.max, p.min, ...stopsOf(model, p.id)].map(
|
|
1420
|
+
(v) => clamp(v, p.min, p.max)
|
|
1421
|
+
)
|
|
1422
|
+
);
|
|
1423
|
+
probes.delete(store.get(p.id));
|
|
1424
|
+
let most = 0;
|
|
1425
|
+
let best;
|
|
1426
|
+
for (const value of probes) {
|
|
1427
|
+
store.set(p.id, value);
|
|
1428
|
+
const d = angle() - rest;
|
|
1429
|
+
const turn = Math.abs(Math.atan2(Math.sin(d), Math.cos(d)));
|
|
1430
|
+
if (turn <= most + MIN_TURN) continue;
|
|
1431
|
+
[most, best] = [turn, { parameter: p.id, value }];
|
|
1432
|
+
}
|
|
1433
|
+
store.reset();
|
|
1434
|
+
if (best) found.push(best);
|
|
1435
|
+
}
|
|
1436
|
+
return found;
|
|
1437
|
+
}
|
|
1438
|
+
function stopsOf(model, parameter) {
|
|
1439
|
+
const stops = /* @__PURE__ */ new Set();
|
|
1440
|
+
for (const d of model.deformers ?? []) {
|
|
1441
|
+
if (d.kind !== "warp") continue;
|
|
1442
|
+
for (const w of d.warps ?? []) {
|
|
1443
|
+
if (w.parameter !== parameter) continue;
|
|
1444
|
+
for (const k of w.keyforms) stops.add(k.value);
|
|
1445
|
+
}
|
|
1446
|
+
const { warp2d } = d;
|
|
1447
|
+
if (warp2d?.parameter === parameter) {
|
|
1448
|
+
for (const v of warp2d.valuesX) stops.add(v);
|
|
1449
|
+
}
|
|
1450
|
+
if (warp2d?.parameterY === parameter) {
|
|
1451
|
+
for (const v of warp2d.valuesY) stops.add(v);
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
return [...stops].sort((a, b) => a - b);
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
// ../engine/src/physics-check.ts
|
|
1458
|
+
var DISPLACEMENT_PX = 1;
|
|
1459
|
+
var PINNED_FRAMES = 60;
|
|
1460
|
+
var TOLERANCE = 1e-9;
|
|
1461
|
+
var UNIT_QUAD = [-0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5];
|
|
1462
|
+
function checkPhysics(model) {
|
|
1463
|
+
const idle = idleRun(model);
|
|
1464
|
+
const displace = displacer(model);
|
|
1465
|
+
const idleExcitation = (output) => {
|
|
1466
|
+
const reading = idle.get(output.id);
|
|
1467
|
+
return {
|
|
1468
|
+
name: "the idle",
|
|
1469
|
+
reading,
|
|
1470
|
+
displacementPx: displace(output, reading.values)
|
|
1471
|
+
};
|
|
1472
|
+
};
|
|
1473
|
+
const param = (id) => model.parameters.find((p) => p.id === id);
|
|
1474
|
+
const springs = (model.physics ?? []).map((rig) => {
|
|
1475
|
+
const inputs = (0, import_format7.physicsInputs)(rig).map((i) => param(i.parameter));
|
|
1476
|
+
const ids = inputs.map((p) => p.id);
|
|
1477
|
+
const output = param(rig.output.parameter);
|
|
1478
|
+
const ranged = inputs.flatMap((input) => {
|
|
1479
|
+
const far = farEnd(input);
|
|
1480
|
+
return far === void 0 ? [] : [{ [input.id]: far }];
|
|
1481
|
+
});
|
|
1482
|
+
const settings = ranged.length === 0 ? [{}] : ranged;
|
|
1483
|
+
const steps = settings.map((values) => {
|
|
1484
|
+
const reading = stepRun(model, [rig], [], values).get(output.id);
|
|
1485
|
+
const setting = inputs.length === 1 ? [] : Object.entries(values).map(([id, v]) => `${id}=${v}`);
|
|
1486
|
+
return {
|
|
1487
|
+
name: ["the step", ...setting].join(" "),
|
|
1488
|
+
reading,
|
|
1489
|
+
displacementPx: displace(output, reading.values),
|
|
1490
|
+
values
|
|
1491
|
+
};
|
|
1492
|
+
});
|
|
1493
|
+
const atIdle = idleExcitation(output);
|
|
1494
|
+
const clean = steps.filter((s) => !unstableWhy(output, [s]));
|
|
1495
|
+
return target(model, {
|
|
1496
|
+
rig: { kind: "spring", id: rig.id },
|
|
1497
|
+
input: ids,
|
|
1498
|
+
output,
|
|
1499
|
+
step: mostMoving(clean.length > 0 ? clean : steps),
|
|
1500
|
+
idle: atIdle,
|
|
1501
|
+
unstable: springWhy(rig) ?? unstableWhy(output, [...steps, atIdle]),
|
|
1502
|
+
inert: ranged.length === 0 ? `${ids.join(", ")} ${ids.length === 1 ? "has" : "have"} no range` : void 0
|
|
1503
|
+
});
|
|
1504
|
+
});
|
|
1505
|
+
const chains = (model.physicsChains ?? []).flatMap((chain) => {
|
|
1506
|
+
const candidates = anchorInputs(model, chain);
|
|
1507
|
+
const settings = candidates.length === 0 ? [{}] : candidates.map((c) => ({ [c.parameter]: c.value }));
|
|
1508
|
+
const runs = settings.map((values) => ({
|
|
1509
|
+
values,
|
|
1510
|
+
readings: stepRun(model, [], [chain], values)
|
|
1511
|
+
}));
|
|
1512
|
+
return chain.segments.map((segment, i) => {
|
|
1513
|
+
const output = param(segment.output.parameter);
|
|
1514
|
+
const steps = runs.map(({ values, readings }) => {
|
|
1515
|
+
const reading = readings.get(output.id);
|
|
1516
|
+
const setting = Object.entries(values).map(([id, v]) => `${id}=${v}`);
|
|
1517
|
+
return {
|
|
1518
|
+
name: ["the step", ...setting].join(" "),
|
|
1519
|
+
reading,
|
|
1520
|
+
displacementPx: displace(output, reading.values),
|
|
1521
|
+
values
|
|
1522
|
+
};
|
|
1523
|
+
});
|
|
1524
|
+
const atIdle = idleExcitation(output);
|
|
1525
|
+
const clean = steps.filter((s) => !unstableWhy(output, [s]));
|
|
1526
|
+
return target(model, {
|
|
1527
|
+
rig: { kind: "chain", id: chain.id, segment: i },
|
|
1528
|
+
input: candidates.map((c) => c.parameter),
|
|
1529
|
+
output,
|
|
1530
|
+
step: mostMoving(clean.length > 0 ? clean : steps),
|
|
1531
|
+
idle: atIdle,
|
|
1532
|
+
unstable: unstableWhy(output, [...steps, atIdle]),
|
|
1533
|
+
inert: candidates.length === 0 ? `nothing turns anchor ${chain.anchorDeformer}` : void 0
|
|
1534
|
+
});
|
|
1535
|
+
});
|
|
1536
|
+
});
|
|
1537
|
+
const targets = [...springs, ...chains];
|
|
1538
|
+
return {
|
|
1539
|
+
thresholds: {
|
|
1540
|
+
displacementPx: DISPLACEMENT_PX,
|
|
1541
|
+
pinnedFrames: PINNED_FRAMES
|
|
1542
|
+
},
|
|
1543
|
+
targets,
|
|
1544
|
+
offenders: [
|
|
1545
|
+
...targets.filter((t) => t.kind === "unstable"),
|
|
1546
|
+
...targets.filter((t) => t.kind === "frozen")
|
|
1547
|
+
]
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1550
|
+
function target(model, t) {
|
|
1551
|
+
const { step, idle, output } = t;
|
|
1552
|
+
const drives = drivesOf(model, output.id);
|
|
1553
|
+
const px2 = Math.floor(step.displacementPx * 10) / 10;
|
|
1554
|
+
const still = step.displacementPx < DISPLACEMENT_PX ? `moves ${px2.toFixed(1)} model px over ${step.name}` : void 0;
|
|
1555
|
+
const frozen = drives.length === 0 ? "drives nothing" : t.inert ?? still;
|
|
1556
|
+
const { peak, at, final } = step.reading;
|
|
1557
|
+
return {
|
|
1558
|
+
rig: t.rig,
|
|
1559
|
+
input: t.input,
|
|
1560
|
+
output: output.id,
|
|
1561
|
+
drives,
|
|
1562
|
+
kind: t.unstable ? "unstable" : frozen ? "frozen" : "ok",
|
|
1563
|
+
why: t.unstable ?? frozen,
|
|
1564
|
+
step: {
|
|
1565
|
+
values: step.values,
|
|
1566
|
+
peak,
|
|
1567
|
+
at,
|
|
1568
|
+
final,
|
|
1569
|
+
displacementPx: step.displacementPx
|
|
1570
|
+
},
|
|
1571
|
+
idle: {
|
|
1572
|
+
peak: Math.abs(idle.reading.peak),
|
|
1573
|
+
at: idle.reading.at,
|
|
1574
|
+
displacementPx: idle.displacementPx
|
|
1575
|
+
}
|
|
1576
|
+
};
|
|
1577
|
+
}
|
|
1578
|
+
function mostMoving(steps) {
|
|
1579
|
+
return steps.reduce((best, s) => {
|
|
1580
|
+
if (s.displacementPx !== best.displacementPx) {
|
|
1581
|
+
return s.displacementPx > best.displacementPx ? s : best;
|
|
1582
|
+
}
|
|
1583
|
+
return Math.abs(s.reading.peak) > Math.abs(best.reading.peak) ? s : best;
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1586
|
+
function drivesOf(model, output) {
|
|
1587
|
+
const parts = model.parts.filter(
|
|
1588
|
+
(p) => [
|
|
1589
|
+
...(p.bindings ?? []).map((b) => b.parameter),
|
|
1590
|
+
...(p.warps ?? []).map((w) => w.parameter)
|
|
1591
|
+
].includes(output)
|
|
1592
|
+
);
|
|
1593
|
+
const deformers = (model.deformers ?? []).filter(
|
|
1594
|
+
(d) => (d.kind === "warp" ? [
|
|
1595
|
+
...(d.warps ?? []).map((w) => w.parameter),
|
|
1596
|
+
d.warp2d?.parameter,
|
|
1597
|
+
d.warp2d?.parameterY
|
|
1598
|
+
] : (d.bindings ?? []).map((b) => b.parameter)).includes(output)
|
|
1599
|
+
);
|
|
1600
|
+
return [
|
|
1601
|
+
...parts.map((p) => ({ kind: "part", id: p.id })),
|
|
1602
|
+
...deformers.map((d) => ({ kind: "deformer", id: d.id }))
|
|
1603
|
+
];
|
|
1604
|
+
}
|
|
1605
|
+
function springStepRadius({ mass, stiffness, damping }) {
|
|
1606
|
+
const k = FIXED_DT_S * FIXED_DT_S * stiffness / mass;
|
|
1607
|
+
const c = FIXED_DT_S * damping / mass;
|
|
1608
|
+
const trace = 2 - k - c;
|
|
1609
|
+
const det = 1 - c;
|
|
1610
|
+
const disc = trace * trace - 4 * det;
|
|
1611
|
+
const radius = disc >= 0 ? (Math.abs(trace) + Math.sqrt(disc)) / 2 : Math.sqrt(det);
|
|
1612
|
+
return { radius, k };
|
|
1613
|
+
}
|
|
1614
|
+
function springWhy(rig) {
|
|
1615
|
+
const { radius, k } = springStepRadius(rig);
|
|
1616
|
+
if (radius > 1 + TOLERANCE) {
|
|
1617
|
+
let digits = 2;
|
|
1618
|
+
while (Number(radius.toFixed(digits)) <= 1) digits++;
|
|
1619
|
+
return `spring step map radius ${radius.toFixed(digits)} over 1 at 1/60 s`;
|
|
1620
|
+
}
|
|
1621
|
+
if (rig.damping === 0 && k >= 4 - TOLERANCE) {
|
|
1622
|
+
return `spring on its undamped boundary, dt\xB2k/m ${k.toFixed(2)}`;
|
|
1623
|
+
}
|
|
1624
|
+
return void 0;
|
|
1625
|
+
}
|
|
1626
|
+
function unstableWhy(output, excitations) {
|
|
1627
|
+
for (const { name, reading } of excitations) {
|
|
1628
|
+
const n = reading.resets;
|
|
1629
|
+
if (n === 0) continue;
|
|
1630
|
+
return `finiteness guard reset it ${n} time${n === 1 ? "" : "s"} in ${name}`;
|
|
1631
|
+
}
|
|
1632
|
+
for (const { name, reading } of excitations) {
|
|
1633
|
+
const { frames, end } = reading.pinned;
|
|
1634
|
+
if (frames < PINNED_FRAMES) continue;
|
|
1635
|
+
return `pinned at ${output.id} ${end} ${output[end]} for ${frames} frames of ${name}`;
|
|
1636
|
+
}
|
|
1637
|
+
return void 0;
|
|
1638
|
+
}
|
|
1639
|
+
function displacer(model) {
|
|
1640
|
+
const deformers = model.deformers ?? [];
|
|
1641
|
+
const store = new ParameterStore(model.parameters);
|
|
1642
|
+
const { worlds } = resolveDeformers(staticDeformers(model), store);
|
|
1643
|
+
const landings = model.parts.map(
|
|
1644
|
+
(part) => landedPart(
|
|
1645
|
+
part,
|
|
1646
|
+
part.mesh?.vertices ?? UNIT_QUAD,
|
|
1647
|
+
deformers,
|
|
1648
|
+
worlds,
|
|
1649
|
+
store
|
|
1650
|
+
)
|
|
1651
|
+
);
|
|
1652
|
+
const atRest = resolveDeformers(deformers, store);
|
|
1653
|
+
const baselines = landings.map(
|
|
1654
|
+
(l) => Float32Array.from(landPart(l, store, atRest))
|
|
1655
|
+
);
|
|
1656
|
+
return (output, values) => {
|
|
1657
|
+
let most = 0;
|
|
1658
|
+
const affected = affectedParts(model, output.id);
|
|
1659
|
+
for (const value of values) {
|
|
1660
|
+
store.set(output.id, value);
|
|
1661
|
+
const resolved = resolveDeformers(deformers, store);
|
|
1662
|
+
landings.forEach((landing, i) => {
|
|
1663
|
+
if (!affected.has(landing.part)) return;
|
|
1664
|
+
const landed = landPart(landing, store, resolved);
|
|
1665
|
+
const base = baselines[i];
|
|
1666
|
+
for (let j = 0; j < landed.length; j += 2) {
|
|
1667
|
+
const dx = landed[j] - base[j];
|
|
1668
|
+
const dy = landed[j + 1] - base[j + 1];
|
|
1669
|
+
most = Math.max(most, dx * dx + dy * dy);
|
|
1670
|
+
}
|
|
1671
|
+
});
|
|
1672
|
+
}
|
|
1673
|
+
store.reset();
|
|
1674
|
+
return Math.sqrt(most);
|
|
1675
|
+
};
|
|
1676
|
+
}
|
|
1677
|
+
function affectedParts(model, output) {
|
|
1678
|
+
const deformers = new Map((model.deformers ?? []).map((d) => [d.id, d]));
|
|
1679
|
+
const reads = (d) => (d.kind === "warp" ? [
|
|
1680
|
+
...(d.warps ?? []).map((w) => w.parameter),
|
|
1681
|
+
d.warp2d?.parameter,
|
|
1682
|
+
d.warp2d?.parameterY
|
|
1683
|
+
] : (d.bindings ?? []).map((b) => b.parameter)).includes(output);
|
|
1684
|
+
const hung = (id) => {
|
|
1685
|
+
for (let d = id && deformers.get(id); d; d = d.parent && deformers.get(d.parent)) {
|
|
1686
|
+
if (reads(d)) return true;
|
|
1687
|
+
}
|
|
1688
|
+
return false;
|
|
1689
|
+
};
|
|
1690
|
+
return new Set(
|
|
1691
|
+
model.parts.filter(
|
|
1692
|
+
(p) => [
|
|
1693
|
+
...(p.bindings ?? []).map((b) => b.parameter),
|
|
1694
|
+
...(p.warps ?? []).map((w) => w.parameter)
|
|
1695
|
+
].includes(output) || hung(p.deformer)
|
|
1696
|
+
)
|
|
1697
|
+
);
|
|
1698
|
+
}
|
|
1699
|
+
|
|
785
1700
|
// src/fold-report.ts
|
|
1701
|
+
var import_editor = require("@ikijs/editor");
|
|
786
1702
|
function checkModelFolds(model, extraValues = []) {
|
|
787
1703
|
const declared = new Set(model.parameters.map((p) => p.id));
|
|
788
1704
|
return checkFolds(model, {
|
|
@@ -790,9 +1706,9 @@ function checkModelFolds(model, extraValues = []) {
|
|
|
790
1706
|
// The effective value, not the pose's overrides: the auto-rig's mouth
|
|
791
1707
|
// rests shut at its default, so `rest` and the other parameters' singles
|
|
792
1708
|
// are shut-mouth poses too.
|
|
793
|
-
expected: (
|
|
794
|
-
if (
|
|
795
|
-
const shutBy = import_editor.SHUT_BY.get(
|
|
1709
|
+
expected: (target2, _pose, value) => {
|
|
1710
|
+
if (target2.kind !== "part") return false;
|
|
1711
|
+
const shutBy = import_editor.SHUT_BY.get(target2.id);
|
|
796
1712
|
return shutBy !== void 0 && declared.has(shutBy) && value(shutBy) === 0;
|
|
797
1713
|
}
|
|
798
1714
|
});
|
|
@@ -831,7 +1747,7 @@ function ratioText(ratio) {
|
|
|
831
1747
|
// src/render-poses.ts
|
|
832
1748
|
var import_node_fs3 = require("fs");
|
|
833
1749
|
var import_node_path3 = __toESM(require("path"));
|
|
834
|
-
var
|
|
1750
|
+
var import_format8 = require("@ikijs/format");
|
|
835
1751
|
|
|
836
1752
|
// src/limits.ts
|
|
837
1753
|
var import_node_fs = __toESM(require("fs"));
|
|
@@ -1332,9 +2248,9 @@ function planRenders(model, requested) {
|
|
|
1332
2248
|
}
|
|
1333
2249
|
const bodyAngles = Object.fromEntries(
|
|
1334
2250
|
[
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
2251
|
+
import_format8.StandardParameter.BodyAngleX,
|
|
2252
|
+
import_format8.StandardParameter.BodyAngleY,
|
|
2253
|
+
import_format8.StandardParameter.BodyAngleZ
|
|
1338
2254
|
].filter((id) => model.parameters.some((p) => p.id === id)).map((id) => [id, -10])
|
|
1339
2255
|
);
|
|
1340
2256
|
const poses = [
|
|
@@ -1420,7 +2336,7 @@ function planRenders(model, requested) {
|
|
|
1420
2336
|
whole("full-elbow-r-45", { ParamElbowR: 45 }),
|
|
1421
2337
|
whole("full-elbow-r-90", { ParamElbowR: 90 })
|
|
1422
2338
|
);
|
|
1423
|
-
if (model.parameters.some((p) => p.id ===
|
|
2339
|
+
if (model.parameters.some((p) => p.id === import_format8.StandardParameter.ArmPoseRight)) {
|
|
1424
2340
|
poses.push(
|
|
1425
2341
|
whole("full-pose-l", { ParamArmPoseL: 1 }),
|
|
1426
2342
|
whole("full-pose-r", { ParamArmPoseR: 1 }),
|
|
@@ -1485,7 +2401,7 @@ async function renderPoses(input) {
|
|
|
1485
2401
|
input.modelPath
|
|
1486
2402
|
);
|
|
1487
2403
|
const outDir = resolveOutputDir(input.outDir);
|
|
1488
|
-
const model = (0,
|
|
2404
|
+
const model = (0, import_format8.loadIkiModel)((0, import_node_fs3.readFileSync)(modelFile, "utf8"));
|
|
1489
2405
|
const plan = planRenders(model, input.poses);
|
|
1490
2406
|
const browser = findBrowser();
|
|
1491
2407
|
if (!browser) return { ok: false, error: NO_BROWSER_MESSAGE };
|
|
@@ -1494,6 +2410,7 @@ async function renderPoses(input) {
|
|
|
1494
2410
|
model,
|
|
1495
2411
|
input.poses?.map((p) => p.values)
|
|
1496
2412
|
);
|
|
2413
|
+
const physics = checkPhysics(model);
|
|
1497
2414
|
const { failedTextures, poses } = await withBrowser(
|
|
1498
2415
|
browser,
|
|
1499
2416
|
async (evaluate) => {
|
|
@@ -1530,10 +2447,11 @@ async function renderPoses(input) {
|
|
|
1530
2447
|
failedTextures,
|
|
1531
2448
|
poses,
|
|
1532
2449
|
modelCanvas: model.canvas,
|
|
1533
|
-
folds
|
|
2450
|
+
folds,
|
|
2451
|
+
physics
|
|
1534
2452
|
};
|
|
1535
2453
|
} catch (error) {
|
|
1536
|
-
if (error instanceof AutoRigInputError || error instanceof
|
|
2454
|
+
if (error instanceof AutoRigInputError || error instanceof import_format8.IkiFormatError) {
|
|
1537
2455
|
return { ok: false, error: error.message };
|
|
1538
2456
|
}
|
|
1539
2457
|
throw error;
|
|
@@ -1610,10 +2528,10 @@ async function renderAtlasToDataUri(crops, layout, quantizeColors) {
|
|
|
1610
2528
|
// src/tools.ts
|
|
1611
2529
|
function coerceModel(model) {
|
|
1612
2530
|
try {
|
|
1613
|
-
const parsed = typeof model === "string" ? (0,
|
|
2531
|
+
const parsed = typeof model === "string" ? (0, import_format9.loadIkiModel)(model) : (0, import_format9.parseIkiModel)(model);
|
|
1614
2532
|
return { ok: true, model: parsed };
|
|
1615
2533
|
} catch (e) {
|
|
1616
|
-
if (e instanceof
|
|
2534
|
+
if (e instanceof import_format9.IkiFormatError) return { ok: false, error: e.message };
|
|
1617
2535
|
throw e;
|
|
1618
2536
|
}
|
|
1619
2537
|
}
|
|
@@ -1730,115 +2648,119 @@ function describeIkiAt(modelPath) {
|
|
|
1730
2648
|
}
|
|
1731
2649
|
var STANDARD_PARAMETER_INFO = [
|
|
1732
2650
|
{
|
|
1733
|
-
id:
|
|
2651
|
+
id: import_format9.StandardParameter.MouthOpen,
|
|
1734
2652
|
description: "Mouth open amount for lip-sync (0 closed .. 1 open)."
|
|
1735
2653
|
},
|
|
1736
2654
|
{
|
|
1737
|
-
id:
|
|
2655
|
+
id: import_format9.StandardParameter.MouthForm,
|
|
1738
2656
|
description: "Mouth form / smile (-1 .. 1)."
|
|
1739
2657
|
},
|
|
1740
2658
|
{
|
|
1741
|
-
id:
|
|
2659
|
+
id: import_format9.StandardParameter.EyeOpenLeft,
|
|
1742
2660
|
description: "Left eye open (0 closed .. 1 open). Drive with the right eye for a blink."
|
|
1743
2661
|
},
|
|
1744
2662
|
{
|
|
1745
|
-
id:
|
|
2663
|
+
id: import_format9.StandardParameter.EyeOpenRight,
|
|
1746
2664
|
description: "Right eye open (0 closed .. 1 open)."
|
|
1747
2665
|
},
|
|
1748
2666
|
{
|
|
1749
|
-
id:
|
|
2667
|
+
id: import_format9.StandardParameter.EyeballX,
|
|
1750
2668
|
description: "Eyeball gaze, horizontal (-1 .. 1)."
|
|
1751
2669
|
},
|
|
1752
2670
|
{
|
|
1753
|
-
id:
|
|
2671
|
+
id: import_format9.StandardParameter.EyeballY,
|
|
1754
2672
|
description: "Eyeball gaze, vertical (-1 .. 1)."
|
|
1755
2673
|
},
|
|
1756
2674
|
{
|
|
1757
|
-
id:
|
|
2675
|
+
id: import_format9.StandardParameter.AngleX,
|
|
1758
2676
|
description: "Head angle, horizontal degrees."
|
|
1759
2677
|
},
|
|
1760
2678
|
{
|
|
1761
|
-
id:
|
|
2679
|
+
id: import_format9.StandardParameter.AngleY,
|
|
1762
2680
|
description: "Head angle, vertical degrees."
|
|
1763
2681
|
},
|
|
1764
2682
|
{
|
|
1765
|
-
id:
|
|
2683
|
+
id: import_format9.StandardParameter.AngleZ,
|
|
1766
2684
|
description: "Head tilt / roll degrees; positive tilts the top of the head toward the viewer's right (clockwise), as in Live2D."
|
|
1767
2685
|
},
|
|
1768
2686
|
{
|
|
1769
|
-
id:
|
|
2687
|
+
id: import_format9.StandardParameter.BodyAngleX,
|
|
1770
2688
|
description: "Body turn, degrees (-10 .. 10); positive turns the body toward the viewer's right, as AngleX does the head."
|
|
1771
2689
|
},
|
|
1772
2690
|
{
|
|
1773
|
-
id:
|
|
2691
|
+
id: import_format9.StandardParameter.BodyAngleY,
|
|
1774
2692
|
description: "Body lean, degrees (-10 .. 10); positive moves the upper body up, negative bows."
|
|
1775
2693
|
},
|
|
1776
2694
|
{
|
|
1777
|
-
id:
|
|
2695
|
+
id: import_format9.StandardParameter.BodyAngleZ,
|
|
1778
2696
|
description: "Body tilt, degrees (-10 .. 10); positive tilts the top toward the viewer's right (clockwise), as AngleZ does the head."
|
|
1779
2697
|
},
|
|
1780
2698
|
{
|
|
1781
|
-
id:
|
|
2699
|
+
id: import_format9.StandardParameter.Breath,
|
|
1782
2700
|
description: "Idle breath (0 .. 1), cycled by the host."
|
|
1783
2701
|
},
|
|
1784
2702
|
{
|
|
1785
|
-
id:
|
|
2703
|
+
id: import_format9.StandardParameter.AmbientSway,
|
|
2704
|
+
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."
|
|
2705
|
+
},
|
|
2706
|
+
{
|
|
2707
|
+
id: import_format9.StandardParameter.BrowLeftY,
|
|
1786
2708
|
description: "Left brow raise/lower (-1 .. 1)."
|
|
1787
2709
|
},
|
|
1788
2710
|
{
|
|
1789
|
-
id:
|
|
2711
|
+
id: import_format9.StandardParameter.BrowRightY,
|
|
1790
2712
|
description: "Right brow raise/lower (-1 .. 1)."
|
|
1791
2713
|
},
|
|
1792
2714
|
{
|
|
1793
|
-
id:
|
|
2715
|
+
id: import_format9.StandardParameter.BrowLeftAngle,
|
|
1794
2716
|
description: "Left brow tilt/angle (-1 .. 1)."
|
|
1795
2717
|
},
|
|
1796
2718
|
{
|
|
1797
|
-
id:
|
|
2719
|
+
id: import_format9.StandardParameter.BrowRightAngle,
|
|
1798
2720
|
description: "Right brow tilt/angle (-1 .. 1)."
|
|
1799
2721
|
},
|
|
1800
2722
|
{
|
|
1801
|
-
id:
|
|
2723
|
+
id: import_format9.StandardParameter.Cheek,
|
|
1802
2724
|
description: "Cheek blush strength (0 .. 1), raised by an expression."
|
|
1803
2725
|
},
|
|
1804
2726
|
{
|
|
1805
|
-
id:
|
|
2727
|
+
id: import_format9.StandardParameter.HairSwayX,
|
|
1806
2728
|
description: "Horizontal hair-sway driver. Physics OUTPUT \u2014 driven by the spring, hosts should not set it directly."
|
|
1807
2729
|
},
|
|
1808
2730
|
{
|
|
1809
|
-
id:
|
|
2731
|
+
id: import_format9.StandardParameter.HairSwayZ,
|
|
1810
2732
|
description: "Hair-sway driver behind a head tilt. Physics OUTPUT \u2014 driven by the spring, hosts should not set it directly."
|
|
1811
2733
|
},
|
|
1812
2734
|
{
|
|
1813
|
-
id:
|
|
2735
|
+
id: import_format9.StandardParameter.ArmLeft,
|
|
1814
2736
|
description: "Left shoulder, degrees; positive raises the arm outward (mirrored on the right)."
|
|
1815
2737
|
},
|
|
1816
2738
|
{
|
|
1817
|
-
id:
|
|
2739
|
+
id: import_format9.StandardParameter.ArmRight,
|
|
1818
2740
|
description: "Right shoulder, degrees; positive raises the arm outward (mirrored on the left)."
|
|
1819
2741
|
},
|
|
1820
2742
|
{
|
|
1821
|
-
id:
|
|
2743
|
+
id: import_format9.StandardParameter.ElbowLeft,
|
|
1822
2744
|
description: "Left elbow, degrees; positive bends the forearm toward the body (the flexion of a hanging arm), negative a little outward (mirrored on the right)."
|
|
1823
2745
|
},
|
|
1824
2746
|
{
|
|
1825
|
-
id:
|
|
2747
|
+
id: import_format9.StandardParameter.ElbowRight,
|
|
1826
2748
|
description: "Right elbow, degrees; positive bends the forearm toward the body (the flexion of a hanging arm), negative a little outward (mirrored on the left)."
|
|
1827
2749
|
},
|
|
1828
2750
|
{
|
|
1829
|
-
id:
|
|
2751
|
+
id: import_format9.StandardParameter.ArmPoseLeft,
|
|
1830
2752
|
description: "Left pose-forearm switch, 0..1; 0 the hanging forearm, 1 the drawn pose forearm, between them a crossfade of the two. Declared by auto-rigged models with a pose forearm."
|
|
1831
2753
|
},
|
|
1832
2754
|
{
|
|
1833
|
-
id:
|
|
2755
|
+
id: import_format9.StandardParameter.ArmPoseRight,
|
|
1834
2756
|
description: "Right pose-forearm switch, 0..1; 0 the hanging forearm, 1 the drawn pose forearm, between them a crossfade of the two. Declared by auto-rigged models with a pose forearm."
|
|
1835
2757
|
},
|
|
1836
2758
|
{
|
|
1837
|
-
id:
|
|
2759
|
+
id: import_format9.StandardParameter.ArmPoseAngleLeft,
|
|
1838
2760
|
description: "Left pose forearm's own small rotation about the elbow, degrees; positive tips the raised hand outward, away from the body (mirrored on the right)."
|
|
1839
2761
|
},
|
|
1840
2762
|
{
|
|
1841
|
-
id:
|
|
2763
|
+
id: import_format9.StandardParameter.ArmPoseAngleRight,
|
|
1842
2764
|
description: "Right pose forearm's own small rotation about the elbow, degrees; positive tips the raised hand outward, away from the body (mirrored on the left)."
|
|
1843
2765
|
}
|
|
1844
2766
|
];
|
|
@@ -2038,9 +2960,10 @@ async function autoRigFromLayers(input) {
|
|
|
2038
2960
|
patched.parts.find((p) => p.id === partId).texture.index = 1;
|
|
2039
2961
|
}
|
|
2040
2962
|
}
|
|
2041
|
-
const finalModel = (0,
|
|
2963
|
+
const finalModel = (0, import_format9.parseIkiModel)(patched);
|
|
2042
2964
|
writeFileAtomic(outPath, JSON.stringify(finalModel));
|
|
2043
2965
|
const folds = checkModelFolds(finalModel);
|
|
2966
|
+
const physics = checkPhysics(finalModel);
|
|
2044
2967
|
return {
|
|
2045
2968
|
ok: true,
|
|
2046
2969
|
path: outPath,
|
|
@@ -2054,6 +2977,7 @@ async function autoRigFromLayers(input) {
|
|
|
2054
2977
|
...noseCore === void 0 ? {} : { noseCore },
|
|
2055
2978
|
...turn === void 0 ? {} : { turn },
|
|
2056
2979
|
folds,
|
|
2980
|
+
physics,
|
|
2057
2981
|
...patches === void 0 ? {} : { patches }
|
|
2058
2982
|
};
|
|
2059
2983
|
} catch (err) {
|
|
@@ -3473,16 +4397,16 @@ async function layerStats(filePath) {
|
|
|
3473
4397
|
let flatCutRun = 0;
|
|
3474
4398
|
let flatCutY = -1;
|
|
3475
4399
|
for (let y = minY + 1; y <= maxY; y++) {
|
|
3476
|
-
let
|
|
4400
|
+
let run2 = 0;
|
|
3477
4401
|
for (let x = minX; x <= maxX; x++) {
|
|
3478
4402
|
if (alpha(x, y - 1) < FLAT_CUT_ALPHA_ABOVE && alpha(x, y) > FLAT_CUT_ALPHA_BELOW) {
|
|
3479
|
-
|
|
3480
|
-
if (
|
|
3481
|
-
flatCutRun =
|
|
4403
|
+
run2++;
|
|
4404
|
+
if (run2 > flatCutRun) {
|
|
4405
|
+
flatCutRun = run2;
|
|
3482
4406
|
flatCutY = y;
|
|
3483
4407
|
}
|
|
3484
4408
|
} else {
|
|
3485
|
-
|
|
4409
|
+
run2 = 0;
|
|
3486
4410
|
}
|
|
3487
4411
|
}
|
|
3488
4412
|
}
|
|
@@ -4730,6 +5654,22 @@ async function composeLayersFromParts(input) {
|
|
|
4730
5654
|
}
|
|
4731
5655
|
}
|
|
4732
5656
|
|
|
5657
|
+
// src/physics-report.ts
|
|
5658
|
+
function formatPhysicsReport(report) {
|
|
5659
|
+
if (report.targets.length === 0) return ["PHYSICS: no rigs"];
|
|
5660
|
+
return report.targets.map(targetLine);
|
|
5661
|
+
}
|
|
5662
|
+
function targetLine(t) {
|
|
5663
|
+
const inputs = t.input.join(", ");
|
|
5664
|
+
const rig = t.rig.kind === "chain" ? `${t.rig.id}/${t.rig.segment} [${inputs}]` : `${t.rig.id} ${inputs}`;
|
|
5665
|
+
const drives = t.drives.length === 0 ? "" : ` (${t.drives.map((d) => d.id).join(", ")})`;
|
|
5666
|
+
const { step, idle } = t;
|
|
5667
|
+
return `PHYSICS ${t.kind} ${rig} -> ${t.output}: step ${foldPose(step.values).name} peak ${step.peak.toFixed(2)} at ${step.at.toFixed(2)} s, final ${step.final.toFixed(2)}, moves ${pxText(step.displacementPx)} model px${drives}; idle peak ${idle.peak.toFixed(2)} at ${idle.at.toFixed(2)} s, ${pxText(idle.displacementPx)} model px` + (t.why === void 0 ? "" : ` \u2014 ${t.why}`);
|
|
5668
|
+
}
|
|
5669
|
+
function pxText(px2) {
|
|
5670
|
+
return (Math.floor(px2 * 10) / 10).toFixed(1);
|
|
5671
|
+
}
|
|
5672
|
+
|
|
4733
5673
|
// src/server.ts
|
|
4734
5674
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
4735
5675
|
var import_zod = require("zod");
|
|
@@ -4741,7 +5681,7 @@ function formatPatchReports(reports) {
|
|
|
4741
5681
|
});
|
|
4742
5682
|
}
|
|
4743
5683
|
function createIkiMcpServer() {
|
|
4744
|
-
const server = new import_mcp.McpServer({ name: "iki", version: "0.
|
|
5684
|
+
const server = new import_mcp.McpServer({ name: "iki", version: "0.28.0" });
|
|
4745
5685
|
server.registerTool(
|
|
4746
5686
|
"validate_iki",
|
|
4747
5687
|
{
|
|
@@ -4816,7 +5756,7 @@ function createIkiMcpServer() {
|
|
|
4816
5756
|
server.registerTool(
|
|
4817
5757
|
"auto_rig_from_layers",
|
|
4818
5758
|
{
|
|
4819
|
-
description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R and either mouth or the lip set (mouth_inner + lip_lower + lip_upper, a mouth that folds open instead of crossfading) required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, forearm_pose_L/forearm_pose_R, mouth_tongue/mouth_teeth (only with the lip set: drawn under its lips and clipped to mouth_inner), etc. optional; an arm needs the body, a pose forearm needs its arm, and a partial lip set, one mixed with mouth/mouth_open, or mouth_tongue/mouth_teeth without it is refused) into a renderable .iki written to disk. Pass full-canvas PNG file paths; returns the output path + summary (the model is NOT inlined). Filenames map to roles unless `fileName` is given. The result's `folds` is the written rig's fold report, printed after the path the way render_poses prints it, and report-only: a fold never refuses the rig. `patches` (see its field) adds displacements to existing keyform stops of the freshly generated rig; each op then prints one line between the path and the fold report \u2014 `PATCH <i> <target> at <Param=v \u2026>: <moved> of <of> points (cols a-b, rows c-d), largest move <maxPx> model px`, with `(vertices)` in place of the columns and rows for a mesh part \u2014 and the result's `patches` carries the same reports (`index`, `target`, `at`, `moved`, `of`, `cols`/`rows` for a grid, `maxPx`), present whenever `patches` was passed, `[]` included. An op the input schema accepts but the rig refuses comes back as `INVALID: patches[i]\u2026` and nothing is written; an op with a missing field or a field of the wrong type is the SDK's input validation error.",
|
|
5759
|
+
description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R and either mouth or the lip set (mouth_inner + lip_lower + lip_upper, a mouth that folds open instead of crossfading) required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, forearm_pose_L/forearm_pose_R, mouth_tongue/mouth_teeth (only with the lip set: drawn under its lips and clipped to mouth_inner), etc. optional; an arm needs the body, a pose forearm needs its arm, and a partial lip set, one mixed with mouth/mouth_open, or mouth_tongue/mouth_teeth without it is refused) into a renderable .iki written to disk. Pass full-canvas PNG file paths; returns the output path + summary (the model is NOT inlined). Filenames map to roles unless `fileName` is given. The result's `folds` is the written rig's fold report, printed after the path the way render_poses prints it, and report-only: a fold never refuses the rig. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output \u2014 a spring's, or each chain segment's \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. `patches` (see its field) adds displacements to existing keyform stops of the freshly generated rig; each op then prints one line between the path and the fold report \u2014 `PATCH <i> <target> at <Param=v \u2026>: <moved> of <of> points (cols a-b, rows c-d), largest move <maxPx> model px`, with `(vertices)` in place of the columns and rows for a mesh part \u2014 and the result's `patches` carries the same reports (`index`, `target`, `at`, `moved`, `of`, `cols`/`rows` for a grid, `maxPx`), present whenever `patches` was passed, `[]` included. An op the input schema accepts but the rig refuses comes back as `INVALID: patches[i]\u2026` and nothing is written; an op with a missing field or a field of the wrong type is the SDK's input validation error.",
|
|
4820
5760
|
inputSchema: {
|
|
4821
5761
|
layers: import_zod.z.array(
|
|
4822
5762
|
import_zod.z.object({
|
|
@@ -4882,7 +5822,8 @@ function createIkiMcpServer() {
|
|
|
4882
5822
|
const text = r.ok ? [
|
|
4883
5823
|
r.path,
|
|
4884
5824
|
...formatPatchReports(r.patches ?? []),
|
|
4885
|
-
...formatFoldReport(r.folds, r.canvas)
|
|
5825
|
+
...formatFoldReport(r.folds, r.canvas),
|
|
5826
|
+
...formatPhysicsReport(r.physics)
|
|
4886
5827
|
].join("\n") : `INVALID: ${r.error}`;
|
|
4887
5828
|
return { content: [{ type: "text", text }], structuredContent: r };
|
|
4888
5829
|
} catch (err) {
|
|
@@ -5011,7 +5952,7 @@ function createIkiMcpServer() {
|
|
|
5011
5952
|
server.registerTool(
|
|
5012
5953
|
"render_poses",
|
|
5013
5954
|
{
|
|
5014
|
-
description: "Renders a rigged .iki into the character loop's pose PNGs with the real engine, through the installed Chrome, Edge or Chromium run headless (set CHROME_PATH to pick one). The model decides the set: a bust gets 560x560 shots (rest, turns, nod, blinks, gaze, combined \u2014 ParamAngleX/Y/Z all at 30 \u2014 and stress: ParamAngleX/Y/Z all at -30, ParamMouthOpenY 1, both eyes at 0.5, the brows at opposite extremes (ParamBrowLY -1, ParamBrowRY 1, ParamBrowLAngle 1, ParamBrowRAngle -1) and each body angle the model declares at -10); a mouth adds 720x480 mouth crops; a full body (taller than wide) adds the full-canvas body, arm and elbow poses on a 1400-wide canvas, and a model with a pose forearm adds the full-pose-* shots. Given `poses` (see its field), the standard set is not rendered: only those poses are, each crop clamped to the model's canvas. Writes <pose>.png files into outDir, overwriting same-named files in place; returns the written paths one per line, then the model's fold report (the result's `folds`), checked by the engine over its own pose set plus any `poses`, each of which a `FOLD` line names by its settings, not its PNG name: a `FOLD` line per warp deformer or mesh part that flips (ratio <= 0) or collapses (under 0.1) at some pose \u2014 its cell or triangle, the ratio of its area there to at rest, the pose as its parameter settings (`rest` for none) and where it rests, in model space and in model px from the top-left (the layer PNGs' own pixels, not a render's) \u2014 or `FOLDS: none over N poses`, then a `FOLDS expected:` line naming the closures the rig draws on purpose (an eye or the mouth shut), each by part id, ratio and the parameter that shuts it. Report-only: a fold never fails the render. Fails with INVALID when no browser is found or an input is refused; a browser that cannot start is a tool error.",
|
|
5955
|
+
description: "Renders a rigged .iki into the character loop's pose PNGs with the real engine, through the installed Chrome, Edge or Chromium run headless (set CHROME_PATH to pick one). The model decides the set: a bust gets 560x560 shots (rest, turns, nod, blinks, gaze, combined \u2014 ParamAngleX/Y/Z all at 30 \u2014 and stress: ParamAngleX/Y/Z all at -30, ParamMouthOpenY 1, both eyes at 0.5, the brows at opposite extremes (ParamBrowLY -1, ParamBrowRY 1, ParamBrowLAngle 1, ParamBrowRAngle -1) and each body angle the model declares at -10); a mouth adds 720x480 mouth crops; a full body (taller than wide) adds the full-canvas body, arm and elbow poses on a 1400-wide canvas, and a model with a pose forearm adds the full-pose-* shots. Given `poses` (see its field), the standard set is not rendered: only those poses are, each crop clamped to the model's canvas. Writes <pose>.png files into outDir, overwriting same-named files in place; returns the written paths one per line, then the model's fold report (the result's `folds`), checked by the engine over its own pose set plus any `poses`, each of which a `FOLD` line names by its settings, not its PNG name: a `FOLD` line per warp deformer or mesh part that flips (ratio <= 0) or collapses (under 0.1) at some pose \u2014 its cell or triangle, the ratio of its area there to at rest, the pose as its parameter settings (`rest` for none) and where it rests, in model space and in model px from the top-left (the layer PNGs' own pixels, not a render's) \u2014 or `FOLDS: none over N poses`, then a `FOLDS expected:` line naming the closures the rig draws on purpose (an eye or the mouth shut), each by part id, ratio and the parameter that shuts it. Report-only: a fold never fails the render. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output of the model's own rigs \u2014 `poses` do not enter it \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. Fails with INVALID when no browser is found or an input is refused; a browser that cannot start is a tool error.",
|
|
5015
5956
|
inputSchema: {
|
|
5016
5957
|
modelPath: import_zod.z.string().describe(
|
|
5017
5958
|
"Rigged .iki file path (resolved against cwd; must sit under the working directory)."
|
|
@@ -5040,7 +5981,8 @@ function createIkiMcpServer() {
|
|
|
5040
5981
|
const r = await renderPoses(args);
|
|
5041
5982
|
const text = r.ok ? [
|
|
5042
5983
|
...r.poses.map((p) => p.path),
|
|
5043
|
-
...formatFoldReport(r.folds, r.modelCanvas)
|
|
5984
|
+
...formatFoldReport(r.folds, r.modelCanvas),
|
|
5985
|
+
...formatPhysicsReport(r.physics)
|
|
5044
5986
|
].join("\n") : `INVALID: ${r.error}`;
|
|
5045
5987
|
return { content: [{ type: "text", text }], structuredContent: r };
|
|
5046
5988
|
} catch (err) {
|
|
@@ -5065,6 +6007,7 @@ function createIkiMcpServer() {
|
|
|
5065
6007
|
describeIkiAt,
|
|
5066
6008
|
formatFoldReport,
|
|
5067
6009
|
formatMeasureReport,
|
|
6010
|
+
formatPhysicsReport,
|
|
5068
6011
|
formatTurnReport,
|
|
5069
6012
|
listStandardParameters,
|
|
5070
6013
|
measureLayers,
|