@ikijs/mcp 0.9.0 → 0.11.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 +6 -5
- package/dist/{chunk-R6LYJVYC.mjs → chunk-LOOIWB2J.mjs} +219 -63
- package/dist/chunk-LOOIWB2J.mjs.map +1 -0
- package/dist/cli.js +218 -62
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +31 -4
- package/dist/index.d.ts +31 -4
- package/dist/index.js +218 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-R6LYJVYC.mjs.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -254,6 +254,24 @@ var BG_HUE_MAX = 260;
|
|
|
254
254
|
var BG_SAT_MAX = 0.2;
|
|
255
255
|
var BG_V_MIN = 0.55;
|
|
256
256
|
var BG_V_BLACK = 0.03;
|
|
257
|
+
function denseCoreOf(rgba, width, height) {
|
|
258
|
+
let minX = width;
|
|
259
|
+
let minY = height;
|
|
260
|
+
let maxX = -1;
|
|
261
|
+
let maxY = -1;
|
|
262
|
+
for (let y = 0; y < height; y++) {
|
|
263
|
+
for (let x = 0; x < width; x++) {
|
|
264
|
+
if (rgba[(y * width + x) * 4 + 3] >= ALPHA_OPAQUE) {
|
|
265
|
+
if (x < minX) minX = x;
|
|
266
|
+
if (x > maxX) maxX = x;
|
|
267
|
+
if (y < minY) minY = y;
|
|
268
|
+
if (y > maxY) maxY = y;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (maxX < 0) return null;
|
|
273
|
+
return { x: minX, y: minY, w: maxX - minX + 1, h: maxY - minY + 1 };
|
|
274
|
+
}
|
|
257
275
|
function rgbToHsv(r, g, b) {
|
|
258
276
|
r /= 255;
|
|
259
277
|
g /= 255;
|
|
@@ -775,6 +793,19 @@ function facePlateHalfOf(layers) {
|
|
|
775
793
|
return face.cropW / 2;
|
|
776
794
|
}
|
|
777
795
|
var STRAND_MIN_RUN_FRACTION = 0.5;
|
|
796
|
+
var LOSSLESS_PAGE_ROLE = "nose";
|
|
797
|
+
async function renderAtlasPage(crops, quantizeColors) {
|
|
798
|
+
const layout = (0, import_editor2.packAtlas)(
|
|
799
|
+
crops.map((c) => ({ id: c.id, width: c.width, height: c.height }))
|
|
800
|
+
);
|
|
801
|
+
if (layout.pageWidth * layout.pageHeight > MAX_ATLAS_AREA) {
|
|
802
|
+
throw new AutoRigInputError(
|
|
803
|
+
`atlas page ${layout.pageWidth}x${layout.pageHeight} exceeds max area ${MAX_ATLAS_AREA}`
|
|
804
|
+
);
|
|
805
|
+
}
|
|
806
|
+
const dataUri = await renderAtlasToDataUri(crops, layout, quantizeColors);
|
|
807
|
+
return { crops, layout, dataUri };
|
|
808
|
+
}
|
|
778
809
|
async function autoRigFromLayers(input) {
|
|
779
810
|
try {
|
|
780
811
|
const layers = input.layers;
|
|
@@ -886,10 +917,14 @@ async function autoRigFromLayers(input) {
|
|
|
886
917
|
);
|
|
887
918
|
}
|
|
888
919
|
layer.rowHalfWidths = rowHalfWidths;
|
|
920
|
+
} else if (role === "nose") {
|
|
921
|
+
const core = denseCoreOf(png.rgba, canvasW, canvasH);
|
|
922
|
+
if (core !== null) layer.denseCore = core;
|
|
889
923
|
}
|
|
890
924
|
layerInputs.push(layer);
|
|
891
925
|
crops.push({ id: role, buffer, width: bbox.w, height: bbox.h });
|
|
892
926
|
}
|
|
927
|
+
const noseCore = layerInputs.find((l) => l.role === "nose")?.denseCore;
|
|
893
928
|
const eyeRow = eyeRowOf(layerInputs);
|
|
894
929
|
const span = foregroundSpan(
|
|
895
930
|
opaque,
|
|
@@ -999,46 +1034,58 @@ async function autoRigFromLayers(input) {
|
|
|
999
1034
|
throw new AutoRigInputError(e.message);
|
|
1000
1035
|
}
|
|
1001
1036
|
const doc = new import_editor2.EditorDocument(model);
|
|
1002
|
-
const
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
)
|
|
1009
|
-
|
|
1010
|
-
const
|
|
1011
|
-
if (
|
|
1037
|
+
const losslessCrop = quantizeColors === void 0 ? void 0 : crops.find((c) => c.id === LOSSLESS_PAGE_ROLE);
|
|
1038
|
+
const pages = losslessCrop === void 0 ? [await renderAtlasPage(crops, quantizeColors)] : [
|
|
1039
|
+
await renderAtlasPage(
|
|
1040
|
+
crops.filter((c) => c !== losslessCrop),
|
|
1041
|
+
quantizeColors
|
|
1042
|
+
),
|
|
1043
|
+
await renderAtlasPage([losslessCrop], void 0)
|
|
1044
|
+
];
|
|
1045
|
+
const atlasBytes = pages.reduce((sum, p) => sum + p.dataUri.length, 0);
|
|
1046
|
+
if (atlasBytes > MAX_OUTPUT_BYTES) {
|
|
1012
1047
|
throw new AutoRigInputError(
|
|
1013
|
-
`atlas data URI ${
|
|
1048
|
+
`atlas data URI ${atlasBytes} bytes exceeds ${MAX_OUTPUT_BYTES}`
|
|
1014
1049
|
);
|
|
1015
1050
|
}
|
|
1016
|
-
const partTextureAssignments =
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1051
|
+
const partTextureAssignments = pages.flatMap(
|
|
1052
|
+
({ crops: pageCrops, layout }) => pageCrops.map((crop) => {
|
|
1053
|
+
const placement2 = layout.placements.find((p) => p.id === crop.id);
|
|
1054
|
+
if (placement2 === void 0) {
|
|
1055
|
+
throw new Error(`auto-rig: no atlas placement for "${crop.id}"`);
|
|
1056
|
+
}
|
|
1057
|
+
return {
|
|
1058
|
+
partId: crop.id,
|
|
1059
|
+
uv: (0, import_editor2.uvRectFor)(placement2, {
|
|
1060
|
+
width: layout.pageWidth,
|
|
1061
|
+
height: layout.pageHeight
|
|
1062
|
+
})
|
|
1063
|
+
};
|
|
1064
|
+
})
|
|
1065
|
+
);
|
|
1066
|
+
doc.applyAtlas({
|
|
1067
|
+
textures: [{ source: pages[0].dataUri }],
|
|
1068
|
+
partTextureAssignments
|
|
1028
1069
|
});
|
|
1029
|
-
doc.
|
|
1030
|
-
|
|
1070
|
+
let patched = doc.getModel();
|
|
1071
|
+
if (losslessCrop !== void 0) {
|
|
1072
|
+
patched = structuredClone(patched);
|
|
1073
|
+
patched.textures = pages.map((p) => ({ source: p.dataUri }));
|
|
1074
|
+
patched.parts.find((p) => p.id === losslessCrop.id).texture.index = 1;
|
|
1075
|
+
}
|
|
1076
|
+
const finalModel = (0, import_format.parseIkiModel)(patched);
|
|
1031
1077
|
writeFileAtomic(outPath, JSON.stringify(finalModel));
|
|
1032
1078
|
return {
|
|
1033
1079
|
ok: true,
|
|
1034
1080
|
path: outPath,
|
|
1035
1081
|
canvas: { width: canvasW, height: canvasH },
|
|
1036
1082
|
partCount: finalModel.parts.length,
|
|
1037
|
-
atlasBytes
|
|
1083
|
+
atlasBytes,
|
|
1038
1084
|
...headHalfWidth === void 0 ? {} : { headHalfWidth },
|
|
1039
1085
|
headHalfWidthApplied,
|
|
1040
1086
|
...headEdges === void 0 ? {} : { headEdges },
|
|
1041
1087
|
...strandEdges === void 0 ? {} : { strandEdges },
|
|
1088
|
+
...noseCore === void 0 ? {} : { noseCore },
|
|
1042
1089
|
...turn === void 0 ? {} : { turn }
|
|
1043
1090
|
};
|
|
1044
1091
|
} catch (err) {
|
|
@@ -1062,7 +1109,8 @@ var EYE_ASPECT_MIN = 0.5;
|
|
|
1062
1109
|
var IRIS_OFFSET_MAX_X = 3;
|
|
1063
1110
|
var IRIS_OFFSET_MAX_Y = 10;
|
|
1064
1111
|
var EDGE_SOLID_MAX = 0.5;
|
|
1065
|
-
var
|
|
1112
|
+
var LASH_STRAY_TOL_FRAC = 0.02;
|
|
1113
|
+
var EYE_FACING_TOL_FRAC = 0.02;
|
|
1066
1114
|
var EDGE_RUN_MIN_PX = 40;
|
|
1067
1115
|
var FLAT_CUT_MAX_FRAC = 0.1;
|
|
1068
1116
|
var FLAT_CUT_MIN_PX = 40;
|
|
@@ -1143,6 +1191,21 @@ async function layerStats(filePath) {
|
|
|
1143
1191
|
};
|
|
1144
1192
|
}
|
|
1145
1193
|
var pct = (v) => `${(v * 100).toFixed(0)}%`;
|
|
1194
|
+
async function lashOffSclera(eyePath, lashPath) {
|
|
1195
|
+
const eye = await decodePng(eyePath);
|
|
1196
|
+
const lash = await decodePng(lashPath);
|
|
1197
|
+
let opaque = 0;
|
|
1198
|
+
let off = 0;
|
|
1199
|
+
for (let y = 0; y < lash.height; y++) {
|
|
1200
|
+
for (let x = 0; x < lash.width; x++) {
|
|
1201
|
+
if (lash.rgba[(y * lash.width + x) * 4 + 3] < 128) continue;
|
|
1202
|
+
opaque++;
|
|
1203
|
+
const onEye = x < eye.width && y < eye.height;
|
|
1204
|
+
if (!onEye || eye.rgba[(y * eye.width + x) * 4 + 3] <= 8) off++;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
return { opaque, off };
|
|
1208
|
+
}
|
|
1146
1209
|
async function measureDir(absDir) {
|
|
1147
1210
|
const files = import_node_fs2.default.readdirSync(absDir).filter((f) => f.endsWith(".png") && f !== "preview.png").sort();
|
|
1148
1211
|
if (files.length === 0) {
|
|
@@ -1224,12 +1287,28 @@ async function measureDir(absDir) {
|
|
|
1224
1287
|
}
|
|
1225
1288
|
}
|
|
1226
1289
|
if (lash) {
|
|
1227
|
-
const
|
|
1290
|
+
const { opaque, off } = await lashOffSclera(
|
|
1291
|
+
import_node_path4.default.join(absDir, `eye_${side}.png`),
|
|
1292
|
+
import_node_path4.default.join(absDir, `lash_${side}.png`)
|
|
1293
|
+
);
|
|
1228
1294
|
const dTop = lash.marginTop - eye.marginTop;
|
|
1229
|
-
|
|
1295
|
+
const faults = [
|
|
1296
|
+
...off > opaque * LASH_STRAY_TOL_FRAC ? [`${off} of its ${opaque} opaque px lie off eye_${side}'s sclera`] : [],
|
|
1297
|
+
...Math.abs(dTop) > 0.5 ? [`its top edge is ${dTop.toFixed(1)} px off the sclera's`] : []
|
|
1298
|
+
];
|
|
1299
|
+
if (faults.length > 0) {
|
|
1230
1300
|
warnings.push(
|
|
1231
|
-
`lash_${side}:
|
|
1301
|
+
`lash_${side}: ${faults.join(" and ")} \u2014 they are split from one source and MUST share cx/cy/w/h in layout, or the blink fold tears. Retune to match.`
|
|
1232
1302
|
);
|
|
1303
|
+
} else {
|
|
1304
|
+
const bareLeft = lash.marginLeft - eye.marginLeft;
|
|
1305
|
+
const bareRight = lash.marginRight - eye.marginRight;
|
|
1306
|
+
const [bareOuter, bareInner] = side === "R" ? [bareLeft, bareRight] : [bareRight, bareLeft];
|
|
1307
|
+
if ((bareOuter - bareInner) / eye.w > EYE_FACING_TOL_FRAC) {
|
|
1308
|
+
warnings.push(
|
|
1309
|
+
`eye_${side}: its lash stops ${pct(bareOuter / eye.w)} of the eye width short of the outer corner and ${pct(bareInner / eye.w)} short of the nose side \u2014 the eyewhite is drawn facing the other way, lash wing at the inner corner. 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. Free fix: compose again with mirrorParts: ["eyewhite.png"] \u2014 no regeneration.`
|
|
1310
|
+
);
|
|
1311
|
+
}
|
|
1233
1312
|
}
|
|
1234
1313
|
}
|
|
1235
1314
|
}
|
|
@@ -1293,6 +1372,7 @@ var IRIS_W = Math.round(EYE_W * 0.5625);
|
|
|
1293
1372
|
var EYEWHITE_SRC = "eyewhite.png";
|
|
1294
1373
|
var EYE_LASH_LUMA = 120;
|
|
1295
1374
|
var LASH_KEEP_FRACTION = 0.5;
|
|
1375
|
+
var NOSE_TIP_AT = 0.86;
|
|
1296
1376
|
var DEFAULT_LAYOUT = {
|
|
1297
1377
|
// Back hair and body sit behind the face. Both are OPTIONAL: a parts dir
|
|
1298
1378
|
// without them still composes (head-only character).
|
|
@@ -1304,9 +1384,11 @@ var DEFAULT_LAYOUT = {
|
|
|
1304
1384
|
face: { src: "face.png", cx: 550, cy: 475, w: 400 },
|
|
1305
1385
|
// The nose, drawn on its own (the face is drawn without one): the auto-rig
|
|
1306
1386
|
// leads the head turn with it and keys the other features' slide on its
|
|
1307
|
-
// presence, so without it the features stay on the face plate.
|
|
1308
|
-
//
|
|
1309
|
-
|
|
1387
|
+
// presence, so without it the features stay on the face plate. `w` is the
|
|
1388
|
+
// width of its dense core, and it has no `cy`: its row comes from the tip
|
|
1389
|
+
// rule (NOSE_TIP_AT), between the eyes and the mouth, so it follows them
|
|
1390
|
+
// when they are retuned. OPTIONAL: a parts dir without it composes.
|
|
1391
|
+
nose: { src: "nose.png", cx: 550, w: 40, optional: true },
|
|
1310
1392
|
mouth: { src: "mouth.png", cx: 550, cy: 619, w: 68 },
|
|
1311
1393
|
// Cross-fades with `mouth` on ParamMouthOpenY (opacity, not scaleY) once the
|
|
1312
1394
|
// auto-rig sees both roles. Same cx/w as `mouth` so the lip width matches;
|
|
@@ -1361,6 +1443,12 @@ var ORDER = [
|
|
|
1361
1443
|
"brow_R",
|
|
1362
1444
|
"hair_front"
|
|
1363
1445
|
];
|
|
1446
|
+
var PART_FILES = [
|
|
1447
|
+
...new Set(
|
|
1448
|
+
Object.values(DEFAULT_LAYOUT).map((cfg) => cfg.src).filter((src) => !src.startsWith("eyewhite_"))
|
|
1449
|
+
),
|
|
1450
|
+
EYEWHITE_SRC
|
|
1451
|
+
];
|
|
1364
1452
|
function resolveLayout(overrides) {
|
|
1365
1453
|
const resolved = { ...DEFAULT_LAYOUT };
|
|
1366
1454
|
if (overrides === void 0) return resolved;
|
|
@@ -1371,7 +1459,7 @@ function resolveLayout(overrides) {
|
|
|
1371
1459
|
);
|
|
1372
1460
|
}
|
|
1373
1461
|
if (override === void 0) continue;
|
|
1374
|
-
const
|
|
1462
|
+
const set = {};
|
|
1375
1463
|
for (const field of ["cx", "cy"]) {
|
|
1376
1464
|
const value = override[field];
|
|
1377
1465
|
if (value === void 0) continue;
|
|
@@ -1380,7 +1468,7 @@ function resolveLayout(overrides) {
|
|
|
1380
1468
|
`layout.${role}.${field} must be a finite number, got ${String(value)}`
|
|
1381
1469
|
);
|
|
1382
1470
|
}
|
|
1383
|
-
|
|
1471
|
+
set[field] = value;
|
|
1384
1472
|
}
|
|
1385
1473
|
for (const field of ["w", "h"]) {
|
|
1386
1474
|
const value = override[field];
|
|
@@ -1390,12 +1478,26 @@ function resolveLayout(overrides) {
|
|
|
1390
1478
|
`layout.${role}.${field} must be an integer in 1..${CANVAS}, got ${String(value)}`
|
|
1391
1479
|
);
|
|
1392
1480
|
}
|
|
1393
|
-
|
|
1481
|
+
set[field] = value;
|
|
1394
1482
|
}
|
|
1395
|
-
|
|
1483
|
+
const key = role;
|
|
1484
|
+
if (key === "nose") resolved.nose = { ...resolved.nose, ...set };
|
|
1485
|
+
else resolved[key] = { ...resolved[key], ...set };
|
|
1396
1486
|
}
|
|
1397
1487
|
return resolved;
|
|
1398
1488
|
}
|
|
1489
|
+
function resolveMirrorParts(names) {
|
|
1490
|
+
const mirrored = /* @__PURE__ */ new Set();
|
|
1491
|
+
for (const [i, name] of (names ?? []).entries()) {
|
|
1492
|
+
if (!PART_FILES.includes(name)) {
|
|
1493
|
+
throw new AutoRigInputError(
|
|
1494
|
+
`mirrorParts[${i}]: unknown part ${JSON.stringify(name)} \u2014 expected one of ${PART_FILES.join(", ")}`
|
|
1495
|
+
);
|
|
1496
|
+
}
|
|
1497
|
+
mirrored.add(name);
|
|
1498
|
+
}
|
|
1499
|
+
return mirrored;
|
|
1500
|
+
}
|
|
1399
1501
|
function keyWhiteToAlpha(rgba) {
|
|
1400
1502
|
const keyed = Buffer.from(rgba);
|
|
1401
1503
|
for (let i = 0; i < keyed.length; i += 4) {
|
|
@@ -1405,7 +1507,16 @@ function keyWhiteToAlpha(rgba) {
|
|
|
1405
1507
|
}
|
|
1406
1508
|
return keyed;
|
|
1407
1509
|
}
|
|
1408
|
-
async function
|
|
1510
|
+
async function coreOf(png) {
|
|
1511
|
+
const { data, info } = await (0, import_sharp2.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
1512
|
+
return denseCoreOf(data, info.width, info.height) ?? {
|
|
1513
|
+
x: 0,
|
|
1514
|
+
y: 0,
|
|
1515
|
+
w: info.width,
|
|
1516
|
+
h: info.height
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
|
|
1409
1520
|
let img;
|
|
1410
1521
|
if (inMemory !== void 0) {
|
|
1411
1522
|
img = (0, import_sharp2.default)(inMemory);
|
|
@@ -1423,35 +1534,58 @@ async function partBuffer(role, cfg, partsDir, inMemory) {
|
|
|
1423
1534
|
});
|
|
1424
1535
|
}
|
|
1425
1536
|
if (!cfg.noTrim) img = img.trim({ threshold: 12 });
|
|
1426
|
-
if (cfg.mirror) img = img.flop();
|
|
1537
|
+
if ((cfg.mirror ?? false) !== flipSource) img = img.flop();
|
|
1427
1538
|
const trimmed = await img.png().toBuffer({ resolveWithObject: true });
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1539
|
+
const { width: trimmedW, height: trimmedH } = trimmed.info;
|
|
1540
|
+
const sized = role === "nose" ? await coreOf(trimmed.data) : { x: 0, y: 0, w: trimmedW, h: trimmedH };
|
|
1541
|
+
const width = Math.round(trimmedW * cfg.w / sized.w);
|
|
1542
|
+
const height = cfg.h === void 0 ? Math.round(trimmedH * width / trimmedW) : Math.round(trimmedH * cfg.h / sized.h);
|
|
1543
|
+
if (width > CANVAS || height > CANVAS) {
|
|
1544
|
+
const field = width > CANVAS || cfg.h === void 0 ? "w" : "h";
|
|
1545
|
+
throw new AutoRigInputError(
|
|
1546
|
+
`layout.${role}.${field}: resized part ${width}x${height} exceeds the ${CANVAS} canvas`
|
|
1431
1547
|
);
|
|
1432
|
-
if (scaledH > CANVAS) {
|
|
1433
|
-
throw new AutoRigInputError(
|
|
1434
|
-
`layout.${role}.w: resized part ${cfg.w}x${scaledH} exceeds the ${CANVAS} canvas`
|
|
1435
|
-
);
|
|
1436
|
-
}
|
|
1437
1548
|
}
|
|
1438
|
-
const resized = await (0, import_sharp2.default)(trimmed.data).resize(
|
|
1439
|
-
cfg.h === void 0 ? { width: cfg.w } : { width: cfg.w, height: cfg.h, fit: "fill" }
|
|
1440
|
-
).png().toBuffer({ resolveWithObject: true });
|
|
1549
|
+
const resized = await (0, import_sharp2.default)(trimmed.data).resize(cfg.h === void 0 ? { width } : { width, height, fit: "fill" }).png().toBuffer({ resolveWithObject: true });
|
|
1441
1550
|
return {
|
|
1442
1551
|
buf: resized.data,
|
|
1443
1552
|
w: resized.info.width,
|
|
1444
1553
|
h: resized.info.height
|
|
1445
1554
|
};
|
|
1446
1555
|
}
|
|
1447
|
-
function
|
|
1448
|
-
const left = Math.round(cfg.cx - w / 2);
|
|
1449
|
-
const top = Math.round(cfg.cy - h / 2);
|
|
1556
|
+
function assertOnCanvas(source, w, h, left, top) {
|
|
1450
1557
|
if (left + w <= 0 || top + h <= 0 || left >= CANVAS || top >= CANVAS) {
|
|
1451
1558
|
throw new AutoRigInputError(
|
|
1452
|
-
|
|
1559
|
+
`${source}: the placed part (${w}x${h} at ${left},${top}) falls entirely outside the ${CANVAS} canvas`
|
|
1453
1560
|
);
|
|
1454
1561
|
}
|
|
1562
|
+
}
|
|
1563
|
+
function placement(role, cfg, w, h) {
|
|
1564
|
+
const left = Math.round(cfg.cx - w / 2);
|
|
1565
|
+
const top = Math.round(cfg.cy - h / 2);
|
|
1566
|
+
assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top);
|
|
1567
|
+
return { left, top };
|
|
1568
|
+
}
|
|
1569
|
+
function nosePlacement(layout, core, w, h) {
|
|
1570
|
+
const { cx, cy } = layout.nose;
|
|
1571
|
+
const left = Math.round(cx - (core.x + core.w / 2));
|
|
1572
|
+
let top;
|
|
1573
|
+
if (cy !== void 0) {
|
|
1574
|
+
top = Math.round(cy - (core.y + core.h / 2));
|
|
1575
|
+
} else {
|
|
1576
|
+
const eyeRow = (layout.eye_L.cy + layout.eye_R.cy) / 2;
|
|
1577
|
+
const tipRow = Math.round(
|
|
1578
|
+
eyeRow + NOSE_TIP_AT * (layout.mouth.cy - eyeRow)
|
|
1579
|
+
);
|
|
1580
|
+
top = tipRow - (core.y + core.h - 1);
|
|
1581
|
+
}
|
|
1582
|
+
assertOnCanvas(
|
|
1583
|
+
cy !== void 0 ? "layout.nose.cx/cy" : "layout.nose.cx/cy (cy unset: its tip row comes from layout.eye_L/eye_R/mouth.cy)",
|
|
1584
|
+
w,
|
|
1585
|
+
h,
|
|
1586
|
+
left,
|
|
1587
|
+
top
|
|
1588
|
+
);
|
|
1455
1589
|
return { left, top };
|
|
1456
1590
|
}
|
|
1457
1591
|
function blankCanvas() {
|
|
@@ -1520,28 +1654,47 @@ async function composeLayersFromParts(input) {
|
|
|
1520
1654
|
);
|
|
1521
1655
|
}
|
|
1522
1656
|
const layout = resolveLayout(input.layout);
|
|
1657
|
+
const mirrored = resolveMirrorParts(input.mirrorParts);
|
|
1523
1658
|
const split = await prepEyeSplit(partsDir);
|
|
1524
1659
|
const splitSources = /* @__PURE__ */ new Map([
|
|
1525
1660
|
["eyewhite_sclera.png", split.sclera],
|
|
1526
1661
|
["eyewhite_lash.png", split.lash]
|
|
1527
1662
|
]);
|
|
1528
|
-
const
|
|
1663
|
+
const placed = [];
|
|
1529
1664
|
const skipped = [];
|
|
1530
|
-
const preview = [];
|
|
1531
1665
|
for (const role of ORDER) {
|
|
1532
1666
|
const cfg = layout[role];
|
|
1667
|
+
const inMemory = splitSources.get(cfg.src);
|
|
1533
1668
|
const part = await partBuffer(
|
|
1534
1669
|
role,
|
|
1535
1670
|
cfg,
|
|
1536
1671
|
partsDir,
|
|
1537
|
-
|
|
1672
|
+
inMemory,
|
|
1673
|
+
// The split halves are cut from eyewhite.png, the file a caller names.
|
|
1674
|
+
mirrored.has(inMemory === void 0 ? cfg.src : EYEWHITE_SRC)
|
|
1538
1675
|
);
|
|
1539
1676
|
if (part === null) {
|
|
1540
1677
|
skipped.push(role);
|
|
1541
|
-
import_node_fs3.default.rmSync(import_node_path5.default.join(outDir, `${role}.png`), { force: true });
|
|
1542
1678
|
continue;
|
|
1543
1679
|
}
|
|
1544
|
-
const { left, top } = placement(role,
|
|
1680
|
+
const { left, top } = role === "nose" ? nosePlacement(layout, await coreOf(part.buf), part.w, part.h) : placement(role, layout[role], part.w, part.h);
|
|
1681
|
+
if (role === "lash_L" || role === "lash_R") {
|
|
1682
|
+
const eyeRole = role === "lash_L" ? "eye_L" : "eye_R";
|
|
1683
|
+
const eye = placed.find((p) => p.role === eyeRole);
|
|
1684
|
+
if (eye !== void 0 && (eye.left !== left || eye.top !== top || eye.part.w !== part.w || eye.part.h !== part.h)) {
|
|
1685
|
+
throw new AutoRigInputError(
|
|
1686
|
+
`layout.${role} places the lash at ${part.w}x${part.h} (${left},${top}), but layout.${eyeRole} places its sclera at ${eye.part.w}x${eye.part.h} (${eye.left},${eye.top}) \u2014 they are cut from one eyewhite into one frame, and the blink fold tears where they part. Set cx/cy/w/h the same on both.`
|
|
1687
|
+
);
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
placed.push({ role, part, left, top });
|
|
1691
|
+
}
|
|
1692
|
+
for (const role of skipped) {
|
|
1693
|
+
import_node_fs3.default.rmSync(import_node_path5.default.join(outDir, `${role}.png`), { force: true });
|
|
1694
|
+
}
|
|
1695
|
+
const layers = [];
|
|
1696
|
+
const preview = [];
|
|
1697
|
+
for (const { role, part, left, top } of placed) {
|
|
1545
1698
|
const layer = await blankCanvas().composite([{ input: part.buf, left, top }]).png().toBuffer();
|
|
1546
1699
|
const outPath = import_node_path5.default.join(outDir, `${role}.png`);
|
|
1547
1700
|
writeFileAtomic(outPath, layer);
|
|
@@ -1582,7 +1735,7 @@ async function composeLayersFromParts(input) {
|
|
|
1582
1735
|
|
|
1583
1736
|
// src/server.ts
|
|
1584
1737
|
function createIkiMcpServer() {
|
|
1585
|
-
const server = new import_mcp.McpServer({ name: "iki", version: "0.
|
|
1738
|
+
const server = new import_mcp.McpServer({ name: "iki", version: "0.11.0" });
|
|
1586
1739
|
server.registerTool(
|
|
1587
1740
|
"validate_iki",
|
|
1588
1741
|
{
|
|
@@ -1661,7 +1814,7 @@ function createIkiMcpServer() {
|
|
|
1661
1814
|
"Output .iki path (resolved against cwd; parent dir must exist)."
|
|
1662
1815
|
),
|
|
1663
1816
|
quantizeColors: import_zod.z.number().int().min(2).max(256).optional().describe(
|
|
1664
|
-
"Palette-quantize the atlas PNG to this many colours (2..256). Flat-shaded art keeps its look at 256 and the model shrinks to about a quarter; omit for lossless."
|
|
1817
|
+
"Palette-quantize the atlas PNG to this many colours (2..256). Flat-shaded art keeps its look at 256 and the model shrinks to about a quarter; omit for lossless. A `nose` layer stays lossless on a second atlas page of its own, since the palette rims a soft-shaded nose's feather; the nose's own lossless page adds a content-dependent amount, since splitting it off also changes how page 0 re-quantizes without it; the result's `atlasBytes` sums both pages."
|
|
1665
1818
|
),
|
|
1666
1819
|
turnTargets: import_zod.z.object({
|
|
1667
1820
|
eyeShift: import_zod.z.number().optional(),
|
|
@@ -1709,7 +1862,10 @@ function createIkiMcpServer() {
|
|
|
1709
1862
|
h: import_zod.z.number()
|
|
1710
1863
|
}).partial()
|
|
1711
1864
|
).optional().describe(
|
|
1712
|
-
"Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, face, 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` are integers in 1..1100; omit `h` to keep the part's own aspect, set it to stretch (
|
|
1865
|
+
"Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, face, 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` are integers in 1..1100; omit `h` to keep the part's own aspect, set it to stretch. 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. Its `cy` defaults to unset, which lands the core's bottom row (the tip) 0.86 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."
|
|
1866
|
+
),
|
|
1867
|
+
mirrorParts: import_zod.z.array(import_zod.z.string()).optional().describe(
|
|
1868
|
+
"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) and brow.png as the brow on the screen RIGHT (thick head at the image's left end, tail at its right); 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."
|
|
1713
1869
|
)
|
|
1714
1870
|
}
|
|
1715
1871
|
},
|