@ikijs/mcp 0.10.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 +3 -3
- package/dist/{chunk-OCIICRUA.mjs → chunk-LOOIWB2J.mjs} +137 -53
- package/dist/chunk-LOOIWB2J.mjs.map +1 -0
- package/dist/cli.js +136 -52
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +24 -4
- package/dist/index.d.ts +24 -4
- package/dist/index.js +136 -52
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-OCIICRUA.mjs.map +0 -1
package/dist/cli.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -66,7 +66,9 @@ interface AutoRigInput {
|
|
|
66
66
|
/** Output `.iki` path (relative paths resolve against the process cwd). */
|
|
67
67
|
outputPath?: string;
|
|
68
68
|
/** Palette-quantize the atlas PNG to this many colours (integer, 2..256).
|
|
69
|
-
* Omitted = lossless. See renderAtlasToDataUri for the size/quality trade.
|
|
69
|
+
* Omitted = lossless. See renderAtlasToDataUri for the size/quality trade.
|
|
70
|
+
* A `nose` layer is left out of the quantized page, on a second, lossless
|
|
71
|
+
* page of its own, because the palette rims a soft-shaded nose's feather. */
|
|
70
72
|
quantizeColors?: number;
|
|
71
73
|
/** Head-turn cues to fit the rig to, as `measure_turn_reference` reports
|
|
72
74
|
* them. */
|
|
@@ -84,6 +86,8 @@ type AutoRigResult = {
|
|
|
84
86
|
height: number;
|
|
85
87
|
};
|
|
86
88
|
partCount: number;
|
|
89
|
+
/** The atlas's embedded size: its data URI's length, summed over both
|
|
90
|
+
* pages when a quantized rig puts the nose on a page of its own. */
|
|
87
91
|
atlasBytes: number;
|
|
88
92
|
/** The head's half-width at the eye row, measured off the layers.
|
|
89
93
|
* Absent when the opaque (alpha >= 128) union has no span there — a
|
|
@@ -129,6 +133,17 @@ type AutoRigResult = {
|
|
|
129
133
|
left?: IrisStrand;
|
|
130
134
|
right?: IrisStrand;
|
|
131
135
|
};
|
|
136
|
+
/** The nose's dense core, canvas px — its pixels at alpha >= 128, not
|
|
137
|
+
* grown — the box handed to the generator as the nose layer's
|
|
138
|
+
* `denseCore` and, there, its turn landmark. Absent without a `nose`
|
|
139
|
+
* layer, or when the nose has no pixel at that threshold (painted
|
|
140
|
+
* wholly translucent). */
|
|
141
|
+
noseCore?: {
|
|
142
|
+
x: number;
|
|
143
|
+
y: number;
|
|
144
|
+
w: number;
|
|
145
|
+
h: number;
|
|
146
|
+
};
|
|
132
147
|
/** What the turn solve settled on — the cues the rig reaches, the
|
|
133
148
|
* targets it had to cut down (`clamped`) and, per side whose far iris
|
|
134
149
|
* the bangs' run still covers at some far stop, how much of it
|
|
@@ -154,7 +169,12 @@ type AutoRigResult = {
|
|
|
154
169
|
* run it would slide under are measured on the iris's own centre row too
|
|
155
170
|
* (`strandEdges`), so the turn keeps the far iris from sliding under the bangs
|
|
156
171
|
* any further than it is painted; a run narrower than half the iris there is
|
|
157
|
-
* hair detail the iris may cross, and is skipped.
|
|
172
|
+
* hair detail the iris may cross, and is skipped. The nose layer alone also
|
|
173
|
+
* gets its dense core measured (`LayerInput.denseCore`, returned as
|
|
174
|
+
* `noseCore`), so a shaded nose is fitted and tilted by the drawing inside its
|
|
175
|
+
* feather rather than by the feather itself. Under `quantizeColors` that nose
|
|
176
|
+
* is atlased alone on a second, lossless page, which the palette would
|
|
177
|
+
* otherwise rim; `atlasBytes` sums both pages.
|
|
158
178
|
*
|
|
159
179
|
* Re-host of examples/editor/src/store.ts `importLayerSet` with the three DOM
|
|
160
180
|
* pixel functions swapped for the sharp-backed ./node-images helpers; the pure
|
|
@@ -242,7 +262,8 @@ declare function formatMeasureReport(result: MeasureReport & {
|
|
|
242
262
|
* Compose AI-generated part PNGs into canvas-aligned, role-named layers for the
|
|
243
263
|
* Iki auto-rig (`auto_rig_from_layers` / `@ikijs/editor` generateIkiFromLayerSet).
|
|
244
264
|
* Each part is alpha-trimmed, resized to a target width, optionally mirrored,
|
|
245
|
-
* and pasted at a chosen center on a shared transparent CANVAS x CANVAS canvas
|
|
265
|
+
* and pasted at a chosen center on a shared transparent CANVAS x CANVAS canvas
|
|
266
|
+
* — the nose by its dense core, the drawing inside a soft nose's feather.
|
|
246
267
|
*
|
|
247
268
|
* Ports the composer that shipped as a script in the Claude Code plugin, so a
|
|
248
269
|
* plugin user gets it from the MCP server instead of an ad-hoc `sharp` install.
|
|
@@ -277,7 +298,6 @@ declare const DEFAULT_LAYOUT: {
|
|
|
277
298
|
nose: {
|
|
278
299
|
src: string;
|
|
279
300
|
cx: number;
|
|
280
|
-
cy: number;
|
|
281
301
|
w: number;
|
|
282
302
|
optional: true;
|
|
283
303
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -66,7 +66,9 @@ interface AutoRigInput {
|
|
|
66
66
|
/** Output `.iki` path (relative paths resolve against the process cwd). */
|
|
67
67
|
outputPath?: string;
|
|
68
68
|
/** Palette-quantize the atlas PNG to this many colours (integer, 2..256).
|
|
69
|
-
* Omitted = lossless. See renderAtlasToDataUri for the size/quality trade.
|
|
69
|
+
* Omitted = lossless. See renderAtlasToDataUri for the size/quality trade.
|
|
70
|
+
* A `nose` layer is left out of the quantized page, on a second, lossless
|
|
71
|
+
* page of its own, because the palette rims a soft-shaded nose's feather. */
|
|
70
72
|
quantizeColors?: number;
|
|
71
73
|
/** Head-turn cues to fit the rig to, as `measure_turn_reference` reports
|
|
72
74
|
* them. */
|
|
@@ -84,6 +86,8 @@ type AutoRigResult = {
|
|
|
84
86
|
height: number;
|
|
85
87
|
};
|
|
86
88
|
partCount: number;
|
|
89
|
+
/** The atlas's embedded size: its data URI's length, summed over both
|
|
90
|
+
* pages when a quantized rig puts the nose on a page of its own. */
|
|
87
91
|
atlasBytes: number;
|
|
88
92
|
/** The head's half-width at the eye row, measured off the layers.
|
|
89
93
|
* Absent when the opaque (alpha >= 128) union has no span there — a
|
|
@@ -129,6 +133,17 @@ type AutoRigResult = {
|
|
|
129
133
|
left?: IrisStrand;
|
|
130
134
|
right?: IrisStrand;
|
|
131
135
|
};
|
|
136
|
+
/** The nose's dense core, canvas px — its pixels at alpha >= 128, not
|
|
137
|
+
* grown — the box handed to the generator as the nose layer's
|
|
138
|
+
* `denseCore` and, there, its turn landmark. Absent without a `nose`
|
|
139
|
+
* layer, or when the nose has no pixel at that threshold (painted
|
|
140
|
+
* wholly translucent). */
|
|
141
|
+
noseCore?: {
|
|
142
|
+
x: number;
|
|
143
|
+
y: number;
|
|
144
|
+
w: number;
|
|
145
|
+
h: number;
|
|
146
|
+
};
|
|
132
147
|
/** What the turn solve settled on — the cues the rig reaches, the
|
|
133
148
|
* targets it had to cut down (`clamped`) and, per side whose far iris
|
|
134
149
|
* the bangs' run still covers at some far stop, how much of it
|
|
@@ -154,7 +169,12 @@ type AutoRigResult = {
|
|
|
154
169
|
* run it would slide under are measured on the iris's own centre row too
|
|
155
170
|
* (`strandEdges`), so the turn keeps the far iris from sliding under the bangs
|
|
156
171
|
* any further than it is painted; a run narrower than half the iris there is
|
|
157
|
-
* hair detail the iris may cross, and is skipped.
|
|
172
|
+
* hair detail the iris may cross, and is skipped. The nose layer alone also
|
|
173
|
+
* gets its dense core measured (`LayerInput.denseCore`, returned as
|
|
174
|
+
* `noseCore`), so a shaded nose is fitted and tilted by the drawing inside its
|
|
175
|
+
* feather rather than by the feather itself. Under `quantizeColors` that nose
|
|
176
|
+
* is atlased alone on a second, lossless page, which the palette would
|
|
177
|
+
* otherwise rim; `atlasBytes` sums both pages.
|
|
158
178
|
*
|
|
159
179
|
* Re-host of examples/editor/src/store.ts `importLayerSet` with the three DOM
|
|
160
180
|
* pixel functions swapped for the sharp-backed ./node-images helpers; the pure
|
|
@@ -242,7 +262,8 @@ declare function formatMeasureReport(result: MeasureReport & {
|
|
|
242
262
|
* Compose AI-generated part PNGs into canvas-aligned, role-named layers for the
|
|
243
263
|
* Iki auto-rig (`auto_rig_from_layers` / `@ikijs/editor` generateIkiFromLayerSet).
|
|
244
264
|
* Each part is alpha-trimmed, resized to a target width, optionally mirrored,
|
|
245
|
-
* and pasted at a chosen center on a shared transparent CANVAS x CANVAS canvas
|
|
265
|
+
* and pasted at a chosen center on a shared transparent CANVAS x CANVAS canvas
|
|
266
|
+
* — the nose by its dense core, the drawing inside a soft nose's feather.
|
|
246
267
|
*
|
|
247
268
|
* Ports the composer that shipped as a script in the Claude Code plugin, so a
|
|
248
269
|
* plugin user gets it from the MCP server instead of an ad-hoc `sharp` install.
|
|
@@ -277,7 +298,6 @@ declare const DEFAULT_LAYOUT: {
|
|
|
277
298
|
nose: {
|
|
278
299
|
src: string;
|
|
279
300
|
cx: number;
|
|
280
|
-
cy: number;
|
|
281
301
|
w: number;
|
|
282
302
|
optional: true;
|
|
283
303
|
};
|
package/dist/index.js
CHANGED
|
@@ -270,6 +270,24 @@ var BG_HUE_MAX = 260;
|
|
|
270
270
|
var BG_SAT_MAX = 0.2;
|
|
271
271
|
var BG_V_MIN = 0.55;
|
|
272
272
|
var BG_V_BLACK = 0.03;
|
|
273
|
+
function denseCoreOf(rgba, width, height) {
|
|
274
|
+
let minX = width;
|
|
275
|
+
let minY = height;
|
|
276
|
+
let maxX = -1;
|
|
277
|
+
let maxY = -1;
|
|
278
|
+
for (let y = 0; y < height; y++) {
|
|
279
|
+
for (let x = 0; x < width; x++) {
|
|
280
|
+
if (rgba[(y * width + x) * 4 + 3] >= ALPHA_OPAQUE) {
|
|
281
|
+
if (x < minX) minX = x;
|
|
282
|
+
if (x > maxX) maxX = x;
|
|
283
|
+
if (y < minY) minY = y;
|
|
284
|
+
if (y > maxY) maxY = y;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (maxX < 0) return null;
|
|
289
|
+
return { x: minX, y: minY, w: maxX - minX + 1, h: maxY - minY + 1 };
|
|
290
|
+
}
|
|
273
291
|
function rgbToHsv(r, g, b) {
|
|
274
292
|
r /= 255;
|
|
275
293
|
g /= 255;
|
|
@@ -791,6 +809,19 @@ function facePlateHalfOf(layers) {
|
|
|
791
809
|
return face.cropW / 2;
|
|
792
810
|
}
|
|
793
811
|
var STRAND_MIN_RUN_FRACTION = 0.5;
|
|
812
|
+
var LOSSLESS_PAGE_ROLE = "nose";
|
|
813
|
+
async function renderAtlasPage(crops, quantizeColors) {
|
|
814
|
+
const layout = (0, import_editor2.packAtlas)(
|
|
815
|
+
crops.map((c) => ({ id: c.id, width: c.width, height: c.height }))
|
|
816
|
+
);
|
|
817
|
+
if (layout.pageWidth * layout.pageHeight > MAX_ATLAS_AREA) {
|
|
818
|
+
throw new AutoRigInputError(
|
|
819
|
+
`atlas page ${layout.pageWidth}x${layout.pageHeight} exceeds max area ${MAX_ATLAS_AREA}`
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
const dataUri = await renderAtlasToDataUri(crops, layout, quantizeColors);
|
|
823
|
+
return { crops, layout, dataUri };
|
|
824
|
+
}
|
|
794
825
|
async function autoRigFromLayers(input) {
|
|
795
826
|
try {
|
|
796
827
|
const layers = input.layers;
|
|
@@ -902,10 +933,14 @@ async function autoRigFromLayers(input) {
|
|
|
902
933
|
);
|
|
903
934
|
}
|
|
904
935
|
layer.rowHalfWidths = rowHalfWidths;
|
|
936
|
+
} else if (role === "nose") {
|
|
937
|
+
const core = denseCoreOf(png.rgba, canvasW, canvasH);
|
|
938
|
+
if (core !== null) layer.denseCore = core;
|
|
905
939
|
}
|
|
906
940
|
layerInputs.push(layer);
|
|
907
941
|
crops.push({ id: role, buffer, width: bbox.w, height: bbox.h });
|
|
908
942
|
}
|
|
943
|
+
const noseCore = layerInputs.find((l) => l.role === "nose")?.denseCore;
|
|
909
944
|
const eyeRow = eyeRowOf(layerInputs);
|
|
910
945
|
const span = foregroundSpan(
|
|
911
946
|
opaque,
|
|
@@ -1015,46 +1050,58 @@ async function autoRigFromLayers(input) {
|
|
|
1015
1050
|
throw new AutoRigInputError(e.message);
|
|
1016
1051
|
}
|
|
1017
1052
|
const doc = new import_editor2.EditorDocument(model);
|
|
1018
|
-
const
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
)
|
|
1025
|
-
|
|
1026
|
-
const
|
|
1027
|
-
if (
|
|
1053
|
+
const losslessCrop = quantizeColors === void 0 ? void 0 : crops.find((c) => c.id === LOSSLESS_PAGE_ROLE);
|
|
1054
|
+
const pages = losslessCrop === void 0 ? [await renderAtlasPage(crops, quantizeColors)] : [
|
|
1055
|
+
await renderAtlasPage(
|
|
1056
|
+
crops.filter((c) => c !== losslessCrop),
|
|
1057
|
+
quantizeColors
|
|
1058
|
+
),
|
|
1059
|
+
await renderAtlasPage([losslessCrop], void 0)
|
|
1060
|
+
];
|
|
1061
|
+
const atlasBytes = pages.reduce((sum, p) => sum + p.dataUri.length, 0);
|
|
1062
|
+
if (atlasBytes > MAX_OUTPUT_BYTES) {
|
|
1028
1063
|
throw new AutoRigInputError(
|
|
1029
|
-
`atlas data URI ${
|
|
1064
|
+
`atlas data URI ${atlasBytes} bytes exceeds ${MAX_OUTPUT_BYTES}`
|
|
1030
1065
|
);
|
|
1031
1066
|
}
|
|
1032
|
-
const partTextureAssignments =
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1067
|
+
const partTextureAssignments = pages.flatMap(
|
|
1068
|
+
({ crops: pageCrops, layout }) => pageCrops.map((crop) => {
|
|
1069
|
+
const placement2 = layout.placements.find((p) => p.id === crop.id);
|
|
1070
|
+
if (placement2 === void 0) {
|
|
1071
|
+
throw new Error(`auto-rig: no atlas placement for "${crop.id}"`);
|
|
1072
|
+
}
|
|
1073
|
+
return {
|
|
1074
|
+
partId: crop.id,
|
|
1075
|
+
uv: (0, import_editor2.uvRectFor)(placement2, {
|
|
1076
|
+
width: layout.pageWidth,
|
|
1077
|
+
height: layout.pageHeight
|
|
1078
|
+
})
|
|
1079
|
+
};
|
|
1080
|
+
})
|
|
1081
|
+
);
|
|
1082
|
+
doc.applyAtlas({
|
|
1083
|
+
textures: [{ source: pages[0].dataUri }],
|
|
1084
|
+
partTextureAssignments
|
|
1044
1085
|
});
|
|
1045
|
-
doc.
|
|
1046
|
-
|
|
1086
|
+
let patched = doc.getModel();
|
|
1087
|
+
if (losslessCrop !== void 0) {
|
|
1088
|
+
patched = structuredClone(patched);
|
|
1089
|
+
patched.textures = pages.map((p) => ({ source: p.dataUri }));
|
|
1090
|
+
patched.parts.find((p) => p.id === losslessCrop.id).texture.index = 1;
|
|
1091
|
+
}
|
|
1092
|
+
const finalModel = (0, import_format.parseIkiModel)(patched);
|
|
1047
1093
|
writeFileAtomic(outPath, JSON.stringify(finalModel));
|
|
1048
1094
|
return {
|
|
1049
1095
|
ok: true,
|
|
1050
1096
|
path: outPath,
|
|
1051
1097
|
canvas: { width: canvasW, height: canvasH },
|
|
1052
1098
|
partCount: finalModel.parts.length,
|
|
1053
|
-
atlasBytes
|
|
1099
|
+
atlasBytes,
|
|
1054
1100
|
...headHalfWidth === void 0 ? {} : { headHalfWidth },
|
|
1055
1101
|
headHalfWidthApplied,
|
|
1056
1102
|
...headEdges === void 0 ? {} : { headEdges },
|
|
1057
1103
|
...strandEdges === void 0 ? {} : { strandEdges },
|
|
1104
|
+
...noseCore === void 0 ? {} : { noseCore },
|
|
1058
1105
|
...turn === void 0 ? {} : { turn }
|
|
1059
1106
|
};
|
|
1060
1107
|
} catch (err) {
|
|
@@ -1341,6 +1388,7 @@ var IRIS_W = Math.round(EYE_W * 0.5625);
|
|
|
1341
1388
|
var EYEWHITE_SRC = "eyewhite.png";
|
|
1342
1389
|
var EYE_LASH_LUMA = 120;
|
|
1343
1390
|
var LASH_KEEP_FRACTION = 0.5;
|
|
1391
|
+
var NOSE_TIP_AT = 0.86;
|
|
1344
1392
|
var DEFAULT_LAYOUT = {
|
|
1345
1393
|
// Back hair and body sit behind the face. Both are OPTIONAL: a parts dir
|
|
1346
1394
|
// without them still composes (head-only character).
|
|
@@ -1352,9 +1400,11 @@ var DEFAULT_LAYOUT = {
|
|
|
1352
1400
|
face: { src: "face.png", cx: 550, cy: 475, w: 400 },
|
|
1353
1401
|
// The nose, drawn on its own (the face is drawn without one): the auto-rig
|
|
1354
1402
|
// leads the head turn with it and keys the other features' slide on its
|
|
1355
|
-
// presence, so without it the features stay on the face plate.
|
|
1356
|
-
//
|
|
1357
|
-
|
|
1403
|
+
// presence, so without it the features stay on the face plate. `w` is the
|
|
1404
|
+
// width of its dense core, and it has no `cy`: its row comes from the tip
|
|
1405
|
+
// rule (NOSE_TIP_AT), between the eyes and the mouth, so it follows them
|
|
1406
|
+
// when they are retuned. OPTIONAL: a parts dir without it composes.
|
|
1407
|
+
nose: { src: "nose.png", cx: 550, w: 40, optional: true },
|
|
1358
1408
|
mouth: { src: "mouth.png", cx: 550, cy: 619, w: 68 },
|
|
1359
1409
|
// Cross-fades with `mouth` on ParamMouthOpenY (opacity, not scaleY) once the
|
|
1360
1410
|
// auto-rig sees both roles. Same cx/w as `mouth` so the lip width matches;
|
|
@@ -1425,7 +1475,7 @@ function resolveLayout(overrides) {
|
|
|
1425
1475
|
);
|
|
1426
1476
|
}
|
|
1427
1477
|
if (override === void 0) continue;
|
|
1428
|
-
const
|
|
1478
|
+
const set = {};
|
|
1429
1479
|
for (const field of ["cx", "cy"]) {
|
|
1430
1480
|
const value = override[field];
|
|
1431
1481
|
if (value === void 0) continue;
|
|
@@ -1434,7 +1484,7 @@ function resolveLayout(overrides) {
|
|
|
1434
1484
|
`layout.${role}.${field} must be a finite number, got ${String(value)}`
|
|
1435
1485
|
);
|
|
1436
1486
|
}
|
|
1437
|
-
|
|
1487
|
+
set[field] = value;
|
|
1438
1488
|
}
|
|
1439
1489
|
for (const field of ["w", "h"]) {
|
|
1440
1490
|
const value = override[field];
|
|
@@ -1444,9 +1494,11 @@ function resolveLayout(overrides) {
|
|
|
1444
1494
|
`layout.${role}.${field} must be an integer in 1..${CANVAS}, got ${String(value)}`
|
|
1445
1495
|
);
|
|
1446
1496
|
}
|
|
1447
|
-
|
|
1497
|
+
set[field] = value;
|
|
1448
1498
|
}
|
|
1449
|
-
|
|
1499
|
+
const key = role;
|
|
1500
|
+
if (key === "nose") resolved.nose = { ...resolved.nose, ...set };
|
|
1501
|
+
else resolved[key] = { ...resolved[key], ...set };
|
|
1450
1502
|
}
|
|
1451
1503
|
return resolved;
|
|
1452
1504
|
}
|
|
@@ -1471,6 +1523,15 @@ function keyWhiteToAlpha(rgba) {
|
|
|
1471
1523
|
}
|
|
1472
1524
|
return keyed;
|
|
1473
1525
|
}
|
|
1526
|
+
async function coreOf(png) {
|
|
1527
|
+
const { data, info } = await (0, import_sharp2.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
1528
|
+
return denseCoreOf(data, info.width, info.height) ?? {
|
|
1529
|
+
x: 0,
|
|
1530
|
+
y: 0,
|
|
1531
|
+
w: info.width,
|
|
1532
|
+
h: info.height
|
|
1533
|
+
};
|
|
1534
|
+
}
|
|
1474
1535
|
async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
|
|
1475
1536
|
let img;
|
|
1476
1537
|
if (inMemory !== void 0) {
|
|
@@ -1491,33 +1552,56 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
|
|
|
1491
1552
|
if (!cfg.noTrim) img = img.trim({ threshold: 12 });
|
|
1492
1553
|
if ((cfg.mirror ?? false) !== flipSource) img = img.flop();
|
|
1493
1554
|
const trimmed = await img.png().toBuffer({ resolveWithObject: true });
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1555
|
+
const { width: trimmedW, height: trimmedH } = trimmed.info;
|
|
1556
|
+
const sized = role === "nose" ? await coreOf(trimmed.data) : { x: 0, y: 0, w: trimmedW, h: trimmedH };
|
|
1557
|
+
const width = Math.round(trimmedW * cfg.w / sized.w);
|
|
1558
|
+
const height = cfg.h === void 0 ? Math.round(trimmedH * width / trimmedW) : Math.round(trimmedH * cfg.h / sized.h);
|
|
1559
|
+
if (width > CANVAS || height > CANVAS) {
|
|
1560
|
+
const field = width > CANVAS || cfg.h === void 0 ? "w" : "h";
|
|
1561
|
+
throw new AutoRigInputError(
|
|
1562
|
+
`layout.${role}.${field}: resized part ${width}x${height} exceeds the ${CANVAS} canvas`
|
|
1497
1563
|
);
|
|
1498
|
-
if (scaledH > CANVAS) {
|
|
1499
|
-
throw new AutoRigInputError(
|
|
1500
|
-
`layout.${role}.w: resized part ${cfg.w}x${scaledH} exceeds the ${CANVAS} canvas`
|
|
1501
|
-
);
|
|
1502
|
-
}
|
|
1503
1564
|
}
|
|
1504
|
-
const resized = await (0, import_sharp2.default)(trimmed.data).resize(
|
|
1505
|
-
cfg.h === void 0 ? { width: cfg.w } : { width: cfg.w, height: cfg.h, fit: "fill" }
|
|
1506
|
-
).png().toBuffer({ resolveWithObject: true });
|
|
1565
|
+
const resized = await (0, import_sharp2.default)(trimmed.data).resize(cfg.h === void 0 ? { width } : { width, height, fit: "fill" }).png().toBuffer({ resolveWithObject: true });
|
|
1507
1566
|
return {
|
|
1508
1567
|
buf: resized.data,
|
|
1509
1568
|
w: resized.info.width,
|
|
1510
1569
|
h: resized.info.height
|
|
1511
1570
|
};
|
|
1512
1571
|
}
|
|
1513
|
-
function
|
|
1514
|
-
const left = Math.round(cfg.cx - w / 2);
|
|
1515
|
-
const top = Math.round(cfg.cy - h / 2);
|
|
1572
|
+
function assertOnCanvas(source, w, h, left, top) {
|
|
1516
1573
|
if (left + w <= 0 || top + h <= 0 || left >= CANVAS || top >= CANVAS) {
|
|
1517
1574
|
throw new AutoRigInputError(
|
|
1518
|
-
|
|
1575
|
+
`${source}: the placed part (${w}x${h} at ${left},${top}) falls entirely outside the ${CANVAS} canvas`
|
|
1519
1576
|
);
|
|
1520
1577
|
}
|
|
1578
|
+
}
|
|
1579
|
+
function placement(role, cfg, w, h) {
|
|
1580
|
+
const left = Math.round(cfg.cx - w / 2);
|
|
1581
|
+
const top = Math.round(cfg.cy - h / 2);
|
|
1582
|
+
assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top);
|
|
1583
|
+
return { left, top };
|
|
1584
|
+
}
|
|
1585
|
+
function nosePlacement(layout, core, w, h) {
|
|
1586
|
+
const { cx, cy } = layout.nose;
|
|
1587
|
+
const left = Math.round(cx - (core.x + core.w / 2));
|
|
1588
|
+
let top;
|
|
1589
|
+
if (cy !== void 0) {
|
|
1590
|
+
top = Math.round(cy - (core.y + core.h / 2));
|
|
1591
|
+
} else {
|
|
1592
|
+
const eyeRow = (layout.eye_L.cy + layout.eye_R.cy) / 2;
|
|
1593
|
+
const tipRow = Math.round(
|
|
1594
|
+
eyeRow + NOSE_TIP_AT * (layout.mouth.cy - eyeRow)
|
|
1595
|
+
);
|
|
1596
|
+
top = tipRow - (core.y + core.h - 1);
|
|
1597
|
+
}
|
|
1598
|
+
assertOnCanvas(
|
|
1599
|
+
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)",
|
|
1600
|
+
w,
|
|
1601
|
+
h,
|
|
1602
|
+
left,
|
|
1603
|
+
top
|
|
1604
|
+
);
|
|
1521
1605
|
return { left, top };
|
|
1522
1606
|
}
|
|
1523
1607
|
function blankCanvas() {
|
|
@@ -1609,7 +1693,7 @@ async function composeLayersFromParts(input) {
|
|
|
1609
1693
|
skipped.push(role);
|
|
1610
1694
|
continue;
|
|
1611
1695
|
}
|
|
1612
|
-
const { left, top } = placement(role,
|
|
1696
|
+
const { left, top } = role === "nose" ? nosePlacement(layout, await coreOf(part.buf), part.w, part.h) : placement(role, layout[role], part.w, part.h);
|
|
1613
1697
|
if (role === "lash_L" || role === "lash_R") {
|
|
1614
1698
|
const eyeRole = role === "lash_L" ? "eye_L" : "eye_R";
|
|
1615
1699
|
const eye = placed.find((p) => p.role === eyeRole);
|
|
@@ -1669,7 +1753,7 @@ async function composeLayersFromParts(input) {
|
|
|
1669
1753
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
1670
1754
|
var import_zod = require("zod");
|
|
1671
1755
|
function createIkiMcpServer() {
|
|
1672
|
-
const server = new import_mcp.McpServer({ name: "iki", version: "0.
|
|
1756
|
+
const server = new import_mcp.McpServer({ name: "iki", version: "0.11.0" });
|
|
1673
1757
|
server.registerTool(
|
|
1674
1758
|
"validate_iki",
|
|
1675
1759
|
{
|
|
@@ -1748,7 +1832,7 @@ function createIkiMcpServer() {
|
|
|
1748
1832
|
"Output .iki path (resolved against cwd; parent dir must exist)."
|
|
1749
1833
|
),
|
|
1750
1834
|
quantizeColors: import_zod.z.number().int().min(2).max(256).optional().describe(
|
|
1751
|
-
"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."
|
|
1835
|
+
"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."
|
|
1752
1836
|
),
|
|
1753
1837
|
turnTargets: import_zod.z.object({
|
|
1754
1838
|
eyeShift: import_zod.z.number().optional(),
|
|
@@ -1796,7 +1880,7 @@ function createIkiMcpServer() {
|
|
|
1796
1880
|
h: import_zod.z.number()
|
|
1797
1881
|
}).partial()
|
|
1798
1882
|
).optional().describe(
|
|
1799
|
-
"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. 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."
|
|
1883
|
+
"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."
|
|
1800
1884
|
),
|
|
1801
1885
|
mirrorParts: import_zod.z.array(import_zod.z.string()).optional().describe(
|
|
1802
1886
|
"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."
|