@ikijs/mcp 0.17.2 → 0.19.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 +11 -10
- package/dist/{chunk-CUINYKRG.mjs → chunk-E6DLZPCX.mjs} +326 -83
- package/dist/chunk-E6DLZPCX.mjs.map +1 -0
- package/dist/cli.js +330 -101
- 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 +330 -101
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
- package/dist/chunk-CUINYKRG.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);
|
|
@@ -346,6 +346,18 @@ var STANDARD_PARAMETER_INFO = [
|
|
|
346
346
|
id: import_format.StandardParameter.AngleZ,
|
|
347
347
|
description: "Head tilt / roll degrees; positive tilts the top of the head toward the viewer's right (clockwise), as in Live2D."
|
|
348
348
|
},
|
|
349
|
+
{
|
|
350
|
+
id: import_format.StandardParameter.BodyAngleX,
|
|
351
|
+
description: "Body turn, degrees (-10 .. 10); positive turns the body toward the viewer's right, as AngleX does the head."
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
id: import_format.StandardParameter.BodyAngleY,
|
|
355
|
+
description: "Body lean, degrees (-10 .. 10); positive moves the upper body up, negative bows."
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
id: import_format.StandardParameter.BodyAngleZ,
|
|
359
|
+
description: "Body tilt, degrees (-10 .. 10); positive tilts the top toward the viewer's right (clockwise), as AngleZ does the head."
|
|
360
|
+
},
|
|
349
361
|
{
|
|
350
362
|
id: import_format.StandardParameter.Breath,
|
|
351
363
|
description: "Idle breath (0 .. 1), cycled by the host."
|
|
@@ -377,6 +389,22 @@ var STANDARD_PARAMETER_INFO = [
|
|
|
377
389
|
{
|
|
378
390
|
id: import_format.StandardParameter.HairSwayZ,
|
|
379
391
|
description: "Hair-sway driver behind a head tilt. Physics OUTPUT \u2014 driven by the spring, hosts should not set it directly."
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
id: import_format.StandardParameter.ArmLeft,
|
|
395
|
+
description: "Left shoulder, degrees; positive raises the arm outward (mirrored on the right)."
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
id: import_format.StandardParameter.ArmRight,
|
|
399
|
+
description: "Right shoulder, degrees; positive raises the arm outward (mirrored on the left)."
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
id: import_format.StandardParameter.ElbowLeft,
|
|
403
|
+
description: "Left elbow, degrees; positive bends the forearm the way positive ArmLeft raises the arm."
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
id: import_format.StandardParameter.ElbowRight,
|
|
407
|
+
description: "Right elbow, degrees; positive bends the forearm the way positive ArmRight raises the arm."
|
|
380
408
|
}
|
|
381
409
|
];
|
|
382
410
|
function listStandardParameters() {
|
|
@@ -396,9 +424,13 @@ async function renderAtlasPage(crops, quantizeColors) {
|
|
|
396
424
|
const layout = (0, import_editor2.packAtlas)(
|
|
397
425
|
crops.map((c) => ({ id: c.id, width: c.width, height: c.height }))
|
|
398
426
|
);
|
|
399
|
-
|
|
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
|
+
);
|
|
400
432
|
throw new AutoRigInputError(
|
|
401
|
-
`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})`
|
|
402
434
|
);
|
|
403
435
|
}
|
|
404
436
|
const dataUri = await renderAtlasToDataUri(crops, layout, quantizeColors);
|
|
@@ -517,7 +549,9 @@ async function autoRigFromLayers(input) {
|
|
|
517
549
|
}
|
|
518
550
|
);
|
|
519
551
|
} catch (e) {
|
|
520
|
-
if (!(e instanceof import_editor2.TurnTargetError))
|
|
552
|
+
if (!(e instanceof import_editor2.TurnTargetError || e instanceof import_editor2.LayerGeometryError)) {
|
|
553
|
+
throw e;
|
|
554
|
+
}
|
|
521
555
|
throw new AutoRigInputError(e.message);
|
|
522
556
|
}
|
|
523
557
|
const doc = new import_editor2.EditorDocument(model);
|
|
@@ -536,18 +570,16 @@ async function autoRigFromLayers(input) {
|
|
|
536
570
|
);
|
|
537
571
|
}
|
|
538
572
|
const partTextureAssignments = pages.flatMap(
|
|
539
|
-
({ crops: pageCrops, layout }) => pageCrops.
|
|
573
|
+
({ crops: pageCrops, layout }) => pageCrops.flatMap((crop) => {
|
|
540
574
|
const placement2 = layout.placements.find((p) => p.id === crop.id);
|
|
541
575
|
if (placement2 === void 0) {
|
|
542
576
|
throw new Error(`auto-rig: no atlas placement for "${crop.id}"`);
|
|
543
577
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
})
|
|
550
|
-
};
|
|
578
|
+
const uv = (0, import_editor2.uvRectFor)(placement2, {
|
|
579
|
+
width: layout.pageWidth,
|
|
580
|
+
height: layout.pageHeight
|
|
581
|
+
});
|
|
582
|
+
return (0, import_editor2.partIdsOfRole)(crop.id).map((partId) => ({ partId, uv }));
|
|
551
583
|
})
|
|
552
584
|
);
|
|
553
585
|
doc.applyAtlas({
|
|
@@ -558,7 +590,9 @@ async function autoRigFromLayers(input) {
|
|
|
558
590
|
if (losslessCrop !== void 0) {
|
|
559
591
|
patched = structuredClone(patched);
|
|
560
592
|
patched.textures = pages.map((p) => ({ source: p.dataUri }));
|
|
561
|
-
|
|
593
|
+
for (const partId of (0, import_editor2.partIdsOfRole)(losslessCrop.id)) {
|
|
594
|
+
patched.parts.find((p) => p.id === partId).texture.index = 1;
|
|
595
|
+
}
|
|
562
596
|
}
|
|
563
597
|
const finalModel = (0, import_format.parseIkiModel)(patched);
|
|
564
598
|
writeFileAtomic(outPath, JSON.stringify(finalModel));
|
|
@@ -584,18 +618,89 @@ async function autoRigFromLayers(input) {
|
|
|
584
618
|
|
|
585
619
|
// src/compose.ts
|
|
586
620
|
var import_node_fs3 = __toESM(require("fs"));
|
|
587
|
-
var
|
|
588
|
-
var
|
|
589
|
-
var
|
|
621
|
+
var import_node_path6 = __toESM(require("path"));
|
|
622
|
+
var import_sharp3 = __toESM(require("sharp"));
|
|
623
|
+
var import_editor7 = require("@ikijs/editor");
|
|
590
624
|
|
|
591
625
|
// src/measure.ts
|
|
592
626
|
var import_node_fs2 = __toESM(require("fs"));
|
|
593
|
-
var
|
|
627
|
+
var import_node_path5 = __toESM(require("path"));
|
|
594
628
|
|
|
595
|
-
// src/measure-
|
|
629
|
+
// src/measure-arms.ts
|
|
596
630
|
var import_node_path3 = __toESM(require("path"));
|
|
597
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"));
|
|
598
702
|
var import_editor4 = require("@ikijs/editor");
|
|
703
|
+
var import_editor5 = require("@ikijs/editor");
|
|
599
704
|
var DEFAULT_IRIS = { hueMin: 230, hueMax: 300, satMin: 0.22 };
|
|
600
705
|
var IRIS_V_MIN = 0.18;
|
|
601
706
|
var IRIS_V_MAX = 0.95;
|
|
@@ -745,7 +850,7 @@ async function measureTurnImage(filePath, iris) {
|
|
|
745
850
|
let transparent = false;
|
|
746
851
|
if (hasAlpha) {
|
|
747
852
|
for (let i = 0; i < n; i++) {
|
|
748
|
-
if (rgba[i * 4 + 3] <
|
|
853
|
+
if (rgba[i * 4 + 3] < import_editor4.ALPHA_OPAQUE) {
|
|
749
854
|
transparent = true;
|
|
750
855
|
break;
|
|
751
856
|
}
|
|
@@ -756,7 +861,7 @@ async function measureTurnImage(filePath, iris) {
|
|
|
756
861
|
const fg = new Uint8Array(n);
|
|
757
862
|
const value = new Float32Array(n);
|
|
758
863
|
for (let i = 0; i < n; i++) {
|
|
759
|
-
if (rgba[i * 4 + 3] <
|
|
864
|
+
if (rgba[i * 4 + 3] < import_editor4.ALPHA_OPAQUE) continue;
|
|
760
865
|
const [hue, s, v] = rgbToHsv(rgba[i * 4], rgba[i * 4 + 1], rgba[i * 4 + 2]);
|
|
761
866
|
if (maskMode === "alpha") {
|
|
762
867
|
fg[i] = 1;
|
|
@@ -822,12 +927,12 @@ async function measureTurnImage(filePath, iris) {
|
|
|
822
927
|
}
|
|
823
928
|
const [irisL, irisR] = best.pair;
|
|
824
929
|
const eyeRow = Math.round((irisL.cy + irisR.cy) / 2);
|
|
825
|
-
const { left, right } = (0,
|
|
930
|
+
const { left, right } = (0, import_editor4.foregroundSpan)(
|
|
826
931
|
fg,
|
|
827
932
|
width,
|
|
828
933
|
height,
|
|
829
|
-
eyeRow -
|
|
830
|
-
eyeRow +
|
|
934
|
+
eyeRow - import_editor4.HEAD_BAND,
|
|
935
|
+
eyeRow + import_editor4.HEAD_BAND
|
|
831
936
|
);
|
|
832
937
|
if (right <= left) {
|
|
833
938
|
throw new AutoRigInputError(
|
|
@@ -851,7 +956,7 @@ async function measureTurnImage(filePath, iris) {
|
|
|
851
956
|
left,
|
|
852
957
|
right,
|
|
853
958
|
cx: (left + right) / 2,
|
|
854
|
-
half: (0,
|
|
959
|
+
half: (0, import_editor4.headHalfOf)({ left, right })
|
|
855
960
|
},
|
|
856
961
|
pairCx: (irisL.cx + irisR.cx) / 2,
|
|
857
962
|
eyeGap: irisR.cx - irisL.cx
|
|
@@ -866,9 +971,9 @@ function overlaySvg(m) {
|
|
|
866
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>";
|
|
867
972
|
}
|
|
868
973
|
async function writeOverlay(debugDir, label, m) {
|
|
869
|
-
const outPath =
|
|
974
|
+
const outPath = import_node_path4.default.join(
|
|
870
975
|
debugDir,
|
|
871
|
-
`${label}-${
|
|
976
|
+
`${label}-${import_node_path4.default.basename(m.file, ".png")}.debug.png`
|
|
872
977
|
);
|
|
873
978
|
writeFileAtomic(outPath, await encodeOverlayPng(m.file, overlaySvg(m)));
|
|
874
979
|
return outPath;
|
|
@@ -1033,6 +1138,7 @@ async function layerStats(filePath) {
|
|
|
1033
1138
|
};
|
|
1034
1139
|
}
|
|
1035
1140
|
var pct = (v) => `${(v * 100).toFixed(0)}%`;
|
|
1141
|
+
var isArm = (role) => ARM_ROLES.includes(role);
|
|
1036
1142
|
function noseSpeckWarning({ core, part }, source) {
|
|
1037
1143
|
const [found, consequence] = source === "compose" ? [
|
|
1038
1144
|
`the source part's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} trimmed part`,
|
|
@@ -1041,7 +1147,7 @@ function noseSpeckWarning({ core, part }, source) {
|
|
|
1041
1147
|
`the layer's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} crop`,
|
|
1042
1148
|
`auto_rig_from_layers turns and tilts the nose about its whole crop instead`
|
|
1043
1149
|
];
|
|
1044
|
-
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.`;
|
|
1045
1151
|
}
|
|
1046
1152
|
async function lashOffSclera(eyePath, lashPath) {
|
|
1047
1153
|
const eye = await decodePng(eyePath);
|
|
@@ -1059,7 +1165,7 @@ async function lashOffSclera(eyePath, lashPath) {
|
|
|
1059
1165
|
return { opaque, off };
|
|
1060
1166
|
}
|
|
1061
1167
|
async function measureDir(absDir, noseSpeck) {
|
|
1062
|
-
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();
|
|
1063
1169
|
if (files.length === 0) {
|
|
1064
1170
|
throw new AutoRigInputError(`no role layers in ${absDir}`);
|
|
1065
1171
|
}
|
|
@@ -1071,8 +1177,8 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1071
1177
|
const layers = {};
|
|
1072
1178
|
const empty = [];
|
|
1073
1179
|
for (const f of files) {
|
|
1074
|
-
const role =
|
|
1075
|
-
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));
|
|
1076
1182
|
if (!m) {
|
|
1077
1183
|
empty.push(role);
|
|
1078
1184
|
continue;
|
|
@@ -1086,8 +1192,13 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1086
1192
|
["left", m.edgeLeft, m.h, m.marginLeft],
|
|
1087
1193
|
["right", m.edgeRight, m.h, m.marginRight]
|
|
1088
1194
|
];
|
|
1089
|
-
if (role !== "body")
|
|
1195
|
+
if (role !== "body") {
|
|
1090
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
|
+
}
|
|
1091
1202
|
for (const [side, v, span, margin] of edges) {
|
|
1092
1203
|
if (v > EDGE_SOLID_MAX && v * span >= EDGE_RUN_MIN_PX) {
|
|
1093
1204
|
const remedy = margin === 0 ? (
|
|
@@ -1099,7 +1210,7 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1099
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.`
|
|
1100
1211
|
) : `its own drawing runs to the frame ${margin} px inside the canvas \u2014 regenerate that part with empty margin on that side. Billed.`;
|
|
1101
1212
|
warnings.push(
|
|
1102
|
-
`${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}`
|
|
1103
1214
|
);
|
|
1104
1215
|
}
|
|
1105
1216
|
}
|
|
@@ -1108,10 +1219,11 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1108
1219
|
if (role === "body") continue;
|
|
1109
1220
|
if (m.flatCutRun > FLAT_CUT_MAX_FRAC * m.w && m.flatCutRun >= FLAT_CUT_MIN_PX) {
|
|
1110
1221
|
warnings.push(
|
|
1111
|
-
`${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.`
|
|
1112
1223
|
);
|
|
1113
1224
|
}
|
|
1114
1225
|
}
|
|
1226
|
+
warnings.push(...await armWarnings(absDir, layers));
|
|
1115
1227
|
for (const side of ["L", "R"]) {
|
|
1116
1228
|
const eye = layers[`eye_${side}`];
|
|
1117
1229
|
const iris = layers[`iris_${side}`];
|
|
@@ -1140,8 +1252,8 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1140
1252
|
}
|
|
1141
1253
|
if (lash) {
|
|
1142
1254
|
const { opaque, off } = await lashOffSclera(
|
|
1143
|
-
|
|
1144
|
-
|
|
1255
|
+
import_node_path5.default.join(absDir, `eye_${side}.png`),
|
|
1256
|
+
import_node_path5.default.join(absDir, `lash_${side}.png`)
|
|
1145
1257
|
);
|
|
1146
1258
|
const dTop = lash.marginTop - eye.marginTop;
|
|
1147
1259
|
const faults = [
|
|
@@ -1167,11 +1279,11 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1167
1279
|
if (noseSpeck !== void 0) {
|
|
1168
1280
|
warnings.push(noseSpeckWarning(noseSpeck, "compose"));
|
|
1169
1281
|
} else if (layers.nose !== void 0) {
|
|
1170
|
-
const nose = await decodePng(
|
|
1171
|
-
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);
|
|
1172
1284
|
if (core !== null) {
|
|
1173
1285
|
const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
|
|
1174
|
-
if ((0,
|
|
1286
|
+
if ((0, import_editor5.isSpeckCore)(core, crop))
|
|
1175
1287
|
warnings.push(noseSpeckWarning({ core, part: crop }, "layer"));
|
|
1176
1288
|
}
|
|
1177
1289
|
}
|
|
@@ -1228,8 +1340,54 @@ function formatMeasureReport(result) {
|
|
|
1228
1340
|
return lines.join("\n");
|
|
1229
1341
|
}
|
|
1230
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
|
+
|
|
1231
1386
|
// src/compose.ts
|
|
1232
1387
|
var CANVAS = 1100;
|
|
1388
|
+
function canvasName(canvas) {
|
|
1389
|
+
return canvas.width === canvas.height ? `${canvas.width}` : `${canvas.width}x${canvas.height}`;
|
|
1390
|
+
}
|
|
1233
1391
|
var EYE_W = 98;
|
|
1234
1392
|
var IRIS_W = 50;
|
|
1235
1393
|
var EYEWHITE_SRC = "eyewhite.png";
|
|
@@ -1242,9 +1400,17 @@ var DEFAULT_LAYOUT = {
|
|
|
1242
1400
|
// Back hair and body sit behind the face. Both are OPTIONAL: a parts dir
|
|
1243
1401
|
// without them still composes (head-only character).
|
|
1244
1402
|
hair_back: { src: "hair_back.png", cx: 550, cy: 523, w: 800, optional: true },
|
|
1245
|
-
// The torso, cut off by
|
|
1246
|
-
// 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.
|
|
1247
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 },
|
|
1248
1414
|
// The face is drawn without a neck, so its box is the skull and centres
|
|
1249
1415
|
// above the eye row (bob's skull at 437 against his eyes' 475).
|
|
1250
1416
|
face: { src: "face.png", cx: 550, cy: 437, w: 400 },
|
|
@@ -1309,6 +1475,8 @@ var LOWER_LASH_SRC = "eyewhite_lash_lower.png";
|
|
|
1309
1475
|
var ORDER = [
|
|
1310
1476
|
"hair_back",
|
|
1311
1477
|
"body",
|
|
1478
|
+
"arm_L",
|
|
1479
|
+
"arm_R",
|
|
1312
1480
|
"face",
|
|
1313
1481
|
"blush_L",
|
|
1314
1482
|
"blush_R",
|
|
@@ -1347,7 +1515,7 @@ var FACE_FEATURES = [
|
|
|
1347
1515
|
"brow_L",
|
|
1348
1516
|
"brow_R"
|
|
1349
1517
|
];
|
|
1350
|
-
function resolveLayout(overrides) {
|
|
1518
|
+
function resolveLayout(overrides, canvas) {
|
|
1351
1519
|
const resolved = { ...DEFAULT_LAYOUT };
|
|
1352
1520
|
if (overrides === void 0) return resolved;
|
|
1353
1521
|
const sets = /* @__PURE__ */ new Map();
|
|
@@ -1372,9 +1540,10 @@ function resolveLayout(overrides) {
|
|
|
1372
1540
|
for (const field of ["w", "h"]) {
|
|
1373
1541
|
const value = override[field];
|
|
1374
1542
|
if (value === void 0) continue;
|
|
1375
|
-
|
|
1543
|
+
const max = field === "w" ? canvas.width : canvas.height;
|
|
1544
|
+
if (!Number.isInteger(value) || value < 1 || value > max) {
|
|
1376
1545
|
throw new AutoRigInputError(
|
|
1377
|
-
`layout.${role}.${field} must be an integer in 1..${
|
|
1546
|
+
`layout.${role}.${field} must be an integer in 1..${max}, got ${String(value)}`
|
|
1378
1547
|
);
|
|
1379
1548
|
}
|
|
1380
1549
|
set[field] = value;
|
|
@@ -1402,10 +1571,22 @@ function resolveLayout(overrides) {
|
|
|
1402
1571
|
for (const [role, set] of sets) {
|
|
1403
1572
|
if (role === "face" || role === "nose") continue;
|
|
1404
1573
|
if (FACE_FEATURES.includes(role)) continue;
|
|
1405
|
-
resolved
|
|
1574
|
+
mergeRole(resolved, role, set);
|
|
1406
1575
|
}
|
|
1407
1576
|
return resolved;
|
|
1408
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
|
+
}
|
|
1409
1590
|
function resolveMirrorParts(names) {
|
|
1410
1591
|
const mirrored = /* @__PURE__ */ new Set();
|
|
1411
1592
|
for (const [i, name] of (names ?? []).entries()) {
|
|
@@ -1428,20 +1609,20 @@ function keyWhiteToAlpha(rgba) {
|
|
|
1428
1609
|
return keyed;
|
|
1429
1610
|
}
|
|
1430
1611
|
async function coreAndBoundsOf(png) {
|
|
1431
|
-
const { data, info } = await (0,
|
|
1612
|
+
const { data, info } = await (0, import_sharp3.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
1432
1613
|
return {
|
|
1433
|
-
core: (0,
|
|
1614
|
+
core: (0, import_editor5.denseCoreOf)(data, info.width, info.height),
|
|
1434
1615
|
bounds: { x: 0, y: 0, w: info.width, h: info.height }
|
|
1435
1616
|
};
|
|
1436
1617
|
}
|
|
1437
1618
|
async function hasCoverage(png) {
|
|
1438
|
-
const { data, info } = await (0,
|
|
1439
|
-
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;
|
|
1440
1621
|
}
|
|
1441
1622
|
async function noseSizingOf(png) {
|
|
1442
1623
|
const { core, bounds } = await coreAndBoundsOf(png);
|
|
1443
1624
|
if (core === null) return { box: bounds, whole: true };
|
|
1444
|
-
if ((0,
|
|
1625
|
+
if ((0, import_editor5.isSpeckCore)(core, bounds)) {
|
|
1445
1626
|
return {
|
|
1446
1627
|
box: bounds,
|
|
1447
1628
|
whole: true,
|
|
@@ -1453,12 +1634,12 @@ async function noseSizingOf(png) {
|
|
|
1453
1634
|
}
|
|
1454
1635
|
return { box: core, whole: false };
|
|
1455
1636
|
}
|
|
1456
|
-
async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
|
|
1637
|
+
async function partBuffer(role, cfg, partsDir, inMemory, flipSource, canvas) {
|
|
1457
1638
|
let img;
|
|
1458
1639
|
if (inMemory !== void 0) {
|
|
1459
|
-
img = (0,
|
|
1640
|
+
img = (0, import_sharp3.default)(inMemory);
|
|
1460
1641
|
} else {
|
|
1461
|
-
const srcPath =
|
|
1642
|
+
const srcPath = import_node_path6.default.join(partsDir, cfg.src);
|
|
1462
1643
|
if (!import_node_fs3.default.existsSync(srcPath)) {
|
|
1463
1644
|
if (cfg.optional) return null;
|
|
1464
1645
|
throw new AutoRigInputError(
|
|
@@ -1466,14 +1647,14 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
|
|
|
1466
1647
|
);
|
|
1467
1648
|
}
|
|
1468
1649
|
const png = await decodePng(srcPath);
|
|
1469
|
-
img = (0,
|
|
1650
|
+
img = (0, import_sharp3.default)(png.hasAlpha ? png.rgba : keyWhiteToAlpha(png.rgba), {
|
|
1470
1651
|
raw: { width: png.width, height: png.height, channels: 4 }
|
|
1471
1652
|
});
|
|
1472
1653
|
}
|
|
1473
1654
|
if (!cfg.noTrim) {
|
|
1474
1655
|
const kept = await img.trim({ threshold: TRIM_THRESHOLD }).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
1475
1656
|
const { width: keptW, height: keptH } = kept.info;
|
|
1476
|
-
img = (0,
|
|
1657
|
+
img = (0, import_sharp3.default)(kept.data, {
|
|
1477
1658
|
raw: { width: keptW, height: keptH, channels: 4 }
|
|
1478
1659
|
});
|
|
1479
1660
|
const box = boxWithoutStraySpecks(kept.data, keptW, keptH);
|
|
@@ -1486,13 +1667,13 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
|
|
|
1486
1667
|
const sized = nose?.box ?? { x: 0, y: 0, w: trimmedW, h: trimmedH };
|
|
1487
1668
|
const width = Math.round(trimmedW * cfg.w / sized.w);
|
|
1488
1669
|
const height = cfg.h === void 0 ? Math.round(trimmedH * width / trimmedW) : Math.round(trimmedH * cfg.h / sized.h);
|
|
1489
|
-
if (width >
|
|
1490
|
-
const field = width >
|
|
1670
|
+
if (width > canvas.width || height > canvas.height) {
|
|
1671
|
+
const field = width > canvas.width || cfg.h === void 0 ? "w" : "h";
|
|
1491
1672
|
throw new AutoRigInputError(
|
|
1492
|
-
`layout.${role}.${field}: resized part ${width}x${height} exceeds the ${
|
|
1673
|
+
`layout.${role}.${field}: resized part ${width}x${height} exceeds the ${canvasName(canvas)} canvas`
|
|
1493
1674
|
);
|
|
1494
1675
|
}
|
|
1495
|
-
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 });
|
|
1496
1677
|
return {
|
|
1497
1678
|
buf: resized.data,
|
|
1498
1679
|
w: resized.info.width,
|
|
@@ -1500,20 +1681,20 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
|
|
|
1500
1681
|
nose
|
|
1501
1682
|
};
|
|
1502
1683
|
}
|
|
1503
|
-
function assertOnCanvas(source, w, h, left, top) {
|
|
1504
|
-
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) {
|
|
1505
1686
|
throw new AutoRigInputError(
|
|
1506
|
-
`${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`
|
|
1507
1688
|
);
|
|
1508
1689
|
}
|
|
1509
1690
|
}
|
|
1510
|
-
function placement(role, cfg, w, h) {
|
|
1691
|
+
function placement(role, cfg, w, h, canvas) {
|
|
1511
1692
|
const left = Math.round(cfg.cx - w / 2);
|
|
1512
1693
|
const top = Math.round(cfg.cy - h / 2);
|
|
1513
|
-
assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top);
|
|
1694
|
+
assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top, canvas);
|
|
1514
1695
|
return { left, top };
|
|
1515
1696
|
}
|
|
1516
|
-
function nosePlacement(layout, box, w, h) {
|
|
1697
|
+
function nosePlacement(layout, box, w, h, canvas) {
|
|
1517
1698
|
const { cx, cy } = layout.nose;
|
|
1518
1699
|
const left = Math.round(cx - (box.x + box.w / 2));
|
|
1519
1700
|
let top;
|
|
@@ -1531,15 +1712,16 @@ function nosePlacement(layout, box, w, h) {
|
|
|
1531
1712
|
w,
|
|
1532
1713
|
h,
|
|
1533
1714
|
left,
|
|
1534
|
-
top
|
|
1715
|
+
top,
|
|
1716
|
+
canvas
|
|
1535
1717
|
);
|
|
1536
1718
|
return { left, top };
|
|
1537
1719
|
}
|
|
1538
|
-
function blankCanvas() {
|
|
1539
|
-
return (0,
|
|
1720
|
+
function blankCanvas(canvas) {
|
|
1721
|
+
return (0, import_sharp3.default)({
|
|
1540
1722
|
create: {
|
|
1541
|
-
width:
|
|
1542
|
-
height:
|
|
1723
|
+
width: canvas.width,
|
|
1724
|
+
height: canvas.height,
|
|
1543
1725
|
channels: 4,
|
|
1544
1726
|
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
|
1545
1727
|
}
|
|
@@ -1571,15 +1753,15 @@ function boxWithoutStraySpecks(rgba, W, H) {
|
|
|
1571
1753
|
while (depth > 0) {
|
|
1572
1754
|
const p = stack[--depth];
|
|
1573
1755
|
size++;
|
|
1574
|
-
if (rgba[p * 4 + 3] >=
|
|
1575
|
-
const
|
|
1576
|
-
const py = (p -
|
|
1577
|
-
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);
|
|
1578
1760
|
setTop = Math.min(setTop, py);
|
|
1579
|
-
setRight = Math.max(setRight,
|
|
1761
|
+
setRight = Math.max(setRight, px2);
|
|
1580
1762
|
setBottom = Math.max(setBottom, py);
|
|
1581
1763
|
for (let y = Math.max(0, py - 1); y <= Math.min(H - 1, py + 1); y++) {
|
|
1582
|
-
for (let x = Math.max(0,
|
|
1764
|
+
for (let x = Math.max(0, px2 - 1); x <= Math.min(W - 1, px2 + 1); x++) {
|
|
1583
1765
|
const q = y * W + x;
|
|
1584
1766
|
if (!visited[q] && rgba[q * 4 + 3] > TRIM_THRESHOLD) {
|
|
1585
1767
|
visited[q] = 1;
|
|
@@ -1612,15 +1794,15 @@ function detachedAboveWhite(rgba, W, H) {
|
|
|
1612
1794
|
for (let p = 0; p < n; p++) {
|
|
1613
1795
|
const alpha = rgba[p * 4 + 3];
|
|
1614
1796
|
if (alpha > 0 && luma(rgba, p * 4) >= EYE_LASH_LUMA)
|
|
1615
|
-
ink[p] = alpha >=
|
|
1797
|
+
ink[p] = alpha >= import_editor7.ALPHA_OPAQUE ? 2 : 1;
|
|
1616
1798
|
}
|
|
1617
1799
|
const label = new Int32Array(n).fill(-1);
|
|
1618
1800
|
const stack = new Int32Array(n);
|
|
1619
1801
|
const near = (p, visit) => {
|
|
1620
|
-
const
|
|
1621
|
-
const py = (p -
|
|
1802
|
+
const px2 = p % W;
|
|
1803
|
+
const py = (p - px2) / W;
|
|
1622
1804
|
for (let y = Math.max(0, py - 1); y <= Math.min(H - 1, py + 1); y++) {
|
|
1623
|
-
for (let x = Math.max(0,
|
|
1805
|
+
for (let x = Math.max(0, px2 - 1); x <= Math.min(W - 1, px2 + 1); x++) {
|
|
1624
1806
|
visit(y * W + x);
|
|
1625
1807
|
}
|
|
1626
1808
|
}
|
|
@@ -1692,7 +1874,7 @@ function detachedAboveWhite(rgba, W, H) {
|
|
|
1692
1874
|
return detached;
|
|
1693
1875
|
}
|
|
1694
1876
|
async function prepEyeSplit(partsDir) {
|
|
1695
|
-
const srcPath =
|
|
1877
|
+
const srcPath = import_node_path6.default.join(partsDir, EYEWHITE_SRC);
|
|
1696
1878
|
if (!import_node_fs3.default.existsSync(srcPath)) {
|
|
1697
1879
|
throw new AutoRigInputError(`missing eyewhite source: ${srcPath}`);
|
|
1698
1880
|
}
|
|
@@ -1753,7 +1935,11 @@ async function composeLayersFromParts(input) {
|
|
|
1753
1935
|
`partsDir and outDir resolve to the same directory (${outDir}): composing would overwrite the source parts`
|
|
1754
1936
|
);
|
|
1755
1937
|
}
|
|
1756
|
-
const
|
|
1938
|
+
const canvas = {
|
|
1939
|
+
width: CANVAS,
|
|
1940
|
+
height: resolveCanvasHeight(input.canvasHeight)
|
|
1941
|
+
};
|
|
1942
|
+
const layout = resolveLayout(input.layout, canvas);
|
|
1757
1943
|
const mirrored = resolveMirrorParts(input.mirrorParts);
|
|
1758
1944
|
const split = await prepEyeSplit(partsDir);
|
|
1759
1945
|
const splitSources = /* @__PURE__ */ new Map([
|
|
@@ -1773,6 +1959,44 @@ async function composeLayersFromParts(input) {
|
|
|
1773
1959
|
skipped.push(role);
|
|
1774
1960
|
continue;
|
|
1775
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
|
+
}
|
|
1776
2000
|
const cfg = lower ? { ...layout[key], src: LOWER_LASH_SRC } : layout[key];
|
|
1777
2001
|
const inMemory = splitSources.get(cfg.src);
|
|
1778
2002
|
const part = await partBuffer(
|
|
@@ -1781,7 +2005,8 @@ async function composeLayersFromParts(input) {
|
|
|
1781
2005
|
partsDir,
|
|
1782
2006
|
inMemory,
|
|
1783
2007
|
// The split halves are cut from eyewhite.png, the file a caller names.
|
|
1784
|
-
mirrored.has(inMemory === void 0 ? cfg.src : EYEWHITE_SRC)
|
|
2008
|
+
mirrored.has(inMemory === void 0 ? cfg.src : EYEWHITE_SRC),
|
|
2009
|
+
canvas
|
|
1785
2010
|
);
|
|
1786
2011
|
if (part === null || lower && !await hasCoverage(part.buf)) {
|
|
1787
2012
|
skipped.push(role);
|
|
@@ -1793,9 +2018,9 @@ async function composeLayersFromParts(input) {
|
|
|
1793
2018
|
noseSpeck = part.nose?.speck;
|
|
1794
2019
|
const { core, bounds } = await coreAndBoundsOf(part.buf);
|
|
1795
2020
|
const box = part.nose?.whole ? bounds : core ?? bounds;
|
|
1796
|
-
({ left, top } = nosePlacement(layout, box, part.w, part.h));
|
|
2021
|
+
({ left, top } = nosePlacement(layout, box, part.w, part.h, canvas));
|
|
1797
2022
|
} else {
|
|
1798
|
-
({ left, top } = placement(key, layout[key], part.w, part.h));
|
|
2023
|
+
({ left, top } = placement(key, layout[key], part.w, part.h, canvas));
|
|
1799
2024
|
}
|
|
1800
2025
|
if (role === "lash_L" || role === "lash_R") {
|
|
1801
2026
|
const eyeRole = role === "lash_L" ? "eye_L" : "eye_R";
|
|
@@ -1808,14 +2033,15 @@ async function composeLayersFromParts(input) {
|
|
|
1808
2033
|
}
|
|
1809
2034
|
placed.push({ role, part, left, top });
|
|
1810
2035
|
}
|
|
1811
|
-
for (const role of
|
|
1812
|
-
|
|
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 });
|
|
1813
2039
|
}
|
|
1814
2040
|
const layers = [];
|
|
1815
2041
|
const preview = [];
|
|
1816
2042
|
for (const { role, part, left, top } of placed) {
|
|
1817
|
-
const layer = await blankCanvas().composite([{ input: part.buf, left, top }]).png().toBuffer();
|
|
1818
|
-
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`);
|
|
1819
2045
|
writeFileAtomic(outPath, layer);
|
|
1820
2046
|
layers.push({
|
|
1821
2047
|
role,
|
|
@@ -1827,15 +2053,15 @@ async function composeLayersFromParts(input) {
|
|
|
1827
2053
|
});
|
|
1828
2054
|
preview.push({ input: part.buf, left, top });
|
|
1829
2055
|
}
|
|
1830
|
-
const previewPng = await (0,
|
|
2056
|
+
const previewPng = await (0, import_sharp3.default)({
|
|
1831
2057
|
create: {
|
|
1832
|
-
width:
|
|
1833
|
-
height:
|
|
2058
|
+
width: canvas.width,
|
|
2059
|
+
height: canvas.height,
|
|
1834
2060
|
channels: 4,
|
|
1835
2061
|
background: { r: 245, g: 245, b: 248, alpha: 1 }
|
|
1836
2062
|
}
|
|
1837
2063
|
}).composite(preview).png().toBuffer();
|
|
1838
|
-
const previewPath =
|
|
2064
|
+
const previewPath = import_node_path6.default.join(outDir, "preview.png");
|
|
1839
2065
|
writeFileAtomic(previewPath, previewPng);
|
|
1840
2066
|
return {
|
|
1841
2067
|
ok: true,
|
|
@@ -1854,7 +2080,7 @@ async function composeLayersFromParts(input) {
|
|
|
1854
2080
|
|
|
1855
2081
|
// src/server.ts
|
|
1856
2082
|
function createIkiMcpServer() {
|
|
1857
|
-
const server = new import_mcp.McpServer({ name: "iki", version: "0.
|
|
2083
|
+
const server = new import_mcp.McpServer({ name: "iki", version: "0.19.0" });
|
|
1858
2084
|
server.registerTool(
|
|
1859
2085
|
"validate_iki",
|
|
1860
2086
|
{
|
|
@@ -1919,7 +2145,7 @@ function createIkiMcpServer() {
|
|
|
1919
2145
|
server.registerTool(
|
|
1920
2146
|
"auto_rig_from_layers",
|
|
1921
2147
|
{
|
|
1922
|
-
description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R, mouth required; iris_L/R, brow_L/R, hair_front, etc. optional) into a renderable .iki written to disk. Pass full-canvas PNG file paths; returns the output path + summary (the model is NOT inlined). Filenames map to roles unless `fileName` is given.",
|
|
2148
|
+
description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R, mouth required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, etc. optional; an arm needs the body) into a renderable .iki written to disk. Pass full-canvas PNG file paths; returns the output path + summary (the model is NOT inlined). Filenames map to roles unless `fileName` is given.",
|
|
1923
2149
|
inputSchema: {
|
|
1924
2150
|
layers: import_zod.z.array(
|
|
1925
2151
|
import_zod.z.object({
|
|
@@ -1974,13 +2200,13 @@ function createIkiMcpServer() {
|
|
|
1974
2200
|
server.registerTool(
|
|
1975
2201
|
"compose_layers_from_parts",
|
|
1976
2202
|
{
|
|
1977
|
-
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`.",
|
|
1978
2204
|
inputSchema: {
|
|
1979
2205
|
partsDir: import_zod.z.string().describe(
|
|
1980
2206
|
"Directory of the source part PNGs (resolved against cwd)."
|
|
1981
2207
|
),
|
|
1982
2208
|
outDir: import_zod.z.string().describe(
|
|
1983
|
-
"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."
|
|
1984
2210
|
),
|
|
1985
2211
|
layout: import_zod.z.record(
|
|
1986
2212
|
import_zod.z.string(),
|
|
@@ -1991,10 +2217,13 @@ function createIkiMcpServer() {
|
|
|
1991
2217
|
h: import_zod.z.number()
|
|
1992
2218
|
}).partial()
|
|
1993
2219
|
).optional().describe(
|
|
1994
|
-
"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."
|
|
1995
2221
|
),
|
|
1996
2222
|
mirrorParts: import_zod.z.array(import_zod.z.string()).optional().describe(
|
|
1997
|
-
"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."
|
|
1998
2227
|
)
|
|
1999
2228
|
}
|
|
2000
2229
|
},
|
|
@@ -2019,7 +2248,7 @@ function createIkiMcpServer() {
|
|
|
2019
2248
|
server.registerTool(
|
|
2020
2249
|
"measure_layers",
|
|
2021
2250
|
{
|
|
2022
|
-
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.",
|
|
2023
2252
|
inputSchema: {
|
|
2024
2253
|
layersDir: import_zod.z.string().describe(
|
|
2025
2254
|
"Directory of role-named layer PNGs (resolved against cwd)."
|