@ikijs/mcp 0.4.0 → 0.6.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-F5RUDS6T.mjs → chunk-JTK6HWKT.mjs} +261 -26
- package/dist/chunk-JTK6HWKT.mjs.map +1 -0
- package/dist/cli.js +260 -25
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +260 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-F5RUDS6T.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -284,11 +284,14 @@ declare const DEFAULT_LAYOUT: {
|
|
|
284
284
|
};
|
|
285
285
|
};
|
|
286
286
|
type Role = keyof typeof DEFAULT_LAYOUT;
|
|
287
|
+
/** A written layer's role: a placed part, or the nose cut out of the face. */
|
|
288
|
+
type LayerRole = Role | "nose";
|
|
287
289
|
/** Per-role placement overrides; anything omitted keeps the default above. */
|
|
288
290
|
type LayoutOverride = Partial<Record<Role, {
|
|
289
291
|
cx?: number;
|
|
290
292
|
cy?: number;
|
|
291
293
|
w?: number;
|
|
294
|
+
h?: number;
|
|
292
295
|
}>>;
|
|
293
296
|
interface ComposeInput {
|
|
294
297
|
/** Directory of the generated part PNGs (relative paths resolve against cwd). */
|
|
@@ -303,7 +306,7 @@ interface ComposeInput {
|
|
|
303
306
|
layout?: LayoutOverride;
|
|
304
307
|
}
|
|
305
308
|
interface ComposedLayer {
|
|
306
|
-
role:
|
|
309
|
+
role: LayerRole;
|
|
307
310
|
path: string;
|
|
308
311
|
/** Size of the placed part itself (the file is always CANVAS x CANVAS). */
|
|
309
312
|
width: number;
|
|
@@ -315,8 +318,9 @@ type ComposeResult = {
|
|
|
315
318
|
ok: true;
|
|
316
319
|
outDir: string;
|
|
317
320
|
layers: ComposedLayer[];
|
|
318
|
-
/** Roles whose optional part was absent from the parts dir
|
|
319
|
-
|
|
321
|
+
/** Roles whose optional part was absent from the parts dir — and `nose`
|
|
322
|
+
* when the face had no drawn nose to cut. */
|
|
323
|
+
skipped: LayerRole[];
|
|
320
324
|
preview: string;
|
|
321
325
|
measure: MeasureReport;
|
|
322
326
|
} | {
|
package/dist/index.d.ts
CHANGED
|
@@ -284,11 +284,14 @@ declare const DEFAULT_LAYOUT: {
|
|
|
284
284
|
};
|
|
285
285
|
};
|
|
286
286
|
type Role = keyof typeof DEFAULT_LAYOUT;
|
|
287
|
+
/** A written layer's role: a placed part, or the nose cut out of the face. */
|
|
288
|
+
type LayerRole = Role | "nose";
|
|
287
289
|
/** Per-role placement overrides; anything omitted keeps the default above. */
|
|
288
290
|
type LayoutOverride = Partial<Record<Role, {
|
|
289
291
|
cx?: number;
|
|
290
292
|
cy?: number;
|
|
291
293
|
w?: number;
|
|
294
|
+
h?: number;
|
|
292
295
|
}>>;
|
|
293
296
|
interface ComposeInput {
|
|
294
297
|
/** Directory of the generated part PNGs (relative paths resolve against cwd). */
|
|
@@ -303,7 +306,7 @@ interface ComposeInput {
|
|
|
303
306
|
layout?: LayoutOverride;
|
|
304
307
|
}
|
|
305
308
|
interface ComposedLayer {
|
|
306
|
-
role:
|
|
309
|
+
role: LayerRole;
|
|
307
310
|
path: string;
|
|
308
311
|
/** Size of the placed part itself (the file is always CANVAS x CANVAS). */
|
|
309
312
|
width: number;
|
|
@@ -315,8 +318,9 @@ type ComposeResult = {
|
|
|
315
318
|
ok: true;
|
|
316
319
|
outDir: string;
|
|
317
320
|
layers: ComposedLayer[];
|
|
318
|
-
/** Roles whose optional part was absent from the parts dir
|
|
319
|
-
|
|
321
|
+
/** Roles whose optional part was absent from the parts dir — and `nose`
|
|
322
|
+
* when the face had no drawn nose to cut. */
|
|
323
|
+
skipped: LayerRole[];
|
|
320
324
|
preview: string;
|
|
321
325
|
measure: MeasureReport;
|
|
322
326
|
} | {
|
package/dist/index.js
CHANGED
|
@@ -535,6 +535,7 @@ var EYE_ASPECT_MIN = 0.5;
|
|
|
535
535
|
var IRIS_OFFSET_MAX_X = 3;
|
|
536
536
|
var IRIS_OFFSET_MAX_Y = 10;
|
|
537
537
|
var EDGE_SOLID_MAX = 0.5;
|
|
538
|
+
var LASH_CENTRE_TOL_FRAC = 0.03;
|
|
538
539
|
var EDGE_RUN_MIN_PX = 40;
|
|
539
540
|
var FLAT_CUT_MAX_FRAC = 0.1;
|
|
540
541
|
var FLAT_CUT_MIN_PX = 40;
|
|
@@ -639,15 +640,24 @@ async function measureDir(absDir) {
|
|
|
639
640
|
const warnings = [];
|
|
640
641
|
for (const [role, m] of Object.entries(layers)) {
|
|
641
642
|
const edges = [
|
|
642
|
-
["top", m.edgeTop, m.w],
|
|
643
|
-
["left", m.edgeLeft, m.h],
|
|
644
|
-
["right", m.edgeRight, m.h]
|
|
643
|
+
["top", m.edgeTop, m.w, m.marginTop],
|
|
644
|
+
["left", m.edgeLeft, m.h, m.marginLeft],
|
|
645
|
+
["right", m.edgeRight, m.h, m.marginRight]
|
|
645
646
|
];
|
|
646
|
-
if (role !== "body")
|
|
647
|
-
|
|
647
|
+
if (role !== "body")
|
|
648
|
+
edges.push(["bottom", m.edgeBottom, m.w, m.marginBottom]);
|
|
649
|
+
for (const [side, v, span, margin] of edges) {
|
|
648
650
|
if (v > EDGE_SOLID_MAX && v * span >= EDGE_RUN_MIN_PX) {
|
|
651
|
+
const remedy = margin === 0 ? (
|
|
652
|
+
// margin 0 is consistent with a clipped placement AND with art
|
|
653
|
+
// already cropped flush that happens to sit on the boundary, and
|
|
654
|
+
// the flattened layer cannot separate them — so name the free
|
|
655
|
+
// move rather than the cause. If moving it inward leaves the
|
|
656
|
+
// edge opaque, the drawing is the one at fault.
|
|
657
|
+
`it sits flush against the canvas ${side}, which a clipped placement and already-cropped art both produce. Move it inward first \u2014 retune layout.${role}.cx/cy/w, free \u2014 and remeasure; regenerate only if the edge is still opaque with margin to spare.`
|
|
658
|
+
) : `its own drawing runs to the frame ${margin} px inside the canvas \u2014 regenerate that part with empty margin on that side. Billed.`;
|
|
649
659
|
warnings.push(
|
|
650
|
-
`${role}: ${pct(v)} of its ${side} edge is opaque \u2014 the art is cut off there, which shows as a straight seam once the head turns.
|
|
660
|
+
`${role}: ${pct(v)} of its ${side} edge is opaque \u2014 the art is cut off there, which shows as a straight seam once the head turns. Cause: ${remedy}`
|
|
651
661
|
);
|
|
652
662
|
}
|
|
653
663
|
}
|
|
@@ -668,7 +678,7 @@ async function measureDir(absDir) {
|
|
|
668
678
|
const aspect = eye.h / eye.w;
|
|
669
679
|
if (aspect < EYE_ASPECT_MIN) {
|
|
670
680
|
warnings.push(
|
|
671
|
-
`eye_${side}: sclera aspect h/w=${aspect.toFixed(2)} is flatter than ${EYE_ASPECT_MIN} \u2014 a round iris cannot sit inside it. Regenerate the eyewhite taller
|
|
681
|
+
`eye_${side}: sclera aspect h/w=${aspect.toFixed(2)} is flatter than ${EYE_ASPECT_MIN} \u2014 a round iris cannot sit inside it. Free fix first: set layout.eye_${side}.h and layout.lash_${side}.h to ${Math.ceil(eye.w * EYE_ASPECT_MIN)} (both, or the fold tears) \u2014 stretching a flat white lens is invisible. Regenerate the eyewhite taller only if that distorts the lash.`
|
|
672
682
|
);
|
|
673
683
|
}
|
|
674
684
|
if (iris) {
|
|
@@ -689,7 +699,7 @@ async function measureDir(absDir) {
|
|
|
689
699
|
if (lash) {
|
|
690
700
|
const dx = lash.bboxCx - eye.bboxCx;
|
|
691
701
|
const dTop = lash.marginTop - eye.marginTop;
|
|
692
|
-
if (Math.abs(dx) >
|
|
702
|
+
if (Math.abs(dx) > eye.w * LASH_CENTRE_TOL_FRAC || Math.abs(dTop) > 0.5) {
|
|
693
703
|
warnings.push(
|
|
694
704
|
`lash_${side}: centre is ${dx.toFixed(1)} px and top edge ${dTop.toFixed(1)} px off eye_${side}. They are split from one source and MUST share cx/cy/w in layout, or the blink fold tears. Retune to match.`
|
|
695
705
|
);
|
|
@@ -752,6 +762,13 @@ var IRIS_W = Math.round(EYE_W * 0.5625);
|
|
|
752
762
|
var EYEWHITE_SRC = "eyewhite.png";
|
|
753
763
|
var EYE_LASH_LUMA = 120;
|
|
754
764
|
var LASH_KEEP_FRACTION = 0.5;
|
|
765
|
+
var NOSE_INK_TOL = 20;
|
|
766
|
+
var NOSE_INK_LOW = 8;
|
|
767
|
+
var NOSE_GROW = 2;
|
|
768
|
+
var NOSE_MIN_PIXELS = 12;
|
|
769
|
+
var NOSE_MAX_CUT_FRACTION = 0.25;
|
|
770
|
+
var NOSE_ROW_MIN_PIXELS = 8;
|
|
771
|
+
var NOSE_FILL_REACH = 8;
|
|
755
772
|
var DEFAULT_LAYOUT = {
|
|
756
773
|
// Back hair and body sit behind the face. Both are OPTIONAL: a parts dir
|
|
757
774
|
// without them still composes (head-only character).
|
|
@@ -835,13 +852,15 @@ function resolveLayout(overrides) {
|
|
|
835
852
|
}
|
|
836
853
|
next[field] = value;
|
|
837
854
|
}
|
|
838
|
-
|
|
839
|
-
|
|
855
|
+
for (const field of ["w", "h"]) {
|
|
856
|
+
const value = override[field];
|
|
857
|
+
if (value === void 0) continue;
|
|
858
|
+
if (!Number.isInteger(value) || value < 1 || value > CANVAS) {
|
|
840
859
|
throw new AutoRigInputError(
|
|
841
|
-
`layout.${role}
|
|
860
|
+
`layout.${role}.${field} must be an integer in 1..${CANVAS}, got ${String(value)}`
|
|
842
861
|
);
|
|
843
862
|
}
|
|
844
|
-
next
|
|
863
|
+
next[field] = value;
|
|
845
864
|
}
|
|
846
865
|
resolved[role] = next;
|
|
847
866
|
}
|
|
@@ -876,15 +895,19 @@ async function partBuffer(role, cfg, partsDir, inMemory) {
|
|
|
876
895
|
if (!cfg.noTrim) img = img.trim({ threshold: 12 });
|
|
877
896
|
if (cfg.mirror) img = img.flop();
|
|
878
897
|
const trimmed = await img.png().toBuffer({ resolveWithObject: true });
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
if (scaledH > CANVAS) {
|
|
883
|
-
throw new AutoRigInputError(
|
|
884
|
-
`layout.${role}.w: resized part ${cfg.w}x${scaledH} exceeds the ${CANVAS} canvas`
|
|
898
|
+
if (cfg.h === void 0) {
|
|
899
|
+
const scaledH = Math.round(
|
|
900
|
+
trimmed.info.height * cfg.w / trimmed.info.width
|
|
885
901
|
);
|
|
902
|
+
if (scaledH > CANVAS) {
|
|
903
|
+
throw new AutoRigInputError(
|
|
904
|
+
`layout.${role}.w: resized part ${cfg.w}x${scaledH} exceeds the ${CANVAS} canvas`
|
|
905
|
+
);
|
|
906
|
+
}
|
|
886
907
|
}
|
|
887
|
-
const resized = await (0, import_sharp2.default)(trimmed.data).resize(
|
|
908
|
+
const resized = await (0, import_sharp2.default)(trimmed.data).resize(
|
|
909
|
+
cfg.h === void 0 ? { width: cfg.w } : { width: cfg.w, height: cfg.h, fit: "fill" }
|
|
910
|
+
).png().toBuffer({ resolveWithObject: true });
|
|
888
911
|
return {
|
|
889
912
|
buf: resized.data,
|
|
890
913
|
w: resized.info.width,
|
|
@@ -957,6 +980,164 @@ async function prepEyeSplit(partsDir) {
|
|
|
957
980
|
lash: await cropToBuffer(lash, W, H, region)
|
|
958
981
|
};
|
|
959
982
|
}
|
|
983
|
+
function cutNose(rgba, box) {
|
|
984
|
+
const W = CANVAS;
|
|
985
|
+
const x0 = Math.max(0, box.x0);
|
|
986
|
+
const y0 = Math.max(0, box.y0);
|
|
987
|
+
const x1 = Math.min(W, box.x1);
|
|
988
|
+
const y1 = Math.min(W, box.y1);
|
|
989
|
+
if (x1 - x0 < 4 || y1 - y0 < 4) return null;
|
|
990
|
+
const bw = x1 - x0;
|
|
991
|
+
const bh = y1 - y0;
|
|
992
|
+
const at = (x, y) => (y * W + x) * 4;
|
|
993
|
+
const median = (v) => v.sort((a, b) => a - b)[v.length >> 1];
|
|
994
|
+
const all = [[], [], []];
|
|
995
|
+
const rows = [];
|
|
996
|
+
for (let y = y0; y < y1; y++) {
|
|
997
|
+
const row = [[], [], []];
|
|
998
|
+
for (let x = x0; x < x1; x++) {
|
|
999
|
+
const i = at(x, y);
|
|
1000
|
+
if (rgba[i + 3] === 0) continue;
|
|
1001
|
+
for (let c = 0; c < 3; c++) {
|
|
1002
|
+
row[c].push(rgba[i + c]);
|
|
1003
|
+
all[c].push(rgba[i + c]);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
rows.push(row);
|
|
1007
|
+
}
|
|
1008
|
+
const opaqueCount = all[0].length;
|
|
1009
|
+
if (opaqueCount === 0) return null;
|
|
1010
|
+
const skin = all.map(median);
|
|
1011
|
+
const skinRow = rows.map(
|
|
1012
|
+
(row) => row[0].length < NOSE_ROW_MIN_PIXELS ? skin : row.map(median)
|
|
1013
|
+
);
|
|
1014
|
+
const distAt = (i, y) => {
|
|
1015
|
+
const ref = skinRow[y - y0];
|
|
1016
|
+
return Math.max(
|
|
1017
|
+
Math.abs(rgba[i] - ref[0]),
|
|
1018
|
+
Math.abs(rgba[i + 1] - ref[1]),
|
|
1019
|
+
Math.abs(rgba[i + 2] - ref[2])
|
|
1020
|
+
);
|
|
1021
|
+
};
|
|
1022
|
+
const dist = new Uint8Array(bw * bh);
|
|
1023
|
+
const ink = new Uint8Array(bw * bh);
|
|
1024
|
+
const queue = [];
|
|
1025
|
+
let inkCount = 0;
|
|
1026
|
+
for (let y = y0; y < y1; y++) {
|
|
1027
|
+
for (let x = x0; x < x1; x++) {
|
|
1028
|
+
const i = at(x, y);
|
|
1029
|
+
if (rgba[i + 3] === 0) continue;
|
|
1030
|
+
const d = distAt(i, y);
|
|
1031
|
+
const k = (y - y0) * bw + (x - x0);
|
|
1032
|
+
dist[k] = d;
|
|
1033
|
+
if (d > NOSE_INK_TOL) {
|
|
1034
|
+
ink[k] = 1;
|
|
1035
|
+
queue.push(k);
|
|
1036
|
+
inkCount++;
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
if (inkCount < NOSE_MIN_PIXELS) return null;
|
|
1041
|
+
while (queue.length > 0) {
|
|
1042
|
+
const k = queue.pop();
|
|
1043
|
+
const kx = k % bw;
|
|
1044
|
+
const ky = (k - kx) / bw;
|
|
1045
|
+
for (let dy = -NOSE_GROW; dy <= NOSE_GROW; dy++) {
|
|
1046
|
+
for (let dx = -NOSE_GROW; dx <= NOSE_GROW; dx++) {
|
|
1047
|
+
const nx = kx + dx;
|
|
1048
|
+
const ny = ky + dy;
|
|
1049
|
+
if (nx < 0 || nx >= bw || ny < 0 || ny >= bh) continue;
|
|
1050
|
+
const n = ny * bw + nx;
|
|
1051
|
+
if (ink[n] === 0 && dist[n] > NOSE_INK_LOW) {
|
|
1052
|
+
ink[n] = 1;
|
|
1053
|
+
queue.push(n);
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
const cut = new Uint8Array(bw * bh);
|
|
1059
|
+
for (let y = 0; y < bh; y++) {
|
|
1060
|
+
for (let x = 0; x < bw; x++) {
|
|
1061
|
+
if (ink[y * bw + x] === 0) continue;
|
|
1062
|
+
for (let dy = -NOSE_GROW; dy <= NOSE_GROW; dy++) {
|
|
1063
|
+
for (let dx = -NOSE_GROW; dx <= NOSE_GROW; dx++) {
|
|
1064
|
+
const yy = y + dy;
|
|
1065
|
+
const xx = x + dx;
|
|
1066
|
+
if (yy >= 0 && yy < bh && xx >= 0 && xx < bw) cut[yy * bw + xx] = 1;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
let cutCount = 0;
|
|
1072
|
+
for (let y = 0; y < bh; y++) {
|
|
1073
|
+
for (let x = 0; x < bw; x++) {
|
|
1074
|
+
if (cut[y * bw + x] === 0) continue;
|
|
1075
|
+
const a = rgba[at(x0 + x, y0 + y) + 3];
|
|
1076
|
+
if (a === 0) continue;
|
|
1077
|
+
if (a < 255) return null;
|
|
1078
|
+
cutCount++;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
if (cutCount > NOSE_MAX_CUT_FRACTION * opaqueCount) return null;
|
|
1082
|
+
const face = Buffer.from(rgba);
|
|
1083
|
+
const nose = Buffer.from(rgba);
|
|
1084
|
+
for (let i = 3; i < nose.length; i += 4) nose[i] = 0;
|
|
1085
|
+
let minX = W;
|
|
1086
|
+
let minY = W;
|
|
1087
|
+
let maxX = -1;
|
|
1088
|
+
let maxY = -1;
|
|
1089
|
+
for (let y = 0; y < bh; y++) {
|
|
1090
|
+
const cy = y0 + y;
|
|
1091
|
+
let x = 0;
|
|
1092
|
+
while (x < bw) {
|
|
1093
|
+
if (cut[y * bw + x] === 0) {
|
|
1094
|
+
x++;
|
|
1095
|
+
continue;
|
|
1096
|
+
}
|
|
1097
|
+
const start = x;
|
|
1098
|
+
while (x < bw && cut[y * bw + x] === 1) x++;
|
|
1099
|
+
const end = x;
|
|
1100
|
+
const skinAt = (bx) => {
|
|
1101
|
+
for (let step = 0; step < NOSE_FILL_REACH && bx >= 0 && bx < bw; step++) {
|
|
1102
|
+
const i = at(x0 + bx, cy);
|
|
1103
|
+
if (rgba[i + 3] > 0 && cut[y * bw + bx] === 0) {
|
|
1104
|
+
if (distAt(i, cy) <= NOSE_INK_TOL / 2) return i;
|
|
1105
|
+
}
|
|
1106
|
+
bx += bx < start ? -1 : 1;
|
|
1107
|
+
}
|
|
1108
|
+
return -1;
|
|
1109
|
+
};
|
|
1110
|
+
const l = skinAt(start - 1);
|
|
1111
|
+
const r = skinAt(end);
|
|
1112
|
+
for (let k = start; k < end; k++) {
|
|
1113
|
+
const cx = x0 + k;
|
|
1114
|
+
const i = at(cx, cy);
|
|
1115
|
+
if (rgba[i + 3] === 0) continue;
|
|
1116
|
+
const t = (k - start + 1) / (end - start + 1);
|
|
1117
|
+
for (let c = 0; c < 3; c++) {
|
|
1118
|
+
const rowSkin = skinRow[y];
|
|
1119
|
+
const lc = l >= 0 ? rgba[l + c] : r >= 0 ? rgba[r + c] : rowSkin[c];
|
|
1120
|
+
const rc = r >= 0 ? rgba[r + c] : l >= 0 ? rgba[l + c] : rowSkin[c];
|
|
1121
|
+
face[i + c] = Math.round(lc * (1 - t) + rc * t);
|
|
1122
|
+
}
|
|
1123
|
+
nose[i] = rgba[i];
|
|
1124
|
+
nose[i + 1] = rgba[i + 1];
|
|
1125
|
+
nose[i + 2] = rgba[i + 2];
|
|
1126
|
+
nose[i + 3] = rgba[i + 3];
|
|
1127
|
+
if (cx < minX) minX = cx;
|
|
1128
|
+
if (cx > maxX) maxX = cx;
|
|
1129
|
+
if (cy < minY) minY = cy;
|
|
1130
|
+
if (cy > maxY) maxY = cy;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
if (maxX < 0) return null;
|
|
1135
|
+
return {
|
|
1136
|
+
face,
|
|
1137
|
+
nose,
|
|
1138
|
+
bbox: { x: minX, y: minY, w: maxX - minX + 1, h: maxY - minY + 1 }
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
960
1141
|
async function composeLayersFromParts(input) {
|
|
961
1142
|
try {
|
|
962
1143
|
const outDir = resolveOutputDir(input.outDir);
|
|
@@ -975,6 +1156,7 @@ async function composeLayersFromParts(input) {
|
|
|
975
1156
|
const layers = [];
|
|
976
1157
|
const skipped = [];
|
|
977
1158
|
const preview = [];
|
|
1159
|
+
let faceRaw;
|
|
978
1160
|
for (const role of ORDER) {
|
|
979
1161
|
const cfg = layout[role];
|
|
980
1162
|
const part = await partBuffer(
|
|
@@ -989,9 +1171,15 @@ async function composeLayersFromParts(input) {
|
|
|
989
1171
|
continue;
|
|
990
1172
|
}
|
|
991
1173
|
const { left, top } = placement(role, cfg, part.w, part.h);
|
|
992
|
-
const
|
|
1174
|
+
const composed = blankCanvas().composite([
|
|
1175
|
+
{ input: part.buf, left, top }
|
|
1176
|
+
]);
|
|
993
1177
|
const outPath = import_node_path4.default.join(outDir, `${role}.png`);
|
|
994
|
-
|
|
1178
|
+
if (role === "face") {
|
|
1179
|
+
faceRaw = await composed.raw().toBuffer();
|
|
1180
|
+
} else {
|
|
1181
|
+
writeFileAtomic(outPath, await composed.png().toBuffer());
|
|
1182
|
+
}
|
|
995
1183
|
layers.push({
|
|
996
1184
|
role,
|
|
997
1185
|
path: outPath,
|
|
@@ -1002,6 +1190,48 @@ async function composeLayersFromParts(input) {
|
|
|
1002
1190
|
});
|
|
1003
1191
|
preview.push({ input: part.buf, left, top });
|
|
1004
1192
|
}
|
|
1193
|
+
const placed = (role) => layers.find((l) => l.role === role);
|
|
1194
|
+
const eyeL = placed("eye_L");
|
|
1195
|
+
const eyeR = placed("eye_R");
|
|
1196
|
+
const mouth = placed("mouth");
|
|
1197
|
+
const noseCut = cutNose(faceRaw, {
|
|
1198
|
+
x0: eyeR.left + eyeR.width,
|
|
1199
|
+
x1: eyeL.left,
|
|
1200
|
+
y0: Math.round(
|
|
1201
|
+
(eyeL.top + eyeL.height / 2 + eyeR.top + eyeR.height / 2) / 2
|
|
1202
|
+
),
|
|
1203
|
+
y1: mouth.top - 2
|
|
1204
|
+
});
|
|
1205
|
+
const rawCanvas = {
|
|
1206
|
+
raw: { width: CANVAS, height: CANVAS, channels: 4 }
|
|
1207
|
+
};
|
|
1208
|
+
const facePath = import_node_path4.default.join(outDir, "face.png");
|
|
1209
|
+
const nosePath = import_node_path4.default.join(outDir, "nose.png");
|
|
1210
|
+
if (noseCut === null) {
|
|
1211
|
+
writeFileAtomic(
|
|
1212
|
+
facePath,
|
|
1213
|
+
await (0, import_sharp2.default)(faceRaw, rawCanvas).png().toBuffer()
|
|
1214
|
+
);
|
|
1215
|
+
import_node_fs3.default.rmSync(nosePath, { force: true });
|
|
1216
|
+
skipped.push("nose");
|
|
1217
|
+
} else {
|
|
1218
|
+
writeFileAtomic(
|
|
1219
|
+
facePath,
|
|
1220
|
+
await (0, import_sharp2.default)(noseCut.face, rawCanvas).png().toBuffer()
|
|
1221
|
+
);
|
|
1222
|
+
writeFileAtomic(
|
|
1223
|
+
nosePath,
|
|
1224
|
+
await (0, import_sharp2.default)(noseCut.nose, rawCanvas).png().toBuffer()
|
|
1225
|
+
);
|
|
1226
|
+
layers.splice(layers.findIndex((l) => l.role === "face") + 1, 0, {
|
|
1227
|
+
role: "nose",
|
|
1228
|
+
path: nosePath,
|
|
1229
|
+
width: noseCut.bbox.w,
|
|
1230
|
+
height: noseCut.bbox.h,
|
|
1231
|
+
left: noseCut.bbox.x,
|
|
1232
|
+
top: noseCut.bbox.y
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1005
1235
|
const previewPng = await (0, import_sharp2.default)({
|
|
1006
1236
|
create: {
|
|
1007
1237
|
width: CANVAS,
|
|
@@ -1031,7 +1261,7 @@ async function composeLayersFromParts(input) {
|
|
|
1031
1261
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
1032
1262
|
var import_zod = require("zod");
|
|
1033
1263
|
function createIkiMcpServer() {
|
|
1034
|
-
const server = new import_mcp.McpServer({ name: "iki", version: "0.
|
|
1264
|
+
const server = new import_mcp.McpServer({ name: "iki", version: "0.6.0" });
|
|
1035
1265
|
server.registerTool(
|
|
1036
1266
|
"validate_iki",
|
|
1037
1267
|
{
|
|
@@ -1132,7 +1362,7 @@ function createIkiMcpServer() {
|
|
|
1132
1362
|
server.registerTool(
|
|
1133
1363
|
"compose_layers_from_parts",
|
|
1134
1364
|
{
|
|
1135
|
-
description: "Composes AI-generated part PNGs into canvas-aligned, role-named PNG layers on disk, ready for auto_rig_from_layers (the eyewhite split, alpha-trim/white-key, and placement pipeline the character-generation skill needs), with the same geometry report measure_layers returns standalone included inline. face, mouth, eyewhite, iris, brow, hair_front are required; hair_back, body, mouth_open are optional.",
|
|
1365
|
+
description: "Composes AI-generated part PNGs into canvas-aligned, role-named PNG layers on disk, ready for auto_rig_from_layers (the eyewhite split, the nose cut out of the face so the rig can lead the turn with it, alpha-trim/white-key, and placement pipeline the character-generation skill needs), with the same geometry report measure_layers returns standalone included inline. face, mouth, eyewhite, iris, brow, hair_front are required; hair_back, body, mouth_open are optional; nose.png is cut from face.png when it has a drawn nose (reported under `skipped` otherwise).",
|
|
1136
1366
|
inputSchema: {
|
|
1137
1367
|
partsDir: import_zod.z.string().describe(
|
|
1138
1368
|
"Directory of the source part PNGs (resolved against cwd)."
|
|
@@ -1142,9 +1372,14 @@ function createIkiMcpServer() {
|
|
|
1142
1372
|
),
|
|
1143
1373
|
layout: import_zod.z.record(
|
|
1144
1374
|
import_zod.z.string(),
|
|
1145
|
-
import_zod.z.object({
|
|
1375
|
+
import_zod.z.object({
|
|
1376
|
+
cx: import_zod.z.number(),
|
|
1377
|
+
cy: import_zod.z.number(),
|
|
1378
|
+
w: import_zod.z.number(),
|
|
1379
|
+
h: import_zod.z.number()
|
|
1380
|
+
}).partial()
|
|
1146
1381
|
).optional().describe(
|
|
1147
|
-
"Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, face, mouth, mouth_open, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_front \u2014 e.g. `{ eye_L: { cx: 660 } }
|
|
1382
|
+
"Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, face, mouth, mouth_open, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_front \u2014 e.g. `{ eye_L: { cx: 660 } }`. `w` and `h` are integers in 1..1100; omit `h` to keep the part's own aspect, set it to stretch (set it on a sclera and its lash together, or the blink fold tears)."
|
|
1148
1383
|
)
|
|
1149
1384
|
}
|
|
1150
1385
|
},
|