@ikijs/mcp 0.33.0 → 0.34.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-5D7374FI.mjs → chunk-HKJT3Q6G.mjs} +1483 -336
- package/dist/chunk-HKJT3Q6G.mjs.map +1 -0
- package/dist/cli.js +1467 -326
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +286 -15
- package/dist/index.d.ts +286 -15
- package/dist/index.js +1477 -326
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -1
- package/package.json +2 -2
- package/dist/chunk-5D7374FI.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -30,8 +30,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
CUSTOM_GATE_LIMITS: () => CUSTOM_GATE_LIMITS,
|
|
33
34
|
SWEEP_PRESETS: () => SWEEP_PRESETS,
|
|
34
35
|
autoRigFromLayers: () => autoRigFromLayers,
|
|
36
|
+
checkCustomGate: () => checkCustomGate,
|
|
35
37
|
checkModelFolds: () => checkModelFolds,
|
|
36
38
|
checkNod: () => checkNod,
|
|
37
39
|
checkSweep: () => checkSweep,
|
|
@@ -40,6 +42,8 @@ __export(index_exports, {
|
|
|
40
42
|
describeIki: () => describeIki,
|
|
41
43
|
describeIkiAt: () => describeIkiAt,
|
|
42
44
|
describeRigPlan: () => describeRigPlan,
|
|
45
|
+
failedCustomGate: () => failedCustomGate,
|
|
46
|
+
formatCustomGate: () => formatCustomGate,
|
|
43
47
|
formatFoldReport: () => formatFoldReport,
|
|
44
48
|
formatHairSideReport: () => formatHairSideReport,
|
|
45
49
|
formatMeasureReport: () => formatMeasureReport,
|
|
@@ -51,6 +55,7 @@ __export(index_exports, {
|
|
|
51
55
|
listStandardParameters: () => listStandardParameters,
|
|
52
56
|
measureLayers: () => measureLayers,
|
|
53
57
|
measureTurnReference: () => measureTurnReference,
|
|
58
|
+
probeRig: () => probeRig,
|
|
54
59
|
renderPoses: () => renderPoses,
|
|
55
60
|
validateIki: () => validateIki
|
|
56
61
|
});
|
|
@@ -61,10 +66,10 @@ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${_
|
|
|
61
66
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
62
67
|
|
|
63
68
|
// src/tools.ts
|
|
64
|
-
var
|
|
69
|
+
var import_node_fs6 = require("fs");
|
|
65
70
|
var import_node_path5 = __toESM(require("path"));
|
|
66
|
-
var
|
|
67
|
-
var
|
|
71
|
+
var import_format11 = require("@ikijs/format");
|
|
72
|
+
var import_editor4 = require("@ikijs/editor");
|
|
68
73
|
|
|
69
74
|
// ../engine/src/math.ts
|
|
70
75
|
function clamp(value, min, max) {
|
|
@@ -1736,58 +1741,6 @@ function affectedParts(model, output) {
|
|
|
1736
1741
|
);
|
|
1737
1742
|
}
|
|
1738
1743
|
|
|
1739
|
-
// src/fold-report.ts
|
|
1740
|
-
var import_editor = require("@ikijs/editor");
|
|
1741
|
-
function checkModelFolds(model, extraValues = []) {
|
|
1742
|
-
const declared = new Set(model.parameters.map((p) => p.id));
|
|
1743
|
-
return checkFolds(model, {
|
|
1744
|
-
poses: [...foldPoses(model), ...extraValues.map(foldPose)],
|
|
1745
|
-
// The effective value, not the pose's overrides: the auto-rig's mouth
|
|
1746
|
-
// rests shut at its default, so `rest` and the other parameters' singles
|
|
1747
|
-
// are shut-mouth poses too.
|
|
1748
|
-
expected: (target2, _pose, value) => {
|
|
1749
|
-
if (target2.kind !== "part") return false;
|
|
1750
|
-
const shutBy = import_editor.SHUT_BY.get(target2.id);
|
|
1751
|
-
return shutBy !== void 0 && declared.has(shutBy) && value(shutBy) === 0;
|
|
1752
|
-
}
|
|
1753
|
-
});
|
|
1754
|
-
}
|
|
1755
|
-
function formatFoldReport(report, canvas) {
|
|
1756
|
-
const lines = report.offenders.length === 0 ? [`FOLDS: none over ${report.poses} poses`] : report.offenders.map((t) => offenderLine(t, t.worst, canvas));
|
|
1757
|
-
const closures = report.targets.flatMap((t) => {
|
|
1758
|
-
if (t.expected === void 0) return [];
|
|
1759
|
-
if (t.expected.ratio >= report.thresholds.collapse) return [];
|
|
1760
|
-
const shutBy = import_editor.SHUT_BY.get(t.target.id);
|
|
1761
|
-
const at = shutBy === void 0 ? "" : ` at ${shutBy}=0`;
|
|
1762
|
-
return [`${t.target.id} ${ratioText(t.expected.ratio)}${at}`];
|
|
1763
|
-
});
|
|
1764
|
-
if (closures.length > 0) {
|
|
1765
|
-
lines.push(
|
|
1766
|
-
`FOLDS expected: by-design closures, not findings \u2014 ${closures.join(", ")}`
|
|
1767
|
-
);
|
|
1768
|
-
}
|
|
1769
|
-
return lines;
|
|
1770
|
-
}
|
|
1771
|
-
function foldPose(values) {
|
|
1772
|
-
const ids = Object.keys(values).sort();
|
|
1773
|
-
const name = ids.length === 0 ? "rest" : ids.map((id) => `${id}=${values[id]}`).join(" ");
|
|
1774
|
-
return { name, values };
|
|
1775
|
-
}
|
|
1776
|
-
function offenderLine(t, hit, canvas) {
|
|
1777
|
-
const where = "triangle" in hit.where ? `triangle ${hit.where.triangle}` : `cell (${hit.where.col},${hit.where.row})`;
|
|
1778
|
-
const { x, y } = hit.rest;
|
|
1779
|
-
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`;
|
|
1780
|
-
}
|
|
1781
|
-
function ratioText(ratio) {
|
|
1782
|
-
if (ratio === 0) return "0";
|
|
1783
|
-
return Math.abs(ratio) < 0.01 ? ratio.toExponential(1) : ratio.toFixed(2);
|
|
1784
|
-
}
|
|
1785
|
-
|
|
1786
|
-
// src/render-poses.ts
|
|
1787
|
-
var import_node_fs4 = require("fs");
|
|
1788
|
-
var import_node_path4 = __toESM(require("path"));
|
|
1789
|
-
var import_format8 = require("@ikijs/format");
|
|
1790
|
-
|
|
1791
1744
|
// src/limits.ts
|
|
1792
1745
|
var import_node_fs = __toESM(require("fs"));
|
|
1793
1746
|
var import_node_path = __toESM(require("path"));
|
|
@@ -1798,6 +1751,8 @@ var MAX_ATLAS_SIDE = 4096;
|
|
|
1798
1751
|
var MAX_INPUT_PIXELS = 4096 * 4096;
|
|
1799
1752
|
var MAX_TOTAL_PIXELS = 128 * 1024 * 1024;
|
|
1800
1753
|
var MAX_OUTPUT_BYTES = 12 * 1024 * 1024;
|
|
1754
|
+
var MAX_PROBE_QUERIES = 64;
|
|
1755
|
+
var MAX_PROBE_POINTS = 5e3;
|
|
1801
1756
|
var AutoRigInputError = class extends Error {
|
|
1802
1757
|
constructor(message) {
|
|
1803
1758
|
super(message);
|
|
@@ -1854,12 +1809,14 @@ function confineToWorkingDirectory(root, dir, label, original) {
|
|
|
1854
1809
|
}
|
|
1855
1810
|
return realDir;
|
|
1856
1811
|
}
|
|
1857
|
-
function resolveOutputPath(outputPath) {
|
|
1812
|
+
function resolveOutputPath(outputPath, extension = ".iki") {
|
|
1858
1813
|
if (typeof outputPath !== "string" || outputPath.trim() === "") {
|
|
1859
1814
|
throw new AutoRigInputError("output path is empty");
|
|
1860
1815
|
}
|
|
1861
|
-
if (!outputPath.toLowerCase().endsWith(
|
|
1862
|
-
throw new AutoRigInputError(
|
|
1816
|
+
if (!outputPath.toLowerCase().endsWith(extension)) {
|
|
1817
|
+
throw new AutoRigInputError(
|
|
1818
|
+
`output path must end in ${extension}: ${outputPath}`
|
|
1819
|
+
);
|
|
1863
1820
|
}
|
|
1864
1821
|
const root = process.cwd();
|
|
1865
1822
|
const resolved = import_node_path.default.resolve(root, outputPath);
|
|
@@ -1909,18 +1866,989 @@ function writeFileAtomic(outPath, data) {
|
|
|
1909
1866
|
import_node_fs.default.rmSync(tmp, { force: true });
|
|
1910
1867
|
} catch {
|
|
1911
1868
|
}
|
|
1912
|
-
throw e;
|
|
1869
|
+
throw e;
|
|
1870
|
+
}
|
|
1871
|
+
} catch (e) {
|
|
1872
|
+
throw new AutoRigInputError(
|
|
1873
|
+
`write: ${e instanceof Error ? e.message : String(e)}`
|
|
1874
|
+
);
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
// src/bake-report.ts
|
|
1879
|
+
var BAKE_TOLERANCE_PX = 0.1;
|
|
1880
|
+
var BUG = "the rig and the engine disagree; report this as a bug in the packages";
|
|
1881
|
+
function checkBakes(model, reports) {
|
|
1882
|
+
const restOf = /* @__PURE__ */ new Map();
|
|
1883
|
+
for (const id of new Set(reports.map((r) => r.part))) {
|
|
1884
|
+
const rest = landParts(model, {}, [id]).get(id);
|
|
1885
|
+
const bare = landParts(
|
|
1886
|
+
{
|
|
1887
|
+
...model,
|
|
1888
|
+
parts: model.parts.map(
|
|
1889
|
+
(p) => p.id === id ? { ...p, warps: void 0 } : p
|
|
1890
|
+
)
|
|
1891
|
+
},
|
|
1892
|
+
{},
|
|
1893
|
+
[id]
|
|
1894
|
+
).get(id);
|
|
1895
|
+
let restGap = 0;
|
|
1896
|
+
for (let i = 0; i < rest.length; i++) {
|
|
1897
|
+
restGap = Math.max(restGap, Math.abs(rest[i] - bare[i]));
|
|
1898
|
+
}
|
|
1899
|
+
if (restGap >= BAKE_TOLERANCE_PX) {
|
|
1900
|
+
throw new AutoRigInputError(
|
|
1901
|
+
`BAKE ERROR ${id} at rest: the part moved ${restGap.toFixed(3)} px, where the bake must leave it (limit ${BAKE_TOLERANCE_PX} px); ${BUG}`
|
|
1902
|
+
);
|
|
1903
|
+
}
|
|
1904
|
+
restOf.set(id, rest);
|
|
1905
|
+
}
|
|
1906
|
+
return reports.map((r) => {
|
|
1907
|
+
const rest = restOf.get(r.part);
|
|
1908
|
+
let errorPx = 0;
|
|
1909
|
+
const asked = [
|
|
1910
|
+
...r.stops.map((value, s) => ({ value, wanted: r.wanted[s] })),
|
|
1911
|
+
...r.ends
|
|
1912
|
+
];
|
|
1913
|
+
asked.forEach(({ value, wanted }) => {
|
|
1914
|
+
const posed = landParts(model, { [r.param]: value }, [r.part]).get(
|
|
1915
|
+
r.part
|
|
1916
|
+
);
|
|
1917
|
+
let worst = 0;
|
|
1918
|
+
let worstVertex = 0;
|
|
1919
|
+
for (let v = 0; v < r.vertexCount; v++) {
|
|
1920
|
+
const gap = Math.hypot(
|
|
1921
|
+
posed[v * 2] - rest[v * 2] - wanted[v * 2],
|
|
1922
|
+
-(posed[v * 2 + 1] - rest[v * 2 + 1]) - wanted[v * 2 + 1]
|
|
1923
|
+
);
|
|
1924
|
+
if (gap > worst) {
|
|
1925
|
+
worst = gap;
|
|
1926
|
+
worstVertex = v;
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
if (worst >= BAKE_TOLERANCE_PX) {
|
|
1930
|
+
throw new AutoRigInputError(
|
|
1931
|
+
`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}`
|
|
1932
|
+
);
|
|
1933
|
+
}
|
|
1934
|
+
errorPx = Math.max(errorPx, worst);
|
|
1935
|
+
});
|
|
1936
|
+
return {
|
|
1937
|
+
part: r.part,
|
|
1938
|
+
param: r.param,
|
|
1939
|
+
vertices: r.vertexCount,
|
|
1940
|
+
stops: r.stops,
|
|
1941
|
+
errorPx
|
|
1942
|
+
};
|
|
1943
|
+
});
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1946
|
+
// src/custom-gate.ts
|
|
1947
|
+
var import_editor3 = require("@ikijs/editor");
|
|
1948
|
+
var import_format9 = require("@ikijs/format");
|
|
1949
|
+
|
|
1950
|
+
// src/fold-report.ts
|
|
1951
|
+
var import_editor = require("@ikijs/editor");
|
|
1952
|
+
function checkModelFolds(model, extraValues = []) {
|
|
1953
|
+
const declared = new Set(model.parameters.map((p) => p.id));
|
|
1954
|
+
return checkFolds(model, {
|
|
1955
|
+
poses: [...foldPoses(model), ...extraValues.map(foldPose)],
|
|
1956
|
+
// The effective value, not the pose's overrides: the auto-rig's mouth
|
|
1957
|
+
// rests shut at its default, so `rest` and the other parameters' singles
|
|
1958
|
+
// are shut-mouth poses too.
|
|
1959
|
+
expected: (target2, _pose, value) => {
|
|
1960
|
+
if (target2.kind !== "part") return false;
|
|
1961
|
+
const shutBy = import_editor.SHUT_BY.get(target2.id);
|
|
1962
|
+
return shutBy !== void 0 && declared.has(shutBy) && value(shutBy) === 0;
|
|
1963
|
+
}
|
|
1964
|
+
});
|
|
1965
|
+
}
|
|
1966
|
+
function formatFoldReport(report, canvas) {
|
|
1967
|
+
const lines = report.offenders.length === 0 ? [`FOLDS: none over ${report.poses} poses`] : report.offenders.map((t) => offenderLine(t, t.worst, canvas));
|
|
1968
|
+
const closures = report.targets.flatMap((t) => {
|
|
1969
|
+
if (t.expected === void 0) return [];
|
|
1970
|
+
if (t.expected.ratio >= report.thresholds.collapse) return [];
|
|
1971
|
+
const shutBy = import_editor.SHUT_BY.get(t.target.id);
|
|
1972
|
+
const at = shutBy === void 0 ? "" : ` at ${shutBy}=0`;
|
|
1973
|
+
return [`${t.target.id} ${ratioText(t.expected.ratio)}${at}`];
|
|
1974
|
+
});
|
|
1975
|
+
if (closures.length > 0) {
|
|
1976
|
+
lines.push(
|
|
1977
|
+
`FOLDS expected: by-design closures, not findings \u2014 ${closures.join(", ")}`
|
|
1978
|
+
);
|
|
1979
|
+
}
|
|
1980
|
+
return lines;
|
|
1981
|
+
}
|
|
1982
|
+
function foldPose(values) {
|
|
1983
|
+
const ids = Object.keys(values).sort();
|
|
1984
|
+
const name = ids.length === 0 ? "rest" : ids.map((id) => `${id}=${values[id]}`).join(" ");
|
|
1985
|
+
return { name, values };
|
|
1986
|
+
}
|
|
1987
|
+
function offenderLine(t, hit, canvas) {
|
|
1988
|
+
const where = "triangle" in hit.where ? `triangle ${hit.where.triangle}` : `cell (${hit.where.col},${hit.where.row})`;
|
|
1989
|
+
const { x, y } = hit.rest;
|
|
1990
|
+
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`;
|
|
1991
|
+
}
|
|
1992
|
+
function ratioText(ratio) {
|
|
1993
|
+
if (ratio === 0) return "0";
|
|
1994
|
+
return Math.abs(ratio) < 0.01 ? ratio.toExponential(1) : ratio.toFixed(2);
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1997
|
+
// src/probe.ts
|
|
1998
|
+
var import_node_fs2 = require("fs");
|
|
1999
|
+
var import_format8 = require("@ikijs/format");
|
|
2000
|
+
|
|
2001
|
+
// src/node-images.ts
|
|
2002
|
+
var import_sharp = __toESM(require("sharp"));
|
|
2003
|
+
var import_editor2 = require("@ikijs/editor");
|
|
2004
|
+
async function decodePng(filePath) {
|
|
2005
|
+
try {
|
|
2006
|
+
const pipeline = (0, import_sharp.default)(filePath, { limitInputPixels: MAX_INPUT_PIXELS });
|
|
2007
|
+
const metadata = await pipeline.metadata();
|
|
2008
|
+
if (metadata.format !== "png") {
|
|
2009
|
+
throw new AutoRigInputError(
|
|
2010
|
+
`non-PNG image (${metadata.format ?? "unknown"}): ${filePath}`
|
|
2011
|
+
);
|
|
2012
|
+
}
|
|
2013
|
+
const { data, info } = await pipeline.ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
2014
|
+
return {
|
|
2015
|
+
width: info.width,
|
|
2016
|
+
height: info.height,
|
|
2017
|
+
rgba: data,
|
|
2018
|
+
hasAlpha: metadata.hasAlpha ?? false
|
|
2019
|
+
};
|
|
2020
|
+
} catch (e) {
|
|
2021
|
+
if (e instanceof AutoRigInputError) throw e;
|
|
2022
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
2023
|
+
throw new AutoRigInputError(`failed to decode PNG ${filePath}: ${msg}`);
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
function detectAlphaBbox(rgba, width, height) {
|
|
2027
|
+
const bbox = (0, import_editor2.detectAlphaBbox)(rgba, width, height);
|
|
2028
|
+
if (bbox === null) {
|
|
2029
|
+
throw new AutoRigInputError("layer is empty after alpha threshold");
|
|
2030
|
+
}
|
|
2031
|
+
return bbox;
|
|
2032
|
+
}
|
|
2033
|
+
function cropToBuffer(rgba, width, height, bbox) {
|
|
2034
|
+
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();
|
|
2035
|
+
}
|
|
2036
|
+
function encodeOverlayPng(filePath, svg) {
|
|
2037
|
+
return (0, import_sharp.default)(filePath, { limitInputPixels: MAX_INPUT_PIXELS }).composite([{ input: Buffer.from(svg) }]).png().toBuffer();
|
|
2038
|
+
}
|
|
2039
|
+
async function renderAtlasToDataUri(crops, layout, quantizeColors) {
|
|
2040
|
+
const byId = /* @__PURE__ */ new Map();
|
|
2041
|
+
for (const crop of crops) byId.set(crop.id, crop);
|
|
2042
|
+
const pad = layout.padding;
|
|
2043
|
+
const composites = await Promise.all(
|
|
2044
|
+
layout.placements.map(async (placement3) => {
|
|
2045
|
+
const crop = byId.get(placement3.id);
|
|
2046
|
+
if (crop === void 0) {
|
|
2047
|
+
throw new AutoRigInputError(
|
|
2048
|
+
`no crop for atlas placement "${placement3.id}"`
|
|
2049
|
+
);
|
|
2050
|
+
}
|
|
2051
|
+
const input = pad > 0 ? await (0, import_sharp.default)(crop.buffer).extend({ right: pad, bottom: pad, extendWith: "copy" }).png().toBuffer() : crop.buffer;
|
|
2052
|
+
return { input, left: placement3.x, top: placement3.y };
|
|
2053
|
+
})
|
|
2054
|
+
);
|
|
2055
|
+
const page = await (0, import_sharp.default)({
|
|
2056
|
+
create: {
|
|
2057
|
+
width: layout.pageWidth,
|
|
2058
|
+
height: layout.pageHeight,
|
|
2059
|
+
channels: 4,
|
|
2060
|
+
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
|
2061
|
+
}
|
|
2062
|
+
}).composite(composites).png(
|
|
2063
|
+
quantizeColors === void 0 ? {} : { palette: true, colours: quantizeColors, dither: 0.5, effort: 10 }
|
|
2064
|
+
).toBuffer();
|
|
2065
|
+
return `data:image/png;base64,${page.toString("base64")}`;
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
// src/probe.ts
|
|
2069
|
+
var OUTPUT_SUFFIX = ".probe.json";
|
|
2070
|
+
var OPAQUE = 128;
|
|
2071
|
+
function paintRuns(png) {
|
|
2072
|
+
const { width, height, rgba } = png;
|
|
2073
|
+
const rows = [];
|
|
2074
|
+
let y0 = -1;
|
|
2075
|
+
for (let y = 0; y < height; y++) {
|
|
2076
|
+
const runs = [];
|
|
2077
|
+
let start = -1;
|
|
2078
|
+
for (let x = 0; x < width; x++) {
|
|
2079
|
+
const on = rgba[(y * width + x) * 4 + 3] >= OPAQUE;
|
|
2080
|
+
if (on && start < 0) start = x;
|
|
2081
|
+
if (!on && start >= 0) {
|
|
2082
|
+
runs.push([start, x]);
|
|
2083
|
+
start = -1;
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
if (start >= 0) runs.push([start, width]);
|
|
2087
|
+
if (runs.length > 0 && y0 < 0) y0 = y;
|
|
2088
|
+
if (y0 >= 0) rows.push(runs);
|
|
2089
|
+
}
|
|
2090
|
+
while (rows.length > 0 && rows[rows.length - 1].length === 0) rows.pop();
|
|
2091
|
+
return rows.length === 0 ? { y0: 0, rows: [] } : { y0, rows };
|
|
2092
|
+
}
|
|
2093
|
+
function toCanvas(model, pts) {
|
|
2094
|
+
const hw = model.canvas.width / 2;
|
|
2095
|
+
const hh = model.canvas.height / 2;
|
|
2096
|
+
const out = new Float64Array(pts.length);
|
|
2097
|
+
for (let i = 0; i < pts.length; i += 2) {
|
|
2098
|
+
out[i] = hw + pts[i];
|
|
2099
|
+
out[i + 1] = hh - pts[i + 1];
|
|
2100
|
+
}
|
|
2101
|
+
return out;
|
|
2102
|
+
}
|
|
2103
|
+
var round = (v) => Math.round(v * 1e3) / 1e3 + 0;
|
|
2104
|
+
function locate(vertices, tri, x, y) {
|
|
2105
|
+
const [a, b, c] = tri;
|
|
2106
|
+
const ax = vertices[a * 2];
|
|
2107
|
+
const ay = vertices[a * 2 + 1];
|
|
2108
|
+
const bx = vertices[b * 2];
|
|
2109
|
+
const by = vertices[b * 2 + 1];
|
|
2110
|
+
const cx = vertices[c * 2];
|
|
2111
|
+
const cy = vertices[c * 2 + 1];
|
|
2112
|
+
const d = (by - cy) * (ax - cx) + (cx - bx) * (ay - cy);
|
|
2113
|
+
if (Math.abs(d) < 1e-12) return null;
|
|
2114
|
+
const l1 = ((by - cy) * (x - cx) + (cx - bx) * (y - cy)) / d;
|
|
2115
|
+
const l2 = ((cy - ay) * (x - cx) + (ax - cx) * (y - cy)) / d;
|
|
2116
|
+
const l3 = 1 - l1 - l2;
|
|
2117
|
+
const eps = 1e-9;
|
|
2118
|
+
return l1 >= -eps && l2 >= -eps && l3 >= -eps ? [l1, l2, l3] : null;
|
|
2119
|
+
}
|
|
2120
|
+
var QUAD_INDICES = [0, 1, 2, 1, 3, 2];
|
|
2121
|
+
function restMesh(model, cache, partId) {
|
|
2122
|
+
let m = cache.get(partId);
|
|
2123
|
+
if (m) return m;
|
|
2124
|
+
const part = model.parts.find((p) => p.id === partId);
|
|
2125
|
+
const indices = part.mesh ? part.mesh.indices : QUAD_INDICES;
|
|
2126
|
+
const rest = toCanvas(model, landParts(model, {}, [partId]).get(partId));
|
|
2127
|
+
const boxes = new Float64Array(indices.length / 3 * 4);
|
|
2128
|
+
for (let t = 0; t < indices.length / 3; t++) {
|
|
2129
|
+
let x0 = Infinity;
|
|
2130
|
+
let y0 = Infinity;
|
|
2131
|
+
let x1 = -Infinity;
|
|
2132
|
+
let y1 = -Infinity;
|
|
2133
|
+
for (let k = 0; k < 3; k++) {
|
|
2134
|
+
const v = indices[t * 3 + k];
|
|
2135
|
+
x0 = Math.min(x0, rest[v * 2]);
|
|
2136
|
+
x1 = Math.max(x1, rest[v * 2]);
|
|
2137
|
+
y0 = Math.min(y0, rest[v * 2 + 1]);
|
|
2138
|
+
y1 = Math.max(y1, rest[v * 2 + 1]);
|
|
2139
|
+
}
|
|
2140
|
+
boxes.set([x0, y0, x1, y1], t * 4);
|
|
2141
|
+
}
|
|
2142
|
+
m = { indices, rest, boxes };
|
|
2143
|
+
cache.set(partId, m);
|
|
2144
|
+
return m;
|
|
2145
|
+
}
|
|
2146
|
+
function locatePoints(mesh, points) {
|
|
2147
|
+
const { indices, rest, boxes } = mesh;
|
|
2148
|
+
const slack = 1e-6;
|
|
2149
|
+
return points.map(([x, y]) => {
|
|
2150
|
+
for (let t = 0; t < indices.length / 3; t++) {
|
|
2151
|
+
const b = t * 4;
|
|
2152
|
+
if (x < boxes[b] - slack || x > boxes[b + 2] + slack || y < boxes[b + 1] - slack || y > boxes[b + 3] + slack) {
|
|
2153
|
+
continue;
|
|
2154
|
+
}
|
|
2155
|
+
const tri = [
|
|
2156
|
+
indices[t * 3],
|
|
2157
|
+
indices[t * 3 + 1],
|
|
2158
|
+
indices[t * 3 + 2]
|
|
2159
|
+
];
|
|
2160
|
+
const w = locate(rest, tri, x, y);
|
|
2161
|
+
if (w) return { tri, w };
|
|
2162
|
+
}
|
|
2163
|
+
return null;
|
|
2164
|
+
});
|
|
2165
|
+
}
|
|
2166
|
+
function landLocated(posed, at) {
|
|
2167
|
+
if (at === null) return null;
|
|
2168
|
+
let px2 = 0;
|
|
2169
|
+
let py = 0;
|
|
2170
|
+
for (let k = 0; k < 3; k++) {
|
|
2171
|
+
px2 += at.w[k] * posed[at.tri[k] * 2];
|
|
2172
|
+
py += at.w[k] * posed[at.tri[k] * 2 + 1];
|
|
2173
|
+
}
|
|
2174
|
+
return [px2, py];
|
|
2175
|
+
}
|
|
2176
|
+
function landPoints(model, cache, partId, points, pose) {
|
|
2177
|
+
const located = locatePoints(restMesh(model, cache, partId), points);
|
|
2178
|
+
const posed = toCanvas(model, landParts(model, pose, [partId]).get(partId));
|
|
2179
|
+
return located.map((at) => landLocated(posed, at));
|
|
2180
|
+
}
|
|
2181
|
+
function invalid(i, field, what) {
|
|
2182
|
+
return new AutoRigInputError(`queries[${i}].${field} ${what}`);
|
|
2183
|
+
}
|
|
2184
|
+
function checkPoints(i, points) {
|
|
2185
|
+
if (!Array.isArray(points) || points.length === 0) {
|
|
2186
|
+
throw invalid(i, "points", "must be a non-empty list of [x, y]");
|
|
2187
|
+
}
|
|
2188
|
+
if (points.length > MAX_PROBE_POINTS) {
|
|
2189
|
+
throw invalid(
|
|
2190
|
+
i,
|
|
2191
|
+
"points",
|
|
2192
|
+
`has ${points.length} points; at most ${MAX_PROBE_POINTS} per query`
|
|
2193
|
+
);
|
|
2194
|
+
}
|
|
2195
|
+
points.forEach((pt, k) => {
|
|
2196
|
+
if (!Array.isArray(pt) || pt.length !== 2 || !pt.every((v) => Number.isFinite(v))) {
|
|
2197
|
+
throw invalid(i, `points[${k}]`, "must be [x, y] with finite numbers");
|
|
2198
|
+
}
|
|
2199
|
+
});
|
|
2200
|
+
return points;
|
|
2201
|
+
}
|
|
2202
|
+
function checkPose(model, i, pose) {
|
|
2203
|
+
const declared = new Set(model.parameters.map((p) => p.id));
|
|
2204
|
+
for (const [id, v] of Object.entries(pose ?? {})) {
|
|
2205
|
+
if (!declared.has(id)) {
|
|
2206
|
+
throw invalid(i, `pose.${id}`, "is not a parameter the model declares");
|
|
2207
|
+
}
|
|
2208
|
+
if (typeof v !== "number" || !Number.isFinite(v)) {
|
|
2209
|
+
throw invalid(i, `pose.${id}`, "must be a finite number");
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
return pose ?? {};
|
|
2213
|
+
}
|
|
2214
|
+
function checkQuery(model, q, i) {
|
|
2215
|
+
if (q.op === "paint") return { op: "paint", path: q.path };
|
|
2216
|
+
if (q.op !== "land" && q.op !== "displacement") {
|
|
2217
|
+
throw invalid(i, "op", `must be paint, land or displacement`);
|
|
2218
|
+
}
|
|
2219
|
+
if (!model.parts.some((p) => p.id === q.part)) {
|
|
2220
|
+
throw invalid(i, "part", `names no part of the model: ${String(q.part)}`);
|
|
2221
|
+
}
|
|
2222
|
+
return {
|
|
2223
|
+
op: q.op,
|
|
2224
|
+
part: q.part,
|
|
2225
|
+
points: checkPoints(i, q.points),
|
|
2226
|
+
pose: checkPose(model, i, q.pose)
|
|
2227
|
+
};
|
|
2228
|
+
}
|
|
2229
|
+
async function runQuery(model, cache, q, i) {
|
|
2230
|
+
if (q.op === "paint") {
|
|
2231
|
+
const file = resolveInputPath(q.path, `queries[${i}].path`);
|
|
2232
|
+
let png;
|
|
2233
|
+
try {
|
|
2234
|
+
png = await decodePng(file);
|
|
2235
|
+
} catch (e) {
|
|
2236
|
+
if (e instanceof AutoRigInputError) throw invalid(i, "path", e.message);
|
|
2237
|
+
throw e;
|
|
2238
|
+
}
|
|
2239
|
+
const { width, height } = model.canvas;
|
|
2240
|
+
if (png.width !== width || png.height !== height) {
|
|
2241
|
+
throw invalid(
|
|
2242
|
+
i,
|
|
2243
|
+
"path",
|
|
2244
|
+
`is ${png.width}x${png.height}, not the model's canvas ${width}x${height}: ${q.path}`
|
|
2245
|
+
);
|
|
2246
|
+
}
|
|
2247
|
+
return { op: "paint", ...paintRuns(png) };
|
|
2248
|
+
}
|
|
2249
|
+
const { points } = q;
|
|
2250
|
+
const landed = landPoints(model, cache, q.part, points, q.pose);
|
|
2251
|
+
return {
|
|
2252
|
+
op: q.op,
|
|
2253
|
+
part: q.part,
|
|
2254
|
+
points: landed.map(
|
|
2255
|
+
(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])]
|
|
2256
|
+
)
|
|
2257
|
+
};
|
|
2258
|
+
}
|
|
2259
|
+
function summarize(r, i) {
|
|
2260
|
+
if (r.op === "paint") {
|
|
2261
|
+
return `${i} paint: ${r.rows.length} rows from y ${r.y0}`;
|
|
2262
|
+
}
|
|
2263
|
+
const off = r.points.filter((p) => p === null).length;
|
|
2264
|
+
return `${i} ${r.op} ${r.part}: ${r.points.length} points, ${off} off the mesh`;
|
|
2265
|
+
}
|
|
2266
|
+
async function probeRig(input) {
|
|
2267
|
+
try {
|
|
2268
|
+
const outFile = input.outputPath !== void 0 ? resolveOutputPath(input.outputPath, OUTPUT_SUFFIX) : void 0;
|
|
2269
|
+
const modelFile = confineToWorkingDirectory(
|
|
2270
|
+
process.cwd(),
|
|
2271
|
+
resolveInputPath(input.modelPath, "model"),
|
|
2272
|
+
"model path",
|
|
2273
|
+
input.modelPath
|
|
2274
|
+
);
|
|
2275
|
+
const model = (0, import_format8.loadIkiModel)((0, import_node_fs2.readFileSync)(modelFile, "utf8"));
|
|
2276
|
+
if (!Array.isArray(input.queries) || input.queries.length === 0) {
|
|
2277
|
+
throw new AutoRigInputError("queries must be a non-empty list");
|
|
2278
|
+
}
|
|
2279
|
+
if (input.queries.length > MAX_PROBE_QUERIES) {
|
|
2280
|
+
throw new AutoRigInputError(
|
|
2281
|
+
`queries has ${input.queries.length} entries; at most ${MAX_PROBE_QUERIES} per call`
|
|
2282
|
+
);
|
|
2283
|
+
}
|
|
2284
|
+
const checked = input.queries.map((q, i) => checkQuery(model, q, i));
|
|
2285
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2286
|
+
const results = [];
|
|
2287
|
+
for (const [i, q] of checked.entries()) {
|
|
2288
|
+
results.push(await runQuery(model, cache, q, i));
|
|
2289
|
+
}
|
|
2290
|
+
if (outFile === void 0) return { ok: true, results };
|
|
2291
|
+
writeFileAtomic(outFile, JSON.stringify(results));
|
|
2292
|
+
return {
|
|
2293
|
+
ok: true,
|
|
2294
|
+
outputPath: outFile,
|
|
2295
|
+
lines: results.map(summarize)
|
|
2296
|
+
};
|
|
2297
|
+
} catch (e) {
|
|
2298
|
+
if (e instanceof AutoRigInputError || e instanceof import_format8.IkiFormatError) {
|
|
2299
|
+
return { ok: false, error: e.message };
|
|
2300
|
+
}
|
|
2301
|
+
throw e;
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
// src/custom-gate.ts
|
|
2306
|
+
var CUSTOM_GATE_LIMITS = {
|
|
2307
|
+
tie: 5e-3,
|
|
2308
|
+
slide: 0.1,
|
|
2309
|
+
onAnchor: 0.015,
|
|
2310
|
+
exposed: 9e-4,
|
|
2311
|
+
rigid: 25e-4
|
|
2312
|
+
};
|
|
2313
|
+
function foldLimit(model) {
|
|
2314
|
+
return checkFolds(model, { poses: [] }).thresholds.collapse;
|
|
2315
|
+
}
|
|
2316
|
+
function failedCustomGate(model, error) {
|
|
2317
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2318
|
+
return {
|
|
2319
|
+
ok: false,
|
|
2320
|
+
faceWidth: model.parts.find((p) => p.id === "face")?.width ?? 0,
|
|
2321
|
+
limits: { ...CUSTOM_GATE_LIMITS, fold: foldLimit(model) },
|
|
2322
|
+
poses: 0,
|
|
2323
|
+
parts: [],
|
|
2324
|
+
failed: [`gate error: ${message}`]
|
|
2325
|
+
};
|
|
2326
|
+
}
|
|
2327
|
+
function readingOf(faceWidth, amount, dimension, pose, limit, reason) {
|
|
2328
|
+
const value = amount === null ? null : amount / faceWidth ** dimension;
|
|
2329
|
+
const pass = value !== null && value <= limit;
|
|
2330
|
+
return {
|
|
2331
|
+
value,
|
|
2332
|
+
...dimension === 1 ? { px: amount } : { px2: amount },
|
|
2333
|
+
pose,
|
|
2334
|
+
limit,
|
|
2335
|
+
pass,
|
|
2336
|
+
...pass ? {} : { reason }
|
|
2337
|
+
};
|
|
2338
|
+
}
|
|
2339
|
+
var TWIN_FACE = 402;
|
|
2340
|
+
var RING_PX = 5;
|
|
2341
|
+
var RING_DIAGONAL_PX = 4;
|
|
2342
|
+
var SAMPLE_REACH_PX = 80;
|
|
2343
|
+
var SAMPLE_STEP_PX = 4;
|
|
2344
|
+
var TIP_INSET_PX = 6;
|
|
2345
|
+
var EXPOSED_REACH = 0.15;
|
|
2346
|
+
var runsAt = (paint, y) => paint.rows[y - paint.y0] ?? [];
|
|
2347
|
+
function paintedAt(paint, x, y) {
|
|
2348
|
+
const px2 = Math.floor(x);
|
|
2349
|
+
return runsAt(paint, Math.floor(y)).some(([a, b]) => px2 >= a && px2 < b);
|
|
2350
|
+
}
|
|
2351
|
+
var GRID_CELLS = 64;
|
|
2352
|
+
function triangleGrid(posed, indices, bounds) {
|
|
2353
|
+
const cell = Math.max(
|
|
2354
|
+
16,
|
|
2355
|
+
(bounds.x1 - bounds.x0) / GRID_CELLS,
|
|
2356
|
+
(bounds.y1 - bounds.y0) / GRID_CELLS
|
|
2357
|
+
);
|
|
2358
|
+
const cols = Math.floor((bounds.x1 - bounds.x0) / cell) + 1;
|
|
2359
|
+
const rows = Math.floor((bounds.y1 - bounds.y0) / cell) + 1;
|
|
2360
|
+
const bins = /* @__PURE__ */ new Map();
|
|
2361
|
+
for (let t = 0; t < indices.length / 3; t++) {
|
|
2362
|
+
let x0 = Infinity;
|
|
2363
|
+
let y0 = Infinity;
|
|
2364
|
+
let x1 = -Infinity;
|
|
2365
|
+
let y1 = -Infinity;
|
|
2366
|
+
for (let k = 0; k < 3; k++) {
|
|
2367
|
+
const v = indices[t * 3 + k];
|
|
2368
|
+
x0 = Math.min(x0, posed[v * 2]);
|
|
2369
|
+
x1 = Math.max(x1, posed[v * 2]);
|
|
2370
|
+
y0 = Math.min(y0, posed[v * 2 + 1]);
|
|
2371
|
+
y1 = Math.max(y1, posed[v * 2 + 1]);
|
|
2372
|
+
}
|
|
2373
|
+
if (x1 < bounds.x0 || x0 > bounds.x1 || y1 < bounds.y0 || y0 > bounds.y1) {
|
|
2374
|
+
continue;
|
|
2375
|
+
}
|
|
2376
|
+
const cx0 = Math.max(0, Math.floor((x0 - bounds.x0) / cell));
|
|
2377
|
+
const cx1 = Math.min(cols - 1, Math.floor((x1 - bounds.x0) / cell));
|
|
2378
|
+
const cy0 = Math.max(0, Math.floor((y0 - bounds.y0) / cell));
|
|
2379
|
+
const cy1 = Math.min(rows - 1, Math.floor((y1 - bounds.y0) / cell));
|
|
2380
|
+
for (let cy = cy0; cy <= cy1; cy++) {
|
|
2381
|
+
for (let cx = cx0; cx <= cx1; cx++) {
|
|
2382
|
+
const k = cx + cy * cols;
|
|
2383
|
+
const bin = bins.get(k);
|
|
2384
|
+
if (bin) bin.push(t);
|
|
2385
|
+
else bins.set(k, [t]);
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
return (x, y) => x < bounds.x0 || y < bounds.y0 || x > bounds.x1 || y > bounds.y1 ? [] : bins.get(
|
|
2390
|
+
Math.floor((x - bounds.x0) / cell) + Math.floor((y - bounds.y0) / cell) * cols
|
|
2391
|
+
) ?? [];
|
|
2392
|
+
}
|
|
2393
|
+
function posesOf(model, baked, base) {
|
|
2394
|
+
const byName = new Map(base.map((p) => [p.name, p]));
|
|
2395
|
+
const add = (values) => {
|
|
2396
|
+
const pose = foldPose(values);
|
|
2397
|
+
if (!byName.has(pose.name)) byName.set(pose.name, pose);
|
|
2398
|
+
};
|
|
2399
|
+
const defaults = new Map(model.parameters.map((p) => [p.id, p.default]));
|
|
2400
|
+
for (const [param, stops] of baked) {
|
|
2401
|
+
for (const v of stops) if (v !== defaults.get(param)) add({ [param]: v });
|
|
2402
|
+
}
|
|
2403
|
+
const params = [...baked.keys()];
|
|
2404
|
+
for (let i = 0; i < params.length; i++) {
|
|
2405
|
+
for (let j = i + 1; j < params.length; j++) {
|
|
2406
|
+
for (const a of baked.get(params[i])) {
|
|
2407
|
+
if (a === defaults.get(params[i])) continue;
|
|
2408
|
+
for (const b of baked.get(params[j])) {
|
|
2409
|
+
if (b === defaults.get(params[j])) continue;
|
|
2410
|
+
add({ [params[i]]: a, [params[j]]: b });
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
return [...byName.values()];
|
|
2416
|
+
}
|
|
2417
|
+
function freeEnd(paint, tie, inset) {
|
|
2418
|
+
if (paint.rows.length === 0) return null;
|
|
2419
|
+
const [top, bottom] = [paint.y0, paint.y0 + paint.rows.length - 1];
|
|
2420
|
+
const y = Math.abs(bottom - tie[1]) > Math.abs(top - tie[1]) ? bottom : top;
|
|
2421
|
+
const runs = runsAt(paint, y);
|
|
2422
|
+
if (runs.length === 0) return null;
|
|
2423
|
+
const widest = runs.reduce((a, b) => b[1] - b[0] > a[1] - a[0] ? b : a);
|
|
2424
|
+
return [(widest[0] + widest[1]) / 2, y > tie[1] ? y - inset : y + inset];
|
|
2425
|
+
}
|
|
2426
|
+
function checkCustomGate(model, parts, paints, options = {}) {
|
|
2427
|
+
const face = model.parts.find((p) => p.id === "face");
|
|
2428
|
+
if (face === void 0) throw new Error("custom gate: the model has no face");
|
|
2429
|
+
const faceWidth = face.width;
|
|
2430
|
+
const limits = {
|
|
2431
|
+
...CUSTOM_GATE_LIMITS,
|
|
2432
|
+
fold: foldLimit(model)
|
|
2433
|
+
};
|
|
2434
|
+
if (parts.length === 0) {
|
|
2435
|
+
return {
|
|
2436
|
+
ok: true,
|
|
2437
|
+
faceWidth,
|
|
2438
|
+
limits,
|
|
2439
|
+
poses: 0,
|
|
2440
|
+
parts: [],
|
|
2441
|
+
failed: []
|
|
2442
|
+
};
|
|
2443
|
+
}
|
|
2444
|
+
const scale2 = faceWidth / TWIN_FACE;
|
|
2445
|
+
const px2 = (twin) => Math.max(1, Math.round(twin * scale2));
|
|
2446
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2447
|
+
const turnParam = model.parameters.find(
|
|
2448
|
+
(p) => p.id === import_format9.StandardParameter.AngleX
|
|
2449
|
+
);
|
|
2450
|
+
const turns = (pose) => turnParam !== void 0 && (pose.values[import_format9.StandardParameter.AngleX] ?? turnParam.default) !== turnParam.default;
|
|
2451
|
+
const bakedOf = (id) => {
|
|
2452
|
+
const part = model.parts.find((p) => p.id === id);
|
|
2453
|
+
return new Map(
|
|
2454
|
+
(part.warps ?? []).map((w) => [
|
|
2455
|
+
w.parameter,
|
|
2456
|
+
w.keyforms.map((k) => k.value)
|
|
2457
|
+
])
|
|
2458
|
+
);
|
|
2459
|
+
};
|
|
2460
|
+
const base = options.poses ?? foldPoses(model);
|
|
2461
|
+
const poseSets = parts.map((part) => {
|
|
2462
|
+
if (!model.parts.some((p) => p.id === part.id)) {
|
|
2463
|
+
throw new Error(`custom gate: the model has no part "${part.id}"`);
|
|
2464
|
+
}
|
|
2465
|
+
return options.poses ?? posesOf(model, bakedOf(part.id), base);
|
|
2466
|
+
});
|
|
2467
|
+
const all = new Map(poseSets.flat().map((p) => [p.name, p]));
|
|
2468
|
+
const reports = parts.map((part, n) => {
|
|
2469
|
+
const poses = poseSets[n];
|
|
2470
|
+
const roleParts = (0, import_editor3.partIdsOfRole)(part.anchor).filter(
|
|
2471
|
+
(id) => model.parts.some((p) => p.id === id)
|
|
2472
|
+
);
|
|
2473
|
+
const anchorId = roleParts.find(
|
|
2474
|
+
(id) => locatePoints(restMesh(model, cache, id), [part.tie])[0] !== null
|
|
2475
|
+
) ?? roleParts[0];
|
|
2476
|
+
const folds = checkFolds(model, { poses });
|
|
2477
|
+
const anchorPart = model.parts.find((p) => p.id === anchorId);
|
|
2478
|
+
if (anchorPart === void 0) {
|
|
2479
|
+
throw new Error(`custom gate: the model has no part "${anchorId}"`);
|
|
2480
|
+
}
|
|
2481
|
+
const ownPaint = paints.get(part.id);
|
|
2482
|
+
const anchorPaint = paints.get(part.anchor);
|
|
2483
|
+
if (ownPaint === void 0 || anchorPaint === void 0) {
|
|
2484
|
+
throw new Error(
|
|
2485
|
+
`custom gate: no paint for "${ownPaint === void 0 ? part.id : part.anchor}"`
|
|
2486
|
+
);
|
|
2487
|
+
}
|
|
2488
|
+
const partMesh = restMesh(model, cache, part.id);
|
|
2489
|
+
const anchorMesh = restMesh(model, cache, anchorId);
|
|
2490
|
+
const length = (amount, pose, limit, reason) => readingOf(faceWidth, amount, 1, pose, limit, reason);
|
|
2491
|
+
const ring = [
|
|
2492
|
+
[0, 0],
|
|
2493
|
+
[px2(RING_PX), 0],
|
|
2494
|
+
[-px2(RING_PX), 0],
|
|
2495
|
+
[0, px2(RING_PX)],
|
|
2496
|
+
[0, -px2(RING_PX)],
|
|
2497
|
+
[px2(RING_DIAGONAL_PX), px2(RING_DIAGONAL_PX)],
|
|
2498
|
+
[-px2(RING_DIAGONAL_PX), px2(RING_DIAGONAL_PX)],
|
|
2499
|
+
[px2(RING_DIAGONAL_PX), -px2(RING_DIAGONAL_PX)],
|
|
2500
|
+
[-px2(RING_DIAGONAL_PX), -px2(RING_DIAGONAL_PX)]
|
|
2501
|
+
].map(([dx, dy]) => [part.tie[0] + dx, part.tie[1] + dy]);
|
|
2502
|
+
const onPart = locatePoints(partMesh, ring);
|
|
2503
|
+
const onAnchor = locatePoints(anchorMesh, ring);
|
|
2504
|
+
const shared = ring.flatMap(
|
|
2505
|
+
(_, i) => onPart[i] && onAnchor[i] ? [i] : []
|
|
2506
|
+
);
|
|
2507
|
+
const reach = px2(SAMPLE_REACH_PX);
|
|
2508
|
+
const step = px2(SAMPLE_STEP_PX);
|
|
2509
|
+
const samples = [];
|
|
2510
|
+
const cx = Math.round(part.tie[0]);
|
|
2511
|
+
const cy = Math.round(part.tie[1]);
|
|
2512
|
+
for (let y = cy - reach; y <= cy + reach; y += step) {
|
|
2513
|
+
const runs = runsAt(anchorPaint, y);
|
|
2514
|
+
for (let x = cx - reach; x <= cx + reach; x += step) {
|
|
2515
|
+
if (runs.some(([a, b]) => x >= a && x < b))
|
|
2516
|
+
samples.push([x + 0.5, y + 0.5]);
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
const samplesOn = locatePoints(anchorMesh, samples).filter(
|
|
2520
|
+
(l) => l !== null
|
|
2521
|
+
);
|
|
2522
|
+
const [tieOnPart] = locatePoints(partMesh, [part.tie]);
|
|
2523
|
+
const partIndex = model.parts.findIndex((p) => p.id === part.id);
|
|
2524
|
+
const anchorIndex = model.parts.indexOf(anchorPart);
|
|
2525
|
+
const ownPart = model.parts[partIndex];
|
|
2526
|
+
const partLower = ownPart.order < anchorPart.order || ownPart.order === anchorPart.order && partIndex < anchorIndex;
|
|
2527
|
+
const [lowerId, upperId] = partLower ? [part.id, anchorId] : [anchorId, part.id];
|
|
2528
|
+
const [lowerMesh, upperMesh] = [
|
|
2529
|
+
restMesh(model, cache, lowerId),
|
|
2530
|
+
restMesh(model, cache, upperId)
|
|
2531
|
+
];
|
|
2532
|
+
const upperPaint = partLower ? anchorPaint : ownPaint;
|
|
2533
|
+
const exposedReach = Math.round(EXPOSED_REACH * faceWidth);
|
|
2534
|
+
const hidden = [];
|
|
2535
|
+
for (let y = Math.floor(part.tie[1]) - exposedReach; y <= Math.ceil(part.tie[1]) + exposedReach; y++) {
|
|
2536
|
+
for (const [a0, a1] of runsAt(ownPaint, y)) {
|
|
2537
|
+
for (const [b0, b1] of runsAt(anchorPaint, y)) {
|
|
2538
|
+
for (let x = Math.max(a0, b0); x < Math.min(a1, b1); x++) {
|
|
2539
|
+
if (Math.hypot(x + 0.5 - part.tie[0], y + 0.5 - part.tie[1]) <= exposedReach) {
|
|
2540
|
+
hidden.push([x + 0.5, y + 0.5]);
|
|
2541
|
+
}
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
const onAnchorMesh = locatePoints(anchorMesh, hidden);
|
|
2547
|
+
const hiddenOn = locatePoints(lowerMesh, hidden).filter(
|
|
2548
|
+
(l, i) => l !== null && onAnchorMesh[i] !== null
|
|
2549
|
+
);
|
|
2550
|
+
const stops = bakedOf(part.id);
|
|
2551
|
+
const worstOf = {
|
|
2552
|
+
tie: { v: -1, pose: "rest" },
|
|
2553
|
+
slide: { v: -1, pose: "rest" },
|
|
2554
|
+
onAnchor: { v: -1, pose: "rest" },
|
|
2555
|
+
exposed: { v: -1, pose: "rest" },
|
|
2556
|
+
exposedTurn: { v: -1, pose: "rest" },
|
|
2557
|
+
rigid: { v: -1, pose: "rest" }
|
|
2558
|
+
};
|
|
2559
|
+
const keep = (w, v, pose) => {
|
|
2560
|
+
if (v > w.v) {
|
|
2561
|
+
w.v = v;
|
|
2562
|
+
w.pose = pose;
|
|
2563
|
+
}
|
|
2564
|
+
};
|
|
2565
|
+
let onAnchorNull = null;
|
|
2566
|
+
let turningPoses = 0;
|
|
2567
|
+
const rest = partMesh.rest;
|
|
2568
|
+
const restPoints = [];
|
|
2569
|
+
for (let i = 0; i < rest.length; i += 2)
|
|
2570
|
+
restPoints.push([rest[i], rest[i + 1]]);
|
|
2571
|
+
const measureRigid = (pose, posed) => {
|
|
2572
|
+
const moved = [];
|
|
2573
|
+
for (let i = 0; i < posed.length; i += 2)
|
|
2574
|
+
moved.push([posed[i], posed[i + 1]]);
|
|
2575
|
+
keep(worstOf.rigid, (0, import_editor3.rigidResidual)(restPoints, moved), pose.name);
|
|
2576
|
+
};
|
|
2577
|
+
for (const pose of poses) {
|
|
2578
|
+
const landed = landParts(model, pose.values, [part.id, anchorId]);
|
|
2579
|
+
const partPosed = toCanvas(model, landed.get(part.id));
|
|
2580
|
+
const anchorPosed = toCanvas(model, landed.get(anchorId));
|
|
2581
|
+
const turning = turns(pose);
|
|
2582
|
+
if (turning) turningPoses++;
|
|
2583
|
+
let gap = 0;
|
|
2584
|
+
for (const i of shared) {
|
|
2585
|
+
const a = landLocated(partPosed, onPart[i]);
|
|
2586
|
+
const b = landLocated(anchorPosed, onAnchor[i]);
|
|
2587
|
+
gap = Math.max(gap, Math.hypot(a[0] - b[0], a[1] - b[1]));
|
|
2588
|
+
}
|
|
2589
|
+
if (shared.length > 0) {
|
|
2590
|
+
keep(turning ? worstOf.slide : worstOf.tie, gap, pose.name);
|
|
2591
|
+
}
|
|
2592
|
+
if (turning) {
|
|
2593
|
+
const at = landLocated(partPosed, tieOnPart);
|
|
2594
|
+
let nearest = null;
|
|
2595
|
+
if (at !== null) {
|
|
2596
|
+
for (const l of samplesOn) {
|
|
2597
|
+
const q = landLocated(anchorPosed, l);
|
|
2598
|
+
const d = Math.hypot(q[0] - at[0], q[1] - at[1]);
|
|
2599
|
+
if (nearest === null || d < nearest) nearest = d;
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
if (nearest === null) onAnchorNull ??= pose.name;
|
|
2603
|
+
else keep(worstOf.onAnchor, nearest, pose.name);
|
|
2604
|
+
}
|
|
2605
|
+
if (hiddenOn.length > 0) {
|
|
2606
|
+
const lowerPosed = lowerId === part.id ? partPosed : anchorPosed;
|
|
2607
|
+
const upperPosed = upperId === part.id ? partPosed : anchorPosed;
|
|
2608
|
+
const upperIndices = upperMesh.indices;
|
|
2609
|
+
const lands = hiddenOn.map((l) => landLocated(lowerPosed, l));
|
|
2610
|
+
const bounds = {
|
|
2611
|
+
x0: Infinity,
|
|
2612
|
+
y0: Infinity,
|
|
2613
|
+
x1: -Infinity,
|
|
2614
|
+
y1: -Infinity
|
|
2615
|
+
};
|
|
2616
|
+
for (const [x, y] of lands) {
|
|
2617
|
+
bounds.x0 = Math.min(bounds.x0, x);
|
|
2618
|
+
bounds.y0 = Math.min(bounds.y0, y);
|
|
2619
|
+
bounds.x1 = Math.max(bounds.x1, x);
|
|
2620
|
+
bounds.y1 = Math.max(bounds.y1, y);
|
|
2621
|
+
}
|
|
2622
|
+
const find = triangleGrid(upperPosed, upperIndices, bounds);
|
|
2623
|
+
let showing = 0;
|
|
2624
|
+
for (const at of lands) {
|
|
2625
|
+
let covered = false;
|
|
2626
|
+
for (const t of find(at[0], at[1])) {
|
|
2627
|
+
const tri = [
|
|
2628
|
+
upperIndices[t * 3],
|
|
2629
|
+
upperIndices[t * 3 + 1],
|
|
2630
|
+
upperIndices[t * 3 + 2]
|
|
2631
|
+
];
|
|
2632
|
+
const w = locate(upperPosed, tri, at[0], at[1]);
|
|
2633
|
+
if (!w) continue;
|
|
2634
|
+
let rx = 0;
|
|
2635
|
+
let ry = 0;
|
|
2636
|
+
for (let k = 0; k < 3; k++) {
|
|
2637
|
+
rx += w[k] * upperMesh.rest[tri[k] * 2];
|
|
2638
|
+
ry += w[k] * upperMesh.rest[tri[k] * 2 + 1];
|
|
2639
|
+
}
|
|
2640
|
+
covered = paintedAt(upperPaint, rx, ry);
|
|
2641
|
+
break;
|
|
2642
|
+
}
|
|
2643
|
+
if (!covered) showing++;
|
|
2644
|
+
}
|
|
2645
|
+
keep(
|
|
2646
|
+
turning ? worstOf.exposedTurn : worstOf.exposed,
|
|
2647
|
+
showing,
|
|
2648
|
+
pose.name
|
|
2649
|
+
);
|
|
2650
|
+
}
|
|
2651
|
+
if (part.rigid) measureRigid(pose, partPosed);
|
|
2652
|
+
}
|
|
2653
|
+
if (part.rigid) {
|
|
2654
|
+
for (const [param, values] of stops) {
|
|
2655
|
+
const def = model.parameters.find((p) => p.id === param).default;
|
|
2656
|
+
const sorted = [.../* @__PURE__ */ new Set([...values, def])].sort((a, b) => a - b);
|
|
2657
|
+
for (let i = 0; i + 1 < sorted.length; i++) {
|
|
2658
|
+
const mid = foldPose({ [param]: (sorted[i] + sorted[i + 1]) / 2 });
|
|
2659
|
+
const posed = landParts(model, mid.values, [part.id]).get(part.id);
|
|
2660
|
+
measureRigid(mid, toCanvas(model, posed));
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
1913
2663
|
}
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
2664
|
+
const tieReading = shared.length === 0 ? length(
|
|
2665
|
+
null,
|
|
2666
|
+
"rest",
|
|
2667
|
+
limits.tie,
|
|
2668
|
+
`no point of the ring around the tie lies on both ${part.id} and ${anchorId}`
|
|
2669
|
+
) : length(
|
|
2670
|
+
Math.max(0, worstOf.tie.v),
|
|
2671
|
+
worstOf.tie.pose,
|
|
2672
|
+
limits.tie,
|
|
2673
|
+
"the tie comes apart"
|
|
2674
|
+
);
|
|
2675
|
+
const slideReading = length(
|
|
2676
|
+
Math.max(0, worstOf.slide.v),
|
|
2677
|
+
worstOf.slide.pose,
|
|
2678
|
+
limits.slide,
|
|
2679
|
+
"the tie slides too far"
|
|
2680
|
+
);
|
|
2681
|
+
const onAnchorReading = onAnchorNull !== null ? length(
|
|
2682
|
+
null,
|
|
2683
|
+
onAnchorNull,
|
|
2684
|
+
limits.onAnchor,
|
|
2685
|
+
`the tie lands off ${part.id}'s mesh, or no painted point of ${anchorId} near it is on its mesh`
|
|
2686
|
+
) : length(
|
|
2687
|
+
Math.max(0, worstOf.onAnchor.v),
|
|
2688
|
+
worstOf.onAnchor.pose,
|
|
2689
|
+
limits.onAnchor,
|
|
2690
|
+
`the tie leaves ${anchorId}'s paint`
|
|
2691
|
+
);
|
|
2692
|
+
const exposedReading = readingOf(
|
|
2693
|
+
faceWidth,
|
|
2694
|
+
Math.max(0, worstOf.exposed.v),
|
|
2695
|
+
2,
|
|
2696
|
+
worstOf.exposed.pose,
|
|
2697
|
+
limits.exposed,
|
|
2698
|
+
"hidden art shows"
|
|
2699
|
+
);
|
|
2700
|
+
const ratioHit = folds.targets.find(
|
|
2701
|
+
(t) => t.target.kind === "part" && t.target.id === part.id
|
|
2702
|
+
)?.worst;
|
|
2703
|
+
const ratio = ratioHit?.ratio ?? 1;
|
|
2704
|
+
const foldsPass = ratio >= limits.fold;
|
|
2705
|
+
const rigidReading = part.rigid ? length(
|
|
2706
|
+
Math.max(0, worstOf.rigid.v),
|
|
2707
|
+
worstOf.rigid.pose,
|
|
2708
|
+
limits.rigid,
|
|
2709
|
+
"the part bends"
|
|
2710
|
+
) : void 0;
|
|
2711
|
+
const tipAt = freeEnd(ownPaint, part.tie, px2(TIP_INSET_PX));
|
|
2712
|
+
const [tipLoc] = tipAt === null ? [null] : locatePoints(partMesh, [tipAt]);
|
|
2713
|
+
const bareModel = stops.size === 0 ? model : {
|
|
2714
|
+
...model,
|
|
2715
|
+
parts: model.parts.map(
|
|
2716
|
+
(p) => p.id === part.id ? { ...p, warps: void 0 } : p
|
|
2717
|
+
)
|
|
2718
|
+
};
|
|
2719
|
+
const tip = [...stops.keys()].map((param) => {
|
|
2720
|
+
const def = model.parameters.find((p) => p.id === param);
|
|
2721
|
+
const ends = [def.min, def.max].map((value) => {
|
|
2722
|
+
const at = (m) => landLocated(
|
|
2723
|
+
toCanvas(
|
|
2724
|
+
m,
|
|
2725
|
+
landParts(m, { [param]: value }, [part.id]).get(part.id)
|
|
2726
|
+
),
|
|
2727
|
+
tipLoc ?? null
|
|
2728
|
+
);
|
|
2729
|
+
const landed = at(model);
|
|
2730
|
+
const bare = at(bareModel);
|
|
2731
|
+
return {
|
|
2732
|
+
value,
|
|
2733
|
+
landed,
|
|
2734
|
+
bare,
|
|
2735
|
+
fromBare: landed && bare ? Math.hypot(landed[0] - bare[0], landed[1] - bare[1]) : null
|
|
2736
|
+
};
|
|
2737
|
+
});
|
|
2738
|
+
const [a, b] = ends;
|
|
2739
|
+
return {
|
|
2740
|
+
param,
|
|
2741
|
+
ends,
|
|
2742
|
+
travel: a.landed && b.landed ? Math.hypot(b.landed[0] - a.landed[0], b.landed[1] - a.landed[1]) : null
|
|
2743
|
+
};
|
|
2744
|
+
});
|
|
2745
|
+
const turningExposed = worstOf.exposedTurn.v < 0 ? null : (({ value, px2: px22, pose }) => ({ value, px2: px22, pose }))(
|
|
2746
|
+
readingOf(
|
|
2747
|
+
faceWidth,
|
|
2748
|
+
worstOf.exposedTurn.v,
|
|
2749
|
+
2,
|
|
2750
|
+
worstOf.exposedTurn.pose,
|
|
2751
|
+
Infinity,
|
|
2752
|
+
""
|
|
2753
|
+
)
|
|
2754
|
+
);
|
|
2755
|
+
const slidePass = slideReading.pass && onAnchorReading.pass;
|
|
2756
|
+
const ok = foldsPass && tieReading.pass && slidePass && exposedReading.pass && (rigidReading?.pass ?? true);
|
|
2757
|
+
return {
|
|
2758
|
+
id: part.id,
|
|
2759
|
+
anchor: part.anchor,
|
|
2760
|
+
folds: {
|
|
2761
|
+
ratio,
|
|
2762
|
+
pose: ratioHit?.pose.name ?? "rest",
|
|
2763
|
+
limit: limits.fold,
|
|
2764
|
+
pass: foldsPass,
|
|
2765
|
+
...foldsPass ? {} : { reason: ratio <= 0 ? "a flip" : "a collapse" }
|
|
2766
|
+
},
|
|
2767
|
+
tie: tieReading,
|
|
2768
|
+
slide: {
|
|
2769
|
+
slide: slideReading,
|
|
2770
|
+
onAnchor: onAnchorReading,
|
|
2771
|
+
turningPoses,
|
|
2772
|
+
pass: slidePass
|
|
2773
|
+
},
|
|
2774
|
+
exposed: {
|
|
2775
|
+
hiddenPx: hiddenOn.length,
|
|
2776
|
+
noTurn: exposedReading,
|
|
2777
|
+
turning: turningExposed,
|
|
2778
|
+
pass: exposedReading.pass
|
|
2779
|
+
},
|
|
2780
|
+
...rigidReading === void 0 ? {} : { rigid: rigidReading },
|
|
2781
|
+
tip,
|
|
2782
|
+
ok
|
|
2783
|
+
};
|
|
2784
|
+
});
|
|
2785
|
+
const failed = reports.flatMap((r) => [
|
|
2786
|
+
...r.folds.pass ? [] : [`${r.id} FOLDS`],
|
|
2787
|
+
...r.tie.pass ? [] : [`${r.id} TIE`],
|
|
2788
|
+
...r.slide.pass ? [] : [`${r.id} SLIDE`],
|
|
2789
|
+
...r.exposed.pass ? [] : [`${r.id} EXPOSED`],
|
|
2790
|
+
...r.rigid === void 0 || r.rigid.pass ? [] : [`${r.id} RIGID`]
|
|
2791
|
+
]);
|
|
2792
|
+
return {
|
|
2793
|
+
ok: failed.length === 0,
|
|
2794
|
+
faceWidth,
|
|
2795
|
+
limits,
|
|
2796
|
+
poses: all.size,
|
|
2797
|
+
parts: reports,
|
|
2798
|
+
failed
|
|
2799
|
+
};
|
|
2800
|
+
}
|
|
2801
|
+
var both = (faceWidth, px2, digits = 4) => px2 === null ? "off the mesh" : `${px2.toFixed(1)} px (${(px2 / faceWidth).toFixed(digits)} face widths)`;
|
|
2802
|
+
function formatCustomGate(report) {
|
|
2803
|
+
const w = report.faceWidth;
|
|
2804
|
+
const verdict = (pass, reason) => pass ? "pass" : `FAIL: ${reason}`;
|
|
2805
|
+
const limit = (fw) => `${fw} face widths, ${(fw * w).toFixed(1)} px`;
|
|
2806
|
+
const lines = [];
|
|
2807
|
+
for (const r of report.parts) {
|
|
2808
|
+
const at = `CUSTOM ${r.id}`;
|
|
2809
|
+
lines.push(
|
|
2810
|
+
`${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)}`
|
|
2811
|
+
);
|
|
2812
|
+
lines.push(
|
|
2813
|
+
`${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)}`
|
|
2814
|
+
);
|
|
2815
|
+
const s = r.slide;
|
|
2816
|
+
lines.push(
|
|
2817
|
+
s.turningPoses === 0 ? `${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)}`
|
|
1917
2818
|
);
|
|
2819
|
+
const e = r.exposed;
|
|
2820
|
+
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)`;
|
|
2821
|
+
lines.push(
|
|
2822
|
+
`${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}`
|
|
2823
|
+
);
|
|
2824
|
+
if (r.rigid) {
|
|
2825
|
+
lines.push(
|
|
2826
|
+
`${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)}`
|
|
2827
|
+
);
|
|
2828
|
+
}
|
|
2829
|
+
for (const t of r.tip) {
|
|
2830
|
+
const ends = t.ends.map(
|
|
2831
|
+
(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`
|
|
2832
|
+
).join("; ");
|
|
2833
|
+
lines.push(
|
|
2834
|
+
`${at} TIP ${t.param}: free end ${ends}; travel end to end ${t.travel === null ? "-" : both(w, t.travel)} (reported, no limit)`
|
|
2835
|
+
);
|
|
2836
|
+
}
|
|
1918
2837
|
}
|
|
2838
|
+
lines.push(
|
|
2839
|
+
report.ok ? "CUSTOM GATE pass" : `CUSTOM GATE FAIL: ${report.failed.join(", ")}`
|
|
2840
|
+
);
|
|
2841
|
+
return lines;
|
|
1919
2842
|
}
|
|
1920
2843
|
|
|
2844
|
+
// src/render-poses.ts
|
|
2845
|
+
var import_node_fs5 = require("fs");
|
|
2846
|
+
var import_node_path4 = __toESM(require("path"));
|
|
2847
|
+
var import_format10 = require("@ikijs/format");
|
|
2848
|
+
|
|
1921
2849
|
// src/render-browser.ts
|
|
1922
2850
|
var import_node_child_process = require("child_process");
|
|
1923
|
-
var
|
|
2851
|
+
var import_node_fs3 = __toESM(require("fs"));
|
|
1924
2852
|
var import_node_os = __toESM(require("os"));
|
|
1925
2853
|
var import_node_path2 = __toESM(require("path"));
|
|
1926
2854
|
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.";
|
|
@@ -1947,8 +2875,8 @@ var DEFAULT_TIMEOUT_MS = 3e4;
|
|
|
1947
2875
|
var BROWSER_CLOSE_MS = 1e3;
|
|
1948
2876
|
function isExecutableFile(file) {
|
|
1949
2877
|
try {
|
|
1950
|
-
if (!
|
|
1951
|
-
|
|
2878
|
+
if (!import_node_fs3.default.statSync(file).isFile()) return false;
|
|
2879
|
+
import_node_fs3.default.accessSync(file, import_node_fs3.default.constants.X_OK);
|
|
1952
2880
|
return true;
|
|
1953
2881
|
} catch {
|
|
1954
2882
|
return false;
|
|
@@ -2107,7 +3035,7 @@ async function openPage(cdp, timeoutMs) {
|
|
|
2107
3035
|
}
|
|
2108
3036
|
function removeProfile(profile) {
|
|
2109
3037
|
try {
|
|
2110
|
-
|
|
3038
|
+
import_node_fs3.default.rmSync(profile, {
|
|
2111
3039
|
recursive: true,
|
|
2112
3040
|
force: true,
|
|
2113
3041
|
maxRetries: 5,
|
|
@@ -2123,7 +3051,7 @@ async function launchBrowser(executable, timeoutMs) {
|
|
|
2123
3051
|
"render_poses needs Node 22 or newer (the global WebSocket is missing)."
|
|
2124
3052
|
);
|
|
2125
3053
|
}
|
|
2126
|
-
const profile =
|
|
3054
|
+
const profile = import_node_fs3.default.mkdtempSync(import_node_path2.default.join(import_node_os.default.tmpdir(), "iki-render-"));
|
|
2127
3055
|
let child;
|
|
2128
3056
|
try {
|
|
2129
3057
|
child = (0, import_node_child_process.spawn)(
|
|
@@ -2143,7 +3071,7 @@ async function launchBrowser(executable, timeoutMs) {
|
|
|
2143
3071
|
{ stdio: ["ignore", "ignore", "pipe"] }
|
|
2144
3072
|
);
|
|
2145
3073
|
} catch (error) {
|
|
2146
|
-
|
|
3074
|
+
import_node_fs3.default.rmSync(profile, { recursive: true, force: true });
|
|
2147
3075
|
throw startError(executable, error);
|
|
2148
3076
|
}
|
|
2149
3077
|
let spawnError;
|
|
@@ -2426,13 +3354,13 @@ function formatNodReport(report) {
|
|
|
2426
3354
|
}
|
|
2427
3355
|
|
|
2428
3356
|
// src/sweep.ts
|
|
2429
|
-
var
|
|
3357
|
+
var import_node_fs4 = __toESM(require("fs"));
|
|
2430
3358
|
var import_node_path3 = __toESM(require("path"));
|
|
2431
3359
|
var SWEEP_CLOCK_HZ = 60;
|
|
2432
3360
|
var SWEEP_FPS = 30;
|
|
2433
3361
|
var SWEEP_DURATION_S = 3;
|
|
2434
3362
|
var BOX_DURATION_S = 6;
|
|
2435
|
-
var SWEEP_PRESETS = ["turn", "turn-nod"];
|
|
3363
|
+
var SWEEP_PRESETS = ["turn", "turn-nod", "roll"];
|
|
2436
3364
|
var SWEEP_WARMUP_S = 0.5;
|
|
2437
3365
|
var SWEEP_FRAME_MS = 1e3 / SWEEP_CLOCK_HZ * (1 + 1e-9);
|
|
2438
3366
|
var SHEET_THETAS = [-30, -20, -10, -5, 0, 5, 10, 20, 30];
|
|
@@ -2485,29 +3413,37 @@ function boxAngles(t) {
|
|
|
2485
3413
|
}
|
|
2486
3414
|
return { x: 0, y: 0 };
|
|
2487
3415
|
}
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
}
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
3416
|
+
var legSheet = (id) => (steps, n) => turnSheetFrames(steps, n, id);
|
|
3417
|
+
var SHAPES = {
|
|
3418
|
+
turn: {
|
|
3419
|
+
durationS: SWEEP_DURATION_S,
|
|
3420
|
+
angles: (t) => ({ ParamAngleX: turnTheta(t) }),
|
|
3421
|
+
sheetFrames: legSheet("ParamAngleX"),
|
|
3422
|
+
label: (s) => `\u03B8 ${signedDeg(s.ParamAngleX)}\xB0`,
|
|
3423
|
+
kymograph: true
|
|
3424
|
+
},
|
|
3425
|
+
// The roll rides the turn's own curve, so its frames sit at the angles the
|
|
3426
|
+
// turn sheet's do.
|
|
3427
|
+
roll: {
|
|
3428
|
+
durationS: SWEEP_DURATION_S,
|
|
3429
|
+
angles: (t) => ({ ParamAngleZ: turnTheta(t) }),
|
|
3430
|
+
sheetFrames: legSheet("ParamAngleZ"),
|
|
3431
|
+
label: (s) => `Z ${signedDeg(s.ParamAngleZ)}\xB0`,
|
|
3432
|
+
kymograph: false
|
|
3433
|
+
},
|
|
3434
|
+
"turn-nod": {
|
|
3435
|
+
durationS: BOX_DURATION_S,
|
|
3436
|
+
angles: (t) => {
|
|
3437
|
+
const { x, y } = boxAngles(t);
|
|
2507
3438
|
return { ParamAngleX: x, ParamAngleY: y };
|
|
2508
|
-
}
|
|
2509
|
-
|
|
2510
|
-
}
|
|
3439
|
+
},
|
|
3440
|
+
sheetFrames: boxSheetFrames,
|
|
3441
|
+
label: (s) => `X ${signedDeg(s.ParamAngleX)}\xB0 Y ${signedDeg(s.ParamAngleY)}\xB0`,
|
|
3442
|
+
kymograph: false
|
|
3443
|
+
}
|
|
3444
|
+
};
|
|
3445
|
+
function sweepDurationS(preset) {
|
|
3446
|
+
return SHAPES[preset].durationS;
|
|
2511
3447
|
}
|
|
2512
3448
|
function eyeRowModelPx(model) {
|
|
2513
3449
|
const landed = landParts(model, {}, ["eye_L", "eye_R"]);
|
|
@@ -2533,13 +3469,13 @@ function physicsOutputIds(model) {
|
|
|
2533
3469
|
}
|
|
2534
3470
|
return [...ids];
|
|
2535
3471
|
}
|
|
2536
|
-
function turnSheetFrames(steps, frames) {
|
|
3472
|
+
function turnSheetFrames(steps, frames, id) {
|
|
2537
3473
|
const onLeg = [];
|
|
2538
3474
|
for (let k = 0; k < frames; k++) {
|
|
2539
3475
|
const t = k / SWEEP_FPS;
|
|
2540
3476
|
if (t >= LEG_FROM_S && t <= LEG_TO_S) onLeg.push(k);
|
|
2541
3477
|
}
|
|
2542
|
-
const x = (k) => steps[CAPTURE_EVERY * k]
|
|
3478
|
+
const x = (k) => steps[CAPTURE_EVERY * k][id];
|
|
2543
3479
|
const picked = [];
|
|
2544
3480
|
for (const target2 of SHEET_THETAS) {
|
|
2545
3481
|
let best = onLeg[0];
|
|
@@ -2569,7 +3505,13 @@ function signedDeg(angle) {
|
|
|
2569
3505
|
return rounded > 0 ? `+${deg}` : deg.replace("-", "\u2212");
|
|
2570
3506
|
}
|
|
2571
3507
|
function sweepSpec(model, preset, crop) {
|
|
2572
|
-
const
|
|
3508
|
+
const shape = SHAPES[preset];
|
|
3509
|
+
const { durationS } = shape;
|
|
3510
|
+
const steps = Array.from(
|
|
3511
|
+
{ length: SWEEP_CLOCK_HZ * durationS },
|
|
3512
|
+
(_, j) => shape.angles(j / SWEEP_CLOCK_HZ)
|
|
3513
|
+
);
|
|
3514
|
+
const parameters = Object.keys(steps[0]);
|
|
2573
3515
|
const frameCount = durationS * SWEEP_FPS;
|
|
2574
3516
|
const dw = crop ? crop.dw : BUST_SIZE;
|
|
2575
3517
|
const dh = crop ? crop.dh : BUST_SIZE;
|
|
@@ -2580,15 +3522,11 @@ function sweepSpec(model, preset, crop) {
|
|
|
2580
3522
|
(SHEET_MAX_SIDE - 2 * m) / (3 * dw),
|
|
2581
3523
|
(SHEET_MAX_SIDE - 2 * m - 3 * b) / (3 * dh)
|
|
2582
3524
|
);
|
|
2583
|
-
const frames =
|
|
2584
|
-
const labelOf = (k) => {
|
|
2585
|
-
const s = steps[CAPTURE_EVERY * k];
|
|
2586
|
-
const t = (k / SWEEP_FPS).toFixed(2);
|
|
2587
|
-
return preset === "turn" ? `\u03B8 ${signedDeg(s.ParamAngleX)}\xB0 t ${t} s` : `X ${signedDeg(s.ParamAngleX)}\xB0 Y ${signedDeg(s.ParamAngleY)}\xB0 t ${t} s`;
|
|
2588
|
-
};
|
|
3525
|
+
const frames = shape.sheetFrames(steps, frameCount);
|
|
3526
|
+
const labelOf = (k) => `${shape.label(steps[CAPTURE_EVERY * k])} t ${(k / SWEEP_FPS).toFixed(2)} s`;
|
|
2589
3527
|
const { width: W, height: H } = model.canvas;
|
|
2590
3528
|
let kymograph;
|
|
2591
|
-
if (
|
|
3529
|
+
if (shape.kymograph) {
|
|
2592
3530
|
const yModel = eyeRowModelPx(model);
|
|
2593
3531
|
let row = Math.round(dh / 2);
|
|
2594
3532
|
let at = "middle";
|
|
@@ -2668,7 +3606,7 @@ img { max-width: 48vw; height: auto; background: #444; }
|
|
|
2668
3606
|
scrub.max = String(n - 1);
|
|
2669
3607
|
if (b) { bi.style.display = "block"; }
|
|
2670
3608
|
function short(id) {
|
|
2671
|
-
return id === "ParamAngleX" ? "X" : id === "ParamAngleY" ? "Y" : id;
|
|
3609
|
+
return id === "ParamAngleX" ? "X" : id === "ParamAngleY" ? "Y" : id === "ParamAngleZ" ? "Z" : id;
|
|
2672
3610
|
}
|
|
2673
3611
|
function show(k) {
|
|
2674
3612
|
i = k;
|
|
@@ -2707,13 +3645,13 @@ var STALE_NAMES = [
|
|
|
2707
3645
|
function prepareSweepDir(outDir, name, label) {
|
|
2708
3646
|
const dir = import_node_path3.default.join(outDir, name);
|
|
2709
3647
|
try {
|
|
2710
|
-
|
|
3648
|
+
import_node_fs4.default.mkdirSync(dir);
|
|
2711
3649
|
} catch (e) {
|
|
2712
3650
|
if (e.code !== "EEXIST") {
|
|
2713
3651
|
throw new AutoRigInputError(`sweep dir: ${e.message}`);
|
|
2714
3652
|
}
|
|
2715
3653
|
}
|
|
2716
|
-
const stat =
|
|
3654
|
+
const stat = import_node_fs4.default.lstatSync(dir);
|
|
2717
3655
|
if (stat.isSymbolicLink()) {
|
|
2718
3656
|
throw new AutoRigInputError(`${label}.name names ${dir}, a symbolic link`);
|
|
2719
3657
|
}
|
|
@@ -2723,9 +3661,9 @@ function prepareSweepDir(outDir, name, label) {
|
|
|
2723
3661
|
return confineToWorkingDirectory(process.cwd(), dir, "sweep dir", name);
|
|
2724
3662
|
}
|
|
2725
3663
|
function clearSweepDir(real) {
|
|
2726
|
-
for (const entry of
|
|
3664
|
+
for (const entry of import_node_fs4.default.readdirSync(real)) {
|
|
2727
3665
|
if (STALE_FILE.test(entry) || STALE_NAMES.includes(entry)) {
|
|
2728
|
-
|
|
3666
|
+
import_node_fs4.default.rmSync(import_node_path3.default.join(real, entry));
|
|
2729
3667
|
}
|
|
2730
3668
|
}
|
|
2731
3669
|
}
|
|
@@ -2841,9 +3779,9 @@ function planRenders(model, requested, sweep, sweeps) {
|
|
|
2841
3779
|
}
|
|
2842
3780
|
const bodyAngles = Object.fromEntries(
|
|
2843
3781
|
[
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
3782
|
+
import_format10.StandardParameter.BodyAngleX,
|
|
3783
|
+
import_format10.StandardParameter.BodyAngleY,
|
|
3784
|
+
import_format10.StandardParameter.BodyAngleZ
|
|
2847
3785
|
].filter((id) => model.parameters.some((p) => p.id === id)).map((id) => [id, -10])
|
|
2848
3786
|
);
|
|
2849
3787
|
const poses = [
|
|
@@ -2929,7 +3867,7 @@ function planRenders(model, requested, sweep, sweeps) {
|
|
|
2929
3867
|
whole("full-elbow-r-45", { ParamElbowR: 45 }),
|
|
2930
3868
|
whole("full-elbow-r-90", { ParamElbowR: 90 })
|
|
2931
3869
|
);
|
|
2932
|
-
if (model.parameters.some((p) => p.id ===
|
|
3870
|
+
if (model.parameters.some((p) => p.id === import_format10.StandardParameter.ArmPoseRight)) {
|
|
2933
3871
|
poses.push(
|
|
2934
3872
|
whole("full-pose-l", { ParamArmPoseL: 1 }),
|
|
2935
3873
|
whole("full-pose-r", { ParamArmPoseR: 1 }),
|
|
@@ -2970,6 +3908,25 @@ function checkRequest(requested, i) {
|
|
|
2970
3908
|
}
|
|
2971
3909
|
}
|
|
2972
3910
|
}
|
|
3911
|
+
function withoutParts(model, hideParts) {
|
|
3912
|
+
const hidden = new Set(hideParts);
|
|
3913
|
+
hideParts.forEach((id, i) => {
|
|
3914
|
+
if (!model.parts.some((p) => p.id === id)) {
|
|
3915
|
+
throw new AutoRigInputError(
|
|
3916
|
+
`hideParts[${i}] ${JSON.stringify(id)} is not a part of the model`
|
|
3917
|
+
);
|
|
3918
|
+
}
|
|
3919
|
+
const kept = model.parts.find(
|
|
3920
|
+
(p) => !hidden.has(p.id) && p.clip?.masks.includes(id)
|
|
3921
|
+
);
|
|
3922
|
+
if (kept) {
|
|
3923
|
+
throw new AutoRigInputError(
|
|
3924
|
+
`hideParts[${i}] ${JSON.stringify(id)} masks ${JSON.stringify(kept.id)}, which stays; hide ${JSON.stringify(kept.id)} too`
|
|
3925
|
+
);
|
|
3926
|
+
}
|
|
3927
|
+
});
|
|
3928
|
+
return { ...model, parts: model.parts.filter((p) => !hidden.has(p.id)) };
|
|
3929
|
+
}
|
|
2973
3930
|
var PNG_PREFIX = "data:image/png;base64,";
|
|
2974
3931
|
var PAGE_SCRIPT_MS = 1e4;
|
|
2975
3932
|
var LOAD_MS = 6e4;
|
|
@@ -2977,7 +3934,7 @@ var CAPTURE_MS = 15e3;
|
|
|
2977
3934
|
function readPageScript() {
|
|
2978
3935
|
const url = new URL("../dist/render-page.global.js", importMetaUrl);
|
|
2979
3936
|
try {
|
|
2980
|
-
return (0,
|
|
3937
|
+
return (0, import_node_fs5.readFileSync)(url, "utf8");
|
|
2981
3938
|
} catch (cause) {
|
|
2982
3939
|
throw new Error(
|
|
2983
3940
|
"could not read the render page script; run `pnpm build` in packages/mcp",
|
|
@@ -3078,8 +4035,9 @@ async function renderPoses(input) {
|
|
|
3078
4035
|
input.modelPath
|
|
3079
4036
|
);
|
|
3080
4037
|
const outDir = resolveOutputDir(input.outDir);
|
|
3081
|
-
const model = (0,
|
|
4038
|
+
const model = (0, import_format10.loadIkiModel)((0, import_node_fs5.readFileSync)(modelFile, "utf8"));
|
|
3082
4039
|
const plan = planRenders(model, input.poses, input.sweep, input.sweeps);
|
|
4040
|
+
const drawn = input.hideParts ? withoutParts(model, input.hideParts) : model;
|
|
3083
4041
|
const browser = findBrowser();
|
|
3084
4042
|
if (!browser) return { ok: false, error: NO_BROWSER_MESSAGE };
|
|
3085
4043
|
const pageScript = readPageScript();
|
|
@@ -3102,7 +4060,7 @@ async function renderPoses(input) {
|
|
|
3102
4060
|
async (evaluate) => {
|
|
3103
4061
|
await evaluate(pageScript, PAGE_SCRIPT_MS);
|
|
3104
4062
|
const loaded = await evaluate(
|
|
3105
|
-
`window.__ikiRender.load(${JSON.stringify(
|
|
4063
|
+
`window.__ikiRender.load(${JSON.stringify(drawn)}, ${JSON.stringify({ canvas: plan.canvas, view: plan.view })})`,
|
|
3106
4064
|
LOAD_MS
|
|
3107
4065
|
);
|
|
3108
4066
|
const written = [];
|
|
@@ -3170,87 +4128,20 @@ async function renderPoses(input) {
|
|
|
3170
4128
|
sweeps
|
|
3171
4129
|
};
|
|
3172
4130
|
} catch (error) {
|
|
3173
|
-
if (error instanceof AutoRigInputError || error instanceof
|
|
4131
|
+
if (error instanceof AutoRigInputError || error instanceof import_format10.IkiFormatError) {
|
|
3174
4132
|
return { ok: false, error: error.message };
|
|
3175
4133
|
}
|
|
3176
4134
|
throw error;
|
|
3177
4135
|
}
|
|
3178
4136
|
}
|
|
3179
4137
|
|
|
3180
|
-
// src/node-images.ts
|
|
3181
|
-
var import_sharp = __toESM(require("sharp"));
|
|
3182
|
-
var import_editor2 = require("@ikijs/editor");
|
|
3183
|
-
async function decodePng(filePath) {
|
|
3184
|
-
try {
|
|
3185
|
-
const pipeline = (0, import_sharp.default)(filePath, { limitInputPixels: MAX_INPUT_PIXELS });
|
|
3186
|
-
const metadata = await pipeline.metadata();
|
|
3187
|
-
if (metadata.format !== "png") {
|
|
3188
|
-
throw new AutoRigInputError(
|
|
3189
|
-
`non-PNG image (${metadata.format ?? "unknown"}): ${filePath}`
|
|
3190
|
-
);
|
|
3191
|
-
}
|
|
3192
|
-
const { data, info } = await pipeline.ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
3193
|
-
return {
|
|
3194
|
-
width: info.width,
|
|
3195
|
-
height: info.height,
|
|
3196
|
-
rgba: data,
|
|
3197
|
-
hasAlpha: metadata.hasAlpha ?? false
|
|
3198
|
-
};
|
|
3199
|
-
} catch (e) {
|
|
3200
|
-
if (e instanceof AutoRigInputError) throw e;
|
|
3201
|
-
const msg = e instanceof Error ? e.message : String(e);
|
|
3202
|
-
throw new AutoRigInputError(`failed to decode PNG ${filePath}: ${msg}`);
|
|
3203
|
-
}
|
|
3204
|
-
}
|
|
3205
|
-
function detectAlphaBbox(rgba, width, height) {
|
|
3206
|
-
const bbox = (0, import_editor2.detectAlphaBbox)(rgba, width, height);
|
|
3207
|
-
if (bbox === null) {
|
|
3208
|
-
throw new AutoRigInputError("layer is empty after alpha threshold");
|
|
3209
|
-
}
|
|
3210
|
-
return bbox;
|
|
3211
|
-
}
|
|
3212
|
-
function cropToBuffer(rgba, width, height, bbox) {
|
|
3213
|
-
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();
|
|
3214
|
-
}
|
|
3215
|
-
function encodeOverlayPng(filePath, svg) {
|
|
3216
|
-
return (0, import_sharp.default)(filePath, { limitInputPixels: MAX_INPUT_PIXELS }).composite([{ input: Buffer.from(svg) }]).png().toBuffer();
|
|
3217
|
-
}
|
|
3218
|
-
async function renderAtlasToDataUri(crops, layout, quantizeColors) {
|
|
3219
|
-
const byId = /* @__PURE__ */ new Map();
|
|
3220
|
-
for (const crop of crops) byId.set(crop.id, crop);
|
|
3221
|
-
const pad = layout.padding;
|
|
3222
|
-
const composites = await Promise.all(
|
|
3223
|
-
layout.placements.map(async (placement3) => {
|
|
3224
|
-
const crop = byId.get(placement3.id);
|
|
3225
|
-
if (crop === void 0) {
|
|
3226
|
-
throw new AutoRigInputError(
|
|
3227
|
-
`no crop for atlas placement "${placement3.id}"`
|
|
3228
|
-
);
|
|
3229
|
-
}
|
|
3230
|
-
const input = pad > 0 ? await (0, import_sharp.default)(crop.buffer).extend({ right: pad, bottom: pad, extendWith: "copy" }).png().toBuffer() : crop.buffer;
|
|
3231
|
-
return { input, left: placement3.x, top: placement3.y };
|
|
3232
|
-
})
|
|
3233
|
-
);
|
|
3234
|
-
const page = await (0, import_sharp.default)({
|
|
3235
|
-
create: {
|
|
3236
|
-
width: layout.pageWidth,
|
|
3237
|
-
height: layout.pageHeight,
|
|
3238
|
-
channels: 4,
|
|
3239
|
-
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
|
3240
|
-
}
|
|
3241
|
-
}).composite(composites).png(
|
|
3242
|
-
quantizeColors === void 0 ? {} : { palette: true, colours: quantizeColors, dither: 0.5, effort: 10 }
|
|
3243
|
-
).toBuffer();
|
|
3244
|
-
return `data:image/png;base64,${page.toString("base64")}`;
|
|
3245
|
-
}
|
|
3246
|
-
|
|
3247
4138
|
// src/tools.ts
|
|
3248
4139
|
function coerceModel(model) {
|
|
3249
4140
|
try {
|
|
3250
|
-
const parsed = typeof model === "string" ? (0,
|
|
4141
|
+
const parsed = typeof model === "string" ? (0, import_format11.loadIkiModel)(model) : (0, import_format11.parseIkiModel)(model);
|
|
3251
4142
|
return { ok: true, model: parsed };
|
|
3252
4143
|
} catch (e) {
|
|
3253
|
-
if (e instanceof
|
|
4144
|
+
if (e instanceof import_format11.IkiFormatError) return { ok: false, error: e.message };
|
|
3254
4145
|
throw e;
|
|
3255
4146
|
}
|
|
3256
4147
|
}
|
|
@@ -3359,7 +4250,7 @@ function describeIkiAt(modelPath) {
|
|
|
3359
4250
|
"model path",
|
|
3360
4251
|
modelPath
|
|
3361
4252
|
);
|
|
3362
|
-
return describeIki((0,
|
|
4253
|
+
return describeIki((0, import_node_fs6.readFileSync)(modelFile, "utf8"));
|
|
3363
4254
|
} catch (e) {
|
|
3364
4255
|
if (e instanceof AutoRigInputError) return { ok: false, error: e.message };
|
|
3365
4256
|
throw e;
|
|
@@ -3367,123 +4258,123 @@ function describeIkiAt(modelPath) {
|
|
|
3367
4258
|
}
|
|
3368
4259
|
var STANDARD_PARAMETER_INFO = [
|
|
3369
4260
|
{
|
|
3370
|
-
id:
|
|
4261
|
+
id: import_format11.StandardParameter.MouthOpen,
|
|
3371
4262
|
description: "Mouth open amount for lip-sync (0 closed .. 1 open)."
|
|
3372
4263
|
},
|
|
3373
4264
|
{
|
|
3374
|
-
id:
|
|
4265
|
+
id: import_format11.StandardParameter.MouthForm,
|
|
3375
4266
|
description: "Mouth form / smile (-1 .. 1)."
|
|
3376
4267
|
},
|
|
3377
4268
|
{
|
|
3378
|
-
id:
|
|
4269
|
+
id: import_format11.StandardParameter.EyeOpenLeft,
|
|
3379
4270
|
description: "Left eye open (0 closed .. 1 open). Drive with the right eye for a blink."
|
|
3380
4271
|
},
|
|
3381
4272
|
{
|
|
3382
|
-
id:
|
|
4273
|
+
id: import_format11.StandardParameter.EyeOpenRight,
|
|
3383
4274
|
description: "Right eye open (0 closed .. 1 open)."
|
|
3384
4275
|
},
|
|
3385
4276
|
{
|
|
3386
|
-
id:
|
|
4277
|
+
id: import_format11.StandardParameter.EyeballX,
|
|
3387
4278
|
description: "Eyeball gaze, horizontal (-1 .. 1)."
|
|
3388
4279
|
},
|
|
3389
4280
|
{
|
|
3390
|
-
id:
|
|
4281
|
+
id: import_format11.StandardParameter.EyeballY,
|
|
3391
4282
|
description: "Eyeball gaze, vertical (-1 .. 1)."
|
|
3392
4283
|
},
|
|
3393
4284
|
{
|
|
3394
|
-
id:
|
|
4285
|
+
id: import_format11.StandardParameter.AngleX,
|
|
3395
4286
|
description: "Head angle, horizontal degrees."
|
|
3396
4287
|
},
|
|
3397
4288
|
{
|
|
3398
|
-
id:
|
|
4289
|
+
id: import_format11.StandardParameter.AngleY,
|
|
3399
4290
|
description: "Head angle, vertical degrees."
|
|
3400
4291
|
},
|
|
3401
4292
|
{
|
|
3402
|
-
id:
|
|
4293
|
+
id: import_format11.StandardParameter.AngleZ,
|
|
3403
4294
|
description: "Head tilt / roll degrees; positive tilts the top of the head toward the viewer's right (clockwise), as in Live2D."
|
|
3404
4295
|
},
|
|
3405
4296
|
{
|
|
3406
|
-
id:
|
|
4297
|
+
id: import_format11.StandardParameter.BodyAngleX,
|
|
3407
4298
|
description: "Body turn, degrees (-10 .. 10); positive turns the body toward the viewer's right, as AngleX does the head."
|
|
3408
4299
|
},
|
|
3409
4300
|
{
|
|
3410
|
-
id:
|
|
4301
|
+
id: import_format11.StandardParameter.BodyAngleY,
|
|
3411
4302
|
description: "Body lean, degrees (-10 .. 10); positive moves the upper body up, negative bows."
|
|
3412
4303
|
},
|
|
3413
4304
|
{
|
|
3414
|
-
id:
|
|
4305
|
+
id: import_format11.StandardParameter.BodyAngleZ,
|
|
3415
4306
|
description: "Body tilt, degrees (-10 .. 10); positive tilts the top toward the viewer's right (clockwise), as AngleZ does the head."
|
|
3416
4307
|
},
|
|
3417
4308
|
{
|
|
3418
|
-
id:
|
|
4309
|
+
id: import_format11.StandardParameter.Breath,
|
|
3419
4310
|
description: "Idle breath (0 .. 1), cycled by the host."
|
|
3420
4311
|
},
|
|
3421
4312
|
{
|
|
3422
|
-
id:
|
|
4313
|
+
id: import_format11.StandardParameter.AmbientSway,
|
|
3423
4314
|
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."
|
|
3424
4315
|
},
|
|
3425
4316
|
{
|
|
3426
|
-
id:
|
|
4317
|
+
id: import_format11.StandardParameter.BrowLeftY,
|
|
3427
4318
|
description: "Left brow raise/lower (-1 .. 1)."
|
|
3428
4319
|
},
|
|
3429
4320
|
{
|
|
3430
|
-
id:
|
|
4321
|
+
id: import_format11.StandardParameter.BrowRightY,
|
|
3431
4322
|
description: "Right brow raise/lower (-1 .. 1)."
|
|
3432
4323
|
},
|
|
3433
4324
|
{
|
|
3434
|
-
id:
|
|
4325
|
+
id: import_format11.StandardParameter.BrowLeftAngle,
|
|
3435
4326
|
description: "Left brow tilt/angle (-1 .. 1)."
|
|
3436
4327
|
},
|
|
3437
4328
|
{
|
|
3438
|
-
id:
|
|
4329
|
+
id: import_format11.StandardParameter.BrowRightAngle,
|
|
3439
4330
|
description: "Right brow tilt/angle (-1 .. 1)."
|
|
3440
4331
|
},
|
|
3441
4332
|
{
|
|
3442
|
-
id:
|
|
4333
|
+
id: import_format11.StandardParameter.Cheek,
|
|
3443
4334
|
description: "Cheek blush strength (0 .. 1), raised by an expression."
|
|
3444
4335
|
},
|
|
3445
4336
|
{
|
|
3446
|
-
id:
|
|
4337
|
+
id: import_format11.StandardParameter.HairSwayX,
|
|
3447
4338
|
description: "Front hair's horizontal sway driver. Physics OUTPUT \u2014 driven by the spring, hosts should not set it directly."
|
|
3448
4339
|
},
|
|
3449
4340
|
{
|
|
3450
|
-
id:
|
|
4341
|
+
id: import_format11.StandardParameter.HairSwayZ,
|
|
3451
4342
|
description: "Front hair's sway driver behind a head tilt. Physics OUTPUT \u2014 driven by the spring, hosts should not set it directly."
|
|
3452
4343
|
},
|
|
3453
4344
|
{
|
|
3454
|
-
id:
|
|
4345
|
+
id: import_format11.StandardParameter.HairBackSway,
|
|
3455
4346
|
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."
|
|
3456
4347
|
},
|
|
3457
4348
|
{
|
|
3458
|
-
id:
|
|
4349
|
+
id: import_format11.StandardParameter.ArmLeft,
|
|
3459
4350
|
description: "Left shoulder, degrees; positive raises the arm outward (mirrored on the right)."
|
|
3460
4351
|
},
|
|
3461
4352
|
{
|
|
3462
|
-
id:
|
|
4353
|
+
id: import_format11.StandardParameter.ArmRight,
|
|
3463
4354
|
description: "Right shoulder, degrees; positive raises the arm outward (mirrored on the left)."
|
|
3464
4355
|
},
|
|
3465
4356
|
{
|
|
3466
|
-
id:
|
|
4357
|
+
id: import_format11.StandardParameter.ElbowLeft,
|
|
3467
4358
|
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)."
|
|
3468
4359
|
},
|
|
3469
4360
|
{
|
|
3470
|
-
id:
|
|
4361
|
+
id: import_format11.StandardParameter.ElbowRight,
|
|
3471
4362
|
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)."
|
|
3472
4363
|
},
|
|
3473
4364
|
{
|
|
3474
|
-
id:
|
|
4365
|
+
id: import_format11.StandardParameter.ArmPoseLeft,
|
|
3475
4366
|
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."
|
|
3476
4367
|
},
|
|
3477
4368
|
{
|
|
3478
|
-
id:
|
|
4369
|
+
id: import_format11.StandardParameter.ArmPoseRight,
|
|
3479
4370
|
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."
|
|
3480
4371
|
},
|
|
3481
4372
|
{
|
|
3482
|
-
id:
|
|
4373
|
+
id: import_format11.StandardParameter.ArmPoseAngleLeft,
|
|
3483
4374
|
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)."
|
|
3484
4375
|
},
|
|
3485
4376
|
{
|
|
3486
|
-
id:
|
|
4377
|
+
id: import_format11.StandardParameter.ArmPoseAngleRight,
|
|
3487
4378
|
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)."
|
|
3488
4379
|
}
|
|
3489
4380
|
];
|
|
@@ -3491,10 +4382,10 @@ function listStandardParameters() {
|
|
|
3491
4382
|
return STANDARD_PARAMETER_INFO.map((p) => ({ ...p }));
|
|
3492
4383
|
}
|
|
3493
4384
|
function describeRigPlan() {
|
|
3494
|
-
return { fields: [...
|
|
4385
|
+
return { fields: [...import_editor4.RIG_PLAN_FIELDS] };
|
|
3495
4386
|
}
|
|
3496
4387
|
function formatRigPlanReport(r) {
|
|
3497
|
-
const fields =
|
|
4388
|
+
const fields = import_editor4.RIG_PLAN_FIELDS.map((f) => {
|
|
3498
4389
|
const value = `${f.path}=${r.effective[f.path]}`;
|
|
3499
4390
|
const clamp2 = r.clamped.find((c) => c.field === f.path);
|
|
3500
4391
|
if (clamp2 !== void 0) {
|
|
@@ -3517,7 +4408,7 @@ function expectInput(label, fn) {
|
|
|
3517
4408
|
}
|
|
3518
4409
|
var LOSSLESS_PAGE_ROLE = "nose";
|
|
3519
4410
|
async function renderAtlasPage(crops, quantizeColors) {
|
|
3520
|
-
const layout = (0,
|
|
4411
|
+
const layout = (0, import_editor4.packAtlas)(
|
|
3521
4412
|
crops.map((c) => ({ id: c.id, width: c.width, height: c.height })),
|
|
3522
4413
|
void 0,
|
|
3523
4414
|
MAX_ATLAS_SIDE
|
|
@@ -3540,9 +4431,20 @@ async function autoRigFromLayers(input) {
|
|
|
3540
4431
|
if (!Array.isArray(layers) || layers.length === 0) {
|
|
3541
4432
|
throw new AutoRigInputError("layers must be a non-empty array");
|
|
3542
4433
|
}
|
|
3543
|
-
|
|
4434
|
+
const customInputs = input.customParts;
|
|
4435
|
+
if (customInputs !== void 0 && !Array.isArray(customInputs)) {
|
|
4436
|
+
throw new AutoRigInputError("customParts must be an array");
|
|
4437
|
+
}
|
|
4438
|
+
const customEntries = customInputs ?? [];
|
|
4439
|
+
customEntries.forEach((entry, i) => {
|
|
4440
|
+
const at = `customParts[${i}]`;
|
|
4441
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
|
|
4442
|
+
throw new AutoRigInputError(`${at} must be a plain object`);
|
|
4443
|
+
}
|
|
4444
|
+
});
|
|
4445
|
+
if (layers.length + customEntries.length > MAX_LAYERS) {
|
|
3544
4446
|
throw new AutoRigInputError(
|
|
3545
|
-
`too many layers: ${layers.length} > ${MAX_LAYERS}`
|
|
4447
|
+
`too many layers: ${layers.length + customEntries.length} > ${MAX_LAYERS}`
|
|
3546
4448
|
);
|
|
3547
4449
|
}
|
|
3548
4450
|
const outPath = resolveOutputPath(
|
|
@@ -3555,7 +4457,7 @@ async function autoRigFromLayers(input) {
|
|
|
3555
4457
|
);
|
|
3556
4458
|
}
|
|
3557
4459
|
if (input.style !== void 0) {
|
|
3558
|
-
throw new AutoRigInputError((0,
|
|
4460
|
+
throw new AutoRigInputError((0, import_editor4.styleRemovedMessage)("style"));
|
|
3559
4461
|
}
|
|
3560
4462
|
const turnTargets = input.turnTargets;
|
|
3561
4463
|
if (turnTargets !== void 0) {
|
|
@@ -3572,9 +4474,12 @@ async function autoRigFromLayers(input) {
|
|
|
3572
4474
|
const resolved = resolveInputPath(layer.path);
|
|
3573
4475
|
return { resolved, fileName: layer.fileName ?? import_node_path5.default.basename(resolved) };
|
|
3574
4476
|
});
|
|
4477
|
+
const customPaths = customEntries.map(
|
|
4478
|
+
(entry, i) => resolveInputPath(entry.path, `customParts[${i}].path`)
|
|
4479
|
+
);
|
|
3575
4480
|
const rolePairs = expectInput(
|
|
3576
4481
|
"role parsing",
|
|
3577
|
-
() => (0,
|
|
4482
|
+
() => (0, import_editor4.parseLayerRoles)(resolvedLayers.map((r) => r.fileName))
|
|
3578
4483
|
);
|
|
3579
4484
|
const roleByFileName = new Map(rolePairs.map((p) => [p.fileName, p.role]));
|
|
3580
4485
|
let canvasW = 0;
|
|
@@ -3582,6 +4487,8 @@ async function autoRigFromLayers(input) {
|
|
|
3582
4487
|
let totalPixels = 0;
|
|
3583
4488
|
let measurer;
|
|
3584
4489
|
const crops = [];
|
|
4490
|
+
const paints = /* @__PURE__ */ new Map();
|
|
4491
|
+
const anchorRoles = new Set(customEntries.map((e) => e.anchor));
|
|
3585
4492
|
for (let i = 0; i < resolvedLayers.length; i++) {
|
|
3586
4493
|
const { resolved, fileName } = resolvedLayers[i];
|
|
3587
4494
|
const png = await decodePng(resolved);
|
|
@@ -3604,7 +4511,7 @@ async function autoRigFromLayers(input) {
|
|
|
3604
4511
|
`canvas ${canvasW}x${canvasH} exceeds ${MAX_CANVAS_DIM}`
|
|
3605
4512
|
);
|
|
3606
4513
|
}
|
|
3607
|
-
measurer = (0,
|
|
4514
|
+
measurer = (0, import_editor4.createLayerSetMeasurer)({ width: canvasW, height: canvasH });
|
|
3608
4515
|
} else if (png.width !== canvasW || png.height !== canvasH) {
|
|
3609
4516
|
throw new AutoRigInputError(
|
|
3610
4517
|
`layer "${fileName}" size ${png.width}x${png.height} differs from canvas ${canvasW}x${canvasH}`
|
|
@@ -3621,9 +4528,48 @@ async function autoRigFromLayers(input) {
|
|
|
3621
4528
|
);
|
|
3622
4529
|
}
|
|
3623
4530
|
const { bbox } = layer;
|
|
4531
|
+
if (anchorRoles.has(role)) paints.set(role, paintRuns(png));
|
|
3624
4532
|
const buffer = await cropToBuffer(png.rgba, png.width, png.height, bbox);
|
|
3625
4533
|
crops.push({ id: role, buffer, width: bbox.w, height: bbox.h });
|
|
3626
4534
|
}
|
|
4535
|
+
const customLayers = [];
|
|
4536
|
+
const customCrops = [];
|
|
4537
|
+
for (let i = 0; i < customEntries.length; i++) {
|
|
4538
|
+
const at = `customParts[${i}]`;
|
|
4539
|
+
const { id } = customEntries[i];
|
|
4540
|
+
const resolved = customPaths[i];
|
|
4541
|
+
const png = await decodePng(resolved);
|
|
4542
|
+
if (png.width > MAX_LAYER_DIM || png.height > MAX_LAYER_DIM) {
|
|
4543
|
+
throw new AutoRigInputError(
|
|
4544
|
+
`${at}.path ${resolved} dimension ${png.width}x${png.height} exceeds ${MAX_LAYER_DIM}`
|
|
4545
|
+
);
|
|
4546
|
+
}
|
|
4547
|
+
totalPixels += png.width * png.height;
|
|
4548
|
+
if (totalPixels > MAX_TOTAL_PIXELS) {
|
|
4549
|
+
throw new AutoRigInputError(
|
|
4550
|
+
`total decoded pixels exceed ${MAX_TOTAL_PIXELS}`
|
|
4551
|
+
);
|
|
4552
|
+
}
|
|
4553
|
+
if (png.width !== canvasW || png.height !== canvasH) {
|
|
4554
|
+
throw new AutoRigInputError(
|
|
4555
|
+
`${at}.path size ${png.width}x${png.height} differs from canvas ${canvasW}x${canvasH}`
|
|
4556
|
+
);
|
|
4557
|
+
}
|
|
4558
|
+
const bbox = (0, import_editor4.detectAlphaBbox)(png.rgba, png.width, png.height);
|
|
4559
|
+
if (bbox === null) {
|
|
4560
|
+
throw new AutoRigInputError(
|
|
4561
|
+
`${at}.path "${import_node_path5.default.basename(resolved)}": layer is empty after alpha threshold`
|
|
4562
|
+
);
|
|
4563
|
+
}
|
|
4564
|
+
customLayers.push({ fileName: import_node_path5.default.basename(resolved), bbox });
|
|
4565
|
+
paints.set(id, paintRuns(png));
|
|
4566
|
+
customCrops.push({
|
|
4567
|
+
id,
|
|
4568
|
+
buffer: await cropToBuffer(png.rgba, png.width, png.height, bbox),
|
|
4569
|
+
width: bbox.w,
|
|
4570
|
+
height: bbox.h
|
|
4571
|
+
});
|
|
4572
|
+
}
|
|
3627
4573
|
const measurement = measurer.finish();
|
|
3628
4574
|
const { headHalfWidth, headHalfWidthApplied, turnOptions } = measurement;
|
|
3629
4575
|
const { headEdges, strandEdges } = turnOptions;
|
|
@@ -3633,9 +4579,10 @@ async function autoRigFromLayers(input) {
|
|
|
3633
4579
|
let turn;
|
|
3634
4580
|
let patches;
|
|
3635
4581
|
let rigPlan;
|
|
4582
|
+
let bakeReports;
|
|
3636
4583
|
let model;
|
|
3637
4584
|
try {
|
|
3638
|
-
model = (0,
|
|
4585
|
+
model = (0, import_editor4.generateIkiFromLayerSet)(
|
|
3639
4586
|
measurement.layers,
|
|
3640
4587
|
{ width: canvasW, height: canvasH },
|
|
3641
4588
|
{
|
|
@@ -3657,16 +4604,30 @@ async function autoRigFromLayers(input) {
|
|
|
3657
4604
|
}
|
|
3658
4605
|
},
|
|
3659
4606
|
...headEdges === void 0 ? {} : { headEdges },
|
|
3660
|
-
...strandEdges === void 0 ? {} : { strandEdges }
|
|
4607
|
+
...strandEdges === void 0 ? {} : { strandEdges },
|
|
4608
|
+
...input.customParts === void 0 ? {} : {
|
|
4609
|
+
customParts: customEntries.map(
|
|
4610
|
+
({ path: _path, ...rest }, i) => ({
|
|
4611
|
+
...rest,
|
|
4612
|
+
layer: customLayers[i]
|
|
4613
|
+
})
|
|
4614
|
+
)
|
|
4615
|
+
},
|
|
4616
|
+
...input.bakes === void 0 ? {} : {
|
|
4617
|
+
bakes: input.bakes,
|
|
4618
|
+
onBakesApplied: (reports) => {
|
|
4619
|
+
bakeReports = reports;
|
|
4620
|
+
}
|
|
4621
|
+
}
|
|
3661
4622
|
}
|
|
3662
4623
|
);
|
|
3663
4624
|
} catch (e) {
|
|
3664
|
-
if (!(e instanceof
|
|
4625
|
+
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)) {
|
|
3665
4626
|
throw e;
|
|
3666
4627
|
}
|
|
3667
4628
|
throw new AutoRigInputError(e.message);
|
|
3668
4629
|
}
|
|
3669
|
-
const doc = new
|
|
4630
|
+
const doc = new import_editor4.EditorDocument(model);
|
|
3670
4631
|
const losslessCrop = quantizeColors === void 0 ? void 0 : crops.find((c) => c.id === LOSSLESS_PAGE_ROLE);
|
|
3671
4632
|
const pages = losslessCrop === void 0 ? [await renderAtlasPage(crops, quantizeColors)] : [
|
|
3672
4633
|
await renderAtlasPage(
|
|
@@ -3675,7 +4636,9 @@ async function autoRigFromLayers(input) {
|
|
|
3675
4636
|
),
|
|
3676
4637
|
await renderAtlasPage([losslessCrop], void 0)
|
|
3677
4638
|
];
|
|
3678
|
-
const
|
|
4639
|
+
const customPage = customCrops.length === 0 ? void 0 : await renderAtlasPage(customCrops, quantizeColors);
|
|
4640
|
+
const allPages = customPage === void 0 ? pages : [...pages, customPage];
|
|
4641
|
+
const atlasBytes = allPages.reduce((sum, p) => sum + p.dataUri.length, 0);
|
|
3679
4642
|
if (atlasBytes > MAX_OUTPUT_BYTES) {
|
|
3680
4643
|
throw new AutoRigInputError(
|
|
3681
4644
|
`atlas data URI ${atlasBytes} bytes exceeds ${MAX_OUTPUT_BYTES}`
|
|
@@ -3687,29 +4650,68 @@ async function autoRigFromLayers(input) {
|
|
|
3687
4650
|
if (placement3 === void 0) {
|
|
3688
4651
|
throw new Error(`auto-rig: no atlas placement for "${crop.id}"`);
|
|
3689
4652
|
}
|
|
3690
|
-
const uv = (0,
|
|
4653
|
+
const uv = (0, import_editor4.uvRectFor)(placement3, {
|
|
3691
4654
|
width: layout.pageWidth,
|
|
3692
4655
|
height: layout.pageHeight
|
|
3693
4656
|
});
|
|
3694
|
-
return (0,
|
|
4657
|
+
return (0, import_editor4.partIdsOfRole)(crop.id).map((partId) => ({ partId, uv }));
|
|
3695
4658
|
})
|
|
3696
4659
|
);
|
|
4660
|
+
if (customPage !== void 0) {
|
|
4661
|
+
partTextureAssignments.push(
|
|
4662
|
+
...customPage.crops.map((crop) => {
|
|
4663
|
+
const placement3 = customPage.layout.placements.find(
|
|
4664
|
+
(p) => p.id === crop.id
|
|
4665
|
+
);
|
|
4666
|
+
return {
|
|
4667
|
+
partId: crop.id,
|
|
4668
|
+
uv: (0, import_editor4.uvRectFor)(placement3, {
|
|
4669
|
+
width: customPage.layout.pageWidth,
|
|
4670
|
+
height: customPage.layout.pageHeight
|
|
4671
|
+
})
|
|
4672
|
+
};
|
|
4673
|
+
})
|
|
4674
|
+
);
|
|
4675
|
+
}
|
|
3697
4676
|
doc.applyAtlas({
|
|
3698
4677
|
textures: [{ source: pages[0].dataUri }],
|
|
3699
4678
|
partTextureAssignments
|
|
3700
4679
|
});
|
|
3701
4680
|
let patched = doc.getModel();
|
|
3702
|
-
if (losslessCrop !== void 0) {
|
|
4681
|
+
if (losslessCrop !== void 0 || customPage !== void 0) {
|
|
3703
4682
|
patched = structuredClone(patched);
|
|
3704
|
-
patched.textures =
|
|
3705
|
-
|
|
3706
|
-
|
|
4683
|
+
patched.textures = allPages.map((p) => ({ source: p.dataUri }));
|
|
4684
|
+
if (losslessCrop !== void 0) {
|
|
4685
|
+
for (const partId of (0, import_editor4.partIdsOfRole)(losslessCrop.id)) {
|
|
4686
|
+
patched.parts.find((p) => p.id === partId).texture.index = 1;
|
|
4687
|
+
}
|
|
4688
|
+
}
|
|
4689
|
+
for (const crop of customCrops) {
|
|
4690
|
+
patched.parts.find((p) => p.id === crop.id).texture.index = pages.length;
|
|
3707
4691
|
}
|
|
3708
4692
|
}
|
|
3709
|
-
const finalModel = (0,
|
|
4693
|
+
const finalModel = (0, import_format11.parseIkiModel)(patched);
|
|
4694
|
+
const bakes = bakeReports === void 0 ? void 0 : checkBakes(finalModel, bakeReports);
|
|
3710
4695
|
writeFileAtomic(outPath, JSON.stringify(finalModel));
|
|
3711
4696
|
const folds = checkModelFolds(finalModel);
|
|
3712
4697
|
const physics = checkPhysics(finalModel);
|
|
4698
|
+
let gate;
|
|
4699
|
+
if (input.customParts !== void 0) {
|
|
4700
|
+
try {
|
|
4701
|
+
gate = checkCustomGate(
|
|
4702
|
+
finalModel,
|
|
4703
|
+
customEntries.map(({ id, anchor, tie, rigid }) => ({
|
|
4704
|
+
id,
|
|
4705
|
+
anchor,
|
|
4706
|
+
tie,
|
|
4707
|
+
...rigid === void 0 ? {} : { rigid }
|
|
4708
|
+
})),
|
|
4709
|
+
paints
|
|
4710
|
+
);
|
|
4711
|
+
} catch (e) {
|
|
4712
|
+
gate = failedCustomGate(finalModel, e);
|
|
4713
|
+
}
|
|
4714
|
+
}
|
|
3713
4715
|
return {
|
|
3714
4716
|
ok: true,
|
|
3715
4717
|
path: outPath,
|
|
@@ -3725,7 +4727,26 @@ async function autoRigFromLayers(input) {
|
|
|
3725
4727
|
folds,
|
|
3726
4728
|
physics,
|
|
3727
4729
|
...patches === void 0 ? {} : { patches },
|
|
3728
|
-
rigPlan
|
|
4730
|
+
rigPlan,
|
|
4731
|
+
...input.customParts === void 0 ? {} : {
|
|
4732
|
+
customParts: {
|
|
4733
|
+
parts: customCrops.map((crop, i) => {
|
|
4734
|
+
const part = finalModel.parts.find((p) => p.id === crop.id);
|
|
4735
|
+
return {
|
|
4736
|
+
id: crop.id,
|
|
4737
|
+
box: customLayers[i].bbox,
|
|
4738
|
+
mesh: {
|
|
4739
|
+
vertices: part.mesh.vertices.length / 2,
|
|
4740
|
+
triangles: part.mesh.indices.length / 3
|
|
4741
|
+
},
|
|
4742
|
+
order: part.order,
|
|
4743
|
+
page: part.texture.index
|
|
4744
|
+
};
|
|
4745
|
+
}),
|
|
4746
|
+
...bakes === void 0 ? {} : { bakes },
|
|
4747
|
+
gate
|
|
4748
|
+
}
|
|
4749
|
+
}
|
|
3729
4750
|
};
|
|
3730
4751
|
} catch (err) {
|
|
3731
4752
|
if (err instanceof AutoRigInputError)
|
|
@@ -3735,13 +4756,13 @@ async function autoRigFromLayers(input) {
|
|
|
3735
4756
|
}
|
|
3736
4757
|
|
|
3737
4758
|
// src/compose.ts
|
|
3738
|
-
var
|
|
4759
|
+
var import_node_fs8 = __toESM(require("fs"));
|
|
3739
4760
|
var import_node_path10 = __toESM(require("path"));
|
|
3740
4761
|
var import_sharp4 = __toESM(require("sharp"));
|
|
3741
|
-
var
|
|
4762
|
+
var import_editor14 = require("@ikijs/editor");
|
|
3742
4763
|
|
|
3743
4764
|
// src/trim.ts
|
|
3744
|
-
var
|
|
4765
|
+
var import_editor5 = require("@ikijs/editor");
|
|
3745
4766
|
var TRIM_THRESHOLD = 12;
|
|
3746
4767
|
var STRAY_SPECK_FRACTION = 0.01;
|
|
3747
4768
|
function luma(rgba, i) {
|
|
@@ -3770,7 +4791,7 @@ function boxWithoutStraySpecks(rgba, W, H) {
|
|
|
3770
4791
|
while (depth > 0) {
|
|
3771
4792
|
const p = stack[--depth];
|
|
3772
4793
|
size++;
|
|
3773
|
-
if (rgba[p * 4 + 3] >=
|
|
4794
|
+
if (rgba[p * 4 + 3] >= import_editor5.ALPHA_OPAQUE) opaque = true;
|
|
3774
4795
|
const px2 = p % W;
|
|
3775
4796
|
const py = (p - px2) / W;
|
|
3776
4797
|
setLeft = Math.min(setLeft, px2);
|
|
@@ -3807,12 +4828,12 @@ function boxWithoutStraySpecks(rgba, W, H) {
|
|
|
3807
4828
|
}
|
|
3808
4829
|
|
|
3809
4830
|
// src/measure.ts
|
|
3810
|
-
var
|
|
4831
|
+
var import_node_fs7 = __toESM(require("fs"));
|
|
3811
4832
|
var import_node_path9 = __toESM(require("path"));
|
|
3812
4833
|
|
|
3813
4834
|
// src/measure-arms.ts
|
|
3814
4835
|
var import_node_path6 = __toESM(require("path"));
|
|
3815
|
-
var
|
|
4836
|
+
var import_editor6 = require("@ikijs/editor");
|
|
3816
4837
|
var ARM_ROLES = ["arm_L", "arm_R"];
|
|
3817
4838
|
var CAP_OVERLAP = 0.5;
|
|
3818
4839
|
var px = (v) => `${Number(v.toFixed(1))}`;
|
|
@@ -3841,7 +4862,7 @@ async function armWarnings(absDir, layers) {
|
|
|
3841
4862
|
continue;
|
|
3842
4863
|
}
|
|
3843
4864
|
if (set === void 0) {
|
|
3844
|
-
const measurer = (0,
|
|
4865
|
+
const measurer = (0, import_editor6.createLayerSetMeasurer)({
|
|
3845
4866
|
width: body.canvasW,
|
|
3846
4867
|
height: body.canvasH
|
|
3847
4868
|
});
|
|
@@ -3849,12 +4870,12 @@ async function armWarnings(absDir, layers) {
|
|
|
3849
4870
|
}
|
|
3850
4871
|
let g;
|
|
3851
4872
|
try {
|
|
3852
|
-
g = (0,
|
|
4873
|
+
g = (0, import_editor6.armGeometry)(
|
|
3853
4874
|
await measured(set.measurer, absDir, arm),
|
|
3854
4875
|
set.body.bbox.x + set.body.bbox.w / 2 - body.canvasW / 2
|
|
3855
4876
|
);
|
|
3856
4877
|
} catch (err) {
|
|
3857
|
-
if (err instanceof
|
|
4878
|
+
if (err instanceof import_editor6.LayerGeometryError) {
|
|
3858
4879
|
warnings.push(
|
|
3859
4880
|
`${arm}: ${err.message} \u2014 auto_rig_from_layers refuses it. Regenerate arm.png drawn hanging, shoulder at the top. Billed.`
|
|
3860
4881
|
);
|
|
@@ -3882,7 +4903,7 @@ function capWarning(arm, g, body) {
|
|
|
3882
4903
|
}
|
|
3883
4904
|
|
|
3884
4905
|
// src/measure-hair-side.ts
|
|
3885
|
-
var
|
|
4906
|
+
var import_editor7 = require("@ikijs/editor");
|
|
3886
4907
|
var LOCK_ROLES = ["hair_side_R", "hair_side_L"];
|
|
3887
4908
|
var VISIBLE_MIN_PX = 3;
|
|
3888
4909
|
var LEAN_HH = 0.12;
|
|
@@ -3894,7 +4915,7 @@ function covers(runs, x) {
|
|
|
3894
4915
|
}
|
|
3895
4916
|
return false;
|
|
3896
4917
|
}
|
|
3897
|
-
function
|
|
4918
|
+
function runsAt2(layer, y) {
|
|
3898
4919
|
return layer?.rowRuns?.[y - layer.bbox.y] ?? [];
|
|
3899
4920
|
}
|
|
3900
4921
|
function opaqueRows(layer) {
|
|
@@ -3930,7 +4951,7 @@ async function hairSideWarnings(absDir, layers) {
|
|
|
3930
4951
|
}
|
|
3931
4952
|
}
|
|
3932
4953
|
if (mismatched) return warnings;
|
|
3933
|
-
const measurer = (0,
|
|
4954
|
+
const measurer = (0, import_editor7.createLayerSetMeasurer)({
|
|
3934
4955
|
width: ref.canvasW,
|
|
3935
4956
|
height: ref.canvasH
|
|
3936
4957
|
});
|
|
@@ -3970,8 +4991,8 @@ async function hairSideWarnings(absDir, layers) {
|
|
|
3970
4991
|
function rootWarning(role, lock, front) {
|
|
3971
4992
|
const y = opaqueRows(lock)?.top;
|
|
3972
4993
|
if (y === void 0) return void 0;
|
|
3973
|
-
const frontRuns =
|
|
3974
|
-
const lockRuns =
|
|
4994
|
+
const frontRuns = runsAt2(front, y);
|
|
4995
|
+
const lockRuns = runsAt2(lock, y);
|
|
3975
4996
|
let shown = 0;
|
|
3976
4997
|
for (let i = 0; i + 1 < lockRuns.length; i += 2) {
|
|
3977
4998
|
let stretch = 0;
|
|
@@ -3990,7 +5011,7 @@ function rootWarning(role, lock, front) {
|
|
|
3990
5011
|
function eyeCornerWarning(role, lock, side, eyeRole, eye) {
|
|
3991
5012
|
const row = Math.floor(eye.bboxCy);
|
|
3992
5013
|
const corner = side < 0 ? eye.marginLeft : eye.marginLeft + eye.w - 1;
|
|
3993
|
-
const runs =
|
|
5014
|
+
const runs = runsAt2(lock, row);
|
|
3994
5015
|
let overlap = 0;
|
|
3995
5016
|
for (let i = 0; i + 1 < runs.length; i += 2) {
|
|
3996
5017
|
if (corner < runs[i] || corner >= runs[i + 1]) continue;
|
|
@@ -4009,14 +5030,14 @@ function leanWarning(role, lock, side, face, back, eye) {
|
|
|
4009
5030
|
const bare = /* @__PURE__ */ new Set();
|
|
4010
5031
|
const rows = /* @__PURE__ */ new Set();
|
|
4011
5032
|
for (let y = lockRows.top; y <= Math.min(lockRows.bottom, faceBottom); y++) {
|
|
4012
|
-
const runs =
|
|
5033
|
+
const runs = runsAt2(lock, y);
|
|
4013
5034
|
if (runs.length === 0) continue;
|
|
4014
5035
|
const from = side < 0 ? runs[0] : runs[runs.length - 2];
|
|
4015
5036
|
const to = side < 0 ? runs[1] : runs[runs.length - 1];
|
|
4016
5037
|
const start = side < 0 ? from : Math.max(from, to - lean);
|
|
4017
5038
|
const end = side < 0 ? Math.min(to, from + lean) : to;
|
|
4018
|
-
const faceRuns =
|
|
4019
|
-
const backRuns =
|
|
5039
|
+
const faceRuns = runsAt2(face, y);
|
|
5040
|
+
const backRuns = runsAt2(back, y);
|
|
4020
5041
|
for (let x = start; x < end; x++) {
|
|
4021
5042
|
if (covers(faceRuns, x) || covers(backRuns, x)) continue;
|
|
4022
5043
|
bare.add(x);
|
|
@@ -4058,7 +5079,7 @@ function drawsTwoLocks(lock) {
|
|
|
4058
5079
|
}
|
|
4059
5080
|
|
|
4060
5081
|
// src/measure-forearm-pose.ts
|
|
4061
|
-
var
|
|
5082
|
+
var import_editor8 = require("@ikijs/editor");
|
|
4062
5083
|
var POSE_ROLES = ["forearm_pose_L", "forearm_pose_R"];
|
|
4063
5084
|
var ARM_OF = {
|
|
4064
5085
|
forearm_pose_L: "arm_L",
|
|
@@ -4092,7 +5113,7 @@ async function forearmPoseWarnings(absDir, layers) {
|
|
|
4092
5113
|
continue;
|
|
4093
5114
|
}
|
|
4094
5115
|
if (layers.body === void 0) continue;
|
|
4095
|
-
const measurer = (0,
|
|
5116
|
+
const measurer = (0, import_editor8.createLayerSetMeasurer)({
|
|
4096
5117
|
width: stats.canvasW,
|
|
4097
5118
|
height: stats.canvasH
|
|
4098
5119
|
});
|
|
@@ -4100,12 +5121,12 @@ async function forearmPoseWarnings(absDir, layers) {
|
|
|
4100
5121
|
let armLayer;
|
|
4101
5122
|
try {
|
|
4102
5123
|
armLayer = await measured(measurer, absDir, arm);
|
|
4103
|
-
a = (0,
|
|
5124
|
+
a = (0, import_editor8.armGeometry)(armLayer, arm === "arm_R" ? Infinity : -Infinity);
|
|
4104
5125
|
} catch (err) {
|
|
4105
|
-
if (err instanceof
|
|
5126
|
+
if (err instanceof import_editor8.LayerGeometryError) continue;
|
|
4106
5127
|
throw err;
|
|
4107
5128
|
}
|
|
4108
|
-
const b = (0,
|
|
5129
|
+
const b = (0, import_editor8.forearmPoseGeometry)(await measured(measurer, absDir, pose));
|
|
4109
5130
|
warnings.push(...jointWarnings(pose, arm, stats, a, armLayer, b));
|
|
4110
5131
|
}
|
|
4111
5132
|
return warnings;
|
|
@@ -4145,11 +5166,11 @@ function jointWarnings(pose, arm, stats, a, armLayer, b) {
|
|
|
4145
5166
|
|
|
4146
5167
|
// src/measure-lips.ts
|
|
4147
5168
|
var import_node_path7 = __toESM(require("path"));
|
|
4148
|
-
var
|
|
5169
|
+
var import_editor10 = require("@ikijs/editor");
|
|
4149
5170
|
|
|
4150
5171
|
// src/compose-lips.ts
|
|
4151
5172
|
var import_sharp2 = __toESM(require("sharp"));
|
|
4152
|
-
var
|
|
5173
|
+
var import_editor9 = require("@ikijs/editor");
|
|
4153
5174
|
var KEYED_SRC = "mouth_keyed.png";
|
|
4154
5175
|
var INTERIOR_SRC = "mouth_interior.png";
|
|
4155
5176
|
var KEY_CANDIDATE = 0.5;
|
|
@@ -4247,7 +5268,7 @@ function keyGreen(rgba, W, H) {
|
|
|
4247
5268
|
let candidates = 0;
|
|
4248
5269
|
for (let p = 0; p < n; p++) {
|
|
4249
5270
|
const i = p * 4;
|
|
4250
|
-
if (rgba[i + 3] <
|
|
5271
|
+
if (rgba[i + 3] < import_editor9.ALPHA_OPAQUE) continue;
|
|
4251
5272
|
const excess = (rgba[i + 1] - Math.max(rgba[i], rgba[i + 2])) / 255;
|
|
4252
5273
|
if (excess < KEY_CANDIDATE) continue;
|
|
4253
5274
|
candidates++;
|
|
@@ -4274,7 +5295,7 @@ function keyGreen(rgba, W, H) {
|
|
|
4274
5295
|
const dg = rgba[i + 1] - G[1];
|
|
4275
5296
|
const db = rgba[i + 2] - G[2];
|
|
4276
5297
|
const green = dr * dr + dg * dg + db * db <= KEY_FILL_DIST * KEY_FILL_DIST;
|
|
4277
|
-
if (rgba[i + 3] <
|
|
5298
|
+
if (rgba[i + 3] < import_editor9.ALPHA_OPAQUE) {
|
|
4278
5299
|
if (green) out[i + 3] = 0;
|
|
4279
5300
|
} else if (green) {
|
|
4280
5301
|
fill[p] = 1;
|
|
@@ -4450,7 +5471,7 @@ async function prepInterior(rgba, W, H) {
|
|
|
4450
5471
|
for (let y = box2.y; y < box2.y + box2.h; y++) {
|
|
4451
5472
|
for (let x = box2.x; x < box2.x + box2.w; x++) {
|
|
4452
5473
|
const i = (y * cw + x) * 4;
|
|
4453
|
-
if (crop[i + 3] <
|
|
5474
|
+
if (crop[i + 3] < import_editor9.ALPHA_OPAQUE) continue;
|
|
4454
5475
|
count++;
|
|
4455
5476
|
for (let c = 0; c < 3; c++) all[c] += crop[i + c];
|
|
4456
5477
|
if (luma(crop, i) < CAVITY_LUMA) {
|
|
@@ -4473,7 +5494,7 @@ function enclosedHole(frame, w, h) {
|
|
|
4473
5494
|
const stack = new Int32Array(n);
|
|
4474
5495
|
let depth = 0;
|
|
4475
5496
|
const seed = (p) => {
|
|
4476
|
-
if (!outside[p] && alpha(p) <
|
|
5497
|
+
if (!outside[p] && alpha(p) < import_editor9.ALPHA_OPAQUE) {
|
|
4477
5498
|
outside[p] = 1;
|
|
4478
5499
|
stack[depth++] = p;
|
|
4479
5500
|
}
|
|
@@ -4496,7 +5517,7 @@ function enclosedHole(frame, w, h) {
|
|
|
4496
5517
|
}
|
|
4497
5518
|
const mask = new Uint8Array(n);
|
|
4498
5519
|
for (let p = 0; p < n; p++) {
|
|
4499
|
-
if (alpha(p) <
|
|
5520
|
+
if (alpha(p) < import_editor9.ALPHA_OPAQUE && !outside[p]) mask[p] = 1;
|
|
4500
5521
|
}
|
|
4501
5522
|
const { label, sizes, boxes } = components(mask, w, h);
|
|
4502
5523
|
const main = largest(sizes);
|
|
@@ -4523,7 +5544,7 @@ function enclosedHole(frame, w, h) {
|
|
|
4523
5544
|
return { label, main, box: box2 };
|
|
4524
5545
|
}
|
|
4525
5546
|
function measureLips(layers, w, h) {
|
|
4526
|
-
const measurer = (0,
|
|
5547
|
+
const measurer = (0, import_editor9.createLayerSetMeasurer)({ width: w, height: h });
|
|
4527
5548
|
return new Map(
|
|
4528
5549
|
Object.entries(layers).map(([role, rgba]) => [
|
|
4529
5550
|
role,
|
|
@@ -4541,8 +5562,8 @@ function assertFoldContract(layers, w, h) {
|
|
|
4541
5562
|
}
|
|
4542
5563
|
byRole.set(role, layer);
|
|
4543
5564
|
}
|
|
4544
|
-
const opening = (0,
|
|
4545
|
-
const runs = (0,
|
|
5565
|
+
const opening = (0, import_editor9.mouthOpening)(byRole);
|
|
5566
|
+
const runs = (0, import_editor9.columnRuns)(byRole.get("mouth_inner"));
|
|
4546
5567
|
for (let col = opening.x0; col <= opening.x1; col++) {
|
|
4547
5568
|
const c = opening.at(col);
|
|
4548
5569
|
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;
|
|
@@ -4572,18 +5593,18 @@ async function splitLipSet(keyedPng, w, h, interior) {
|
|
|
4572
5593
|
}
|
|
4573
5594
|
const centre = Math.round((hb.x0 + hb.x1) / 2);
|
|
4574
5595
|
let stroke = 0;
|
|
4575
|
-
while (top[centre] - 1 - stroke >= 0 && alpha((top[centre] - 1 - stroke) * w + centre) >=
|
|
5596
|
+
while (top[centre] - 1 - stroke >= 0 && alpha((top[centre] - 1 - stroke) * w + centre) >= import_editor9.ALPHA_OPAQUE)
|
|
4576
5597
|
stroke++;
|
|
4577
5598
|
const bandCap = BAND_CAP * Math.max(1, stroke);
|
|
4578
5599
|
const skinRow = new Int32Array(w).fill(-1);
|
|
4579
5600
|
const inM = new Uint8Array(n);
|
|
4580
5601
|
for (let x = hb.x0; x <= hb.x1; x++) {
|
|
4581
5602
|
let y = bot[x];
|
|
4582
|
-
while (y < h && y - bot[x] < bandCap && alpha(y * w + x) >=
|
|
5603
|
+
while (y < h && y - bot[x] < bandCap && alpha(y * w + x) >= import_editor9.ALPHA_OPAQUE && luma(frame, (y * w + x) * 4) < BAND_LUMA)
|
|
4583
5604
|
y++;
|
|
4584
5605
|
for (let k = top[x]; k < y; k++) inM[k * w + x] = 1;
|
|
4585
5606
|
let r = y;
|
|
4586
|
-
while (r < h && alpha(r * w + x) <
|
|
5607
|
+
while (r < h && alpha(r * w + x) < import_editor9.ALPHA_OPAQUE) r++;
|
|
4587
5608
|
if (r < h) {
|
|
4588
5609
|
skinRow[x] = r;
|
|
4589
5610
|
inM[r * w + x] = 1;
|
|
@@ -4593,7 +5614,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
|
|
|
4593
5614
|
for (let y = 0; y < h; y++) {
|
|
4594
5615
|
for (let x = 0; x < w; x++) {
|
|
4595
5616
|
const p = y * w + x;
|
|
4596
|
-
if (inM[p] || alpha(p) <
|
|
5617
|
+
if (inM[p] || alpha(p) < import_editor9.ALPHA_OPAQUE) continue;
|
|
4597
5618
|
if (top[x] >= 0 && y < top[x]) continue;
|
|
4598
5619
|
if (x > 0 && inM[p - 1] || x < w - 1 && inM[p + 1]) grown[p] = 1;
|
|
4599
5620
|
}
|
|
@@ -4603,7 +5624,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
|
|
|
4603
5624
|
if (x < 0 || x >= w) continue;
|
|
4604
5625
|
let first = 0;
|
|
4605
5626
|
while (first < h && !(grown[first * w + x] && !inM[first * w + x])) first++;
|
|
4606
|
-
if (first > 0 && first < h && alpha((first - 1) * w + x) >=
|
|
5627
|
+
if (first > 0 && first < h && alpha((first - 1) * w + x) >= import_editor9.ALPHA_OPAQUE)
|
|
4607
5628
|
wall[x] = 1;
|
|
4608
5629
|
}
|
|
4609
5630
|
const gx = hb.x0 - 1;
|
|
@@ -4630,7 +5651,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
|
|
|
4630
5651
|
if (inOpening && skinRow[x] >= 0 && y >= skinRow[x]) copy(lower, p);
|
|
4631
5652
|
if (!grown[p]) {
|
|
4632
5653
|
const a = alpha(p);
|
|
4633
|
-
if (a >=
|
|
5654
|
+
if (a >= import_editor9.ALPHA_OPAQUE && a < 255 && besideHole(p, x, y)) {
|
|
4634
5655
|
inner.set(interior.cavity, p * 4);
|
|
4635
5656
|
inner[p * 4 + 3] = 255 - a;
|
|
4636
5657
|
}
|
|
@@ -4695,7 +5716,7 @@ async function restShiftOf(layers, width, height) {
|
|
|
4695
5716
|
}
|
|
4696
5717
|
byRole.set(role, layer);
|
|
4697
5718
|
}
|
|
4698
|
-
return (0,
|
|
5719
|
+
return (0, import_editor9.mouthRestShift)(byRole);
|
|
4699
5720
|
}
|
|
4700
5721
|
async function closedLips(upper, lower, shift, left, top) {
|
|
4701
5722
|
const shut = async (png, role) => {
|
|
@@ -4745,7 +5766,7 @@ async function closedLips(upper, lower, shift, left, top) {
|
|
|
4745
5766
|
}
|
|
4746
5767
|
|
|
4747
5768
|
// src/measure-lips.ts
|
|
4748
|
-
var isLipLayerRole = (role) =>
|
|
5769
|
+
var isLipLayerRole = (role) => import_editor10.LIP_ROLES.includes(role) || (0, import_editor10.isLipInsideRole)(role);
|
|
4749
5770
|
var MIN_OPENING_ROWS = 8;
|
|
4750
5771
|
var MIN_LINE_ROWS = 2;
|
|
4751
5772
|
var GREEN_EXCESS = 40;
|
|
@@ -4753,8 +5774,8 @@ var INTERIOR_GAP_FRACTION = 0.05;
|
|
|
4753
5774
|
var columns = (cols) => `${cols.length} column${cols.length === 1 ? "" : "s"} (first at x=${cols[0]})`;
|
|
4754
5775
|
async function lipWarnings(absDir, layers) {
|
|
4755
5776
|
const warnings = [];
|
|
4756
|
-
const present =
|
|
4757
|
-
const inside =
|
|
5777
|
+
const present = import_editor10.LIP_ROLES.filter((role) => layers[role] !== void 0);
|
|
5778
|
+
const inside = import_editor10.LIP_INSIDE_ROLES.filter((role) => layers[role] !== void 0);
|
|
4758
5779
|
if (present.length === 0) {
|
|
4759
5780
|
if (inside.length > 0) {
|
|
4760
5781
|
warnings.push(
|
|
@@ -4771,8 +5792,8 @@ async function lipWarnings(absDir, layers) {
|
|
|
4771
5792
|
`${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.`
|
|
4772
5793
|
);
|
|
4773
5794
|
}
|
|
4774
|
-
if (present.length <
|
|
4775
|
-
const missing =
|
|
5795
|
+
if (present.length < import_editor10.LIP_ROLES.length) {
|
|
5796
|
+
const missing = import_editor10.LIP_ROLES.filter((role) => layers[role] === void 0);
|
|
4776
5797
|
warnings.push(
|
|
4777
5798
|
`${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.`
|
|
4778
5799
|
);
|
|
@@ -4803,18 +5824,18 @@ async function lipWarnings(absDir, layers) {
|
|
|
4803
5824
|
);
|
|
4804
5825
|
}
|
|
4805
5826
|
}
|
|
4806
|
-
const measurer = (0,
|
|
5827
|
+
const measurer = (0, import_editor10.createLayerSetMeasurer)({
|
|
4807
5828
|
width: inner.canvasW,
|
|
4808
5829
|
height: inner.canvasH
|
|
4809
5830
|
});
|
|
4810
5831
|
const set = /* @__PURE__ */ new Map();
|
|
4811
5832
|
const green = [];
|
|
4812
|
-
for (const role of
|
|
5833
|
+
for (const role of import_editor10.LIP_ROLES) {
|
|
4813
5834
|
const fileName = `${role}.png`;
|
|
4814
5835
|
const { rgba } = await decodePng(import_node_path7.default.join(absDir, fileName));
|
|
4815
5836
|
set.set(role, measurer.add({ role, fileName, rgba }));
|
|
4816
5837
|
for (let i = 0; i < rgba.length; i += 4) {
|
|
4817
|
-
if (rgba[i + 3] >=
|
|
5838
|
+
if (rgba[i + 3] >= import_editor10.ALPHA_OPAQUE && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > GREEN_EXCESS) {
|
|
4818
5839
|
green.push(role);
|
|
4819
5840
|
break;
|
|
4820
5841
|
}
|
|
@@ -4822,15 +5843,15 @@ async function lipWarnings(absDir, layers) {
|
|
|
4822
5843
|
}
|
|
4823
5844
|
let opening;
|
|
4824
5845
|
try {
|
|
4825
|
-
opening = (0,
|
|
5846
|
+
opening = (0, import_editor10.mouthOpening)(set);
|
|
4826
5847
|
} catch (err) {
|
|
4827
|
-
if (err instanceof
|
|
5848
|
+
if (err instanceof import_editor10.LayerGeometryError) {
|
|
4828
5849
|
warnings.push(err.message);
|
|
4829
5850
|
return { warnings };
|
|
4830
5851
|
}
|
|
4831
5852
|
throw err;
|
|
4832
5853
|
}
|
|
4833
|
-
const innerRuns = (0,
|
|
5854
|
+
const innerRuns = (0, import_editor10.columnRuns)(set.get("mouth_inner"));
|
|
4834
5855
|
const noInterior = [];
|
|
4835
5856
|
const gap = [];
|
|
4836
5857
|
const noLine = [];
|
|
@@ -4916,8 +5937,8 @@ async function lipWarnings(absDir, layers) {
|
|
|
4916
5937
|
|
|
4917
5938
|
// src/measure-turn.ts
|
|
4918
5939
|
var import_node_path8 = __toESM(require("path"));
|
|
4919
|
-
var import_editor10 = require("@ikijs/editor");
|
|
4920
5940
|
var import_editor11 = require("@ikijs/editor");
|
|
5941
|
+
var import_editor12 = require("@ikijs/editor");
|
|
4921
5942
|
var DEFAULT_IRIS = { hueMin: 230, hueMax: 300, satMin: 0.22 };
|
|
4922
5943
|
var IRIS_V_MIN = 0.18;
|
|
4923
5944
|
var IRIS_V_MAX = 0.95;
|
|
@@ -5067,7 +6088,7 @@ async function measureTurnImage(filePath, iris) {
|
|
|
5067
6088
|
let transparent = false;
|
|
5068
6089
|
if (hasAlpha) {
|
|
5069
6090
|
for (let i = 0; i < n; i++) {
|
|
5070
|
-
if (rgba[i * 4 + 3] <
|
|
6091
|
+
if (rgba[i * 4 + 3] < import_editor11.ALPHA_OPAQUE) {
|
|
5071
6092
|
transparent = true;
|
|
5072
6093
|
break;
|
|
5073
6094
|
}
|
|
@@ -5078,7 +6099,7 @@ async function measureTurnImage(filePath, iris) {
|
|
|
5078
6099
|
const fg = new Uint8Array(n);
|
|
5079
6100
|
const value = new Float32Array(n);
|
|
5080
6101
|
for (let i = 0; i < n; i++) {
|
|
5081
|
-
if (rgba[i * 4 + 3] <
|
|
6102
|
+
if (rgba[i * 4 + 3] < import_editor11.ALPHA_OPAQUE) continue;
|
|
5082
6103
|
const [hue, s, v] = rgbToHsv(rgba[i * 4], rgba[i * 4 + 1], rgba[i * 4 + 2]);
|
|
5083
6104
|
if (maskMode === "alpha") {
|
|
5084
6105
|
fg[i] = 1;
|
|
@@ -5144,12 +6165,12 @@ async function measureTurnImage(filePath, iris) {
|
|
|
5144
6165
|
}
|
|
5145
6166
|
const [irisL, irisR] = best.pair;
|
|
5146
6167
|
const eyeRow = Math.round((irisL.cy + irisR.cy) / 2);
|
|
5147
|
-
const { left, right } = (0,
|
|
6168
|
+
const { left, right } = (0, import_editor11.foregroundSpan)(
|
|
5148
6169
|
fg,
|
|
5149
6170
|
width,
|
|
5150
6171
|
height,
|
|
5151
|
-
eyeRow -
|
|
5152
|
-
eyeRow +
|
|
6172
|
+
eyeRow - import_editor11.HEAD_BAND,
|
|
6173
|
+
eyeRow + import_editor11.HEAD_BAND
|
|
5153
6174
|
);
|
|
5154
6175
|
if (right <= left) {
|
|
5155
6176
|
throw new AutoRigInputError(
|
|
@@ -5173,7 +6194,7 @@ async function measureTurnImage(filePath, iris) {
|
|
|
5173
6194
|
left,
|
|
5174
6195
|
right,
|
|
5175
6196
|
cx: (left + right) / 2,
|
|
5176
|
-
half: (0,
|
|
6197
|
+
half: (0, import_editor11.headHalfOf)({ left, right })
|
|
5177
6198
|
},
|
|
5178
6199
|
pairCx: (irisL.cx + irisR.cx) / 2,
|
|
5179
6200
|
eyeGap: irisR.cx - irisL.cx
|
|
@@ -5364,7 +6385,7 @@ function noseSpeckWarning({ core, part }, source) {
|
|
|
5364
6385
|
`the layer's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} crop`,
|
|
5365
6386
|
`auto_rig_from_layers turns and tilts the nose about its whole crop instead`
|
|
5366
6387
|
];
|
|
5367
|
-
return `nose: ${found} \u2014 under ${
|
|
6388
|
+
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.`;
|
|
5368
6389
|
}
|
|
5369
6390
|
async function lashOffSclera(eyePath, lashPath) {
|
|
5370
6391
|
const eye = await decodePng(eyePath);
|
|
@@ -5382,7 +6403,7 @@ async function lashOffSclera(eyePath, lashPath) {
|
|
|
5382
6403
|
return { opaque, off };
|
|
5383
6404
|
}
|
|
5384
6405
|
async function measureDir(absDir, noseSpeck) {
|
|
5385
|
-
const files =
|
|
6406
|
+
const files = import_node_fs7.default.readdirSync(absDir).filter((f) => f.endsWith(".png") && !f.startsWith("preview")).sort();
|
|
5386
6407
|
if (files.length === 0) {
|
|
5387
6408
|
throw new AutoRigInputError(`no role layers in ${absDir}`);
|
|
5388
6409
|
}
|
|
@@ -5502,10 +6523,10 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
5502
6523
|
warnings.push(noseSpeckWarning(noseSpeck, "compose"));
|
|
5503
6524
|
} else if (layers.nose !== void 0) {
|
|
5504
6525
|
const nose = await decodePng(import_node_path9.default.join(absDir, "nose.png"));
|
|
5505
|
-
const core = (0,
|
|
6526
|
+
const core = (0, import_editor12.denseCoreOf)(nose.rgba, nose.width, nose.height);
|
|
5506
6527
|
if (core !== null) {
|
|
5507
6528
|
const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
|
|
5508
|
-
if ((0,
|
|
6529
|
+
if ((0, import_editor12.isSpeckCore)(core, crop))
|
|
5509
6530
|
warnings.push(noseSpeckWarning({ core, part: crop }, "layer"));
|
|
5510
6531
|
}
|
|
5511
6532
|
}
|
|
@@ -5576,12 +6597,12 @@ function formatMeasureReport(result) {
|
|
|
5576
6597
|
|
|
5577
6598
|
// src/compose-arms.ts
|
|
5578
6599
|
var import_sharp3 = __toESM(require("sharp"));
|
|
5579
|
-
var
|
|
6600
|
+
var import_editor13 = require("@ikijs/editor");
|
|
5580
6601
|
var ARM_WIDTH = 0.4;
|
|
5581
6602
|
var SHOULDER_DROP = 0.12;
|
|
5582
6603
|
async function armPlacement(role, cfg, part, body) {
|
|
5583
6604
|
const { data } = await (0, import_sharp3.default)(part.buf).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
5584
|
-
const layer = (0,
|
|
6605
|
+
const layer = (0, import_editor13.createLayerSetMeasurer)({ width: part.w, height: part.h }).add({
|
|
5585
6606
|
role,
|
|
5586
6607
|
fileName: "arm.png",
|
|
5587
6608
|
rgba: data
|
|
@@ -5593,9 +6614,9 @@ async function armPlacement(role, cfg, part, body) {
|
|
|
5593
6614
|
}
|
|
5594
6615
|
let g;
|
|
5595
6616
|
try {
|
|
5596
|
-
g = (0,
|
|
6617
|
+
g = (0, import_editor13.armGeometry)(layer, role === "arm_R" ? Infinity : -Infinity);
|
|
5597
6618
|
} catch (err) {
|
|
5598
|
-
if (err instanceof
|
|
6619
|
+
if (err instanceof import_editor13.LayerGeometryError) {
|
|
5599
6620
|
throw new AutoRigInputError(`layout.${role}: ${err.message}`);
|
|
5600
6621
|
}
|
|
5601
6622
|
throw err;
|
|
@@ -5622,7 +6643,7 @@ async function armPlacement(role, cfg, part, body) {
|
|
|
5622
6643
|
}
|
|
5623
6644
|
async function poseGeometryOf(role, png, size, when) {
|
|
5624
6645
|
const { data } = await (0, import_sharp3.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
5625
|
-
const layer = (0,
|
|
6646
|
+
const layer = (0, import_editor13.createLayerSetMeasurer)({
|
|
5626
6647
|
width: size.w,
|
|
5627
6648
|
height: size.h
|
|
5628
6649
|
}).add({ role, fileName: "forearm_pose.png", rgba: data });
|
|
@@ -5631,7 +6652,7 @@ async function poseGeometryOf(role, png, size, when) {
|
|
|
5631
6652
|
`layout.${role}: forearm_pose.png is empty after alpha threshold${when}`
|
|
5632
6653
|
);
|
|
5633
6654
|
}
|
|
5634
|
-
return (0,
|
|
6655
|
+
return (0, import_editor13.forearmPoseGeometry)(layer);
|
|
5635
6656
|
}
|
|
5636
6657
|
async function forearmPoseWidth(role, trimmed, elbowRun) {
|
|
5637
6658
|
const g = await poseGeometryOf(role, trimmed.data, trimmed, "");
|
|
@@ -5929,18 +6950,18 @@ function keyWhiteToAlpha(rgba) {
|
|
|
5929
6950
|
async function coreAndBoundsOf(png) {
|
|
5930
6951
|
const { data, info } = await (0, import_sharp4.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
5931
6952
|
return {
|
|
5932
|
-
core: (0,
|
|
6953
|
+
core: (0, import_editor12.denseCoreOf)(data, info.width, info.height),
|
|
5933
6954
|
bounds: { x: 0, y: 0, w: info.width, h: info.height }
|
|
5934
6955
|
};
|
|
5935
6956
|
}
|
|
5936
6957
|
async function hasCoverage(png) {
|
|
5937
6958
|
const { data, info } = await (0, import_sharp4.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
5938
|
-
return (0,
|
|
6959
|
+
return (0, import_editor14.detectAlphaBbox)(data, info.width, info.height) !== null;
|
|
5939
6960
|
}
|
|
5940
6961
|
async function noseSizingOf(png) {
|
|
5941
6962
|
const { core, bounds } = await coreAndBoundsOf(png);
|
|
5942
6963
|
if (core === null) return { box: bounds, whole: true };
|
|
5943
|
-
if ((0,
|
|
6964
|
+
if ((0, import_editor12.isSpeckCore)(core, bounds)) {
|
|
5944
6965
|
return {
|
|
5945
6966
|
box: bounds,
|
|
5946
6967
|
whole: true,
|
|
@@ -5958,7 +6979,7 @@ async function trimmedPart(role, cfg, partsDir, inMemory, flipSource) {
|
|
|
5958
6979
|
img = (0, import_sharp4.default)(inMemory);
|
|
5959
6980
|
} else {
|
|
5960
6981
|
const srcPath = import_node_path10.default.join(partsDir, cfg.src);
|
|
5961
|
-
if (!
|
|
6982
|
+
if (!import_node_fs8.default.existsSync(srcPath)) {
|
|
5962
6983
|
if (cfg.optional) return null;
|
|
5963
6984
|
throw new AutoRigInputError(
|
|
5964
6985
|
`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" : "")
|
|
@@ -6062,7 +7083,7 @@ function detachedAboveWhite(rgba, W, H) {
|
|
|
6062
7083
|
for (let p = 0; p < n; p++) {
|
|
6063
7084
|
const alpha = rgba[p * 4 + 3];
|
|
6064
7085
|
if (alpha > 0 && luma(rgba, p * 4) >= EYE_LASH_LUMA)
|
|
6065
|
-
ink[p] = alpha >=
|
|
7086
|
+
ink[p] = alpha >= import_editor14.ALPHA_OPAQUE ? 2 : 1;
|
|
6066
7087
|
}
|
|
6067
7088
|
const label = new Int32Array(n).fill(-1);
|
|
6068
7089
|
const stack = new Int32Array(n);
|
|
@@ -6143,7 +7164,7 @@ function detachedAboveWhite(rgba, W, H) {
|
|
|
6143
7164
|
}
|
|
6144
7165
|
async function prepEyeSplit(partsDir) {
|
|
6145
7166
|
const srcPath = import_node_path10.default.join(partsDir, EYEWHITE_SRC);
|
|
6146
|
-
if (!
|
|
7167
|
+
if (!import_node_fs8.default.existsSync(srcPath)) {
|
|
6147
7168
|
throw new AutoRigInputError(`missing eyewhite source: ${srcPath}`);
|
|
6148
7169
|
}
|
|
6149
7170
|
const { width: W, height: H, rgba: data } = await decodePng(srcPath);
|
|
@@ -6167,7 +7188,7 @@ async function prepEyeSplit(partsDir) {
|
|
|
6167
7188
|
const lashCutoffY = minY + LASH_KEEP_FRACTION * (maxY - minY + 1);
|
|
6168
7189
|
const detached = detachedAboveWhite(data, W, H);
|
|
6169
7190
|
const isDark = (i) => data[i + 3] > 0 && luma(data, i) < EYE_LASH_LUMA;
|
|
6170
|
-
const isLight = (i) => data[i + 3] >=
|
|
7191
|
+
const isLight = (i) => data[i + 3] >= import_editor14.ALPHA_OPAQUE && luma(data, i) >= EYE_LASH_LUMA;
|
|
6171
7192
|
const isWarm = (i) => data[i] - data[i + 2] >= EYE_LID_WARMTH;
|
|
6172
7193
|
const whiteTop = new Int32Array(W).fill(-1);
|
|
6173
7194
|
for (let x = 0; x < W; x++) {
|
|
@@ -6230,7 +7251,7 @@ function hasTransparency(rgba) {
|
|
|
6230
7251
|
return false;
|
|
6231
7252
|
}
|
|
6232
7253
|
async function prepLipSources(partsDir, mirrored) {
|
|
6233
|
-
const has = (name) =>
|
|
7254
|
+
const has = (name) => import_node_fs8.default.existsSync(import_node_path10.default.join(partsDir, name));
|
|
6234
7255
|
const keyed = has(KEYED_SRC);
|
|
6235
7256
|
const interior = has(INTERIOR_SRC);
|
|
6236
7257
|
if (keyed && !interior) {
|
|
@@ -6273,7 +7294,7 @@ async function composeLayersFromParts(input) {
|
|
|
6273
7294
|
try {
|
|
6274
7295
|
const outDir = resolveOutputDir(input.outDir);
|
|
6275
7296
|
const partsDir = resolveInputDir(input.partsDir);
|
|
6276
|
-
if (
|
|
7297
|
+
if (import_node_fs8.default.realpathSync(partsDir) === outDir) {
|
|
6277
7298
|
throw new AutoRigInputError(
|
|
6278
7299
|
`partsDir and outDir resolve to the same directory (${outDir}): composing would overwrite the source parts`
|
|
6279
7300
|
);
|
|
@@ -6337,7 +7358,7 @@ async function composeLayersFromParts(input) {
|
|
|
6337
7358
|
lip_lower: split2.lower,
|
|
6338
7359
|
lip_upper: split2.upper
|
|
6339
7360
|
}[role];
|
|
6340
|
-
if ((0,
|
|
7361
|
+
if ((0, import_editor14.isLipInsideRole)(role) && !await hasCoverage(buf)) {
|
|
6341
7362
|
skipped.push(role);
|
|
6342
7363
|
continue;
|
|
6343
7364
|
}
|
|
@@ -6352,7 +7373,7 @@ async function composeLayersFromParts(input) {
|
|
|
6352
7373
|
}
|
|
6353
7374
|
if (key === "arm_L" || key === "arm_R") {
|
|
6354
7375
|
const arm = layout[key];
|
|
6355
|
-
if (!
|
|
7376
|
+
if (!import_node_fs8.default.existsSync(import_node_path10.default.join(partsDir, arm.src))) continue;
|
|
6356
7377
|
const body = placed.find((p) => p.role === "body");
|
|
6357
7378
|
if (body === void 0) {
|
|
6358
7379
|
throw new AutoRigInputError(
|
|
@@ -6395,7 +7416,7 @@ async function composeLayersFromParts(input) {
|
|
|
6395
7416
|
}
|
|
6396
7417
|
if (key === "forearm_pose_L" || key === "forearm_pose_R") {
|
|
6397
7418
|
const pose = layout[key];
|
|
6398
|
-
if (!
|
|
7419
|
+
if (!import_node_fs8.default.existsSync(import_node_path10.default.join(partsDir, pose.src))) continue;
|
|
6399
7420
|
const armRole = key === "forearm_pose_L" ? "arm_L" : "arm_R";
|
|
6400
7421
|
const arm = placed.find((p) => p.role === armRole);
|
|
6401
7422
|
if (arm?.elbow === void 0 || arm.elbowRun === void 0) {
|
|
@@ -6512,11 +7533,11 @@ async function composeLayersFromParts(input) {
|
|
|
6512
7533
|
);
|
|
6513
7534
|
for (const role of ORDER) {
|
|
6514
7535
|
if (placed.some((p) => p.role === role)) continue;
|
|
6515
|
-
|
|
7536
|
+
import_node_fs8.default.rmSync(import_node_path10.default.join(outDir, `${role}.png`), { force: true });
|
|
6516
7537
|
}
|
|
6517
7538
|
const posed = (role) => role === "forearm_pose_L" || role === "forearm_pose_R";
|
|
6518
7539
|
if (!placed.some((p) => posed(p.role))) {
|
|
6519
|
-
|
|
7540
|
+
import_node_fs8.default.rmSync(import_node_path10.default.join(outDir, "preview-pose.png"), { force: true });
|
|
6520
7541
|
}
|
|
6521
7542
|
const layers = [];
|
|
6522
7543
|
for (const { role, part, left, top } of placed) {
|
|
@@ -6532,7 +7553,7 @@ async function composeLayersFromParts(input) {
|
|
|
6532
7553
|
});
|
|
6533
7554
|
}
|
|
6534
7555
|
const restInput = (role, buf) => {
|
|
6535
|
-
if (role === "mouth_inner" || (0,
|
|
7556
|
+
if (role === "mouth_inner" || (0, import_editor14.isLipInsideRole)(role)) return null;
|
|
6536
7557
|
if (closed === void 0) return buf;
|
|
6537
7558
|
if (role === "lip_upper") return closed.upper;
|
|
6538
7559
|
if (role === "lip_lower") return closed.lower;
|
|
@@ -6659,8 +7680,18 @@ function formatPatchReports(reports) {
|
|
|
6659
7680
|
return `PATCH ${r.index} ${r.target} at ${at}: ${r.moved} of ${r.of} points (${where}), largest move ${r.maxPx} model px`;
|
|
6660
7681
|
});
|
|
6661
7682
|
}
|
|
7683
|
+
function formatCustomPartReports(parts) {
|
|
7684
|
+
return parts.map(
|
|
7685
|
+
(p) => `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}`
|
|
7686
|
+
);
|
|
7687
|
+
}
|
|
7688
|
+
function formatBakeChecks(bakes) {
|
|
7689
|
+
return bakes.map(
|
|
7690
|
+
(b) => `BAKE ${b.part} ${b.param}: ${b.vertices} vertices, stops ${b.stops.join(",")}, error ${Math.round(b.errorPx * 1e3) / 1e3} px`
|
|
7691
|
+
);
|
|
7692
|
+
}
|
|
6662
7693
|
function createIkiMcpServer() {
|
|
6663
|
-
const server = new import_mcp.McpServer({ name: "iki", version: "0.
|
|
7694
|
+
const server = new import_mcp.McpServer({ name: "iki", version: "0.34.0" });
|
|
6664
7695
|
server.registerTool(
|
|
6665
7696
|
"validate_iki",
|
|
6666
7697
|
{
|
|
@@ -6752,7 +7783,7 @@ function createIkiMcpServer() {
|
|
|
6752
7783
|
server.registerTool(
|
|
6753
7784
|
"auto_rig_from_layers",
|
|
6754
7785
|
{
|
|
6755
|
-
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.",
|
|
7786
|
+
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`. 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.",
|
|
6756
7787
|
inputSchema: {
|
|
6757
7788
|
layers: import_zod.z.array(
|
|
6758
7789
|
import_zod.z.object({
|
|
@@ -6775,7 +7806,7 @@ function createIkiMcpServer() {
|
|
|
6775
7806
|
noseShift: import_zod.z.number().optional(),
|
|
6776
7807
|
mouthShift: import_zod.z.number().optional()
|
|
6777
7808
|
}).passthrough().optional().describe(
|
|
6778
|
-
"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."
|
|
7809
|
+
"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."
|
|
6779
7810
|
),
|
|
6780
7811
|
style: import_zod.z.unknown().optional().describe(
|
|
6781
7812
|
"Removed in @ikijs/mcp 0.30.0: pass `rigPlan`. Any value here is refused with the field map."
|
|
@@ -6796,6 +7827,63 @@ function createIkiMcpServer() {
|
|
|
6796
7827
|
}).passthrough().optional().describe(
|
|
6797
7828
|
"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."
|
|
6798
7829
|
),
|
|
7830
|
+
customParts: import_zod.z.array(
|
|
7831
|
+
import_zod.z.object({
|
|
7832
|
+
id: import_zod.z.string().describe(
|
|
7833
|
+
"The part's id: a plain identifier, not a role's name or a part id."
|
|
7834
|
+
),
|
|
7835
|
+
path: import_zod.z.string().describe(
|
|
7836
|
+
"The part's own PNG, the same size as the role layers (resolved against cwd), drawn alone and whole on a transparent ground."
|
|
7837
|
+
),
|
|
7838
|
+
anchor: import_zod.z.string().describe("The role whose layer the part is fixed against."),
|
|
7839
|
+
tie: import_zod.z.array(import_zod.z.number()).length(2).describe(
|
|
7840
|
+
"[x, y] in canvas px where the part meets the anchor: inside both the part's alpha box and the anchor layer's."
|
|
7841
|
+
),
|
|
7842
|
+
after: import_zod.z.string().describe(
|
|
7843
|
+
"A role of the set: the part is drawn right after that role's last part."
|
|
7844
|
+
),
|
|
7845
|
+
deformer: import_zod.z.string().optional().describe(
|
|
7846
|
+
"The matrix deformer it hangs on; only `headDeformer` (the default) is accepted."
|
|
7847
|
+
),
|
|
7848
|
+
rigid: import_zod.z.boolean().optional().describe(
|
|
7849
|
+
"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."
|
|
7850
|
+
)
|
|
7851
|
+
}).passthrough()
|
|
7852
|
+
).optional().describe(
|
|
7853
|
+
"Parts the auto-rigger has no role for, each `{ id, path, anchor, tie, after, deformer?, rigid? }`. 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."
|
|
7854
|
+
),
|
|
7855
|
+
bakes: import_zod.z.object({
|
|
7856
|
+
targets: import_zod.z.array(
|
|
7857
|
+
import_zod.z.object({
|
|
7858
|
+
id: import_zod.z.string().optional(),
|
|
7859
|
+
param: import_zod.z.string(),
|
|
7860
|
+
parts: import_zod.z.array(import_zod.z.string()),
|
|
7861
|
+
box: import_zod.z.object({
|
|
7862
|
+
x: import_zod.z.number(),
|
|
7863
|
+
y: import_zod.z.number(),
|
|
7864
|
+
w: import_zod.z.number(),
|
|
7865
|
+
h: import_zod.z.number()
|
|
7866
|
+
}).passthrough().optional(),
|
|
7867
|
+
grid: import_zod.z.object({ cols: import_zod.z.number(), rows: import_zod.z.number() }).passthrough(),
|
|
7868
|
+
stops: import_zod.z.record(
|
|
7869
|
+
import_zod.z.string(),
|
|
7870
|
+
import_zod.z.array(import_zod.z.array(import_zod.z.number()).length(2))
|
|
7871
|
+
),
|
|
7872
|
+
mirror: import_zod.z.boolean().optional(),
|
|
7873
|
+
why: import_zod.z.string().optional()
|
|
7874
|
+
}).passthrough()
|
|
7875
|
+
),
|
|
7876
|
+
meshes: import_zod.z.record(
|
|
7877
|
+
import_zod.z.string(),
|
|
7878
|
+
import_zod.z.object({
|
|
7879
|
+
rows: import_zod.z.array(import_zod.z.number()).optional(),
|
|
7880
|
+
cols: import_zod.z.number().optional(),
|
|
7881
|
+
cellPx: import_zod.z.number().optional()
|
|
7882
|
+
}).passthrough()
|
|
7883
|
+
).optional()
|
|
7884
|
+
}).passthrough().optional().describe(
|
|
7885
|
+
"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."
|
|
7886
|
+
),
|
|
6799
7887
|
patches: import_zod.z.array(
|
|
6800
7888
|
import_zod.z.object({
|
|
6801
7889
|
target: import_zod.z.string(),
|
|
@@ -6822,7 +7910,11 @@ function createIkiMcpServer() {
|
|
|
6822
7910
|
...args,
|
|
6823
7911
|
// `.length(2)` makes each region span a pair, which its inferred
|
|
6824
7912
|
// `number[]` cannot say.
|
|
6825
|
-
patches: args.patches
|
|
7913
|
+
patches: args.patches,
|
|
7914
|
+
customParts: args.customParts,
|
|
7915
|
+
// Each stop's `.length(2)` makes it a pair, which its inferred
|
|
7916
|
+
// `number[]` cannot say.
|
|
7917
|
+
bakes: args.bakes
|
|
6826
7918
|
});
|
|
6827
7919
|
const text = r.ok ? [
|
|
6828
7920
|
r.path,
|
|
@@ -6830,7 +7922,10 @@ function createIkiMcpServer() {
|
|
|
6830
7922
|
...formatPatchReports(r.patches ?? []),
|
|
6831
7923
|
...formatFoldReport(r.folds, r.canvas),
|
|
6832
7924
|
...formatPhysicsReport(r.physics),
|
|
6833
|
-
...formatHairSideReport(r.turn?.hairSide, r.canvas)
|
|
7925
|
+
...formatHairSideReport(r.turn?.hairSide, r.canvas),
|
|
7926
|
+
...formatCustomPartReports(r.customParts?.parts ?? []),
|
|
7927
|
+
...formatBakeChecks(r.customParts?.bakes ?? []),
|
|
7928
|
+
...r.customParts ? formatCustomGate(r.customParts.gate) : []
|
|
6834
7929
|
].join("\n") : `INVALID: ${r.error}`;
|
|
6835
7930
|
return { content: [{ type: "text", text }], structuredContent: r };
|
|
6836
7931
|
} catch (err) {
|
|
@@ -6922,7 +8017,7 @@ function createIkiMcpServer() {
|
|
|
6922
8017
|
server.registerTool(
|
|
6923
8018
|
"measure_turn_reference",
|
|
6924
8019
|
{
|
|
6925
|
-
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.",
|
|
8020
|
+
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.",
|
|
6926
8021
|
inputSchema: {
|
|
6927
8022
|
front: import_zod.z.string().describe("Front-facing PNG file path (resolved against cwd)."),
|
|
6928
8023
|
turned: import_zod.z.string().describe("The same character turned, as a PNG file path."),
|
|
@@ -7005,7 +8100,10 @@ function createIkiMcpServer() {
|
|
|
7005
8100
|
}).optional()
|
|
7006
8101
|
})
|
|
7007
8102
|
).optional().describe(
|
|
7008
|
-
"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`."
|
|
8103
|
+
"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."
|
|
8104
|
+
),
|
|
8105
|
+
hideParts: import_zod.z.array(import_zod.z.string()).optional().describe(
|
|
8106
|
+
"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, 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."
|
|
7009
8107
|
)
|
|
7010
8108
|
}
|
|
7011
8109
|
},
|
|
@@ -7041,12 +8139,62 @@ function createIkiMcpServer() {
|
|
|
7041
8139
|
}
|
|
7042
8140
|
}
|
|
7043
8141
|
);
|
|
8142
|
+
server.registerTool(
|
|
8143
|
+
"probe_rig",
|
|
8144
|
+
{
|
|
8145
|
+
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.",
|
|
8146
|
+
inputSchema: {
|
|
8147
|
+
modelPath: import_zod.z.string().describe(
|
|
8148
|
+
"Rigged .iki file path (resolved against cwd; must sit under the working directory)."
|
|
8149
|
+
),
|
|
8150
|
+
queries: import_zod.z.array(
|
|
8151
|
+
import_zod.z.discriminatedUnion("op", [
|
|
8152
|
+
import_zod.z.object({
|
|
8153
|
+
op: import_zod.z.literal("paint"),
|
|
8154
|
+
path: import_zod.z.string().describe(
|
|
8155
|
+
"Canvas-sized layer PNG (resolved against cwd), the drawing the part was built from."
|
|
8156
|
+
)
|
|
8157
|
+
}),
|
|
8158
|
+
import_zod.z.object({
|
|
8159
|
+
op: import_zod.z.enum(["land", "displacement"]),
|
|
8160
|
+
part: import_zod.z.string().describe("A part id of the model."),
|
|
8161
|
+
points: import_zod.z.array(import_zod.z.array(import_zod.z.number()).length(2)).describe(
|
|
8162
|
+
"Canvas-px points `[x, y]`, at most 5000, each on the part at rest."
|
|
8163
|
+
),
|
|
8164
|
+
pose: import_zod.z.record(import_zod.z.string(), import_zod.z.number()).optional().describe(
|
|
8165
|
+
"Parameter id to value; the others stay at their defaults."
|
|
8166
|
+
)
|
|
8167
|
+
})
|
|
8168
|
+
])
|
|
8169
|
+
).describe("The queries, answered in order; at most 64 per call."),
|
|
8170
|
+
outputPath: import_zod.z.string().optional().describe(
|
|
8171
|
+
"A path ending in `.probe.json` (resolved against cwd, under it; its folder must exist) to write the results to."
|
|
8172
|
+
)
|
|
8173
|
+
}
|
|
8174
|
+
},
|
|
8175
|
+
async (args) => {
|
|
8176
|
+
try {
|
|
8177
|
+
const r = await probeRig(args);
|
|
8178
|
+
const text = !r.ok ? `INVALID: ${r.error}` : "results" in r ? JSON.stringify(r.results) : [r.outputPath, ...r.lines].join("\n");
|
|
8179
|
+
return { content: [{ type: "text", text }], structuredContent: r };
|
|
8180
|
+
} catch (err) {
|
|
8181
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
8182
|
+
return {
|
|
8183
|
+
content: [{ type: "text", text: `Unexpected error: ${error}` }],
|
|
8184
|
+
structuredContent: { ok: false, error },
|
|
8185
|
+
isError: true
|
|
8186
|
+
};
|
|
8187
|
+
}
|
|
8188
|
+
}
|
|
8189
|
+
);
|
|
7044
8190
|
return server;
|
|
7045
8191
|
}
|
|
7046
8192
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7047
8193
|
0 && (module.exports = {
|
|
8194
|
+
CUSTOM_GATE_LIMITS,
|
|
7048
8195
|
SWEEP_PRESETS,
|
|
7049
8196
|
autoRigFromLayers,
|
|
8197
|
+
checkCustomGate,
|
|
7050
8198
|
checkModelFolds,
|
|
7051
8199
|
checkNod,
|
|
7052
8200
|
checkSweep,
|
|
@@ -7055,6 +8203,8 @@ function createIkiMcpServer() {
|
|
|
7055
8203
|
describeIki,
|
|
7056
8204
|
describeIkiAt,
|
|
7057
8205
|
describeRigPlan,
|
|
8206
|
+
failedCustomGate,
|
|
8207
|
+
formatCustomGate,
|
|
7058
8208
|
formatFoldReport,
|
|
7059
8209
|
formatHairSideReport,
|
|
7060
8210
|
formatMeasureReport,
|
|
@@ -7066,6 +8216,7 @@ function createIkiMcpServer() {
|
|
|
7066
8216
|
listStandardParameters,
|
|
7067
8217
|
measureLayers,
|
|
7068
8218
|
measureTurnReference,
|
|
8219
|
+
probeRig,
|
|
7069
8220
|
renderPoses,
|
|
7070
8221
|
validateIki
|
|
7071
8222
|
});
|