@ikijs/mcp 0.8.0 → 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/README.md +2 -2
- package/dist/{chunk-JPWDKP43.mjs → chunk-R6LYJVYC.mjs} +80 -6
- package/dist/chunk-R6LYJVYC.mjs.map +1 -0
- package/dist/cli.js +79 -5
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +34 -9
- package/dist/index.d.ts +34 -9
- package/dist/index.js +79 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-JPWDKP43.mjs.map +0 -1
package/dist/cli.mjs
CHANGED
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
|
|
|
@@ -99,10 +99,12 @@ type AutoRigResult = {
|
|
|
99
99
|
* `headHalfWidth`, per side, each with its own rest x there (canvas px)
|
|
100
100
|
* — present only when `headHalfWidthApplied` is true, since the
|
|
101
101
|
* fallback path has no measured edge to report at all. Passed to the
|
|
102
|
-
* generator so it can land each candidate through its OWN
|
|
103
|
-
* (hair_front's
|
|
104
|
-
*
|
|
105
|
-
*
|
|
102
|
+
* generator so it can land each candidate through its OWN motion
|
|
103
|
+
* (hair_front's silhouette hold, a turn group's grid for the face and
|
|
104
|
+
* its features, the body's own turn translate; `hair_back` holds the
|
|
105
|
+
* outline and lands where it rests, and a role outside that table is
|
|
106
|
+
* refused) and take the outermost LANDING, not just the outermost
|
|
107
|
+
* REST pixel. */
|
|
106
108
|
headEdges?: {
|
|
107
109
|
left: {
|
|
108
110
|
role: string;
|
|
@@ -113,9 +115,25 @@ type AutoRigResult = {
|
|
|
113
115
|
x: number;
|
|
114
116
|
}[];
|
|
115
117
|
};
|
|
116
|
-
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
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. */
|
|
119
137
|
turn?: TurnSolveReport;
|
|
120
138
|
} | {
|
|
121
139
|
ok: false;
|
|
@@ -129,7 +147,14 @@ type AutoRigResult = {
|
|
|
129
147
|
*
|
|
130
148
|
* The head turn is fitted to `input.turnTargets`, on the head half-width this
|
|
131
149
|
* measures off the layers themselves; what the solve settled on comes back in
|
|
132
|
-
* `turn`.
|
|
150
|
+
* `turn`. The face layer alone also gets its per-row painted half-widths
|
|
151
|
+
* (`LayerInput.rowHalfWidths`), which bend the face plate on a row-dependent
|
|
152
|
+
* radius: the generator reads no other role's, so measuring any other layer's
|
|
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.
|
|
133
158
|
*
|
|
134
159
|
* Re-host of examples/editor/src/store.ts `importLayerSet` with the three DOM
|
|
135
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
|
|
|
@@ -99,10 +99,12 @@ type AutoRigResult = {
|
|
|
99
99
|
* `headHalfWidth`, per side, each with its own rest x there (canvas px)
|
|
100
100
|
* — present only when `headHalfWidthApplied` is true, since the
|
|
101
101
|
* fallback path has no measured edge to report at all. Passed to the
|
|
102
|
-
* generator so it can land each candidate through its OWN
|
|
103
|
-
* (hair_front's
|
|
104
|
-
*
|
|
105
|
-
*
|
|
102
|
+
* generator so it can land each candidate through its OWN motion
|
|
103
|
+
* (hair_front's silhouette hold, a turn group's grid for the face and
|
|
104
|
+
* its features, the body's own turn translate; `hair_back` holds the
|
|
105
|
+
* outline and lands where it rests, and a role outside that table is
|
|
106
|
+
* refused) and take the outermost LANDING, not just the outermost
|
|
107
|
+
* REST pixel. */
|
|
106
108
|
headEdges?: {
|
|
107
109
|
left: {
|
|
108
110
|
role: string;
|
|
@@ -113,9 +115,25 @@ type AutoRigResult = {
|
|
|
113
115
|
x: number;
|
|
114
116
|
}[];
|
|
115
117
|
};
|
|
116
|
-
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
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. */
|
|
119
137
|
turn?: TurnSolveReport;
|
|
120
138
|
} | {
|
|
121
139
|
ok: false;
|
|
@@ -129,7 +147,14 @@ type AutoRigResult = {
|
|
|
129
147
|
*
|
|
130
148
|
* The head turn is fitted to `input.turnTargets`, on the head half-width this
|
|
131
149
|
* measures off the layers themselves; what the solve settled on comes back in
|
|
132
|
-
* `turn`.
|
|
150
|
+
* `turn`. The face layer alone also gets its per-row painted half-widths
|
|
151
|
+
* (`LayerInput.rowHalfWidths`), which bend the face plate on a row-dependent
|
|
152
|
+
* radius: the generator reads no other role's, so measuring any other layer's
|
|
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.
|
|
133
158
|
*
|
|
134
159
|
* Re-host of examples/editor/src/store.ts `importLayerSet` with the three DOM
|
|
135
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,17 +872,20 @@ 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 });
|
|
883
|
-
|
|
887
|
+
if (ownMask !== void 0) hairFrontMask = ownMask;
|
|
888
|
+
const layer = {
|
|
884
889
|
role,
|
|
885
890
|
fileName,
|
|
886
891
|
canvasW,
|
|
@@ -888,7 +893,17 @@ async function autoRigFromLayers(input) {
|
|
|
888
893
|
bbox,
|
|
889
894
|
cropW: bbox.w,
|
|
890
895
|
cropH: bbox.h
|
|
891
|
-
}
|
|
896
|
+
};
|
|
897
|
+
if (role === "face") {
|
|
898
|
+
const rowHalfWidths = [];
|
|
899
|
+
for (let y = bbox.y; y < bbox.y + bbox.h; y++) {
|
|
900
|
+
rowHalfWidths.push(
|
|
901
|
+
rowRight[y] >= rowLeft[y] ? headHalfOf({ left: rowLeft[y], right: rowRight[y] }) : 0
|
|
902
|
+
);
|
|
903
|
+
}
|
|
904
|
+
layer.rowHalfWidths = rowHalfWidths;
|
|
905
|
+
}
|
|
906
|
+
layerInputs.push(layer);
|
|
892
907
|
crops.push({ id: role, buffer, width: bbox.w, height: bbox.h });
|
|
893
908
|
}
|
|
894
909
|
const eyeRow = eyeRowOf(layerInputs);
|
|
@@ -915,6 +930,63 @@ async function autoRigFromLayers(input) {
|
|
|
915
930
|
}
|
|
916
931
|
headEdges = { left, right };
|
|
917
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
|
+
}
|
|
918
990
|
let turn;
|
|
919
991
|
let model;
|
|
920
992
|
try {
|
|
@@ -934,7 +1006,8 @@ async function autoRigFromLayers(input) {
|
|
|
934
1006
|
onTurnSolved: (report) => {
|
|
935
1007
|
turn = report;
|
|
936
1008
|
},
|
|
937
|
-
...headEdges === void 0 ? {} : { headEdges }
|
|
1009
|
+
...headEdges === void 0 ? {} : { headEdges },
|
|
1010
|
+
...strandEdges === void 0 ? {} : { strandEdges }
|
|
938
1011
|
}
|
|
939
1012
|
);
|
|
940
1013
|
} catch (e) {
|
|
@@ -981,6 +1054,7 @@ async function autoRigFromLayers(input) {
|
|
|
981
1054
|
...headHalfWidth === void 0 ? {} : { headHalfWidth },
|
|
982
1055
|
headHalfWidthApplied,
|
|
983
1056
|
...headEdges === void 0 ? {} : { headEdges },
|
|
1057
|
+
...strandEdges === void 0 ? {} : { strandEdges },
|
|
984
1058
|
...turn === void 0 ? {} : { turn }
|
|
985
1059
|
};
|
|
986
1060
|
} catch (err) {
|
|
@@ -1526,7 +1600,7 @@ async function composeLayersFromParts(input) {
|
|
|
1526
1600
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
1527
1601
|
var import_zod = require("zod");
|
|
1528
1602
|
function createIkiMcpServer() {
|
|
1529
|
-
const server = new import_mcp.McpServer({ name: "iki", version: "0.
|
|
1603
|
+
const server = new import_mcp.McpServer({ name: "iki", version: "0.9.0" });
|
|
1530
1604
|
server.registerTool(
|
|
1531
1605
|
"validate_iki",
|
|
1532
1606
|
{
|
|
@@ -1614,7 +1688,7 @@ function createIkiMcpServer() {
|
|
|
1614
1688
|
noseShift: import_zod.z.number().optional(),
|
|
1615
1689
|
mouthShift: import_zod.z.number().optional()
|
|
1616
1690
|
}).optional().describe(
|
|
1617
|
-
"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
|
|
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."
|
|
1618
1692
|
)
|
|
1619
1693
|
}
|
|
1620
1694
|
},
|