@ikijs/editor 0.23.0 → 0.24.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/dist/index.d.mts +36 -20
- package/dist/index.d.ts +36 -20
- package/dist/index.js +73 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1761,7 +1761,10 @@ function captureBindingEndpoint(channel, restValue, posedValue) {
|
|
|
1761
1761
|
// src/atlas.ts
|
|
1762
1762
|
var ATLAS_PADDING = 2;
|
|
1763
1763
|
var UV_INSET_PX = 0.5;
|
|
1764
|
-
function packAtlas(sources, padding = ATLAS_PADDING) {
|
|
1764
|
+
function packAtlas(sources, padding = ATLAS_PADDING, maxSide) {
|
|
1765
|
+
if (maxSide !== void 0 && !(isFinite(maxSide) && maxSide > 0)) {
|
|
1766
|
+
throw new Error(`packAtlas: invalid maxSide ${maxSide}`);
|
|
1767
|
+
}
|
|
1765
1768
|
for (const src of sources) {
|
|
1766
1769
|
if (!isFinite(src.width) || src.width <= 0) {
|
|
1767
1770
|
throw new Error(
|
|
@@ -1782,42 +1785,50 @@ function packAtlas(sources, padding = ATLAS_PADDING) {
|
|
|
1782
1785
|
(sum, s) => sum + (s.width + padding) * (s.height + padding),
|
|
1783
1786
|
0
|
|
1784
1787
|
);
|
|
1785
|
-
const
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1788
|
+
const widest = Math.max(...sorted.map((s) => s.width + padding));
|
|
1789
|
+
const firstWidth = Math.max(Math.ceil(Math.sqrt(totalArea)), widest);
|
|
1790
|
+
const shelve = (targetWidth) => {
|
|
1791
|
+
const placements = [];
|
|
1792
|
+
let shelfX = 0;
|
|
1793
|
+
let shelfY = 0;
|
|
1794
|
+
let shelfHeight = 0;
|
|
1795
|
+
for (const src of sorted) {
|
|
1796
|
+
const paddedW = src.width + padding;
|
|
1797
|
+
const paddedH = src.height + padding;
|
|
1798
|
+
if (shelfX > 0 && shelfX + paddedW > targetWidth) {
|
|
1799
|
+
shelfY += shelfHeight;
|
|
1800
|
+
shelfX = 0;
|
|
1801
|
+
shelfHeight = 0;
|
|
1802
|
+
}
|
|
1803
|
+
placements.push({
|
|
1804
|
+
id: src.id,
|
|
1805
|
+
x: shelfX,
|
|
1806
|
+
y: shelfY,
|
|
1807
|
+
width: src.width,
|
|
1808
|
+
height: src.height
|
|
1809
|
+
});
|
|
1810
|
+
shelfX += paddedW;
|
|
1811
|
+
if (paddedH > shelfHeight) shelfHeight = paddedH;
|
|
1812
|
+
}
|
|
1813
|
+
let pageWidth = 0;
|
|
1814
|
+
let pageHeight = 0;
|
|
1815
|
+
for (const p of placements) {
|
|
1816
|
+
const right = p.x + p.width + padding;
|
|
1817
|
+
const bottom = p.y + p.height + padding;
|
|
1818
|
+
if (right > pageWidth) pageWidth = right;
|
|
1819
|
+
if (bottom > pageHeight) pageHeight = bottom;
|
|
1820
|
+
}
|
|
1821
|
+
return { pageWidth, pageHeight, placements };
|
|
1822
|
+
};
|
|
1823
|
+
const first = shelve(firstWidth);
|
|
1824
|
+
if (maxSide === void 0 || first.pageHeight <= maxSide || first.pageWidth > maxSide) {
|
|
1825
|
+
return { ...first, padding };
|
|
1811
1826
|
}
|
|
1812
|
-
let
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
const right = p.x + p.width + padding;
|
|
1816
|
-
const bottom = p.y + p.height + padding;
|
|
1817
|
-
if (right > pageWidth) pageWidth = right;
|
|
1818
|
-
if (bottom > pageHeight) pageHeight = bottom;
|
|
1827
|
+
for (let w = widest; w <= maxSide; w++) {
|
|
1828
|
+
const layout = shelve(w);
|
|
1829
|
+
if (layout.pageHeight <= maxSide) return { ...layout, padding };
|
|
1819
1830
|
}
|
|
1820
|
-
return {
|
|
1831
|
+
return { ...first, padding };
|
|
1821
1832
|
}
|
|
1822
1833
|
function uvRectFor(placement, page, insetPx = UV_INSET_PX) {
|
|
1823
1834
|
const px = placement.x + insetPx;
|
|
@@ -2926,14 +2937,14 @@ function armParts(role, layer, g, order, poseSwitch) {
|
|
|
2926
2937
|
},
|
|
2927
2938
|
true
|
|
2928
2939
|
),
|
|
2929
|
-
part(role, ids.armDeformer, order + 1, meshOf(band(0.5, seam), quad)),
|
|
2930
2940
|
part(
|
|
2931
2941
|
ids.forearm,
|
|
2932
2942
|
ids.forearmDeformer,
|
|
2933
|
-
order +
|
|
2943
|
+
order + 1,
|
|
2934
2944
|
meshOf(band(seam, -0.5), quad),
|
|
2935
2945
|
true
|
|
2936
|
-
)
|
|
2946
|
+
),
|
|
2947
|
+
part(role, ids.armDeformer, order + 2, meshOf(band(0.5, seam), quad))
|
|
2937
2948
|
];
|
|
2938
2949
|
}
|
|
2939
2950
|
var rotateBinding = (parameter, range, sign) => ({
|
|
@@ -3031,8 +3042,8 @@ var isLipInsideRole = (role) => LIP_INSIDE_ROLES.includes(role);
|
|
|
3031
3042
|
var ROLE_TABLE = [
|
|
3032
3043
|
{ role: "hair_back", family: "hair_back" },
|
|
3033
3044
|
{ role: "body", family: "body" },
|
|
3034
|
-
{ role: "arm_L", family: "arm", parts: ["elbow_L", "
|
|
3035
|
-
{ role: "arm_R", family: "arm", parts: ["elbow_R", "
|
|
3045
|
+
{ role: "arm_L", family: "arm", parts: ["elbow_L", "forearm_L", "arm_L"] },
|
|
3046
|
+
{ role: "arm_R", family: "arm", parts: ["elbow_R", "forearm_R", "arm_R"] },
|
|
3036
3047
|
{ role: "face", family: "face", required: true },
|
|
3037
3048
|
{ role: "blush_L", family: "face" },
|
|
3038
3049
|
{ role: "blush_R", family: "face" },
|
|
@@ -3177,6 +3188,7 @@ function parseLayerRoles(fileNames) {
|
|
|
3177
3188
|
|
|
3178
3189
|
// src/auto-rig/mouth.ts
|
|
3179
3190
|
var UPPER_SHARE = 0.4;
|
|
3191
|
+
var CLOSED_SAG_MAX = 0.1;
|
|
3180
3192
|
var UPPER_THIN = 0.7;
|
|
3181
3193
|
var END_TAPER = 0.35;
|
|
3182
3194
|
var END_TAPER_FROM = 0.7;
|
|
@@ -3243,10 +3255,15 @@ function mouthOpening(byRole) {
|
|
|
3243
3255
|
for (let d = 0; (r = read(c - d) ?? read(c + d)) === void 0; d++) ;
|
|
3244
3256
|
reads.push(r);
|
|
3245
3257
|
}
|
|
3258
|
+
const n = reads.length;
|
|
3246
3259
|
const m = (x0 + x1) / 2;
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3260
|
+
const centre = Math.round(m);
|
|
3261
|
+
const smooth = reads.map((_, i) => {
|
|
3262
|
+
const near = reads.slice(Math.max(0, i - 3), i + 4);
|
|
3263
|
+
return near.reduce((s, r) => s + r.Tu, 0) / near.length;
|
|
3264
|
+
});
|
|
3265
|
+
let sag = 0;
|
|
3266
|
+
if (n >= 4) {
|
|
3250
3267
|
let s11 = 0;
|
|
3251
3268
|
let s12 = 0;
|
|
3252
3269
|
let s22 = 0;
|
|
@@ -3264,16 +3281,24 @@ function mouthOpening(byRole) {
|
|
|
3264
3281
|
t2 += b2 * d;
|
|
3265
3282
|
});
|
|
3266
3283
|
const det = s11 * s22 - s12 * s12;
|
|
3267
|
-
p = (t1 * s22 - t2 * s12) / det;
|
|
3268
|
-
q = (s11 * t2 - s12 * t1) / det;
|
|
3284
|
+
const p = (t1 * s22 - t2 * s12) / det;
|
|
3285
|
+
const q = (s11 * t2 - s12 * t1) / det;
|
|
3286
|
+
const c = centre - x0;
|
|
3287
|
+
const D = c * (centre - x1) * (p + q * (centre - m));
|
|
3288
|
+
const arc = (reads[0].Tu + reads[n - 1].Tu) / 2 - reads[c].Tu;
|
|
3289
|
+
const t = c / (n - 1);
|
|
3290
|
+
const k = 4 * t * (1 - t);
|
|
3291
|
+
const offset = arc - (smooth[0] + (smooth[n - 1] - smooth[0]) * t - smooth[c]);
|
|
3292
|
+
sag = Math.min(arc - D, CLOSED_SAG_MAX * n - Math.max(0, offset) / k);
|
|
3269
3293
|
}
|
|
3270
3294
|
const columns = reads.map((r, i) => {
|
|
3271
|
-
|
|
3272
|
-
|
|
3295
|
+
if (n < 4) return { ...r, seam: r.Tu };
|
|
3296
|
+
const t = i / (x1 - x0);
|
|
3297
|
+
const parabola = smooth[0] + (smooth[n - 1] - smooth[0]) * t - sag * 4 * t * (1 - t);
|
|
3298
|
+
return { ...r, seam: r.Tu + parabola - smooth[i] };
|
|
3273
3299
|
});
|
|
3274
3300
|
const clamp2 = (col) => Math.min(x1, Math.max(x0, col));
|
|
3275
3301
|
const base = (col) => columns[clamp2(col) - x0];
|
|
3276
|
-
const centre = Math.round((x0 + x1) / 2);
|
|
3277
3302
|
const w = base(centre).lineH;
|
|
3278
3303
|
const from = END_TAPER_FROM * ((x1 - x0 + 1) / 2);
|
|
3279
3304
|
const squash = (col) => {
|