three-slicer 0.2.0 → 0.2.2

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.
@@ -0,0 +1,482 @@
1
+ const X = {
2
+ 0: [0.42, 0.45, 0.5],
3
+ 1: [0.85, 0.51, 0.17],
4
+ 2: [0.21, 0.45, 0.76],
5
+ 3: [0.35, 0.75, 0.85],
6
+ 4: [0.16, 0.68, 0.4],
7
+ 5: [0.66, 0.42, 0.85],
8
+ 6: [0.55, 0.45, 0.35],
9
+ 7: [0.95, 0.85, 0.25],
10
+ 8: [0.9, 0.35, 0.65],
11
+ 9: [0.9, 0.25, 0.25],
12
+ 10: [0.6, 0.82, 0.55],
13
+ 11: [0.3, 0.72, 0.7]
14
+ }, fe = [
15
+ [0.85, 0.28, 0.25],
16
+ [0.2, 0.52, 0.85],
17
+ [0.25, 0.72, 0.38],
18
+ [0.96, 0.74, 0.16],
19
+ [0.62, 0.36, 0.82],
20
+ [0.18, 0.74, 0.74],
21
+ [0.95, 0.5, 0.15],
22
+ [0.55, 0.56, 0.6]
23
+ ];
24
+ function ge(t) {
25
+ const i = String(t ?? "").trim().replace(/^#/, "");
26
+ if (i.length !== 3 && i.length !== 6) return null;
27
+ const o = i.length === 3 ? i.split("").map((l) => l + l).join("") : i, n = [0, 2, 4].map((l) => parseInt(o.slice(l, l + 2), 16) / 255);
28
+ return n.some(Number.isNaN) ? null : n;
29
+ }
30
+ function ae(t) {
31
+ const i = Math.round(t[0] * 255), o = Math.round(t[1] * 255), n = Math.round(t[2] * 255);
32
+ return i << 16 | o << 8 | n;
33
+ }
34
+ const me = { 1: "Wall", 2: "Sparse", 3: "Solid", 4: "Skirt", 5: "Support", 6: "Raft", 7: "Gap fill", 8: "Thin wall", 9: "Bridge", 10: "Ironing", 11: "Prime" }, ye = [
35
+ [11, 44, 122],
36
+ [19, 89, 133],
37
+ [28, 136, 145],
38
+ [4, 214, 15],
39
+ [170, 242, 0],
40
+ [252, 249, 3],
41
+ [245, 206, 10],
42
+ [227, 136, 32],
43
+ [209, 104, 48],
44
+ [194, 82, 60],
45
+ [148, 38, 22]
46
+ ].map((t) => [t[0] / 255, t[1] / 255, t[2] / 255]);
47
+ function xe(t, i, o, n) {
48
+ const l = n.length;
49
+ if (!(o > i)) return n[0];
50
+ const r = (o - i) / (l - 1), u = (t - i) / r, h = Math.max(0, Math.min(l - 1, Math.floor(u))), f = Math.max(0, Math.min(l - 1, h + 1)), p = u - h, c = n[h], v = n[f];
51
+ return [c[0] + (v[0] - c[0]) * p, c[1] + (v[1] - c[1]) * p, c[2] + (v[2] - c[2]) * p];
52
+ }
53
+ const we = 15, be = 4;
54
+ function Ie(t, i) {
55
+ const o = t.length, n = i > 0 ? i : 0.42, l = new Array(o);
56
+ for (let e = 0; e < o; e++) {
57
+ const _ = t[e].z;
58
+ l[e] = Math.max(0.02, e === 0 ? _ : _ - t[e - 1].z);
59
+ }
60
+ const r = [], u = [], h = [], f = [], p = [], c = [], v = [], g = [], M = [], S = [], m = [], P = new Float64Array(16), A = [], N = [], k = [];
61
+ let D = -1, K = 0, te = 0, ie = 0, ne = -1, oe = 0;
62
+ const E = 1e-4, a = (e, _, y, x, z, w, F) => (r.push(e), u.push(_), h.push(y), c.push(x), v.push(z), f.push(w), p.push(F), g.push(oe), M.push(!1), r.length - 1);
63
+ for (let e = 0; e < o; e++) {
64
+ const _ = t[e].paths, y = t[e].widths, x = l[e];
65
+ if (oe = e, !_) continue;
66
+ const z = S.length;
67
+ for (let w = 0; w < _.length; w += 8) {
68
+ const F = _[w + 3], C = F & we, U = F >>> be, V = _[w], Y = _[w + 1], j = _[w + 2], B = _[w + 4], O = _[w + 5], ee = _[w + 6];
69
+ if (C === 0) {
70
+ A.push(V, Y, j, B, O, ee), N.push(e), k.push(S.length - z);
71
+ continue;
72
+ }
73
+ const le = y && y[w / 8] > 0 ? y[w / 8] : n;
74
+ P[C] += Math.hypot(B - V, O - Y);
75
+ let H;
76
+ D >= 0 && ne === F && Math.abs(K - V) < E && Math.abs(te - Y) < E && Math.abs(ie - j) < E ? (H = D, a(B, O, ee, C, U, x, le)) : (H = a(V, Y, j, C, U, x, le), a(B, O, ee, C, U, x, le)), M[H] = !0, D = H + 1, K = B, te = O, ie = ee, ne = F, S.push(H), m.push(e);
77
+ }
78
+ }
79
+ const s = r.length, d = S.length, b = new Float32Array(s * 4), L = new Float32Array(s * 4);
80
+ let I = 0, _e = !1, Z = 1 / 0, q = 1 / 0, J = 1 / 0, Q = -1 / 0, $ = -1 / 0, R = -1 / 0;
81
+ for (let e = 0; e < s; e++) {
82
+ const _ = f[e], y = r[e], x = u[e], z = h[e] - 0.5 * _;
83
+ b[e * 4] = y, b[e * 4 + 1] = x, b[e * 4 + 2] = z;
84
+ const w = e > 0 && M[e - 1], F = M[e];
85
+ let C = 0;
86
+ if (w || F) {
87
+ const U = w ? r[e] - r[e - 1] : 0, V = w ? u[e] - u[e - 1] : 0, Y = w ? h[e] - h[e - 1] : 0, j = F ? r[e + 1] - r[e] : 0, B = F ? u[e + 1] - u[e] : 0, O = F ? h[e + 1] - h[e] : 0;
88
+ C = Math.atan2(U * B - V * j, U * j + V * B + Y * O);
89
+ }
90
+ L[e * 4] = _, L[e * 4 + 1] = p[e], L[e * 4 + 2] = C, L[e * 4 + 3] = ae(X[c[e]] || X[1]), (!Number.isFinite(y) || !Number.isFinite(x) || !Number.isFinite(z) || !Number.isFinite(C)) && (_e = !0), I = Math.max(I, Math.abs(y), Math.abs(x), Math.abs(z)), y < Z && (Z = y), y > Q && (Q = y), x < q && (q = x), x > $ && ($ = x), z < J && (J = z), z > R && (R = z);
91
+ }
92
+ const re = new Uint32Array(d * 4);
93
+ for (let e = 0; e < d; e++)
94
+ re[e * 4] = S[e], re[e * 4 + 1] = m[e];
95
+ const W = { vType: new Uint8Array(s), vTool: new Uint8Array(s), vWidth: new Float32Array(s), vHeight: new Float32Array(s), vLayer: new Int32Array(s) };
96
+ for (let e = 0; e < s; e++)
97
+ W.vType[e] = c[e], W.vTool[e] = v[e], W.vWidth[e] = p[e], W.vHeight[e] = f[e], W.vLayer[e] = g[e];
98
+ const ce = new Int32Array(o + 1);
99
+ {
100
+ let e = 0;
101
+ for (let _ = 0; _ < o; _++) {
102
+ for (; e < d && m[e] === _; ) e++;
103
+ ce[_ + 1] = e;
104
+ }
105
+ }
106
+ const G = N.length, T = new Float32Array(G * 6);
107
+ for (let e = 0; e < T.length; e++) T[e] = A[e];
108
+ for (let e = 0; e < T.length; e += 3) {
109
+ const _ = T[e], y = T[e + 1], x = T[e + 2];
110
+ _ < Z && (Z = _), _ > Q && (Q = _), y < q && (q = y), y > $ && ($ = y), x < J && (J = x), x > R && (R = x);
111
+ }
112
+ const he = new Int32Array(o + 1);
113
+ {
114
+ let e = 0;
115
+ for (let _ = 0; _ < o; _++) {
116
+ for (; e < G && N[e] === _; ) e++;
117
+ he[_ + 1] = e;
118
+ }
119
+ }
120
+ const ue = new Int32Array(G);
121
+ for (let e = 0; e < G; e++) ue[e] = k[e];
122
+ const de = s + G > 0 ? { min: [Z, q, J], max: [Q, $, R] } : null;
123
+ return {
124
+ position: b,
125
+ hwa: L,
126
+ segIndex: re,
127
+ nV: s,
128
+ nSeg: d,
129
+ layerSegPrefix: ce,
130
+ travelPos: T,
131
+ travelPrefix: he,
132
+ travelSegBefore: ue,
133
+ nTrav: G,
134
+ layerCount: o,
135
+ maxAbs: I,
136
+ hasNaN: _e,
137
+ meta: W,
138
+ typeLengths: P,
139
+ bbox: de
140
+ };
141
+ }
142
+ function pe(t, i) {
143
+ const o = Math.max(0, Math.min(t.layerCount - 1, i | 0));
144
+ return t.layerSegPrefix[o + 1] - t.layerSegPrefix[o] + (t.travelPrefix[o + 1] - t.travelPrefix[o]);
145
+ }
146
+ function Me(t, i, o) {
147
+ const n = t.layerCount - 1, l = Math.max(0, Math.min(n, i | 0)), r = Math.max(l, Math.min(n, o | 0));
148
+ for (let u = r; u >= l; u--) if (pe(t, u) > 0) return u;
149
+ return r;
150
+ }
151
+ function se(t, i, o) {
152
+ const n = Math.max(0, Math.min(t.layerCount - 1, i | 0)), l = t.layerSegPrefix[n], r = t.travelPrefix[n], u = pe(t, n), h = Math.max(0, Math.min(u, o | 0));
153
+ let f = r, p = t.travelPrefix[n + 1];
154
+ for (; f < p; ) {
155
+ const m = f + p >> 1;
156
+ t.travelSegBefore[m] + (m - r) < h ? f = m + 1 : p = m;
157
+ }
158
+ const c = f - r, v = h - c;
159
+ if (h === 0) return { segCount: 0, travCount: 0, point: null, onTravel: !1 };
160
+ if (f > r && t.travelSegBefore[f - 1] + (f - 1 - r) === h - 1) {
161
+ const m = (f - 1) * 6;
162
+ return { segCount: v, travCount: c, onTravel: !0, point: [t.travelPos[m + 3], t.travelPos[m + 4], t.travelPos[m + 5]] };
163
+ }
164
+ const M = l + v - 1, S = t.segIndex[M * 4] + 1;
165
+ return {
166
+ segCount: v,
167
+ travCount: c,
168
+ onTravel: !1,
169
+ point: [t.position[S * 4], t.position[S * 4 + 1], t.position[S * 4 + 2] + 0.5 * t.hwa[S * 4]]
170
+ };
171
+ }
172
+ function Ce(t) {
173
+ let i = 0;
174
+ for (let n = 1; n < 16; n++) i += t[n] || 0;
175
+ const o = [];
176
+ if (i <= 0) return o;
177
+ for (let n = 1; n < 16; n++) {
178
+ const l = t[n] || 0;
179
+ l > 0 && o.push({ type: n, label: me[n] || "t" + n, pct: 100 * l / i, color: X[n] || X[1] });
180
+ }
181
+ return o.sort((n, l) => l.pct - n.pct);
182
+ }
183
+ const Se = `
184
+ precision highp float;
185
+ precision highp int;
186
+ precision highp sampler2D;
187
+ precision highp usampler2D;
188
+ #define POINTY_CAPS
189
+ #define FIX_TWISTING
190
+ const vec3 light_top_dir = vec3(-0.4574957, 0.4574957, 0.7624929);
191
+ const float light_top_diffuse = 0.6 * 0.8;
192
+ const float light_top_specular = 0.6 * 0.125;
193
+ const float light_top_shininess = 20.0;
194
+ const vec3 light_front_dir = vec3(0.6985074, 0.1397015, 0.6985074);
195
+ const float light_front_diffuse = 0.6 * 0.3;
196
+ const float ambient = 0.3;
197
+ const float emission = 0.15;
198
+ const vec3 UP = vec3(0, 0, 1);
199
+ uniform mat4 view_matrix;
200
+ uniform mat4 projection_matrix;
201
+ uniform vec3 camera_position;
202
+ uniform sampler2D position_tex;
203
+ uniform sampler2D height_width_angle_tex;
204
+ uniform int layer_lo; // stage 25: dual slider lower bound (layer). The shader clips out-of-range segments in O(1).
205
+ uniform int layer_hi; // the upper bound is cut via instanceCount (sorted by layer).
206
+ in float vertex_id_float;
207
+ in uint seg_id_a_u; // instance attribute (formerly segment_index_tex.r) — attribute fetch is cheaper than texelFetch
208
+ in uint seg_layer_u; // instance attribute (formerly segment_index_tex.g)
209
+ out vec3 color;
210
+ vec3 decode_color(float col) {
211
+ int c = int(round(col));
212
+ int r = (c >> 16) & 0xFF;
213
+ int g = (c >> 8) & 0xFF;
214
+ int b = (c >> 0) & 0xFF;
215
+ float f = 1.0 / 255.0;
216
+ return f * vec3(r, g, b);
217
+ }
218
+ float lighting(vec3 eye_position, vec3 eye_normal) {
219
+ float top_diffuse = light_top_diffuse * max(dot(eye_normal, light_top_dir), 0.0);
220
+ float front_diffuse = light_front_diffuse * max(dot(eye_normal, light_front_dir), 0.0);
221
+ float top_specular = light_top_specular * pow(max(dot(-normalize(eye_position), reflect(-light_top_dir, eye_normal)), 0.0), light_top_shininess);
222
+ return ambient + top_diffuse + front_diffuse + top_specular + emission;
223
+ }
224
+ ivec2 tex_coord(sampler2D sampler, int id) {
225
+ ivec2 tex_size = textureSize(sampler, 0);
226
+ return (tex_size.y == 1) ? ivec2(id, 0) : ivec2(id % tex_size.x, id / tex_size.x);
227
+ }
228
+ void main() {
229
+ int vertex_id = int(vertex_id_float);
230
+ int seg_layer = int(seg_layer_u);
231
+ if (seg_layer < layer_lo || seg_layer > layer_hi) { gl_Position = vec4(2.0, 2.0, 2.0, 1.0); return; } // out of range -> clip
232
+ int id_a = int(seg_id_a_u);
233
+ int id_b = id_a + 1;
234
+ vec3 pos_a = texelFetch(position_tex, tex_coord(position_tex, id_a), 0).xyz;
235
+ vec3 pos_b = texelFetch(position_tex, tex_coord(position_tex, id_b), 0).xyz;
236
+ vec3 line = pos_b - pos_a;
237
+ float line_len = length(line);
238
+ vec3 line_dir;
239
+ if (line_len < 1e-4)
240
+ line_dir = vec3(1.0, 0.0, 0.0);
241
+ else
242
+ line_dir = line / line_len;
243
+ vec3 line_right_dir;
244
+ if (abs(dot(line_dir, UP)) > 0.9) {
245
+ line_right_dir = normalize(cross(vec3(1, 0, 0), line_dir));
246
+ }
247
+ else
248
+ line_right_dir = normalize(cross(line_dir, UP));
249
+ vec3 line_up_dir = normalize(cross(line_right_dir, line_dir));
250
+ const vec2 horizontal_vertical_view_signs_array[16] = vec2[](
251
+ vec2(1.0, 0.0), vec2(0.0, 1.0), vec2(0.0, 0.0), vec2(0.0, -1.0),
252
+ vec2(0.0, -1.0), vec2(1.0, 0.0), vec2(0.0, 1.0), vec2(0.0, 0.0),
253
+ vec2(0.0, 1.0), vec2(-1.0, 0.0), vec2(0.0, 0.0), vec2(1.0, 0.0),
254
+ vec2(1.0, 0.0), vec2(0.0, 1.0), vec2(-1.0, 0.0), vec2(0.0, 0.0)
255
+ );
256
+ int id = vertex_id < 4 ? id_a : id_b;
257
+ vec3 endpoint_pos = vertex_id < 4 ? pos_a : pos_b;
258
+ vec4 hwa_color = texelFetch(height_width_angle_tex, tex_coord(height_width_angle_tex, id), 0); // .xyz=h/w/angle, .w=packed color
259
+ vec3 height_width_angle = hwa_color.xyz;
260
+ #ifdef FIX_TWISTING
261
+ int closer_id = (dot(camera_position - pos_a, camera_position - pos_a) < dot(camera_position - pos_b, camera_position - pos_b)) ? id_a : id_b;
262
+ vec3 closer_pos = (closer_id == id_a) ? pos_a : pos_b;
263
+ vec3 camera_view_dir = normalize(closer_pos - camera_position);
264
+ vec3 closer_height_width_angle = texelFetch(height_width_angle_tex, tex_coord(height_width_angle_tex, closer_id), 0).xyz;
265
+ vec3 diagonal_dir_border = normalize(closer_height_width_angle.x * line_up_dir + closer_height_width_angle.y * line_right_dir);
266
+ #else
267
+ vec3 camera_view_dir = normalize(endpoint_pos - camera_position);
268
+ vec3 diagonal_dir_border = normalize(height_width_angle.x * line_up_dir + height_width_angle.y * line_right_dir);
269
+ #endif
270
+ bool is_vertical_view = abs(dot(camera_view_dir, line_up_dir)) / abs(dot(diagonal_dir_border, line_up_dir)) >
271
+ abs(dot(camera_view_dir, line_right_dir)) / abs(dot(diagonal_dir_border, line_right_dir));
272
+ vec2 signs = horizontal_vertical_view_signs_array[vertex_id + 8 * int(is_vertical_view)];
273
+ #ifndef POINTY_CAPS
274
+ if (vertex_id == 2 || vertex_id == 7) signs = -horizontal_vertical_view_signs_array[(vertex_id - 2) + 8 * int(is_vertical_view)];
275
+ #endif
276
+ float view_right_sign = sign(dot(-camera_view_dir, line_right_dir));
277
+ float view_top_sign = sign(dot(-camera_view_dir, line_up_dir));
278
+ float half_height = 0.5 * height_width_angle.x;
279
+ float half_width = 0.5 * height_width_angle.y;
280
+ vec3 horizontal_dir = half_width * line_right_dir;
281
+ vec3 vertical_dir = half_height * line_up_dir;
282
+ float horizontal_sign = signs.x * view_right_sign;
283
+ float vertical_sign = signs.y * view_top_sign;
284
+ vec3 pos = endpoint_pos + horizontal_sign * horizontal_dir + vertical_sign * vertical_dir;
285
+ if (vertex_id == 2 || vertex_id == 7) {
286
+ float line_dir_sign = (vertex_id == 2) ? -1.0 : 1.0;
287
+ if (height_width_angle.z == 0.0) {
288
+ #ifdef POINTY_CAPS
289
+ pos += line_dir_sign * line_dir * half_width;
290
+ #endif
291
+ }
292
+ else {
293
+ pos += line_dir_sign * line_dir * half_width * sin(abs(height_width_angle.z) * 0.5);
294
+ pos += sign(height_width_angle.z) * horizontal_dir * cos(abs(height_width_angle.z) * 0.5);
295
+ }
296
+ }
297
+ vec3 eye_position = (view_matrix * vec4(pos, 1.0)).xyz;
298
+ vec3 eye_normal = (view_matrix * vec4(normalize(pos - endpoint_pos), 0.0)).xyz;
299
+ vec3 color_base = decode_color(hwa_color.w);
300
+ color = color_base * lighting(eye_position, eye_normal);
301
+ gl_Position = projection_matrix * vec4(eye_position, 1.0);
302
+ }
303
+ `, Ae = `
304
+ precision highp float;
305
+ in vec3 color;
306
+ out vec4 fragment_color;
307
+ void main() {
308
+ fragment_color = vec4(color, 1.0);
309
+ }
310
+ `, ze = [
311
+ 0,
312
+ 1,
313
+ 2,
314
+ 0,
315
+ 2,
316
+ 3,
317
+ // front spike
318
+ 0,
319
+ 3,
320
+ 4,
321
+ 0,
322
+ 4,
323
+ 5,
324
+ // right/bottom body
325
+ 0,
326
+ 5,
327
+ 6,
328
+ 0,
329
+ 6,
330
+ 1,
331
+ // left/top body
332
+ 5,
333
+ 4,
334
+ 7,
335
+ 5,
336
+ 7,
337
+ 6
338
+ // back spike
339
+ ];
340
+ function Pe(t, i) {
341
+ const o = (a, s) => {
342
+ const d = Math.min(2048, Math.max(1, s)), b = Math.max(1, Math.ceil(s / d)), L = new Float32Array(d * b * 4);
343
+ L.set(a.subarray(0, Math.min(a.length, d * b * 4)));
344
+ const I = new t.DataTexture(L, d, b, t.RGBAFormat, t.FloatType);
345
+ return I.minFilter = I.magFilter = t.NearestFilter, I.generateMipmaps = !1, I.needsUpdate = !0, I;
346
+ }, n = o(i.position, i.nV), l = o(i.hwa, i.nV), r = new t.InstancedBufferGeometry();
347
+ r.setIndex(ze), r.setAttribute("position", new t.BufferAttribute(new Float32Array(8 * 3), 3)), r.setAttribute("vertex_id_float", new t.BufferAttribute(new Float32Array([0, 1, 2, 3, 4, 5, 6, 7]), 1));
348
+ const u = new t.InstancedInterleavedBuffer(i.segIndex, 4);
349
+ r.setAttribute("seg_id_a_u", new t.InterleavedBufferAttribute(u, 1, 0)), r.setAttribute("seg_layer_u", new t.InterleavedBufferAttribute(u, 1, 1)), r.instanceCount = 0;
350
+ const h = new t.RawShaderMaterial({
351
+ glslVersion: t.GLSL3,
352
+ uniforms: {
353
+ view_matrix: { value: new t.Matrix4() },
354
+ projection_matrix: { value: new t.Matrix4() },
355
+ camera_position: { value: new t.Vector3() },
356
+ position_tex: { value: n },
357
+ height_width_angle_tex: { value: l },
358
+ layer_lo: { value: 0 },
359
+ layer_hi: { value: i.layerCount }
360
+ },
361
+ vertexShader: Se,
362
+ fragmentShader: Ae,
363
+ side: t.DoubleSide
364
+ }), f = new t.Mesh(r, h);
365
+ let p = null;
366
+ if (i.bbox) {
367
+ const { min: a, max: s } = i.bbox, d = new t.Vector3((a[0] + s[0]) / 2, (a[1] + s[1]) / 2, (a[2] + s[2]) / 2), b = Math.hypot(s[0] - a[0], s[1] - a[1], s[2] - a[2]) / 2 + 2;
368
+ p = new t.Sphere(d, b);
369
+ }
370
+ f.frustumCulled = !!p, p && (r.boundingSphere = p);
371
+ const c = new t.Matrix4(), v = new t.Vector3();
372
+ f.onBeforeRender = (a, s, d) => {
373
+ h.uniforms.projection_matrix.value.copy(d.projectionMatrix), h.uniforms.view_matrix.value.multiplyMatrices(d.matrixWorldInverse, f.matrixWorld), c.copy(f.matrixWorld).invert(), d.getWorldPosition(v).applyMatrix4(c), h.uniforms.camera_position.value.copy(v);
374
+ };
375
+ const g = new t.BufferGeometry();
376
+ g.setAttribute("position", new t.BufferAttribute(i.travelPos, 3)), g.setDrawRange(0, 0);
377
+ const M = new t.LineSegments(g, new t.LineBasicMaterial({ color: 7041658 }));
378
+ M.frustumCulled = !!p, M.visible = !1, p && (g.boundingSphere = p);
379
+ let S = !1, m = 0, P = i.layerCount - 1, A = null;
380
+ const N = () => Me(i, m, P), k = () => {
381
+ const a = i.travelPrefix[m], s = N(), d = A == null ? i.travelPrefix[P + 1] : i.travelPrefix[s] + se(i, s, A).travCount, b = Math.max(0, d - a);
382
+ g.setDrawRange(S ? a * 2 : 0, S ? b * 2 : 0);
383
+ }, D = () => {
384
+ const a = N();
385
+ r.instanceCount = A == null ? i.layerSegPrefix[P + 1] : i.layerSegPrefix[a] + se(i, a, A).segCount;
386
+ }, K = (a, s) => {
387
+ const d = i.layerCount;
388
+ m = Math.max(0, Math.min(d - 1, a | 0)), P = Math.max(m, Math.min(d - 1, s | 0)), h.uniforms.layer_lo.value = m, h.uniforms.layer_hi.value = P, A = null, D(), k();
389
+ };
390
+ return {
391
+ mesh: f,
392
+ travLines: M,
393
+ setVisibleLayers: (a) => K(0, (a | 0) - 1),
394
+ setLayerRange: K,
395
+ setMoveRange: (a) => {
396
+ if (A = a == null ? null : Math.max(0, a | 0), D(), k(), A == null) return null;
397
+ const s = N();
398
+ return { layer: s, ...se(i, s, A) };
399
+ },
400
+ setTravelVisible: (a) => {
401
+ S = !!a, M.visible = S, k();
402
+ },
403
+ setColors: (a) => {
404
+ const s = l.image.data, d = Math.min(a.length, s.length) / 4;
405
+ for (let b = 0; b < d; b++) s[b * 4 + 3] = a[b * 4];
406
+ l.needsUpdate = !0;
407
+ },
408
+ dispose: () => {
409
+ r.dispose(), h.dispose(), n.dispose(), l.dispose(), g.dispose(), M.material.dispose();
410
+ },
411
+ data: i,
412
+ nSeg: i.nSeg,
413
+ layerCount: i.layerCount
414
+ };
415
+ }
416
+ const ve = [
417
+ { key: "feature", label: "Feature type", cont: !1, unit: "" },
418
+ { key: "speed", label: "Speed", cont: !0, unit: "mm/s" },
419
+ { key: "height", label: "Layer Height", cont: !0, unit: "mm" },
420
+ { key: "width", label: "Line Width", cont: !0, unit: "mm" },
421
+ { key: "fan", label: "Fan Speed", cont: !0, unit: "%" },
422
+ { key: "temp", label: "Temperature", cont: !0, unit: "°C" },
423
+ // Last, like upstream's EViewType::Tool: it answers "did my painted regions come out on the extruder I assigned?",
424
+ // which is a check you run after slicing, not a property you scrub through. Discrete like the feature view — an
425
+ // extruder index is a label, and a heatmap over it would imply tool 2 sits "between" tools 1 and 3.
426
+ { key: "filament", label: "Filament", cont: !1, unit: "" }
427
+ ];
428
+ function Fe(t, i, o, n) {
429
+ const l = i.vType[o], r = i.vLayer[o], u = r === 0;
430
+ switch (t) {
431
+ case "height":
432
+ return i.vHeight[o];
433
+ case "width":
434
+ return i.vWidth[o];
435
+ case "speed":
436
+ return u ? n.firstLayerSpeed : n.speedByType[l] ?? n.speedByType[1];
437
+ case "fan":
438
+ return r < n.closeFanLayers ? 0 : l === 9 ? 100 : n.fanNormal;
439
+ case "temp":
440
+ return u ? n.tempFirst : n.tempNormal;
441
+ default:
442
+ return 0;
443
+ }
444
+ }
445
+ function Le(t, i, o) {
446
+ const { meta: n, nV: l } = t, r = new Float32Array(l * 4), u = ve.find((c) => c.key === i) || ve[0];
447
+ if (!u.cont) {
448
+ const c = ((o == null ? void 0 : o.toolColors) ?? []).map(ge), v = u.key === "filament" ? (g) => {
449
+ const M = n.vTool ? n.vTool[g] : 0;
450
+ return c[M] || fe[M % fe.length];
451
+ } : (g) => X[n.vType[g]] || X[1];
452
+ for (let g = 0; g < l; g++) r[g * 4] = ae(v(g));
453
+ return { color: r, min: 0, max: 0, viewType: i, label: u.label, unit: u.unit, cont: !1 };
454
+ }
455
+ let h = 1 / 0, f = -1 / 0;
456
+ const p = new Float32Array(l);
457
+ for (let c = 0; c < l; c++) {
458
+ const v = Fe(i, n, c, o);
459
+ p[c] = v, v < h && (h = v), v > f && (f = v);
460
+ }
461
+ Number.isFinite(h) || (h = 0, f = 1);
462
+ for (let c = 0; c < l; c++) {
463
+ const v = xe(p[c], h, f, ye);
464
+ r[c * 4] = ae(v);
465
+ }
466
+ return { color: r, min: h, max: f, viewType: i, label: u.label, unit: u.unit, cont: !0 };
467
+ }
468
+ export {
469
+ ye as D,
470
+ fe as T,
471
+ ve as V,
472
+ Pe as a,
473
+ Ie as b,
474
+ Le as c,
475
+ X as d,
476
+ me as e,
477
+ ze as f,
478
+ pe as l,
479
+ se as m,
480
+ Ce as r,
481
+ Me as t
482
+ };