three-slicer-viewer 0.4.0 → 0.4.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.
- package/README.md +7 -0
- package/dist/index.js +2886 -2861
- package/dist/model_loaders-kvOxEvFT.js +230 -0
- package/dist/model_loaders.js +14 -9
- package/dist/parse_3mf-6PLUgcZp.js +951 -0
- package/dist/parse_3mf.worker.js +101 -39
- package/package.json +5 -1
- package/src/settings/toggle_eval.js +112 -6
- package/types/loaders.d.ts +23 -1
- package/types/toggle.d.ts +6 -0
- package/types/workers.d.ts +10 -0
- package/dist/model_loaders-Dk9rqXFb.js +0 -196
- package/dist/parse_3mf-CpbA-6Iq.js +0 -666
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import * as v from "three";
|
|
2
|
+
import { OBJLoader as B } from "three/examples/jsm/loaders/OBJLoader.js";
|
|
3
|
+
import { PLYLoader as W } from "three/examples/jsm/loaders/PLYLoader.js";
|
|
4
|
+
import { AMFLoader as _ } from "three/examples/jsm/loaders/AMFLoader.js";
|
|
5
|
+
import { p as L } from "./parse_3mf-6PLUgcZp.js";
|
|
6
|
+
import { makeParse3mfWorker as D } from "./make_worker.js";
|
|
7
|
+
const O = 80, E = 84, $ = 50, C = (t) => E + t * $;
|
|
8
|
+
let p = null, h = !1, I = 0;
|
|
9
|
+
const w = /* @__PURE__ */ new Map();
|
|
10
|
+
function j() {
|
|
11
|
+
if (h || typeof Worker > "u") return null;
|
|
12
|
+
if (p) return p;
|
|
13
|
+
try {
|
|
14
|
+
A(D());
|
|
15
|
+
} catch {
|
|
16
|
+
h = !0, p = null;
|
|
17
|
+
}
|
|
18
|
+
return p;
|
|
19
|
+
}
|
|
20
|
+
function Z(t) {
|
|
21
|
+
if (p || h) {
|
|
22
|
+
t.terminate();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
A(t);
|
|
26
|
+
}
|
|
27
|
+
function A(t) {
|
|
28
|
+
p = t, p.onmessage = (e) => {
|
|
29
|
+
const { id: s, objects: o, project: i, error: n } = e.data || {}, a = w.get(s);
|
|
30
|
+
a && (w.delete(s), n ? a.reject(new Error(n)) : a.resolve({ objects: o, project: i }));
|
|
31
|
+
}, p.onerror = () => {
|
|
32
|
+
h = !0;
|
|
33
|
+
for (const [, e] of w) e.reject(new Error("3MF parse worker failed"));
|
|
34
|
+
w.clear(), p = null;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function M(t) {
|
|
38
|
+
return typeof Blob < "u" && t instanceof Blob ? t.arrayBuffer() : t;
|
|
39
|
+
}
|
|
40
|
+
async function R(t, e) {
|
|
41
|
+
const s = j();
|
|
42
|
+
if (!s) return L(await M(t), e);
|
|
43
|
+
try {
|
|
44
|
+
const o = ++I, i = new Promise((n, a) => w.set(o, { resolve: n, reject: a }));
|
|
45
|
+
return s.postMessage({ id: o, source: t, baseName: e }), await i;
|
|
46
|
+
} catch {
|
|
47
|
+
return L(await M(t), e);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function tt(t) {
|
|
51
|
+
x(t) === "3mf" && j()?.postMessage({ type: "warm" });
|
|
52
|
+
}
|
|
53
|
+
const T = ["stl", "obj", "3mf", "amf", "ply"], N = ["gcode", "gco", "g"], X = "sl1";
|
|
54
|
+
function et() {
|
|
55
|
+
return [...T, X, ...N];
|
|
56
|
+
}
|
|
57
|
+
const P = /* @__PURE__ */ new Map();
|
|
58
|
+
function nt(t, e) {
|
|
59
|
+
for (const s of (Array.isArray(t) ? t : String(t).split(",")).map((o) => o.trim().toLowerCase()))
|
|
60
|
+
P.set(s, e), T.includes(s) || T.push(s);
|
|
61
|
+
}
|
|
62
|
+
function x(t) {
|
|
63
|
+
const e = t.lastIndexOf(".");
|
|
64
|
+
return e < 0 ? "" : t.slice(e + 1).toLowerCase();
|
|
65
|
+
}
|
|
66
|
+
function Y(t) {
|
|
67
|
+
const e = new DataView(t);
|
|
68
|
+
if (t.byteLength >= E) {
|
|
69
|
+
const a = e.getUint32(O, !0);
|
|
70
|
+
if (t.byteLength === C(a)) {
|
|
71
|
+
const c = new Float32Array(a * 9);
|
|
72
|
+
let u = E, l = 0;
|
|
73
|
+
for (let r = 0; r < a; r++) {
|
|
74
|
+
u += 12;
|
|
75
|
+
for (let f = 0; f < 3; f++)
|
|
76
|
+
c[l++] = e.getFloat32(u, !0), c[l++] = e.getFloat32(u + 4, !0), c[l++] = e.getFloat32(u + 8, !0), u += 12;
|
|
77
|
+
u += 2;
|
|
78
|
+
}
|
|
79
|
+
return c;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const s = new TextDecoder().decode(t), o = /vertex\s+([-\d.eE+]+)\s+([-\d.eE+]+)\s+([-\d.eE+]+)/g, i = [];
|
|
83
|
+
let n;
|
|
84
|
+
for (; n = o.exec(s); ) i.push(+n[1], +n[2], +n[3]);
|
|
85
|
+
return i.length < 9 ? null : new Float32Array(i);
|
|
86
|
+
}
|
|
87
|
+
function S(t, e) {
|
|
88
|
+
const s = t?.attributes?.position;
|
|
89
|
+
if (!s || s.count < 3) return null;
|
|
90
|
+
const o = t.index, i = new v.Vector3(), n = Math.floor((o ? o.count : s.count) / 3), a = new Float32Array(n * 9);
|
|
91
|
+
let c = 0;
|
|
92
|
+
const u = (l) => {
|
|
93
|
+
i.fromBufferAttribute(s, l), e && i.applyMatrix4(e), a[c++] = i.x, a[c++] = i.y, a[c++] = i.z;
|
|
94
|
+
};
|
|
95
|
+
if (o)
|
|
96
|
+
for (let l = 0; l < n * 3; l++) u(o.getX(l));
|
|
97
|
+
else
|
|
98
|
+
for (let l = 0; l < n * 3; l++) u(l);
|
|
99
|
+
return a;
|
|
100
|
+
}
|
|
101
|
+
function F(t) {
|
|
102
|
+
t.updateMatrixWorld(!0);
|
|
103
|
+
const e = [];
|
|
104
|
+
return t.traverse((s) => {
|
|
105
|
+
s.isMesh && s.geometry && e.push({ geometry: s.geometry, matrix: s.matrixWorld });
|
|
106
|
+
}), e;
|
|
107
|
+
}
|
|
108
|
+
function k(t, e, s) {
|
|
109
|
+
const o = e.map((c) => S(c.geometry, c.matrix)).filter(Boolean);
|
|
110
|
+
if (!o.length) return [];
|
|
111
|
+
if (s && o.length > 1)
|
|
112
|
+
return o.map((c, u) => ({ name: `${t}#${u + 1}`, modelPos: c }));
|
|
113
|
+
if (o.length === 1) return [{ name: t, modelPos: o[0] }];
|
|
114
|
+
let i = 0;
|
|
115
|
+
for (const c of o) i += c.length;
|
|
116
|
+
const n = new Float32Array(i);
|
|
117
|
+
let a = 0;
|
|
118
|
+
for (const c of o)
|
|
119
|
+
n.set(c, a), a += c.length;
|
|
120
|
+
return [{ name: t, modelPos: n }];
|
|
121
|
+
}
|
|
122
|
+
async function z(t, e) {
|
|
123
|
+
const { objects: s, project: o } = await R(e, t), i = s.map((n) => ({ name: n.name, modelPos: n.tris, baked: n.baked, objectid: n.objectid, paint: n.paint, bbox: n.bbox, project: o }));
|
|
124
|
+
if (!i.length && o.gcodePlates) return [{ name: t, gcodePlates: o.gcodePlates, project: o }];
|
|
125
|
+
if (!i.length) throw new Error("No mesh in 3MF");
|
|
126
|
+
return i;
|
|
127
|
+
}
|
|
128
|
+
const y = /* @__PURE__ */ new WeakMap();
|
|
129
|
+
function rt(t, e) {
|
|
130
|
+
e === null || typeof e != "object" || y.has(e) || y.set(e, G(t, e));
|
|
131
|
+
}
|
|
132
|
+
async function G(t, e) {
|
|
133
|
+
const s = y.get(e);
|
|
134
|
+
if (s)
|
|
135
|
+
return y.delete(e), s;
|
|
136
|
+
const o = x(t);
|
|
137
|
+
if (o === "3mf") return z(t, e);
|
|
138
|
+
const i = await M(e);
|
|
139
|
+
switch (o) {
|
|
140
|
+
case "stl": {
|
|
141
|
+
const n = Y(i);
|
|
142
|
+
if (!n) throw new Error("Failed to parse STL");
|
|
143
|
+
return [{ name: t, modelPos: n }];
|
|
144
|
+
}
|
|
145
|
+
case "obj": {
|
|
146
|
+
const n = new B().parse(new TextDecoder().decode(i));
|
|
147
|
+
return k(t, F(n), !1);
|
|
148
|
+
}
|
|
149
|
+
case "ply": {
|
|
150
|
+
const n = new W().parse(i), a = S(n, null);
|
|
151
|
+
if (!a) throw new Error("No PLY geometry");
|
|
152
|
+
return [{ name: t, modelPos: a }];
|
|
153
|
+
}
|
|
154
|
+
case "amf": {
|
|
155
|
+
const n = new _().parse(i), a = k(t, F(n), !0);
|
|
156
|
+
if (!a.length) throw new Error("No mesh in AMF");
|
|
157
|
+
return a;
|
|
158
|
+
}
|
|
159
|
+
default: {
|
|
160
|
+
const n = P.get(o);
|
|
161
|
+
if (!n) throw new Error(`Unsupported format: .${o}`);
|
|
162
|
+
const a = await n(i, t);
|
|
163
|
+
if (!a?.length) throw new Error(`No mesh in .${o}`);
|
|
164
|
+
return a;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function ot(t) {
|
|
169
|
+
return H(t)?.map((e) => U(t, e)) ?? null;
|
|
170
|
+
}
|
|
171
|
+
function U(t, e) {
|
|
172
|
+
const s = new Float32Array(e.length * 9);
|
|
173
|
+
let o = 0;
|
|
174
|
+
for (const i of e) {
|
|
175
|
+
const n = i * 9;
|
|
176
|
+
for (let a = 0; a < 9; a++) s[o++] = t[n + a];
|
|
177
|
+
}
|
|
178
|
+
return s;
|
|
179
|
+
}
|
|
180
|
+
function H(t) {
|
|
181
|
+
const e = Math.floor(t.length / 9);
|
|
182
|
+
if (e < 2) return null;
|
|
183
|
+
const s = 1e4, o = /* @__PURE__ */ new Map(), i = new Int32Array(e * 3);
|
|
184
|
+
for (let r = 0; r < e; r++)
|
|
185
|
+
for (let f = 0; f < 3; f++) {
|
|
186
|
+
const d = r * 9 + f * 3, m = `${Math.round(t[d] * s)},${Math.round(t[d + 1] * s)},${Math.round(t[d + 2] * s)}`;
|
|
187
|
+
let g = o.get(m);
|
|
188
|
+
g === void 0 && (g = o.size, o.set(m, g)), i[r * 3 + f] = g;
|
|
189
|
+
}
|
|
190
|
+
const n = new Int32Array(e);
|
|
191
|
+
for (let r = 0; r < e; r++) n[r] = r;
|
|
192
|
+
const a = (r) => {
|
|
193
|
+
for (; n[r] !== r; )
|
|
194
|
+
n[r] = n[n[r]], r = n[r];
|
|
195
|
+
return r;
|
|
196
|
+
}, c = (r, f) => {
|
|
197
|
+
r = a(r), f = a(f), r !== f && (n[f] = r);
|
|
198
|
+
}, u = /* @__PURE__ */ new Map();
|
|
199
|
+
for (let r = 0; r < e; r++)
|
|
200
|
+
for (let f = 0; f < 3; f++) {
|
|
201
|
+
const d = i[r * 3 + f], m = i[r * 3 + (f + 1) % 3], g = d < m ? d * 4294967296 + m : m * 4294967296 + d, b = u.get(g);
|
|
202
|
+
b === void 0 ? u.set(g, r) : c(r, b);
|
|
203
|
+
}
|
|
204
|
+
const l = /* @__PURE__ */ new Map();
|
|
205
|
+
for (let r = 0; r < e; r++) {
|
|
206
|
+
const f = a(r);
|
|
207
|
+
let d = l.get(f);
|
|
208
|
+
d || (d = [], l.set(f, d)), d.push(r);
|
|
209
|
+
}
|
|
210
|
+
return l.size < 2 ? null : [...l.values()].sort((r, f) => f.length - r.length);
|
|
211
|
+
}
|
|
212
|
+
export {
|
|
213
|
+
N as G,
|
|
214
|
+
O as S,
|
|
215
|
+
E as a,
|
|
216
|
+
$ as b,
|
|
217
|
+
X as c,
|
|
218
|
+
T as d,
|
|
219
|
+
H as e,
|
|
220
|
+
x as f,
|
|
221
|
+
U as g,
|
|
222
|
+
Z as h,
|
|
223
|
+
ot as i,
|
|
224
|
+
G as l,
|
|
225
|
+
et as o,
|
|
226
|
+
rt as p,
|
|
227
|
+
nt as r,
|
|
228
|
+
C as s,
|
|
229
|
+
tt as w
|
|
230
|
+
};
|
package/dist/model_loaders.js
CHANGED
|
@@ -2,16 +2,21 @@ import "three";
|
|
|
2
2
|
import "three/examples/jsm/loaders/OBJLoader.js";
|
|
3
3
|
import "three/examples/jsm/loaders/PLYLoader.js";
|
|
4
4
|
import "three/examples/jsm/loaders/AMFLoader.js";
|
|
5
|
-
import "./parse_3mf-
|
|
5
|
+
import "./parse_3mf-6PLUgcZp.js";
|
|
6
6
|
import "./make_worker.js";
|
|
7
|
-
import { G as m, c as n,
|
|
7
|
+
import { G as m, c as n, d, h as l, g as E, f as c, l as f, o as C, p as P, r as T, e as x, i as L, w as S } from "./model_loaders-kvOxEvFT.js";
|
|
8
8
|
export {
|
|
9
9
|
m as GCODE_EXTS,
|
|
10
|
-
n as
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
E as
|
|
14
|
-
c as
|
|
15
|
-
f as
|
|
16
|
-
C as
|
|
10
|
+
n as SL1_EXT,
|
|
11
|
+
d as SUPPORTED_EXT,
|
|
12
|
+
l as adoptParseWorker,
|
|
13
|
+
E as facetPositions,
|
|
14
|
+
c as fileExt,
|
|
15
|
+
f as loadModel,
|
|
16
|
+
C as openableExtensions,
|
|
17
|
+
P as preloadModel,
|
|
18
|
+
T as registerLoader,
|
|
19
|
+
x as splitComponentFacets,
|
|
20
|
+
L as splitConnectedComponents,
|
|
21
|
+
S as warmLoaderFor
|
|
17
22
|
};
|