@ikijs/mcp 0.33.1 → 0.34.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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { TurnTargets, RigPlan, RigPatch, IrisStrand, TurnSolveReport, PatchReport, RigPlanReport, RigPlanField } from '@ikijs/editor';
1
+ import { CustomPart, TurnTargets, RigPlan, RigPatch, RigBakes, IrisStrand, TurnSolveReport, PatchReport, RigPlanReport, RigPlanField } from '@ikijs/editor';
2
2
  export { RigPlanReport, TurnSolveReport } from '@ikijs/editor';
3
3
  import { IkiModel } from '@ikijs/format';
4
4
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
@@ -118,6 +118,226 @@ interface PhysicsReport {
118
118
  offenders: PhysicsTarget[];
119
119
  }
120
120
 
121
+ /**
122
+ * What `auto_rig_from_layers` checks of `bakes` before it writes the rig: each
123
+ * baked custom part landed through the engine's own `landParts` at every stop
124
+ * and at the parameter's range ends where it holds the outermost stop, against
125
+ * the displacement the generator was asked for. The generator solves its
126
+ * offsets in closed form, so this is the check that the closed form and the
127
+ * player agree on the written model.
128
+ */
129
+
130
+ /** One baked part on one parameter, as the engine lands it. */
131
+ interface BakeCheck {
132
+ part: string;
133
+ param: string;
134
+ vertices: number;
135
+ /** The stops written, ascending (rest, implicit, is not among them). */
136
+ stops: number[];
137
+ /** The largest gap, over the part's vertices and the stops, between the
138
+ * displacement the bake asked for and the engine's, in canvas px. */
139
+ errorPx: number;
140
+ }
141
+
142
+ /**
143
+ * `probe_rig`: measuring a rigged model without rendering it. Where a point of
144
+ * a part lands in a pose, how far that is from where it rests, and the opaque
145
+ * runs of a layer PNG — the numbers a rigging program (or an agent checking
146
+ * a custom part) needs and a picture cannot give exactly.
147
+ *
148
+ * The landing is the engine's own `landParts`, so it is what the player draws.
149
+ * Frame: canvas px, origin top-left, x right, y down — the frame of the layer
150
+ * PNGs and of `describe_iki`'s boxes.
151
+ */
152
+
153
+ type ProbePoint = [number, number];
154
+ type ProbeQuery = {
155
+ op: "paint";
156
+ path: string;
157
+ } | {
158
+ op: "land" | "displacement";
159
+ part: string;
160
+ points: ProbePoint[];
161
+ pose?: Record<string, number>;
162
+ };
163
+ interface ProbeInput {
164
+ /** The rigged `.iki` to measure (resolved against cwd, under it). */
165
+ modelPath: string;
166
+ queries: ProbeQuery[];
167
+ /** A `.probe.json` under the working directory to write the results to. */
168
+ outputPath?: string;
169
+ }
170
+ /**
171
+ * The opaque (alpha >= 128) runs of a layer per canvas row. `rows[i]` holds
172
+ * the `[x0, x1)` runs (`x1` exclusive) of canvas row `y0 + i`; a row inside the
173
+ * painted range with none is `[]`. A layer with no opaque pixel gives
174
+ * `{ y0: 0, rows: [] }`.
175
+ */
176
+ interface PaintRuns {
177
+ y0: number;
178
+ rows: [number, number][][];
179
+ }
180
+ type ProbeQueryResult = ({
181
+ op: "paint";
182
+ } & PaintRuns) | {
183
+ op: "land" | "displacement";
184
+ part: string;
185
+ /** One per input point; `null` for a point outside the part's mesh. */
186
+ points: (ProbePoint | null)[];
187
+ };
188
+ type ProbeResult = {
189
+ ok: true;
190
+ results: ProbeQueryResult[];
191
+ } | {
192
+ ok: true;
193
+ outputPath: string;
194
+ lines: string[];
195
+ } | {
196
+ ok: false;
197
+ error: string;
198
+ };
199
+ /**
200
+ * Measure the model. Only caller-input failures (`AutoRigInputError`,
201
+ * `IkiFormatError`) come back as `{ ok: false, error }`. With `outputPath` the
202
+ * results go to that file and the return carries a line per query instead.
203
+ */
204
+ declare function probeRig(input: ProbeInput): Promise<ProbeResult>;
205
+
206
+ /**
207
+ * The per-part gate for custom parts, reported by `auto_rig_from_layers` and
208
+ * blocking the character loop's candidate: each custom part measured over a
209
+ * pose set for whether it folds, stays tied where it hangs from its anchor,
210
+ * keeps the art it hides hidden, and (rigid parts) does not bend.
211
+ *
212
+ * Every landing is the engine's own `landParts`, through `probe.ts`'s rest
213
+ * triangles, so the numbers are what the player draws. Lengths are in face
214
+ * widths (the `face` part's width), so nothing is tied to one canvas; the
215
+ * values are experiment C's gate over twin's 402 px face. Frame: canvas px,
216
+ * origin top-left, x right, y down.
217
+ */
218
+
219
+ /** A custom part as the gate reads it. */
220
+ interface CustomGatePart {
221
+ id: string;
222
+ /** The role the part is fixed against; its first part is the anchor. */
223
+ anchor: string;
224
+ /** Where the part meets the anchor, canvas px. */
225
+ tie: [number, number];
226
+ rigid?: boolean;
227
+ }
228
+ interface CustomGateOptions {
229
+ /** Replaces the default pose set (`RIGID` still adds its stop midpoints). */
230
+ poses?: FoldPose[];
231
+ }
232
+ /**
233
+ * In face widths (squared for `EXPOSED`). Each is experiment C's gate v2 over
234
+ * twin's 402 px face, the only evidence there is, as a share of that face:
235
+ * `tie` 2 px, `slide` 40 px, `onAnchor` 6 px, `exposed` 150 px², `rigid` 1 px.
236
+ * The fold limit is the engine's own collapse threshold, read from its report.
237
+ */
238
+ declare const CUSTOM_GATE_LIMITS: {
239
+ readonly tie: 0.005;
240
+ readonly slide: 0.1;
241
+ readonly onAnchor: 0.015;
242
+ readonly exposed: 0.0009;
243
+ readonly rigid: 0.0025;
244
+ };
245
+ type CustomGateLimits = typeof CUSTOM_GATE_LIMITS & {
246
+ fold: number;
247
+ };
248
+ /** One measure's worst reading. `value` is in face widths (squared for an
249
+ * area), the limit's unit; null where the measure has no number (a tie off
250
+ * the mesh). */
251
+ interface CustomGateReadingBase {
252
+ value: number | null;
253
+ pose: string;
254
+ limit: number;
255
+ pass: boolean;
256
+ reason?: string;
257
+ }
258
+ /** A length: `px` is the same worst value in canvas px. */
259
+ interface CustomGateReading extends CustomGateReadingBase {
260
+ px: number | null;
261
+ }
262
+ /** An area (`EXPOSED`): `px2` is the same worst value in canvas px². */
263
+ interface CustomGateAreaReading extends CustomGateReadingBase {
264
+ px2: number | null;
265
+ }
266
+ interface CustomGateTip {
267
+ param: string;
268
+ /** The part's free end at the parameter's two ends, min then max. */
269
+ ends: {
270
+ value: number;
271
+ /** Canvas px. */
272
+ landed: ProbePoint | null;
273
+ /** The same point with the part's warps removed (its deformer alone), canvas px. */
274
+ bare: ProbePoint | null;
275
+ /** Distance from `bare` to `landed`, canvas px. */
276
+ fromBare: number | null;
277
+ }[];
278
+ /** Between the two landed positions, canvas px. */
279
+ travel: number | null;
280
+ }
281
+ interface CustomGatePartReport {
282
+ id: string;
283
+ anchor: string;
284
+ folds: {
285
+ ratio: number;
286
+ pose: string;
287
+ limit: number;
288
+ pass: boolean;
289
+ reason?: string;
290
+ };
291
+ tie: CustomGateReading;
292
+ slide: {
293
+ slide: CustomGateReading;
294
+ onAnchor: CustomGateReading;
295
+ /** How many poses of the set turn the head; 0 leaves both at 0. */
296
+ turningPoses: number;
297
+ pass: boolean;
298
+ };
299
+ exposed: {
300
+ /** Pixels both layers paint within 0.15 face widths of the tie. */
301
+ hiddenPx: number;
302
+ /** Where the head does not turn: limited. */
303
+ noTurn: CustomGateAreaReading;
304
+ /** Where it turns: reported, no limit. */
305
+ turning: {
306
+ value: number;
307
+ px2: number;
308
+ pose: string;
309
+ } | null;
310
+ pass: boolean;
311
+ };
312
+ rigid?: CustomGateReading;
313
+ tip: CustomGateTip[];
314
+ ok: boolean;
315
+ }
316
+ interface CustomGateReport {
317
+ ok: boolean;
318
+ faceWidth: number;
319
+ limits: CustomGateLimits;
320
+ poses: number;
321
+ parts: CustomGatePartReport[];
322
+ /** `<part> <LINE>` per limited line that failed, or `gate error: <message>`. */
323
+ failed: string[];
324
+ }
325
+ /** The report for a gate that threw: failed, naming the error, no parts. */
326
+ declare function failedCustomGate(model: IkiModel, error: unknown): CustomGateReport;
327
+ /**
328
+ * Measure every custom part of `model`. `paints` holds the opaque runs of each
329
+ * anchor role's layer and of each custom layer, by id. Throws `Error` on an
330
+ * inconsistent call (a part, anchor or paint the model or `paints` lacks):
331
+ * `auto_rig_from_layers` has validated those by then.
332
+ */
333
+ declare function checkCustomGate(model: IkiModel, parts: CustomGatePart[], paints: ReadonlyMap<string, PaintRuns>, options?: CustomGateOptions): CustomGateReport;
334
+ /**
335
+ * The gate as text: per part one `CUSTOM <id> <LINE>: …` line per measure
336
+ * (value in px and face widths, the pose, `pass` or `FAIL: <reason>`), then
337
+ * `CUSTOM GATE pass` or `CUSTOM GATE FAIL: <part LINE, …>`.
338
+ */
339
+ declare function formatCustomGate(report: CustomGateReport): string[];
340
+
121
341
  type ValidateResult = {
122
342
  ok: true;
123
343
  } | {
@@ -246,6 +466,21 @@ interface AutoRigInput {
246
466
  * rig, replayed on every rig of these inputs (see @ikijs/editor's
247
467
  * `RigPatch`). */
248
468
  patches?: RigPatch[];
469
+ /** Parts the auto-rigger has no role for (a twin tail, a hairpin), each from
470
+ * a canvas-sized PNG of its own, put in the model unrigged on `headDeformer`
471
+ * (see @ikijs/editor's `CustomPart`). Their pixels never reach the role
472
+ * parse or the measurements the head's width and turn are fitted to. */
473
+ customParts?: AutoRigCustomPartInput[];
474
+ /** Lattices that move the custom parts when a parameter does (see
475
+ * @ikijs/editor's `RigBakes`); needs `customParts`. The written model is
476
+ * landed through the engine and refused (`BAKE ERROR`, nothing written) when
477
+ * a stop is off by 0.1 px or more. */
478
+ bakes?: RigBakes;
479
+ }
480
+ /** One `customParts` entry: a `CustomPart` whose `layer` is read off `path`
481
+ * (a PNG the size of the role layers) instead of given. */
482
+ interface AutoRigCustomPartInput extends Omit<CustomPart, "layer"> {
483
+ path: string;
249
484
  }
250
485
  /** The turn cues a caller may pass, which is every one but `headHalfWidth`:
251
486
  * the pixels the shift fractions are fractions of are measured off the layers
@@ -259,8 +494,9 @@ type AutoRigResult = {
259
494
  height: number;
260
495
  };
261
496
  partCount: number;
262
- /** The atlas's embedded size: its data URI's length, summed over both
263
- * pages when a quantized rig puts the nose on a page of its own. */
497
+ /** The atlas's embedded size: its data URI's length, summed over
498
+ * every page: the nose's own under `quantizeColors`, and the custom
499
+ * parts' page. */
264
500
  atlasBytes: number;
265
501
  /** The head's half-width at the eye row, measured off the layers.
266
502
  * Absent when the opaque (alpha >= 128) union has no span there — a
@@ -344,10 +580,39 @@ type AutoRigResult = {
344
580
  * Always present on a rigged model; absent only from a server before
345
581
  * 0.30.0. */
346
582
  rigPlan: RigPlanReport;
583
+ /** Where each of `input.customParts` landed — present whenever
584
+ * `customParts` was passed, `[]` included, so a caller can tell this
585
+ * server from one that drops the field. `box` is the layer's alpha box
586
+ * in canvas px; `page` is the atlas page, the last one. `bakes` is
587
+ * present only when `bakes` was passed: one entry per baked part and
588
+ * parameter, as the engine lands it. `gate` is the per-part gate over
589
+ * the written model (`ok`, the limits, each part's measures); a failing
590
+ * one blocks the character loop's candidate, the model is written
591
+ * either way. Absent from a server before 0.34.0. */
592
+ customParts?: {
593
+ parts: CustomPartReport[];
594
+ bakes?: BakeCheck[];
595
+ gate: CustomGateReport;
596
+ };
347
597
  } | {
348
598
  ok: false;
349
599
  error: string;
350
600
  };
601
+ interface CustomPartReport {
602
+ id: string;
603
+ box: {
604
+ x: number;
605
+ y: number;
606
+ w: number;
607
+ h: number;
608
+ };
609
+ mesh: {
610
+ vertices: number;
611
+ triangles: number;
612
+ };
613
+ order: number;
614
+ page: number;
615
+ }
351
616
 
352
617
  /**
353
618
  * Decode role-named PNG file paths, auto-rig a model from them, atlas + embed
@@ -360,10 +625,10 @@ type AutoRigResult = {
360
625
  * and hair layers' opaque runs and the nose's dense core, returned as
361
626
  * `noseCore`); what the solve settled on comes back in `turn`. Under
362
627
  * `quantizeColors` the nose is atlased alone on a second, lossless page, which
363
- * the palette would otherwise rim; `atlasBytes` sums both pages. The
364
- * generator replays `input.patches` on the fresh rig before it validates and
365
- * reports the turn, and what each op moved comes back in `patches`; a refused
366
- * op writes nothing.
628
+ * the palette would otherwise rim; `atlasBytes` sums every page, the custom
629
+ * page included. The generator replays `input.patches` on the fresh rig before
630
+ * it validates and reports the turn, and what each op moved comes back in
631
+ * `patches`; a refused op writes nothing.
367
632
  *
368
633
  * Re-host of examples/editor/src/store.ts `importLayerSet` with the three DOM
369
634
  * pixel functions swapped for the sharp-backed ./node-images helpers; the pure
@@ -1102,6 +1367,11 @@ interface RenderPosesInput {
1102
1367
  sweep?: RequestedSweep;
1103
1368
  /** More sweeps, rendered after `sweep`, each into its own `<outDir>/<name>/`. */
1104
1369
  sweeps?: RequestedSweep[];
1370
+ /**
1371
+ * Part ids left out of the drawn frames of this call, poses and sweeps alike.
1372
+ * The reports still read the whole model.
1373
+ */
1374
+ hideParts?: string[];
1105
1375
  }
1106
1376
  interface SweepOutput {
1107
1377
  name: string;
@@ -1158,15 +1428,16 @@ declare function renderPoses(input: RenderPosesInput): Promise<RenderPosesResult
1158
1428
 
1159
1429
  /**
1160
1430
  * The sweeps `render_poses` renders on request: an eased ±30 `ParamAngleX`
1161
- * turn, or the `turn-nod` box through every `ParamAngleX` × `ParamAngleY`
1162
- * stop, with the hair physics running. This file is their pure pieces — the
1163
- * schedules, the sheet picks, the kymograph row, the flipbook template and the
1164
- * output directory — all decided in Node; the page only draws what the
1165
- * {@link SweepSpec} says. The page script imports this file for TYPES only (it
1166
- * is bundled as a browser IIFE and must never pull in `node:fs`).
1431
+ * turn, the same curve on `ParamAngleZ` (`roll`), or the `turn-nod` box through
1432
+ * every `ParamAngleX` × `ParamAngleY` stop, with the hair physics running. This
1433
+ * file is their pure pieces — the schedules, the sheet picks, the kymograph
1434
+ * row, the flipbook template and the output directory — all decided in Node;
1435
+ * the page only draws what the {@link SweepSpec} says. The page script imports
1436
+ * this file for TYPES only (it is bundled as a browser IIFE and must never pull
1437
+ * in `node:fs`).
1167
1438
  */
1168
1439
 
1169
- declare const SWEEP_PRESETS: readonly ["turn", "turn-nod"];
1440
+ declare const SWEEP_PRESETS: readonly ["turn", "turn-nod", "roll"];
1170
1441
  type SweepPreset = (typeof SWEEP_PRESETS)[number];
1171
1442
  /** What the caller asks for. */
1172
1443
  interface RequestedSweep {
@@ -1223,4 +1494,4 @@ interface SweepManifest {
1223
1494
 
1224
1495
  declare function createIkiMcpServer(): McpServer;
1225
1496
 
1226
- export { type AutoRigInput, type AutoRigLayerInput, type AutoRigResult, type AutoRigTurnTargets, type ComposeInput, type ComposeResult, type DeformerSummary, type DescribeResult, type IkiSummary, type IrisBlob, type IrisColor, type LayoutOverride, type MeasureInput, type MeasureResult, type MeasureTurnInput, type MeasureTurnResult, type NodReport, type PartSummary, type RenderPosesInput, type RenderPosesResult, type RequestedPose, type RequestedSweep, SWEEP_PRESETS, type StandardParameterInfo, type SweepManifest, type SweepPreset, type SweepReport, type TurnImageMeasure, type TurnMeasurement, type ValidateResult, autoRigFromLayers, checkModelFolds, checkNod, checkSweep, composeLayersFromParts, createIkiMcpServer, describeIki, describeIkiAt, describeRigPlan, formatFoldReport, formatHairSideReport, formatMeasureReport, formatNodReport, formatPhysicsReport, formatRigPlanReport, formatSweepReport, formatTurnReport, listStandardParameters, measureLayers, measureTurnReference, renderPoses, validateIki };
1497
+ export { type AutoRigCustomPartInput, type AutoRigInput, type AutoRigLayerInput, type AutoRigResult, type AutoRigTurnTargets, type BakeCheck, CUSTOM_GATE_LIMITS, type ComposeInput, type ComposeResult, type CustomGateAreaReading, type CustomGateLimits, type CustomGateOptions, type CustomGatePart, type CustomGatePartReport, type CustomGateReading, type CustomGateReport, type CustomGateTip, type CustomPartReport, type DeformerSummary, type DescribeResult, type IkiSummary, type IrisBlob, type IrisColor, type LayoutOverride, type MeasureInput, type MeasureResult, type MeasureTurnInput, type MeasureTurnResult, type NodReport, type PaintRuns, type PartSummary, type ProbeInput, type ProbePoint, type ProbeQuery, type ProbeQueryResult, type ProbeResult, type RenderPosesInput, type RenderPosesResult, type RequestedPose, type RequestedSweep, SWEEP_PRESETS, type StandardParameterInfo, type SweepManifest, type SweepPreset, type SweepReport, type TurnImageMeasure, type TurnMeasurement, type ValidateResult, autoRigFromLayers, checkCustomGate, checkModelFolds, checkNod, checkSweep, composeLayersFromParts, createIkiMcpServer, describeIki, describeIkiAt, describeRigPlan, failedCustomGate, formatCustomGate, formatFoldReport, formatHairSideReport, formatMeasureReport, formatNodReport, formatPhysicsReport, formatRigPlanReport, formatSweepReport, formatTurnReport, listStandardParameters, measureLayers, measureTurnReference, probeRig, renderPoses, validateIki };