@ikijs/mcp 0.21.0 → 0.23.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 -6
- package/dist/{chunk-EKGWFKU2.mjs → chunk-YQECLFI4.mjs} +1080 -119
- package/dist/chunk-YQECLFI4.mjs.map +1 -0
- package/dist/cli.js +1088 -148
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +64 -3
- package/dist/index.d.ts +64 -3
- package/dist/index.js +1088 -148
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-EKGWFKU2.mjs.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -634,17 +634,83 @@ async function autoRigFromLayers(input) {
|
|
|
634
634
|
|
|
635
635
|
// src/compose.ts
|
|
636
636
|
var import_node_fs3 = __toESM(require("fs"));
|
|
637
|
-
var
|
|
638
|
-
var
|
|
639
|
-
var
|
|
637
|
+
var import_node_path7 = __toESM(require("path"));
|
|
638
|
+
var import_sharp4 = __toESM(require("sharp"));
|
|
639
|
+
var import_editor11 = require("@ikijs/editor");
|
|
640
|
+
|
|
641
|
+
// src/trim.ts
|
|
642
|
+
var import_editor3 = require("@ikijs/editor");
|
|
643
|
+
var TRIM_THRESHOLD = 12;
|
|
644
|
+
var STRAY_SPECK_FRACTION = 0.01;
|
|
645
|
+
function luma(rgba, i) {
|
|
646
|
+
return 0.299 * rgba[i] + 0.587 * rgba[i + 1] + 0.114 * rgba[i + 2];
|
|
647
|
+
}
|
|
648
|
+
function boxWithoutStraySpecks(rgba, W, H) {
|
|
649
|
+
const n = W * H;
|
|
650
|
+
let kept = 0;
|
|
651
|
+
for (let p = 0; p < n; p++) if (rgba[p * 4 + 3] > TRIM_THRESHOLD) kept++;
|
|
652
|
+
const visited = new Uint8Array(n);
|
|
653
|
+
let stack = new Int32Array(1024);
|
|
654
|
+
const drawing = [W, H, -1, -1];
|
|
655
|
+
const strays = [W, H, -1, -1];
|
|
656
|
+
let anyOpaque = false;
|
|
657
|
+
for (let start = 0; start < n; start++) {
|
|
658
|
+
if (visited[start] || rgba[start * 4 + 3] <= TRIM_THRESHOLD) continue;
|
|
659
|
+
let setLeft = W;
|
|
660
|
+
let setTop = H;
|
|
661
|
+
let setRight = -1;
|
|
662
|
+
let setBottom = -1;
|
|
663
|
+
let size = 0;
|
|
664
|
+
let opaque = false;
|
|
665
|
+
let depth = 0;
|
|
666
|
+
visited[start] = 1;
|
|
667
|
+
stack[depth++] = start;
|
|
668
|
+
while (depth > 0) {
|
|
669
|
+
const p = stack[--depth];
|
|
670
|
+
size++;
|
|
671
|
+
if (rgba[p * 4 + 3] >= import_editor3.ALPHA_OPAQUE) opaque = true;
|
|
672
|
+
const px2 = p % W;
|
|
673
|
+
const py = (p - px2) / W;
|
|
674
|
+
setLeft = Math.min(setLeft, px2);
|
|
675
|
+
setTop = Math.min(setTop, py);
|
|
676
|
+
setRight = Math.max(setRight, px2);
|
|
677
|
+
setBottom = Math.max(setBottom, py);
|
|
678
|
+
for (let y = Math.max(0, py - 1); y <= Math.min(H - 1, py + 1); y++) {
|
|
679
|
+
for (let x = Math.max(0, px2 - 1); x <= Math.min(W - 1, px2 + 1); x++) {
|
|
680
|
+
const q = y * W + x;
|
|
681
|
+
if (!visited[q] && rgba[q * 4 + 3] > TRIM_THRESHOLD) {
|
|
682
|
+
visited[q] = 1;
|
|
683
|
+
if (depth === stack.length) {
|
|
684
|
+
const grown = new Int32Array(Math.min(n, stack.length * 2));
|
|
685
|
+
grown.set(stack);
|
|
686
|
+
stack = grown;
|
|
687
|
+
}
|
|
688
|
+
stack[depth++] = q;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
anyOpaque ||= opaque;
|
|
694
|
+
const into = !opaque && size < kept * STRAY_SPECK_FRACTION ? strays : drawing;
|
|
695
|
+
into[0] = Math.min(into[0], setLeft);
|
|
696
|
+
into[1] = Math.min(into[1], setTop);
|
|
697
|
+
into[2] = Math.max(into[2], setRight);
|
|
698
|
+
into[3] = Math.max(into[3], setBottom);
|
|
699
|
+
}
|
|
700
|
+
if (!anyOpaque || strays[2] < 0) return null;
|
|
701
|
+
const [left, top, right, bottom] = drawing;
|
|
702
|
+
if (strays[0] >= left && strays[1] >= top && strays[2] <= right && strays[3] <= bottom)
|
|
703
|
+
return null;
|
|
704
|
+
return { left, top, width: right - left + 1, height: bottom - top + 1 };
|
|
705
|
+
}
|
|
640
706
|
|
|
641
707
|
// src/measure.ts
|
|
642
708
|
var import_node_fs2 = __toESM(require("fs"));
|
|
643
|
-
var
|
|
709
|
+
var import_node_path6 = __toESM(require("path"));
|
|
644
710
|
|
|
645
711
|
// src/measure-arms.ts
|
|
646
712
|
var import_node_path3 = __toESM(require("path"));
|
|
647
|
-
var
|
|
713
|
+
var import_editor4 = require("@ikijs/editor");
|
|
648
714
|
var ARM_ROLES = ["arm_L", "arm_R"];
|
|
649
715
|
var CAP_OVERLAP = 0.5;
|
|
650
716
|
var px = (v) => `${Number(v.toFixed(1))}`;
|
|
@@ -673,7 +739,7 @@ async function armWarnings(absDir, layers) {
|
|
|
673
739
|
continue;
|
|
674
740
|
}
|
|
675
741
|
if (set === void 0) {
|
|
676
|
-
const measurer = (0,
|
|
742
|
+
const measurer = (0, import_editor4.createLayerSetMeasurer)({
|
|
677
743
|
width: body.canvasW,
|
|
678
744
|
height: body.canvasH
|
|
679
745
|
});
|
|
@@ -681,12 +747,12 @@ async function armWarnings(absDir, layers) {
|
|
|
681
747
|
}
|
|
682
748
|
let g;
|
|
683
749
|
try {
|
|
684
|
-
g = (0,
|
|
750
|
+
g = (0, import_editor4.armGeometry)(
|
|
685
751
|
await measured(set.measurer, absDir, arm),
|
|
686
752
|
set.body.bbox.x + set.body.bbox.w / 2 - body.canvasW / 2
|
|
687
753
|
);
|
|
688
754
|
} catch (err) {
|
|
689
|
-
if (err instanceof
|
|
755
|
+
if (err instanceof import_editor4.LayerGeometryError) {
|
|
690
756
|
warnings.push(
|
|
691
757
|
`${arm}: ${err.message} \u2014 auto_rig_from_layers refuses it. Regenerate arm.png drawn hanging, shoulder at the top. Billed.`
|
|
692
758
|
);
|
|
@@ -714,7 +780,7 @@ function capWarning(arm, g, body) {
|
|
|
714
780
|
}
|
|
715
781
|
|
|
716
782
|
// src/measure-forearm-pose.ts
|
|
717
|
-
var
|
|
783
|
+
var import_editor5 = require("@ikijs/editor");
|
|
718
784
|
var POSE_ROLES = ["forearm_pose_L", "forearm_pose_R"];
|
|
719
785
|
var ARM_OF = {
|
|
720
786
|
forearm_pose_L: "arm_L",
|
|
@@ -748,7 +814,7 @@ async function forearmPoseWarnings(absDir, layers) {
|
|
|
748
814
|
continue;
|
|
749
815
|
}
|
|
750
816
|
if (layers.body === void 0) continue;
|
|
751
|
-
const measurer = (0,
|
|
817
|
+
const measurer = (0, import_editor5.createLayerSetMeasurer)({
|
|
752
818
|
width: stats.canvasW,
|
|
753
819
|
height: stats.canvasH
|
|
754
820
|
});
|
|
@@ -756,12 +822,12 @@ async function forearmPoseWarnings(absDir, layers) {
|
|
|
756
822
|
let armLayer;
|
|
757
823
|
try {
|
|
758
824
|
armLayer = await measured(measurer, absDir, arm);
|
|
759
|
-
a = (0,
|
|
825
|
+
a = (0, import_editor5.armGeometry)(armLayer, arm === "arm_R" ? Infinity : -Infinity);
|
|
760
826
|
} catch (err) {
|
|
761
|
-
if (err instanceof
|
|
827
|
+
if (err instanceof import_editor5.LayerGeometryError) continue;
|
|
762
828
|
throw err;
|
|
763
829
|
}
|
|
764
|
-
const b = (0,
|
|
830
|
+
const b = (0, import_editor5.forearmPoseGeometry)(await measured(measurer, absDir, pose));
|
|
765
831
|
warnings.push(...jointWarnings(pose, arm, stats, a, armLayer, b));
|
|
766
832
|
}
|
|
767
833
|
return warnings;
|
|
@@ -799,10 +865,781 @@ function jointWarnings(pose, arm, stats, a, armLayer, b) {
|
|
|
799
865
|
return warnings;
|
|
800
866
|
}
|
|
801
867
|
|
|
802
|
-
// src/measure-
|
|
868
|
+
// src/measure-lips.ts
|
|
803
869
|
var import_node_path4 = __toESM(require("path"));
|
|
804
|
-
var
|
|
870
|
+
var import_editor7 = require("@ikijs/editor");
|
|
871
|
+
|
|
872
|
+
// src/compose-lips.ts
|
|
873
|
+
var import_sharp2 = __toESM(require("sharp"));
|
|
805
874
|
var import_editor6 = require("@ikijs/editor");
|
|
875
|
+
var KEYED_SRC = "mouth_keyed.png";
|
|
876
|
+
var INTERIOR_SRC = "mouth_interior.png";
|
|
877
|
+
var KEY_CANDIDATE = 0.5;
|
|
878
|
+
var KEY_FILL_DIST = 20;
|
|
879
|
+
var KEY_REACH = 8;
|
|
880
|
+
var KEY_COLLINEAR = 12;
|
|
881
|
+
var KEY_MIN_SHARE = 0.05;
|
|
882
|
+
var STRAY_KEY_FRACTION = 0.02;
|
|
883
|
+
var MIN_OPENING_WIDTH = 0.3;
|
|
884
|
+
var SECOND_HOLE_FRACTION = 0.05;
|
|
885
|
+
var BAND_LUMA = 150;
|
|
886
|
+
var BAND_CAP = 3;
|
|
887
|
+
var CAVITY_LUMA = 100;
|
|
888
|
+
var SKIN_MIN_R = 225;
|
|
889
|
+
var SKIN_MIN_G = 160;
|
|
890
|
+
var SKIN_MIN_B = 135;
|
|
891
|
+
var TEETH_MIN_G = 215;
|
|
892
|
+
var TEETH_MIN_B = 205;
|
|
893
|
+
var isSkin = (r, g, b) => r > SKIN_MIN_R && g > SKIN_MIN_G && b > SKIN_MIN_B && !(g > TEETH_MIN_G && b > TEETH_MIN_B);
|
|
894
|
+
function components(mask, W, H) {
|
|
895
|
+
const n = W * H;
|
|
896
|
+
const label = new Int32Array(n).fill(-1);
|
|
897
|
+
const stack = new Int32Array(n);
|
|
898
|
+
const sizes = [];
|
|
899
|
+
const boxes = [];
|
|
900
|
+
for (let start = 0; start < n; start++) {
|
|
901
|
+
if (!mask[start] || label[start] >= 0) continue;
|
|
902
|
+
const id = sizes.length;
|
|
903
|
+
const box = { x0: W, y0: H, x1: -1, y1: -1 };
|
|
904
|
+
let size = 0;
|
|
905
|
+
let depth = 0;
|
|
906
|
+
label[start] = id;
|
|
907
|
+
stack[depth++] = start;
|
|
908
|
+
while (depth > 0) {
|
|
909
|
+
const p = stack[--depth];
|
|
910
|
+
size++;
|
|
911
|
+
const px2 = p % W;
|
|
912
|
+
const py = (p - px2) / W;
|
|
913
|
+
box.x0 = Math.min(box.x0, px2);
|
|
914
|
+
box.x1 = Math.max(box.x1, px2);
|
|
915
|
+
box.y0 = Math.min(box.y0, py);
|
|
916
|
+
box.y1 = Math.max(box.y1, py);
|
|
917
|
+
for (let y = Math.max(0, py - 1); y <= Math.min(H - 1, py + 1); y++) {
|
|
918
|
+
for (let x = Math.max(0, px2 - 1); x <= Math.min(W - 1, px2 + 1); x++) {
|
|
919
|
+
if (x !== px2 && y !== py) continue;
|
|
920
|
+
const q = y * W + x;
|
|
921
|
+
if (mask[q] && label[q] < 0) {
|
|
922
|
+
label[q] = id;
|
|
923
|
+
stack[depth++] = q;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
sizes.push(size);
|
|
929
|
+
boxes.push(box);
|
|
930
|
+
}
|
|
931
|
+
return { label, sizes, boxes };
|
|
932
|
+
}
|
|
933
|
+
var largest = (sizes) => sizes.reduce((best, s, i) => best < 0 || s > sizes[best] ? i : best, -1);
|
|
934
|
+
function dilate(mask, W, H, reach) {
|
|
935
|
+
const rows = new Uint8Array(W * H);
|
|
936
|
+
const prefix = new Int32Array(Math.max(W, H) + 1);
|
|
937
|
+
for (let y = 0; y < H; y++) {
|
|
938
|
+
for (let x = 0; x < W; x++) prefix[x + 1] = prefix[x] + mask[y * W + x];
|
|
939
|
+
for (let x = 0; x < W; x++) {
|
|
940
|
+
rows[y * W + x] = prefix[Math.min(W, x + reach + 1)] - prefix[Math.max(0, x - reach)] > 0 ? 1 : 0;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
const out = new Uint8Array(W * H);
|
|
944
|
+
for (let x = 0; x < W; x++) {
|
|
945
|
+
for (let y = 0; y < H; y++) prefix[y + 1] = prefix[y] + rows[y * W + x];
|
|
946
|
+
for (let y = 0; y < H; y++) {
|
|
947
|
+
out[y * W + x] = prefix[Math.min(H, y + reach + 1)] - prefix[Math.max(0, y - reach)] > 0 ? 1 : 0;
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
return out;
|
|
951
|
+
}
|
|
952
|
+
function shareOf(rgba, i, j, g) {
|
|
953
|
+
const dr = g[0] - rgba[j];
|
|
954
|
+
const dg = g[1] - rgba[j + 1];
|
|
955
|
+
const db = g[2] - rgba[j + 2];
|
|
956
|
+
const t = ((rgba[i] - rgba[j]) * dr + (rgba[i + 1] - rgba[j + 1]) * dg + (rgba[i + 2] - rgba[j + 2]) * db) / (dr * dr + dg * dg + db * db);
|
|
957
|
+
return Math.min(1, Math.max(0, t));
|
|
958
|
+
}
|
|
959
|
+
function keyGreen(rgba, W, H) {
|
|
960
|
+
const n = W * H;
|
|
961
|
+
const noGreen = new AutoRigInputError(
|
|
962
|
+
`${KEYED_SRC}: no green opening (#00FF00) to key \u2014 regenerate it with the inside of the open mouth painted ONE flat pure green`
|
|
963
|
+
);
|
|
964
|
+
const hist = [
|
|
965
|
+
new Uint32Array(256),
|
|
966
|
+
new Uint32Array(256),
|
|
967
|
+
new Uint32Array(256)
|
|
968
|
+
];
|
|
969
|
+
let candidates = 0;
|
|
970
|
+
for (let p = 0; p < n; p++) {
|
|
971
|
+
const i = p * 4;
|
|
972
|
+
if (rgba[i + 3] < import_editor6.ALPHA_OPAQUE) continue;
|
|
973
|
+
const excess = (rgba[i + 1] - Math.max(rgba[i], rgba[i + 2])) / 255;
|
|
974
|
+
if (excess < KEY_CANDIDATE) continue;
|
|
975
|
+
candidates++;
|
|
976
|
+
for (let c = 0; c < 3; c++) hist[c][rgba[i + c]]++;
|
|
977
|
+
}
|
|
978
|
+
if (candidates === 0) throw noGreen;
|
|
979
|
+
const median = (h) => {
|
|
980
|
+
let seen = 0;
|
|
981
|
+
for (let v = 0; v < 256; v++) {
|
|
982
|
+
seen += h[v];
|
|
983
|
+
if (seen * 2 >= candidates) return v;
|
|
984
|
+
}
|
|
985
|
+
return 255;
|
|
986
|
+
};
|
|
987
|
+
const G = [median(hist[0]), median(hist[1]), median(hist[2])];
|
|
988
|
+
const out = Buffer.from(rgba);
|
|
989
|
+
const fill = new Uint8Array(n);
|
|
990
|
+
const ref = new Uint8Array(n);
|
|
991
|
+
let fillCount = 0;
|
|
992
|
+
for (let p = 0; p < n; p++) {
|
|
993
|
+
const i = p * 4;
|
|
994
|
+
if (rgba[i + 3] === 0) continue;
|
|
995
|
+
const dr = rgba[i] - G[0];
|
|
996
|
+
const dg = rgba[i + 1] - G[1];
|
|
997
|
+
const db = rgba[i + 2] - G[2];
|
|
998
|
+
const green = dr * dr + dg * dg + db * db <= KEY_FILL_DIST * KEY_FILL_DIST;
|
|
999
|
+
if (rgba[i + 3] < import_editor6.ALPHA_OPAQUE) {
|
|
1000
|
+
if (green) out[i + 3] = 0;
|
|
1001
|
+
} else if (green) {
|
|
1002
|
+
fill[p] = 1;
|
|
1003
|
+
fillCount++;
|
|
1004
|
+
} else {
|
|
1005
|
+
ref[p] = 1;
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
if (fillCount === 0) throw noGreen;
|
|
1009
|
+
const reach = dilate(fill, W, H, KEY_REACH);
|
|
1010
|
+
const collinear = KEY_COLLINEAR * KEY_COLLINEAR;
|
|
1011
|
+
for (let y = 0; y < H; y++) {
|
|
1012
|
+
for (let x = 0; x < W; x++) {
|
|
1013
|
+
const p = y * W + x;
|
|
1014
|
+
if (!reach[p] || fill[p] || out[p * 4 + 3] === 0) continue;
|
|
1015
|
+
const i = p * 4;
|
|
1016
|
+
let best = i;
|
|
1017
|
+
let bestD2 = (rgba[i] - G[0]) ** 2 + (rgba[i + 1] - G[1]) ** 2 + (rgba[i + 2] - G[2]) ** 2;
|
|
1018
|
+
const y1 = Math.min(H - 1, y + KEY_REACH);
|
|
1019
|
+
const x1 = Math.min(W - 1, x + KEY_REACH);
|
|
1020
|
+
for (let qy = Math.max(0, y - KEY_REACH); qy <= y1; qy++) {
|
|
1021
|
+
for (let qx = Math.max(0, x - KEY_REACH); qx <= x1; qx++) {
|
|
1022
|
+
const q = qy * W + qx;
|
|
1023
|
+
if (q === p || !ref[q]) continue;
|
|
1024
|
+
const j = q * 4;
|
|
1025
|
+
const d2 = (rgba[j] - G[0]) ** 2 + (rgba[j + 1] - G[1]) ** 2 + (rgba[j + 2] - G[2]) ** 2;
|
|
1026
|
+
if (d2 <= bestD2) continue;
|
|
1027
|
+
const t = shareOf(rgba, i, j, G);
|
|
1028
|
+
const er = rgba[i] - rgba[j] - t * (G[0] - rgba[j]);
|
|
1029
|
+
const eg = rgba[i + 1] - rgba[j + 1] - t * (G[1] - rgba[j + 1]);
|
|
1030
|
+
const eb = rgba[i + 2] - rgba[j + 2] - t * (G[2] - rgba[j + 2]);
|
|
1031
|
+
if (er * er + eg * eg + eb * eb > collinear) continue;
|
|
1032
|
+
bestD2 = d2;
|
|
1033
|
+
best = j;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
const k = shareOf(rgba, i, best, G);
|
|
1037
|
+
if (k < KEY_MIN_SHARE) continue;
|
|
1038
|
+
rgba.copy(out, i, best, best + 3);
|
|
1039
|
+
out[i + 3] = Math.round(rgba[i + 3] * (1 - k));
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
for (let p = 0; p < n; p++) if (fill[p]) out[p * 4 + 3] = 0;
|
|
1043
|
+
const { sizes } = components(fill, W, H);
|
|
1044
|
+
const main2 = largest(sizes);
|
|
1045
|
+
const strays = sizes.filter((_, i) => i !== main2);
|
|
1046
|
+
const strayPx = strays.reduce((a, b) => a + b, 0);
|
|
1047
|
+
if (strayPx > STRAY_KEY_FRACTION * sizes[main2]) {
|
|
1048
|
+
throw new AutoRigInputError(
|
|
1049
|
+
`${KEYED_SRC}: green outside the opening (${strayPx} px in ${strays.length} regions beside the opening's) \u2014 the key must be one flat region inside the outline; regenerate with no green elsewhere`
|
|
1050
|
+
);
|
|
1051
|
+
}
|
|
1052
|
+
return out;
|
|
1053
|
+
}
|
|
1054
|
+
var GROUND_TOLERANCE = 4;
|
|
1055
|
+
var GROUND_LIGHT = 200;
|
|
1056
|
+
var GROUND_MIN = 238;
|
|
1057
|
+
var GROUND_BORDER_SHARE = 0.65;
|
|
1058
|
+
function keyBorderWhite(rgba, W, H) {
|
|
1059
|
+
const border = [[], [], []];
|
|
1060
|
+
const edge = (p) => {
|
|
1061
|
+
for (let c = 0; c < 3; c++) border[c].push(rgba[p * 4 + c]);
|
|
1062
|
+
};
|
|
1063
|
+
for (let x = 0; x < W; x++) {
|
|
1064
|
+
edge(x);
|
|
1065
|
+
edge((H - 1) * W + x);
|
|
1066
|
+
}
|
|
1067
|
+
for (let y = 1; y < H - 1; y++) {
|
|
1068
|
+
edge(y * W);
|
|
1069
|
+
edge(y * W + W - 1);
|
|
1070
|
+
}
|
|
1071
|
+
const ground = border.map((v) => v.sort((a, b) => a - b)[v.length >> 1]);
|
|
1072
|
+
const light = ground.every((v) => v >= GROUND_LIGHT);
|
|
1073
|
+
if (light && ground.some((v) => v < GROUND_MIN)) {
|
|
1074
|
+
throw new AutoRigInputError(
|
|
1075
|
+
`${INTERIOR_SRC} came back opaque on a non-white ground \u2014 regenerate it with a transparent background. Billed.`
|
|
1076
|
+
);
|
|
1077
|
+
}
|
|
1078
|
+
if (!light) ground.fill(255);
|
|
1079
|
+
const out = Buffer.from(rgba);
|
|
1080
|
+
const seen = new Uint8Array(W * H);
|
|
1081
|
+
const stack = new Int32Array(W * H);
|
|
1082
|
+
let depth = 0;
|
|
1083
|
+
const seed = (p) => {
|
|
1084
|
+
if (seen[p]) return;
|
|
1085
|
+
for (let c = 0; c < 3; c++) {
|
|
1086
|
+
if (Math.abs(rgba[p * 4 + c] - ground[c]) > GROUND_TOLERANCE) return;
|
|
1087
|
+
}
|
|
1088
|
+
seen[p] = 1;
|
|
1089
|
+
stack[depth++] = p;
|
|
1090
|
+
};
|
|
1091
|
+
for (let x = 0; x < W; x++) {
|
|
1092
|
+
seed(x);
|
|
1093
|
+
seed((H - 1) * W + x);
|
|
1094
|
+
}
|
|
1095
|
+
for (let y = 0; y < H; y++) {
|
|
1096
|
+
seed(y * W);
|
|
1097
|
+
seed(y * W + W - 1);
|
|
1098
|
+
}
|
|
1099
|
+
if (light && depth < GROUND_BORDER_SHARE * border[0].length) {
|
|
1100
|
+
throw new AutoRigInputError(
|
|
1101
|
+
`${INTERIOR_SRC} came back opaque on a white ground too noisy or shaded to key cleanly \u2014 regenerate it with a transparent background. Billed.`
|
|
1102
|
+
);
|
|
1103
|
+
}
|
|
1104
|
+
while (depth > 0) {
|
|
1105
|
+
const p = stack[--depth];
|
|
1106
|
+
out[p * 4 + 3] = 0;
|
|
1107
|
+
const x = p % W;
|
|
1108
|
+
if (x > 0) seed(p - 1);
|
|
1109
|
+
if (x < W - 1) seed(p + 1);
|
|
1110
|
+
if (p >= W) seed(p - W);
|
|
1111
|
+
if (p < W * H - W) seed(p + W);
|
|
1112
|
+
}
|
|
1113
|
+
return out;
|
|
1114
|
+
}
|
|
1115
|
+
function drawingBox(rgba, W, H) {
|
|
1116
|
+
const speckless = boxWithoutStraySpecks(rgba, W, H);
|
|
1117
|
+
if (speckless !== null) {
|
|
1118
|
+
return {
|
|
1119
|
+
x: speckless.left,
|
|
1120
|
+
y: speckless.top,
|
|
1121
|
+
w: speckless.width,
|
|
1122
|
+
h: speckless.height
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
let x0 = W;
|
|
1126
|
+
let y0 = H;
|
|
1127
|
+
let x1 = -1;
|
|
1128
|
+
let y1 = -1;
|
|
1129
|
+
for (let y = 0; y < H; y++) {
|
|
1130
|
+
for (let x = 0; x < W; x++) {
|
|
1131
|
+
if (rgba[(y * W + x) * 4 + 3] <= TRIM_THRESHOLD) continue;
|
|
1132
|
+
x0 = Math.min(x0, x);
|
|
1133
|
+
x1 = Math.max(x1, x);
|
|
1134
|
+
y0 = Math.min(y0, y);
|
|
1135
|
+
y1 = Math.max(y1, y);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
return x1 < 0 ? null : { x: x0, y: y0, w: x1 - x0 + 1, h: y1 - y0 + 1 };
|
|
1139
|
+
}
|
|
1140
|
+
async function prepInterior(rgba, W, H) {
|
|
1141
|
+
const empty = new AutoRigInputError(
|
|
1142
|
+
`${INTERIOR_SRC}: nothing but lips/skin after trimming \u2014 regenerate it with the cavity, the teeth and the tongue only, NO lips`
|
|
1143
|
+
);
|
|
1144
|
+
const first = drawingBox(rgba, W, H);
|
|
1145
|
+
if (first === null) throw empty;
|
|
1146
|
+
const cw = first.w;
|
|
1147
|
+
const ch = first.h;
|
|
1148
|
+
const crop = Buffer.alloc(cw * ch * 4);
|
|
1149
|
+
for (let y = 0; y < ch; y++) {
|
|
1150
|
+
const from2 = ((first.y + y) * W + first.x) * 4;
|
|
1151
|
+
rgba.copy(crop, y * cw * 4, from2, from2 + cw * 4);
|
|
1152
|
+
}
|
|
1153
|
+
const skin = new Uint8Array(cw * ch);
|
|
1154
|
+
for (let p = 0; p < cw * ch; p++) {
|
|
1155
|
+
const i = p * 4;
|
|
1156
|
+
if (crop[i + 3] > TRIM_THRESHOLD && isSkin(crop[i], crop[i + 1], crop[i + 2]))
|
|
1157
|
+
skin[p] = 1;
|
|
1158
|
+
}
|
|
1159
|
+
const { label, boxes } = components(skin, cw, ch);
|
|
1160
|
+
const rim = boxes.map(
|
|
1161
|
+
(b) => b.x0 === 0 || b.y0 === 0 || b.x1 === cw - 1 || b.y1 === ch - 1
|
|
1162
|
+
);
|
|
1163
|
+
for (let p = 0; p < cw * ch; p++) {
|
|
1164
|
+
if (label[p] >= 0 && rim[label[p]]) crop[p * 4 + 3] = 0;
|
|
1165
|
+
}
|
|
1166
|
+
const box = drawingBox(crop, cw, ch);
|
|
1167
|
+
if (box === null) throw empty;
|
|
1168
|
+
const sum = [0, 0, 0];
|
|
1169
|
+
const all = [0, 0, 0];
|
|
1170
|
+
let dark = 0;
|
|
1171
|
+
let count = 0;
|
|
1172
|
+
for (let y = box.y; y < box.y + box.h; y++) {
|
|
1173
|
+
for (let x = box.x; x < box.x + box.w; x++) {
|
|
1174
|
+
const i = (y * cw + x) * 4;
|
|
1175
|
+
if (crop[i + 3] < import_editor6.ALPHA_OPAQUE) continue;
|
|
1176
|
+
count++;
|
|
1177
|
+
for (let c = 0; c < 3; c++) all[c] += crop[i + c];
|
|
1178
|
+
if (luma(crop, i) < CAVITY_LUMA) {
|
|
1179
|
+
dark++;
|
|
1180
|
+
for (let c = 0; c < 3; c++) sum[c] += crop[i + c];
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
if (count === 0) throw empty;
|
|
1185
|
+
const [from, over] = dark > 0 ? [sum, dark] : [all, count];
|
|
1186
|
+
const cavity = from.map((v) => Math.round(v / over));
|
|
1187
|
+
return { png: await cropToBuffer(crop, cw, ch, box), cavity };
|
|
1188
|
+
}
|
|
1189
|
+
var rawOf = async (png) => (0, import_sharp2.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
1190
|
+
var encode = (rgba, w, h) => (0, import_sharp2.default)(rgba, { raw: { width: w, height: h, channels: 4 } }).png().toBuffer();
|
|
1191
|
+
function enclosedHole(frame, w, h) {
|
|
1192
|
+
const n = w * h;
|
|
1193
|
+
const alpha = (p) => frame[p * 4 + 3];
|
|
1194
|
+
const outside = new Uint8Array(n);
|
|
1195
|
+
const stack = new Int32Array(n);
|
|
1196
|
+
let depth = 0;
|
|
1197
|
+
const seed = (p) => {
|
|
1198
|
+
if (!outside[p] && alpha(p) < import_editor6.ALPHA_OPAQUE) {
|
|
1199
|
+
outside[p] = 1;
|
|
1200
|
+
stack[depth++] = p;
|
|
1201
|
+
}
|
|
1202
|
+
};
|
|
1203
|
+
for (let x = 0; x < w; x++) {
|
|
1204
|
+
seed(x);
|
|
1205
|
+
seed((h - 1) * w + x);
|
|
1206
|
+
}
|
|
1207
|
+
for (let y = 0; y < h; y++) {
|
|
1208
|
+
seed(y * w);
|
|
1209
|
+
seed(y * w + w - 1);
|
|
1210
|
+
}
|
|
1211
|
+
while (depth > 0) {
|
|
1212
|
+
const p = stack[--depth];
|
|
1213
|
+
const x = p % w;
|
|
1214
|
+
if (x > 0) seed(p - 1);
|
|
1215
|
+
if (x < w - 1) seed(p + 1);
|
|
1216
|
+
if (p >= w) seed(p - w);
|
|
1217
|
+
if (p < n - w) seed(p + w);
|
|
1218
|
+
}
|
|
1219
|
+
const mask = new Uint8Array(n);
|
|
1220
|
+
for (let p = 0; p < n; p++) {
|
|
1221
|
+
if (alpha(p) < import_editor6.ALPHA_OPAQUE && !outside[p]) mask[p] = 1;
|
|
1222
|
+
}
|
|
1223
|
+
const { label, sizes, boxes } = components(mask, w, h);
|
|
1224
|
+
const main2 = largest(sizes);
|
|
1225
|
+
if (main2 < 0) {
|
|
1226
|
+
throw new AutoRigInputError(
|
|
1227
|
+
`${KEYED_SRC}: the outline is not closed round the opening (the key reached the outside, or the line is broken or too thin at this size) \u2014 regenerate with ONE closed, bolder outline`
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
const box = boxes[main2];
|
|
1231
|
+
const holeW = box.x1 - box.x0 + 1;
|
|
1232
|
+
if (holeW < MIN_OPENING_WIDTH * w) {
|
|
1233
|
+
throw new AutoRigInputError(
|
|
1234
|
+
`${KEYED_SRC}: the opening is only ${holeW} px wide of the mouth's ${w} \u2014 too small to fold; regenerate with the mouth open wider, or, if its outline is broken (only a small pocket of the opening was enclosed), with ONE closed, bolder outline`
|
|
1235
|
+
);
|
|
1236
|
+
}
|
|
1237
|
+
const others = sizes.filter(
|
|
1238
|
+
(s, i) => i !== main2 && s >= SECOND_HOLE_FRACTION * sizes[main2]
|
|
1239
|
+
);
|
|
1240
|
+
if (others.length > 0) {
|
|
1241
|
+
throw new AutoRigInputError(
|
|
1242
|
+
`${KEYED_SRC}: the opening is not one connected region (${others.length + 1} holes: teeth or tongue drawn into the green?) \u2014 regenerate with nothing drawn inside the green`
|
|
1243
|
+
);
|
|
1244
|
+
}
|
|
1245
|
+
return { label, main: main2, box };
|
|
1246
|
+
}
|
|
1247
|
+
function measureLips(layers, w, h) {
|
|
1248
|
+
const measurer = (0, import_editor6.createLayerSetMeasurer)({ width: w, height: h });
|
|
1249
|
+
return new Map(
|
|
1250
|
+
Object.entries(layers).map(([role, rgba]) => [
|
|
1251
|
+
role,
|
|
1252
|
+
measurer.add({ role, fileName: `${role}.png`, rgba })
|
|
1253
|
+
])
|
|
1254
|
+
);
|
|
1255
|
+
}
|
|
1256
|
+
function assertFoldContract(layers, w, h) {
|
|
1257
|
+
const byRole = /* @__PURE__ */ new Map();
|
|
1258
|
+
for (const [role, layer] of measureLips(layers, w, h)) {
|
|
1259
|
+
if (layer === null && role === "lip_lower") {
|
|
1260
|
+
throw new AutoRigInputError(
|
|
1261
|
+
`${KEYED_SRC}: no lip_lower after the split \u2014 there is no skin under the opening; draw the lower lip under the outline`
|
|
1262
|
+
);
|
|
1263
|
+
}
|
|
1264
|
+
byRole.set(role, layer);
|
|
1265
|
+
}
|
|
1266
|
+
const opening = (0, import_editor6.mouthOpening)(byRole);
|
|
1267
|
+
const runs = (0, import_editor6.columnRuns)(byRole.get("mouth_inner"));
|
|
1268
|
+
for (let col = opening.x0; col <= opening.x1; col++) {
|
|
1269
|
+
const c = opening.at(col);
|
|
1270
|
+
const why = !runs.has(col) ? "has no interior run" : c.Tu > c.T ? `has a gap between the line and the interior (Tu ${c.Tu} > T ${c.T})` : c.T > c.lineTop || c.lineH <= 0 ? `has no line above the interior (T ${c.T}, line top ${c.lineTop})` : c.Bl < c.Bb ? `has a gap between the interior and the skin (Bl ${c.Bl} < Bb ${c.Bb})` : null;
|
|
1271
|
+
if (why !== null) throw new Error(`splitLipSet: column ${col} ${why}`);
|
|
1272
|
+
}
|
|
1273
|
+
return opening;
|
|
1274
|
+
}
|
|
1275
|
+
async function splitLipSet(keyedPng, w, h, interior) {
|
|
1276
|
+
const { data: frame, info } = await rawOf(keyedPng);
|
|
1277
|
+
if (info.width !== w || info.height !== h) {
|
|
1278
|
+
throw new Error(
|
|
1279
|
+
`splitLipSet: the frame is ${info.width}x${info.height}, not ${w}x${h}`
|
|
1280
|
+
);
|
|
1281
|
+
}
|
|
1282
|
+
const n = w * h;
|
|
1283
|
+
const alpha = (p) => frame[p * 4 + 3];
|
|
1284
|
+
const { label, main: main2, box: hb } = enclosedHole(frame, w, h);
|
|
1285
|
+
const holeW = hb.x1 - hb.x0 + 1;
|
|
1286
|
+
const top = new Int32Array(w).fill(-1);
|
|
1287
|
+
const bot = new Int32Array(w).fill(-1);
|
|
1288
|
+
for (let y = 0; y < h; y++) {
|
|
1289
|
+
for (let x = hb.x0; x <= hb.x1; x++) {
|
|
1290
|
+
if (label[y * w + x] !== main2) continue;
|
|
1291
|
+
if (top[x] < 0) top[x] = y;
|
|
1292
|
+
bot[x] = y + 1;
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
const centre = Math.round((hb.x0 + hb.x1) / 2);
|
|
1296
|
+
let stroke = 0;
|
|
1297
|
+
while (top[centre] - 1 - stroke >= 0 && alpha((top[centre] - 1 - stroke) * w + centre) >= import_editor6.ALPHA_OPAQUE)
|
|
1298
|
+
stroke++;
|
|
1299
|
+
const bandCap = BAND_CAP * Math.max(1, stroke);
|
|
1300
|
+
const skinRow = new Int32Array(w).fill(-1);
|
|
1301
|
+
const inM = new Uint8Array(n);
|
|
1302
|
+
for (let x = hb.x0; x <= hb.x1; x++) {
|
|
1303
|
+
let y = bot[x];
|
|
1304
|
+
while (y < h && y - bot[x] < bandCap && alpha(y * w + x) >= import_editor6.ALPHA_OPAQUE && luma(frame, (y * w + x) * 4) < BAND_LUMA)
|
|
1305
|
+
y++;
|
|
1306
|
+
for (let k = top[x]; k < y; k++) inM[k * w + x] = 1;
|
|
1307
|
+
let r = y;
|
|
1308
|
+
while (r < h && alpha(r * w + x) < import_editor6.ALPHA_OPAQUE) r++;
|
|
1309
|
+
if (r < h) {
|
|
1310
|
+
skinRow[x] = r;
|
|
1311
|
+
inM[r * w + x] = 1;
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
const grown = Uint8Array.from(inM);
|
|
1315
|
+
for (let y = 0; y < h; y++) {
|
|
1316
|
+
for (let x = 0; x < w; x++) {
|
|
1317
|
+
const p = y * w + x;
|
|
1318
|
+
if (inM[p] || alpha(p) < import_editor6.ALPHA_OPAQUE) continue;
|
|
1319
|
+
if (top[x] >= 0 && y < top[x]) continue;
|
|
1320
|
+
if (x > 0 && inM[p - 1] || x < w - 1 && inM[p + 1]) grown[p] = 1;
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
const wall = new Uint8Array(w);
|
|
1324
|
+
for (const x of [hb.x0 - 1, hb.x1 + 1]) {
|
|
1325
|
+
if (x < 0 || x >= w) continue;
|
|
1326
|
+
let first = 0;
|
|
1327
|
+
while (first < h && !(grown[first * w + x] && !inM[first * w + x])) first++;
|
|
1328
|
+
if (first > 0 && first < h && alpha((first - 1) * w + x) >= import_editor6.ALPHA_OPAQUE)
|
|
1329
|
+
wall[x] = 1;
|
|
1330
|
+
}
|
|
1331
|
+
const gx = hb.x0 - 1;
|
|
1332
|
+
const gy = hb.y0 - 1;
|
|
1333
|
+
const gw = holeW + 2;
|
|
1334
|
+
const gh = hb.y1 - hb.y0 + 3;
|
|
1335
|
+
const { data: fitted } = await (0, import_sharp2.default)(interior.png).resize(gw, gh, { fit: "fill" }).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
1336
|
+
const hole = (q) => label[q] === main2;
|
|
1337
|
+
const upperHalf = (x, y) => 2 * y < top[x] + bot[x];
|
|
1338
|
+
const faintUpper = (p, x, y) => y < bot[x] && hole(p) && upperHalf(x, y);
|
|
1339
|
+
const besideHole = (p, x, y) => x > 0 && hole(p - 1) || x < w - 1 && hole(p + 1) || y > 0 && hole(p - w) || y < h - 1 && hole(p + w);
|
|
1340
|
+
const upper = Buffer.alloc(n * 4);
|
|
1341
|
+
const lower = Buffer.alloc(n * 4);
|
|
1342
|
+
const inner = Buffer.alloc(n * 4);
|
|
1343
|
+
const tongue = Buffer.alloc(n * 4);
|
|
1344
|
+
const teeth = Buffer.alloc(n * 4);
|
|
1345
|
+
const copy = (to, p) => frame.copy(to, p * 4, p * 4, p * 4 + 4);
|
|
1346
|
+
for (let y = 0; y < h; y++) {
|
|
1347
|
+
for (let x = 0; x < w; x++) {
|
|
1348
|
+
const p = y * w + x;
|
|
1349
|
+
const inOpening = top[x] >= 0;
|
|
1350
|
+
if ((!inOpening || y < top[x] || faintUpper(p, x, y)) && !(wall[x] && grown[p]))
|
|
1351
|
+
copy(upper, p);
|
|
1352
|
+
if (inOpening && skinRow[x] >= 0 && y >= skinRow[x]) copy(lower, p);
|
|
1353
|
+
if (!grown[p]) {
|
|
1354
|
+
const a = alpha(p);
|
|
1355
|
+
if (a >= import_editor6.ALPHA_OPAQUE && a < 255 && besideHole(p, x, y)) {
|
|
1356
|
+
inner.set(interior.cavity, p * 4);
|
|
1357
|
+
inner[p * 4 + 3] = 255 - a;
|
|
1358
|
+
}
|
|
1359
|
+
continue;
|
|
1360
|
+
}
|
|
1361
|
+
const out = [...interior.cavity];
|
|
1362
|
+
const ix = x - gx;
|
|
1363
|
+
const iy = y - gy;
|
|
1364
|
+
if (ix >= 0 && ix < gw && iy >= 0 && iy < gh) {
|
|
1365
|
+
const i = (iy * gw + ix) * 4;
|
|
1366
|
+
const a = fitted[i + 3] / 255;
|
|
1367
|
+
for (let c = 0; c < 3; c++) out[c] += (fitted[i + c] - out[c]) * a;
|
|
1368
|
+
}
|
|
1369
|
+
if ((inM[p] || wall[x]) && !faintUpper(p, x, y)) {
|
|
1370
|
+
const a = alpha(p) / 255;
|
|
1371
|
+
for (let c = 0; c < 3; c++) out[c] += (frame[p * 4 + c] - out[c]) * a;
|
|
1372
|
+
}
|
|
1373
|
+
inner[p * 4] = Math.round(out[0]);
|
|
1374
|
+
inner[p * 4 + 1] = Math.round(out[1]);
|
|
1375
|
+
inner[p * 4 + 2] = Math.round(out[2]);
|
|
1376
|
+
inner[p * 4 + 3] = 255;
|
|
1377
|
+
if (hole(p) && luma(inner, p * 4) >= CAVITY_LUMA) {
|
|
1378
|
+
const to = upperHalf(x, y) ? teeth : tongue;
|
|
1379
|
+
inner.copy(to, p * 4, p * 4, p * 4 + 4);
|
|
1380
|
+
inner.set(interior.cavity, p * 4);
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
const opening = assertFoldContract(
|
|
1385
|
+
{ mouth_inner: inner, lip_lower: lower, lip_upper: upper },
|
|
1386
|
+
w,
|
|
1387
|
+
h
|
|
1388
|
+
);
|
|
1389
|
+
const [innerPng, lowerPng, upperPng, tonguePng, teethPng] = await Promise.all(
|
|
1390
|
+
[inner, lower, upper, tongue, teeth].map((b) => encode(b, w, h))
|
|
1391
|
+
);
|
|
1392
|
+
return {
|
|
1393
|
+
inner: innerPng,
|
|
1394
|
+
lower: lowerPng,
|
|
1395
|
+
upper: upperPng,
|
|
1396
|
+
tongue: tonguePng,
|
|
1397
|
+
teeth: teethPng,
|
|
1398
|
+
opening
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
async function restShiftOf(layers, width, height) {
|
|
1402
|
+
const [mouth_inner, lip_lower, lip_upper] = await Promise.all(
|
|
1403
|
+
[layers.mouth_inner, layers.lip_lower, layers.lip_upper].map(
|
|
1404
|
+
async (png) => (await rawOf(png)).data
|
|
1405
|
+
)
|
|
1406
|
+
);
|
|
1407
|
+
const byRole = /* @__PURE__ */ new Map();
|
|
1408
|
+
for (const [role, layer] of measureLips(
|
|
1409
|
+
{ mouth_inner, lip_lower, lip_upper },
|
|
1410
|
+
width,
|
|
1411
|
+
height
|
|
1412
|
+
)) {
|
|
1413
|
+
if (layer === null) {
|
|
1414
|
+
throw new AutoRigInputError(
|
|
1415
|
+
`layout.mouth_inner places the lip set so that ${role} falls off the canvas (nothing of it is left) \u2014 move it back on the canvas`
|
|
1416
|
+
);
|
|
1417
|
+
}
|
|
1418
|
+
byRole.set(role, layer);
|
|
1419
|
+
}
|
|
1420
|
+
return (0, import_editor6.mouthRestShift)(byRole);
|
|
1421
|
+
}
|
|
1422
|
+
async function closedLips(upper, lower, shift, left, top) {
|
|
1423
|
+
const shut = async (png, role) => {
|
|
1424
|
+
const { data, info } = await rawOf(png);
|
|
1425
|
+
const { width: w, height: h } = info;
|
|
1426
|
+
const out = Buffer.alloc(w * h * 4);
|
|
1427
|
+
for (let x = 0; x < w; x++) {
|
|
1428
|
+
const px2 = (row, c) => row < 0 || row >= h ? 0 : data[(row * w + x) * 4 + c];
|
|
1429
|
+
const landed = [];
|
|
1430
|
+
for (let row = 0; row < h; row++) {
|
|
1431
|
+
const dy = shift(role, left + x, top + row);
|
|
1432
|
+
if (dy !== void 0) landed.push([row, row + 0.5 - dy]);
|
|
1433
|
+
}
|
|
1434
|
+
if (landed.length > 1) {
|
|
1435
|
+
const [a, b] = landed;
|
|
1436
|
+
const [y, z2] = landed.slice(-2);
|
|
1437
|
+
landed.unshift([a[0] - 1, 2 * a[1] - b[1]]);
|
|
1438
|
+
landed.push([z2[0] + 1, 2 * z2[1] - y[1]]);
|
|
1439
|
+
}
|
|
1440
|
+
let i = 0;
|
|
1441
|
+
for (let to = 0; to < h; to++) {
|
|
1442
|
+
const centre = to + 0.5;
|
|
1443
|
+
while (i + 1 < landed.length && landed[i + 1][1] < centre) i++;
|
|
1444
|
+
if (i + 1 >= landed.length || landed[i][1] > centre) continue;
|
|
1445
|
+
const [r0, y0] = landed[i];
|
|
1446
|
+
const [r1, y1] = landed[i + 1];
|
|
1447
|
+
const t = (centre - y0) / (y1 - y0);
|
|
1448
|
+
const a0 = px2(r0, 3);
|
|
1449
|
+
const a1 = px2(r1, 3);
|
|
1450
|
+
const a = (1 - t) * a0 + t * a1;
|
|
1451
|
+
if (a === 0) continue;
|
|
1452
|
+
const o = (to * w + x) * 4;
|
|
1453
|
+
for (let c = 0; c < 3; c++)
|
|
1454
|
+
out[o + c] = Math.round(
|
|
1455
|
+
((1 - t) * a0 * px2(r0, c) + t * a1 * px2(r1, c)) / a
|
|
1456
|
+
);
|
|
1457
|
+
out[o + 3] = Math.round(a);
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
return encode(out, w, h);
|
|
1461
|
+
};
|
|
1462
|
+
const [u, l] = await Promise.all([
|
|
1463
|
+
shut(upper, "lip_upper"),
|
|
1464
|
+
shut(lower, "lip_lower")
|
|
1465
|
+
]);
|
|
1466
|
+
return { upper: u, lower: l };
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
// src/measure-lips.ts
|
|
1470
|
+
var isLipLayerRole = (role) => import_editor7.LIP_ROLES.includes(role) || (0, import_editor7.isLipInsideRole)(role);
|
|
1471
|
+
var MIN_OPENING_ROWS = 8;
|
|
1472
|
+
var MIN_LINE_ROWS = 2;
|
|
1473
|
+
var GREEN_EXCESS = 40;
|
|
1474
|
+
var INTERIOR_GAP_FRACTION = 0.05;
|
|
1475
|
+
var columns = (cols) => `${cols.length} column${cols.length === 1 ? "" : "s"} (first at x=${cols[0]})`;
|
|
1476
|
+
async function lipWarnings(absDir, layers) {
|
|
1477
|
+
const warnings = [];
|
|
1478
|
+
const present = import_editor7.LIP_ROLES.filter((role) => layers[role] !== void 0);
|
|
1479
|
+
const inside = import_editor7.LIP_INSIDE_ROLES.filter((role) => layers[role] !== void 0);
|
|
1480
|
+
if (present.length === 0) {
|
|
1481
|
+
if (inside.length > 0) {
|
|
1482
|
+
warnings.push(
|
|
1483
|
+
`${inside.join("/")}: a lip set's inside layer with no lip set \u2014 auto_rig_from_layers refuses it (it is cut from the interior and clipped to it). Recompose from mouth_keyed.png + mouth_interior.png, or remove it.`
|
|
1484
|
+
);
|
|
1485
|
+
}
|
|
1486
|
+
return { warnings };
|
|
1487
|
+
}
|
|
1488
|
+
const legacy = ["mouth", "mouth_open"].filter(
|
|
1489
|
+
(role) => layers[role] !== void 0
|
|
1490
|
+
);
|
|
1491
|
+
if (legacy.length > 0) {
|
|
1492
|
+
warnings.push(
|
|
1493
|
+
`${present.join("/")}: the lip set cannot be mixed with ${legacy.join("/")} \u2014 auto_rig_from_layers refuses it. Remove one route: compose again with only mouth_keyed.png + mouth_interior.png, or without them.`
|
|
1494
|
+
);
|
|
1495
|
+
}
|
|
1496
|
+
if (present.length < import_editor7.LIP_ROLES.length) {
|
|
1497
|
+
const missing = import_editor7.LIP_ROLES.filter((role) => layers[role] === void 0);
|
|
1498
|
+
warnings.push(
|
|
1499
|
+
`${present.join("/")}: partial lip set, missing ${missing.join("/")} \u2014 auto_rig_from_layers refuses it. Compose mouth_keyed.png + mouth_interior.png together, which cuts all three.`
|
|
1500
|
+
);
|
|
1501
|
+
return { warnings };
|
|
1502
|
+
}
|
|
1503
|
+
const { mouth_inner: inner, lip_upper: upper } = layers;
|
|
1504
|
+
for (const role of ["lip_lower", "lip_upper", ...inside]) {
|
|
1505
|
+
const stats = layers[role];
|
|
1506
|
+
if (stats.canvasW !== inner.canvasW || stats.canvasH !== inner.canvasH) {
|
|
1507
|
+
warnings.push(
|
|
1508
|
+
`${role}: its canvas ${stats.canvasW}x${stats.canvasH} differs from mouth_inner's ${inner.canvasW}x${inner.canvasH} \u2014 auto_rig_from_layers refuses layers of different sizes; recompose them together.`
|
|
1509
|
+
);
|
|
1510
|
+
return { warnings };
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
const box = (m) => ({
|
|
1514
|
+
x0: m.bboxCx - m.w / 2,
|
|
1515
|
+
x1: m.bboxCx + m.w / 2,
|
|
1516
|
+
y0: m.bboxCy - m.h / 2,
|
|
1517
|
+
y1: m.bboxCy + m.h / 2
|
|
1518
|
+
});
|
|
1519
|
+
const cavity = box(inner);
|
|
1520
|
+
for (const role of inside) {
|
|
1521
|
+
const b = box(layers[role]);
|
|
1522
|
+
if (b.x0 < cavity.x0 || b.x1 > cavity.x1 || b.y0 < cavity.y0 || b.y1 > cavity.y1) {
|
|
1523
|
+
warnings.push(
|
|
1524
|
+
`${role}: its box leaves mouth_inner's \u2014 the cavity clips it away there. Recompose from mouth_keyed.png + mouth_interior.png (free).`
|
|
1525
|
+
);
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
const measurer = (0, import_editor7.createLayerSetMeasurer)({
|
|
1529
|
+
width: inner.canvasW,
|
|
1530
|
+
height: inner.canvasH
|
|
1531
|
+
});
|
|
1532
|
+
const set = /* @__PURE__ */ new Map();
|
|
1533
|
+
const green = [];
|
|
1534
|
+
for (const role of import_editor7.LIP_ROLES) {
|
|
1535
|
+
const fileName = `${role}.png`;
|
|
1536
|
+
const { rgba } = await decodePng(import_node_path4.default.join(absDir, fileName));
|
|
1537
|
+
set.set(role, measurer.add({ role, fileName, rgba }));
|
|
1538
|
+
for (let i = 0; i < rgba.length; i += 4) {
|
|
1539
|
+
if (rgba[i + 3] >= import_editor7.ALPHA_OPAQUE && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > GREEN_EXCESS) {
|
|
1540
|
+
green.push(role);
|
|
1541
|
+
break;
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
let opening;
|
|
1546
|
+
try {
|
|
1547
|
+
opening = (0, import_editor7.mouthOpening)(set);
|
|
1548
|
+
} catch (err) {
|
|
1549
|
+
if (err instanceof import_editor7.LayerGeometryError) {
|
|
1550
|
+
warnings.push(err.message);
|
|
1551
|
+
return { warnings };
|
|
1552
|
+
}
|
|
1553
|
+
throw err;
|
|
1554
|
+
}
|
|
1555
|
+
const innerRuns = (0, import_editor7.columnRuns)(set.get("mouth_inner"));
|
|
1556
|
+
const noInterior = [];
|
|
1557
|
+
const gap = [];
|
|
1558
|
+
const noLine = [];
|
|
1559
|
+
const skinGap = [];
|
|
1560
|
+
let area = 0;
|
|
1561
|
+
let hollow = 0;
|
|
1562
|
+
for (let x = opening.x0; x <= opening.x1; x++) {
|
|
1563
|
+
const runs = innerRuns.get(x);
|
|
1564
|
+
if (runs === void 0) {
|
|
1565
|
+
noInterior.push(x);
|
|
1566
|
+
continue;
|
|
1567
|
+
}
|
|
1568
|
+
const span = runs[runs.length - 1][1] - runs[0][0];
|
|
1569
|
+
area += span;
|
|
1570
|
+
hollow += span - runs.reduce((n, r) => n + r[1] - r[0], 0);
|
|
1571
|
+
const c = opening.at(x);
|
|
1572
|
+
if (c.lineH <= 0) noLine.push(x);
|
|
1573
|
+
else if (c.Tu > c.T) gap.push(x);
|
|
1574
|
+
if (c.Bl < c.Bb) skinGap.push(x);
|
|
1575
|
+
}
|
|
1576
|
+
const recompose = (file, ask) => `Recompose from mouth_keyed.png + mouth_interior.png (free); if it persists, regenerate ${file} ${ask}. Billed.`;
|
|
1577
|
+
const regenKeyed = recompose(
|
|
1578
|
+
"mouth_keyed.png",
|
|
1579
|
+
"with a closed outline and solid lips under it"
|
|
1580
|
+
);
|
|
1581
|
+
if (noInterior.length > 0) {
|
|
1582
|
+
warnings.push(
|
|
1583
|
+
`mouth_inner: no interior in ${columns(noInterior)} of the opening \u2014 the fold has nothing to scale there. ${recompose("mouth_interior.png", "as one solid cavity")}`
|
|
1584
|
+
);
|
|
1585
|
+
}
|
|
1586
|
+
if (gap.length > 0) {
|
|
1587
|
+
warnings.push(
|
|
1588
|
+
`lip_upper: a gap between the line and the interior in ${columns(gap)} \u2014 the face shows through it at rest (the interior's top must reach the line's ink). ${regenKeyed}`
|
|
1589
|
+
);
|
|
1590
|
+
}
|
|
1591
|
+
if (noLine.length > 0) {
|
|
1592
|
+
warnings.push(
|
|
1593
|
+
`lip_upper: no line above the interior in ${columns(noLine)} \u2014 nothing closes the mouth there. ${regenKeyed}`
|
|
1594
|
+
);
|
|
1595
|
+
}
|
|
1596
|
+
if (skinGap.length > 0) {
|
|
1597
|
+
warnings.push(
|
|
1598
|
+
`lip_lower: a gap between the interior and the skin in ${columns(skinGap)} \u2014 the face shows through it once the mouth opens (the skin must reach the interior's bottom). ${regenKeyed}`
|
|
1599
|
+
);
|
|
1600
|
+
}
|
|
1601
|
+
const width = opening.x1 - opening.x0 + 1;
|
|
1602
|
+
const centre = opening.at(opening.centre);
|
|
1603
|
+
if (width < MIN_OPENING_WIDTH * upper.w) {
|
|
1604
|
+
warnings.push(
|
|
1605
|
+
`mouth_inner: the opening is ${width} px wide, ${Math.round(100 * width / upper.w)}% of lip_upper's ${upper.w} px (under ${Math.round(100 * MIN_OPENING_WIDTH)}%) \u2014 too narrow to fold; the slit stays a hairline. Regenerate mouth_keyed.png with the mouth open wider. Billed.`
|
|
1606
|
+
);
|
|
1607
|
+
}
|
|
1608
|
+
if (centre.H < MIN_OPENING_ROWS) {
|
|
1609
|
+
const w = Math.ceil(upper.w * MIN_OPENING_ROWS / centre.H);
|
|
1610
|
+
const retune = w <= inner.canvasW ? w : null;
|
|
1611
|
+
warnings.push(
|
|
1612
|
+
`mouth_inner: the opening is ${centre.H} px tall at its centre (under ${MIN_OPENING_ROWS}) \u2014 too small to fold; the slit stays shut until MouthOpen is nearly 1. ` + (retune === null ? "" : `If the mouth is smaller than the reference's, set layout.mouth_inner.w to ${retune} (free; the whole set scales with it, so scale layout.mouth_inner.h too if it is set). Otherwise `) + `${retune === null ? "R" : "r"}egenerate mouth_keyed.png with the mouth open taller. Billed.`
|
|
1613
|
+
);
|
|
1614
|
+
}
|
|
1615
|
+
if (opening.w < MIN_LINE_ROWS) {
|
|
1616
|
+
warnings.push(
|
|
1617
|
+
`lip_upper: the upper line is ${opening.w} px at the opening's centre (under ${MIN_LINE_ROWS}) \u2014 a hairline closes to nothing. Regenerate mouth_keyed.png with a bolder upper line, never thinner than the reference's mouth line. Billed.`
|
|
1618
|
+
);
|
|
1619
|
+
}
|
|
1620
|
+
if (green.length > 0) {
|
|
1621
|
+
warnings.push(
|
|
1622
|
+
`${green.join("/")}: opaque green left (key green, g exceeds r and b by over ${GREEN_EXCESS}) \u2014 it shows as a green fringe on the lips. Regenerate mouth_keyed.png with the green only inside the opening, or mouth_interior.png without green in it. Billed.`
|
|
1623
|
+
);
|
|
1624
|
+
}
|
|
1625
|
+
if (area > 0 && hollow > INTERIOR_GAP_FRACTION * area) {
|
|
1626
|
+
warnings.push(
|
|
1627
|
+
`mouth_inner: ${Math.round(100 * hollow / area)}% of the opening is transparent inside the interior's own span (over ${Math.round(100 * INTERIOR_GAP_FRACTION)}%) \u2014 the face shows through it. Regenerate mouth_interior.png as one solid cavity. Billed.`
|
|
1628
|
+
);
|
|
1629
|
+
}
|
|
1630
|
+
return {
|
|
1631
|
+
warnings,
|
|
1632
|
+
lips: {
|
|
1633
|
+
opening: { width, height: centre.H, line: opening.w },
|
|
1634
|
+
deadZone: centre.overlap / (centre.H + centre.overlap)
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
// src/measure-turn.ts
|
|
1640
|
+
var import_node_path5 = __toESM(require("path"));
|
|
1641
|
+
var import_editor8 = require("@ikijs/editor");
|
|
1642
|
+
var import_editor9 = require("@ikijs/editor");
|
|
806
1643
|
var DEFAULT_IRIS = { hueMin: 230, hueMax: 300, satMin: 0.22 };
|
|
807
1644
|
var IRIS_V_MIN = 0.18;
|
|
808
1645
|
var IRIS_V_MAX = 0.95;
|
|
@@ -839,7 +1676,7 @@ function rgbToHsv(r, g, b) {
|
|
|
839
1676
|
}
|
|
840
1677
|
return [h, max === 0 ? 0 : d / max, max];
|
|
841
1678
|
}
|
|
842
|
-
function
|
|
1679
|
+
function dilate2(mask, width, height, r) {
|
|
843
1680
|
const out = new Uint8Array(width * height);
|
|
844
1681
|
for (let y = 0; y < height; y++) {
|
|
845
1682
|
for (let x = 0; x < width; x++) {
|
|
@@ -878,9 +1715,9 @@ function erode(mask, width, height, r) {
|
|
|
878
1715
|
return out;
|
|
879
1716
|
}
|
|
880
1717
|
function closeMask(mask, width, height, r) {
|
|
881
|
-
return erode(
|
|
1718
|
+
return erode(dilate2(mask, width, height, r), width, height, r);
|
|
882
1719
|
}
|
|
883
|
-
function
|
|
1720
|
+
function components2(mask, width, height, minArea) {
|
|
884
1721
|
const seen = new Uint8Array(width * height);
|
|
885
1722
|
const out = [];
|
|
886
1723
|
for (let i = 0; i < width * height; i++) {
|
|
@@ -952,7 +1789,7 @@ async function measureTurnImage(filePath, iris) {
|
|
|
952
1789
|
let transparent = false;
|
|
953
1790
|
if (hasAlpha) {
|
|
954
1791
|
for (let i = 0; i < n; i++) {
|
|
955
|
-
if (rgba[i * 4 + 3] <
|
|
1792
|
+
if (rgba[i * 4 + 3] < import_editor8.ALPHA_OPAQUE) {
|
|
956
1793
|
transparent = true;
|
|
957
1794
|
break;
|
|
958
1795
|
}
|
|
@@ -963,7 +1800,7 @@ async function measureTurnImage(filePath, iris) {
|
|
|
963
1800
|
const fg = new Uint8Array(n);
|
|
964
1801
|
const value = new Float32Array(n);
|
|
965
1802
|
for (let i = 0; i < n; i++) {
|
|
966
|
-
if (rgba[i * 4 + 3] <
|
|
1803
|
+
if (rgba[i * 4 + 3] < import_editor8.ALPHA_OPAQUE) continue;
|
|
967
1804
|
const [hue, s, v] = rgbToHsv(rgba[i * 4], rgba[i * 4 + 1], rgba[i * 4 + 2]);
|
|
968
1805
|
if (maskMode === "alpha") {
|
|
969
1806
|
fg[i] = 1;
|
|
@@ -999,7 +1836,7 @@ async function measureTurnImage(filePath, iris) {
|
|
|
999
1836
|
}
|
|
1000
1837
|
return count ? total / count : 0;
|
|
1001
1838
|
};
|
|
1002
|
-
const candidates =
|
|
1839
|
+
const candidates = components2(
|
|
1003
1840
|
closeMask(irisMask, width, height, closeRadius),
|
|
1004
1841
|
width,
|
|
1005
1842
|
height,
|
|
@@ -1029,12 +1866,12 @@ async function measureTurnImage(filePath, iris) {
|
|
|
1029
1866
|
}
|
|
1030
1867
|
const [irisL, irisR] = best.pair;
|
|
1031
1868
|
const eyeRow = Math.round((irisL.cy + irisR.cy) / 2);
|
|
1032
|
-
const { left, right } = (0,
|
|
1869
|
+
const { left, right } = (0, import_editor8.foregroundSpan)(
|
|
1033
1870
|
fg,
|
|
1034
1871
|
width,
|
|
1035
1872
|
height,
|
|
1036
|
-
eyeRow -
|
|
1037
|
-
eyeRow +
|
|
1873
|
+
eyeRow - import_editor8.HEAD_BAND,
|
|
1874
|
+
eyeRow + import_editor8.HEAD_BAND
|
|
1038
1875
|
);
|
|
1039
1876
|
if (right <= left) {
|
|
1040
1877
|
throw new AutoRigInputError(
|
|
@@ -1058,7 +1895,7 @@ async function measureTurnImage(filePath, iris) {
|
|
|
1058
1895
|
left,
|
|
1059
1896
|
right,
|
|
1060
1897
|
cx: (left + right) / 2,
|
|
1061
|
-
half: (0,
|
|
1898
|
+
half: (0, import_editor8.headHalfOf)({ left, right })
|
|
1062
1899
|
},
|
|
1063
1900
|
pairCx: (irisL.cx + irisR.cx) / 2,
|
|
1064
1901
|
eyeGap: irisR.cx - irisL.cx
|
|
@@ -1073,9 +1910,9 @@ function overlaySvg(m) {
|
|
|
1073
1910
|
return `<svg width="${m.width}" height="${m.height}">` + box(m.irisL, "#ff0000") + box(m.irisR, "#00c000") + tick(m.head.left, 40, "#0000ff") + tick(m.head.right, 40, "#0000ff") + tick(m.head.cx, 60, "#ff8800") + tick(m.pairCx, 60, "#ff00ff") + "</svg>";
|
|
1074
1911
|
}
|
|
1075
1912
|
async function writeOverlay(debugDir, label, m) {
|
|
1076
|
-
const outPath =
|
|
1913
|
+
const outPath = import_node_path5.default.join(
|
|
1077
1914
|
debugDir,
|
|
1078
|
-
`${label}-${
|
|
1915
|
+
`${label}-${import_node_path5.default.basename(m.file, ".png")}.debug.png`
|
|
1079
1916
|
);
|
|
1080
1917
|
writeFileAtomic(outPath, await encodeOverlayPng(m.file, overlaySvg(m)));
|
|
1081
1918
|
return outPath;
|
|
@@ -1249,7 +2086,7 @@ function noseSpeckWarning({ core, part }, source) {
|
|
|
1249
2086
|
`the layer's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} crop`,
|
|
1250
2087
|
`auto_rig_from_layers turns and tilts the nose about its whole crop instead`
|
|
1251
2088
|
];
|
|
1252
|
-
return `nose: ${found} \u2014 under ${
|
|
2089
|
+
return `nose: ${found} \u2014 under ${import_editor9.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.`;
|
|
1253
2090
|
}
|
|
1254
2091
|
async function lashOffSclera(eyePath, lashPath) {
|
|
1255
2092
|
const eye = await decodePng(eyePath);
|
|
@@ -1279,8 +2116,8 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1279
2116
|
const layers = {};
|
|
1280
2117
|
const empty = [];
|
|
1281
2118
|
for (const f of files) {
|
|
1282
|
-
const role =
|
|
1283
|
-
const m = await layerStats(
|
|
2119
|
+
const role = import_node_path6.default.basename(f, ".png");
|
|
2120
|
+
const m = await layerStats(import_node_path6.default.join(absDir, f));
|
|
1284
2121
|
if (!m) {
|
|
1285
2122
|
empty.push(role);
|
|
1286
2123
|
continue;
|
|
@@ -1289,6 +2126,7 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1289
2126
|
}
|
|
1290
2127
|
const warnings = [];
|
|
1291
2128
|
for (const [role, m] of Object.entries(layers)) {
|
|
2129
|
+
if (isLipLayerRole(role)) continue;
|
|
1292
2130
|
const edges = [
|
|
1293
2131
|
["top", m.edgeTop, m.w, m.marginTop],
|
|
1294
2132
|
["left", m.edgeLeft, m.h, m.marginLeft],
|
|
@@ -1318,7 +2156,7 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1318
2156
|
}
|
|
1319
2157
|
}
|
|
1320
2158
|
for (const [role, m] of Object.entries(layers)) {
|
|
1321
|
-
if (role === "body") continue;
|
|
2159
|
+
if (role === "body" || isLipLayerRole(role)) continue;
|
|
1322
2160
|
if (m.flatCutRun > FLAT_CUT_MAX_FRAC * m.w && m.flatCutRun >= FLAT_CUT_MIN_PX) {
|
|
1323
2161
|
warnings.push(
|
|
1324
2162
|
`${role}: ${m.flatCutRun}px of straight flat edge at y=${m.flatCutY} (${pct(m.flatCutRun / m.w)} of its width) \u2014 the source art is cut through there. ` + (isArm(role) ? `It hides at rest and opens into a seam once the arm raises. ` : `It hides while the head faces front and opens into a seam on turn. `) + `Regenerate this part with the whole subject inside the frame.`
|
|
@@ -1327,6 +2165,8 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1327
2165
|
}
|
|
1328
2166
|
warnings.push(...await armWarnings(absDir, layers));
|
|
1329
2167
|
warnings.push(...await forearmPoseWarnings(absDir, layers));
|
|
2168
|
+
const lip = await lipWarnings(absDir, layers);
|
|
2169
|
+
warnings.push(...lip.warnings);
|
|
1330
2170
|
for (const side of ["L", "R"]) {
|
|
1331
2171
|
const eye = layers[`eye_${side}`];
|
|
1332
2172
|
const iris = layers[`iris_${side}`];
|
|
@@ -1355,8 +2195,8 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1355
2195
|
}
|
|
1356
2196
|
if (lash) {
|
|
1357
2197
|
const { opaque, off } = await lashOffSclera(
|
|
1358
|
-
|
|
1359
|
-
|
|
2198
|
+
import_node_path6.default.join(absDir, `eye_${side}.png`),
|
|
2199
|
+
import_node_path6.default.join(absDir, `lash_${side}.png`)
|
|
1360
2200
|
);
|
|
1361
2201
|
const dTop = lash.marginTop - eye.marginTop;
|
|
1362
2202
|
const faults = [
|
|
@@ -1382,11 +2222,11 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1382
2222
|
if (noseSpeck !== void 0) {
|
|
1383
2223
|
warnings.push(noseSpeckWarning(noseSpeck, "compose"));
|
|
1384
2224
|
} else if (layers.nose !== void 0) {
|
|
1385
|
-
const nose = await decodePng(
|
|
1386
|
-
const core = (0,
|
|
2225
|
+
const nose = await decodePng(import_node_path6.default.join(absDir, "nose.png"));
|
|
2226
|
+
const core = (0, import_editor9.denseCoreOf)(nose.rgba, nose.width, nose.height);
|
|
1387
2227
|
if (core !== null) {
|
|
1388
2228
|
const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
|
|
1389
|
-
if ((0,
|
|
2229
|
+
if ((0, import_editor9.isSpeckCore)(core, crop))
|
|
1390
2230
|
warnings.push(noseSpeckWarning({ core, part: crop }, "layer"));
|
|
1391
2231
|
}
|
|
1392
2232
|
}
|
|
@@ -1400,7 +2240,12 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1400
2240
|
]) {
|
|
1401
2241
|
if (layers[role] === void 0) warnings.push(`${role}: missing \u2014 ${why}.`);
|
|
1402
2242
|
}
|
|
1403
|
-
return {
|
|
2243
|
+
return {
|
|
2244
|
+
layers,
|
|
2245
|
+
empty,
|
|
2246
|
+
warnings,
|
|
2247
|
+
...lip.lips === void 0 ? {} : { lips: lip.lips }
|
|
2248
|
+
};
|
|
1404
2249
|
}
|
|
1405
2250
|
async function measureLayers(input) {
|
|
1406
2251
|
try {
|
|
@@ -1434,6 +2279,13 @@ function formatMeasureReport(result) {
|
|
|
1434
2279
|
`${role.padEnd(13)} ${`${m.w}x${m.h}`.padEnd(11)} ${`${m.bboxCx.toFixed(0)},${m.bboxCy.toFixed(0)}`.padEnd(14)} ${`${m.massCx.toFixed(0)},${m.massCy.toFixed(0)}`.padEnd(13)} ${m.marginTop}/${m.marginBottom}/${m.marginLeft}/${m.marginRight}`
|
|
1435
2280
|
);
|
|
1436
2281
|
}
|
|
2282
|
+
if (result.lips !== void 0) {
|
|
2283
|
+
const { opening, deadZone } = result.lips;
|
|
2284
|
+
lines.push(
|
|
2285
|
+
"",
|
|
2286
|
+
`lips: opening ${opening.width} px wide, ${opening.height} px tall at its centre under a ${opening.line} px line \u2014 no slit below MouthOpen ${deadZone.toFixed(2)}`
|
|
2287
|
+
);
|
|
2288
|
+
}
|
|
1437
2289
|
lines.push("", "# checks", "");
|
|
1438
2290
|
if (result.warnings.length === 0) {
|
|
1439
2291
|
lines.push("all geometry checks passed");
|
|
@@ -1444,13 +2296,13 @@ function formatMeasureReport(result) {
|
|
|
1444
2296
|
}
|
|
1445
2297
|
|
|
1446
2298
|
// src/compose-arms.ts
|
|
1447
|
-
var
|
|
1448
|
-
var
|
|
2299
|
+
var import_sharp3 = __toESM(require("sharp"));
|
|
2300
|
+
var import_editor10 = require("@ikijs/editor");
|
|
1449
2301
|
var ARM_WIDTH = 0.4;
|
|
1450
2302
|
var SHOULDER_DROP = 0.12;
|
|
1451
2303
|
async function armPlacement(role, cfg, part, body) {
|
|
1452
|
-
const { data } = await (0,
|
|
1453
|
-
const layer = (0,
|
|
2304
|
+
const { data } = await (0, import_sharp3.default)(part.buf).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
2305
|
+
const layer = (0, import_editor10.createLayerSetMeasurer)({ width: part.w, height: part.h }).add({
|
|
1454
2306
|
role,
|
|
1455
2307
|
fileName: "arm.png",
|
|
1456
2308
|
rgba: data
|
|
@@ -1462,9 +2314,9 @@ async function armPlacement(role, cfg, part, body) {
|
|
|
1462
2314
|
}
|
|
1463
2315
|
let g;
|
|
1464
2316
|
try {
|
|
1465
|
-
g = (0,
|
|
2317
|
+
g = (0, import_editor10.armGeometry)(layer, role === "arm_R" ? Infinity : -Infinity);
|
|
1466
2318
|
} catch (err) {
|
|
1467
|
-
if (err instanceof
|
|
2319
|
+
if (err instanceof import_editor10.LayerGeometryError) {
|
|
1468
2320
|
throw new AutoRigInputError(`layout.${role}: ${err.message}`);
|
|
1469
2321
|
}
|
|
1470
2322
|
throw err;
|
|
@@ -1490,8 +2342,8 @@ async function armPlacement(role, cfg, part, body) {
|
|
|
1490
2342
|
};
|
|
1491
2343
|
}
|
|
1492
2344
|
async function poseGeometryOf(role, png, size, when) {
|
|
1493
|
-
const { data } = await (0,
|
|
1494
|
-
const layer = (0,
|
|
2345
|
+
const { data } = await (0, import_sharp3.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
2346
|
+
const layer = (0, import_editor10.createLayerSetMeasurer)({
|
|
1495
2347
|
width: size.w,
|
|
1496
2348
|
height: size.h
|
|
1497
2349
|
}).add({ role, fileName: "forearm_pose.png", rgba: data });
|
|
@@ -1500,7 +2352,7 @@ async function poseGeometryOf(role, png, size, when) {
|
|
|
1500
2352
|
`layout.${role}: forearm_pose.png is empty after alpha threshold${when}`
|
|
1501
2353
|
);
|
|
1502
2354
|
}
|
|
1503
|
-
return (0,
|
|
2355
|
+
return (0, import_editor10.forearmPoseGeometry)(layer);
|
|
1504
2356
|
}
|
|
1505
2357
|
async function forearmPoseWidth(role, trimmed, elbowRun) {
|
|
1506
2358
|
const g = await poseGeometryOf(role, trimmed.data, trimmed, "");
|
|
@@ -1530,8 +2382,6 @@ var IRIS_W = 50;
|
|
|
1530
2382
|
var EYEWHITE_SRC = "eyewhite.png";
|
|
1531
2383
|
var EYE_LASH_LUMA = 120;
|
|
1532
2384
|
var LASH_KEEP_FRACTION = 0.5;
|
|
1533
|
-
var TRIM_THRESHOLD = 12;
|
|
1534
|
-
var STRAY_SPECK_FRACTION = 0.01;
|
|
1535
2385
|
var NOSE_TIP_AT = 0.66;
|
|
1536
2386
|
var DEFAULT_LAYOUT = {
|
|
1537
2387
|
// Back hair and body sit behind the face. Both are OPTIONAL: a parts dir
|
|
@@ -1582,6 +2432,19 @@ var DEFAULT_LAYOUT = {
|
|
|
1582
2432
|
w: 76,
|
|
1583
2433
|
optional: true
|
|
1584
2434
|
},
|
|
2435
|
+
// The lip set's ONE frame, mouth_open's place: the keyed mouth is split into
|
|
2436
|
+
// mouth_inner / lip_lower / lip_upper, the interior's light paint into
|
|
2437
|
+
// mouth_tongue / mouth_teeth, and all of them land here, so a retune moves
|
|
2438
|
+
// them together. The other four have no key of their own (LIP_FRAME).
|
|
2439
|
+
// OPTIONAL and opt-in: with mouth_keyed.png + mouth_interior.png it stands
|
|
2440
|
+
// in for mouth and mouth_open.
|
|
2441
|
+
mouth_inner: {
|
|
2442
|
+
src: KEYED_SRC,
|
|
2443
|
+
cx: 550,
|
|
2444
|
+
cy: 596,
|
|
2445
|
+
w: 76,
|
|
2446
|
+
optional: true
|
|
2447
|
+
},
|
|
1585
2448
|
// eye_* (sclera) and lash_* share the eyewhite's cropped frame via noTrim (so
|
|
1586
2449
|
// they are NOT re-bboxed independently): the upper lash stays anchored ABOVE
|
|
1587
2450
|
// the sclera center, so on blink it folds DOWN over the eye like the sample
|
|
@@ -1628,6 +2491,11 @@ var ORDER = [
|
|
|
1628
2491
|
"nose",
|
|
1629
2492
|
"mouth",
|
|
1630
2493
|
"mouth_open",
|
|
2494
|
+
"mouth_inner",
|
|
2495
|
+
"mouth_tongue",
|
|
2496
|
+
"mouth_teeth",
|
|
2497
|
+
"lip_lower",
|
|
2498
|
+
"lip_upper",
|
|
1631
2499
|
"eye_L",
|
|
1632
2500
|
"eye_R",
|
|
1633
2501
|
"iris_L",
|
|
@@ -1646,13 +2514,15 @@ var PART_FILES = [
|
|
|
1646
2514
|
...new Set(
|
|
1647
2515
|
Object.values(DEFAULT_LAYOUT).map((cfg) => cfg.src).filter((src) => !src.startsWith("eyewhite_"))
|
|
1648
2516
|
),
|
|
1649
|
-
EYEWHITE_SRC
|
|
2517
|
+
EYEWHITE_SRC,
|
|
2518
|
+
INTERIOR_SRC
|
|
1650
2519
|
];
|
|
1651
2520
|
var FACE_FEATURES = [
|
|
1652
2521
|
"blush_L",
|
|
1653
2522
|
"blush_R",
|
|
1654
2523
|
"mouth",
|
|
1655
2524
|
"mouth_open",
|
|
2525
|
+
"mouth_inner",
|
|
1656
2526
|
"eye_L",
|
|
1657
2527
|
"eye_R",
|
|
1658
2528
|
"iris_L",
|
|
@@ -1756,20 +2626,20 @@ function keyWhiteToAlpha(rgba) {
|
|
|
1756
2626
|
return keyed;
|
|
1757
2627
|
}
|
|
1758
2628
|
async function coreAndBoundsOf(png) {
|
|
1759
|
-
const { data, info } = await (0,
|
|
2629
|
+
const { data, info } = await (0, import_sharp4.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
1760
2630
|
return {
|
|
1761
|
-
core: (0,
|
|
2631
|
+
core: (0, import_editor9.denseCoreOf)(data, info.width, info.height),
|
|
1762
2632
|
bounds: { x: 0, y: 0, w: info.width, h: info.height }
|
|
1763
2633
|
};
|
|
1764
2634
|
}
|
|
1765
2635
|
async function hasCoverage(png) {
|
|
1766
|
-
const { data, info } = await (0,
|
|
1767
|
-
return (0,
|
|
2636
|
+
const { data, info } = await (0, import_sharp4.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
2637
|
+
return (0, import_editor11.detectAlphaBbox)(data, info.width, info.height) !== null;
|
|
1768
2638
|
}
|
|
1769
2639
|
async function noseSizingOf(png) {
|
|
1770
2640
|
const { core, bounds } = await coreAndBoundsOf(png);
|
|
1771
2641
|
if (core === null) return { box: bounds, whole: true };
|
|
1772
|
-
if ((0,
|
|
2642
|
+
if ((0, import_editor9.isSpeckCore)(core, bounds)) {
|
|
1773
2643
|
return {
|
|
1774
2644
|
box: bounds,
|
|
1775
2645
|
whole: true,
|
|
@@ -1784,24 +2654,24 @@ async function noseSizingOf(png) {
|
|
|
1784
2654
|
async function trimmedPart(role, cfg, partsDir, inMemory, flipSource) {
|
|
1785
2655
|
let img;
|
|
1786
2656
|
if (inMemory !== void 0) {
|
|
1787
|
-
img = (0,
|
|
2657
|
+
img = (0, import_sharp4.default)(inMemory);
|
|
1788
2658
|
} else {
|
|
1789
|
-
const srcPath =
|
|
2659
|
+
const srcPath = import_node_path7.default.join(partsDir, cfg.src);
|
|
1790
2660
|
if (!import_node_fs3.default.existsSync(srcPath)) {
|
|
1791
2661
|
if (cfg.optional) return null;
|
|
1792
2662
|
throw new AutoRigInputError(
|
|
1793
|
-
`missing part source for role "${role}": ${srcPath}`
|
|
2663
|
+
`missing part source for role "${role}": ${srcPath}` + (role === "mouth" ? " \u2014 draw mouth.png (with mouth_open.png), or the lip set's mouth_keyed.png + mouth_interior.png" : "")
|
|
1794
2664
|
);
|
|
1795
2665
|
}
|
|
1796
2666
|
const png = await decodePng(srcPath);
|
|
1797
|
-
img = (0,
|
|
2667
|
+
img = (0, import_sharp4.default)(png.hasAlpha ? png.rgba : keyWhiteToAlpha(png.rgba), {
|
|
1798
2668
|
raw: { width: png.width, height: png.height, channels: 4 }
|
|
1799
2669
|
});
|
|
1800
2670
|
}
|
|
1801
2671
|
if (!cfg.noTrim) {
|
|
1802
2672
|
const kept = await img.trim({ threshold: TRIM_THRESHOLD }).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
1803
2673
|
const { width: keptW, height: keptH } = kept.info;
|
|
1804
|
-
img = (0,
|
|
2674
|
+
img = (0, import_sharp4.default)(kept.data, {
|
|
1805
2675
|
raw: { width: keptW, height: keptH, channels: 4 }
|
|
1806
2676
|
});
|
|
1807
2677
|
const box = boxWithoutStraySpecks(kept.data, keptW, keptH);
|
|
@@ -1827,7 +2697,7 @@ async function sizedPart(role, cfg, trimmed, canvas) {
|
|
|
1827
2697
|
`layout.${role}.${field}: resized part ${width}x${height} exceeds the ${canvasName(canvas)} canvas`
|
|
1828
2698
|
);
|
|
1829
2699
|
}
|
|
1830
|
-
const resized = await (0,
|
|
2700
|
+
const resized = await (0, import_sharp4.default)(trimmed.data).resize(cfg.h === void 0 ? { width } : { width, height, fit: "fill" }).png().toBuffer({ resolveWithObject: true });
|
|
1831
2701
|
return {
|
|
1832
2702
|
buf: resized.data,
|
|
1833
2703
|
w: resized.info.width,
|
|
@@ -1852,7 +2722,7 @@ function placement(role, cfg, w, h, canvas) {
|
|
|
1852
2722
|
assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top, canvas);
|
|
1853
2723
|
return { left, top };
|
|
1854
2724
|
}
|
|
1855
|
-
function nosePlacement(layout, box, w, h, canvas) {
|
|
2725
|
+
function nosePlacement(layout, mouthKey, box, w, h, canvas) {
|
|
1856
2726
|
const { cx, cy } = layout.nose;
|
|
1857
2727
|
const left = Math.round(cx - (box.x + box.w / 2));
|
|
1858
2728
|
let top;
|
|
@@ -1861,12 +2731,12 @@ function nosePlacement(layout, box, w, h, canvas) {
|
|
|
1861
2731
|
} else {
|
|
1862
2732
|
const eyeRow = (layout.eye_L.cy + layout.eye_R.cy) / 2;
|
|
1863
2733
|
const tipRow = Math.round(
|
|
1864
|
-
eyeRow + NOSE_TIP_AT * (layout.
|
|
2734
|
+
eyeRow + NOSE_TIP_AT * (layout[mouthKey].cy - eyeRow)
|
|
1865
2735
|
);
|
|
1866
2736
|
top = tipRow - (box.y + box.h - 1);
|
|
1867
2737
|
}
|
|
1868
2738
|
assertOnCanvas(
|
|
1869
|
-
cy !== void 0 ? "layout.nose.cx/cy" :
|
|
2739
|
+
cy !== void 0 ? "layout.nose.cx/cy" : `layout.nose.cx/cy (cy unset: its tip row comes from layout.eye_L/eye_R/${mouthKey}.cy)`,
|
|
1870
2740
|
w,
|
|
1871
2741
|
h,
|
|
1872
2742
|
left,
|
|
@@ -1876,7 +2746,7 @@ function nosePlacement(layout, box, w, h, canvas) {
|
|
|
1876
2746
|
return { left, top };
|
|
1877
2747
|
}
|
|
1878
2748
|
function blankCanvas(canvas) {
|
|
1879
|
-
return (0,
|
|
2749
|
+
return (0, import_sharp4.default)({
|
|
1880
2750
|
create: {
|
|
1881
2751
|
width: canvas.width,
|
|
1882
2752
|
height: canvas.height,
|
|
@@ -1885,74 +2755,13 @@ function blankCanvas(canvas) {
|
|
|
1885
2755
|
}
|
|
1886
2756
|
});
|
|
1887
2757
|
}
|
|
1888
|
-
function luma(rgba, i) {
|
|
1889
|
-
return 0.299 * rgba[i] + 0.587 * rgba[i + 1] + 0.114 * rgba[i + 2];
|
|
1890
|
-
}
|
|
1891
|
-
function boxWithoutStraySpecks(rgba, W, H) {
|
|
1892
|
-
const n = W * H;
|
|
1893
|
-
let kept = 0;
|
|
1894
|
-
for (let p = 0; p < n; p++) if (rgba[p * 4 + 3] > TRIM_THRESHOLD) kept++;
|
|
1895
|
-
const visited = new Uint8Array(n);
|
|
1896
|
-
let stack = new Int32Array(1024);
|
|
1897
|
-
const drawing = [W, H, -1, -1];
|
|
1898
|
-
const strays = [W, H, -1, -1];
|
|
1899
|
-
let anyOpaque = false;
|
|
1900
|
-
for (let start = 0; start < n; start++) {
|
|
1901
|
-
if (visited[start] || rgba[start * 4 + 3] <= TRIM_THRESHOLD) continue;
|
|
1902
|
-
let setLeft = W;
|
|
1903
|
-
let setTop = H;
|
|
1904
|
-
let setRight = -1;
|
|
1905
|
-
let setBottom = -1;
|
|
1906
|
-
let size = 0;
|
|
1907
|
-
let opaque = false;
|
|
1908
|
-
let depth = 0;
|
|
1909
|
-
visited[start] = 1;
|
|
1910
|
-
stack[depth++] = start;
|
|
1911
|
-
while (depth > 0) {
|
|
1912
|
-
const p = stack[--depth];
|
|
1913
|
-
size++;
|
|
1914
|
-
if (rgba[p * 4 + 3] >= import_editor8.ALPHA_OPAQUE) opaque = true;
|
|
1915
|
-
const px2 = p % W;
|
|
1916
|
-
const py = (p - px2) / W;
|
|
1917
|
-
setLeft = Math.min(setLeft, px2);
|
|
1918
|
-
setTop = Math.min(setTop, py);
|
|
1919
|
-
setRight = Math.max(setRight, px2);
|
|
1920
|
-
setBottom = Math.max(setBottom, py);
|
|
1921
|
-
for (let y = Math.max(0, py - 1); y <= Math.min(H - 1, py + 1); y++) {
|
|
1922
|
-
for (let x = Math.max(0, px2 - 1); x <= Math.min(W - 1, px2 + 1); x++) {
|
|
1923
|
-
const q = y * W + x;
|
|
1924
|
-
if (!visited[q] && rgba[q * 4 + 3] > TRIM_THRESHOLD) {
|
|
1925
|
-
visited[q] = 1;
|
|
1926
|
-
if (depth === stack.length) {
|
|
1927
|
-
const grown = new Int32Array(Math.min(n, stack.length * 2));
|
|
1928
|
-
grown.set(stack);
|
|
1929
|
-
stack = grown;
|
|
1930
|
-
}
|
|
1931
|
-
stack[depth++] = q;
|
|
1932
|
-
}
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
|
-
}
|
|
1936
|
-
anyOpaque ||= opaque;
|
|
1937
|
-
const into = !opaque && size < kept * STRAY_SPECK_FRACTION ? strays : drawing;
|
|
1938
|
-
into[0] = Math.min(into[0], setLeft);
|
|
1939
|
-
into[1] = Math.min(into[1], setTop);
|
|
1940
|
-
into[2] = Math.max(into[2], setRight);
|
|
1941
|
-
into[3] = Math.max(into[3], setBottom);
|
|
1942
|
-
}
|
|
1943
|
-
if (!anyOpaque || strays[2] < 0) return null;
|
|
1944
|
-
const [left, top, right, bottom] = drawing;
|
|
1945
|
-
if (strays[0] >= left && strays[1] >= top && strays[2] <= right && strays[3] <= bottom)
|
|
1946
|
-
return null;
|
|
1947
|
-
return { left, top, width: right - left + 1, height: bottom - top + 1 };
|
|
1948
|
-
}
|
|
1949
2758
|
function detachedAboveWhite(rgba, W, H) {
|
|
1950
2759
|
const n = W * H;
|
|
1951
2760
|
const ink = new Uint8Array(n);
|
|
1952
2761
|
for (let p = 0; p < n; p++) {
|
|
1953
2762
|
const alpha = rgba[p * 4 + 3];
|
|
1954
2763
|
if (alpha > 0 && luma(rgba, p * 4) >= EYE_LASH_LUMA)
|
|
1955
|
-
ink[p] = alpha >=
|
|
2764
|
+
ink[p] = alpha >= import_editor11.ALPHA_OPAQUE ? 2 : 1;
|
|
1956
2765
|
}
|
|
1957
2766
|
const label = new Int32Array(n).fill(-1);
|
|
1958
2767
|
const stack = new Int32Array(n);
|
|
@@ -2032,7 +2841,7 @@ function detachedAboveWhite(rgba, W, H) {
|
|
|
2032
2841
|
return detached;
|
|
2033
2842
|
}
|
|
2034
2843
|
async function prepEyeSplit(partsDir) {
|
|
2035
|
-
const srcPath =
|
|
2844
|
+
const srcPath = import_node_path7.default.join(partsDir, EYEWHITE_SRC);
|
|
2036
2845
|
if (!import_node_fs3.default.existsSync(srcPath)) {
|
|
2037
2846
|
throw new AutoRigInputError(`missing eyewhite source: ${srcPath}`);
|
|
2038
2847
|
}
|
|
@@ -2084,6 +2893,50 @@ async function prepEyeSplit(partsDir) {
|
|
|
2084
2893
|
lashLower: lowerInk ? await cropToBuffer(lashLower, W, H, region) : null
|
|
2085
2894
|
};
|
|
2086
2895
|
}
|
|
2896
|
+
function hasTransparency(rgba) {
|
|
2897
|
+
for (let p = 3; p < rgba.length; p += 4) if (rgba[p] < 255) return true;
|
|
2898
|
+
return false;
|
|
2899
|
+
}
|
|
2900
|
+
async function prepLipSources(partsDir, mirrored) {
|
|
2901
|
+
const has = (name) => import_node_fs3.default.existsSync(import_node_path7.default.join(partsDir, name));
|
|
2902
|
+
const keyed = has(KEYED_SRC);
|
|
2903
|
+
const interior = has(INTERIOR_SRC);
|
|
2904
|
+
if (keyed && !interior) {
|
|
2905
|
+
throw new AutoRigInputError(
|
|
2906
|
+
`${KEYED_SRC} needs ${INTERIOR_SRC}: the composer fits the drawn interior into the keyed opening \u2014 draw it (billed)`
|
|
2907
|
+
);
|
|
2908
|
+
}
|
|
2909
|
+
if (interior && !keyed) {
|
|
2910
|
+
throw new AutoRigInputError(
|
|
2911
|
+
`${INTERIOR_SRC} needs ${KEYED_SRC}: the composer cuts the lip set from the keyed open mouth and fits the interior into its opening \u2014 draw it (billed)`
|
|
2912
|
+
);
|
|
2913
|
+
}
|
|
2914
|
+
if (!keyed) return void 0;
|
|
2915
|
+
const legacy = ["mouth.png", "mouth_open.png"].filter(has);
|
|
2916
|
+
if (legacy.length > 0) {
|
|
2917
|
+
throw new AutoRigInputError(
|
|
2918
|
+
`${KEYED_SRC}/${INTERIOR_SRC} cannot be composed beside mouth.png/mouth_open.png (the lip set replaces the mouth drawings, and auto_rig_from_layers refuses the mix) \u2014 remove ${legacy.join(" and ")}`
|
|
2919
|
+
);
|
|
2920
|
+
}
|
|
2921
|
+
const k = await decodePng(import_node_path7.default.join(partsDir, KEYED_SRC));
|
|
2922
|
+
const keyedRgba = keyGreen(
|
|
2923
|
+
hasTransparency(k.rgba) ? k.rgba : keyWhiteToAlpha(k.rgba),
|
|
2924
|
+
k.width,
|
|
2925
|
+
k.height
|
|
2926
|
+
);
|
|
2927
|
+
const i = await decodePng(import_node_path7.default.join(partsDir, INTERIOR_SRC));
|
|
2928
|
+
const prepared = await prepInterior(
|
|
2929
|
+
hasTransparency(i.rgba) ? i.rgba : keyBorderWhite(i.rgba, i.width, i.height),
|
|
2930
|
+
i.width,
|
|
2931
|
+
i.height
|
|
2932
|
+
);
|
|
2933
|
+
return {
|
|
2934
|
+
keyedPng: await (0, import_sharp4.default)(keyedRgba, {
|
|
2935
|
+
raw: { width: k.width, height: k.height, channels: 4 }
|
|
2936
|
+
}).png().toBuffer(),
|
|
2937
|
+
interior: mirrored.has(INTERIOR_SRC) ? { ...prepared, png: await (0, import_sharp4.default)(prepared.png).flop().png().toBuffer() } : prepared
|
|
2938
|
+
};
|
|
2939
|
+
}
|
|
2087
2940
|
async function composeLayersFromParts(input) {
|
|
2088
2941
|
try {
|
|
2089
2942
|
const outDir = resolveOutputDir(input.outDir);
|
|
@@ -2107,10 +2960,58 @@ async function composeLayersFromParts(input) {
|
|
|
2107
2960
|
if (split.lashLower !== null) {
|
|
2108
2961
|
splitSources.set(LOWER_LASH_SRC, split.lashLower);
|
|
2109
2962
|
}
|
|
2963
|
+
const lips = await prepLipSources(partsDir, mirrored);
|
|
2964
|
+
let lipSplit;
|
|
2110
2965
|
const placed = [];
|
|
2111
2966
|
const skipped = [];
|
|
2112
2967
|
let noseSpeck;
|
|
2113
2968
|
for (const role of ORDER) {
|
|
2969
|
+
if (lips !== void 0 && (role === "mouth" || role === "mouth_open")) {
|
|
2970
|
+
continue;
|
|
2971
|
+
}
|
|
2972
|
+
if (role === "mouth_inner") {
|
|
2973
|
+
if (lips === void 0) continue;
|
|
2974
|
+
const cfg2 = layout.mouth_inner;
|
|
2975
|
+
const part2 = await partBuffer(
|
|
2976
|
+
role,
|
|
2977
|
+
cfg2,
|
|
2978
|
+
partsDir,
|
|
2979
|
+
lips.keyedPng,
|
|
2980
|
+
mirrored.has(KEYED_SRC),
|
|
2981
|
+
canvas
|
|
2982
|
+
);
|
|
2983
|
+
const split2 = await splitLipSet(
|
|
2984
|
+
part2.buf,
|
|
2985
|
+
part2.w,
|
|
2986
|
+
part2.h,
|
|
2987
|
+
lips.interior
|
|
2988
|
+
);
|
|
2989
|
+
const { left: left2, top: top2 } = placement(role, cfg2, part2.w, part2.h, canvas);
|
|
2990
|
+
lipSplit = { split: split2, w: part2.w, h: part2.h, left: left2, top: top2 };
|
|
2991
|
+
placed.push({
|
|
2992
|
+
role,
|
|
2993
|
+
part: { buf: split2.inner, w: part2.w, h: part2.h },
|
|
2994
|
+
left: left2,
|
|
2995
|
+
top: top2
|
|
2996
|
+
});
|
|
2997
|
+
continue;
|
|
2998
|
+
}
|
|
2999
|
+
if (role === "mouth_tongue" || role === "mouth_teeth" || role === "lip_lower" || role === "lip_upper") {
|
|
3000
|
+
if (lipSplit === void 0) continue;
|
|
3001
|
+
const { split: split2, w, h, left: left2, top: top2 } = lipSplit;
|
|
3002
|
+
const buf = {
|
|
3003
|
+
mouth_tongue: split2.tongue,
|
|
3004
|
+
mouth_teeth: split2.teeth,
|
|
3005
|
+
lip_lower: split2.lower,
|
|
3006
|
+
lip_upper: split2.upper
|
|
3007
|
+
}[role];
|
|
3008
|
+
if ((0, import_editor11.isLipInsideRole)(role) && !await hasCoverage(buf)) {
|
|
3009
|
+
skipped.push(role);
|
|
3010
|
+
continue;
|
|
3011
|
+
}
|
|
3012
|
+
placed.push({ role, part: { buf, w, h }, left: left2, top: top2 });
|
|
3013
|
+
continue;
|
|
3014
|
+
}
|
|
2114
3015
|
const lower = role === "lash_lower_L" || role === "lash_lower_R";
|
|
2115
3016
|
const key = lower ? LOWER_LASH[role] : role;
|
|
2116
3017
|
if (lower && split.lashLower === null) {
|
|
@@ -2119,7 +3020,7 @@ async function composeLayersFromParts(input) {
|
|
|
2119
3020
|
}
|
|
2120
3021
|
if (key === "arm_L" || key === "arm_R") {
|
|
2121
3022
|
const arm = layout[key];
|
|
2122
|
-
if (!import_node_fs3.default.existsSync(
|
|
3023
|
+
if (!import_node_fs3.default.existsSync(import_node_path7.default.join(partsDir, arm.src))) continue;
|
|
2123
3024
|
const body = placed.find((p) => p.role === "body");
|
|
2124
3025
|
if (body === void 0) {
|
|
2125
3026
|
throw new AutoRigInputError(
|
|
@@ -2162,7 +3063,7 @@ async function composeLayersFromParts(input) {
|
|
|
2162
3063
|
}
|
|
2163
3064
|
if (key === "forearm_pose_L" || key === "forearm_pose_R") {
|
|
2164
3065
|
const pose = layout[key];
|
|
2165
|
-
if (!import_node_fs3.default.existsSync(
|
|
3066
|
+
if (!import_node_fs3.default.existsSync(import_node_path7.default.join(partsDir, pose.src))) continue;
|
|
2166
3067
|
const armRole = key === "forearm_pose_L" ? "arm_L" : "arm_R";
|
|
2167
3068
|
const arm = placed.find((p) => p.role === armRole);
|
|
2168
3069
|
if (arm?.elbow === void 0 || arm.elbowRun === void 0) {
|
|
@@ -2233,7 +3134,14 @@ async function composeLayersFromParts(input) {
|
|
|
2233
3134
|
noseSpeck = part.nose?.speck;
|
|
2234
3135
|
const { core, bounds } = await coreAndBoundsOf(part.buf);
|
|
2235
3136
|
const box = part.nose?.whole ? bounds : core ?? bounds;
|
|
2236
|
-
({ left, top } = nosePlacement(
|
|
3137
|
+
({ left, top } = nosePlacement(
|
|
3138
|
+
layout,
|
|
3139
|
+
lips === void 0 ? "mouth" : "mouth_inner",
|
|
3140
|
+
box,
|
|
3141
|
+
part.w,
|
|
3142
|
+
part.h,
|
|
3143
|
+
canvas
|
|
3144
|
+
));
|
|
2237
3145
|
} else {
|
|
2238
3146
|
({ left, top } = placement(key, layout[key], part.w, part.h, canvas));
|
|
2239
3147
|
}
|
|
@@ -2248,20 +3156,40 @@ async function composeLayersFromParts(input) {
|
|
|
2248
3156
|
}
|
|
2249
3157
|
placed.push({ role, part, left, top });
|
|
2250
3158
|
}
|
|
3159
|
+
const built = /* @__PURE__ */ new Map();
|
|
3160
|
+
for (const { role, part, left, top } of placed) {
|
|
3161
|
+
built.set(
|
|
3162
|
+
role,
|
|
3163
|
+
await blankCanvas(canvas).composite([{ input: part.buf, left, top }]).png().toBuffer()
|
|
3164
|
+
);
|
|
3165
|
+
}
|
|
3166
|
+
const closed = lipSplit === void 0 ? void 0 : await closedLips(
|
|
3167
|
+
lipSplit.split.upper,
|
|
3168
|
+
lipSplit.split.lower,
|
|
3169
|
+
await restShiftOf(
|
|
3170
|
+
{
|
|
3171
|
+
mouth_inner: built.get("mouth_inner"),
|
|
3172
|
+
lip_lower: built.get("lip_lower"),
|
|
3173
|
+
lip_upper: built.get("lip_upper")
|
|
3174
|
+
},
|
|
3175
|
+
canvas.width,
|
|
3176
|
+
canvas.height
|
|
3177
|
+
),
|
|
3178
|
+
lipSplit.left,
|
|
3179
|
+
lipSplit.top
|
|
3180
|
+
);
|
|
2251
3181
|
for (const role of ORDER) {
|
|
2252
3182
|
if (placed.some((p) => p.role === role)) continue;
|
|
2253
|
-
import_node_fs3.default.rmSync(
|
|
3183
|
+
import_node_fs3.default.rmSync(import_node_path7.default.join(outDir, `${role}.png`), { force: true });
|
|
2254
3184
|
}
|
|
2255
3185
|
const posed = (role) => role === "forearm_pose_L" || role === "forearm_pose_R";
|
|
2256
3186
|
if (!placed.some((p) => posed(p.role))) {
|
|
2257
|
-
import_node_fs3.default.rmSync(
|
|
3187
|
+
import_node_fs3.default.rmSync(import_node_path7.default.join(outDir, "preview-pose.png"), { force: true });
|
|
2258
3188
|
}
|
|
2259
3189
|
const layers = [];
|
|
2260
|
-
const preview = [];
|
|
2261
3190
|
for (const { role, part, left, top } of placed) {
|
|
2262
|
-
const
|
|
2263
|
-
|
|
2264
|
-
writeFileAtomic(outPath, layer);
|
|
3191
|
+
const outPath = import_node_path7.default.join(outDir, `${role}.png`);
|
|
3192
|
+
writeFileAtomic(outPath, built.get(role));
|
|
2265
3193
|
layers.push({
|
|
2266
3194
|
role,
|
|
2267
3195
|
path: outPath,
|
|
@@ -2270,9 +3198,20 @@ async function composeLayersFromParts(input) {
|
|
|
2270
3198
|
left,
|
|
2271
3199
|
top
|
|
2272
3200
|
});
|
|
2273
|
-
if (!posed(role)) preview.push({ input: part.buf, left, top });
|
|
2274
3201
|
}
|
|
2275
|
-
const
|
|
3202
|
+
const restInput = (role, buf) => {
|
|
3203
|
+
if (role === "mouth_inner" || (0, import_editor11.isLipInsideRole)(role)) return null;
|
|
3204
|
+
if (closed === void 0) return buf;
|
|
3205
|
+
if (role === "lip_upper") return closed.upper;
|
|
3206
|
+
if (role === "lip_lower") return closed.lower;
|
|
3207
|
+
return buf;
|
|
3208
|
+
};
|
|
3209
|
+
const preview = [];
|
|
3210
|
+
for (const { role, part, left, top } of placed) {
|
|
3211
|
+
const input2 = restInput(role, part.buf);
|
|
3212
|
+
if (!posed(role) && input2 !== null) preview.push({ input: input2, left, top });
|
|
3213
|
+
}
|
|
3214
|
+
const previewPng = await (0, import_sharp4.default)({
|
|
2276
3215
|
create: {
|
|
2277
3216
|
width: canvas.width,
|
|
2278
3217
|
height: canvas.height,
|
|
@@ -2280,7 +3219,7 @@ async function composeLayersFromParts(input) {
|
|
|
2280
3219
|
background: { r: 245, g: 245, b: 248, alpha: 1 }
|
|
2281
3220
|
}
|
|
2282
3221
|
}).composite(preview).png().toBuffer();
|
|
2283
|
-
const previewPath =
|
|
3222
|
+
const previewPath = import_node_path7.default.join(outDir, "preview.png");
|
|
2284
3223
|
writeFileAtomic(previewPath, previewPng);
|
|
2285
3224
|
let previewPosePath;
|
|
2286
3225
|
if (placed.some((p) => posed(p.role))) {
|
|
@@ -2290,17 +3229,18 @@ async function composeLayersFromParts(input) {
|
|
|
2290
3229
|
(p) => p.role === (role === "arm_L" ? "forearm_pose_L" : "forearm_pose_R")
|
|
2291
3230
|
);
|
|
2292
3231
|
if (!armPosed) {
|
|
2293
|
-
|
|
3232
|
+
const input2 = restInput(role, part.buf);
|
|
3233
|
+
if (input2 !== null) pose.push({ input: input2, left, top });
|
|
2294
3234
|
continue;
|
|
2295
3235
|
}
|
|
2296
3236
|
const rows = Math.min(part.h, Math.max(1, Math.round(elbow.y - top)));
|
|
2297
3237
|
pose.push({
|
|
2298
|
-
input: await (0,
|
|
3238
|
+
input: await (0, import_sharp4.default)(part.buf).extract({ left: 0, top: 0, width: part.w, height: rows }).png().toBuffer(),
|
|
2299
3239
|
left,
|
|
2300
3240
|
top
|
|
2301
3241
|
});
|
|
2302
3242
|
}
|
|
2303
|
-
const posePng = await (0,
|
|
3243
|
+
const posePng = await (0, import_sharp4.default)({
|
|
2304
3244
|
create: {
|
|
2305
3245
|
width: canvas.width,
|
|
2306
3246
|
height: canvas.height,
|
|
@@ -2308,7 +3248,7 @@ async function composeLayersFromParts(input) {
|
|
|
2308
3248
|
background: { r: 245, g: 245, b: 248, alpha: 1 }
|
|
2309
3249
|
}
|
|
2310
3250
|
}).composite(pose).png().toBuffer();
|
|
2311
|
-
previewPosePath =
|
|
3251
|
+
previewPosePath = import_node_path7.default.join(outDir, "preview-pose.png");
|
|
2312
3252
|
writeFileAtomic(previewPosePath, posePng);
|
|
2313
3253
|
}
|
|
2314
3254
|
return {
|
|
@@ -2329,7 +3269,7 @@ async function composeLayersFromParts(input) {
|
|
|
2329
3269
|
|
|
2330
3270
|
// src/server.ts
|
|
2331
3271
|
function createIkiMcpServer() {
|
|
2332
|
-
const server = new import_mcp.McpServer({ name: "iki", version: "0.
|
|
3272
|
+
const server = new import_mcp.McpServer({ name: "iki", version: "0.23.0" });
|
|
2333
3273
|
server.registerTool(
|
|
2334
3274
|
"validate_iki",
|
|
2335
3275
|
{
|
|
@@ -2394,7 +3334,7 @@ function createIkiMcpServer() {
|
|
|
2394
3334
|
server.registerTool(
|
|
2395
3335
|
"auto_rig_from_layers",
|
|
2396
3336
|
{
|
|
2397
|
-
description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R and either mouth or the lip set (mouth_inner + lip_lower + lip_upper, a mouth that folds open instead of crossfading) required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, forearm_pose_L/forearm_pose_R, etc. optional; an arm needs the body, a pose forearm needs its arm, and a partial lip set
|
|
3337
|
+
description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R and either mouth or the lip set (mouth_inner + lip_lower + lip_upper, a mouth that folds open instead of crossfading) required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, forearm_pose_L/forearm_pose_R, mouth_tongue/mouth_teeth (only with the lip set: drawn under its lips and clipped to mouth_inner), etc. optional; an arm needs the body, a pose forearm needs its arm, and a partial lip set, one mixed with mouth/mouth_open, or mouth_tongue/mouth_teeth without it is refused) into a renderable .iki written to disk. Pass full-canvas PNG file paths; returns the output path + summary (the model is NOT inlined). Filenames map to roles unless `fileName` is given.",
|
|
2398
3338
|
inputSchema: {
|
|
2399
3339
|
layers: import_zod.z.array(
|
|
2400
3340
|
import_zod.z.object({
|
|
@@ -2449,7 +3389,7 @@ function createIkiMcpServer() {
|
|
|
2449
3389
|
server.registerTool(
|
|
2450
3390
|
"compose_layers_from_parts",
|
|
2451
3391
|
{
|
|
2452
|
-
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,
|
|
3392
|
+
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, eyewhite, iris, brow, hair_front are required, with mouth.png \u2014 or the lip set's mouth_keyed.png (the open mouth, its inside painted flat #00FF00) + mouth_interior.png (the cavity, teeth and tongue alone), which the composer keys and splits into mouth_inner / lip_lower / lip_upper on one frame so auto_rig_from_layers folds the mouth open like the eyelid, the interior's light paint (luma 100 and over) written as mouth_tongue and mouth_teeth on the same frame, riding the opening's bottom and the upper line and clipped to the cavity (listed in `skipped` when the interior has none); the two routes cannot be mixed, one keyed file without the other is refused, and a key that fails (no green, green outside the opening, an outline not closed round it, more than one opening, no skin under the opening, an interior that is only lips, or one drawn opaque on a non-white or noisy ground) is refused naming the regeneration; with the lip set neither mouth nor mouth_open is written and preview.png shows the mouth closed, as the rig draws the rest pose. hair_back, body, mouth_open (legacy route only), blush (one blush.png makes the blush_L/blush_R pair) and nose are optional \u2014 without a nose layer the head still turns on the rig's default profile, but it has no nose to lead the turn, and `auto_rig_from_layers` fits no turn to the art (`turnTargets` is inert, no `turn` report). One arm.png \u2014 the arm on the screen LEFT, drawn hanging with its shoulder at the top \u2014 makes both arms of a full body: arm_R takes it as drawn and arm_L mirrored. The arms are opt-in: without arm.png the compose is a bust's and `skipped` never lists them. arm.png needs body.png, and each arm is hung on the body's shoulder by default (see `layout`). One forearm_pose.png \u2014 the arm's forearm raised, on the screen LEFT, standing up from its elbow with the hand at the top \u2014 makes both pose forearms (forearm_pose_R as drawn, forearm_pose_L mirrored): each is scaled so its elbow end is as wide as its arm's elbow run and pinned on that arm's elbow (see `layout`), and it needs arm.png. With one, preview-pose.png shows the switch at 1 as the rig draws it (the hanging forearms hidden below the elbow, the pose forearms over everything) while preview.png stays the rest pose; without one it is removed. The inline report carries the full-body checks too: a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge, and a pose forearm without its arm or off its arm's elbow in pivot, width or length. A nose whose dense core is a speck \u2014 under a quarter of its trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole, and the inline report warns of it. A light mark drawn detached above the eye white, such as a double-eyelid crease, is dropped from the sclera (the iris's clip); dark strokes there stay lash ink. The eyewhite's dark lower lid \u2014 its line and lashes \u2014 becomes lash_lower_L/lash_lower_R, drawn over the iris; a white with none writes none and lists them in `skipped`.",
|
|
2453
3393
|
inputSchema: {
|
|
2454
3394
|
partsDir: import_zod.z.string().describe(
|
|
2455
3395
|
"Directory of the source part PNGs (resolved against cwd)."
|
|
@@ -2466,7 +3406,7 @@ function createIkiMcpServer() {
|
|
|
2466
3406
|
h: import_zod.z.number()
|
|
2467
3407
|
}).partial()
|
|
2468
3408
|
).optional().describe(
|
|
2469
|
-
"Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, arm_L, arm_R, face, blush_L, blush_R, nose, mouth, mouth_open, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_front, forearm_pose_L, forearm_pose_R \u2014 e.g. `{ eye_L: { cx: 660 } }`. `w` is an integer in 1..1100 (the canvas width) and `h` in 1..canvasHeight; omit `h` to keep the part's own aspect, set it to stretch. The defaults of the face's features \u2014 blush, nose, mouth, mouth_open, eyes, irises, lashes, brows \u2014 are proportions of the face: an override of face.cx, face.cy or face.w carries them with it (scaled by the width; face.h stretches the face alone), while a feature's own override names canvas px. The nose is sized and placed by its dense core (its pixels at alpha >= 128, the drawing inside a soft nose's feather), not its whole part: `w`/`h` size the core, `cx` centres it, and a set `cy` centres its rows. A nose whose core is a speck \u2014 under a quarter of the trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole instead, and the report warns of it. Its `cy` defaults to unset, which lands the core's bottom row (the tip) 0.66 of the way from the eye row down to the mouth's, so the nose follows a retuned eye or mouth row. eye_L/lash_L and eye_R/lash_R are cut from one eyewhite into one frame, so each pair must land on the same frame \u2014 a pair set to land apart is rejected. lash_lower_L/lash_lower_R are cut from it too and have no key: they land on their eye's frame. arm_L/arm_R have no cx/cy/w defaults: an unset `w` is 0.4 of the placed body's width, and an unset `cx` or `cy` hangs the arm's shoulder pivot \u2014 the one auto_rig_from_layers turns it about \u2014 on the body box's shoulder corner on that axis: its left edge for arm_R, its right edge for arm_L, 0.12 of its height under its top. A set one centres the arm as for every other role. forearm_pose_L/forearm_pose_R have no cx/cy/w defaults either: an unset `w` scales the forearm so its elbow end (the shoulder rule run from its bottom) is as wide as the placed arm's elbow run, and an unset `cx` or `cy` pins that elbow end's pivot on the arm's elbow \u2014 the one auto_rig_from_layers hangs it from."
|
|
3409
|
+
"Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, arm_L, arm_R, face, blush_L, blush_R, nose, mouth, mouth_open, mouth_inner, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_front, forearm_pose_L, forearm_pose_R \u2014 e.g. `{ eye_L: { cx: 660 } }`. `w` is an integer in 1..1100 (the canvas width) and `h` in 1..canvasHeight; omit `h` to keep the part's own aspect, set it to stretch. The defaults of the face's features \u2014 blush, nose, mouth, mouth_open, mouth_inner, eyes, irises, lashes, brows \u2014 are proportions of the face: an override of face.cx, face.cy or face.w carries them with it (scaled by the width; face.h stretches the face alone), while a feature's own override names canvas px. The nose is sized and placed by its dense core (its pixels at alpha >= 128, the drawing inside a soft nose's feather), not its whole part: `w`/`h` size the core, `cx` centres it, and a set `cy` centres its rows. A nose whose core is a speck \u2014 under a quarter of the trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole instead, and the report warns of it. Its `cy` defaults to unset, which lands the core's bottom row (the tip) 0.66 of the way from the eye row down to the mouth's, so the nose follows a retuned eye or mouth row. eye_L/lash_L and eye_R/lash_R are cut from one eyewhite into one frame, so each pair must land on the same frame \u2014 a pair set to land apart is rejected. lash_lower_L/lash_lower_R are cut from it too and have no key: they land on their eye's frame. mouth_inner is the lip set's one frame (mouth_open's place by default; lip_lower, lip_upper, mouth_tongue and mouth_teeth have no key and land on it, so a retune moves them together), and with the lip set the nose's tip rule reads layout.mouth_inner.cy. arm_L/arm_R have no cx/cy/w defaults: an unset `w` is 0.4 of the placed body's width, and an unset `cx` or `cy` hangs the arm's shoulder pivot \u2014 the one auto_rig_from_layers turns it about \u2014 on the body box's shoulder corner on that axis: its left edge for arm_R, its right edge for arm_L, 0.12 of its height under its top. A set one centres the arm as for every other role. forearm_pose_L/forearm_pose_R have no cx/cy/w defaults either: an unset `w` scales the forearm so its elbow end (the shoulder rule run from its bottom) is as wide as the placed arm's elbow run, and an unset `cx` or `cy` pins that elbow end's pivot on the arm's elbow \u2014 the one auto_rig_from_layers hangs it from."
|
|
2470
3410
|
),
|
|
2471
3411
|
mirrorParts: import_zod.z.array(import_zod.z.string()).optional().describe(
|
|
2472
3412
|
"Part files to flip left-right as they are read, e.g. `[\"eyewhite.png\"]`. The composer reads eyewhite.png as the eye on the screen LEFT (lash wing at the image's left end, lash-free tear duct at its right), brow.png as the brow on the screen RIGHT (thick head at the image's left end, tail at its right), blush.png as the blush on the screen LEFT (outer end, toward the face's edge, at the image's left end, inner end at its right), arm.png as the arm on the screen LEFT (the character's right, hanging, its shoulder at the image's top), and forearm_pose.png as the raised forearm on the screen LEFT (standing up from its elbow, the hand at the image's top, the thumb toward the body at the image's 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."
|
|
@@ -2497,7 +3437,7 @@ function createIkiMcpServer() {
|
|
|
2497
3437
|
server.registerTool(
|
|
2498
3438
|
"measure_layers",
|
|
2499
3439
|
{
|
|
2500
|
-
description: "Reports read-only geometry checks over an already-composed layers directory \u2014 the same checks compose_layers_from_parts returns inline (iris ratio/offset, eye aspect, cropped/cut edges, a nose whose dense core is a speck of its crop, missing optional roles, a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge on its shoulder pivot's row, a pose forearm without its arm or whose elbow end is off its arm's elbow in pivot, width or length). Every preview*.png is skipped. Use to re-check a layers dir without recomposing. Its nose check reads the composed file against its crop, which is what auto_rig_from_layers acts on. Compose's inline report does the same unless the composer found the source part's core a speck, which it reports instead \u2014 so a speck that resampling erased from the layer shows there and not here.",
|
|
3440
|
+
description: "Reports read-only geometry checks over an already-composed layers directory \u2014 the same checks compose_layers_from_parts returns inline (iris ratio/offset, eye aspect, cropped/cut edges, a nose whose dense core is a speck of its crop, missing optional roles, a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge on its shoulder pivot's row, a pose forearm without its arm or whose elbow end is off its arm's elbow in pivot, width or length, and the lip set: a partial one or one beside mouth/mouth_open, the fold's contract per column of the opening, an opening too narrow or short, a line too thin, green left, an interior with holes, and of mouth_tongue/mouth_teeth: one with no lip set, one on another canvas, one whose box leaves mouth_inner's \u2014 with the opening's size and the MouthOpen below which no slit shows). Every preview*.png is skipped. Use to re-check a layers dir without recomposing. Its nose check reads the composed file against its crop, which is what auto_rig_from_layers acts on. Compose's inline report does the same unless the composer found the source part's core a speck, which it reports instead \u2014 so a speck that resampling erased from the layer shows there and not here.",
|
|
2501
3441
|
inputSchema: {
|
|
2502
3442
|
layersDir: import_zod.z.string().describe(
|
|
2503
3443
|
"Directory of role-named layer PNGs (resolved against cwd)."
|