@ikijs/mcp 0.8.1 → 0.10.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-LIWK4PQV.mjs → chunk-OCIICRUA.mjs} +151 -15
- package/dist/chunk-OCIICRUA.mjs.map +1 -0
- package/dist/cli.js +150 -14
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +32 -5
- package/dist/index.d.ts +32 -5
- package/dist/index.js +150 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-LIWK4PQV.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
|
|
26
|
-
- **Result** — on success the result text is the written file path and `structuredContent` carries `{ ok: true, path, canvas, partCount, atlasBytes, headHalfWidth?, headHalfWidthApplied, headEdges?, turn? }`. `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. `turn` is what the solve settled on — `{ radius, holdBase, depths, achieved: { eyeShift, farEyeRatio, silhouetteRatio }, clamped }`, where `clamped` names the _defaulted_
|
|
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?, turn? }`. `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. `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) 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,12 +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. Set `h` on a sclera and its lash together — they share one frame, and the blink fold tears if they diverge.
|
|
37
|
-
-
|
|
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. 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
|
+
- **`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; `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.
|
|
38
39
|
|
|
39
40
|
### `measure_layers`
|
|
40
41
|
|
|
41
|
-
Reports the same read-only geometry checks `compose_layers_from_parts` returns inline (iris size/offset relative to the sclera, eye aspect, 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, missing optional roles), over an already-composed layers directory — for re-checking a layers dir without recomposing it.
|
|
42
43
|
|
|
43
44
|
- **`layersDir`** — directory of role-named layer PNGs (resolved against the working directory).
|
|
44
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.
|
|
@@ -757,6 +757,7 @@ function facePlateHalfOf(layers) {
|
|
|
757
757
|
}
|
|
758
758
|
return face.cropW / 2;
|
|
759
759
|
}
|
|
760
|
+
var STRAND_MIN_RUN_FRACTION = 0.5;
|
|
760
761
|
async function autoRigFromLayers(input) {
|
|
761
762
|
try {
|
|
762
763
|
const layers = input.layers;
|
|
@@ -793,6 +794,7 @@ async function autoRigFromLayers(input) {
|
|
|
793
794
|
const layerInputs = [];
|
|
794
795
|
const crops = [];
|
|
795
796
|
const rowSpansByRole = [];
|
|
797
|
+
let hairFrontMask;
|
|
796
798
|
for (let i = 0; i < resolvedLayers.length; i++) {
|
|
797
799
|
const { resolved, fileName } = resolvedLayers[i];
|
|
798
800
|
const png = await decodePng(resolved);
|
|
@@ -837,16 +839,19 @@ async function autoRigFromLayers(input) {
|
|
|
837
839
|
const buffer = await cropToBuffer(png.rgba, png.width, png.height, bbox);
|
|
838
840
|
const rowLeft = new Int32Array(canvasH).fill(canvasW);
|
|
839
841
|
const rowRight = new Int32Array(canvasH).fill(-1);
|
|
842
|
+
const ownMask = role === "hair_front" ? new Uint8Array(canvasW * canvasH) : void 0;
|
|
840
843
|
for (let y = 0; y < canvasH; y++) {
|
|
841
844
|
for (let x = 0; x < canvasW; x++) {
|
|
842
845
|
const p = y * canvasW + x;
|
|
843
846
|
if (png.rgba[p * 4 + 3] < ALPHA_OPAQUE) continue;
|
|
844
847
|
opaque[p] = 1;
|
|
848
|
+
if (ownMask !== void 0) ownMask[p] = 1;
|
|
845
849
|
if (x < rowLeft[y]) rowLeft[y] = x;
|
|
846
850
|
if (x > rowRight[y]) rowRight[y] = x;
|
|
847
851
|
}
|
|
848
852
|
}
|
|
849
853
|
rowSpansByRole.push({ role, rowLeft, rowRight });
|
|
854
|
+
if (ownMask !== void 0) hairFrontMask = ownMask;
|
|
850
855
|
const layer = {
|
|
851
856
|
role,
|
|
852
857
|
fileName,
|
|
@@ -892,6 +897,63 @@ async function autoRigFromLayers(input) {
|
|
|
892
897
|
}
|
|
893
898
|
headEdges = { left, right };
|
|
894
899
|
}
|
|
900
|
+
let strandEdges;
|
|
901
|
+
const irisLayers = layerInputs.filter((l) => l.role === "iris_L" || l.role === "iris_R").sort((a, b) => a.bbox.x + a.bbox.w / 2 - (b.bbox.x + b.bbox.w / 2));
|
|
902
|
+
if (hairFrontMask !== void 0 && irisLayers.length === 2) {
|
|
903
|
+
const mask = hairFrontMask;
|
|
904
|
+
const half = canvasW / 2;
|
|
905
|
+
const strandOn = (iris, other, side) => {
|
|
906
|
+
const r = Math.floor(iris.bbox.y + iris.bbox.h / 2);
|
|
907
|
+
const centre = iris.bbox.x + iris.bbox.w / 2;
|
|
908
|
+
const otherX = other.bbox.x + other.bbox.w / 2 - half;
|
|
909
|
+
const c = side < 0 ? Math.ceil(centre) - 1 : Math.floor(centre);
|
|
910
|
+
const span2 = rowSpansByRole.find((s) => s.role === iris.role);
|
|
911
|
+
if (span2.rowRight[r] < span2.rowLeft[r]) return void 0;
|
|
912
|
+
const minRun = STRAND_MIN_RUN_FRACTION * (span2.rowRight[r] + 1 - span2.rowLeft[r]);
|
|
913
|
+
const strand = new Uint8Array(canvasW);
|
|
914
|
+
for (let a = 0; a < canvasW; ) {
|
|
915
|
+
if (mask[r * canvasW + a] !== 1) {
|
|
916
|
+
a++;
|
|
917
|
+
continue;
|
|
918
|
+
}
|
|
919
|
+
let b = a;
|
|
920
|
+
while (b < canvasW && mask[r * canvasW + b] === 1) b++;
|
|
921
|
+
if (b - a >= minRun) strand.fill(1, a, b);
|
|
922
|
+
a = b;
|
|
923
|
+
}
|
|
924
|
+
const strandAt = (x2) => x2 >= 0 && x2 < canvasW && strand[x2] === 1;
|
|
925
|
+
const outerBoundary = (x2) => (side < 0 ? x2 : x2 + 1) - half;
|
|
926
|
+
let x = c;
|
|
927
|
+
let runFace;
|
|
928
|
+
if (!strandAt(c)) {
|
|
929
|
+
while (x >= 0 && x < canvasW && !strandAt(x)) x += side;
|
|
930
|
+
if (x < 0 || x >= canvasW) return void 0;
|
|
931
|
+
runFace = outerBoundary(x - side);
|
|
932
|
+
} else {
|
|
933
|
+
let f = c - side;
|
|
934
|
+
while (strandAt(f)) f -= side;
|
|
935
|
+
const face = outerBoundary(f);
|
|
936
|
+
runFace = side * (face - otherX) > 0 ? face : null;
|
|
937
|
+
}
|
|
938
|
+
while (strandAt(x)) x += side;
|
|
939
|
+
return {
|
|
940
|
+
y: canvasH / 2 - (r + 0.5),
|
|
941
|
+
irisOuter: (side < 0 ? span2.rowLeft[r] : span2.rowRight[r] + 1) - half,
|
|
942
|
+
irisInner: (side < 0 ? span2.rowRight[r] + 1 : span2.rowLeft[r]) - half,
|
|
943
|
+
runOuter: outerBoundary(x - side),
|
|
944
|
+
runFace
|
|
945
|
+
};
|
|
946
|
+
};
|
|
947
|
+
const [low, high] = irisLayers;
|
|
948
|
+
const left = strandOn(low, high, -1);
|
|
949
|
+
const right = strandOn(high, low, 1);
|
|
950
|
+
if (left !== void 0 || right !== void 0) {
|
|
951
|
+
strandEdges = {
|
|
952
|
+
...left === void 0 ? {} : { left },
|
|
953
|
+
...right === void 0 ? {} : { right }
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
}
|
|
895
957
|
let turn;
|
|
896
958
|
let model;
|
|
897
959
|
try {
|
|
@@ -911,7 +973,8 @@ async function autoRigFromLayers(input) {
|
|
|
911
973
|
onTurnSolved: (report) => {
|
|
912
974
|
turn = report;
|
|
913
975
|
},
|
|
914
|
-
...headEdges === void 0 ? {} : { headEdges }
|
|
976
|
+
...headEdges === void 0 ? {} : { headEdges },
|
|
977
|
+
...strandEdges === void 0 ? {} : { strandEdges }
|
|
915
978
|
}
|
|
916
979
|
);
|
|
917
980
|
} catch (e) {
|
|
@@ -958,6 +1021,7 @@ async function autoRigFromLayers(input) {
|
|
|
958
1021
|
...headHalfWidth === void 0 ? {} : { headHalfWidth },
|
|
959
1022
|
headHalfWidthApplied,
|
|
960
1023
|
...headEdges === void 0 ? {} : { headEdges },
|
|
1024
|
+
...strandEdges === void 0 ? {} : { strandEdges },
|
|
961
1025
|
...turn === void 0 ? {} : { turn }
|
|
962
1026
|
};
|
|
963
1027
|
} catch (err) {
|
|
@@ -976,7 +1040,8 @@ var EYE_ASPECT_MIN = 0.5;
|
|
|
976
1040
|
var IRIS_OFFSET_MAX_X = 3;
|
|
977
1041
|
var IRIS_OFFSET_MAX_Y = 10;
|
|
978
1042
|
var EDGE_SOLID_MAX = 0.5;
|
|
979
|
-
var
|
|
1043
|
+
var LASH_STRAY_TOL_FRAC = 0.02;
|
|
1044
|
+
var EYE_FACING_TOL_FRAC = 0.02;
|
|
980
1045
|
var EDGE_RUN_MIN_PX = 40;
|
|
981
1046
|
var FLAT_CUT_MAX_FRAC = 0.1;
|
|
982
1047
|
var FLAT_CUT_MIN_PX = 40;
|
|
@@ -1057,6 +1122,21 @@ async function layerStats(filePath) {
|
|
|
1057
1122
|
};
|
|
1058
1123
|
}
|
|
1059
1124
|
var pct = (v) => `${(v * 100).toFixed(0)}%`;
|
|
1125
|
+
async function lashOffSclera(eyePath, lashPath) {
|
|
1126
|
+
const eye = await decodePng(eyePath);
|
|
1127
|
+
const lash = await decodePng(lashPath);
|
|
1128
|
+
let opaque = 0;
|
|
1129
|
+
let off = 0;
|
|
1130
|
+
for (let y = 0; y < lash.height; y++) {
|
|
1131
|
+
for (let x = 0; x < lash.width; x++) {
|
|
1132
|
+
if (lash.rgba[(y * lash.width + x) * 4 + 3] < 128) continue;
|
|
1133
|
+
opaque++;
|
|
1134
|
+
const onEye = x < eye.width && y < eye.height;
|
|
1135
|
+
if (!onEye || eye.rgba[(y * eye.width + x) * 4 + 3] <= 8) off++;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
return { opaque, off };
|
|
1139
|
+
}
|
|
1060
1140
|
async function measureDir(absDir) {
|
|
1061
1141
|
const files = fs2.readdirSync(absDir).filter((f) => f.endsWith(".png") && f !== "preview.png").sort();
|
|
1062
1142
|
if (files.length === 0) {
|
|
@@ -1138,12 +1218,28 @@ async function measureDir(absDir) {
|
|
|
1138
1218
|
}
|
|
1139
1219
|
}
|
|
1140
1220
|
if (lash) {
|
|
1141
|
-
const
|
|
1221
|
+
const { opaque, off } = await lashOffSclera(
|
|
1222
|
+
path4.join(absDir, `eye_${side}.png`),
|
|
1223
|
+
path4.join(absDir, `lash_${side}.png`)
|
|
1224
|
+
);
|
|
1142
1225
|
const dTop = lash.marginTop - eye.marginTop;
|
|
1143
|
-
|
|
1226
|
+
const faults = [
|
|
1227
|
+
...off > opaque * LASH_STRAY_TOL_FRAC ? [`${off} of its ${opaque} opaque px lie off eye_${side}'s sclera`] : [],
|
|
1228
|
+
...Math.abs(dTop) > 0.5 ? [`its top edge is ${dTop.toFixed(1)} px off the sclera's`] : []
|
|
1229
|
+
];
|
|
1230
|
+
if (faults.length > 0) {
|
|
1144
1231
|
warnings.push(
|
|
1145
|
-
`lash_${side}:
|
|
1232
|
+
`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.`
|
|
1146
1233
|
);
|
|
1234
|
+
} else {
|
|
1235
|
+
const bareLeft = lash.marginLeft - eye.marginLeft;
|
|
1236
|
+
const bareRight = lash.marginRight - eye.marginRight;
|
|
1237
|
+
const [bareOuter, bareInner] = side === "R" ? [bareLeft, bareRight] : [bareRight, bareLeft];
|
|
1238
|
+
if ((bareOuter - bareInner) / eye.w > EYE_FACING_TOL_FRAC) {
|
|
1239
|
+
warnings.push(
|
|
1240
|
+
`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.`
|
|
1241
|
+
);
|
|
1242
|
+
}
|
|
1147
1243
|
}
|
|
1148
1244
|
}
|
|
1149
1245
|
}
|
|
@@ -1278,6 +1374,12 @@ var ORDER = [
|
|
|
1278
1374
|
"brow_R",
|
|
1279
1375
|
"hair_front"
|
|
1280
1376
|
];
|
|
1377
|
+
var PART_FILES = [
|
|
1378
|
+
...new Set(
|
|
1379
|
+
Object.values(DEFAULT_LAYOUT).map((cfg) => cfg.src).filter((src) => !src.startsWith("eyewhite_"))
|
|
1380
|
+
),
|
|
1381
|
+
EYEWHITE_SRC
|
|
1382
|
+
];
|
|
1281
1383
|
function resolveLayout(overrides) {
|
|
1282
1384
|
const resolved = { ...DEFAULT_LAYOUT };
|
|
1283
1385
|
if (overrides === void 0) return resolved;
|
|
@@ -1313,6 +1415,18 @@ function resolveLayout(overrides) {
|
|
|
1313
1415
|
}
|
|
1314
1416
|
return resolved;
|
|
1315
1417
|
}
|
|
1418
|
+
function resolveMirrorParts(names) {
|
|
1419
|
+
const mirrored = /* @__PURE__ */ new Set();
|
|
1420
|
+
for (const [i, name] of (names ?? []).entries()) {
|
|
1421
|
+
if (!PART_FILES.includes(name)) {
|
|
1422
|
+
throw new AutoRigInputError(
|
|
1423
|
+
`mirrorParts[${i}]: unknown part ${JSON.stringify(name)} \u2014 expected one of ${PART_FILES.join(", ")}`
|
|
1424
|
+
);
|
|
1425
|
+
}
|
|
1426
|
+
mirrored.add(name);
|
|
1427
|
+
}
|
|
1428
|
+
return mirrored;
|
|
1429
|
+
}
|
|
1316
1430
|
function keyWhiteToAlpha(rgba) {
|
|
1317
1431
|
const keyed = Buffer.from(rgba);
|
|
1318
1432
|
for (let i = 0; i < keyed.length; i += 4) {
|
|
@@ -1322,7 +1436,7 @@ function keyWhiteToAlpha(rgba) {
|
|
|
1322
1436
|
}
|
|
1323
1437
|
return keyed;
|
|
1324
1438
|
}
|
|
1325
|
-
async function partBuffer(role, cfg, partsDir, inMemory) {
|
|
1439
|
+
async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
|
|
1326
1440
|
let img;
|
|
1327
1441
|
if (inMemory !== void 0) {
|
|
1328
1442
|
img = sharp2(inMemory);
|
|
@@ -1340,7 +1454,7 @@ async function partBuffer(role, cfg, partsDir, inMemory) {
|
|
|
1340
1454
|
});
|
|
1341
1455
|
}
|
|
1342
1456
|
if (!cfg.noTrim) img = img.trim({ threshold: 12 });
|
|
1343
|
-
if (cfg.mirror) img = img.flop();
|
|
1457
|
+
if ((cfg.mirror ?? false) !== flipSource) img = img.flop();
|
|
1344
1458
|
const trimmed = await img.png().toBuffer({ resolveWithObject: true });
|
|
1345
1459
|
if (cfg.h === void 0) {
|
|
1346
1460
|
const scaledH = Math.round(
|
|
@@ -1437,28 +1551,47 @@ async function composeLayersFromParts(input) {
|
|
|
1437
1551
|
);
|
|
1438
1552
|
}
|
|
1439
1553
|
const layout = resolveLayout(input.layout);
|
|
1554
|
+
const mirrored = resolveMirrorParts(input.mirrorParts);
|
|
1440
1555
|
const split = await prepEyeSplit(partsDir);
|
|
1441
1556
|
const splitSources = /* @__PURE__ */ new Map([
|
|
1442
1557
|
["eyewhite_sclera.png", split.sclera],
|
|
1443
1558
|
["eyewhite_lash.png", split.lash]
|
|
1444
1559
|
]);
|
|
1445
|
-
const
|
|
1560
|
+
const placed = [];
|
|
1446
1561
|
const skipped = [];
|
|
1447
|
-
const preview = [];
|
|
1448
1562
|
for (const role of ORDER) {
|
|
1449
1563
|
const cfg = layout[role];
|
|
1564
|
+
const inMemory = splitSources.get(cfg.src);
|
|
1450
1565
|
const part = await partBuffer(
|
|
1451
1566
|
role,
|
|
1452
1567
|
cfg,
|
|
1453
1568
|
partsDir,
|
|
1454
|
-
|
|
1569
|
+
inMemory,
|
|
1570
|
+
// The split halves are cut from eyewhite.png, the file a caller names.
|
|
1571
|
+
mirrored.has(inMemory === void 0 ? cfg.src : EYEWHITE_SRC)
|
|
1455
1572
|
);
|
|
1456
1573
|
if (part === null) {
|
|
1457
1574
|
skipped.push(role);
|
|
1458
|
-
fs3.rmSync(path5.join(outDir, `${role}.png`), { force: true });
|
|
1459
1575
|
continue;
|
|
1460
1576
|
}
|
|
1461
1577
|
const { left, top } = placement(role, cfg, part.w, part.h);
|
|
1578
|
+
if (role === "lash_L" || role === "lash_R") {
|
|
1579
|
+
const eyeRole = role === "lash_L" ? "eye_L" : "eye_R";
|
|
1580
|
+
const eye = placed.find((p) => p.role === eyeRole);
|
|
1581
|
+
if (eye !== void 0 && (eye.left !== left || eye.top !== top || eye.part.w !== part.w || eye.part.h !== part.h)) {
|
|
1582
|
+
throw new AutoRigInputError(
|
|
1583
|
+
`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.`
|
|
1584
|
+
);
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
placed.push({ role, part, left, top });
|
|
1588
|
+
}
|
|
1589
|
+
for (const role of skipped) {
|
|
1590
|
+
fs3.rmSync(path5.join(outDir, `${role}.png`), { force: true });
|
|
1591
|
+
}
|
|
1592
|
+
const layers = [];
|
|
1593
|
+
const preview = [];
|
|
1594
|
+
for (const { role, part, left, top } of placed) {
|
|
1462
1595
|
const layer = await blankCanvas().composite([{ input: part.buf, left, top }]).png().toBuffer();
|
|
1463
1596
|
const outPath = path5.join(outDir, `${role}.png`);
|
|
1464
1597
|
writeFileAtomic(outPath, layer);
|
|
@@ -1501,7 +1634,7 @@ async function composeLayersFromParts(input) {
|
|
|
1501
1634
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
1502
1635
|
import { z } from "zod";
|
|
1503
1636
|
function createIkiMcpServer() {
|
|
1504
|
-
const server = new McpServer({ name: "iki", version: "0.
|
|
1637
|
+
const server = new McpServer({ name: "iki", version: "0.10.0" });
|
|
1505
1638
|
server.registerTool(
|
|
1506
1639
|
"validate_iki",
|
|
1507
1640
|
{
|
|
@@ -1589,7 +1722,7 @@ function createIkiMcpServer() {
|
|
|
1589
1722
|
noseShift: z.number().optional(),
|
|
1590
1723
|
mouthShift: z.number().optional()
|
|
1591
1724
|
}).optional().describe(
|
|
1592
|
-
"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 (the result's `turn.clamped` lists
|
|
1725
|
+
"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."
|
|
1593
1726
|
)
|
|
1594
1727
|
}
|
|
1595
1728
|
},
|
|
@@ -1628,7 +1761,10 @@ function createIkiMcpServer() {
|
|
|
1628
1761
|
h: z.number()
|
|
1629
1762
|
}).partial()
|
|
1630
1763
|
).optional().describe(
|
|
1631
|
-
"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
|
|
1764
|
+
"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."
|
|
1765
|
+
),
|
|
1766
|
+
mirrorParts: z.array(z.string()).optional().describe(
|
|
1767
|
+
"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."
|
|
1632
1768
|
)
|
|
1633
1769
|
}
|
|
1634
1770
|
},
|
|
@@ -1730,4 +1866,4 @@ export {
|
|
|
1730
1866
|
composeLayersFromParts,
|
|
1731
1867
|
createIkiMcpServer
|
|
1732
1868
|
};
|
|
1733
|
-
//# sourceMappingURL=chunk-
|
|
1869
|
+
//# sourceMappingURL=chunk-OCIICRUA.mjs.map
|