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