three-slicer-viewer 0.2.5 → 0.3.1

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.
@@ -1,190 +1,192 @@
1
- const it = {
1
+ import { D as at, a as rt } from "./viewer_defaults-B7UUZ582.js";
2
+ import { R as t, e as B } from "./toolpath_encoding-BuYs95qZ.js";
3
+ const F = 1e-6, lt = {
2
4
  // OrcaSlicer / PrusaSlicer ;TYPE: names
3
- "outer wall": 1,
4
- "external perimeter": 1,
5
- "inner wall": 1,
6
- perimeter: 1,
7
- "internal perimeter": 1,
8
- "overhang wall": 1,
9
- "overhang perimeter": 1,
10
- "sparse infill": 2,
11
- "internal infill": 2,
12
- "solid infill": 3,
13
- "internal solid infill": 3,
14
- "top solid infill": 3,
15
- "top surface": 3,
16
- "bottom surface": 3,
17
- skirt: 4,
18
- brim: 4,
19
- "skirt/brim": 4,
20
- support: 5,
21
- "support material": 5,
22
- "support material interface": 5,
23
- "support interface": 5,
24
- "support transition": 5,
25
- raft: 6,
26
- "gap fill": 7,
27
- "gap infill": 7,
28
- "thin wall": 8,
29
- bridge: 9,
30
- "bridge infill": 9,
31
- "internal bridge": 9,
32
- "internal bridge infill": 9,
33
- ironing: 10,
34
- "prime tower": 11,
35
- "wipe tower": 11,
36
- custom: 1,
5
+ "outer wall": t.WALL,
6
+ "external perimeter": t.WALL,
7
+ "inner wall": t.WALL,
8
+ perimeter: t.WALL,
9
+ "internal perimeter": t.WALL,
10
+ "overhang wall": t.WALL,
11
+ "overhang perimeter": t.WALL,
12
+ "sparse infill": t.SPARSE,
13
+ "internal infill": t.SPARSE,
14
+ "solid infill": t.SOLID,
15
+ "internal solid infill": t.SOLID,
16
+ "top solid infill": t.SOLID,
17
+ "top surface": t.SOLID,
18
+ "bottom surface": t.SOLID,
19
+ skirt: t.SKIRT,
20
+ brim: t.SKIRT,
21
+ "skirt/brim": t.SKIRT,
22
+ support: t.SUPPORT,
23
+ "support material": t.SUPPORT,
24
+ "support material interface": t.SUPPORT,
25
+ "support interface": t.SUPPORT,
26
+ "support transition": t.SUPPORT,
27
+ raft: t.RAFT,
28
+ "gap fill": t.GAP,
29
+ "gap infill": t.GAP,
30
+ "thin wall": t.THIN,
31
+ bridge: t.BRIDGE,
32
+ "bridge infill": t.BRIDGE,
33
+ "internal bridge": t.BRIDGE,
34
+ "internal bridge infill": t.BRIDGE,
35
+ ironing: t.IRONING,
36
+ "prime tower": t.PRIME,
37
+ "wipe tower": t.PRIME,
38
+ custom: t.WALL,
37
39
  // Cura ;TYPE: names
38
- "wall-outer": 1,
39
- "wall-inner": 1,
40
- fill: 2,
41
- skin: 3,
42
- "support-interface": 5,
43
- "prime-tower": 11
44
- }, nt = [
45
- ["skirt/brim", 4],
46
- ["skirt", 4],
47
- ["walls", 1],
48
- ["thin-wall", 8],
49
- ["gap-fill", 7],
50
- ["bridge", 9],
51
- ["ironing", 10],
52
- ["support", 5],
53
- ["prime tower", 11],
54
- ["wipe_tower_real", 11]
55
- ], st = (w, c) => w === c || c.length < w.length && " (:/".includes(w[c.length]) && w.startsWith(c), at = {
56
- 1: 1,
57
- 2: 1,
58
- 3: 1,
59
- 4: 2,
60
- 5: 3,
61
- 6: 3,
62
- 7: 3,
63
- 8: 10,
64
- 9: 9,
65
- 10: 9,
66
- 11: 7,
67
- 12: 4,
68
- 13: 4,
69
- 14: 5,
70
- 15: 5,
71
- 16: 5,
72
- 17: 11
40
+ "wall-outer": t.WALL,
41
+ "wall-inner": t.WALL,
42
+ fill: t.SPARSE,
43
+ skin: t.SOLID,
44
+ "support-interface": t.SUPPORT,
45
+ "prime-tower": t.PRIME
46
+ }, ot = [
47
+ ["skirt/brim", t.SKIRT],
48
+ ["skirt", t.SKIRT],
49
+ ["walls", t.WALL],
50
+ ["thin-wall", t.THIN],
51
+ ["gap-fill", t.GAP],
52
+ ["bridge", t.BRIDGE],
53
+ ["ironing", t.IRONING],
54
+ ["support", t.SUPPORT],
55
+ ["prime tower", t.PRIME],
56
+ ["wipe_tower_real", t.PRIME]
57
+ ], ct = (I, f) => I === f || f.length < I.length && " (:/".includes(I[f.length]) && I.startsWith(f), ft = {
58
+ 1: t.WALL,
59
+ 2: t.WALL,
60
+ 3: t.WALL,
61
+ 4: t.SPARSE,
62
+ 5: t.SOLID,
63
+ 6: t.SOLID,
64
+ 7: t.SOLID,
65
+ 8: t.IRONING,
66
+ 9: t.BRIDGE,
67
+ 10: t.BRIDGE,
68
+ 11: t.GAP,
69
+ 12: t.SKIRT,
70
+ 13: t.SKIRT,
71
+ 14: t.SUPPORT,
72
+ 15: t.SUPPORT,
73
+ 16: t.SUPPORT,
74
+ 17: t.PRIME
73
75
  };
74
- function rt(w, c = {}) {
75
- const V = Math.PI / 4 * (c.filamentDiameter > 0 ? c.filamentDiameter : 1.75) ** 2, tt = c.defaultLayerHeight > 0 ? c.defaultLayerHeight : 0.2;
76
- let f = 0, u = 0, m = 0, L = 0, x = !0, v = !0, E = 0, P = 1, S = 0, p = null;
77
- const g = [];
78
- let z = !1, I = !0, R = NaN, q = 0, H = 0, O = 0;
79
- const j = /* @__PURE__ */ new Set([0]), W = (s) => {
80
- p = { z: s, p: [], w: [] }, g.push(p), I = !1, R = NaN, P = 1, S = 0;
81
- }, et = () => g.length > 1 ? g[g.length - 2].z : 0, C = (s, o, d, b, N, e, t) => {
82
- const a = Math.hypot(b - s, N - o, e - d);
83
- if (!(a < 1e-6))
84
- if (t > 1e-6) {
85
- O += t, I ? W(Number.isNaN(R) ? e : R) : !z && e > p.z + 1e-3 && W(e);
86
- const r = P + E * 16;
87
- p.p.push(s, o, d, r, b, N, e, r);
88
- const i = Math.max(0.02, p.z - et() || tt), F = S > 0 ? S : t * V / (a * i) + i * (1 - Math.PI / 4);
89
- p.w.push(Math.min(3, Math.max(0.05, F))), q++;
90
- } else p && (p.p.push(s, o, d, E * 16, b, N, e, E * 16), p.w.push(0), H++);
76
+ function Lt(I, f = {}) {
77
+ const it = Math.PI / 4 * (f.filamentDiameter > 0 ? f.filamentDiameter : at) ** 2, nt = f.defaultLayerHeight > 0 ? f.defaultLayerHeight : rt;
78
+ let p = 0, u = 0, h = 0, G = 0, d = !0, O = !0, w = 0, T = t.WALL, W = 0, L = null;
79
+ const P = [];
80
+ let b = !1, D = !0, K = NaN, z = 0, H = 0, k = 0;
81
+ const Y = /* @__PURE__ */ new Set([0]), y = (a) => {
82
+ L = { z: a, p: [], w: [] }, P.push(L), D = !1, K = NaN, T = t.WALL, W = 0;
83
+ }, st = () => P.length > 1 ? P[P.length - 2].z : 0, Z = (a, c, R, A, m, i, e) => {
84
+ const r = Math.hypot(A - a, m - c, i - R);
85
+ if (!(r < F))
86
+ if (e > F) {
87
+ k += e, D ? y(Number.isNaN(K) ? i : K) : !b && i > L.z + 1e-3 && y(i);
88
+ const l = B(T, w);
89
+ L.p.push(a, c, R, l, A, m, i, l);
90
+ const n = Math.max(0.02, L.z - st() || nt), _ = W > 0 ? W : e * it / (r * n) + n * (1 - Math.PI / 4);
91
+ L.w.push(Math.min(3, Math.max(0.05, _))), z++;
92
+ } else L && (L.p.push(a, c, R, B(t.TRAVEL, w), A, m, i, B(t.TRAVEL, w)), L.w.push(0), H++);
91
93
  };
92
- for (const s of w.split(`
94
+ for (const a of I.split(`
93
95
  `)) {
94
- const o = s.indexOf(";"), d = (o < 0 ? s : s.slice(0, o)).trim(), b = o < 0 ? "" : s.slice(o + 1).trim();
95
- if (b && !d) {
96
- const t = b.toLowerCase();
97
- if (t.startsWith("type:")) {
98
- P = it[t.slice(5).trim()] ?? 1;
96
+ const c = a.indexOf(";"), R = (c < 0 ? a : a.slice(0, c)).trim(), A = c < 0 ? "" : a.slice(c + 1).trim();
97
+ if (A && !R) {
98
+ const e = A.toLowerCase();
99
+ if (e.startsWith("type:")) {
100
+ T = lt[e.slice(5).trim()] ?? t.WALL;
99
101
  continue;
100
102
  }
101
- if (t.startsWith("_extrusion_role:")) {
102
- P = at[parseInt(t.slice(16), 10)] ?? 1;
103
+ if (e.startsWith("_extrusion_role:")) {
104
+ T = ft[parseInt(e.slice(16), 10)] ?? t.WALL;
103
105
  continue;
104
106
  }
105
- if (t.startsWith("width:")) {
106
- const i = parseFloat(t.slice(6));
107
- S = i > 0 ? i : 0;
107
+ if (e.startsWith("width:")) {
108
+ const n = parseFloat(e.slice(6));
109
+ W = n > 0 ? n : 0;
108
110
  continue;
109
111
  }
110
- if (t.startsWith("layer_change") || t.startsWith("layer:")) {
111
- z = !0, I = !0;
112
+ if (e.startsWith("layer_change") || e.startsWith("layer:")) {
113
+ b = !0, D = !0;
112
114
  continue;
113
115
  }
114
- if (t.startsWith("z:")) {
115
- const i = parseFloat(t.slice(2));
116
- I && i > 0 && (z = !0, W(i));
116
+ if (e.startsWith("z:")) {
117
+ const n = parseFloat(e.slice(2));
118
+ D && n > 0 && (b = !0, y(n));
117
119
  continue;
118
120
  }
119
- const a = /^layer \d+ z([-\d.]+)/.exec(t);
120
- if (a) {
121
- z = !0, W(parseFloat(a[1]));
121
+ const r = /^layer \d+ z([-\d.]+)/.exec(e);
122
+ if (r) {
123
+ b = !0, y(parseFloat(r[1]));
122
124
  continue;
123
125
  }
124
- const r = nt.find(([i]) => st(t, i));
125
- r && (P = r[1]);
126
+ const l = ot.find(([n]) => ct(e, n));
127
+ l && (T = l[1]);
126
128
  continue;
127
129
  }
128
- if (!d) continue;
129
- const N = d.split(/\s+/), e = N[0].toUpperCase();
130
- if (e === "G90") {
131
- x = !0;
130
+ if (!R) continue;
131
+ const m = R.split(/\s+/), i = m[0].toUpperCase();
132
+ if (i === "G90") {
133
+ d = !0;
132
134
  continue;
133
135
  }
134
- if (e === "G91") {
135
- x = !1;
136
+ if (i === "G91") {
137
+ d = !1;
136
138
  continue;
137
139
  }
138
- if (e === "M82") {
139
- v = !0;
140
+ if (i === "M82") {
141
+ O = !0;
140
142
  continue;
141
143
  }
142
- if (e === "M83") {
143
- v = !1;
144
+ if (i === "M83") {
145
+ O = !1;
144
146
  continue;
145
147
  }
146
- if (/^T\d+$/.test(e)) {
147
- E = parseInt(e.slice(1), 10), j.add(E);
148
+ if (/^T\d+$/.test(i)) {
149
+ w = parseInt(i.slice(1), 10), Y.add(w);
148
150
  continue;
149
151
  }
150
- if (e === "G92" || e === "G0" || e === "G1" || e === "G2" || e === "G3") {
151
- let t = NaN, a = NaN, r = NaN, i = NaN, F = 0, D = 0;
152
- for (let h = 1; h < N.length; h++) {
153
- const n = N[h][0], l = parseFloat(N[h].slice(1));
154
- Number.isNaN(l) || (n === "X" || n === "x" ? t = l : n === "Y" || n === "y" ? a = l : n === "Z" || n === "z" ? r = l : n === "E" || n === "e" ? i = l : n === "I" || n === "i" ? F = l : (n === "J" || n === "j") && (D = l));
152
+ if (i === "G92" || i === "G0" || i === "G1" || i === "G2" || i === "G3") {
153
+ let e = NaN, r = NaN, l = NaN, n = NaN, _ = 0, q = 0;
154
+ for (let N = 1; N < m.length; N++) {
155
+ const s = m[N][0], o = parseFloat(m[N].slice(1));
156
+ Number.isNaN(o) || (s === "X" || s === "x" ? e = o : s === "Y" || s === "y" ? r = o : s === "Z" || s === "z" ? l = o : s === "E" || s === "e" ? n = o : s === "I" || s === "i" ? _ = o : (s === "J" || s === "j") && (q = o));
155
157
  }
156
- if (e === "G92") {
157
- Number.isNaN(t) || (f = t), Number.isNaN(a) || (u = a), Number.isNaN(r) || (m = r), Number.isNaN(i) || (L = i);
158
+ if (i === "G92") {
159
+ Number.isNaN(e) || (p = e), Number.isNaN(r) || (u = r), Number.isNaN(l) || (h = l), Number.isNaN(n) || (G = n);
158
160
  continue;
159
161
  }
160
- const k = Number.isNaN(t) ? f : x ? t : f + t, A = Number.isNaN(a) ? u : x ? a : u + a, Z = Number.isNaN(r) ? m : x ? r : m + r, K = Number.isNaN(i) ? 0 : v ? i - L : i;
161
- if (e === "G2" || e === "G3") {
162
- const h = f + F, n = u + D, l = Math.hypot(f - h, u - n), _ = Math.atan2(u - n, f - h);
163
- let M = Math.atan2(A - n, k - h);
164
- const T = e === "G3";
165
- T && M <= _ + 1e-6 && (M += 2 * Math.PI), !T && M >= _ - 1e-6 && (M -= 2 * Math.PI);
166
- const y = Math.max(1, Math.min(360, Math.ceil(Math.abs(M - _) * l / 0.3)));
167
- let X = f, Y = u, J = m;
168
- for (let G = 1; G <= y; G++) {
169
- const U = _ + (M - _) * G / y, $ = G === y ? k : h + l * Math.cos(U), B = G === y ? A : n + l * Math.sin(U), Q = m + (Z - m) * G / y;
170
- C(X, Y, J, $, B, Q, K / y), X = $, Y = B, J = Q;
162
+ const U = Number.isNaN(e) ? p : d ? e : p + e, x = Number.isNaN(r) ? u : d ? r : u + r, v = Number.isNaN(l) ? h : d ? l : h + l, j = Number.isNaN(n) ? 0 : O ? n - G : n;
163
+ if (i === "G2" || i === "G3") {
164
+ const N = p + _, s = u + q, o = Math.hypot(p - N, u - s), g = Math.atan2(u - s, p - N);
165
+ let S = Math.atan2(x - s, U - N);
166
+ const C = i === "G3";
167
+ C && S <= g + F && (S += 2 * Math.PI), !C && S >= g - F && (S -= 2 * Math.PI);
168
+ const E = Math.max(1, Math.min(360, Math.ceil(Math.abs(S - g) * o / 0.3)));
169
+ let V = p, X = u, J = h;
170
+ for (let M = 1; M <= E; M++) {
171
+ const $ = g + (S - g) * M / E, Q = M === E ? U : N + o * Math.cos($), tt = M === E ? x : s + o * Math.sin($), et = h + (v - h) * M / E;
172
+ Z(V, X, J, Q, tt, et, j / E), V = Q, X = tt, J = et;
171
173
  }
172
174
  } else
173
- C(f, u, m, k, A, Z, K);
174
- f = k, u = A, m = Z, Number.isNaN(i) || (L = v ? i : L + i);
175
+ Z(p, u, h, U, x, v, j);
176
+ p = U, u = x, h = v, Number.isNaN(n) || (G = O ? n : G + n);
175
177
  }
176
178
  }
177
179
  return {
178
- layers: g.map((s) => ({ z: s.z, paths: Float32Array.from(s.p), widths: Float32Array.from(s.w) })),
180
+ layers: P.map((a) => ({ z: a.z, paths: Float32Array.from(a.p), widths: Float32Array.from(a.w) })),
179
181
  stats: {
180
- layers: g.length,
181
- path_segments: q,
182
+ layers: P.length,
183
+ path_segments: z,
182
184
  travel_segments: H,
183
- filament_mm: O,
184
- tools: [...j].sort((s, o) => s - o)
185
+ filament_mm: k,
186
+ tools: [...Y].sort((a, c) => a - c)
185
187
  }
186
188
  };
187
189
  }
188
190
  export {
189
- rt as parseGcode
191
+ Lt as parseGcode
190
192
  };