three-slicer-viewer 0.3.3 → 0.3.4

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/toolpath.js CHANGED
@@ -1,113 +1,133 @@
1
- import { a as Z, b as It, p as at, h as St, T as wt, r as Nt, D as Pt } from "./toolpath_palette-B8xEl-qa.js";
2
- import { b as Bt, a as Vt } from "./viewer_defaults-B7UUZ582.js";
3
- import { r as At, S as lt, R as et, t as _t } from "./toolpath_encoding-BuYs95qZ.js";
4
- import { T as kt } from "./theme-2oyfMuvf.js";
5
- const ct = {};
6
- for (const t of Object.keys(Z)) ct[t] = at(Z[t]);
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";
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";
4
+ import { T as Ut } from "./theme-2oyfMuvf.js";
5
+ const ft = {};
6
+ for (const t of Object.keys(R)) ft[t] = lt(R[t]);
7
7
  function Wt(t) {
8
8
  const e = new Float32Array(t.length);
9
- for (let o = 0; o < t.length; o++) {
10
- const n = Number(t[o]?.z) || 0, r = o > 0 && Number(t[o - 1]?.z) || 0, c = o > 0 ? n - r : n;
11
- e[o] = c > 1e-6 ? c : Vt;
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;
12
12
  }
13
13
  return e;
14
14
  }
15
- const ft = (t) => t?.paths?.length ? t.paths : null, gt = (t) => {
16
- const e = ft(t);
17
- return e ? Math.floor(e.length / lt) : 0;
18
- };
19
- function Ht(t, e) {
20
- const o = Array.isArray(t) ? t : [], n = o.length, r = Number(e) > 0 ? Number(e) : Bt, c = Wt(o), h = new Uint32Array(n + 1), d = new Uint32Array(n + 1), u = new Uint32Array(n + 1);
21
- let m = 0, s = 0, f = 0;
22
- for (let p = 0; p < n; p++) {
23
- const P = ft(o[p]), C = gt(o[p]);
24
- for (let A = 0; A < C; A++)
25
- At(P[A * lt + 3]) === et.TRAVEL ? s++ : m++;
26
- f += C, h[p + 1] = m, d[p + 1] = s, u[p + 1] = f;
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) => {
19
+ const n = e * 8, o = n + 4;
20
+ return Math.atan2(t[o + 1] - t[n + 1], t[o] - t[n]);
21
+ }, Mt = (t, e) => {
22
+ const n = e * 8, o = n + 4;
23
+ return Math.hypot(t[o] - t[n], t[o + 1] - t[n + 1]);
24
+ }, zt = (t, e, n) => t[e] === t[n] && t[e + 1] === t[n + 1] && t[e + 2] === t[n + 2];
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;
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);
33
+ continue;
34
+ }
35
+ m < a && l(a, m) && r(a, m), m = a + 1;
27
36
  }
28
- const l = m * 2, L = new Float32Array(l * 4), I = new Float32Array(l * 4), v = new Uint32Array(l * 2), q = new Uint8Array(l), B = new Uint8Array(l), V = new Float32Array(l), ot = new Float32Array(l), T = new Int32Array(l), F = new Float32Array(s * 6), _ = new Float32Array(f * 3), j = new Uint8Array(f), nt = new Float64Array(16);
29
- let J = !1, Y = 0, z = 1 / 0, k = 1 / 0, X = 1 / 0, W = -1 / 0, D = -1 / 0, i = -1 / 0, a = 0, b = 0, w = 0, x = 0;
30
- for (let p = 0; p < n; p++) {
31
- const P = o[p], C = ft(P), A = gt(P), Q = P?.widths, O = c[p], y = O / 2;
32
- for (let g = 0; g < A; g++) {
33
- const S = g * lt, G = C[S], rt = C[S + 1], it = C[S + 2], $ = C[S + 4], H = C[S + 5], R = C[S + 6], ht = C[S + 3] | 0, E = At(ht), Ct = _t(ht);
34
- if (Number.isFinite(G + rt + it + $ + H + R) || (J = !0), j[x] = E === et.TRAVEL ? 0 : 1, _[x * 3] = $, _[x * 3 + 1] = H, _[x * 3 + 2] = R, x++, E === et.TRAVEL) {
35
- const M = w * 6;
36
- F[M] = G, F[M + 1] = rt, F[M + 2] = it, F[M + 3] = $, F[M + 4] = H, F[M + 5] = R, w++;
37
+ }
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;
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++;
37
56
  continue;
38
57
  }
39
- const st = Q ? Number(Q[g]) : NaN, mt = Number.isFinite(st) && st > 0 ? st : r, pt = $ - G, yt = H - rt, Mt = Math.atan2(yt, pt), vt = Math.hypot(pt, yt, R - it);
40
- Number.isFinite(vt) && (nt[E] += vt);
41
- const Ft = ct[E] ?? ct[1];
42
- for (const [M, K, dt] of [[G, rt, it], [$, H, R]]) {
43
- const U = a * 4;
44
- L[U] = M, L[U + 1] = K, L[U + 2] = dt - y, L[U + 3] = 0, I[U] = O, I[U + 1] = mt, I[U + 2] = Mt, I[U + 3] = Ft, v[a * 2] = b, v[a * 2 + 1] = p, q[a] = E, B[a] = Ct, V[a] = mt, ot[a] = O, T[a] = p, a++;
45
- const tt = dt - y;
46
- M < z && (z = M), M > W && (W = M), K < k && (k = K), K > D && (D = K), tt < X && (X = tt), tt > i && (i = tt);
47
- const bt = Math.max(Math.abs(M), Math.abs(K), Math.abs(tt));
48
- bt > Y && (Y = bt);
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++;
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);
49
68
  }
50
- b++;
69
+ J++;
51
70
  }
52
71
  }
53
- const N = l > 0 && Number.isFinite(z) ? { min: [z, k, X], max: [W, D, i] } : null;
72
+ Dt(L, S, E, p);
73
+ const f = c > 0 && Number.isFinite(G) ? { min: [G, Z, N], max: [q, k, O] } : null;
54
74
  return {
55
75
  position: L,
56
- hwa: I,
57
- segIndex: v,
58
- nV: l,
59
- nSeg: m,
60
- layerSegPrefix: h,
76
+ hwa: S,
77
+ segIndex: W,
78
+ nV: c,
79
+ nSeg: p,
80
+ layerSegPrefix: m,
61
81
  travelPos: F,
62
- travelPrefix: d,
82
+ travelPrefix: a,
63
83
  nTrav: s,
64
- movePos: _,
65
- moveKind: j,
66
- movePrefix: u,
67
- layerCount: n,
68
- maxAbs: Y,
69
- hasNaN: J,
70
- typeLengths: nt,
71
- bbox: N,
72
- meta: { vType: q, vTool: B, vWidth: V, vHeight: ot, vLayer: T }
84
+ movePos: I,
85
+ moveKind: z,
86
+ movePrefix: h,
87
+ layerCount: o,
88
+ maxAbs: K,
89
+ hasNaN: it,
90
+ typeLengths: D,
91
+ bbox: f,
92
+ meta: { vType: b, vTool: H, vWidth: B, vHeight: _, vLayer: E }
73
93
  };
74
94
  }
75
- function Rt(t) {
95
+ function ce(t) {
76
96
  const e = t ?? [];
77
- let o = 0;
78
- for (let r = 0; r < 16; r++) o += Number(e[r]) || 0;
79
- if (o <= 0) return [];
80
- const n = [];
97
+ let n = 0;
98
+ for (let r = 0; r < 16; r++) n += Number(e[r]) || 0;
99
+ if (n <= 0) return [];
100
+ const o = [];
81
101
  for (let r = 0; r < 16; r++) {
82
- const c = Number(e[r]) || 0;
83
- c <= 0 || n.push({ type: r, label: It[r] ?? String(r), pct: c / o * 100, color: Z[r] ?? Z[1] });
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] });
84
104
  }
85
- return n.sort((r, c) => c.pct - r.pct);
105
+ return o.sort((r, l) => l.pct - r.pct);
86
106
  }
87
- const ut = (t, e) => e >= 0 && e < t.layerCount ? t.movePrefix[e + 1] - t.movePrefix[e] : 0;
88
- function Et(t, e) {
89
- return ut(t, e);
107
+ const ht = (t, e) => e >= 0 && e < t.layerCount ? t.movePrefix[e + 1] - t.movePrefix[e] : 0;
108
+ function fe(t, e) {
109
+ return ht(t, e);
90
110
  }
91
- function te(t, e, o) {
92
- const n = Math.min(o, t.layerCount - 1);
93
- for (let r = n; r >= e; r--) if (ut(t, r) > 0) return r;
111
+ function Gt(t, e, n) {
112
+ const o = Math.min(n, t.layerCount - 1);
113
+ for (let r = o; r >= e; r--) if (ht(t, r) > 0) return r;
94
114
  return e;
95
115
  }
96
- function ee(t, e, o) {
97
- const n = ut(t, e), r = Math.max(0, Math.min(Number(o) || 0, n)), c = e >= 0 && e < t.layerCount ? t.movePrefix[e] : 0;
98
- let h = 0, d = 0;
99
- for (let m = 0; m < r; m++)
100
- t.moveKind[c + m] === 0 ? d++ : h++;
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;
119
+ for (let p = 0; p < r; p++)
120
+ t.moveKind[l + p] === 0 ? a++ : m++;
101
121
  if (r === 0) return { point: null, segCount: 0, travCount: 0, onTravel: !1 };
102
- const u = c + r - 1;
122
+ const h = l + r - 1;
103
123
  return {
104
- point: [t.movePos[u * 3], t.movePos[u * 3 + 1], t.movePos[u * 3 + 2]],
105
- segCount: h,
106
- travCount: d,
107
- onTravel: t.moveKind[u] === 0
124
+ point: [t.movePos[h * 3], t.movePos[h * 3 + 1], t.movePos[h * 3 + 2]],
125
+ segCount: m,
126
+ travCount: a,
127
+ onTravel: t.moveKind[h] === 0
108
128
  };
109
129
  }
110
- const Lt = [
130
+ const Ct = [
111
131
  { key: "feature", label: "Feature type", cont: !1, unit: "" },
112
132
  { key: "speed", label: "Speed", cont: !0, unit: "mm/s" },
113
133
  { key: "height", label: "Layer Height", cont: !0, unit: "mm" },
@@ -119,47 +139,51 @@ const Lt = [
119
139
  // extruder index is a label, and a heatmap over it would imply tool 2 sits "between" tools 1 and 3.
120
140
  { key: "filament", label: "Filament", cont: !1, unit: "" }
121
141
  ];
122
- function Ot(t, e, o, n) {
123
- const r = e.vType[o], c = e.vLayer[o], h = c === 0;
142
+ function Xt(t, e, n, o) {
143
+ const r = e.vType[n], l = e.vLayer[n], m = l === 0;
124
144
  switch (t) {
125
145
  case "height":
126
- return e.vHeight[o];
146
+ return e.vHeight[n];
127
147
  case "width":
128
- return e.vWidth[o];
148
+ return e.vWidth[n];
129
149
  case "speed":
130
- return h ? n.firstLayerSpeed : n.speedByType[r] ?? n.speedByType[1];
150
+ return m ? o.firstLayerSpeed : o.speedByType[r] ?? o.speedByType[1];
131
151
  case "fan":
132
- return c < n.closeFanLayers ? 0 : r === 9 ? 100 : n.fanNormal;
152
+ return l < o.closeFanLayers ? 0 : r === 9 ? 100 : o.fanNormal;
133
153
  case "temp":
134
- return h ? n.tempFirst : n.tempNormal;
154
+ return m ? o.tempFirst : o.tempNormal;
135
155
  default:
136
156
  return 0;
137
157
  }
138
158
  }
139
- function oe(t, e, o) {
140
- const { meta: n, nV: r } = t, c = new Float32Array(r * 4), h = Lt.find((s) => s.key === e) || Lt[0];
141
- if (!h.cont) {
142
- const s = (o?.toolColors ?? []).map((l) => l && St(l)), f = h.key === "filament" ? (l) => {
143
- const L = n.vTool ? n.vTool[l] : 0;
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];
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;
144
164
  return s[L] || wt[L % wt.length];
145
- } : (l) => Z[n.vType[l]] || Z[1];
146
- for (let l = 0; l < r; l++) c[l * 4] = at(f(l));
147
- return { color: c, min: 0, max: 0, viewType: e, label: h.label, unit: h.unit, cont: !1 };
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 };
148
168
  }
149
- let d = 1 / 0, u = -1 / 0;
150
- const m = new Float32Array(r);
169
+ let a = 1 / 0, h = -1 / 0;
170
+ const p = new Float32Array(r);
151
171
  for (let s = 0; s < r; s++) {
152
- const f = Ot(e, n, s, o), l = Number.isFinite(f) ? f : 0;
153
- m[s] = l, l < d && (d = l), l > u && (u = l);
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);
154
174
  }
155
- Number.isFinite(d) || (d = 0, u = 1);
175
+ Number.isFinite(a) || (a = 0, h = 1);
156
176
  for (let s = 0; s < r; s++) {
157
- const f = Nt(m[s], d, u, Pt);
158
- c[s * 4] = at(f);
177
+ const d = kt(p[s], a, h, Ot);
178
+ l[s * 4] = lt(d);
159
179
  }
160
- return { color: c, min: d, max: u, viewType: e, label: h.label, unit: h.unit, cont: !0 };
180
+ return { color: l, min: a, max: h, viewType: e, label: m.label, unit: m.unit, cont: !0 };
161
181
  }
162
- const Ut = `
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));
183
+ function Kt(t, e) {
184
+ return St(t) * rt + St(e);
185
+ }
186
+ const Zt = `
163
187
  precision highp float;
164
188
 
165
189
  uniform mat4 projectionMatrix;
@@ -173,6 +197,7 @@ in vec3 iEnd;
173
197
  in vec2 iHW; // [height, width]
174
198
  in float iColor; // r<<16 | g<<8 | b
175
199
  in float iLayer;
200
+ in float iJoin; // packJoin(start heading, end heading)
176
201
 
177
202
  out vec3 vColor;
178
203
  out vec3 vNormal;
@@ -199,8 +224,26 @@ void main() {
199
224
  vec3 axis = iEnd - iStart;
200
225
  // A zero-length segment has no direction to orient against; pick one rather than emitting NaN.
201
226
  vec2 flat2 = axis.xy;
202
- vec2 dir = length(flat2) > 1e-9 ? normalize(flat2) : vec2(1.0, 0.0);
203
- vec3 side = vec3(-dir.y, dir.x, 0.0);
227
+ vec2 dir = vec2(1.0, 0.0);
228
+ if (length(flat2) > 1e-9) dir = normalize(flat2);
229
+ vec2 ownSide = vec2(-dir.y, dir.x);
230
+
231
+ float joinStart = floor(iJoin / ${rt}.0);
232
+ float joined = joinStart;
233
+ if (tpl.x > 0.5) joined = iJoin - joinStart * ${rt}.0;
234
+ joined = joined * (6.283185307179586 / ${rt - 1}.0) - 3.141592653589793;
235
+ vec2 bisector = dir + vec2(cos(joined), sin(joined));
236
+ vec2 side2 = ownSide;
237
+ vec2 facing2 = ownSide;
238
+ if (length(bisector) > 1e-6) {
239
+ vec2 tangent = normalize(bisector);
240
+ vec2 miterSide = vec2(-tangent.y, tangent.x);
241
+ float halfTurnCos = dot(miterSide, ownSide);
242
+ if (halfTurnCos > ${Math.cos(Yt / 2)}) side2 = miterSide / halfTurnCos;
243
+ if (halfTurnCos > ${Math.cos($t / 2)}) facing2 = miterSide;
244
+ }
245
+ vec3 side = vec3(side2, 0.0);
246
+ vec3 facing = vec3(facing2, 0.0);
204
247
  vec3 up = vec3(0.0, 0.0, 1.0);
205
248
 
206
249
  float halfHeight = iHW.x * 0.5;
@@ -208,18 +251,19 @@ void main() {
208
251
 
209
252
  float ring = tpl.y;
210
253
  vec3 offset;
211
- if (ring < 0.5) offset = side * halfWidth;
212
- else if (ring < 1.5) offset = up * halfHeight;
213
- else if (ring < 2.5) offset = -side * halfWidth;
214
- else offset = -up * halfHeight;
254
+ vec3 normal;
255
+ if (ring < 0.5) { offset = side * halfWidth; normal = facing; }
256
+ else if (ring < 1.5) { offset = up * halfHeight; normal = up; }
257
+ else if (ring < 2.5) { offset = -side * halfWidth; normal = -facing; }
258
+ else { offset = -up * halfHeight; normal = -up; }
215
259
 
216
260
  vec3 world = mix(iStart, iEnd, tpl.x) + offset;
217
261
 
218
- vNormal = normalize(mat3(modelViewMatrix) * normalize(offset));
262
+ vNormal = normalize(mat3(modelViewMatrix) * normal);
219
263
  vColor = unpackColor(iColor);
220
264
  gl_Position = projectionMatrix * modelViewMatrix * vec4(world, 1.0);
221
265
  }
222
- `, zt = `
266
+ `, qt = `
223
267
  precision highp float;
224
268
 
225
269
  in vec3 vColor;
@@ -234,41 +278,41 @@ void main() {
234
278
  float lambert = max(dot(n, normalize(vec3(0.35, 0.35, 1.0))), 0.0);
235
279
  fragColor = vec4(vColor * (0.55 + 0.45 * lambert), 1.0);
236
280
  }
237
- `, xt = [2, 4], Dt = 1.5;
238
- function Gt(t, e) {
239
- let o = 0;
240
- for (let n = 0; n < t.length; n += 2)
241
- (t[n] === et.RAFT || t[n] === et.SKIRT) && e[n] > o && (o = e[n]);
242
- return o;
281
+ `, Ft = [2, 4], Qt = 1.5;
282
+ function Rt(t, e) {
283
+ let n = 0;
284
+ for (let o = 0; o < t.length; o += 2)
285
+ (t[o] === ot.RAFT || t[o] === ot.SKIRT) && e[o] > n && (n = e[o]);
286
+ return n;
243
287
  }
244
- function Tt(t, e, o, n) {
288
+ function Ht(t, e, n, o) {
245
289
  let r = 0;
246
290
  for (let s = 0; s < e; s++) t(s) > r && (r = t(s));
247
- const c = (s) => s <= n || (r - s) % o === 0;
248
- let h = 0;
249
- for (let s = 0; s < e; s++) c(t(s)) && h++;
250
- const d = new Uint32Array(h), u = new Uint8Array(h);
291
+ const l = (s) => s <= o || (r - s) % n === 0;
251
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);
295
+ let p = 0;
252
296
  for (let s = 0; s < e; s++) {
253
- const f = t(s);
254
- c(f) && (d[m] = s, u[m] = 1, f > n && (u[m] = Math.min(o, f - n)), m++);
297
+ const d = t(s);
298
+ l(d) && (a[p] = s, h[p] = 1, d > o && (h[p] = Math.min(n, d - o)), p++);
255
299
  }
256
- return { source: d, layers: u };
300
+ return { source: a, layers: h };
257
301
  }
258
- function jt(t, e) {
259
- const o = Math.max(1, Math.floor(e / 4096)), n = [];
260
- for (let r = 0; r < e; r += o) n.push(t(r));
261
- return n.length ? (n.sort((r, c) => r - c), n[n.length >> 1]) : 0;
302
+ function Et(t, e) {
303
+ const n = Math.max(1, Math.floor(e / 4096)), o = [];
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;
262
306
  }
263
- function Yt(t, e, o, n) {
264
- return e > 0 ? t * (n / 2) / (e * Math.tan(o * Math.PI / 360)) : 1 / 0;
307
+ function te(t, e, n, o) {
308
+ return e > 0 ? t * (o / 2) / (e * Math.tan(n * Math.PI / 360)) : 1 / 0;
265
309
  }
266
- function Xt(t, e = xt) {
267
- let o = 1;
268
- for (const n of e) n * t <= Dt && n > o && (o = n);
269
- return o;
310
+ function ee(t, e = Ft) {
311
+ let n = 1;
312
+ for (const o of e) o * t <= Qt && o > n && (n = o);
313
+ return n;
270
314
  }
271
- const Kt = new Float32Array([
315
+ const ne = new Float32Array([
272
316
  0,
273
317
  0,
274
318
  0,
@@ -287,119 +331,129 @@ const Kt = new Float32Array([
287
331
  1,
288
332
  3
289
333
  // end ring
290
- ]), Zt = (() => {
334
+ ]), oe = (() => {
291
335
  const t = [];
292
336
  for (let e = 0; e < 4; e++) {
293
- const o = e, n = (e + 1) % 4, r = 4 + (e + 1) % 4, c = 4 + e;
294
- t.push(o, n, r, o, r, c);
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);
295
339
  }
296
340
  return t;
297
341
  })();
298
- function ne(t, e) {
299
- const { nSeg: o, nV: n, position: r, hwa: c, travelPos: h, travelPrefix: d, layerCount: u, meta: m } = e, s = new Float32Array(o * 3), f = new Float32Array(o * 3), l = new Float32Array(o * 2), L = new Float32Array(o), I = new Float32Array(o);
300
- for (let i = 0; i < o; i++) {
301
- const a = i * 2 * 4, b = (i * 2 + 1) * 4;
302
- s[i * 3] = r[a], s[i * 3 + 1] = r[a + 1], s[i * 3 + 2] = r[a + 2], f[i * 3] = r[b], f[i * 3 + 1] = r[b + 1], f[i * 3 + 2] = r[b + 2], l[i * 2] = c[a], l[i * 2 + 1] = c[a + 1], L[i] = c[a + 3], I[i] = m.vLayer[i * 2];
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);
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]);
303
347
  }
304
- const v = new t.InstancedBufferGeometry();
305
- v.setAttribute("tpl", new t.BufferAttribute(Kt, 2)), v.setIndex(Zt), v.setAttribute("iStart", new t.InstancedBufferAttribute(s, 3)), v.setAttribute("iEnd", new t.InstancedBufferAttribute(f, 3)), v.setAttribute("iHW", new t.InstancedBufferAttribute(l, 2));
306
- const q = new t.InstancedBufferAttribute(L, 1);
307
- v.setAttribute("iColor", q), v.setAttribute("iLayer", new t.InstancedBufferAttribute(I, 1)), v.instanceCount = o, v.boundingSphere = new t.Sphere(new t.Vector3(0, 0, 0), (e.maxAbs || 1) * 2);
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));
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);
308
352
  const B = new t.RawShaderMaterial({
309
- vertexShader: Ut,
310
- fragmentShader: zt,
353
+ vertexShader: Zt,
354
+ fragmentShader: qt,
311
355
  glslVersion: t.GLSL3,
312
356
  // Every face of the template winds outward (test_toolpath_contract.mjs), so a back face is only ever the
313
357
  // inside of a bead seen through its open end. Drawing those doubled the GPU time of a frame: measured on a
314
358
  // 14.6M-segment scene (6 plates, M5 Pro, DPR 2), 53.6 -> 29.4 ms with back faces culled.
315
359
  side: t.FrontSide,
316
- uniforms: { uLayerLo: { value: 0 }, uLayerHi: { value: Math.max(0, u - 1) } }
317
- }), V = new t.Mesh(v, B);
318
- V.frustumCulled = !1;
319
- const ot = Gt(m.vType, m.vLayer), T = xt.map((i) => {
320
- const { source: a, layers: b } = Tt((y) => I[y], o, i, ot), w = a.length, x = new Float32Array(w * 3), N = new Float32Array(w * 3), p = new Float32Array(w * 2), P = new Float32Array(w), C = new Float32Array(w);
321
- for (let y = 0; y < w; y++) {
322
- const g = a[y], S = l[g * 2], G = (b[y] - 1) * S / 2;
323
- x[y * 3] = s[g * 3], x[y * 3 + 1] = s[g * 3 + 1], x[y * 3 + 2] = s[g * 3 + 2] - G, N[y * 3] = f[g * 3], N[y * 3 + 1] = f[g * 3 + 1], N[y * 3 + 2] = f[g * 3 + 2] - G, p[y * 2] = S * b[y], p[y * 2 + 1] = l[g * 2 + 1], P[y] = L[g], C[y] = I[g];
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];
324
368
  }
325
- const A = new t.InstancedBufferGeometry();
326
- A.setAttribute("tpl", v.attributes.tpl), A.setIndex(v.index), A.setAttribute("iStart", new t.InstancedBufferAttribute(x, 3)), A.setAttribute("iEnd", new t.InstancedBufferAttribute(N, 3)), A.setAttribute("iHW", new t.InstancedBufferAttribute(p, 2));
327
- const Q = new t.InstancedBufferAttribute(P, 1);
328
- A.setAttribute("iColor", Q), A.setAttribute("iLayer", new t.InstancedBufferAttribute(C, 1)), A.instanceCount = w;
329
- const O = new t.Mesh(A, B);
330
- return O.frustumCulled = !1, O.visible = !1, V.add(O), { k: i, mesh: O, source: a, colors: P, colorAttr: Q };
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: $ };
331
375
  });
332
- let F = 1, _ = !0;
333
- const j = (i) => {
334
- if (i !== F) {
335
- F = i;
336
- for (const a of T) a.mesh.visible = a.k === i;
337
- v.instanceCount = 0, i === 1 && (v.instanceCount = o);
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);
338
382
  }
339
- }, nt = jt((i) => l[i * 2], o), J = e.bbox && new t.Box3(new t.Vector3(...e.bbox.min), new t.Vector3(...e.bbox.max)), Y = new t.Box3(), z = (i, a) => {
340
- if (!_ || !J || !i?.isPerspectiveCamera) {
341
- j(1);
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);
342
386
  return;
343
387
  }
344
- Y.copy(J).applyMatrix4(V.matrixWorld), j(Xt(Yt(nt, Y.distanceToPoint(i.position), i.fov, a)));
388
+ G.copy(K).applyMatrix4(_.matrixWorld), D(ee(te(it, G.distanceToPoint(i.position), i.fov, f)));
345
389
  };
346
- V.userData.updateLod = z;
347
- const k = new t.BufferGeometry();
348
- k.setAttribute("position", new t.BufferAttribute(h, 3));
349
- const X = new t.LineBasicMaterial({ color: kt.travel, transparent: !0, opacity: 0.6 }), W = new t.LineSegments(k, X);
350
- W.visible = !1, W.frustumCulled = !1;
351
- const D = (i, a) => {
352
- const b = Math.max(0, u - 1), w = Math.max(0, Math.min(i | 0, b)), x = Math.max(w, Math.min(a | 0, b));
353
- B.uniforms.uLayerLo.value = w, B.uniforms.uLayerHi.value = x, _ = w === 0 && x === b, _ || j(1);
354
- const N = d[w] * 2, p = d[x + 1] * 2;
355
- k.setDrawRange(N, Math.max(0, p - N));
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));
356
401
  };
357
- return D(0, u - 1), {
358
- mesh: V,
359
- travLines: W,
360
- setLayerRange: D,
361
- setVisibleLayers: (i) => D(0, (i | 0) - 1),
402
+ return J(0, h - 1), {
403
+ mesh: _,
404
+ travLines: k,
405
+ setLayerRange: J,
406
+ setMoveRange: (i) => {
407
+ 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 };
413
+ },
414
+ data: e,
415
+ setVisibleLayers: (i) => J(0, (i | 0) - 1),
362
416
  setTravelVisible: (i) => {
363
- W.visible = !!i;
417
+ k.visible = !!i;
364
418
  },
365
419
  /** color is Float32Array(nV*4) with the packed value in .r — computeColors' output shape. One instance
366
420
  * takes the colour of its first vertex; the two agree, since a segment is one colour. */
367
421
  setColors: (i) => {
368
- if (!(!i || i.length < n * 4)) {
369
- for (let a = 0; a < o; a++) L[a] = i[a * 2 * 4];
370
- q.needsUpdate = !0;
371
- for (const a of T) {
372
- for (let b = 0; b < a.source.length; b++) a.colors[b] = L[a.source[b]];
373
- a.colorAttr.needsUpdate = !0;
422
+ if (!(!i || i.length < o * 4)) {
423
+ for (let f = 0; f < n; f++) L[f] = i[f * 2 * 4];
424
+ 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;
374
428
  }
375
429
  }
376
430
  },
377
431
  /** Call once per frame before rendering; viewportPixels is the drawing buffer's height. */
378
- updateLod: z,
379
- lodLevel: () => F,
432
+ updateLod: Z,
433
+ lodLevel: () => I,
380
434
  dispose: () => {
381
- for (const i of T) i.mesh.geometry.dispose();
382
- v.dispose(), B.dispose(), k.dispose(), X.dispose();
435
+ for (const i of F) i.mesh.geometry.dispose();
436
+ b.dispose(), B.dispose(), N.dispose(), q.dispose();
383
437
  },
384
- nSeg: o,
385
- layerCount: u
438
+ nSeg: n,
439
+ layerCount: h
386
440
  };
387
441
  }
388
442
  export {
389
- Pt as DEFAULT_RANGES_COLORS,
443
+ Ot as DEFAULT_RANGES_COLORS,
390
444
  wt as TOOL_COLOR,
391
- Z as TYPE_COLOR,
392
- It as TYPE_LABEL,
393
- Zt as VERTEX_DATA,
394
- Lt as VIEW_TYPES,
395
- Ht as buildSegmentData,
396
- oe as computeColors,
397
- St as hexToRgb,
398
- Et as layerMoveCount,
399
- ne as makeToolpath,
400
- ee as moveCursor,
401
- at as packColor,
402
- Nt as rangeColorAt,
403
- Rt as roleRatios,
404
- te as topMoveLayer
445
+ R as TYPE_COLOR,
446
+ Bt as TYPE_LABEL,
447
+ oe as VERTEX_DATA,
448
+ Ct as VIEW_TYPES,
449
+ le as buildSegmentData,
450
+ ue as computeColors,
451
+ _t as hexToRgb,
452
+ fe as layerMoveCount,
453
+ he as makeToolpath,
454
+ Jt as moveCursor,
455
+ lt as packColor,
456
+ kt as rangeColorAt,
457
+ ce as roleRatios,
458
+ Gt as topMoveLayer
405
459
  };