@shopware-ag/dive
Version:
Shopware Spatial Framework
2 lines (1 loc) • 1.69 kB
JavaScript
;var i=Object.defineProperty;var c=(o,r,t)=>r in o?i(o,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[r]=t;var n=(o,r,t)=>c(o,typeof r!="symbol"?r+"":r,t);const p=require("three/webgpu"),u=require("three/examples/jsm/exporters/GLTFExporter.js"),f=require("three/examples/jsm/exporters/USDZExporter.js"),s=require("./parse-error-Dy_EE4rL.cjs");class x{constructor(){n(this,"_gltfExporter");n(this,"_usdzExporter");this._gltfExporter=new u.GLTFExporter,this._usdzExporter=new f.USDZExporter}async export(r,t,e){switch(this._computeNormals(r),t){case"glb":return this._exportGlb(r,e);case"gltf":return this._exportGltf(r,e);case"usdz":return this._exportUsdz(r,e);default:throw new s.FileTypeError(`Unsupported file type: ${t}`,t)}}async _exportGlb(r,t){try{const e=await this._gltfExporter.parseAsync(r,{animations:r.animations.length>0?r.animations:void 0,...t,binary:!0});if(e instanceof ArrayBuffer)return e;throw new s.ParseError("Failed to export GLB: expected ArrayBuffer")}catch(e){throw e instanceof s.ParseError?e:new s.ParseError("Failed to export GLB",e)}}async _exportGltf(r,t){try{const e=await this._gltfExporter.parseAsync(r,{animations:r.animations||[],...t,binary:!1}),a=JSON.stringify(e);return new TextEncoder().encode(a).buffer}catch(e){throw e instanceof s.ParseError?e:new s.ParseError("Failed to export GLTF",e)}}async _exportUsdz(r,t){try{return(await this._usdzExporter.parseAsync(r,t)).buffer}catch(e){throw e instanceof s.ParseError?e:new s.ParseError("Failed to export USDZ",e)}}_computeNormals(r){r.traverse(t=>{t instanceof p.Mesh&&t.geometry&&(t.geometry.getAttribute("normal")||t.geometry.computeVertexNormals())})}}exports.AssetExporter=x;