three-slicer-viewer 0.4.2 → 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.
Files changed (3) hide show
  1. package/dist/index.js +5039 -4925
  2. package/dist/toolpath.js +168 -159
  3. package/package.json +1 -1
package/dist/toolpath.js CHANGED
@@ -1,95 +1,95 @@
1
- import { a as R, b as Bt, p as lt, h as _t, T as wt, r as kt, D as Ot } from "./toolpath_palette-B8xEl-qa.js";
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 At, S as ct, R as ot, t as Tt } from "./toolpath_encoding-BuYs95qZ.js";
3
+ import { r as Lt, S as ft, R as ot, t as Tt } from "./toolpath_encoding-BuYs95qZ.js";
4
4
  import { T as Ut } from "./theme-BwyYoVl6.js";
5
- const ft = {};
6
- for (const t of Object.keys(R)) ft[t] = lt(R[t]);
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, l = n > 0 ? o - r : o;
11
- e[n] = l > 1e-6 ? l : jt;
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 ut = (t) => t?.paths?.length ? t.paths : null, Lt = (t) => {
16
- const e = ut(t);
17
- return e ? Math.floor(e.length / ct) : 0;
18
- }, xt = (t, e) => {
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
- }, Mt = (t, e) => {
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 = (a, h) => {
27
- e[a * 8 + 4 + 2] = xt(t, h), e[h * 8 + 2] = xt(t, a);
28
- }, l = (a, h) => n[a * 2] === n[h * 2] && zt(t, a * 8 + 4, h * 8) && Mt(t, a) > 0 && Mt(t, h) > 0;
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 a = 0; a < o; a++) {
31
- if (a + 1 < o && l(a, a + 1)) {
32
- r(a, a + 1);
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 < a && l(a, m) && r(a, m), m = a + 1;
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, l = Wt(n), m = new Uint32Array(o + 1), a = new Uint32Array(o + 1), h = new Uint32Array(o + 1);
40
- let p = 0, s = 0, d = 0;
41
- for (let u = 0; u < o; u++) {
42
- const v = ut(n[u]), g = Lt(n[u]);
43
- for (let M = 0; M < g; M++)
44
- At(v[M * ct + 3]) === ot.TRAVEL ? s++ : p++;
45
- d += g, m[u + 1] = p, a[u + 1] = s, h[u + 1] = d;
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 c = p * 2, L = new Float32Array(c * 4), S = new Float32Array(c * 4), W = new Uint32Array(c * 2), b = new Uint8Array(c), H = new Uint8Array(c), B = new Float32Array(c), _ = new Float32Array(c), E = new Int32Array(c), F = new Float32Array(s * 6), I = new Float32Array(d * 3), z = new Uint8Array(d), D = new Float64Array(16);
48
- let it = !1, K = 0, G = 1 / 0, Z = 1 / 0, N = 1 / 0, q = -1 / 0, k = -1 / 0, O = -1 / 0, x = 0, J = 0, st = 0, i = 0;
49
- for (let u = 0; u < o; u++) {
50
- const v = n[u], g = ut(v), M = Lt(v), V = v?.widths, X = l[u], tt = X / 2;
51
- for (let Y = 0; Y < M; Y++) {
52
- const w = Y * ct, $ = g[w], P = g[w + 1], y = g[w + 2], A = g[w + 4], j = g[w + 5], T = g[w + 6], mt = g[w + 3] | 0, et = At(mt), It = Tt(mt);
53
- if (Number.isFinite($ + P + y + A + j + T) || (it = !0), z[i] = et === ot.TRAVEL ? 0 : 1, I[i * 3] = A, I[i * 3 + 1] = j, I[i * 3 + 2] = T, i++, et === ot.TRAVEL) {
54
- const C = st * 6;
55
- F[C] = $, F[C + 1] = P, F[C + 2] = y, F[C + 3] = A, F[C + 4] = j, F[C + 5] = T, st++;
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 at = V ? Number(V[Y]) : NaN, dt = Number.isFinite(at) && at > 0 ? at : r, vt = A - $, yt = j - P, Nt = Math.atan2(yt, vt), pt = Math.hypot(vt, yt, T - y);
59
- Number.isFinite(pt) && (D[et] += pt);
60
- const Pt = ft[et] ?? ft[1];
61
- for (const [C, Q, bt] of [[$, P, y], [A, j, T]]) {
62
- const U = x * 4;
63
- L[U] = C, L[U + 1] = Q, L[U + 2] = bt - tt, L[U + 3] = 0, S[U] = X, S[U + 1] = dt, S[U + 2] = Nt, S[U + 3] = Pt, W[x * 2] = J, W[x * 2 + 1] = u, b[x] = et, H[x] = It, B[x] = dt, _[x] = X, E[x] = u, x++;
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 < G && (G = C), C > q && (q = C), Q < Z && (Z = Q), Q > k && (k = Q), nt < N && (N = nt), nt > O && (O = nt);
66
- const gt = Math.max(Math.abs(C), Math.abs(Q), Math.abs(nt));
67
- gt > K && (K = gt);
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
- J++;
69
+ X++;
70
70
  }
71
71
  }
72
- Dt(L, S, E, p);
73
- const f = c > 0 && Number.isFinite(G) ? { min: [G, Z, N], max: [q, k, O] } : null;
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: S,
77
- segIndex: W,
78
- nV: c,
76
+ hwa: F,
77
+ segIndex: z,
78
+ nV: f,
79
79
  nSeg: p,
80
80
  layerSegPrefix: m,
81
- travelPos: F,
82
- travelPrefix: a,
81
+ travelPos: S,
82
+ travelPrefix: l,
83
83
  nTrav: s,
84
- movePos: I,
85
- moveKind: z,
84
+ movePos: N,
85
+ moveKind: D,
86
86
  movePrefix: h,
87
87
  layerCount: o,
88
- maxAbs: K,
88
+ maxAbs: k,
89
89
  hasNaN: it,
90
- typeLengths: D,
91
- bbox: f,
92
- meta: { vType: b, vTool: H, vWidth: B, vHeight: _, vLayer: E }
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 l = Number(e[r]) || 0;
103
- l <= 0 || o.push({ type: r, label: Bt[r] ?? String(r), pct: l / n * 100, color: R[r] ?? R[1] });
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, l) => l.pct - r.pct);
105
+ return o.sort((r, u) => u.pct - r.pct);
106
106
  }
107
- const ht = (t, e) => e >= 0 && e < t.layerCount ? t.movePrefix[e + 1] - t.movePrefix[e] : 0;
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 ht(t, e);
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 (ht(t, r) > 0) return r;
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 = ht(t, e), r = Math.max(0, Math.min(Number(n) || 0, o)), l = e >= 0 && e < t.layerCount ? t.movePrefix[e] : 0;
118
- let m = 0, a = 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[l + p] === 0 ? a++ : m++;
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 = l + r - 1;
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: a,
126
+ travCount: l,
127
127
  onTravel: t.moveKind[h] === 0
128
128
  };
129
129
  }
130
- const Ct = [
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], l = e.vLayer[n], m = l === 0;
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 l < o.closeFanLayers ? 0 : r === 9 ? 100 : o.fanNormal;
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, l = new Float32Array(r * 4), m = Ct.find((s) => s.key === e) || Ct[0];
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((c) => c && _t(c)), d = m.key === "filament" ? (c) => {
163
- const L = o.vTool ? o.vTool[c] : 0;
164
- return s[L] || wt[L % wt.length];
165
- } : (c) => R[o.vType[c]] || R[1];
166
- for (let c = 0; c < r; c++) l[c * 4] = lt(d(c));
167
- return { color: l, min: 0, max: 0, viewType: e, label: m.label, unit: m.unit, cont: !1 };
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 a = 1 / 0, h = -1 / 0;
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 d = Xt(e, o, s, n), c = Number.isFinite(d) ? d : 0;
173
- p[s] = c, c < a && (a = c), c > h && (h = c);
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(a) || (a = 0, h = 1);
175
+ Number.isFinite(l) || (l = 0, h = 1);
176
176
  for (let s = 0; s < r; s++) {
177
- const d = kt(p[s], a, h, Ot);
178
- l[s * 4] = lt(d);
177
+ const v = kt(p[s], l, h, Ot);
178
+ u[s * 4] = ct(v);
179
179
  }
180
- return { color: l, min: a, max: h, viewType: e, label: m.label, unit: m.unit, cont: !0 };
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, St = (t) => Math.round((t + Math.PI) / (2 * Math.PI) * (rt - 1));
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 St(t) * rt + St(e);
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
- `, Ft = [2, 4], Qt = 1.5;
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 l = (s) => s <= o || (r - s) % n === 0;
291
+ const u = (s) => s <= o || (r - s) % n === 0;
292
292
  let m = 0;
293
- for (let s = 0; s < e; s++) l(t(s)) && m++;
294
- const a = new Uint32Array(m), h = new Uint8Array(m);
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 d = t(s);
298
- l(d) && (a[p] = s, h[p] = 1, d > o && (h[p] = Math.min(n, d - o)), p++);
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: a, layers: h };
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, l) => r - l), o[o.length >> 1]) : 0;
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 = Ft) {
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, l = 4 + e;
338
- t.push(n, o, r, n, r, l);
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: l, travelPos: m, travelPrefix: a, layerCount: h, meta: p } = e, s = new Float32Array(n * 3), d = new Float32Array(n * 3), c = new Float32Array(n * 2), L = new Float32Array(n), S = new Float32Array(n), W = new Float32Array(n);
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 f = i * 2 * 4, u = (i * 2 + 1) * 4;
346
- s[i * 3] = r[f], s[i * 3 + 1] = r[f + 1], s[i * 3 + 2] = r[f + 2], d[i * 3] = r[u], d[i * 3 + 1] = r[u + 1], d[i * 3 + 2] = r[u + 2], c[i * 2] = l[f], c[i * 2 + 1] = l[f + 1], L[i] = l[f + 3], S[i] = p.vLayer[i * 2], W[i] = Kt(l[f + 2], l[u + 2]);
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 b = new t.InstancedBufferGeometry();
349
- b.setAttribute("tpl", new t.BufferAttribute(ne, 2)), b.setIndex(oe), b.setAttribute("iStart", new t.InstancedBufferAttribute(s, 3)), b.setAttribute("iEnd", new t.InstancedBufferAttribute(d, 3)), b.setAttribute("iHW", new t.InstancedBufferAttribute(c, 2));
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
- b.setAttribute("iColor", H), b.setAttribute("iLayer", new t.InstancedBufferAttribute(S, 1)), b.setAttribute("iJoin", new t.InstancedBufferAttribute(W, 1)), b.instanceCount = n, b.boundingSphere = new t.Sphere(new t.Vector3(0, 0, 0), (e.maxAbs || 1) * 2);
352
- const B = new t.RawShaderMaterial({
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
- }), _ = new t.Mesh(b, B);
362
- _.frustumCulled = !1;
363
- const E = Rt(p.vType, p.vLayer), F = Ft.map((i) => {
364
- const { source: f, layers: u } = Ht((y) => S[y], n, i, E), v = f.length, g = new Float32Array(v * 3), M = new Float32Array(v * 3), V = new Float32Array(v * 2), X = new Float32Array(v), tt = new Float32Array(v), Y = new Float32Array(v);
365
- for (let y = 0; y < v; y++) {
366
- const A = f[y], j = c[A * 2], T = (u[y] - 1) * j / 2;
367
- g[y * 3] = s[A * 3], g[y * 3 + 1] = s[A * 3 + 1], g[y * 3 + 2] = s[A * 3 + 2] - T, M[y * 3] = d[A * 3], M[y * 3 + 1] = d[A * 3 + 1], M[y * 3 + 2] = d[A * 3 + 2] - T, V[y * 2] = j * u[y], V[y * 2 + 1] = c[A * 2 + 1], X[y] = L[A], tt[y] = S[A], Y[y] = W[A];
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", b.attributes.tpl), w.setIndex(b.index), w.setAttribute("iStart", new t.InstancedBufferAttribute(g, 3)), w.setAttribute("iEnd", new t.InstancedBufferAttribute(M, 3)), w.setAttribute("iHW", new t.InstancedBufferAttribute(V, 2));
371
- const $ = new t.InstancedBufferAttribute(X, 1);
372
- w.setAttribute("iColor", $), w.setAttribute("iLayer", new t.InstancedBufferAttribute(tt, 1)), w.setAttribute("iJoin", new t.InstancedBufferAttribute(Y, 1)), w.instanceCount = v;
373
- const P = new t.Mesh(w, B);
374
- return P.frustumCulled = !1, P.visible = !1, _.add(P), { k: i, mesh: P, source: f, colors: X, colorAttr: $ };
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 I = 1, z = !0;
377
- const D = (i) => {
378
- if (i !== I) {
379
- I = i;
380
- for (const f of F) f.mesh.visible = f.k === i;
381
- b.instanceCount = 0, i === 1 && (b.instanceCount = n);
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) => c[i * 2], n), K = e.bbox && new t.Box3(new t.Vector3(...e.bbox.min), new t.Vector3(...e.bbox.max)), G = new t.Box3(), Z = (i, f) => {
384
- if (!z || !K || !i?.isPerspectiveCamera) {
385
- D(1);
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
- G.copy(K).applyMatrix4(_.matrixWorld), D(ee(te(it, G.distanceToPoint(i.position), i.fov, f)));
397
+ J.copy(k).applyMatrix4(I.matrixWorld), G(ee(te(it, J.distanceToPoint(i.position), i.fov, c)));
389
398
  };
390
- _.userData.updateLod = Z;
391
- const N = new t.BufferGeometry();
392
- N.setAttribute("position", new t.BufferAttribute(m, 3));
393
- const q = new t.LineBasicMaterial({ color: Ut.travel, transparent: !0, opacity: 0.6 }), k = new t.LineSegments(N, q);
394
- k.visible = !1, k.frustumCulled = !1;
395
- let O = 0, x = Math.max(0, h - 1);
396
- const J = (i, f) => {
397
- const u = Math.max(0, h - 1), v = Math.max(0, Math.min(i | 0, u)), g = Math.max(v, Math.min(f | 0, u));
398
- O = v, x = g, I === 1 && (b.instanceCount = n), B.uniforms.uLayerLo.value = v, B.uniforms.uLayerHi.value = g, z = v === 0 && g === u, z || D(1);
399
- const M = a[v] * 2, V = a[g + 1] * 2;
400
- N.setDrawRange(M, Math.max(0, V - M));
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 J(0, h - 1), {
403
- mesh: _,
404
- travLines: k,
405
- setLayerRange: J,
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 J(O, x), null;
409
- const f = Gt(e, O, x), u = Jt(e, f, i);
410
- z = !1, D(1), b.instanceCount = e.layerSegPrefix[f] + u.segCount;
411
- const v = a[O] * 2;
412
- return N.setDrawRange(v, Math.max(0, (a[f] + u.travCount) * 2 - v)), { ...u, layer: f };
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) => J(0, (i | 0) - 1),
424
+ setVisibleLayers: (i) => X(0, (i | 0) - 1),
416
425
  setTravelVisible: (i) => {
417
- k.visible = !!i;
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 f = 0; f < n; f++) L[f] = i[f * 2 * 4];
432
+ for (let c = 0; c < n; c++) L[c] = i[c * 2 * 4];
424
433
  H.needsUpdate = !0;
425
- for (const f of F) {
426
- for (let u = 0; u < f.source.length; u++) f.colors[u] = L[f.source[u]];
427
- f.colorAttr.needsUpdate = !0;
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: () => I,
442
+ lodLevel: () => N,
434
443
  dispose: () => {
435
- for (const i of F) i.mesh.geometry.dispose();
436
- b.dispose(), B.dispose(), N.dispose(), q.dispose();
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
- wt as TOOL_COLOR,
453
+ At as TOOL_COLOR,
445
454
  R as TYPE_COLOR,
446
455
  Bt as TYPE_LABEL,
447
456
  oe as VERTEX_DATA,
448
- Ct as VIEW_TYPES,
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
- lt as packColor,
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.2",
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",