UNPKG

@shopware-ag/dive

Version:

Shopware Spatial Framework

68 lines (67 loc) 2.11 kB
var i = Object.defineProperty; var f = (s, r, e) => r in s ? i(s, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[r] = e; var n = (s, r, e) => f(s, typeof r != "symbol" ? r + "" : r, e); import { Mesh as p } from "three/webgpu"; import { GLTFExporter as c } from "three/examples/jsm/exporters/GLTFExporter.js"; import { USDZExporter as x } from "three/examples/jsm/exporters/USDZExporter.js"; import { F as u, P as o } from "./parse-error-DfOPyLWM.mjs"; class E { constructor() { n(this, "_gltfExporter"); n(this, "_usdzExporter"); this._gltfExporter = new c(), this._usdzExporter = new x(); } async export(r, e, t) { switch (this._computeNormals(r), e) { case "glb": return this._exportGlb(r, t); case "gltf": return this._exportGltf(r, t); case "usdz": return this._exportUsdz(r, t); default: throw new u(`Unsupported file type: ${e}`, e); } } async _exportGlb(r, e) { try { const t = await this._gltfExporter.parseAsync(r, { animations: r.animations.length > 0 ? r.animations : void 0, ...e, binary: !0 }); if (t instanceof ArrayBuffer) return t; throw new o("Failed to export GLB: expected ArrayBuffer"); } catch (t) { throw t instanceof o ? t : new o("Failed to export GLB", t); } } async _exportGltf(r, e) { try { const t = await this._gltfExporter.parseAsync(r, { animations: r.animations || [], ...e, binary: !1 }), a = JSON.stringify(t); return new TextEncoder().encode(a).buffer; } catch (t) { throw t instanceof o ? t : new o("Failed to export GLTF", t); } } async _exportUsdz(r, e) { try { return (await this._usdzExporter.parseAsync(r, e)).buffer; } catch (t) { throw t instanceof o ? t : new o("Failed to export USDZ", t); } } _computeNormals(r) { r.traverse((e) => { e instanceof p && e.geometry && (e.geometry.getAttribute("normal") || e.geometry.computeVertexNormals()); }); } } export { E as A };