@ikijs/mcp 0.11.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/{chunk-LOOIWB2J.mjs → chunk-4AE4D6SE.mjs} +72 -22
- package/dist/chunk-4AE4D6SE.mjs.map +1 -0
- package/dist/cli.js +71 -21
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +71 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-LOOIWB2J.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -22,8 +22,8 @@ Turns a set of role-named, full-canvas transparent PNG layers into a renderable,
|
|
|
22
22
|
|
|
23
23
|
- **`layers`** — array of `{ path, fileName? }`. `path` is a PNG file path (resolved against the server's working directory); the role is derived from `fileName ?? basename(path)`. Required roles: `face`, `eye_L`, `eye_R`, `mouth`. Optional roles include `iris_L`/`iris_R`, `brow_L`/`brow_R`, `hair_front`/`hair_back`, `lash_L`/`lash_R`, etc. All layers must share the same canvas size (taken from the first layer).
|
|
24
24
|
- **`outputPath`** — optional `.iki` output path (resolved against the working directory; the parent directory must already exist, and the path must end in `.iki`). Defaults to `auto-rigged-model.iki`.
|
|
25
|
-
- **`turnTargets`** — optional head-turn cues to fit the rig to, in the units `measure_turn_reference` reports off a front/turned reference pair: `eyeShift` (plus `noseShift` and `mouthShift`, derived from it when absent) is how far that feature slides across the head at full turn, as a fraction of the head's half-width — a **magnitude**, since the rig turns both ways and the sign is the turn's own business; `farEyeRatio` is the far/near eye width at full turn over that same ratio at rest; `silhouetteRatio` the head's half-width turned over at rest. An omitted field falls back to a built-in default, which is _clamped_ to what the layer set can do, and so is an `eyeShift` you pass that runs past the room the art leaves the far eye — the face plate's edge, or the bangs' side strand over the far iris — since that room is a fact about these layers, not about the reference. Any other target you **do** pass that it cannot reach is refused, including an `eyeShift` smaller than the slide the face's own turn already gives the eyes, because that number is a measurement rather than a preference. Only a layer set carrying a `nose` solves a turn at all.
|
|
26
|
-
- **Result** — on success the result text is the written file path and `structuredContent` carries `{ ok: true, path, canvas, partCount, atlasBytes, headHalfWidth?, headHalfWidthApplied, headEdges?, strandEdges?, noseCore?, turn? }`. `atlasBytes` is the embedded atlas's data-URI length, summed over both pages when the nose has one of its own. `headHalfWidth` is the head measured here rather than asked for: the layers' own opaque union at the eye row, under the same `alpha >= 128` rule and ±10-row band `measure_turn_reference` spans a render with, so the rig's own rest render measures that span back; it is **absent** when that union has no span there at all (translucent art painted below alpha 128 — still a valid layer set, just with nothing to measure). `headHalfWidthApplied` is `false` when the measured value is absent, or no wider than the face plate (a hairless set, or one widest at the plate itself) — the generator will not take such a head, so the plate stands in for it and the rig is still produced either way. `headEdges` is a companion to a measured, applied `headHalfWidth` (absent otherwise): every role with an opaque pixel in that same eye-row band, per side, each with its own rest x there — passed straight to the generator's own `options.headEdges` so it can tell which part's own deformation actually carries the union's outermost pixel through the turn. `strandEdges` is each side's iris and the `hair_front` run it would slide under on the turn, measured whenever the layers include `hair_front`, `iris_L` and `iris_R`: the iris's opaque span and the run's outer and face-side ends as pixel edges on the row holding the iris's centre (a run that reaches the other iris's centre, a fringe spanning the face, has `runFace: null`; a run narrower than half the iris's painted width on that row is hair detail the iris may cross, and is skipped as if clear) — passed straight to the generator's own `options.strandEdges`, which keeps the far iris from sliding under the bangs any further than it is painted. `turn` is what the solve settled on — `{ radius, holdBase, depths, achieved: { eyeShift, farEyeRatio, silhouetteRatio }, clamped, strandOverlap? }`, where `achieved` is what the rig does reach and `clamped` names every target the rig cut down: each _defaulted_ target this layer set could not reach, plus a passed `eyeShift` that the face plate's edge or the strand cut short. `strandOverlap` gives, per side whose far iris the bangs still cover at some far stop, the covered width — how much of the iris's painted row the run covers where that is largest (`deg`, `px`, and `hh` in head half-widths), how much it covers at rest (`restPx`), and whether the bound held (`held`: `true` means the iris is kept no deeper under the run than it is painted; `false` means the fitted radius could not do that — always so for a fringe spanning the face — so the eyes' turn depth is 0 and `px` is what stays covered); it is absent when nothing is covered. `noseCore` is the nose's dense core in canvas px — its pixels at alpha >= 128, not grown, the box handed to the generator as the nose layer's `denseCore` and its turn landmark — absent without a `nose` layer
|
|
25
|
+
- **`turnTargets`** — optional head-turn cues to fit the rig to, in the units `measure_turn_reference` reports off a front/turned reference pair: `eyeShift` (plus `noseShift` and `mouthShift`, derived from it when absent) is how far that feature slides across the head at full turn, as a fraction of the head's half-width — a **magnitude**, since the rig turns both ways and the sign is the turn's own business; `farEyeRatio` is the far/near eye width at full turn over that same ratio at rest; `silhouetteRatio` the head's half-width turned over at rest. An omitted field falls back to a built-in default, which is _clamped_ to what the layer set can do, and so is an `eyeShift` you pass that runs past the room the art leaves the far eye — the face plate's edge, or the bangs' side strand over the far iris — since that room is a fact about these layers, not about the reference. Any other target you **do** pass that it cannot reach is refused, including an `eyeShift` smaller than the slide the face's own turn already gives the eyes, because that number is a measurement rather than a preference — except a `silhouetteRatio` when no ratio in its whole accepted range renders on this layer set: that refusal reads `… is unreachable for this layer set, and so is every silhouetteRatio in [0.5, 1.5]` and offers no range, so leave the field out, since a defaulted one clamps. Only a layer set carrying a `nose` solves a turn at all.
|
|
26
|
+
- **Result** — on success the result text is the written file path and `structuredContent` carries `{ ok: true, path, canvas, partCount, atlasBytes, headHalfWidth?, headHalfWidthApplied, headEdges?, strandEdges?, noseCore?, turn? }`. `atlasBytes` is the embedded atlas's data-URI length, summed over both pages when the nose has one of its own. `headHalfWidth` is the head measured here rather than asked for: the layers' own opaque union at the eye row, under the same `alpha >= 128` rule and ±10-row band `measure_turn_reference` spans a render with, so the rig's own rest render measures that span back; it is **absent** when that union has no span there at all (translucent art painted below alpha 128 — still a valid layer set, just with nothing to measure). `headHalfWidthApplied` is `false` when the measured value is absent, or no wider than the face plate (a hairless set, or one widest at the plate itself) — the generator will not take such a head, so the plate stands in for it and the rig is still produced either way. `headEdges` is a companion to a measured, applied `headHalfWidth` (absent otherwise): every role with an opaque pixel in that same eye-row band, per side, each with its own rest x there — passed straight to the generator's own `options.headEdges` so it can tell which part's own deformation actually carries the union's outermost pixel through the turn. `strandEdges` is each side's iris and the `hair_front` run it would slide under on the turn, measured whenever the layers include `hair_front`, `iris_L` and `iris_R`: the iris's opaque span and the run's outer and face-side ends as pixel edges on the row holding the iris's centre (a run that reaches the other iris's centre, a fringe spanning the face, has `runFace: null`; a run narrower than half the iris's painted width on that row is hair detail the iris may cross, and is skipped as if clear) — passed straight to the generator's own `options.strandEdges`, which keeps the far iris from sliding under the bangs any further than it is painted. `turn` is what the solve settled on — `{ radius, holdBase, depths, achieved: { eyeShift, farEyeRatio, silhouetteRatio }, clamped, strandOverlap? }`, where `achieved` is what the rig does reach and `clamped` names every target the rig cut down: each _defaulted_ target this layer set could not reach, plus a passed `eyeShift` that the face plate's edge or the strand cut short. `strandOverlap` gives, per side whose far iris the bangs still cover at some far stop, the covered width — how much of the iris's painted row the run covers where that is largest (`deg`, `px`, and `hh` in head half-widths), how much it covers at rest (`restPx`), and whether the bound held (`held`: `true` means the iris is kept no deeper under the run than it is painted; `false` means the fitted radius could not do that — always so for a fringe spanning the face — so the eyes' turn depth is 0 and `px` is what stays covered); it is absent when nothing is covered. `noseCore` is the nose's dense core in canvas px — its pixels at alpha >= 128, not grown, the box handed to the generator as the nose layer's `denseCore` and its turn landmark — absent without a `nose` layer, when it has no pixel at that threshold (painted wholly translucent), or when that core is a speck of the nose's crop (under a quarter of its width or height, such as a lone nostril mark), and in both of the last two cases the crop stands in for it. `turn` is absent without a `nose` layer. The (potentially multi-MB) model is written to disk, not inlined. Invalid input (unknown/missing role, empty layer, mismatched sizes, bad path, oversized atlas, a `turnTargets` field that is not a number or that this layer set cannot reach — any passed field other than an `eyeShift` past the art's room, and a passed `eyeShift` below the face's own slide; the message names the field and the attainable range, except a `silhouetteRatio` when no ratio in [0.5, 1.5] renders on this layer set, whose message names no range) returns `{ ok: false, error }` with a `INVALID: …` text — not a protocol error.
|
|
27
27
|
|
|
28
28
|
The decode/atlas pipeline runs in Node via `sharp` (a native dependency confined to this package); it mirrors the browser editor app's import flow and reuses the pure `@ikijs/editor` model + atlas math, so both paths produce the same rig.
|
|
29
29
|
|
|
@@ -33,13 +33,13 @@ Composes a directory of AI-generated part PNGs into canvas-aligned, role-named l
|
|
|
33
33
|
|
|
34
34
|
- **`partsDir`** — directory of the source part PNGs (resolved against the server's working directory). Required sources: `face.png`, `eyewhite.png` (split into the sclera + lash layers), `iris.png`, `mouth.png`, `brow.png`, `hair_front.png`. Optional: `hair_back.png`, `body.png`, `mouth_open.png`, `nose.png` — a parts dir without them still composes, minus those roles. The nose is what the auto-rig leads the head turn with (without a `nose` layer nothing on the face slides), and a face supplied alongside it must be drawn without one, or the painted nose stays on the face plate while the real one moves.
|
|
35
35
|
- **`outDir`** — an existing directory (resolved against the working directory, confined to it exactly like `auto_rig_from_layers`'s `outputPath`; the tool never creates directories) to write the role layer PNGs and a flattened `preview.png` into. Reusing a directory across runs is intentional — a role this run skips (e.g. composing a head-only set that omits `body`) has its stale `<role>.png` from an earlier run deleted, so the directory always holds exactly this run's roles.
|
|
36
|
-
- **`layout`** — optional per-role override merged over the built-in defaults, e.g. `{ "eye_L": { "cx": 660 } }`, so a character can be retuned by re-running compose rather than editing a script. Each of `cx`, `cy`, `w`, `h` is optional; `w` and `h` must be integers in 1..1100 (the canvas size). Omitting `h` keeps the part's own aspect ratio, which is what every role wants until one does not: a generated eyewhite often comes back flatter than its reference, and stretching a flat white lens costs nothing where regenerating it is billed and unreliable. The nose is sized and placed by its dense core — its pixels at alpha ≥ 128, the drawing a viewer reads inside a soft nose's feather — rather than its whole part, which for a shaded-bump nose is mostly feather: `w` (default 40) and `h` size the core, `cx` (default 550) centres it, and a set `cy` centres its rows. By default its `cy` is unset, and the core's bottom row (the tip) lands 0.86 of the way from the eye row down to the mouth's, so the nose follows a retuned eye or mouth row. A nose with no pixel at alpha ≥ 128 is sized and placed whole. Set `h` on a sclera and its lash together — they share one frame, and the blink fold tears if they diverge, so a pair set to land on different frames is rejected.
|
|
36
|
+
- **`layout`** — optional per-role override merged over the built-in defaults, e.g. `{ "eye_L": { "cx": 660 } }`, so a character can be retuned by re-running compose rather than editing a script. Each of `cx`, `cy`, `w`, `h` is optional; `w` and `h` must be integers in 1..1100 (the canvas size). Omitting `h` keeps the part's own aspect ratio, which is what every role wants until one does not: a generated eyewhite often comes back flatter than its reference, and stretching a flat white lens costs nothing where regenerating it is billed and unreliable. The nose is sized and placed by its dense core — its pixels at alpha ≥ 128, the drawing a viewer reads inside a soft nose's feather — rather than its whole part, which for a shaded-bump nose is mostly feather: `w` (default 40) and `h` size the core, `cx` (default 550) centres it, and a set `cy` centres its rows. By default its `cy` is unset, and the core's bottom row (the tip) lands 0.86 of the way from the eye row down to the mouth's, so the nose follows a retuned eye or mouth row. A nose with no pixel at alpha ≥ 128 is sized and placed whole, and so is one whose core is a speck of its trimmed part — under a quarter of its width or height, such as a lone nostril mark or highlight, which sized to `w` would blow the whole nose up — and the report warns of the speck. Set `h` on a sclera and its lash together — they share one frame, and the blink fold tears if they diverge, so a pair set to land on different frames is rejected.
|
|
37
37
|
- **`mirrorParts`** — optional list of part files to flip left-right as they are read, e.g. `["eyewhite.png"]`. Which way a part faces is fixed by the layout, and "left eye" cannot pin it down — it reads as the viewer's left or the character's — so in image terms: `eyewhite.png` is read as the eye on the screen left, lash wing (outer corner) at the image's left end and lash-free tear duct at its right; `brow.png` as the brow on the screen right, thick head at the image's left end and tail at its right. A part drawn the other way round is fixed here for free instead of regenerated. It flips the source, so every role cut from it flips together and an eye's sclera and lash stay in one frame.
|
|
38
|
-
- **Result** — on success the text is the written layer paths (one per line) followed by the same geometry report `measure_layers` returns
|
|
38
|
+
- **Result** — on success the text is the written layer paths (one per line) followed by the same geometry report `measure_layers` returns — except that when the composer found the core of the nose's source part a speck, its nose check reports that verdict instead of what the composed file shows, so a speck that resampling erased from the layer is warned about here and not by `measure_layers`. `structuredContent` is `{ ok: true, outDir, layers, skipped, preview, measure }`. Invalid input (a missing required part, an unknown `layout` role, an out-of-range `w` or `h`, a lash placed on a different frame from its sclera's, a `mirrorParts` entry that is not a part file, a part that lands entirely off-canvas, a non-existent `outDir`) returns `{ ok: false, error }` with `INVALID: …` text.
|
|
39
39
|
|
|
40
40
|
### `measure_layers`
|
|
41
41
|
|
|
42
|
-
Reports the same read-only geometry checks `compose_layers_from_parts` returns inline (iris size/offset relative to the sclera, eye aspect, an eye drawn facing the other way, cropped or flat-cut edges, missing optional roles), over an already-composed layers directory — for re-checking a layers dir without recomposing it.
|
|
42
|
+
Reports the same read-only geometry checks `compose_layers_from_parts` returns inline (iris size/offset relative to the sclera, eye aspect, an eye drawn facing the other way, cropped or flat-cut edges, a nose whose dense core is a speck of its crop, missing optional roles), over an already-composed layers directory — for re-checking a layers dir without recomposing it. Its nose check reads the composed file against its crop, which is what `auto_rig_from_layers` acts on: a speck core there is one the rig does not turn or tilt the nose about. The composer's inline report does the same unless it found the source part's core a speck, which it reports instead, so a speck that resampling erased from the layer shows there and not here.
|
|
43
43
|
|
|
44
44
|
- **`layersDir`** — directory of role-named layer PNGs (resolved against the working directory).
|
|
45
45
|
- **Result** — the text is the report: a per-layer size/bbox-centre/mass-centre/margins table, then the checks that fired. `structuredContent` is `{ ok: true, layersDir, layers, empty, warnings, passed }`. A missing or non-directory `layersDir` returns `{ ok: false, error }` with `INVALID: …` text.
|
|
@@ -240,6 +240,10 @@ function denseCoreOf(rgba, width, height) {
|
|
|
240
240
|
if (maxX < 0) return null;
|
|
241
241
|
return { x: minX, y: minY, w: maxX - minX + 1, h: maxY - minY + 1 };
|
|
242
242
|
}
|
|
243
|
+
var SPECK_CORE_FRACTION = 0.25;
|
|
244
|
+
function isSpeckCore(core, part) {
|
|
245
|
+
return core.w < SPECK_CORE_FRACTION * part.w || core.h < SPECK_CORE_FRACTION * part.h;
|
|
246
|
+
}
|
|
243
247
|
function rgbToHsv(r, g, b) {
|
|
244
248
|
r /= 255;
|
|
245
249
|
g /= 255;
|
|
@@ -902,7 +906,7 @@ async function autoRigFromLayers(input) {
|
|
|
902
906
|
layer.rowHalfWidths = rowHalfWidths;
|
|
903
907
|
} else if (role === "nose") {
|
|
904
908
|
const core = denseCoreOf(png.rgba, canvasW, canvasH);
|
|
905
|
-
if (core !== null) layer.denseCore = core;
|
|
909
|
+
if (core !== null && !isSpeckCore(core, bbox)) layer.denseCore = core;
|
|
906
910
|
}
|
|
907
911
|
layerInputs.push(layer);
|
|
908
912
|
crops.push({ id: role, buffer, width: bbox.w, height: bbox.h });
|
|
@@ -1169,6 +1173,16 @@ async function layerStats(filePath) {
|
|
|
1169
1173
|
};
|
|
1170
1174
|
}
|
|
1171
1175
|
var pct = (v) => `${(v * 100).toFixed(0)}%`;
|
|
1176
|
+
function noseSpeckWarning({ core, part }, source) {
|
|
1177
|
+
const [found, consequence] = source === "compose" ? [
|
|
1178
|
+
`the source part's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} trimmed part`,
|
|
1179
|
+
`compose_layers_from_parts sized and placed the whole part instead \u2014 layout.nose's w and h now size it, feather included`
|
|
1180
|
+
] : [
|
|
1181
|
+
`the layer's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} crop`,
|
|
1182
|
+
`auto_rig_from_layers turns and tilts the nose about its whole crop instead`
|
|
1183
|
+
];
|
|
1184
|
+
return `nose: ${found} \u2014 under ${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.`;
|
|
1185
|
+
}
|
|
1172
1186
|
async function lashOffSclera(eyePath, lashPath) {
|
|
1173
1187
|
const eye = await decodePng(eyePath);
|
|
1174
1188
|
const lash = await decodePng(lashPath);
|
|
@@ -1184,7 +1198,7 @@ async function lashOffSclera(eyePath, lashPath) {
|
|
|
1184
1198
|
}
|
|
1185
1199
|
return { opaque, off };
|
|
1186
1200
|
}
|
|
1187
|
-
async function measureDir(absDir) {
|
|
1201
|
+
async function measureDir(absDir, noseSpeck) {
|
|
1188
1202
|
const files = fs2.readdirSync(absDir).filter((f) => f.endsWith(".png") && f !== "preview.png").sort();
|
|
1189
1203
|
if (files.length === 0) {
|
|
1190
1204
|
throw new AutoRigInputError(`no role layers in ${absDir}`);
|
|
@@ -1290,6 +1304,17 @@ async function measureDir(absDir) {
|
|
|
1290
1304
|
}
|
|
1291
1305
|
}
|
|
1292
1306
|
}
|
|
1307
|
+
if (noseSpeck !== void 0) {
|
|
1308
|
+
warnings.push(noseSpeckWarning(noseSpeck, "compose"));
|
|
1309
|
+
} else if (layers.nose !== void 0) {
|
|
1310
|
+
const nose = await decodePng(path4.join(absDir, "nose.png"));
|
|
1311
|
+
const core = denseCoreOf(nose.rgba, nose.width, nose.height);
|
|
1312
|
+
if (core !== null) {
|
|
1313
|
+
const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
|
|
1314
|
+
if (isSpeckCore(core, crop))
|
|
1315
|
+
warnings.push(noseSpeckWarning({ core, part: crop }, "layer"));
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1293
1318
|
for (const [role, why] of [
|
|
1294
1319
|
["body", "without it the character reads as a floating head on head-turn"],
|
|
1295
1320
|
["hair_back", "without it the silhouette is flat behind the face"],
|
|
@@ -1488,15 +1513,28 @@ function keyWhiteToAlpha(rgba) {
|
|
|
1488
1513
|
}
|
|
1489
1514
|
return keyed;
|
|
1490
1515
|
}
|
|
1491
|
-
async function
|
|
1516
|
+
async function coreAndBoundsOf(png) {
|
|
1492
1517
|
const { data, info } = await sharp2(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
1493
|
-
return
|
|
1494
|
-
|
|
1495
|
-
y: 0,
|
|
1496
|
-
w: info.width,
|
|
1497
|
-
h: info.height
|
|
1518
|
+
return {
|
|
1519
|
+
core: denseCoreOf(data, info.width, info.height),
|
|
1520
|
+
bounds: { x: 0, y: 0, w: info.width, h: info.height }
|
|
1498
1521
|
};
|
|
1499
1522
|
}
|
|
1523
|
+
async function noseSizingOf(png) {
|
|
1524
|
+
const { core, bounds } = await coreAndBoundsOf(png);
|
|
1525
|
+
if (core === null) return { box: bounds, whole: true };
|
|
1526
|
+
if (isSpeckCore(core, bounds)) {
|
|
1527
|
+
return {
|
|
1528
|
+
box: bounds,
|
|
1529
|
+
whole: true,
|
|
1530
|
+
speck: {
|
|
1531
|
+
core: { w: core.w, h: core.h },
|
|
1532
|
+
part: { w: bounds.w, h: bounds.h }
|
|
1533
|
+
}
|
|
1534
|
+
};
|
|
1535
|
+
}
|
|
1536
|
+
return { box: core, whole: false };
|
|
1537
|
+
}
|
|
1500
1538
|
async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
|
|
1501
1539
|
let img;
|
|
1502
1540
|
if (inMemory !== void 0) {
|
|
@@ -1518,7 +1556,8 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
|
|
|
1518
1556
|
if ((cfg.mirror ?? false) !== flipSource) img = img.flop();
|
|
1519
1557
|
const trimmed = await img.png().toBuffer({ resolveWithObject: true });
|
|
1520
1558
|
const { width: trimmedW, height: trimmedH } = trimmed.info;
|
|
1521
|
-
const
|
|
1559
|
+
const nose = role === "nose" ? await noseSizingOf(trimmed.data) : void 0;
|
|
1560
|
+
const sized = nose?.box ?? { x: 0, y: 0, w: trimmedW, h: trimmedH };
|
|
1522
1561
|
const width = Math.round(trimmedW * cfg.w / sized.w);
|
|
1523
1562
|
const height = cfg.h === void 0 ? Math.round(trimmedH * width / trimmedW) : Math.round(trimmedH * cfg.h / sized.h);
|
|
1524
1563
|
if (width > CANVAS || height > CANVAS) {
|
|
@@ -1531,7 +1570,8 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
|
|
|
1531
1570
|
return {
|
|
1532
1571
|
buf: resized.data,
|
|
1533
1572
|
w: resized.info.width,
|
|
1534
|
-
h: resized.info.height
|
|
1573
|
+
h: resized.info.height,
|
|
1574
|
+
nose
|
|
1535
1575
|
};
|
|
1536
1576
|
}
|
|
1537
1577
|
function assertOnCanvas(source, w, h, left, top) {
|
|
@@ -1547,18 +1587,18 @@ function placement(role, cfg, w, h) {
|
|
|
1547
1587
|
assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top);
|
|
1548
1588
|
return { left, top };
|
|
1549
1589
|
}
|
|
1550
|
-
function nosePlacement(layout,
|
|
1590
|
+
function nosePlacement(layout, box, w, h) {
|
|
1551
1591
|
const { cx, cy } = layout.nose;
|
|
1552
|
-
const left = Math.round(cx - (
|
|
1592
|
+
const left = Math.round(cx - (box.x + box.w / 2));
|
|
1553
1593
|
let top;
|
|
1554
1594
|
if (cy !== void 0) {
|
|
1555
|
-
top = Math.round(cy - (
|
|
1595
|
+
top = Math.round(cy - (box.y + box.h / 2));
|
|
1556
1596
|
} else {
|
|
1557
1597
|
const eyeRow = (layout.eye_L.cy + layout.eye_R.cy) / 2;
|
|
1558
1598
|
const tipRow = Math.round(
|
|
1559
1599
|
eyeRow + NOSE_TIP_AT * (layout.mouth.cy - eyeRow)
|
|
1560
1600
|
);
|
|
1561
|
-
top = tipRow - (
|
|
1601
|
+
top = tipRow - (box.y + box.h - 1);
|
|
1562
1602
|
}
|
|
1563
1603
|
assertOnCanvas(
|
|
1564
1604
|
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)",
|
|
@@ -1643,6 +1683,7 @@ async function composeLayersFromParts(input) {
|
|
|
1643
1683
|
]);
|
|
1644
1684
|
const placed = [];
|
|
1645
1685
|
const skipped = [];
|
|
1686
|
+
let noseSpeck;
|
|
1646
1687
|
for (const role of ORDER) {
|
|
1647
1688
|
const cfg = layout[role];
|
|
1648
1689
|
const inMemory = splitSources.get(cfg.src);
|
|
@@ -1658,7 +1699,16 @@ async function composeLayersFromParts(input) {
|
|
|
1658
1699
|
skipped.push(role);
|
|
1659
1700
|
continue;
|
|
1660
1701
|
}
|
|
1661
|
-
|
|
1702
|
+
let left;
|
|
1703
|
+
let top;
|
|
1704
|
+
if (role === "nose") {
|
|
1705
|
+
noseSpeck = part.nose?.speck;
|
|
1706
|
+
const { core, bounds } = await coreAndBoundsOf(part.buf);
|
|
1707
|
+
const box = part.nose?.whole ? bounds : core ?? bounds;
|
|
1708
|
+
({ left, top } = nosePlacement(layout, box, part.w, part.h));
|
|
1709
|
+
} else {
|
|
1710
|
+
({ left, top } = placement(role, layout[role], part.w, part.h));
|
|
1711
|
+
}
|
|
1662
1712
|
if (role === "lash_L" || role === "lash_R") {
|
|
1663
1713
|
const eyeRole = role === "lash_L" ? "eye_L" : "eye_R";
|
|
1664
1714
|
const eye = placed.find((p) => p.role === eyeRole);
|
|
@@ -1705,7 +1755,7 @@ async function composeLayersFromParts(input) {
|
|
|
1705
1755
|
layers,
|
|
1706
1756
|
skipped,
|
|
1707
1757
|
preview: previewPath,
|
|
1708
|
-
measure: await measureDir(outDir)
|
|
1758
|
+
measure: await measureDir(outDir, noseSpeck)
|
|
1709
1759
|
};
|
|
1710
1760
|
} catch (err) {
|
|
1711
1761
|
if (err instanceof AutoRigInputError)
|
|
@@ -1718,7 +1768,7 @@ async function composeLayersFromParts(input) {
|
|
|
1718
1768
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
1719
1769
|
import { z } from "zod";
|
|
1720
1770
|
function createIkiMcpServer() {
|
|
1721
|
-
const server = new McpServer({ name: "iki", version: "0.11.
|
|
1771
|
+
const server = new McpServer({ name: "iki", version: "0.11.1" });
|
|
1722
1772
|
server.registerTool(
|
|
1723
1773
|
"validate_iki",
|
|
1724
1774
|
{
|
|
@@ -1806,7 +1856,7 @@ function createIkiMcpServer() {
|
|
|
1806
1856
|
noseShift: z.number().optional(),
|
|
1807
1857
|
mouthShift: z.number().optional()
|
|
1808
1858
|
}).optional().describe(
|
|
1809
|
-
"What the head turn is fitted to, as `measure_turn_reference` reports it off a front/turned reference pair. `eyeShift` (and the optional `noseShift`/`mouthShift`, derived from it when absent) is how far that feature slides across the head at full turn, as a fraction of the head's half-width \u2014 a MAGNITUDE: the rig turns both ways, so the sign is ignored. `farEyeRatio` is the far/near eye width at full turn over that same ratio at rest, `silhouetteRatio` the head's half-width turned over at rest. The half-width the shifts are fractions of is measured off the layers themselves, so it is not an input. An omitted field falls back to a default, which is clamped to what this layer set can do, and so is a passed `eyeShift` past the room the art leaves the far eye \u2014 the face plate's edge, or the bangs' side strand over the far iris (the result's `turn.clamped` lists every clamped field, `turn.achieved` what the rig reaches, and `turn.strandOverlap` how much of a far iris the bangs still cover). Any other passed target this layer set cannot reach, including an `eyeShift` smaller than the slide the face's own turn already gives the eyes, comes back as `INVALID: \u2026` naming the field and the attainable range, since it is a measurement rather than a preference."
|
|
1859
|
+
"What the head turn is fitted to, as `measure_turn_reference` reports it off a front/turned reference pair. `eyeShift` (and the optional `noseShift`/`mouthShift`, derived from it when absent) is how far that feature slides across the head at full turn, as a fraction of the head's half-width \u2014 a MAGNITUDE: the rig turns both ways, so the sign is ignored. `farEyeRatio` is the far/near eye width at full turn over that same ratio at rest, `silhouetteRatio` the head's half-width turned over at rest. The half-width the shifts are fractions of is measured off the layers themselves, so it is not an input. An omitted field falls back to a default, which is clamped to what this layer set can do, and so is a passed `eyeShift` past the room the art leaves the far eye \u2014 the face plate's edge, or the bangs' side strand over the far iris (the result's `turn.clamped` lists every clamped field, `turn.achieved` what the rig reaches, and `turn.strandOverlap` how much of a far iris the bangs still cover). Any other passed target this layer set cannot reach, including an `eyeShift` smaller than the slide the face's own turn already gives the eyes, comes back as `INVALID: \u2026` naming the field and the attainable range, since it is a measurement rather than a preference \u2014 except a passed `silhouetteRatio` when no ratio in its whole accepted range renders on this layer set: that refusal reads `\u2026 is unreachable for this layer set, and so is every silhouetteRatio in [0.5, 1.5]` and names no range, so leave the field out, since a defaulted one clamps."
|
|
1810
1860
|
)
|
|
1811
1861
|
}
|
|
1812
1862
|
},
|
|
@@ -1828,7 +1878,7 @@ function createIkiMcpServer() {
|
|
|
1828
1878
|
server.registerTool(
|
|
1829
1879
|
"compose_layers_from_parts",
|
|
1830
1880
|
{
|
|
1831
|
-
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, nose are optional \u2014 without a nose layer the rig does not slide the features on the head turn.",
|
|
1881
|
+
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, nose are optional \u2014 without a nose layer the rig does not slide the features on the head turn. 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.",
|
|
1832
1882
|
inputSchema: {
|
|
1833
1883
|
partsDir: z.string().describe(
|
|
1834
1884
|
"Directory of the source part PNGs (resolved against cwd)."
|
|
@@ -1845,7 +1895,7 @@ function createIkiMcpServer() {
|
|
|
1845
1895
|
h: z.number()
|
|
1846
1896
|
}).partial()
|
|
1847
1897
|
).optional().describe(
|
|
1848
|
-
"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."
|
|
1898
|
+
"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. 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.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."
|
|
1849
1899
|
),
|
|
1850
1900
|
mirrorParts: z.array(z.string()).optional().describe(
|
|
1851
1901
|
"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."
|
|
@@ -1873,7 +1923,7 @@ function createIkiMcpServer() {
|
|
|
1873
1923
|
server.registerTool(
|
|
1874
1924
|
"measure_layers",
|
|
1875
1925
|
{
|
|
1876
|
-
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, missing optional roles). Use to re-check a layers dir without recomposing.",
|
|
1926
|
+
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.",
|
|
1877
1927
|
inputSchema: {
|
|
1878
1928
|
layersDir: z.string().describe(
|
|
1879
1929
|
"Directory of role-named layer PNGs (resolved against cwd)."
|
|
@@ -1950,4 +2000,4 @@ export {
|
|
|
1950
2000
|
composeLayersFromParts,
|
|
1951
2001
|
createIkiMcpServer
|
|
1952
2002
|
};
|
|
1953
|
-
//# sourceMappingURL=chunk-
|
|
2003
|
+
//# sourceMappingURL=chunk-4AE4D6SE.mjs.map
|