@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.js CHANGED
@@ -774,6 +774,7 @@ function facePlateHalfOf(layers) {
774
774
  }
775
775
  return face.cropW / 2;
776
776
  }
777
+ var STRAND_MIN_RUN_FRACTION = 0.5;
777
778
  async function autoRigFromLayers(input) {
778
779
  try {
779
780
  const layers = input.layers;
@@ -810,6 +811,7 @@ async function autoRigFromLayers(input) {
810
811
  const layerInputs = [];
811
812
  const crops = [];
812
813
  const rowSpansByRole = [];
814
+ let hairFrontMask;
813
815
  for (let i = 0; i < resolvedLayers.length; i++) {
814
816
  const { resolved, fileName } = resolvedLayers[i];
815
817
  const png = await decodePng(resolved);
@@ -854,16 +856,19 @@ async function autoRigFromLayers(input) {
854
856
  const buffer = await cropToBuffer(png.rgba, png.width, png.height, bbox);
855
857
  const rowLeft = new Int32Array(canvasH).fill(canvasW);
856
858
  const rowRight = new Int32Array(canvasH).fill(-1);
859
+ const ownMask = role === "hair_front" ? new Uint8Array(canvasW * canvasH) : void 0;
857
860
  for (let y = 0; y < canvasH; y++) {
858
861
  for (let x = 0; x < canvasW; x++) {
859
862
  const p = y * canvasW + x;
860
863
  if (png.rgba[p * 4 + 3] < ALPHA_OPAQUE) continue;
861
864
  opaque[p] = 1;
865
+ if (ownMask !== void 0) ownMask[p] = 1;
862
866
  if (x < rowLeft[y]) rowLeft[y] = x;
863
867
  if (x > rowRight[y]) rowRight[y] = x;
864
868
  }
865
869
  }
866
870
  rowSpansByRole.push({ role, rowLeft, rowRight });
871
+ if (ownMask !== void 0) hairFrontMask = ownMask;
867
872
  const layer = {
868
873
  role,
869
874
  fileName,
@@ -909,6 +914,63 @@ async function autoRigFromLayers(input) {
909
914
  }
910
915
  headEdges = { left, right };
911
916
  }
917
+ let strandEdges;
918
+ 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));
919
+ if (hairFrontMask !== void 0 && irisLayers.length === 2) {
920
+ const mask = hairFrontMask;
921
+ const half = canvasW / 2;
922
+ const strandOn = (iris, other, side) => {
923
+ const r = Math.floor(iris.bbox.y + iris.bbox.h / 2);
924
+ const centre = iris.bbox.x + iris.bbox.w / 2;
925
+ const otherX = other.bbox.x + other.bbox.w / 2 - half;
926
+ const c = side < 0 ? Math.ceil(centre) - 1 : Math.floor(centre);
927
+ const span2 = rowSpansByRole.find((s) => s.role === iris.role);
928
+ if (span2.rowRight[r] < span2.rowLeft[r]) return void 0;
929
+ const minRun = STRAND_MIN_RUN_FRACTION * (span2.rowRight[r] + 1 - span2.rowLeft[r]);
930
+ const strand = new Uint8Array(canvasW);
931
+ for (let a = 0; a < canvasW; ) {
932
+ if (mask[r * canvasW + a] !== 1) {
933
+ a++;
934
+ continue;
935
+ }
936
+ let b = a;
937
+ while (b < canvasW && mask[r * canvasW + b] === 1) b++;
938
+ if (b - a >= minRun) strand.fill(1, a, b);
939
+ a = b;
940
+ }
941
+ const strandAt = (x2) => x2 >= 0 && x2 < canvasW && strand[x2] === 1;
942
+ const outerBoundary = (x2) => (side < 0 ? x2 : x2 + 1) - half;
943
+ let x = c;
944
+ let runFace;
945
+ if (!strandAt(c)) {
946
+ while (x >= 0 && x < canvasW && !strandAt(x)) x += side;
947
+ if (x < 0 || x >= canvasW) return void 0;
948
+ runFace = outerBoundary(x - side);
949
+ } else {
950
+ let f = c - side;
951
+ while (strandAt(f)) f -= side;
952
+ const face = outerBoundary(f);
953
+ runFace = side * (face - otherX) > 0 ? face : null;
954
+ }
955
+ while (strandAt(x)) x += side;
956
+ return {
957
+ y: canvasH / 2 - (r + 0.5),
958
+ irisOuter: (side < 0 ? span2.rowLeft[r] : span2.rowRight[r] + 1) - half,
959
+ irisInner: (side < 0 ? span2.rowRight[r] + 1 : span2.rowLeft[r]) - half,
960
+ runOuter: outerBoundary(x - side),
961
+ runFace
962
+ };
963
+ };
964
+ const [low, high] = irisLayers;
965
+ const left = strandOn(low, high, -1);
966
+ const right = strandOn(high, low, 1);
967
+ if (left !== void 0 || right !== void 0) {
968
+ strandEdges = {
969
+ ...left === void 0 ? {} : { left },
970
+ ...right === void 0 ? {} : { right }
971
+ };
972
+ }
973
+ }
912
974
  let turn;
913
975
  let model;
914
976
  try {
@@ -928,7 +990,8 @@ async function autoRigFromLayers(input) {
928
990
  onTurnSolved: (report) => {
929
991
  turn = report;
930
992
  },
931
- ...headEdges === void 0 ? {} : { headEdges }
993
+ ...headEdges === void 0 ? {} : { headEdges },
994
+ ...strandEdges === void 0 ? {} : { strandEdges }
932
995
  }
933
996
  );
934
997
  } catch (e) {
@@ -975,6 +1038,7 @@ async function autoRigFromLayers(input) {
975
1038
  ...headHalfWidth === void 0 ? {} : { headHalfWidth },
976
1039
  headHalfWidthApplied,
977
1040
  ...headEdges === void 0 ? {} : { headEdges },
1041
+ ...strandEdges === void 0 ? {} : { strandEdges },
978
1042
  ...turn === void 0 ? {} : { turn }
979
1043
  };
980
1044
  } catch (err) {
@@ -1518,7 +1582,7 @@ async function composeLayersFromParts(input) {
1518
1582
 
1519
1583
  // src/server.ts
1520
1584
  function createIkiMcpServer() {
1521
- const server = new import_mcp.McpServer({ name: "iki", version: "0.8.1" });
1585
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.9.0" });
1522
1586
  server.registerTool(
1523
1587
  "validate_iki",
1524
1588
  {
@@ -1606,7 +1670,7 @@ function createIkiMcpServer() {
1606
1670
  noseShift: import_zod.z.number().optional(),
1607
1671
  mouthShift: import_zod.z.number().optional()
1608
1672
  }).optional().describe(
1609
- "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."
1673
+ "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."
1610
1674
  )
1611
1675
  }
1612
1676
  },