@ikijs/mcp 0.33.1 → 0.35.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 +24 -6
- package/dist/{chunk-VTJEYDRK.mjs → chunk-SNBG5VHS.mjs} +1740 -420
- package/dist/chunk-SNBG5VHS.mjs.map +1 -0
- package/dist/cli.js +1640 -326
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +323 -16
- package/dist/index.d.ts +323 -16
- package/dist/index.js +1650 -326
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -1
- package/dist/render-page.global.js +98 -8
- package/package.json +4 -4
- package/dist/chunk-VTJEYDRK.mjs.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -32,10 +32,10 @@ var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
|
32
32
|
var import_zod = require("zod");
|
|
33
33
|
|
|
34
34
|
// src/tools.ts
|
|
35
|
-
var
|
|
35
|
+
var import_node_fs6 = require("fs");
|
|
36
36
|
var import_node_path5 = __toESM(require("path"));
|
|
37
|
-
var
|
|
38
|
-
var
|
|
37
|
+
var import_format11 = require("@ikijs/format");
|
|
38
|
+
var import_editor4 = require("@ikijs/editor");
|
|
39
39
|
|
|
40
40
|
// ../engine/src/math.ts
|
|
41
41
|
function clamp(value, min, max) {
|
|
@@ -449,6 +449,22 @@ function resolveDeformers(deformers, params) {
|
|
|
449
449
|
return { worlds, grids };
|
|
450
450
|
}
|
|
451
451
|
|
|
452
|
+
// ../engine/src/occlusion.ts
|
|
453
|
+
function occlusionAmount(occlusion, value) {
|
|
454
|
+
const { stops } = occlusion;
|
|
455
|
+
const first = stops[0];
|
|
456
|
+
if (value <= first.value) return first.amount;
|
|
457
|
+
for (let i = 1; i < stops.length; i++) {
|
|
458
|
+
const hi = stops[i];
|
|
459
|
+
if (value <= hi.value) {
|
|
460
|
+
const lo = stops[i - 1];
|
|
461
|
+
const t = (value - lo.value) / (hi.value - lo.value);
|
|
462
|
+
return lo.amount * (1 - t) + hi.amount * t;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return stops[stops.length - 1].amount;
|
|
466
|
+
}
|
|
467
|
+
|
|
452
468
|
// ../engine/src/idle-motion.ts
|
|
453
469
|
var import_format = require("@ikijs/format");
|
|
454
470
|
|
|
@@ -1707,58 +1723,6 @@ function affectedParts(model, output) {
|
|
|
1707
1723
|
);
|
|
1708
1724
|
}
|
|
1709
1725
|
|
|
1710
|
-
// src/fold-report.ts
|
|
1711
|
-
var import_editor = require("@ikijs/editor");
|
|
1712
|
-
function checkModelFolds(model, extraValues = []) {
|
|
1713
|
-
const declared = new Set(model.parameters.map((p) => p.id));
|
|
1714
|
-
return checkFolds(model, {
|
|
1715
|
-
poses: [...foldPoses(model), ...extraValues.map(foldPose)],
|
|
1716
|
-
// The effective value, not the pose's overrides: the auto-rig's mouth
|
|
1717
|
-
// rests shut at its default, so `rest` and the other parameters' singles
|
|
1718
|
-
// are shut-mouth poses too.
|
|
1719
|
-
expected: (target2, _pose, value) => {
|
|
1720
|
-
if (target2.kind !== "part") return false;
|
|
1721
|
-
const shutBy = import_editor.SHUT_BY.get(target2.id);
|
|
1722
|
-
return shutBy !== void 0 && declared.has(shutBy) && value(shutBy) === 0;
|
|
1723
|
-
}
|
|
1724
|
-
});
|
|
1725
|
-
}
|
|
1726
|
-
function formatFoldReport(report, canvas) {
|
|
1727
|
-
const lines = report.offenders.length === 0 ? [`FOLDS: none over ${report.poses} poses`] : report.offenders.map((t) => offenderLine(t, t.worst, canvas));
|
|
1728
|
-
const closures = report.targets.flatMap((t) => {
|
|
1729
|
-
if (t.expected === void 0) return [];
|
|
1730
|
-
if (t.expected.ratio >= report.thresholds.collapse) return [];
|
|
1731
|
-
const shutBy = import_editor.SHUT_BY.get(t.target.id);
|
|
1732
|
-
const at = shutBy === void 0 ? "" : ` at ${shutBy}=0`;
|
|
1733
|
-
return [`${t.target.id} ${ratioText(t.expected.ratio)}${at}`];
|
|
1734
|
-
});
|
|
1735
|
-
if (closures.length > 0) {
|
|
1736
|
-
lines.push(
|
|
1737
|
-
`FOLDS expected: by-design closures, not findings \u2014 ${closures.join(", ")}`
|
|
1738
|
-
);
|
|
1739
|
-
}
|
|
1740
|
-
return lines;
|
|
1741
|
-
}
|
|
1742
|
-
function foldPose(values) {
|
|
1743
|
-
const ids = Object.keys(values).sort();
|
|
1744
|
-
const name = ids.length === 0 ? "rest" : ids.map((id) => `${id}=${values[id]}`).join(" ");
|
|
1745
|
-
return { name, values };
|
|
1746
|
-
}
|
|
1747
|
-
function offenderLine(t, hit, canvas) {
|
|
1748
|
-
const where = "triangle" in hit.where ? `triangle ${hit.where.triangle}` : `cell (${hit.where.col},${hit.where.row})`;
|
|
1749
|
-
const { x, y } = hit.rest;
|
|
1750
|
-
return `FOLD ${t.kind} ${t.target.kind} ${t.target.id} ${where} ratio ${ratioText(hit.ratio)} pose [${hit.pose.name}] rest at (${x.toFixed(1)}, ${y.toFixed(1)}) model space, (${(canvas.width / 2 + x).toFixed(0)}, ${(canvas.height / 2 - y).toFixed(0)}) model px from the top-left`;
|
|
1751
|
-
}
|
|
1752
|
-
function ratioText(ratio) {
|
|
1753
|
-
if (ratio === 0) return "0";
|
|
1754
|
-
return Math.abs(ratio) < 0.01 ? ratio.toExponential(1) : ratio.toFixed(2);
|
|
1755
|
-
}
|
|
1756
|
-
|
|
1757
|
-
// src/render-poses.ts
|
|
1758
|
-
var import_node_fs4 = require("fs");
|
|
1759
|
-
var import_node_path4 = __toESM(require("path"));
|
|
1760
|
-
var import_format8 = require("@ikijs/format");
|
|
1761
|
-
|
|
1762
1726
|
// src/limits.ts
|
|
1763
1727
|
var import_node_fs = __toESM(require("fs"));
|
|
1764
1728
|
var import_node_path = __toESM(require("path"));
|
|
@@ -1769,6 +1733,8 @@ var MAX_ATLAS_SIDE = 4096;
|
|
|
1769
1733
|
var MAX_INPUT_PIXELS = 4096 * 4096;
|
|
1770
1734
|
var MAX_TOTAL_PIXELS = 128 * 1024 * 1024;
|
|
1771
1735
|
var MAX_OUTPUT_BYTES = 12 * 1024 * 1024;
|
|
1736
|
+
var MAX_PROBE_QUERIES = 64;
|
|
1737
|
+
var MAX_PROBE_POINTS = 5e3;
|
|
1772
1738
|
var AutoRigInputError = class extends Error {
|
|
1773
1739
|
constructor(message) {
|
|
1774
1740
|
super(message);
|
|
@@ -1825,12 +1791,14 @@ function confineToWorkingDirectory(root, dir, label, original) {
|
|
|
1825
1791
|
}
|
|
1826
1792
|
return realDir;
|
|
1827
1793
|
}
|
|
1828
|
-
function resolveOutputPath(outputPath) {
|
|
1794
|
+
function resolveOutputPath(outputPath, extension = ".iki") {
|
|
1829
1795
|
if (typeof outputPath !== "string" || outputPath.trim() === "") {
|
|
1830
1796
|
throw new AutoRigInputError("output path is empty");
|
|
1831
1797
|
}
|
|
1832
|
-
if (!outputPath.toLowerCase().endsWith(
|
|
1833
|
-
throw new AutoRigInputError(
|
|
1798
|
+
if (!outputPath.toLowerCase().endsWith(extension)) {
|
|
1799
|
+
throw new AutoRigInputError(
|
|
1800
|
+
`output path must end in ${extension}: ${outputPath}`
|
|
1801
|
+
);
|
|
1834
1802
|
}
|
|
1835
1803
|
const root = process.cwd();
|
|
1836
1804
|
const resolved = import_node_path.default.resolve(root, outputPath);
|
|
@@ -1880,18 +1848,1111 @@ function writeFileAtomic(outPath, data) {
|
|
|
1880
1848
|
import_node_fs.default.rmSync(tmp, { force: true });
|
|
1881
1849
|
} catch {
|
|
1882
1850
|
}
|
|
1883
|
-
throw e;
|
|
1851
|
+
throw e;
|
|
1852
|
+
}
|
|
1853
|
+
} catch (e) {
|
|
1854
|
+
throw new AutoRigInputError(
|
|
1855
|
+
`write: ${e instanceof Error ? e.message : String(e)}`
|
|
1856
|
+
);
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
// src/bake-report.ts
|
|
1861
|
+
var BAKE_TOLERANCE_PX = 0.1;
|
|
1862
|
+
var BUG = "the rig and the engine disagree; report this as a bug in the packages";
|
|
1863
|
+
function checkBakes(model, reports) {
|
|
1864
|
+
const restOf = /* @__PURE__ */ new Map();
|
|
1865
|
+
for (const id of new Set(reports.map((r) => r.part))) {
|
|
1866
|
+
const rest = landParts(model, {}, [id]).get(id);
|
|
1867
|
+
const bare = landParts(
|
|
1868
|
+
{
|
|
1869
|
+
...model,
|
|
1870
|
+
parts: model.parts.map(
|
|
1871
|
+
(p) => p.id === id ? { ...p, warps: void 0 } : p
|
|
1872
|
+
)
|
|
1873
|
+
},
|
|
1874
|
+
{},
|
|
1875
|
+
[id]
|
|
1876
|
+
).get(id);
|
|
1877
|
+
let restGap = 0;
|
|
1878
|
+
for (let i = 0; i < rest.length; i++) {
|
|
1879
|
+
restGap = Math.max(restGap, Math.abs(rest[i] - bare[i]));
|
|
1880
|
+
}
|
|
1881
|
+
if (restGap >= BAKE_TOLERANCE_PX) {
|
|
1882
|
+
throw new AutoRigInputError(
|
|
1883
|
+
`BAKE ERROR ${id} at rest: the part moved ${restGap.toFixed(3)} px, where the bake must leave it (limit ${BAKE_TOLERANCE_PX} px); ${BUG}`
|
|
1884
|
+
);
|
|
1885
|
+
}
|
|
1886
|
+
restOf.set(id, rest);
|
|
1887
|
+
}
|
|
1888
|
+
return reports.map((r) => {
|
|
1889
|
+
const rest = restOf.get(r.part);
|
|
1890
|
+
let errorPx = 0;
|
|
1891
|
+
const asked = [
|
|
1892
|
+
...r.stops.map((value, s) => ({ value, wanted: r.wanted[s] })),
|
|
1893
|
+
...r.ends
|
|
1894
|
+
];
|
|
1895
|
+
asked.forEach(({ value, wanted }) => {
|
|
1896
|
+
const posed = landParts(model, { [r.param]: value }, [r.part]).get(
|
|
1897
|
+
r.part
|
|
1898
|
+
);
|
|
1899
|
+
let worst = 0;
|
|
1900
|
+
let worstVertex = 0;
|
|
1901
|
+
for (let v = 0; v < r.vertexCount; v++) {
|
|
1902
|
+
const gap = Math.hypot(
|
|
1903
|
+
posed[v * 2] - rest[v * 2] - wanted[v * 2],
|
|
1904
|
+
-(posed[v * 2 + 1] - rest[v * 2 + 1]) - wanted[v * 2 + 1]
|
|
1905
|
+
);
|
|
1906
|
+
if (gap > worst) {
|
|
1907
|
+
worst = gap;
|
|
1908
|
+
worstVertex = v;
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
if (worst >= BAKE_TOLERANCE_PX) {
|
|
1912
|
+
throw new AutoRigInputError(
|
|
1913
|
+
`BAKE ERROR ${r.part} ${r.param}=${value}: vertex ${worstVertex} lands ${worst.toFixed(3)} px from the displacement the bake asked for (limit ${BAKE_TOLERANCE_PX} px); ${BUG}`
|
|
1914
|
+
);
|
|
1915
|
+
}
|
|
1916
|
+
errorPx = Math.max(errorPx, worst);
|
|
1917
|
+
});
|
|
1918
|
+
return {
|
|
1919
|
+
part: r.part,
|
|
1920
|
+
param: r.param,
|
|
1921
|
+
vertices: r.vertexCount,
|
|
1922
|
+
stops: r.stops,
|
|
1923
|
+
errorPx
|
|
1924
|
+
};
|
|
1925
|
+
});
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
// src/custom-gate.ts
|
|
1929
|
+
var import_editor3 = require("@ikijs/editor");
|
|
1930
|
+
var import_format9 = require("@ikijs/format");
|
|
1931
|
+
|
|
1932
|
+
// src/fold-report.ts
|
|
1933
|
+
var import_editor = require("@ikijs/editor");
|
|
1934
|
+
function checkModelFolds(model, extraValues = []) {
|
|
1935
|
+
const declared = new Set(model.parameters.map((p) => p.id));
|
|
1936
|
+
return checkFolds(model, {
|
|
1937
|
+
poses: [...foldPoses(model), ...extraValues.map(foldPose)],
|
|
1938
|
+
// The effective value, not the pose's overrides: the auto-rig's mouth
|
|
1939
|
+
// rests shut at its default, so `rest` and the other parameters' singles
|
|
1940
|
+
// are shut-mouth poses too.
|
|
1941
|
+
expected: (target2, _pose, value) => {
|
|
1942
|
+
if (target2.kind !== "part") return false;
|
|
1943
|
+
const shutBy = import_editor.SHUT_BY.get(target2.id);
|
|
1944
|
+
return shutBy !== void 0 && declared.has(shutBy) && value(shutBy) === 0;
|
|
1945
|
+
}
|
|
1946
|
+
});
|
|
1947
|
+
}
|
|
1948
|
+
function formatFoldReport(report, canvas) {
|
|
1949
|
+
const lines = report.offenders.length === 0 ? [`FOLDS: none over ${report.poses} poses`] : report.offenders.map((t) => offenderLine(t, t.worst, canvas));
|
|
1950
|
+
const closures = report.targets.flatMap((t) => {
|
|
1951
|
+
if (t.expected === void 0) return [];
|
|
1952
|
+
if (t.expected.ratio >= report.thresholds.collapse) return [];
|
|
1953
|
+
const shutBy = import_editor.SHUT_BY.get(t.target.id);
|
|
1954
|
+
const at = shutBy === void 0 ? "" : ` at ${shutBy}=0`;
|
|
1955
|
+
return [`${t.target.id} ${ratioText(t.expected.ratio)}${at}`];
|
|
1956
|
+
});
|
|
1957
|
+
if (closures.length > 0) {
|
|
1958
|
+
lines.push(
|
|
1959
|
+
`FOLDS expected: by-design closures, not findings \u2014 ${closures.join(", ")}`
|
|
1960
|
+
);
|
|
1961
|
+
}
|
|
1962
|
+
return lines;
|
|
1963
|
+
}
|
|
1964
|
+
function foldPose(values) {
|
|
1965
|
+
const ids = Object.keys(values).sort();
|
|
1966
|
+
const name = ids.length === 0 ? "rest" : ids.map((id) => `${id}=${values[id]}`).join(" ");
|
|
1967
|
+
return { name, values };
|
|
1968
|
+
}
|
|
1969
|
+
function offenderLine(t, hit, canvas) {
|
|
1970
|
+
const where = "triangle" in hit.where ? `triangle ${hit.where.triangle}` : `cell (${hit.where.col},${hit.where.row})`;
|
|
1971
|
+
const { x, y } = hit.rest;
|
|
1972
|
+
return `FOLD ${t.kind} ${t.target.kind} ${t.target.id} ${where} ratio ${ratioText(hit.ratio)} pose [${hit.pose.name}] rest at (${x.toFixed(1)}, ${y.toFixed(1)}) model space, (${(canvas.width / 2 + x).toFixed(0)}, ${(canvas.height / 2 - y).toFixed(0)}) model px from the top-left`;
|
|
1973
|
+
}
|
|
1974
|
+
function ratioText(ratio) {
|
|
1975
|
+
if (ratio === 0) return "0";
|
|
1976
|
+
return Math.abs(ratio) < 0.01 ? ratio.toExponential(1) : ratio.toFixed(2);
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1979
|
+
// src/probe.ts
|
|
1980
|
+
var import_node_fs2 = require("fs");
|
|
1981
|
+
var import_format8 = require("@ikijs/format");
|
|
1982
|
+
|
|
1983
|
+
// src/node-images.ts
|
|
1984
|
+
var import_sharp = __toESM(require("sharp"));
|
|
1985
|
+
var import_editor2 = require("@ikijs/editor");
|
|
1986
|
+
async function decodePng(filePath) {
|
|
1987
|
+
try {
|
|
1988
|
+
const pipeline = (0, import_sharp.default)(filePath, { limitInputPixels: MAX_INPUT_PIXELS });
|
|
1989
|
+
const metadata = await pipeline.metadata();
|
|
1990
|
+
if (metadata.format !== "png") {
|
|
1991
|
+
throw new AutoRigInputError(
|
|
1992
|
+
`non-PNG image (${metadata.format ?? "unknown"}): ${filePath}`
|
|
1993
|
+
);
|
|
1994
|
+
}
|
|
1995
|
+
const { data, info } = await pipeline.ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
1996
|
+
return {
|
|
1997
|
+
width: info.width,
|
|
1998
|
+
height: info.height,
|
|
1999
|
+
rgba: data,
|
|
2000
|
+
hasAlpha: metadata.hasAlpha ?? false
|
|
2001
|
+
};
|
|
2002
|
+
} catch (e) {
|
|
2003
|
+
if (e instanceof AutoRigInputError) throw e;
|
|
2004
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
2005
|
+
throw new AutoRigInputError(`failed to decode PNG ${filePath}: ${msg}`);
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
function detectAlphaBbox(rgba, width, height) {
|
|
2009
|
+
const bbox = (0, import_editor2.detectAlphaBbox)(rgba, width, height);
|
|
2010
|
+
if (bbox === null) {
|
|
2011
|
+
throw new AutoRigInputError("layer is empty after alpha threshold");
|
|
2012
|
+
}
|
|
2013
|
+
return bbox;
|
|
2014
|
+
}
|
|
2015
|
+
function cropToBuffer(rgba, width, height, bbox) {
|
|
2016
|
+
return (0, import_sharp.default)(rgba, { raw: { width, height, channels: 4 } }).extract({ left: bbox.x, top: bbox.y, width: bbox.w, height: bbox.h }).png().toBuffer();
|
|
2017
|
+
}
|
|
2018
|
+
function encodeOverlayPng(filePath, svg) {
|
|
2019
|
+
return (0, import_sharp.default)(filePath, { limitInputPixels: MAX_INPUT_PIXELS }).composite([{ input: Buffer.from(svg) }]).png().toBuffer();
|
|
2020
|
+
}
|
|
2021
|
+
async function renderAtlasToDataUri(crops, layout, quantizeColors) {
|
|
2022
|
+
const byId = /* @__PURE__ */ new Map();
|
|
2023
|
+
for (const crop of crops) byId.set(crop.id, crop);
|
|
2024
|
+
const pad = layout.padding;
|
|
2025
|
+
const composites = await Promise.all(
|
|
2026
|
+
layout.placements.map(async (placement3) => {
|
|
2027
|
+
const crop = byId.get(placement3.id);
|
|
2028
|
+
if (crop === void 0) {
|
|
2029
|
+
throw new AutoRigInputError(
|
|
2030
|
+
`no crop for atlas placement "${placement3.id}"`
|
|
2031
|
+
);
|
|
2032
|
+
}
|
|
2033
|
+
const input = pad > 0 ? await (0, import_sharp.default)(crop.buffer).extend({ right: pad, bottom: pad, extendWith: "copy" }).png().toBuffer() : crop.buffer;
|
|
2034
|
+
return { input, left: placement3.x, top: placement3.y };
|
|
2035
|
+
})
|
|
2036
|
+
);
|
|
2037
|
+
const page = await (0, import_sharp.default)({
|
|
2038
|
+
create: {
|
|
2039
|
+
width: layout.pageWidth,
|
|
2040
|
+
height: layout.pageHeight,
|
|
2041
|
+
channels: 4,
|
|
2042
|
+
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
|
2043
|
+
}
|
|
2044
|
+
}).composite(composites).png(
|
|
2045
|
+
quantizeColors === void 0 ? {} : { palette: true, colours: quantizeColors, dither: 0.5, effort: 10 }
|
|
2046
|
+
).toBuffer();
|
|
2047
|
+
return `data:image/png;base64,${page.toString("base64")}`;
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
// src/probe.ts
|
|
2051
|
+
var OUTPUT_SUFFIX = ".probe.json";
|
|
2052
|
+
var OPAQUE = 128;
|
|
2053
|
+
function paintRuns(png) {
|
|
2054
|
+
const { width, height, rgba } = png;
|
|
2055
|
+
const rows = [];
|
|
2056
|
+
let y0 = -1;
|
|
2057
|
+
for (let y = 0; y < height; y++) {
|
|
2058
|
+
const runs = [];
|
|
2059
|
+
let start = -1;
|
|
2060
|
+
for (let x = 0; x < width; x++) {
|
|
2061
|
+
const on = rgba[(y * width + x) * 4 + 3] >= OPAQUE;
|
|
2062
|
+
if (on && start < 0) start = x;
|
|
2063
|
+
if (!on && start >= 0) {
|
|
2064
|
+
runs.push([start, x]);
|
|
2065
|
+
start = -1;
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
if (start >= 0) runs.push([start, width]);
|
|
2069
|
+
if (runs.length > 0 && y0 < 0) y0 = y;
|
|
2070
|
+
if (y0 >= 0) rows.push(runs);
|
|
2071
|
+
}
|
|
2072
|
+
while (rows.length > 0 && rows[rows.length - 1].length === 0) rows.pop();
|
|
2073
|
+
return rows.length === 0 ? { y0: 0, rows: [] } : { y0, rows };
|
|
2074
|
+
}
|
|
2075
|
+
function toCanvas(model, pts) {
|
|
2076
|
+
const hw = model.canvas.width / 2;
|
|
2077
|
+
const hh = model.canvas.height / 2;
|
|
2078
|
+
const out = new Float64Array(pts.length);
|
|
2079
|
+
for (let i = 0; i < pts.length; i += 2) {
|
|
2080
|
+
out[i] = hw + pts[i];
|
|
2081
|
+
out[i + 1] = hh - pts[i + 1];
|
|
2082
|
+
}
|
|
2083
|
+
return out;
|
|
2084
|
+
}
|
|
2085
|
+
var round = (v) => Math.round(v * 1e3) / 1e3 + 0;
|
|
2086
|
+
function locate(vertices, tri, x, y) {
|
|
2087
|
+
const [a, b, c] = tri;
|
|
2088
|
+
const ax = vertices[a * 2];
|
|
2089
|
+
const ay = vertices[a * 2 + 1];
|
|
2090
|
+
const bx = vertices[b * 2];
|
|
2091
|
+
const by = vertices[b * 2 + 1];
|
|
2092
|
+
const cx = vertices[c * 2];
|
|
2093
|
+
const cy = vertices[c * 2 + 1];
|
|
2094
|
+
const d = (by - cy) * (ax - cx) + (cx - bx) * (ay - cy);
|
|
2095
|
+
if (Math.abs(d) < 1e-12) return null;
|
|
2096
|
+
const l1 = ((by - cy) * (x - cx) + (cx - bx) * (y - cy)) / d;
|
|
2097
|
+
const l2 = ((cy - ay) * (x - cx) + (ax - cx) * (y - cy)) / d;
|
|
2098
|
+
const l3 = 1 - l1 - l2;
|
|
2099
|
+
const eps = 1e-9;
|
|
2100
|
+
return l1 >= -eps && l2 >= -eps && l3 >= -eps ? [l1, l2, l3] : null;
|
|
2101
|
+
}
|
|
2102
|
+
var QUAD_INDICES = [0, 1, 2, 1, 3, 2];
|
|
2103
|
+
function restMesh(model, cache, partId) {
|
|
2104
|
+
let m = cache.get(partId);
|
|
2105
|
+
if (m) return m;
|
|
2106
|
+
const part = model.parts.find((p) => p.id === partId);
|
|
2107
|
+
const indices = part.mesh ? part.mesh.indices : QUAD_INDICES;
|
|
2108
|
+
const rest = toCanvas(model, landParts(model, {}, [partId]).get(partId));
|
|
2109
|
+
const boxes = new Float64Array(indices.length / 3 * 4);
|
|
2110
|
+
for (let t = 0; t < indices.length / 3; t++) {
|
|
2111
|
+
let x0 = Infinity;
|
|
2112
|
+
let y0 = Infinity;
|
|
2113
|
+
let x1 = -Infinity;
|
|
2114
|
+
let y1 = -Infinity;
|
|
2115
|
+
for (let k = 0; k < 3; k++) {
|
|
2116
|
+
const v = indices[t * 3 + k];
|
|
2117
|
+
x0 = Math.min(x0, rest[v * 2]);
|
|
2118
|
+
x1 = Math.max(x1, rest[v * 2]);
|
|
2119
|
+
y0 = Math.min(y0, rest[v * 2 + 1]);
|
|
2120
|
+
y1 = Math.max(y1, rest[v * 2 + 1]);
|
|
2121
|
+
}
|
|
2122
|
+
boxes.set([x0, y0, x1, y1], t * 4);
|
|
2123
|
+
}
|
|
2124
|
+
m = { indices, rest, boxes };
|
|
2125
|
+
cache.set(partId, m);
|
|
2126
|
+
return m;
|
|
2127
|
+
}
|
|
2128
|
+
function locatePoints(mesh, points) {
|
|
2129
|
+
const { indices, rest, boxes } = mesh;
|
|
2130
|
+
const slack = 1e-6;
|
|
2131
|
+
return points.map(([x, y]) => {
|
|
2132
|
+
for (let t = 0; t < indices.length / 3; t++) {
|
|
2133
|
+
const b = t * 4;
|
|
2134
|
+
if (x < boxes[b] - slack || x > boxes[b + 2] + slack || y < boxes[b + 1] - slack || y > boxes[b + 3] + slack) {
|
|
2135
|
+
continue;
|
|
2136
|
+
}
|
|
2137
|
+
const tri = [
|
|
2138
|
+
indices[t * 3],
|
|
2139
|
+
indices[t * 3 + 1],
|
|
2140
|
+
indices[t * 3 + 2]
|
|
2141
|
+
];
|
|
2142
|
+
const w = locate(rest, tri, x, y);
|
|
2143
|
+
if (w) return { tri, w };
|
|
2144
|
+
}
|
|
2145
|
+
return null;
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
function landLocated(posed, at) {
|
|
2149
|
+
if (at === null) return null;
|
|
2150
|
+
let px2 = 0;
|
|
2151
|
+
let py = 0;
|
|
2152
|
+
for (let k = 0; k < 3; k++) {
|
|
2153
|
+
px2 += at.w[k] * posed[at.tri[k] * 2];
|
|
2154
|
+
py += at.w[k] * posed[at.tri[k] * 2 + 1];
|
|
2155
|
+
}
|
|
2156
|
+
return [px2, py];
|
|
2157
|
+
}
|
|
2158
|
+
function landPoints(model, cache, partId, points, pose) {
|
|
2159
|
+
const located = locatePoints(restMesh(model, cache, partId), points);
|
|
2160
|
+
const posed = toCanvas(model, landParts(model, pose, [partId]).get(partId));
|
|
2161
|
+
return located.map((at) => landLocated(posed, at));
|
|
2162
|
+
}
|
|
2163
|
+
function invalid(i, field, what) {
|
|
2164
|
+
return new AutoRigInputError(`queries[${i}].${field} ${what}`);
|
|
2165
|
+
}
|
|
2166
|
+
function checkPoints(i, points) {
|
|
2167
|
+
if (!Array.isArray(points) || points.length === 0) {
|
|
2168
|
+
throw invalid(i, "points", "must be a non-empty list of [x, y]");
|
|
2169
|
+
}
|
|
2170
|
+
if (points.length > MAX_PROBE_POINTS) {
|
|
2171
|
+
throw invalid(
|
|
2172
|
+
i,
|
|
2173
|
+
"points",
|
|
2174
|
+
`has ${points.length} points; at most ${MAX_PROBE_POINTS} per query`
|
|
2175
|
+
);
|
|
2176
|
+
}
|
|
2177
|
+
points.forEach((pt, k) => {
|
|
2178
|
+
if (!Array.isArray(pt) || pt.length !== 2 || !pt.every((v) => Number.isFinite(v))) {
|
|
2179
|
+
throw invalid(i, `points[${k}]`, "must be [x, y] with finite numbers");
|
|
2180
|
+
}
|
|
2181
|
+
});
|
|
2182
|
+
return points;
|
|
2183
|
+
}
|
|
2184
|
+
function checkPose(model, i, pose) {
|
|
2185
|
+
const declared = new Set(model.parameters.map((p) => p.id));
|
|
2186
|
+
for (const [id, v] of Object.entries(pose ?? {})) {
|
|
2187
|
+
if (!declared.has(id)) {
|
|
2188
|
+
throw invalid(i, `pose.${id}`, "is not a parameter the model declares");
|
|
2189
|
+
}
|
|
2190
|
+
if (typeof v !== "number" || !Number.isFinite(v)) {
|
|
2191
|
+
throw invalid(i, `pose.${id}`, "must be a finite number");
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
return pose ?? {};
|
|
2195
|
+
}
|
|
2196
|
+
function checkQuery(model, q, i) {
|
|
2197
|
+
if (q.op === "paint") return { op: "paint", path: q.path };
|
|
2198
|
+
if (q.op !== "land" && q.op !== "displacement") {
|
|
2199
|
+
throw invalid(i, "op", `must be paint, land or displacement`);
|
|
2200
|
+
}
|
|
2201
|
+
if (!model.parts.some((p) => p.id === q.part)) {
|
|
2202
|
+
throw invalid(i, "part", `names no part of the model: ${String(q.part)}`);
|
|
2203
|
+
}
|
|
2204
|
+
return {
|
|
2205
|
+
op: q.op,
|
|
2206
|
+
part: q.part,
|
|
2207
|
+
points: checkPoints(i, q.points),
|
|
2208
|
+
pose: checkPose(model, i, q.pose)
|
|
2209
|
+
};
|
|
2210
|
+
}
|
|
2211
|
+
async function runQuery(model, cache, q, i) {
|
|
2212
|
+
if (q.op === "paint") {
|
|
2213
|
+
const file = resolveInputPath(q.path, `queries[${i}].path`);
|
|
2214
|
+
let png;
|
|
2215
|
+
try {
|
|
2216
|
+
png = await decodePng(file);
|
|
2217
|
+
} catch (e) {
|
|
2218
|
+
if (e instanceof AutoRigInputError) throw invalid(i, "path", e.message);
|
|
2219
|
+
throw e;
|
|
2220
|
+
}
|
|
2221
|
+
const { width, height } = model.canvas;
|
|
2222
|
+
if (png.width !== width || png.height !== height) {
|
|
2223
|
+
throw invalid(
|
|
2224
|
+
i,
|
|
2225
|
+
"path",
|
|
2226
|
+
`is ${png.width}x${png.height}, not the model's canvas ${width}x${height}: ${q.path}`
|
|
2227
|
+
);
|
|
2228
|
+
}
|
|
2229
|
+
return { op: "paint", ...paintRuns(png) };
|
|
2230
|
+
}
|
|
2231
|
+
const { points } = q;
|
|
2232
|
+
const landed = landPoints(model, cache, q.part, points, q.pose);
|
|
2233
|
+
return {
|
|
2234
|
+
op: q.op,
|
|
2235
|
+
part: q.part,
|
|
2236
|
+
points: landed.map(
|
|
2237
|
+
(l, k) => l === null ? null : q.op === "land" ? [round(l[0]), round(l[1])] : [round(l[0] - points[k][0]), round(l[1] - points[k][1])]
|
|
2238
|
+
)
|
|
2239
|
+
};
|
|
2240
|
+
}
|
|
2241
|
+
function summarize(r, i) {
|
|
2242
|
+
if (r.op === "paint") {
|
|
2243
|
+
return `${i} paint: ${r.rows.length} rows from y ${r.y0}`;
|
|
2244
|
+
}
|
|
2245
|
+
const off = r.points.filter((p) => p === null).length;
|
|
2246
|
+
return `${i} ${r.op} ${r.part}: ${r.points.length} points, ${off} off the mesh`;
|
|
2247
|
+
}
|
|
2248
|
+
async function probeRig(input) {
|
|
2249
|
+
try {
|
|
2250
|
+
const outFile = input.outputPath !== void 0 ? resolveOutputPath(input.outputPath, OUTPUT_SUFFIX) : void 0;
|
|
2251
|
+
const modelFile = confineToWorkingDirectory(
|
|
2252
|
+
process.cwd(),
|
|
2253
|
+
resolveInputPath(input.modelPath, "model"),
|
|
2254
|
+
"model path",
|
|
2255
|
+
input.modelPath
|
|
2256
|
+
);
|
|
2257
|
+
const model = (0, import_format8.loadIkiModel)((0, import_node_fs2.readFileSync)(modelFile, "utf8"));
|
|
2258
|
+
if (!Array.isArray(input.queries) || input.queries.length === 0) {
|
|
2259
|
+
throw new AutoRigInputError("queries must be a non-empty list");
|
|
2260
|
+
}
|
|
2261
|
+
if (input.queries.length > MAX_PROBE_QUERIES) {
|
|
2262
|
+
throw new AutoRigInputError(
|
|
2263
|
+
`queries has ${input.queries.length} entries; at most ${MAX_PROBE_QUERIES} per call`
|
|
2264
|
+
);
|
|
2265
|
+
}
|
|
2266
|
+
const checked = input.queries.map((q, i) => checkQuery(model, q, i));
|
|
2267
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2268
|
+
const results = [];
|
|
2269
|
+
for (const [i, q] of checked.entries()) {
|
|
2270
|
+
results.push(await runQuery(model, cache, q, i));
|
|
2271
|
+
}
|
|
2272
|
+
if (outFile === void 0) return { ok: true, results };
|
|
2273
|
+
writeFileAtomic(outFile, JSON.stringify(results));
|
|
2274
|
+
return {
|
|
2275
|
+
ok: true,
|
|
2276
|
+
outputPath: outFile,
|
|
2277
|
+
lines: results.map(summarize)
|
|
2278
|
+
};
|
|
2279
|
+
} catch (e) {
|
|
2280
|
+
if (e instanceof AutoRigInputError || e instanceof import_format8.IkiFormatError) {
|
|
2281
|
+
return { ok: false, error: e.message };
|
|
2282
|
+
}
|
|
2283
|
+
throw e;
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2287
|
+
// src/custom-gate.ts
|
|
2288
|
+
var CUSTOM_GATE_LIMITS = {
|
|
2289
|
+
tie: 5e-3,
|
|
2290
|
+
slide: 0.1,
|
|
2291
|
+
onAnchor: 0.015,
|
|
2292
|
+
exposed: 9e-4,
|
|
2293
|
+
rigid: 25e-4
|
|
2294
|
+
};
|
|
2295
|
+
function foldLimit(model) {
|
|
2296
|
+
return checkFolds(model, { poses: [] }).thresholds.collapse;
|
|
2297
|
+
}
|
|
2298
|
+
function failedCustomGate(model, error) {
|
|
2299
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2300
|
+
return {
|
|
2301
|
+
ok: false,
|
|
2302
|
+
faceWidth: model.parts.find((p) => p.id === "face")?.width ?? 0,
|
|
2303
|
+
limits: { ...CUSTOM_GATE_LIMITS, fold: foldLimit(model) },
|
|
2304
|
+
poses: 0,
|
|
2305
|
+
parts: [],
|
|
2306
|
+
failed: [`gate error: ${message}`]
|
|
2307
|
+
};
|
|
2308
|
+
}
|
|
2309
|
+
function readingOf(faceWidth, amount, dimension, pose, limit, reason) {
|
|
2310
|
+
const value = amount === null ? null : amount / faceWidth ** dimension;
|
|
2311
|
+
const pass = value !== null && value <= limit;
|
|
2312
|
+
return {
|
|
2313
|
+
value,
|
|
2314
|
+
...dimension === 1 ? { px: amount } : { px2: amount },
|
|
2315
|
+
pose,
|
|
2316
|
+
limit,
|
|
2317
|
+
pass,
|
|
2318
|
+
...pass ? {} : { reason }
|
|
2319
|
+
};
|
|
2320
|
+
}
|
|
2321
|
+
var TWIN_FACE = 402;
|
|
2322
|
+
var RING_PX = 5;
|
|
2323
|
+
var RING_DIAGONAL_PX = 4;
|
|
2324
|
+
var SAMPLE_REACH_PX = 80;
|
|
2325
|
+
var SAMPLE_STEP_PX = 4;
|
|
2326
|
+
var TIP_INSET_PX = 6;
|
|
2327
|
+
var EXPOSED_REACH = 0.15;
|
|
2328
|
+
var runsAt = (paint, y) => paint.rows[y - paint.y0] ?? [];
|
|
2329
|
+
function paintedAt(paint, x, y) {
|
|
2330
|
+
const px2 = Math.floor(x);
|
|
2331
|
+
return runsAt(paint, Math.floor(y)).some(([a, b]) => px2 >= a && px2 < b);
|
|
2332
|
+
}
|
|
2333
|
+
var GRID_CELLS = 64;
|
|
2334
|
+
function triangleGrid(posed, indices, bounds) {
|
|
2335
|
+
const cell = Math.max(
|
|
2336
|
+
16,
|
|
2337
|
+
(bounds.x1 - bounds.x0) / GRID_CELLS,
|
|
2338
|
+
(bounds.y1 - bounds.y0) / GRID_CELLS
|
|
2339
|
+
);
|
|
2340
|
+
const cols = Math.floor((bounds.x1 - bounds.x0) / cell) + 1;
|
|
2341
|
+
const rows = Math.floor((bounds.y1 - bounds.y0) / cell) + 1;
|
|
2342
|
+
const bins = /* @__PURE__ */ new Map();
|
|
2343
|
+
for (let t = 0; t < indices.length / 3; t++) {
|
|
2344
|
+
let x0 = Infinity;
|
|
2345
|
+
let y0 = Infinity;
|
|
2346
|
+
let x1 = -Infinity;
|
|
2347
|
+
let y1 = -Infinity;
|
|
2348
|
+
for (let k = 0; k < 3; k++) {
|
|
2349
|
+
const v = indices[t * 3 + k];
|
|
2350
|
+
x0 = Math.min(x0, posed[v * 2]);
|
|
2351
|
+
x1 = Math.max(x1, posed[v * 2]);
|
|
2352
|
+
y0 = Math.min(y0, posed[v * 2 + 1]);
|
|
2353
|
+
y1 = Math.max(y1, posed[v * 2 + 1]);
|
|
2354
|
+
}
|
|
2355
|
+
if (x1 < bounds.x0 || x0 > bounds.x1 || y1 < bounds.y0 || y0 > bounds.y1) {
|
|
2356
|
+
continue;
|
|
2357
|
+
}
|
|
2358
|
+
const cx0 = Math.max(0, Math.floor((x0 - bounds.x0) / cell));
|
|
2359
|
+
const cx1 = Math.min(cols - 1, Math.floor((x1 - bounds.x0) / cell));
|
|
2360
|
+
const cy0 = Math.max(0, Math.floor((y0 - bounds.y0) / cell));
|
|
2361
|
+
const cy1 = Math.min(rows - 1, Math.floor((y1 - bounds.y0) / cell));
|
|
2362
|
+
for (let cy = cy0; cy <= cy1; cy++) {
|
|
2363
|
+
for (let cx = cx0; cx <= cx1; cx++) {
|
|
2364
|
+
const k = cx + cy * cols;
|
|
2365
|
+
const bin = bins.get(k);
|
|
2366
|
+
if (bin) bin.push(t);
|
|
2367
|
+
else bins.set(k, [t]);
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
return (x, y) => x < bounds.x0 || y < bounds.y0 || x > bounds.x1 || y > bounds.y1 ? [] : bins.get(
|
|
2372
|
+
Math.floor((x - bounds.x0) / cell) + Math.floor((y - bounds.y0) / cell) * cols
|
|
2373
|
+
) ?? [];
|
|
2374
|
+
}
|
|
2375
|
+
function paintedUnder(posed, mesh, paint, points) {
|
|
2376
|
+
if (points.length === 0) return [];
|
|
2377
|
+
const bounds = { x0: Infinity, y0: Infinity, x1: -Infinity, y1: -Infinity };
|
|
2378
|
+
for (const [x, y] of points) {
|
|
2379
|
+
bounds.x0 = Math.min(bounds.x0, x);
|
|
2380
|
+
bounds.y0 = Math.min(bounds.y0, y);
|
|
2381
|
+
bounds.x1 = Math.max(bounds.x1, x);
|
|
2382
|
+
bounds.y1 = Math.max(bounds.y1, y);
|
|
2383
|
+
}
|
|
2384
|
+
const find = triangleGrid(posed, mesh.indices, bounds);
|
|
2385
|
+
return points.map(([x, y]) => {
|
|
2386
|
+
for (const t of find(x, y)) {
|
|
2387
|
+
const tri = [
|
|
2388
|
+
mesh.indices[t * 3],
|
|
2389
|
+
mesh.indices[t * 3 + 1],
|
|
2390
|
+
mesh.indices[t * 3 + 2]
|
|
2391
|
+
];
|
|
2392
|
+
const w = locate(posed, tri, x, y);
|
|
2393
|
+
if (!w) continue;
|
|
2394
|
+
let rx = 0;
|
|
2395
|
+
let ry = 0;
|
|
2396
|
+
for (let k = 0; k < 3; k++) {
|
|
2397
|
+
rx += w[k] * mesh.rest[tri[k] * 2];
|
|
2398
|
+
ry += w[k] * mesh.rest[tri[k] * 2 + 1];
|
|
2399
|
+
}
|
|
2400
|
+
return paintedAt(paint, rx, ry);
|
|
2401
|
+
}
|
|
2402
|
+
return false;
|
|
2403
|
+
});
|
|
2404
|
+
}
|
|
2405
|
+
function hiddenSide(occlusion, from, direction) {
|
|
2406
|
+
const at = (v) => occlusionAmount(occlusion, v);
|
|
2407
|
+
const rest = at(from);
|
|
2408
|
+
const marks = occlusion.stops.map((s) => s.value).filter((v) => (v - from) * direction > 0).sort((a, b) => (a - b) * direction);
|
|
2409
|
+
const run2 = [from, ...marks];
|
|
2410
|
+
let leaves = null;
|
|
2411
|
+
let full = rest === 1 ? from : null;
|
|
2412
|
+
for (let i = 0; i + 1 < run2.length; i++) {
|
|
2413
|
+
if (leaves === null && at(run2[i + 1]) !== rest) leaves = run2[i];
|
|
2414
|
+
if (full === null && at(run2[i + 1]) === 1) full = run2[i + 1];
|
|
2415
|
+
}
|
|
2416
|
+
return { leaves, full };
|
|
2417
|
+
}
|
|
2418
|
+
function posesOf(model, baked, base) {
|
|
2419
|
+
const byName = new Map(base.map((p) => [p.name, p]));
|
|
2420
|
+
const add = (values) => {
|
|
2421
|
+
const pose = foldPose(values);
|
|
2422
|
+
if (!byName.has(pose.name)) byName.set(pose.name, pose);
|
|
2423
|
+
};
|
|
2424
|
+
const defaults = new Map(model.parameters.map((p) => [p.id, p.default]));
|
|
2425
|
+
for (const [param, stops] of baked) {
|
|
2426
|
+
for (const v of stops) if (v !== defaults.get(param)) add({ [param]: v });
|
|
2427
|
+
}
|
|
2428
|
+
const params = [...baked.keys()];
|
|
2429
|
+
for (let i = 0; i < params.length; i++) {
|
|
2430
|
+
for (let j = i + 1; j < params.length; j++) {
|
|
2431
|
+
for (const a of baked.get(params[i])) {
|
|
2432
|
+
if (a === defaults.get(params[i])) continue;
|
|
2433
|
+
for (const b of baked.get(params[j])) {
|
|
2434
|
+
if (b === defaults.get(params[j])) continue;
|
|
2435
|
+
add({ [params[i]]: a, [params[j]]: b });
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
return [...byName.values()];
|
|
2441
|
+
}
|
|
2442
|
+
function freeEnd(paint, tie, inset) {
|
|
2443
|
+
if (paint.rows.length === 0) return null;
|
|
2444
|
+
const [top, bottom] = [paint.y0, paint.y0 + paint.rows.length - 1];
|
|
2445
|
+
const y = Math.abs(bottom - tie[1]) > Math.abs(top - tie[1]) ? bottom : top;
|
|
2446
|
+
const runs = runsAt(paint, y);
|
|
2447
|
+
if (runs.length === 0) return null;
|
|
2448
|
+
const widest = runs.reduce((a, b) => b[1] - b[0] > a[1] - a[0] ? b : a);
|
|
2449
|
+
return [(widest[0] + widest[1]) / 2, y > tie[1] ? y - inset : y + inset];
|
|
2450
|
+
}
|
|
2451
|
+
function checkCustomGate(model, parts, paints, options = {}) {
|
|
2452
|
+
const face = model.parts.find((p) => p.id === "face");
|
|
2453
|
+
if (face === void 0) throw new Error("custom gate: the model has no face");
|
|
2454
|
+
const faceWidth = face.width;
|
|
2455
|
+
const limits = {
|
|
2456
|
+
...CUSTOM_GATE_LIMITS,
|
|
2457
|
+
fold: foldLimit(model)
|
|
2458
|
+
};
|
|
2459
|
+
if (parts.length === 0) {
|
|
2460
|
+
return {
|
|
2461
|
+
ok: true,
|
|
2462
|
+
faceWidth,
|
|
2463
|
+
limits,
|
|
2464
|
+
poses: 0,
|
|
2465
|
+
parts: [],
|
|
2466
|
+
failed: []
|
|
2467
|
+
};
|
|
2468
|
+
}
|
|
2469
|
+
const scale2 = faceWidth / TWIN_FACE;
|
|
2470
|
+
const px2 = (twin) => Math.max(1, Math.round(twin * scale2));
|
|
2471
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2472
|
+
const turnParam = model.parameters.find(
|
|
2473
|
+
(p) => p.id === import_format9.StandardParameter.AngleX
|
|
2474
|
+
);
|
|
2475
|
+
const turns = (pose) => turnParam !== void 0 && (pose.values[import_format9.StandardParameter.AngleX] ?? turnParam.default) !== turnParam.default;
|
|
2476
|
+
const bakedOf = (id) => {
|
|
2477
|
+
const part = model.parts.find((p) => p.id === id);
|
|
2478
|
+
return new Map(
|
|
2479
|
+
(part.warps ?? []).map((w) => [
|
|
2480
|
+
w.parameter,
|
|
2481
|
+
w.keyforms.map((k) => k.value)
|
|
2482
|
+
])
|
|
2483
|
+
);
|
|
2484
|
+
};
|
|
2485
|
+
const base = options.poses ?? foldPoses(model);
|
|
2486
|
+
const poseSets = parts.map((part) => {
|
|
2487
|
+
if (!model.parts.some((p) => p.id === part.id)) {
|
|
2488
|
+
throw new Error(`custom gate: the model has no part "${part.id}"`);
|
|
2489
|
+
}
|
|
2490
|
+
if (options.poses) return options.poses;
|
|
2491
|
+
const sampledOf = bakedOf(part.id);
|
|
2492
|
+
const occ = model.parts.find((p) => p.id === part.id).occlusion;
|
|
2493
|
+
if (occ !== void 0) {
|
|
2494
|
+
const at = sampledOf.get(occ.parameter) ?? [];
|
|
2495
|
+
sampledOf.set(occ.parameter, [
|
|
2496
|
+
.../* @__PURE__ */ new Set([...at, ...occ.stops.map((s) => s.value)])
|
|
2497
|
+
]);
|
|
2498
|
+
}
|
|
2499
|
+
return posesOf(model, sampledOf, base);
|
|
2500
|
+
});
|
|
2501
|
+
const all = new Map(poseSets.flat().map((p) => [p.name, p]));
|
|
2502
|
+
const reports = parts.map((part, n) => {
|
|
2503
|
+
const poses = poseSets[n];
|
|
2504
|
+
const roleParts = (0, import_editor3.partIdsOfRole)(part.anchor).filter(
|
|
2505
|
+
(id) => model.parts.some((p) => p.id === id)
|
|
2506
|
+
);
|
|
2507
|
+
const anchorId = roleParts.find(
|
|
2508
|
+
(id) => locatePoints(restMesh(model, cache, id), [part.tie])[0] !== null
|
|
2509
|
+
) ?? roleParts[0];
|
|
2510
|
+
const folds = checkFolds(model, { poses });
|
|
2511
|
+
const anchorPart = model.parts.find((p) => p.id === anchorId);
|
|
2512
|
+
if (anchorPart === void 0) {
|
|
2513
|
+
throw new Error(`custom gate: the model has no part "${anchorId}"`);
|
|
2514
|
+
}
|
|
2515
|
+
const ownPaint = paints.get(part.id);
|
|
2516
|
+
const anchorPaint = paints.get(part.anchor);
|
|
2517
|
+
if (ownPaint === void 0 || anchorPaint === void 0) {
|
|
2518
|
+
throw new Error(
|
|
2519
|
+
`custom gate: no paint for "${ownPaint === void 0 ? part.id : part.anchor}"`
|
|
2520
|
+
);
|
|
2521
|
+
}
|
|
2522
|
+
const partMesh = restMesh(model, cache, part.id);
|
|
2523
|
+
const anchorMesh = restMesh(model, cache, anchorId);
|
|
2524
|
+
const length = (amount, pose, limit, reason) => readingOf(faceWidth, amount, 1, pose, limit, reason);
|
|
2525
|
+
const ring = [
|
|
2526
|
+
[0, 0],
|
|
2527
|
+
[px2(RING_PX), 0],
|
|
2528
|
+
[-px2(RING_PX), 0],
|
|
2529
|
+
[0, px2(RING_PX)],
|
|
2530
|
+
[0, -px2(RING_PX)],
|
|
2531
|
+
[px2(RING_DIAGONAL_PX), px2(RING_DIAGONAL_PX)],
|
|
2532
|
+
[-px2(RING_DIAGONAL_PX), px2(RING_DIAGONAL_PX)],
|
|
2533
|
+
[px2(RING_DIAGONAL_PX), -px2(RING_DIAGONAL_PX)],
|
|
2534
|
+
[-px2(RING_DIAGONAL_PX), -px2(RING_DIAGONAL_PX)]
|
|
2535
|
+
].map(([dx, dy]) => [part.tie[0] + dx, part.tie[1] + dy]);
|
|
2536
|
+
const onPart = locatePoints(partMesh, ring);
|
|
2537
|
+
const onAnchor = locatePoints(anchorMesh, ring);
|
|
2538
|
+
const shared = ring.flatMap(
|
|
2539
|
+
(_, i) => onPart[i] && onAnchor[i] ? [i] : []
|
|
2540
|
+
);
|
|
2541
|
+
const reach = px2(SAMPLE_REACH_PX);
|
|
2542
|
+
const step = px2(SAMPLE_STEP_PX);
|
|
2543
|
+
const samples = [];
|
|
2544
|
+
const cx = Math.round(part.tie[0]);
|
|
2545
|
+
const cy = Math.round(part.tie[1]);
|
|
2546
|
+
for (let y = cy - reach; y <= cy + reach; y += step) {
|
|
2547
|
+
const runs = runsAt(anchorPaint, y);
|
|
2548
|
+
for (let x = cx - reach; x <= cx + reach; x += step) {
|
|
2549
|
+
if (runs.some(([a, b]) => x >= a && x < b))
|
|
2550
|
+
samples.push([x + 0.5, y + 0.5]);
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
const samplesOn = locatePoints(anchorMesh, samples).filter(
|
|
2554
|
+
(l) => l !== null
|
|
2555
|
+
);
|
|
2556
|
+
const [tieOnPart] = locatePoints(partMesh, [part.tie]);
|
|
2557
|
+
const partIndex = model.parts.findIndex((p) => p.id === part.id);
|
|
2558
|
+
const anchorIndex = model.parts.indexOf(anchorPart);
|
|
2559
|
+
const ownPart = model.parts[partIndex];
|
|
2560
|
+
const partLower = ownPart.order < anchorPart.order || ownPart.order === anchorPart.order && partIndex < anchorIndex;
|
|
2561
|
+
const [lowerId, upperId] = partLower ? [part.id, anchorId] : [anchorId, part.id];
|
|
2562
|
+
const [lowerMesh, upperMesh] = [
|
|
2563
|
+
restMesh(model, cache, lowerId),
|
|
2564
|
+
restMesh(model, cache, upperId)
|
|
2565
|
+
];
|
|
2566
|
+
const upperPaint = partLower ? anchorPaint : ownPaint;
|
|
2567
|
+
const exposedReach = Math.round(EXPOSED_REACH * faceWidth);
|
|
2568
|
+
const hidden = [];
|
|
2569
|
+
for (let y = Math.floor(part.tie[1]) - exposedReach; y <= Math.ceil(part.tie[1]) + exposedReach; y++) {
|
|
2570
|
+
for (const [a0, a1] of runsAt(ownPaint, y)) {
|
|
2571
|
+
for (const [b0, b1] of runsAt(anchorPaint, y)) {
|
|
2572
|
+
for (let x = Math.max(a0, b0); x < Math.min(a1, b1); x++) {
|
|
2573
|
+
if (Math.hypot(x + 0.5 - part.tie[0], y + 0.5 - part.tie[1]) <= exposedReach) {
|
|
2574
|
+
hidden.push([x + 0.5, y + 0.5]);
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
const onAnchorMesh = locatePoints(anchorMesh, hidden);
|
|
2581
|
+
const hiddenOn = locatePoints(lowerMesh, hidden).filter(
|
|
2582
|
+
(l, i) => l !== null && onAnchorMesh[i] !== null
|
|
2583
|
+
);
|
|
2584
|
+
const occlusion = ownPart.occlusion;
|
|
2585
|
+
const coverParts = [];
|
|
2586
|
+
if (occlusion !== void 0) {
|
|
2587
|
+
for (const role of part.occludedBy ?? []) {
|
|
2588
|
+
for (const id of (0, import_editor3.partIdsOfRole)(role)) {
|
|
2589
|
+
const o = model.parts.find((p) => p.id === id);
|
|
2590
|
+
if (o === void 0 || !occlusion.by.includes(id)) continue;
|
|
2591
|
+
const steady = o.color[3] === 1 && (o.transform.opacity ?? 1) >= 1 && !(o.bindings ?? []).some((b) => b.channel === "opacity");
|
|
2592
|
+
if (!steady) continue;
|
|
2593
|
+
const paint = paints.get(role);
|
|
2594
|
+
if (paint === void 0) {
|
|
2595
|
+
throw new Error(`custom gate: no paint for "${role}"`);
|
|
2596
|
+
}
|
|
2597
|
+
coverParts.push({ id, mesh: restMesh(model, cache, id), paint });
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
const coverIds = new Set(coverParts.map((c) => c.id));
|
|
2602
|
+
const keyParam = occlusion === void 0 ? void 0 : model.parameters.find((p) => p.id === occlusion.parameter);
|
|
2603
|
+
const keyOf = (values) => Math.min(
|
|
2604
|
+
keyParam.max,
|
|
2605
|
+
Math.max(keyParam.min, values[keyParam.id] ?? keyParam.default)
|
|
2606
|
+
);
|
|
2607
|
+
const sampled = keyParam === void 0 ? [] : [
|
|
2608
|
+
.../* @__PURE__ */ new Set([
|
|
2609
|
+
keyParam.default,
|
|
2610
|
+
...poses.map((p) => keyOf(p.values))
|
|
2611
|
+
])
|
|
2612
|
+
].sort((a, b) => a - b);
|
|
2613
|
+
const fullyHidden = (lo, hi) => occlusion.stops.every(
|
|
2614
|
+
(st) => st.value <= lo || st.value >= hi || st.amount === 1
|
|
2615
|
+
) && occlusionAmount(occlusion, lo) === 1 && occlusionAmount(occlusion, hi) === 1;
|
|
2616
|
+
const hiddenAt = (v) => fullyHidden(
|
|
2617
|
+
sampled.filter((x) => x < v).at(-1) ?? v,
|
|
2618
|
+
sampled.find((x) => x > v) ?? v
|
|
2619
|
+
);
|
|
2620
|
+
let leftOut = 0;
|
|
2621
|
+
let leftOutTurning = 0;
|
|
2622
|
+
let readNoTurn = 0;
|
|
2623
|
+
const stops = bakedOf(part.id);
|
|
2624
|
+
const worstOf = {
|
|
2625
|
+
tie: { v: -1, pose: "rest" },
|
|
2626
|
+
slide: { v: -1, pose: "rest" },
|
|
2627
|
+
onAnchor: { v: -1, pose: "rest" },
|
|
2628
|
+
exposed: { v: -1, pose: "rest" },
|
|
2629
|
+
exposedTurn: { v: -1, pose: "rest" },
|
|
2630
|
+
rigid: { v: -1, pose: "rest" }
|
|
2631
|
+
};
|
|
2632
|
+
const keep = (w, v, pose) => {
|
|
2633
|
+
if (v > w.v) {
|
|
2634
|
+
w.v = v;
|
|
2635
|
+
w.pose = pose;
|
|
2636
|
+
}
|
|
2637
|
+
};
|
|
2638
|
+
let onAnchorNull = null;
|
|
2639
|
+
let turningPoses = 0;
|
|
2640
|
+
const rest = partMesh.rest;
|
|
2641
|
+
const restPoints = [];
|
|
2642
|
+
for (let i = 0; i < rest.length; i += 2)
|
|
2643
|
+
restPoints.push([rest[i], rest[i + 1]]);
|
|
2644
|
+
const measureRigid = (pose, posed) => {
|
|
2645
|
+
const moved = [];
|
|
2646
|
+
for (let i = 0; i < posed.length; i += 2)
|
|
2647
|
+
moved.push([posed[i], posed[i + 1]]);
|
|
2648
|
+
keep(worstOf.rigid, (0, import_editor3.rigidResidual)(restPoints, moved), pose.name);
|
|
2649
|
+
};
|
|
2650
|
+
for (const pose of poses) {
|
|
2651
|
+
const hiding = occlusion !== void 0 && hiddenAt(keyOf(pose.values));
|
|
2652
|
+
const landed = landParts(model, pose.values, [
|
|
2653
|
+
.../* @__PURE__ */ new Set([
|
|
2654
|
+
part.id,
|
|
2655
|
+
anchorId,
|
|
2656
|
+
...hiding && coverIds.size > 0 ? coverIds : []
|
|
2657
|
+
])
|
|
2658
|
+
]);
|
|
2659
|
+
const partPosed = toCanvas(model, landed.get(part.id));
|
|
2660
|
+
const anchorPosed = toCanvas(model, landed.get(anchorId));
|
|
2661
|
+
const canvasOf = /* @__PURE__ */ new Map();
|
|
2662
|
+
const underCover = (points, skip) => {
|
|
2663
|
+
const covered = points.map(() => false);
|
|
2664
|
+
if (!hiding) return covered;
|
|
2665
|
+
for (const c of coverParts) {
|
|
2666
|
+
if (c.id === skip) continue;
|
|
2667
|
+
let posed = canvasOf.get(c.id);
|
|
2668
|
+
if (posed === void 0) {
|
|
2669
|
+
posed = toCanvas(model, landed.get(c.id));
|
|
2670
|
+
canvasOf.set(c.id, posed);
|
|
2671
|
+
}
|
|
2672
|
+
const under = paintedUnder(posed, c.mesh, c.paint, points);
|
|
2673
|
+
under.forEach((u, i) => {
|
|
2674
|
+
if (u) covered[i] = true;
|
|
2675
|
+
});
|
|
2676
|
+
}
|
|
2677
|
+
return covered;
|
|
2678
|
+
};
|
|
2679
|
+
const turning = turns(pose);
|
|
2680
|
+
const ringLands = onPart.map(
|
|
2681
|
+
(l) => l === null ? null : landLocated(partPosed, l)
|
|
2682
|
+
);
|
|
2683
|
+
const ringHidden = hiding && ringLands.every((p) => p !== null) && underCover(ringLands).every(Boolean);
|
|
2684
|
+
if (ringHidden) {
|
|
2685
|
+
leftOut++;
|
|
2686
|
+
if (turning) leftOutTurning++;
|
|
2687
|
+
} else if (turning) turningPoses++;
|
|
2688
|
+
else readNoTurn++;
|
|
2689
|
+
let gap = 0;
|
|
2690
|
+
for (const i of shared) {
|
|
2691
|
+
const a = landLocated(partPosed, onPart[i]);
|
|
2692
|
+
const b = landLocated(anchorPosed, onAnchor[i]);
|
|
2693
|
+
gap = Math.max(gap, Math.hypot(a[0] - b[0], a[1] - b[1]));
|
|
2694
|
+
}
|
|
2695
|
+
if (shared.length > 0 && !ringHidden) {
|
|
2696
|
+
keep(turning ? worstOf.slide : worstOf.tie, gap, pose.name);
|
|
2697
|
+
}
|
|
2698
|
+
if (turning && !ringHidden) {
|
|
2699
|
+
const at = landLocated(partPosed, tieOnPart);
|
|
2700
|
+
let nearest = null;
|
|
2701
|
+
if (at !== null) {
|
|
2702
|
+
for (const l of samplesOn) {
|
|
2703
|
+
const q = landLocated(anchorPosed, l);
|
|
2704
|
+
const d = Math.hypot(q[0] - at[0], q[1] - at[1]);
|
|
2705
|
+
if (nearest === null || d < nearest) nearest = d;
|
|
2706
|
+
}
|
|
2707
|
+
}
|
|
2708
|
+
if (nearest === null) onAnchorNull ??= pose.name;
|
|
2709
|
+
else keep(worstOf.onAnchor, nearest, pose.name);
|
|
2710
|
+
}
|
|
2711
|
+
if (hiddenOn.length > 0) {
|
|
2712
|
+
const lowerPosed = lowerId === part.id ? partPosed : anchorPosed;
|
|
2713
|
+
const upperPosed = upperId === part.id ? partPosed : anchorPosed;
|
|
2714
|
+
const lands = hiddenOn.map((l) => landLocated(lowerPosed, l));
|
|
2715
|
+
const underUpper = paintedUnder(
|
|
2716
|
+
upperPosed,
|
|
2717
|
+
upperMesh,
|
|
2718
|
+
upperPaint,
|
|
2719
|
+
lands
|
|
2720
|
+
);
|
|
2721
|
+
const underHider = coverIds.has(lowerId) ? lands.map(() => hiding) : underCover(lands, upperId);
|
|
2722
|
+
let showing = 0;
|
|
2723
|
+
lands.forEach((_, i) => {
|
|
2724
|
+
if (!underUpper[i] && !underHider[i]) showing++;
|
|
2725
|
+
});
|
|
2726
|
+
keep(
|
|
2727
|
+
turning ? worstOf.exposedTurn : worstOf.exposed,
|
|
2728
|
+
showing,
|
|
2729
|
+
pose.name
|
|
2730
|
+
);
|
|
2731
|
+
}
|
|
2732
|
+
if (part.rigid) measureRigid(pose, partPosed);
|
|
2733
|
+
}
|
|
2734
|
+
if (part.rigid) {
|
|
2735
|
+
for (const [param, values] of stops) {
|
|
2736
|
+
const def = model.parameters.find((p) => p.id === param).default;
|
|
2737
|
+
const sorted = [.../* @__PURE__ */ new Set([...values, def])].sort((a, b) => a - b);
|
|
2738
|
+
for (let i = 0; i + 1 < sorted.length; i++) {
|
|
2739
|
+
const mid = foldPose({ [param]: (sorted[i] + sorted[i + 1]) / 2 });
|
|
2740
|
+
const posed = landParts(model, mid.values, [part.id]).get(part.id);
|
|
2741
|
+
measureRigid(mid, toCanvas(model, posed));
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
1884
2744
|
}
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
2745
|
+
const tieReading = shared.length === 0 ? length(
|
|
2746
|
+
null,
|
|
2747
|
+
"rest",
|
|
2748
|
+
limits.tie,
|
|
2749
|
+
`no point of the ring around the tie lies on both ${part.id} and ${anchorId}`
|
|
2750
|
+
) : length(
|
|
2751
|
+
Math.max(0, worstOf.tie.v),
|
|
2752
|
+
worstOf.tie.pose,
|
|
2753
|
+
limits.tie,
|
|
2754
|
+
"the tie comes apart"
|
|
2755
|
+
);
|
|
2756
|
+
const slideReading = length(
|
|
2757
|
+
Math.max(0, worstOf.slide.v),
|
|
2758
|
+
worstOf.slide.pose,
|
|
2759
|
+
limits.slide,
|
|
2760
|
+
"the tie slides too far"
|
|
2761
|
+
);
|
|
2762
|
+
const onAnchorReading = onAnchorNull !== null ? length(
|
|
2763
|
+
null,
|
|
2764
|
+
onAnchorNull,
|
|
2765
|
+
limits.onAnchor,
|
|
2766
|
+
`the tie lands off ${part.id}'s mesh, or no painted point of ${anchorId} near it is on its mesh`
|
|
2767
|
+
) : length(
|
|
2768
|
+
Math.max(0, worstOf.onAnchor.v),
|
|
2769
|
+
worstOf.onAnchor.pose,
|
|
2770
|
+
limits.onAnchor,
|
|
2771
|
+
`the tie leaves ${anchorId}'s paint`
|
|
2772
|
+
);
|
|
2773
|
+
const exposedReading = readingOf(
|
|
2774
|
+
faceWidth,
|
|
2775
|
+
Math.max(0, worstOf.exposed.v),
|
|
2776
|
+
2,
|
|
2777
|
+
worstOf.exposed.pose,
|
|
2778
|
+
limits.exposed,
|
|
2779
|
+
"hidden art shows"
|
|
2780
|
+
);
|
|
2781
|
+
const ratioHit = folds.targets.find(
|
|
2782
|
+
(t) => t.target.kind === "part" && t.target.id === part.id
|
|
2783
|
+
)?.worst;
|
|
2784
|
+
const ratio = ratioHit?.ratio ?? 1;
|
|
2785
|
+
const foldsPass = ratio >= limits.fold;
|
|
2786
|
+
const rigidReading = part.rigid ? length(
|
|
2787
|
+
Math.max(0, worstOf.rigid.v),
|
|
2788
|
+
worstOf.rigid.pose,
|
|
2789
|
+
limits.rigid,
|
|
2790
|
+
"the part bends"
|
|
2791
|
+
) : void 0;
|
|
2792
|
+
const tipAt = freeEnd(ownPaint, part.tie, px2(TIP_INSET_PX));
|
|
2793
|
+
const [tipLoc] = tipAt === null ? [null] : locatePoints(partMesh, [tipAt]);
|
|
2794
|
+
const bareModel = stops.size === 0 ? model : {
|
|
2795
|
+
...model,
|
|
2796
|
+
parts: model.parts.map(
|
|
2797
|
+
(p) => p.id === part.id ? { ...p, warps: void 0 } : p
|
|
2798
|
+
)
|
|
2799
|
+
};
|
|
2800
|
+
const tip = [...stops.keys()].map((param) => {
|
|
2801
|
+
const def = model.parameters.find((p) => p.id === param);
|
|
2802
|
+
const ends = [def.min, def.max].map((value) => {
|
|
2803
|
+
const at = (m) => landLocated(
|
|
2804
|
+
toCanvas(
|
|
2805
|
+
m,
|
|
2806
|
+
landParts(m, { [param]: value }, [part.id]).get(part.id)
|
|
2807
|
+
),
|
|
2808
|
+
tipLoc ?? null
|
|
2809
|
+
);
|
|
2810
|
+
const landed = at(model);
|
|
2811
|
+
const bare = at(bareModel);
|
|
2812
|
+
return {
|
|
2813
|
+
value,
|
|
2814
|
+
landed,
|
|
2815
|
+
bare,
|
|
2816
|
+
fromBare: landed && bare ? Math.hypot(landed[0] - bare[0], landed[1] - bare[1]) : null
|
|
2817
|
+
};
|
|
2818
|
+
});
|
|
2819
|
+
const [a, b] = ends;
|
|
2820
|
+
return {
|
|
2821
|
+
param,
|
|
2822
|
+
ends,
|
|
2823
|
+
travel: a.landed && b.landed ? Math.hypot(b.landed[0] - a.landed[0], b.landed[1] - a.landed[1]) : null
|
|
2824
|
+
};
|
|
2825
|
+
});
|
|
2826
|
+
const turningExposed = worstOf.exposedTurn.v < 0 ? null : (({ value, px2: px22, pose }) => ({ value, px2: px22, pose }))(
|
|
2827
|
+
readingOf(
|
|
2828
|
+
faceWidth,
|
|
2829
|
+
worstOf.exposedTurn.v,
|
|
2830
|
+
2,
|
|
2831
|
+
worstOf.exposedTurn.pose,
|
|
2832
|
+
Infinity,
|
|
2833
|
+
""
|
|
2834
|
+
)
|
|
2835
|
+
);
|
|
2836
|
+
const slidePass = slideReading.pass && onAnchorReading.pass;
|
|
2837
|
+
const ok = foldsPass && tieReading.pass && slidePass && exposedReading.pass && (rigidReading?.pass ?? true);
|
|
2838
|
+
return {
|
|
2839
|
+
id: part.id,
|
|
2840
|
+
anchor: part.anchor,
|
|
2841
|
+
folds: {
|
|
2842
|
+
ratio,
|
|
2843
|
+
pose: ratioHit?.pose.name ?? "rest",
|
|
2844
|
+
limit: limits.fold,
|
|
2845
|
+
pass: foldsPass,
|
|
2846
|
+
...foldsPass ? {} : { reason: ratio <= 0 ? "a flip" : "a collapse" }
|
|
2847
|
+
},
|
|
2848
|
+
tie: tieReading,
|
|
2849
|
+
slide: {
|
|
2850
|
+
slide: slideReading,
|
|
2851
|
+
onAnchor: onAnchorReading,
|
|
2852
|
+
turningPoses,
|
|
2853
|
+
pass: slidePass
|
|
2854
|
+
},
|
|
2855
|
+
exposed: {
|
|
2856
|
+
hiddenPx: hiddenOn.length,
|
|
2857
|
+
noTurn: exposedReading,
|
|
2858
|
+
turning: turningExposed,
|
|
2859
|
+
pass: exposedReading.pass
|
|
2860
|
+
},
|
|
2861
|
+
...rigidReading === void 0 ? {} : { rigid: rigidReading },
|
|
2862
|
+
tip,
|
|
2863
|
+
...occlusion === void 0 ? {} : {
|
|
2864
|
+
hidden: {
|
|
2865
|
+
by: occlusion.by,
|
|
2866
|
+
cover: [...coverIds],
|
|
2867
|
+
parameter: occlusion.parameter,
|
|
2868
|
+
default: keyParam.default,
|
|
2869
|
+
atRest: occlusionAmount(occlusion, keyParam.default),
|
|
2870
|
+
below: hiddenSide(occlusion, keyParam.default, -1),
|
|
2871
|
+
above: hiddenSide(occlusion, keyParam.default, 1),
|
|
2872
|
+
leftOut,
|
|
2873
|
+
leftOutTurning,
|
|
2874
|
+
readNoTurn,
|
|
2875
|
+
poses: poses.length
|
|
2876
|
+
}
|
|
2877
|
+
},
|
|
2878
|
+
ok
|
|
2879
|
+
};
|
|
2880
|
+
});
|
|
2881
|
+
const failed = reports.flatMap((r) => [
|
|
2882
|
+
...r.folds.pass ? [] : [`${r.id} FOLDS`],
|
|
2883
|
+
...r.tie.pass ? [] : [`${r.id} TIE`],
|
|
2884
|
+
...r.slide.pass ? [] : [`${r.id} SLIDE`],
|
|
2885
|
+
...r.exposed.pass ? [] : [`${r.id} EXPOSED`],
|
|
2886
|
+
...r.rigid === void 0 || r.rigid.pass ? [] : [`${r.id} RIGID`]
|
|
2887
|
+
]);
|
|
2888
|
+
return {
|
|
2889
|
+
ok: failed.length === 0,
|
|
2890
|
+
faceWidth,
|
|
2891
|
+
limits,
|
|
2892
|
+
poses: all.size,
|
|
2893
|
+
parts: reports,
|
|
2894
|
+
failed
|
|
2895
|
+
};
|
|
2896
|
+
}
|
|
2897
|
+
var both = (faceWidth, px2, digits = 4) => px2 === null ? "off the mesh" : `${px2.toFixed(1)} px (${(px2 / faceWidth).toFixed(digits)} face widths)`;
|
|
2898
|
+
function formatCustomGate(report) {
|
|
2899
|
+
const w = report.faceWidth;
|
|
2900
|
+
const verdict = (pass, reason) => pass ? "pass" : `FAIL: ${reason}`;
|
|
2901
|
+
const limit = (fw) => `${fw} face widths, ${(fw * w).toFixed(1)} px`;
|
|
2902
|
+
const lines = [];
|
|
2903
|
+
for (const r of report.parts) {
|
|
2904
|
+
const at = `CUSTOM ${r.id}`;
|
|
2905
|
+
lines.push(
|
|
2906
|
+
`${at} FOLDS: least triangle area ratio ${r.folds.ratio.toFixed(3)} at [${r.folds.pose}] (limit >= ${r.folds.limit}) ${verdict(r.folds.pass, r.folds.reason)}`
|
|
2907
|
+
);
|
|
2908
|
+
const noTurnLeftOut = r.hidden !== void 0 && r.hidden.readNoTurn === 0 && r.hidden.leftOut > r.hidden.leftOutTurning;
|
|
2909
|
+
lines.push(
|
|
2910
|
+
noTurnLeftOut ? `${at} TIE: every pose that does not turn the head is left out as hidden (see HIDDEN) ${verdict(r.tie.pass, r.tie.reason)}` : `${at} TIE: at the tie and the ring around it, ${r.id} against ${r.anchor}, poses that do not turn the head: max ${both(w, r.tie.px)} at [${r.tie.pose}] (limit <= ${limit(r.tie.limit)}) ${verdict(r.tie.pass, r.tie.reason)}`
|
|
2911
|
+
);
|
|
2912
|
+
const s = r.slide;
|
|
2913
|
+
lines.push(
|
|
2914
|
+
s.turningPoses === 0 ? r.hidden !== void 0 && r.hidden.leftOutTurning > 0 ? `${at} SLIDE: every pose that turns the head is left out as hidden (see HIDDEN) pass` : `${at} SLIDE: no pose turns the head pass` : `${at} SLIDE: poses that turn the head, the same length: max ${both(w, s.slide.px)} at [${s.slide.pose}] (limit <= ${limit(s.slide.limit)}); the tie's distance to the nearest painted point of ${r.anchor} as landed: max ${both(w, s.onAnchor.px)} at [${s.onAnchor.pose}] (limit <= ${limit(s.onAnchor.limit)}) ${verdict(s.pass, s.slide.pass ? s.onAnchor.reason : s.slide.reason)}`
|
|
2915
|
+
);
|
|
2916
|
+
const e = r.exposed;
|
|
2917
|
+
const turnText = e.turning === null ? "no pose turns the head" : `max ${e.turning.px2.toFixed(0)} px\xB2 (${e.turning.value.toFixed(5)} face widths\xB2) at [${e.turning.pose}] (reported, no limit)`;
|
|
2918
|
+
lines.push(
|
|
2919
|
+
`${at} EXPOSED: ${e.hiddenPx} px of art both ${r.id} and ${r.anchor} paint near the tie, the lower one's hidden at rest; showing where the head does not turn: max ${(e.noTurn.px2 ?? 0).toFixed(0)} px\xB2 (${(e.noTurn.value ?? 0).toFixed(5)} face widths\xB2) at [${e.noTurn.pose}] (limit <= ${e.noTurn.limit} face widths\xB2, ${(e.noTurn.limit * w * w).toFixed(0)} px\xB2) ${verdict(e.pass, e.noTurn.reason)}; where it turns: ${turnText}`
|
|
1888
2920
|
);
|
|
2921
|
+
if (r.hidden) {
|
|
2922
|
+
const h = r.hidden;
|
|
2923
|
+
const side = (name, s2) => h.atRest === 1 ? `${name} ${h.default} the amount is 1 at rest and ${s2.leaves === null ? "stays 1" : `leaves it at ${s2.leaves}`}` : `${name} ${h.default} the amount ${s2.leaves === null ? `never leaves ${h.atRest}` : `leaves ${h.atRest} at ${s2.leaves}`} and ${s2.full === null ? "never reaches 1" : `reaches 1 at ${s2.full}`}`;
|
|
2924
|
+
lines.push(
|
|
2925
|
+
`${at} HIDDEN: hidden by ${h.by.join(",")} on ${h.parameter}, cover from ${h.cover.length === 0 ? "none of them" : h.cover.join(",")}${h.cover.length === h.by.length ? "" : " (the rest fade or are roles not passed, and give none)"}; amount ${h.atRest} at rest; ${side("below", h.below)}; ${side("above", h.above)}; left out of TIE and SLIDE: ${h.leftOut} of ${h.poses} poses (reported, no limit)`
|
|
2926
|
+
);
|
|
2927
|
+
}
|
|
2928
|
+
if (r.rigid) {
|
|
2929
|
+
lines.push(
|
|
2930
|
+
`${at} RIGID: bend against rest: max ${both(w, r.rigid.px)} at [${r.rigid.pose}] (limit <= ${limit(r.rigid.limit)}) ${verdict(r.rigid.pass, r.rigid.reason)}`
|
|
2931
|
+
);
|
|
2932
|
+
}
|
|
2933
|
+
for (const t of r.tip) {
|
|
2934
|
+
const ends = t.ends.map(
|
|
2935
|
+
(x) => `${t.param}=${x.value} lands ${x.landed ? `(${x.landed.map((v) => v.toFixed(1)).join(", ")})` : "off the mesh"}, ${x.fromBare === null ? "-" : both(w, x.fromBare)} from where its deformer alone lands it`
|
|
2936
|
+
).join("; ");
|
|
2937
|
+
lines.push(
|
|
2938
|
+
`${at} TIP ${t.param}: free end ${ends}; travel end to end ${t.travel === null ? "-" : both(w, t.travel)} (reported, no limit)`
|
|
2939
|
+
);
|
|
2940
|
+
}
|
|
1889
2941
|
}
|
|
2942
|
+
lines.push(
|
|
2943
|
+
report.ok ? "CUSTOM GATE pass" : `CUSTOM GATE FAIL: ${report.failed.join(", ")}`
|
|
2944
|
+
);
|
|
2945
|
+
return lines;
|
|
1890
2946
|
}
|
|
1891
2947
|
|
|
2948
|
+
// src/render-poses.ts
|
|
2949
|
+
var import_node_fs5 = require("fs");
|
|
2950
|
+
var import_node_path4 = __toESM(require("path"));
|
|
2951
|
+
var import_format10 = require("@ikijs/format");
|
|
2952
|
+
|
|
1892
2953
|
// src/render-browser.ts
|
|
1893
2954
|
var import_node_child_process = require("child_process");
|
|
1894
|
-
var
|
|
2955
|
+
var import_node_fs3 = __toESM(require("fs"));
|
|
1895
2956
|
var import_node_os = __toESM(require("os"));
|
|
1896
2957
|
var import_node_path2 = __toESM(require("path"));
|
|
1897
2958
|
var NO_BROWSER_MESSAGE = "render_poses needs a Chromium-based browser and found none. Install Google Chrome, Microsoft Edge or Chromium, or set CHROME_PATH to its executable.";
|
|
@@ -1918,8 +2979,8 @@ var DEFAULT_TIMEOUT_MS = 3e4;
|
|
|
1918
2979
|
var BROWSER_CLOSE_MS = 1e3;
|
|
1919
2980
|
function isExecutableFile(file) {
|
|
1920
2981
|
try {
|
|
1921
|
-
if (!
|
|
1922
|
-
|
|
2982
|
+
if (!import_node_fs3.default.statSync(file).isFile()) return false;
|
|
2983
|
+
import_node_fs3.default.accessSync(file, import_node_fs3.default.constants.X_OK);
|
|
1923
2984
|
return true;
|
|
1924
2985
|
} catch {
|
|
1925
2986
|
return false;
|
|
@@ -2078,7 +3139,7 @@ async function openPage(cdp, timeoutMs) {
|
|
|
2078
3139
|
}
|
|
2079
3140
|
function removeProfile(profile) {
|
|
2080
3141
|
try {
|
|
2081
|
-
|
|
3142
|
+
import_node_fs3.default.rmSync(profile, {
|
|
2082
3143
|
recursive: true,
|
|
2083
3144
|
force: true,
|
|
2084
3145
|
maxRetries: 5,
|
|
@@ -2094,7 +3155,7 @@ async function launchBrowser(executable, timeoutMs) {
|
|
|
2094
3155
|
"render_poses needs Node 22 or newer (the global WebSocket is missing)."
|
|
2095
3156
|
);
|
|
2096
3157
|
}
|
|
2097
|
-
const profile =
|
|
3158
|
+
const profile = import_node_fs3.default.mkdtempSync(import_node_path2.default.join(import_node_os.default.tmpdir(), "iki-render-"));
|
|
2098
3159
|
let child;
|
|
2099
3160
|
try {
|
|
2100
3161
|
child = (0, import_node_child_process.spawn)(
|
|
@@ -2114,7 +3175,7 @@ async function launchBrowser(executable, timeoutMs) {
|
|
|
2114
3175
|
{ stdio: ["ignore", "ignore", "pipe"] }
|
|
2115
3176
|
);
|
|
2116
3177
|
} catch (error) {
|
|
2117
|
-
|
|
3178
|
+
import_node_fs3.default.rmSync(profile, { recursive: true, force: true });
|
|
2118
3179
|
throw startError(executable, error);
|
|
2119
3180
|
}
|
|
2120
3181
|
let spawnError;
|
|
@@ -2397,13 +3458,13 @@ function formatNodReport(report) {
|
|
|
2397
3458
|
}
|
|
2398
3459
|
|
|
2399
3460
|
// src/sweep.ts
|
|
2400
|
-
var
|
|
3461
|
+
var import_node_fs4 = __toESM(require("fs"));
|
|
2401
3462
|
var import_node_path3 = __toESM(require("path"));
|
|
2402
3463
|
var SWEEP_CLOCK_HZ = 60;
|
|
2403
3464
|
var SWEEP_FPS = 30;
|
|
2404
3465
|
var SWEEP_DURATION_S = 3;
|
|
2405
3466
|
var BOX_DURATION_S = 6;
|
|
2406
|
-
var SWEEP_PRESETS = ["turn", "turn-nod"];
|
|
3467
|
+
var SWEEP_PRESETS = ["turn", "turn-nod", "roll"];
|
|
2407
3468
|
var SWEEP_WARMUP_S = 0.5;
|
|
2408
3469
|
var SWEEP_FRAME_MS = 1e3 / SWEEP_CLOCK_HZ * (1 + 1e-9);
|
|
2409
3470
|
var SHEET_THETAS = [-30, -20, -10, -5, 0, 5, 10, 20, 30];
|
|
@@ -2456,29 +3517,37 @@ function boxAngles(t) {
|
|
|
2456
3517
|
}
|
|
2457
3518
|
return { x: 0, y: 0 };
|
|
2458
3519
|
}
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
}
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
3520
|
+
var legSheet = (id) => (steps, n) => turnSheetFrames(steps, n, id);
|
|
3521
|
+
var SHAPES = {
|
|
3522
|
+
turn: {
|
|
3523
|
+
durationS: SWEEP_DURATION_S,
|
|
3524
|
+
angles: (t) => ({ ParamAngleX: turnTheta(t) }),
|
|
3525
|
+
sheetFrames: legSheet("ParamAngleX"),
|
|
3526
|
+
label: (s) => `\u03B8 ${signedDeg(s.ParamAngleX)}\xB0`,
|
|
3527
|
+
kymograph: true
|
|
3528
|
+
},
|
|
3529
|
+
// The roll rides the turn's own curve, so its frames sit at the angles the
|
|
3530
|
+
// turn sheet's do.
|
|
3531
|
+
roll: {
|
|
3532
|
+
durationS: SWEEP_DURATION_S,
|
|
3533
|
+
angles: (t) => ({ ParamAngleZ: turnTheta(t) }),
|
|
3534
|
+
sheetFrames: legSheet("ParamAngleZ"),
|
|
3535
|
+
label: (s) => `Z ${signedDeg(s.ParamAngleZ)}\xB0`,
|
|
3536
|
+
kymograph: false
|
|
3537
|
+
},
|
|
3538
|
+
"turn-nod": {
|
|
3539
|
+
durationS: BOX_DURATION_S,
|
|
3540
|
+
angles: (t) => {
|
|
3541
|
+
const { x, y } = boxAngles(t);
|
|
2478
3542
|
return { ParamAngleX: x, ParamAngleY: y };
|
|
2479
|
-
}
|
|
2480
|
-
|
|
2481
|
-
}
|
|
3543
|
+
},
|
|
3544
|
+
sheetFrames: boxSheetFrames,
|
|
3545
|
+
label: (s) => `X ${signedDeg(s.ParamAngleX)}\xB0 Y ${signedDeg(s.ParamAngleY)}\xB0`,
|
|
3546
|
+
kymograph: false
|
|
3547
|
+
}
|
|
3548
|
+
};
|
|
3549
|
+
function sweepDurationS(preset) {
|
|
3550
|
+
return SHAPES[preset].durationS;
|
|
2482
3551
|
}
|
|
2483
3552
|
function eyeRowModelPx(model) {
|
|
2484
3553
|
const landed = landParts(model, {}, ["eye_L", "eye_R"]);
|
|
@@ -2504,13 +3573,13 @@ function physicsOutputIds(model) {
|
|
|
2504
3573
|
}
|
|
2505
3574
|
return [...ids];
|
|
2506
3575
|
}
|
|
2507
|
-
function turnSheetFrames(steps, frames) {
|
|
3576
|
+
function turnSheetFrames(steps, frames, id) {
|
|
2508
3577
|
const onLeg = [];
|
|
2509
3578
|
for (let k = 0; k < frames; k++) {
|
|
2510
3579
|
const t = k / SWEEP_FPS;
|
|
2511
3580
|
if (t >= LEG_FROM_S && t <= LEG_TO_S) onLeg.push(k);
|
|
2512
3581
|
}
|
|
2513
|
-
const x = (k) => steps[CAPTURE_EVERY * k]
|
|
3582
|
+
const x = (k) => steps[CAPTURE_EVERY * k][id];
|
|
2514
3583
|
const picked = [];
|
|
2515
3584
|
for (const target2 of SHEET_THETAS) {
|
|
2516
3585
|
let best = onLeg[0];
|
|
@@ -2540,7 +3609,13 @@ function signedDeg(angle) {
|
|
|
2540
3609
|
return rounded > 0 ? `+${deg}` : deg.replace("-", "\u2212");
|
|
2541
3610
|
}
|
|
2542
3611
|
function sweepSpec(model, preset, crop) {
|
|
2543
|
-
const
|
|
3612
|
+
const shape = SHAPES[preset];
|
|
3613
|
+
const { durationS } = shape;
|
|
3614
|
+
const steps = Array.from(
|
|
3615
|
+
{ length: SWEEP_CLOCK_HZ * durationS },
|
|
3616
|
+
(_, j) => shape.angles(j / SWEEP_CLOCK_HZ)
|
|
3617
|
+
);
|
|
3618
|
+
const parameters = Object.keys(steps[0]);
|
|
2544
3619
|
const frameCount = durationS * SWEEP_FPS;
|
|
2545
3620
|
const dw = crop ? crop.dw : BUST_SIZE;
|
|
2546
3621
|
const dh = crop ? crop.dh : BUST_SIZE;
|
|
@@ -2551,15 +3626,11 @@ function sweepSpec(model, preset, crop) {
|
|
|
2551
3626
|
(SHEET_MAX_SIDE - 2 * m) / (3 * dw),
|
|
2552
3627
|
(SHEET_MAX_SIDE - 2 * m - 3 * b) / (3 * dh)
|
|
2553
3628
|
);
|
|
2554
|
-
const frames =
|
|
2555
|
-
const labelOf = (k) => {
|
|
2556
|
-
const s = steps[CAPTURE_EVERY * k];
|
|
2557
|
-
const t = (k / SWEEP_FPS).toFixed(2);
|
|
2558
|
-
return preset === "turn" ? `\u03B8 ${signedDeg(s.ParamAngleX)}\xB0 t ${t} s` : `X ${signedDeg(s.ParamAngleX)}\xB0 Y ${signedDeg(s.ParamAngleY)}\xB0 t ${t} s`;
|
|
2559
|
-
};
|
|
3629
|
+
const frames = shape.sheetFrames(steps, frameCount);
|
|
3630
|
+
const labelOf = (k) => `${shape.label(steps[CAPTURE_EVERY * k])} t ${(k / SWEEP_FPS).toFixed(2)} s`;
|
|
2560
3631
|
const { width: W, height: H } = model.canvas;
|
|
2561
3632
|
let kymograph;
|
|
2562
|
-
if (
|
|
3633
|
+
if (shape.kymograph) {
|
|
2563
3634
|
const yModel = eyeRowModelPx(model);
|
|
2564
3635
|
let row = Math.round(dh / 2);
|
|
2565
3636
|
let at = "middle";
|
|
@@ -2639,7 +3710,7 @@ img { max-width: 48vw; height: auto; background: #444; }
|
|
|
2639
3710
|
scrub.max = String(n - 1);
|
|
2640
3711
|
if (b) { bi.style.display = "block"; }
|
|
2641
3712
|
function short(id) {
|
|
2642
|
-
return id === "ParamAngleX" ? "X" : id === "ParamAngleY" ? "Y" : id;
|
|
3713
|
+
return id === "ParamAngleX" ? "X" : id === "ParamAngleY" ? "Y" : id === "ParamAngleZ" ? "Z" : id;
|
|
2643
3714
|
}
|
|
2644
3715
|
function show(k) {
|
|
2645
3716
|
i = k;
|
|
@@ -2678,13 +3749,13 @@ var STALE_NAMES = [
|
|
|
2678
3749
|
function prepareSweepDir(outDir, name, label) {
|
|
2679
3750
|
const dir = import_node_path3.default.join(outDir, name);
|
|
2680
3751
|
try {
|
|
2681
|
-
|
|
3752
|
+
import_node_fs4.default.mkdirSync(dir);
|
|
2682
3753
|
} catch (e) {
|
|
2683
3754
|
if (e.code !== "EEXIST") {
|
|
2684
3755
|
throw new AutoRigInputError(`sweep dir: ${e.message}`);
|
|
2685
3756
|
}
|
|
2686
3757
|
}
|
|
2687
|
-
const stat =
|
|
3758
|
+
const stat = import_node_fs4.default.lstatSync(dir);
|
|
2688
3759
|
if (stat.isSymbolicLink()) {
|
|
2689
3760
|
throw new AutoRigInputError(`${label}.name names ${dir}, a symbolic link`);
|
|
2690
3761
|
}
|
|
@@ -2694,9 +3765,9 @@ function prepareSweepDir(outDir, name, label) {
|
|
|
2694
3765
|
return confineToWorkingDirectory(process.cwd(), dir, "sweep dir", name);
|
|
2695
3766
|
}
|
|
2696
3767
|
function clearSweepDir(real) {
|
|
2697
|
-
for (const entry of
|
|
3768
|
+
for (const entry of import_node_fs4.default.readdirSync(real)) {
|
|
2698
3769
|
if (STALE_FILE.test(entry) || STALE_NAMES.includes(entry)) {
|
|
2699
|
-
|
|
3770
|
+
import_node_fs4.default.rmSync(import_node_path3.default.join(real, entry));
|
|
2700
3771
|
}
|
|
2701
3772
|
}
|
|
2702
3773
|
}
|
|
@@ -2812,9 +3883,9 @@ function planRenders(model, requested, sweep, sweeps) {
|
|
|
2812
3883
|
}
|
|
2813
3884
|
const bodyAngles = Object.fromEntries(
|
|
2814
3885
|
[
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
3886
|
+
import_format10.StandardParameter.BodyAngleX,
|
|
3887
|
+
import_format10.StandardParameter.BodyAngleY,
|
|
3888
|
+
import_format10.StandardParameter.BodyAngleZ
|
|
2818
3889
|
].filter((id) => model.parameters.some((p) => p.id === id)).map((id) => [id, -10])
|
|
2819
3890
|
);
|
|
2820
3891
|
const poses = [
|
|
@@ -2900,7 +3971,7 @@ function planRenders(model, requested, sweep, sweeps) {
|
|
|
2900
3971
|
whole("full-elbow-r-45", { ParamElbowR: 45 }),
|
|
2901
3972
|
whole("full-elbow-r-90", { ParamElbowR: 90 })
|
|
2902
3973
|
);
|
|
2903
|
-
if (model.parameters.some((p) => p.id ===
|
|
3974
|
+
if (model.parameters.some((p) => p.id === import_format10.StandardParameter.ArmPoseRight)) {
|
|
2904
3975
|
poses.push(
|
|
2905
3976
|
whole("full-pose-l", { ParamArmPoseL: 1 }),
|
|
2906
3977
|
whole("full-pose-r", { ParamArmPoseR: 1 }),
|
|
@@ -2941,6 +4012,33 @@ function checkRequest(requested, i) {
|
|
|
2941
4012
|
}
|
|
2942
4013
|
}
|
|
2943
4014
|
}
|
|
4015
|
+
function withoutParts(model, hideParts) {
|
|
4016
|
+
const hidden = new Set(hideParts);
|
|
4017
|
+
hideParts.forEach((id, i) => {
|
|
4018
|
+
if (!model.parts.some((p) => p.id === id)) {
|
|
4019
|
+
throw new AutoRigInputError(
|
|
4020
|
+
`hideParts[${i}] ${JSON.stringify(id)} is not a part of the model`
|
|
4021
|
+
);
|
|
4022
|
+
}
|
|
4023
|
+
const kept = model.parts.find(
|
|
4024
|
+
(p) => !hidden.has(p.id) && p.clip?.masks.includes(id)
|
|
4025
|
+
);
|
|
4026
|
+
if (kept) {
|
|
4027
|
+
throw new AutoRigInputError(
|
|
4028
|
+
`hideParts[${i}] ${JSON.stringify(id)} masks ${JSON.stringify(kept.id)}, which stays; hide ${JSON.stringify(kept.id)} too`
|
|
4029
|
+
);
|
|
4030
|
+
}
|
|
4031
|
+
const occluded = model.parts.find(
|
|
4032
|
+
(p) => !hidden.has(p.id) && p.occlusion?.by.includes(id)
|
|
4033
|
+
);
|
|
4034
|
+
if (occluded) {
|
|
4035
|
+
throw new AutoRigInputError(
|
|
4036
|
+
`hideParts[${i}] ${JSON.stringify(id)} occludes ${JSON.stringify(occluded.id)}, which stays; hide ${JSON.stringify(occluded.id)} too`
|
|
4037
|
+
);
|
|
4038
|
+
}
|
|
4039
|
+
});
|
|
4040
|
+
return { ...model, parts: model.parts.filter((p) => !hidden.has(p.id)) };
|
|
4041
|
+
}
|
|
2944
4042
|
var PNG_PREFIX = "data:image/png;base64,";
|
|
2945
4043
|
var PAGE_SCRIPT_MS = 1e4;
|
|
2946
4044
|
var LOAD_MS = 6e4;
|
|
@@ -2948,7 +4046,7 @@ var CAPTURE_MS = 15e3;
|
|
|
2948
4046
|
function readPageScript() {
|
|
2949
4047
|
const url = new URL("../dist/render-page.global.js", importMetaUrl);
|
|
2950
4048
|
try {
|
|
2951
|
-
return (0,
|
|
4049
|
+
return (0, import_node_fs5.readFileSync)(url, "utf8");
|
|
2952
4050
|
} catch (cause) {
|
|
2953
4051
|
throw new Error(
|
|
2954
4052
|
"could not read the render page script; run `pnpm build` in packages/mcp",
|
|
@@ -3049,8 +4147,9 @@ async function renderPoses(input) {
|
|
|
3049
4147
|
input.modelPath
|
|
3050
4148
|
);
|
|
3051
4149
|
const outDir = resolveOutputDir(input.outDir);
|
|
3052
|
-
const model = (0,
|
|
4150
|
+
const model = (0, import_format10.loadIkiModel)((0, import_node_fs5.readFileSync)(modelFile, "utf8"));
|
|
3053
4151
|
const plan = planRenders(model, input.poses, input.sweep, input.sweeps);
|
|
4152
|
+
const drawn = input.hideParts ? withoutParts(model, input.hideParts) : model;
|
|
3054
4153
|
const browser = findBrowser();
|
|
3055
4154
|
if (!browser) return { ok: false, error: NO_BROWSER_MESSAGE };
|
|
3056
4155
|
const pageScript = readPageScript();
|
|
@@ -3073,7 +4172,7 @@ async function renderPoses(input) {
|
|
|
3073
4172
|
async (evaluate) => {
|
|
3074
4173
|
await evaluate(pageScript, PAGE_SCRIPT_MS);
|
|
3075
4174
|
const loaded = await evaluate(
|
|
3076
|
-
`window.__ikiRender.load(${JSON.stringify(
|
|
4175
|
+
`window.__ikiRender.load(${JSON.stringify(drawn)}, ${JSON.stringify({ canvas: plan.canvas, view: plan.view })})`,
|
|
3077
4176
|
LOAD_MS
|
|
3078
4177
|
);
|
|
3079
4178
|
const written = [];
|
|
@@ -3141,87 +4240,20 @@ async function renderPoses(input) {
|
|
|
3141
4240
|
sweeps
|
|
3142
4241
|
};
|
|
3143
4242
|
} catch (error) {
|
|
3144
|
-
if (error instanceof AutoRigInputError || error instanceof
|
|
4243
|
+
if (error instanceof AutoRigInputError || error instanceof import_format10.IkiFormatError) {
|
|
3145
4244
|
return { ok: false, error: error.message };
|
|
3146
4245
|
}
|
|
3147
4246
|
throw error;
|
|
3148
4247
|
}
|
|
3149
4248
|
}
|
|
3150
4249
|
|
|
3151
|
-
// src/node-images.ts
|
|
3152
|
-
var import_sharp = __toESM(require("sharp"));
|
|
3153
|
-
var import_editor2 = require("@ikijs/editor");
|
|
3154
|
-
async function decodePng(filePath) {
|
|
3155
|
-
try {
|
|
3156
|
-
const pipeline = (0, import_sharp.default)(filePath, { limitInputPixels: MAX_INPUT_PIXELS });
|
|
3157
|
-
const metadata = await pipeline.metadata();
|
|
3158
|
-
if (metadata.format !== "png") {
|
|
3159
|
-
throw new AutoRigInputError(
|
|
3160
|
-
`non-PNG image (${metadata.format ?? "unknown"}): ${filePath}`
|
|
3161
|
-
);
|
|
3162
|
-
}
|
|
3163
|
-
const { data, info } = await pipeline.ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
3164
|
-
return {
|
|
3165
|
-
width: info.width,
|
|
3166
|
-
height: info.height,
|
|
3167
|
-
rgba: data,
|
|
3168
|
-
hasAlpha: metadata.hasAlpha ?? false
|
|
3169
|
-
};
|
|
3170
|
-
} catch (e) {
|
|
3171
|
-
if (e instanceof AutoRigInputError) throw e;
|
|
3172
|
-
const msg = e instanceof Error ? e.message : String(e);
|
|
3173
|
-
throw new AutoRigInputError(`failed to decode PNG ${filePath}: ${msg}`);
|
|
3174
|
-
}
|
|
3175
|
-
}
|
|
3176
|
-
function detectAlphaBbox(rgba, width, height) {
|
|
3177
|
-
const bbox = (0, import_editor2.detectAlphaBbox)(rgba, width, height);
|
|
3178
|
-
if (bbox === null) {
|
|
3179
|
-
throw new AutoRigInputError("layer is empty after alpha threshold");
|
|
3180
|
-
}
|
|
3181
|
-
return bbox;
|
|
3182
|
-
}
|
|
3183
|
-
function cropToBuffer(rgba, width, height, bbox) {
|
|
3184
|
-
return (0, import_sharp.default)(rgba, { raw: { width, height, channels: 4 } }).extract({ left: bbox.x, top: bbox.y, width: bbox.w, height: bbox.h }).png().toBuffer();
|
|
3185
|
-
}
|
|
3186
|
-
function encodeOverlayPng(filePath, svg) {
|
|
3187
|
-
return (0, import_sharp.default)(filePath, { limitInputPixels: MAX_INPUT_PIXELS }).composite([{ input: Buffer.from(svg) }]).png().toBuffer();
|
|
3188
|
-
}
|
|
3189
|
-
async function renderAtlasToDataUri(crops, layout, quantizeColors) {
|
|
3190
|
-
const byId = /* @__PURE__ */ new Map();
|
|
3191
|
-
for (const crop of crops) byId.set(crop.id, crop);
|
|
3192
|
-
const pad = layout.padding;
|
|
3193
|
-
const composites = await Promise.all(
|
|
3194
|
-
layout.placements.map(async (placement3) => {
|
|
3195
|
-
const crop = byId.get(placement3.id);
|
|
3196
|
-
if (crop === void 0) {
|
|
3197
|
-
throw new AutoRigInputError(
|
|
3198
|
-
`no crop for atlas placement "${placement3.id}"`
|
|
3199
|
-
);
|
|
3200
|
-
}
|
|
3201
|
-
const input = pad > 0 ? await (0, import_sharp.default)(crop.buffer).extend({ right: pad, bottom: pad, extendWith: "copy" }).png().toBuffer() : crop.buffer;
|
|
3202
|
-
return { input, left: placement3.x, top: placement3.y };
|
|
3203
|
-
})
|
|
3204
|
-
);
|
|
3205
|
-
const page = await (0, import_sharp.default)({
|
|
3206
|
-
create: {
|
|
3207
|
-
width: layout.pageWidth,
|
|
3208
|
-
height: layout.pageHeight,
|
|
3209
|
-
channels: 4,
|
|
3210
|
-
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
|
3211
|
-
}
|
|
3212
|
-
}).composite(composites).png(
|
|
3213
|
-
quantizeColors === void 0 ? {} : { palette: true, colours: quantizeColors, dither: 0.5, effort: 10 }
|
|
3214
|
-
).toBuffer();
|
|
3215
|
-
return `data:image/png;base64,${page.toString("base64")}`;
|
|
3216
|
-
}
|
|
3217
|
-
|
|
3218
4250
|
// src/tools.ts
|
|
3219
4251
|
function coerceModel(model) {
|
|
3220
4252
|
try {
|
|
3221
|
-
const parsed = typeof model === "string" ? (0,
|
|
4253
|
+
const parsed = typeof model === "string" ? (0, import_format11.loadIkiModel)(model) : (0, import_format11.parseIkiModel)(model);
|
|
3222
4254
|
return { ok: true, model: parsed };
|
|
3223
4255
|
} catch (e) {
|
|
3224
|
-
if (e instanceof
|
|
4256
|
+
if (e instanceof import_format11.IkiFormatError) return { ok: false, error: e.message };
|
|
3225
4257
|
throw e;
|
|
3226
4258
|
}
|
|
3227
4259
|
}
|
|
@@ -3330,7 +4362,7 @@ function describeIkiAt(modelPath) {
|
|
|
3330
4362
|
"model path",
|
|
3331
4363
|
modelPath
|
|
3332
4364
|
);
|
|
3333
|
-
return describeIki((0,
|
|
4365
|
+
return describeIki((0, import_node_fs6.readFileSync)(modelFile, "utf8"));
|
|
3334
4366
|
} catch (e) {
|
|
3335
4367
|
if (e instanceof AutoRigInputError) return { ok: false, error: e.message };
|
|
3336
4368
|
throw e;
|
|
@@ -3338,123 +4370,123 @@ function describeIkiAt(modelPath) {
|
|
|
3338
4370
|
}
|
|
3339
4371
|
var STANDARD_PARAMETER_INFO = [
|
|
3340
4372
|
{
|
|
3341
|
-
id:
|
|
4373
|
+
id: import_format11.StandardParameter.MouthOpen,
|
|
3342
4374
|
description: "Mouth open amount for lip-sync (0 closed .. 1 open)."
|
|
3343
4375
|
},
|
|
3344
4376
|
{
|
|
3345
|
-
id:
|
|
4377
|
+
id: import_format11.StandardParameter.MouthForm,
|
|
3346
4378
|
description: "Mouth form / smile (-1 .. 1)."
|
|
3347
4379
|
},
|
|
3348
4380
|
{
|
|
3349
|
-
id:
|
|
4381
|
+
id: import_format11.StandardParameter.EyeOpenLeft,
|
|
3350
4382
|
description: "Left eye open (0 closed .. 1 open). Drive with the right eye for a blink."
|
|
3351
4383
|
},
|
|
3352
4384
|
{
|
|
3353
|
-
id:
|
|
4385
|
+
id: import_format11.StandardParameter.EyeOpenRight,
|
|
3354
4386
|
description: "Right eye open (0 closed .. 1 open)."
|
|
3355
4387
|
},
|
|
3356
4388
|
{
|
|
3357
|
-
id:
|
|
4389
|
+
id: import_format11.StandardParameter.EyeballX,
|
|
3358
4390
|
description: "Eyeball gaze, horizontal (-1 .. 1)."
|
|
3359
4391
|
},
|
|
3360
4392
|
{
|
|
3361
|
-
id:
|
|
4393
|
+
id: import_format11.StandardParameter.EyeballY,
|
|
3362
4394
|
description: "Eyeball gaze, vertical (-1 .. 1)."
|
|
3363
4395
|
},
|
|
3364
4396
|
{
|
|
3365
|
-
id:
|
|
4397
|
+
id: import_format11.StandardParameter.AngleX,
|
|
3366
4398
|
description: "Head angle, horizontal degrees."
|
|
3367
4399
|
},
|
|
3368
4400
|
{
|
|
3369
|
-
id:
|
|
4401
|
+
id: import_format11.StandardParameter.AngleY,
|
|
3370
4402
|
description: "Head angle, vertical degrees."
|
|
3371
4403
|
},
|
|
3372
4404
|
{
|
|
3373
|
-
id:
|
|
4405
|
+
id: import_format11.StandardParameter.AngleZ,
|
|
3374
4406
|
description: "Head tilt / roll degrees; positive tilts the top of the head toward the viewer's right (clockwise), as in Live2D."
|
|
3375
4407
|
},
|
|
3376
4408
|
{
|
|
3377
|
-
id:
|
|
4409
|
+
id: import_format11.StandardParameter.BodyAngleX,
|
|
3378
4410
|
description: "Body turn, degrees (-10 .. 10); positive turns the body toward the viewer's right, as AngleX does the head."
|
|
3379
4411
|
},
|
|
3380
4412
|
{
|
|
3381
|
-
id:
|
|
4413
|
+
id: import_format11.StandardParameter.BodyAngleY,
|
|
3382
4414
|
description: "Body lean, degrees (-10 .. 10); positive moves the upper body up, negative bows."
|
|
3383
4415
|
},
|
|
3384
4416
|
{
|
|
3385
|
-
id:
|
|
4417
|
+
id: import_format11.StandardParameter.BodyAngleZ,
|
|
3386
4418
|
description: "Body tilt, degrees (-10 .. 10); positive tilts the top toward the viewer's right (clockwise), as AngleZ does the head."
|
|
3387
4419
|
},
|
|
3388
4420
|
{
|
|
3389
|
-
id:
|
|
4421
|
+
id: import_format11.StandardParameter.Breath,
|
|
3390
4422
|
description: "Idle breath (0 .. 1), cycled by the host."
|
|
3391
4423
|
},
|
|
3392
4424
|
{
|
|
3393
|
-
id:
|
|
4425
|
+
id: import_format11.StandardParameter.AmbientSway,
|
|
3394
4426
|
description: "Ambient sway (-1 .. 1): a slow zero-mean drift the idle writes for physics rigs to follow (the auto-rig's hair in idle). Not a wind: no bias. Stays procedural under a declared Idle group, as Breath does."
|
|
3395
4427
|
},
|
|
3396
4428
|
{
|
|
3397
|
-
id:
|
|
4429
|
+
id: import_format11.StandardParameter.BrowLeftY,
|
|
3398
4430
|
description: "Left brow raise/lower (-1 .. 1)."
|
|
3399
4431
|
},
|
|
3400
4432
|
{
|
|
3401
|
-
id:
|
|
4433
|
+
id: import_format11.StandardParameter.BrowRightY,
|
|
3402
4434
|
description: "Right brow raise/lower (-1 .. 1)."
|
|
3403
4435
|
},
|
|
3404
4436
|
{
|
|
3405
|
-
id:
|
|
4437
|
+
id: import_format11.StandardParameter.BrowLeftAngle,
|
|
3406
4438
|
description: "Left brow tilt/angle (-1 .. 1)."
|
|
3407
4439
|
},
|
|
3408
4440
|
{
|
|
3409
|
-
id:
|
|
4441
|
+
id: import_format11.StandardParameter.BrowRightAngle,
|
|
3410
4442
|
description: "Right brow tilt/angle (-1 .. 1)."
|
|
3411
4443
|
},
|
|
3412
4444
|
{
|
|
3413
|
-
id:
|
|
4445
|
+
id: import_format11.StandardParameter.Cheek,
|
|
3414
4446
|
description: "Cheek blush strength (0 .. 1), raised by an expression."
|
|
3415
4447
|
},
|
|
3416
4448
|
{
|
|
3417
|
-
id:
|
|
4449
|
+
id: import_format11.StandardParameter.HairSwayX,
|
|
3418
4450
|
description: "Front hair's horizontal sway driver. Physics OUTPUT \u2014 driven by the spring, hosts should not set it directly."
|
|
3419
4451
|
},
|
|
3420
4452
|
{
|
|
3421
|
-
id:
|
|
4453
|
+
id: import_format11.StandardParameter.HairSwayZ,
|
|
3422
4454
|
description: "Front hair's sway driver behind a head tilt. Physics OUTPUT \u2014 driven by the spring, hosts should not set it directly."
|
|
3423
4455
|
},
|
|
3424
4456
|
{
|
|
3425
|
-
id:
|
|
4457
|
+
id: import_format11.StandardParameter.HairBackSway,
|
|
3426
4458
|
description: "Back hair's sway driver behind the head turn, tilt and ambient drift, one spring slower than the front hair's so the two swing out of phase. Physics OUTPUT \u2014 driven by the spring, hosts should not set it directly."
|
|
3427
4459
|
},
|
|
3428
4460
|
{
|
|
3429
|
-
id:
|
|
4461
|
+
id: import_format11.StandardParameter.ArmLeft,
|
|
3430
4462
|
description: "Left shoulder, degrees; positive raises the arm outward (mirrored on the right)."
|
|
3431
4463
|
},
|
|
3432
4464
|
{
|
|
3433
|
-
id:
|
|
4465
|
+
id: import_format11.StandardParameter.ArmRight,
|
|
3434
4466
|
description: "Right shoulder, degrees; positive raises the arm outward (mirrored on the left)."
|
|
3435
4467
|
},
|
|
3436
4468
|
{
|
|
3437
|
-
id:
|
|
4469
|
+
id: import_format11.StandardParameter.ElbowLeft,
|
|
3438
4470
|
description: "Left elbow, degrees; positive bends the forearm toward the body (the flexion of a hanging arm), negative a little outward (mirrored on the right)."
|
|
3439
4471
|
},
|
|
3440
4472
|
{
|
|
3441
|
-
id:
|
|
4473
|
+
id: import_format11.StandardParameter.ElbowRight,
|
|
3442
4474
|
description: "Right elbow, degrees; positive bends the forearm toward the body (the flexion of a hanging arm), negative a little outward (mirrored on the left)."
|
|
3443
4475
|
},
|
|
3444
4476
|
{
|
|
3445
|
-
id:
|
|
4477
|
+
id: import_format11.StandardParameter.ArmPoseLeft,
|
|
3446
4478
|
description: "Left pose-forearm switch, 0..1; 0 the hanging forearm, 1 the drawn pose forearm, between them a crossfade of the two. Declared by auto-rigged models with a pose forearm."
|
|
3447
4479
|
},
|
|
3448
4480
|
{
|
|
3449
|
-
id:
|
|
4481
|
+
id: import_format11.StandardParameter.ArmPoseRight,
|
|
3450
4482
|
description: "Right pose-forearm switch, 0..1; 0 the hanging forearm, 1 the drawn pose forearm, between them a crossfade of the two. Declared by auto-rigged models with a pose forearm."
|
|
3451
4483
|
},
|
|
3452
4484
|
{
|
|
3453
|
-
id:
|
|
4485
|
+
id: import_format11.StandardParameter.ArmPoseAngleLeft,
|
|
3454
4486
|
description: "Left pose forearm's own small rotation about the elbow, degrees; positive tips the raised hand outward, away from the body (mirrored on the right)."
|
|
3455
4487
|
},
|
|
3456
4488
|
{
|
|
3457
|
-
id:
|
|
4489
|
+
id: import_format11.StandardParameter.ArmPoseAngleRight,
|
|
3458
4490
|
description: "Right pose forearm's own small rotation about the elbow, degrees; positive tips the raised hand outward, away from the body (mirrored on the left)."
|
|
3459
4491
|
}
|
|
3460
4492
|
];
|
|
@@ -3462,10 +4494,10 @@ function listStandardParameters() {
|
|
|
3462
4494
|
return STANDARD_PARAMETER_INFO.map((p) => ({ ...p }));
|
|
3463
4495
|
}
|
|
3464
4496
|
function describeRigPlan() {
|
|
3465
|
-
return { fields: [...
|
|
4497
|
+
return { fields: [...import_editor4.RIG_PLAN_FIELDS] };
|
|
3466
4498
|
}
|
|
3467
4499
|
function formatRigPlanReport(r) {
|
|
3468
|
-
const fields =
|
|
4500
|
+
const fields = import_editor4.RIG_PLAN_FIELDS.map((f) => {
|
|
3469
4501
|
const value = `${f.path}=${r.effective[f.path]}`;
|
|
3470
4502
|
const clamp2 = r.clamped.find((c) => c.field === f.path);
|
|
3471
4503
|
if (clamp2 !== void 0) {
|
|
@@ -3488,7 +4520,7 @@ function expectInput(label, fn) {
|
|
|
3488
4520
|
}
|
|
3489
4521
|
var LOSSLESS_PAGE_ROLE = "nose";
|
|
3490
4522
|
async function renderAtlasPage(crops, quantizeColors) {
|
|
3491
|
-
const layout = (0,
|
|
4523
|
+
const layout = (0, import_editor4.packAtlas)(
|
|
3492
4524
|
crops.map((c) => ({ id: c.id, width: c.width, height: c.height })),
|
|
3493
4525
|
void 0,
|
|
3494
4526
|
MAX_ATLAS_SIDE
|
|
@@ -3511,9 +4543,20 @@ async function autoRigFromLayers(input) {
|
|
|
3511
4543
|
if (!Array.isArray(layers) || layers.length === 0) {
|
|
3512
4544
|
throw new AutoRigInputError("layers must be a non-empty array");
|
|
3513
4545
|
}
|
|
3514
|
-
|
|
4546
|
+
const customInputs = input.customParts;
|
|
4547
|
+
if (customInputs !== void 0 && !Array.isArray(customInputs)) {
|
|
4548
|
+
throw new AutoRigInputError("customParts must be an array");
|
|
4549
|
+
}
|
|
4550
|
+
const customEntries = customInputs ?? [];
|
|
4551
|
+
customEntries.forEach((entry, i) => {
|
|
4552
|
+
const at = `customParts[${i}]`;
|
|
4553
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
|
|
4554
|
+
throw new AutoRigInputError(`${at} must be a plain object`);
|
|
4555
|
+
}
|
|
4556
|
+
});
|
|
4557
|
+
if (layers.length + customEntries.length > MAX_LAYERS) {
|
|
3515
4558
|
throw new AutoRigInputError(
|
|
3516
|
-
`too many layers: ${layers.length} > ${MAX_LAYERS}`
|
|
4559
|
+
`too many layers: ${layers.length + customEntries.length} > ${MAX_LAYERS}`
|
|
3517
4560
|
);
|
|
3518
4561
|
}
|
|
3519
4562
|
const outPath = resolveOutputPath(
|
|
@@ -3526,7 +4569,7 @@ async function autoRigFromLayers(input) {
|
|
|
3526
4569
|
);
|
|
3527
4570
|
}
|
|
3528
4571
|
if (input.style !== void 0) {
|
|
3529
|
-
throw new AutoRigInputError((0,
|
|
4572
|
+
throw new AutoRigInputError((0, import_editor4.styleRemovedMessage)("style"));
|
|
3530
4573
|
}
|
|
3531
4574
|
const turnTargets = input.turnTargets;
|
|
3532
4575
|
if (turnTargets !== void 0) {
|
|
@@ -3543,9 +4586,12 @@ async function autoRigFromLayers(input) {
|
|
|
3543
4586
|
const resolved = resolveInputPath(layer.path);
|
|
3544
4587
|
return { resolved, fileName: layer.fileName ?? import_node_path5.default.basename(resolved) };
|
|
3545
4588
|
});
|
|
4589
|
+
const customPaths = customEntries.map(
|
|
4590
|
+
(entry, i) => resolveInputPath(entry.path, `customParts[${i}].path`)
|
|
4591
|
+
);
|
|
3546
4592
|
const rolePairs = expectInput(
|
|
3547
4593
|
"role parsing",
|
|
3548
|
-
() => (0,
|
|
4594
|
+
() => (0, import_editor4.parseLayerRoles)(resolvedLayers.map((r) => r.fileName))
|
|
3549
4595
|
);
|
|
3550
4596
|
const roleByFileName = new Map(rolePairs.map((p) => [p.fileName, p.role]));
|
|
3551
4597
|
let canvasW = 0;
|
|
@@ -3553,6 +4599,10 @@ async function autoRigFromLayers(input) {
|
|
|
3553
4599
|
let totalPixels = 0;
|
|
3554
4600
|
let measurer;
|
|
3555
4601
|
const crops = [];
|
|
4602
|
+
const paints = /* @__PURE__ */ new Map();
|
|
4603
|
+
const anchorRoles = new Set(
|
|
4604
|
+
customEntries.flatMap((e) => [e.anchor, ...e.occlusion?.by ?? []])
|
|
4605
|
+
);
|
|
3556
4606
|
for (let i = 0; i < resolvedLayers.length; i++) {
|
|
3557
4607
|
const { resolved, fileName } = resolvedLayers[i];
|
|
3558
4608
|
const png = await decodePng(resolved);
|
|
@@ -3575,7 +4625,7 @@ async function autoRigFromLayers(input) {
|
|
|
3575
4625
|
`canvas ${canvasW}x${canvasH} exceeds ${MAX_CANVAS_DIM}`
|
|
3576
4626
|
);
|
|
3577
4627
|
}
|
|
3578
|
-
measurer = (0,
|
|
4628
|
+
measurer = (0, import_editor4.createLayerSetMeasurer)({ width: canvasW, height: canvasH });
|
|
3579
4629
|
} else if (png.width !== canvasW || png.height !== canvasH) {
|
|
3580
4630
|
throw new AutoRigInputError(
|
|
3581
4631
|
`layer "${fileName}" size ${png.width}x${png.height} differs from canvas ${canvasW}x${canvasH}`
|
|
@@ -3592,9 +4642,48 @@ async function autoRigFromLayers(input) {
|
|
|
3592
4642
|
);
|
|
3593
4643
|
}
|
|
3594
4644
|
const { bbox } = layer;
|
|
4645
|
+
if (anchorRoles.has(role)) paints.set(role, paintRuns(png));
|
|
3595
4646
|
const buffer = await cropToBuffer(png.rgba, png.width, png.height, bbox);
|
|
3596
4647
|
crops.push({ id: role, buffer, width: bbox.w, height: bbox.h });
|
|
3597
4648
|
}
|
|
4649
|
+
const customLayers = [];
|
|
4650
|
+
const customCrops = [];
|
|
4651
|
+
for (let i = 0; i < customEntries.length; i++) {
|
|
4652
|
+
const at = `customParts[${i}]`;
|
|
4653
|
+
const { id } = customEntries[i];
|
|
4654
|
+
const resolved = customPaths[i];
|
|
4655
|
+
const png = await decodePng(resolved);
|
|
4656
|
+
if (png.width > MAX_LAYER_DIM || png.height > MAX_LAYER_DIM) {
|
|
4657
|
+
throw new AutoRigInputError(
|
|
4658
|
+
`${at}.path ${resolved} dimension ${png.width}x${png.height} exceeds ${MAX_LAYER_DIM}`
|
|
4659
|
+
);
|
|
4660
|
+
}
|
|
4661
|
+
totalPixels += png.width * png.height;
|
|
4662
|
+
if (totalPixels > MAX_TOTAL_PIXELS) {
|
|
4663
|
+
throw new AutoRigInputError(
|
|
4664
|
+
`total decoded pixels exceed ${MAX_TOTAL_PIXELS}`
|
|
4665
|
+
);
|
|
4666
|
+
}
|
|
4667
|
+
if (png.width !== canvasW || png.height !== canvasH) {
|
|
4668
|
+
throw new AutoRigInputError(
|
|
4669
|
+
`${at}.path size ${png.width}x${png.height} differs from canvas ${canvasW}x${canvasH}`
|
|
4670
|
+
);
|
|
4671
|
+
}
|
|
4672
|
+
const bbox = (0, import_editor4.detectAlphaBbox)(png.rgba, png.width, png.height);
|
|
4673
|
+
if (bbox === null) {
|
|
4674
|
+
throw new AutoRigInputError(
|
|
4675
|
+
`${at}.path "${import_node_path5.default.basename(resolved)}": layer is empty after alpha threshold`
|
|
4676
|
+
);
|
|
4677
|
+
}
|
|
4678
|
+
customLayers.push({ fileName: import_node_path5.default.basename(resolved), bbox });
|
|
4679
|
+
paints.set(id, paintRuns(png));
|
|
4680
|
+
customCrops.push({
|
|
4681
|
+
id,
|
|
4682
|
+
buffer: await cropToBuffer(png.rgba, png.width, png.height, bbox),
|
|
4683
|
+
width: bbox.w,
|
|
4684
|
+
height: bbox.h
|
|
4685
|
+
});
|
|
4686
|
+
}
|
|
3598
4687
|
const measurement = measurer.finish();
|
|
3599
4688
|
const { headHalfWidth, headHalfWidthApplied, turnOptions } = measurement;
|
|
3600
4689
|
const { headEdges, strandEdges } = turnOptions;
|
|
@@ -3604,9 +4693,10 @@ async function autoRigFromLayers(input) {
|
|
|
3604
4693
|
let turn;
|
|
3605
4694
|
let patches;
|
|
3606
4695
|
let rigPlan;
|
|
4696
|
+
let bakeReports;
|
|
3607
4697
|
let model;
|
|
3608
4698
|
try {
|
|
3609
|
-
model = (0,
|
|
4699
|
+
model = (0, import_editor4.generateIkiFromLayerSet)(
|
|
3610
4700
|
measurement.layers,
|
|
3611
4701
|
{ width: canvasW, height: canvasH },
|
|
3612
4702
|
{
|
|
@@ -3628,16 +4718,30 @@ async function autoRigFromLayers(input) {
|
|
|
3628
4718
|
}
|
|
3629
4719
|
},
|
|
3630
4720
|
...headEdges === void 0 ? {} : { headEdges },
|
|
3631
|
-
...strandEdges === void 0 ? {} : { strandEdges }
|
|
4721
|
+
...strandEdges === void 0 ? {} : { strandEdges },
|
|
4722
|
+
...input.customParts === void 0 ? {} : {
|
|
4723
|
+
customParts: customEntries.map(
|
|
4724
|
+
({ path: _path, ...rest }, i) => ({
|
|
4725
|
+
...rest,
|
|
4726
|
+
layer: customLayers[i]
|
|
4727
|
+
})
|
|
4728
|
+
)
|
|
4729
|
+
},
|
|
4730
|
+
...input.bakes === void 0 ? {} : {
|
|
4731
|
+
bakes: input.bakes,
|
|
4732
|
+
onBakesApplied: (reports) => {
|
|
4733
|
+
bakeReports = reports;
|
|
4734
|
+
}
|
|
4735
|
+
}
|
|
3632
4736
|
}
|
|
3633
4737
|
);
|
|
3634
4738
|
} catch (e) {
|
|
3635
|
-
if (!(e instanceof
|
|
4739
|
+
if (!(e instanceof import_editor4.TurnTargetError || e instanceof import_editor4.LayerGeometryError || e instanceof import_editor4.PatchError || e instanceof import_editor4.RigPlanError || e instanceof import_editor4.CustomPartError || e instanceof import_editor4.BakeError)) {
|
|
3636
4740
|
throw e;
|
|
3637
4741
|
}
|
|
3638
4742
|
throw new AutoRigInputError(e.message);
|
|
3639
4743
|
}
|
|
3640
|
-
const doc = new
|
|
4744
|
+
const doc = new import_editor4.EditorDocument(model);
|
|
3641
4745
|
const losslessCrop = quantizeColors === void 0 ? void 0 : crops.find((c) => c.id === LOSSLESS_PAGE_ROLE);
|
|
3642
4746
|
const pages = losslessCrop === void 0 ? [await renderAtlasPage(crops, quantizeColors)] : [
|
|
3643
4747
|
await renderAtlasPage(
|
|
@@ -3646,7 +4750,9 @@ async function autoRigFromLayers(input) {
|
|
|
3646
4750
|
),
|
|
3647
4751
|
await renderAtlasPage([losslessCrop], void 0)
|
|
3648
4752
|
];
|
|
3649
|
-
const
|
|
4753
|
+
const customPage = customCrops.length === 0 ? void 0 : await renderAtlasPage(customCrops, quantizeColors);
|
|
4754
|
+
const allPages = customPage === void 0 ? pages : [...pages, customPage];
|
|
4755
|
+
const atlasBytes = allPages.reduce((sum, p) => sum + p.dataUri.length, 0);
|
|
3650
4756
|
if (atlasBytes > MAX_OUTPUT_BYTES) {
|
|
3651
4757
|
throw new AutoRigInputError(
|
|
3652
4758
|
`atlas data URI ${atlasBytes} bytes exceeds ${MAX_OUTPUT_BYTES}`
|
|
@@ -3658,29 +4764,69 @@ async function autoRigFromLayers(input) {
|
|
|
3658
4764
|
if (placement3 === void 0) {
|
|
3659
4765
|
throw new Error(`auto-rig: no atlas placement for "${crop.id}"`);
|
|
3660
4766
|
}
|
|
3661
|
-
const uv = (0,
|
|
4767
|
+
const uv = (0, import_editor4.uvRectFor)(placement3, {
|
|
3662
4768
|
width: layout.pageWidth,
|
|
3663
4769
|
height: layout.pageHeight
|
|
3664
4770
|
});
|
|
3665
|
-
return (0,
|
|
4771
|
+
return (0, import_editor4.partIdsOfRole)(crop.id).map((partId) => ({ partId, uv }));
|
|
3666
4772
|
})
|
|
3667
4773
|
);
|
|
4774
|
+
if (customPage !== void 0) {
|
|
4775
|
+
partTextureAssignments.push(
|
|
4776
|
+
...customPage.crops.map((crop) => {
|
|
4777
|
+
const placement3 = customPage.layout.placements.find(
|
|
4778
|
+
(p) => p.id === crop.id
|
|
4779
|
+
);
|
|
4780
|
+
return {
|
|
4781
|
+
partId: crop.id,
|
|
4782
|
+
uv: (0, import_editor4.uvRectFor)(placement3, {
|
|
4783
|
+
width: customPage.layout.pageWidth,
|
|
4784
|
+
height: customPage.layout.pageHeight
|
|
4785
|
+
})
|
|
4786
|
+
};
|
|
4787
|
+
})
|
|
4788
|
+
);
|
|
4789
|
+
}
|
|
3668
4790
|
doc.applyAtlas({
|
|
3669
4791
|
textures: [{ source: pages[0].dataUri }],
|
|
3670
4792
|
partTextureAssignments
|
|
3671
4793
|
});
|
|
3672
4794
|
let patched = doc.getModel();
|
|
3673
|
-
if (losslessCrop !== void 0) {
|
|
4795
|
+
if (losslessCrop !== void 0 || customPage !== void 0) {
|
|
3674
4796
|
patched = structuredClone(patched);
|
|
3675
|
-
patched.textures =
|
|
3676
|
-
|
|
3677
|
-
|
|
4797
|
+
patched.textures = allPages.map((p) => ({ source: p.dataUri }));
|
|
4798
|
+
if (losslessCrop !== void 0) {
|
|
4799
|
+
for (const partId of (0, import_editor4.partIdsOfRole)(losslessCrop.id)) {
|
|
4800
|
+
patched.parts.find((p) => p.id === partId).texture.index = 1;
|
|
4801
|
+
}
|
|
4802
|
+
}
|
|
4803
|
+
for (const crop of customCrops) {
|
|
4804
|
+
patched.parts.find((p) => p.id === crop.id).texture.index = pages.length;
|
|
3678
4805
|
}
|
|
3679
4806
|
}
|
|
3680
|
-
const finalModel = (0,
|
|
4807
|
+
const finalModel = (0, import_format11.parseIkiModel)(patched);
|
|
4808
|
+
const bakes = bakeReports === void 0 ? void 0 : checkBakes(finalModel, bakeReports);
|
|
3681
4809
|
writeFileAtomic(outPath, JSON.stringify(finalModel));
|
|
3682
4810
|
const folds = checkModelFolds(finalModel);
|
|
3683
4811
|
const physics = checkPhysics(finalModel);
|
|
4812
|
+
let gate;
|
|
4813
|
+
if (input.customParts !== void 0) {
|
|
4814
|
+
try {
|
|
4815
|
+
gate = checkCustomGate(
|
|
4816
|
+
finalModel,
|
|
4817
|
+
customEntries.map(({ id, anchor, tie, rigid, occlusion }) => ({
|
|
4818
|
+
id,
|
|
4819
|
+
anchor,
|
|
4820
|
+
tie,
|
|
4821
|
+
...rigid === void 0 ? {} : { rigid },
|
|
4822
|
+
...occlusion === void 0 ? {} : { occludedBy: occlusion.by }
|
|
4823
|
+
})),
|
|
4824
|
+
paints
|
|
4825
|
+
);
|
|
4826
|
+
} catch (e) {
|
|
4827
|
+
gate = failedCustomGate(finalModel, e);
|
|
4828
|
+
}
|
|
4829
|
+
}
|
|
3684
4830
|
return {
|
|
3685
4831
|
ok: true,
|
|
3686
4832
|
path: outPath,
|
|
@@ -3696,7 +4842,27 @@ async function autoRigFromLayers(input) {
|
|
|
3696
4842
|
folds,
|
|
3697
4843
|
physics,
|
|
3698
4844
|
...patches === void 0 ? {} : { patches },
|
|
3699
|
-
rigPlan
|
|
4845
|
+
rigPlan,
|
|
4846
|
+
...input.customParts === void 0 ? {} : {
|
|
4847
|
+
customParts: {
|
|
4848
|
+
parts: customCrops.map((crop, i) => {
|
|
4849
|
+
const part = finalModel.parts.find((p) => p.id === crop.id);
|
|
4850
|
+
return {
|
|
4851
|
+
id: crop.id,
|
|
4852
|
+
box: customLayers[i].bbox,
|
|
4853
|
+
mesh: {
|
|
4854
|
+
vertices: part.mesh.vertices.length / 2,
|
|
4855
|
+
triangles: part.mesh.indices.length / 3
|
|
4856
|
+
},
|
|
4857
|
+
order: part.order,
|
|
4858
|
+
page: part.texture.index,
|
|
4859
|
+
...part.occlusion === void 0 ? {} : { occlusion: part.occlusion }
|
|
4860
|
+
};
|
|
4861
|
+
}),
|
|
4862
|
+
...bakes === void 0 ? {} : { bakes },
|
|
4863
|
+
gate
|
|
4864
|
+
}
|
|
4865
|
+
}
|
|
3700
4866
|
};
|
|
3701
4867
|
} catch (err) {
|
|
3702
4868
|
if (err instanceof AutoRigInputError)
|
|
@@ -3706,13 +4872,13 @@ async function autoRigFromLayers(input) {
|
|
|
3706
4872
|
}
|
|
3707
4873
|
|
|
3708
4874
|
// src/compose.ts
|
|
3709
|
-
var
|
|
4875
|
+
var import_node_fs8 = __toESM(require("fs"));
|
|
3710
4876
|
var import_node_path10 = __toESM(require("path"));
|
|
3711
4877
|
var import_sharp4 = __toESM(require("sharp"));
|
|
3712
|
-
var
|
|
4878
|
+
var import_editor14 = require("@ikijs/editor");
|
|
3713
4879
|
|
|
3714
4880
|
// src/trim.ts
|
|
3715
|
-
var
|
|
4881
|
+
var import_editor5 = require("@ikijs/editor");
|
|
3716
4882
|
var TRIM_THRESHOLD = 12;
|
|
3717
4883
|
var STRAY_SPECK_FRACTION = 0.01;
|
|
3718
4884
|
function luma(rgba, i) {
|
|
@@ -3741,7 +4907,7 @@ function boxWithoutStraySpecks(rgba, W, H) {
|
|
|
3741
4907
|
while (depth > 0) {
|
|
3742
4908
|
const p = stack[--depth];
|
|
3743
4909
|
size++;
|
|
3744
|
-
if (rgba[p * 4 + 3] >=
|
|
4910
|
+
if (rgba[p * 4 + 3] >= import_editor5.ALPHA_OPAQUE) opaque = true;
|
|
3745
4911
|
const px2 = p % W;
|
|
3746
4912
|
const py = (p - px2) / W;
|
|
3747
4913
|
setLeft = Math.min(setLeft, px2);
|
|
@@ -3778,12 +4944,12 @@ function boxWithoutStraySpecks(rgba, W, H) {
|
|
|
3778
4944
|
}
|
|
3779
4945
|
|
|
3780
4946
|
// src/measure.ts
|
|
3781
|
-
var
|
|
4947
|
+
var import_node_fs7 = __toESM(require("fs"));
|
|
3782
4948
|
var import_node_path9 = __toESM(require("path"));
|
|
3783
4949
|
|
|
3784
4950
|
// src/measure-arms.ts
|
|
3785
4951
|
var import_node_path6 = __toESM(require("path"));
|
|
3786
|
-
var
|
|
4952
|
+
var import_editor6 = require("@ikijs/editor");
|
|
3787
4953
|
var ARM_ROLES = ["arm_L", "arm_R"];
|
|
3788
4954
|
var CAP_OVERLAP = 0.5;
|
|
3789
4955
|
var px = (v) => `${Number(v.toFixed(1))}`;
|
|
@@ -3812,7 +4978,7 @@ async function armWarnings(absDir, layers) {
|
|
|
3812
4978
|
continue;
|
|
3813
4979
|
}
|
|
3814
4980
|
if (set === void 0) {
|
|
3815
|
-
const measurer = (0,
|
|
4981
|
+
const measurer = (0, import_editor6.createLayerSetMeasurer)({
|
|
3816
4982
|
width: body.canvasW,
|
|
3817
4983
|
height: body.canvasH
|
|
3818
4984
|
});
|
|
@@ -3820,12 +4986,12 @@ async function armWarnings(absDir, layers) {
|
|
|
3820
4986
|
}
|
|
3821
4987
|
let g;
|
|
3822
4988
|
try {
|
|
3823
|
-
g = (0,
|
|
4989
|
+
g = (0, import_editor6.armGeometry)(
|
|
3824
4990
|
await measured(set.measurer, absDir, arm),
|
|
3825
4991
|
set.body.bbox.x + set.body.bbox.w / 2 - body.canvasW / 2
|
|
3826
4992
|
);
|
|
3827
4993
|
} catch (err) {
|
|
3828
|
-
if (err instanceof
|
|
4994
|
+
if (err instanceof import_editor6.LayerGeometryError) {
|
|
3829
4995
|
warnings.push(
|
|
3830
4996
|
`${arm}: ${err.message} \u2014 auto_rig_from_layers refuses it. Regenerate arm.png drawn hanging, shoulder at the top. Billed.`
|
|
3831
4997
|
);
|
|
@@ -3853,7 +5019,7 @@ function capWarning(arm, g, body) {
|
|
|
3853
5019
|
}
|
|
3854
5020
|
|
|
3855
5021
|
// src/measure-hair-side.ts
|
|
3856
|
-
var
|
|
5022
|
+
var import_editor7 = require("@ikijs/editor");
|
|
3857
5023
|
var LOCK_ROLES = ["hair_side_R", "hair_side_L"];
|
|
3858
5024
|
var VISIBLE_MIN_PX = 3;
|
|
3859
5025
|
var LEAN_HH = 0.12;
|
|
@@ -3865,7 +5031,7 @@ function covers(runs, x) {
|
|
|
3865
5031
|
}
|
|
3866
5032
|
return false;
|
|
3867
5033
|
}
|
|
3868
|
-
function
|
|
5034
|
+
function runsAt2(layer, y) {
|
|
3869
5035
|
return layer?.rowRuns?.[y - layer.bbox.y] ?? [];
|
|
3870
5036
|
}
|
|
3871
5037
|
function opaqueRows(layer) {
|
|
@@ -3901,7 +5067,7 @@ async function hairSideWarnings(absDir, layers) {
|
|
|
3901
5067
|
}
|
|
3902
5068
|
}
|
|
3903
5069
|
if (mismatched) return warnings;
|
|
3904
|
-
const measurer = (0,
|
|
5070
|
+
const measurer = (0, import_editor7.createLayerSetMeasurer)({
|
|
3905
5071
|
width: ref.canvasW,
|
|
3906
5072
|
height: ref.canvasH
|
|
3907
5073
|
});
|
|
@@ -3941,8 +5107,8 @@ async function hairSideWarnings(absDir, layers) {
|
|
|
3941
5107
|
function rootWarning(role, lock, front) {
|
|
3942
5108
|
const y = opaqueRows(lock)?.top;
|
|
3943
5109
|
if (y === void 0) return void 0;
|
|
3944
|
-
const frontRuns =
|
|
3945
|
-
const lockRuns =
|
|
5110
|
+
const frontRuns = runsAt2(front, y);
|
|
5111
|
+
const lockRuns = runsAt2(lock, y);
|
|
3946
5112
|
let shown = 0;
|
|
3947
5113
|
for (let i = 0; i + 1 < lockRuns.length; i += 2) {
|
|
3948
5114
|
let stretch = 0;
|
|
@@ -3961,7 +5127,7 @@ function rootWarning(role, lock, front) {
|
|
|
3961
5127
|
function eyeCornerWarning(role, lock, side, eyeRole, eye) {
|
|
3962
5128
|
const row = Math.floor(eye.bboxCy);
|
|
3963
5129
|
const corner = side < 0 ? eye.marginLeft : eye.marginLeft + eye.w - 1;
|
|
3964
|
-
const runs =
|
|
5130
|
+
const runs = runsAt2(lock, row);
|
|
3965
5131
|
let overlap = 0;
|
|
3966
5132
|
for (let i = 0; i + 1 < runs.length; i += 2) {
|
|
3967
5133
|
if (corner < runs[i] || corner >= runs[i + 1]) continue;
|
|
@@ -3980,14 +5146,14 @@ function leanWarning(role, lock, side, face, back, eye) {
|
|
|
3980
5146
|
const bare = /* @__PURE__ */ new Set();
|
|
3981
5147
|
const rows = /* @__PURE__ */ new Set();
|
|
3982
5148
|
for (let y = lockRows.top; y <= Math.min(lockRows.bottom, faceBottom); y++) {
|
|
3983
|
-
const runs =
|
|
5149
|
+
const runs = runsAt2(lock, y);
|
|
3984
5150
|
if (runs.length === 0) continue;
|
|
3985
5151
|
const from = side < 0 ? runs[0] : runs[runs.length - 2];
|
|
3986
5152
|
const to = side < 0 ? runs[1] : runs[runs.length - 1];
|
|
3987
5153
|
const start = side < 0 ? from : Math.max(from, to - lean);
|
|
3988
5154
|
const end = side < 0 ? Math.min(to, from + lean) : to;
|
|
3989
|
-
const faceRuns =
|
|
3990
|
-
const backRuns =
|
|
5155
|
+
const faceRuns = runsAt2(face, y);
|
|
5156
|
+
const backRuns = runsAt2(back, y);
|
|
3991
5157
|
for (let x = start; x < end; x++) {
|
|
3992
5158
|
if (covers(faceRuns, x) || covers(backRuns, x)) continue;
|
|
3993
5159
|
bare.add(x);
|
|
@@ -4029,7 +5195,7 @@ function drawsTwoLocks(lock) {
|
|
|
4029
5195
|
}
|
|
4030
5196
|
|
|
4031
5197
|
// src/measure-forearm-pose.ts
|
|
4032
|
-
var
|
|
5198
|
+
var import_editor8 = require("@ikijs/editor");
|
|
4033
5199
|
var POSE_ROLES = ["forearm_pose_L", "forearm_pose_R"];
|
|
4034
5200
|
var ARM_OF = {
|
|
4035
5201
|
forearm_pose_L: "arm_L",
|
|
@@ -4063,7 +5229,7 @@ async function forearmPoseWarnings(absDir, layers) {
|
|
|
4063
5229
|
continue;
|
|
4064
5230
|
}
|
|
4065
5231
|
if (layers.body === void 0) continue;
|
|
4066
|
-
const measurer = (0,
|
|
5232
|
+
const measurer = (0, import_editor8.createLayerSetMeasurer)({
|
|
4067
5233
|
width: stats.canvasW,
|
|
4068
5234
|
height: stats.canvasH
|
|
4069
5235
|
});
|
|
@@ -4071,12 +5237,12 @@ async function forearmPoseWarnings(absDir, layers) {
|
|
|
4071
5237
|
let armLayer;
|
|
4072
5238
|
try {
|
|
4073
5239
|
armLayer = await measured(measurer, absDir, arm);
|
|
4074
|
-
a = (0,
|
|
5240
|
+
a = (0, import_editor8.armGeometry)(armLayer, arm === "arm_R" ? Infinity : -Infinity);
|
|
4075
5241
|
} catch (err) {
|
|
4076
|
-
if (err instanceof
|
|
5242
|
+
if (err instanceof import_editor8.LayerGeometryError) continue;
|
|
4077
5243
|
throw err;
|
|
4078
5244
|
}
|
|
4079
|
-
const b = (0,
|
|
5245
|
+
const b = (0, import_editor8.forearmPoseGeometry)(await measured(measurer, absDir, pose));
|
|
4080
5246
|
warnings.push(...jointWarnings(pose, arm, stats, a, armLayer, b));
|
|
4081
5247
|
}
|
|
4082
5248
|
return warnings;
|
|
@@ -4116,11 +5282,11 @@ function jointWarnings(pose, arm, stats, a, armLayer, b) {
|
|
|
4116
5282
|
|
|
4117
5283
|
// src/measure-lips.ts
|
|
4118
5284
|
var import_node_path7 = __toESM(require("path"));
|
|
4119
|
-
var
|
|
5285
|
+
var import_editor10 = require("@ikijs/editor");
|
|
4120
5286
|
|
|
4121
5287
|
// src/compose-lips.ts
|
|
4122
5288
|
var import_sharp2 = __toESM(require("sharp"));
|
|
4123
|
-
var
|
|
5289
|
+
var import_editor9 = require("@ikijs/editor");
|
|
4124
5290
|
var KEYED_SRC = "mouth_keyed.png";
|
|
4125
5291
|
var INTERIOR_SRC = "mouth_interior.png";
|
|
4126
5292
|
var KEY_CANDIDATE = 0.5;
|
|
@@ -4218,7 +5384,7 @@ function keyGreen(rgba, W, H) {
|
|
|
4218
5384
|
let candidates = 0;
|
|
4219
5385
|
for (let p = 0; p < n; p++) {
|
|
4220
5386
|
const i = p * 4;
|
|
4221
|
-
if (rgba[i + 3] <
|
|
5387
|
+
if (rgba[i + 3] < import_editor9.ALPHA_OPAQUE) continue;
|
|
4222
5388
|
const excess = (rgba[i + 1] - Math.max(rgba[i], rgba[i + 2])) / 255;
|
|
4223
5389
|
if (excess < KEY_CANDIDATE) continue;
|
|
4224
5390
|
candidates++;
|
|
@@ -4245,7 +5411,7 @@ function keyGreen(rgba, W, H) {
|
|
|
4245
5411
|
const dg = rgba[i + 1] - G[1];
|
|
4246
5412
|
const db = rgba[i + 2] - G[2];
|
|
4247
5413
|
const green = dr * dr + dg * dg + db * db <= KEY_FILL_DIST * KEY_FILL_DIST;
|
|
4248
|
-
if (rgba[i + 3] <
|
|
5414
|
+
if (rgba[i + 3] < import_editor9.ALPHA_OPAQUE) {
|
|
4249
5415
|
if (green) out[i + 3] = 0;
|
|
4250
5416
|
} else if (green) {
|
|
4251
5417
|
fill[p] = 1;
|
|
@@ -4421,7 +5587,7 @@ async function prepInterior(rgba, W, H) {
|
|
|
4421
5587
|
for (let y = box2.y; y < box2.y + box2.h; y++) {
|
|
4422
5588
|
for (let x = box2.x; x < box2.x + box2.w; x++) {
|
|
4423
5589
|
const i = (y * cw + x) * 4;
|
|
4424
|
-
if (crop[i + 3] <
|
|
5590
|
+
if (crop[i + 3] < import_editor9.ALPHA_OPAQUE) continue;
|
|
4425
5591
|
count++;
|
|
4426
5592
|
for (let c = 0; c < 3; c++) all[c] += crop[i + c];
|
|
4427
5593
|
if (luma(crop, i) < CAVITY_LUMA) {
|
|
@@ -4444,7 +5610,7 @@ function enclosedHole(frame, w, h) {
|
|
|
4444
5610
|
const stack = new Int32Array(n);
|
|
4445
5611
|
let depth = 0;
|
|
4446
5612
|
const seed = (p) => {
|
|
4447
|
-
if (!outside[p] && alpha(p) <
|
|
5613
|
+
if (!outside[p] && alpha(p) < import_editor9.ALPHA_OPAQUE) {
|
|
4448
5614
|
outside[p] = 1;
|
|
4449
5615
|
stack[depth++] = p;
|
|
4450
5616
|
}
|
|
@@ -4467,7 +5633,7 @@ function enclosedHole(frame, w, h) {
|
|
|
4467
5633
|
}
|
|
4468
5634
|
const mask = new Uint8Array(n);
|
|
4469
5635
|
for (let p = 0; p < n; p++) {
|
|
4470
|
-
if (alpha(p) <
|
|
5636
|
+
if (alpha(p) < import_editor9.ALPHA_OPAQUE && !outside[p]) mask[p] = 1;
|
|
4471
5637
|
}
|
|
4472
5638
|
const { label, sizes, boxes } = components(mask, w, h);
|
|
4473
5639
|
const main2 = largest(sizes);
|
|
@@ -4494,7 +5660,7 @@ function enclosedHole(frame, w, h) {
|
|
|
4494
5660
|
return { label, main: main2, box: box2 };
|
|
4495
5661
|
}
|
|
4496
5662
|
function measureLips(layers, w, h) {
|
|
4497
|
-
const measurer = (0,
|
|
5663
|
+
const measurer = (0, import_editor9.createLayerSetMeasurer)({ width: w, height: h });
|
|
4498
5664
|
return new Map(
|
|
4499
5665
|
Object.entries(layers).map(([role, rgba]) => [
|
|
4500
5666
|
role,
|
|
@@ -4512,8 +5678,8 @@ function assertFoldContract(layers, w, h) {
|
|
|
4512
5678
|
}
|
|
4513
5679
|
byRole.set(role, layer);
|
|
4514
5680
|
}
|
|
4515
|
-
const opening = (0,
|
|
4516
|
-
const runs = (0,
|
|
5681
|
+
const opening = (0, import_editor9.mouthOpening)(byRole);
|
|
5682
|
+
const runs = (0, import_editor9.columnRuns)(byRole.get("mouth_inner"));
|
|
4517
5683
|
for (let col = opening.x0; col <= opening.x1; col++) {
|
|
4518
5684
|
const c = opening.at(col);
|
|
4519
5685
|
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;
|
|
@@ -4543,18 +5709,18 @@ async function splitLipSet(keyedPng, w, h, interior) {
|
|
|
4543
5709
|
}
|
|
4544
5710
|
const centre = Math.round((hb.x0 + hb.x1) / 2);
|
|
4545
5711
|
let stroke = 0;
|
|
4546
|
-
while (top[centre] - 1 - stroke >= 0 && alpha((top[centre] - 1 - stroke) * w + centre) >=
|
|
5712
|
+
while (top[centre] - 1 - stroke >= 0 && alpha((top[centre] - 1 - stroke) * w + centre) >= import_editor9.ALPHA_OPAQUE)
|
|
4547
5713
|
stroke++;
|
|
4548
5714
|
const bandCap = BAND_CAP * Math.max(1, stroke);
|
|
4549
5715
|
const skinRow = new Int32Array(w).fill(-1);
|
|
4550
5716
|
const inM = new Uint8Array(n);
|
|
4551
5717
|
for (let x = hb.x0; x <= hb.x1; x++) {
|
|
4552
5718
|
let y = bot[x];
|
|
4553
|
-
while (y < h && y - bot[x] < bandCap && alpha(y * w + x) >=
|
|
5719
|
+
while (y < h && y - bot[x] < bandCap && alpha(y * w + x) >= import_editor9.ALPHA_OPAQUE && luma(frame, (y * w + x) * 4) < BAND_LUMA)
|
|
4554
5720
|
y++;
|
|
4555
5721
|
for (let k = top[x]; k < y; k++) inM[k * w + x] = 1;
|
|
4556
5722
|
let r = y;
|
|
4557
|
-
while (r < h && alpha(r * w + x) <
|
|
5723
|
+
while (r < h && alpha(r * w + x) < import_editor9.ALPHA_OPAQUE) r++;
|
|
4558
5724
|
if (r < h) {
|
|
4559
5725
|
skinRow[x] = r;
|
|
4560
5726
|
inM[r * w + x] = 1;
|
|
@@ -4564,7 +5730,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
|
|
|
4564
5730
|
for (let y = 0; y < h; y++) {
|
|
4565
5731
|
for (let x = 0; x < w; x++) {
|
|
4566
5732
|
const p = y * w + x;
|
|
4567
|
-
if (inM[p] || alpha(p) <
|
|
5733
|
+
if (inM[p] || alpha(p) < import_editor9.ALPHA_OPAQUE) continue;
|
|
4568
5734
|
if (top[x] >= 0 && y < top[x]) continue;
|
|
4569
5735
|
if (x > 0 && inM[p - 1] || x < w - 1 && inM[p + 1]) grown[p] = 1;
|
|
4570
5736
|
}
|
|
@@ -4574,7 +5740,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
|
|
|
4574
5740
|
if (x < 0 || x >= w) continue;
|
|
4575
5741
|
let first = 0;
|
|
4576
5742
|
while (first < h && !(grown[first * w + x] && !inM[first * w + x])) first++;
|
|
4577
|
-
if (first > 0 && first < h && alpha((first - 1) * w + x) >=
|
|
5743
|
+
if (first > 0 && first < h && alpha((first - 1) * w + x) >= import_editor9.ALPHA_OPAQUE)
|
|
4578
5744
|
wall[x] = 1;
|
|
4579
5745
|
}
|
|
4580
5746
|
const gx = hb.x0 - 1;
|
|
@@ -4601,7 +5767,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
|
|
|
4601
5767
|
if (inOpening && skinRow[x] >= 0 && y >= skinRow[x]) copy(lower, p);
|
|
4602
5768
|
if (!grown[p]) {
|
|
4603
5769
|
const a = alpha(p);
|
|
4604
|
-
if (a >=
|
|
5770
|
+
if (a >= import_editor9.ALPHA_OPAQUE && a < 255 && besideHole(p, x, y)) {
|
|
4605
5771
|
inner.set(interior.cavity, p * 4);
|
|
4606
5772
|
inner[p * 4 + 3] = 255 - a;
|
|
4607
5773
|
}
|
|
@@ -4666,7 +5832,7 @@ async function restShiftOf(layers, width, height) {
|
|
|
4666
5832
|
}
|
|
4667
5833
|
byRole.set(role, layer);
|
|
4668
5834
|
}
|
|
4669
|
-
return (0,
|
|
5835
|
+
return (0, import_editor9.mouthRestShift)(byRole);
|
|
4670
5836
|
}
|
|
4671
5837
|
async function closedLips(upper, lower, shift, left, top) {
|
|
4672
5838
|
const shut = async (png, role) => {
|
|
@@ -4716,7 +5882,7 @@ async function closedLips(upper, lower, shift, left, top) {
|
|
|
4716
5882
|
}
|
|
4717
5883
|
|
|
4718
5884
|
// src/measure-lips.ts
|
|
4719
|
-
var isLipLayerRole = (role) =>
|
|
5885
|
+
var isLipLayerRole = (role) => import_editor10.LIP_ROLES.includes(role) || (0, import_editor10.isLipInsideRole)(role);
|
|
4720
5886
|
var MIN_OPENING_ROWS = 8;
|
|
4721
5887
|
var MIN_LINE_ROWS = 2;
|
|
4722
5888
|
var GREEN_EXCESS = 40;
|
|
@@ -4724,8 +5890,8 @@ var INTERIOR_GAP_FRACTION = 0.05;
|
|
|
4724
5890
|
var columns = (cols) => `${cols.length} column${cols.length === 1 ? "" : "s"} (first at x=${cols[0]})`;
|
|
4725
5891
|
async function lipWarnings(absDir, layers) {
|
|
4726
5892
|
const warnings = [];
|
|
4727
|
-
const present =
|
|
4728
|
-
const inside =
|
|
5893
|
+
const present = import_editor10.LIP_ROLES.filter((role) => layers[role] !== void 0);
|
|
5894
|
+
const inside = import_editor10.LIP_INSIDE_ROLES.filter((role) => layers[role] !== void 0);
|
|
4729
5895
|
if (present.length === 0) {
|
|
4730
5896
|
if (inside.length > 0) {
|
|
4731
5897
|
warnings.push(
|
|
@@ -4742,8 +5908,8 @@ async function lipWarnings(absDir, layers) {
|
|
|
4742
5908
|
`${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.`
|
|
4743
5909
|
);
|
|
4744
5910
|
}
|
|
4745
|
-
if (present.length <
|
|
4746
|
-
const missing =
|
|
5911
|
+
if (present.length < import_editor10.LIP_ROLES.length) {
|
|
5912
|
+
const missing = import_editor10.LIP_ROLES.filter((role) => layers[role] === void 0);
|
|
4747
5913
|
warnings.push(
|
|
4748
5914
|
`${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.`
|
|
4749
5915
|
);
|
|
@@ -4774,18 +5940,18 @@ async function lipWarnings(absDir, layers) {
|
|
|
4774
5940
|
);
|
|
4775
5941
|
}
|
|
4776
5942
|
}
|
|
4777
|
-
const measurer = (0,
|
|
5943
|
+
const measurer = (0, import_editor10.createLayerSetMeasurer)({
|
|
4778
5944
|
width: inner.canvasW,
|
|
4779
5945
|
height: inner.canvasH
|
|
4780
5946
|
});
|
|
4781
5947
|
const set = /* @__PURE__ */ new Map();
|
|
4782
5948
|
const green = [];
|
|
4783
|
-
for (const role of
|
|
5949
|
+
for (const role of import_editor10.LIP_ROLES) {
|
|
4784
5950
|
const fileName = `${role}.png`;
|
|
4785
5951
|
const { rgba } = await decodePng(import_node_path7.default.join(absDir, fileName));
|
|
4786
5952
|
set.set(role, measurer.add({ role, fileName, rgba }));
|
|
4787
5953
|
for (let i = 0; i < rgba.length; i += 4) {
|
|
4788
|
-
if (rgba[i + 3] >=
|
|
5954
|
+
if (rgba[i + 3] >= import_editor10.ALPHA_OPAQUE && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > GREEN_EXCESS) {
|
|
4789
5955
|
green.push(role);
|
|
4790
5956
|
break;
|
|
4791
5957
|
}
|
|
@@ -4793,15 +5959,15 @@ async function lipWarnings(absDir, layers) {
|
|
|
4793
5959
|
}
|
|
4794
5960
|
let opening;
|
|
4795
5961
|
try {
|
|
4796
|
-
opening = (0,
|
|
5962
|
+
opening = (0, import_editor10.mouthOpening)(set);
|
|
4797
5963
|
} catch (err) {
|
|
4798
|
-
if (err instanceof
|
|
5964
|
+
if (err instanceof import_editor10.LayerGeometryError) {
|
|
4799
5965
|
warnings.push(err.message);
|
|
4800
5966
|
return { warnings };
|
|
4801
5967
|
}
|
|
4802
5968
|
throw err;
|
|
4803
5969
|
}
|
|
4804
|
-
const innerRuns = (0,
|
|
5970
|
+
const innerRuns = (0, import_editor10.columnRuns)(set.get("mouth_inner"));
|
|
4805
5971
|
const noInterior = [];
|
|
4806
5972
|
const gap = [];
|
|
4807
5973
|
const noLine = [];
|
|
@@ -4887,8 +6053,8 @@ async function lipWarnings(absDir, layers) {
|
|
|
4887
6053
|
|
|
4888
6054
|
// src/measure-turn.ts
|
|
4889
6055
|
var import_node_path8 = __toESM(require("path"));
|
|
4890
|
-
var import_editor10 = require("@ikijs/editor");
|
|
4891
6056
|
var import_editor11 = require("@ikijs/editor");
|
|
6057
|
+
var import_editor12 = require("@ikijs/editor");
|
|
4892
6058
|
var DEFAULT_IRIS = { hueMin: 230, hueMax: 300, satMin: 0.22 };
|
|
4893
6059
|
var IRIS_V_MIN = 0.18;
|
|
4894
6060
|
var IRIS_V_MAX = 0.95;
|
|
@@ -5038,7 +6204,7 @@ async function measureTurnImage(filePath, iris) {
|
|
|
5038
6204
|
let transparent = false;
|
|
5039
6205
|
if (hasAlpha) {
|
|
5040
6206
|
for (let i = 0; i < n; i++) {
|
|
5041
|
-
if (rgba[i * 4 + 3] <
|
|
6207
|
+
if (rgba[i * 4 + 3] < import_editor11.ALPHA_OPAQUE) {
|
|
5042
6208
|
transparent = true;
|
|
5043
6209
|
break;
|
|
5044
6210
|
}
|
|
@@ -5049,7 +6215,7 @@ async function measureTurnImage(filePath, iris) {
|
|
|
5049
6215
|
const fg = new Uint8Array(n);
|
|
5050
6216
|
const value = new Float32Array(n);
|
|
5051
6217
|
for (let i = 0; i < n; i++) {
|
|
5052
|
-
if (rgba[i * 4 + 3] <
|
|
6218
|
+
if (rgba[i * 4 + 3] < import_editor11.ALPHA_OPAQUE) continue;
|
|
5053
6219
|
const [hue, s, v] = rgbToHsv(rgba[i * 4], rgba[i * 4 + 1], rgba[i * 4 + 2]);
|
|
5054
6220
|
if (maskMode === "alpha") {
|
|
5055
6221
|
fg[i] = 1;
|
|
@@ -5115,12 +6281,12 @@ async function measureTurnImage(filePath, iris) {
|
|
|
5115
6281
|
}
|
|
5116
6282
|
const [irisL, irisR] = best.pair;
|
|
5117
6283
|
const eyeRow = Math.round((irisL.cy + irisR.cy) / 2);
|
|
5118
|
-
const { left, right } = (0,
|
|
6284
|
+
const { left, right } = (0, import_editor11.foregroundSpan)(
|
|
5119
6285
|
fg,
|
|
5120
6286
|
width,
|
|
5121
6287
|
height,
|
|
5122
|
-
eyeRow -
|
|
5123
|
-
eyeRow +
|
|
6288
|
+
eyeRow - import_editor11.HEAD_BAND,
|
|
6289
|
+
eyeRow + import_editor11.HEAD_BAND
|
|
5124
6290
|
);
|
|
5125
6291
|
if (right <= left) {
|
|
5126
6292
|
throw new AutoRigInputError(
|
|
@@ -5144,7 +6310,7 @@ async function measureTurnImage(filePath, iris) {
|
|
|
5144
6310
|
left,
|
|
5145
6311
|
right,
|
|
5146
6312
|
cx: (left + right) / 2,
|
|
5147
|
-
half: (0,
|
|
6313
|
+
half: (0, import_editor11.headHalfOf)({ left, right })
|
|
5148
6314
|
},
|
|
5149
6315
|
pairCx: (irisL.cx + irisR.cx) / 2,
|
|
5150
6316
|
eyeGap: irisR.cx - irisL.cx
|
|
@@ -5335,7 +6501,7 @@ function noseSpeckWarning({ core, part }, source) {
|
|
|
5335
6501
|
`the layer's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} crop`,
|
|
5336
6502
|
`auto_rig_from_layers turns and tilts the nose about its whole crop instead`
|
|
5337
6503
|
];
|
|
5338
|
-
return `nose: ${found} \u2014 under ${
|
|
6504
|
+
return `nose: ${found} \u2014 under ${import_editor12.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.`;
|
|
5339
6505
|
}
|
|
5340
6506
|
async function lashOffSclera(eyePath, lashPath) {
|
|
5341
6507
|
const eye = await decodePng(eyePath);
|
|
@@ -5353,7 +6519,7 @@ async function lashOffSclera(eyePath, lashPath) {
|
|
|
5353
6519
|
return { opaque, off };
|
|
5354
6520
|
}
|
|
5355
6521
|
async function measureDir(absDir, noseSpeck) {
|
|
5356
|
-
const files =
|
|
6522
|
+
const files = import_node_fs7.default.readdirSync(absDir).filter((f) => f.endsWith(".png") && !f.startsWith("preview")).sort();
|
|
5357
6523
|
if (files.length === 0) {
|
|
5358
6524
|
throw new AutoRigInputError(`no role layers in ${absDir}`);
|
|
5359
6525
|
}
|
|
@@ -5473,10 +6639,10 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
5473
6639
|
warnings.push(noseSpeckWarning(noseSpeck, "compose"));
|
|
5474
6640
|
} else if (layers.nose !== void 0) {
|
|
5475
6641
|
const nose = await decodePng(import_node_path9.default.join(absDir, "nose.png"));
|
|
5476
|
-
const core = (0,
|
|
6642
|
+
const core = (0, import_editor12.denseCoreOf)(nose.rgba, nose.width, nose.height);
|
|
5477
6643
|
if (core !== null) {
|
|
5478
6644
|
const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
|
|
5479
|
-
if ((0,
|
|
6645
|
+
if ((0, import_editor12.isSpeckCore)(core, crop))
|
|
5480
6646
|
warnings.push(noseSpeckWarning({ core, part: crop }, "layer"));
|
|
5481
6647
|
}
|
|
5482
6648
|
}
|
|
@@ -5547,12 +6713,12 @@ function formatMeasureReport(result) {
|
|
|
5547
6713
|
|
|
5548
6714
|
// src/compose-arms.ts
|
|
5549
6715
|
var import_sharp3 = __toESM(require("sharp"));
|
|
5550
|
-
var
|
|
6716
|
+
var import_editor13 = require("@ikijs/editor");
|
|
5551
6717
|
var ARM_WIDTH = 0.4;
|
|
5552
6718
|
var SHOULDER_DROP = 0.12;
|
|
5553
6719
|
async function armPlacement(role, cfg, part, body) {
|
|
5554
6720
|
const { data } = await (0, import_sharp3.default)(part.buf).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
5555
|
-
const layer = (0,
|
|
6721
|
+
const layer = (0, import_editor13.createLayerSetMeasurer)({ width: part.w, height: part.h }).add({
|
|
5556
6722
|
role,
|
|
5557
6723
|
fileName: "arm.png",
|
|
5558
6724
|
rgba: data
|
|
@@ -5564,9 +6730,9 @@ async function armPlacement(role, cfg, part, body) {
|
|
|
5564
6730
|
}
|
|
5565
6731
|
let g;
|
|
5566
6732
|
try {
|
|
5567
|
-
g = (0,
|
|
6733
|
+
g = (0, import_editor13.armGeometry)(layer, role === "arm_R" ? Infinity : -Infinity);
|
|
5568
6734
|
} catch (err) {
|
|
5569
|
-
if (err instanceof
|
|
6735
|
+
if (err instanceof import_editor13.LayerGeometryError) {
|
|
5570
6736
|
throw new AutoRigInputError(`layout.${role}: ${err.message}`);
|
|
5571
6737
|
}
|
|
5572
6738
|
throw err;
|
|
@@ -5593,7 +6759,7 @@ async function armPlacement(role, cfg, part, body) {
|
|
|
5593
6759
|
}
|
|
5594
6760
|
async function poseGeometryOf(role, png, size, when) {
|
|
5595
6761
|
const { data } = await (0, import_sharp3.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
5596
|
-
const layer = (0,
|
|
6762
|
+
const layer = (0, import_editor13.createLayerSetMeasurer)({
|
|
5597
6763
|
width: size.w,
|
|
5598
6764
|
height: size.h
|
|
5599
6765
|
}).add({ role, fileName: "forearm_pose.png", rgba: data });
|
|
@@ -5602,7 +6768,7 @@ async function poseGeometryOf(role, png, size, when) {
|
|
|
5602
6768
|
`layout.${role}: forearm_pose.png is empty after alpha threshold${when}`
|
|
5603
6769
|
);
|
|
5604
6770
|
}
|
|
5605
|
-
return (0,
|
|
6771
|
+
return (0, import_editor13.forearmPoseGeometry)(layer);
|
|
5606
6772
|
}
|
|
5607
6773
|
async function forearmPoseWidth(role, trimmed, elbowRun) {
|
|
5608
6774
|
const g = await poseGeometryOf(role, trimmed.data, trimmed, "");
|
|
@@ -5900,18 +7066,18 @@ function keyWhiteToAlpha(rgba) {
|
|
|
5900
7066
|
async function coreAndBoundsOf(png) {
|
|
5901
7067
|
const { data, info } = await (0, import_sharp4.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
5902
7068
|
return {
|
|
5903
|
-
core: (0,
|
|
7069
|
+
core: (0, import_editor12.denseCoreOf)(data, info.width, info.height),
|
|
5904
7070
|
bounds: { x: 0, y: 0, w: info.width, h: info.height }
|
|
5905
7071
|
};
|
|
5906
7072
|
}
|
|
5907
7073
|
async function hasCoverage(png) {
|
|
5908
7074
|
const { data, info } = await (0, import_sharp4.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
5909
|
-
return (0,
|
|
7075
|
+
return (0, import_editor14.detectAlphaBbox)(data, info.width, info.height) !== null;
|
|
5910
7076
|
}
|
|
5911
7077
|
async function noseSizingOf(png) {
|
|
5912
7078
|
const { core, bounds } = await coreAndBoundsOf(png);
|
|
5913
7079
|
if (core === null) return { box: bounds, whole: true };
|
|
5914
|
-
if ((0,
|
|
7080
|
+
if ((0, import_editor12.isSpeckCore)(core, bounds)) {
|
|
5915
7081
|
return {
|
|
5916
7082
|
box: bounds,
|
|
5917
7083
|
whole: true,
|
|
@@ -5929,7 +7095,7 @@ async function trimmedPart(role, cfg, partsDir, inMemory, flipSource) {
|
|
|
5929
7095
|
img = (0, import_sharp4.default)(inMemory);
|
|
5930
7096
|
} else {
|
|
5931
7097
|
const srcPath = import_node_path10.default.join(partsDir, cfg.src);
|
|
5932
|
-
if (!
|
|
7098
|
+
if (!import_node_fs8.default.existsSync(srcPath)) {
|
|
5933
7099
|
if (cfg.optional) return null;
|
|
5934
7100
|
throw new AutoRigInputError(
|
|
5935
7101
|
`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" : "")
|
|
@@ -6033,7 +7199,7 @@ function detachedAboveWhite(rgba, W, H) {
|
|
|
6033
7199
|
for (let p = 0; p < n; p++) {
|
|
6034
7200
|
const alpha = rgba[p * 4 + 3];
|
|
6035
7201
|
if (alpha > 0 && luma(rgba, p * 4) >= EYE_LASH_LUMA)
|
|
6036
|
-
ink[p] = alpha >=
|
|
7202
|
+
ink[p] = alpha >= import_editor14.ALPHA_OPAQUE ? 2 : 1;
|
|
6037
7203
|
}
|
|
6038
7204
|
const label = new Int32Array(n).fill(-1);
|
|
6039
7205
|
const stack = new Int32Array(n);
|
|
@@ -6114,7 +7280,7 @@ function detachedAboveWhite(rgba, W, H) {
|
|
|
6114
7280
|
}
|
|
6115
7281
|
async function prepEyeSplit(partsDir) {
|
|
6116
7282
|
const srcPath = import_node_path10.default.join(partsDir, EYEWHITE_SRC);
|
|
6117
|
-
if (!
|
|
7283
|
+
if (!import_node_fs8.default.existsSync(srcPath)) {
|
|
6118
7284
|
throw new AutoRigInputError(`missing eyewhite source: ${srcPath}`);
|
|
6119
7285
|
}
|
|
6120
7286
|
const { width: W, height: H, rgba: data } = await decodePng(srcPath);
|
|
@@ -6138,7 +7304,7 @@ async function prepEyeSplit(partsDir) {
|
|
|
6138
7304
|
const lashCutoffY = minY + LASH_KEEP_FRACTION * (maxY - minY + 1);
|
|
6139
7305
|
const detached = detachedAboveWhite(data, W, H);
|
|
6140
7306
|
const isDark = (i) => data[i + 3] > 0 && luma(data, i) < EYE_LASH_LUMA;
|
|
6141
|
-
const isLight = (i) => data[i + 3] >=
|
|
7307
|
+
const isLight = (i) => data[i + 3] >= import_editor14.ALPHA_OPAQUE && luma(data, i) >= EYE_LASH_LUMA;
|
|
6142
7308
|
const isWarm = (i) => data[i] - data[i + 2] >= EYE_LID_WARMTH;
|
|
6143
7309
|
const whiteTop = new Int32Array(W).fill(-1);
|
|
6144
7310
|
for (let x = 0; x < W; x++) {
|
|
@@ -6201,7 +7367,7 @@ function hasTransparency(rgba) {
|
|
|
6201
7367
|
return false;
|
|
6202
7368
|
}
|
|
6203
7369
|
async function prepLipSources(partsDir, mirrored) {
|
|
6204
|
-
const has = (name) =>
|
|
7370
|
+
const has = (name) => import_node_fs8.default.existsSync(import_node_path10.default.join(partsDir, name));
|
|
6205
7371
|
const keyed = has(KEYED_SRC);
|
|
6206
7372
|
const interior = has(INTERIOR_SRC);
|
|
6207
7373
|
if (keyed && !interior) {
|
|
@@ -6244,7 +7410,7 @@ async function composeLayersFromParts(input) {
|
|
|
6244
7410
|
try {
|
|
6245
7411
|
const outDir = resolveOutputDir(input.outDir);
|
|
6246
7412
|
const partsDir = resolveInputDir(input.partsDir);
|
|
6247
|
-
if (
|
|
7413
|
+
if (import_node_fs8.default.realpathSync(partsDir) === outDir) {
|
|
6248
7414
|
throw new AutoRigInputError(
|
|
6249
7415
|
`partsDir and outDir resolve to the same directory (${outDir}): composing would overwrite the source parts`
|
|
6250
7416
|
);
|
|
@@ -6308,7 +7474,7 @@ async function composeLayersFromParts(input) {
|
|
|
6308
7474
|
lip_lower: split2.lower,
|
|
6309
7475
|
lip_upper: split2.upper
|
|
6310
7476
|
}[role];
|
|
6311
|
-
if ((0,
|
|
7477
|
+
if ((0, import_editor14.isLipInsideRole)(role) && !await hasCoverage(buf)) {
|
|
6312
7478
|
skipped.push(role);
|
|
6313
7479
|
continue;
|
|
6314
7480
|
}
|
|
@@ -6323,7 +7489,7 @@ async function composeLayersFromParts(input) {
|
|
|
6323
7489
|
}
|
|
6324
7490
|
if (key === "arm_L" || key === "arm_R") {
|
|
6325
7491
|
const arm = layout[key];
|
|
6326
|
-
if (!
|
|
7492
|
+
if (!import_node_fs8.default.existsSync(import_node_path10.default.join(partsDir, arm.src))) continue;
|
|
6327
7493
|
const body = placed.find((p) => p.role === "body");
|
|
6328
7494
|
if (body === void 0) {
|
|
6329
7495
|
throw new AutoRigInputError(
|
|
@@ -6366,7 +7532,7 @@ async function composeLayersFromParts(input) {
|
|
|
6366
7532
|
}
|
|
6367
7533
|
if (key === "forearm_pose_L" || key === "forearm_pose_R") {
|
|
6368
7534
|
const pose = layout[key];
|
|
6369
|
-
if (!
|
|
7535
|
+
if (!import_node_fs8.default.existsSync(import_node_path10.default.join(partsDir, pose.src))) continue;
|
|
6370
7536
|
const armRole = key === "forearm_pose_L" ? "arm_L" : "arm_R";
|
|
6371
7537
|
const arm = placed.find((p) => p.role === armRole);
|
|
6372
7538
|
if (arm?.elbow === void 0 || arm.elbowRun === void 0) {
|
|
@@ -6483,11 +7649,11 @@ async function composeLayersFromParts(input) {
|
|
|
6483
7649
|
);
|
|
6484
7650
|
for (const role of ORDER) {
|
|
6485
7651
|
if (placed.some((p) => p.role === role)) continue;
|
|
6486
|
-
|
|
7652
|
+
import_node_fs8.default.rmSync(import_node_path10.default.join(outDir, `${role}.png`), { force: true });
|
|
6487
7653
|
}
|
|
6488
7654
|
const posed = (role) => role === "forearm_pose_L" || role === "forearm_pose_R";
|
|
6489
7655
|
if (!placed.some((p) => posed(p.role))) {
|
|
6490
|
-
|
|
7656
|
+
import_node_fs8.default.rmSync(import_node_path10.default.join(outDir, "preview-pose.png"), { force: true });
|
|
6491
7657
|
}
|
|
6492
7658
|
const layers = [];
|
|
6493
7659
|
for (const { role, part, left, top } of placed) {
|
|
@@ -6503,7 +7669,7 @@ async function composeLayersFromParts(input) {
|
|
|
6503
7669
|
});
|
|
6504
7670
|
}
|
|
6505
7671
|
const restInput = (role, buf) => {
|
|
6506
|
-
if (role === "mouth_inner" || (0,
|
|
7672
|
+
if (role === "mouth_inner" || (0, import_editor14.isLipInsideRole)(role)) return null;
|
|
6507
7673
|
if (closed === void 0) return buf;
|
|
6508
7674
|
if (role === "lip_upper") return closed.upper;
|
|
6509
7675
|
if (role === "lip_lower") return closed.lower;
|
|
@@ -6628,8 +7794,21 @@ function formatPatchReports(reports) {
|
|
|
6628
7794
|
return `PATCH ${r.index} ${r.target} at ${at}: ${r.moved} of ${r.of} points (${where}), largest move ${r.maxPx} model px`;
|
|
6629
7795
|
});
|
|
6630
7796
|
}
|
|
7797
|
+
function formatCustomPartReports(parts) {
|
|
7798
|
+
return parts.map((p) => {
|
|
7799
|
+
const line = `CUSTOM ${p.id}: box ${p.box.x},${p.box.y} ${p.box.w}x${p.box.h} px, mesh ${p.mesh.vertices} vertices ${p.mesh.triangles} triangles, order ${p.order}, atlas page ${p.page}`;
|
|
7800
|
+
if (p.occlusion === void 0) return line;
|
|
7801
|
+
const { by, parameter, stops } = p.occlusion;
|
|
7802
|
+
return `${line}, hidden by ${by.join(",")} on ${parameter} at ${stops.map((s) => `${s.value}:${s.amount}`).join(" ")}`;
|
|
7803
|
+
});
|
|
7804
|
+
}
|
|
7805
|
+
function formatBakeChecks(bakes) {
|
|
7806
|
+
return bakes.map(
|
|
7807
|
+
(b) => `BAKE ${b.part} ${b.param}: ${b.vertices} vertices, stops ${b.stops.join(",")}, error ${Math.round(b.errorPx * 1e3) / 1e3} px`
|
|
7808
|
+
);
|
|
7809
|
+
}
|
|
6631
7810
|
function createIkiMcpServer() {
|
|
6632
|
-
const server = new import_mcp.McpServer({ name: "iki", version: "0.
|
|
7811
|
+
const server = new import_mcp.McpServer({ name: "iki", version: "0.35.0" });
|
|
6633
7812
|
server.registerTool(
|
|
6634
7813
|
"validate_iki",
|
|
6635
7814
|
{
|
|
@@ -6721,7 +7900,7 @@ function createIkiMcpServer() {
|
|
|
6721
7900
|
server.registerTool(
|
|
6722
7901
|
"auto_rig_from_layers",
|
|
6723
7902
|
{
|
|
6724
|
-
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, hair_side_L/hair_side_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, a side lock needs hair_front, 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. The result's `folds` is the written rig's fold report, printed after the path the way render_poses prints it, and report-only: a fold never refuses the rig. The `RIGPLAN:` line (the result's `rigPlan`: `effective`, `clamped`, `overriddenBy`) follows the path and precedes the `PATCH` lines. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output \u2014 a spring's, or each chain segment's \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. With side locks and a `nose` (which `turn` needs) the `HAIRSIDE` lines follow the `PHYSICS` lines (the result's `turn.hairSide`), each naming the lock's role, report-only as well. `patches` (see its field) adds displacements to existing keyform stops of the freshly generated rig; each op then prints one line between the path and the fold report \u2014 `PATCH <i> <target> at <Param=v \u2026>: <moved> of <of> points (cols a-b, rows c-d), largest move <maxPx> model px`, with `(vertices)` in place of the columns and rows for a mesh part \u2014 and the result's `patches` carries the same reports (`index`, `target`, `at`, `moved`, `of`, `cols`/`rows` for a grid, `maxPx`), present whenever `patches` was passed, `[]` included. An op the input schema accepts but the rig refuses comes back as `INVALID: patches[i]\u2026` and nothing is written; an op with a missing field or a field of the wrong type is the SDK's input validation error.",
|
|
7903
|
+
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, hair_side_L/hair_side_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, a side lock needs hair_front, 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. The result's `folds` is the written rig's fold report, printed after the path the way render_poses prints it, and report-only: a fold never refuses the rig. The `RIGPLAN:` line (the result's `rigPlan`: `effective`, `clamped`, `overriddenBy`) follows the path and precedes the `PATCH` lines. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output \u2014 a spring's, or each chain segment's \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. With side locks and a `nose` (which `turn` needs) the `HAIRSIDE` lines follow the `PHYSICS` lines (the result's `turn.hairSide`), each naming the lock's role, report-only as well. `patches` (see its field) adds displacements to existing keyform stops of the freshly generated rig; each op then prints one line between the path and the fold report \u2014 `PATCH <i> <target> at <Param=v \u2026>: <moved> of <of> points (cols a-b, rows c-d), largest move <maxPx> model px`, with `(vertices)` in place of the columns and rows for a mesh part \u2014 and the result's `patches` carries the same reports (`index`, `target`, `at`, `moved`, `of`, `cols`/`rows` for a grid, `maxPx`), present whenever `patches` was passed, `[]` included. An op the input schema accepts but the rig refuses comes back as `INVALID: patches[i]\u2026` and nothing is written; an op with a missing field or a field of the wrong type is the SDK's input validation error. `customParts` adds parts the rig has no role for (a twin tail, a hairpin), each from a canvas-sized PNG of its own, as an unrigged mesh on `headDeformer` after its `after` role's parts; it needs @ikijs/mcp 0.34.0, and an older server drops the field and returns no `customParts`. A part can declare `occlusion` (hidden where named roles' paint covers it, by an amount keyed on a parameter; it needs 0.35.0, and an older server refuses the key as `INVALID: customParts[i]\u2026`); its `CUSTOM <id>:` line then ends `, hidden by <id>,<id>\u2026 on <parameter> at <value>:<amount> <value>:<amount>\u2026`, and the result's part carries `occlusion` (`by` as the part ids written, `parameter`, `stops`). The result's `customParts` (`parts`: `id`, rest `box`, `mesh`, `order`, atlas `page`) is present whenever the input was passed, `[]` included, and one `CUSTOM <id>: \u2026` line per part follows the `HAIRSIDE` lines. `bakes` (see its field) moves the custom parts with a parameter and needs `customParts`; each part and parameter it moves then prints one `BAKE <part> <param>: <n> vertices, stops <values>, error <px> px` line after the `CUSTOM` lines (the result's `customParts.bakes`: `part`, `param`, `vertices`, `stops`, `errorPx`), the written model having been landed through the engine, and a stop off by 0.1 px or more comes back as `INVALID: BAKE ERROR <part> <param>=<value>: \u2026`, and a part the bake moves at rest as `INVALID: BAKE ERROR <part> at rest: \u2026`, with nothing written (the rig and the engine disagree: report it as a bug in the packages). Whenever `customParts` was passed, the written model is also measured per custom part (the result's `customParts.gate`: `ok`, `limits`, `parts`, `failed`) and the text ends with its lines, `CUSTOM <id> FOLDS|TIE|SLIDE|EXPOSED|RIGID|TIP: \u2026` then `CUSTOM GATE pass` or `CUSTOM GATE FAIL: <part LINE, \u2026>`, always the last line: a part's least triangle area ratio, its tie's displacement against the anchor where the head does not turn and where it does, the hidden art showing, how far a rigid part bends and where its free end lands, each in px and face widths with its worst pose; `TIP` never fails the gate and the other lines do. The model is written either way; from 0.34.0 on `customParts` always carries `gate` (a gate that throws still writes the file and ends the text `CUSTOM GATE FAIL: gate error: <message>`), so a result without `customParts` is from an older server and was never gated. The custom layers are not role layers: they are left out of the head's width and turn measurements, and an empty or wrong-size one, or an entry the rig refuses, comes back as `INVALID: customParts[i]\u2026` with nothing written. A missing field or one of the wrong type (a `tie` that is not two numbers, say) is refused by the schema itself, as the SDK's input validation error.",
|
|
6725
7904
|
inputSchema: {
|
|
6726
7905
|
layers: import_zod.z.array(
|
|
6727
7906
|
import_zod.z.object({
|
|
@@ -6744,7 +7923,7 @@ function createIkiMcpServer() {
|
|
|
6744
7923
|
noseShift: import_zod.z.number().optional(),
|
|
6745
7924
|
mouthShift: import_zod.z.number().optional()
|
|
6746
7925
|
}).passthrough().optional().describe(
|
|
6747
|
-
"What the head turn is fitted to, as `measure_turn_reference` reports it off a front/turned reference pair. `eyeShift` (and the optional `noseShift`/`mouthShift`) is how far that feature slides across the head at full turn, as a fraction of the head's half-width \u2014 a MAGNITUDE: the rig turns both ways, so the sign is ignored. `farEyeRatio` is the far/near eye width at full turn over that same ratio at rest, `silhouetteRatio` the head's half-width turned over at rest. The half-width the shifts are fractions of is measured off the layers themselves, so it is not an input. An omitted field leaves that part of the turn at the profile the rig defaults to. A passed `eyeShift` is fitted by the turn's amount and clamped to the room the art leaves the far eye \u2014 the face plate's edge, or the bangs' side strand over the far iris (the result's `turn.clamped` lists every clamped field, `turn.achieved` what the rig reaches, and `turn.strandOverlap` how much of a far iris the bangs still cover). A passed `silhouetteRatio` is clamped too, only on a face drawn without hair and with ear islands, where narrowing the head that far would no longer cover the far ear's slide. Any other passed target this layer set cannot reach comes back as `INVALID: \u2026` naming the field and the attainable range, since it is a measurement rather than a preference. A field not named here is refused the same way."
|
|
7926
|
+
"What the head turn is fitted to, as `measure_turn_reference` reports it off a front/turned reference pair. `eyeShift` (and the optional `noseShift`/`mouthShift`) is how far that feature slides across the head at full turn, as a fraction of the head's half-width \u2014 a MAGNITUDE: the rig turns both ways, so the sign is ignored. `farEyeRatio` is the far/near eye width at full turn over that same ratio at rest, `silhouetteRatio` the head's half-width turned over at rest. The half-width the shifts are fractions of is measured off the layers themselves, so it is not an input. An omitted field leaves that part of the turn at the profile the rig defaults to. A passed `eyeShift` is fitted by the turn's amount and clamped to the room the art leaves the far eye \u2014 the face plate's edge, or the bangs' side strand over the far iris (the result's `turn.clamped` lists every clamped field, `turn.achieved` what the rig reaches, and `turn.strandOverlap` how much of a far iris the bangs still cover). A passed `silhouetteRatio` is clamped too, only on a face drawn without hair and with ear islands, where narrowing the head that far would no longer cover the far ear's slide. Any other passed target this layer set cannot reach comes back as `INVALID: \u2026` naming the field and the attainable range, since it is a measurement rather than a preference. A field not named here is refused the same way. A pair that shows a custom part crossing the eye row reads a wider head than the rig fits to, since the rig measures the role layers alone: measure a pair drawn without the custom parts."
|
|
6748
7927
|
),
|
|
6749
7928
|
style: import_zod.z.unknown().optional().describe(
|
|
6750
7929
|
"Removed in @ikijs/mcp 0.30.0: pass `rigPlan`. Any value here is refused with the field map."
|
|
@@ -6765,6 +7944,83 @@ function createIkiMcpServer() {
|
|
|
6765
7944
|
}).passthrough().optional().describe(
|
|
6766
7945
|
"Per-character tuning from the profile the rig defaults to, in three groups: `turn` (`amount`, `featureLead`, `eyeForeshorten`, `noseLead`: the last two turn only, the nod untouched, and fitted by `turnTargets.farEyeRatio` / `turnTargets.noseShift` when those are given, which the `RIGPLAN:` line then reports as overridden), `hair` (`follow`, `outlineFollow`, `sway`) and `eyes` (`blink`). `describe_rig_plan` lists every field's default, range, recommended span, step and poses. A value out of range, or a group or key not named there, comes back as `INVALID: rigPlan.<path> \u2026`; an object left out or `{}` is the profile. The result reports what the rig built with as `rigPlan` and a `RIGPLAN:` line."
|
|
6767
7946
|
),
|
|
7947
|
+
customParts: import_zod.z.array(
|
|
7948
|
+
import_zod.z.object({
|
|
7949
|
+
id: import_zod.z.string().describe(
|
|
7950
|
+
"The part's id: a plain identifier, not a role's name or a part id."
|
|
7951
|
+
),
|
|
7952
|
+
path: import_zod.z.string().describe(
|
|
7953
|
+
"The part's own PNG, the same size as the role layers (resolved against cwd), drawn alone and whole on a transparent ground."
|
|
7954
|
+
),
|
|
7955
|
+
anchor: import_zod.z.string().describe("The role whose layer the part is fixed against."),
|
|
7956
|
+
tie: import_zod.z.array(import_zod.z.number()).length(2).describe(
|
|
7957
|
+
"[x, y] in canvas px where the part meets the anchor: inside both the part's alpha box and the anchor layer's."
|
|
7958
|
+
),
|
|
7959
|
+
after: import_zod.z.string().describe(
|
|
7960
|
+
"A role of the set: the part is drawn right after that role's last part."
|
|
7961
|
+
),
|
|
7962
|
+
deformer: import_zod.z.string().optional().describe(
|
|
7963
|
+
"The matrix deformer it hangs on; only `headDeformer` (the default) is accepted."
|
|
7964
|
+
),
|
|
7965
|
+
rigid: import_zod.z.boolean().optional().describe(
|
|
7966
|
+
"The art does not bend (a hairpin, a ribbon): a bake that bends it by more than 0.0025 face widths at a stop, from its best-fit rotation and translation, is refused as `INVALID: bakes\u2026` with nothing written. Give a rigid part one displacement for every control point, or a rotation."
|
|
7967
|
+
),
|
|
7968
|
+
occlusion: import_zod.z.object({
|
|
7969
|
+
by: import_zod.z.array(import_zod.z.string()).describe(
|
|
7970
|
+
"Roles of the set whose paint hides the part (an arm role is its three parts); a non-empty list with no role repeated, each a role of the set. A role with a clipped or meshless part (`iris_L`, `forearm_pose_L`) is refused."
|
|
7971
|
+
),
|
|
7972
|
+
parameter: import_zod.z.string().describe(
|
|
7973
|
+
"Any declared parameter but a physics output (a spring's or a chain segment's)."
|
|
7974
|
+
),
|
|
7975
|
+
stops: import_zod.z.array(
|
|
7976
|
+
import_zod.z.object({
|
|
7977
|
+
value: import_zod.z.number(),
|
|
7978
|
+
amount: import_zod.z.number().describe(
|
|
7979
|
+
"0 to 1: 1 hides the part wherever the roles' paint lies over it."
|
|
7980
|
+
)
|
|
7981
|
+
}).passthrough()
|
|
7982
|
+
).describe(
|
|
7983
|
+
"At least one, `value` strictly ascending and inside the parameter's range. The amount is linear between stops and held before the first and after the last."
|
|
7984
|
+
)
|
|
7985
|
+
}).passthrough().optional().describe(
|
|
7986
|
+
"Hide the part where the named roles' paint covers it, by an amount keyed on a parameter: `{ by, parameter, stops: [{ value, amount }] }`. Cover is where a role's drawn alpha at that pose is at least 0.5, a hard edge; a role that fades (`mouth_open`, a blush, a pose forearm) covers only while drawn at half strength or more. Use the stops as a short switch starting a degree or more past the idle sway, the hiding's progress coming from the part's baked motion. Needs @ikijs/mcp 0.35.0; an older server refuses the key as an unknown key (`INVALID: customParts[i]\u2026`). An unknown key, a bad stop or a part the key cannot be written for comes back as `INVALID: customParts[i].occlusion\u2026` with nothing written."
|
|
7987
|
+
)
|
|
7988
|
+
}).passthrough()
|
|
7989
|
+
).optional().describe(
|
|
7990
|
+
"Parts the auto-rigger has no role for, each `{ id, path, anchor, tie, after, deformer?, rigid?, occlusion? }`. A custom layer is read apart from `layers`: never role-parsed or measured, so its name is free and it does not widen the head the turn is fitted to; it counts toward the layer and pixel limits. All custom parts share one extra atlas page, the last, quantized on a palette of its own, so the other pages keep their bytes. An entry the rig refuses (an unknown key, a bad tie) comes back as `INVALID: customParts[i]\u2026` with nothing written; a missing field or one of the wrong type (a `tie` that is not two numbers, say) is refused by the schema itself, as the SDK's input validation error. `[]` is the same rig as leaving the field out, plus an empty `customParts` in the result."
|
|
7991
|
+
),
|
|
7992
|
+
bakes: import_zod.z.object({
|
|
7993
|
+
targets: import_zod.z.array(
|
|
7994
|
+
import_zod.z.object({
|
|
7995
|
+
id: import_zod.z.string().optional(),
|
|
7996
|
+
param: import_zod.z.string(),
|
|
7997
|
+
parts: import_zod.z.array(import_zod.z.string()),
|
|
7998
|
+
box: import_zod.z.object({
|
|
7999
|
+
x: import_zod.z.number(),
|
|
8000
|
+
y: import_zod.z.number(),
|
|
8001
|
+
w: import_zod.z.number(),
|
|
8002
|
+
h: import_zod.z.number()
|
|
8003
|
+
}).passthrough().optional(),
|
|
8004
|
+
grid: import_zod.z.object({ cols: import_zod.z.number(), rows: import_zod.z.number() }).passthrough(),
|
|
8005
|
+
stops: import_zod.z.record(
|
|
8006
|
+
import_zod.z.string(),
|
|
8007
|
+
import_zod.z.array(import_zod.z.array(import_zod.z.number()).length(2))
|
|
8008
|
+
),
|
|
8009
|
+
mirror: import_zod.z.boolean().optional(),
|
|
8010
|
+
why: import_zod.z.string().optional()
|
|
8011
|
+
}).passthrough()
|
|
8012
|
+
),
|
|
8013
|
+
meshes: import_zod.z.record(
|
|
8014
|
+
import_zod.z.string(),
|
|
8015
|
+
import_zod.z.object({
|
|
8016
|
+
rows: import_zod.z.array(import_zod.z.number()).optional(),
|
|
8017
|
+
cols: import_zod.z.number().optional(),
|
|
8018
|
+
cellPx: import_zod.z.number().optional()
|
|
8019
|
+
}).passthrough()
|
|
8020
|
+
).optional()
|
|
8021
|
+
}).passthrough().optional().describe(
|
|
8022
|
+
"Lattices that move the CUSTOM parts when a parameter does, which an unrigged custom part otherwise does not: `{ targets, meshes? }`; it needs `customParts` and names no other part. A target `{ id?, param, parts, box?, grid: { cols, rows }, stops, mirror?, why? }` is `(cols + 1) x (rows + 1)` control points laid evenly over `box` (canvas px; absent, the union of the parts' rest boxes grown by 2 px), listed row-major from the top-left; `stops` is `{ \"<value>\": [[dx, dy], \u2026 one per control point] }`. FRAME: every position and displacement is in canvas px, origin top-left, x right, y DOWN, the frame of the layer PNGs and of `describe_iki`'s boxes and `probe_rig`. A STOP is the part's TOTAL landed displacement from rest when `param` alone is at that value and every other parameter is at its default: the head's own carry is inside it, so a neighbour's displacement as `probe_rig` measures it is written as it is. Stop keys are values of `param` inside its range, never its default (rest is implicit). The landing is exact at rest, at each stop and at one end key at the range end on a side whose outermost stop is inside the range (it holds that stop's displacement); a side with no stop is not moved by the target. Between keys the offsets blend linearly, so under the head's roll (ParamAngleZ) the path bows off the line, about 1 px midway over 15\xB0: put a stop where the path matters. Each vertex takes the bilinear value of the lattice at its REST position, and a vertex outside `box` takes the nearest edge's value. `mirror: true` fills a missing stop from the one at the value mirrored about the rest value, when that value is inside the parameter's range: the lattice reflected about the box's vertical centre line, `dx` negated; a stop you wrote is never overwritten. Targets that name the same part and parameter SUM; a part in targets on two parameters gets one warp per parameter, and the two add in the head's frame, so under a roll a sway tilts with the head. `meshes` re-meshes a custom part before the bake, `{ <id>: { rows: [canvas-px y, \u2026], cols } }` (the first row at the part's top and the last at its bottom, within 0.5 px) or `{ <id>: { cellPx } }`; the rest picture is unchanged. The written model is then landed through the engine at every stop and at the range end each side holds its outermost stop to, and refused when one is off by 0.1 px or more. An input the rig refuses comes back as `INVALID: bakes\u2026` (`bakes.targets[2].stops[\"30\"][7]\u2026`) and nothing is written; a field of the wrong type is refused by the schema itself, as the SDK's input validation error. A bake is measured on one rig: after a retune of the layout or `rigPlan`, a regenerated anchor, a changed custom layer or an accepted patch batch, measure the stops again."
|
|
8023
|
+
),
|
|
6768
8024
|
patches: import_zod.z.array(
|
|
6769
8025
|
import_zod.z.object({
|
|
6770
8026
|
target: import_zod.z.string(),
|
|
@@ -6791,7 +8047,11 @@ function createIkiMcpServer() {
|
|
|
6791
8047
|
...args,
|
|
6792
8048
|
// `.length(2)` makes each region span a pair, which its inferred
|
|
6793
8049
|
// `number[]` cannot say.
|
|
6794
|
-
patches: args.patches
|
|
8050
|
+
patches: args.patches,
|
|
8051
|
+
customParts: args.customParts,
|
|
8052
|
+
// Each stop's `.length(2)` makes it a pair, which its inferred
|
|
8053
|
+
// `number[]` cannot say.
|
|
8054
|
+
bakes: args.bakes
|
|
6795
8055
|
});
|
|
6796
8056
|
const text = r.ok ? [
|
|
6797
8057
|
r.path,
|
|
@@ -6799,7 +8059,10 @@ function createIkiMcpServer() {
|
|
|
6799
8059
|
...formatPatchReports(r.patches ?? []),
|
|
6800
8060
|
...formatFoldReport(r.folds, r.canvas),
|
|
6801
8061
|
...formatPhysicsReport(r.physics),
|
|
6802
|
-
...formatHairSideReport(r.turn?.hairSide, r.canvas)
|
|
8062
|
+
...formatHairSideReport(r.turn?.hairSide, r.canvas),
|
|
8063
|
+
...formatCustomPartReports(r.customParts?.parts ?? []),
|
|
8064
|
+
...formatBakeChecks(r.customParts?.bakes ?? []),
|
|
8065
|
+
...r.customParts ? formatCustomGate(r.customParts.gate) : []
|
|
6803
8066
|
].join("\n") : `INVALID: ${r.error}`;
|
|
6804
8067
|
return { content: [{ type: "text", text }], structuredContent: r };
|
|
6805
8068
|
} catch (err) {
|
|
@@ -6891,7 +8154,7 @@ function createIkiMcpServer() {
|
|
|
6891
8154
|
server.registerTool(
|
|
6892
8155
|
"measure_turn_reference",
|
|
6893
8156
|
{
|
|
6894
|
-
description: "Measures how far a head turns between two images of the same character \u2014 a front view and a turned one, at the SAME scale \u2014 as three ratios, so a rigged turn can be compared to a reference turn (or to an earlier rig) without registering the images: farEyeRatio (turned far/near iris width over the same ratio at rest), eyeShift (how far the eye pair slides across the head, in units of the FRONT head half-width; NEGATIVE = toward the image's left), silhouetteRatio (head half-width, turned over front). The ratios divide out crop and position, not scale, so the pair must already share framing and head size; since a yaw never changes iris height, a pair whose mean iris height differs by more than 10% is refused instead of measured as a turn. Reads engine renders (transparent backdrop) and opaque reference art alike.",
|
|
8157
|
+
description: "Measures how far a head turns between two images of the same character \u2014 a front view and a turned one, at the SAME scale \u2014 as three ratios, so a rigged turn can be compared to a reference turn (or to an earlier rig) without registering the images: farEyeRatio (turned far/near iris width over the same ratio at rest), eyeShift (how far the eye pair slides across the head, in units of the FRONT head half-width; NEGATIVE = toward the image's left), silhouetteRatio (head half-width, turned over front). The ratios divide out crop and position, not scale, so the pair must already share framing and head size; since a yaw never changes iris height, a pair whose mean iris height differs by more than 10% is refused instead of measured as a turn. Reads engine renders (transparent backdrop) and opaque reference art alike. A pair that shows a custom part crossing the eye row reads a wider head than the rig fits to, so measure a pair drawn without the custom parts.",
|
|
6895
8158
|
inputSchema: {
|
|
6896
8159
|
front: import_zod.z.string().describe("Front-facing PNG file path (resolved against cwd)."),
|
|
6897
8160
|
turned: import_zod.z.string().describe("The same character turned, as a PNG file path."),
|
|
@@ -6974,7 +8237,10 @@ function createIkiMcpServer() {
|
|
|
6974
8237
|
}).optional()
|
|
6975
8238
|
})
|
|
6976
8239
|
).optional().describe(
|
|
6977
|
-
"More sweeps rendered after `sweep`, each `{ name, preset, crop? }` into its own `<outDir>/<name>/` (files and `crop` as `sweep`'s). Names are distinct from `sweep`'s and from each other's ignoring case, and presets are distinct (at most one of each). `turn` is `sweep`'s. `turn-nod` is the box (0,0) -> (0,-30) -> (-30,-30) -> (-30,+30) -> (+30,+30) -> (+30,-30) -> (0,-30) -> (0,0) of `ParamAngleX` x `ParamAngleY`, each leg eased, 6 s, 180 frames; its `sheet.png` is a 3 x 3 grid BY ANGLE (columns AngleX -30/0/+30, rows AngleY +30/0/-30, rest in the centre, cells labelled X, Y and t) and it has no kymograph. `manifest.json` is version 2 (`parameters`, and per frame `t` and `values`). A sweep dir's earlier frames, sheet, kymograph, manifest and flipbook are cleared first. An empty list, a repeated name or preset, or a bad crop comes back as `INVALID: sweeps...`. A server before 0.32.0 strips `sweeps` and renders the rest. The `SWEEP nod` lines (the eye-pair and iris-pair gap range and the mouth width range along the nod at each turn, in face widths) and `SWEEP corner` lines (the additivity residual per landmark at the four corners, the rest term included; 0 on an additive rig) print once per call whenever `sweep` or `sweeps` was asked for, report-only like `FOLD` and `PHYSICS`."
|
|
8240
|
+
"More sweeps rendered after `sweep`, each `{ name, preset, crop? }` into its own `<outDir>/<name>/` (files and `crop` as `sweep`'s). Names are distinct from `sweep`'s and from each other's ignoring case, and presets are distinct (at most one of each). `turn` is `sweep`'s. `roll` is the same eased curve on `ParamAngleZ` (0 to -30 to +30 to 0 over 3 s, 90 frames, physics running, idle off); its `sheet.png` is the nine frames nearest the turn sheet's angles on the -30 to +30 leg, labelled with the angle (Z) and time, and it has no kymograph (the eye row moves with the roll). `turn-nod` is the box (0,0) -> (0,-30) -> (-30,-30) -> (-30,+30) -> (+30,+30) -> (+30,-30) -> (0,-30) -> (0,0) of `ParamAngleX` x `ParamAngleY`, each leg eased, 6 s, 180 frames; its `sheet.png` is a 3 x 3 grid BY ANGLE (columns AngleX -30/0/+30, rows AngleY +30/0/-30, rest in the centre, cells labelled X, Y and t) and it has no kymograph. `manifest.json` is version 2 (`parameters`, and per frame `t` and `values`). A sweep dir's earlier frames, sheet, kymograph, manifest and flipbook are cleared first. An empty list, a repeated name or preset, or a bad crop comes back as `INVALID: sweeps...`. A server before 0.32.0 strips `sweeps` and renders the rest. The `SWEEP nod` lines (the eye-pair and iris-pair gap range and the mouth width range along the nod at each turn, in face widths) and `SWEEP corner` lines (the additivity residual per landmark at the four corners, the rest term included; 0 on an additive rig) print once per call whenever `sweep` or `sweeps` was asked for, report-only like `FOLD` and `PHYSICS`. A `roll` adds no `SWEEP` line of its own and changes none: they are read from the model. `roll` needs @ikijs/mcp 0.34.0; an older server refuses it as an input validation error."
|
|
8241
|
+
),
|
|
8242
|
+
hideParts: import_zod.z.array(import_zod.z.string()).optional().describe(
|
|
8243
|
+
"Part ids left out of the drawn frames (poses and sweeps); the fold, physics and sweep reports still read the whole model. Use it to render a character without its custom parts, so `measure_turn_reference` reads the rig's own head (a custom part crossing the eye row widens the head it measures, as it does on a drawn reference). An id the model lacks, or one that is the clip mask of a part that stays, or one a part that stays names in its `occlusion.by` (hide that part too), comes back as `INVALID: hideParts[i] \u2026` and nothing is rendered. Needs @ikijs/mcp 0.34.0; an older server drops the field and draws every part."
|
|
6978
8244
|
)
|
|
6979
8245
|
}
|
|
6980
8246
|
},
|
|
@@ -7010,6 +8276,54 @@ function createIkiMcpServer() {
|
|
|
7010
8276
|
}
|
|
7011
8277
|
}
|
|
7012
8278
|
);
|
|
8279
|
+
server.registerTool(
|
|
8280
|
+
"probe_rig",
|
|
8281
|
+
{
|
|
8282
|
+
description: "Measures a rigged .iki without rendering it, through the engine's own landing. Each query is one of: `paint` (the opaque runs, alpha 128 and over, of a layer PNG, per canvas row, as `{ y0, rows }` with `[x0, x1)` runs; read from the PNG you give, not the atlas, so a quantized model reads the same, and the PNG must be the model's canvas size), `land` (where each canvas-px point of a part lands in a pose) or `displacement` (the landing minus the point). The frame is canvas px, origin top-left, x right, y down \u2014 the frame of the layer PNGs and describe_iki's boxes. A point is `[x, y]` and must lie on the part at rest, inside one of its mesh triangles (a part without a mesh, its unit quad); its landing is then found by barycentric interpolation inside that triangle. A point outside the part's mesh comes back as `null`, never an extrapolation. `pose` is parameter settings: every parameter it does not name is at its default, a value outside the parameter's range is clamped as the player does, and an id the model does not declare or a non-finite value is refused. The text is the results as JSON, one entry per query in order. With `outputPath` (a `.probe.json` under the working directory, its folder existing) the results are written there as the same JSON and the text is the path and one line per query, so a part's paint stays out of your context for a rigging program to read. A query's refusal comes back as `INVALID: queries[i].<field> \u2026`, any refusal writes nothing.",
|
|
8283
|
+
inputSchema: {
|
|
8284
|
+
modelPath: import_zod.z.string().describe(
|
|
8285
|
+
"Rigged .iki file path (resolved against cwd; must sit under the working directory)."
|
|
8286
|
+
),
|
|
8287
|
+
queries: import_zod.z.array(
|
|
8288
|
+
import_zod.z.discriminatedUnion("op", [
|
|
8289
|
+
import_zod.z.object({
|
|
8290
|
+
op: import_zod.z.literal("paint"),
|
|
8291
|
+
path: import_zod.z.string().describe(
|
|
8292
|
+
"Canvas-sized layer PNG (resolved against cwd), the drawing the part was built from."
|
|
8293
|
+
)
|
|
8294
|
+
}),
|
|
8295
|
+
import_zod.z.object({
|
|
8296
|
+
op: import_zod.z.enum(["land", "displacement"]),
|
|
8297
|
+
part: import_zod.z.string().describe("A part id of the model."),
|
|
8298
|
+
points: import_zod.z.array(import_zod.z.array(import_zod.z.number()).length(2)).describe(
|
|
8299
|
+
"Canvas-px points `[x, y]`, at most 5000, each on the part at rest."
|
|
8300
|
+
),
|
|
8301
|
+
pose: import_zod.z.record(import_zod.z.string(), import_zod.z.number()).optional().describe(
|
|
8302
|
+
"Parameter id to value; the others stay at their defaults."
|
|
8303
|
+
)
|
|
8304
|
+
})
|
|
8305
|
+
])
|
|
8306
|
+
).describe("The queries, answered in order; at most 64 per call."),
|
|
8307
|
+
outputPath: import_zod.z.string().optional().describe(
|
|
8308
|
+
"A path ending in `.probe.json` (resolved against cwd, under it; its folder must exist) to write the results to."
|
|
8309
|
+
)
|
|
8310
|
+
}
|
|
8311
|
+
},
|
|
8312
|
+
async (args) => {
|
|
8313
|
+
try {
|
|
8314
|
+
const r = await probeRig(args);
|
|
8315
|
+
const text = !r.ok ? `INVALID: ${r.error}` : "results" in r ? JSON.stringify(r.results) : [r.outputPath, ...r.lines].join("\n");
|
|
8316
|
+
return { content: [{ type: "text", text }], structuredContent: r };
|
|
8317
|
+
} catch (err) {
|
|
8318
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
8319
|
+
return {
|
|
8320
|
+
content: [{ type: "text", text: `Unexpected error: ${error}` }],
|
|
8321
|
+
structuredContent: { ok: false, error },
|
|
8322
|
+
isError: true
|
|
8323
|
+
};
|
|
8324
|
+
}
|
|
8325
|
+
}
|
|
8326
|
+
);
|
|
7013
8327
|
return server;
|
|
7014
8328
|
}
|
|
7015
8329
|
|