@ikijs/mcp 0.18.0 → 0.19.1
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 +11 -10
- package/dist/{chunk-JKH44M2Z.mjs → chunk-RBQJ5FJA.mjs} +285 -74
- package/dist/chunk-RBQJ5FJA.mjs.map +1 -0
- package/dist/cli.js +291 -92
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +31 -6
- package/dist/index.d.ts +31 -6
- package/dist/index.js +291 -92
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
- package/dist/chunk-JKH44M2Z.mjs.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -42,10 +42,10 @@ var import_node_path = __toESM(require("path"));
|
|
|
42
42
|
var MAX_LAYERS = 64;
|
|
43
43
|
var MAX_LAYER_DIM = 4096;
|
|
44
44
|
var MAX_CANVAS_DIM = 4096;
|
|
45
|
-
var
|
|
45
|
+
var MAX_ATLAS_SIDE = 4096;
|
|
46
46
|
var MAX_INPUT_PIXELS = 4096 * 4096;
|
|
47
|
-
var MAX_TOTAL_PIXELS =
|
|
48
|
-
var MAX_OUTPUT_BYTES =
|
|
47
|
+
var MAX_TOTAL_PIXELS = 128 * 1024 * 1024;
|
|
48
|
+
var MAX_OUTPUT_BYTES = 12 * 1024 * 1024;
|
|
49
49
|
var AutoRigInputError = class extends Error {
|
|
50
50
|
constructor(message) {
|
|
51
51
|
super(message);
|
|
@@ -400,11 +400,11 @@ var STANDARD_PARAMETER_INFO = [
|
|
|
400
400
|
},
|
|
401
401
|
{
|
|
402
402
|
id: import_format.StandardParameter.ElbowLeft,
|
|
403
|
-
description: "Left elbow, degrees; positive bends the forearm the
|
|
403
|
+
description: "Left elbow, degrees; positive bends the forearm toward the body (the flexion of a hanging arm), negative a little outward (mirrored on the right)."
|
|
404
404
|
},
|
|
405
405
|
{
|
|
406
406
|
id: import_format.StandardParameter.ElbowRight,
|
|
407
|
-
description: "Right elbow, degrees; positive bends the forearm the
|
|
407
|
+
description: "Right elbow, degrees; positive bends the forearm toward the body (the flexion of a hanging arm), negative a little outward (mirrored on the left)."
|
|
408
408
|
}
|
|
409
409
|
];
|
|
410
410
|
function listStandardParameters() {
|
|
@@ -424,9 +424,13 @@ async function renderAtlasPage(crops, quantizeColors) {
|
|
|
424
424
|
const layout = (0, import_editor2.packAtlas)(
|
|
425
425
|
crops.map((c) => ({ id: c.id, width: c.width, height: c.height }))
|
|
426
426
|
);
|
|
427
|
-
|
|
427
|
+
const over = layout.pageWidth > MAX_ATLAS_SIDE ? { side: "width", crop: "widest" } : layout.pageHeight > MAX_ATLAS_SIDE ? { side: "height", crop: "tallest" } : void 0;
|
|
428
|
+
if (over !== void 0) {
|
|
429
|
+
const crop = layout.placements.reduce(
|
|
430
|
+
(a, b) => b[over.side] > a[over.side] ? b : a
|
|
431
|
+
);
|
|
428
432
|
throw new AutoRigInputError(
|
|
429
|
-
`atlas page ${layout.pageWidth}x${layout.pageHeight} exceeds max
|
|
433
|
+
`atlas page ${layout.pageWidth}x${layout.pageHeight} exceeds max side ${MAX_ATLAS_SIDE} (its ${over.crop} crop: "${crop.id}" ${crop.width}x${crop.height})`
|
|
430
434
|
);
|
|
431
435
|
}
|
|
432
436
|
const dataUri = await renderAtlasToDataUri(crops, layout, quantizeColors);
|
|
@@ -614,18 +618,89 @@ async function autoRigFromLayers(input) {
|
|
|
614
618
|
|
|
615
619
|
// src/compose.ts
|
|
616
620
|
var import_node_fs3 = __toESM(require("fs"));
|
|
617
|
-
var
|
|
618
|
-
var
|
|
619
|
-
var
|
|
621
|
+
var import_node_path6 = __toESM(require("path"));
|
|
622
|
+
var import_sharp3 = __toESM(require("sharp"));
|
|
623
|
+
var import_editor7 = require("@ikijs/editor");
|
|
620
624
|
|
|
621
625
|
// src/measure.ts
|
|
622
626
|
var import_node_fs2 = __toESM(require("fs"));
|
|
623
|
-
var
|
|
627
|
+
var import_node_path5 = __toESM(require("path"));
|
|
624
628
|
|
|
625
|
-
// src/measure-
|
|
629
|
+
// src/measure-arms.ts
|
|
626
630
|
var import_node_path3 = __toESM(require("path"));
|
|
627
631
|
var import_editor3 = require("@ikijs/editor");
|
|
632
|
+
var ARM_ROLES = ["arm_L", "arm_R"];
|
|
633
|
+
var CAP_OVERLAP = 0.5;
|
|
634
|
+
var px = (v) => `${Number(v.toFixed(1))}`;
|
|
635
|
+
async function measured(measurer, absDir, role) {
|
|
636
|
+
const fileName = `${role}.png`;
|
|
637
|
+
const { rgba } = await decodePng(import_node_path3.default.join(absDir, fileName));
|
|
638
|
+
return measurer.add({ role, fileName, rgba });
|
|
639
|
+
}
|
|
640
|
+
async function armWarnings(absDir, layers) {
|
|
641
|
+
const warnings = [];
|
|
642
|
+
const body = layers.body;
|
|
643
|
+
let set;
|
|
644
|
+
for (const arm of ARM_ROLES) {
|
|
645
|
+
const stats = layers[arm];
|
|
646
|
+
if (stats === void 0) continue;
|
|
647
|
+
if (body === void 0) {
|
|
648
|
+
warnings.push(
|
|
649
|
+
`${arm}: no body layer \u2014 an arm hangs from the body's shoulder, and auto_rig_from_layers refuses it.`
|
|
650
|
+
);
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
if (stats.canvasW !== body.canvasW || stats.canvasH !== body.canvasH) {
|
|
654
|
+
warnings.push(
|
|
655
|
+
`${arm}: its canvas ${stats.canvasW}x${stats.canvasH} differs from body's ${body.canvasW}x${body.canvasH} \u2014 auto_rig_from_layers refuses layers of different sizes; recompose them together.`
|
|
656
|
+
);
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
if (set === void 0) {
|
|
660
|
+
const measurer = (0, import_editor3.createLayerSetMeasurer)({
|
|
661
|
+
width: body.canvasW,
|
|
662
|
+
height: body.canvasH
|
|
663
|
+
});
|
|
664
|
+
set = { measurer, body: await measured(measurer, absDir, "body") };
|
|
665
|
+
}
|
|
666
|
+
let g;
|
|
667
|
+
try {
|
|
668
|
+
g = (0, import_editor3.armGeometry)(
|
|
669
|
+
await measured(set.measurer, absDir, arm),
|
|
670
|
+
set.body.bbox.x + set.body.bbox.w / 2 - body.canvasW / 2
|
|
671
|
+
);
|
|
672
|
+
} catch (err) {
|
|
673
|
+
if (err instanceof import_editor3.LayerGeometryError) {
|
|
674
|
+
warnings.push(
|
|
675
|
+
`${arm}: ${err.message} \u2014 auto_rig_from_layers refuses it. Regenerate arm.png drawn hanging, shoulder at the top. Billed.`
|
|
676
|
+
);
|
|
677
|
+
continue;
|
|
678
|
+
}
|
|
679
|
+
throw err;
|
|
680
|
+
}
|
|
681
|
+
const cap = capWarning(arm, g, set.body);
|
|
682
|
+
if (cap !== void 0) warnings.push(cap);
|
|
683
|
+
}
|
|
684
|
+
return warnings;
|
|
685
|
+
}
|
|
686
|
+
function capWarning(arm, g, body) {
|
|
687
|
+
const pivotX = g.shoulder.x + body.canvasW / 2;
|
|
688
|
+
const row = Math.floor(body.canvasH / 2 - g.shoulder.y);
|
|
689
|
+
const runs = body.rowRuns?.[row - body.bbox.y] ?? [];
|
|
690
|
+
if (runs.length === 0) {
|
|
691
|
+
return `${arm}: the body has no paint on its shoulder pivot's row (y=${row}) \u2014 the torso shows a gap beside the shoulder once the arm raises. Retune layout.${arm}.cy onto the shoulder (free).`;
|
|
692
|
+
}
|
|
693
|
+
const edge = g.side === 1 ? runs[runs.length - 1] : runs[0];
|
|
694
|
+
const overlap = g.shoulderRadius - g.side * (pivotX - edge);
|
|
695
|
+
const need = CAP_OVERLAP * g.shoulderRadius;
|
|
696
|
+
if (overlap >= need) return void 0;
|
|
697
|
+
return `${arm}: its shoulder cap reaches ${px(overlap)} px under the torso's edge on its pivot row (y=${row}), under half its radius (${px(need)} px) \u2014 a gap opens beside the shoulder once the arm raises. Move layout.${arm}.cx ${Math.ceil(need - overlap)} px toward the body (free).`;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// src/measure-turn.ts
|
|
701
|
+
var import_node_path4 = __toESM(require("path"));
|
|
628
702
|
var import_editor4 = require("@ikijs/editor");
|
|
703
|
+
var import_editor5 = require("@ikijs/editor");
|
|
629
704
|
var DEFAULT_IRIS = { hueMin: 230, hueMax: 300, satMin: 0.22 };
|
|
630
705
|
var IRIS_V_MIN = 0.18;
|
|
631
706
|
var IRIS_V_MAX = 0.95;
|
|
@@ -775,7 +850,7 @@ async function measureTurnImage(filePath, iris) {
|
|
|
775
850
|
let transparent = false;
|
|
776
851
|
if (hasAlpha) {
|
|
777
852
|
for (let i = 0; i < n; i++) {
|
|
778
|
-
if (rgba[i * 4 + 3] <
|
|
853
|
+
if (rgba[i * 4 + 3] < import_editor4.ALPHA_OPAQUE) {
|
|
779
854
|
transparent = true;
|
|
780
855
|
break;
|
|
781
856
|
}
|
|
@@ -786,7 +861,7 @@ async function measureTurnImage(filePath, iris) {
|
|
|
786
861
|
const fg = new Uint8Array(n);
|
|
787
862
|
const value = new Float32Array(n);
|
|
788
863
|
for (let i = 0; i < n; i++) {
|
|
789
|
-
if (rgba[i * 4 + 3] <
|
|
864
|
+
if (rgba[i * 4 + 3] < import_editor4.ALPHA_OPAQUE) continue;
|
|
790
865
|
const [hue, s, v] = rgbToHsv(rgba[i * 4], rgba[i * 4 + 1], rgba[i * 4 + 2]);
|
|
791
866
|
if (maskMode === "alpha") {
|
|
792
867
|
fg[i] = 1;
|
|
@@ -852,12 +927,12 @@ async function measureTurnImage(filePath, iris) {
|
|
|
852
927
|
}
|
|
853
928
|
const [irisL, irisR] = best.pair;
|
|
854
929
|
const eyeRow = Math.round((irisL.cy + irisR.cy) / 2);
|
|
855
|
-
const { left, right } = (0,
|
|
930
|
+
const { left, right } = (0, import_editor4.foregroundSpan)(
|
|
856
931
|
fg,
|
|
857
932
|
width,
|
|
858
933
|
height,
|
|
859
|
-
eyeRow -
|
|
860
|
-
eyeRow +
|
|
934
|
+
eyeRow - import_editor4.HEAD_BAND,
|
|
935
|
+
eyeRow + import_editor4.HEAD_BAND
|
|
861
936
|
);
|
|
862
937
|
if (right <= left) {
|
|
863
938
|
throw new AutoRigInputError(
|
|
@@ -881,7 +956,7 @@ async function measureTurnImage(filePath, iris) {
|
|
|
881
956
|
left,
|
|
882
957
|
right,
|
|
883
958
|
cx: (left + right) / 2,
|
|
884
|
-
half: (0,
|
|
959
|
+
half: (0, import_editor4.headHalfOf)({ left, right })
|
|
885
960
|
},
|
|
886
961
|
pairCx: (irisL.cx + irisR.cx) / 2,
|
|
887
962
|
eyeGap: irisR.cx - irisL.cx
|
|
@@ -896,9 +971,9 @@ function overlaySvg(m) {
|
|
|
896
971
|
return `<svg width="${m.width}" height="${m.height}">` + box(m.irisL, "#ff0000") + box(m.irisR, "#00c000") + tick(m.head.left, 40, "#0000ff") + tick(m.head.right, 40, "#0000ff") + tick(m.head.cx, 60, "#ff8800") + tick(m.pairCx, 60, "#ff00ff") + "</svg>";
|
|
897
972
|
}
|
|
898
973
|
async function writeOverlay(debugDir, label, m) {
|
|
899
|
-
const outPath =
|
|
974
|
+
const outPath = import_node_path4.default.join(
|
|
900
975
|
debugDir,
|
|
901
|
-
`${label}-${
|
|
976
|
+
`${label}-${import_node_path4.default.basename(m.file, ".png")}.debug.png`
|
|
902
977
|
);
|
|
903
978
|
writeFileAtomic(outPath, await encodeOverlayPng(m.file, overlaySvg(m)));
|
|
904
979
|
return outPath;
|
|
@@ -1063,6 +1138,7 @@ async function layerStats(filePath) {
|
|
|
1063
1138
|
};
|
|
1064
1139
|
}
|
|
1065
1140
|
var pct = (v) => `${(v * 100).toFixed(0)}%`;
|
|
1141
|
+
var isArm = (role) => ARM_ROLES.includes(role);
|
|
1066
1142
|
function noseSpeckWarning({ core, part }, source) {
|
|
1067
1143
|
const [found, consequence] = source === "compose" ? [
|
|
1068
1144
|
`the source part's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} trimmed part`,
|
|
@@ -1071,7 +1147,7 @@ function noseSpeckWarning({ core, part }, source) {
|
|
|
1071
1147
|
`the layer's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} crop`,
|
|
1072
1148
|
`auto_rig_from_layers turns and tilts the nose about its whole crop instead`
|
|
1073
1149
|
];
|
|
1074
|
-
return `nose: ${found} \u2014 under ${
|
|
1150
|
+
return `nose: ${found} \u2014 under ${import_editor5.SPECK_CORE_FRACTION} of its width or height, a speck: a lone nostril mark or highlight at alpha >= 128, not the drawing, so ${consequence}. Regenerate the nose with its shading painted denser, so the drawing itself reaches alpha 128. Billed.`;
|
|
1075
1151
|
}
|
|
1076
1152
|
async function lashOffSclera(eyePath, lashPath) {
|
|
1077
1153
|
const eye = await decodePng(eyePath);
|
|
@@ -1089,7 +1165,7 @@ async function lashOffSclera(eyePath, lashPath) {
|
|
|
1089
1165
|
return { opaque, off };
|
|
1090
1166
|
}
|
|
1091
1167
|
async function measureDir(absDir, noseSpeck) {
|
|
1092
|
-
const files = import_node_fs2.default.readdirSync(absDir).filter((f) => f.endsWith(".png") && f
|
|
1168
|
+
const files = import_node_fs2.default.readdirSync(absDir).filter((f) => f.endsWith(".png") && !f.startsWith("preview")).sort();
|
|
1093
1169
|
if (files.length === 0) {
|
|
1094
1170
|
throw new AutoRigInputError(`no role layers in ${absDir}`);
|
|
1095
1171
|
}
|
|
@@ -1101,8 +1177,8 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1101
1177
|
const layers = {};
|
|
1102
1178
|
const empty = [];
|
|
1103
1179
|
for (const f of files) {
|
|
1104
|
-
const role =
|
|
1105
|
-
const m = await layerStats(
|
|
1180
|
+
const role = import_node_path5.default.basename(f, ".png");
|
|
1181
|
+
const m = await layerStats(import_node_path5.default.join(absDir, f));
|
|
1106
1182
|
if (!m) {
|
|
1107
1183
|
empty.push(role);
|
|
1108
1184
|
continue;
|
|
@@ -1116,8 +1192,13 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1116
1192
|
["left", m.edgeLeft, m.h, m.marginLeft],
|
|
1117
1193
|
["right", m.edgeRight, m.h, m.marginRight]
|
|
1118
1194
|
];
|
|
1119
|
-
if (role !== "body")
|
|
1195
|
+
if (role !== "body") {
|
|
1120
1196
|
edges.push(["bottom", m.edgeBottom, m.w, m.marginBottom]);
|
|
1197
|
+
} else if (m.canvasH > m.canvasW && m.marginBottom === 0) {
|
|
1198
|
+
warnings.push(
|
|
1199
|
+
`body: its bottom row is the canvas's last \u2014 on a tall canvas that cuts the feet off. Free fix: raise canvasHeight (the canvas grows downward, nothing else moves) and remeasure; regenerate body.png only if the drawing itself stops short of the soles.`
|
|
1200
|
+
);
|
|
1201
|
+
}
|
|
1121
1202
|
for (const [side, v, span, margin] of edges) {
|
|
1122
1203
|
if (v > EDGE_SOLID_MAX && v * span >= EDGE_RUN_MIN_PX) {
|
|
1123
1204
|
const remedy = margin === 0 ? (
|
|
@@ -1129,7 +1210,7 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1129
1210
|
`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.`
|
|
1130
1211
|
) : `its own drawing runs to the frame ${margin} px inside the canvas \u2014 regenerate that part with empty margin on that side. Billed.`;
|
|
1131
1212
|
warnings.push(
|
|
1132
|
-
`${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}`
|
|
1213
|
+
`${role}: ${pct(v)} of its ${side} edge is opaque \u2014 the art is cut off there, which shows as a straight seam ${isArm(role) ? "once the arm raises" : "once the head turns"}. Cause: ${remedy}`
|
|
1133
1214
|
);
|
|
1134
1215
|
}
|
|
1135
1216
|
}
|
|
@@ -1138,10 +1219,11 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1138
1219
|
if (role === "body") continue;
|
|
1139
1220
|
if (m.flatCutRun > FLAT_CUT_MAX_FRAC * m.w && m.flatCutRun >= FLAT_CUT_MIN_PX) {
|
|
1140
1221
|
warnings.push(
|
|
1141
|
-
`${role}: ${m.flatCutRun}px of straight flat edge at y=${m.flatCutY} (${pct(m.flatCutRun / m.w)} of its width) \u2014 the source art is cut through there. It hides while the head faces front and opens into a seam on turn. Regenerate this part with the whole subject inside the frame.`
|
|
1222
|
+
`${role}: ${m.flatCutRun}px of straight flat edge at y=${m.flatCutY} (${pct(m.flatCutRun / m.w)} of its width) \u2014 the source art is cut through there. ` + (isArm(role) ? `It hides at rest and opens into a seam once the arm raises. ` : `It hides while the head faces front and opens into a seam on turn. `) + `Regenerate this part with the whole subject inside the frame.`
|
|
1142
1223
|
);
|
|
1143
1224
|
}
|
|
1144
1225
|
}
|
|
1226
|
+
warnings.push(...await armWarnings(absDir, layers));
|
|
1145
1227
|
for (const side of ["L", "R"]) {
|
|
1146
1228
|
const eye = layers[`eye_${side}`];
|
|
1147
1229
|
const iris = layers[`iris_${side}`];
|
|
@@ -1170,8 +1252,8 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1170
1252
|
}
|
|
1171
1253
|
if (lash) {
|
|
1172
1254
|
const { opaque, off } = await lashOffSclera(
|
|
1173
|
-
|
|
1174
|
-
|
|
1255
|
+
import_node_path5.default.join(absDir, `eye_${side}.png`),
|
|
1256
|
+
import_node_path5.default.join(absDir, `lash_${side}.png`)
|
|
1175
1257
|
);
|
|
1176
1258
|
const dTop = lash.marginTop - eye.marginTop;
|
|
1177
1259
|
const faults = [
|
|
@@ -1197,11 +1279,11 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1197
1279
|
if (noseSpeck !== void 0) {
|
|
1198
1280
|
warnings.push(noseSpeckWarning(noseSpeck, "compose"));
|
|
1199
1281
|
} else if (layers.nose !== void 0) {
|
|
1200
|
-
const nose = await decodePng(
|
|
1201
|
-
const core = (0,
|
|
1282
|
+
const nose = await decodePng(import_node_path5.default.join(absDir, "nose.png"));
|
|
1283
|
+
const core = (0, import_editor5.denseCoreOf)(nose.rgba, nose.width, nose.height);
|
|
1202
1284
|
if (core !== null) {
|
|
1203
1285
|
const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
|
|
1204
|
-
if ((0,
|
|
1286
|
+
if ((0, import_editor5.isSpeckCore)(core, crop))
|
|
1205
1287
|
warnings.push(noseSpeckWarning({ core, part: crop }, "layer"));
|
|
1206
1288
|
}
|
|
1207
1289
|
}
|
|
@@ -1258,8 +1340,54 @@ function formatMeasureReport(result) {
|
|
|
1258
1340
|
return lines.join("\n");
|
|
1259
1341
|
}
|
|
1260
1342
|
|
|
1343
|
+
// src/compose-arms.ts
|
|
1344
|
+
var import_sharp2 = __toESM(require("sharp"));
|
|
1345
|
+
var import_editor6 = require("@ikijs/editor");
|
|
1346
|
+
var ARM_WIDTH = 0.4;
|
|
1347
|
+
var SHOULDER_DROP = 0.12;
|
|
1348
|
+
async function armPlacement(role, cfg, part, body) {
|
|
1349
|
+
const { data } = await (0, import_sharp2.default)(part.buf).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
1350
|
+
const layer = (0, import_editor6.createLayerSetMeasurer)({ width: part.w, height: part.h }).add({
|
|
1351
|
+
role,
|
|
1352
|
+
fileName: "arm.png",
|
|
1353
|
+
rgba: data
|
|
1354
|
+
});
|
|
1355
|
+
if (layer === null) {
|
|
1356
|
+
throw new AutoRigInputError(
|
|
1357
|
+
`layout.${role}: arm.png is empty after alpha threshold once resized`
|
|
1358
|
+
);
|
|
1359
|
+
}
|
|
1360
|
+
let shoulder;
|
|
1361
|
+
try {
|
|
1362
|
+
({ shoulder } = (0, import_editor6.armGeometry)(
|
|
1363
|
+
layer,
|
|
1364
|
+
role === "arm_R" ? Infinity : -Infinity
|
|
1365
|
+
));
|
|
1366
|
+
} catch (err) {
|
|
1367
|
+
if (err instanceof import_editor6.LayerGeometryError) {
|
|
1368
|
+
throw new AutoRigInputError(`layout.${role}: ${err.message}`);
|
|
1369
|
+
}
|
|
1370
|
+
throw err;
|
|
1371
|
+
}
|
|
1372
|
+
const pivotX = shoulder.x + part.w / 2;
|
|
1373
|
+
const pivotY = part.h / 2 - shoulder.y;
|
|
1374
|
+
const cornerX = role === "arm_R" ? body.left : body.left + body.w;
|
|
1375
|
+
const cornerY = body.top + SHOULDER_DROP * body.h;
|
|
1376
|
+
return {
|
|
1377
|
+
left: Math.round(
|
|
1378
|
+
cfg.cx === void 0 ? cornerX - pivotX : cfg.cx - part.w / 2
|
|
1379
|
+
),
|
|
1380
|
+
top: Math.round(
|
|
1381
|
+
cfg.cy === void 0 ? cornerY - pivotY : cfg.cy - part.h / 2
|
|
1382
|
+
)
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1261
1386
|
// src/compose.ts
|
|
1262
1387
|
var CANVAS = 1100;
|
|
1388
|
+
function canvasName(canvas) {
|
|
1389
|
+
return canvas.width === canvas.height ? `${canvas.width}` : `${canvas.width}x${canvas.height}`;
|
|
1390
|
+
}
|
|
1263
1391
|
var EYE_W = 98;
|
|
1264
1392
|
var IRIS_W = 50;
|
|
1265
1393
|
var EYEWHITE_SRC = "eyewhite.png";
|
|
@@ -1272,9 +1400,17 @@ var DEFAULT_LAYOUT = {
|
|
|
1272
1400
|
// Back hair and body sit behind the face. Both are OPTIONAL: a parts dir
|
|
1273
1401
|
// without them still composes (head-only character).
|
|
1274
1402
|
hair_back: { src: "hair_back.png", cx: 550, cy: 523, w: 800, optional: true },
|
|
1275
|
-
// The torso, cut off by
|
|
1276
|
-
// floating head
|
|
1403
|
+
// The bust's torso, cut off by a square canvas's bottom, so the character is
|
|
1404
|
+
// not a floating head; a full body on a tall canvas sets `layout.body`
|
|
1405
|
+
// itself. It rides the rig's `bodyWarp`, which the head hangs from.
|
|
1277
1406
|
body: { src: "body.png", cx: 550, cy: 1017, w: 840, optional: true },
|
|
1407
|
+
// The arms, one part for both: arm_R (screen left) takes arm.png as drawn
|
|
1408
|
+
// and arm_L mirrors it, like the blush. They draw over the body and under
|
|
1409
|
+
// the face. They have no cx/cy/w defaults: each is derived from the placed
|
|
1410
|
+
// body (ArmLayout). OPTIONAL and opt-in: a parts dir without arm.png
|
|
1411
|
+
// composes as a bust does, and `skipped` never lists them.
|
|
1412
|
+
arm_L: { src: "arm.png", optional: true, mirror: true },
|
|
1413
|
+
arm_R: { src: "arm.png", optional: true, mirror: false },
|
|
1278
1414
|
// The face is drawn without a neck, so its box is the skull and centres
|
|
1279
1415
|
// above the eye row (bob's skull at 437 against his eyes' 475).
|
|
1280
1416
|
face: { src: "face.png", cx: 550, cy: 437, w: 400 },
|
|
@@ -1339,6 +1475,8 @@ var LOWER_LASH_SRC = "eyewhite_lash_lower.png";
|
|
|
1339
1475
|
var ORDER = [
|
|
1340
1476
|
"hair_back",
|
|
1341
1477
|
"body",
|
|
1478
|
+
"arm_L",
|
|
1479
|
+
"arm_R",
|
|
1342
1480
|
"face",
|
|
1343
1481
|
"blush_L",
|
|
1344
1482
|
"blush_R",
|
|
@@ -1377,7 +1515,7 @@ var FACE_FEATURES = [
|
|
|
1377
1515
|
"brow_L",
|
|
1378
1516
|
"brow_R"
|
|
1379
1517
|
];
|
|
1380
|
-
function resolveLayout(overrides) {
|
|
1518
|
+
function resolveLayout(overrides, canvas) {
|
|
1381
1519
|
const resolved = { ...DEFAULT_LAYOUT };
|
|
1382
1520
|
if (overrides === void 0) return resolved;
|
|
1383
1521
|
const sets = /* @__PURE__ */ new Map();
|
|
@@ -1402,9 +1540,10 @@ function resolveLayout(overrides) {
|
|
|
1402
1540
|
for (const field of ["w", "h"]) {
|
|
1403
1541
|
const value = override[field];
|
|
1404
1542
|
if (value === void 0) continue;
|
|
1405
|
-
|
|
1543
|
+
const max = field === "w" ? canvas.width : canvas.height;
|
|
1544
|
+
if (!Number.isInteger(value) || value < 1 || value > max) {
|
|
1406
1545
|
throw new AutoRigInputError(
|
|
1407
|
-
`layout.${role}.${field} must be an integer in 1..${
|
|
1546
|
+
`layout.${role}.${field} must be an integer in 1..${max}, got ${String(value)}`
|
|
1408
1547
|
);
|
|
1409
1548
|
}
|
|
1410
1549
|
set[field] = value;
|
|
@@ -1432,10 +1571,22 @@ function resolveLayout(overrides) {
|
|
|
1432
1571
|
for (const [role, set] of sets) {
|
|
1433
1572
|
if (role === "face" || role === "nose") continue;
|
|
1434
1573
|
if (FACE_FEATURES.includes(role)) continue;
|
|
1435
|
-
resolved
|
|
1574
|
+
mergeRole(resolved, role, set);
|
|
1436
1575
|
}
|
|
1437
1576
|
return resolved;
|
|
1438
1577
|
}
|
|
1578
|
+
function mergeRole(resolved, role, set) {
|
|
1579
|
+
resolved[role] = { ...resolved[role], ...set };
|
|
1580
|
+
}
|
|
1581
|
+
function resolveCanvasHeight(value) {
|
|
1582
|
+
if (value === void 0) return CANVAS;
|
|
1583
|
+
if (!Number.isInteger(value) || value % 2 !== 0 || value < CANVAS || value > MAX_CANVAS_DIM) {
|
|
1584
|
+
throw new AutoRigInputError(
|
|
1585
|
+
`canvasHeight must be an even integer in ${CANVAS}..${MAX_CANVAS_DIM}, got ${String(value)}`
|
|
1586
|
+
);
|
|
1587
|
+
}
|
|
1588
|
+
return value;
|
|
1589
|
+
}
|
|
1439
1590
|
function resolveMirrorParts(names) {
|
|
1440
1591
|
const mirrored = /* @__PURE__ */ new Set();
|
|
1441
1592
|
for (const [i, name] of (names ?? []).entries()) {
|
|
@@ -1458,20 +1609,20 @@ function keyWhiteToAlpha(rgba) {
|
|
|
1458
1609
|
return keyed;
|
|
1459
1610
|
}
|
|
1460
1611
|
async function coreAndBoundsOf(png) {
|
|
1461
|
-
const { data, info } = await (0,
|
|
1612
|
+
const { data, info } = await (0, import_sharp3.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
1462
1613
|
return {
|
|
1463
|
-
core: (0,
|
|
1614
|
+
core: (0, import_editor5.denseCoreOf)(data, info.width, info.height),
|
|
1464
1615
|
bounds: { x: 0, y: 0, w: info.width, h: info.height }
|
|
1465
1616
|
};
|
|
1466
1617
|
}
|
|
1467
1618
|
async function hasCoverage(png) {
|
|
1468
|
-
const { data, info } = await (0,
|
|
1469
|
-
return (0,
|
|
1619
|
+
const { data, info } = await (0, import_sharp3.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
1620
|
+
return (0, import_editor7.detectAlphaBbox)(data, info.width, info.height) !== null;
|
|
1470
1621
|
}
|
|
1471
1622
|
async function noseSizingOf(png) {
|
|
1472
1623
|
const { core, bounds } = await coreAndBoundsOf(png);
|
|
1473
1624
|
if (core === null) return { box: bounds, whole: true };
|
|
1474
|
-
if ((0,
|
|
1625
|
+
if ((0, import_editor5.isSpeckCore)(core, bounds)) {
|
|
1475
1626
|
return {
|
|
1476
1627
|
box: bounds,
|
|
1477
1628
|
whole: true,
|
|
@@ -1483,12 +1634,12 @@ async function noseSizingOf(png) {
|
|
|
1483
1634
|
}
|
|
1484
1635
|
return { box: core, whole: false };
|
|
1485
1636
|
}
|
|
1486
|
-
async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
|
|
1637
|
+
async function partBuffer(role, cfg, partsDir, inMemory, flipSource, canvas) {
|
|
1487
1638
|
let img;
|
|
1488
1639
|
if (inMemory !== void 0) {
|
|
1489
|
-
img = (0,
|
|
1640
|
+
img = (0, import_sharp3.default)(inMemory);
|
|
1490
1641
|
} else {
|
|
1491
|
-
const srcPath =
|
|
1642
|
+
const srcPath = import_node_path6.default.join(partsDir, cfg.src);
|
|
1492
1643
|
if (!import_node_fs3.default.existsSync(srcPath)) {
|
|
1493
1644
|
if (cfg.optional) return null;
|
|
1494
1645
|
throw new AutoRigInputError(
|
|
@@ -1496,14 +1647,14 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
|
|
|
1496
1647
|
);
|
|
1497
1648
|
}
|
|
1498
1649
|
const png = await decodePng(srcPath);
|
|
1499
|
-
img = (0,
|
|
1650
|
+
img = (0, import_sharp3.default)(png.hasAlpha ? png.rgba : keyWhiteToAlpha(png.rgba), {
|
|
1500
1651
|
raw: { width: png.width, height: png.height, channels: 4 }
|
|
1501
1652
|
});
|
|
1502
1653
|
}
|
|
1503
1654
|
if (!cfg.noTrim) {
|
|
1504
1655
|
const kept = await img.trim({ threshold: TRIM_THRESHOLD }).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
1505
1656
|
const { width: keptW, height: keptH } = kept.info;
|
|
1506
|
-
img = (0,
|
|
1657
|
+
img = (0, import_sharp3.default)(kept.data, {
|
|
1507
1658
|
raw: { width: keptW, height: keptH, channels: 4 }
|
|
1508
1659
|
});
|
|
1509
1660
|
const box = boxWithoutStraySpecks(kept.data, keptW, keptH);
|
|
@@ -1516,13 +1667,13 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
|
|
|
1516
1667
|
const sized = nose?.box ?? { x: 0, y: 0, w: trimmedW, h: trimmedH };
|
|
1517
1668
|
const width = Math.round(trimmedW * cfg.w / sized.w);
|
|
1518
1669
|
const height = cfg.h === void 0 ? Math.round(trimmedH * width / trimmedW) : Math.round(trimmedH * cfg.h / sized.h);
|
|
1519
|
-
if (width >
|
|
1520
|
-
const field = width >
|
|
1670
|
+
if (width > canvas.width || height > canvas.height) {
|
|
1671
|
+
const field = width > canvas.width || cfg.h === void 0 ? "w" : "h";
|
|
1521
1672
|
throw new AutoRigInputError(
|
|
1522
|
-
`layout.${role}.${field}: resized part ${width}x${height} exceeds the ${
|
|
1673
|
+
`layout.${role}.${field}: resized part ${width}x${height} exceeds the ${canvasName(canvas)} canvas`
|
|
1523
1674
|
);
|
|
1524
1675
|
}
|
|
1525
|
-
const resized = await (0,
|
|
1676
|
+
const resized = await (0, import_sharp3.default)(trimmed.data).resize(cfg.h === void 0 ? { width } : { width, height, fit: "fill" }).png().toBuffer({ resolveWithObject: true });
|
|
1526
1677
|
return {
|
|
1527
1678
|
buf: resized.data,
|
|
1528
1679
|
w: resized.info.width,
|
|
@@ -1530,20 +1681,20 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
|
|
|
1530
1681
|
nose
|
|
1531
1682
|
};
|
|
1532
1683
|
}
|
|
1533
|
-
function assertOnCanvas(source, w, h, left, top) {
|
|
1534
|
-
if (left + w <= 0 || top + h <= 0 || left >=
|
|
1684
|
+
function assertOnCanvas(source, w, h, left, top, canvas) {
|
|
1685
|
+
if (left + w <= 0 || top + h <= 0 || left >= canvas.width || top >= canvas.height) {
|
|
1535
1686
|
throw new AutoRigInputError(
|
|
1536
|
-
`${source}: the placed part (${w}x${h} at ${left},${top}) falls entirely outside the ${
|
|
1687
|
+
`${source}: the placed part (${w}x${h} at ${left},${top}) falls entirely outside the ${canvasName(canvas)} canvas`
|
|
1537
1688
|
);
|
|
1538
1689
|
}
|
|
1539
1690
|
}
|
|
1540
|
-
function placement(role, cfg, w, h) {
|
|
1691
|
+
function placement(role, cfg, w, h, canvas) {
|
|
1541
1692
|
const left = Math.round(cfg.cx - w / 2);
|
|
1542
1693
|
const top = Math.round(cfg.cy - h / 2);
|
|
1543
|
-
assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top);
|
|
1694
|
+
assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top, canvas);
|
|
1544
1695
|
return { left, top };
|
|
1545
1696
|
}
|
|
1546
|
-
function nosePlacement(layout, box, w, h) {
|
|
1697
|
+
function nosePlacement(layout, box, w, h, canvas) {
|
|
1547
1698
|
const { cx, cy } = layout.nose;
|
|
1548
1699
|
const left = Math.round(cx - (box.x + box.w / 2));
|
|
1549
1700
|
let top;
|
|
@@ -1561,15 +1712,16 @@ function nosePlacement(layout, box, w, h) {
|
|
|
1561
1712
|
w,
|
|
1562
1713
|
h,
|
|
1563
1714
|
left,
|
|
1564
|
-
top
|
|
1715
|
+
top,
|
|
1716
|
+
canvas
|
|
1565
1717
|
);
|
|
1566
1718
|
return { left, top };
|
|
1567
1719
|
}
|
|
1568
|
-
function blankCanvas() {
|
|
1569
|
-
return (0,
|
|
1720
|
+
function blankCanvas(canvas) {
|
|
1721
|
+
return (0, import_sharp3.default)({
|
|
1570
1722
|
create: {
|
|
1571
|
-
width:
|
|
1572
|
-
height:
|
|
1723
|
+
width: canvas.width,
|
|
1724
|
+
height: canvas.height,
|
|
1573
1725
|
channels: 4,
|
|
1574
1726
|
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
|
1575
1727
|
}
|
|
@@ -1601,15 +1753,15 @@ function boxWithoutStraySpecks(rgba, W, H) {
|
|
|
1601
1753
|
while (depth > 0) {
|
|
1602
1754
|
const p = stack[--depth];
|
|
1603
1755
|
size++;
|
|
1604
|
-
if (rgba[p * 4 + 3] >=
|
|
1605
|
-
const
|
|
1606
|
-
const py = (p -
|
|
1607
|
-
setLeft = Math.min(setLeft,
|
|
1756
|
+
if (rgba[p * 4 + 3] >= import_editor7.ALPHA_OPAQUE) opaque = true;
|
|
1757
|
+
const px2 = p % W;
|
|
1758
|
+
const py = (p - px2) / W;
|
|
1759
|
+
setLeft = Math.min(setLeft, px2);
|
|
1608
1760
|
setTop = Math.min(setTop, py);
|
|
1609
|
-
setRight = Math.max(setRight,
|
|
1761
|
+
setRight = Math.max(setRight, px2);
|
|
1610
1762
|
setBottom = Math.max(setBottom, py);
|
|
1611
1763
|
for (let y = Math.max(0, py - 1); y <= Math.min(H - 1, py + 1); y++) {
|
|
1612
|
-
for (let x = Math.max(0,
|
|
1764
|
+
for (let x = Math.max(0, px2 - 1); x <= Math.min(W - 1, px2 + 1); x++) {
|
|
1613
1765
|
const q = y * W + x;
|
|
1614
1766
|
if (!visited[q] && rgba[q * 4 + 3] > TRIM_THRESHOLD) {
|
|
1615
1767
|
visited[q] = 1;
|
|
@@ -1642,15 +1794,15 @@ function detachedAboveWhite(rgba, W, H) {
|
|
|
1642
1794
|
for (let p = 0; p < n; p++) {
|
|
1643
1795
|
const alpha = rgba[p * 4 + 3];
|
|
1644
1796
|
if (alpha > 0 && luma(rgba, p * 4) >= EYE_LASH_LUMA)
|
|
1645
|
-
ink[p] = alpha >=
|
|
1797
|
+
ink[p] = alpha >= import_editor7.ALPHA_OPAQUE ? 2 : 1;
|
|
1646
1798
|
}
|
|
1647
1799
|
const label = new Int32Array(n).fill(-1);
|
|
1648
1800
|
const stack = new Int32Array(n);
|
|
1649
1801
|
const near = (p, visit) => {
|
|
1650
|
-
const
|
|
1651
|
-
const py = (p -
|
|
1802
|
+
const px2 = p % W;
|
|
1803
|
+
const py = (p - px2) / W;
|
|
1652
1804
|
for (let y = Math.max(0, py - 1); y <= Math.min(H - 1, py + 1); y++) {
|
|
1653
|
-
for (let x = Math.max(0,
|
|
1805
|
+
for (let x = Math.max(0, px2 - 1); x <= Math.min(W - 1, px2 + 1); x++) {
|
|
1654
1806
|
visit(y * W + x);
|
|
1655
1807
|
}
|
|
1656
1808
|
}
|
|
@@ -1722,7 +1874,7 @@ function detachedAboveWhite(rgba, W, H) {
|
|
|
1722
1874
|
return detached;
|
|
1723
1875
|
}
|
|
1724
1876
|
async function prepEyeSplit(partsDir) {
|
|
1725
|
-
const srcPath =
|
|
1877
|
+
const srcPath = import_node_path6.default.join(partsDir, EYEWHITE_SRC);
|
|
1726
1878
|
if (!import_node_fs3.default.existsSync(srcPath)) {
|
|
1727
1879
|
throw new AutoRigInputError(`missing eyewhite source: ${srcPath}`);
|
|
1728
1880
|
}
|
|
@@ -1783,7 +1935,11 @@ async function composeLayersFromParts(input) {
|
|
|
1783
1935
|
`partsDir and outDir resolve to the same directory (${outDir}): composing would overwrite the source parts`
|
|
1784
1936
|
);
|
|
1785
1937
|
}
|
|
1786
|
-
const
|
|
1938
|
+
const canvas = {
|
|
1939
|
+
width: CANVAS,
|
|
1940
|
+
height: resolveCanvasHeight(input.canvasHeight)
|
|
1941
|
+
};
|
|
1942
|
+
const layout = resolveLayout(input.layout, canvas);
|
|
1787
1943
|
const mirrored = resolveMirrorParts(input.mirrorParts);
|
|
1788
1944
|
const split = await prepEyeSplit(partsDir);
|
|
1789
1945
|
const splitSources = /* @__PURE__ */ new Map([
|
|
@@ -1803,6 +1959,44 @@ async function composeLayersFromParts(input) {
|
|
|
1803
1959
|
skipped.push(role);
|
|
1804
1960
|
continue;
|
|
1805
1961
|
}
|
|
1962
|
+
if (key === "arm_L" || key === "arm_R") {
|
|
1963
|
+
const arm = layout[key];
|
|
1964
|
+
if (!import_node_fs3.default.existsSync(import_node_path6.default.join(partsDir, arm.src))) continue;
|
|
1965
|
+
const body = placed.find((p) => p.role === "body");
|
|
1966
|
+
if (body === void 0) {
|
|
1967
|
+
throw new AutoRigInputError(
|
|
1968
|
+
"arm.png: an arm needs body.png \u2014 the composer hangs each arm on the body's shoulder, and auto_rig_from_layers hangs it from the body"
|
|
1969
|
+
);
|
|
1970
|
+
}
|
|
1971
|
+
const w = arm.w ?? Math.max(1, Math.round(ARM_WIDTH * body.part.w));
|
|
1972
|
+
const part2 = await partBuffer(
|
|
1973
|
+
role,
|
|
1974
|
+
{ ...arm, w },
|
|
1975
|
+
partsDir,
|
|
1976
|
+
void 0,
|
|
1977
|
+
mirrored.has(arm.src),
|
|
1978
|
+
canvas
|
|
1979
|
+
);
|
|
1980
|
+
const { left: left2, top: top2 } = await armPlacement(key, arm, part2, {
|
|
1981
|
+
left: body.left,
|
|
1982
|
+
top: body.top,
|
|
1983
|
+
w: body.part.w,
|
|
1984
|
+
h: body.part.h
|
|
1985
|
+
});
|
|
1986
|
+
const unset = ["cx", "cy"].filter(
|
|
1987
|
+
(field) => arm[field] === void 0
|
|
1988
|
+
);
|
|
1989
|
+
assertOnCanvas(
|
|
1990
|
+
unset.length === 0 ? `layout.${key}.cx/cy` : `layout.${key}.cx/cy (${unset.join("/")} unset: its shoulder pivot hangs on the shoulder corner of layout.body's box)`,
|
|
1991
|
+
part2.w,
|
|
1992
|
+
part2.h,
|
|
1993
|
+
left2,
|
|
1994
|
+
top2,
|
|
1995
|
+
canvas
|
|
1996
|
+
);
|
|
1997
|
+
placed.push({ role, part: part2, left: left2, top: top2 });
|
|
1998
|
+
continue;
|
|
1999
|
+
}
|
|
1806
2000
|
const cfg = lower ? { ...layout[key], src: LOWER_LASH_SRC } : layout[key];
|
|
1807
2001
|
const inMemory = splitSources.get(cfg.src);
|
|
1808
2002
|
const part = await partBuffer(
|
|
@@ -1811,7 +2005,8 @@ async function composeLayersFromParts(input) {
|
|
|
1811
2005
|
partsDir,
|
|
1812
2006
|
inMemory,
|
|
1813
2007
|
// The split halves are cut from eyewhite.png, the file a caller names.
|
|
1814
|
-
mirrored.has(inMemory === void 0 ? cfg.src : EYEWHITE_SRC)
|
|
2008
|
+
mirrored.has(inMemory === void 0 ? cfg.src : EYEWHITE_SRC),
|
|
2009
|
+
canvas
|
|
1815
2010
|
);
|
|
1816
2011
|
if (part === null || lower && !await hasCoverage(part.buf)) {
|
|
1817
2012
|
skipped.push(role);
|
|
@@ -1823,9 +2018,9 @@ async function composeLayersFromParts(input) {
|
|
|
1823
2018
|
noseSpeck = part.nose?.speck;
|
|
1824
2019
|
const { core, bounds } = await coreAndBoundsOf(part.buf);
|
|
1825
2020
|
const box = part.nose?.whole ? bounds : core ?? bounds;
|
|
1826
|
-
({ left, top } = nosePlacement(layout, box, part.w, part.h));
|
|
2021
|
+
({ left, top } = nosePlacement(layout, box, part.w, part.h, canvas));
|
|
1827
2022
|
} else {
|
|
1828
|
-
({ left, top } = placement(key, layout[key], part.w, part.h));
|
|
2023
|
+
({ left, top } = placement(key, layout[key], part.w, part.h, canvas));
|
|
1829
2024
|
}
|
|
1830
2025
|
if (role === "lash_L" || role === "lash_R") {
|
|
1831
2026
|
const eyeRole = role === "lash_L" ? "eye_L" : "eye_R";
|
|
@@ -1838,14 +2033,15 @@ async function composeLayersFromParts(input) {
|
|
|
1838
2033
|
}
|
|
1839
2034
|
placed.push({ role, part, left, top });
|
|
1840
2035
|
}
|
|
1841
|
-
for (const role of
|
|
1842
|
-
|
|
2036
|
+
for (const role of ORDER) {
|
|
2037
|
+
if (placed.some((p) => p.role === role)) continue;
|
|
2038
|
+
import_node_fs3.default.rmSync(import_node_path6.default.join(outDir, `${role}.png`), { force: true });
|
|
1843
2039
|
}
|
|
1844
2040
|
const layers = [];
|
|
1845
2041
|
const preview = [];
|
|
1846
2042
|
for (const { role, part, left, top } of placed) {
|
|
1847
|
-
const layer = await blankCanvas().composite([{ input: part.buf, left, top }]).png().toBuffer();
|
|
1848
|
-
const outPath =
|
|
2043
|
+
const layer = await blankCanvas(canvas).composite([{ input: part.buf, left, top }]).png().toBuffer();
|
|
2044
|
+
const outPath = import_node_path6.default.join(outDir, `${role}.png`);
|
|
1849
2045
|
writeFileAtomic(outPath, layer);
|
|
1850
2046
|
layers.push({
|
|
1851
2047
|
role,
|
|
@@ -1857,15 +2053,15 @@ async function composeLayersFromParts(input) {
|
|
|
1857
2053
|
});
|
|
1858
2054
|
preview.push({ input: part.buf, left, top });
|
|
1859
2055
|
}
|
|
1860
|
-
const previewPng = await (0,
|
|
2056
|
+
const previewPng = await (0, import_sharp3.default)({
|
|
1861
2057
|
create: {
|
|
1862
|
-
width:
|
|
1863
|
-
height:
|
|
2058
|
+
width: canvas.width,
|
|
2059
|
+
height: canvas.height,
|
|
1864
2060
|
channels: 4,
|
|
1865
2061
|
background: { r: 245, g: 245, b: 248, alpha: 1 }
|
|
1866
2062
|
}
|
|
1867
2063
|
}).composite(preview).png().toBuffer();
|
|
1868
|
-
const previewPath =
|
|
2064
|
+
const previewPath = import_node_path6.default.join(outDir, "preview.png");
|
|
1869
2065
|
writeFileAtomic(previewPath, previewPng);
|
|
1870
2066
|
return {
|
|
1871
2067
|
ok: true,
|
|
@@ -1884,7 +2080,7 @@ async function composeLayersFromParts(input) {
|
|
|
1884
2080
|
|
|
1885
2081
|
// src/server.ts
|
|
1886
2082
|
function createIkiMcpServer() {
|
|
1887
|
-
const server = new import_mcp.McpServer({ name: "iki", version: "0.
|
|
2083
|
+
const server = new import_mcp.McpServer({ name: "iki", version: "0.19.1" });
|
|
1888
2084
|
server.registerTool(
|
|
1889
2085
|
"validate_iki",
|
|
1890
2086
|
{
|
|
@@ -2004,13 +2200,13 @@ function createIkiMcpServer() {
|
|
|
2004
2200
|
server.registerTool(
|
|
2005
2201
|
"compose_layers_from_parts",
|
|
2006
2202
|
{
|
|
2007
|
-
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, blush (one blush.png makes the blush_L/blush_R pair) and nose are optional \u2014 without a nose layer the head still turns on the rig's default profile, but it has no nose to lead the turn, and `auto_rig_from_layers` fits no turn to the art (`turnTargets` is inert, no `turn` report). A nose whose dense core is a speck \u2014 under a quarter of its trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole, and the inline report warns of it. A light mark drawn detached above the eye white, such as a double-eyelid crease, is dropped from the sclera (the iris's clip); dark strokes there stay lash ink. The eyewhite's dark lower lid \u2014 its line and lashes \u2014 becomes lash_lower_L/lash_lower_R, drawn over the iris; a white with none writes none and lists them in `skipped`.",
|
|
2203
|
+
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, blush (one blush.png makes the blush_L/blush_R pair) and nose are optional \u2014 without a nose layer the head still turns on the rig's default profile, but it has no nose to lead the turn, and `auto_rig_from_layers` fits no turn to the art (`turnTargets` is inert, no `turn` report). One arm.png \u2014 the arm on the screen LEFT, drawn hanging with its shoulder at the top \u2014 makes both arms of a full body: arm_R takes it as drawn and arm_L mirrored. The arms are opt-in: without arm.png the compose is a bust's and `skipped` never lists them. arm.png needs body.png, and each arm is hung on the body's shoulder by default (see `layout`). The inline report carries the full-body checks too: a body whose feet a tall canvas's bottom cuts off, an arm without a body, and an arm whose shoulder cap does not reach under the torso's edge. A nose whose dense core is a speck \u2014 under a quarter of its trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole, and the inline report warns of it. A light mark drawn detached above the eye white, such as a double-eyelid crease, is dropped from the sclera (the iris's clip); dark strokes there stay lash ink. The eyewhite's dark lower lid \u2014 its line and lashes \u2014 becomes lash_lower_L/lash_lower_R, drawn over the iris; a white with none writes none and lists them in `skipped`.",
|
|
2008
2204
|
inputSchema: {
|
|
2009
2205
|
partsDir: import_zod.z.string().describe(
|
|
2010
2206
|
"Directory of the source part PNGs (resolved against cwd)."
|
|
2011
2207
|
),
|
|
2012
2208
|
outDir: import_zod.z.string().describe(
|
|
2013
|
-
"Existing directory to write the role layer PNGs + preview.png into (resolved against cwd; must already exist; confined to the working directory). Reused across runs: a role this run skips has its stale PNG from an earlier run deleted."
|
|
2209
|
+
"Existing directory to write the role layer PNGs + preview.png into (resolved against cwd; must already exist; confined to the working directory). Reused across runs: a role this run does not write \u2014 one it skips, or an arm once arm.png is gone \u2014 has its stale PNG from an earlier run deleted."
|
|
2014
2210
|
),
|
|
2015
2211
|
layout: import_zod.z.record(
|
|
2016
2212
|
import_zod.z.string(),
|
|
@@ -2021,10 +2217,13 @@ function createIkiMcpServer() {
|
|
|
2021
2217
|
h: import_zod.z.number()
|
|
2022
2218
|
}).partial()
|
|
2023
2219
|
).optional().describe(
|
|
2024
|
-
"Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, face, blush_L, blush_R, nose, 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`
|
|
2220
|
+
"Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, arm_L, arm_R, face, blush_L, blush_R, nose, 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` is an integer in 1..1100 (the canvas width) and `h` in 1..canvasHeight; omit `h` to keep the part's own aspect, set it to stretch. The defaults of the face's features \u2014 blush, nose, mouth, mouth_open, eyes, irises, lashes, brows \u2014 are proportions of the face: an override of face.cx, face.cy or face.w carries them with it (scaled by the width; face.h stretches the face alone), while a feature's own override names canvas px. The nose is sized and placed by its dense core (its pixels at alpha >= 128, the drawing inside a soft nose's feather), not its whole part: `w`/`h` size the core, `cx` centres it, and a set `cy` centres its rows. A nose whose core is a speck \u2014 under a quarter of the trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole instead, and the report warns of it. Its `cy` defaults to unset, which lands the core's bottom row (the tip) 0.66 of the way from the eye row down to the mouth's, so the nose follows a retuned eye or mouth row. eye_L/lash_L and eye_R/lash_R are cut from one eyewhite into one frame, so each pair must land on the same frame \u2014 a pair set to land apart is rejected. lash_lower_L/lash_lower_R are cut from it too and have no key: they land on their eye's frame. arm_L/arm_R have no cx/cy/w defaults: an unset `w` is 0.4 of the placed body's width, and an unset `cx` or `cy` hangs the arm's shoulder pivot \u2014 the one auto_rig_from_layers turns it about \u2014 on the body box's shoulder corner on that axis: its left edge for arm_R, its right edge for arm_L, 0.12 of its height under its top. A set one centres the arm as for every other role."
|
|
2025
2221
|
),
|
|
2026
2222
|
mirrorParts: import_zod.z.array(import_zod.z.string()).optional().describe(
|
|
2027
|
-
"Part files to flip left-right as they are read, e.g. `[\"eyewhite.png\"]`. The composer reads eyewhite.png as the eye on the screen LEFT (lash wing at the image's left end, lash-free tear duct at its right), brow.png as the brow on the screen RIGHT (thick head at the image's left end, tail at its right),
|
|
2223
|
+
"Part files to flip left-right as they are read, e.g. `[\"eyewhite.png\"]`. The composer reads eyewhite.png as the eye on the screen LEFT (lash wing at the image's left end, lash-free tear duct at its right), brow.png as the brow on the screen RIGHT (thick head at the image's left end, tail at its right), blush.png as the blush on the screen LEFT (outer end, toward the face's edge, at the image's left end, inner end at its right), and arm.png as the arm on the screen LEFT (the character's right, hanging, its shoulder at the image's top); a part drawn the other way round is fixed here for free. It flips the source, so every role cut from it flips together and an eye's sclera and lash stay in one frame."
|
|
2224
|
+
),
|
|
2225
|
+
canvasHeight: import_zod.z.number().optional().describe(
|
|
2226
|
+
"The canvas's height in px: an even integer in 1100..4096, default 1100 (a square bust canvas; at 1100 every output is byte-identical to leaving it out). The width stays 1100. The canvas grows downward: every default and every override keeps its canvas px from the top-left, so the head lands where it does on a bust and a full body gets room below. An odd height is refused \u2014 model space is centred on the canvas, so it would put the head on a half pixel \u2014 and it is checked before any part decodes."
|
|
2028
2227
|
)
|
|
2029
2228
|
}
|
|
2030
2229
|
},
|
|
@@ -2049,7 +2248,7 @@ function createIkiMcpServer() {
|
|
|
2049
2248
|
server.registerTool(
|
|
2050
2249
|
"measure_layers",
|
|
2051
2250
|
{
|
|
2052
|
-
description: "Reports read-only geometry checks over an already-composed layers directory \u2014 the same checks compose_layers_from_parts returns inline (iris ratio/offset, eye aspect, cropped/cut edges, a nose whose dense core is a speck of its crop, missing optional roles). Use to re-check a layers dir without recomposing. Its nose check reads the composed file against its crop, which is what auto_rig_from_layers acts on. Compose's inline report does the same unless the composer found the source part's core a speck, which it reports instead \u2014 so a speck that resampling erased from the layer shows there and not here.",
|
|
2251
|
+
description: "Reports read-only geometry checks over an already-composed layers directory \u2014 the same checks compose_layers_from_parts returns inline (iris ratio/offset, eye aspect, cropped/cut edges, a nose whose dense core is a speck of its crop, missing optional roles, a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge on its shoulder pivot's row). Every preview*.png is skipped. Use to re-check a layers dir without recomposing. Its nose check reads the composed file against its crop, which is what auto_rig_from_layers acts on. Compose's inline report does the same unless the composer found the source part's core a speck, which it reports instead \u2014 so a speck that resampling erased from the layer shows there and not here.",
|
|
2053
2252
|
inputSchema: {
|
|
2054
2253
|
layersDir: import_zod.z.string().describe(
|
|
2055
2254
|
"Directory of role-named layer PNGs (resolved against cwd)."
|