@ikijs/mcp 0.8.1 → 0.9.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/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  createIkiMcpServer
4
- } from "./chunk-LIWK4PQV.mjs";
4
+ } from "./chunk-R6LYJVYC.mjs";
5
5
 
6
6
  // src/cli.ts
7
7
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { TurnTargets, TurnSolveReport } from '@ikijs/editor';
1
+ import { TurnTargets, IrisStrand, TurnSolveReport } from '@ikijs/editor';
2
2
  export { TurnSolveReport } from '@ikijs/editor';
3
3
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
4
4
 
@@ -115,9 +115,25 @@ type AutoRigResult = {
115
115
  x: number;
116
116
  }[];
117
117
  };
118
- /** What the turn solve settled on — the cues the rig reaches and the
119
- * defaulted targets it had to cut down. Absent for a layer set with no
120
- * nose, which solves no turn at all. */
118
+ /** Each side's iris and the `hair_front` run it would slide under on
119
+ * the turn, as pixel edges on the row holding that iris's centre, in
120
+ * model coordinates (`IrisStrand`: canvas x minus half the canvas
121
+ * width) — measured whenever the layer set has `hair_front`, `iris_L`
122
+ * and `iris_R`, and passed to the generator as `options.strandEdges`.
123
+ * A run narrower than half that iris's painted width on the row is
124
+ * hair detail, not a strand, and is skipped as if clear. A side is
125
+ * absent only when its iris has no opaque pixel on that row, or when no
126
+ * run it keeps covers the pixel on that side of the iris's centre or
127
+ * lies outward of it; the whole field only when neither side has one. */
128
+ strandEdges?: {
129
+ left?: IrisStrand;
130
+ right?: IrisStrand;
131
+ };
132
+ /** What the turn solve settled on — the cues the rig reaches, the
133
+ * targets it had to cut down (`clamped`) and, per side whose far iris
134
+ * the bangs' run still covers at some far stop, how much of it
135
+ * (`strandOverlap`). Absent for a layer set with no nose, which solves
136
+ * no turn at all. */
121
137
  turn?: TurnSolveReport;
122
138
  } | {
123
139
  ok: false;
@@ -134,7 +150,11 @@ type AutoRigResult = {
134
150
  * `turn`. The face layer alone also gets its per-row painted half-widths
135
151
  * (`LayerInput.rowHalfWidths`), which bend the face plate on a row-dependent
136
152
  * radius: the generator reads no other role's, so measuring any other layer's
137
- * would only hand it bytes it discards.
153
+ * would only hand it bytes it discards. Each iris's opaque span and the bangs'
154
+ * run it would slide under are measured on the iris's own centre row too
155
+ * (`strandEdges`), so the turn keeps the far iris from sliding under the bangs
156
+ * any further than it is painted; a run narrower than half the iris there is
157
+ * hair detail the iris may cross, and is skipped.
138
158
  *
139
159
  * Re-host of examples/editor/src/store.ts `importLayerSet` with the three DOM
140
160
  * pixel functions swapped for the sharp-backed ./node-images helpers; the pure
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { TurnTargets, TurnSolveReport } from '@ikijs/editor';
1
+ import { TurnTargets, IrisStrand, TurnSolveReport } from '@ikijs/editor';
2
2
  export { TurnSolveReport } from '@ikijs/editor';
3
3
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
4
4
 
@@ -115,9 +115,25 @@ type AutoRigResult = {
115
115
  x: number;
116
116
  }[];
117
117
  };
118
- /** What the turn solve settled on — the cues the rig reaches and the
119
- * defaulted targets it had to cut down. Absent for a layer set with no
120
- * nose, which solves no turn at all. */
118
+ /** Each side's iris and the `hair_front` run it would slide under on
119
+ * the turn, as pixel edges on the row holding that iris's centre, in
120
+ * model coordinates (`IrisStrand`: canvas x minus half the canvas
121
+ * width) — measured whenever the layer set has `hair_front`, `iris_L`
122
+ * and `iris_R`, and passed to the generator as `options.strandEdges`.
123
+ * A run narrower than half that iris's painted width on the row is
124
+ * hair detail, not a strand, and is skipped as if clear. A side is
125
+ * absent only when its iris has no opaque pixel on that row, or when no
126
+ * run it keeps covers the pixel on that side of the iris's centre or
127
+ * lies outward of it; the whole field only when neither side has one. */
128
+ strandEdges?: {
129
+ left?: IrisStrand;
130
+ right?: IrisStrand;
131
+ };
132
+ /** What the turn solve settled on — the cues the rig reaches, the
133
+ * targets it had to cut down (`clamped`) and, per side whose far iris
134
+ * the bangs' run still covers at some far stop, how much of it
135
+ * (`strandOverlap`). Absent for a layer set with no nose, which solves
136
+ * no turn at all. */
121
137
  turn?: TurnSolveReport;
122
138
  } | {
123
139
  ok: false;
@@ -134,7 +150,11 @@ type AutoRigResult = {
134
150
  * `turn`. The face layer alone also gets its per-row painted half-widths
135
151
  * (`LayerInput.rowHalfWidths`), which bend the face plate on a row-dependent
136
152
  * radius: the generator reads no other role's, so measuring any other layer's
137
- * would only hand it bytes it discards.
153
+ * would only hand it bytes it discards. Each iris's opaque span and the bangs'
154
+ * run it would slide under are measured on the iris's own centre row too
155
+ * (`strandEdges`), so the turn keeps the far iris from sliding under the bangs
156
+ * any further than it is painted; a run narrower than half the iris there is
157
+ * hair detail the iris may cross, and is skipped.
138
158
  *
139
159
  * Re-host of examples/editor/src/store.ts `importLayerSet` with the three DOM
140
160
  * pixel functions swapped for the sharp-backed ./node-images helpers; the pure
package/dist/index.js CHANGED
@@ -790,6 +790,7 @@ function facePlateHalfOf(layers) {
790
790
  }
791
791
  return face.cropW / 2;
792
792
  }
793
+ var STRAND_MIN_RUN_FRACTION = 0.5;
793
794
  async function autoRigFromLayers(input) {
794
795
  try {
795
796
  const layers = input.layers;
@@ -826,6 +827,7 @@ async function autoRigFromLayers(input) {
826
827
  const layerInputs = [];
827
828
  const crops = [];
828
829
  const rowSpansByRole = [];
830
+ let hairFrontMask;
829
831
  for (let i = 0; i < resolvedLayers.length; i++) {
830
832
  const { resolved, fileName } = resolvedLayers[i];
831
833
  const png = await decodePng(resolved);
@@ -870,16 +872,19 @@ async function autoRigFromLayers(input) {
870
872
  const buffer = await cropToBuffer(png.rgba, png.width, png.height, bbox);
871
873
  const rowLeft = new Int32Array(canvasH).fill(canvasW);
872
874
  const rowRight = new Int32Array(canvasH).fill(-1);
875
+ const ownMask = role === "hair_front" ? new Uint8Array(canvasW * canvasH) : void 0;
873
876
  for (let y = 0; y < canvasH; y++) {
874
877
  for (let x = 0; x < canvasW; x++) {
875
878
  const p = y * canvasW + x;
876
879
  if (png.rgba[p * 4 + 3] < ALPHA_OPAQUE) continue;
877
880
  opaque[p] = 1;
881
+ if (ownMask !== void 0) ownMask[p] = 1;
878
882
  if (x < rowLeft[y]) rowLeft[y] = x;
879
883
  if (x > rowRight[y]) rowRight[y] = x;
880
884
  }
881
885
  }
882
886
  rowSpansByRole.push({ role, rowLeft, rowRight });
887
+ if (ownMask !== void 0) hairFrontMask = ownMask;
883
888
  const layer = {
884
889
  role,
885
890
  fileName,
@@ -925,6 +930,63 @@ async function autoRigFromLayers(input) {
925
930
  }
926
931
  headEdges = { left, right };
927
932
  }
933
+ let strandEdges;
934
+ const irisLayers = layerInputs.filter((l) => l.role === "iris_L" || l.role === "iris_R").sort((a, b) => a.bbox.x + a.bbox.w / 2 - (b.bbox.x + b.bbox.w / 2));
935
+ if (hairFrontMask !== void 0 && irisLayers.length === 2) {
936
+ const mask = hairFrontMask;
937
+ const half = canvasW / 2;
938
+ const strandOn = (iris, other, side) => {
939
+ const r = Math.floor(iris.bbox.y + iris.bbox.h / 2);
940
+ const centre = iris.bbox.x + iris.bbox.w / 2;
941
+ const otherX = other.bbox.x + other.bbox.w / 2 - half;
942
+ const c = side < 0 ? Math.ceil(centre) - 1 : Math.floor(centre);
943
+ const span2 = rowSpansByRole.find((s) => s.role === iris.role);
944
+ if (span2.rowRight[r] < span2.rowLeft[r]) return void 0;
945
+ const minRun = STRAND_MIN_RUN_FRACTION * (span2.rowRight[r] + 1 - span2.rowLeft[r]);
946
+ const strand = new Uint8Array(canvasW);
947
+ for (let a = 0; a < canvasW; ) {
948
+ if (mask[r * canvasW + a] !== 1) {
949
+ a++;
950
+ continue;
951
+ }
952
+ let b = a;
953
+ while (b < canvasW && mask[r * canvasW + b] === 1) b++;
954
+ if (b - a >= minRun) strand.fill(1, a, b);
955
+ a = b;
956
+ }
957
+ const strandAt = (x2) => x2 >= 0 && x2 < canvasW && strand[x2] === 1;
958
+ const outerBoundary = (x2) => (side < 0 ? x2 : x2 + 1) - half;
959
+ let x = c;
960
+ let runFace;
961
+ if (!strandAt(c)) {
962
+ while (x >= 0 && x < canvasW && !strandAt(x)) x += side;
963
+ if (x < 0 || x >= canvasW) return void 0;
964
+ runFace = outerBoundary(x - side);
965
+ } else {
966
+ let f = c - side;
967
+ while (strandAt(f)) f -= side;
968
+ const face = outerBoundary(f);
969
+ runFace = side * (face - otherX) > 0 ? face : null;
970
+ }
971
+ while (strandAt(x)) x += side;
972
+ return {
973
+ y: canvasH / 2 - (r + 0.5),
974
+ irisOuter: (side < 0 ? span2.rowLeft[r] : span2.rowRight[r] + 1) - half,
975
+ irisInner: (side < 0 ? span2.rowRight[r] + 1 : span2.rowLeft[r]) - half,
976
+ runOuter: outerBoundary(x - side),
977
+ runFace
978
+ };
979
+ };
980
+ const [low, high] = irisLayers;
981
+ const left = strandOn(low, high, -1);
982
+ const right = strandOn(high, low, 1);
983
+ if (left !== void 0 || right !== void 0) {
984
+ strandEdges = {
985
+ ...left === void 0 ? {} : { left },
986
+ ...right === void 0 ? {} : { right }
987
+ };
988
+ }
989
+ }
928
990
  let turn;
929
991
  let model;
930
992
  try {
@@ -944,7 +1006,8 @@ async function autoRigFromLayers(input) {
944
1006
  onTurnSolved: (report) => {
945
1007
  turn = report;
946
1008
  },
947
- ...headEdges === void 0 ? {} : { headEdges }
1009
+ ...headEdges === void 0 ? {} : { headEdges },
1010
+ ...strandEdges === void 0 ? {} : { strandEdges }
948
1011
  }
949
1012
  );
950
1013
  } catch (e) {
@@ -991,6 +1054,7 @@ async function autoRigFromLayers(input) {
991
1054
  ...headHalfWidth === void 0 ? {} : { headHalfWidth },
992
1055
  headHalfWidthApplied,
993
1056
  ...headEdges === void 0 ? {} : { headEdges },
1057
+ ...strandEdges === void 0 ? {} : { strandEdges },
994
1058
  ...turn === void 0 ? {} : { turn }
995
1059
  };
996
1060
  } catch (err) {
@@ -1536,7 +1600,7 @@ async function composeLayersFromParts(input) {
1536
1600
  var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
1537
1601
  var import_zod = require("zod");
1538
1602
  function createIkiMcpServer() {
1539
- const server = new import_mcp.McpServer({ name: "iki", version: "0.8.1" });
1603
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.9.0" });
1540
1604
  server.registerTool(
1541
1605
  "validate_iki",
1542
1606
  {
@@ -1624,7 +1688,7 @@ function createIkiMcpServer() {
1624
1688
  noseShift: import_zod.z.number().optional(),
1625
1689
  mouthShift: import_zod.z.number().optional()
1626
1690
  }).optional().describe(
1627
- "What the head turn is fitted to, as `measure_turn_reference` reports it off a front/turned reference pair. `eyeShift` (and the optional `noseShift`/`mouthShift`, derived from it when absent) is how far that feature slides across the head at full turn, as a fraction of the head's half-width \u2014 a MAGNITUDE: the rig turns both ways, so the sign is ignored. `farEyeRatio` is the far/near eye width at full turn over that same ratio at rest, `silhouetteRatio` the head's half-width turned over at rest. The half-width the shifts are fractions of is measured off the layers themselves, so it is not an input. An omitted field falls back to a default, which is clamped to what this layer set can do (the result's `turn.clamped` lists the ones that were, `turn.achieved` what the rig reaches); a target you DO pass that this layer set cannot reach comes back as `INVALID: \u2026` naming the field and the attainable range, since it is a measurement rather than a preference."
1691
+ "What the head turn is fitted to, as `measure_turn_reference` reports it off a front/turned reference pair. `eyeShift` (and the optional `noseShift`/`mouthShift`, derived from it when absent) is how far that feature slides across the head at full turn, as a fraction of the head's half-width \u2014 a MAGNITUDE: the rig turns both ways, so the sign is ignored. `farEyeRatio` is the far/near eye width at full turn over that same ratio at rest, `silhouetteRatio` the head's half-width turned over at rest. The half-width the shifts are fractions of is measured off the layers themselves, so it is not an input. An omitted field falls back to a default, which is clamped to what this layer set can do, and so is a passed `eyeShift` past the room the art leaves the far eye \u2014 the face plate's edge, or the bangs' side strand over the far iris (the result's `turn.clamped` lists every clamped field, `turn.achieved` what the rig reaches, and `turn.strandOverlap` how much of a far iris the bangs still cover). Any other passed target this layer set cannot reach, including an `eyeShift` smaller than the slide the face's own turn already gives the eyes, comes back as `INVALID: \u2026` naming the field and the attainable range, since it is a measurement rather than a preference."
1628
1692
  )
1629
1693
  }
1630
1694
  },