printbench 0.6.5 → 0.8.0

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.
Binary file
Binary file
@@ -0,0 +1,136 @@
1
+ import j from "jszip";
2
+ import { h as w, r as R } from "./index-Ci-Js4Ma.js";
3
+ function p(s, l) {
4
+ return s.match(new RegExp(`\\b${l}\\s*=\\s*"([^"]*)"`, "i"))?.[1];
5
+ }
6
+ function F(s) {
7
+ return s.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
8
+ }
9
+ function D(s) {
10
+ const l = /* @__PURE__ */ new Map(), o = /<basematerials\b([^>]*)>([\s\S]*?)<\/basematerials>/gi;
11
+ let i;
12
+ for (; i = o.exec(s); ) {
13
+ const t = Number(p(i[1], "id")), m = [], a = /<base\b([^>]*)\/?>/gi;
14
+ let n;
15
+ for (; n = a.exec(i[2]); ) {
16
+ const e = p(n[1], "displaycolor"), c = e ? w(e) : void 0;
17
+ c && m.push(c);
18
+ }
19
+ Number.isFinite(t) && m.length && l.set(t, m);
20
+ }
21
+ return l;
22
+ }
23
+ function C(s) {
24
+ const l = D(s), o = [], i = /<object\b([^>]*)>([\s\S]*?)<\/object>/gi;
25
+ let t;
26
+ for (; t = i.exec(s); ) {
27
+ const m = t[2];
28
+ if (!/<mesh\b/i.test(m)) continue;
29
+ const a = [], n = /<vertex\b([^>]*)\/?>/gi;
30
+ let e;
31
+ for (; e = n.exec(m); ) {
32
+ const f = Number(p(e[1], "x")), h = Number(p(e[1], "y")), x = Number(p(e[1], "z"));
33
+ [f, h, x].every(Number.isFinite) && a.push(f, h, x);
34
+ }
35
+ const c = [], d = /<triangle\b([^>]*)\/?>/gi;
36
+ let u;
37
+ const v = a.length / 3;
38
+ for (; u = d.exec(m); ) {
39
+ const f = Number(p(u[1], "v1")), h = Number(p(u[1], "v2")), x = Number(p(u[1], "v3"));
40
+ [f, h, x].every(($) => Number.isInteger($) && $ >= 0 && $ < v) && c.push(f, h, x);
41
+ }
42
+ if (v < 3 || c.length < 3) continue;
43
+ const r = p(t[1], "name"), g = Number(p(t[1], "pid")), b = Number(p(t[1], "pindex") ?? "0"), T = (Number.isFinite(g) ? l.get(g) : void 0)?.[Number.isFinite(b) ? b : 0];
44
+ o.push({
45
+ name: r ? F(r) : `part_${o.length + 1}`,
46
+ positions: Float32Array.from(a),
47
+ indices: Uint32Array.from(c),
48
+ printColor: T
49
+ });
50
+ }
51
+ return o;
52
+ }
53
+ function _(s, l, o, i) {
54
+ const t = s.map((n, e) => ` <basematerials id="${100 + e}">
55
+ <base name="${N(o?.[e] || `part_${e + 1}`)}" displaycolor="${R(i?.[e])}" />
56
+ </basematerials>`).join(`
57
+ `), m = s.map((n, e) => {
58
+ const c = [];
59
+ for (let r = 0; r < n.positions.length; r += 3)
60
+ c.push(` <vertex x="${n.positions[r]}" y="${n.positions[r + 1]}" z="${n.positions[r + 2]}" />`);
61
+ const d = [], u = n.positions.length / 3;
62
+ for (let r = 0; r < n.indices.length; r += 3) {
63
+ const g = n.indices[r], b = n.indices[r + 1], y = n.indices[r + 2];
64
+ g >= u || b >= u || y >= u || d.push(` <triangle v1="${g}" v2="${b}" v3="${y}" />`);
65
+ }
66
+ const v = N(o?.[e] || `part_${e + 1}`);
67
+ return ` <object id="${e + 1}" name="${v}" type="model" pid="${100 + e}" pindex="0">
68
+ <mesh>
69
+ <vertices>
70
+ ${c.join(`
71
+ `)}
72
+ </vertices>
73
+ <triangles>
74
+ ${d.join(`
75
+ `)}
76
+ </triangles>
77
+ </mesh>
78
+ </object>`;
79
+ }), a = s.map((n, e) => ` <item objectid="${e + 1}" />`).join(`
80
+ `);
81
+ return `<?xml version="1.0" encoding="UTF-8"?>
82
+ <model unit="millimeter" xml:lang="en-US" xmlns="http://schemas.microsoft.com/3dmanufacturing/core/2015/02">
83
+ <metadata name="Title">${N(l)}</metadata>
84
+ <metadata name="Application">PrintBench</metadata>
85
+ <resources>
86
+ ${t}
87
+ ${m.join(`
88
+ `)}
89
+ </resources>
90
+ <build>
91
+ ${a}
92
+ </build>
93
+ </model>
94
+ `;
95
+ }
96
+ function N(s) {
97
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
98
+ }
99
+ async function E(s, l = "PrintBench", o, i) {
100
+ const t = new j();
101
+ return t.file(
102
+ "[Content_Types].xml",
103
+ `<?xml version="1.0" encoding="UTF-8"?>
104
+ <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
105
+ <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
106
+ <Default Extension="model" ContentType="application/vnd.ms-package.3dmanufacturing-3dmodel+xml"/>
107
+ </Types>`
108
+ ), t.folder("_rels")?.file(
109
+ ".rels",
110
+ `<?xml version="1.0" encoding="UTF-8"?>
111
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
112
+ <Relationship Target="/3D/3dmodel.model" Id="rel0" Type="http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel"/>
113
+ </Relationships>`
114
+ ), t.folder("3D")?.file("3dmodel.model", _(s, l, o, i)), t.generateAsync({ type: "arraybuffer", compression: "DEFLATE" });
115
+ }
116
+ async function U(s) {
117
+ const o = (await j.loadAsync(s)).file("3D/3dmodel.model");
118
+ if (!o) return !1;
119
+ const i = await o.async("string");
120
+ if (!i.includes("<model") || !/unit\s*=\s*"millimeter"/.test(i)) return !1;
121
+ const t = (i.match(/<vertex\b/g) ?? []).length;
122
+ if (t < 3) return !1;
123
+ const m = /v1="(\d+)"\s+v2="(\d+)"\s+v3="(\d+)"/g;
124
+ let a, n = 0;
125
+ for (; a = m.exec(i); ) {
126
+ n++;
127
+ const e = Number(a[1]), c = Number(a[2]), d = Number(a[3]);
128
+ if (e >= t || c >= t || d >= t || e < 0 || c < 0 || d < 0) return !1;
129
+ }
130
+ return n > 0;
131
+ }
132
+ export {
133
+ E as export3mf,
134
+ C as parse3mfMeshObjects,
135
+ U as validate3mf
136
+ };
@@ -0,0 +1,30 @@
1
+ import { Group as w, Mesh as l, MeshStandardMaterial as u, DoubleSide as h, Color as c } from "three";
2
+ import { GLTFExporter as p } from "three/examples/jsm/exporters/GLTFExporter.js";
3
+ import { b as d } from "./index-Ci-Js4Ma.js";
4
+ async function G(r, e, n) {
5
+ const t = new w();
6
+ t.name = "PrintBench", r.forEach((f, o) => {
7
+ const m = d(f), s = n?.[o], i = new l(
8
+ m,
9
+ new u({
10
+ color: s ? new c().fromArray(s) : new c(9090303),
11
+ metalness: 0.08,
12
+ roughness: 0.55,
13
+ side: h
14
+ })
15
+ );
16
+ i.name = e?.[o] || `part_${o + 1}`, t.add(i);
17
+ });
18
+ const a = await new p().parseAsync(t, { binary: !0 });
19
+ if (!(a instanceof ArrayBuffer)) throw new Error("GLB 导出失败");
20
+ return a;
21
+ }
22
+ function A(r) {
23
+ if (r.byteLength < 12) return !1;
24
+ const e = String.fromCharCode(...new Uint8Array(r, 0, 4)), n = new DataView(r).getUint32(4, !0);
25
+ return e === "glTF" && n === 2;
26
+ }
27
+ export {
28
+ G as exportGlb,
29
+ A as validateGlb
30
+ };