babylonjs-serializers 9.16.0 → 9.16.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.
- package/babylon.objSerializer.js +1 -1
- package/babylon.objSerializer.js.map +1 -1
- package/babylon.objSerializer.min.js +1 -1
- package/babylon.objSerializer.min.js.map +1 -1
- package/babylonjs.serializers.d.ts +2 -1
- package/babylonjs.serializers.js +1 -1
- package/babylonjs.serializers.js.map +1 -1
- package/babylonjs.serializers.min.js +1 -1
- package/babylonjs.serializers.min.js.map +1 -1
- package/babylonjs.serializers.module.d.ts +4 -2
- package/package.json +3 -3
package/babylonjs.serializers.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("babylonjs")):"function"==typeof define&&define.amd?define(["exports","babylonjs"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).BABYLON=e.BABYLON||{},e.BABYLON)}(this,function(e,t){"use strict";class n{static OBJ(e,n,s,r){const i=[];let o=1,a=1;n&&(s||(s="mat"),i.push("mtllib "+s+".mtl"));for(let s=0;s<e.length;s++){const l=e[s],u=l.name||`mesh${s}}`;i.push(`o ${u}`);let c=null;if(r){const e=l.computeWorldMatrix(!0);c=new t.Matrix,e.invertToRef(c),l.bakeTransformIntoVertices(e)}if(n){const e=l.material;e&&i.push("usemtl "+e.id)}const h=l.geometry;if(!h){t.Tools.Warn("No geometry is present on the mesh");continue}const d=h.getVerticesData("position"),f=h.getVerticesData("normal"),p=h.getVerticesData("uv"),m=h.getIndices();let g=0,x=0;if(!d||!m){t.Tools.Warn("There are no position vertices or indices on the mesh!");continue}const _=e[0].getScene().useRightHandedSystem?1:-1;for(let e=0;e<d.length;e+=3)i.push("v "+d[e]*_+" "+d[e+1]+" "+d[e+2]),g++;if(null!=f)for(let e=0;e<f.length;e+=3)i.push("vn "+f[e]*_+" "+f[e+1]+" "+f[e+2]);if(null!=p)for(let e=0;e<p.length;e+=2)i.push("vt "+p[e]+" "+p[e+1]),x++;const T=["","",""],y=(l.material||l.getScene().defaultMaterial)._getEffectiveOrientation(l),[b,v]=y===t.Material.ClockWiseSideOrientation?[2,1]:[1,2];for(let e=0;e<m.length;e+=3){const t=[String(m[e]+o),String(m[e+b]+o),String(m[e+v]+o)],n=[String(m[e]+a),String(m[e+b]+a),String(m[e+v]+a)],s=t,r=null!=p?n:T,l=null!=f?t:T;i.push("f "+s[0]+"/"+r[0]+"/"+l[0]+" "+s[1]+"/"+r[1]+"/"+l[1]+" "+s[2]+"/"+r[2]+"/"+l[2])}r&&c&&l.bakeTransformIntoVertices(c),o+=g,a+=x}return i.join("\n")}static MTL(e){const t=[],n=e.material;return t.push("newmtl mat1"),t.push(" Ns "+n.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+n.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+n.ambientColor.r.toFixed(4)+" "+n.ambientColor.g.toFixed(4)+" "+n.ambientColor.b.toFixed(4)),t.push(" Kd "+n.diffuseColor.r.toFixed(4)+" "+n.diffuseColor.g.toFixed(4)+" "+n.diffuseColor.b.toFixed(4)),t.push(" Ks "+n.specularColor.r.toFixed(4)+" "+n.specularColor.g.toFixed(4)+" "+n.specularColor.b.toFixed(4)),t.push(" Ke "+n.emissiveColor.r.toFixed(4)+" "+n.emissiveColor.g.toFixed(4)+" "+n.emissiveColor.b.toFixed(4)),n.ambientTexture&&t.push(" map_Ka "+n.ambientTexture.name),n.diffuseTexture&&t.push(" map_Kd "+n.diffuseTexture.name),n.specularTexture&&t.push(" map_Ks "+n.specularTexture.name),n.bumpTexture&&t.push(" map_bump -imfchan z "+n.bumpTexture.name),n.opacityTexture&&t.push(" map_d "+n.opacityTexture.name),t.join("\n")}}var s={__proto__:null,OBJExport:n},r={__proto__:null,__IGLTFExporterExtension:0};class i{constructor(){this.files={}}get glTFFiles(){return this.files}downloadFiles(){for(const e in this.files){const n=this.files[e],s=new Blob([n],{type:t.GetMimeType(e)});t.Tools.Download(s,e)}}}var o={__proto__:null,GLTFData:i};function a(e,t,n,s,r,i){function o(e){if(void 0!==e&&"function"!=typeof e)throw new TypeError("Function expected");return e}for(var a,l=s.kind,u="getter"===l?"get":"setter"===l?"set":"value",c=!t&&e?s.static?e:e.prototype:null,h=t||(c?Object.getOwnPropertyDescriptor(c,s.name):{}),d=!1,f=n.length-1;f>=0;f--){var p={};for(var m in s)p[m]="access"===m?{}:s[m];for(var m in s.access)p.access[m]=s.access[m];p.addInitializer=function(e){if(d)throw new TypeError("Cannot add initializers after decoration has completed");i.push(o(e||null))};var g=(0,n[f])("accessor"===l?{get:h.get,set:h.set}:h[u],p);if("accessor"===l){if(void 0===g)continue;if(null===g||"object"!=typeof g)throw new TypeError("Object expected");(a=o(g.get))&&(h.get=a),(a=o(g.set))&&(h.set=a),(a=o(g.init))&&r.unshift(a)}else(a=o(g))&&("field"===l?r.unshift(a):h[u]=a)}c&&Object.defineProperty(c,s.name,h),d=!0}function l(e,t,n){for(var s=arguments.length>2,r=0;r<t.length;r++)n=s?t[r].call(e,n):t[r].call(e);return s?n:void 0}function u(e,t,n){return"symbol"==typeof t&&(t=t.description?"[".concat(t.description,"]"):""),Object.defineProperty(e,"name",{configurable:!0,value:n?"".concat(n," ",t):t})}function c(e,t,n,s){return new(n||(n=Promise))(function(r,i){function o(e){try{l(s.next(e))}catch(e){i(e)}}function a(e){try{l(s.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,a)}l((s=s.apply(e,t||[])).next())})}function h(e){return c(this,void 0,void 0,function*(){var n;const s=e.getInternalTexture();if(!s||1!==s.source)return null;if(s.invertY&&!((null===(n=e.getScene())||void 0===n?void 0:n.getEngine())instanceof t.NullEngine))return null;const r=s._buffer;let i,o=e.mimeType;try{r?ArrayBuffer.isView(r)?i=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength):r instanceof ArrayBuffer?i=r:r instanceof Blob?(i=yield r.arrayBuffer(),o=r.type||o):"string"==typeof r?(i=yield t.Tools.LoadFileAsync(r),o=t.GetMimeType(r)||o):"undefined"!=typeof HTMLImageElement&&r instanceof HTMLImageElement&&(i=yield t.Tools.LoadFileAsync(r.src),o=t.GetMimeType(r.src)||o):(i=yield t.Tools.LoadFileAsync(s.url),o=t.GetMimeType(s.url)||o)}catch(e){return null}if(i&&!o&&s.url){const e=s.url.match(/^data:([^;,]+)/);o=e?e[1]:t.GetMimeType(s.url)}return i&&o?{data:i,mimeType:o}:null})}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;const d=1e-6,f=new t.Color3(.04,.04,.04),p=t.Color3.White(),m=t.Color3.BlackReadOnly;function g(e){switch(e){case"image/jpeg":case"image/png":case"image/webp":case"image/avif":case"image/ktx2":return!0;default:return!1}}function x(e,n,s){if(n<f.r)return 0;const r=f.r,i=e*s/(1-f.r)+n-2*f.r,o=i*i-4*r*(f.r-n);return t.Scalar.Clamp((-i+Math.sqrt(o))/(2*r),0,1)}function _(e){const n=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),s=e.alpha,r=t.Scalar.Clamp(e.specularPower,0,1024),i=t.SpecularPowerToRoughness(r);return{baseColorFactor:[n.r,n.g,n.b,s],metallicFactor:0,roughnessFactor:i}}function T(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function y(e,n,s){const r=new Uint8Array(e*n*4);for(let e=0;e<r.length;e+=4)r[e]=r[e+1]=r[e+2]=r[e+3]=255;return t.RawTexture.CreateRGBATexture(r,e,n,s)}function b(e){if(e instanceof Uint8Array){const t=e.length,n=new Float32Array(e.length);for(let s=0;s<t;++s)n[s]=e[s]/255;return n}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")}class v{constructor(e){this._exporter=e,this._textureMap=new Map,this._internalTextureToImage={}}getTextureInfo(e){var t;return e&&null!==(t=this._textureMap.get(e.uniqueId))&&void 0!==t?t:null}exportStandardMaterialAsync(e,n){return c(this,void 0,void 0,function*(){const s=_(e),r={name:e.name};if(null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||t.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),n){const t=[],n=e.diffuseTexture;n&&t.push(this.exportTextureAsync(n).then(e=>{e&&(s.baseColorTexture=e)}));const i=e.bumpTexture;i&&t.push(this.exportTextureAsync(i).then(e=>{e&&(r.normalTexture=e,1!==i.level&&(r.normalTexture.scale=i.level))}));const o=e.emissiveTexture;o&&(r.emissiveFactor=[1,1,1],t.push(this.exportTextureAsync(o).then(e=>{e&&(r.emissiveTexture=e)})));const a=e.ambientTexture;a&&t.push(this.exportTextureAsync(a).then(e=>{if(e){const t={index:e.index};r.occlusionTexture=t}})),t.length>0&&(this._exporter._materialNeedsUVsSet.add(e),yield Promise.all(t))}(e.alpha<1||e.opacityTexture)&&(e.alphaMode===t.Constants.ALPHA_COMBINE?r.alphaMode="BLEND":t.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(m,d)&&(r.emissiveFactor=e.emissiveColor.asArray()),r.pbrMetallicRoughness=s,T(r,e),yield this._finishMaterialAsync(r,e);const i=this._exporter._materials;return i.push(r),i.length-1})}_finishMaterialAsync(e,t){return c(this,void 0,void 0,function*(){const n=yield this._exporter._extensionsPostExportMaterialAdditionalTexturesAsync("exportMaterial",e,t),s=[];for(const e of n)s.push(this.exportTextureAsync(e));yield Promise.all(s),yield this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)})}_resizeTexturesToSameDimensions(e,n,s){const r=e?e.getSize():{width:0,height:0},i=n?n.getSize():{width:0,height:0};let o,a;return r.width<i.width?(o=e&&e instanceof t.Texture?t.TextureTools.CreateResizedCopy(e,i.width,i.height,!0):y(i.width,i.height,s),a=n):r.width>i.width?(a=n&&n instanceof t.Texture?t.TextureTools.CreateResizedCopy(n,r.width,r.height,!0):y(r.width,r.height,s),o=e):(o=e,a=n),{texture1:o,texture2:a}}_convertSpecularGlossinessTexturesToMetallicRoughnessAsync(e,n,s){return c(this,void 0,void 0,function*(){var r;const i=new Array;if(!e&&!n)return yield Promise.reject("diffuse and specular glossiness textures are not defined!");const o=e?e.getScene():n?n.getScene():null;if(o){const a=this._resizeTexturesToSameDimensions(e,n,o),l=null===(r=a.texture1)||void 0===r?void 0:r.getSize();let u,c;const h=l.width,f=l.height,m=yield a.texture1.readPixels(),g=yield a.texture2.readPixels();if(!m)return yield Promise.reject("Failed to retrieve pixels from diffuse texture!");if(u=b(m),!g)return yield Promise.reject("Failed to retrieve pixels from specular glossiness texture!");c=b(g);const x=c.byteLength,_=new Uint8Array(x),T=new Uint8Array(x),y=4,v=new t.Color3(0,0,0);let M=0,w=0;for(let e=0;e<f;++e)for(let n=0;n<h;++n){const r=(h*e+n)*y,i={diffuseColor:new t.Color3(u[r],u[r+1],u[r+2]).toLinearSpace(o.getEngine().useExactSrgbConversions).multiply(s.diffuseColor),specularColor:new t.Color3(c[r],c[r+1],c[r+2]).toLinearSpace(o.getEngine().useExactSrgbConversions).multiply(s.specularColor),glossiness:c[r+3]*s.glossiness},l=this._convertSpecularGlossinessToMetallicRoughness(i);v.r=Math.max(v.r,l.baseColor.r),v.g=Math.max(v.g,l.baseColor.g),v.b=Math.max(v.b,l.baseColor.b),M=Math.max(M,l.metallic),w=Math.max(w,l.roughness),T[r]=255*l.baseColor.r,T[r+1]=255*l.baseColor.g,T[r+2]=255*l.baseColor.b,T[r+3]=a.texture1.hasAlpha?255*u[r+3]:255,_[r]=0,_[r+1]=255*l.roughness,_[r+2]=255*l.metallic,_[r+3]=255}const R={baseColor:v,metallic:M,roughness:w};let A=!1,C=!1;for(let e=0;e<f;++e)for(let n=0;n<h;++n){const s=(h*e+n)*y;T[s]/=R.baseColor.r>d?R.baseColor.r:1,T[s+1]/=R.baseColor.g>d?R.baseColor.g:1,T[s+2]/=R.baseColor.b>d?R.baseColor.b:1;const r=t.Color3.FromInts(T[s],T[s+1],T[s+2]).toGammaSpace(o.getEngine().useExactSrgbConversions);T[s]=255*r.r,T[s+1]=255*r.g,T[s+2]=255*r.b,r.equalsWithEpsilon(p,d)||(C=!0),_[s+1]/=R.roughness>d?R.roughness:1,_[s+2]/=R.metallic>d?R.metallic:1,t.Color3.FromInts(255,_[s+1],_[s+2]).equalsWithEpsilon(p,d)||(A=!0)}return A&&i.push(t.EncodeImageAsync(_,h,f).then(e=>{R.metallicRoughnessTextureData=e})),C&&i.push(t.EncodeImageAsync(T,h,f).then(e=>{R.baseColorTextureData=e})),yield Promise.all(i).then(()=>R)}return yield Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")})}_convertSpecularGlossinessToMetallicRoughness(e){const n=this._getPerceivedBrightness(e.diffuseColor),s=this._getPerceivedBrightness(e.specularColor),r=1-this._getMaxComponent(e.specularColor),i=x(n,s,r),o=e.diffuseColor.scale(r/(1-f.r)/Math.max(1-i,d)),a=e.specularColor.subtract(f.scale(1-i)).scale(1/Math.max(i,d));let l=t.Color3.Lerp(o,a,i*i);return l=l.clampToRef(0,1,l),{baseColor:l,metallic:i,roughness:1-e.glossiness}}_getPerceivedBrightness(e){return Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b)}_getMaxComponent(e){return Math.max(e.r,Math.max(e.g,e.b))}_convertMetalRoughFactorsToMetallicRoughnessAsync(e,n,s,r,i,o,a,l,u){return c(this,void 0,void 0,function*(){const h=[],d={baseColor:e,metallic:n,roughness:s};if(u)if(a instanceof t.OpenPBRMaterial){if(a.geometryOpacityTexture){const e=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:0,n=a.geometryOpacityTexture&&a.geometryOpacityTexture.getInternalTexture()?a.geometryOpacityTexture.getInternalTexture().uniqueId:0,s=Number(`${e}${n}`),i=this._textureMap.get(s);i?l.baseColorTexture=i:h.push(t.MergeTexturesAsync("baseColorOpacityTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),r?t.CreateTextureInput(r,1):t.CreateConstantInput(1),r?t.CreateTextureInput(r,2):t.CreateConstantInput(1),t.CreateTextureInput(a.geometryOpacityTexture,0)),a.getScene()).then(e=>c(this,void 0,void 0,function*(){const t=yield this.exportTextureAsync(e,s);t&&(l.baseColorTexture=t)})))}else r&&h.push(this.exportTextureAsync(r).then(e=>{e&&(l.baseColorTexture=e)}));if(a._useMetallicFromMetallicTextureBlue&&i)h.push(this.exportTextureAsync(i).then(e=>{e&&(l.metallicRoughnessTexture=e)}));else if(o||i){const e=i&&i.getInternalTexture()?i.getInternalTexture().uniqueId:0,n=o&&o.getInternalTexture()?o.getInternalTexture().uniqueId:0,s=Number(`${e}${n}`),r=this._textureMap.get(s);r?l.metallicRoughnessTexture=r:h.push(t.MergeTexturesAsync("MetalRoughTexture",t.CreateRGBAConfiguration(a.ambientOcclusionTexture?t.CreateTextureInput(a.ambientOcclusionTexture,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,0):t.CreateConstantInput(1),i?t.CreateTextureInput(i,0):t.CreateConstantInput(1)),a.getScene()).then(e=>c(this,void 0,void 0,function*(){const t=yield this.exportTextureAsync(e,s);t&&(l.metallicRoughnessTexture=t)})))}}else r&&h.push(this.exportTextureAsync(r).then(e=>{e&&(l.baseColorTexture=e)})),i&&h.push(this.exportTextureAsync(i).then(e=>{e&&(l.metallicRoughnessTexture=e)}));return h.length>0&&(this._exporter._materialNeedsUVsSet.add(a),yield Promise.all(h)),d})}_getTextureSampler(e){const n={};if(!(e&&e instanceof t.Texture))return n;const s=this._getGLTFTextureWrapMode(e.wrapU);10497!==s&&(n.wrapS=s);const r=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==r&&(n.wrapT=r),e.samplingMode){case t.Texture.LINEAR_LINEAR:n.magFilter=9729,n.minFilter=9729;break;case t.Texture.LINEAR_NEAREST:n.magFilter=9729,n.minFilter=9728;break;case t.Texture.NEAREST_LINEAR:n.magFilter=9728,n.minFilter=9729;break;case t.Texture.NEAREST_LINEAR_MIPLINEAR:n.magFilter=9728,n.minFilter=9987;break;case t.Texture.NEAREST_NEAREST:n.magFilter=9728,n.minFilter=9728;break;case t.Texture.NEAREST_LINEAR_MIPNEAREST:n.magFilter=9728,n.minFilter=9985;break;case t.Texture.LINEAR_NEAREST_MIPNEAREST:n.magFilter=9729,n.minFilter=9984;break;case t.Texture.LINEAR_NEAREST_MIPLINEAR:n.magFilter=9729,n.minFilter=9986;break;case t.Texture.NEAREST_NEAREST_MIPLINEAR:n.magFilter=9728,n.minFilter=9986;break;case t.Texture.LINEAR_LINEAR_MIPLINEAR:n.magFilter=9729,n.minFilter=9987;break;case t.Texture.LINEAR_LINEAR_MIPNEAREST:n.magFilter=9729,n.minFilter=9985;break;case t.Texture.NEAREST_NEAREST_MIPNEAREST:n.magFilter=9728,n.minFilter=9984}return n}_getGLTFTextureWrapMode(e){switch(e){case t.Texture.WRAP_ADDRESSMODE:return 10497;case t.Texture.CLAMP_ADDRESSMODE:return 33071;case t.Texture.MIRROR_ADDRESSMODE:return 33648;default:return t.Tools.Error(`Unsupported Texture Wrap Mode ${e}!`),10497}}_convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,n){return c(this,void 0,void 0,function*(){const s={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},r=e._albedoTexture,i=e._reflectivityTexture,o=e._useMicroSurfaceFromReflectivityMapAlpha;if(i&&!o)return yield Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported");if((r||i)&&n){this._exporter._materialNeedsUVsSet.add(e);const n=this._exportTextureSampler(r||i),o=yield this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(r,i,s),a=this._exporter._textures;if(o.baseColorTextureData){const e=yield this._exportImageAsync(`baseColor${a.length}`,o.baseColorTextureData);t.baseColorTexture=this._exportTextureInfo(e,n,null==r?void 0:r.coordinatesIndex)}if(o.metallicRoughnessTextureData){const e=yield this._exportImageAsync(`metallicRoughness${a.length}`,o.metallicRoughnessTextureData);t.metallicRoughnessTexture=this._exportTextureInfo(e,n,null==i?void 0:i.coordinatesIndex)}return o}return this._convertSpecularGlossinessToMetallicRoughness(s)})}exportPBRMaterialAsync(e,t){return c(this,void 0,void 0,function*(){const n={},s={name:e.name},r=e.isMetallicWorkflow();if(r){const t=e._albedoColor,s=e.alpha;t&&(n.baseColorFactor=[t.r,t.g,t.b,s])}const i=r?yield this._convertMetalRoughFactorsToMetallicRoughnessAsync(e._albedoColor,e._metallic,e._roughness,e._albedoTexture,e._metallicTexture,e._metallicTexture,e,n,t):yield this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,n,t);yield this._setMetallicRoughnessPbrMaterialAsync(i,e,s,n,t),yield this._finishMaterialAsync(s,e);const o=this._exporter._materials;return o.push(s),o.length-1})}_setMetallicRoughnessPbrMaterialAsync(e,n,s,r,i){return c(this,void 0,void 0,function*(){if(T(s,n),e.baseColor.equalsWithEpsilon(p,d)&&t.Scalar.WithinEpsilon(n.alpha,1,d)||(r.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,n.alpha]),null!=e.metallic&&1!==e.metallic&&(r.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(r.roughnessFactor=e.roughness),null==n.backFaceCulling||n.backFaceCulling||(n._twoSidedLighting||t.Tools.Warn(n.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),s.doubleSided=!0),i){const e=[],i=n instanceof t.PBRBaseMaterial?n._bumpTexture:n.geometryNormalTexture;i&&e.push(this.exportTextureAsync(i).then(e=>{e&&(s.normalTexture=e,1!==i.level&&(s.normalTexture.scale=i.level))}));const o=n instanceof t.PBRBaseMaterial?n._ambientTexture:n.ambientOcclusionTexture;o&&e.push(new Promise(e=>c(this,void 0,void 0,function*(){if(n instanceof t.OpenPBRMaterial&&r.metallicRoughnessTexture){const t=this._exportTextureSampler(o),n=this._exporter._textures[r.metallicRoughnessTexture.index].source,s=this._exportTextureInfo(n,t,o.coordinatesIndex);return this._textureMap.set(o.uniqueId,s),this._exporter._extensionsPostExportTextures("exporter",s,o),e(s)}return e(yield this.exportTextureAsync(o))})).then(e=>c(this,void 0,void 0,function*(){if(e){const r={index:e.index,texCoord:e.texCoord,extensions:e.extensions};s.occlusionTexture=r,n instanceof t.PBRBaseMaterial?r.strength=n._ambientTextureStrength:r.strength=n.ambientOcclusionTexture.level}})));const a=n instanceof t.PBRBaseMaterial?n._emissiveTexture:n.emissionColorTexture;a&&e.push(this.exportTextureAsync(a).then(e=>{e&&(s.emissiveTexture=e)})),e.length>0&&(this._exporter._materialNeedsUVsSet.add(n),yield Promise.all(e))}const o=n instanceof t.PBRBaseMaterial?n._emissiveColor:n.emissionColor;o.equalsWithEpsilon(m,d)||(s.emissiveFactor=o.asArray()),s.pbrMetallicRoughness=r})}exportOpenPBRMaterialAsync(e,t){return c(this,void 0,void 0,function*(){const n={},s={name:e.name},r=e.baseColor,i=e.geometryOpacity;r&&(n.baseColorFactor=[r.r,r.g,r.b,i]);const o=yield this._convertMetalRoughFactorsToMetallicRoughnessAsync(e.baseColor,e.baseMetalness,e.specularRoughness,e.baseColorTexture,e.baseMetalnessTexture,e.specularRoughnessTexture,e,n,t);yield this._setMetallicRoughnessPbrMaterialAsync(o,e,s,n,t),yield this._finishMaterialAsync(s,e);const a=this._exporter._materials;return a.push(s),a.length-1})}exportTextureAsync(e){return c(this,arguments,void 0,function*(e,t=null){let n=this._textureMap.get(null!=t?t:e.uniqueId);if(n)return n;const s=this._exportTextureSampler(e),r=yield this._exportTextureImageAsync(e);return n=this._exportTextureInfo(r,s,e.coordinatesIndex),this._textureMap.set(null!=t?t:e.uniqueId,n),this._exporter._extensionsPostExportTextures("exporter",n,e),n})}_exportTextureImageAsync(e){return c(this,void 0,void 0,function*(){var n;const s=null!==(n=e.mimeType)&&void 0!==n?n:"none",r=this._internalTextureToImage,i=e.getInternalTexture().uniqueId;r[i]=r[i]||{};let o=r[i][s];return void 0===o&&(o=(()=>c(this,void 0,void 0,function*(){const n=yield h(e);if(n&&g(n.mimeType)&&("none"===s||n.mimeType===s))return yield this._exportImageAsync(e.name,new Blob([n.data],{type:n.mimeType}));let r="image/png";"none"!==s&&(g(s)?r=s:(r="image/png",t.Tools.Warn(`Unsupported media type: ${s}. Exporting texture as PNG.`)));const i=e.getSize(),o=yield t.GetTextureDataAsync(e),a=yield t.EncodeImageAsync(o,i.width,i.height,r);return yield this._exportImageAsync(e.name,a)}))(),r[i][s]=o),yield o})}_exportImageAsync(e,n){return c(this,void 0,void 0,function*(){const s=this._exporter._images;let r;if(this._exporter._shouldUseGlb){r={name:e,mimeType:n.type,bufferView:void 0};const t=yield n.arrayBuffer(),s=this._exporter._bufferManager.createBufferView(new Uint8Array(t));this._exporter._bufferManager.setBufferView(r,s)}else{const i=e.replace(/\.\/|\/|\.\\|\\/g,"_"),o=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp";case"image/avif":return".avif";case"image/ktx2":return".ktx2"}}(n.type);let a=i+o;s.some(e=>e.uri===a)&&(a=`${i}_${t.Tools.RandomId()}${o}`),r={name:e,uri:a},this._exporter._imageData[a]=n}return s.push(r),s.length-1})}_exportTextureInfo(e,t,n){const s=this._exporter._textures;let r=s.findIndex(n=>n.sampler==t&&n.source===e);-1===r&&(r=s.length,s.push({source:e,sampler:t}));const i={index:r};return n&&(i.texCoord=n),i}_exportTextureSampler(e){const t=this._getTextureSampler(e),n=this._exporter._samplers,s=n.findIndex(e=>e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT);return-1!==s?s:(n.push(t),n.length-1)}}const M=t.Matrix.Compose(new t.Vector3(-1,1,1),t.Quaternion.Identity(),t.Vector3.Zero());function w(e,n){if(!(e instanceof t.TransformNode))return!1;if(n){if(!e.getWorldMatrix().equalsWithEpsilon(t.Matrix.IdentityReadOnly,t.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(M,t.TmpVectors.Matrix[0]).equalsWithEpsilon(t.Matrix.IdentityReadOnly,t.Epsilon))return!1;return!(e instanceof t.AbstractMesh&&e.geometry)}const R=t.Vector3.ZeroReadOnly,A=t.Quaternion.Identity(),C=t.Vector3.OneReadOnly,E=new t.Vector3(-1,1,1);function I(e,t){const{byteOffset:n,byteStride:s,type:r,normalized:i}=e,o=e.getSize(),a=t.reduce((e,t)=>t.getTotalVertices()>e?t.getTotalVertices():e,-Number.MAX_VALUE);return{byteOffset:n,byteStride:s,componentCount:o,type:r,count:a*o,normalized:i,totalVertices:a,kind:e.getKind()}}function S(e){switch(e){case"MAT2":case"VEC4":return 4;case"MAT3":return 9;case"MAT4":return 16;case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3}}function V(e){return e.some(e=>e>=256)}function F(e){switch(e){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:case t.VertexBuffer.ColorKind:case t.VertexBuffer.MatricesIndicesKind:case t.VertexBuffer.MatricesIndicesExtraKind:case t.VertexBuffer.MatricesWeightsKind:case t.VertexBuffer.MatricesWeightsExtraKind:case t.VertexBuffer.UVKind:case t.VertexBuffer.UV2Kind:case t.VertexBuffer.UV3Kind:case t.VertexBuffer.UV4Kind:case t.VertexBuffer.UV5Kind:case t.VertexBuffer.UV6Kind:return!0}return!1}function O(e){const t=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);t>0&&(e.x/=t,e.y/=t,e.z/=t)}function B(e){return e.x*=-1,e}function N(e){return M.invertToRef(t.TmpVectors.Matrix[0]).multiplyToRef(e,e).multiplyToRef(M,e),e}function P(e){if(e.x*e.x+e.y*e.y>.5){const t=Math.abs(e.x),n=Math.abs(e.y);if(t>n){const n=Math.sign(e.x);e.x=t,e.y*=-n,e.z*=-n,e.w*=n}else{const t=Math.sign(e.y);e.x*=-t,e.y=n,e.z*=t,e.w*=-t}}else{const t=Math.abs(e.z),n=Math.abs(e.w);if(t>n){const n=Math.sign(e.z);e.x*=-n,e.y*=n,e.z=t,e.w*=-n}else{const t=Math.sign(e.w);e.x*=t,e.y*=-t,e.z*=-t,e.w=n}}return e}function U(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function k(e,n){const s=t.Vector3.FromArrayToRef(n.translation||[0,0,0],0,t.TmpVectors.Vector3[0]),r=t.Quaternion.FromArrayToRef(n.rotation||[0,0,0,1],0,t.TmpVectors.Quaternion[0]),i=t.Matrix.ComposeToRef(C,r,s,t.TmpVectors.Matrix[0]),o=t.Vector3.FromArrayToRef(e.translation||[0,0,0],0,t.TmpVectors.Vector3[2]),a=t.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,t.TmpVectors.Quaternion[1]),l=t.Matrix.ComposeToRef(C,a,o,t.TmpVectors.Matrix[1]);i.multiplyToRef(l,l),l.decompose(void 0,r,s),s.equalsWithEpsilon(R,t.Epsilon)?delete n.translation:n.translation=s.asArray(),r.equalsWithEpsilon(A,t.Epsilon)?delete n.rotation:n.rotation=r.asArray(),n.scale&&delete n.scale}function K(e,n){if(!(n instanceof t.TransformNode))return!1;if(1!==n.getChildren().length||0!==e.getChildren().length||e.parent!==n)return!1;const s=e.getScene(),r=e instanceof t.TargetCamera&&!s.useRightHandedSystem?E:C;return!!n.scaling.equalsWithEpsilon(r,t.Epsilon)||(t.Logger.Warn(`Cannot collapse node ${e.name} into parent node ${n.name} with modified scaling.`),!1)}function $(e){if(e instanceof Array){const t=new Float32Array(e);return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}return ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e)}function z(e,t){for(const[n,s]of Object.entries(e)){const r=t[n];(Array.isArray(s)&&Array.isArray(r)&&W(s,r)||s===r)&&delete e[n]}return e}function W(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}const D=new Map([[Int8Array,(e,t,n)=>e.setInt8(t,n)],[Uint8Array,(e,t,n)=>e.setUint8(t,n)],[Uint8ClampedArray,(e,t,n)=>e.setUint8(t,n)],[Int16Array,(e,t,n)=>e.setInt16(t,n,!0)],[Uint16Array,(e,t,n)=>e.setUint16(t,n,!0)],[Int32Array,(e,t,n)=>e.setInt32(t,n,!0)],[Uint32Array,(e,t,n)=>e.setUint32(t,n,!0)],[Float32Array,(e,t,n)=>e.setFloat32(t,n,!0)],[Float64Array,(e,t,n)=>e.setFloat64(t,n,!0)]]);class L{writeTypedArray(e){this._checkGrowBuffer(e.byteLength);const t=D.get(e.constructor);for(let n=0;n<e.length;n++)t(this._dataView,this._byteOffset,e[n]),this._byteOffset+=e.BYTES_PER_ELEMENT}constructor(e){this._data=new Uint8Array(e),this._dataView=new DataView(this._data.buffer),this._byteOffset=0}get byteOffset(){return this._byteOffset}getOutputData(){return new Uint8Array(this._data.buffer,0,this._byteOffset)}writeUInt8(e){this._checkGrowBuffer(1),this._dataView.setUint8(this._byteOffset,e),this._byteOffset++}writeInt8(e){this._checkGrowBuffer(1),this._dataView.setInt8(this._byteOffset,e),this._byteOffset++}writeInt16(e){this._checkGrowBuffer(2),this._dataView.setInt16(this._byteOffset,e,!0),this._byteOffset+=2}writeUInt16(e){this._checkGrowBuffer(2),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2}writeInt32(e){this._checkGrowBuffer(4),this._dataView.setInt32(this._byteOffset,e,!0),this._byteOffset+=4}writeUInt32(e){this._checkGrowBuffer(4),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4}writeFloat32(e){this._checkGrowBuffer(4),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4}writeFloat64(e){this._checkGrowBuffer(8),this._dataView.setFloat64(this._byteOffset,e,!0),this._byteOffset+=8}_checkGrowBuffer(e){const t=this.byteOffset+e;if(t>this._data.byteLength){const e=new Uint8Array(2*t);e.set(this._data),this._data=e,this._dataView=new DataView(this._data.buffer)}}}function H(e){return e%4==0?4:e%2==0?2:1}class j{constructor(){this._bufferViewToData=new Map,this._bufferViewToProperties=new Map,this._accessorToBufferView=new Map}generateBinary(e){let t=0;this._bufferViewToData.forEach(e=>{t+=e.byteLength});const n=new L(t),s=Array.from(this._bufferViewToData.keys()).sort((e,t)=>H(t.byteLength)-H(e.byteLength));for(const t of s){t.byteOffset=n.byteOffset,e.push(t);const s=e.length-1,r=this.getPropertiesWithBufferView(t);for(const e of r)e.bufferView=s;n.writeTypedArray(this._bufferViewToData.get(t)),this._bufferViewToData.delete(t)}return n.getOutputData()}createBufferView(e,t){const n={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(n,e),n}createAccessor(e,t,n,s,r,i,o){this._verifyBufferView(e);const a={bufferView:void 0,componentType:n,count:s,type:t,min:null==i?void 0:i.min,max:null==i?void 0:i.max,normalized:o,byteOffset:r};return this.setBufferView(a,e),this._accessorToBufferView.set(a,e),a}setBufferView(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)}removeBufferView(e){const t=this.getPropertiesWithBufferView(e);for(const e of t)void 0!==e.bufferView&&delete e.bufferView;this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach((t,n)=>{t===e&&(void 0!==n.byteOffset&&delete n.byteOffset,this._accessorToBufferView.delete(n))})}getBufferView(e){const t=this._accessorToBufferView.get(e);return this._verifyBufferView(t),t}getPropertiesWithBufferView(e){var t;return this._verifyBufferView(e),this._bufferViewToProperties.set(e,null!==(t=this._bufferViewToProperties.get(e))&&void 0!==t?t:[]),this._bufferViewToProperties.get(e)}getData(e){return this._verifyBufferView(e),this._bufferViewToData.get(e)}_verifyBufferView(e){if(void 0===e||!this._bufferViewToData.has(e))throw new Error(`BufferView ${e} not found in BufferManager.`)}}var q;!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(q||(q={}));class G{static _IsTransformable(e){return e&&(e instanceof t.TransformNode||e instanceof t.Camera||e instanceof t.Light)}static _CreateNodeAnimation(e,n,s,r,i){if(this._IsTransformable(e)){const o=[],a=[],l=n.getKeys(),u=G._CalculateMinMaxKeyFrames(l),c=G._DeduceInterpolation(l,s,r),h=c.interpolationType,d=c.shouldBakeAnimation;if(d?G._CreateBakedAnimation(e,n,s,u.min,u.max,n.framePerSecond,i,o,a,u,r):"LINEAR"===h||"STEP"===h?G._CreateLinearOrStepAnimation(e,n,s,o,a,r):"CUBICSPLINE"===h?G._CreateCubicSplineAnimation(e,n,s,o,a,r):G._CreateBakedAnimation(e,n,s,u.min,u.max,n.framePerSecond,i,o,a,u,r),o.length&&a.length)return{inputs:o,outputs:a,samplerInterpolation:h,inputsMin:d?u.min:t.Tools.FloatRound(u.min/n.framePerSecond),inputsMax:d?u.max:t.Tools.FloatRound(u.max/n.framePerSecond)}}return null}static _DeduceAnimationInfo(e){let n=null,s="VEC3",r=!1;const i=e.targetProperty.split(".");switch(i[0]){case"scaling":n="scale";break;case"position":n="translation";break;case"rotation":s="VEC4",n="rotation";break;case"rotationQuaternion":s="VEC4",r=!0,n="rotation";break;case"influence":s="SCALAR",n="weights";break;default:t.Tools.Error(`Unsupported animatable property ${i[0]}`)}return n?{animationChannelTargetPath:n,dataAccessorType:s,useQuaternion:r}:(t.Tools.Error("animation channel target path and data accessor type could be deduced"),null)}static _CreateNodeAnimationFromNodeAnimations(e,t,n,s,r,i,o,a,l,u,c){let h;if(G._IsTransformable(e)&&e.animations)for(const r of e.animations){if(c&&!c(r))continue;const d=G._DeduceAnimationInfo(r);d&&(h={name:r.name,samplers:[],channels:[]},G._AddAnimation(`${r.name}`,r.hasRunningRuntimeAnimations?t:h,e,r,d.dataAccessorType,d.animationChannelTargetPath,s,i,o,a,d.useQuaternion,l,u),h.samplers.length&&h.channels.length&&n.push(h))}}static _CreateMorphTargetAnimationFromMorphTargetAnimations(e,n,s,r,i,o,a,l,u,c,h){let d;if(e instanceof t.Mesh){const i=e.morphTargetManager;if(i)for(let f=0;f<i.numTargets;++f){const p=i.getTarget(f);for(const m of p.animations){if(h&&!h(m))continue;const p=new t.Animation(`${m.name}`,"influence",m.framePerSecond,m.dataType,m.loopMode,m.enableBlending),g=[],x=m.getKeys();for(let e=0;e<x.length;++e){const t=x[e];for(let e=0;e<i.numTargets;++e)e==f?g.push(t):g.push({frame:t.frame,value:0})}p.setKeys(g,!0);const _=G._DeduceAnimationInfo(p);_&&(d={name:p.name,samplers:[],channels:[]},G._AddAnimation(m.name,m.hasRunningRuntimeAnimations?n:d,e,p,_.dataAccessorType,_.animationChannelTargetPath,r,o,a,l,_.useQuaternion,u,c,i.numTargets),d.samplers.length&&d.channels.length&&s.push(d))}}}}static _CreateNodeAndMorphAnimationFromAnimationGroups(e,n,s,r,i,o,a,l,u){var c;let h;if(e.animationGroups){const d=e.animationGroups;for(const f of d){const d=new Map,p=new Map,m=new Set,g=f.to-f.from;h={name:f.name,channels:[],samplers:[]};for(let n=0;n<f.targetedAnimations.length;++n){const g=f.targetedAnimations[n],x=g.target,_=g.animation;if(u&&!u(_))continue;const T=l.has(x);if(this._IsTransformable(x)||1===x.length&&this._IsTransformable(x[0])){const e=G._DeduceAnimationInfo(g.animation);if(e){const t=this._IsTransformable(x)?x:this._IsTransformable(x[0])?x[0]:null;t&&G._AddAnimation(`${_.name}`,h,t,_,e.dataAccessorType,e.animationChannelTargetPath,s,r,i,o,e.useQuaternion,a,T)}}else if((x instanceof t.MorphTarget||1===x.length&&x[0]instanceof t.MorphTarget)&&G._DeduceAnimationInfo(g.animation)){const n=x instanceof t.MorphTarget?x:x[0];if(n){const t=e.morphTargetManagers.find(e=>{for(let t=0;t<e.numTargets;++t)if(e.getTarget(t)===n)return!0;return!1});if(t){const s=e.meshes.find(e=>e.morphTargetManager===t);s&&(d.has(s)||d.set(s,new Map),null===(c=d.get(s))||void 0===c||c.set(n,_),m.add(s),p.set(s,_))}}}}m.forEach(e=>{const n=e.morphTargetManager;let l=null;const u=[],c=p.get(e).getKeys(),m=c.length;for(let s=0;s<m;++s)for(let r=0;r<n.numTargets;++r){const i=n.getTarget(r),o=d.get(e);if(o){const n=o.get(i);n?(l||(l=new t.Animation(`${f.name}_${e.name}_MorphWeightAnimation`,"influence",n.framePerSecond,t.Animation.ANIMATIONTYPE_FLOAT,n.loopMode,n.enableBlending)),u.push(n.getKeys()[s])):u.push({frame:f.from+g/m*s,value:i.influence,inTangent:c[0].inTangent?0:void 0,outTangent:c[0].outTangent?0:void 0})}}l.setKeys(u,!0);const x=G._DeduceAnimationInfo(l);x&&G._AddAnimation(`${f.name}_${e.name}_MorphWeightAnimation`,h,e,l,x.dataAccessorType,x.animationChannelTargetPath,s,r,i,o,x.useQuaternion,a,!1,null==n?void 0:n.numTargets)}),h.channels.length&&h.samplers.length&&n.push(h)}}}static _AddAnimation(e,n,s,r,i,o,a,l,u,c,h,d,f,p){const m=G._CreateNodeAnimation(s,r,o,h,d);let g,x,_,T,y,b;if(m){if(p){let e,t=0;const n=[];for(;m.inputs.length>0;)e=m.inputs.shift(),t%p==0&&n.push(e),t++;m.inputs=n}const e=a.get(s),r=new Float32Array(m.inputs);g=l.createBufferView(r),x=l.createAccessor(g,"SCALAR",5126,m.inputs.length,void 0,{min:[m.inputsMin],max:[m.inputsMax]}),c.push(x),_=c.length-1;const u=new t.Quaternion,h=new t.Vector3,d=new t.Vector3,v=s instanceof t.Camera,M=S(i),w=new Float32Array(m.outputs.length*M);m.outputs.forEach(function(e,n){let s=e;switch(o){case"translation":f&&(t.Vector3.FromArrayToRef(e,0,d),B(d),d.toArray(s));break;case"rotation":4===e.length?t.Quaternion.FromArrayToRef(e,0,u):(s=new Array(4),t.Vector3.FromArrayToRef(e,0,h),t.Quaternion.FromEulerVectorToRef(h,u)),f&&(P(u),v&&U(u)),u.toArray(s)}w.set(s,n*M)}),g=l.createBufferView(w),x=l.createAccessor(g,i,5126,m.outputs.length),c.push(x),T=c.length-1,y={interpolation:m.samplerInterpolation,input:_,output:T},n.samplers.push(y),b={sampler:n.samplers.length-1,target:{node:e,path:o}},n.channels.push(b)}}static _CreateBakedAnimation(e,n,s,r,i,o,a,l,u,c,h){let d;const f=t.Quaternion.Identity();let p,m,g,x,_,T=null,y=null;c.min=t.Tools.FloatRound(r/o);const b=n.getKeys();for(let r=0,c=b.length;r<c;++r){if(m=b[r],r+1<c)if(g=b[r+1],m.value.equals&&m.value.equals(g.value)||m.value===g.value){if(0!==r)continue;_=m.frame}else _=g.frame;else{if(x=b[r-1],m.value.equals&&m.value.equals(x.value)||m.value===x.value)continue;_=i}if(_)for(let r=m.frame;r<=_;r+=a){if(p=t.Tools.FloatRound(r/o),p===T)continue;T=p,y=p;const i={key:0,repeatCount:0,loopMode:n.loopMode};d=n._interpolate(r,i),G._SetInterpolatedValue(e,d,p,n,s,f,l,u,h)}}y&&(c.max=y)}static _ConvertFactorToVector3OrQuaternion(e,n,s,r,i){const o=G._GetBasePositionRotationOrScale(n,r,i),a=s.targetProperty.split("."),l=a?a[1]:"",u=i?t.Quaternion.FromArray(o).normalize():t.Vector3.FromArray(o);switch(l){case"x":case"y":case"z":u[l]=e;break;case"w":u.w=e;break;default:t.Tools.Error(`glTFAnimation: Unsupported component name "${l}"!`)}return u}static _SetInterpolatedValue(e,n,s,r,i,o,a,l,u){let c;a.push(s),"weights"!==i?(r.dataType===t.Animation.ANIMATIONTYPE_FLOAT&&(n=this._ConvertFactorToVector3OrQuaternion(n,e,r,i,u)),"rotation"===i?(u?o=n:(c=n,t.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,o)),l.push(o.asArray())):(c=n,l.push(c.asArray()))):l.push([n])}static _CreateLinearOrStepAnimation(e,t,n,s,r,i){for(const o of t.getKeys())s.push(o.frame/t.framePerSecond),G._AddKeyframeValue(o,t,r,n,e,i)}static _CreateCubicSplineAnimation(e,t,n,s,r,i){t.getKeys().forEach(function(o){s.push(o.frame/t.framePerSecond),G._AddSplineTangent(q.INTANGENT,r,n,"CUBICSPLINE",o,i),G._AddKeyframeValue(o,t,r,n,e,i),G._AddSplineTangent(q.OUTTANGENT,r,n,"CUBICSPLINE",o,i)})}static _GetBasePositionRotationOrScale(e,n,s){let r;if("rotation"===n)if(s){const n=e.rotationQuaternion;r=(null!=n?n:t.Quaternion.Identity()).asArray()}else{const n=e.rotation;r=(null!=n?n:t.Vector3.Zero()).asArray()}else if("translation"===n){const n=e.position;r=(null!=n?n:t.Vector3.Zero()).asArray()}else{const n=e.scaling;r=(null!=n?n:t.Vector3.One()).asArray()}return r}static _AddKeyframeValue(e,n,s,r,i,o){let a;const l=n.dataType;if(l===t.Animation.ANIMATIONTYPE_VECTOR3){let n=e.value.asArray();if("rotation"===r){const e=t.Vector3.FromArray(n);n=t.Quaternion.RotationYawPitchRoll(e.y,e.x,e.z).asArray()}s.push(n)}else if(l===t.Animation.ANIMATIONTYPE_FLOAT){if("weights"===r)s.push([e.value]);else if(a=this._ConvertFactorToVector3OrQuaternion(e.value,i,n,r,o),a){if("rotation"===r){const e=o?a:t.Quaternion.RotationYawPitchRoll(a.y,a.x,a.z).normalize();s.push(e.asArray())}s.push(a.asArray())}}else l===t.Animation.ANIMATIONTYPE_QUATERNION?s.push(e.value.normalize().asArray()):t.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")}static _DeduceInterpolation(e,t,n){let s,r,i=!1;if("rotation"===t&&!n)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(let t=0,n=e.length;t<n;++t)if(r=e[t],r.inTangent||r.outTangent)if(s){if("CUBICSPLINE"!==s){s="LINEAR",i=!0;break}}else s="CUBICSPLINE";else if(s){if("CUBICSPLINE"===s||r.interpolation&&1===r.interpolation&&"STEP"!==s){s="LINEAR",i=!0;break}}else s=r.interpolation&&1===r.interpolation?"STEP":"LINEAR";return s||(s="LINEAR"),{interpolationType:s,shouldBakeAnimation:i}}static _AddSplineTangent(e,n,s,r,i,o){let a;const l=e===q.INTANGENT?i.inTangent:i.outTangent;if("CUBICSPLINE"===r){if("rotation"===s)if(l)if(o)a=l.asArray();else{const e=l;a=t.Quaternion.RotationYawPitchRoll(e.y,e.x,e.z).asArray()}else a=[0,0,0,0];else a="weights"===s?l?[l]:[0]:l?l.asArray():[0,0,0];n.push(a)}}static _CalculateMinMaxKeyFrames(e){let t=1/0,n=-1/0;return e.forEach(function(e){t=Math.min(t,e.frame),n=Math.max(n,e.frame)}),{min:t,max:n}}}function X(e,n,s,r,i,o){const a={attributes:{},influence:e.influence,name:e.name},l=n.geometry;if(!l)return t.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),a;const u=o?-1:1,c=t.Vector3.Zero();let h,d;if(e.hasPositions){const r=e.getPositions(),o=l.getVerticesData(t.VertexBuffer.PositionKind);if(o){const e=new Float32Array(o.length),n=[1/0,1/0,1/0],l=[-1/0,-1/0,-1/0];d=o.length/3,h=0;for(let s=h;s<d;++s){const i=t.Vector3.FromArray(o,3*s);t.Vector3.FromArray(r,3*s).subtractToRef(i,c),c.x*=u,n[0]=Math.min(n[0],c.x),l[0]=Math.max(l[0],c.x),n[1]=Math.min(n[1],c.y),l[1]=Math.max(l[1],c.y),n[2]=Math.min(n[2],c.z),l[2]=Math.max(l[2],c.z),e[3*s]=c.x,e[3*s+1]=c.y,e[3*s+2]=c.z}const f=s.createBufferView(e,12),p=s.createAccessor(f,"VEC3",5126,r.length/3,0,{min:n,max:l});i.push(p),a.attributes.POSITION=i.length-1}else t.Tools.Warn(`Morph target positions for mesh ${n.name} were not exported. Mesh does not have position vertex data`)}if(e.hasNormals){const r=e.getNormals(),o=l.getVerticesData(t.VertexBuffer.NormalKind);if(o){const e=new Float32Array(o.length);d=o.length/3,h=0;for(let n=h;n<d;++n){const s=t.Vector3.FromArray(o,3*n).normalize();t.Vector3.FromArray(r,3*n).normalize().subtractToRef(s,c),e[3*n]=c.x*u,e[3*n+1]=c.y,e[3*n+2]=c.z}const n=s.createBufferView(e,12),l=s.createAccessor(n,"VEC3",5126,r.length/3,0);i.push(l),a.attributes.NORMAL=i.length-1}else t.Tools.Warn(`Morph target normals for mesh ${n.name} were not exported. Mesh does not have normals vertex data`)}if(e.hasTangents){const r=e.getTangents(),o=l.getVerticesData(t.VertexBuffer.TangentKind);if(o){d=o.length/4;const e=new Float32Array(3*d);h=0;for(let n=h;n<d;++n){const s=t.Vector3.FromArray(o,4*n);O(s);const i=t.Vector3.FromArray(r,3*n);O(i),i.subtractToRef(s,c),e[3*n]=c.x*u,e[3*n+1]=c.y,e[3*n+2]=c.z}const n=s.createBufferView(e,12),l=s.createAccessor(n,"VEC3",5126,d,0);i.push(l),a.attributes.TANGENT=i.length-1}else t.Tools.Warn(`Morph target tangents for mesh ${n.name} were not exported. Mesh does not have tangents vertex data`)}if(e.hasColors){const r=e.getColors(),o=l.getVerticesData(t.VertexBuffer.ColorKind),u=l.getVertexBuffer(t.VertexBuffer.ColorKind);if(o&&u){const e=u.getSize();d=o.length/e;const n=new Float32Array(d*e);h=0;for(let s=h;s<d;++s)if(3===e){const i=t.Vector3.FromArray(o,s*e);t.Vector3.FromArray(r,s*e).subtractToRef(i,c),n[3*s]=c.x,n[3*s+1]=c.y,n[3*s+2]=c.z}else if(4===e){const i=new t.Vector4,a=t.Vector4.FromArray(o,s*e);t.Vector4.FromArray(r,s*e).subtractToRef(a,i),n[4*s]=i.x,n[4*s+1]=i.y,n[4*s+2]=i.z,n[4*s+3]=i.w}else t.Tools.Warn(`Unsupported number of components for color attribute: ${e}`);const l=s.createBufferView(n,4*e),f=s.createAccessor(l,3===e?"VEC3":"VEC4",5126,d,0);i.push(f),a.attributes.COLOR_0=i.length-1}else t.Tools.Warn(`Morph target colors for mesh ${n.name} were not exported. Mesh does not have colors vertex data`)}return a}class Q{constructor(e,t){this._indicesAccessorMap=new Map,this._vertexBufferViewMap=new Map,this._vertexAccessorMap=new Map,this._remappedBufferView=new Map,this._meshMorphTargetMap=new Map,this._vertexMapColorAlpha=new Map,this._exportedNodes=new Set,this._meshMap=new Map,this.convertedToRightHandedBuffers=new Map,this.convertToRightHanded=e,this.wasAddedByNoopNode=t}getIndicesAccessor(e,t,n,s,r){var i,o,a,l;return null===(l=null===(a=null===(o=null===(i=this._indicesAccessorMap.get(e))||void 0===i?void 0:i.get(t))||void 0===o?void 0:o.get(n))||void 0===a?void 0:a.get(s))||void 0===l?void 0:l.get(r)}setIndicesAccessor(e,t,n,s,r,i){let o=this._indicesAccessorMap.get(e);o||(o=new Map,this._indicesAccessorMap.set(e,o));let a=o.get(t);a||(a=new Map,o.set(t,a));let l=a.get(n);l||(l=new Map,a.set(n,l));let u=l.get(s);u||(u=new Map,l.set(s,u)),u.set(r,i)}pushExportedNode(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)}getNodesSet(){return this._exportedNodes}getVertexBufferView(e){return this._vertexBufferViewMap.get(e)}setVertexBufferView(e,t){this._vertexBufferViewMap.set(e,t)}setRemappedBufferView(e,t,n){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,n)}getRemappedBufferView(e,t){var n;return null===(n=this._remappedBufferView.get(e))||void 0===n?void 0:n.get(t)}getVertexAccessor(e,t,n){var s,r;return null===(r=null===(s=this._vertexAccessorMap.get(e))||void 0===s?void 0:s.get(t))||void 0===r?void 0:r.get(n)}setVertexAccessor(e,t,n,s){let r=this._vertexAccessorMap.get(e);r||(r=new Map,this._vertexAccessorMap.set(e,r));let i=r.get(t);i||(i=new Map,r.set(t,i)),i.set(n,s)}hasVertexColorAlpha(e){return this._vertexMapColorAlpha.get(e)||!1}setHasVertexColorAlpha(e,t){return this._vertexMapColorAlpha.set(e,t)}getMesh(e){return this._meshMap.get(e)}setMesh(e,t){this._meshMap.set(e,t)}bindMorphDataToMesh(e,t){const n=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,n),-1===n.indexOf(t)&&n.push(t)}getMorphTargetsFromMesh(e){return this._meshMorphTargetMap.get(e)}}class Z{_ApplyExtension(e,t,n,s){if(n>=t.length)return Promise.resolve(e);const r=s(t[n],e);return r?r.then(e=>c(this,void 0,void 0,function*(){return e?yield this._ApplyExtension(e,t,n+1,s):null})):this._ApplyExtension(e,t,n+1,s)}_ApplyExtensions(e,t){const n=[];for(const e of Z._ExtensionNames)n.push(this._extensions[e]);return this._ApplyExtension(e,n,0,t)}_extensionsPostExportNodeAsync(e,t,n,s,r){return this._ApplyExtensions(t,(t,i)=>t.postExportNodeAsync&&t.postExportNodeAsync(e,i,n,s,r,this._bufferManager))}_extensionsPostExportMaterialAsync(e,t,n){return this._ApplyExtensions(t,(t,s)=>t.postExportMaterialAsync&&t.postExportMaterialAsync(e,s,n))}_extensionsPostExportMaterialAdditionalTexturesAsync(e,t,n){return c(this,void 0,void 0,function*(){const s=[];return yield Promise.all(Z._ExtensionNames.map(r=>c(this,void 0,void 0,function*(){const i=this._extensions[r];if(i.postExportMaterialAdditionalTexturesAsync){const r=yield i.postExportMaterialAdditionalTexturesAsync(e,t,n);s.push(...r)}}))),s})}_extensionsPostExportTextures(e,t,n){for(const s of Z._ExtensionNames){const r=this._extensions[s];r.postExportTexture&&r.postExportTexture(e,t,n)}}_extensionsPostExportMeshPrimitive(e){for(const t of Z._ExtensionNames){const n=this._extensions[t];n.postExportMeshPrimitive&&n.postExportMeshPrimitive(e,this._bufferManager,this._accessors)}}_extensionsPreGenerateBinaryAsync(){return c(this,void 0,void 0,function*(){for(const e of Z._ExtensionNames){const t=this._extensions[e];t.preGenerateBinaryAsync&&(yield t.preGenerateBinaryAsync(this._bufferManager))}})}_forEachExtensions(e){for(const t of Z._ExtensionNames){const n=this._extensions[t];n.enabled&&e(n)}}_extensionsOnExporting(){this._forEachExtensions(e=>{var t,n,s;e.wasUsed&&((t=this._glTF).extensionsUsed||(t.extensionsUsed=[]),-1===this._glTF.extensionsUsed.indexOf(e.name)&&this._glTF.extensionsUsed.push(e.name),e.required&&((n=this._glTF).extensionsRequired||(n.extensionsRequired=[]),-1===this._glTF.extensionsRequired.indexOf(e.name)&&this._glTF.extensionsRequired.push(e.name)),(s=this._glTF).extensions||(s.extensions={}),e.onExporting&&e.onExporting())})}_loadExtensions(){for(const e of Z._ExtensionNames){const t=Z._ExtensionFactories[e](this);this._extensions[e]=t}}constructor(e=t.EngineStore.LastCreatedScene,n){if(this._glTF={asset:{generator:`Babylon.js v${t.Engine.Version}`,version:"2.0"}},this._animations=[],this._accessors=[],this._bufferViews=[],this._cameras=[],this._images=[],this._materials=[],this._meshes=[],this._nodes=[],this._samplers=[],this._scenes=[],this._skins=[],this._textures=[],this._imageData={},this._shouldUseGlb=!1,this._materialExporter=new v(this),this._extensions={},this._bufferManager=new j,this._shouldExportNodeMap=new Map,this._nodeMap=new Map,this._materialMap=new Map,this._camerasMap=new Map,this._nodesCameraMap=new Map,this._skinMap=new Map,this._nodesSkinMap=new Map,this._materialNeedsUVsSet=new Set,!e)throw new Error("No scene available to export");this._babylonScene=e,this._options=Object.assign({shouldExportNode:()=>!0,shouldExportAnimation:()=>!0,metadataSelector:e=>{var t;return null===(t=null==e?void 0:e.gltf)||void 0===t?void 0:t.extras},animationSampleRate:1/60,exportWithoutWaitingForScene:!1,exportUnusedUVs:!1,removeNoopRootNodes:!0,includeCoordinateSystemConversionNodes:!1,meshCompressionMethod:"None"},n),this._loadExtensions()}dispose(){for(const e in this._extensions)this._extensions[e].dispose()}get options(){return this._options}static RegisterExtension(e,n,s=100){Z.UnregisterExtension(e)&&t.Tools.Warn(`Extension with the name ${e} already exists`),Z._ExtensionFactories[e]=n;const r=null!=s?s:0;Z._ExtensionOrders[e]=r;let i=Z._ExtensionNames.length;for(let e=0;e<Z._ExtensionNames.length;e++){const t=Z._ExtensionNames[e];if(r<Z._ExtensionOrders[t]){i=e;break}}Z._ExtensionNames.splice(i,0,e)}static UnregisterExtension(e){if(!Z._ExtensionFactories[e])return!1;delete Z._ExtensionFactories[e],delete Z._ExtensionOrders[e];const t=Z._ExtensionNames.indexOf(e);return-1!==t&&Z._ExtensionNames.splice(t,1),!0}_generateJSON(e,t,n){const s={byteLength:e};return s.byteLength&&(this._glTF.buffers=[s]),this._nodes&&this._nodes.length&&(this._glTF.nodes=this._nodes),this._meshes&&this._meshes.length&&(this._glTF.meshes=this._meshes),this._scenes&&this._scenes.length&&(this._glTF.scenes=this._scenes,this._glTF.scene=0),this._cameras&&this._cameras.length&&(this._glTF.cameras=this._cameras),this._bufferViews&&this._bufferViews.length&&(this._glTF.bufferViews=this._bufferViews),this._accessors&&this._accessors.length&&(this._glTF.accessors=this._accessors),this._animations&&this._animations.length&&(this._glTF.animations=this._animations),this._materials&&this._materials.length&&(this._glTF.materials=this._materials),this._textures&&this._textures.length&&(this._glTF.textures=this._textures),this._samplers&&this._samplers.length&&(this._glTF.samplers=this._samplers),this._skins&&this._skins.length&&(this._glTF.skins=this._skins),this._images&&this._images.length&&(this._glTF.images=this._images),this._shouldUseGlb||(s.uri=t+".bin"),n?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)}generateGLTFAsync(e){return c(this,void 0,void 0,function*(){const t=yield this._generateBinaryAsync();this._extensionsOnExporting();const n=this._generateJSON(t.byteLength,e,!0),s=new Blob([t],{type:"application/octet-stream"}),r=e+".gltf",o=e+".bin",a=new i;if(a.files[r]=n,a.files[o]=s,this._imageData)for(const e in this._imageData)a.files[e]=this._imageData[e];return a})}_generateBinaryAsync(){return c(this,void 0,void 0,function*(){return yield this._exportSceneAsync(),yield this._extensionsPreGenerateBinaryAsync(),this._bufferManager.generateBinary(this._bufferViews)})}_getPadding(e){const t=e%4;return 0===t?t:4-t}generateGLBAsync(e){return c(this,void 0,void 0,function*(){this._shouldUseGlb=!0;const t=yield this._generateBinaryAsync();this._extensionsOnExporting();const n=this._generateJSON(t.byteLength),s=e+".glb";let r,o=n.length;"undefined"!=typeof TextEncoder&&(r=(new TextEncoder).encode(n),o=r.length);const a=this._getPadding(o),l=this._getPadding(t.byteLength),u=28+o+a+t.byteLength+l,c=new L(u);if(c.writeUInt32(1179937895),c.writeUInt32(2),c.writeUInt32(u),c.writeUInt32(o+a),c.writeUInt32(1313821514),r)c.writeTypedArray(r);else{const e="_".charCodeAt(0);for(let t=0;t<o;++t){const s=n.charCodeAt(t);s!=n.codePointAt(t)?c.writeUInt8(e):c.writeUInt8(s)}}for(let e=0;e<a;++e)c.writeUInt8(32);c.writeUInt32(t.byteLength+l),c.writeUInt32(5130562),c.writeTypedArray(t);for(let e=0;e<l;++e)c.writeUInt8(0);const h=new i;return h.files[s]=new Blob([c.getOutputData()],{type:"application/octet-stream"}),h})}_setNodeTransformation(e,n,s){var r;if(n.getPivotPoint().equalsWithEpsilon(R,t.Epsilon)||t.Tools.Warn("Pivot points are not supported in the glTF serializer"),!n.position.equalsWithEpsilon(R,t.Epsilon)){const r=t.TmpVectors.Vector3[0].copyFrom(n.position);s&&B(r),e.translation=r.asArray()}n.scaling.equalsWithEpsilon(C,t.Epsilon)||(e.scale=n.scaling.asArray());const i=(null===(r=n.rotationQuaternion)||void 0===r?void 0:r.clone())||t.Quaternion.FromEulerAngles(n.rotation.x,n.rotation.y,n.rotation.z);i.equalsWithEpsilon(A,t.Epsilon)||(s&&P(i),e.rotation=i.normalize().asArray())}_setCameraTransformation(e,n,s){const r=t.TmpVectors.Vector3[0],i=t.TmpVectors.Quaternion[0],o=n.getWorldMatrix();if(n.parent){const e=n.parent.getWorldMatrix().invertToRef(t.TmpVectors.Matrix[0]);o.multiplyToRef(e,t.TmpVectors.Matrix[1]).decompose(void 0,i,r)}else o.decompose(void 0,i,r);r.equalsWithEpsilon(R,t.Epsilon)||(s&&B(r),e.translation=r.asArray()),s&&P(i),this._babylonScene.useRightHandedSystem||U(i),i.equalsWithEpsilon(A,t.Epsilon)||(e.rotation=i.asArray())}_listAvailableCameras(){for(const e of this._babylonScene.cameras){const n={type:e.mode===t.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(e.name&&(n.name=e.name),"perspective"===n.type)n.perspective={aspectRatio:e.getEngine().getAspectRatio(e),yfov:e.fovMode===t.Camera.FOVMODE_VERTICAL_FIXED?e.fov:e.fov*e.getEngine().getAspectRatio(e),znear:e.minZ,zfar:e.maxZ};else if("orthographic"===n.type){const t=e.orthoLeft&&e.orthoRight?.5*(e.orthoRight-e.orthoLeft):.5*e.getEngine().getRenderWidth(),s=e.orthoBottom&&e.orthoTop?.5*(e.orthoTop-e.orthoBottom):.5*e.getEngine().getRenderHeight();n.orthographic={xmag:t,ymag:s,znear:e.minZ,zfar:e.maxZ}}this._camerasMap.set(e,n)}}_exportAndAssignCameras(){const e=Array.from(this._camerasMap.values());for(const t of e){const e=this._nodesCameraMap.get(t);if(void 0!==e){this._cameras.push(t);for(const t of e)t.camera=this._cameras.length-1}}}_listAvailableSkeletons(){for(const e of this._babylonScene.skeletons){if(e.bones.length<=0)continue;const t={joints:[]};this._skinMap.set(e,t)}}_exportAndAssignSkeletons(e){var n;for(const s of this._babylonScene.skeletons){if(s.bones.length<=0)continue;const r=this._skinMap.get(s);if(null==r)continue;const i={};let o=-1;for(let e=0;e<s.bones.length;++e){const t=s.bones[e],r=null!==(n=t.getIndex())&&void 0!==n?n:e;-1!==r&&(i[r]=t,r>o&&(o=r))}const a=[];for(let n=0;n<=o;++n){const s=i[n],o=s.getTransformNode(),l=o?this._nodeMap.get(o):void 0;if(void 0===l){t.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.");continue}r.joints.push(l);const u=s.getAbsoluteInverseBindMatrix().clone();e.has(o)&&N(u),a.push(u)}const l=this._nodesSkinMap.get(r);if(r.joints.length>0&&void 0!==l){const e=new Float32Array(16*a.length);a.forEach((t,n)=>{e.set(t.m,16*n)});const t=this._bufferManager.createBufferView(e);this._accessors.push(this._bufferManager.createAccessor(t,"MAT4",5126,a.length)),r.inverseBindMatrices=this._accessors.length-1,this._skins.push(r);const n=this._skins.length-1;for(const e of l)e.skin=n}}}_exportSceneAsync(){return c(this,void 0,void 0,function*(){const e={nodes:[]};if(this._babylonScene.metadata){const t=this._options.metadataSelector(this._babylonScene.metadata);t&&(e.extras=t)}const n=new Array,s=new Array,r=new Array;let i;if(this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes)for(const e of this._babylonScene.animationGroups)for(const n of e.targetedAnimations){const e=n.target;e instanceof t.TransformNode&&!e.parent&&(null!=i?i:i=new Set).add(e)}for(const e of this._babylonScene.rootNodes){const t=e.animations,o=!!t&&t.length>0||(null==i?void 0:i.has(e));this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&w(e,this._babylonScene.useRightHandedSystem)&&!o?r.push(...e.getChildren()):this._babylonScene.useRightHandedSystem?n.push(e):s.push(e)}this._listAvailableCameras(),this._listAvailableSkeletons();const o=new Q(!0,!1);e.nodes.push(...yield this._exportNodesAsync(s,o));const a=new Q(!1,!1);e.nodes.push(...yield this._exportNodesAsync(n,a));const l=new Q(!1,!0);e.nodes.push(...yield this._exportNodesAsync(r,l)),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(o.getNodesSet()),this._babylonScene.animationGroups.length&&G._CreateNodeAndMorphAnimationFromAnimationGroups(this._babylonScene,this._animations,this._nodeMap,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,o.getNodesSet(),this._options.shouldExportAnimation)})}_shouldExportNode(e){let t=this._shouldExportNodeMap.get(e);return void 0===t&&(t=this._options.shouldExportNode(e),this._shouldExportNodeMap.set(e,t)),t}_exportNodesAsync(e,t){return c(this,void 0,void 0,function*(){const n=new Array;this._exportBuffers(e,t);for(const s of e)yield this._exportNodeAsync(s,n,t);return n})}_collectBuffers(e,n,s,r,i){if(this._shouldExportNode(e)&&e instanceof t.AbstractMesh&&e.geometry){const t=e.geometry.getVertexBuffers();if(t)for(const r in t){if(!F(r))continue;const o=t[r];i.setHasVertexColorAlpha(o,e.hasVertexAlpha);const a=o._buffer,l=n.get(a)||[];n.set(a,l),-1===l.indexOf(o)&&l.push(o);const u=s.get(o)||[];s.set(o,u),-1===u.indexOf(e)&&u.push(e)}const o=e.morphTargetManager;if(o)for(let t=0;t<o.numTargets;t++){const n=o.getTarget(t),s=r.get(n)||[];r.set(n,s),-1===s.indexOf(e)&&s.push(e)}}for(const t of e.getChildren())this._collectBuffers(t,n,s,r,i)}_exportBuffers(e,n){const s=new Map,r=new Map,i=new Map;for(const t of e)this._collectBuffers(t,s,r,i,n);const o=Array.from(s.keys());for(const e of o){const i=e.getData();if(!i)throw new Error("Buffer data is not available");const o=s.get(e);if(!o)continue;const a=o[0].byteStride;if(o.some(e=>e.byteStride!==a))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");const l=$(i).slice();for(const e of o){const n=r.get(e),{byteOffset:s,byteStride:i,componentCount:o,type:a,count:u,normalized:c,kind:h}=I(e,n);switch(h){case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:t.EnumerateFloatValues(l,s,i,o,a,u,c,e=>{const t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){const n=1/t;e[0]*=n,e[1]*=n,e[2]*=n}});break;case t.VertexBuffer.ColorKind:{const e=n.filter(e=>e.material instanceof t.StandardMaterial||null==e.material).length;if(0==e)break;if(e!=n.length){t.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}a==t.VertexBuffer.UNSIGNED_BYTE&&t.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");const r=new t.Color3,h=new t.Color4,d=this._babylonScene.getEngine().useExactSrgbConversions;t.EnumerateFloatValues(l,s,i,o,a,u,c,e=>{3===e.length?(r.fromArray(e,0),r.toLinearSpaceToRef(r,d),r.toArray(e,0)):(h.fromArray(e,0),h.toLinearSpaceToRef(h,d),h.toArray(e,0))})}}}if(n.convertToRightHanded){for(const e of o){const n=r.get(e),{byteOffset:s,byteStride:i,componentCount:o,type:a,count:u,normalized:c,kind:h}=I(e,n);switch(h){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:t.EnumerateFloatValues(l,s,i,o,a,u,c,e=>{e[0]=-e[0]})}}n.convertedToRightHandedBuffers.set(e,l)}const u=this._bufferManager.createBufferView(l,a);n.setVertexBufferView(e,u);const c=new Map;for(const e of o){const n=r.get(e),{kind:s,totalVertices:i}=I(e,n);switch(s){case t.VertexBuffer.MatricesIndicesKind:case t.VertexBuffer.MatricesIndicesExtraKind:if(e.type==t.VertexBuffer.FLOAT){const t=e.getFloatData(i);null!==t&&c.set(e,t)}}}0!==c.size&&t.Logger.Warn("Joint indices conversion needed: some joint indices are stored as floats in Babylon but GLTF requires UNSIGNED BYTES. We will perform the conversion but this might lead to unused data in the buffer.");const h=Array.from(c.keys());for(const t of h){const s=c.get(t);if(!s)continue;const r=V(s),i=new(r?Uint16Array:Uint8Array)(s.length);for(let e=0;e<s.length;e++)i[e]=s[e];const o=this._bufferManager.createBufferView(i,4*(r?2:1));n.setRemappedBufferView(e,t,o)}}const a=Array.from(i.keys());for(const e of a){const t=i.get(e);if(!t)continue;const s=X(e,t[0],this._bufferManager,this._bufferViews,this._accessors,n.convertToRightHanded);for(const e of t)n.bindMorphDataToMesh(e,s)}}_exportNodeAsync(e,t,n){return c(this,void 0,void 0,function*(){let s=this._nodeMap.get(e);if(void 0!==s)return void(t.includes(s)||t.push(s));const r=yield this._createNodeAsync(e,n);if(r){s=this._nodes.length,this._nodes.push(r),this._nodeMap.set(e,s),n.pushExportedNode(e),t.push(s);const i={name:"runtime animations",channels:[],samplers:[]},o=[];this._babylonScene.animationGroups.length||(G._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,o,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&G._CreateNodeAnimationFromNodeAnimations(e,i,o,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation)),i.channels.length&&i.samplers.length&&this._animations.push(i),o.forEach(e=>{e.channels.length&&e.samplers.length&&this._animations.push(e)})}const i=r?[]:t;for(const t of e.getChildren())yield this._exportNodeAsync(t,i,n);r&&i.length&&(r.children=i)})}_createNodeAsync(e,n){return c(this,void 0,void 0,function*(){var s,r,i;if(!this._shouldExportNode(e))return null;const o={};if(e.name&&(o.name=e.name),e.metadata){const t=this._options.metadataSelector(e.metadata);t&&(o.extras=t)}if(e instanceof t.TransformNode&&(this._setNodeTransformation(o,e,n.convertToRightHanded),e instanceof t.AbstractMesh)){const r=e instanceof t.InstancedMesh?e.sourceMesh:e;if(r.subMeshes&&r.subMeshes.length>0&&(o.mesh=yield this._exportMeshAsync(r,n)),e.skeleton){const t=this._skinMap.get(e.skeleton);void 0!==t&&(void 0===this._nodesSkinMap.get(t)&&this._nodesSkinMap.set(t,[]),null===(s=this._nodesSkinMap.get(t))||void 0===s||s.push(o))}}if(e instanceof t.TargetCamera){const t=this._camerasMap.get(e);if(t){void 0===this._nodesCameraMap.get(t)&&this._nodesCameraMap.set(t,[]),this._setCameraTransformation(o,e,n.convertToRightHanded);const s=e.parent;if(null!==s&&K(e,s)){const e=this._nodeMap.get(s);if(void 0!==e){const n=this._nodes[e];return k(o,n),null===(r=this._nodesCameraMap.get(t))||void 0===r||r.push(n),null}}null===(i=this._nodesCameraMap.get(t))||void 0===i||i.push(o)}}return(yield this._extensionsPostExportNodeAsync("exportNodeAsync",o,e,this._nodeMap,n.convertToRightHanded))?o:(t.Logger.Warn(`Not exporting node ${e.name}`),null)})}_exportIndices(e,n,s,r,i,o,a,l,u){let c=null;u.mode=function(e){switch(e){case t.Material.TriangleFillMode:return 4;case t.Material.TriangleStripDrawMode:return 5;case t.Material.TriangleFanDrawMode:return 6;case t.Material.PointListDrawMode:case t.Material.PointFillMode:return 0;case t.Material.LineLoopDrawMode:return 2;case t.Material.LineListDrawMode:return 1;case t.Material.LineStripDrawMode:return 3}throw new Error(`Unknown fill mode: ${e}`)}(o);const h=a!==t.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case t.Material.TriangleFillMode:case t.Material.TriangleStripDrawMode:case t.Material.TriangleFanDrawMode:return!0}return!1}(o);if(h){if(o===t.Material.TriangleStripDrawMode||o===t.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");const a=n?new Uint32Array(r):new Uint16Array(r);if(e)for(let t=0;t+2<r;t+=3)a[t]=e[s+t]+i,a[t+1]=e[s+t+2]+i,a[t+2]=e[s+t+1]+i;else for(let e=0;e+2<r;e+=3)a[e]=e,a[e+1]=e+2,a[e+2]=e+1;c=a}else if(e&&0!==i){const t=n?new Uint32Array(r):new Uint16Array(r);for(let n=0;n<r;n++)t[n]=e[s+n]+i;c=t}else e&&(c=function(e,t,n,s){let r=e;return 0===t&&n===e.length||(r=Array.isArray(e)?e.slice(t,t+n):e.subarray(t,t+n)),r instanceof Int32Array?new Uint32Array(r.buffer,r.byteOffset,r.length):Array.isArray(r)?s?new Uint32Array(r):new Uint16Array(r):r}(e,s,r,n));if(c){let t=l.getIndicesAccessor(e,s,r,i,h);if(void 0===t){const o=this._bufferManager.createBufferView(c),a=n?5125:5123;this._accessors.push(this._bufferManager.createAccessor(o,"SCALAR",a,r,0)),t=this._accessors.length-1,l.setIndicesAccessor(e,s,r,i,h,t)}u.indices=t}}_exportVertexBuffer(e,n,s,r,i,o){const a=e.getKind();if(!F(a))return;if(a.startsWith("uv")&&!this._options.exportUnusedUVs&&(!n||!this._materialNeedsUVsSet.has(n)))return;let l=i.getVertexAccessor(e,s,r);if(void 0===l){const n=i.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),o=a===t.VertexBuffer.PositionKind?function(e,n,s,r){const{byteOffset:i,byteStride:o,type:a,normalized:l}=n,u=n.getSize(),c=new Array(u).fill(1/0),h=new Array(u).fill(-1/0);return t.EnumerateFloatValues(e,i+s*o,o,u,a,r*u,l,e=>{for(let t=0;t<u;t++)c[t]=Math.min(c[t],e[t]),h[t]=Math.max(h[t],e[t])}),{min:c,max:h}}(n,e,s,r):void 0,u=(a===t.VertexBuffer.MatricesIndicesKind||a===t.VertexBuffer.MatricesIndicesExtraKind)&&e.type===t.VertexBuffer.FLOAT,c=u?t.VertexBuffer.UNSIGNED_BYTE:e.type,h=u?void 0:e.normalized,d=u?i.getRemappedBufferView(e._buffer,e):i.getVertexBufferView(e._buffer),f=e.byteOffset+s*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(d,function(e,n){if(e==t.VertexBuffer.ColorKind)return n?"VEC4":"VEC3";switch(e){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:return"VEC3";case t.VertexBuffer.TangentKind:case t.VertexBuffer.MatricesIndicesKind:case t.VertexBuffer.MatricesIndicesExtraKind:case t.VertexBuffer.MatricesWeightsKind:case t.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case t.VertexBuffer.UVKind:case t.VertexBuffer.UV2Kind:case t.VertexBuffer.UV3Kind:case t.VertexBuffer.UV4Kind:case t.VertexBuffer.UV5Kind:case t.VertexBuffer.UV6Kind:return"VEC2"}throw new Error(`Unknown kind ${e}`)}(a,i.hasVertexColorAlpha(e)),c,r,f,o,h)),l=this._accessors.length-1,i.setVertexAccessor(e,s,r,l)}o.attributes[function(e){switch(e){case t.VertexBuffer.PositionKind:return"POSITION";case t.VertexBuffer.NormalKind:return"NORMAL";case t.VertexBuffer.TangentKind:return"TANGENT";case t.VertexBuffer.ColorKind:return"COLOR_0";case t.VertexBuffer.UVKind:return"TEXCOORD_0";case t.VertexBuffer.UV2Kind:return"TEXCOORD_1";case t.VertexBuffer.UV3Kind:return"TEXCOORD_2";case t.VertexBuffer.UV4Kind:return"TEXCOORD_3";case t.VertexBuffer.UV5Kind:return"TEXCOORD_4";case t.VertexBuffer.UV6Kind:return"TEXCOORD_5";case t.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case t.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case t.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case t.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error(`Unknown kind: ${e}`)}(a)]=l}_exportMaterialAsync(e,n,s,r){return c(this,void 0,void 0,function*(){let i=this._materialMap.get(e);if(void 0===i){const r=n&&Object.keys(n).some(e=>e.startsWith("uv"));if((e=e instanceof t.MultiMaterial?e.subMaterials[s.materialIndex]:e)instanceof t.PBRBaseMaterial)i=yield this._materialExporter.exportPBRMaterialAsync(e,r);else if(e instanceof t.StandardMaterial)i=yield this._materialExporter.exportStandardMaterialAsync(e,r);else{if(!(e instanceof t.OpenPBRMaterial))return void t.Logger.Warn(`Unsupported material '${e.name}' with type ${e.getClassName()}`);i=yield this._materialExporter.exportOpenPBRMaterialAsync(e,r)}this._materialMap.set(e,i)}r.material=i})}_exportMeshAsync(e,n){return c(this,void 0,void 0,function*(){var s,r,i,o,a,l;let u=n.getMesh(e);if(void 0!==u)return u;const c={primitives:[]};u=this._meshes.length,this._meshes.push(c),n.setMesh(e,u);const h=e.isUnIndexed?null:e.getIndices(),d=null===(s=e.geometry)||void 0===s?void 0:s.getVertexBuffers(),f=n.getMorphTargetsFromMesh(e),p=e instanceof t.LinesMesh,m=e instanceof t.GreasedLineBaseMesh,g=e.subMeshes;if(d&&g&&g.length>0)for(const s of g){const u={attributes:{}},g=s.getMaterial()||this._babylonScene.defaultMaterial;if(m){const n={name:g.name},s=e,l=t.Color3.White(),c=null!==(i=null===(r=s.material)||void 0===r?void 0:r.alpha)&&void 0!==i?i:1,h=null!==(a=null===(o=s.greasedLineMaterial)||void 0===o?void 0:o.color)&&void 0!==a?a:l;(!h.equalsWithEpsilon(l,t.Epsilon)||c<1)&&(n.pbrMetallicRoughness={baseColorFactor:[...h.asArray(),c]}),this._materials.push(n),u.material=this._materials.length-1}else if(p){const n={name:g.name},s=e;(!s.color.equalsWithEpsilon(t.Color3.White(),t.Epsilon)||s.alpha<1)&&(n.pbrMetallicRoughness={baseColorFactor:[...s.color.asArray(),s.alpha]}),this._materials.push(n),u.material=this._materials.length-1}else yield this._exportMaterialAsync(g,d,s,u);const x=p||m?t.Material.LineListDrawMode:null!==(l=e.overrideRenderingFillMode)&&void 0!==l?l:g.fillMode;let _=g._getEffectiveOrientation(e);n.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(_=_===t.Material.ClockWiseSideOrientation?t.Material.CounterClockWiseSideOrientation:t.Material.ClockWiseSideOrientation),this._exportIndices(h,h?t.AreIndices32Bits(h,s.indexCount,s.indexStart,s.verticesStart):s.verticesCount>65535,h?s.indexStart:s.verticesStart,h?s.indexCount:s.verticesCount,-s.verticesStart,x,_,n,u);for(const e of Object.values(d))this._exportVertexBuffer(e,g,s.verticesStart,s.verticesCount,n,u);if(f){u.targets=[];for(const e of f)u.targets.push(e.attributes)}c.primitives.push(u),this._extensionsPostExportMeshPrimitive(u)}if(f){c.weights=[],c.extras||(c.extras={}),c.extras.targetNames=[];for(const e of f)c.weights.push(e.influence),c.extras.targetNames.push(e.name)}return u})}}Z._ExtensionNames=new Array,Z._ExtensionFactories={},Z._ExtensionOrders={};class Y{static GLTFAsync(e,t,n){return c(this,void 0,void 0,function*(){n&&n.exportWithoutWaitingForScene||(yield e.whenReadyAsync());const s=new Z(e,n),r=yield s.generateGLTFAsync(t.replace(/\.[^/.]+$/,""));return s.dispose(),r})}static GLBAsync(e,t,n){return c(this,void 0,void 0,function*(){n&&n.exportWithoutWaitingForScene||(yield e.whenReadyAsync());const s=new Z(e,n),r=yield s.generateGLBAsync(t.replace(/\.[^/.]+$/,""));return s.dispose(),r})}}var J={__proto__:null,GLTF2Export:Y};const ee="EXT_mesh_gpu_instancing";function te(e,t){const n=new Float32Array(3*t);for(let s=0;s<t;s++)n[3*s+0]=e[4*s+0],n[3*s+1]=e[4*s+1],n[3*s+2]=e[4*s+2];return n}class ne{constructor(e){this.name=ee,this.enabled=!0,this.required=!1,this._instanceColorWarned=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportNodeAsync(e,n,s,r,i,o){return c(this,void 0,void 0,function*(){return yield new Promise(e=>{var r,a;if(n&&s instanceof t.Mesh&&s.hasThinInstances&&this._exporter){this._wasUsed=!0;const e=t.Vector3.Zero(),l=t.Quaternion.Identity(),u=t.Vector3.One(),c=s.thinInstanceGetWorldMatrices(),h=t.TmpVectors.Vector3[2],d=t.TmpVectors.Quaternion[1],f=t.TmpVectors.Vector3[3];let p=!1,m=!1,g=!1;const x=new Float32Array(3*s.thinInstanceCount),_=new Float32Array(4*s.thinInstanceCount),T=new Float32Array(3*s.thinInstanceCount);let y=0;for(const t of c)t.decompose(f,d,h),i&&(B(h),P(d)),x.set(h.asArray(),3*y),_.set(d.normalize().asArray(),4*y),T.set(f.asArray(),3*y),p=p||!h.equalsWithEpsilon(e),m=m||!d.equalsWithEpsilon(l),g=g||!f.equalsWithEpsilon(u),y++;const b={attributes:{}};p&&(b.attributes.TRANSLATION=this._buildAccessor(x,"VEC3",s.thinInstanceCount,o)),m&&(b.attributes.ROTATION=this._buildAccessor(_,"VEC4",s.thinInstanceCount,o)),g&&(b.attributes.SCALE=this._buildAccessor(T,"VEC3",s.thinInstanceCount,o));let v=null===(a=null===(r=s._userThinInstanceBuffersStorage)||void 0===r?void 0:r.data)||void 0===a?void 0:a.instanceColor;if(v){const e=s.thinInstanceCount,n="VEC3";s.hasVertexAlpha&&v.length===4*e?(this._instanceColorWarned||(t.Logger.Warn("EXT_mesh_gpu_instancing: Exporting instance colors as RGB, alpha channel of instance color is not exported"),this._instanceColorWarned=!0),v=te(v,e)):v.length===4*e&&(v=te(v,e)),v.length===3*e&&(b.attributes._COLOR_0=this._buildAccessor(v,n,e,o))}n.extensions=n.extensions||{},n.extensions[ee]=b}e(n)})})}_buildAccessor(e,t,n,s){const r=s.createBufferView(e),i=s.createAccessor(r,t,5126,n);return this._exporter._accessors.push(i),this._exporter._accessors.length-1}}let se=!1;function re(){se||(se=!0,Z.RegisterExtension(ee,e=>new ne(e)))}re();const ie="KHR_draco_mesh_compression";function oe(e){return"POSITION"===e?"POSITION":"NORMAL"===e?"NORMAL":e.startsWith("COLOR")?"COLOR":e.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"}class ae{get wasUsed(){return this._wasUsed}constructor(e){this.name=ie,this.required=!0,this._bufferViewsUsed=new Set,this._accessorsUsed=new Set,this._encodePromises=[],this._wasUsed=!1,this.enabled="Draco"===e.options.meshCompressionMethod&&t.DracoEncoder.DefaultAvailable}dispose(){}postExportMeshPrimitive(e,n,s){if(!this.enabled)return;if(4!==e.mode&&5!==e.mode)return void t.Logger.Warn("Cannot compress primitive with mode "+e.mode+".");const r=[],i=[];let o=null;if(void 0!==e.indices){const t=s[e.indices],a=n.getBufferView(t);o=n.getData(a).slice(),r.push(a),i.push(t)}const a=[];for(const[o,l]of Object.entries(e.attributes)){const e=s[l],u=n.getBufferView(e),c=S(e.type),h=t.GetTypedArrayData(n.getData(u),c,e.componentType,e.byteOffset||0,u.byteStride||t.GetTypeByteLength(e.componentType)*c,e.count,!0);a.push({kind:o,dracoName:oe(o),size:S(e.type),data:h}),r.push(u),i.push(e)}const l={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},u=t.DracoEncoder.Default._encodeAsync(a,o,l).then(t=>{const s={bufferView:-1,attributes:t.attributeIds},o=n.createBufferView(t.data);n.setBufferView(s,o);for(const e of r)this._bufferViewsUsed.add(e);for(const e of i)this._accessorsUsed.add(e);e.extensions||(e.extensions={}),e.extensions[ie]=s}).catch(e=>{t.Logger.Error("KHR_draco_mesh_compression: Failed to export Draco-encoded primitive. Resulting glTF may be invalid. "+e.message)});this._encodePromises.push(u),this._wasUsed=!0}preGenerateBinaryAsync(e){return c(this,void 0,void 0,function*(){this.enabled&&(yield Promise.all(this._encodePromises),this._bufferViewsUsed.forEach(t=>{e.getPropertiesWithBufferView(t).every(e=>this._accessorsUsed.has(e))&&e.removeBufferView(t)}),this._bufferViewsUsed.clear(),this._accessorsUsed.clear())})}}let le=!1;function ue(){le||(le=!0,Z.RegisterExtension(ie,e=>new ae(e)))}ue();const ce="KHR_lights_punctual",he={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},de={innerConeAngle:0,outerConeAngle:Math.PI/4},fe=t.Vector3.Backward();class pe{constructor(e){this.name=ce,this.enabled=!0,this.required=!1,this._exporter=e}dispose(){this._lights=null}get wasUsed(){return!!this._lights}onExporting(){this._exporter._glTF.extensions[ce]=this._lights}postExportNodeAsync(e,n,s,r,i){return c(this,void 0,void 0,function*(){return yield new Promise(o=>{if(!(s instanceof t.Light))return void o(n);const a=s.getTypeID()==t.Light.LIGHTTYPEID_POINTLIGHT?"point":s.getTypeID()==t.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":s.getTypeID()==t.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(a&&s instanceof t.ShadowLight))return t.Logger.Warn(`${e}: Light ${s.name} is not supported in ${ce}`),void o(n);if(s.falloffType!==t.Light.FALLOFF_GLTF&&t.Logger.Warn(`${e}: Light falloff for ${s.name} does not match the ${ce} specification!`),!s.position.equalsToFloats(0,0,0)){const e=t.TmpVectors.Vector3[0].copyFrom(s.position);i&&B(e),n.translation=e.asArray()}if("point"!==a){const e=s.direction.normalizeToRef(t.TmpVectors.Vector3[0]);i&&B(e);const r=t.Quaternion.FromUnitVectorsToRef(fe,e,t.TmpVectors.Quaternion[0]);t.Quaternion.IsIdentity(r)||(n.rotation=r.asArray())}const l={type:a,name:s.name,color:s.diffuse.asArray(),intensity:s.intensity,range:s.range};if(z(l,he),"spot"===a){const e=s;l.spot={innerConeAngle:e.innerAngle/2,outerConeAngle:e.angle/2},z(l.spot,de)}this._lights||(this._lights={lights:[]}),this._lights.lights.push(l);const u={light:this._lights.lights.length-1},c=s.parent;if(c&&K(s,c)){const e=r.get(c);if(e){const t=this._exporter._nodes[e];return k(n,t),t.extensions||(t.extensions={}),t.extensions[ce]=u,void o(null)}}n.extensions||(n.extensions={}),n.extensions[ce]=u,o(n)})})}}let me=!1;function ge(){me||(me=!0,Z.RegisterExtension(ce,e=>new pe(e)))}ge();const xe="EXT_lights_area",_e={name:"",color:[1,1,1],intensity:1,size:1},Te={aspect:1},ye=t.Vector3.Backward();class be{constructor(e){this.name=xe,this.enabled=!0,this.required=!1,this._exporter=e}dispose(){this._lights=null}get wasUsed(){return!!this._lights}onExporting(){this._exporter._glTF.extensions[xe]=this._lights}postExportNodeAsync(e,n,s,r,i){return c(this,void 0,void 0,function*(){return yield new Promise(o=>{if(!(s instanceof t.Light))return void o(n);const a=s.getTypeID()==t.Light.LIGHTTYPEID_RECT_AREALIGHT?"rect":null;if(!a)return t.Logger.Warn(`${e}: Light ${s.name} is not supported in ${xe}`),void o(n);const l=s;if(l.falloffType!==t.Light.FALLOFF_GLTF&&t.Logger.Warn(`${e}: Light falloff for ${s.name} does not match the ${xe} specification!`),!l.position.equalsToFloats(0,0,0)){const e=t.TmpVectors.Vector3[0].copyFrom(l.position);i&&B(e),n.translation=e.asArray()}const u=t.Vector3.Forward();i&&B(u);const c=t.Quaternion.FromUnitVectorsToRef(ye,u,t.TmpVectors.Quaternion[0]);t.Quaternion.IsIdentity(c)||(n.rotation=c.asArray());const h={type:a,name:l.name,color:l.diffuse.asArray(),intensity:l.intensity,size:l.height,rect:{aspect:l.width/l.height}};z(h,_e),h.rect&&z(h.rect,Te),this._lights||(this._lights={lights:[]}),this._lights.lights.push(h);const d={light:this._lights.lights.length-1},f=s.parent;if(f&&K(l,f)){const e=r.get(f);if(e){const t=this._exporter._nodes[e];return k(n,t),t.extensions||(t.extensions={}),t.extensions[xe]=d,void o(null)}}n.extensions||(n.extensions={}),n.extensions[xe]=d,o(n)})})}}let ve=!1;function Me(){ve||(ve=!0,Z.RegisterExtension(xe,e=>new be(e)))}Me();const we="KHR_materials_anisotropy";class Re{constructor(e){this.name=we,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._anisoTexturesMap={},this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const e=[];if(s instanceof t.PBRBaseMaterial){if(s.anisotropy.isEnabled&&!s.anisotropy.legacy)return s.anisotropy.texture&&e.push(s.anisotropy.texture),e}else if(s instanceof t.OpenPBRMaterial&&s.specularRoughnessAnisotropy>0){const n=function(e){const t=e.specularRoughnessAnisotropyTexture,n=e.geometryTangentTexture;return`${t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength"}_${n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoTangent"}`}(s);if(this._anisoTexturesMap[n])e.push(this._anisoTexturesMap[n]);else{const r=yield function(e){return c(this,void 0,void 0,function*(){const n=e.getScene(),s=e.specularRoughnessAnisotropyTexture,r=e.geometryTangentTexture;return s||r?yield t.MergeTexturesAsync("AnisotropyTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),r?t.CreateTextureInput(r,1):t.CreateConstantInput(0),s?t.CreateTextureInput(s,0):t.CreateConstantInput(1)),n):null})}(s);r&&(e.push(r),this._anisoTexturesMap[n]=r)}return e}return[]})}postExportMaterialAsync(e,n,s){return new Promise(e=>{var r;if(s instanceof t.PBRBaseMaterial){if(!s.anisotropy.isEnabled||s.anisotropy.legacy)return void e(n);this._wasUsed=!0,n.extensions=n.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(s.anisotropy.texture),r={anisotropyStrength:s.anisotropy.intensity,anisotropyRotation:s.anisotropy.angle,anisotropyTexture:null!=t?t:void 0};null!==r.anisotropyTexture&&this._exporter._materialNeedsUVsSet.add(s),n.extensions[we]=r}else if(s instanceof t.OpenPBRMaterial&&s.specularRoughnessAnisotropy>0){this._wasUsed=!0,n.extensions=n.extensions||{};let t=s.specularRoughnessTexture;s._useRoughnessFromMetallicTextureGreen&&(t=s.baseMetalnessTexture);const i=this._anisoTexturesMap[s.id];if(!t&&!i){let t=s.specularRoughness,r=s.specularRoughnessAnisotropy;if(!s._useGltfStyleAnisotropy){const e=function(e,t){const n=e*e,s=n*Math.sqrt(2/(1+(1-t)*(1-t))),r=(1-t)*s;return{newBaseRoughness:Math.sqrt(r),newAnisotropyStrength:Math.min(Math.sqrt((s-n)/Math.max(1-n,1e-4)),1)}}(s.specularRoughness,s.specularRoughnessAnisotropy);t=e.newBaseRoughness,r=e.newAnisotropyStrength}n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=t);const i={anisotropyStrength:r,anisotropyRotation:s.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return n.extensions[we]=i,e(n)}const o=i?this._exporter._materialExporter.getTextureInfo(i):null,a={anisotropyStrength:s.specularRoughnessAnisotropy,anisotropyRotation:s.geometryTangentAngle,anisotropyTexture:o||void 0,extensions:{}};s._useGltfStyleAnisotropy||(n.extensions.KHR_materials_openpbr={},(r=this._exporter._glTF).extensionsUsed||(r.extensionsUsed=[]),-1===this._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&this._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr")),this._exporter._materialNeedsUVsSet.add(s),n.extensions[we]=a}e(n)})}}let Ae=!1;function Ce(){Ae||(Ae=!0,Z.RegisterExtension(we,e=>new Re(e)))}Ce();const Ee="KHR_materials_clearcoat";function Ie(e,n){const s=new t.Texture(n.name,n.getScene());return s._texture=e,s.coordinatesIndex=n.coordinatesIndex,n instanceof t.Texture&&(s.uOffset=n.uOffset,s.vOffset=n.vOffset,s.uScale=n.uScale,s.vScale=n.vScale,s.wAng=n.wAng),s.wrapU=n.wrapU,s.wrapV=n.wrapV,s}class Se{constructor(e){this.name=Ee,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}dispose(){for(const e of Object.keys(this._mergedTexturesMap))this._mergedTexturesMap[e].dispose();this._mergedTexturesMap={};for(const e of Object.keys(this._cachedInternalTexturesMap))this._cachedInternalTexturesMap[e].dispose();this._cachedInternalTexturesMap={}}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const e=[];if(s instanceof t.PBRBaseMaterial){if(s.clearCoat.isEnabled)return s.clearCoat.texture&&e.push(s.clearCoat.texture),!s.clearCoat.useRoughnessFromMainTexture&&s.clearCoat.textureRoughness&&e.push(s.clearCoat.textureRoughness),s.clearCoat.bumpTexture&&e.push(s.clearCoat.bumpTexture),e}else if(s instanceof t.OpenPBRMaterial&&s.coatWeight>0){let n=!1;if(s.coatWeightTexture?s.coatRoughnessTexture?s._useCoatRoughnessFromGreenChannel&&s.coatWeightTexture.getInternalTexture()===s.coatRoughnessTexture.getInternalTexture()?(e.push(s.coatWeightTexture),e.push(s.coatRoughnessTexture)):n=!0:e.push(s.coatWeightTexture):s.coatRoughnessTexture&&(s._useCoatRoughnessFromGreenChannel?e.push(s.coatRoughnessTexture):n=!0),n){const n=function(e){const t=e.coatWeightTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",s=e.coatRoughnessTexture;return`${n}_${s&&s.getInternalTexture()?s.getInternalTexture().uniqueId:"NoRoughness"}`}(s);if(!this._cachedInternalTexturesMap[n]){const e=yield function(e){return c(this,void 0,void 0,function*(){const n=e.getScene(),s=e.coatWeightTexture,r=e.coatRoughnessTexture;return s||r?(yield t.MergeTexturesAsync("CoatTexture",t.CreateRGBAConfiguration(s?t.CreateTextureInput(s,0):t.CreateConstantInput(1),r?t.CreateTextureInput(r,e._useCoatRoughnessFromGreenChannel?1:0):t.CreateConstantInput(1)),n)).getInternalTexture():null})}(s);e&&(this._cachedInternalTexturesMap[n]=e)}this._cachedInternalTexturesMap[n]&&(s.coatWeightTexture&&(this._mergedTexturesMap[s.coatWeightTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[n],s.coatWeightTexture),e.push(this._mergedTexturesMap[s.coatWeightTexture.uniqueId])),s.coatRoughnessTexture&&(this._mergedTexturesMap[s.coatRoughnessTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[n],s.coatRoughnessTexture),e.push(this._mergedTexturesMap[s.coatRoughnessTexture.uniqueId])))}return s.geometryCoatNormalTexture&&e.push(s.geometryCoatNormalTexture),e}return[]})}postExportMaterialAsync(e,n,s){return new Promise(e=>{if(s instanceof t.PBRBaseMaterial){if(!s.clearCoat.isEnabled)return void e(n);this._wasUsed=!0,n.extensions=n.extensions||{};const r=this._exporter._materialExporter.getTextureInfo(s.clearCoat.texture);let i;i=s.clearCoat.useRoughnessFromMainTexture?this._exporter._materialExporter.getTextureInfo(s.clearCoat.texture):this._exporter._materialExporter.getTextureInfo(s.clearCoat.textureRoughness),s.clearCoat.isTintEnabled&&t.Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${s.name}`),s.clearCoat.remapF0OnInterfaceChange&&t.Tools.Warn(`Clear Color F0 remapping is not supported for glTF export. Ignoring for: ${s.name}`);const o=this._exporter._materialExporter.getTextureInfo(s.clearCoat.bumpTexture),a={clearcoatFactor:s.clearCoat.intensity,clearcoatTexture:null!=r?r:void 0,clearcoatRoughnessFactor:s.clearCoat.roughness,clearcoatRoughnessTexture:null!=i?i:void 0,clearcoatNormalTexture:null!=o?o:void 0};null===a.clearcoatTexture&&null===a.clearcoatRoughnessTexture&&null===a.clearcoatRoughnessTexture||this._exporter._materialNeedsUVsSet.add(s),n.extensions[Ee]=a}else if(s instanceof t.OpenPBRMaterial){if(0==s.coatWeight)return void e(n);let r,i,o,a;this._wasUsed=!0,n.extensions=n.extensions||{},s.coatWeightTexture&&(r=this._mergedTexturesMap[s.coatWeightTexture.uniqueId],i=this._exporter._materialExporter.getTextureInfo(r)),s.coatRoughnessTexture&&(o=this._mergedTexturesMap[s.coatRoughnessTexture.uniqueId],a=this._exporter._materialExporter.getTextureInfo(o)),s.coatColorTexture&&t.Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${s.name}`);const l=this._exporter._materialExporter.getTextureInfo(s.geometryCoatNormalTexture),u={clearcoatFactor:s.coatWeight,clearcoatTexture:null!=i?i:void 0,clearcoatRoughnessFactor:s.coatRoughness,clearcoatRoughnessTexture:null!=a?a:void 0,clearcoatNormalTexture:null!=l?l:void 0};null===u.clearcoatTexture&&null===u.clearcoatRoughnessTexture&&null===u.clearcoatRoughnessTexture||this._exporter._materialNeedsUVsSet.add(s),n.extensions[Ee]=u}e(n)})}}let Ve=!1;function Fe(){Ve||(Ve=!0,Z.RegisterExtension(Ee,e=>new Se(e)))}Fe();const Oe="KHR_materials_coat";function Be(e){const t=e.coatRoughnessAnisotropyTexture,n=e.geometryCoatTangentTexture;return`${t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength"}_${n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoTangent"}`}function Ne(e,n){const s=new t.Texture(n.name,n.getScene());return s._texture=e,s.coordinatesIndex=n.coordinatesIndex,n instanceof t.Texture&&(s.uOffset=n.uOffset,s.vOffset=n.vOffset,s.uScale=n.uScale,s.vScale=n.vScale,s.wAng=n.wAng),s.wrapU=n.wrapU,s.wrapV=n.wrapV,s}class Pe{constructor(e){this.name=Oe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}dispose(){for(const e of Object.keys(this._mergedTexturesMap))this._mergedTexturesMap[e].dispose();this._mergedTexturesMap={};for(const e of Object.keys(this._cachedInternalTexturesMap))this._cachedInternalTexturesMap[e].dispose();this._cachedInternalTexturesMap={}}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const e=[];if(s instanceof t.PBRBaseMaterial){if(s.clearCoat.isEnabled)return s.clearCoat.texture&&e.push(s.clearCoat.texture),!s.clearCoat.useRoughnessFromMainTexture&&s.clearCoat.textureRoughness&&e.push(s.clearCoat.textureRoughness),s.clearCoat.bumpTexture&&e.push(s.clearCoat.bumpTexture),s.clearCoat.tintTexture&&e.push(s.clearCoat.tintTexture),e}else if(s instanceof t.OpenPBRMaterial&&s.coatWeight>0){let n=!1;if(s.coatWeightTexture?s.coatRoughnessTexture?s._useCoatRoughnessFromGreenChannel&&s.coatWeightTexture.getInternalTexture()===s.coatRoughnessTexture.getInternalTexture()?(e.push(s.coatWeightTexture),e.push(s.coatRoughnessTexture)):n=!0:e.push(s.coatWeightTexture):s.coatRoughnessTexture&&(s._useCoatRoughnessFromGreenChannel?e.push(s.coatRoughnessTexture):n=!0),n){const n=function(e){const t=e.coatWeightTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",s=e.coatRoughnessTexture;return`${n}_${s&&s.getInternalTexture()?s.getInternalTexture().uniqueId:"NoRoughness"}`}(s);if(!this._cachedInternalTexturesMap[n]){const e=yield function(e){return c(this,void 0,void 0,function*(){const n=e.getScene(),s=e.coatWeightTexture,r=e.coatRoughnessTexture;return s||r?(yield t.MergeTexturesAsync("CoatTexture",t.CreateRGBAConfiguration(s?t.CreateTextureInput(s,0):t.CreateConstantInput(1),r?t.CreateTextureInput(r,e._useCoatRoughnessFromGreenChannel?1:0):t.CreateConstantInput(1)),n)).getInternalTexture():null})}(s);e&&(this._cachedInternalTexturesMap[n]=e)}this._cachedInternalTexturesMap[n]&&(s.coatWeightTexture&&(this._mergedTexturesMap[s.coatWeightTexture.uniqueId]=Ne(this._cachedInternalTexturesMap[n],s.coatWeightTexture),e.push(this._mergedTexturesMap[s.coatWeightTexture.uniqueId])),s.coatRoughnessTexture&&(this._mergedTexturesMap[s.coatRoughnessTexture.uniqueId]=Ne(this._cachedInternalTexturesMap[n],s.coatRoughnessTexture),e.push(this._mergedTexturesMap[s.coatRoughnessTexture.uniqueId])))}if(s.geometryCoatNormalTexture&&e.push(s.geometryCoatNormalTexture),s.coatColorTexture&&e.push(s.coatColorTexture),s.coatRoughnessAnisotropy>0){const n=Be(s);if(this._mergedTexturesMap[n])e.push(this._mergedTexturesMap[n]);else{const r=yield function(e){return c(this,void 0,void 0,function*(){const n=e.getScene(),s=e.coatRoughnessAnisotropyTexture,r=e.geometryCoatTangentTexture;return s||r?yield t.MergeTexturesAsync("AnisotropyTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),r?t.CreateTextureInput(r,1):t.CreateConstantInput(0),s?t.CreateTextureInput(s,0):t.CreateConstantInput(1)),n):null})}(s);r&&(e.push(r),this._mergedTexturesMap[n]=r)}return e}return e}return[]})}postExportMaterialAsync(e,n,s){return new Promise(e=>{var r;if(s instanceof t.PBRBaseMaterial){if(!s.clearCoat.isEnabled)return void e(n);this._wasUsed=!0,n.extensions=n.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(s.clearCoat.texture);let r,i;r=s.clearCoat.useRoughnessFromMainTexture?this._exporter._materialExporter.getTextureInfo(s.clearCoat.texture):this._exporter._materialExporter.getTextureInfo(s.clearCoat.textureRoughness),s.clearCoat.isTintEnabled&&(i=this._exporter._materialExporter.getTextureInfo(s.clearCoat.tintTexture));const o=this._exporter._materialExporter.getTextureInfo(s.clearCoat.bumpTexture),a=s.clearCoat.indexOfRefraction,l={coatFactor:s.clearCoat.intensity,coatTexture:null!=t?t:void 0,coatRoughnessFactor:s.clearCoat.roughness,coatRoughnessTexture:null!=r?r:void 0,coatNormalTexture:null!=o?o:void 0,coatColorFactor:s.clearCoat.tintColor.asArray(),coatColorTexture:null!=i?i:void 0,coatIor:1.5!==a?a:void 0};null===l.coatTexture&&null===l.coatRoughnessTexture&&null===l.coatRoughnessTexture&&null===l.coatColorTexture||this._exporter._materialNeedsUVsSet.add(s),n.extensions[Oe]=l}else if(s instanceof t.OpenPBRMaterial){if(0==s.coatWeight)return void e(n);let t,i,o,a;this._wasUsed=!0,n.extensions=n.extensions||{},s.coatWeightTexture&&(t=this._mergedTexturesMap[s.coatWeightTexture.uniqueId]?this._mergedTexturesMap[s.coatWeightTexture.uniqueId]:s.coatWeightTexture,i=this._exporter._materialExporter.getTextureInfo(t)),s.coatRoughnessTexture&&(o=this._mergedTexturesMap[s.coatRoughnessTexture.uniqueId]?this._mergedTexturesMap[s.coatRoughnessTexture.uniqueId]:s.coatRoughnessTexture,a=this._exporter._materialExporter.getTextureInfo(o));const l=this._exporter._materialExporter.getTextureInfo(s.geometryCoatNormalTexture),u=this._exporter._materialExporter.getTextureInfo(s.coatColorTexture),c=s.coatIor,h=s.coatDarkening,d=s.coatRoughnessTexture,f=Be(s),p=this._mergedTexturesMap[f];let m,g=0,x=0;if(s.coatRoughnessAnisotropy>0){if(d||p){const e=p?this._exporter._materialExporter.getTextureInfo(p):null;g=s.coatRoughnessAnisotropy,x=s.geometryCoatTangentAngle,m=e||void 0}else{let e=s.coatRoughness,t=s.coatRoughnessAnisotropy;if(!s._useGltfStyleAnisotropy){const n=function(e,t){const n=e*e,s=n*Math.sqrt(2/(1+(1-t)*(1-t))),r=(1-t)*s;return{newBaseRoughness:Math.sqrt(r),newAnisotropyStrength:Math.min(Math.sqrt((s-n)/Math.max(1-n,1e-4)),1)}}(s.coatRoughness,s.coatRoughnessAnisotropy);e=n.newBaseRoughness,t=n.newAnisotropyStrength}n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=e),g=t,x=s.geometryCoatTangentAngle+.5*Math.PI,m=void 0}s._useGltfStyleAnisotropy||(n.extensions.KHR_materials_openpbr={},(r=this._exporter._glTF).extensionsUsed||(r.extensionsUsed=[]),-1===this._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&this._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr"))}const _={coatFactor:s.coatWeight,coatTexture:null!=i?i:void 0,coatRoughnessFactor:s.coatRoughness,coatRoughnessTexture:null!=a?a:void 0,coatNormalTexture:null!=l?l:void 0,coatColorFactor:s.coatColor.asArray(),coatColorTexture:null!=u?u:void 0,coatIor:1.5!==c?c:void 0,coatDarkeningFactor:1!==h?h:void 0,coatAnisotropyRotation:x,coatAnisotropyStrength:g,coatAnisotropyTexture:m};null===_.coatTexture&&null===_.coatRoughnessTexture&&null===_.coatRoughnessTexture&&null===_.coatAnisotropyTexture&&null===_.coatColorTexture||this._exporter._materialNeedsUVsSet.add(s),n.extensions[Oe]=_}e(n)})}}let Ue=!1;function ke(){Ue||(Ue=!0,Z.RegisterExtension(Oe,e=>new Pe(e)))}ke();const Ke="KHR_materials_diffuse_transmission";function $e(e,n){const s=n.subSurface;let r=null;return s.translucencyIntensityTexture?r=s.translucencyIntensityTexture:s.thicknessTexture&&s.useMaskFromThicknessTexture&&(r=s.thicknessTexture),r&&!s.useGltfStyleTextures?(t.Logger.Warn(`${e}: Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ${n.name}`,1),null):r}class ze{constructor(e){this.name=Ke,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const n=[];if(s instanceof t.PBRMaterial&&this._isExtensionEnabled(s)){const t=$e(e,s);return t&&n.push(t),s.subSurface.translucencyColorTexture&&n.push(s.subSurface.translucencyColorTexture),n}return n})}_isExtensionEnabled(e){if(e.unlit)return!1;const t=e.subSurface;return!!t.isTranslucencyEnabled&&!e.unlit&&!t.useAlbedoToTintTranslucency&&t.useGltfStyleTextures&&1===t.volumeIndexOfRefraction&&0===t.minimumThickness&&0===t.maximumThickness}postExportMaterialAsync(e,n,s){return new Promise(r=>{var i,o;if(s instanceof t.PBRMaterial&&this._isExtensionEnabled(s)){this._wasUsed=!0;const t=s.subSurface,r=$e(e,s),a=0==t.translucencyIntensity?void 0:t.translucencyIntensity,l=null!==(i=this._exporter._materialExporter.getTextureInfo(r))&&void 0!==i?i:void 0,u=!t.translucencyColor||t.translucencyColor.equalsFloats(1,1,1)?void 0:t.translucencyColor.asArray(),c=null!==(o=this._exporter._materialExporter.getTextureInfo(t.translucencyColorTexture))&&void 0!==o?o:void 0,h={diffuseTransmissionFactor:a,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:u,diffuseTransmissionColorTexture:c};(l||c)&&this._exporter._materialNeedsUVsSet.add(s),n.extensions=n.extensions||{},n.extensions[Ke]=h}r(n)})}}let We=!1;function De(){We||(We=!0,Z.RegisterExtension(Ke,e=>new ze(e)))}De();const Le="KHR_materials_dispersion";class He{constructor(){this.name=Le,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}_isExtensionEnabled(e){if(e.unlit)return!1;const t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isDispersionEnabled)}postExportMaterialAsync(e,n,s){return new Promise(e=>{if(s instanceof t.PBRMaterial&&this._isExtensionEnabled(s)){this._wasUsed=!0;const e={dispersion:s.subSurface.dispersion};n.extensions=n.extensions||{},n.extensions[Le]=e}e(n)})}}let je=!1;function qe(){je||(je=!0,Z.RegisterExtension(Le,()=>new He))}qe();const Ge="KHR_materials_emissive_strength";class Xe{constructor(){this.name=Ge,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAsync(e,n,s){return c(this,void 0,void 0,function*(){return yield new Promise(e=>{if(!(s instanceof t.PBRMaterial))return e(n);const r=s.emissiveColor.scale(s.emissiveIntensity),i=Math.max(...r.asArray());if(i>1){n.emissiveFactor=r.scale(1/i).asArray(),this._wasUsed=!0;const e={emissiveStrength:i};n.extensions||(n.extensions={}),n.extensions[Ge]=e}else n.emissiveFactor=r.asArray();return e(n)})})}}let Qe=!1;function Ze(){Qe||(Qe=!0,Z.RegisterExtension(Ge,()=>new Xe))}Ze();const Ye="KHR_materials_ior";class Je{constructor(){this.name=Ye,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}_isExtensionEnabled(e){return!e.unlit&&(e instanceof t.OpenPBRMaterial?1.5!=e.specularIor:e instanceof t.PBRMaterial&&null!=e.indexOfRefraction&&1.5!=e.indexOfRefraction)}postExportMaterialAsync(e,n,s){return new Promise(e=>{if(s instanceof t.PBRMaterial&&this._isExtensionEnabled(s)){this._wasUsed=!0;const e={ior:s.indexOfRefraction};n.extensions=n.extensions||{},n.extensions[Ye]=e}else if(s instanceof t.OpenPBRMaterial&&this._isExtensionEnabled(s)){this._wasUsed=!0;const e={ior:s.specularIor};n.extensions=n.extensions||{},n.extensions[Ye]=e}e(n)})}}let et=!1;function tt(){et||(et=!0,Z.RegisterExtension(Ye,()=>new Je))}tt();const nt="KHR_materials_iridescence";class st{constructor(e){this.name=nt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const e=[];if(s instanceof t.PBRBaseMaterial){if(s.iridescence.isEnabled)return s.iridescence.texture&&e.push(s.iridescence.texture),s.iridescence.thicknessTexture&&s.iridescence.thicknessTexture!==s.iridescence.texture&&e.push(s.iridescence.thicknessTexture),e}else if(s instanceof t.OpenPBRMaterial&&s.thinFilmWeight>0)return s.thinFilmWeightTexture&&e.push(s.thinFilmWeightTexture),s.thinFilmThicknessTexture&&s.thinFilmThicknessTexture!==s.thinFilmWeightTexture&&e.push(s.thinFilmThicknessTexture),e;return[]})}postExportMaterialAsync(e,n,s){return new Promise(e=>{if(s instanceof t.PBRBaseMaterial){if(!s.iridescence.isEnabled)return void e(n);this._wasUsed=!0,n.extensions=n.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(s.iridescence.texture),r=this._exporter._materialExporter.getTextureInfo(s.iridescence.thicknessTexture),i={iridescenceFactor:s.iridescence.intensity,iridescenceIor:s.iridescence.indexOfRefraction,iridescenceThicknessMinimum:s.iridescence.minimumThickness,iridescenceThicknessMaximum:s.iridescence.maximumThickness,iridescenceTexture:null!=t?t:void 0,iridescenceThicknessTexture:null!=r?r:void 0};null===i.iridescenceTexture&&null===i.iridescenceThicknessTexture||this._exporter._materialNeedsUVsSet.add(s),n.extensions[nt]=i}else if(s instanceof t.OpenPBRMaterial){if(s.thinFilmWeight<=0)return void e(n);this._wasUsed=!0,n.extensions=n.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(s.thinFilmWeightTexture),r=this._exporter._materialExporter.getTextureInfo(s.thinFilmThicknessTexture),i={iridescenceFactor:s.thinFilmWeight,iridescenceIor:s.thinFilmIor,iridescenceThicknessMinimum:1e3*s.thinFilmThicknessMin,iridescenceThicknessMaximum:1e3*s.thinFilmThickness,iridescenceTexture:null!=t?t:void 0,iridescenceThicknessTexture:null!=r?r:void 0};null===i.iridescenceTexture&&null===i.iridescenceThicknessTexture||this._exporter._materialNeedsUVsSet.add(s),n.extensions[nt]=i}e(n)})}}let rt=!1;function it(){rt||(rt=!0,Z.RegisterExtension(nt,e=>new st(e)))}it();const ot="KHR_materials_sheen";class at{constructor(e){this.name=ot,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){return s instanceof t.PBRMaterial&&s.sheen.isEnabled&&s.sheen.texture?[s.sheen.texture]:[]})}postExportMaterialAsync(e,n,s){return c(this,void 0,void 0,function*(){return yield new Promise(e=>{var r,i,o,a;if(s instanceof t.PBRMaterial){if(!s.sheen.isEnabled)return void e(n);this._wasUsed=!0,null==n.extensions&&(n.extensions={});const t={sheenColorFactor:s.sheen.color.asArray(),sheenRoughnessFactor:null!==(r=s.sheen.roughness)&&void 0!==r?r:0};null===t.sheenColorTexture&&null===t.sheenRoughnessTexture||this._exporter._materialNeedsUVsSet.add(s),s.sheen.texture&&(t.sheenColorTexture=null!==(i=this._exporter._materialExporter.getTextureInfo(s.sheen.texture))&&void 0!==i?i:void 0),s.sheen.textureRoughness&&!s.sheen.useRoughnessFromMainTexture?t.sheenRoughnessTexture=null!==(o=this._exporter._materialExporter.getTextureInfo(s.sheen.textureRoughness))&&void 0!==o?o:void 0:s.sheen.texture&&s.sheen.useRoughnessFromMainTexture&&(t.sheenRoughnessTexture=null!==(a=this._exporter._materialExporter.getTextureInfo(s.sheen.texture))&&void 0!==a?a:void 0),n.extensions[ot]=t}e(n)})})}}let lt=!1;function ut(){lt||(lt=!0,Z.RegisterExtension(ot,e=>new at(e)))}ut();const ct="KHR_materials_fuzz";function ht(e,n){const s=new t.Texture(n.name,n.getScene());return s._texture=e,s.coordinatesIndex=n.coordinatesIndex,n instanceof t.Texture&&(s.uOffset=n.uOffset,s.vOffset=n.vOffset,s.uScale=n.uScale,s.vScale=n.vScale,s.wAng=n.wAng),s.wrapU=n.wrapU,s.wrapV=n.wrapV,s}class dt{constructor(e){this.name=ct,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}dispose(){for(const e of Object.keys(this._mergedTexturesMap))this._mergedTexturesMap[e].dispose();this._mergedTexturesMap={};for(const e of Object.keys(this._cachedInternalTexturesMap))this._cachedInternalTexturesMap[e].dispose();this._cachedInternalTexturesMap={}}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){if(s instanceof t.OpenPBRMaterial){const e=[];if(s.fuzzWeight>0){s.fuzzWeightTexture&&e.push(s.fuzzWeightTexture);let n=!1;if(s.fuzzRoughnessTexture&&(s._useFuzzRoughnessFromTextureAlpha?e.push(s.fuzzRoughnessTexture):n=!0),s.fuzzColorTexture&&!n&&e.push(s.fuzzColorTexture),n){const n=function(e){const t=e.fuzzColorTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoFuzzColor",s=e.fuzzRoughnessTexture;return`FuzzColor_${n}_FuzzRoughness_${s&&s.getInternalTexture()?s.getInternalTexture().uniqueId:"NoFuzzRoughness"}`}(s);if(!this._cachedInternalTexturesMap[n]){const e=yield function(e){return c(this,void 0,void 0,function*(){const n=e.getScene(),s=e.fuzzColorTexture,r=e.fuzzRoughnessTexture;return s||r?(yield t.MergeTexturesAsync("FuzzTexture",t.CreateRGBAConfiguration(s?t.CreateTextureInput(s,0):t.CreateConstantInput(1),s?t.CreateTextureInput(s,1):t.CreateConstantInput(1),s?t.CreateTextureInput(s,2):t.CreateConstantInput(1),r?t.CreateTextureInput(r,e._useFuzzRoughnessFromTextureAlpha?3:0):t.CreateConstantInput(1)),n)).getInternalTexture():null})}(s);e&&(this._cachedInternalTexturesMap[n]=e)}this._cachedInternalTexturesMap[n]&&(s.fuzzColorTexture&&(this._mergedTexturesMap[s.fuzzColorTexture.uniqueId]=ht(this._cachedInternalTexturesMap[n],s.fuzzColorTexture),e.push(this._mergedTexturesMap[s.fuzzColorTexture.uniqueId])),s.fuzzRoughnessTexture&&(this._mergedTexturesMap[s.fuzzRoughnessTexture.uniqueId]=ht(this._cachedInternalTexturesMap[n],s.fuzzRoughnessTexture),e.push(this._mergedTexturesMap[s.fuzzRoughnessTexture.uniqueId])))}}return e}return[]})}postExportMaterialAsync(e,n,s){return c(this,void 0,void 0,function*(){return yield new Promise(e=>{var r,i,o;if(s instanceof t.OpenPBRMaterial){if(0==s.fuzzWeight)return void e(n);this._wasUsed=!0,null==n.extensions&&(n.extensions={});const t={fuzzFactor:s.fuzzWeight,fuzzColorFactor:s.fuzzColor.asArray(),fuzzRoughnessFactor:s.fuzzRoughness};let a,l;s.fuzzWeightTexture&&(t.fuzzTexture=null!==(r=this._exporter._materialExporter.getTextureInfo(s.fuzzWeightTexture))&&void 0!==r?r:void 0),s.fuzzColorTexture&&(a=this._mergedTexturesMap[s.fuzzColorTexture.uniqueId]?this._mergedTexturesMap[s.fuzzColorTexture.uniqueId]:s.fuzzColorTexture,t.fuzzColorTexture=null!==(i=this._exporter._materialExporter.getTextureInfo(a))&&void 0!==i?i:void 0),s.fuzzRoughnessTexture&&(l=this._mergedTexturesMap[s.fuzzRoughnessTexture.uniqueId]?this._mergedTexturesMap[s.fuzzRoughnessTexture.uniqueId]:s.fuzzRoughnessTexture,t.fuzzRoughnessTexture=null!==(o=this._exporter._materialExporter.getTextureInfo(l))&&void 0!==o?o:void 0),null===t.fuzzColorTexture&&null===t.fuzzRoughnessTexture||this._exporter._materialNeedsUVsSet.add(s),n.extensions[ct]=t}e(n)})})}}let ft=!1;function pt(){ft||(ft=!0,Z.RegisterExtension(ct,e=>new dt(e)))}pt();const mt="KHR_materials_specular";class gt{constructor(e){this.name=mt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const e=[];return s instanceof t.PBRMaterial&&this._isExtensionEnabled(s)?(s.metallicReflectanceTexture&&e.push(s.metallicReflectanceTexture),s.reflectanceTexture&&e.push(s.reflectanceTexture),e):e})}_isExtensionEnabled(e){return!e.unlit&&(null!=e.metallicF0Factor&&1!=e.metallicF0Factor||null!=e.metallicReflectanceColor&&!e.metallicReflectanceColor.equalsFloats(1,1,1)||this._hasTexturesExtension(e))}_hasTexturesExtension(e){return null!=e.metallicReflectanceTexture||null!=e.reflectanceTexture}postExportMaterialAsync(e,n,s){return new Promise(e=>{var r,i,o,a,l;if(s instanceof t.PBRMaterial&&this._isExtensionEnabled(s)){this._wasUsed=!0,n.extensions=n.extensions||{};const e=null!==(r=this._exporter._materialExporter.getTextureInfo(s.metallicReflectanceTexture))&&void 0!==r?r:void 0,t=null!==(i=this._exporter._materialExporter.getTextureInfo(s.reflectanceTexture))&&void 0!==i?i:void 0,o={specularFactor:1==s.metallicF0Factor?void 0:s.metallicF0Factor,specularTexture:e,specularColorFactor:s.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:s.metallicReflectanceColor.asArray(),specularColorTexture:t};this._hasTexturesExtension(s)&&this._exporter._materialNeedsUVsSet.add(s),n.extensions[mt]=o}else if(s instanceof t.OpenPBRMaterial){n.extensions=n.extensions||{};const t=null!==(o=this._exporter._materialExporter.getTextureInfo(s.specularWeightTexture))&&void 0!==o?o:void 0,r=null!==(a=this._exporter._materialExporter.getTextureInfo(s.specularColorTexture))&&void 0!==a?a:void 0,i=1==s.specularWeight?void 0:s.specularWeight,u=s.specularColor.equalsFloats(1,1,1)?void 0:s.specularColor.asArray();if(!r&&!t&&void 0===i&&void 0===u)return e(n);this._wasUsed=!0;const c={specularEdgeColorEnabled:!0},h={specularFactor:i,specularTexture:t,specularColorFactor:u,specularColorTexture:r,extensions:{}};h.extensions.EXT_materials_specular_edge_color=c,(l=this._exporter._glTF).extensionsUsed||(l.extensionsUsed=[]),-1===this._exporter._glTF.extensionsUsed.indexOf("EXT_materials_specular_edge_color")&&this._exporter._glTF.extensionsUsed.push("EXT_materials_specular_edge_color"),(t||r)&&this._exporter._materialNeedsUVsSet.add(s),n.extensions[mt]=h}e(n)})}}let xt=!1;function _t(){xt||(xt=!0,Z.RegisterExtension(mt,e=>new gt(e)))}_t();const Tt="KHR_materials_transmission";class yt{constructor(e){this.name=Tt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const e=[];if(s instanceof t.PBRMaterial){if(this._isExtensionEnabled(s))return s.subSurface.refractionIntensityTexture&&s.subSurface.useGltfStyleTextures&&e.push(s.subSurface.refractionIntensityTexture),e}else s instanceof t.OpenPBRMaterial&&(s.transmissionWeight>0&&s.transmissionWeightTexture&&(e.push(s.transmissionWeightTexture),s.transmissionColorTexture&&e.push(s.transmissionColorTexture)),s.subsurfaceWeight>0&&s.subsurfaceWeightTexture&&e.push(s.subsurfaceWeightTexture));return e})}_isExtensionEnabled(e){if(e instanceof t.OpenPBRMaterial&&!e.unlit)return e.transmissionWeight>0||e.subsurfaceWeight>0;if(e instanceof t.PBRMaterial&&!e.unlit){const t=e.subSurface;return t.isRefractionEnabled&&null!=t.refractionIntensity&&0!=t.refractionIntensity||null!=t.refractionIntensityTexture&&t.useGltfStyleTextures}return!1}postExportMaterialAsync(e,n,s){return c(this,void 0,void 0,function*(){if(!this._isExtensionEnabled(s))return n;if(s instanceof t.PBRMaterial){this._wasUsed=!0;const r=s.subSurface,i={transmissionFactor:0===r.refractionIntensity?void 0:r.refractionIntensity};if(r.refractionIntensityTexture)if(r.useGltfStyleTextures){this._exporter._materialNeedsUVsSet.add(s);const e=this._exporter._materialExporter.getTextureInfo(r.refractionIntensityTexture);e&&(i.transmissionTexture=e)}else t.Logger.Warn(`${e}: Exporting a subsurface refraction intensity texture without \`useGltfStyleTextures\` is not supported`);n.extensions||(n.extensions={}),n.extensions[Tt]=i}else if(s instanceof t.OpenPBRMaterial){this._wasUsed=!0;const e={transmissionFactor:(1-s.transmissionWeight)*s.subsurfaceWeight+s.transmissionWeight};if(s.transmissionWeightTexture){this._exporter._materialNeedsUVsSet.add(s);const t=this._exporter._materialExporter.getTextureInfo(s.transmissionWeightTexture);t&&(e.transmissionTexture=t)}else if(s.subsurfaceWeightTexture){this._exporter._materialNeedsUVsSet.add(s);const t=this._exporter._materialExporter.getTextureInfo(s.subsurfaceWeightTexture);t&&(e.transmissionTexture=t)}if(0==s.transmissionDepth&&(!s.transmissionColor.equals(t.Color3.White())||s.transmissionColorTexture)&&n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.baseColorFactor||(n.pbrMetallicRoughness.baseColorFactor=[1,1,1,1]),n.pbrMetallicRoughness.baseColorFactor[0]*=s.transmissionColor.r,n.pbrMetallicRoughness.baseColorFactor[1]*=s.transmissionColor.g,n.pbrMetallicRoughness.baseColorFactor[2]*=s.transmissionColor.b,s.transmissionColorTexture&&!n.pbrMetallicRoughness.baseColorTexture)){const e=this._exporter._materialExporter.getTextureInfo(s.transmissionColorTexture);e&&(n.pbrMetallicRoughness.baseColorTexture=e,this._exporter._materialNeedsUVsSet.add(s))}n.extensions||(n.extensions={}),n.extensions[Tt]=e}return n})}}let bt=!1;function vt(){bt||(bt=!0,Z.RegisterExtension(Tt,e=>new yt(e)))}vt();const Mt="KHR_materials_unlit";class wt{constructor(){this.name=Mt,this.enabled=!0,this.required=!1,this._wasUsed=!1}get wasUsed(){return this._wasUsed}dispose(){}postExportMaterialAsync(e,n,s){return new Promise(e=>{let r=!1;s instanceof t.PBRMaterial?r=s.unlit:s instanceof t.StandardMaterial&&(r=s.disableLighting),r&&(this._wasUsed=!0,null==n.extensions&&(n.extensions={}),n.extensions[Mt]={}),e(n)})}}let Rt=!1;function At(){Rt||(Rt=!0,Z.RegisterExtension(Mt,()=>new wt))}At();const Ct="KHR_materials_volume";class Et{constructor(e){this.name=Ct,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const e=[];if(s instanceof t.PBRMaterial){if(this._isExtensionEnabled(s))return s.subSurface.thicknessTexture&&e.push(s.subSurface.thicknessTexture),e}else s instanceof t.OpenPBRMaterial&&(s.transmissionWeight>0||s.subsurfaceWeight>0)&&s.geometryThicknessTexture&&e.push(s.geometryThicknessTexture);return e})}_isExtensionEnabled(e){if(e.unlit)return!1;const n=e.subSurface;return!(!n.isRefractionEnabled&&!n.isTranslucencyEnabled)&&(null!=n.maximumThickness&&0!=n.maximumThickness||null!=n.tintColorAtDistance&&n.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=n.tintColor&&n.tintColor!=t.Color3.White()||this._hasTexturesExtension(e))}_hasTexturesExtension(e){return null!=e.subSurface.thicknessTexture}postExportMaterialAsync(e,n,s){return new Promise(e=>{var r,i;if(s instanceof t.PBRMaterial&&this._isExtensionEnabled(s)){this._wasUsed=!0;const e=s.subSurface,t={thicknessFactor:0==e.maximumThickness?void 0:e.maximumThickness,thicknessTexture:null!==(r=this._exporter._materialExporter.getTextureInfo(e.thicknessTexture))&&void 0!==r?r:void 0,attenuationDistance:e.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:e.tintColorAtDistance,attenuationColor:e.tintColor.equalsFloats(1,1,1)?void 0:e.tintColor.asArray()};this._hasTexturesExtension(s)&&this._exporter._materialNeedsUVsSet.add(s),n.extensions=n.extensions||{},n.extensions[Ct]=t}else if(s instanceof t.OpenPBRMaterial){const e=s.transmissionWeight>0&&!s.geometryThinWalled,r=s.subsurfaceWeight>0&&!s.geometryThinWalled;if(e||r){this._wasUsed=!0;const o=s.geometryThickness,a=null!==(i=this._exporter._materialExporter.getTextureInfo(s.geometryThicknessTexture))&&void 0!==i?i:void 0;let l;a&&this._exporter._materialNeedsUVsSet.add(s);const u=t.Color3.White().asArray();if(e&&s.transmissionDepth>0){const e=1/s.transmissionDepth;let n=new t.Vector3(-Math.log(s.transmissionColor.r)*e,-Math.log(s.transmissionColor.g)*e,-Math.log(s.transmissionColor.b)*e);const r=new t.Vector3(s.transmissionScatter.r*e,s.transmissionScatter.g*e,s.transmissionScatter.b*e),i=n.subtract(r),o=Math.min(i.x,i.y,i.z);o<0&&(i.x=i.x-o,i.y=i.y-o,i.z=i.z-o),n=i.add(r),l=1/Math.max(n.x,n.y,n.z),u[0]=Math.exp(-n.x*l),u[1]=Math.exp(-n.y*l),u[2]=Math.exp(-n.z*l)}else l=Number.MAX_VALUE,u[0]=1,u[1]=1,u[2]=1;let c=1;const h=t.Color3.White().asArray();if(r){const e=s.subsurfaceRadius,n=s.subsurfaceRadiusScale,r=new t.Vector3(n.r,n.g,n.b).multiplyByFloats(e,e,e),i=new t.Vector3(1/Math.max(r.x,1e-6),1/Math.max(r.y,1e-6),1/Math.max(r.z,1e-6));c=1/Math.max(i.x,i.y,i.z),h[0]=Math.exp(-i.x*c),h[1]=Math.exp(-i.y*c),h[2]=Math.exp(-i.z*c)}const d=(1-s.transmissionWeight)*s.subsurfaceWeight,f=d+s.transmissionWeight,p=1/Math.max(f,1e-6),m=s.transmissionWeight*p,g=d*p,x=u.map((e,t)=>e*m+h[t]*g),_={thicknessFactor:o,thicknessTexture:a,attenuationDistance:l*m+c*g,attenuationColor:x};n.extensions=n.extensions||{},n.extensions[Ct]=_}}e(n)})}}let It=!1;function St(){It||(It=!0,Z.RegisterExtension(Ct,e=>new Et(e)))}St();const Vt="KHR_materials_volume_scatter";class Ft{constructor(e){this.name=Vt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const e=[];return s instanceof t.OpenPBRMaterial&&(s.transmissionWeight>0&&s.transmissionScatterTexture&&e.push(s.transmissionScatterTexture),s.subsurfaceWeight>0&&s.subsurfaceColorTexture&&e.push(s.subsurfaceColorTexture)),e})}_isExtensionEnabled(e){if(e.unlit)return!1;const n=e.transmissionWeight>0&&!e.geometryThinWalled&&e.transmissionDepth>0&&!e.transmissionScatter.equals(t.Color3.Black()),s=e.subsurfaceWeight>0&&!e.geometryThinWalled;return!(!n&&!s)}postExportMaterialAsync(e,n,s){return new Promise(e=>{if(s instanceof t.OpenPBRMaterial&&this._isExtensionEnabled(s)){this._wasUsed=!0;let e=t.Vector3.Zero(),r=0;s.transmissionWeight>0&&(e=function(e){const n=new t.Vector3(Math.sqrt(1-e.x),Math.sqrt(1-e.y),Math.sqrt(1-e.z)),s=new t.Vector3(1,1,1),r=s.subtract(n),i=s.subtract(new t.Vector3(.139,.139,.139).multiplyInPlace(n)),o=s.add(new t.Vector3(1.17,1.17,1.17).multiplyInPlace(n));return r.multiplyInPlace(i).divideInPlace(o)}(new t.Vector3(s.transmissionScatter.r,s.transmissionScatter.g,s.transmissionScatter.b)),r=s.transmissionScatterAnisotropy);const i=t.Vector3.Zero();let o=0;s.subsurfaceWeight>0&&(i.set(s.subsurfaceColor.r,s.subsurfaceColor.g,s.subsurfaceColor.b),o=s.subsurfaceScatterAnisotropy);const a=(1-s.transmissionWeight)*s.subsurfaceWeight,l=a+s.transmissionWeight,u=1/Math.max(l,1e-6),c=s.transmissionWeight*u,h=a*u,d={multiscatterColorFactor:e.multiplyByFloats(c,c,c).addInPlace(i.multiplyByFloats(h,h,h)).asArray(),scatterAnisotropy:r*c+o*h};if(s.subsurfaceWeight>0&&s.subsurfaceColorTexture){this._exporter._materialNeedsUVsSet.add(s);const e=this._exporter._materialExporter.getTextureInfo(s.subsurfaceColorTexture);e&&(d.multiscatterColorTexture=e)}else if(s.transmissionWeight>0&&s.transmissionScatterTexture){this._exporter._materialNeedsUVsSet.add(s);const e=this._exporter._materialExporter.getTextureInfo(s.transmissionScatterTexture);e&&(d.multiscatterColorTexture=e)}n.extensions=n.extensions||{},n.extensions[Vt]=d}e(n)})}}let Ot=!1;function Bt(){Ot||(Ot=!0,Z.RegisterExtension(Vt,e=>new Ft(e),101))}Bt();const Nt="KHR_materials_diffuse_roughness";class Pt{constructor(e){this.name=Nt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const e=[];if(s instanceof t.PBRBaseMaterial){if(s._baseDiffuseRoughness)return s._baseDiffuseRoughnessTexture&&e.push(s._baseDiffuseRoughnessTexture),e}else if(s instanceof t.OpenPBRMaterial&&s.baseDiffuseRoughness)return s.baseDiffuseRoughnessTexture&&e.push(s.baseDiffuseRoughnessTexture),e;return[]})}postExportMaterialAsync(e,n,s){return new Promise(e=>{let r=null,i=null;if(s instanceof t.PBRBaseMaterial?(r=s._baseDiffuseRoughness,i=s._baseDiffuseRoughnessTexture):s instanceof t.OpenPBRMaterial&&(r=s.baseDiffuseRoughness,i=s.baseDiffuseRoughnessTexture),!r)return void e(n);this._wasUsed=!0,n.extensions=n.extensions||{};const o=this._exporter._materialExporter.getTextureInfo(i),a={diffuseRoughnessFactor:r,diffuseRoughnessTexture:null!=o?o:void 0};null!==a.diffuseRoughnessTexture&&this._exporter._materialNeedsUVsSet.add(s),n.extensions[Nt]=a,e(n)})}}let Ut=!1;function kt(){Ut||(Ut=!0,Z.RegisterExtension(Nt,e=>new Pt(e)))}kt();const Kt="KHR_materials_openpbr";class $t{constructor(){this.name=Kt,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAsync(e,n,s){return new Promise(e=>{s instanceof t.OpenPBRMaterial&&(this._wasUsed=!0,n.extensions=n.extensions||{},n.extensions[Kt]={}),e(n)})}}let zt=!1;function Wt(){zt||(zt=!0,Z.RegisterExtension(Kt,()=>new $t))}Wt();const Dt="KHR_texture_transform";class Lt{constructor(){this.name=Dt,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}postExportTexture(e,n,s){if(s.getScene()||t.Tools.Warn(`${e}: "scene" is not defined for Babylon texture ${s.name}!`),(0!==s.uAng||0!==s.vAng)&&(t.Tools.Warn(`${e}: Texture ${s.name} with rotation in the u or v axis is not supported in glTF.`),0!==s.uRotationCenter||0!==s.vRotationCenter))return;const r={};let i=!1;if(0===s.uOffset&&0===s.vOffset||(r.offset=[s.uOffset,s.vOffset],i=!0),1===s.uScale&&1===s.vScale||(r.scale=[s.uScale,s.vScale],i=!0),0!==s.wAng){if(0!==s.uRotationCenter||0!==s.vRotationCenter){if(s.homogeneousRotationInUVTransform&&s.uScale!==s.vScale)return void t.Tools.Warn(`${e}: Texture ${s.name} with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ${Dt}.`);t.Tools.Warn(`${e}: Texture ${s.name} with non-origin rotation center will be exported using an adjusted offset with ${Dt}.`),r.offset=function(e){const{uOffset:t,vOffset:n,uRotationCenter:s,vRotationCenter:r,uScale:i,vScale:o,wAng:a}=e,l=Math.cos(a),u=Math.sin(a),c=s*i,h=r*o;return[t+(c*(1-l)+h*u),n+(h*(1-l)-c*u)]}(s)}r.rotation=-s.wAng,i=!0}0!==s.coordinatesIndex&&(r.texCoord=s.coordinatesIndex,i=!0),i&&(this._wasUsed=!0,n.extensions||(n.extensions={}),n.extensions[Dt]=r)}}let Ht=!1;function jt(){Ht||(Ht=!0,Z.RegisterExtension(Dt,()=>new Lt))}jt();const qt="KHR_texture_basisu";class Gt{get wasUsed(){return this._wasUsed}constructor(e){this.name=qt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}dispose(){}postExportTexture(e,n){const s=this._exporter._textures[n.index],r=s.source;if(void 0===r)return;const i=this._exporter._images[r];"image/ktx2"===(i.mimeType||t.GetMimeType(i.uri))&&(s.source=void 0,s.extensions||(s.extensions={}),s.extensions[qt]={source:r},this._wasUsed=!0)}}let Xt=!1;function Qt(){Xt||(Xt=!0,Z.RegisterExtension(qt,e=>new Gt(e)))}Qt();const Zt="EXT_texture_webp";class Yt{get wasUsed(){return this._wasUsed}constructor(e){this.name=Zt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}dispose(){}postExportTexture(e,n){const s=this._exporter._textures[n.index],r=s.source;if(void 0===r)return;const i=this._exporter._images[r];"image/webp"===(i.mimeType||t.GetMimeType(i.uri))&&(s.source=void 0,s.extensions||(s.extensions={}),s.extensions[Zt]={source:r},this._wasUsed=!0)}}let Jt=!1;function en(){Jt||(Jt=!0,Z.RegisterExtension(Zt,e=>new Yt(e)))}en();const tn="EXT_texture_avif";class nn{get wasUsed(){return this._wasUsed}constructor(e){this.name=tn,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}dispose(){}postExportTexture(e,n){const s=this._exporter._textures[n.index],r=s.source;if(void 0===r)return;const i=this._exporter._images[r];"image/avif"===(i.mimeType||t.GetMimeType(i.uri))&&(s.source=void 0,s.extensions||(s.extensions={}),s.extensions[tn]={source:r},this._wasUsed=!0)}}let sn=!1;function rn(){sn||(sn=!0,Z.RegisterExtension(tn,e=>new nn(e)))}rn();var on={__proto__:null,EXT_lights_area:be,EXT_mesh_gpu_instancing:ne,EXT_texture_avif:nn,EXT_texture_webp:Yt,KHR_draco_mesh_compression:ae,KHR_lights_punctual:pe,KHR_materials_anisotropy:Re,KHR_materials_clearcoat:Se,KHR_materials_coat:Pe,KHR_materials_diffuse_roughness:Pt,KHR_materials_diffuse_transmission:ze,KHR_materials_dispersion:He,KHR_materials_emissive_strength:Xe,KHR_materials_fuzz:dt,KHR_materials_ior:Je,KHR_materials_iridescence:st,KHR_materials_openpbr:$t,KHR_materials_sheen:at,KHR_materials_specular:gt,KHR_materials_transmission:yt,KHR_materials_unlit:wt,KHR_materials_volume:Et,KHR_materials_volume_scatter:Ft,KHR_texture_basisu:Gt,KHR_texture_transform:Lt,RegisterEXT_lights_area:Me,RegisterEXT_mesh_gpu_instancing:re,RegisterEXT_texture_avif:rn,RegisterEXT_texture_webp:en,RegisterKHR_draco_mesh_compression:ue,RegisterKHR_lights_punctual:ge,RegisterKHR_materials_anisotropy:Ce,RegisterKHR_materials_clearcoat:Fe,RegisterKHR_materials_coat:ke,RegisterKHR_materials_diffuse_roughness:kt,RegisterKHR_materials_diffuse_transmission:De,RegisterKHR_materials_dispersion:qe,RegisterKHR_materials_emissive_strength:Ze,RegisterKHR_materials_fuzz:pt,RegisterKHR_materials_ior:tt,RegisterKHR_materials_iridescence:it,RegisterKHR_materials_openpbr:Wt,RegisterKHR_materials_sheen:ut,RegisterKHR_materials_specular:_t,RegisterKHR_materials_transmission:vt,RegisterKHR_materials_unlit:At,RegisterKHR_materials_volume:St,RegisterKHR_materials_volume_scatter:Bt,RegisterKHR_texture_basisu:Qt,RegisterKHR_texture_transform:jt},an={__proto__:null,EXT_lights_area:be,EXT_mesh_gpu_instancing:ne,EXT_texture_avif:nn,EXT_texture_webp:Yt,GLTF2Export:Y,GLTFData:i,KHR_draco_mesh_compression:ae,KHR_lights_punctual:pe,KHR_materials_anisotropy:Re,KHR_materials_clearcoat:Se,KHR_materials_coat:Pe,KHR_materials_diffuse_roughness:Pt,KHR_materials_diffuse_transmission:ze,KHR_materials_dispersion:He,KHR_materials_emissive_strength:Xe,KHR_materials_fuzz:dt,KHR_materials_ior:Je,KHR_materials_iridescence:st,KHR_materials_openpbr:$t,KHR_materials_sheen:at,KHR_materials_specular:gt,KHR_materials_transmission:yt,KHR_materials_unlit:wt,KHR_materials_volume:Et,KHR_materials_volume_scatter:Ft,KHR_texture_basisu:Gt,KHR_texture_transform:Lt,RegisterEXT_lights_area:Me,RegisterEXT_mesh_gpu_instancing:re,RegisterEXT_texture_avif:rn,RegisterEXT_texture_webp:en,RegisterKHR_draco_mesh_compression:ue,RegisterKHR_lights_punctual:ge,RegisterKHR_materials_anisotropy:Ce,RegisterKHR_materials_clearcoat:Fe,RegisterKHR_materials_coat:ke,RegisterKHR_materials_diffuse_roughness:kt,RegisterKHR_materials_diffuse_transmission:De,RegisterKHR_materials_dispersion:qe,RegisterKHR_materials_emissive_strength:Ze,RegisterKHR_materials_fuzz:pt,RegisterKHR_materials_ior:tt,RegisterKHR_materials_iridescence:it,RegisterKHR_materials_openpbr:Wt,RegisterKHR_materials_sheen:ut,RegisterKHR_materials_specular:_t,RegisterKHR_materials_transmission:vt,RegisterKHR_materials_unlit:At,RegisterKHR_materials_volume:St,RegisterKHR_materials_volume_scatter:Bt,RegisterKHR_texture_basisu:Qt,RegisterKHR_texture_transform:jt,_ConvertToGLTFPBRMetallicRoughness:_,_SolveMetallic:x};class ln{static CreateSTL(e,n=!0,s="stlmesh",r=!1,i=!0,o=!1,a=!1,l=!1){const u=function(e,n,s){const r=[3*e[s],3*e[s+1],3*e[s+2]],i=[new t.Vector3(n[r[0]],n[r[0]+2],n[r[0]+1]),new t.Vector3(n[r[1]],n[r[1]+2],n[r[1]+1]),new t.Vector3(n[r[2]],n[r[2]+2],n[r[2]+1])],o=i[0].subtract(i[1]),a=i[2].subtract(i[1]);return{v:i,n:t.Vector3.Cross(a,o).normalize()}},c=function(e,t,n,s){return t=h(e,t,n.x,s),t=h(e,t,n.y,s),h(e,t,n.z,s)},h=function(e,t,n,s){return e.setFloat32(t,n,s),t+4},d=function(e){if(a){let n=e;e instanceof t.InstancedMesh&&(n=e.sourceMesh);const s=n.getVerticesData(t.VertexBuffer.PositionKind,!0,!0);if(!s)return[];const r=t.Vector3.Zero();let i;for(i=0;i<s.length;i+=3)t.Vector3.TransformCoordinatesFromFloatsToRef(s[i],s[i+1],s[i+2],e.computeWorldMatrix(!0),r).toArray(s,i);return s}return e.getVerticesData(t.VertexBuffer.PositionKind)||[]};a&&(o=!0);let f="",p=0,m=0;if(r){for(let t=0;t<e.length;t++){const n=e[t].getIndices();p+=n?n.length/3:0}const t=new ArrayBuffer(84+50*p);f=new DataView(t),m+=80,f.setUint32(m,p,i),m+=4}else l||(f="solid stlmesh\r\n");for(let n=0;n<e.length;n++){const s=e[n];!r&&l&&(f+="solid "+s.name+"\r\n"),!o&&s instanceof t.Mesh&&s.bakeCurrentTransformIntoVertices();const a=d(s),h=s.getIndices()||[];for(let e=0;e<h.length;e+=3){const t=u(h,a,e);r?(m=c(f,m,t.n,i),m=c(f,m,t.v[0],i),m=c(f,m,t.v[1],i),m=c(f,m,t.v[2],i),m+=2):(f+="\tfacet normal "+t.n.x+" "+t.n.y+" "+t.n.z+"\r\n",f+="\t\touter loop\r\n",f+="\t\t\tvertex "+t.v[0].x+" "+t.v[0].y+" "+t.v[0].z+"\r\n",f+="\t\t\tvertex "+t.v[1].x+" "+t.v[1].y+" "+t.v[1].z+"\r\n",f+="\t\t\tvertex "+t.v[2].x+" "+t.v[2].y+" "+t.v[2].z+"\r\n",f+="\t\tendloop\r\n",f+="\tendfacet\r\n")}!r&&l&&(f+="endsolid "+name+"\r\n")}if(r||l||(f+="endsolid stlmesh"),n){const e=document.createElement("a"),t=new Blob([f],{type:"application/octet-stream"});e.href=window.URL.createObjectURL(t),e.download=s+".stl",e.click()}return f}}var un={__proto__:null,STLExport:ln};function cn(e,t,n=3,s=!1){const r=[];for(let i=0;i<e.length/n;i++){const o=e[i*n]*(s?-1:1),a=e[i*n+1],l=e[i*n+2];r.push(`(${o.toPrecision(t.precision)}, ${a.toPrecision(t.precision)}, ${l.toPrecision(t.precision)})`)}return r.join(", ")}function hn(e,t){const n=[];for(let s=0;s<e.length/2;s++){const r=e[2*s],i=e[2*s+1];n.push(`(${r.toPrecision(t.precision)}, ${(1-i).toPrecision(t.precision)})`)}return n.join(", ")}function dn(e,n,s,r){return`\n def "Geometry"\n {\n ${function(e,n,s,r){const i=e.getVerticesData(t.VertexBuffer.PositionKind),o=e.getVerticesData(t.VertexBuffer.NormalKind);if(i&&o)return`\n\tdef Mesh "Geometry"\n\t{\n uniform token orientation = "${s}"\n\t\tint[] faceVertexCounts = [${function(e){var t;const n=(null===(t=e.getIndices())||void 0===t?void 0:t.length)?e.getTotalIndices():e.getTotalVertices();return Array(n/3).fill(3).join(", ")}(e)}]\n\t\tint[] faceVertexIndices = [${function(e){var t;const n=e.getIndices(),s=null!==(t=null==n?void 0:n.length)&&void 0!==t?t:e.getTotalVertices(),r=[];if(null!==n)for(let e=0;e<s;e++)r.push(n[e]);else for(let e=0;e<s;e++)r.push(e);return r.join(", ")}(e)}]\n\t\tnormal3f[] normals = [${cn(o,n,void 0,r)}] (\n\t\t\tinterpolation = "vertex"\n\t\t)\n\t\tpoint3f[] points = [${cn(i,n,void 0,r)}]\n ${function(e,n){let s="";for(let r=0;r<4;r++){const i=r>0?r:"",o=e.getVerticesData(t.VertexBuffer.UVKind+(i?i+1:""));o&&(s+=`\n\t\ttexCoord2f[] primvars:st${i} = [${hn(o,n)}] (\n\t\t\tinterpolation = "vertex"\n\t\t)`)}const r=e.getVerticesData(t.VertexBuffer.ColorKind);return r&&(s+=`\n\tcolor3f[] primvars:displayColor = [${cn(r,n,r.length/e.getTotalVertices())}] (\n\t\tinterpolation = "vertex"\n\t\t)`),s}(e,n)}\n\t\tuniform token subdivisionScheme = "none"\n\t}\n`}(e,n,s,r)}\n }\n `}function fn(e){let t='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )';return t+=e,fflate.strToU8(t)}function pn(e){const t=e.m;return`( ${mn(t,0)}, ${mn(t,4)}, ${mn(t,8)}, ${mn(t,12)} )`}function mn(e,t){return`(${e[t+0]}, ${e[t+1]}, ${e[t+2]}, ${e[t+3]})`}function gn(e,t){const n="Object_"+e.uniqueId,s=pn(t);return`def Xform "${n}" (\n\tprepend references = @./geometries/Geometry_${e.geometry.uniqueId}.usda@</Geometry>\n\tprepend apiSchemas = ["MaterialBindingAPI"]\n)\n{\n\tmatrix4d xformOp:transform = ${s}\n\tuniform token[] xformOpOrder = ["xformOp:transform"]\t\n\n rel material:binding = </Root/Materials/Material_${e.material.uniqueId}>\n}\n\n`}function xn(e){switch(e){case t.Constants.TEXTURE_CLAMP_ADDRESSMODE:return"clamp";case t.Constants.TEXTURE_MIRROR_ADDRESSMODE:return"mirror";case t.Constants.TEXTURE_WRAP_ADDRESSMODE:default:return"repeat"}}function _n(e){return`(${e.x}, ${e.y})`}function Tn(e){return`(${e.r}, ${e.g}, ${e.b})`}function yn(e){return"image/jpeg"===e||"image/png"===e}function bn(e,n,s,r,i,o){var a,l;const u=e.getInternalTexture().uniqueId+"_"+e.invertY,c=e.mimeType||t.GetMimeType(null!==(l=null===(a=e.getInternalTexture())||void 0===a?void 0:a.url)&&void 0!==l?l:""),h=yn(c)?c:"image/png",d="image/jpeg"===h?"jpg":"png";i[u]={texture:e,mimeType:h,ext:d};const f=e.coordinatesIndex>0?"st"+e.coordinatesIndex:"st",p=new t.Vector2(e.uScale,e.vScale),m=new t.Vector2(e.uOffset,e.vOffset),g=e.wAng,x=Math.sin(g),_=Math.cos(g);return m.y=1-m.y-p.y,m.x+=x*p.x,m.y+=(1-_)*p.y,`\n def Shader "PrimvarReader_${s}"\n {\n uniform token info:id = "UsdPrimvarReader_float2"\n float2 inputs:fallback = (0.0, 0.0)\n token inputs:varname = "${f}"\n float2 outputs:result\n }\n\n def Shader "Transform2d_${s}"\n {\n uniform token info:id = "UsdTransform2d"\n token inputs:in.connect = </Root/Materials/Material_${n.uniqueId}/PrimvarReader_${s}.outputs:result>\n float inputs:rotation = ${(g*(180/Math.PI)).toFixed(o.precision)}\n float2 inputs:scale = ${_n(p)}\n float2 inputs:translation = ${_n(m)}\n float2 outputs:result\n }\n\n def Shader "Texture_${e.uniqueId}_${s}"\n {\n uniform token info:id = "UsdUVTexture"\n asset inputs:file = @textures/Texture_${u}.${d}@\n float2 inputs:st.connect = </Root/Materials/Material_${n.uniqueId}/Transform2d_${s}.outputs:result>\n ${r?"float4 inputs:scale = "+function(e){return`(${e.r}, ${e.g}, ${e.b}, 1.0)`}(r):""}\n token inputs:sourceColorSpace = "${e.gammaSpace?"sRGB":"raw"}"\n token inputs:wrapS = "${xn(e.wrapU)}"\n token inputs:wrapT = "${xn(e.wrapV)}"\n float outputs:r\n float outputs:g\n float outputs:b\n float3 outputs:rgb\n ${n.needAlphaBlending()||n.needAlphaTesting()?"float outputs:a":""}\n }`}function vn(e,n,s){const r="\t\t\t",i=[],o=[],{diffuseMap:a,diffuse:l,alphaCutOff:u,emissiveMap:c,emissive:h,normalMap:d,roughnessMap:f,roughnessChannel:p,roughness:m,metalnessMap:g,metalnessChannel:x,metalness:_,aoMap:T,aoMapChannel:y,aoMapIntensity:b,alphaMap:v,ior:M,clearCoatEnabled:w,clearCoat:R,clearCoatMap:A,clearCoatRoughness:C,clearCoatRoughnessMap:E}=function(e){var n,s;const r={diffuseMap:null,diffuse:null,alphaCutOff:0,emissiveMap:null,emissive:null,normalMap:null,roughnessMap:null,roughnessChannel:"a",roughness:0,metalnessMap:null,metalnessChannel:"r",metalness:0,aoMap:null,aoMapChannel:"rgb",aoMapIntensity:0,alphaMap:null,ior:1,clearCoatEnabled:!1,clearCoat:0,clearCoatMap:null,clearCoatRoughness:0,clearCoatRoughnessMap:null};return e instanceof t.StandardMaterial?Object.assign(Object.assign({},r),{diffuseMap:e.diffuseTexture,diffuse:e.diffuseColor,alphaCutOff:e.alphaCutOff,emissiveMap:e.emissiveTexture,emissive:e.emissiveColor,roughness:1,alphaMap:e.opacityTexture}):e instanceof t.PBRBaseMaterial?Object.assign(Object.assign({},r),{diffuseMap:e._albedoTexture,diffuse:e._albedoColor,alphaCutOff:e._alphaCutOff,emissiveMap:e._emissiveTexture,emissive:e._emissiveColor,normalMap:e._bumpTexture,roughnessMap:e._metallicTexture,roughnessChannel:e._useRoughnessFromMetallicTextureAlpha?"a":"g",roughness:null!==(n=e._roughness)&&void 0!==n?n:1,metalnessMap:e._metallicTexture,metalnessChannel:e._useMetallnessFromMetallicTextureBlue?"b":"r",metalness:null!==(s=e._metallic)&&void 0!==s?s:0,aoMap:e._ambientTexture,aoMapChannel:e._useAmbientInGrayScale?"r":"rgb",aoMapIntensity:e._ambientTextureStrength,alphaMap:e._opacityTexture,ior:e.subSurface.indexOfRefraction,clearCoatEnabled:e.clearCoat.isEnabled,clearCoat:e.clearCoat.intensity,clearCoatMap:e.clearCoat.texture,clearCoatRoughness:e.clearCoat.roughness,clearCoatRoughnessMap:e.clearCoat.useRoughnessFromMainTexture?e.clearCoat.texture:e.clearCoat.textureRoughness}):r}(e);return null!==a?(i.push(`${r}color3f inputs:diffuseColor.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${a.uniqueId}_diffuse.outputs:rgb>`),e.needAlphaBlending()?i.push(`${r}float inputs:opacity.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${a.uniqueId}_diffuse.outputs:a>`):e.needAlphaTesting()&&(i.push(`${r}float inputs:opacity.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${a.uniqueId}_diffuse.outputs:a>`),i.push(`${r}float inputs:opacityThreshold = ${u}`)),o.push(bn(a,e,"diffuse",l,n,s))):i.push(`${r}color3f inputs:diffuseColor = ${Tn(l||t.Color3.White())}`),null!==c?(i.push(`${r}color3f inputs:emissiveColor.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${c.uniqueId}_emissive.outputs:rgb>`),o.push(bn(c,e,"emissive",h,n,s))):h&&h.toLuminance()>0&&i.push(`${r}color3f inputs:emissiveColor = ${Tn(h)}`),null!==d&&(i.push(`${r}normal3f inputs:normal.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${d.uniqueId}_normal.outputs:rgb>`),o.push(bn(d,e,"normal",null,n,s))),null!==T&&(i.push(`${r}float inputs:occlusion.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${T.uniqueId}_occlusion.outputs:${y}>`),o.push(bn(T,e,"occlusion",new t.Color3(b,b,b),n,s))),null!==f?(i.push(`${r}float inputs:roughness.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${f.uniqueId}_roughness.outputs:${p}>`),o.push(bn(f,e,"roughness",new t.Color3(m,m,m),n,s))):i.push(`${r}float inputs:roughness = ${m}`),null!==g?(i.push(`${r}float inputs:metallic.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${g.uniqueId}_metallic.outputs:${x}>`),o.push(bn(g,e,"metallic",new t.Color3(_,_,_),n,s))):i.push(`${r}float inputs:metallic = ${_}`),null!==v?(i.push(`${r}float inputs:opacity.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${v.uniqueId}_opacity.outputs:r>`),i.push(`${r}float inputs:opacityThreshold = 0.0001`),o.push(bn(v,e,"opacity",null,n,s))):i.push(`${r}float inputs:opacity = ${e.alpha}`),w&&(null!==A?(i.push(`${r}float inputs:clearcoat.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${A.uniqueId}_clearcoat.outputs:r>`),o.push(bn(A,e,"clearcoat",new t.Color3(R,R,R),n,s))):i.push(`${r}float inputs:clearcoat = ${R}`),null!==E?(i.push(`${r}float inputs:clearcoatRoughness.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${E.uniqueId}_clearcoatRoughness.outputs:g>`),o.push(bn(E,e,"clearcoatRoughness",new t.Color3(C,C,C),n,s))):i.push(`${r}float inputs:clearcoatRoughness = ${C}`)),i.push(`${r}float inputs:ior = ${M}`),`\n\tdef Material "Material_${e.uniqueId}"\n\t{\n\t\tdef Shader "PreviewSurface"\n\t\t{\n\t\t\tuniform token info:id = "UsdPreviewSurface"\n${i.join("\n")}\n\t\t\tint inputs:useSpecularWorkflow = 0\n\t\t\ttoken outputs:surface\n\t\t}\n\n\t\ttoken outputs:surface.connect = </Root/Materials/Material_${e.uniqueId}/PreviewSurface.outputs:surface>\n\n${o.join("\n")}\n\n\t}\n`}function Mn(e){var n,s;e.computeWorldMatrix(!0);const r=e.getWorldMatrix().clone(),i=e.getScene().useRightHandedSystem;let o=null!==(s=null===(n=e.material)||void 0===n?void 0:n._getEffectiveOrientation(e))&&void 0!==s?s:e.sideOrientation,a=!i,l=e.parent;for(;l;){if(w(l,i)&&null===l.parent){i||(r.multiplyToRef(l.getWorldMatrix().invert(),r),o=o===t.Material.ClockWiseSideOrientation?t.Material.CounterClockWiseSideOrientation:t.Material.ClockWiseSideOrientation),a=!1;break}l=l.parent}return r.determinant()<0&&t.Tools.Warn(`Mesh ${e.name} has a negative scale, which may look incorrect in destinations like QuickLook.`),{matrix:r,windingOrder:o===t.Material.ClockWiseSideOrientation?"leftHanded":"rightHanded",convertToRightHanded:a}}function wn(e,n,s){return c(this,void 0,void 0,function*(){const r=Object.assign({fflateUrl:"https://unpkg.com/fflate@0.8.2",includeAnchoringProperties:!0,anchoringType:"plane",planeAnchoringAlignment:"horizontal",modelFileName:"model.usda",precision:5,exportCamera:!1,cameraSensorWidth:35},n);"undefined"==typeof fflate&&(yield t.Tools.LoadScriptAsync(r.fflateUrl));const i={};i[r.modelFileName]=null;let o='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )';o+=function(e){return`def Xform "Root"\n {\n def Scope "Scenes" (\n kind = "sceneLibrary"\n )\n {\n def Xform "Scene" (\n customData = {\n bool preliminary_collidesWithEnvironment = 0\n string sceneName = "Scene"\n }\n sceneName = "Scene"\n )\n {${!0===e.includeAnchoringProperties?`\n\t\ttoken preliminary:anchoring:type = "${e.anchoringType}"\n\t\ttoken preliminary:planeAnchoring:alignment = "${e.planeAnchoringAlignment}"`:""}\n `}(r);const a={};for(const n of e.meshes){if(0===n.getTotalVertices())continue;const e=n,l=e.geometry,u=e.material;if(u&&l&&(!s||s(e)))if(-1!==["StandardMaterial","PBRMaterial","PBRMetallicRoughnessMaterial"].indexOf(u.getClassName())){const t="geometries/Geometry_"+l.uniqueId+".usda",{matrix:n,windingOrder:s,convertToRightHanded:c}=Mn(e);if(!(t in i)){const e=dn(l,r,s,c);i[t]=fn(e)}u.uniqueId in a||(a[u.uniqueId]=u),o+=gn(e,n)}else t.Tools.Warn("USDZExportAsync does not support this material type: "+u.getClassName())}e.activeCamera&&r.exportCamera&&(o+=function(e,n){const s="Camera_"+e.uniqueId,r=pn(t.Matrix.RotationY(Math.PI).multiply(e.getWorldMatrix()));if(e.mode===t.Constants.ORTHOGRAPHIC_CAMERA)return`def Camera "${s}"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ${r}\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (${e.minZ.toPrecision(n.precision)}, ${e.maxZ.toPrecision(n.precision)})\n\t\t\tfloat horizontalAperture = ${(10*(Math.abs(e.orthoLeft||1)+Math.abs(e.orthoRight||1))).toPrecision(n.precision)}\n\t\t\tfloat verticalAperture = ${(10*(Math.abs(e.orthoTop||1)+Math.abs(e.orthoBottom||1))).toPrecision(n.precision)}\n\t\t\ttoken projection = "orthographic"\n\t\t}\n\t\n\t`;{const t=e.getEngine().getAspectRatio(e),i=n.cameraSensorWidth||35;return`def Camera "${s}"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ${r}\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (${e.minZ.toPrecision(n.precision)}, ${e.maxZ.toPrecision(n.precision)})\n\t\t\tfloat focalLength = ${(i/(2*Math.tan(.5*e.fov))).toPrecision(n.precision)}\n token projection = "perspective"\n\t\t\tfloat horizontalAperture = ${(i*t).toPrecision(n.precision)}\n\t\t\tfloat verticalAperture = ${(i/t).toPrecision(n.precision)} \n\t\t}\n\t\n\t`}}(e.activeCamera,r)),o+="\n }\n }";const l={};o+=function(e,t,n){const s=[];for(const r in e){const i=e[r];s.push(vn(i,t,n))}return`\n def "Materials"\n{\n${s.join("")}\n}\n\n`}(a,l,r),o+="\n }",i[r.modelFileName]=fflate.strToU8(o);for(const e in l){const{texture:n,ext:s,mimeType:r}=l[e],o=yield h(n);if(o&&yn(o.mimeType)&&o.mimeType===r)i[`textures/Texture_${e}.${s}`]=new Uint8Array(o.data);else{const o=n.getSize(),a=yield t.GetTextureDataAsync(n),l=yield t.DumpTools.DumpDataAsync(o.width,o.height,a,r,void 0,!1,!0);i[`textures/Texture_${e}.${s}`]=new Uint8Array(l).slice()}}let u=0;for(const e in i){const t=i[e];if(!t)continue;u+=34+e.length;const n=63&u;if(4!==n){const s=new Uint8Array(64-n);i[e]=[t,{extra:{12345:s}}]}u=t.length}return fflate.zipSync(i,{level:0})})}var Rn={__proto__:null,USDZExportAsync:wn};class An{static Export(e,n=[],s){var r;if(!e||0===e.bones.length)throw new Error("Invalid or empty skeleton provided");let i=n;n&&0!==n.length||(i=e.animations.map(e=>e.name));let o=null;for(const n of i){const s=e.getAnimationRange(n);s&&(o=o?new t.AnimationRange("animation-range",Math.min(o.from,s.from),Math.max(o.to,s.to)):s)}if(!o&&(e.animations.length>0&&(o=e.getAnimationRange(e.animations[0].name)),!o))throw new Error("No animation range found in skeleton");const a=s||1/((null===(r=e.animations[0])||void 0===r?void 0:r.framePerSecond)||30),l=this._BuildBoneHierarchy(e,i);let u=0;for(const e of l)e.positionKeys.length>0&&(u=Math.max(u,e.positionKeys.length)),e.rotationKeys.length>0&&(u=Math.max(u,e.rotationKeys.length));0===u&&(u=Math.floor((o.to-o.from)/a)+1);let c="";return c+="HIERARCHY\n",c+=this._ExportHierarchy(l,0),c+="MOTION\n",c+=`Frames: ${u}\n`,c+=`Frame Time: ${a.toFixed(6)}\n`,c+=this._ExportMotionData(l,u,0,i),c}static _BuildBoneHierarchy(e,t){const n=new Map,s=[];for(const t of e.bones){const e={bone:t,children:[],hasPositionChannels:!1,hasRotationChannels:!1,positionKeys:[],rotationKeys:[]};n.set(t,e)}for(const r of e.bones){const e=n.get(r);if(r.animations.length>0)for(const n of r.animations)t.includes(n.name)&&("position"===n.targetProperty?(e.hasPositionChannels=!0,e.positionKeys.push(...n.getKeys())):"rotationQuaternion"===n.targetProperty&&(e.hasRotationChannels=!0,e.rotationKeys.push(...n.getKeys())));if(r.getParent()){const t=n.get(r.getParent());t&&t.children.push(e)}else s.push(e)}return s}static _ExportHierarchy(e,t){let n="";const s=" ".repeat(t);for(const r of e){const e=r.bone;if(this._IsEndSite(r)){n+=`${s}End Site\n`,n+=`${s}{\n`;const t=this._GetBoneOffset(e);n+=`${s} OFFSET ${t.x.toFixed(6)} ${t.y.toFixed(6)} ${t.z.toFixed(6)}\n`,n+=`${s}}\n`}else{n+=`${0===t?"ROOT":`${s}JOINT`} ${e.name}\n`,n+=`${s}{\n`;const i=this._GetBoneOffset(e);n+=`${s} OFFSET ${i.x.toFixed(6)} ${i.y.toFixed(6)} ${i.z.toFixed(6)}\n`;const o=[];r.hasPositionChannels&&o.push("Xposition","Yposition","Zposition"),r.hasRotationChannels&&o.push("Zrotation","Xrotation","Yrotation"),o.length>0&&(n+=`${s} CHANNELS ${o.length} ${o.join(" ")}\n`),r.children.length>0&&(n+=this._ExportHierarchy(r.children,t+1)),n+=`${s}}\n`}}return n}static _IsEndSite(e){return 0===e.children.length}static _GetBoneOffset(e){try{return e.getParent()?e.getLocalMatrix().getTranslation():e.getRestMatrix().getTranslation()}catch(e){return t.Vector3.Zero()}}static _ExportMotionData(e,t,n,s){let r="";for(let i=0;i<t;i++){const t=[];this._CollectFrameValues(e,i+n,t,s),r+=t.map(e=>e.toFixed(6)).join(" ")+"\n"}return r}static _CollectFrameValues(e,t,n,s){for(const r of e)if(!this._IsEndSite(r)){if(r.hasPositionChannels){const e=this._GetPositionAtFrameIndex(r.positionKeys,t);n.push(e.x,e.y,e.z)}if(r.hasRotationChannels){const e=this._GetRotationAtFrameIndex(r.rotationKeys,t),s=this._QuaternionToEuler(e);n.push(s.z,s.x,s.y)}r.children.length>0&&this._CollectFrameValues(r.children,t,n,s)}}static _GetPositionAtFrameIndex(e,n){return 0===e.length?t.Vector3.Zero():e[Math.max(0,Math.min(n,e.length-1))].value.clone()}static _GetRotationAtFrameIndex(e,n){return 0===e.length?t.Quaternion.Identity():e[Math.max(0,Math.min(n,e.length-1))].value.clone()}static _QuaternionToEuler(e){const n=new t.Matrix;e.toRotationMatrix(n);const s=n.m;let r,i,o;const a=Math.sqrt(s[0]*s[0]+s[1]*s[1]);return a>t.Epsilon?(r=Math.atan2(s[6],s[10]),i=Math.atan2(-s[2],a),o=Math.atan2(s[1],s[0])):(r=Math.atan2(-s[9],s[5]),i=Math.atan2(-s[2],a),o=0),new t.Vector3(t.Tools.ToDegrees(r),t.Tools.ToDegrees(i),t.Tools.ToDegrees(o))}}var Cn={__proto__:null,BVHExporter:An};function En(e){return"string"==typeof(null==e?void 0:e.name)}const In=Symbol("__xml:meta$__"),Sn=Symbol("__xml:name$__");function Vn(e,t){Object.prototype.hasOwnProperty.call(e.metadata,In)||(e.metadata[In]=[]),e.metadata[In].push(t)}function Fn(e){return(t,n)=>{t[Sn]=e}}function On(){return(e,t)=>Vn(t,{kind:"none",prop:String(t.name),ignore:!0})}function Bn(e){return(t,n)=>Vn(n,Object.assign({kind:"attr",prop:String(n.name)},e))}function Nn(e){return(t,n)=>Vn(n,Object.assign({kind:"elem",prop:String(n.name)},e))}function Pn(e){const t="function"==typeof e?e:null==e?void 0:e.constructor,n=null==t?void 0:t[Symbol.metadata];if(!n)return[];const s=[];let r=n;for(;r;)Object.prototype.hasOwnProperty.call(r,In)&&s.push(...r[In]),r=Object.getPrototypeOf(r);return s}function Un(e){var t;return(null===(t=null==e?void 0:e.constructor)||void 0===t?void 0:t[Sn])||void 0}function kn(e){return/^[A-Za-z_][A-Za-z0-9._-]*$/.test(e)}function Kn(e){if(En(e))return e;const t=(null!=e?e:"").trim();if(!t)return{name:""};const n=t.indexOf(":");if(-1===n)return{name:t};if(-1!==t.indexOf(":",n+1))return{name:t};const s=t.slice(0,n),r=t.slice(n+1);return kn(s)&&kn(r)?{ns:s,name:r}:{name:t}}function $n(e,t){return t?`${t}:${e}`:e}const zn=Object.freeze({eps:1e-6,maxDecimalsCap:15,trimTrailingZeros:!0,allowScientific:!1,snapNearZero:!0}),Wn=Object.freeze({number:zn});function Dn(e){var t,n,s,r,i,o;const a=null!==(t=null==e?void 0:e.eps)&&void 0!==t?t:zn.eps;return{eps:a,maxDecimalsCap:null!==(n=null==e?void 0:e.maxDecimalsCap)&&void 0!==n?n:zn.maxDecimalsCap,trimTrailingZeros:null!==(s=null==e?void 0:e.trimTrailingZeros)&&void 0!==s?s:zn.trimTrailingZeros,fixedDecimals:null==e?void 0:e.fixedDecimals,allowScientific:null!==(r=null==e?void 0:e.allowScientific)&&void 0!==r?r:zn.allowScientific,snapNearZero:null!==(i=null==e?void 0:e.snapNearZero)&&void 0!==i?i:zn.snapNearZero,zeroThreshold:null!==(o=null==e?void 0:e.zeroThreshold)&&void 0!==o?o:a,perAttributeEps:null==e?void 0:e.perAttributeEps}}function Ln(e){return{number:Dn(null==e?void 0:e.number)}}class Hn{constructor(e){if(this.o=e,this._o=e.number,!Number.isFinite(this._o.eps)||this._o.eps<=0)throw new Error("opts.eps must be a finite, positive number")}toString(e){var t,n,s,r;if(!Number.isFinite(e))throw new Error(`Cannot format non-finite number: ${e}`);const i=this._o,o=this._clampInt(null!==(t=i.maxDecimalsCap)&&void 0!==t?t:15,0,20),a=null===(n=i.trimTrailingZeros)||void 0===n||n,l=null===(s=i.snapNearZero)||void 0===s||s,u=null!==(r=i.zeroThreshold)&&void 0!==r?r:i.eps,c=1/i.eps;let h,d=Math.round(e*c)/c;if(Object.is(d,-0)&&(d=0),l&&Math.abs(d)<=u&&(d=0),h=void 0!==i.fixedDecimals?this._clampInt(i.fixedDecimals,0,o):this._clampInt(Math.ceil(-Math.log10(i.eps)),0,o),i.allowScientific,0===h)return String(Math.trunc(d));let f=d.toFixed(h);if(a&&void 0===i.fixedDecimals&&(f=f.replace(/(\.\d*?[1-9])0+$/,"$1").replace(/\.0+$/,"").replace(/\.$/,"")),/[eE]/.test(f))throw new Error(`Scientific notation not allowed in XML output: ${f}`);return f}_clampInt(e,t,n){return Number.isFinite(e)?(e=Math.trunc(e),Math.max(t,Math.min(n,e))):t}}function jn(e){return e instanceof Date}function qn(e){return"string"==typeof e}function Gn(e){return"number"==typeof e}function Xn(e){return"string"==typeof e||"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||jn(e)}function Qn(e){return"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||jn(e)}class Zn{constructor(e,t){this._ns=new Map,this._prefixCount=0,this._builder=e,this._format=Ln(t),this._nFmt=new Hn(this._format)}withNamespace(...e){for(const t of e)this._assignNamespace(t);return this}serialize(e,t){if(!(t=null!=t?t:Un(e)))throw new Error("can not find name for given object");const n=Kn(t);n.ns&&this._assignNamespace(n.ns,"xmlns"),this._gatherNamespaces(e,new WeakSet);const s=this._builder.ele(null,n.name);for(const[e,t]of Array.from(this._ns.entries()))s.att("xmlns",t,e);this._writeObjectContent(s,e,(new WeakSet).add(e)),this._builder.end()}_writeObject(e,t,n){if(n.has(t))return;if(n.add(t),Array.isArray(t)){for(const s of t)Qn(s)||(qn(s)?this._builder.text(s):this._writeObject(e,s,n));return}const s=Un(t);if(!s)return;const r=Kn(s),i=this._getPrefix(r),o=$n(r.name,i);e.ele(null,o),this._writeObjectContent(e,t,n),this._builder.end()}_getPrefix(e){if(e.ns){const t=this._ns.get(e.ns.toLowerCase());if("xmlns"!==t)return t}}_writeObjectContent(e,t,n){var s,r,i;const o=null!==(s=Pn(t))&&void 0!==s?s:[],a=new Map;for(const e of o){const t=null!==(r=a.get(e.prop))&&void 0!==r?r:[];t.push(e),a.set(e.prop,t)}const l=Object.keys(t).sort((e,t)=>{var n,s;const r=(null!==(n=a.get(e))&&void 0!==n?n:[]).some(e=>"attr"===e.kind);return r===(null!==(s=a.get(t))&&void 0!==s?s:[]).some(e=>"attr"===e.kind)?0:r?-1:1});for(const s of l){const r=t[s];if(null==r)continue;const o=a.get(s);if(o){if(o.some(e=>!0===e.ignore||"none"===e.kind))continue;for(const t of o){const n=null!==(i=t.name)&&void 0!==i?i:t.prop.toLowerCase();if(n)switch(t.kind){case"attr":{let s=null;if(Gn(r)&&this._nFmt&&(s=this._nFmt.toString(r)),t.formatter&&(s=new t.formatter(this._format).toString(r)),s=null!=s?s:r.toString(),s){const t=Kn(n),r=this._getPrefix(t),i=$n(t.name,r);e.att(null,i,s)}break}}}}else Qn(r)||(qn(r)?this._builder.text(r):this._writeObject(e,r,n))}}_gatherNamespaces(e,t){var n,s;if(t.has(e))return;if(t.add(e),Array.isArray(e)){for(const n of e)Xn(n)||this._gatherNamespaces(n,t);return}const r=Un(e);r&&this._assignNamespace(r);const i=null!==(n=Pn(e))&&void 0!==n?n:[],o=new Map;for(const e of i){const t=null!==(s=o.get(e.prop))&&void 0!==s?s:[];t.push(e),o.set(e.prop,t)}const a=[];for(const t of Object.keys(e)){const n=e[t];if(null==n)continue;const s=o.get(t);if(s){if(s.some(e=>!0===e.ignore||"none"===e.kind))continue;for(const e of s)e.name&&this._assignNamespace(e.name)}a.push(n)}for(const e of a)Xn(e)||this._gatherNamespaces(e,t)}_assignNamespace(e,t){const n=Kn(e);if(null==n?void 0:n.ns){const e=n.ns.toLowerCase();return void(this._ns.get(e)||this._ns.set(e,null!=t?t:this._buildNsPrefix(e)))}if("xmlns"===t){const e=n.name.toLowerCase();this._ns.get(e)||this._ns.set(e,null!=t?t:this._buildNsPrefix(e))}}_buildNsPrefix(e){let t,n=!1;do{t="ns"+this._prefixCount++;for(const e of Array.from(this._ns.values()))if(e===t){n=!0;break}}while(n);return t}}class Yn{}var Jn;Yn.OpenTag="<",Yn.CloseTag=">",Yn.Slash="/",Yn.Question="?",Yn.Quote='"',Yn.Equal="=",Yn.Space=" ",Yn.Semicolon=":",Yn.Dec="<?xml",Yn.Xml="xml",Yn.Xmlns="xmlns",Yn.Xsi="xsi",Yn.VersionKeyword="version",Yn.EncodingKeyword="encoding",Yn.StandaloneKeyword="standalone",e.TokenType=void 0,(Jn=e.TokenType||(e.TokenType={}))[Jn.Declaration=0]="Declaration",Jn[Jn.Tag=1]="Tag",Jn[Jn.Attribute=2]="Attribute",Jn[Jn.Text=3]="Text";class es{constructor(e){this._ctxStack=[],this._d=0,this._w=e}dec(e,t,n){return this._w.write(Yn.Dec),this._writeAttStr(Yn.VersionKeyword,e),t&&this._writeAttStr(Yn.EncodingKeyword,t),void 0!==n&&this._writeAttStr(Yn.StandaloneKeyword,n?"yes":"no"),this._w.write(Yn.Question,Yn.CloseTag),this}att(t,n,s){const r=this._peekContext();if(!r)throw new Error("att() without open element");if(r.closed)throw new Error(`att() after start tag closed for <${r.name}>`);if(this._isXmlnsDecl(t,n)){if(n===Yn.Xmlns)r.defaultNs=s,this._registerNamespace(r,"",s),this._writeAttStr(Yn.Xmlns,s);else if(t)this._registerNamespace(r,n,s),this._writeAttStr(`${t}:${n}`,s);else{const e=n.slice(6);this._registerNamespace(r,e,s),this._writeAttStr(n,s)}return r.lastToken=e.TokenType.Attribute,this}let i=n;return t&&(i=`${this._ensurePrefixDeclared(r,t)}:${n}`),r.lastToken=e.TokenType.Attribute,this._writeAttStr(i,s),this}ele(e,t){var n;const s=this._peekContext();s&&this._closeOpenTagIfNeeded(s);let r=t;return e&&(r=`${null!==(n=this._lookupPrefix(e))&&void 0!==n?n:e}:${t}`),this._pushContext(r,++this._d),this._w.write(Yn.OpenTag,r),this}text(t){const n=this._peekContext();if(!n)throw new Error("text() without open element");return this._closeOpenTagIfNeeded(n),n.lastToken=e.TokenType.Text,this._w.write(this._escText(t)),this}end(){const e=this._popContext();return e&&(this._d--,e.closed?this._w.write(Yn.OpenTag,Yn.Slash,e.name,Yn.CloseTag):this._w.write(Yn.Slash,Yn.CloseTag)),this}_pushContext(e,t){const n=new es.Context(e,t);return this._ctxStack.push(n),n}_popContext(){return this._ctxStack.pop()}_peekContext(){return this._ctxStack[this._ctxStack.length-1]}get _contextDepth(){return this._ctxStack.length}_writeAttStr(e,t){this._w.write(Yn.Space,e,Yn.Equal,Yn.Quote,this._escAttr(t),Yn.Quote)}_lookupPrefix(e){var t;let n=this._ctxStack.length-1;if(n>=0)do{const s=null===(t=this._ctxStack[n--].ns2prefix)||void 0===t?void 0:t.get(e);if(s)return s}while(n>=0)}_escText(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}_escAttr(e){return this._escText(e).replace(/"/g,""").replace(/'/g,"'")}_isXmlnsDecl(e,t){if(e)return e===Yn.Xmlns;const n=t.length,s=Yn.Xmlns.length;return n>=s&&t.startsWith(Yn.Xmlns)&&(t.length==s||t[s]==Yn.Semicolon)}_registerNamespace(e,t,n){if(t===Yn.Xml||t===Yn.Xmlns)throw new Error(`reserved prefix '${t}'`);const s=e.prefix2ns.get(t);if(s&&s!==n)throw new Error(`prefix '${t}' already bound to a different namespace`);e.ns2prefix.get(n)||e.ns2prefix.set(n,t),e.prefix2ns.set(t,n)}_allocPrefix(e){let t=1;for(;;){const n="ns"+t++;if(!e.prefix2ns.has(n))return n}}_ensurePrefixDeclared(e,t){const n=this._lookupPrefix(t);if(n)return n;if(e.closed)throw new Error(`can not declare namespace after start tag closed for <${e.name}>`);const s=this._allocPrefix(e);return this._writeAttStr(`${Yn.Xmlns}:${s}`,t),this._registerNamespace(e,s,t),s}_closeOpenTagIfNeeded(e){e.closed||(this._w.write(Yn.CloseTag),e.closed=!0)}}es.Context=class{constructor(e,t){this.name="",this.closed=!1,this.lastToken=null,this.ns2prefix=new Map,this.prefix2ns=new Map,this.defaultNs=null,this.name=e,this.depth=t}};class ts{constructor(){this.count=0,this._chunks=[]}write(...e){if(0===e.length)return this;const t=e.join("");return this._chunks.push(t),this.count+=t.length,this}toString(){return this._chunks.join("")}clear(){this._chunks=[],this.count=0}}class ns{constructor(e,t={}){this._sink=e,this._opts=t,this.count=0,this._encoder=new TextEncoder,this._pending="",this._pendingChars=0}write(...e){var t;if(0===e.length)return this;const n=e.join("");if(0===n.length)return this;this._pending+=n,this._pendingChars+=n.length;const s=null!==(t=this._opts.flushChars)&&void 0!==t?t:65536;return this._pendingChars>=s&&this.flush(),this}flush(){if(0===this._pendingChars)return this;const e=this._encoder.encode(this._pending);return this._sink.push(e),this.count+=e.length,this._pending="",this._pendingChars=0,this}finish(){this.flush(),this._sink.push(new Uint8Array(0),!0)}clear(){this._pending="",this._pendingChars=0,this.count=0}}const ss="http://schemas.microsoft.com/3dmanufacturing/core/2015/02",rs="http://schemas.microsoft.com/3dmanufacturing/trianglesets/2021/07";var is,os;e.ST_Unit=void 0,(is=e.ST_Unit||(e.ST_Unit={})).micron="micron",is.millimeter="millimeter",is.centimeter="centimeter",is.inch="inch",is.foot="foot",is.meter="meter",e.ST_ObjectType=void 0,(os=e.ST_ObjectType||(e.ST_ObjectType={})).model="model",os.solidsupport="solidsupport",os.support="support",os.surface="surface",os.other="other";const as="http://schemas.openxmlformats.org/package/2006/content-types",ls="http://schemas.openxmlformats.org/package/2006/relationships";var us;e.KnownI3mfContentType=void 0,(us=e.KnownI3mfContentType||(e.KnownI3mfContentType={})).Relationships="application/vnd.openxmlformats-package.relationships+xml",us.Model="application/vnd.ms-package.3dmanufacturing-3dmodel+xml",us.Materials="application/vnd.ms-package.3dmanufacturing-material+xml",us.Colors="application/vnd.ms-package.3dmanufacturing-colors+xml",us.Texture="application/vnd.ms-package.3dmanufacturing-texture+xml",us.Texture2D="application/vnd.ms-package.3dmanufacturing-texture2d+xml",us.Production="application/vnd.ms-package.3dmanufacturing-production+xml",us.Slice="application/vnd.ms-package.3dmanufacturing-slice+xml",us.BeamLattice="application/vnd.ms-package.3dmanufacturing-beamlattice+xml",us.SecureContent="application/vnd.ms-package.3dmanufacturing-securecontent+xml",us.Png="image/png",us.Jpeg="image/jpeg",us.Tiff="image/tiff",us.Xml="application/xml";const cs="_rels/",hs="3D/",ds="3dmodel.model",fs=".rels",ps="[Content_Types].xml";class ms{static IsKnown(e){return ms.Known.has(e)}static IsThreeDimModel(e){return e===ms.ThreeDimModel}}ms.ThreeDimModel="http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel",ms.Thumbnail="http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail",ms.PrintTicket="http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket",ms.MustPreserve="http://schemas.openxmlformats.org/package/2006/relationships/mustpreserve",ms.Known=new Set([ms.ThreeDimModel,ms.Thumbnail,ms.PrintTicket,ms.MustPreserve]);let gs=(()=>{let e,t,n=[Fn({ns:as,name:"Types"})],s=[];return t=class{constructor(){this.items=[]}},u(t,"ThreeMfContentTypes"),(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;a(null,e={value:t},n,{kind:"class",name:t.name,metadata:r},null,s),t=e.value,r&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),l(t,s)})(),t})(),xs=(()=>{let e,t,n,s,r=[Fn({ns:as,name:"Default"})],i=[],o=[],c=[],h=[],d=[];return t=class{constructor(e,t){this.ext=l(this,o,void 0),this.ct=(l(this,c),l(this,h,void 0)),l(this,d),this.ext=e,this.ct=t}},u(t,"ThreeMfContentType"),(()=>{const u="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;n=[Bn({name:{ns:as,name:"Extension"}})],s=[Bn({name:{ns:as,name:"ContentType"}})],a(null,null,n,{kind:"field",name:"ext",static:!1,private:!1,access:{has:e=>"ext"in e,get:e=>e.ext,set:(e,t)=>{e.ext=t}},metadata:u},o,c),a(null,null,s,{kind:"field",name:"ct",static:!1,private:!1,access:{has:e=>"ct"in e,get:e=>e.ct,set:(e,t)=>{e.ct=t}},metadata:u},h,d),a(null,e={value:t},r,{kind:"class",name:t.name,metadata:u},null,i),t=e.value,u&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:u}),l(t,i)})(),t})(),_s=(()=>{let e,t,n=[Fn({ns:ls,name:"Relationships"})],s=[];return t=class{constructor(){this.items=[]}},u(t,"ThreeMfRelationships"),(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;a(null,e={value:t},n,{kind:"class",name:t.name,metadata:r},null,s),t=e.value,r&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),l(t,s)})(),t})(),Ts=(()=>{let e,t,n,s,r,i=[Fn({ns:ls,name:"Relationship"})],o=[],c=[],h=[],d=[],f=[],p=[],m=[];return t=class{constructor(e,t,n){this.id=l(this,c,void 0),this.type=(l(this,h),l(this,d,void 0)),this.target=(l(this,f),l(this,p,void 0)),l(this,m),this.id=e,this.type=t,this.target=n}},u(t,"ThreeMfRelationship"),(()=>{const u="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;n=[Bn({name:"Id"})],s=[Bn({name:"Type"})],r=[Bn({name:"Target"})],a(null,null,n,{kind:"field",name:"id",static:!1,private:!1,access:{has:e=>"id"in e,get:e=>e.id,set:(e,t)=>{e.id=t}},metadata:u},c,h),a(null,null,s,{kind:"field",name:"type",static:!1,private:!1,access:{has:e=>"type"in e,get:e=>e.type,set:(e,t)=>{e.type=t}},metadata:u},d,f),a(null,null,r,{kind:"field",name:"target",static:!1,private:!1,access:{has:e=>"target"in e,get:e=>e.target,set:(e,t)=>{e.target=t}},metadata:u},p,m),a(null,e={value:t},i,{kind:"class",name:t.name,metadata:u},null,o),t=e.value,u&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:u}),l(t,o)})(),t})();class ys{constructor(e,t,n){this.contentTypes=e,this.relationships=t,this.model=n}}class bs{static Zero(){return new bs([0,0,0,0,0,0,0,0,0,0,0,0])}constructor(e){this.values=e}toString(){return this.values.join(" ")}}class vs{constructor(e){this.o=e,this._f=new Hn(e)}toString(e){return e.values.map(e=>this._f.toString(e)).join(" ")}}let Ms=(()=>{let t,n,s,r,i,o=[Fn({ns:ss,name:"model"})],c=[],h=[],d=[],f=[],p=[],m=[],g=[];return n=class{constructor(){this.unit=l(this,h,e.ST_Unit.millimeter),this.requiredextensions=(l(this,d),l(this,f,void 0)),this.recommendedextensions=(l(this,p),l(this,m,void 0)),this.metadata=l(this,g)}},u(n,"ThreeMfModel"),(()=>{const e="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;s=[Bn({name:"unit"})],r=[Bn({name:"requiredextensions"})],i=[Bn({name:"recommendedextensions"})],a(null,null,s,{kind:"field",name:"unit",static:!1,private:!1,access:{has:e=>"unit"in e,get:e=>e.unit,set:(e,t)=>{e.unit=t}},metadata:e},h,d),a(null,null,r,{kind:"field",name:"requiredextensions",static:!1,private:!1,access:{has:e=>"requiredextensions"in e,get:e=>e.requiredextensions,set:(e,t)=>{e.requiredextensions=t}},metadata:e},f,p),a(null,null,i,{kind:"field",name:"recommendedextensions",static:!1,private:!1,access:{has:e=>"recommendedextensions"in e,get:e=>e.recommendedextensions,set:(e,t)=>{e.recommendedextensions=t}},metadata:e},m,g),a(null,t={value:n},o,{kind:"class",name:n.name,metadata:e},null,c),n=t.value,e&&Object.defineProperty(n,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:e})})(),n.KnownMeta=["Title","Designer","Description","Copyright","LicenseTerms","Rating","CreationDate","ModificationDate","Application"],l(n,c),n})(),ws=(()=>{let e,t,n,s,r,i=[Fn({ns:ss,name:"meta"})],o=[],c=[],h=[],d=[],f=[],p=[],m=[];return t=class{constructor(e,t,n,s){this.name=l(this,c,void 0),this.preserve=(l(this,h),l(this,d,void 0)),this.type=(l(this,f),l(this,p,void 0)),this.value=l(this,m),this.name=e,this.value=t,this.preserve=n,this.type=s}},u(t,"ThreeMfMeta"),(()=>{const u="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;n=[Bn({name:"name"})],s=[Bn({name:"preserve"})],r=[Bn({name:"type"})],a(null,null,n,{kind:"field",name:"name",static:!1,private:!1,access:{has:e=>"name"in e,get:e=>e.name,set:(e,t)=>{e.name=t}},metadata:u},c,h),a(null,null,s,{kind:"field",name:"preserve",static:!1,private:!1,access:{has:e=>"preserve"in e,get:e=>e.preserve,set:(e,t)=>{e.preserve=t}},metadata:u},d,f),a(null,null,r,{kind:"field",name:"type",static:!1,private:!1,access:{has:e=>"type"in e,get:e=>e.type,set:(e,t)=>{e.type=t}},metadata:u},p,m),a(null,e={value:t},i,{kind:"class",name:t.name,metadata:u},null,o),t=e.value,u&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:u}),l(t,o)})(),t})(),Rs=(()=>{let e,t,n=[Fn({ns:ss,name:"metadatagroup"})],s=[];return t=class{constructor(){this.metadata=[]}},u(t,"ThreeMfMetadataGroup"),(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;a(null,e={value:t},n,{kind:"class",name:t.name,metadata:r},null,s),t=e.value,r&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),l(t,s)})(),t})(),As=(()=>{let e,t,n=[Fn({ns:ss,name:"resources"})],s=[];return t=class{constructor(){this.object=[]}},u(t,"ThreeMfResources"),(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;a(null,e={value:t},n,{kind:"class",name:t.name,metadata:r},null,s),t=e.value,r&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),l(t,s)})(),t})(),Cs=(()=>{let t,n,s,r,i,o,c,h,d,f=[Fn({ns:ss,name:"object"})],p=[],m=[],g=[],x=[],_=[],T=[],y=[],b=[],v=[],M=[],w=[],R=[],A=[],C=[],E=[];return n=class{constructor(t,n=e.ST_ObjectType.model){this.id=l(this,m,void 0),this.type=(l(this,g),l(this,x,void 0)),this.thumbnail=(l(this,_),l(this,T,void 0)),this.partnumber=(l(this,y),l(this,b,void 0)),this.name=(l(this,v),l(this,M,void 0)),this.pid=(l(this,w),l(this,R,void 0)),this.pindex=(l(this,A),l(this,C,void 0)),this.metadatagroup=l(this,E),this.id=t,this.type=n}},u(n,"ThreeMfObject"),(()=>{const e="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;s=[Bn({name:"id"})],r=[Bn({name:"type"})],i=[Bn({name:"thumbnail"})],o=[Bn({name:"partnumber"})],c=[Bn({name:"name"})],h=[Bn({name:"pid"})],d=[Bn({name:"pindex"})],a(null,null,s,{kind:"field",name:"id",static:!1,private:!1,access:{has:e=>"id"in e,get:e=>e.id,set:(e,t)=>{e.id=t}},metadata:e},m,g),a(null,null,r,{kind:"field",name:"type",static:!1,private:!1,access:{has:e=>"type"in e,get:e=>e.type,set:(e,t)=>{e.type=t}},metadata:e},x,_),a(null,null,i,{kind:"field",name:"thumbnail",static:!1,private:!1,access:{has:e=>"thumbnail"in e,get:e=>e.thumbnail,set:(e,t)=>{e.thumbnail=t}},metadata:e},T,y),a(null,null,o,{kind:"field",name:"partnumber",static:!1,private:!1,access:{has:e=>"partnumber"in e,get:e=>e.partnumber,set:(e,t)=>{e.partnumber=t}},metadata:e},b,v),a(null,null,c,{kind:"field",name:"name",static:!1,private:!1,access:{has:e=>"name"in e,get:e=>e.name,set:(e,t)=>{e.name=t}},metadata:e},M,w),a(null,null,h,{kind:"field",name:"pid",static:!1,private:!1,access:{has:e=>"pid"in e,get:e=>e.pid,set:(e,t)=>{e.pid=t}},metadata:e},R,A),a(null,null,d,{kind:"field",name:"pindex",static:!1,private:!1,access:{has:e=>"pindex"in e,get:e=>e.pindex,set:(e,t)=>{e.pindex=t}},metadata:e},C,E),a(null,t={value:n},f,{kind:"class",name:n.name,metadata:e},null,p),n=t.value,e&&Object.defineProperty(n,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:e}),l(n,p)})(),n})(),Es=(()=>{let e,t,n=[Fn({ns:ss,name:"mesh"})],s=[];return t=class{constructor(e,t){this.vertices=null!=e?e:new Is,this.triangles=null!=t?t:new Vs}},u(t,"ThreeMfMesh"),(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;a(null,e={value:t},n,{kind:"class",name:t.name,metadata:r},null,s),t=e.value,r&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),l(t,s)})(),t})(),Is=(()=>{let e,t,n=[Fn({ns:ss,name:"vertices"})],s=[];return t=class{constructor(){this.vertex=[]}},u(t,"ThreeMfVertices"),(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;a(null,e={value:t},n,{kind:"class",name:t.name,metadata:r},null,s),t=e.value,r&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),l(t,s)})(),t})(),Ss=(()=>{let e,t,n,s,r,i=[Fn({ns:ss,name:"vertex"})],o=[],c=[],h=[],d=[],f=[],p=[],m=[];return t=class{constructor(e=0,t=0,n=0){this.x=l(this,c,void 0),this.y=(l(this,h),l(this,d,void 0)),this.z=(l(this,f),l(this,p,void 0)),l(this,m),this.x=e,this.y=t,this.z=n}},u(t,"ThreeMfVertex"),(()=>{const u="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;n=[Bn({name:"x"})],s=[Bn({name:"y"})],r=[Bn({name:"z"})],a(null,null,n,{kind:"field",name:"x",static:!1,private:!1,access:{has:e=>"x"in e,get:e=>e.x,set:(e,t)=>{e.x=t}},metadata:u},c,h),a(null,null,s,{kind:"field",name:"y",static:!1,private:!1,access:{has:e=>"y"in e,get:e=>e.y,set:(e,t)=>{e.y=t}},metadata:u},d,f),a(null,null,r,{kind:"field",name:"z",static:!1,private:!1,access:{has:e=>"z"in e,get:e=>e.z,set:(e,t)=>{e.z=t}},metadata:u},p,m),a(null,e={value:t},i,{kind:"class",name:t.name,metadata:u},null,o),t=e.value,u&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:u}),l(t,o)})(),t})(),Vs=(()=>{let e,t,n=[Fn({ns:ss,name:"triangles"})],s=[];return t=class{constructor(){this.triangle=[]}},u(t,"ThreeMfTriangles"),(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;a(null,e={value:t},n,{kind:"class",name:t.name,metadata:r},null,s),t=e.value,r&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),l(t,s)})(),t})(),Fs=(()=>{let e,t,n,s,r,i,o,c,h,d=[Fn({ns:ss,name:"triangle"})],f=[],p=[],m=[],g=[],x=[],_=[],T=[],y=[],b=[],v=[],M=[],w=[],R=[],A=[],C=[];return t=class{constructor(e,t,n){this.v1=l(this,p,void 0),this.v2=(l(this,m),l(this,g,void 0)),this.v3=(l(this,x),l(this,_,void 0)),this.p1=(l(this,T),l(this,y,void 0)),this.p2=(l(this,b),l(this,v,void 0)),this.p3=(l(this,M),l(this,w,void 0)),this.pid=(l(this,R),l(this,A,void 0)),l(this,C),this.v1=e,this.v2=t,this.v3=n}},u(t,"ThreeMfTriangle"),(()=>{const u="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;n=[Bn({name:"v1"})],s=[Bn({name:"v2"})],r=[Bn({name:"v3"})],i=[Bn({name:"p1"})],o=[Bn({name:"p2"})],c=[Bn({name:"p3"})],h=[Bn({name:"pid"})],a(null,null,n,{kind:"field",name:"v1",static:!1,private:!1,access:{has:e=>"v1"in e,get:e=>e.v1,set:(e,t)=>{e.v1=t}},metadata:u},p,m),a(null,null,s,{kind:"field",name:"v2",static:!1,private:!1,access:{has:e=>"v2"in e,get:e=>e.v2,set:(e,t)=>{e.v2=t}},metadata:u},g,x),a(null,null,r,{kind:"field",name:"v3",static:!1,private:!1,access:{has:e=>"v3"in e,get:e=>e.v3,set:(e,t)=>{e.v3=t}},metadata:u},_,T),a(null,null,i,{kind:"field",name:"p1",static:!1,private:!1,access:{has:e=>"p1"in e,get:e=>e.p1,set:(e,t)=>{e.p1=t}},metadata:u},y,b),a(null,null,o,{kind:"field",name:"p2",static:!1,private:!1,access:{has:e=>"p2"in e,get:e=>e.p2,set:(e,t)=>{e.p2=t}},metadata:u},v,M),a(null,null,c,{kind:"field",name:"p3",static:!1,private:!1,access:{has:e=>"p3"in e,get:e=>e.p3,set:(e,t)=>{e.p3=t}},metadata:u},w,R),a(null,null,h,{kind:"field",name:"pid",static:!1,private:!1,access:{has:e=>"pid"in e,get:e=>e.pid,set:(e,t)=>{e.pid=t}},metadata:u},A,C),a(null,e={value:t},d,{kind:"class",name:t.name,metadata:u},null,f),t=e.value,u&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:u}),l(t,f)})(),t})(),Os=(()=>{let e,t,n=[Fn({ns:ss,name:"components"})],s=[];return t=class{constructor(){this.component=[]}},u(t,"ThreeMfComponents"),(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;a(null,e={value:t},n,{kind:"class",name:t.name,metadata:r},null,s),t=e.value,r&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),l(t,s)})(),t})(),Bs=(()=>{let e,t,n,s,r=[Fn({ns:ss,name:"component"})],i=[],o=[],c=[],h=[],d=[];return t=class{constructor(e,t){this.objectid=l(this,o,void 0),this.transform=(l(this,c),l(this,h,void 0)),l(this,d),this.objectid=e,this.transform=t}},u(t,"ThreeMfComponent"),(()=>{const u="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;n=[Bn({name:"objectid"})],s=[Bn({name:"transform",formatter:vs})],a(null,null,n,{kind:"field",name:"objectid",static:!1,private:!1,access:{has:e=>"objectid"in e,get:e=>e.objectid,set:(e,t)=>{e.objectid=t}},metadata:u},o,c),a(null,null,s,{kind:"field",name:"transform",static:!1,private:!1,access:{has:e=>"transform"in e,get:e=>e.transform,set:(e,t)=>{e.transform=t}},metadata:u},h,d),a(null,e={value:t},r,{kind:"class",name:t.name,metadata:u},null,i),t=e.value,u&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:u}),l(t,i)})(),t})(),Ns=(()=>{let e,t,n,s=[Fn({ns:ss,name:"basematerials"})],r=[],i=[],o=[];return t=class{constructor(e){this.id=l(this,i,void 0),this.base=(l(this,o),[]),this.id=e}},u(t,"ThreeMfBaseMaterials"),(()=>{const u="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;n=[Bn({name:"id"})],a(null,null,n,{kind:"field",name:"id",static:!1,private:!1,access:{has:e=>"id"in e,get:e=>e.id,set:(e,t)=>{e.id=t}},metadata:u},i,o),a(null,e={value:t},s,{kind:"class",name:t.name,metadata:u},null,r),t=e.value,u&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:u}),l(t,r)})(),t})(),Ps=(()=>{let e,t,n,s,r=[Fn({ns:ss,name:"base"})],i=[],o=[],c=[],h=[],d=[];return t=class{constructor(e,t){this.name=l(this,o,void 0),this.displaycolor=(l(this,c),l(this,h,void 0)),l(this,d),this.name=e,this.displaycolor=t}},u(t,"ThreeMfBase"),(()=>{const u="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;n=[Bn({name:"name"})],s=[Bn({name:"displaycolor"})],a(null,null,n,{kind:"field",name:"name",static:!1,private:!1,access:{has:e=>"name"in e,get:e=>e.name,set:(e,t)=>{e.name=t}},metadata:u},o,c),a(null,null,s,{kind:"field",name:"displaycolor",static:!1,private:!1,access:{has:e=>"displaycolor"in e,get:e=>e.displaycolor,set:(e,t)=>{e.displaycolor=t}},metadata:u},h,d),a(null,e={value:t},r,{kind:"class",name:t.name,metadata:u},null,i),t=e.value,u&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:u}),l(t,i)})(),t})(),Us=(()=>{let e,t,n=[Fn({ns:ss,name:"build"})],s=[];return t=class{constructor(){this.item=[]}},u(t,"ThreeMfBuild"),(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;a(null,e={value:t},n,{kind:"class",name:t.name,metadata:r},null,s),t=e.value,r&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),l(t,s)})(),t})(),ks=(()=>{let e,t,n,s,r,i=[Fn({ns:ss,name:"item"})],o=[],c=[],h=[],d=[],f=[],p=[],m=[];return t=class{constructor(e,t,n){this.objectid=l(this,c,void 0),this.transform=(l(this,h),l(this,d,void 0)),this.partnumber=(l(this,f),l(this,p,void 0)),this.metadatagroup=l(this,m),this.objectid=e,this.transform=t,this.partnumber=n}},u(t,"ThreeMfItem"),(()=>{const u="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;n=[Bn({name:"objectid"})],s=[Bn({name:"transform",formatter:vs})],r=[Bn({name:"partnumber"})],a(null,null,n,{kind:"field",name:"objectid",static:!1,private:!1,access:{has:e=>"objectid"in e,get:e=>e.objectid,set:(e,t)=>{e.objectid=t}},metadata:u},c,h),a(null,null,s,{kind:"field",name:"transform",static:!1,private:!1,access:{has:e=>"transform"in e,get:e=>e.transform,set:(e,t)=>{e.transform=t}},metadata:u},d,f),a(null,null,r,{kind:"field",name:"partnumber",static:!1,private:!1,access:{has:e=>"partnumber"in e,get:e=>e.partnumber,set:(e,t)=>{e.partnumber=t}},metadata:u},p,m),a(null,e={value:t},i,{kind:"class",name:t.name,metadata:u},null,o),t=e.value,u&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:u}),l(t,o)})(),t})();class Ks{constructor(e,t){this._object=new Cs(e,t)}withName(e){return this._object.name=e,this}withThumbnail(e){return this._object.thumbnail=e,this}withProperty(e,t=0){return this._object.pid=e,this._object.id=t,this}build(){return this._object}reset(e,t){this._object=new Cs(e,t)}}class $s extends Ks{constructor(t,n=e.ST_ObjectType.model){super(t,n),this._object.content=new Os}withComponent(e,t){return this._object.content.component.push(new Bs(e,t)),this}}class zs extends Ks{constructor(t){super(t,e.ST_ObjectType.model)}withPostProcessHandlers(e,t){return this._vh=e,this._th=t,this}withData(e){return this._object.content=this._buildMesh(e),this}withMaterial(e,t){return this._object.pid=e,this._object.pindex=t,this}_buildMesh(e){const t=this._buildVertices(e.positions),n=this._buildTriangle(e.indices);return new Es(t,n)}_buildVertices(e){const t=new Is;if(e)for(let n=0;n<e.length;){const s=e[n++],r=e[n++],i=e[n++];let o=new Ss(s,r,i);this._vh&&(o=this._vh(o)),t.vertex.push(o)}return t}_buildTriangle(e){const t=new Vs;if(e)for(let n=0;n<e.length;){const s=e[n++],r=e[n++],i=e[n++];let o=new Fs(s,r,i);this._th&&(o=this._th(o)),t.triangle.push(o)}return t}}class Ws{constructor(e){this._m=new Ns(e)}withColor(e,t){var n;this._m.base=null!==(n=this._m.base)&&void 0!==n?n:[];let s=this._m.base.find(t=>t.name.toLowerCase()===e.toLowerCase());return s?(s.displaycolor=this._rgbaToHex(t),this):(s=new Ps(e,this._rgbaToHex(t)),this._m.base.push(s),this)}build(){return this._m}_rgbaToHex(e){const t=e=>Math.round(Math.min(255,Math.max(0,255*Math.pow(e,1/2.2)))),n=t(e.r).toString(16).padStart(2,"0").toUpperCase(),s=t(e.g).toString(16).padStart(2,"0").toUpperCase(),r=t(e.b).toString(16).padStart(2,"0").toUpperCase();return"number"==typeof e.a?`#${n}${s}${r}${Math.round(Math.min(255,Math.max(0,255*e.a))).toString(16).padStart(2,"0").toUpperCase()}`:`#${n}${s}${r}`}}class Ds{constructor(){this._model=new Ms,this._objects=new Map}withMetaData(e,t,n,s){return this._model.metadata||(this._model.metadata=new Array),this._model.metadata.push(new ws(e,t,n,s)),this}withMaterial(e){var t,n;return e instanceof Ws&&(e=e.build()),e&&(this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new As,this._model.resources.basematerials=null!==(n=this._model.resources.basematerials)&&void 0!==n?n:[],this._model.resources.basematerials.push(e)),this}withMesh(e){var t;return e instanceof zs&&(e=e.build()),this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new As,this._model.resources.object.push(e),this}withComponents(e){var t;return e instanceof $s&&(e=e.build()),this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new As,this._model.resources.object.push(e),this}withBuild(e,t,n){var s,r;return this._model.build=null!==(s=this._model.build)&&void 0!==s?s:new Us,null===(r=this._model.build.item)||void 0===r||r.push(new ks(e,t,n)),this}withUnit(e){return this._model.unit=e,this}reset(){return this._model=new Ms,this._objects=new Map,this}build(){var e,t,n,s;if(!(null===(t=null===(e=this._model.resources)||void 0===e?void 0:e.object)||void 0===t?void 0:t.length))throw new Error("Invalid state: resources MUST be defined ");if(!(null===(s=null===(n=this._model.build)||void 0===n?void 0:n.item)||void 0===s?void 0:s.length))throw new Error("Invalid state: Build MUST be defined ");return this._model}}Ds.KnownMetaSet=new Set(Ms.KnownMeta.map(e=>e.toLowerCase()));class Ls{withContentType(e){this._cts||(this._cts=new gs);const t=this._cts.items;return t.some(t=>t.ext===e.ext&&t.ct===e.ct)||t.push(e),this}withRelationship(t){this._rs||(this._rs=new _s);const n=this._rs.items;return n.some(e=>e.id===t.id)||n.push(t),this.withContentType(new xs("rels",e.KnownI3mfContentType.Relationships)),this}withModel(t){return t instanceof Ds&&(t=t.build()),this._m=t,this.withContentType(new xs("model",e.KnownI3mfContentType.Model)),this}build(){if(!this._m)throw new Error("Invalid state: you Must provide at least a model.");const e=`${hs}${ds}`;if(!this._rs){const t=`/${e}`;this.withRelationship(new Ts("rel0",ms.ThreeDimModel,t))}return new ys(this._cts,this._rs,this._m)}}class Hs{constructor(e){this._o=e}get options(){return this._o}serializeAsync(e,...t){return c(this,void 0,void 0,function*(){const n=yield this.ensureZipLibReadyAsync();if(!n)return;const s=n.Zip,r=n.ZipDeflate;if(!s||!r)throw new Error("fflate Zip / ZipDeflate not available");const i=function(e,t,n){const s=new r(t,{level:6});e.add(s);const i=function(e){return{push:(t,n)=>e.push(t,n)}}(s),o=new ns(i),a=new es(o).dec("1.0","UTF-8");new Zn(a).serialize(n),o.finish()},o=this.toDocument(...t);if(!o)return;const a=new s(e);i(a,ps,o.contentTypes),i(a,`${cs}${fs}`,o.relationships),i(a,`${hs}${ds}`,o.model),a.end()})}toDocument(...t){var n,s;const r=(new Ds).withUnit(null!==(s=null===(n=this._o)||void 0===n?void 0:n.unit)&&void 0!==s?s:e.ST_Unit.millimeter);if(this.options.metadata)for(const e in this.options.metadata)r.withMetaData(e,this.options.metadata[e]);return(new Ls).withModel(this.toModel(r,...t)).build()}}class js{static SerializeToMemoryAsync(e,...t){return c(this,void 0,void 0,function*(){const n=new Array;let s=0;if(yield e.serializeAsync(function(e,t,r){n.push(t),s+=t.length},...t),!s)return;const r=new Uint8Array(s);let i=0;for(const e of n)r.set(e,i),i+=e.length;return r})}}class qs{}qs.FFLATEUrl="https://unpkg.com/fflate@0.8.2";class Gs{constructor(e=0,t=Number.MIN_SAFE_INTEGER,n=1){this._from=e,this._to=t,this._step=n,this._i=e}next(){if(this._i<this._to)throw new Error("ST_ResourceID out of bound");const e=this._i;return this._i+=this._step,e}reset(){return this._i=this._from,this}}class Xs extends Hs{constructor(e={}){super(Object.assign(Object.assign({},Xs.DefaultOptions),e))}toModel(e,...n){n=n.filter(e=>e instanceof t.Mesh||e instanceof t.InstancedMesh);const s=new Gs,r=e,i=new Map,o=this.options.exportInstances?[]:null;for(let e=0;e<n.length;e++){const a=n[e];if(a instanceof t.InstancedMesh){null==o||o.push(a);continue}const l=a.name||`mesh${e}`,u=a.getWorldMatrix(),c=this._handleBabylonTo3mfMatrixTransformToRef(u,bs.Zero()),h=a.subMeshes;if(void 0===h)continue;const d=1==h.length;for(let e=0;e<h.length;e++){const t=h[e],n=this._extractSubMesh(a,t);if(n){const o=d?`${l}`:`${l}_${e}`,a=new zs(s.next()).withData(n).withName(o).build();r.withMesh(a),r.withBuild(a.id,c),i.set(t,a)}}}if(o&&o.length){const e=this._groupBy(o,e=>e.sourceMesh);for(const[t,n]of Array.from(e.entries()))if(n&&n.length)for(let e=0;e<n.length;e++){const s=n[e].getWorldMatrix(),o=t.subMeshes;for(let e=0;e<o.length;e++){const t=o[e],n=i.get(t);n&&r.withBuild(n.id,this._handleBabylonTo3mfMatrixTransformToRef(s,bs.Zero()))}}}return r.build()}ensureZipLibReadyAsync(){return c(this,void 0,void 0,function*(){return this._fflateReadyPromise||(this._fflateReadyPromise=(()=>c(this,void 0,void 0,function*(){const e=globalThis;return e.fflate||(yield t.Tools.LoadScriptAsync(qs.FFLATEUrl)),e.fflate}))()),yield this._fflateReadyPromise})}_extractSubMesh(e,t){const n=e.getIndices();if(!n)return;const s=e.getVerticesData(Xs._PositionKind);if(!s)return;if(0==t.indexStart&&t.indexCount==n.length)return{positions:s,indices:n};const r=t.indexStart,i=new Map,o=[],a=new Uint32Array(t.indexCount);for(let e=0;e<t.indexCount;e++){const t=n[r+e];let l=i.get(t);if(void 0===l){l=i.size,i.set(t,l);const e=3*t;o.push(s[e],s[e+1],s[e+2])}a[e]=l}return{positions:new Float32Array(o),indices:a}}_groupBy(e,t){const n=new Map;for(const s of e){const e=t(s),r=n.get(e);r?r.push(s):n.set(e,[s])}return n}_handleBabylonTo3mfMatrixTransformToRef(e,n){const s=e.multiplyToRef(Xs._R_BJS_TO_3MF,t.Matrix.Zero()).m;return n.values=[s[0],s[1],s[2],s[4],s[5],s[6],s[8],s[9],s[10],s[12],s[13],s[14]],n}}Xs.DefaultOptions={unit:e.ST_Unit.meter,exportInstances:!1},Xs._PositionKind="position",Xs._R_BJS_TO_3MF=t.Matrix.RotationX(Math.PI/2).multiply(t.Matrix.Scaling(1,-1,1));var Qs={__proto__:null,AbstractThreeMfSerializer:Hs,ContentTypeFileName:ps,DefaultXmlSerializerFormatOptions:Wn,DefaultXmlSerializerNumberOptions:zn,GetXmlFieldMeta:Pn,GetXmlName:Un,IsQualifiedName:En,Known3mfRelationshipTypes:ms,get KnownI3mfContentType(){return e.KnownI3mfContentType},Matrix3d:bs,MatrixFormatter:vs,ModelFileName:ds,NumberFormatter:Hn,Object3dDirName:hs,OpenXmlContentTypesNamespace:as,OpenXmlRelationshipsNamespace:ls,RelationshipDirName:cs,RelationshipFileName:fs,ResolveFormatOptions:Ln,ResolveNumberOptions:Dn,get ST_ObjectType(){return e.ST_ObjectType},get ST_Unit(){return e.ST_Unit},StringXmlWriter:ts,ThreeDimModelNamespace:ss,ThreeMf:js,ThreeMfBase:Ps,ThreeMfBaseMaterials:Ns,ThreeMfBuild:Us,ThreeMfComponent:Bs,ThreeMfComponents:Os,ThreeMfComponentsBuilder:$s,ThreeMfContentType:xs,ThreeMfContentTypes:gs,ThreeMfDocument:ys,ThreeMfDocumentBuilder:Ls,ThreeMfItem:ks,ThreeMfMaterialBuilder:Ws,ThreeMfMesh:Es,ThreeMfMeshBuilder:zs,ThreeMfMeta:ws,ThreeMfMetadataGroup:Rs,ThreeMfModel:Ms,ThreeMfModelBuilder:Ds,ThreeMfObject:Cs,ThreeMfObjectBuilder:Ks,ThreeMfRelationship:Ts,ThreeMfRelationships:_s,ThreeMfResources:As,ThreeMfSerializer:Xs,ThreeMfSerializerGlobalConfiguration:qs,ThreeMfTriangle:Fs,ThreeMfTriangles:Vs,ThreeMfVertex:Ss,ThreeMfVertices:Is,ToQualifiedString:$n,get TokenType(){return e.TokenType},TriangleSetsNamespace:rs,Utf8XmlWriterToBytes:ns,XmlAttr:Bn,XmlBuilder:es,XmlElem:Nn,XmlIgnore:On,XmlName:Fn,XmlNameToParts:Kn,XmlSerializer:Zn};const Zs="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==Zs)for(const e in Cn)Zs.BABYLON[e]=Cn[e];const Ys="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==Ys){Ys.BABYLON=Ys.BABYLON||{};const e=Ys.BABYLON;e.GLTF2=e.GLTF2||{},e.GLTF2.Exporter=e.GLTF2.Exporter||{},e.GLTF2.Exporter.Extensions=e.GLTF2.Exporter.Extensions||{};const t=[];for(const n in r)e[n]=r[n],t.push(n);for(const n in o)e[n]=o[n],t.push(n);for(const n in J)e[n]=J[n],t.push(n);for(const n in on)e.GLTF2.Exporter.Extensions[n]=on[n],t.push(n);for(const n in an)t.indexOf(n)>-1||(e.GLTF2.Exporter[n]=an[n])}const Js="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==Js)for(const e in s)Js.BABYLON[e]=s[e];const er="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==er)for(const e in un)er.BABYLON[e]=un[e];const tr="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==tr)for(const e in Rn)tr.BABYLON[e]=Rn[e];const nr="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==nr){const e=[];for(const t in Qs)e.indexOf(t)>-1||(nr.BABYLON[t]=Qs[t],e.push(t))}e.AbstractThreeMfSerializer=Hs,e.BVHExporter=An,e.ContentTypeFileName=ps,e.DefaultXmlSerializerFormatOptions=Wn,e.DefaultXmlSerializerNumberOptions=zn,e.EXT_lights_area=be,e.EXT_mesh_gpu_instancing=ne,e.EXT_texture_avif=nn,e.EXT_texture_webp=Yt,e.GLTF2Export=Y,e.GLTFData=i,e.GetXmlFieldMeta=Pn,e.GetXmlName=Un,e.IsQualifiedName=En,e.KHR_draco_mesh_compression=ae,e.KHR_lights_punctual=pe,e.KHR_materials_anisotropy=Re,e.KHR_materials_clearcoat=Se,e.KHR_materials_coat=Pe,e.KHR_materials_diffuse_roughness=Pt,e.KHR_materials_diffuse_transmission=ze,e.KHR_materials_dispersion=He,e.KHR_materials_emissive_strength=Xe,e.KHR_materials_fuzz=dt,e.KHR_materials_ior=Je,e.KHR_materials_iridescence=st,e.KHR_materials_openpbr=$t,e.KHR_materials_sheen=at,e.KHR_materials_specular=gt,e.KHR_materials_transmission=yt,e.KHR_materials_unlit=wt,e.KHR_materials_volume=Et,e.KHR_materials_volume_scatter=Ft,e.KHR_texture_basisu=Gt,e.KHR_texture_transform=Lt,e.Known3mfRelationshipTypes=ms,e.Matrix3d=bs,e.MatrixFormatter=vs,e.ModelFileName=ds,e.NumberFormatter=Hn,e.OBJExport=n,e.Object3dDirName=hs,e.OpenXmlContentTypesNamespace=as,e.OpenXmlRelationshipsNamespace=ls,e.RegisterEXT_lights_area=Me,e.RegisterEXT_mesh_gpu_instancing=re,e.RegisterEXT_texture_avif=rn,e.RegisterEXT_texture_webp=en,e.RegisterKHR_draco_mesh_compression=ue,e.RegisterKHR_lights_punctual=ge,e.RegisterKHR_materials_anisotropy=Ce,e.RegisterKHR_materials_clearcoat=Fe,e.RegisterKHR_materials_coat=ke,e.RegisterKHR_materials_diffuse_roughness=kt,e.RegisterKHR_materials_diffuse_transmission=De,e.RegisterKHR_materials_dispersion=qe,e.RegisterKHR_materials_emissive_strength=Ze,e.RegisterKHR_materials_fuzz=pt,e.RegisterKHR_materials_ior=tt,e.RegisterKHR_materials_iridescence=it,e.RegisterKHR_materials_openpbr=Wt,e.RegisterKHR_materials_sheen=ut,e.RegisterKHR_materials_specular=_t,e.RegisterKHR_materials_transmission=vt,e.RegisterKHR_materials_unlit=At,e.RegisterKHR_materials_volume=St,e.RegisterKHR_materials_volume_scatter=Bt,e.RegisterKHR_texture_basisu=Qt,e.RegisterKHR_texture_transform=jt,e.RelationshipDirName=cs,e.RelationshipFileName=fs,e.ResolveFormatOptions=Ln,e.ResolveNumberOptions=Dn,e.STLExport=ln,e.StringXmlWriter=ts,e.ThreeDimModelNamespace=ss,e.ThreeMf=js,e.ThreeMfBase=Ps,e.ThreeMfBaseMaterials=Ns,e.ThreeMfBuild=Us,e.ThreeMfComponent=Bs,e.ThreeMfComponents=Os,e.ThreeMfComponentsBuilder=$s,e.ThreeMfContentType=xs,e.ThreeMfContentTypes=gs,e.ThreeMfDocument=ys,e.ThreeMfDocumentBuilder=Ls,e.ThreeMfItem=ks,e.ThreeMfMaterialBuilder=Ws,e.ThreeMfMesh=Es,e.ThreeMfMeshBuilder=zs,e.ThreeMfMeta=ws,e.ThreeMfMetadataGroup=Rs,e.ThreeMfModel=Ms,e.ThreeMfModelBuilder=Ds,e.ThreeMfObject=Cs,e.ThreeMfObjectBuilder=Ks,e.ThreeMfRelationship=Ts,e.ThreeMfRelationships=_s,e.ThreeMfResources=As,e.ThreeMfSerializer=Xs,e.ThreeMfSerializerGlobalConfiguration=qs,e.ThreeMfTriangle=Fs,e.ThreeMfTriangles=Vs,e.ThreeMfVertex=Ss,e.ThreeMfVertices=Is,e.ToQualifiedString=$n,e.TriangleSetsNamespace=rs,e.USDZExportAsync=wn,e.Utf8XmlWriterToBytes=ns,e.XmlAttr=Bn,e.XmlBuilder=es,e.XmlElem=Nn,e.XmlIgnore=On,e.XmlName=Fn,e.XmlNameToParts=Kn,e.XmlSerializer=Zn,e._ConvertToGLTFPBRMetallicRoughness=_,e._SolveMetallic=x,e.__IGLTFExporterExtension=0});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("babylonjs")):"function"==typeof define&&define.amd?define(["exports","babylonjs"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).BABYLON=e.BABYLON||{},e.BABYLON)}(this,function(e,t){"use strict";class n{static OBJ(e,n,s,r){const i=[];let o=1,a=1;n&&(s||(s="mat"),i.push("mtllib "+s+".mtl"));for(let s=0;s<e.length;s++){const l=e[s],u=l.name||`mesh${s}}`;i.push(`o ${u}`);let c=null;if(r){const e=l.computeWorldMatrix(!0);c=new t.Matrix,e.invertToRef(c),l.bakeTransformIntoVertices(e)}if(n){const e=l.material;e&&i.push("usemtl "+e.id)}const h=l.geometry;if(!h){t.Tools.Warn("No geometry is present on the mesh");continue}const d=h.getVerticesData("position"),f=h.getVerticesData("normal"),p=h.getVerticesData("uv"),m=h.getIndices();let g=0,x=0;if(!d||!m){t.Tools.Warn("There are no position vertices or indices on the mesh!");continue}const _=e[0].getScene().useRightHandedSystem?1:-1;for(let e=0;e<d.length;e+=3)i.push("v "+d[e]*_+" "+d[e+1]+" "+d[e+2]),g++;if(null!=f)for(let e=0;e<f.length;e+=3)i.push("vn "+f[e]*_+" "+f[e+1]+" "+f[e+2]);if(null!=p)for(let e=0;e<p.length;e+=2)i.push("vt "+p[e]+" "+p[e+1]),x++;const T=["","",""],y=(l.material||l.getScene().defaultMaterial)._getEffectiveOrientation(l),[b,v]=y===t.Material.ClockWiseSideOrientation?[2,1]:[1,2];for(let e=0;e<m.length;e+=3){const t=[String(m[e]+o),String(m[e+b]+o),String(m[e+v]+o)],n=[String(m[e]+a),String(m[e+b]+a),String(m[e+v]+a)],s=t,r=null!=p?n:T,l=null!=f?t:T;i.push("f "+s[0]+"/"+r[0]+"/"+l[0]+" "+s[1]+"/"+r[1]+"/"+l[1]+" "+s[2]+"/"+r[2]+"/"+l[2])}r&&c&&l.bakeTransformIntoVertices(c),o+=g,a+=x}return i.join("\n")}static MTL(e,t="mat1"){const n=[],s=e.material;return n.push("newmtl "+t),n.push(" Ns "+s.specularPower.toFixed(4)),n.push(" Ni 1.5000"),n.push(" d "+s.alpha.toFixed(4)),n.push(" Tr 0.0000"),n.push(" Tf 1.0000 1.0000 1.0000"),n.push(" illum 2"),n.push(" Ka "+s.ambientColor.r.toFixed(4)+" "+s.ambientColor.g.toFixed(4)+" "+s.ambientColor.b.toFixed(4)),n.push(" Kd "+s.diffuseColor.r.toFixed(4)+" "+s.diffuseColor.g.toFixed(4)+" "+s.diffuseColor.b.toFixed(4)),n.push(" Ks "+s.specularColor.r.toFixed(4)+" "+s.specularColor.g.toFixed(4)+" "+s.specularColor.b.toFixed(4)),n.push(" Ke "+s.emissiveColor.r.toFixed(4)+" "+s.emissiveColor.g.toFixed(4)+" "+s.emissiveColor.b.toFixed(4)),s.ambientTexture&&n.push(" map_Ka "+s.ambientTexture.name),s.diffuseTexture&&n.push(" map_Kd "+s.diffuseTexture.name),s.specularTexture&&n.push(" map_Ks "+s.specularTexture.name),s.bumpTexture&&n.push(" map_bump -imfchan z "+s.bumpTexture.name),s.opacityTexture&&n.push(" map_d "+s.opacityTexture.name),n.join("\n")}}var s={__proto__:null,OBJExport:n},r={__proto__:null,__IGLTFExporterExtension:0};class i{constructor(){this.files={}}get glTFFiles(){return this.files}downloadFiles(){for(const e in this.files){const n=this.files[e],s=new Blob([n],{type:t.GetMimeType(e)});t.Tools.Download(s,e)}}}var o={__proto__:null,GLTFData:i};function a(e,t,n,s,r,i){function o(e){if(void 0!==e&&"function"!=typeof e)throw new TypeError("Function expected");return e}for(var a,l=s.kind,u="getter"===l?"get":"setter"===l?"set":"value",c=!t&&e?s.static?e:e.prototype:null,h=t||(c?Object.getOwnPropertyDescriptor(c,s.name):{}),d=!1,f=n.length-1;f>=0;f--){var p={};for(var m in s)p[m]="access"===m?{}:s[m];for(var m in s.access)p.access[m]=s.access[m];p.addInitializer=function(e){if(d)throw new TypeError("Cannot add initializers after decoration has completed");i.push(o(e||null))};var g=(0,n[f])("accessor"===l?{get:h.get,set:h.set}:h[u],p);if("accessor"===l){if(void 0===g)continue;if(null===g||"object"!=typeof g)throw new TypeError("Object expected");(a=o(g.get))&&(h.get=a),(a=o(g.set))&&(h.set=a),(a=o(g.init))&&r.unshift(a)}else(a=o(g))&&("field"===l?r.unshift(a):h[u]=a)}c&&Object.defineProperty(c,s.name,h),d=!0}function l(e,t,n){for(var s=arguments.length>2,r=0;r<t.length;r++)n=s?t[r].call(e,n):t[r].call(e);return s?n:void 0}function u(e,t,n){return"symbol"==typeof t&&(t=t.description?"[".concat(t.description,"]"):""),Object.defineProperty(e,"name",{configurable:!0,value:n?"".concat(n," ",t):t})}function c(e,t,n,s){return new(n||(n=Promise))(function(r,i){function o(e){try{l(s.next(e))}catch(e){i(e)}}function a(e){try{l(s.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,a)}l((s=s.apply(e,t||[])).next())})}function h(e){return c(this,void 0,void 0,function*(){var n;const s=e.getInternalTexture();if(!s||1!==s.source)return null;if(s.invertY&&!((null===(n=e.getScene())||void 0===n?void 0:n.getEngine())instanceof t.NullEngine))return null;const r=s._buffer;let i,o=e.mimeType;try{r?ArrayBuffer.isView(r)?i=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength):r instanceof ArrayBuffer?i=r:r instanceof Blob?(i=yield r.arrayBuffer(),o=r.type||o):"string"==typeof r?(i=yield t.Tools.LoadFileAsync(r),o=t.GetMimeType(r)||o):"undefined"!=typeof HTMLImageElement&&r instanceof HTMLImageElement&&(i=yield t.Tools.LoadFileAsync(r.src),o=t.GetMimeType(r.src)||o):(i=yield t.Tools.LoadFileAsync(s.url),o=t.GetMimeType(s.url)||o)}catch(e){return null}if(i&&!o&&s.url){const e=s.url.match(/^data:([^;,]+)/);o=e?e[1]:t.GetMimeType(s.url)}return i&&o?{data:i,mimeType:o}:null})}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;const d=1e-6,f=new t.Color3(.04,.04,.04),p=t.Color3.White(),m=t.Color3.BlackReadOnly;function g(e){switch(e){case"image/jpeg":case"image/png":case"image/webp":case"image/avif":case"image/ktx2":return!0;default:return!1}}function x(e,n,s){if(n<f.r)return 0;const r=f.r,i=e*s/(1-f.r)+n-2*f.r,o=i*i-4*r*(f.r-n);return t.Scalar.Clamp((-i+Math.sqrt(o))/(2*r),0,1)}function _(e){const n=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),s=e.alpha,r=t.Scalar.Clamp(e.specularPower,0,1024),i=t.SpecularPowerToRoughness(r);return{baseColorFactor:[n.r,n.g,n.b,s],metallicFactor:0,roughnessFactor:i}}function T(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function y(e,n,s){const r=new Uint8Array(e*n*4);for(let e=0;e<r.length;e+=4)r[e]=r[e+1]=r[e+2]=r[e+3]=255;return t.RawTexture.CreateRGBATexture(r,e,n,s)}function b(e){if(e instanceof Uint8Array){const t=e.length,n=new Float32Array(e.length);for(let s=0;s<t;++s)n[s]=e[s]/255;return n}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")}class v{constructor(e){this._exporter=e,this._textureMap=new Map,this._internalTextureToImage={}}getTextureInfo(e){var t;return e&&null!==(t=this._textureMap.get(e.uniqueId))&&void 0!==t?t:null}exportStandardMaterialAsync(e,n){return c(this,void 0,void 0,function*(){const s=_(e),r={name:e.name};if(null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||t.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),n){const t=[],n=e.diffuseTexture;n&&t.push(this.exportTextureAsync(n).then(e=>{e&&(s.baseColorTexture=e)}));const i=e.bumpTexture;i&&t.push(this.exportTextureAsync(i).then(e=>{e&&(r.normalTexture=e,1!==i.level&&(r.normalTexture.scale=i.level))}));const o=e.emissiveTexture;o&&(r.emissiveFactor=[1,1,1],t.push(this.exportTextureAsync(o).then(e=>{e&&(r.emissiveTexture=e)})));const a=e.ambientTexture;a&&t.push(this.exportTextureAsync(a).then(e=>{if(e){const t={index:e.index};r.occlusionTexture=t}})),t.length>0&&(this._exporter._materialNeedsUVsSet.add(e),yield Promise.all(t))}(e.alpha<1||e.opacityTexture)&&(e.alphaMode===t.Constants.ALPHA_COMBINE?r.alphaMode="BLEND":t.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(m,d)&&(r.emissiveFactor=e.emissiveColor.asArray()),r.pbrMetallicRoughness=s,T(r,e),yield this._finishMaterialAsync(r,e);const i=this._exporter._materials;return i.push(r),i.length-1})}_finishMaterialAsync(e,t){return c(this,void 0,void 0,function*(){const n=yield this._exporter._extensionsPostExportMaterialAdditionalTexturesAsync("exportMaterial",e,t),s=[];for(const e of n)s.push(this.exportTextureAsync(e));yield Promise.all(s),yield this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)})}_resizeTexturesToSameDimensions(e,n,s){const r=e?e.getSize():{width:0,height:0},i=n?n.getSize():{width:0,height:0};let o,a;return r.width<i.width?(o=e&&e instanceof t.Texture?t.TextureTools.CreateResizedCopy(e,i.width,i.height,!0):y(i.width,i.height,s),a=n):r.width>i.width?(a=n&&n instanceof t.Texture?t.TextureTools.CreateResizedCopy(n,r.width,r.height,!0):y(r.width,r.height,s),o=e):(o=e,a=n),{texture1:o,texture2:a}}_convertSpecularGlossinessTexturesToMetallicRoughnessAsync(e,n,s){return c(this,void 0,void 0,function*(){var r;const i=new Array;if(!e&&!n)return yield Promise.reject("diffuse and specular glossiness textures are not defined!");const o=e?e.getScene():n?n.getScene():null;if(o){const a=this._resizeTexturesToSameDimensions(e,n,o),l=null===(r=a.texture1)||void 0===r?void 0:r.getSize();let u,c;const h=l.width,f=l.height,m=yield a.texture1.readPixels(),g=yield a.texture2.readPixels();if(!m)return yield Promise.reject("Failed to retrieve pixels from diffuse texture!");if(u=b(m),!g)return yield Promise.reject("Failed to retrieve pixels from specular glossiness texture!");c=b(g);const x=c.byteLength,_=new Uint8Array(x),T=new Uint8Array(x),y=4,v=new t.Color3(0,0,0);let M=0,w=0;for(let e=0;e<f;++e)for(let n=0;n<h;++n){const r=(h*e+n)*y,i={diffuseColor:new t.Color3(u[r],u[r+1],u[r+2]).toLinearSpace(o.getEngine().useExactSrgbConversions).multiply(s.diffuseColor),specularColor:new t.Color3(c[r],c[r+1],c[r+2]).toLinearSpace(o.getEngine().useExactSrgbConversions).multiply(s.specularColor),glossiness:c[r+3]*s.glossiness},l=this._convertSpecularGlossinessToMetallicRoughness(i);v.r=Math.max(v.r,l.baseColor.r),v.g=Math.max(v.g,l.baseColor.g),v.b=Math.max(v.b,l.baseColor.b),M=Math.max(M,l.metallic),w=Math.max(w,l.roughness),T[r]=255*l.baseColor.r,T[r+1]=255*l.baseColor.g,T[r+2]=255*l.baseColor.b,T[r+3]=a.texture1.hasAlpha?255*u[r+3]:255,_[r]=0,_[r+1]=255*l.roughness,_[r+2]=255*l.metallic,_[r+3]=255}const R={baseColor:v,metallic:M,roughness:w};let A=!1,C=!1;for(let e=0;e<f;++e)for(let n=0;n<h;++n){const s=(h*e+n)*y;T[s]/=R.baseColor.r>d?R.baseColor.r:1,T[s+1]/=R.baseColor.g>d?R.baseColor.g:1,T[s+2]/=R.baseColor.b>d?R.baseColor.b:1;const r=t.Color3.FromInts(T[s],T[s+1],T[s+2]).toGammaSpace(o.getEngine().useExactSrgbConversions);T[s]=255*r.r,T[s+1]=255*r.g,T[s+2]=255*r.b,r.equalsWithEpsilon(p,d)||(C=!0),_[s+1]/=R.roughness>d?R.roughness:1,_[s+2]/=R.metallic>d?R.metallic:1,t.Color3.FromInts(255,_[s+1],_[s+2]).equalsWithEpsilon(p,d)||(A=!0)}return A&&i.push(t.EncodeImageAsync(_,h,f).then(e=>{R.metallicRoughnessTextureData=e})),C&&i.push(t.EncodeImageAsync(T,h,f).then(e=>{R.baseColorTextureData=e})),yield Promise.all(i).then(()=>R)}return yield Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")})}_convertSpecularGlossinessToMetallicRoughness(e){const n=this._getPerceivedBrightness(e.diffuseColor),s=this._getPerceivedBrightness(e.specularColor),r=1-this._getMaxComponent(e.specularColor),i=x(n,s,r),o=e.diffuseColor.scale(r/(1-f.r)/Math.max(1-i,d)),a=e.specularColor.subtract(f.scale(1-i)).scale(1/Math.max(i,d));let l=t.Color3.Lerp(o,a,i*i);return l=l.clampToRef(0,1,l),{baseColor:l,metallic:i,roughness:1-e.glossiness}}_getPerceivedBrightness(e){return Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b)}_getMaxComponent(e){return Math.max(e.r,Math.max(e.g,e.b))}_convertMetalRoughFactorsToMetallicRoughnessAsync(e,n,s,r,i,o,a,l,u){return c(this,void 0,void 0,function*(){const h=[],d={baseColor:e,metallic:n,roughness:s};if(u)if(a instanceof t.OpenPBRMaterial){if(a.geometryOpacityTexture){const e=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:0,n=a.geometryOpacityTexture&&a.geometryOpacityTexture.getInternalTexture()?a.geometryOpacityTexture.getInternalTexture().uniqueId:0,s=Number(`${e}${n}`),i=this._textureMap.get(s);i?l.baseColorTexture=i:h.push(t.MergeTexturesAsync("baseColorOpacityTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),r?t.CreateTextureInput(r,1):t.CreateConstantInput(1),r?t.CreateTextureInput(r,2):t.CreateConstantInput(1),t.CreateTextureInput(a.geometryOpacityTexture,0)),a.getScene()).then(e=>c(this,void 0,void 0,function*(){const t=yield this.exportTextureAsync(e,s);t&&(l.baseColorTexture=t)})))}else r&&h.push(this.exportTextureAsync(r).then(e=>{e&&(l.baseColorTexture=e)}));if(a._useMetallicFromMetallicTextureBlue&&i)h.push(this.exportTextureAsync(i).then(e=>{e&&(l.metallicRoughnessTexture=e)}));else if(o||i){const e=i&&i.getInternalTexture()?i.getInternalTexture().uniqueId:0,n=o&&o.getInternalTexture()?o.getInternalTexture().uniqueId:0,s=Number(`${e}${n}`),r=this._textureMap.get(s);r?l.metallicRoughnessTexture=r:h.push(t.MergeTexturesAsync("MetalRoughTexture",t.CreateRGBAConfiguration(a.ambientOcclusionTexture?t.CreateTextureInput(a.ambientOcclusionTexture,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,0):t.CreateConstantInput(1),i?t.CreateTextureInput(i,0):t.CreateConstantInput(1)),a.getScene()).then(e=>c(this,void 0,void 0,function*(){const t=yield this.exportTextureAsync(e,s);t&&(l.metallicRoughnessTexture=t)})))}}else r&&h.push(this.exportTextureAsync(r).then(e=>{e&&(l.baseColorTexture=e)})),i&&h.push(this.exportTextureAsync(i).then(e=>{e&&(l.metallicRoughnessTexture=e)}));return h.length>0&&(this._exporter._materialNeedsUVsSet.add(a),yield Promise.all(h)),d})}_getTextureSampler(e){const n={};if(!(e&&e instanceof t.Texture))return n;const s=this._getGLTFTextureWrapMode(e.wrapU);10497!==s&&(n.wrapS=s);const r=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==r&&(n.wrapT=r),e.samplingMode){case t.Texture.LINEAR_LINEAR:n.magFilter=9729,n.minFilter=9729;break;case t.Texture.LINEAR_NEAREST:n.magFilter=9729,n.minFilter=9728;break;case t.Texture.NEAREST_LINEAR:n.magFilter=9728,n.minFilter=9729;break;case t.Texture.NEAREST_LINEAR_MIPLINEAR:n.magFilter=9728,n.minFilter=9987;break;case t.Texture.NEAREST_NEAREST:n.magFilter=9728,n.minFilter=9728;break;case t.Texture.NEAREST_LINEAR_MIPNEAREST:n.magFilter=9728,n.minFilter=9985;break;case t.Texture.LINEAR_NEAREST_MIPNEAREST:n.magFilter=9729,n.minFilter=9984;break;case t.Texture.LINEAR_NEAREST_MIPLINEAR:n.magFilter=9729,n.minFilter=9986;break;case t.Texture.NEAREST_NEAREST_MIPLINEAR:n.magFilter=9728,n.minFilter=9986;break;case t.Texture.LINEAR_LINEAR_MIPLINEAR:n.magFilter=9729,n.minFilter=9987;break;case t.Texture.LINEAR_LINEAR_MIPNEAREST:n.magFilter=9729,n.minFilter=9985;break;case t.Texture.NEAREST_NEAREST_MIPNEAREST:n.magFilter=9728,n.minFilter=9984}return n}_getGLTFTextureWrapMode(e){switch(e){case t.Texture.WRAP_ADDRESSMODE:return 10497;case t.Texture.CLAMP_ADDRESSMODE:return 33071;case t.Texture.MIRROR_ADDRESSMODE:return 33648;default:return t.Tools.Error(`Unsupported Texture Wrap Mode ${e}!`),10497}}_convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,n){return c(this,void 0,void 0,function*(){const s={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},r=e._albedoTexture,i=e._reflectivityTexture,o=e._useMicroSurfaceFromReflectivityMapAlpha;if(i&&!o)return yield Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported");if((r||i)&&n){this._exporter._materialNeedsUVsSet.add(e);const n=this._exportTextureSampler(r||i),o=yield this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(r,i,s),a=this._exporter._textures;if(o.baseColorTextureData){const e=yield this._exportImageAsync(`baseColor${a.length}`,o.baseColorTextureData);t.baseColorTexture=this._exportTextureInfo(e,n,null==r?void 0:r.coordinatesIndex)}if(o.metallicRoughnessTextureData){const e=yield this._exportImageAsync(`metallicRoughness${a.length}`,o.metallicRoughnessTextureData);t.metallicRoughnessTexture=this._exportTextureInfo(e,n,null==i?void 0:i.coordinatesIndex)}return o}return this._convertSpecularGlossinessToMetallicRoughness(s)})}exportPBRMaterialAsync(e,t){return c(this,void 0,void 0,function*(){const n={},s={name:e.name},r=e.isMetallicWorkflow();if(r){const t=e._albedoColor,s=e.alpha;t&&(n.baseColorFactor=[t.r,t.g,t.b,s])}const i=r?yield this._convertMetalRoughFactorsToMetallicRoughnessAsync(e._albedoColor,e._metallic,e._roughness,e._albedoTexture,e._metallicTexture,e._metallicTexture,e,n,t):yield this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,n,t);yield this._setMetallicRoughnessPbrMaterialAsync(i,e,s,n,t),yield this._finishMaterialAsync(s,e);const o=this._exporter._materials;return o.push(s),o.length-1})}_setMetallicRoughnessPbrMaterialAsync(e,n,s,r,i){return c(this,void 0,void 0,function*(){if(T(s,n),e.baseColor.equalsWithEpsilon(p,d)&&t.Scalar.WithinEpsilon(n.alpha,1,d)||(r.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,n.alpha]),null!=e.metallic&&1!==e.metallic&&(r.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(r.roughnessFactor=e.roughness),null==n.backFaceCulling||n.backFaceCulling||(n._twoSidedLighting||t.Tools.Warn(n.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),s.doubleSided=!0),i){const e=[],i=n instanceof t.PBRBaseMaterial?n._bumpTexture:n.geometryNormalTexture;i&&e.push(this.exportTextureAsync(i).then(e=>{e&&(s.normalTexture=e,1!==i.level&&(s.normalTexture.scale=i.level))}));const o=n instanceof t.PBRBaseMaterial?n._ambientTexture:n.ambientOcclusionTexture;o&&e.push(new Promise(e=>c(this,void 0,void 0,function*(){if(n instanceof t.OpenPBRMaterial&&r.metallicRoughnessTexture){const t=this._exportTextureSampler(o),n=this._exporter._textures[r.metallicRoughnessTexture.index].source,s=this._exportTextureInfo(n,t,o.coordinatesIndex);return this._textureMap.set(o.uniqueId,s),this._exporter._extensionsPostExportTextures("exporter",s,o),e(s)}return e(yield this.exportTextureAsync(o))})).then(e=>c(this,void 0,void 0,function*(){if(e){const r={index:e.index,texCoord:e.texCoord,extensions:e.extensions};s.occlusionTexture=r,n instanceof t.PBRBaseMaterial?r.strength=n._ambientTextureStrength:r.strength=n.ambientOcclusionTexture.level}})));const a=n instanceof t.PBRBaseMaterial?n._emissiveTexture:n.emissionColorTexture;a&&e.push(this.exportTextureAsync(a).then(e=>{e&&(s.emissiveTexture=e)})),e.length>0&&(this._exporter._materialNeedsUVsSet.add(n),yield Promise.all(e))}const o=n instanceof t.PBRBaseMaterial?n._emissiveColor:n.emissionColor;o.equalsWithEpsilon(m,d)||(s.emissiveFactor=o.asArray()),s.pbrMetallicRoughness=r})}exportOpenPBRMaterialAsync(e,t){return c(this,void 0,void 0,function*(){const n={},s={name:e.name},r=e.baseColor,i=e.geometryOpacity;r&&(n.baseColorFactor=[r.r,r.g,r.b,i]);const o=yield this._convertMetalRoughFactorsToMetallicRoughnessAsync(e.baseColor,e.baseMetalness,e.specularRoughness,e.baseColorTexture,e.baseMetalnessTexture,e.specularRoughnessTexture,e,n,t);yield this._setMetallicRoughnessPbrMaterialAsync(o,e,s,n,t),yield this._finishMaterialAsync(s,e);const a=this._exporter._materials;return a.push(s),a.length-1})}exportTextureAsync(e){return c(this,arguments,void 0,function*(e,t=null){let n=this._textureMap.get(null!=t?t:e.uniqueId);if(n)return n;const s=this._exportTextureSampler(e),r=yield this._exportTextureImageAsync(e);return n=this._exportTextureInfo(r,s,e.coordinatesIndex),this._textureMap.set(null!=t?t:e.uniqueId,n),this._exporter._extensionsPostExportTextures("exporter",n,e),n})}_exportTextureImageAsync(e){return c(this,void 0,void 0,function*(){var n;const s=null!==(n=e.mimeType)&&void 0!==n?n:"none",r=this._internalTextureToImage,i=e.getInternalTexture().uniqueId;r[i]=r[i]||{};let o=r[i][s];return void 0===o&&(o=(()=>c(this,void 0,void 0,function*(){const n=yield h(e);if(n&&g(n.mimeType)&&("none"===s||n.mimeType===s))return yield this._exportImageAsync(e.name,new Blob([n.data],{type:n.mimeType}));let r="image/png";"none"!==s&&(g(s)?r=s:(r="image/png",t.Tools.Warn(`Unsupported media type: ${s}. Exporting texture as PNG.`)));const i=e.getSize(),o=yield t.GetTextureDataAsync(e),a=yield t.EncodeImageAsync(o,i.width,i.height,r);return yield this._exportImageAsync(e.name,a)}))(),r[i][s]=o),yield o})}_exportImageAsync(e,n){return c(this,void 0,void 0,function*(){const s=this._exporter._images;let r;if(this._exporter._shouldUseGlb){r={name:e,mimeType:n.type,bufferView:void 0};const t=yield n.arrayBuffer(),s=this._exporter._bufferManager.createBufferView(new Uint8Array(t));this._exporter._bufferManager.setBufferView(r,s)}else{const i=e.replace(/\.\/|\/|\.\\|\\/g,"_"),o=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp";case"image/avif":return".avif";case"image/ktx2":return".ktx2"}}(n.type);let a=i+o;s.some(e=>e.uri===a)&&(a=`${i}_${t.Tools.RandomId()}${o}`),r={name:e,uri:a},this._exporter._imageData[a]=n}return s.push(r),s.length-1})}_exportTextureInfo(e,t,n){const s=this._exporter._textures;let r=s.findIndex(n=>n.sampler==t&&n.source===e);-1===r&&(r=s.length,s.push({source:e,sampler:t}));const i={index:r};return n&&(i.texCoord=n),i}_exportTextureSampler(e){const t=this._getTextureSampler(e),n=this._exporter._samplers,s=n.findIndex(e=>e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT);return-1!==s?s:(n.push(t),n.length-1)}}const M=t.Matrix.Compose(new t.Vector3(-1,1,1),t.Quaternion.Identity(),t.Vector3.Zero());function w(e,n){if(!(e instanceof t.TransformNode))return!1;if(n){if(!e.getWorldMatrix().equalsWithEpsilon(t.Matrix.IdentityReadOnly,t.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(M,t.TmpVectors.Matrix[0]).equalsWithEpsilon(t.Matrix.IdentityReadOnly,t.Epsilon))return!1;return!(e instanceof t.AbstractMesh&&e.geometry)}const R=t.Vector3.ZeroReadOnly,A=t.Quaternion.Identity(),C=t.Vector3.OneReadOnly,E=new t.Vector3(-1,1,1);function I(e,t){const{byteOffset:n,byteStride:s,type:r,normalized:i}=e,o=e.getSize(),a=t.reduce((e,t)=>t.getTotalVertices()>e?t.getTotalVertices():e,-Number.MAX_VALUE);return{byteOffset:n,byteStride:s,componentCount:o,type:r,count:a*o,normalized:i,totalVertices:a,kind:e.getKind()}}function S(e){switch(e){case"MAT2":case"VEC4":return 4;case"MAT3":return 9;case"MAT4":return 16;case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3}}function V(e){return e.some(e=>e>=256)}function F(e){switch(e){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:case t.VertexBuffer.ColorKind:case t.VertexBuffer.MatricesIndicesKind:case t.VertexBuffer.MatricesIndicesExtraKind:case t.VertexBuffer.MatricesWeightsKind:case t.VertexBuffer.MatricesWeightsExtraKind:case t.VertexBuffer.UVKind:case t.VertexBuffer.UV2Kind:case t.VertexBuffer.UV3Kind:case t.VertexBuffer.UV4Kind:case t.VertexBuffer.UV5Kind:case t.VertexBuffer.UV6Kind:return!0}return!1}function O(e){const t=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);t>0&&(e.x/=t,e.y/=t,e.z/=t)}function B(e){return e.x*=-1,e}function N(e){return M.invertToRef(t.TmpVectors.Matrix[0]).multiplyToRef(e,e).multiplyToRef(M,e),e}function P(e){if(e.x*e.x+e.y*e.y>.5){const t=Math.abs(e.x),n=Math.abs(e.y);if(t>n){const n=Math.sign(e.x);e.x=t,e.y*=-n,e.z*=-n,e.w*=n}else{const t=Math.sign(e.y);e.x*=-t,e.y=n,e.z*=t,e.w*=-t}}else{const t=Math.abs(e.z),n=Math.abs(e.w);if(t>n){const n=Math.sign(e.z);e.x*=-n,e.y*=n,e.z=t,e.w*=-n}else{const t=Math.sign(e.w);e.x*=t,e.y*=-t,e.z*=-t,e.w=n}}return e}function U(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function k(e,n){const s=t.Vector3.FromArrayToRef(n.translation||[0,0,0],0,t.TmpVectors.Vector3[0]),r=t.Quaternion.FromArrayToRef(n.rotation||[0,0,0,1],0,t.TmpVectors.Quaternion[0]),i=t.Matrix.ComposeToRef(C,r,s,t.TmpVectors.Matrix[0]),o=t.Vector3.FromArrayToRef(e.translation||[0,0,0],0,t.TmpVectors.Vector3[2]),a=t.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,t.TmpVectors.Quaternion[1]),l=t.Matrix.ComposeToRef(C,a,o,t.TmpVectors.Matrix[1]);i.multiplyToRef(l,l),l.decompose(void 0,r,s),s.equalsWithEpsilon(R,t.Epsilon)?delete n.translation:n.translation=s.asArray(),r.equalsWithEpsilon(A,t.Epsilon)?delete n.rotation:n.rotation=r.asArray(),n.scale&&delete n.scale}function K(e,n){if(!(n instanceof t.TransformNode))return!1;if(1!==n.getChildren().length||0!==e.getChildren().length||e.parent!==n)return!1;const s=e.getScene(),r=e instanceof t.TargetCamera&&!s.useRightHandedSystem?E:C;return!!n.scaling.equalsWithEpsilon(r,t.Epsilon)||(t.Logger.Warn(`Cannot collapse node ${e.name} into parent node ${n.name} with modified scaling.`),!1)}function $(e){if(e instanceof Array){const t=new Float32Array(e);return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}return ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e)}function z(e,t){for(const[n,s]of Object.entries(e)){const r=t[n];(Array.isArray(s)&&Array.isArray(r)&&W(s,r)||s===r)&&delete e[n]}return e}function W(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}const D=new Map([[Int8Array,(e,t,n)=>e.setInt8(t,n)],[Uint8Array,(e,t,n)=>e.setUint8(t,n)],[Uint8ClampedArray,(e,t,n)=>e.setUint8(t,n)],[Int16Array,(e,t,n)=>e.setInt16(t,n,!0)],[Uint16Array,(e,t,n)=>e.setUint16(t,n,!0)],[Int32Array,(e,t,n)=>e.setInt32(t,n,!0)],[Uint32Array,(e,t,n)=>e.setUint32(t,n,!0)],[Float32Array,(e,t,n)=>e.setFloat32(t,n,!0)],[Float64Array,(e,t,n)=>e.setFloat64(t,n,!0)]]);class L{writeTypedArray(e){this._checkGrowBuffer(e.byteLength);const t=D.get(e.constructor);for(let n=0;n<e.length;n++)t(this._dataView,this._byteOffset,e[n]),this._byteOffset+=e.BYTES_PER_ELEMENT}constructor(e){this._data=new Uint8Array(e),this._dataView=new DataView(this._data.buffer),this._byteOffset=0}get byteOffset(){return this._byteOffset}getOutputData(){return new Uint8Array(this._data.buffer,0,this._byteOffset)}writeUInt8(e){this._checkGrowBuffer(1),this._dataView.setUint8(this._byteOffset,e),this._byteOffset++}writeInt8(e){this._checkGrowBuffer(1),this._dataView.setInt8(this._byteOffset,e),this._byteOffset++}writeInt16(e){this._checkGrowBuffer(2),this._dataView.setInt16(this._byteOffset,e,!0),this._byteOffset+=2}writeUInt16(e){this._checkGrowBuffer(2),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2}writeInt32(e){this._checkGrowBuffer(4),this._dataView.setInt32(this._byteOffset,e,!0),this._byteOffset+=4}writeUInt32(e){this._checkGrowBuffer(4),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4}writeFloat32(e){this._checkGrowBuffer(4),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4}writeFloat64(e){this._checkGrowBuffer(8),this._dataView.setFloat64(this._byteOffset,e,!0),this._byteOffset+=8}_checkGrowBuffer(e){const t=this.byteOffset+e;if(t>this._data.byteLength){const e=new Uint8Array(2*t);e.set(this._data),this._data=e,this._dataView=new DataView(this._data.buffer)}}}function H(e){return e%4==0?4:e%2==0?2:1}class j{constructor(){this._bufferViewToData=new Map,this._bufferViewToProperties=new Map,this._accessorToBufferView=new Map}generateBinary(e){let t=0;this._bufferViewToData.forEach(e=>{t+=e.byteLength});const n=new L(t),s=Array.from(this._bufferViewToData.keys()).sort((e,t)=>H(t.byteLength)-H(e.byteLength));for(const t of s){t.byteOffset=n.byteOffset,e.push(t);const s=e.length-1,r=this.getPropertiesWithBufferView(t);for(const e of r)e.bufferView=s;n.writeTypedArray(this._bufferViewToData.get(t)),this._bufferViewToData.delete(t)}return n.getOutputData()}createBufferView(e,t){const n={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(n,e),n}createAccessor(e,t,n,s,r,i,o){this._verifyBufferView(e);const a={bufferView:void 0,componentType:n,count:s,type:t,min:null==i?void 0:i.min,max:null==i?void 0:i.max,normalized:o,byteOffset:r};return this.setBufferView(a,e),this._accessorToBufferView.set(a,e),a}setBufferView(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)}removeBufferView(e){const t=this.getPropertiesWithBufferView(e);for(const e of t)void 0!==e.bufferView&&delete e.bufferView;this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach((t,n)=>{t===e&&(void 0!==n.byteOffset&&delete n.byteOffset,this._accessorToBufferView.delete(n))})}getBufferView(e){const t=this._accessorToBufferView.get(e);return this._verifyBufferView(t),t}getPropertiesWithBufferView(e){var t;return this._verifyBufferView(e),this._bufferViewToProperties.set(e,null!==(t=this._bufferViewToProperties.get(e))&&void 0!==t?t:[]),this._bufferViewToProperties.get(e)}getData(e){return this._verifyBufferView(e),this._bufferViewToData.get(e)}_verifyBufferView(e){if(void 0===e||!this._bufferViewToData.has(e))throw new Error(`BufferView ${e} not found in BufferManager.`)}}var q;!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(q||(q={}));class G{static _IsTransformable(e){return e&&(e instanceof t.TransformNode||e instanceof t.Camera||e instanceof t.Light)}static _CreateNodeAnimation(e,n,s,r,i){if(this._IsTransformable(e)){const o=[],a=[],l=n.getKeys(),u=G._CalculateMinMaxKeyFrames(l),c=G._DeduceInterpolation(l,s,r),h=c.interpolationType,d=c.shouldBakeAnimation;if(d?G._CreateBakedAnimation(e,n,s,u.min,u.max,n.framePerSecond,i,o,a,u,r):"LINEAR"===h||"STEP"===h?G._CreateLinearOrStepAnimation(e,n,s,o,a,r):"CUBICSPLINE"===h?G._CreateCubicSplineAnimation(e,n,s,o,a,r):G._CreateBakedAnimation(e,n,s,u.min,u.max,n.framePerSecond,i,o,a,u,r),o.length&&a.length)return{inputs:o,outputs:a,samplerInterpolation:h,inputsMin:d?u.min:t.Tools.FloatRound(u.min/n.framePerSecond),inputsMax:d?u.max:t.Tools.FloatRound(u.max/n.framePerSecond)}}return null}static _DeduceAnimationInfo(e){let n=null,s="VEC3",r=!1;const i=e.targetProperty.split(".");switch(i[0]){case"scaling":n="scale";break;case"position":n="translation";break;case"rotation":s="VEC4",n="rotation";break;case"rotationQuaternion":s="VEC4",r=!0,n="rotation";break;case"influence":s="SCALAR",n="weights";break;default:t.Tools.Error(`Unsupported animatable property ${i[0]}`)}return n?{animationChannelTargetPath:n,dataAccessorType:s,useQuaternion:r}:(t.Tools.Error("animation channel target path and data accessor type could be deduced"),null)}static _CreateNodeAnimationFromNodeAnimations(e,t,n,s,r,i,o,a,l,u,c){let h;if(G._IsTransformable(e)&&e.animations)for(const r of e.animations){if(c&&!c(r))continue;const d=G._DeduceAnimationInfo(r);d&&(h={name:r.name,samplers:[],channels:[]},G._AddAnimation(`${r.name}`,r.hasRunningRuntimeAnimations?t:h,e,r,d.dataAccessorType,d.animationChannelTargetPath,s,i,o,a,d.useQuaternion,l,u),h.samplers.length&&h.channels.length&&n.push(h))}}static _CreateMorphTargetAnimationFromMorphTargetAnimations(e,n,s,r,i,o,a,l,u,c,h){let d;if(e instanceof t.Mesh){const i=e.morphTargetManager;if(i)for(let f=0;f<i.numTargets;++f){const p=i.getTarget(f);for(const m of p.animations){if(h&&!h(m))continue;const p=new t.Animation(`${m.name}`,"influence",m.framePerSecond,m.dataType,m.loopMode,m.enableBlending),g=[],x=m.getKeys();for(let e=0;e<x.length;++e){const t=x[e];for(let e=0;e<i.numTargets;++e)e==f?g.push(t):g.push({frame:t.frame,value:0})}p.setKeys(g,!0);const _=G._DeduceAnimationInfo(p);_&&(d={name:p.name,samplers:[],channels:[]},G._AddAnimation(m.name,m.hasRunningRuntimeAnimations?n:d,e,p,_.dataAccessorType,_.animationChannelTargetPath,r,o,a,l,_.useQuaternion,u,c,i.numTargets),d.samplers.length&&d.channels.length&&s.push(d))}}}}static _CreateNodeAndMorphAnimationFromAnimationGroups(e,n,s,r,i,o,a,l,u){var c;let h;if(e.animationGroups){const d=e.animationGroups;for(const f of d){const d=new Map,p=new Map,m=new Set,g=f.to-f.from;h={name:f.name,channels:[],samplers:[]};for(let n=0;n<f.targetedAnimations.length;++n){const g=f.targetedAnimations[n],x=g.target,_=g.animation;if(u&&!u(_))continue;const T=l.has(x);if(this._IsTransformable(x)||1===x.length&&this._IsTransformable(x[0])){const e=G._DeduceAnimationInfo(g.animation);if(e){const t=this._IsTransformable(x)?x:this._IsTransformable(x[0])?x[0]:null;t&&G._AddAnimation(`${_.name}`,h,t,_,e.dataAccessorType,e.animationChannelTargetPath,s,r,i,o,e.useQuaternion,a,T)}}else if((x instanceof t.MorphTarget||1===x.length&&x[0]instanceof t.MorphTarget)&&G._DeduceAnimationInfo(g.animation)){const n=x instanceof t.MorphTarget?x:x[0];if(n){const t=e.morphTargetManagers.find(e=>{for(let t=0;t<e.numTargets;++t)if(e.getTarget(t)===n)return!0;return!1});if(t){const s=e.meshes.find(e=>e.morphTargetManager===t);s&&(d.has(s)||d.set(s,new Map),null===(c=d.get(s))||void 0===c||c.set(n,_),m.add(s),p.set(s,_))}}}}m.forEach(e=>{const n=e.morphTargetManager;let l=null;const u=[],c=p.get(e).getKeys(),m=c.length;for(let s=0;s<m;++s)for(let r=0;r<n.numTargets;++r){const i=n.getTarget(r),o=d.get(e);if(o){const n=o.get(i);n?(l||(l=new t.Animation(`${f.name}_${e.name}_MorphWeightAnimation`,"influence",n.framePerSecond,t.Animation.ANIMATIONTYPE_FLOAT,n.loopMode,n.enableBlending)),u.push(n.getKeys()[s])):u.push({frame:f.from+g/m*s,value:i.influence,inTangent:c[0].inTangent?0:void 0,outTangent:c[0].outTangent?0:void 0})}}l.setKeys(u,!0);const x=G._DeduceAnimationInfo(l);x&&G._AddAnimation(`${f.name}_${e.name}_MorphWeightAnimation`,h,e,l,x.dataAccessorType,x.animationChannelTargetPath,s,r,i,o,x.useQuaternion,a,!1,null==n?void 0:n.numTargets)}),h.channels.length&&h.samplers.length&&n.push(h)}}}static _AddAnimation(e,n,s,r,i,o,a,l,u,c,h,d,f,p){const m=G._CreateNodeAnimation(s,r,o,h,d);let g,x,_,T,y,b;if(m){if(p){let e,t=0;const n=[];for(;m.inputs.length>0;)e=m.inputs.shift(),t%p==0&&n.push(e),t++;m.inputs=n}const e=a.get(s),r=new Float32Array(m.inputs);g=l.createBufferView(r),x=l.createAccessor(g,"SCALAR",5126,m.inputs.length,void 0,{min:[m.inputsMin],max:[m.inputsMax]}),c.push(x),_=c.length-1;const u=new t.Quaternion,h=new t.Vector3,d=new t.Vector3,v=s instanceof t.Camera,M=S(i),w=new Float32Array(m.outputs.length*M);m.outputs.forEach(function(e,n){let s=e;switch(o){case"translation":f&&(t.Vector3.FromArrayToRef(e,0,d),B(d),d.toArray(s));break;case"rotation":4===e.length?t.Quaternion.FromArrayToRef(e,0,u):(s=new Array(4),t.Vector3.FromArrayToRef(e,0,h),t.Quaternion.FromEulerVectorToRef(h,u)),f&&(P(u),v&&U(u)),u.toArray(s)}w.set(s,n*M)}),g=l.createBufferView(w),x=l.createAccessor(g,i,5126,m.outputs.length),c.push(x),T=c.length-1,y={interpolation:m.samplerInterpolation,input:_,output:T},n.samplers.push(y),b={sampler:n.samplers.length-1,target:{node:e,path:o}},n.channels.push(b)}}static _CreateBakedAnimation(e,n,s,r,i,o,a,l,u,c,h){let d;const f=t.Quaternion.Identity();let p,m,g,x,_,T=null,y=null;c.min=t.Tools.FloatRound(r/o);const b=n.getKeys();for(let r=0,c=b.length;r<c;++r){if(m=b[r],r+1<c)if(g=b[r+1],m.value.equals&&m.value.equals(g.value)||m.value===g.value){if(0!==r)continue;_=m.frame}else _=g.frame;else{if(x=b[r-1],m.value.equals&&m.value.equals(x.value)||m.value===x.value)continue;_=i}if(_)for(let r=m.frame;r<=_;r+=a){if(p=t.Tools.FloatRound(r/o),p===T)continue;T=p,y=p;const i={key:0,repeatCount:0,loopMode:n.loopMode};d=n._interpolate(r,i),G._SetInterpolatedValue(e,d,p,n,s,f,l,u,h)}}y&&(c.max=y)}static _ConvertFactorToVector3OrQuaternion(e,n,s,r,i){const o=G._GetBasePositionRotationOrScale(n,r,i),a=s.targetProperty.split("."),l=a?a[1]:"",u=i?t.Quaternion.FromArray(o).normalize():t.Vector3.FromArray(o);switch(l){case"x":case"y":case"z":u[l]=e;break;case"w":u.w=e;break;default:t.Tools.Error(`glTFAnimation: Unsupported component name "${l}"!`)}return u}static _SetInterpolatedValue(e,n,s,r,i,o,a,l,u){let c;a.push(s),"weights"!==i?(r.dataType===t.Animation.ANIMATIONTYPE_FLOAT&&(n=this._ConvertFactorToVector3OrQuaternion(n,e,r,i,u)),"rotation"===i?(u?o=n:(c=n,t.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,o)),l.push(o.asArray())):(c=n,l.push(c.asArray()))):l.push([n])}static _CreateLinearOrStepAnimation(e,t,n,s,r,i){for(const o of t.getKeys())s.push(o.frame/t.framePerSecond),G._AddKeyframeValue(o,t,r,n,e,i)}static _CreateCubicSplineAnimation(e,t,n,s,r,i){t.getKeys().forEach(function(o){s.push(o.frame/t.framePerSecond),G._AddSplineTangent(q.INTANGENT,r,n,"CUBICSPLINE",o,i),G._AddKeyframeValue(o,t,r,n,e,i),G._AddSplineTangent(q.OUTTANGENT,r,n,"CUBICSPLINE",o,i)})}static _GetBasePositionRotationOrScale(e,n,s){let r;if("rotation"===n)if(s){const n=e.rotationQuaternion;r=(null!=n?n:t.Quaternion.Identity()).asArray()}else{const n=e.rotation;r=(null!=n?n:t.Vector3.Zero()).asArray()}else if("translation"===n){const n=e.position;r=(null!=n?n:t.Vector3.Zero()).asArray()}else{const n=e.scaling;r=(null!=n?n:t.Vector3.One()).asArray()}return r}static _AddKeyframeValue(e,n,s,r,i,o){let a;const l=n.dataType;if(l===t.Animation.ANIMATIONTYPE_VECTOR3){let n=e.value.asArray();if("rotation"===r){const e=t.Vector3.FromArray(n);n=t.Quaternion.RotationYawPitchRoll(e.y,e.x,e.z).asArray()}s.push(n)}else if(l===t.Animation.ANIMATIONTYPE_FLOAT){if("weights"===r)s.push([e.value]);else if(a=this._ConvertFactorToVector3OrQuaternion(e.value,i,n,r,o),a){if("rotation"===r){const e=o?a:t.Quaternion.RotationYawPitchRoll(a.y,a.x,a.z).normalize();s.push(e.asArray())}s.push(a.asArray())}}else l===t.Animation.ANIMATIONTYPE_QUATERNION?s.push(e.value.normalize().asArray()):t.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")}static _DeduceInterpolation(e,t,n){let s,r,i=!1;if("rotation"===t&&!n)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(let t=0,n=e.length;t<n;++t)if(r=e[t],r.inTangent||r.outTangent)if(s){if("CUBICSPLINE"!==s){s="LINEAR",i=!0;break}}else s="CUBICSPLINE";else if(s){if("CUBICSPLINE"===s||r.interpolation&&1===r.interpolation&&"STEP"!==s){s="LINEAR",i=!0;break}}else s=r.interpolation&&1===r.interpolation?"STEP":"LINEAR";return s||(s="LINEAR"),{interpolationType:s,shouldBakeAnimation:i}}static _AddSplineTangent(e,n,s,r,i,o){let a;const l=e===q.INTANGENT?i.inTangent:i.outTangent;if("CUBICSPLINE"===r){if("rotation"===s)if(l)if(o)a=l.asArray();else{const e=l;a=t.Quaternion.RotationYawPitchRoll(e.y,e.x,e.z).asArray()}else a=[0,0,0,0];else a="weights"===s?l?[l]:[0]:l?l.asArray():[0,0,0];n.push(a)}}static _CalculateMinMaxKeyFrames(e){let t=1/0,n=-1/0;return e.forEach(function(e){t=Math.min(t,e.frame),n=Math.max(n,e.frame)}),{min:t,max:n}}}function X(e,n,s,r,i,o){const a={attributes:{},influence:e.influence,name:e.name},l=n.geometry;if(!l)return t.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),a;const u=o?-1:1,c=t.Vector3.Zero();let h,d;if(e.hasPositions){const r=e.getPositions(),o=l.getVerticesData(t.VertexBuffer.PositionKind);if(o){const e=new Float32Array(o.length),n=[1/0,1/0,1/0],l=[-1/0,-1/0,-1/0];d=o.length/3,h=0;for(let s=h;s<d;++s){const i=t.Vector3.FromArray(o,3*s);t.Vector3.FromArray(r,3*s).subtractToRef(i,c),c.x*=u,n[0]=Math.min(n[0],c.x),l[0]=Math.max(l[0],c.x),n[1]=Math.min(n[1],c.y),l[1]=Math.max(l[1],c.y),n[2]=Math.min(n[2],c.z),l[2]=Math.max(l[2],c.z),e[3*s]=c.x,e[3*s+1]=c.y,e[3*s+2]=c.z}const f=s.createBufferView(e,12),p=s.createAccessor(f,"VEC3",5126,r.length/3,0,{min:n,max:l});i.push(p),a.attributes.POSITION=i.length-1}else t.Tools.Warn(`Morph target positions for mesh ${n.name} were not exported. Mesh does not have position vertex data`)}if(e.hasNormals){const r=e.getNormals(),o=l.getVerticesData(t.VertexBuffer.NormalKind);if(o){const e=new Float32Array(o.length);d=o.length/3,h=0;for(let n=h;n<d;++n){const s=t.Vector3.FromArray(o,3*n).normalize();t.Vector3.FromArray(r,3*n).normalize().subtractToRef(s,c),e[3*n]=c.x*u,e[3*n+1]=c.y,e[3*n+2]=c.z}const n=s.createBufferView(e,12),l=s.createAccessor(n,"VEC3",5126,r.length/3,0);i.push(l),a.attributes.NORMAL=i.length-1}else t.Tools.Warn(`Morph target normals for mesh ${n.name} were not exported. Mesh does not have normals vertex data`)}if(e.hasTangents){const r=e.getTangents(),o=l.getVerticesData(t.VertexBuffer.TangentKind);if(o){d=o.length/4;const e=new Float32Array(3*d);h=0;for(let n=h;n<d;++n){const s=t.Vector3.FromArray(o,4*n);O(s);const i=t.Vector3.FromArray(r,3*n);O(i),i.subtractToRef(s,c),e[3*n]=c.x*u,e[3*n+1]=c.y,e[3*n+2]=c.z}const n=s.createBufferView(e,12),l=s.createAccessor(n,"VEC3",5126,d,0);i.push(l),a.attributes.TANGENT=i.length-1}else t.Tools.Warn(`Morph target tangents for mesh ${n.name} were not exported. Mesh does not have tangents vertex data`)}if(e.hasColors){const r=e.getColors(),o=l.getVerticesData(t.VertexBuffer.ColorKind),u=l.getVertexBuffer(t.VertexBuffer.ColorKind);if(o&&u){const e=u.getSize();d=o.length/e;const n=new Float32Array(d*e);h=0;for(let s=h;s<d;++s)if(3===e){const i=t.Vector3.FromArray(o,s*e);t.Vector3.FromArray(r,s*e).subtractToRef(i,c),n[3*s]=c.x,n[3*s+1]=c.y,n[3*s+2]=c.z}else if(4===e){const i=new t.Vector4,a=t.Vector4.FromArray(o,s*e);t.Vector4.FromArray(r,s*e).subtractToRef(a,i),n[4*s]=i.x,n[4*s+1]=i.y,n[4*s+2]=i.z,n[4*s+3]=i.w}else t.Tools.Warn(`Unsupported number of components for color attribute: ${e}`);const l=s.createBufferView(n,4*e),f=s.createAccessor(l,3===e?"VEC3":"VEC4",5126,d,0);i.push(f),a.attributes.COLOR_0=i.length-1}else t.Tools.Warn(`Morph target colors for mesh ${n.name} were not exported. Mesh does not have colors vertex data`)}return a}class Q{constructor(e,t){this._indicesAccessorMap=new Map,this._vertexBufferViewMap=new Map,this._vertexAccessorMap=new Map,this._remappedBufferView=new Map,this._meshMorphTargetMap=new Map,this._vertexMapColorAlpha=new Map,this._exportedNodes=new Set,this._meshMap=new Map,this.convertedToRightHandedBuffers=new Map,this.convertToRightHanded=e,this.wasAddedByNoopNode=t}getIndicesAccessor(e,t,n,s,r){var i,o,a,l;return null===(l=null===(a=null===(o=null===(i=this._indicesAccessorMap.get(e))||void 0===i?void 0:i.get(t))||void 0===o?void 0:o.get(n))||void 0===a?void 0:a.get(s))||void 0===l?void 0:l.get(r)}setIndicesAccessor(e,t,n,s,r,i){let o=this._indicesAccessorMap.get(e);o||(o=new Map,this._indicesAccessorMap.set(e,o));let a=o.get(t);a||(a=new Map,o.set(t,a));let l=a.get(n);l||(l=new Map,a.set(n,l));let u=l.get(s);u||(u=new Map,l.set(s,u)),u.set(r,i)}pushExportedNode(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)}getNodesSet(){return this._exportedNodes}getVertexBufferView(e){return this._vertexBufferViewMap.get(e)}setVertexBufferView(e,t){this._vertexBufferViewMap.set(e,t)}setRemappedBufferView(e,t,n){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,n)}getRemappedBufferView(e,t){var n;return null===(n=this._remappedBufferView.get(e))||void 0===n?void 0:n.get(t)}getVertexAccessor(e,t,n){var s,r;return null===(r=null===(s=this._vertexAccessorMap.get(e))||void 0===s?void 0:s.get(t))||void 0===r?void 0:r.get(n)}setVertexAccessor(e,t,n,s){let r=this._vertexAccessorMap.get(e);r||(r=new Map,this._vertexAccessorMap.set(e,r));let i=r.get(t);i||(i=new Map,r.set(t,i)),i.set(n,s)}hasVertexColorAlpha(e){return this._vertexMapColorAlpha.get(e)||!1}setHasVertexColorAlpha(e,t){return this._vertexMapColorAlpha.set(e,t)}getMesh(e){return this._meshMap.get(e)}setMesh(e,t){this._meshMap.set(e,t)}bindMorphDataToMesh(e,t){const n=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,n),-1===n.indexOf(t)&&n.push(t)}getMorphTargetsFromMesh(e){return this._meshMorphTargetMap.get(e)}}class Z{_ApplyExtension(e,t,n,s){if(n>=t.length)return Promise.resolve(e);const r=s(t[n],e);return r?r.then(e=>c(this,void 0,void 0,function*(){return e?yield this._ApplyExtension(e,t,n+1,s):null})):this._ApplyExtension(e,t,n+1,s)}_ApplyExtensions(e,t){const n=[];for(const e of Z._ExtensionNames)n.push(this._extensions[e]);return this._ApplyExtension(e,n,0,t)}_extensionsPostExportNodeAsync(e,t,n,s,r){return this._ApplyExtensions(t,(t,i)=>t.postExportNodeAsync&&t.postExportNodeAsync(e,i,n,s,r,this._bufferManager))}_extensionsPostExportMaterialAsync(e,t,n){return this._ApplyExtensions(t,(t,s)=>t.postExportMaterialAsync&&t.postExportMaterialAsync(e,s,n))}_extensionsPostExportMaterialAdditionalTexturesAsync(e,t,n){return c(this,void 0,void 0,function*(){const s=[];return yield Promise.all(Z._ExtensionNames.map(r=>c(this,void 0,void 0,function*(){const i=this._extensions[r];if(i.postExportMaterialAdditionalTexturesAsync){const r=yield i.postExportMaterialAdditionalTexturesAsync(e,t,n);s.push(...r)}}))),s})}_extensionsPostExportTextures(e,t,n){for(const s of Z._ExtensionNames){const r=this._extensions[s];r.postExportTexture&&r.postExportTexture(e,t,n)}}_extensionsPostExportMeshPrimitive(e){for(const t of Z._ExtensionNames){const n=this._extensions[t];n.postExportMeshPrimitive&&n.postExportMeshPrimitive(e,this._bufferManager,this._accessors)}}_extensionsPreGenerateBinaryAsync(){return c(this,void 0,void 0,function*(){for(const e of Z._ExtensionNames){const t=this._extensions[e];t.preGenerateBinaryAsync&&(yield t.preGenerateBinaryAsync(this._bufferManager))}})}_forEachExtensions(e){for(const t of Z._ExtensionNames){const n=this._extensions[t];n.enabled&&e(n)}}_extensionsOnExporting(){this._forEachExtensions(e=>{var t,n,s;e.wasUsed&&((t=this._glTF).extensionsUsed||(t.extensionsUsed=[]),-1===this._glTF.extensionsUsed.indexOf(e.name)&&this._glTF.extensionsUsed.push(e.name),e.required&&((n=this._glTF).extensionsRequired||(n.extensionsRequired=[]),-1===this._glTF.extensionsRequired.indexOf(e.name)&&this._glTF.extensionsRequired.push(e.name)),(s=this._glTF).extensions||(s.extensions={}),e.onExporting&&e.onExporting())})}_loadExtensions(){for(const e of Z._ExtensionNames){const t=Z._ExtensionFactories[e](this);this._extensions[e]=t}}constructor(e=t.EngineStore.LastCreatedScene,n){if(this._glTF={asset:{generator:`Babylon.js v${t.Engine.Version}`,version:"2.0"}},this._animations=[],this._accessors=[],this._bufferViews=[],this._cameras=[],this._images=[],this._materials=[],this._meshes=[],this._nodes=[],this._samplers=[],this._scenes=[],this._skins=[],this._textures=[],this._imageData={},this._shouldUseGlb=!1,this._materialExporter=new v(this),this._extensions={},this._bufferManager=new j,this._shouldExportNodeMap=new Map,this._nodeMap=new Map,this._materialMap=new Map,this._camerasMap=new Map,this._nodesCameraMap=new Map,this._skinMap=new Map,this._nodesSkinMap=new Map,this._materialNeedsUVsSet=new Set,!e)throw new Error("No scene available to export");this._babylonScene=e,this._options=Object.assign({shouldExportNode:()=>!0,shouldExportAnimation:()=>!0,metadataSelector:e=>{var t;return null===(t=null==e?void 0:e.gltf)||void 0===t?void 0:t.extras},animationSampleRate:1/60,exportWithoutWaitingForScene:!1,exportUnusedUVs:!1,removeNoopRootNodes:!0,includeCoordinateSystemConversionNodes:!1,meshCompressionMethod:"None"},n),this._loadExtensions()}dispose(){for(const e in this._extensions)this._extensions[e].dispose()}get options(){return this._options}static RegisterExtension(e,n,s=100){Z.UnregisterExtension(e)&&t.Tools.Warn(`Extension with the name ${e} already exists`),Z._ExtensionFactories[e]=n;const r=null!=s?s:0;Z._ExtensionOrders[e]=r;let i=Z._ExtensionNames.length;for(let e=0;e<Z._ExtensionNames.length;e++){const t=Z._ExtensionNames[e];if(r<Z._ExtensionOrders[t]){i=e;break}}Z._ExtensionNames.splice(i,0,e)}static UnregisterExtension(e){if(!Z._ExtensionFactories[e])return!1;delete Z._ExtensionFactories[e],delete Z._ExtensionOrders[e];const t=Z._ExtensionNames.indexOf(e);return-1!==t&&Z._ExtensionNames.splice(t,1),!0}_generateJSON(e,t,n){const s={byteLength:e};return s.byteLength&&(this._glTF.buffers=[s]),this._nodes&&this._nodes.length&&(this._glTF.nodes=this._nodes),this._meshes&&this._meshes.length&&(this._glTF.meshes=this._meshes),this._scenes&&this._scenes.length&&(this._glTF.scenes=this._scenes,this._glTF.scene=0),this._cameras&&this._cameras.length&&(this._glTF.cameras=this._cameras),this._bufferViews&&this._bufferViews.length&&(this._glTF.bufferViews=this._bufferViews),this._accessors&&this._accessors.length&&(this._glTF.accessors=this._accessors),this._animations&&this._animations.length&&(this._glTF.animations=this._animations),this._materials&&this._materials.length&&(this._glTF.materials=this._materials),this._textures&&this._textures.length&&(this._glTF.textures=this._textures),this._samplers&&this._samplers.length&&(this._glTF.samplers=this._samplers),this._skins&&this._skins.length&&(this._glTF.skins=this._skins),this._images&&this._images.length&&(this._glTF.images=this._images),this._shouldUseGlb||(s.uri=t+".bin"),n?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)}generateGLTFAsync(e){return c(this,void 0,void 0,function*(){const t=yield this._generateBinaryAsync();this._extensionsOnExporting();const n=this._generateJSON(t.byteLength,e,!0),s=new Blob([t],{type:"application/octet-stream"}),r=e+".gltf",o=e+".bin",a=new i;if(a.files[r]=n,a.files[o]=s,this._imageData)for(const e in this._imageData)a.files[e]=this._imageData[e];return a})}_generateBinaryAsync(){return c(this,void 0,void 0,function*(){return yield this._exportSceneAsync(),yield this._extensionsPreGenerateBinaryAsync(),this._bufferManager.generateBinary(this._bufferViews)})}_getPadding(e){const t=e%4;return 0===t?t:4-t}generateGLBAsync(e){return c(this,void 0,void 0,function*(){this._shouldUseGlb=!0;const t=yield this._generateBinaryAsync();this._extensionsOnExporting();const n=this._generateJSON(t.byteLength),s=e+".glb";let r,o=n.length;"undefined"!=typeof TextEncoder&&(r=(new TextEncoder).encode(n),o=r.length);const a=this._getPadding(o),l=this._getPadding(t.byteLength),u=28+o+a+t.byteLength+l,c=new L(u);if(c.writeUInt32(1179937895),c.writeUInt32(2),c.writeUInt32(u),c.writeUInt32(o+a),c.writeUInt32(1313821514),r)c.writeTypedArray(r);else{const e="_".charCodeAt(0);for(let t=0;t<o;++t){const s=n.charCodeAt(t);s!=n.codePointAt(t)?c.writeUInt8(e):c.writeUInt8(s)}}for(let e=0;e<a;++e)c.writeUInt8(32);c.writeUInt32(t.byteLength+l),c.writeUInt32(5130562),c.writeTypedArray(t);for(let e=0;e<l;++e)c.writeUInt8(0);const h=new i;return h.files[s]=new Blob([c.getOutputData()],{type:"application/octet-stream"}),h})}_setNodeTransformation(e,n,s){var r;if(n.getPivotPoint().equalsWithEpsilon(R,t.Epsilon)||t.Tools.Warn("Pivot points are not supported in the glTF serializer"),!n.position.equalsWithEpsilon(R,t.Epsilon)){const r=t.TmpVectors.Vector3[0].copyFrom(n.position);s&&B(r),e.translation=r.asArray()}n.scaling.equalsWithEpsilon(C,t.Epsilon)||(e.scale=n.scaling.asArray());const i=(null===(r=n.rotationQuaternion)||void 0===r?void 0:r.clone())||t.Quaternion.FromEulerAngles(n.rotation.x,n.rotation.y,n.rotation.z);i.equalsWithEpsilon(A,t.Epsilon)||(s&&P(i),e.rotation=i.normalize().asArray())}_setCameraTransformation(e,n,s){const r=t.TmpVectors.Vector3[0],i=t.TmpVectors.Quaternion[0],o=n.getWorldMatrix();if(n.parent){const e=n.parent.getWorldMatrix().invertToRef(t.TmpVectors.Matrix[0]);o.multiplyToRef(e,t.TmpVectors.Matrix[1]).decompose(void 0,i,r)}else o.decompose(void 0,i,r);r.equalsWithEpsilon(R,t.Epsilon)||(s&&B(r),e.translation=r.asArray()),s&&P(i),this._babylonScene.useRightHandedSystem||U(i),i.equalsWithEpsilon(A,t.Epsilon)||(e.rotation=i.asArray())}_listAvailableCameras(){for(const e of this._babylonScene.cameras){const n={type:e.mode===t.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(e.name&&(n.name=e.name),"perspective"===n.type)n.perspective={aspectRatio:e.getEngine().getAspectRatio(e),yfov:e.fovMode===t.Camera.FOVMODE_VERTICAL_FIXED?e.fov:e.fov*e.getEngine().getAspectRatio(e),znear:e.minZ,zfar:e.maxZ};else if("orthographic"===n.type){const t=e.orthoLeft&&e.orthoRight?.5*(e.orthoRight-e.orthoLeft):.5*e.getEngine().getRenderWidth(),s=e.orthoBottom&&e.orthoTop?.5*(e.orthoTop-e.orthoBottom):.5*e.getEngine().getRenderHeight();n.orthographic={xmag:t,ymag:s,znear:e.minZ,zfar:e.maxZ}}this._camerasMap.set(e,n)}}_exportAndAssignCameras(){const e=Array.from(this._camerasMap.values());for(const t of e){const e=this._nodesCameraMap.get(t);if(void 0!==e){this._cameras.push(t);for(const t of e)t.camera=this._cameras.length-1}}}_listAvailableSkeletons(){for(const e of this._babylonScene.skeletons){if(e.bones.length<=0)continue;const t={joints:[]};this._skinMap.set(e,t)}}_exportAndAssignSkeletons(e){var n;for(const s of this._babylonScene.skeletons){if(s.bones.length<=0)continue;const r=this._skinMap.get(s);if(null==r)continue;const i={};let o=-1;for(let e=0;e<s.bones.length;++e){const t=s.bones[e],r=null!==(n=t.getIndex())&&void 0!==n?n:e;-1!==r&&(i[r]=t,r>o&&(o=r))}const a=[];for(let n=0;n<=o;++n){const s=i[n],o=s.getTransformNode(),l=o?this._nodeMap.get(o):void 0;if(void 0===l){t.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.");continue}r.joints.push(l);const u=s.getAbsoluteInverseBindMatrix().clone();e.has(o)&&N(u),a.push(u)}const l=this._nodesSkinMap.get(r);if(r.joints.length>0&&void 0!==l){const e=new Float32Array(16*a.length);a.forEach((t,n)=>{e.set(t.m,16*n)});const t=this._bufferManager.createBufferView(e);this._accessors.push(this._bufferManager.createAccessor(t,"MAT4",5126,a.length)),r.inverseBindMatrices=this._accessors.length-1,this._skins.push(r);const n=this._skins.length-1;for(const e of l)e.skin=n}}}_exportSceneAsync(){return c(this,void 0,void 0,function*(){const e={nodes:[]};if(this._babylonScene.metadata){const t=this._options.metadataSelector(this._babylonScene.metadata);t&&(e.extras=t)}const n=new Array,s=new Array,r=new Array;let i;if(this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes)for(const e of this._babylonScene.animationGroups)for(const n of e.targetedAnimations){const e=n.target;e instanceof t.TransformNode&&!e.parent&&(null!=i?i:i=new Set).add(e)}for(const e of this._babylonScene.rootNodes){const t=e.animations,o=!!t&&t.length>0||(null==i?void 0:i.has(e));this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&w(e,this._babylonScene.useRightHandedSystem)&&!o?r.push(...e.getChildren()):this._babylonScene.useRightHandedSystem?n.push(e):s.push(e)}this._listAvailableCameras(),this._listAvailableSkeletons();const o=new Q(!0,!1);e.nodes.push(...yield this._exportNodesAsync(s,o));const a=new Q(!1,!1);e.nodes.push(...yield this._exportNodesAsync(n,a));const l=new Q(!1,!0);e.nodes.push(...yield this._exportNodesAsync(r,l)),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(o.getNodesSet()),this._babylonScene.animationGroups.length&&G._CreateNodeAndMorphAnimationFromAnimationGroups(this._babylonScene,this._animations,this._nodeMap,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,o.getNodesSet(),this._options.shouldExportAnimation)})}_shouldExportNode(e){let t=this._shouldExportNodeMap.get(e);return void 0===t&&(t=this._options.shouldExportNode(e),this._shouldExportNodeMap.set(e,t)),t}_exportNodesAsync(e,t){return c(this,void 0,void 0,function*(){const n=new Array;this._exportBuffers(e,t);for(const s of e)yield this._exportNodeAsync(s,n,t);return n})}_collectBuffers(e,n,s,r,i){if(this._shouldExportNode(e)&&e instanceof t.AbstractMesh&&e.geometry){const t=e.geometry.getVertexBuffers();if(t)for(const r in t){if(!F(r))continue;const o=t[r];i.setHasVertexColorAlpha(o,e.hasVertexAlpha);const a=o._buffer,l=n.get(a)||[];n.set(a,l),-1===l.indexOf(o)&&l.push(o);const u=s.get(o)||[];s.set(o,u),-1===u.indexOf(e)&&u.push(e)}const o=e.morphTargetManager;if(o)for(let t=0;t<o.numTargets;t++){const n=o.getTarget(t),s=r.get(n)||[];r.set(n,s),-1===s.indexOf(e)&&s.push(e)}}for(const t of e.getChildren())this._collectBuffers(t,n,s,r,i)}_exportBuffers(e,n){const s=new Map,r=new Map,i=new Map;for(const t of e)this._collectBuffers(t,s,r,i,n);const o=Array.from(s.keys());for(const e of o){const i=e.getData();if(!i)throw new Error("Buffer data is not available");const o=s.get(e);if(!o)continue;const a=o[0].byteStride;if(o.some(e=>e.byteStride!==a))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");const l=$(i).slice();for(const e of o){const n=r.get(e),{byteOffset:s,byteStride:i,componentCount:o,type:a,count:u,normalized:c,kind:h}=I(e,n);switch(h){case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:t.EnumerateFloatValues(l,s,i,o,a,u,c,e=>{const t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){const n=1/t;e[0]*=n,e[1]*=n,e[2]*=n}});break;case t.VertexBuffer.ColorKind:{const e=n.filter(e=>e.material instanceof t.StandardMaterial||null==e.material).length;if(0==e)break;if(e!=n.length){t.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}a==t.VertexBuffer.UNSIGNED_BYTE&&t.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");const r=new t.Color3,h=new t.Color4,d=this._babylonScene.getEngine().useExactSrgbConversions;t.EnumerateFloatValues(l,s,i,o,a,u,c,e=>{3===e.length?(r.fromArray(e,0),r.toLinearSpaceToRef(r,d),r.toArray(e,0)):(h.fromArray(e,0),h.toLinearSpaceToRef(h,d),h.toArray(e,0))})}}}if(n.convertToRightHanded){for(const e of o){const n=r.get(e),{byteOffset:s,byteStride:i,componentCount:o,type:a,count:u,normalized:c,kind:h}=I(e,n);switch(h){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:t.EnumerateFloatValues(l,s,i,o,a,u,c,e=>{e[0]=-e[0]})}}n.convertedToRightHandedBuffers.set(e,l)}const u=this._bufferManager.createBufferView(l,a);n.setVertexBufferView(e,u);const c=new Map;for(const e of o){const n=r.get(e),{kind:s,totalVertices:i}=I(e,n);switch(s){case t.VertexBuffer.MatricesIndicesKind:case t.VertexBuffer.MatricesIndicesExtraKind:if(e.type==t.VertexBuffer.FLOAT){const t=e.getFloatData(i);null!==t&&c.set(e,t)}}}0!==c.size&&t.Logger.Warn("Joint indices conversion needed: some joint indices are stored as floats in Babylon but GLTF requires UNSIGNED BYTES. We will perform the conversion but this might lead to unused data in the buffer.");const h=Array.from(c.keys());for(const t of h){const s=c.get(t);if(!s)continue;const r=V(s),i=new(r?Uint16Array:Uint8Array)(s.length);for(let e=0;e<s.length;e++)i[e]=s[e];const o=this._bufferManager.createBufferView(i,4*(r?2:1));n.setRemappedBufferView(e,t,o)}}const a=Array.from(i.keys());for(const e of a){const t=i.get(e);if(!t)continue;const s=X(e,t[0],this._bufferManager,this._bufferViews,this._accessors,n.convertToRightHanded);for(const e of t)n.bindMorphDataToMesh(e,s)}}_exportNodeAsync(e,t,n){return c(this,void 0,void 0,function*(){let s=this._nodeMap.get(e);if(void 0!==s)return void(t.includes(s)||t.push(s));const r=yield this._createNodeAsync(e,n);if(r){s=this._nodes.length,this._nodes.push(r),this._nodeMap.set(e,s),n.pushExportedNode(e),t.push(s);const i={name:"runtime animations",channels:[],samplers:[]},o=[];this._babylonScene.animationGroups.length||(G._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,o,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&G._CreateNodeAnimationFromNodeAnimations(e,i,o,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation)),i.channels.length&&i.samplers.length&&this._animations.push(i),o.forEach(e=>{e.channels.length&&e.samplers.length&&this._animations.push(e)})}const i=r?[]:t;for(const t of e.getChildren())yield this._exportNodeAsync(t,i,n);r&&i.length&&(r.children=i)})}_createNodeAsync(e,n){return c(this,void 0,void 0,function*(){var s,r,i;if(!this._shouldExportNode(e))return null;const o={};if(e.name&&(o.name=e.name),e.metadata){const t=this._options.metadataSelector(e.metadata);t&&(o.extras=t)}if(e instanceof t.TransformNode&&(this._setNodeTransformation(o,e,n.convertToRightHanded),e instanceof t.AbstractMesh)){const r=e instanceof t.InstancedMesh?e.sourceMesh:e;if(r.subMeshes&&r.subMeshes.length>0&&(o.mesh=yield this._exportMeshAsync(r,n)),e.skeleton){const t=this._skinMap.get(e.skeleton);void 0!==t&&(void 0===this._nodesSkinMap.get(t)&&this._nodesSkinMap.set(t,[]),null===(s=this._nodesSkinMap.get(t))||void 0===s||s.push(o))}}if(e instanceof t.TargetCamera){const t=this._camerasMap.get(e);if(t){void 0===this._nodesCameraMap.get(t)&&this._nodesCameraMap.set(t,[]),this._setCameraTransformation(o,e,n.convertToRightHanded);const s=e.parent;if(null!==s&&K(e,s)){const e=this._nodeMap.get(s);if(void 0!==e){const n=this._nodes[e];return k(o,n),null===(r=this._nodesCameraMap.get(t))||void 0===r||r.push(n),null}}null===(i=this._nodesCameraMap.get(t))||void 0===i||i.push(o)}}return(yield this._extensionsPostExportNodeAsync("exportNodeAsync",o,e,this._nodeMap,n.convertToRightHanded))?o:(t.Logger.Warn(`Not exporting node ${e.name}`),null)})}_exportIndices(e,n,s,r,i,o,a,l,u){let c=null;u.mode=function(e){switch(e){case t.Material.TriangleFillMode:return 4;case t.Material.TriangleStripDrawMode:return 5;case t.Material.TriangleFanDrawMode:return 6;case t.Material.PointListDrawMode:case t.Material.PointFillMode:return 0;case t.Material.LineLoopDrawMode:return 2;case t.Material.LineListDrawMode:return 1;case t.Material.LineStripDrawMode:return 3}throw new Error(`Unknown fill mode: ${e}`)}(o);const h=a!==t.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case t.Material.TriangleFillMode:case t.Material.TriangleStripDrawMode:case t.Material.TriangleFanDrawMode:return!0}return!1}(o);if(h){if(o===t.Material.TriangleStripDrawMode||o===t.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");const a=n?new Uint32Array(r):new Uint16Array(r);if(e)for(let t=0;t+2<r;t+=3)a[t]=e[s+t]+i,a[t+1]=e[s+t+2]+i,a[t+2]=e[s+t+1]+i;else for(let e=0;e+2<r;e+=3)a[e]=e,a[e+1]=e+2,a[e+2]=e+1;c=a}else if(e&&0!==i){const t=n?new Uint32Array(r):new Uint16Array(r);for(let n=0;n<r;n++)t[n]=e[s+n]+i;c=t}else e&&(c=function(e,t,n,s){let r=e;return 0===t&&n===e.length||(r=Array.isArray(e)?e.slice(t,t+n):e.subarray(t,t+n)),r instanceof Int32Array?new Uint32Array(r.buffer,r.byteOffset,r.length):Array.isArray(r)?s?new Uint32Array(r):new Uint16Array(r):r}(e,s,r,n));if(c){let t=l.getIndicesAccessor(e,s,r,i,h);if(void 0===t){const o=this._bufferManager.createBufferView(c),a=n?5125:5123;this._accessors.push(this._bufferManager.createAccessor(o,"SCALAR",a,r,0)),t=this._accessors.length-1,l.setIndicesAccessor(e,s,r,i,h,t)}u.indices=t}}_exportVertexBuffer(e,n,s,r,i,o){const a=e.getKind();if(!F(a))return;if(a.startsWith("uv")&&!this._options.exportUnusedUVs&&(!n||!this._materialNeedsUVsSet.has(n)))return;let l=i.getVertexAccessor(e,s,r);if(void 0===l){const n=i.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),o=a===t.VertexBuffer.PositionKind?function(e,n,s,r){const{byteOffset:i,byteStride:o,type:a,normalized:l}=n,u=n.getSize(),c=new Array(u).fill(1/0),h=new Array(u).fill(-1/0);return t.EnumerateFloatValues(e,i+s*o,o,u,a,r*u,l,e=>{for(let t=0;t<u;t++)c[t]=Math.min(c[t],e[t]),h[t]=Math.max(h[t],e[t])}),{min:c,max:h}}(n,e,s,r):void 0,u=(a===t.VertexBuffer.MatricesIndicesKind||a===t.VertexBuffer.MatricesIndicesExtraKind)&&e.type===t.VertexBuffer.FLOAT,c=u?t.VertexBuffer.UNSIGNED_BYTE:e.type,h=u?void 0:e.normalized,d=u?i.getRemappedBufferView(e._buffer,e):i.getVertexBufferView(e._buffer),f=e.byteOffset+s*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(d,function(e,n){if(e==t.VertexBuffer.ColorKind)return n?"VEC4":"VEC3";switch(e){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:return"VEC3";case t.VertexBuffer.TangentKind:case t.VertexBuffer.MatricesIndicesKind:case t.VertexBuffer.MatricesIndicesExtraKind:case t.VertexBuffer.MatricesWeightsKind:case t.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case t.VertexBuffer.UVKind:case t.VertexBuffer.UV2Kind:case t.VertexBuffer.UV3Kind:case t.VertexBuffer.UV4Kind:case t.VertexBuffer.UV5Kind:case t.VertexBuffer.UV6Kind:return"VEC2"}throw new Error(`Unknown kind ${e}`)}(a,i.hasVertexColorAlpha(e)),c,r,f,o,h)),l=this._accessors.length-1,i.setVertexAccessor(e,s,r,l)}o.attributes[function(e){switch(e){case t.VertexBuffer.PositionKind:return"POSITION";case t.VertexBuffer.NormalKind:return"NORMAL";case t.VertexBuffer.TangentKind:return"TANGENT";case t.VertexBuffer.ColorKind:return"COLOR_0";case t.VertexBuffer.UVKind:return"TEXCOORD_0";case t.VertexBuffer.UV2Kind:return"TEXCOORD_1";case t.VertexBuffer.UV3Kind:return"TEXCOORD_2";case t.VertexBuffer.UV4Kind:return"TEXCOORD_3";case t.VertexBuffer.UV5Kind:return"TEXCOORD_4";case t.VertexBuffer.UV6Kind:return"TEXCOORD_5";case t.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case t.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case t.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case t.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error(`Unknown kind: ${e}`)}(a)]=l}_exportMaterialAsync(e,n,s,r){return c(this,void 0,void 0,function*(){let i=this._materialMap.get(e);if(void 0===i){const r=n&&Object.keys(n).some(e=>e.startsWith("uv"));if((e=e instanceof t.MultiMaterial?e.subMaterials[s.materialIndex]:e)instanceof t.PBRBaseMaterial)i=yield this._materialExporter.exportPBRMaterialAsync(e,r);else if(e instanceof t.StandardMaterial)i=yield this._materialExporter.exportStandardMaterialAsync(e,r);else{if(!(e instanceof t.OpenPBRMaterial))return void t.Logger.Warn(`Unsupported material '${e.name}' with type ${e.getClassName()}`);i=yield this._materialExporter.exportOpenPBRMaterialAsync(e,r)}this._materialMap.set(e,i)}r.material=i})}_exportMeshAsync(e,n){return c(this,void 0,void 0,function*(){var s,r,i,o,a,l;let u=n.getMesh(e);if(void 0!==u)return u;const c={primitives:[]};u=this._meshes.length,this._meshes.push(c),n.setMesh(e,u);const h=e.isUnIndexed?null:e.getIndices(),d=null===(s=e.geometry)||void 0===s?void 0:s.getVertexBuffers(),f=n.getMorphTargetsFromMesh(e),p=e instanceof t.LinesMesh,m=e instanceof t.GreasedLineBaseMesh,g=e.subMeshes;if(d&&g&&g.length>0)for(const s of g){const u={attributes:{}},g=s.getMaterial()||this._babylonScene.defaultMaterial;if(m){const n={name:g.name},s=e,l=t.Color3.White(),c=null!==(i=null===(r=s.material)||void 0===r?void 0:r.alpha)&&void 0!==i?i:1,h=null!==(a=null===(o=s.greasedLineMaterial)||void 0===o?void 0:o.color)&&void 0!==a?a:l;(!h.equalsWithEpsilon(l,t.Epsilon)||c<1)&&(n.pbrMetallicRoughness={baseColorFactor:[...h.asArray(),c]}),this._materials.push(n),u.material=this._materials.length-1}else if(p){const n={name:g.name},s=e;(!s.color.equalsWithEpsilon(t.Color3.White(),t.Epsilon)||s.alpha<1)&&(n.pbrMetallicRoughness={baseColorFactor:[...s.color.asArray(),s.alpha]}),this._materials.push(n),u.material=this._materials.length-1}else yield this._exportMaterialAsync(g,d,s,u);const x=p||m?t.Material.LineListDrawMode:null!==(l=e.overrideRenderingFillMode)&&void 0!==l?l:g.fillMode;let _=g._getEffectiveOrientation(e);n.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(_=_===t.Material.ClockWiseSideOrientation?t.Material.CounterClockWiseSideOrientation:t.Material.ClockWiseSideOrientation),this._exportIndices(h,h?t.AreIndices32Bits(h,s.indexCount,s.indexStart,s.verticesStart):s.verticesCount>65535,h?s.indexStart:s.verticesStart,h?s.indexCount:s.verticesCount,-s.verticesStart,x,_,n,u);for(const e of Object.values(d))this._exportVertexBuffer(e,g,s.verticesStart,s.verticesCount,n,u);if(f){u.targets=[];for(const e of f)u.targets.push(e.attributes)}c.primitives.push(u),this._extensionsPostExportMeshPrimitive(u)}if(f){c.weights=[],c.extras||(c.extras={}),c.extras.targetNames=[];for(const e of f)c.weights.push(e.influence),c.extras.targetNames.push(e.name)}return u})}}Z._ExtensionNames=new Array,Z._ExtensionFactories={},Z._ExtensionOrders={};class Y{static GLTFAsync(e,t,n){return c(this,void 0,void 0,function*(){n&&n.exportWithoutWaitingForScene||(yield e.whenReadyAsync());const s=new Z(e,n),r=yield s.generateGLTFAsync(t.replace(/\.[^/.]+$/,""));return s.dispose(),r})}static GLBAsync(e,t,n){return c(this,void 0,void 0,function*(){n&&n.exportWithoutWaitingForScene||(yield e.whenReadyAsync());const s=new Z(e,n),r=yield s.generateGLBAsync(t.replace(/\.[^/.]+$/,""));return s.dispose(),r})}}var J={__proto__:null,GLTF2Export:Y};const ee="EXT_mesh_gpu_instancing";function te(e,t){const n=new Float32Array(3*t);for(let s=0;s<t;s++)n[3*s+0]=e[4*s+0],n[3*s+1]=e[4*s+1],n[3*s+2]=e[4*s+2];return n}class ne{constructor(e){this.name=ee,this.enabled=!0,this.required=!1,this._instanceColorWarned=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportNodeAsync(e,n,s,r,i,o){return c(this,void 0,void 0,function*(){return yield new Promise(e=>{var r,a;if(n&&s instanceof t.Mesh&&s.hasThinInstances&&this._exporter){this._wasUsed=!0;const e=t.Vector3.Zero(),l=t.Quaternion.Identity(),u=t.Vector3.One(),c=s.thinInstanceGetWorldMatrices(),h=t.TmpVectors.Vector3[2],d=t.TmpVectors.Quaternion[1],f=t.TmpVectors.Vector3[3];let p=!1,m=!1,g=!1;const x=new Float32Array(3*s.thinInstanceCount),_=new Float32Array(4*s.thinInstanceCount),T=new Float32Array(3*s.thinInstanceCount);let y=0;for(const t of c)t.decompose(f,d,h),i&&(B(h),P(d)),x.set(h.asArray(),3*y),_.set(d.normalize().asArray(),4*y),T.set(f.asArray(),3*y),p=p||!h.equalsWithEpsilon(e),m=m||!d.equalsWithEpsilon(l),g=g||!f.equalsWithEpsilon(u),y++;const b={attributes:{}};p&&(b.attributes.TRANSLATION=this._buildAccessor(x,"VEC3",s.thinInstanceCount,o)),m&&(b.attributes.ROTATION=this._buildAccessor(_,"VEC4",s.thinInstanceCount,o)),g&&(b.attributes.SCALE=this._buildAccessor(T,"VEC3",s.thinInstanceCount,o));let v=null===(a=null===(r=s._userThinInstanceBuffersStorage)||void 0===r?void 0:r.data)||void 0===a?void 0:a.instanceColor;if(v){const e=s.thinInstanceCount,n="VEC3";s.hasVertexAlpha&&v.length===4*e?(this._instanceColorWarned||(t.Logger.Warn("EXT_mesh_gpu_instancing: Exporting instance colors as RGB, alpha channel of instance color is not exported"),this._instanceColorWarned=!0),v=te(v,e)):v.length===4*e&&(v=te(v,e)),v.length===3*e&&(b.attributes._COLOR_0=this._buildAccessor(v,n,e,o))}n.extensions=n.extensions||{},n.extensions[ee]=b}e(n)})})}_buildAccessor(e,t,n,s){const r=s.createBufferView(e),i=s.createAccessor(r,t,5126,n);return this._exporter._accessors.push(i),this._exporter._accessors.length-1}}let se=!1;function re(){se||(se=!0,Z.RegisterExtension(ee,e=>new ne(e)))}re();const ie="KHR_draco_mesh_compression";function oe(e){return"POSITION"===e?"POSITION":"NORMAL"===e?"NORMAL":e.startsWith("COLOR")?"COLOR":e.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"}class ae{get wasUsed(){return this._wasUsed}constructor(e){this.name=ie,this.required=!0,this._bufferViewsUsed=new Set,this._accessorsUsed=new Set,this._encodePromises=[],this._wasUsed=!1,this.enabled="Draco"===e.options.meshCompressionMethod&&t.DracoEncoder.DefaultAvailable}dispose(){}postExportMeshPrimitive(e,n,s){if(!this.enabled)return;if(4!==e.mode&&5!==e.mode)return void t.Logger.Warn("Cannot compress primitive with mode "+e.mode+".");const r=[],i=[];let o=null;if(void 0!==e.indices){const t=s[e.indices],a=n.getBufferView(t);o=n.getData(a).slice(),r.push(a),i.push(t)}const a=[];for(const[o,l]of Object.entries(e.attributes)){const e=s[l],u=n.getBufferView(e),c=S(e.type),h=t.GetTypedArrayData(n.getData(u),c,e.componentType,e.byteOffset||0,u.byteStride||t.GetTypeByteLength(e.componentType)*c,e.count,!0);a.push({kind:o,dracoName:oe(o),size:S(e.type),data:h}),r.push(u),i.push(e)}const l={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},u=t.DracoEncoder.Default._encodeAsync(a,o,l).then(t=>{const s={bufferView:-1,attributes:t.attributeIds},o=n.createBufferView(t.data);n.setBufferView(s,o);for(const e of r)this._bufferViewsUsed.add(e);for(const e of i)this._accessorsUsed.add(e);e.extensions||(e.extensions={}),e.extensions[ie]=s}).catch(e=>{t.Logger.Error("KHR_draco_mesh_compression: Failed to export Draco-encoded primitive. Resulting glTF may be invalid. "+e.message)});this._encodePromises.push(u),this._wasUsed=!0}preGenerateBinaryAsync(e){return c(this,void 0,void 0,function*(){this.enabled&&(yield Promise.all(this._encodePromises),this._bufferViewsUsed.forEach(t=>{e.getPropertiesWithBufferView(t).every(e=>this._accessorsUsed.has(e))&&e.removeBufferView(t)}),this._bufferViewsUsed.clear(),this._accessorsUsed.clear())})}}let le=!1;function ue(){le||(le=!0,Z.RegisterExtension(ie,e=>new ae(e)))}ue();const ce="KHR_lights_punctual",he={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},de={innerConeAngle:0,outerConeAngle:Math.PI/4},fe=t.Vector3.Backward();class pe{constructor(e){this.name=ce,this.enabled=!0,this.required=!1,this._exporter=e}dispose(){this._lights=null}get wasUsed(){return!!this._lights}onExporting(){this._exporter._glTF.extensions[ce]=this._lights}postExportNodeAsync(e,n,s,r,i){return c(this,void 0,void 0,function*(){return yield new Promise(o=>{if(!(s instanceof t.Light))return void o(n);const a=s.getTypeID()==t.Light.LIGHTTYPEID_POINTLIGHT?"point":s.getTypeID()==t.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":s.getTypeID()==t.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(a&&s instanceof t.ShadowLight))return t.Logger.Warn(`${e}: Light ${s.name} is not supported in ${ce}`),void o(n);if(s.falloffType!==t.Light.FALLOFF_GLTF&&t.Logger.Warn(`${e}: Light falloff for ${s.name} does not match the ${ce} specification!`),!s.position.equalsToFloats(0,0,0)){const e=t.TmpVectors.Vector3[0].copyFrom(s.position);i&&B(e),n.translation=e.asArray()}if("point"!==a){const e=s.direction.normalizeToRef(t.TmpVectors.Vector3[0]);i&&B(e);const r=t.Quaternion.FromUnitVectorsToRef(fe,e,t.TmpVectors.Quaternion[0]);t.Quaternion.IsIdentity(r)||(n.rotation=r.asArray())}const l={type:a,name:s.name,color:s.diffuse.asArray(),intensity:s.intensity,range:s.range};if(z(l,he),"spot"===a){const e=s;l.spot={innerConeAngle:e.innerAngle/2,outerConeAngle:e.angle/2},z(l.spot,de)}this._lights||(this._lights={lights:[]}),this._lights.lights.push(l);const u={light:this._lights.lights.length-1},c=s.parent;if(c&&K(s,c)){const e=r.get(c);if(e){const t=this._exporter._nodes[e];return k(n,t),t.extensions||(t.extensions={}),t.extensions[ce]=u,void o(null)}}n.extensions||(n.extensions={}),n.extensions[ce]=u,o(n)})})}}let me=!1;function ge(){me||(me=!0,Z.RegisterExtension(ce,e=>new pe(e)))}ge();const xe="EXT_lights_area",_e={name:"",color:[1,1,1],intensity:1,size:1},Te={aspect:1},ye=t.Vector3.Backward();class be{constructor(e){this.name=xe,this.enabled=!0,this.required=!1,this._exporter=e}dispose(){this._lights=null}get wasUsed(){return!!this._lights}onExporting(){this._exporter._glTF.extensions[xe]=this._lights}postExportNodeAsync(e,n,s,r,i){return c(this,void 0,void 0,function*(){return yield new Promise(o=>{if(!(s instanceof t.Light))return void o(n);const a=s.getTypeID()==t.Light.LIGHTTYPEID_RECT_AREALIGHT?"rect":null;if(!a)return t.Logger.Warn(`${e}: Light ${s.name} is not supported in ${xe}`),void o(n);const l=s;if(l.falloffType!==t.Light.FALLOFF_GLTF&&t.Logger.Warn(`${e}: Light falloff for ${s.name} does not match the ${xe} specification!`),!l.position.equalsToFloats(0,0,0)){const e=t.TmpVectors.Vector3[0].copyFrom(l.position);i&&B(e),n.translation=e.asArray()}const u=t.Vector3.Forward();i&&B(u);const c=t.Quaternion.FromUnitVectorsToRef(ye,u,t.TmpVectors.Quaternion[0]);t.Quaternion.IsIdentity(c)||(n.rotation=c.asArray());const h={type:a,name:l.name,color:l.diffuse.asArray(),intensity:l.intensity,size:l.height,rect:{aspect:l.width/l.height}};z(h,_e),h.rect&&z(h.rect,Te),this._lights||(this._lights={lights:[]}),this._lights.lights.push(h);const d={light:this._lights.lights.length-1},f=s.parent;if(f&&K(l,f)){const e=r.get(f);if(e){const t=this._exporter._nodes[e];return k(n,t),t.extensions||(t.extensions={}),t.extensions[xe]=d,void o(null)}}n.extensions||(n.extensions={}),n.extensions[xe]=d,o(n)})})}}let ve=!1;function Me(){ve||(ve=!0,Z.RegisterExtension(xe,e=>new be(e)))}Me();const we="KHR_materials_anisotropy";class Re{constructor(e){this.name=we,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._anisoTexturesMap={},this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const e=[];if(s instanceof t.PBRBaseMaterial){if(s.anisotropy.isEnabled&&!s.anisotropy.legacy)return s.anisotropy.texture&&e.push(s.anisotropy.texture),e}else if(s instanceof t.OpenPBRMaterial&&s.specularRoughnessAnisotropy>0){const n=function(e){const t=e.specularRoughnessAnisotropyTexture,n=e.geometryTangentTexture;return`${t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength"}_${n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoTangent"}`}(s);if(this._anisoTexturesMap[n])e.push(this._anisoTexturesMap[n]);else{const r=yield function(e){return c(this,void 0,void 0,function*(){const n=e.getScene(),s=e.specularRoughnessAnisotropyTexture,r=e.geometryTangentTexture;return s||r?yield t.MergeTexturesAsync("AnisotropyTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),r?t.CreateTextureInput(r,1):t.CreateConstantInput(0),s?t.CreateTextureInput(s,0):t.CreateConstantInput(1)),n):null})}(s);r&&(e.push(r),this._anisoTexturesMap[n]=r)}return e}return[]})}postExportMaterialAsync(e,n,s){return new Promise(e=>{var r;if(s instanceof t.PBRBaseMaterial){if(!s.anisotropy.isEnabled||s.anisotropy.legacy)return void e(n);this._wasUsed=!0,n.extensions=n.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(s.anisotropy.texture),r={anisotropyStrength:s.anisotropy.intensity,anisotropyRotation:s.anisotropy.angle,anisotropyTexture:null!=t?t:void 0};null!==r.anisotropyTexture&&this._exporter._materialNeedsUVsSet.add(s),n.extensions[we]=r}else if(s instanceof t.OpenPBRMaterial&&s.specularRoughnessAnisotropy>0){this._wasUsed=!0,n.extensions=n.extensions||{};let t=s.specularRoughnessTexture;s._useRoughnessFromMetallicTextureGreen&&(t=s.baseMetalnessTexture);const i=this._anisoTexturesMap[s.id];if(!t&&!i){let t=s.specularRoughness,r=s.specularRoughnessAnisotropy;if(!s._useGltfStyleAnisotropy){const e=function(e,t){const n=e*e,s=n*Math.sqrt(2/(1+(1-t)*(1-t))),r=(1-t)*s;return{newBaseRoughness:Math.sqrt(r),newAnisotropyStrength:Math.min(Math.sqrt((s-n)/Math.max(1-n,1e-4)),1)}}(s.specularRoughness,s.specularRoughnessAnisotropy);t=e.newBaseRoughness,r=e.newAnisotropyStrength}n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=t);const i={anisotropyStrength:r,anisotropyRotation:s.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return n.extensions[we]=i,e(n)}const o=i?this._exporter._materialExporter.getTextureInfo(i):null,a={anisotropyStrength:s.specularRoughnessAnisotropy,anisotropyRotation:s.geometryTangentAngle,anisotropyTexture:o||void 0,extensions:{}};s._useGltfStyleAnisotropy||(n.extensions.KHR_materials_openpbr={},(r=this._exporter._glTF).extensionsUsed||(r.extensionsUsed=[]),-1===this._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&this._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr")),this._exporter._materialNeedsUVsSet.add(s),n.extensions[we]=a}e(n)})}}let Ae=!1;function Ce(){Ae||(Ae=!0,Z.RegisterExtension(we,e=>new Re(e)))}Ce();const Ee="KHR_materials_clearcoat";function Ie(e,n){const s=new t.Texture(n.name,n.getScene());return s._texture=e,s.coordinatesIndex=n.coordinatesIndex,n instanceof t.Texture&&(s.uOffset=n.uOffset,s.vOffset=n.vOffset,s.uScale=n.uScale,s.vScale=n.vScale,s.wAng=n.wAng),s.wrapU=n.wrapU,s.wrapV=n.wrapV,s}class Se{constructor(e){this.name=Ee,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}dispose(){for(const e of Object.keys(this._mergedTexturesMap))this._mergedTexturesMap[e].dispose();this._mergedTexturesMap={};for(const e of Object.keys(this._cachedInternalTexturesMap))this._cachedInternalTexturesMap[e].dispose();this._cachedInternalTexturesMap={}}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const e=[];if(s instanceof t.PBRBaseMaterial){if(s.clearCoat.isEnabled)return s.clearCoat.texture&&e.push(s.clearCoat.texture),!s.clearCoat.useRoughnessFromMainTexture&&s.clearCoat.textureRoughness&&e.push(s.clearCoat.textureRoughness),s.clearCoat.bumpTexture&&e.push(s.clearCoat.bumpTexture),e}else if(s instanceof t.OpenPBRMaterial&&s.coatWeight>0){let n=!1;if(s.coatWeightTexture?s.coatRoughnessTexture?s._useCoatRoughnessFromGreenChannel&&s.coatWeightTexture.getInternalTexture()===s.coatRoughnessTexture.getInternalTexture()?(e.push(s.coatWeightTexture),e.push(s.coatRoughnessTexture)):n=!0:e.push(s.coatWeightTexture):s.coatRoughnessTexture&&(s._useCoatRoughnessFromGreenChannel?e.push(s.coatRoughnessTexture):n=!0),n){const n=function(e){const t=e.coatWeightTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",s=e.coatRoughnessTexture;return`${n}_${s&&s.getInternalTexture()?s.getInternalTexture().uniqueId:"NoRoughness"}`}(s);if(!this._cachedInternalTexturesMap[n]){const e=yield function(e){return c(this,void 0,void 0,function*(){const n=e.getScene(),s=e.coatWeightTexture,r=e.coatRoughnessTexture;return s||r?(yield t.MergeTexturesAsync("CoatTexture",t.CreateRGBAConfiguration(s?t.CreateTextureInput(s,0):t.CreateConstantInput(1),r?t.CreateTextureInput(r,e._useCoatRoughnessFromGreenChannel?1:0):t.CreateConstantInput(1)),n)).getInternalTexture():null})}(s);e&&(this._cachedInternalTexturesMap[n]=e)}this._cachedInternalTexturesMap[n]&&(s.coatWeightTexture&&(this._mergedTexturesMap[s.coatWeightTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[n],s.coatWeightTexture),e.push(this._mergedTexturesMap[s.coatWeightTexture.uniqueId])),s.coatRoughnessTexture&&(this._mergedTexturesMap[s.coatRoughnessTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[n],s.coatRoughnessTexture),e.push(this._mergedTexturesMap[s.coatRoughnessTexture.uniqueId])))}return s.geometryCoatNormalTexture&&e.push(s.geometryCoatNormalTexture),e}return[]})}postExportMaterialAsync(e,n,s){return new Promise(e=>{if(s instanceof t.PBRBaseMaterial){if(!s.clearCoat.isEnabled)return void e(n);this._wasUsed=!0,n.extensions=n.extensions||{};const r=this._exporter._materialExporter.getTextureInfo(s.clearCoat.texture);let i;i=s.clearCoat.useRoughnessFromMainTexture?this._exporter._materialExporter.getTextureInfo(s.clearCoat.texture):this._exporter._materialExporter.getTextureInfo(s.clearCoat.textureRoughness),s.clearCoat.isTintEnabled&&t.Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${s.name}`),s.clearCoat.remapF0OnInterfaceChange&&t.Tools.Warn(`Clear Color F0 remapping is not supported for glTF export. Ignoring for: ${s.name}`);const o=this._exporter._materialExporter.getTextureInfo(s.clearCoat.bumpTexture),a={clearcoatFactor:s.clearCoat.intensity,clearcoatTexture:null!=r?r:void 0,clearcoatRoughnessFactor:s.clearCoat.roughness,clearcoatRoughnessTexture:null!=i?i:void 0,clearcoatNormalTexture:null!=o?o:void 0};null===a.clearcoatTexture&&null===a.clearcoatRoughnessTexture&&null===a.clearcoatRoughnessTexture||this._exporter._materialNeedsUVsSet.add(s),n.extensions[Ee]=a}else if(s instanceof t.OpenPBRMaterial){if(0==s.coatWeight)return void e(n);let r,i,o,a;this._wasUsed=!0,n.extensions=n.extensions||{},s.coatWeightTexture&&(r=this._mergedTexturesMap[s.coatWeightTexture.uniqueId],i=this._exporter._materialExporter.getTextureInfo(r)),s.coatRoughnessTexture&&(o=this._mergedTexturesMap[s.coatRoughnessTexture.uniqueId],a=this._exporter._materialExporter.getTextureInfo(o)),s.coatColorTexture&&t.Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${s.name}`);const l=this._exporter._materialExporter.getTextureInfo(s.geometryCoatNormalTexture),u={clearcoatFactor:s.coatWeight,clearcoatTexture:null!=i?i:void 0,clearcoatRoughnessFactor:s.coatRoughness,clearcoatRoughnessTexture:null!=a?a:void 0,clearcoatNormalTexture:null!=l?l:void 0};null===u.clearcoatTexture&&null===u.clearcoatRoughnessTexture&&null===u.clearcoatRoughnessTexture||this._exporter._materialNeedsUVsSet.add(s),n.extensions[Ee]=u}e(n)})}}let Ve=!1;function Fe(){Ve||(Ve=!0,Z.RegisterExtension(Ee,e=>new Se(e)))}Fe();const Oe="KHR_materials_coat";function Be(e){const t=e.coatRoughnessAnisotropyTexture,n=e.geometryCoatTangentTexture;return`${t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength"}_${n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoTangent"}`}function Ne(e,n){const s=new t.Texture(n.name,n.getScene());return s._texture=e,s.coordinatesIndex=n.coordinatesIndex,n instanceof t.Texture&&(s.uOffset=n.uOffset,s.vOffset=n.vOffset,s.uScale=n.uScale,s.vScale=n.vScale,s.wAng=n.wAng),s.wrapU=n.wrapU,s.wrapV=n.wrapV,s}class Pe{constructor(e){this.name=Oe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}dispose(){for(const e of Object.keys(this._mergedTexturesMap))this._mergedTexturesMap[e].dispose();this._mergedTexturesMap={};for(const e of Object.keys(this._cachedInternalTexturesMap))this._cachedInternalTexturesMap[e].dispose();this._cachedInternalTexturesMap={}}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const e=[];if(s instanceof t.PBRBaseMaterial){if(s.clearCoat.isEnabled)return s.clearCoat.texture&&e.push(s.clearCoat.texture),!s.clearCoat.useRoughnessFromMainTexture&&s.clearCoat.textureRoughness&&e.push(s.clearCoat.textureRoughness),s.clearCoat.bumpTexture&&e.push(s.clearCoat.bumpTexture),s.clearCoat.tintTexture&&e.push(s.clearCoat.tintTexture),e}else if(s instanceof t.OpenPBRMaterial&&s.coatWeight>0){let n=!1;if(s.coatWeightTexture?s.coatRoughnessTexture?s._useCoatRoughnessFromGreenChannel&&s.coatWeightTexture.getInternalTexture()===s.coatRoughnessTexture.getInternalTexture()?(e.push(s.coatWeightTexture),e.push(s.coatRoughnessTexture)):n=!0:e.push(s.coatWeightTexture):s.coatRoughnessTexture&&(s._useCoatRoughnessFromGreenChannel?e.push(s.coatRoughnessTexture):n=!0),n){const n=function(e){const t=e.coatWeightTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",s=e.coatRoughnessTexture;return`${n}_${s&&s.getInternalTexture()?s.getInternalTexture().uniqueId:"NoRoughness"}`}(s);if(!this._cachedInternalTexturesMap[n]){const e=yield function(e){return c(this,void 0,void 0,function*(){const n=e.getScene(),s=e.coatWeightTexture,r=e.coatRoughnessTexture;return s||r?(yield t.MergeTexturesAsync("CoatTexture",t.CreateRGBAConfiguration(s?t.CreateTextureInput(s,0):t.CreateConstantInput(1),r?t.CreateTextureInput(r,e._useCoatRoughnessFromGreenChannel?1:0):t.CreateConstantInput(1)),n)).getInternalTexture():null})}(s);e&&(this._cachedInternalTexturesMap[n]=e)}this._cachedInternalTexturesMap[n]&&(s.coatWeightTexture&&(this._mergedTexturesMap[s.coatWeightTexture.uniqueId]=Ne(this._cachedInternalTexturesMap[n],s.coatWeightTexture),e.push(this._mergedTexturesMap[s.coatWeightTexture.uniqueId])),s.coatRoughnessTexture&&(this._mergedTexturesMap[s.coatRoughnessTexture.uniqueId]=Ne(this._cachedInternalTexturesMap[n],s.coatRoughnessTexture),e.push(this._mergedTexturesMap[s.coatRoughnessTexture.uniqueId])))}if(s.geometryCoatNormalTexture&&e.push(s.geometryCoatNormalTexture),s.coatColorTexture&&e.push(s.coatColorTexture),s.coatRoughnessAnisotropy>0){const n=Be(s);if(this._mergedTexturesMap[n])e.push(this._mergedTexturesMap[n]);else{const r=yield function(e){return c(this,void 0,void 0,function*(){const n=e.getScene(),s=e.coatRoughnessAnisotropyTexture,r=e.geometryCoatTangentTexture;return s||r?yield t.MergeTexturesAsync("AnisotropyTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),r?t.CreateTextureInput(r,1):t.CreateConstantInput(0),s?t.CreateTextureInput(s,0):t.CreateConstantInput(1)),n):null})}(s);r&&(e.push(r),this._mergedTexturesMap[n]=r)}return e}return e}return[]})}postExportMaterialAsync(e,n,s){return new Promise(e=>{var r;if(s instanceof t.PBRBaseMaterial){if(!s.clearCoat.isEnabled)return void e(n);this._wasUsed=!0,n.extensions=n.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(s.clearCoat.texture);let r,i;r=s.clearCoat.useRoughnessFromMainTexture?this._exporter._materialExporter.getTextureInfo(s.clearCoat.texture):this._exporter._materialExporter.getTextureInfo(s.clearCoat.textureRoughness),s.clearCoat.isTintEnabled&&(i=this._exporter._materialExporter.getTextureInfo(s.clearCoat.tintTexture));const o=this._exporter._materialExporter.getTextureInfo(s.clearCoat.bumpTexture),a=s.clearCoat.indexOfRefraction,l={coatFactor:s.clearCoat.intensity,coatTexture:null!=t?t:void 0,coatRoughnessFactor:s.clearCoat.roughness,coatRoughnessTexture:null!=r?r:void 0,coatNormalTexture:null!=o?o:void 0,coatColorFactor:s.clearCoat.tintColor.asArray(),coatColorTexture:null!=i?i:void 0,coatIor:1.5!==a?a:void 0};null===l.coatTexture&&null===l.coatRoughnessTexture&&null===l.coatRoughnessTexture&&null===l.coatColorTexture||this._exporter._materialNeedsUVsSet.add(s),n.extensions[Oe]=l}else if(s instanceof t.OpenPBRMaterial){if(0==s.coatWeight)return void e(n);let t,i,o,a;this._wasUsed=!0,n.extensions=n.extensions||{},s.coatWeightTexture&&(t=this._mergedTexturesMap[s.coatWeightTexture.uniqueId]?this._mergedTexturesMap[s.coatWeightTexture.uniqueId]:s.coatWeightTexture,i=this._exporter._materialExporter.getTextureInfo(t)),s.coatRoughnessTexture&&(o=this._mergedTexturesMap[s.coatRoughnessTexture.uniqueId]?this._mergedTexturesMap[s.coatRoughnessTexture.uniqueId]:s.coatRoughnessTexture,a=this._exporter._materialExporter.getTextureInfo(o));const l=this._exporter._materialExporter.getTextureInfo(s.geometryCoatNormalTexture),u=this._exporter._materialExporter.getTextureInfo(s.coatColorTexture),c=s.coatIor,h=s.coatDarkening,d=s.coatRoughnessTexture,f=Be(s),p=this._mergedTexturesMap[f];let m,g=0,x=0;if(s.coatRoughnessAnisotropy>0){if(d||p){const e=p?this._exporter._materialExporter.getTextureInfo(p):null;g=s.coatRoughnessAnisotropy,x=s.geometryCoatTangentAngle,m=e||void 0}else{let e=s.coatRoughness,t=s.coatRoughnessAnisotropy;if(!s._useGltfStyleAnisotropy){const n=function(e,t){const n=e*e,s=n*Math.sqrt(2/(1+(1-t)*(1-t))),r=(1-t)*s;return{newBaseRoughness:Math.sqrt(r),newAnisotropyStrength:Math.min(Math.sqrt((s-n)/Math.max(1-n,1e-4)),1)}}(s.coatRoughness,s.coatRoughnessAnisotropy);e=n.newBaseRoughness,t=n.newAnisotropyStrength}n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=e),g=t,x=s.geometryCoatTangentAngle+.5*Math.PI,m=void 0}s._useGltfStyleAnisotropy||(n.extensions.KHR_materials_openpbr={},(r=this._exporter._glTF).extensionsUsed||(r.extensionsUsed=[]),-1===this._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&this._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr"))}const _={coatFactor:s.coatWeight,coatTexture:null!=i?i:void 0,coatRoughnessFactor:s.coatRoughness,coatRoughnessTexture:null!=a?a:void 0,coatNormalTexture:null!=l?l:void 0,coatColorFactor:s.coatColor.asArray(),coatColorTexture:null!=u?u:void 0,coatIor:1.5!==c?c:void 0,coatDarkeningFactor:1!==h?h:void 0,coatAnisotropyRotation:x,coatAnisotropyStrength:g,coatAnisotropyTexture:m};null===_.coatTexture&&null===_.coatRoughnessTexture&&null===_.coatRoughnessTexture&&null===_.coatAnisotropyTexture&&null===_.coatColorTexture||this._exporter._materialNeedsUVsSet.add(s),n.extensions[Oe]=_}e(n)})}}let Ue=!1;function ke(){Ue||(Ue=!0,Z.RegisterExtension(Oe,e=>new Pe(e)))}ke();const Ke="KHR_materials_diffuse_transmission";function $e(e,n){const s=n.subSurface;let r=null;return s.translucencyIntensityTexture?r=s.translucencyIntensityTexture:s.thicknessTexture&&s.useMaskFromThicknessTexture&&(r=s.thicknessTexture),r&&!s.useGltfStyleTextures?(t.Logger.Warn(`${e}: Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ${n.name}`,1),null):r}class ze{constructor(e){this.name=Ke,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const n=[];if(s instanceof t.PBRMaterial&&this._isExtensionEnabled(s)){const t=$e(e,s);return t&&n.push(t),s.subSurface.translucencyColorTexture&&n.push(s.subSurface.translucencyColorTexture),n}return n})}_isExtensionEnabled(e){if(e.unlit)return!1;const t=e.subSurface;return!!t.isTranslucencyEnabled&&!e.unlit&&!t.useAlbedoToTintTranslucency&&t.useGltfStyleTextures&&1===t.volumeIndexOfRefraction&&0===t.minimumThickness&&0===t.maximumThickness}postExportMaterialAsync(e,n,s){return new Promise(r=>{var i,o;if(s instanceof t.PBRMaterial&&this._isExtensionEnabled(s)){this._wasUsed=!0;const t=s.subSurface,r=$e(e,s),a=0==t.translucencyIntensity?void 0:t.translucencyIntensity,l=null!==(i=this._exporter._materialExporter.getTextureInfo(r))&&void 0!==i?i:void 0,u=!t.translucencyColor||t.translucencyColor.equalsFloats(1,1,1)?void 0:t.translucencyColor.asArray(),c=null!==(o=this._exporter._materialExporter.getTextureInfo(t.translucencyColorTexture))&&void 0!==o?o:void 0,h={diffuseTransmissionFactor:a,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:u,diffuseTransmissionColorTexture:c};(l||c)&&this._exporter._materialNeedsUVsSet.add(s),n.extensions=n.extensions||{},n.extensions[Ke]=h}r(n)})}}let We=!1;function De(){We||(We=!0,Z.RegisterExtension(Ke,e=>new ze(e)))}De();const Le="KHR_materials_dispersion";class He{constructor(){this.name=Le,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}_isExtensionEnabled(e){if(e.unlit)return!1;const t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isDispersionEnabled)}postExportMaterialAsync(e,n,s){return new Promise(e=>{if(s instanceof t.PBRMaterial&&this._isExtensionEnabled(s)){this._wasUsed=!0;const e={dispersion:s.subSurface.dispersion};n.extensions=n.extensions||{},n.extensions[Le]=e}e(n)})}}let je=!1;function qe(){je||(je=!0,Z.RegisterExtension(Le,()=>new He))}qe();const Ge="KHR_materials_emissive_strength";class Xe{constructor(){this.name=Ge,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAsync(e,n,s){return c(this,void 0,void 0,function*(){return yield new Promise(e=>{if(!(s instanceof t.PBRMaterial))return e(n);const r=s.emissiveColor.scale(s.emissiveIntensity),i=Math.max(...r.asArray());if(i>1){n.emissiveFactor=r.scale(1/i).asArray(),this._wasUsed=!0;const e={emissiveStrength:i};n.extensions||(n.extensions={}),n.extensions[Ge]=e}else n.emissiveFactor=r.asArray();return e(n)})})}}let Qe=!1;function Ze(){Qe||(Qe=!0,Z.RegisterExtension(Ge,()=>new Xe))}Ze();const Ye="KHR_materials_ior";class Je{constructor(){this.name=Ye,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}_isExtensionEnabled(e){return!e.unlit&&(e instanceof t.OpenPBRMaterial?1.5!=e.specularIor:e instanceof t.PBRMaterial&&null!=e.indexOfRefraction&&1.5!=e.indexOfRefraction)}postExportMaterialAsync(e,n,s){return new Promise(e=>{if(s instanceof t.PBRMaterial&&this._isExtensionEnabled(s)){this._wasUsed=!0;const e={ior:s.indexOfRefraction};n.extensions=n.extensions||{},n.extensions[Ye]=e}else if(s instanceof t.OpenPBRMaterial&&this._isExtensionEnabled(s)){this._wasUsed=!0;const e={ior:s.specularIor};n.extensions=n.extensions||{},n.extensions[Ye]=e}e(n)})}}let et=!1;function tt(){et||(et=!0,Z.RegisterExtension(Ye,()=>new Je))}tt();const nt="KHR_materials_iridescence";class st{constructor(e){this.name=nt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const e=[];if(s instanceof t.PBRBaseMaterial){if(s.iridescence.isEnabled)return s.iridescence.texture&&e.push(s.iridescence.texture),s.iridescence.thicknessTexture&&s.iridescence.thicknessTexture!==s.iridescence.texture&&e.push(s.iridescence.thicknessTexture),e}else if(s instanceof t.OpenPBRMaterial&&s.thinFilmWeight>0)return s.thinFilmWeightTexture&&e.push(s.thinFilmWeightTexture),s.thinFilmThicknessTexture&&s.thinFilmThicknessTexture!==s.thinFilmWeightTexture&&e.push(s.thinFilmThicknessTexture),e;return[]})}postExportMaterialAsync(e,n,s){return new Promise(e=>{if(s instanceof t.PBRBaseMaterial){if(!s.iridescence.isEnabled)return void e(n);this._wasUsed=!0,n.extensions=n.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(s.iridescence.texture),r=this._exporter._materialExporter.getTextureInfo(s.iridescence.thicknessTexture),i={iridescenceFactor:s.iridescence.intensity,iridescenceIor:s.iridescence.indexOfRefraction,iridescenceThicknessMinimum:s.iridescence.minimumThickness,iridescenceThicknessMaximum:s.iridescence.maximumThickness,iridescenceTexture:null!=t?t:void 0,iridescenceThicknessTexture:null!=r?r:void 0};null===i.iridescenceTexture&&null===i.iridescenceThicknessTexture||this._exporter._materialNeedsUVsSet.add(s),n.extensions[nt]=i}else if(s instanceof t.OpenPBRMaterial){if(s.thinFilmWeight<=0)return void e(n);this._wasUsed=!0,n.extensions=n.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(s.thinFilmWeightTexture),r=this._exporter._materialExporter.getTextureInfo(s.thinFilmThicknessTexture),i={iridescenceFactor:s.thinFilmWeight,iridescenceIor:s.thinFilmIor,iridescenceThicknessMinimum:1e3*s.thinFilmThicknessMin,iridescenceThicknessMaximum:1e3*s.thinFilmThickness,iridescenceTexture:null!=t?t:void 0,iridescenceThicknessTexture:null!=r?r:void 0};null===i.iridescenceTexture&&null===i.iridescenceThicknessTexture||this._exporter._materialNeedsUVsSet.add(s),n.extensions[nt]=i}e(n)})}}let rt=!1;function it(){rt||(rt=!0,Z.RegisterExtension(nt,e=>new st(e)))}it();const ot="KHR_materials_sheen";class at{constructor(e){this.name=ot,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){return s instanceof t.PBRMaterial&&s.sheen.isEnabled&&s.sheen.texture?[s.sheen.texture]:[]})}postExportMaterialAsync(e,n,s){return c(this,void 0,void 0,function*(){return yield new Promise(e=>{var r,i,o,a;if(s instanceof t.PBRMaterial){if(!s.sheen.isEnabled)return void e(n);this._wasUsed=!0,null==n.extensions&&(n.extensions={});const t={sheenColorFactor:s.sheen.color.asArray(),sheenRoughnessFactor:null!==(r=s.sheen.roughness)&&void 0!==r?r:0};null===t.sheenColorTexture&&null===t.sheenRoughnessTexture||this._exporter._materialNeedsUVsSet.add(s),s.sheen.texture&&(t.sheenColorTexture=null!==(i=this._exporter._materialExporter.getTextureInfo(s.sheen.texture))&&void 0!==i?i:void 0),s.sheen.textureRoughness&&!s.sheen.useRoughnessFromMainTexture?t.sheenRoughnessTexture=null!==(o=this._exporter._materialExporter.getTextureInfo(s.sheen.textureRoughness))&&void 0!==o?o:void 0:s.sheen.texture&&s.sheen.useRoughnessFromMainTexture&&(t.sheenRoughnessTexture=null!==(a=this._exporter._materialExporter.getTextureInfo(s.sheen.texture))&&void 0!==a?a:void 0),n.extensions[ot]=t}e(n)})})}}let lt=!1;function ut(){lt||(lt=!0,Z.RegisterExtension(ot,e=>new at(e)))}ut();const ct="KHR_materials_fuzz";function ht(e,n){const s=new t.Texture(n.name,n.getScene());return s._texture=e,s.coordinatesIndex=n.coordinatesIndex,n instanceof t.Texture&&(s.uOffset=n.uOffset,s.vOffset=n.vOffset,s.uScale=n.uScale,s.vScale=n.vScale,s.wAng=n.wAng),s.wrapU=n.wrapU,s.wrapV=n.wrapV,s}class dt{constructor(e){this.name=ct,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}dispose(){for(const e of Object.keys(this._mergedTexturesMap))this._mergedTexturesMap[e].dispose();this._mergedTexturesMap={};for(const e of Object.keys(this._cachedInternalTexturesMap))this._cachedInternalTexturesMap[e].dispose();this._cachedInternalTexturesMap={}}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){if(s instanceof t.OpenPBRMaterial){const e=[];if(s.fuzzWeight>0){s.fuzzWeightTexture&&e.push(s.fuzzWeightTexture);let n=!1;if(s.fuzzRoughnessTexture&&(s._useFuzzRoughnessFromTextureAlpha?e.push(s.fuzzRoughnessTexture):n=!0),s.fuzzColorTexture&&!n&&e.push(s.fuzzColorTexture),n){const n=function(e){const t=e.fuzzColorTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoFuzzColor",s=e.fuzzRoughnessTexture;return`FuzzColor_${n}_FuzzRoughness_${s&&s.getInternalTexture()?s.getInternalTexture().uniqueId:"NoFuzzRoughness"}`}(s);if(!this._cachedInternalTexturesMap[n]){const e=yield function(e){return c(this,void 0,void 0,function*(){const n=e.getScene(),s=e.fuzzColorTexture,r=e.fuzzRoughnessTexture;return s||r?(yield t.MergeTexturesAsync("FuzzTexture",t.CreateRGBAConfiguration(s?t.CreateTextureInput(s,0):t.CreateConstantInput(1),s?t.CreateTextureInput(s,1):t.CreateConstantInput(1),s?t.CreateTextureInput(s,2):t.CreateConstantInput(1),r?t.CreateTextureInput(r,e._useFuzzRoughnessFromTextureAlpha?3:0):t.CreateConstantInput(1)),n)).getInternalTexture():null})}(s);e&&(this._cachedInternalTexturesMap[n]=e)}this._cachedInternalTexturesMap[n]&&(s.fuzzColorTexture&&(this._mergedTexturesMap[s.fuzzColorTexture.uniqueId]=ht(this._cachedInternalTexturesMap[n],s.fuzzColorTexture),e.push(this._mergedTexturesMap[s.fuzzColorTexture.uniqueId])),s.fuzzRoughnessTexture&&(this._mergedTexturesMap[s.fuzzRoughnessTexture.uniqueId]=ht(this._cachedInternalTexturesMap[n],s.fuzzRoughnessTexture),e.push(this._mergedTexturesMap[s.fuzzRoughnessTexture.uniqueId])))}}return e}return[]})}postExportMaterialAsync(e,n,s){return c(this,void 0,void 0,function*(){return yield new Promise(e=>{var r,i,o;if(s instanceof t.OpenPBRMaterial){if(0==s.fuzzWeight)return void e(n);this._wasUsed=!0,null==n.extensions&&(n.extensions={});const t={fuzzFactor:s.fuzzWeight,fuzzColorFactor:s.fuzzColor.asArray(),fuzzRoughnessFactor:s.fuzzRoughness};let a,l;s.fuzzWeightTexture&&(t.fuzzTexture=null!==(r=this._exporter._materialExporter.getTextureInfo(s.fuzzWeightTexture))&&void 0!==r?r:void 0),s.fuzzColorTexture&&(a=this._mergedTexturesMap[s.fuzzColorTexture.uniqueId]?this._mergedTexturesMap[s.fuzzColorTexture.uniqueId]:s.fuzzColorTexture,t.fuzzColorTexture=null!==(i=this._exporter._materialExporter.getTextureInfo(a))&&void 0!==i?i:void 0),s.fuzzRoughnessTexture&&(l=this._mergedTexturesMap[s.fuzzRoughnessTexture.uniqueId]?this._mergedTexturesMap[s.fuzzRoughnessTexture.uniqueId]:s.fuzzRoughnessTexture,t.fuzzRoughnessTexture=null!==(o=this._exporter._materialExporter.getTextureInfo(l))&&void 0!==o?o:void 0),null===t.fuzzColorTexture&&null===t.fuzzRoughnessTexture||this._exporter._materialNeedsUVsSet.add(s),n.extensions[ct]=t}e(n)})})}}let ft=!1;function pt(){ft||(ft=!0,Z.RegisterExtension(ct,e=>new dt(e)))}pt();const mt="KHR_materials_specular";class gt{constructor(e){this.name=mt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const e=[];return s instanceof t.PBRMaterial&&this._isExtensionEnabled(s)?(s.metallicReflectanceTexture&&e.push(s.metallicReflectanceTexture),s.reflectanceTexture&&e.push(s.reflectanceTexture),e):e})}_isExtensionEnabled(e){return!e.unlit&&(null!=e.metallicF0Factor&&1!=e.metallicF0Factor||null!=e.metallicReflectanceColor&&!e.metallicReflectanceColor.equalsFloats(1,1,1)||this._hasTexturesExtension(e))}_hasTexturesExtension(e){return null!=e.metallicReflectanceTexture||null!=e.reflectanceTexture}postExportMaterialAsync(e,n,s){return new Promise(e=>{var r,i,o,a,l;if(s instanceof t.PBRMaterial&&this._isExtensionEnabled(s)){this._wasUsed=!0,n.extensions=n.extensions||{};const e=null!==(r=this._exporter._materialExporter.getTextureInfo(s.metallicReflectanceTexture))&&void 0!==r?r:void 0,t=null!==(i=this._exporter._materialExporter.getTextureInfo(s.reflectanceTexture))&&void 0!==i?i:void 0,o={specularFactor:1==s.metallicF0Factor?void 0:s.metallicF0Factor,specularTexture:e,specularColorFactor:s.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:s.metallicReflectanceColor.asArray(),specularColorTexture:t};this._hasTexturesExtension(s)&&this._exporter._materialNeedsUVsSet.add(s),n.extensions[mt]=o}else if(s instanceof t.OpenPBRMaterial){n.extensions=n.extensions||{};const t=null!==(o=this._exporter._materialExporter.getTextureInfo(s.specularWeightTexture))&&void 0!==o?o:void 0,r=null!==(a=this._exporter._materialExporter.getTextureInfo(s.specularColorTexture))&&void 0!==a?a:void 0,i=1==s.specularWeight?void 0:s.specularWeight,u=s.specularColor.equalsFloats(1,1,1)?void 0:s.specularColor.asArray();if(!r&&!t&&void 0===i&&void 0===u)return e(n);this._wasUsed=!0;const c={specularEdgeColorEnabled:!0},h={specularFactor:i,specularTexture:t,specularColorFactor:u,specularColorTexture:r,extensions:{}};h.extensions.EXT_materials_specular_edge_color=c,(l=this._exporter._glTF).extensionsUsed||(l.extensionsUsed=[]),-1===this._exporter._glTF.extensionsUsed.indexOf("EXT_materials_specular_edge_color")&&this._exporter._glTF.extensionsUsed.push("EXT_materials_specular_edge_color"),(t||r)&&this._exporter._materialNeedsUVsSet.add(s),n.extensions[mt]=h}e(n)})}}let xt=!1;function _t(){xt||(xt=!0,Z.RegisterExtension(mt,e=>new gt(e)))}_t();const Tt="KHR_materials_transmission";class yt{constructor(e){this.name=Tt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const e=[];if(s instanceof t.PBRMaterial){if(this._isExtensionEnabled(s))return s.subSurface.refractionIntensityTexture&&s.subSurface.useGltfStyleTextures&&e.push(s.subSurface.refractionIntensityTexture),e}else s instanceof t.OpenPBRMaterial&&(s.transmissionWeight>0&&s.transmissionWeightTexture&&(e.push(s.transmissionWeightTexture),s.transmissionColorTexture&&e.push(s.transmissionColorTexture)),s.subsurfaceWeight>0&&s.subsurfaceWeightTexture&&e.push(s.subsurfaceWeightTexture));return e})}_isExtensionEnabled(e){if(e instanceof t.OpenPBRMaterial&&!e.unlit)return e.transmissionWeight>0||e.subsurfaceWeight>0;if(e instanceof t.PBRMaterial&&!e.unlit){const t=e.subSurface;return t.isRefractionEnabled&&null!=t.refractionIntensity&&0!=t.refractionIntensity||null!=t.refractionIntensityTexture&&t.useGltfStyleTextures}return!1}postExportMaterialAsync(e,n,s){return c(this,void 0,void 0,function*(){if(!this._isExtensionEnabled(s))return n;if(s instanceof t.PBRMaterial){this._wasUsed=!0;const r=s.subSurface,i={transmissionFactor:0===r.refractionIntensity?void 0:r.refractionIntensity};if(r.refractionIntensityTexture)if(r.useGltfStyleTextures){this._exporter._materialNeedsUVsSet.add(s);const e=this._exporter._materialExporter.getTextureInfo(r.refractionIntensityTexture);e&&(i.transmissionTexture=e)}else t.Logger.Warn(`${e}: Exporting a subsurface refraction intensity texture without \`useGltfStyleTextures\` is not supported`);n.extensions||(n.extensions={}),n.extensions[Tt]=i}else if(s instanceof t.OpenPBRMaterial){this._wasUsed=!0;const e={transmissionFactor:(1-s.transmissionWeight)*s.subsurfaceWeight+s.transmissionWeight};if(s.transmissionWeightTexture){this._exporter._materialNeedsUVsSet.add(s);const t=this._exporter._materialExporter.getTextureInfo(s.transmissionWeightTexture);t&&(e.transmissionTexture=t)}else if(s.subsurfaceWeightTexture){this._exporter._materialNeedsUVsSet.add(s);const t=this._exporter._materialExporter.getTextureInfo(s.subsurfaceWeightTexture);t&&(e.transmissionTexture=t)}if(0==s.transmissionDepth&&(!s.transmissionColor.equals(t.Color3.White())||s.transmissionColorTexture)&&n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.baseColorFactor||(n.pbrMetallicRoughness.baseColorFactor=[1,1,1,1]),n.pbrMetallicRoughness.baseColorFactor[0]*=s.transmissionColor.r,n.pbrMetallicRoughness.baseColorFactor[1]*=s.transmissionColor.g,n.pbrMetallicRoughness.baseColorFactor[2]*=s.transmissionColor.b,s.transmissionColorTexture&&!n.pbrMetallicRoughness.baseColorTexture)){const e=this._exporter._materialExporter.getTextureInfo(s.transmissionColorTexture);e&&(n.pbrMetallicRoughness.baseColorTexture=e,this._exporter._materialNeedsUVsSet.add(s))}n.extensions||(n.extensions={}),n.extensions[Tt]=e}return n})}}let bt=!1;function vt(){bt||(bt=!0,Z.RegisterExtension(Tt,e=>new yt(e)))}vt();const Mt="KHR_materials_unlit";class wt{constructor(){this.name=Mt,this.enabled=!0,this.required=!1,this._wasUsed=!1}get wasUsed(){return this._wasUsed}dispose(){}postExportMaterialAsync(e,n,s){return new Promise(e=>{let r=!1;s instanceof t.PBRMaterial?r=s.unlit:s instanceof t.StandardMaterial&&(r=s.disableLighting),r&&(this._wasUsed=!0,null==n.extensions&&(n.extensions={}),n.extensions[Mt]={}),e(n)})}}let Rt=!1;function At(){Rt||(Rt=!0,Z.RegisterExtension(Mt,()=>new wt))}At();const Ct="KHR_materials_volume";class Et{constructor(e){this.name=Ct,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const e=[];if(s instanceof t.PBRMaterial){if(this._isExtensionEnabled(s))return s.subSurface.thicknessTexture&&e.push(s.subSurface.thicknessTexture),e}else s instanceof t.OpenPBRMaterial&&(s.transmissionWeight>0||s.subsurfaceWeight>0)&&s.geometryThicknessTexture&&e.push(s.geometryThicknessTexture);return e})}_isExtensionEnabled(e){if(e.unlit)return!1;const n=e.subSurface;return!(!n.isRefractionEnabled&&!n.isTranslucencyEnabled)&&(null!=n.maximumThickness&&0!=n.maximumThickness||null!=n.tintColorAtDistance&&n.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=n.tintColor&&n.tintColor!=t.Color3.White()||this._hasTexturesExtension(e))}_hasTexturesExtension(e){return null!=e.subSurface.thicknessTexture}postExportMaterialAsync(e,n,s){return new Promise(e=>{var r,i;if(s instanceof t.PBRMaterial&&this._isExtensionEnabled(s)){this._wasUsed=!0;const e=s.subSurface,t={thicknessFactor:0==e.maximumThickness?void 0:e.maximumThickness,thicknessTexture:null!==(r=this._exporter._materialExporter.getTextureInfo(e.thicknessTexture))&&void 0!==r?r:void 0,attenuationDistance:e.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:e.tintColorAtDistance,attenuationColor:e.tintColor.equalsFloats(1,1,1)?void 0:e.tintColor.asArray()};this._hasTexturesExtension(s)&&this._exporter._materialNeedsUVsSet.add(s),n.extensions=n.extensions||{},n.extensions[Ct]=t}else if(s instanceof t.OpenPBRMaterial){const e=s.transmissionWeight>0&&!s.geometryThinWalled,r=s.subsurfaceWeight>0&&!s.geometryThinWalled;if(e||r){this._wasUsed=!0;const o=s.geometryThickness,a=null!==(i=this._exporter._materialExporter.getTextureInfo(s.geometryThicknessTexture))&&void 0!==i?i:void 0;let l;a&&this._exporter._materialNeedsUVsSet.add(s);const u=t.Color3.White().asArray();if(e&&s.transmissionDepth>0){const e=1/s.transmissionDepth;let n=new t.Vector3(-Math.log(s.transmissionColor.r)*e,-Math.log(s.transmissionColor.g)*e,-Math.log(s.transmissionColor.b)*e);const r=new t.Vector3(s.transmissionScatter.r*e,s.transmissionScatter.g*e,s.transmissionScatter.b*e),i=n.subtract(r),o=Math.min(i.x,i.y,i.z);o<0&&(i.x=i.x-o,i.y=i.y-o,i.z=i.z-o),n=i.add(r),l=1/Math.max(n.x,n.y,n.z),u[0]=Math.exp(-n.x*l),u[1]=Math.exp(-n.y*l),u[2]=Math.exp(-n.z*l)}else l=Number.MAX_VALUE,u[0]=1,u[1]=1,u[2]=1;let c=1;const h=t.Color3.White().asArray();if(r){const e=s.subsurfaceRadius,n=s.subsurfaceRadiusScale,r=new t.Vector3(n.r,n.g,n.b).multiplyByFloats(e,e,e),i=new t.Vector3(1/Math.max(r.x,1e-6),1/Math.max(r.y,1e-6),1/Math.max(r.z,1e-6));c=1/Math.max(i.x,i.y,i.z),h[0]=Math.exp(-i.x*c),h[1]=Math.exp(-i.y*c),h[2]=Math.exp(-i.z*c)}const d=(1-s.transmissionWeight)*s.subsurfaceWeight,f=d+s.transmissionWeight,p=1/Math.max(f,1e-6),m=s.transmissionWeight*p,g=d*p,x=u.map((e,t)=>e*m+h[t]*g),_={thicknessFactor:o,thicknessTexture:a,attenuationDistance:l*m+c*g,attenuationColor:x};n.extensions=n.extensions||{},n.extensions[Ct]=_}}e(n)})}}let It=!1;function St(){It||(It=!0,Z.RegisterExtension(Ct,e=>new Et(e)))}St();const Vt="KHR_materials_volume_scatter";class Ft{constructor(e){this.name=Vt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const e=[];return s instanceof t.OpenPBRMaterial&&(s.transmissionWeight>0&&s.transmissionScatterTexture&&e.push(s.transmissionScatterTexture),s.subsurfaceWeight>0&&s.subsurfaceColorTexture&&e.push(s.subsurfaceColorTexture)),e})}_isExtensionEnabled(e){if(e.unlit)return!1;const n=e.transmissionWeight>0&&!e.geometryThinWalled&&e.transmissionDepth>0&&!e.transmissionScatter.equals(t.Color3.Black()),s=e.subsurfaceWeight>0&&!e.geometryThinWalled;return!(!n&&!s)}postExportMaterialAsync(e,n,s){return new Promise(e=>{if(s instanceof t.OpenPBRMaterial&&this._isExtensionEnabled(s)){this._wasUsed=!0;let e=t.Vector3.Zero(),r=0;s.transmissionWeight>0&&(e=function(e){const n=new t.Vector3(Math.sqrt(1-e.x),Math.sqrt(1-e.y),Math.sqrt(1-e.z)),s=new t.Vector3(1,1,1),r=s.subtract(n),i=s.subtract(new t.Vector3(.139,.139,.139).multiplyInPlace(n)),o=s.add(new t.Vector3(1.17,1.17,1.17).multiplyInPlace(n));return r.multiplyInPlace(i).divideInPlace(o)}(new t.Vector3(s.transmissionScatter.r,s.transmissionScatter.g,s.transmissionScatter.b)),r=s.transmissionScatterAnisotropy);const i=t.Vector3.Zero();let o=0;s.subsurfaceWeight>0&&(i.set(s.subsurfaceColor.r,s.subsurfaceColor.g,s.subsurfaceColor.b),o=s.subsurfaceScatterAnisotropy);const a=(1-s.transmissionWeight)*s.subsurfaceWeight,l=a+s.transmissionWeight,u=1/Math.max(l,1e-6),c=s.transmissionWeight*u,h=a*u,d={multiscatterColorFactor:e.multiplyByFloats(c,c,c).addInPlace(i.multiplyByFloats(h,h,h)).asArray(),scatterAnisotropy:r*c+o*h};if(s.subsurfaceWeight>0&&s.subsurfaceColorTexture){this._exporter._materialNeedsUVsSet.add(s);const e=this._exporter._materialExporter.getTextureInfo(s.subsurfaceColorTexture);e&&(d.multiscatterColorTexture=e)}else if(s.transmissionWeight>0&&s.transmissionScatterTexture){this._exporter._materialNeedsUVsSet.add(s);const e=this._exporter._materialExporter.getTextureInfo(s.transmissionScatterTexture);e&&(d.multiscatterColorTexture=e)}n.extensions=n.extensions||{},n.extensions[Vt]=d}e(n)})}}let Ot=!1;function Bt(){Ot||(Ot=!0,Z.RegisterExtension(Vt,e=>new Ft(e),101))}Bt();const Nt="KHR_materials_diffuse_roughness";class Pt{constructor(e){this.name=Nt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,n,s){return c(this,void 0,void 0,function*(){const e=[];if(s instanceof t.PBRBaseMaterial){if(s._baseDiffuseRoughness)return s._baseDiffuseRoughnessTexture&&e.push(s._baseDiffuseRoughnessTexture),e}else if(s instanceof t.OpenPBRMaterial&&s.baseDiffuseRoughness)return s.baseDiffuseRoughnessTexture&&e.push(s.baseDiffuseRoughnessTexture),e;return[]})}postExportMaterialAsync(e,n,s){return new Promise(e=>{let r=null,i=null;if(s instanceof t.PBRBaseMaterial?(r=s._baseDiffuseRoughness,i=s._baseDiffuseRoughnessTexture):s instanceof t.OpenPBRMaterial&&(r=s.baseDiffuseRoughness,i=s.baseDiffuseRoughnessTexture),!r)return void e(n);this._wasUsed=!0,n.extensions=n.extensions||{};const o=this._exporter._materialExporter.getTextureInfo(i),a={diffuseRoughnessFactor:r,diffuseRoughnessTexture:null!=o?o:void 0};null!==a.diffuseRoughnessTexture&&this._exporter._materialNeedsUVsSet.add(s),n.extensions[Nt]=a,e(n)})}}let Ut=!1;function kt(){Ut||(Ut=!0,Z.RegisterExtension(Nt,e=>new Pt(e)))}kt();const Kt="KHR_materials_openpbr";class $t{constructor(){this.name=Kt,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAsync(e,n,s){return new Promise(e=>{s instanceof t.OpenPBRMaterial&&(this._wasUsed=!0,n.extensions=n.extensions||{},n.extensions[Kt]={}),e(n)})}}let zt=!1;function Wt(){zt||(zt=!0,Z.RegisterExtension(Kt,()=>new $t))}Wt();const Dt="KHR_texture_transform";class Lt{constructor(){this.name=Dt,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}postExportTexture(e,n,s){if(s.getScene()||t.Tools.Warn(`${e}: "scene" is not defined for Babylon texture ${s.name}!`),(0!==s.uAng||0!==s.vAng)&&(t.Tools.Warn(`${e}: Texture ${s.name} with rotation in the u or v axis is not supported in glTF.`),0!==s.uRotationCenter||0!==s.vRotationCenter))return;const r={};let i=!1;if(0===s.uOffset&&0===s.vOffset||(r.offset=[s.uOffset,s.vOffset],i=!0),1===s.uScale&&1===s.vScale||(r.scale=[s.uScale,s.vScale],i=!0),0!==s.wAng){if(0!==s.uRotationCenter||0!==s.vRotationCenter){if(s.homogeneousRotationInUVTransform&&s.uScale!==s.vScale)return void t.Tools.Warn(`${e}: Texture ${s.name} with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ${Dt}.`);t.Tools.Warn(`${e}: Texture ${s.name} with non-origin rotation center will be exported using an adjusted offset with ${Dt}.`),r.offset=function(e){const{uOffset:t,vOffset:n,uRotationCenter:s,vRotationCenter:r,uScale:i,vScale:o,wAng:a}=e,l=Math.cos(a),u=Math.sin(a),c=s*i,h=r*o;return[t+(c*(1-l)+h*u),n+(h*(1-l)-c*u)]}(s)}r.rotation=-s.wAng,i=!0}0!==s.coordinatesIndex&&(r.texCoord=s.coordinatesIndex,i=!0),i&&(this._wasUsed=!0,n.extensions||(n.extensions={}),n.extensions[Dt]=r)}}let Ht=!1;function jt(){Ht||(Ht=!0,Z.RegisterExtension(Dt,()=>new Lt))}jt();const qt="KHR_texture_basisu";class Gt{get wasUsed(){return this._wasUsed}constructor(e){this.name=qt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}dispose(){}postExportTexture(e,n){const s=this._exporter._textures[n.index],r=s.source;if(void 0===r)return;const i=this._exporter._images[r];"image/ktx2"===(i.mimeType||t.GetMimeType(i.uri))&&(s.source=void 0,s.extensions||(s.extensions={}),s.extensions[qt]={source:r},this._wasUsed=!0)}}let Xt=!1;function Qt(){Xt||(Xt=!0,Z.RegisterExtension(qt,e=>new Gt(e)))}Qt();const Zt="EXT_texture_webp";class Yt{get wasUsed(){return this._wasUsed}constructor(e){this.name=Zt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}dispose(){}postExportTexture(e,n){const s=this._exporter._textures[n.index],r=s.source;if(void 0===r)return;const i=this._exporter._images[r];"image/webp"===(i.mimeType||t.GetMimeType(i.uri))&&(s.source=void 0,s.extensions||(s.extensions={}),s.extensions[Zt]={source:r},this._wasUsed=!0)}}let Jt=!1;function en(){Jt||(Jt=!0,Z.RegisterExtension(Zt,e=>new Yt(e)))}en();const tn="EXT_texture_avif";class nn{get wasUsed(){return this._wasUsed}constructor(e){this.name=tn,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}dispose(){}postExportTexture(e,n){const s=this._exporter._textures[n.index],r=s.source;if(void 0===r)return;const i=this._exporter._images[r];"image/avif"===(i.mimeType||t.GetMimeType(i.uri))&&(s.source=void 0,s.extensions||(s.extensions={}),s.extensions[tn]={source:r},this._wasUsed=!0)}}let sn=!1;function rn(){sn||(sn=!0,Z.RegisterExtension(tn,e=>new nn(e)))}rn();var on={__proto__:null,EXT_lights_area:be,EXT_mesh_gpu_instancing:ne,EXT_texture_avif:nn,EXT_texture_webp:Yt,KHR_draco_mesh_compression:ae,KHR_lights_punctual:pe,KHR_materials_anisotropy:Re,KHR_materials_clearcoat:Se,KHR_materials_coat:Pe,KHR_materials_diffuse_roughness:Pt,KHR_materials_diffuse_transmission:ze,KHR_materials_dispersion:He,KHR_materials_emissive_strength:Xe,KHR_materials_fuzz:dt,KHR_materials_ior:Je,KHR_materials_iridescence:st,KHR_materials_openpbr:$t,KHR_materials_sheen:at,KHR_materials_specular:gt,KHR_materials_transmission:yt,KHR_materials_unlit:wt,KHR_materials_volume:Et,KHR_materials_volume_scatter:Ft,KHR_texture_basisu:Gt,KHR_texture_transform:Lt,RegisterEXT_lights_area:Me,RegisterEXT_mesh_gpu_instancing:re,RegisterEXT_texture_avif:rn,RegisterEXT_texture_webp:en,RegisterKHR_draco_mesh_compression:ue,RegisterKHR_lights_punctual:ge,RegisterKHR_materials_anisotropy:Ce,RegisterKHR_materials_clearcoat:Fe,RegisterKHR_materials_coat:ke,RegisterKHR_materials_diffuse_roughness:kt,RegisterKHR_materials_diffuse_transmission:De,RegisterKHR_materials_dispersion:qe,RegisterKHR_materials_emissive_strength:Ze,RegisterKHR_materials_fuzz:pt,RegisterKHR_materials_ior:tt,RegisterKHR_materials_iridescence:it,RegisterKHR_materials_openpbr:Wt,RegisterKHR_materials_sheen:ut,RegisterKHR_materials_specular:_t,RegisterKHR_materials_transmission:vt,RegisterKHR_materials_unlit:At,RegisterKHR_materials_volume:St,RegisterKHR_materials_volume_scatter:Bt,RegisterKHR_texture_basisu:Qt,RegisterKHR_texture_transform:jt},an={__proto__:null,EXT_lights_area:be,EXT_mesh_gpu_instancing:ne,EXT_texture_avif:nn,EXT_texture_webp:Yt,GLTF2Export:Y,GLTFData:i,KHR_draco_mesh_compression:ae,KHR_lights_punctual:pe,KHR_materials_anisotropy:Re,KHR_materials_clearcoat:Se,KHR_materials_coat:Pe,KHR_materials_diffuse_roughness:Pt,KHR_materials_diffuse_transmission:ze,KHR_materials_dispersion:He,KHR_materials_emissive_strength:Xe,KHR_materials_fuzz:dt,KHR_materials_ior:Je,KHR_materials_iridescence:st,KHR_materials_openpbr:$t,KHR_materials_sheen:at,KHR_materials_specular:gt,KHR_materials_transmission:yt,KHR_materials_unlit:wt,KHR_materials_volume:Et,KHR_materials_volume_scatter:Ft,KHR_texture_basisu:Gt,KHR_texture_transform:Lt,RegisterEXT_lights_area:Me,RegisterEXT_mesh_gpu_instancing:re,RegisterEXT_texture_avif:rn,RegisterEXT_texture_webp:en,RegisterKHR_draco_mesh_compression:ue,RegisterKHR_lights_punctual:ge,RegisterKHR_materials_anisotropy:Ce,RegisterKHR_materials_clearcoat:Fe,RegisterKHR_materials_coat:ke,RegisterKHR_materials_diffuse_roughness:kt,RegisterKHR_materials_diffuse_transmission:De,RegisterKHR_materials_dispersion:qe,RegisterKHR_materials_emissive_strength:Ze,RegisterKHR_materials_fuzz:pt,RegisterKHR_materials_ior:tt,RegisterKHR_materials_iridescence:it,RegisterKHR_materials_openpbr:Wt,RegisterKHR_materials_sheen:ut,RegisterKHR_materials_specular:_t,RegisterKHR_materials_transmission:vt,RegisterKHR_materials_unlit:At,RegisterKHR_materials_volume:St,RegisterKHR_materials_volume_scatter:Bt,RegisterKHR_texture_basisu:Qt,RegisterKHR_texture_transform:jt,_ConvertToGLTFPBRMetallicRoughness:_,_SolveMetallic:x};class ln{static CreateSTL(e,n=!0,s="stlmesh",r=!1,i=!0,o=!1,a=!1,l=!1){const u=function(e,n,s){const r=[3*e[s],3*e[s+1],3*e[s+2]],i=[new t.Vector3(n[r[0]],n[r[0]+2],n[r[0]+1]),new t.Vector3(n[r[1]],n[r[1]+2],n[r[1]+1]),new t.Vector3(n[r[2]],n[r[2]+2],n[r[2]+1])],o=i[0].subtract(i[1]),a=i[2].subtract(i[1]);return{v:i,n:t.Vector3.Cross(a,o).normalize()}},c=function(e,t,n,s){return t=h(e,t,n.x,s),t=h(e,t,n.y,s),h(e,t,n.z,s)},h=function(e,t,n,s){return e.setFloat32(t,n,s),t+4},d=function(e){if(a){let n=e;e instanceof t.InstancedMesh&&(n=e.sourceMesh);const s=n.getVerticesData(t.VertexBuffer.PositionKind,!0,!0);if(!s)return[];const r=t.Vector3.Zero();let i;for(i=0;i<s.length;i+=3)t.Vector3.TransformCoordinatesFromFloatsToRef(s[i],s[i+1],s[i+2],e.computeWorldMatrix(!0),r).toArray(s,i);return s}return e.getVerticesData(t.VertexBuffer.PositionKind)||[]};a&&(o=!0);let f="",p=0,m=0;if(r){for(let t=0;t<e.length;t++){const n=e[t].getIndices();p+=n?n.length/3:0}const t=new ArrayBuffer(84+50*p);f=new DataView(t),m+=80,f.setUint32(m,p,i),m+=4}else l||(f="solid stlmesh\r\n");for(let n=0;n<e.length;n++){const s=e[n];!r&&l&&(f+="solid "+s.name+"\r\n"),!o&&s instanceof t.Mesh&&s.bakeCurrentTransformIntoVertices();const a=d(s),h=s.getIndices()||[];for(let e=0;e<h.length;e+=3){const t=u(h,a,e);r?(m=c(f,m,t.n,i),m=c(f,m,t.v[0],i),m=c(f,m,t.v[1],i),m=c(f,m,t.v[2],i),m+=2):(f+="\tfacet normal "+t.n.x+" "+t.n.y+" "+t.n.z+"\r\n",f+="\t\touter loop\r\n",f+="\t\t\tvertex "+t.v[0].x+" "+t.v[0].y+" "+t.v[0].z+"\r\n",f+="\t\t\tvertex "+t.v[1].x+" "+t.v[1].y+" "+t.v[1].z+"\r\n",f+="\t\t\tvertex "+t.v[2].x+" "+t.v[2].y+" "+t.v[2].z+"\r\n",f+="\t\tendloop\r\n",f+="\tendfacet\r\n")}!r&&l&&(f+="endsolid "+name+"\r\n")}if(r||l||(f+="endsolid stlmesh"),n){const e=document.createElement("a"),t=new Blob([f],{type:"application/octet-stream"});e.href=window.URL.createObjectURL(t),e.download=s+".stl",e.click()}return f}}var un={__proto__:null,STLExport:ln};function cn(e,t,n=3,s=!1){const r=[];for(let i=0;i<e.length/n;i++){const o=e[i*n]*(s?-1:1),a=e[i*n+1],l=e[i*n+2];r.push(`(${o.toPrecision(t.precision)}, ${a.toPrecision(t.precision)}, ${l.toPrecision(t.precision)})`)}return r.join(", ")}function hn(e,t){const n=[];for(let s=0;s<e.length/2;s++){const r=e[2*s],i=e[2*s+1];n.push(`(${r.toPrecision(t.precision)}, ${(1-i).toPrecision(t.precision)})`)}return n.join(", ")}function dn(e,n,s,r){return`\n def "Geometry"\n {\n ${function(e,n,s,r){const i=e.getVerticesData(t.VertexBuffer.PositionKind),o=e.getVerticesData(t.VertexBuffer.NormalKind);if(i&&o)return`\n\tdef Mesh "Geometry"\n\t{\n uniform token orientation = "${s}"\n\t\tint[] faceVertexCounts = [${function(e){var t;const n=(null===(t=e.getIndices())||void 0===t?void 0:t.length)?e.getTotalIndices():e.getTotalVertices();return Array(n/3).fill(3).join(", ")}(e)}]\n\t\tint[] faceVertexIndices = [${function(e){var t;const n=e.getIndices(),s=null!==(t=null==n?void 0:n.length)&&void 0!==t?t:e.getTotalVertices(),r=[];if(null!==n)for(let e=0;e<s;e++)r.push(n[e]);else for(let e=0;e<s;e++)r.push(e);return r.join(", ")}(e)}]\n\t\tnormal3f[] normals = [${cn(o,n,void 0,r)}] (\n\t\t\tinterpolation = "vertex"\n\t\t)\n\t\tpoint3f[] points = [${cn(i,n,void 0,r)}]\n ${function(e,n){let s="";for(let r=0;r<4;r++){const i=r>0?r:"",o=e.getVerticesData(t.VertexBuffer.UVKind+(i?i+1:""));o&&(s+=`\n\t\ttexCoord2f[] primvars:st${i} = [${hn(o,n)}] (\n\t\t\tinterpolation = "vertex"\n\t\t)`)}const r=e.getVerticesData(t.VertexBuffer.ColorKind);return r&&(s+=`\n\tcolor3f[] primvars:displayColor = [${cn(r,n,r.length/e.getTotalVertices())}] (\n\t\tinterpolation = "vertex"\n\t\t)`),s}(e,n)}\n\t\tuniform token subdivisionScheme = "none"\n\t}\n`}(e,n,s,r)}\n }\n `}function fn(e){let t='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )';return t+=e,fflate.strToU8(t)}function pn(e){const t=e.m;return`( ${mn(t,0)}, ${mn(t,4)}, ${mn(t,8)}, ${mn(t,12)} )`}function mn(e,t){return`(${e[t+0]}, ${e[t+1]}, ${e[t+2]}, ${e[t+3]})`}function gn(e,t){const n="Object_"+e.uniqueId,s=pn(t);return`def Xform "${n}" (\n\tprepend references = @./geometries/Geometry_${e.geometry.uniqueId}.usda@</Geometry>\n\tprepend apiSchemas = ["MaterialBindingAPI"]\n)\n{\n\tmatrix4d xformOp:transform = ${s}\n\tuniform token[] xformOpOrder = ["xformOp:transform"]\t\n\n rel material:binding = </Root/Materials/Material_${e.material.uniqueId}>\n}\n\n`}function xn(e){switch(e){case t.Constants.TEXTURE_CLAMP_ADDRESSMODE:return"clamp";case t.Constants.TEXTURE_MIRROR_ADDRESSMODE:return"mirror";case t.Constants.TEXTURE_WRAP_ADDRESSMODE:default:return"repeat"}}function _n(e){return`(${e.x}, ${e.y})`}function Tn(e){return`(${e.r}, ${e.g}, ${e.b})`}function yn(e){return"image/jpeg"===e||"image/png"===e}function bn(e,n,s,r,i,o){var a,l;const u=e.getInternalTexture().uniqueId+"_"+e.invertY,c=e.mimeType||t.GetMimeType(null!==(l=null===(a=e.getInternalTexture())||void 0===a?void 0:a.url)&&void 0!==l?l:""),h=yn(c)?c:"image/png",d="image/jpeg"===h?"jpg":"png";i[u]={texture:e,mimeType:h,ext:d};const f=e.coordinatesIndex>0?"st"+e.coordinatesIndex:"st",p=new t.Vector2(e.uScale,e.vScale),m=new t.Vector2(e.uOffset,e.vOffset),g=e.wAng,x=Math.sin(g),_=Math.cos(g);return m.y=1-m.y-p.y,m.x+=x*p.x,m.y+=(1-_)*p.y,`\n def Shader "PrimvarReader_${s}"\n {\n uniform token info:id = "UsdPrimvarReader_float2"\n float2 inputs:fallback = (0.0, 0.0)\n token inputs:varname = "${f}"\n float2 outputs:result\n }\n\n def Shader "Transform2d_${s}"\n {\n uniform token info:id = "UsdTransform2d"\n token inputs:in.connect = </Root/Materials/Material_${n.uniqueId}/PrimvarReader_${s}.outputs:result>\n float inputs:rotation = ${(g*(180/Math.PI)).toFixed(o.precision)}\n float2 inputs:scale = ${_n(p)}\n float2 inputs:translation = ${_n(m)}\n float2 outputs:result\n }\n\n def Shader "Texture_${e.uniqueId}_${s}"\n {\n uniform token info:id = "UsdUVTexture"\n asset inputs:file = @textures/Texture_${u}.${d}@\n float2 inputs:st.connect = </Root/Materials/Material_${n.uniqueId}/Transform2d_${s}.outputs:result>\n ${r?"float4 inputs:scale = "+function(e){return`(${e.r}, ${e.g}, ${e.b}, 1.0)`}(r):""}\n token inputs:sourceColorSpace = "${e.gammaSpace?"sRGB":"raw"}"\n token inputs:wrapS = "${xn(e.wrapU)}"\n token inputs:wrapT = "${xn(e.wrapV)}"\n float outputs:r\n float outputs:g\n float outputs:b\n float3 outputs:rgb\n ${n.needAlphaBlending()||n.needAlphaTesting()?"float outputs:a":""}\n }`}function vn(e,n,s){const r="\t\t\t",i=[],o=[],{diffuseMap:a,diffuse:l,alphaCutOff:u,emissiveMap:c,emissive:h,normalMap:d,roughnessMap:f,roughnessChannel:p,roughness:m,metalnessMap:g,metalnessChannel:x,metalness:_,aoMap:T,aoMapChannel:y,aoMapIntensity:b,alphaMap:v,ior:M,clearCoatEnabled:w,clearCoat:R,clearCoatMap:A,clearCoatRoughness:C,clearCoatRoughnessMap:E}=function(e){var n,s;const r={diffuseMap:null,diffuse:null,alphaCutOff:0,emissiveMap:null,emissive:null,normalMap:null,roughnessMap:null,roughnessChannel:"a",roughness:0,metalnessMap:null,metalnessChannel:"r",metalness:0,aoMap:null,aoMapChannel:"rgb",aoMapIntensity:0,alphaMap:null,ior:1,clearCoatEnabled:!1,clearCoat:0,clearCoatMap:null,clearCoatRoughness:0,clearCoatRoughnessMap:null};return e instanceof t.StandardMaterial?Object.assign(Object.assign({},r),{diffuseMap:e.diffuseTexture,diffuse:e.diffuseColor,alphaCutOff:e.alphaCutOff,emissiveMap:e.emissiveTexture,emissive:e.emissiveColor,roughness:1,alphaMap:e.opacityTexture}):e instanceof t.PBRBaseMaterial?Object.assign(Object.assign({},r),{diffuseMap:e._albedoTexture,diffuse:e._albedoColor,alphaCutOff:e._alphaCutOff,emissiveMap:e._emissiveTexture,emissive:e._emissiveColor,normalMap:e._bumpTexture,roughnessMap:e._metallicTexture,roughnessChannel:e._useRoughnessFromMetallicTextureAlpha?"a":"g",roughness:null!==(n=e._roughness)&&void 0!==n?n:1,metalnessMap:e._metallicTexture,metalnessChannel:e._useMetallnessFromMetallicTextureBlue?"b":"r",metalness:null!==(s=e._metallic)&&void 0!==s?s:0,aoMap:e._ambientTexture,aoMapChannel:e._useAmbientInGrayScale?"r":"rgb",aoMapIntensity:e._ambientTextureStrength,alphaMap:e._opacityTexture,ior:e.subSurface.indexOfRefraction,clearCoatEnabled:e.clearCoat.isEnabled,clearCoat:e.clearCoat.intensity,clearCoatMap:e.clearCoat.texture,clearCoatRoughness:e.clearCoat.roughness,clearCoatRoughnessMap:e.clearCoat.useRoughnessFromMainTexture?e.clearCoat.texture:e.clearCoat.textureRoughness}):r}(e);return null!==a?(i.push(`${r}color3f inputs:diffuseColor.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${a.uniqueId}_diffuse.outputs:rgb>`),e.needAlphaBlending()?i.push(`${r}float inputs:opacity.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${a.uniqueId}_diffuse.outputs:a>`):e.needAlphaTesting()&&(i.push(`${r}float inputs:opacity.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${a.uniqueId}_diffuse.outputs:a>`),i.push(`${r}float inputs:opacityThreshold = ${u}`)),o.push(bn(a,e,"diffuse",l,n,s))):i.push(`${r}color3f inputs:diffuseColor = ${Tn(l||t.Color3.White())}`),null!==c?(i.push(`${r}color3f inputs:emissiveColor.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${c.uniqueId}_emissive.outputs:rgb>`),o.push(bn(c,e,"emissive",h,n,s))):h&&h.toLuminance()>0&&i.push(`${r}color3f inputs:emissiveColor = ${Tn(h)}`),null!==d&&(i.push(`${r}normal3f inputs:normal.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${d.uniqueId}_normal.outputs:rgb>`),o.push(bn(d,e,"normal",null,n,s))),null!==T&&(i.push(`${r}float inputs:occlusion.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${T.uniqueId}_occlusion.outputs:${y}>`),o.push(bn(T,e,"occlusion",new t.Color3(b,b,b),n,s))),null!==f?(i.push(`${r}float inputs:roughness.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${f.uniqueId}_roughness.outputs:${p}>`),o.push(bn(f,e,"roughness",new t.Color3(m,m,m),n,s))):i.push(`${r}float inputs:roughness = ${m}`),null!==g?(i.push(`${r}float inputs:metallic.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${g.uniqueId}_metallic.outputs:${x}>`),o.push(bn(g,e,"metallic",new t.Color3(_,_,_),n,s))):i.push(`${r}float inputs:metallic = ${_}`),null!==v?(i.push(`${r}float inputs:opacity.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${v.uniqueId}_opacity.outputs:r>`),i.push(`${r}float inputs:opacityThreshold = 0.0001`),o.push(bn(v,e,"opacity",null,n,s))):i.push(`${r}float inputs:opacity = ${e.alpha}`),w&&(null!==A?(i.push(`${r}float inputs:clearcoat.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${A.uniqueId}_clearcoat.outputs:r>`),o.push(bn(A,e,"clearcoat",new t.Color3(R,R,R),n,s))):i.push(`${r}float inputs:clearcoat = ${R}`),null!==E?(i.push(`${r}float inputs:clearcoatRoughness.connect = </Root/Materials/Material_${e.uniqueId}/Texture_${E.uniqueId}_clearcoatRoughness.outputs:g>`),o.push(bn(E,e,"clearcoatRoughness",new t.Color3(C,C,C),n,s))):i.push(`${r}float inputs:clearcoatRoughness = ${C}`)),i.push(`${r}float inputs:ior = ${M}`),`\n\tdef Material "Material_${e.uniqueId}"\n\t{\n\t\tdef Shader "PreviewSurface"\n\t\t{\n\t\t\tuniform token info:id = "UsdPreviewSurface"\n${i.join("\n")}\n\t\t\tint inputs:useSpecularWorkflow = 0\n\t\t\ttoken outputs:surface\n\t\t}\n\n\t\ttoken outputs:surface.connect = </Root/Materials/Material_${e.uniqueId}/PreviewSurface.outputs:surface>\n\n${o.join("\n")}\n\n\t}\n`}function Mn(e){var n,s;e.computeWorldMatrix(!0);const r=e.getWorldMatrix().clone(),i=e.getScene().useRightHandedSystem;let o=null!==(s=null===(n=e.material)||void 0===n?void 0:n._getEffectiveOrientation(e))&&void 0!==s?s:e.sideOrientation,a=!i,l=e.parent;for(;l;){if(w(l,i)&&null===l.parent){i||(r.multiplyToRef(l.getWorldMatrix().invert(),r),o=o===t.Material.ClockWiseSideOrientation?t.Material.CounterClockWiseSideOrientation:t.Material.ClockWiseSideOrientation),a=!1;break}l=l.parent}return r.determinant()<0&&t.Tools.Warn(`Mesh ${e.name} has a negative scale, which may look incorrect in destinations like QuickLook.`),{matrix:r,windingOrder:o===t.Material.ClockWiseSideOrientation?"leftHanded":"rightHanded",convertToRightHanded:a}}function wn(e,n,s){return c(this,void 0,void 0,function*(){const r=Object.assign({fflateUrl:"https://unpkg.com/fflate@0.8.2",includeAnchoringProperties:!0,anchoringType:"plane",planeAnchoringAlignment:"horizontal",modelFileName:"model.usda",precision:5,exportCamera:!1,cameraSensorWidth:35},n);"undefined"==typeof fflate&&(yield t.Tools.LoadScriptAsync(r.fflateUrl));const i={};i[r.modelFileName]=null;let o='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )';o+=function(e){return`def Xform "Root"\n {\n def Scope "Scenes" (\n kind = "sceneLibrary"\n )\n {\n def Xform "Scene" (\n customData = {\n bool preliminary_collidesWithEnvironment = 0\n string sceneName = "Scene"\n }\n sceneName = "Scene"\n )\n {${!0===e.includeAnchoringProperties?`\n\t\ttoken preliminary:anchoring:type = "${e.anchoringType}"\n\t\ttoken preliminary:planeAnchoring:alignment = "${e.planeAnchoringAlignment}"`:""}\n `}(r);const a={};for(const n of e.meshes){if(0===n.getTotalVertices())continue;const e=n,l=e.geometry,u=e.material;if(u&&l&&(!s||s(e)))if(-1!==["StandardMaterial","PBRMaterial","PBRMetallicRoughnessMaterial"].indexOf(u.getClassName())){const t="geometries/Geometry_"+l.uniqueId+".usda",{matrix:n,windingOrder:s,convertToRightHanded:c}=Mn(e);if(!(t in i)){const e=dn(l,r,s,c);i[t]=fn(e)}u.uniqueId in a||(a[u.uniqueId]=u),o+=gn(e,n)}else t.Tools.Warn("USDZExportAsync does not support this material type: "+u.getClassName())}e.activeCamera&&r.exportCamera&&(o+=function(e,n){const s="Camera_"+e.uniqueId,r=pn(t.Matrix.RotationY(Math.PI).multiply(e.getWorldMatrix()));if(e.mode===t.Constants.ORTHOGRAPHIC_CAMERA)return`def Camera "${s}"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ${r}\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (${e.minZ.toPrecision(n.precision)}, ${e.maxZ.toPrecision(n.precision)})\n\t\t\tfloat horizontalAperture = ${(10*(Math.abs(e.orthoLeft||1)+Math.abs(e.orthoRight||1))).toPrecision(n.precision)}\n\t\t\tfloat verticalAperture = ${(10*(Math.abs(e.orthoTop||1)+Math.abs(e.orthoBottom||1))).toPrecision(n.precision)}\n\t\t\ttoken projection = "orthographic"\n\t\t}\n\t\n\t`;{const t=e.getEngine().getAspectRatio(e),i=n.cameraSensorWidth||35;return`def Camera "${s}"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ${r}\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (${e.minZ.toPrecision(n.precision)}, ${e.maxZ.toPrecision(n.precision)})\n\t\t\tfloat focalLength = ${(i/(2*Math.tan(.5*e.fov))).toPrecision(n.precision)}\n token projection = "perspective"\n\t\t\tfloat horizontalAperture = ${(i*t).toPrecision(n.precision)}\n\t\t\tfloat verticalAperture = ${(i/t).toPrecision(n.precision)} \n\t\t}\n\t\n\t`}}(e.activeCamera,r)),o+="\n }\n }";const l={};o+=function(e,t,n){const s=[];for(const r in e){const i=e[r];s.push(vn(i,t,n))}return`\n def "Materials"\n{\n${s.join("")}\n}\n\n`}(a,l,r),o+="\n }",i[r.modelFileName]=fflate.strToU8(o);for(const e in l){const{texture:n,ext:s,mimeType:r}=l[e],o=yield h(n);if(o&&yn(o.mimeType)&&o.mimeType===r)i[`textures/Texture_${e}.${s}`]=new Uint8Array(o.data);else{const o=n.getSize(),a=yield t.GetTextureDataAsync(n),l=yield t.DumpTools.DumpDataAsync(o.width,o.height,a,r,void 0,!1,!0);i[`textures/Texture_${e}.${s}`]=new Uint8Array(l).slice()}}let u=0;for(const e in i){const t=i[e];if(!t)continue;u+=34+e.length;const n=63&u;if(4!==n){const s=new Uint8Array(64-n);i[e]=[t,{extra:{12345:s}}]}u=t.length}return fflate.zipSync(i,{level:0})})}var Rn={__proto__:null,USDZExportAsync:wn};class An{static Export(e,n=[],s){var r;if(!e||0===e.bones.length)throw new Error("Invalid or empty skeleton provided");let i=n;n&&0!==n.length||(i=e.animations.map(e=>e.name));let o=null;for(const n of i){const s=e.getAnimationRange(n);s&&(o=o?new t.AnimationRange("animation-range",Math.min(o.from,s.from),Math.max(o.to,s.to)):s)}if(!o&&(e.animations.length>0&&(o=e.getAnimationRange(e.animations[0].name)),!o))throw new Error("No animation range found in skeleton");const a=s||1/((null===(r=e.animations[0])||void 0===r?void 0:r.framePerSecond)||30),l=this._BuildBoneHierarchy(e,i);let u=0;for(const e of l)e.positionKeys.length>0&&(u=Math.max(u,e.positionKeys.length)),e.rotationKeys.length>0&&(u=Math.max(u,e.rotationKeys.length));0===u&&(u=Math.floor((o.to-o.from)/a)+1);let c="";return c+="HIERARCHY\n",c+=this._ExportHierarchy(l,0),c+="MOTION\n",c+=`Frames: ${u}\n`,c+=`Frame Time: ${a.toFixed(6)}\n`,c+=this._ExportMotionData(l,u,0,i),c}static _BuildBoneHierarchy(e,t){const n=new Map,s=[];for(const t of e.bones){const e={bone:t,children:[],hasPositionChannels:!1,hasRotationChannels:!1,positionKeys:[],rotationKeys:[]};n.set(t,e)}for(const r of e.bones){const e=n.get(r);if(r.animations.length>0)for(const n of r.animations)t.includes(n.name)&&("position"===n.targetProperty?(e.hasPositionChannels=!0,e.positionKeys.push(...n.getKeys())):"rotationQuaternion"===n.targetProperty&&(e.hasRotationChannels=!0,e.rotationKeys.push(...n.getKeys())));if(r.getParent()){const t=n.get(r.getParent());t&&t.children.push(e)}else s.push(e)}return s}static _ExportHierarchy(e,t){let n="";const s=" ".repeat(t);for(const r of e){const e=r.bone;if(this._IsEndSite(r)){n+=`${s}End Site\n`,n+=`${s}{\n`;const t=this._GetBoneOffset(e);n+=`${s} OFFSET ${t.x.toFixed(6)} ${t.y.toFixed(6)} ${t.z.toFixed(6)}\n`,n+=`${s}}\n`}else{n+=`${0===t?"ROOT":`${s}JOINT`} ${e.name}\n`,n+=`${s}{\n`;const i=this._GetBoneOffset(e);n+=`${s} OFFSET ${i.x.toFixed(6)} ${i.y.toFixed(6)} ${i.z.toFixed(6)}\n`;const o=[];r.hasPositionChannels&&o.push("Xposition","Yposition","Zposition"),r.hasRotationChannels&&o.push("Zrotation","Xrotation","Yrotation"),o.length>0&&(n+=`${s} CHANNELS ${o.length} ${o.join(" ")}\n`),r.children.length>0&&(n+=this._ExportHierarchy(r.children,t+1)),n+=`${s}}\n`}}return n}static _IsEndSite(e){return 0===e.children.length}static _GetBoneOffset(e){try{return e.getParent()?e.getLocalMatrix().getTranslation():e.getRestMatrix().getTranslation()}catch(e){return t.Vector3.Zero()}}static _ExportMotionData(e,t,n,s){let r="";for(let i=0;i<t;i++){const t=[];this._CollectFrameValues(e,i+n,t,s),r+=t.map(e=>e.toFixed(6)).join(" ")+"\n"}return r}static _CollectFrameValues(e,t,n,s){for(const r of e)if(!this._IsEndSite(r)){if(r.hasPositionChannels){const e=this._GetPositionAtFrameIndex(r.positionKeys,t);n.push(e.x,e.y,e.z)}if(r.hasRotationChannels){const e=this._GetRotationAtFrameIndex(r.rotationKeys,t),s=this._QuaternionToEuler(e);n.push(s.z,s.x,s.y)}r.children.length>0&&this._CollectFrameValues(r.children,t,n,s)}}static _GetPositionAtFrameIndex(e,n){return 0===e.length?t.Vector3.Zero():e[Math.max(0,Math.min(n,e.length-1))].value.clone()}static _GetRotationAtFrameIndex(e,n){return 0===e.length?t.Quaternion.Identity():e[Math.max(0,Math.min(n,e.length-1))].value.clone()}static _QuaternionToEuler(e){const n=new t.Matrix;e.toRotationMatrix(n);const s=n.m;let r,i,o;const a=Math.sqrt(s[0]*s[0]+s[1]*s[1]);return a>t.Epsilon?(r=Math.atan2(s[6],s[10]),i=Math.atan2(-s[2],a),o=Math.atan2(s[1],s[0])):(r=Math.atan2(-s[9],s[5]),i=Math.atan2(-s[2],a),o=0),new t.Vector3(t.Tools.ToDegrees(r),t.Tools.ToDegrees(i),t.Tools.ToDegrees(o))}}var Cn={__proto__:null,BVHExporter:An};function En(e){return"string"==typeof(null==e?void 0:e.name)}const In=Symbol("__xml:meta$__"),Sn=Symbol("__xml:name$__");function Vn(e,t){Object.prototype.hasOwnProperty.call(e.metadata,In)||(e.metadata[In]=[]),e.metadata[In].push(t)}function Fn(e){return(t,n)=>{t[Sn]=e}}function On(){return(e,t)=>Vn(t,{kind:"none",prop:String(t.name),ignore:!0})}function Bn(e){return(t,n)=>Vn(n,Object.assign({kind:"attr",prop:String(n.name)},e))}function Nn(e){return(t,n)=>Vn(n,Object.assign({kind:"elem",prop:String(n.name)},e))}function Pn(e){const t="function"==typeof e?e:null==e?void 0:e.constructor,n=null==t?void 0:t[Symbol.metadata];if(!n)return[];const s=[];let r=n;for(;r;)Object.prototype.hasOwnProperty.call(r,In)&&s.push(...r[In]),r=Object.getPrototypeOf(r);return s}function Un(e){var t;return(null===(t=null==e?void 0:e.constructor)||void 0===t?void 0:t[Sn])||void 0}function kn(e){return/^[A-Za-z_][A-Za-z0-9._-]*$/.test(e)}function Kn(e){if(En(e))return e;const t=(null!=e?e:"").trim();if(!t)return{name:""};const n=t.indexOf(":");if(-1===n)return{name:t};if(-1!==t.indexOf(":",n+1))return{name:t};const s=t.slice(0,n),r=t.slice(n+1);return kn(s)&&kn(r)?{ns:s,name:r}:{name:t}}function $n(e,t){return t?`${t}:${e}`:e}const zn=Object.freeze({eps:1e-6,maxDecimalsCap:15,trimTrailingZeros:!0,allowScientific:!1,snapNearZero:!0}),Wn=Object.freeze({number:zn});function Dn(e){var t,n,s,r,i,o;const a=null!==(t=null==e?void 0:e.eps)&&void 0!==t?t:zn.eps;return{eps:a,maxDecimalsCap:null!==(n=null==e?void 0:e.maxDecimalsCap)&&void 0!==n?n:zn.maxDecimalsCap,trimTrailingZeros:null!==(s=null==e?void 0:e.trimTrailingZeros)&&void 0!==s?s:zn.trimTrailingZeros,fixedDecimals:null==e?void 0:e.fixedDecimals,allowScientific:null!==(r=null==e?void 0:e.allowScientific)&&void 0!==r?r:zn.allowScientific,snapNearZero:null!==(i=null==e?void 0:e.snapNearZero)&&void 0!==i?i:zn.snapNearZero,zeroThreshold:null!==(o=null==e?void 0:e.zeroThreshold)&&void 0!==o?o:a,perAttributeEps:null==e?void 0:e.perAttributeEps}}function Ln(e){return{number:Dn(null==e?void 0:e.number)}}class Hn{constructor(e){if(this.o=e,this._o=e.number,!Number.isFinite(this._o.eps)||this._o.eps<=0)throw new Error("opts.eps must be a finite, positive number")}toString(e){var t,n,s,r;if(!Number.isFinite(e))throw new Error(`Cannot format non-finite number: ${e}`);const i=this._o,o=this._clampInt(null!==(t=i.maxDecimalsCap)&&void 0!==t?t:15,0,20),a=null===(n=i.trimTrailingZeros)||void 0===n||n,l=null===(s=i.snapNearZero)||void 0===s||s,u=null!==(r=i.zeroThreshold)&&void 0!==r?r:i.eps,c=1/i.eps;let h,d=Math.round(e*c)/c;if(Object.is(d,-0)&&(d=0),l&&Math.abs(d)<=u&&(d=0),h=void 0!==i.fixedDecimals?this._clampInt(i.fixedDecimals,0,o):this._clampInt(Math.ceil(-Math.log10(i.eps)),0,o),i.allowScientific,0===h)return String(Math.trunc(d));let f=d.toFixed(h);if(a&&void 0===i.fixedDecimals&&(f=f.replace(/(\.\d*?[1-9])0+$/,"$1").replace(/\.0+$/,"").replace(/\.$/,"")),/[eE]/.test(f))throw new Error(`Scientific notation not allowed in XML output: ${f}`);return f}_clampInt(e,t,n){return Number.isFinite(e)?(e=Math.trunc(e),Math.max(t,Math.min(n,e))):t}}function jn(e){return e instanceof Date}function qn(e){return"string"==typeof e}function Gn(e){return"number"==typeof e}function Xn(e){return"string"==typeof e||"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||jn(e)}function Qn(e){return"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||jn(e)}class Zn{constructor(e,t){this._ns=new Map,this._prefixCount=0,this._builder=e,this._format=Ln(t),this._nFmt=new Hn(this._format)}withNamespace(...e){for(const t of e)this._assignNamespace(t);return this}serialize(e,t){if(!(t=null!=t?t:Un(e)))throw new Error("can not find name for given object");const n=Kn(t);n.ns&&this._assignNamespace(n.ns,"xmlns"),this._gatherNamespaces(e,new WeakSet);const s=this._builder.ele(null,n.name);for(const[e,t]of Array.from(this._ns.entries()))s.att("xmlns",t,e);this._writeObjectContent(s,e,(new WeakSet).add(e)),this._builder.end()}_writeObject(e,t,n){if(n.has(t))return;if(n.add(t),Array.isArray(t)){for(const s of t)Qn(s)||(qn(s)?this._builder.text(s):this._writeObject(e,s,n));return}const s=Un(t);if(!s)return;const r=Kn(s),i=this._getPrefix(r),o=$n(r.name,i);e.ele(null,o),this._writeObjectContent(e,t,n),this._builder.end()}_getPrefix(e){if(e.ns){const t=this._ns.get(e.ns.toLowerCase());if("xmlns"!==t)return t}}_writeObjectContent(e,t,n){var s,r,i;const o=null!==(s=Pn(t))&&void 0!==s?s:[],a=new Map;for(const e of o){const t=null!==(r=a.get(e.prop))&&void 0!==r?r:[];t.push(e),a.set(e.prop,t)}const l=Object.keys(t).sort((e,t)=>{var n,s;const r=(null!==(n=a.get(e))&&void 0!==n?n:[]).some(e=>"attr"===e.kind);return r===(null!==(s=a.get(t))&&void 0!==s?s:[]).some(e=>"attr"===e.kind)?0:r?-1:1});for(const s of l){const r=t[s];if(null==r)continue;const o=a.get(s);if(o){if(o.some(e=>!0===e.ignore||"none"===e.kind))continue;for(const t of o){const n=null!==(i=t.name)&&void 0!==i?i:t.prop.toLowerCase();if(n)switch(t.kind){case"attr":{let s=null;if(Gn(r)&&this._nFmt&&(s=this._nFmt.toString(r)),t.formatter&&(s=new t.formatter(this._format).toString(r)),s=null!=s?s:r.toString(),s){const t=Kn(n),r=this._getPrefix(t),i=$n(t.name,r);e.att(null,i,s)}break}}}}else Qn(r)||(qn(r)?this._builder.text(r):this._writeObject(e,r,n))}}_gatherNamespaces(e,t){var n,s;if(t.has(e))return;if(t.add(e),Array.isArray(e)){for(const n of e)Xn(n)||this._gatherNamespaces(n,t);return}const r=Un(e);r&&this._assignNamespace(r);const i=null!==(n=Pn(e))&&void 0!==n?n:[],o=new Map;for(const e of i){const t=null!==(s=o.get(e.prop))&&void 0!==s?s:[];t.push(e),o.set(e.prop,t)}const a=[];for(const t of Object.keys(e)){const n=e[t];if(null==n)continue;const s=o.get(t);if(s){if(s.some(e=>!0===e.ignore||"none"===e.kind))continue;for(const e of s)e.name&&this._assignNamespace(e.name)}a.push(n)}for(const e of a)Xn(e)||this._gatherNamespaces(e,t)}_assignNamespace(e,t){const n=Kn(e);if(null==n?void 0:n.ns){const e=n.ns.toLowerCase();return void(this._ns.get(e)||this._ns.set(e,null!=t?t:this._buildNsPrefix(e)))}if("xmlns"===t){const e=n.name.toLowerCase();this._ns.get(e)||this._ns.set(e,null!=t?t:this._buildNsPrefix(e))}}_buildNsPrefix(e){let t,n=!1;do{t="ns"+this._prefixCount++;for(const e of Array.from(this._ns.values()))if(e===t){n=!0;break}}while(n);return t}}class Yn{}var Jn;Yn.OpenTag="<",Yn.CloseTag=">",Yn.Slash="/",Yn.Question="?",Yn.Quote='"',Yn.Equal="=",Yn.Space=" ",Yn.Semicolon=":",Yn.Dec="<?xml",Yn.Xml="xml",Yn.Xmlns="xmlns",Yn.Xsi="xsi",Yn.VersionKeyword="version",Yn.EncodingKeyword="encoding",Yn.StandaloneKeyword="standalone",e.TokenType=void 0,(Jn=e.TokenType||(e.TokenType={}))[Jn.Declaration=0]="Declaration",Jn[Jn.Tag=1]="Tag",Jn[Jn.Attribute=2]="Attribute",Jn[Jn.Text=3]="Text";class es{constructor(e){this._ctxStack=[],this._d=0,this._w=e}dec(e,t,n){return this._w.write(Yn.Dec),this._writeAttStr(Yn.VersionKeyword,e),t&&this._writeAttStr(Yn.EncodingKeyword,t),void 0!==n&&this._writeAttStr(Yn.StandaloneKeyword,n?"yes":"no"),this._w.write(Yn.Question,Yn.CloseTag),this}att(t,n,s){const r=this._peekContext();if(!r)throw new Error("att() without open element");if(r.closed)throw new Error(`att() after start tag closed for <${r.name}>`);if(this._isXmlnsDecl(t,n)){if(n===Yn.Xmlns)r.defaultNs=s,this._registerNamespace(r,"",s),this._writeAttStr(Yn.Xmlns,s);else if(t)this._registerNamespace(r,n,s),this._writeAttStr(`${t}:${n}`,s);else{const e=n.slice(6);this._registerNamespace(r,e,s),this._writeAttStr(n,s)}return r.lastToken=e.TokenType.Attribute,this}let i=n;return t&&(i=`${this._ensurePrefixDeclared(r,t)}:${n}`),r.lastToken=e.TokenType.Attribute,this._writeAttStr(i,s),this}ele(e,t){var n;const s=this._peekContext();s&&this._closeOpenTagIfNeeded(s);let r=t;return e&&(r=`${null!==(n=this._lookupPrefix(e))&&void 0!==n?n:e}:${t}`),this._pushContext(r,++this._d),this._w.write(Yn.OpenTag,r),this}text(t){const n=this._peekContext();if(!n)throw new Error("text() without open element");return this._closeOpenTagIfNeeded(n),n.lastToken=e.TokenType.Text,this._w.write(this._escText(t)),this}end(){const e=this._popContext();return e&&(this._d--,e.closed?this._w.write(Yn.OpenTag,Yn.Slash,e.name,Yn.CloseTag):this._w.write(Yn.Slash,Yn.CloseTag)),this}_pushContext(e,t){const n=new es.Context(e,t);return this._ctxStack.push(n),n}_popContext(){return this._ctxStack.pop()}_peekContext(){return this._ctxStack[this._ctxStack.length-1]}get _contextDepth(){return this._ctxStack.length}_writeAttStr(e,t){this._w.write(Yn.Space,e,Yn.Equal,Yn.Quote,this._escAttr(t),Yn.Quote)}_lookupPrefix(e){var t;let n=this._ctxStack.length-1;if(n>=0)do{const s=null===(t=this._ctxStack[n--].ns2prefix)||void 0===t?void 0:t.get(e);if(s)return s}while(n>=0)}_escText(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}_escAttr(e){return this._escText(e).replace(/"/g,""").replace(/'/g,"'")}_isXmlnsDecl(e,t){if(e)return e===Yn.Xmlns;const n=t.length,s=Yn.Xmlns.length;return n>=s&&t.startsWith(Yn.Xmlns)&&(t.length==s||t[s]==Yn.Semicolon)}_registerNamespace(e,t,n){if(t===Yn.Xml||t===Yn.Xmlns)throw new Error(`reserved prefix '${t}'`);const s=e.prefix2ns.get(t);if(s&&s!==n)throw new Error(`prefix '${t}' already bound to a different namespace`);e.ns2prefix.get(n)||e.ns2prefix.set(n,t),e.prefix2ns.set(t,n)}_allocPrefix(e){let t=1;for(;;){const n="ns"+t++;if(!e.prefix2ns.has(n))return n}}_ensurePrefixDeclared(e,t){const n=this._lookupPrefix(t);if(n)return n;if(e.closed)throw new Error(`can not declare namespace after start tag closed for <${e.name}>`);const s=this._allocPrefix(e);return this._writeAttStr(`${Yn.Xmlns}:${s}`,t),this._registerNamespace(e,s,t),s}_closeOpenTagIfNeeded(e){e.closed||(this._w.write(Yn.CloseTag),e.closed=!0)}}es.Context=class{constructor(e,t){this.name="",this.closed=!1,this.lastToken=null,this.ns2prefix=new Map,this.prefix2ns=new Map,this.defaultNs=null,this.name=e,this.depth=t}};class ts{constructor(){this.count=0,this._chunks=[]}write(...e){if(0===e.length)return this;const t=e.join("");return this._chunks.push(t),this.count+=t.length,this}toString(){return this._chunks.join("")}clear(){this._chunks=[],this.count=0}}class ns{constructor(e,t={}){this._sink=e,this._opts=t,this.count=0,this._encoder=new TextEncoder,this._pending="",this._pendingChars=0}write(...e){var t;if(0===e.length)return this;const n=e.join("");if(0===n.length)return this;this._pending+=n,this._pendingChars+=n.length;const s=null!==(t=this._opts.flushChars)&&void 0!==t?t:65536;return this._pendingChars>=s&&this.flush(),this}flush(){if(0===this._pendingChars)return this;const e=this._encoder.encode(this._pending);return this._sink.push(e),this.count+=e.length,this._pending="",this._pendingChars=0,this}finish(){this.flush(),this._sink.push(new Uint8Array(0),!0)}clear(){this._pending="",this._pendingChars=0,this.count=0}}const ss="http://schemas.microsoft.com/3dmanufacturing/core/2015/02",rs="http://schemas.microsoft.com/3dmanufacturing/trianglesets/2021/07";var is,os;e.ST_Unit=void 0,(is=e.ST_Unit||(e.ST_Unit={})).micron="micron",is.millimeter="millimeter",is.centimeter="centimeter",is.inch="inch",is.foot="foot",is.meter="meter",e.ST_ObjectType=void 0,(os=e.ST_ObjectType||(e.ST_ObjectType={})).model="model",os.solidsupport="solidsupport",os.support="support",os.surface="surface",os.other="other";const as="http://schemas.openxmlformats.org/package/2006/content-types",ls="http://schemas.openxmlformats.org/package/2006/relationships";var us;e.KnownI3mfContentType=void 0,(us=e.KnownI3mfContentType||(e.KnownI3mfContentType={})).Relationships="application/vnd.openxmlformats-package.relationships+xml",us.Model="application/vnd.ms-package.3dmanufacturing-3dmodel+xml",us.Materials="application/vnd.ms-package.3dmanufacturing-material+xml",us.Colors="application/vnd.ms-package.3dmanufacturing-colors+xml",us.Texture="application/vnd.ms-package.3dmanufacturing-texture+xml",us.Texture2D="application/vnd.ms-package.3dmanufacturing-texture2d+xml",us.Production="application/vnd.ms-package.3dmanufacturing-production+xml",us.Slice="application/vnd.ms-package.3dmanufacturing-slice+xml",us.BeamLattice="application/vnd.ms-package.3dmanufacturing-beamlattice+xml",us.SecureContent="application/vnd.ms-package.3dmanufacturing-securecontent+xml",us.Png="image/png",us.Jpeg="image/jpeg",us.Tiff="image/tiff",us.Xml="application/xml";const cs="_rels/",hs="3D/",ds="3dmodel.model",fs=".rels",ps="[Content_Types].xml";class ms{static IsKnown(e){return ms.Known.has(e)}static IsThreeDimModel(e){return e===ms.ThreeDimModel}}ms.ThreeDimModel="http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel",ms.Thumbnail="http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail",ms.PrintTicket="http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket",ms.MustPreserve="http://schemas.openxmlformats.org/package/2006/relationships/mustpreserve",ms.Known=new Set([ms.ThreeDimModel,ms.Thumbnail,ms.PrintTicket,ms.MustPreserve]);let gs=(()=>{let e,t,n=[Fn({ns:as,name:"Types"})],s=[];return t=class{constructor(){this.items=[]}},u(t,"ThreeMfContentTypes"),(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;a(null,e={value:t},n,{kind:"class",name:t.name,metadata:r},null,s),t=e.value,r&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),l(t,s)})(),t})(),xs=(()=>{let e,t,n,s,r=[Fn({ns:as,name:"Default"})],i=[],o=[],c=[],h=[],d=[];return t=class{constructor(e,t){this.ext=l(this,o,void 0),this.ct=(l(this,c),l(this,h,void 0)),l(this,d),this.ext=e,this.ct=t}},u(t,"ThreeMfContentType"),(()=>{const u="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;n=[Bn({name:{ns:as,name:"Extension"}})],s=[Bn({name:{ns:as,name:"ContentType"}})],a(null,null,n,{kind:"field",name:"ext",static:!1,private:!1,access:{has:e=>"ext"in e,get:e=>e.ext,set:(e,t)=>{e.ext=t}},metadata:u},o,c),a(null,null,s,{kind:"field",name:"ct",static:!1,private:!1,access:{has:e=>"ct"in e,get:e=>e.ct,set:(e,t)=>{e.ct=t}},metadata:u},h,d),a(null,e={value:t},r,{kind:"class",name:t.name,metadata:u},null,i),t=e.value,u&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:u}),l(t,i)})(),t})(),_s=(()=>{let e,t,n=[Fn({ns:ls,name:"Relationships"})],s=[];return t=class{constructor(){this.items=[]}},u(t,"ThreeMfRelationships"),(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;a(null,e={value:t},n,{kind:"class",name:t.name,metadata:r},null,s),t=e.value,r&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),l(t,s)})(),t})(),Ts=(()=>{let e,t,n,s,r,i=[Fn({ns:ls,name:"Relationship"})],o=[],c=[],h=[],d=[],f=[],p=[],m=[];return t=class{constructor(e,t,n){this.id=l(this,c,void 0),this.type=(l(this,h),l(this,d,void 0)),this.target=(l(this,f),l(this,p,void 0)),l(this,m),this.id=e,this.type=t,this.target=n}},u(t,"ThreeMfRelationship"),(()=>{const u="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;n=[Bn({name:"Id"})],s=[Bn({name:"Type"})],r=[Bn({name:"Target"})],a(null,null,n,{kind:"field",name:"id",static:!1,private:!1,access:{has:e=>"id"in e,get:e=>e.id,set:(e,t)=>{e.id=t}},metadata:u},c,h),a(null,null,s,{kind:"field",name:"type",static:!1,private:!1,access:{has:e=>"type"in e,get:e=>e.type,set:(e,t)=>{e.type=t}},metadata:u},d,f),a(null,null,r,{kind:"field",name:"target",static:!1,private:!1,access:{has:e=>"target"in e,get:e=>e.target,set:(e,t)=>{e.target=t}},metadata:u},p,m),a(null,e={value:t},i,{kind:"class",name:t.name,metadata:u},null,o),t=e.value,u&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:u}),l(t,o)})(),t})();class ys{constructor(e,t,n){this.contentTypes=e,this.relationships=t,this.model=n}}class bs{static Zero(){return new bs([0,0,0,0,0,0,0,0,0,0,0,0])}constructor(e){this.values=e}toString(){return this.values.join(" ")}}class vs{constructor(e){this.o=e,this._f=new Hn(e)}toString(e){return e.values.map(e=>this._f.toString(e)).join(" ")}}let Ms=(()=>{let t,n,s,r,i,o=[Fn({ns:ss,name:"model"})],c=[],h=[],d=[],f=[],p=[],m=[],g=[];return n=class{constructor(){this.unit=l(this,h,e.ST_Unit.millimeter),this.requiredextensions=(l(this,d),l(this,f,void 0)),this.recommendedextensions=(l(this,p),l(this,m,void 0)),this.metadata=l(this,g)}},u(n,"ThreeMfModel"),(()=>{const e="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;s=[Bn({name:"unit"})],r=[Bn({name:"requiredextensions"})],i=[Bn({name:"recommendedextensions"})],a(null,null,s,{kind:"field",name:"unit",static:!1,private:!1,access:{has:e=>"unit"in e,get:e=>e.unit,set:(e,t)=>{e.unit=t}},metadata:e},h,d),a(null,null,r,{kind:"field",name:"requiredextensions",static:!1,private:!1,access:{has:e=>"requiredextensions"in e,get:e=>e.requiredextensions,set:(e,t)=>{e.requiredextensions=t}},metadata:e},f,p),a(null,null,i,{kind:"field",name:"recommendedextensions",static:!1,private:!1,access:{has:e=>"recommendedextensions"in e,get:e=>e.recommendedextensions,set:(e,t)=>{e.recommendedextensions=t}},metadata:e},m,g),a(null,t={value:n},o,{kind:"class",name:n.name,metadata:e},null,c),n=t.value,e&&Object.defineProperty(n,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:e})})(),n.KnownMeta=["Title","Designer","Description","Copyright","LicenseTerms","Rating","CreationDate","ModificationDate","Application"],l(n,c),n})(),ws=(()=>{let e,t,n,s,r,i=[Fn({ns:ss,name:"meta"})],o=[],c=[],h=[],d=[],f=[],p=[],m=[];return t=class{constructor(e,t,n,s){this.name=l(this,c,void 0),this.preserve=(l(this,h),l(this,d,void 0)),this.type=(l(this,f),l(this,p,void 0)),this.value=l(this,m),this.name=e,this.value=t,this.preserve=n,this.type=s}},u(t,"ThreeMfMeta"),(()=>{const u="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;n=[Bn({name:"name"})],s=[Bn({name:"preserve"})],r=[Bn({name:"type"})],a(null,null,n,{kind:"field",name:"name",static:!1,private:!1,access:{has:e=>"name"in e,get:e=>e.name,set:(e,t)=>{e.name=t}},metadata:u},c,h),a(null,null,s,{kind:"field",name:"preserve",static:!1,private:!1,access:{has:e=>"preserve"in e,get:e=>e.preserve,set:(e,t)=>{e.preserve=t}},metadata:u},d,f),a(null,null,r,{kind:"field",name:"type",static:!1,private:!1,access:{has:e=>"type"in e,get:e=>e.type,set:(e,t)=>{e.type=t}},metadata:u},p,m),a(null,e={value:t},i,{kind:"class",name:t.name,metadata:u},null,o),t=e.value,u&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:u}),l(t,o)})(),t})(),Rs=(()=>{let e,t,n=[Fn({ns:ss,name:"metadatagroup"})],s=[];return t=class{constructor(){this.metadata=[]}},u(t,"ThreeMfMetadataGroup"),(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;a(null,e={value:t},n,{kind:"class",name:t.name,metadata:r},null,s),t=e.value,r&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),l(t,s)})(),t})(),As=(()=>{let e,t,n=[Fn({ns:ss,name:"resources"})],s=[];return t=class{constructor(){this.object=[]}},u(t,"ThreeMfResources"),(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;a(null,e={value:t},n,{kind:"class",name:t.name,metadata:r},null,s),t=e.value,r&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),l(t,s)})(),t})(),Cs=(()=>{let t,n,s,r,i,o,c,h,d,f=[Fn({ns:ss,name:"object"})],p=[],m=[],g=[],x=[],_=[],T=[],y=[],b=[],v=[],M=[],w=[],R=[],A=[],C=[],E=[];return n=class{constructor(t,n=e.ST_ObjectType.model){this.id=l(this,m,void 0),this.type=(l(this,g),l(this,x,void 0)),this.thumbnail=(l(this,_),l(this,T,void 0)),this.partnumber=(l(this,y),l(this,b,void 0)),this.name=(l(this,v),l(this,M,void 0)),this.pid=(l(this,w),l(this,R,void 0)),this.pindex=(l(this,A),l(this,C,void 0)),this.metadatagroup=l(this,E),this.id=t,this.type=n}},u(n,"ThreeMfObject"),(()=>{const e="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;s=[Bn({name:"id"})],r=[Bn({name:"type"})],i=[Bn({name:"thumbnail"})],o=[Bn({name:"partnumber"})],c=[Bn({name:"name"})],h=[Bn({name:"pid"})],d=[Bn({name:"pindex"})],a(null,null,s,{kind:"field",name:"id",static:!1,private:!1,access:{has:e=>"id"in e,get:e=>e.id,set:(e,t)=>{e.id=t}},metadata:e},m,g),a(null,null,r,{kind:"field",name:"type",static:!1,private:!1,access:{has:e=>"type"in e,get:e=>e.type,set:(e,t)=>{e.type=t}},metadata:e},x,_),a(null,null,i,{kind:"field",name:"thumbnail",static:!1,private:!1,access:{has:e=>"thumbnail"in e,get:e=>e.thumbnail,set:(e,t)=>{e.thumbnail=t}},metadata:e},T,y),a(null,null,o,{kind:"field",name:"partnumber",static:!1,private:!1,access:{has:e=>"partnumber"in e,get:e=>e.partnumber,set:(e,t)=>{e.partnumber=t}},metadata:e},b,v),a(null,null,c,{kind:"field",name:"name",static:!1,private:!1,access:{has:e=>"name"in e,get:e=>e.name,set:(e,t)=>{e.name=t}},metadata:e},M,w),a(null,null,h,{kind:"field",name:"pid",static:!1,private:!1,access:{has:e=>"pid"in e,get:e=>e.pid,set:(e,t)=>{e.pid=t}},metadata:e},R,A),a(null,null,d,{kind:"field",name:"pindex",static:!1,private:!1,access:{has:e=>"pindex"in e,get:e=>e.pindex,set:(e,t)=>{e.pindex=t}},metadata:e},C,E),a(null,t={value:n},f,{kind:"class",name:n.name,metadata:e},null,p),n=t.value,e&&Object.defineProperty(n,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:e}),l(n,p)})(),n})(),Es=(()=>{let e,t,n=[Fn({ns:ss,name:"mesh"})],s=[];return t=class{constructor(e,t){this.vertices=null!=e?e:new Is,this.triangles=null!=t?t:new Vs}},u(t,"ThreeMfMesh"),(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;a(null,e={value:t},n,{kind:"class",name:t.name,metadata:r},null,s),t=e.value,r&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),l(t,s)})(),t})(),Is=(()=>{let e,t,n=[Fn({ns:ss,name:"vertices"})],s=[];return t=class{constructor(){this.vertex=[]}},u(t,"ThreeMfVertices"),(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;a(null,e={value:t},n,{kind:"class",name:t.name,metadata:r},null,s),t=e.value,r&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),l(t,s)})(),t})(),Ss=(()=>{let e,t,n,s,r,i=[Fn({ns:ss,name:"vertex"})],o=[],c=[],h=[],d=[],f=[],p=[],m=[];return t=class{constructor(e=0,t=0,n=0){this.x=l(this,c,void 0),this.y=(l(this,h),l(this,d,void 0)),this.z=(l(this,f),l(this,p,void 0)),l(this,m),this.x=e,this.y=t,this.z=n}},u(t,"ThreeMfVertex"),(()=>{const u="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;n=[Bn({name:"x"})],s=[Bn({name:"y"})],r=[Bn({name:"z"})],a(null,null,n,{kind:"field",name:"x",static:!1,private:!1,access:{has:e=>"x"in e,get:e=>e.x,set:(e,t)=>{e.x=t}},metadata:u},c,h),a(null,null,s,{kind:"field",name:"y",static:!1,private:!1,access:{has:e=>"y"in e,get:e=>e.y,set:(e,t)=>{e.y=t}},metadata:u},d,f),a(null,null,r,{kind:"field",name:"z",static:!1,private:!1,access:{has:e=>"z"in e,get:e=>e.z,set:(e,t)=>{e.z=t}},metadata:u},p,m),a(null,e={value:t},i,{kind:"class",name:t.name,metadata:u},null,o),t=e.value,u&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:u}),l(t,o)})(),t})(),Vs=(()=>{let e,t,n=[Fn({ns:ss,name:"triangles"})],s=[];return t=class{constructor(){this.triangle=[]}},u(t,"ThreeMfTriangles"),(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;a(null,e={value:t},n,{kind:"class",name:t.name,metadata:r},null,s),t=e.value,r&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),l(t,s)})(),t})(),Fs=(()=>{let e,t,n,s,r,i,o,c,h,d=[Fn({ns:ss,name:"triangle"})],f=[],p=[],m=[],g=[],x=[],_=[],T=[],y=[],b=[],v=[],M=[],w=[],R=[],A=[],C=[];return t=class{constructor(e,t,n){this.v1=l(this,p,void 0),this.v2=(l(this,m),l(this,g,void 0)),this.v3=(l(this,x),l(this,_,void 0)),this.p1=(l(this,T),l(this,y,void 0)),this.p2=(l(this,b),l(this,v,void 0)),this.p3=(l(this,M),l(this,w,void 0)),this.pid=(l(this,R),l(this,A,void 0)),l(this,C),this.v1=e,this.v2=t,this.v3=n}},u(t,"ThreeMfTriangle"),(()=>{const u="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;n=[Bn({name:"v1"})],s=[Bn({name:"v2"})],r=[Bn({name:"v3"})],i=[Bn({name:"p1"})],o=[Bn({name:"p2"})],c=[Bn({name:"p3"})],h=[Bn({name:"pid"})],a(null,null,n,{kind:"field",name:"v1",static:!1,private:!1,access:{has:e=>"v1"in e,get:e=>e.v1,set:(e,t)=>{e.v1=t}},metadata:u},p,m),a(null,null,s,{kind:"field",name:"v2",static:!1,private:!1,access:{has:e=>"v2"in e,get:e=>e.v2,set:(e,t)=>{e.v2=t}},metadata:u},g,x),a(null,null,r,{kind:"field",name:"v3",static:!1,private:!1,access:{has:e=>"v3"in e,get:e=>e.v3,set:(e,t)=>{e.v3=t}},metadata:u},_,T),a(null,null,i,{kind:"field",name:"p1",static:!1,private:!1,access:{has:e=>"p1"in e,get:e=>e.p1,set:(e,t)=>{e.p1=t}},metadata:u},y,b),a(null,null,o,{kind:"field",name:"p2",static:!1,private:!1,access:{has:e=>"p2"in e,get:e=>e.p2,set:(e,t)=>{e.p2=t}},metadata:u},v,M),a(null,null,c,{kind:"field",name:"p3",static:!1,private:!1,access:{has:e=>"p3"in e,get:e=>e.p3,set:(e,t)=>{e.p3=t}},metadata:u},w,R),a(null,null,h,{kind:"field",name:"pid",static:!1,private:!1,access:{has:e=>"pid"in e,get:e=>e.pid,set:(e,t)=>{e.pid=t}},metadata:u},A,C),a(null,e={value:t},d,{kind:"class",name:t.name,metadata:u},null,f),t=e.value,u&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:u}),l(t,f)})(),t})(),Os=(()=>{let e,t,n=[Fn({ns:ss,name:"components"})],s=[];return t=class{constructor(){this.component=[]}},u(t,"ThreeMfComponents"),(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;a(null,e={value:t},n,{kind:"class",name:t.name,metadata:r},null,s),t=e.value,r&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),l(t,s)})(),t})(),Bs=(()=>{let e,t,n,s,r=[Fn({ns:ss,name:"component"})],i=[],o=[],c=[],h=[],d=[];return t=class{constructor(e,t){this.objectid=l(this,o,void 0),this.transform=(l(this,c),l(this,h,void 0)),l(this,d),this.objectid=e,this.transform=t}},u(t,"ThreeMfComponent"),(()=>{const u="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;n=[Bn({name:"objectid"})],s=[Bn({name:"transform",formatter:vs})],a(null,null,n,{kind:"field",name:"objectid",static:!1,private:!1,access:{has:e=>"objectid"in e,get:e=>e.objectid,set:(e,t)=>{e.objectid=t}},metadata:u},o,c),a(null,null,s,{kind:"field",name:"transform",static:!1,private:!1,access:{has:e=>"transform"in e,get:e=>e.transform,set:(e,t)=>{e.transform=t}},metadata:u},h,d),a(null,e={value:t},r,{kind:"class",name:t.name,metadata:u},null,i),t=e.value,u&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:u}),l(t,i)})(),t})(),Ns=(()=>{let e,t,n,s=[Fn({ns:ss,name:"basematerials"})],r=[],i=[],o=[];return t=class{constructor(e){this.id=l(this,i,void 0),this.base=(l(this,o),[]),this.id=e}},u(t,"ThreeMfBaseMaterials"),(()=>{const u="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;n=[Bn({name:"id"})],a(null,null,n,{kind:"field",name:"id",static:!1,private:!1,access:{has:e=>"id"in e,get:e=>e.id,set:(e,t)=>{e.id=t}},metadata:u},i,o),a(null,e={value:t},s,{kind:"class",name:t.name,metadata:u},null,r),t=e.value,u&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:u}),l(t,r)})(),t})(),Ps=(()=>{let e,t,n,s,r=[Fn({ns:ss,name:"base"})],i=[],o=[],c=[],h=[],d=[];return t=class{constructor(e,t){this.name=l(this,o,void 0),this.displaycolor=(l(this,c),l(this,h,void 0)),l(this,d),this.name=e,this.displaycolor=t}},u(t,"ThreeMfBase"),(()=>{const u="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;n=[Bn({name:"name"})],s=[Bn({name:"displaycolor"})],a(null,null,n,{kind:"field",name:"name",static:!1,private:!1,access:{has:e=>"name"in e,get:e=>e.name,set:(e,t)=>{e.name=t}},metadata:u},o,c),a(null,null,s,{kind:"field",name:"displaycolor",static:!1,private:!1,access:{has:e=>"displaycolor"in e,get:e=>e.displaycolor,set:(e,t)=>{e.displaycolor=t}},metadata:u},h,d),a(null,e={value:t},r,{kind:"class",name:t.name,metadata:u},null,i),t=e.value,u&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:u}),l(t,i)})(),t})(),Us=(()=>{let e,t,n=[Fn({ns:ss,name:"build"})],s=[];return t=class{constructor(){this.item=[]}},u(t,"ThreeMfBuild"),(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;a(null,e={value:t},n,{kind:"class",name:t.name,metadata:r},null,s),t=e.value,r&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),l(t,s)})(),t})(),ks=(()=>{let e,t,n,s,r,i=[Fn({ns:ss,name:"item"})],o=[],c=[],h=[],d=[],f=[],p=[],m=[];return t=class{constructor(e,t,n){this.objectid=l(this,c,void 0),this.transform=(l(this,h),l(this,d,void 0)),this.partnumber=(l(this,f),l(this,p,void 0)),this.metadatagroup=l(this,m),this.objectid=e,this.transform=t,this.partnumber=n}},u(t,"ThreeMfItem"),(()=>{const u="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;n=[Bn({name:"objectid"})],s=[Bn({name:"transform",formatter:vs})],r=[Bn({name:"partnumber"})],a(null,null,n,{kind:"field",name:"objectid",static:!1,private:!1,access:{has:e=>"objectid"in e,get:e=>e.objectid,set:(e,t)=>{e.objectid=t}},metadata:u},c,h),a(null,null,s,{kind:"field",name:"transform",static:!1,private:!1,access:{has:e=>"transform"in e,get:e=>e.transform,set:(e,t)=>{e.transform=t}},metadata:u},d,f),a(null,null,r,{kind:"field",name:"partnumber",static:!1,private:!1,access:{has:e=>"partnumber"in e,get:e=>e.partnumber,set:(e,t)=>{e.partnumber=t}},metadata:u},p,m),a(null,e={value:t},i,{kind:"class",name:t.name,metadata:u},null,o),t=e.value,u&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:u}),l(t,o)})(),t})();class Ks{constructor(e,t){this._object=new Cs(e,t)}withName(e){return this._object.name=e,this}withThumbnail(e){return this._object.thumbnail=e,this}withProperty(e,t=0){return this._object.pid=e,this._object.id=t,this}build(){return this._object}reset(e,t){this._object=new Cs(e,t)}}class $s extends Ks{constructor(t,n=e.ST_ObjectType.model){super(t,n),this._object.content=new Os}withComponent(e,t){return this._object.content.component.push(new Bs(e,t)),this}}class zs extends Ks{constructor(t){super(t,e.ST_ObjectType.model)}withPostProcessHandlers(e,t){return this._vh=e,this._th=t,this}withData(e){return this._object.content=this._buildMesh(e),this}withMaterial(e,t){return this._object.pid=e,this._object.pindex=t,this}_buildMesh(e){const t=this._buildVertices(e.positions),n=this._buildTriangle(e.indices);return new Es(t,n)}_buildVertices(e){const t=new Is;if(e)for(let n=0;n<e.length;){const s=e[n++],r=e[n++],i=e[n++];let o=new Ss(s,r,i);this._vh&&(o=this._vh(o)),t.vertex.push(o)}return t}_buildTriangle(e){const t=new Vs;if(e)for(let n=0;n<e.length;){const s=e[n++],r=e[n++],i=e[n++];let o=new Fs(s,r,i);this._th&&(o=this._th(o)),t.triangle.push(o)}return t}}class Ws{constructor(e){this._m=new Ns(e)}withColor(e,t){var n;this._m.base=null!==(n=this._m.base)&&void 0!==n?n:[];let s=this._m.base.find(t=>t.name.toLowerCase()===e.toLowerCase());return s?(s.displaycolor=this._rgbaToHex(t),this):(s=new Ps(e,this._rgbaToHex(t)),this._m.base.push(s),this)}build(){return this._m}_rgbaToHex(e){const t=e=>Math.round(Math.min(255,Math.max(0,255*Math.pow(e,1/2.2)))),n=t(e.r).toString(16).padStart(2,"0").toUpperCase(),s=t(e.g).toString(16).padStart(2,"0").toUpperCase(),r=t(e.b).toString(16).padStart(2,"0").toUpperCase();return"number"==typeof e.a?`#${n}${s}${r}${Math.round(Math.min(255,Math.max(0,255*e.a))).toString(16).padStart(2,"0").toUpperCase()}`:`#${n}${s}${r}`}}class Ds{constructor(){this._model=new Ms,this._objects=new Map}withMetaData(e,t,n,s){return this._model.metadata||(this._model.metadata=new Array),this._model.metadata.push(new ws(e,t,n,s)),this}withMaterial(e){var t,n;return e instanceof Ws&&(e=e.build()),e&&(this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new As,this._model.resources.basematerials=null!==(n=this._model.resources.basematerials)&&void 0!==n?n:[],this._model.resources.basematerials.push(e)),this}withMesh(e){var t;return e instanceof zs&&(e=e.build()),this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new As,this._model.resources.object.push(e),this}withComponents(e){var t;return e instanceof $s&&(e=e.build()),this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new As,this._model.resources.object.push(e),this}withBuild(e,t,n){var s,r;return this._model.build=null!==(s=this._model.build)&&void 0!==s?s:new Us,null===(r=this._model.build.item)||void 0===r||r.push(new ks(e,t,n)),this}withUnit(e){return this._model.unit=e,this}reset(){return this._model=new Ms,this._objects=new Map,this}build(){var e,t,n,s;if(!(null===(t=null===(e=this._model.resources)||void 0===e?void 0:e.object)||void 0===t?void 0:t.length))throw new Error("Invalid state: resources MUST be defined ");if(!(null===(s=null===(n=this._model.build)||void 0===n?void 0:n.item)||void 0===s?void 0:s.length))throw new Error("Invalid state: Build MUST be defined ");return this._model}}Ds.KnownMetaSet=new Set(Ms.KnownMeta.map(e=>e.toLowerCase()));class Ls{withContentType(e){this._cts||(this._cts=new gs);const t=this._cts.items;return t.some(t=>t.ext===e.ext&&t.ct===e.ct)||t.push(e),this}withRelationship(t){this._rs||(this._rs=new _s);const n=this._rs.items;return n.some(e=>e.id===t.id)||n.push(t),this.withContentType(new xs("rels",e.KnownI3mfContentType.Relationships)),this}withModel(t){return t instanceof Ds&&(t=t.build()),this._m=t,this.withContentType(new xs("model",e.KnownI3mfContentType.Model)),this}build(){if(!this._m)throw new Error("Invalid state: you Must provide at least a model.");const e=`${hs}${ds}`;if(!this._rs){const t=`/${e}`;this.withRelationship(new Ts("rel0",ms.ThreeDimModel,t))}return new ys(this._cts,this._rs,this._m)}}class Hs{constructor(e){this._o=e}get options(){return this._o}serializeAsync(e,...t){return c(this,void 0,void 0,function*(){const n=yield this.ensureZipLibReadyAsync();if(!n)return;const s=n.Zip,r=n.ZipDeflate;if(!s||!r)throw new Error("fflate Zip / ZipDeflate not available");const i=function(e,t,n){const s=new r(t,{level:6});e.add(s);const i=function(e){return{push:(t,n)=>e.push(t,n)}}(s),o=new ns(i),a=new es(o).dec("1.0","UTF-8");new Zn(a).serialize(n),o.finish()},o=this.toDocument(...t);if(!o)return;const a=new s(e);i(a,ps,o.contentTypes),i(a,`${cs}${fs}`,o.relationships),i(a,`${hs}${ds}`,o.model),a.end()})}toDocument(...t){var n,s;const r=(new Ds).withUnit(null!==(s=null===(n=this._o)||void 0===n?void 0:n.unit)&&void 0!==s?s:e.ST_Unit.millimeter);if(this.options.metadata)for(const e in this.options.metadata)r.withMetaData(e,this.options.metadata[e]);return(new Ls).withModel(this.toModel(r,...t)).build()}}class js{static SerializeToMemoryAsync(e,...t){return c(this,void 0,void 0,function*(){const n=new Array;let s=0;if(yield e.serializeAsync(function(e,t,r){n.push(t),s+=t.length},...t),!s)return;const r=new Uint8Array(s);let i=0;for(const e of n)r.set(e,i),i+=e.length;return r})}}class qs{}qs.FFLATEUrl="https://unpkg.com/fflate@0.8.2";class Gs{constructor(e=0,t=Number.MIN_SAFE_INTEGER,n=1){this._from=e,this._to=t,this._step=n,this._i=e}next(){if(this._i<this._to)throw new Error("ST_ResourceID out of bound");const e=this._i;return this._i+=this._step,e}reset(){return this._i=this._from,this}}class Xs extends Hs{constructor(e={}){super(Object.assign(Object.assign({},Xs.DefaultOptions),e))}toModel(e,...n){n=n.filter(e=>e instanceof t.Mesh||e instanceof t.InstancedMesh);const s=new Gs,r=e,i=new Map,o=this.options.exportInstances?[]:null;for(let e=0;e<n.length;e++){const a=n[e];if(a instanceof t.InstancedMesh){null==o||o.push(a);continue}const l=a.name||`mesh${e}`,u=a.getWorldMatrix(),c=this._handleBabylonTo3mfMatrixTransformToRef(u,bs.Zero()),h=a.subMeshes;if(void 0===h)continue;const d=1==h.length;for(let e=0;e<h.length;e++){const t=h[e],n=this._extractSubMesh(a,t);if(n){const o=d?`${l}`:`${l}_${e}`,a=new zs(s.next()).withData(n).withName(o).build();r.withMesh(a),r.withBuild(a.id,c),i.set(t,a)}}}if(o&&o.length){const e=this._groupBy(o,e=>e.sourceMesh);for(const[t,n]of Array.from(e.entries()))if(n&&n.length)for(let e=0;e<n.length;e++){const s=n[e].getWorldMatrix(),o=t.subMeshes;for(let e=0;e<o.length;e++){const t=o[e],n=i.get(t);n&&r.withBuild(n.id,this._handleBabylonTo3mfMatrixTransformToRef(s,bs.Zero()))}}}return r.build()}ensureZipLibReadyAsync(){return c(this,void 0,void 0,function*(){return this._fflateReadyPromise||(this._fflateReadyPromise=(()=>c(this,void 0,void 0,function*(){const e=globalThis;return e.fflate||(yield t.Tools.LoadScriptAsync(qs.FFLATEUrl)),e.fflate}))()),yield this._fflateReadyPromise})}_extractSubMesh(e,t){const n=e.getIndices();if(!n)return;const s=e.getVerticesData(Xs._PositionKind);if(!s)return;if(0==t.indexStart&&t.indexCount==n.length)return{positions:s,indices:n};const r=t.indexStart,i=new Map,o=[],a=new Uint32Array(t.indexCount);for(let e=0;e<t.indexCount;e++){const t=n[r+e];let l=i.get(t);if(void 0===l){l=i.size,i.set(t,l);const e=3*t;o.push(s[e],s[e+1],s[e+2])}a[e]=l}return{positions:new Float32Array(o),indices:a}}_groupBy(e,t){const n=new Map;for(const s of e){const e=t(s),r=n.get(e);r?r.push(s):n.set(e,[s])}return n}_handleBabylonTo3mfMatrixTransformToRef(e,n){const s=e.multiplyToRef(Xs._R_BJS_TO_3MF,t.Matrix.Zero()).m;return n.values=[s[0],s[1],s[2],s[4],s[5],s[6],s[8],s[9],s[10],s[12],s[13],s[14]],n}}Xs.DefaultOptions={unit:e.ST_Unit.meter,exportInstances:!1},Xs._PositionKind="position",Xs._R_BJS_TO_3MF=t.Matrix.RotationX(Math.PI/2).multiply(t.Matrix.Scaling(1,-1,1));var Qs={__proto__:null,AbstractThreeMfSerializer:Hs,ContentTypeFileName:ps,DefaultXmlSerializerFormatOptions:Wn,DefaultXmlSerializerNumberOptions:zn,GetXmlFieldMeta:Pn,GetXmlName:Un,IsQualifiedName:En,Known3mfRelationshipTypes:ms,get KnownI3mfContentType(){return e.KnownI3mfContentType},Matrix3d:bs,MatrixFormatter:vs,ModelFileName:ds,NumberFormatter:Hn,Object3dDirName:hs,OpenXmlContentTypesNamespace:as,OpenXmlRelationshipsNamespace:ls,RelationshipDirName:cs,RelationshipFileName:fs,ResolveFormatOptions:Ln,ResolveNumberOptions:Dn,get ST_ObjectType(){return e.ST_ObjectType},get ST_Unit(){return e.ST_Unit},StringXmlWriter:ts,ThreeDimModelNamespace:ss,ThreeMf:js,ThreeMfBase:Ps,ThreeMfBaseMaterials:Ns,ThreeMfBuild:Us,ThreeMfComponent:Bs,ThreeMfComponents:Os,ThreeMfComponentsBuilder:$s,ThreeMfContentType:xs,ThreeMfContentTypes:gs,ThreeMfDocument:ys,ThreeMfDocumentBuilder:Ls,ThreeMfItem:ks,ThreeMfMaterialBuilder:Ws,ThreeMfMesh:Es,ThreeMfMeshBuilder:zs,ThreeMfMeta:ws,ThreeMfMetadataGroup:Rs,ThreeMfModel:Ms,ThreeMfModelBuilder:Ds,ThreeMfObject:Cs,ThreeMfObjectBuilder:Ks,ThreeMfRelationship:Ts,ThreeMfRelationships:_s,ThreeMfResources:As,ThreeMfSerializer:Xs,ThreeMfSerializerGlobalConfiguration:qs,ThreeMfTriangle:Fs,ThreeMfTriangles:Vs,ThreeMfVertex:Ss,ThreeMfVertices:Is,ToQualifiedString:$n,get TokenType(){return e.TokenType},TriangleSetsNamespace:rs,Utf8XmlWriterToBytes:ns,XmlAttr:Bn,XmlBuilder:es,XmlElem:Nn,XmlIgnore:On,XmlName:Fn,XmlNameToParts:Kn,XmlSerializer:Zn};const Zs="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==Zs)for(const e in Cn)Zs.BABYLON[e]=Cn[e];const Ys="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==Ys){Ys.BABYLON=Ys.BABYLON||{};const e=Ys.BABYLON;e.GLTF2=e.GLTF2||{},e.GLTF2.Exporter=e.GLTF2.Exporter||{},e.GLTF2.Exporter.Extensions=e.GLTF2.Exporter.Extensions||{};const t=[];for(const n in r)e[n]=r[n],t.push(n);for(const n in o)e[n]=o[n],t.push(n);for(const n in J)e[n]=J[n],t.push(n);for(const n in on)e.GLTF2.Exporter.Extensions[n]=on[n],t.push(n);for(const n in an)t.indexOf(n)>-1||(e.GLTF2.Exporter[n]=an[n])}const Js="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==Js)for(const e in s)Js.BABYLON[e]=s[e];const er="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==er)for(const e in un)er.BABYLON[e]=un[e];const tr="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==tr)for(const e in Rn)tr.BABYLON[e]=Rn[e];const nr="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==nr){const e=[];for(const t in Qs)e.indexOf(t)>-1||(nr.BABYLON[t]=Qs[t],e.push(t))}e.AbstractThreeMfSerializer=Hs,e.BVHExporter=An,e.ContentTypeFileName=ps,e.DefaultXmlSerializerFormatOptions=Wn,e.DefaultXmlSerializerNumberOptions=zn,e.EXT_lights_area=be,e.EXT_mesh_gpu_instancing=ne,e.EXT_texture_avif=nn,e.EXT_texture_webp=Yt,e.GLTF2Export=Y,e.GLTFData=i,e.GetXmlFieldMeta=Pn,e.GetXmlName=Un,e.IsQualifiedName=En,e.KHR_draco_mesh_compression=ae,e.KHR_lights_punctual=pe,e.KHR_materials_anisotropy=Re,e.KHR_materials_clearcoat=Se,e.KHR_materials_coat=Pe,e.KHR_materials_diffuse_roughness=Pt,e.KHR_materials_diffuse_transmission=ze,e.KHR_materials_dispersion=He,e.KHR_materials_emissive_strength=Xe,e.KHR_materials_fuzz=dt,e.KHR_materials_ior=Je,e.KHR_materials_iridescence=st,e.KHR_materials_openpbr=$t,e.KHR_materials_sheen=at,e.KHR_materials_specular=gt,e.KHR_materials_transmission=yt,e.KHR_materials_unlit=wt,e.KHR_materials_volume=Et,e.KHR_materials_volume_scatter=Ft,e.KHR_texture_basisu=Gt,e.KHR_texture_transform=Lt,e.Known3mfRelationshipTypes=ms,e.Matrix3d=bs,e.MatrixFormatter=vs,e.ModelFileName=ds,e.NumberFormatter=Hn,e.OBJExport=n,e.Object3dDirName=hs,e.OpenXmlContentTypesNamespace=as,e.OpenXmlRelationshipsNamespace=ls,e.RegisterEXT_lights_area=Me,e.RegisterEXT_mesh_gpu_instancing=re,e.RegisterEXT_texture_avif=rn,e.RegisterEXT_texture_webp=en,e.RegisterKHR_draco_mesh_compression=ue,e.RegisterKHR_lights_punctual=ge,e.RegisterKHR_materials_anisotropy=Ce,e.RegisterKHR_materials_clearcoat=Fe,e.RegisterKHR_materials_coat=ke,e.RegisterKHR_materials_diffuse_roughness=kt,e.RegisterKHR_materials_diffuse_transmission=De,e.RegisterKHR_materials_dispersion=qe,e.RegisterKHR_materials_emissive_strength=Ze,e.RegisterKHR_materials_fuzz=pt,e.RegisterKHR_materials_ior=tt,e.RegisterKHR_materials_iridescence=it,e.RegisterKHR_materials_openpbr=Wt,e.RegisterKHR_materials_sheen=ut,e.RegisterKHR_materials_specular=_t,e.RegisterKHR_materials_transmission=vt,e.RegisterKHR_materials_unlit=At,e.RegisterKHR_materials_volume=St,e.RegisterKHR_materials_volume_scatter=Bt,e.RegisterKHR_texture_basisu=Qt,e.RegisterKHR_texture_transform=jt,e.RelationshipDirName=cs,e.RelationshipFileName=fs,e.ResolveFormatOptions=Ln,e.ResolveNumberOptions=Dn,e.STLExport=ln,e.StringXmlWriter=ts,e.ThreeDimModelNamespace=ss,e.ThreeMf=js,e.ThreeMfBase=Ps,e.ThreeMfBaseMaterials=Ns,e.ThreeMfBuild=Us,e.ThreeMfComponent=Bs,e.ThreeMfComponents=Os,e.ThreeMfComponentsBuilder=$s,e.ThreeMfContentType=xs,e.ThreeMfContentTypes=gs,e.ThreeMfDocument=ys,e.ThreeMfDocumentBuilder=Ls,e.ThreeMfItem=ks,e.ThreeMfMaterialBuilder=Ws,e.ThreeMfMesh=Es,e.ThreeMfMeshBuilder=zs,e.ThreeMfMeta=ws,e.ThreeMfMetadataGroup=Rs,e.ThreeMfModel=Ms,e.ThreeMfModelBuilder=Ds,e.ThreeMfObject=Cs,e.ThreeMfObjectBuilder=Ks,e.ThreeMfRelationship=Ts,e.ThreeMfRelationships=_s,e.ThreeMfResources=As,e.ThreeMfSerializer=Xs,e.ThreeMfSerializerGlobalConfiguration=qs,e.ThreeMfTriangle=Fs,e.ThreeMfTriangles=Vs,e.ThreeMfVertex=Ss,e.ThreeMfVertices=Is,e.ToQualifiedString=$n,e.TriangleSetsNamespace=rs,e.USDZExportAsync=wn,e.Utf8XmlWriterToBytes=ns,e.XmlAttr=Bn,e.XmlBuilder=es,e.XmlElem=Nn,e.XmlIgnore=On,e.XmlName=Fn,e.XmlNameToParts=Kn,e.XmlSerializer=Zn,e._ConvertToGLTFPBRMetallicRoughness=_,e._SolveMetallic=x,e.__IGLTFExporterExtension=0});
|
|
2
2
|
//# sourceMappingURL=babylonjs.serializers.min.js.map
|