three-slicer-viewer 0.4.1 → 0.4.3
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/VIEWER.md +30 -4
- package/data/config-schema-lean.json +1 -1
- package/data/ui-tree-keys.json +1 -1
- package/dist/components.js +135 -118
- package/dist/index.js +6816 -5149
- package/dist/{model_loaders-kvOxEvFT.js → model_loaders-CuHlnAw6.js} +1 -1
- package/dist/model_loaders.js +2 -2
- package/dist/{parse_3mf-6PLUgcZp.js → parse_3mf-BCD9FIz5.js} +174 -173
- package/dist/parse_3mf.worker.js +1 -1
- package/dist/{sla_reconstruct-CRZ3TrI1.js → sla_reconstruct-MtrOJRWL.js} +1 -1
- package/dist/sla_reconstruct.worker.js +1 -1
- package/dist/sla_slice.worker.js +1 -1
- package/dist/{theme-2oyfMuvf.js → theme-BwyYoVl6.js} +15 -12
- package/dist/toolpath.js +169 -160
- package/package.json +1 -1
- package/src/settings/settings_core.js +4 -0
- package/types/settings-keys.d.ts +40 -40
- package/types/viewer.d.ts +10 -1
package/dist/parse_3mf.worker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as M, s as w, r as k, i as I, a as g, p as P, b as S } from "./parse_3mf-
|
|
1
|
+
import { c as M, s as w, r as k, i as I, a as g, p as P, b as S } from "./parse_3mf-BCD9FIz5.js";
|
|
2
2
|
function b(r) {
|
|
3
3
|
if (!r) return [];
|
|
4
4
|
const t = [r.tris.buffer, ...r.modifiers.map((a) => a.tris.buffer)];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as V, h as ht } from "./theme-
|
|
1
|
+
import { T as V, h as ht } from "./theme-BwyYoVl6.js";
|
|
2
2
|
import { R as at } from "./toolpath_encoding-BuYs95qZ.js";
|
|
3
3
|
const U = new Int8Array(8), q = new Int8Array(8), H = new Int8Array(8);
|
|
4
4
|
for (let t = 0; t < 8; t++)
|
package/dist/sla_slice.worker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const o = Object.freeze({
|
|
2
2
|
accent: "#00ae42",
|
|
3
3
|
// selection: the object, the selected plate, the scale handles, the box-select band
|
|
4
4
|
accentHover: "#1f5c34",
|
|
@@ -19,17 +19,19 @@ const t = Object.freeze({
|
|
|
19
19
|
slaModel: "#d7862a",
|
|
20
20
|
slaSupport: "#9b78d8",
|
|
21
21
|
slaPad: "#b0a06a",
|
|
22
|
+
negativePart: "#e23b3b",
|
|
23
|
+
// a negative part: what is cut away where it overlaps
|
|
22
24
|
inkOnLight: "#10141a",
|
|
23
25
|
// label text on a light swatch
|
|
24
26
|
inkOnDark: "#ffffff"
|
|
25
27
|
});
|
|
26
|
-
function
|
|
28
|
+
function b(r) {
|
|
27
29
|
const e = (a) => a <= 0.04045 ? a / 12.92 : ((a + 0.055) / 1.055) ** 2.4;
|
|
28
30
|
return [1, 3, 5].map((a) => e(parseInt(r.slice(a, a + 2), 16) / 255));
|
|
29
31
|
}
|
|
30
|
-
const
|
|
32
|
+
const i = Object.freeze({
|
|
31
33
|
// the brand green and its family
|
|
32
|
-
accent:
|
|
34
|
+
accent: o.accent,
|
|
33
35
|
accentHover: "#06c04d",
|
|
34
36
|
accentDeep: "#23402c",
|
|
35
37
|
// the busy pulse on a dark control
|
|
@@ -52,7 +54,7 @@ const c = Object.freeze({
|
|
|
52
54
|
darkText: "#cdd6dd",
|
|
53
55
|
darkTextMuted: "#aebcc6",
|
|
54
56
|
darkTextFaint: "#8b98a2",
|
|
55
|
-
darkTextDisabled:
|
|
57
|
+
darkTextDisabled: o.plateLabel,
|
|
56
58
|
// the light sidebar and the settings panel
|
|
57
59
|
lightBg: "#eef0f2",
|
|
58
60
|
lightSurface: "#ffffff",
|
|
@@ -84,14 +86,15 @@ const c = Object.freeze({
|
|
|
84
86
|
warnOnDark: "#f0c060",
|
|
85
87
|
warnDeep: "#3a2a10",
|
|
86
88
|
warnDeepBorder: "#7a5a1e"
|
|
87
|
-
}),
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
}), c = (r) => r.replace(/[A-Z]/g, (e) => "-" + e.toLowerCase()), f = ["accent", "darkBase", "darkSurface", "warnDeep"], d = (r) => [1, 3, 5].map((e) => parseInt(r.slice(e, e + 2), 16)).join(", "), l = (r, e) => `rgba(${d(r)}, ${e})`, t = ":is(.sidebar,.settings-panel) :where(select,textarea,input:not([type=checkbox],[type=color],[type=range],[type=radio]))", s = `${t}{box-sizing:border-box;height:26px;padding:0 6px;font:inherit;font-size:12.5px;color:var(--_light-text);background:var(--_light-surface);border:1px solid var(--_light-border);border-radius:5px;}${t}:focus-visible{outline:2px solid var(--_accent);outline-offset:-1px;}${t}:disabled{background:var(--_light-subtle);color:var(--_light-text-faint);}:is(.sidebar,.settings-panel) textarea{height:auto;padding:4px 6px;}:is(.sidebar,.settings-panel) input[type=checkbox]{width:15px;height:15px;margin:0;accent-color:var(--_accent);}:is(.sidebar,.settings-panel) input[type=color]{box-sizing:border-box;width:26px;height:26px;padding:1px;border:1px solid var(--_light-border);border-radius:5px;background:none;cursor:pointer;}
|
|
90
|
+
`, g = `:host{${Object.entries(i).map(([r, e]) => {
|
|
91
|
+
const a = c(r), n = `--_${a}:var(--vp-${a},${e});`;
|
|
92
|
+
return f.includes(r) ? n + `--_${a}-rgb:var(--vp-${a}-rgb,${d(e)});` : n;
|
|
90
93
|
}).join("")}}
|
|
91
|
-
`;
|
|
94
|
+
${s}`;
|
|
92
95
|
export {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
o as T,
|
|
97
|
+
g as a,
|
|
98
|
+
b as h,
|
|
96
99
|
l as w
|
|
97
100
|
};
|
package/dist/toolpath.js
CHANGED
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
import { a as R, b as Bt, p as
|
|
1
|
+
import { a as R, b as Bt, p as ct, h as _t, T as At, r as kt, D as Ot } from "./toolpath_palette-B8xEl-qa.js";
|
|
2
2
|
import { b as Vt, a as jt } from "./viewer_defaults-B7UUZ582.js";
|
|
3
|
-
import { r as
|
|
4
|
-
import { T as Ut } from "./theme-
|
|
5
|
-
const
|
|
6
|
-
for (const t of Object.keys(R))
|
|
3
|
+
import { r as Lt, S as ft, R as ot, t as Tt } from "./toolpath_encoding-BuYs95qZ.js";
|
|
4
|
+
import { T as Ut } from "./theme-BwyYoVl6.js";
|
|
5
|
+
const ut = {};
|
|
6
|
+
for (const t of Object.keys(R)) ut[t] = ct(R[t]);
|
|
7
7
|
function Wt(t) {
|
|
8
8
|
const e = new Float32Array(t.length);
|
|
9
9
|
for (let n = 0; n < t.length; n++) {
|
|
10
|
-
const o = Number(t[n]?.z) || 0, r = n > 0 && Number(t[n - 1]?.z) || 0,
|
|
11
|
-
e[n] =
|
|
10
|
+
const o = Number(t[n]?.z) || 0, r = n > 0 && Number(t[n - 1]?.z) || 0, u = n > 0 ? o - r : o;
|
|
11
|
+
e[n] = u > 1e-6 ? u : jt;
|
|
12
12
|
}
|
|
13
13
|
return e;
|
|
14
14
|
}
|
|
15
|
-
const
|
|
16
|
-
const e =
|
|
17
|
-
return e ? Math.floor(e.length /
|
|
18
|
-
},
|
|
15
|
+
const ht = (t) => t?.paths?.length ? t.paths : null, xt = (t) => {
|
|
16
|
+
const e = ht(t);
|
|
17
|
+
return e ? Math.floor(e.length / ft) : 0;
|
|
18
|
+
}, Mt = (t, e) => {
|
|
19
19
|
const n = e * 8, o = n + 4;
|
|
20
20
|
return Math.atan2(t[o + 1] - t[n + 1], t[o] - t[n]);
|
|
21
|
-
},
|
|
21
|
+
}, Ct = (t, e) => {
|
|
22
22
|
const n = e * 8, o = n + 4;
|
|
23
23
|
return Math.hypot(t[o] - t[n], t[o + 1] - t[n + 1]);
|
|
24
24
|
}, zt = (t, e, n) => t[e] === t[n] && t[e + 1] === t[n + 1] && t[e + 2] === t[n + 2];
|
|
25
25
|
function Dt(t, e, n, o) {
|
|
26
|
-
const r = (
|
|
27
|
-
e[
|
|
28
|
-
},
|
|
26
|
+
const r = (l, h) => {
|
|
27
|
+
e[l * 8 + 4 + 2] = Mt(t, h), e[h * 8 + 2] = Mt(t, l);
|
|
28
|
+
}, u = (l, h) => n[l * 2] === n[h * 2] && zt(t, l * 8 + 4, h * 8) && Ct(t, l) > 0 && Ct(t, h) > 0;
|
|
29
29
|
let m = 0;
|
|
30
|
-
for (let
|
|
31
|
-
if (
|
|
32
|
-
r(
|
|
30
|
+
for (let l = 0; l < o; l++) {
|
|
31
|
+
if (l + 1 < o && u(l, l + 1)) {
|
|
32
|
+
r(l, l + 1);
|
|
33
33
|
continue;
|
|
34
34
|
}
|
|
35
|
-
m <
|
|
35
|
+
m < l && u(l, m) && r(l, m), m = l + 1;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
function le(t, e) {
|
|
39
|
-
const n = Array.isArray(t) ? t : [], o = n.length, r = Number(e) > 0 ? Number(e) : Vt,
|
|
40
|
-
let p = 0, s = 0,
|
|
41
|
-
for (let
|
|
42
|
-
const
|
|
43
|
-
for (let M = 0; M <
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
const n = Array.isArray(t) ? t : [], o = n.length, r = Number(e) > 0 ? Number(e) : Vt, u = Wt(n), m = new Uint32Array(o + 1), l = new Uint32Array(o + 1), h = new Uint32Array(o + 1);
|
|
40
|
+
let p = 0, s = 0, v = 0;
|
|
41
|
+
for (let a = 0; a < o; a++) {
|
|
42
|
+
const d = ht(n[a]), b = xt(n[a]);
|
|
43
|
+
for (let M = 0; M < b; M++)
|
|
44
|
+
Lt(d[M * ft + 3]) === ot.TRAVEL ? s++ : p++;
|
|
45
|
+
v += b, m[a + 1] = p, l[a + 1] = s, h[a + 1] = v;
|
|
46
46
|
}
|
|
47
|
-
const
|
|
48
|
-
let it = !1,
|
|
49
|
-
for (let
|
|
50
|
-
const
|
|
51
|
-
for (let
|
|
52
|
-
const w =
|
|
53
|
-
if (Number.isFinite(
|
|
54
|
-
const C =
|
|
55
|
-
|
|
47
|
+
const f = p * 2, L = new Float32Array(f * 4), F = new Float32Array(f * 4), z = new Uint32Array(f * 2), g = new Uint8Array(f), H = new Uint8Array(f), _ = new Float32Array(f), I = new Float32Array(f), E = new Int32Array(f), S = new Float32Array(s * 6), N = new Float32Array(v * 3), D = new Uint8Array(v), G = new Float64Array(16);
|
|
48
|
+
let it = !1, k = 0, J = 1 / 0, Z = 1 / 0, P = 1 / 0, q = -1 / 0, O = -1 / 0, V = -1 / 0, x = 0, X = 0, at = 0, i = 0;
|
|
49
|
+
for (let a = 0; a < o; a++) {
|
|
50
|
+
const d = n[a], b = ht(d), M = xt(d), j = d?.widths, Y = u[a], tt = Y / 2;
|
|
51
|
+
for (let $ = 0; $ < M; $++) {
|
|
52
|
+
const w = $ * ft, K = b[w], B = b[w + 1], y = b[w + 2], A = b[w + 4], T = b[w + 5], U = b[w + 6], dt = b[w + 3] | 0, et = Lt(dt), It = Tt(dt);
|
|
53
|
+
if (Number.isFinite(K + B + y + A + T + U) || (it = !0), D[i] = et === ot.TRAVEL ? 0 : 1, N[i * 3] = A, N[i * 3 + 1] = T, N[i * 3 + 2] = U, i++, et === ot.TRAVEL) {
|
|
54
|
+
const C = at * 6;
|
|
55
|
+
S[C] = K, S[C + 1] = B, S[C + 2] = y, S[C + 3] = A, S[C + 4] = T, S[C + 5] = U, at++;
|
|
56
56
|
continue;
|
|
57
57
|
}
|
|
58
|
-
const
|
|
59
|
-
Number.isFinite(
|
|
60
|
-
const Pt =
|
|
61
|
-
for (const [C, Q, bt] of [[
|
|
62
|
-
const
|
|
63
|
-
L[
|
|
58
|
+
const lt = j ? Number(j[$]) : NaN, vt = Number.isFinite(lt) && lt > 0 ? lt : r, yt = A - K, pt = T - B, Nt = Math.atan2(pt, yt), gt = Math.hypot(yt, pt, U - y);
|
|
59
|
+
Number.isFinite(gt) && (G[et] += gt);
|
|
60
|
+
const Pt = ut[et] ?? ut[1];
|
|
61
|
+
for (const [C, Q, bt] of [[K, B, y], [A, T, U]]) {
|
|
62
|
+
const W = x * 4;
|
|
63
|
+
L[W] = C, L[W + 1] = Q, L[W + 2] = bt - tt, L[W + 3] = 0, F[W] = Y, F[W + 1] = vt, F[W + 2] = Nt, F[W + 3] = Pt, z[x * 2] = X, z[x * 2 + 1] = a, g[x] = et, H[x] = It, _[x] = vt, I[x] = Y, E[x] = a, x++;
|
|
64
64
|
const nt = bt - tt;
|
|
65
|
-
C <
|
|
66
|
-
const
|
|
67
|
-
|
|
65
|
+
C < J && (J = C), C > q && (q = C), Q < Z && (Z = Q), Q > O && (O = Q), nt < P && (P = nt), nt > V && (V = nt);
|
|
66
|
+
const wt = Math.max(Math.abs(C), Math.abs(Q), Math.abs(nt));
|
|
67
|
+
wt > k && (k = wt);
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
X++;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
Dt(L,
|
|
73
|
-
const
|
|
72
|
+
Dt(L, F, E, p);
|
|
73
|
+
const c = f > 0 && Number.isFinite(J) ? { min: [J, Z, P], max: [q, O, V] } : null;
|
|
74
74
|
return {
|
|
75
75
|
position: L,
|
|
76
|
-
hwa:
|
|
77
|
-
segIndex:
|
|
78
|
-
nV:
|
|
76
|
+
hwa: F,
|
|
77
|
+
segIndex: z,
|
|
78
|
+
nV: f,
|
|
79
79
|
nSeg: p,
|
|
80
80
|
layerSegPrefix: m,
|
|
81
|
-
travelPos:
|
|
82
|
-
travelPrefix:
|
|
81
|
+
travelPos: S,
|
|
82
|
+
travelPrefix: l,
|
|
83
83
|
nTrav: s,
|
|
84
|
-
movePos:
|
|
85
|
-
moveKind:
|
|
84
|
+
movePos: N,
|
|
85
|
+
moveKind: D,
|
|
86
86
|
movePrefix: h,
|
|
87
87
|
layerCount: o,
|
|
88
|
-
maxAbs:
|
|
88
|
+
maxAbs: k,
|
|
89
89
|
hasNaN: it,
|
|
90
|
-
typeLengths:
|
|
91
|
-
bbox:
|
|
92
|
-
meta: { vType:
|
|
90
|
+
typeLengths: G,
|
|
91
|
+
bbox: c,
|
|
92
|
+
meta: { vType: g, vTool: H, vWidth: _, vHeight: I, vLayer: E }
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
95
|
function ce(t) {
|
|
@@ -99,35 +99,35 @@ function ce(t) {
|
|
|
99
99
|
if (n <= 0) return [];
|
|
100
100
|
const o = [];
|
|
101
101
|
for (let r = 0; r < 16; r++) {
|
|
102
|
-
const
|
|
103
|
-
|
|
102
|
+
const u = Number(e[r]) || 0;
|
|
103
|
+
u <= 0 || o.push({ type: r, label: Bt[r] ?? String(r), pct: u / n * 100, color: R[r] ?? R[1] });
|
|
104
104
|
}
|
|
105
|
-
return o.sort((r,
|
|
105
|
+
return o.sort((r, u) => u.pct - r.pct);
|
|
106
106
|
}
|
|
107
|
-
const
|
|
107
|
+
const mt = (t, e) => e >= 0 && e < t.layerCount ? t.movePrefix[e + 1] - t.movePrefix[e] : 0;
|
|
108
108
|
function fe(t, e) {
|
|
109
|
-
return
|
|
109
|
+
return mt(t, e);
|
|
110
110
|
}
|
|
111
111
|
function Gt(t, e, n) {
|
|
112
112
|
const o = Math.min(n, t.layerCount - 1);
|
|
113
|
-
for (let r = o; r >= e; r--) if (
|
|
113
|
+
for (let r = o; r >= e; r--) if (mt(t, r) > 0) return r;
|
|
114
114
|
return e;
|
|
115
115
|
}
|
|
116
116
|
function Jt(t, e, n) {
|
|
117
|
-
const o =
|
|
118
|
-
let m = 0,
|
|
117
|
+
const o = mt(t, e), r = Math.max(0, Math.min(Number(n) || 0, o)), u = e >= 0 && e < t.layerCount ? t.movePrefix[e] : 0;
|
|
118
|
+
let m = 0, l = 0;
|
|
119
119
|
for (let p = 0; p < r; p++)
|
|
120
|
-
t.moveKind[
|
|
120
|
+
t.moveKind[u + p] === 0 ? l++ : m++;
|
|
121
121
|
if (r === 0) return { point: null, segCount: 0, travCount: 0, onTravel: !1 };
|
|
122
|
-
const h =
|
|
122
|
+
const h = u + r - 1;
|
|
123
123
|
return {
|
|
124
124
|
point: [t.movePos[h * 3], t.movePos[h * 3 + 1], t.movePos[h * 3 + 2]],
|
|
125
125
|
segCount: m,
|
|
126
|
-
travCount:
|
|
126
|
+
travCount: l,
|
|
127
127
|
onTravel: t.moveKind[h] === 0
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
|
-
const
|
|
130
|
+
const St = [
|
|
131
131
|
{ key: "feature", label: "Feature type", cont: !1, unit: "" },
|
|
132
132
|
{ key: "speed", label: "Speed", cont: !0, unit: "mm/s" },
|
|
133
133
|
{ key: "height", label: "Layer Height", cont: !0, unit: "mm" },
|
|
@@ -140,7 +140,7 @@ const Ct = [
|
|
|
140
140
|
{ key: "filament", label: "Filament", cont: !1, unit: "" }
|
|
141
141
|
];
|
|
142
142
|
function Xt(t, e, n, o) {
|
|
143
|
-
const r = e.vType[n],
|
|
143
|
+
const r = e.vType[n], u = e.vLayer[n], m = u === 0;
|
|
144
144
|
switch (t) {
|
|
145
145
|
case "height":
|
|
146
146
|
return e.vHeight[n];
|
|
@@ -149,7 +149,7 @@ function Xt(t, e, n, o) {
|
|
|
149
149
|
case "speed":
|
|
150
150
|
return m ? o.firstLayerSpeed : o.speedByType[r] ?? o.speedByType[1];
|
|
151
151
|
case "fan":
|
|
152
|
-
return
|
|
152
|
+
return u < o.closeFanLayers ? 0 : r === 9 ? 100 : o.fanNormal;
|
|
153
153
|
case "temp":
|
|
154
154
|
return m ? o.tempFirst : o.tempNormal;
|
|
155
155
|
default:
|
|
@@ -157,31 +157,31 @@ function Xt(t, e, n, o) {
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
function ue(t, e, n) {
|
|
160
|
-
const { meta: o, nV: r } = t,
|
|
160
|
+
const { meta: o, nV: r } = t, u = new Float32Array(r * 4), m = St.find((s) => s.key === e) || St[0];
|
|
161
161
|
if (!m.cont) {
|
|
162
|
-
const s = (n?.toolColors ?? []).map((
|
|
163
|
-
const L = o.vTool ? o.vTool[
|
|
164
|
-
return s[L] ||
|
|
165
|
-
} : (
|
|
166
|
-
for (let
|
|
167
|
-
return { color:
|
|
162
|
+
const s = (n?.toolColors ?? []).map((f) => f && _t(f)), v = m.key === "filament" ? (f) => {
|
|
163
|
+
const L = o.vTool ? o.vTool[f] : 0;
|
|
164
|
+
return s[L] || At[L % At.length];
|
|
165
|
+
} : (f) => R[o.vType[f]] || R[1];
|
|
166
|
+
for (let f = 0; f < r; f++) u[f * 4] = ct(v(f));
|
|
167
|
+
return { color: u, min: 0, max: 0, viewType: e, label: m.label, unit: m.unit, cont: !1 };
|
|
168
168
|
}
|
|
169
|
-
let
|
|
169
|
+
let l = 1 / 0, h = -1 / 0;
|
|
170
170
|
const p = new Float32Array(r);
|
|
171
171
|
for (let s = 0; s < r; s++) {
|
|
172
|
-
const
|
|
173
|
-
p[s] =
|
|
172
|
+
const v = Xt(e, o, s, n), f = Number.isFinite(v) ? v : 0;
|
|
173
|
+
p[s] = f, f < l && (l = f), f > h && (h = f);
|
|
174
174
|
}
|
|
175
|
-
Number.isFinite(
|
|
175
|
+
Number.isFinite(l) || (l = 0, h = 1);
|
|
176
176
|
for (let s = 0; s < r; s++) {
|
|
177
|
-
const
|
|
178
|
-
|
|
177
|
+
const v = kt(p[s], l, h, Ot);
|
|
178
|
+
u[s * 4] = ct(v);
|
|
179
179
|
}
|
|
180
|
-
return { color:
|
|
180
|
+
return { color: u, min: l, max: h, viewType: e, label: m.label, unit: m.unit, cont: !0 };
|
|
181
181
|
}
|
|
182
|
-
const rt = 4096, Yt = 140 * Math.PI / 180, $t = 45 * Math.PI / 180,
|
|
182
|
+
const rt = 4096, Yt = 140 * Math.PI / 180, $t = 45 * Math.PI / 180, Ft = (t) => Math.round((t + Math.PI) / (2 * Math.PI) * (rt - 1));
|
|
183
183
|
function Kt(t, e) {
|
|
184
|
-
return
|
|
184
|
+
return Ft(t) * rt + Ft(e);
|
|
185
185
|
}
|
|
186
186
|
const Zt = `
|
|
187
187
|
precision highp float;
|
|
@@ -278,7 +278,7 @@ void main() {
|
|
|
278
278
|
float lambert = max(dot(n, normalize(vec3(0.35, 0.35, 1.0))), 0.0);
|
|
279
279
|
fragColor = vec4(vColor * (0.55 + 0.45 * lambert), 1.0);
|
|
280
280
|
}
|
|
281
|
-
`,
|
|
281
|
+
`, st = [2, 4], Qt = 1.5;
|
|
282
282
|
function Rt(t, e) {
|
|
283
283
|
let n = 0;
|
|
284
284
|
for (let o = 0; o < t.length; o += 2)
|
|
@@ -288,26 +288,26 @@ function Rt(t, e) {
|
|
|
288
288
|
function Ht(t, e, n, o) {
|
|
289
289
|
let r = 0;
|
|
290
290
|
for (let s = 0; s < e; s++) t(s) > r && (r = t(s));
|
|
291
|
-
const
|
|
291
|
+
const u = (s) => s <= o || (r - s) % n === 0;
|
|
292
292
|
let m = 0;
|
|
293
|
-
for (let s = 0; s < e; s++)
|
|
294
|
-
const
|
|
293
|
+
for (let s = 0; s < e; s++) u(t(s)) && m++;
|
|
294
|
+
const l = new Uint32Array(m), h = new Uint8Array(m);
|
|
295
295
|
let p = 0;
|
|
296
296
|
for (let s = 0; s < e; s++) {
|
|
297
|
-
const
|
|
298
|
-
|
|
297
|
+
const v = t(s);
|
|
298
|
+
u(v) && (l[p] = s, h[p] = 1, v > o && (h[p] = Math.min(n, v - o)), p++);
|
|
299
299
|
}
|
|
300
|
-
return { source:
|
|
300
|
+
return { source: l, layers: h };
|
|
301
301
|
}
|
|
302
302
|
function Et(t, e) {
|
|
303
303
|
const n = Math.max(1, Math.floor(e / 4096)), o = [];
|
|
304
304
|
for (let r = 0; r < e; r += n) o.push(t(r));
|
|
305
|
-
return o.length ? (o.sort((r,
|
|
305
|
+
return o.length ? (o.sort((r, u) => r - u), o[o.length >> 1]) : 0;
|
|
306
306
|
}
|
|
307
307
|
function te(t, e, n, o) {
|
|
308
308
|
return e > 0 ? t * (o / 2) / (e * Math.tan(n * Math.PI / 360)) : 1 / 0;
|
|
309
309
|
}
|
|
310
|
-
function ee(t, e =
|
|
310
|
+
function ee(t, e = st) {
|
|
311
311
|
let n = 1;
|
|
312
312
|
for (const o of e) o * t <= Qt && o > n && (n = o);
|
|
313
313
|
return n;
|
|
@@ -334,22 +334,22 @@ const ne = new Float32Array([
|
|
|
334
334
|
]), oe = (() => {
|
|
335
335
|
const t = [];
|
|
336
336
|
for (let e = 0; e < 4; e++) {
|
|
337
|
-
const n = e, o = (e + 1) % 4, r = 4 + (e + 1) % 4,
|
|
338
|
-
t.push(n, o, r, n, r,
|
|
337
|
+
const n = e, o = (e + 1) % 4, r = 4 + (e + 1) % 4, u = 4 + e;
|
|
338
|
+
t.push(n, o, r, n, r, u);
|
|
339
339
|
}
|
|
340
340
|
return t;
|
|
341
341
|
})();
|
|
342
342
|
function he(t, e) {
|
|
343
|
-
const { nSeg: n, nV: o, position: r, hwa:
|
|
343
|
+
const { nSeg: n, nV: o, position: r, hwa: u, travelPos: m, travelPrefix: l, layerCount: h, meta: p } = e, s = new Float32Array(n * 3), v = new Float32Array(n * 3), f = new Float32Array(n * 2), L = new Float32Array(n), F = new Float32Array(n), z = new Float32Array(n);
|
|
344
344
|
for (let i = 0; i < n; i++) {
|
|
345
|
-
const
|
|
346
|
-
s[i * 3] = r[
|
|
345
|
+
const c = i * 2 * 4, a = (i * 2 + 1) * 4;
|
|
346
|
+
s[i * 3] = r[c], s[i * 3 + 1] = r[c + 1], s[i * 3 + 2] = r[c + 2], v[i * 3] = r[a], v[i * 3 + 1] = r[a + 1], v[i * 3 + 2] = r[a + 2], f[i * 2] = u[c], f[i * 2 + 1] = u[c + 1], L[i] = u[c + 3], F[i] = p.vLayer[i * 2], z[i] = Kt(u[c + 2], u[a + 2]);
|
|
347
347
|
}
|
|
348
|
-
const
|
|
349
|
-
|
|
348
|
+
const g = new t.InstancedBufferGeometry();
|
|
349
|
+
g.setAttribute("tpl", new t.BufferAttribute(ne, 2)), g.setIndex(oe), g.setAttribute("iStart", new t.InstancedBufferAttribute(s, 3)), g.setAttribute("iEnd", new t.InstancedBufferAttribute(v, 3)), g.setAttribute("iHW", new t.InstancedBufferAttribute(f, 2));
|
|
350
350
|
const H = new t.InstancedBufferAttribute(L, 1);
|
|
351
|
-
|
|
352
|
-
const
|
|
351
|
+
g.setAttribute("iColor", H), g.setAttribute("iLayer", new t.InstancedBufferAttribute(F, 1)), g.setAttribute("iJoin", new t.InstancedBufferAttribute(z, 1)), g.instanceCount = n, g.boundingSphere = new t.Sphere(new t.Vector3(0, 0, 0), (e.maxAbs || 1) * 2);
|
|
352
|
+
const _ = new t.RawShaderMaterial({
|
|
353
353
|
vertexShader: Zt,
|
|
354
354
|
fragmentShader: qt,
|
|
355
355
|
glslVersion: t.GLSL3,
|
|
@@ -358,82 +358,91 @@ function he(t, e) {
|
|
|
358
358
|
// 14.6M-segment scene (6 plates, M5 Pro, DPR 2), 53.6 -> 29.4 ms with back faces culled.
|
|
359
359
|
side: t.FrontSide,
|
|
360
360
|
uniforms: { uLayerLo: { value: 0 }, uLayerHi: { value: Math.max(0, h - 1) } }
|
|
361
|
-
}),
|
|
362
|
-
|
|
363
|
-
const E = Rt(p.vType, p.vLayer),
|
|
364
|
-
const { source:
|
|
365
|
-
for (let y = 0; y <
|
|
366
|
-
const A =
|
|
367
|
-
|
|
361
|
+
}), I = new t.Mesh(g, _);
|
|
362
|
+
I.frustumCulled = !1;
|
|
363
|
+
const E = Rt(p.vType, p.vLayer), S = st.map((i) => {
|
|
364
|
+
const { source: c, layers: a } = Ht((y) => F[y], n, i, E), d = c.length, b = new Float32Array(d * 3), M = new Float32Array(d * 3), j = new Float32Array(d * 2), Y = new Float32Array(d), tt = new Float32Array(d), $ = new Float32Array(d);
|
|
365
|
+
for (let y = 0; y < d; y++) {
|
|
366
|
+
const A = c[y], T = f[A * 2], U = (a[y] - 1) * T / 2;
|
|
367
|
+
b[y * 3] = s[A * 3], b[y * 3 + 1] = s[A * 3 + 1], b[y * 3 + 2] = s[A * 3 + 2] - U, M[y * 3] = v[A * 3], M[y * 3 + 1] = v[A * 3 + 1], M[y * 3 + 2] = v[A * 3 + 2] - U, j[y * 2] = T * a[y], j[y * 2 + 1] = f[A * 2 + 1], Y[y] = L[A], tt[y] = F[A], $[y] = z[A];
|
|
368
368
|
}
|
|
369
369
|
const w = new t.InstancedBufferGeometry();
|
|
370
|
-
w.setAttribute("tpl",
|
|
371
|
-
const
|
|
372
|
-
w.setAttribute("iColor",
|
|
373
|
-
const
|
|
374
|
-
return
|
|
370
|
+
w.setAttribute("tpl", g.attributes.tpl), w.setIndex(g.index), w.setAttribute("iStart", new t.InstancedBufferAttribute(b, 3)), w.setAttribute("iEnd", new t.InstancedBufferAttribute(M, 3)), w.setAttribute("iHW", new t.InstancedBufferAttribute(j, 2));
|
|
371
|
+
const K = new t.InstancedBufferAttribute(Y, 1);
|
|
372
|
+
w.setAttribute("iColor", K), w.setAttribute("iLayer", new t.InstancedBufferAttribute(tt, 1)), w.setAttribute("iJoin", new t.InstancedBufferAttribute($, 1)), w.instanceCount = d;
|
|
373
|
+
const B = new t.Mesh(w, _);
|
|
374
|
+
return B.frustumCulled = !1, B.visible = !1, I.add(B), { k: i, mesh: B, source: c, colors: Y, colorAttr: K };
|
|
375
375
|
});
|
|
376
|
-
let
|
|
377
|
-
const
|
|
378
|
-
if (i !==
|
|
379
|
-
|
|
380
|
-
for (const
|
|
381
|
-
|
|
376
|
+
let N = 1, D = !0;
|
|
377
|
+
const G = (i) => {
|
|
378
|
+
if (i !== N) {
|
|
379
|
+
N = i;
|
|
380
|
+
for (const c of S) c.mesh.visible = c.k === i;
|
|
381
|
+
g.instanceCount = 0, i === 1 && (g.instanceCount = n);
|
|
382
382
|
}
|
|
383
|
-
}, it = Et((i) =>
|
|
384
|
-
|
|
385
|
-
|
|
383
|
+
}, it = Et((i) => f[i * 2], n), k = e.bbox && new t.Box3(new t.Vector3(...e.bbox.min), new t.Vector3(...e.bbox.max));
|
|
384
|
+
if (k) {
|
|
385
|
+
const i = k.getBoundingSphere(new t.Sphere());
|
|
386
|
+
let c = 0;
|
|
387
|
+
for (let a = 0; a < n; a++) c = Math.max(c, f[a * 2], f[a * 2 + 1]);
|
|
388
|
+
i.radius += c * st[st.length - 1];
|
|
389
|
+
for (const a of [I, ...S.map((d) => d.mesh)])
|
|
390
|
+
a.geometry.boundingSphere = i, a.frustumCulled = !0;
|
|
391
|
+
}
|
|
392
|
+
const J = new t.Box3(), Z = (i, c) => {
|
|
393
|
+
if (!D || !k || !i?.isPerspectiveCamera) {
|
|
394
|
+
G(1);
|
|
386
395
|
return;
|
|
387
396
|
}
|
|
388
|
-
|
|
397
|
+
J.copy(k).applyMatrix4(I.matrixWorld), G(ee(te(it, J.distanceToPoint(i.position), i.fov, c)));
|
|
389
398
|
};
|
|
390
|
-
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
const q = new t.LineBasicMaterial({ color: Ut.travel, transparent: !0, opacity: 0.6 }),
|
|
394
|
-
|
|
395
|
-
let
|
|
396
|
-
const
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
const M =
|
|
400
|
-
|
|
399
|
+
I.userData.updateLod = Z;
|
|
400
|
+
const P = new t.BufferGeometry();
|
|
401
|
+
P.setAttribute("position", new t.BufferAttribute(m, 3));
|
|
402
|
+
const q = new t.LineBasicMaterial({ color: Ut.travel, transparent: !0, opacity: 0.6 }), O = new t.LineSegments(P, q);
|
|
403
|
+
O.visible = !1, O.frustumCulled = !1;
|
|
404
|
+
let V = 0, x = Math.max(0, h - 1);
|
|
405
|
+
const X = (i, c) => {
|
|
406
|
+
const a = Math.max(0, h - 1), d = Math.max(0, Math.min(i | 0, a)), b = Math.max(d, Math.min(c | 0, a));
|
|
407
|
+
V = d, x = b, N === 1 && (g.instanceCount = n), _.uniforms.uLayerLo.value = d, _.uniforms.uLayerHi.value = b, D = d === 0 && b === a, D || G(1);
|
|
408
|
+
const M = l[d] * 2, j = l[b + 1] * 2;
|
|
409
|
+
P.setDrawRange(M, Math.max(0, j - M));
|
|
401
410
|
};
|
|
402
|
-
return
|
|
403
|
-
mesh:
|
|
404
|
-
travLines:
|
|
405
|
-
setLayerRange:
|
|
411
|
+
return X(0, h - 1), {
|
|
412
|
+
mesh: I,
|
|
413
|
+
travLines: O,
|
|
414
|
+
setLayerRange: X,
|
|
406
415
|
setMoveRange: (i) => {
|
|
407
416
|
if (i == null)
|
|
408
|
-
return
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
const
|
|
412
|
-
return
|
|
417
|
+
return X(V, x), null;
|
|
418
|
+
const c = Gt(e, V, x), a = Jt(e, c, i);
|
|
419
|
+
D = !1, G(1), g.instanceCount = e.layerSegPrefix[c] + a.segCount;
|
|
420
|
+
const d = l[V] * 2;
|
|
421
|
+
return P.setDrawRange(d, Math.max(0, (l[c] + a.travCount) * 2 - d)), { ...a, layer: c };
|
|
413
422
|
},
|
|
414
423
|
data: e,
|
|
415
|
-
setVisibleLayers: (i) =>
|
|
424
|
+
setVisibleLayers: (i) => X(0, (i | 0) - 1),
|
|
416
425
|
setTravelVisible: (i) => {
|
|
417
|
-
|
|
426
|
+
O.visible = !!i;
|
|
418
427
|
},
|
|
419
428
|
/** color is Float32Array(nV*4) with the packed value in .r — computeColors' output shape. One instance
|
|
420
429
|
* takes the colour of its first vertex; the two agree, since a segment is one colour. */
|
|
421
430
|
setColors: (i) => {
|
|
422
431
|
if (!(!i || i.length < o * 4)) {
|
|
423
|
-
for (let
|
|
432
|
+
for (let c = 0; c < n; c++) L[c] = i[c * 2 * 4];
|
|
424
433
|
H.needsUpdate = !0;
|
|
425
|
-
for (const
|
|
426
|
-
for (let
|
|
427
|
-
|
|
434
|
+
for (const c of S) {
|
|
435
|
+
for (let a = 0; a < c.source.length; a++) c.colors[a] = L[c.source[a]];
|
|
436
|
+
c.colorAttr.needsUpdate = !0;
|
|
428
437
|
}
|
|
429
438
|
}
|
|
430
439
|
},
|
|
431
440
|
/** Call once per frame before rendering; viewportPixels is the drawing buffer's height. */
|
|
432
441
|
updateLod: Z,
|
|
433
|
-
lodLevel: () =>
|
|
442
|
+
lodLevel: () => N,
|
|
434
443
|
dispose: () => {
|
|
435
|
-
for (const i of
|
|
436
|
-
|
|
444
|
+
for (const i of S) i.mesh.geometry.dispose();
|
|
445
|
+
g.dispose(), _.dispose(), P.dispose(), q.dispose();
|
|
437
446
|
},
|
|
438
447
|
nSeg: n,
|
|
439
448
|
layerCount: h
|
|
@@ -441,18 +450,18 @@ function he(t, e) {
|
|
|
441
450
|
}
|
|
442
451
|
export {
|
|
443
452
|
Ot as DEFAULT_RANGES_COLORS,
|
|
444
|
-
|
|
453
|
+
At as TOOL_COLOR,
|
|
445
454
|
R as TYPE_COLOR,
|
|
446
455
|
Bt as TYPE_LABEL,
|
|
447
456
|
oe as VERTEX_DATA,
|
|
448
|
-
|
|
457
|
+
St as VIEW_TYPES,
|
|
449
458
|
le as buildSegmentData,
|
|
450
459
|
ue as computeColors,
|
|
451
460
|
_t as hexToRgb,
|
|
452
461
|
fe as layerMoveCount,
|
|
453
462
|
he as makeToolpath,
|
|
454
463
|
Jt as moveCursor,
|
|
455
|
-
|
|
464
|
+
ct as packColor,
|
|
456
465
|
kt as rangeColorAt,
|
|
457
466
|
ce as roleRatios,
|
|
458
467
|
Gt as topMoveLayer
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "three-slicer-viewer",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "The three-slicer viewer without the slicer — model loading, G-code parsing, GPU toolpath rendering and the settings transforms, under MIT. Plug a slicer in through the `slicer` prop.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -573,7 +573,11 @@ export function deriveKernelParams(settings, opts) {
|
|
|
573
573
|
})
|
|
574
574
|
}
|
|
575
575
|
|
|
576
|
+
const bands = settings?.variable_layer_heights
|
|
577
|
+
const layerBands = {}
|
|
578
|
+
if (Array.isArray(bands) && bands.length) layerBands.variable_layer_heights = bands
|
|
576
579
|
return {
|
|
580
|
+
...layerBands,
|
|
577
581
|
...widths,
|
|
578
582
|
...machine,
|
|
579
583
|
...passthrough, // present only for keys the settings map actually holds (see PASSTHROUGH_* above)
|