babylonjs-serializers 9.26.1 → 9.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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";var s={__proto__:null,__IGLTFExporterExtension:0};class r{constructor(){this.files={}}get glTFFiles(){return this.files}downloadFiles(){for(const e in this.files){const s=this.files[e],r=new Blob([s],{type:t.GetMimeType(e)});t.Tools.Download(r,e)}}}var n={__proto__:null,GLTFData:r};function i(e,t,s,r){return new(s||(s=Promise))(function(n,i){function o(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(o,a)}u((r=r.apply(e,t||[])).next())})}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;const o=1e-6,a=new t.Color3(.04,.04,.04),u=t.Color3.White(),l=t.Color3.BlackReadOnly;function c(e){switch(e){case"image/jpeg":case"image/png":case"image/webp":case"image/avif":case"image/ktx2":return!0;default:return!1}}function h(e,s,r){if(s<a.r)return 0;const n=a.r,i=e*r/(1-a.r)+s-2*a.r,o=i*i-4*n*(a.r-s);return t.Scalar.Clamp((-i+Math.sqrt(o))/(2*n),0,1)}function f(e){const s=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),r=e.alpha,n=t.Scalar.Clamp(e.specularPower,0,1024),i=t.SpecularPowerToRoughness(n);return{baseColorFactor:[s.r,s.g,s.b,r],metallicFactor:0,roughnessFactor:i}}function d(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function p(e,s,r){const n=new Uint8Array(e*s*4);for(let e=0;e<n.length;e+=4)n[e]=n[e+1]=n[e+2]=n[e+3]=255;return t.RawTexture.CreateRGBATexture(n,e,s,r)}function x(e){if(e instanceof Uint8Array){const t=e.length,s=new Float32Array(e.length);for(let r=0;r<t;++r)s[r]=e[r]/255;return s}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")}class _{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,s){return i(this,void 0,void 0,function*(){const r=f(e),n={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."),n.doubleSided=!0),s){const t=[],s=e.diffuseTexture;s&&t.push(this.exportTextureAsync(s).then(e=>{e&&(r.baseColorTexture=e)}));const i=e.bumpTexture;i&&t.push(this.exportTextureAsync(i).then(e=>{e&&(n.normalTexture=e,1!==i.level&&(n.normalTexture.scale=i.level))}));const o=e.emissiveTexture;o&&(n.emissiveFactor=[1,1,1],t.push(this.exportTextureAsync(o).then(e=>{e&&(n.emissiveTexture=e)})));const a=e.ambientTexture;a&&t.push(this.exportTextureAsync(a).then(e=>{if(e){const t={index:e.index};n.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?n.alphaMode="BLEND":t.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(l,o)&&(n.emissiveFactor=e.emissiveColor.asArray()),n.pbrMetallicRoughness=r,d(n,e),yield this._finishMaterialAsync(n,e);const i=this._exporter._materials;return i.push(n),i.length-1})}_finishMaterialAsync(e,t){return i(this,void 0,void 0,function*(){const s=yield this._exporter._extensionsPostExportMaterialAdditionalTexturesAsync("exportMaterial",e,t),r=[];for(const e of s)r.push(this.exportTextureAsync(e));yield Promise.all(r),yield this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)})}_resizeTexturesToSameDimensions(e,s,r){const n=e?e.getSize():{width:0,height:0},i=s?s.getSize():{width:0,height:0};let o,a;return n.width<i.width?(o=e&&e instanceof t.Texture?t.TextureTools.CreateResizedCopy(e,i.width,i.height,!0):p(i.width,i.height,r),a=s):n.width>i.width?(a=s&&s instanceof t.Texture?t.TextureTools.CreateResizedCopy(s,n.width,n.height,!0):p(n.width,n.height,r),o=e):(o=e,a=s),{texture1:o,texture2:a}}_convertSpecularGlossinessTexturesToMetallicRoughnessAsync(e,s,r){return i(this,void 0,void 0,function*(){var n;const i=new Array;if(!e&&!s)return yield Promise.reject("diffuse and specular glossiness textures are not defined!");const a=e?e.getScene():s?s.getScene():null;if(a){const l=this._resizeTexturesToSameDimensions(e,s,a),c=null===(n=l.texture1)||void 0===n?void 0:n.getSize();let h,f;const d=c.width,p=c.height,_=yield l.texture1.readPixels(),g=yield l.texture2.readPixels();if(!_)return yield Promise.reject("Failed to retrieve pixels from diffuse texture!");if(h=x(_),!g)return yield Promise.reject("Failed to retrieve pixels from specular glossiness texture!");f=x(g);const m=f.byteLength,T=new Uint8Array(m),y=new Uint8Array(m),R=4,M=new t.Color3(0,0,0);let A=0,b=0;for(let e=0;e<p;++e)for(let s=0;s<d;++s){const n=(d*e+s)*R,i={diffuseColor:new t.Color3(h[n],h[n+1],h[n+2]).toLinearSpace(a.getEngine().useExactSrgbConversions).multiply(r.diffuseColor),specularColor:new t.Color3(f[n],f[n+1],f[n+2]).toLinearSpace(a.getEngine().useExactSrgbConversions).multiply(r.specularColor),glossiness:f[n+3]*r.glossiness},o=this._convertSpecularGlossinessToMetallicRoughness(i);M.r=Math.max(M.r,o.baseColor.r),M.g=Math.max(M.g,o.baseColor.g),M.b=Math.max(M.b,o.baseColor.b),A=Math.max(A,o.metallic),b=Math.max(b,o.roughness),y[n]=255*o.baseColor.r,y[n+1]=255*o.baseColor.g,y[n+2]=255*o.baseColor.b,y[n+3]=l.texture1.hasAlpha?255*h[n+3]:255,T[n]=0,T[n+1]=255*o.roughness,T[n+2]=255*o.metallic,T[n+3]=255}const w={baseColor:M,metallic:A,roughness:b};let E=!1,v=!1;for(let e=0;e<p;++e)for(let s=0;s<d;++s){const r=(d*e+s)*R;y[r]/=w.baseColor.r>o?w.baseColor.r:1,y[r+1]/=w.baseColor.g>o?w.baseColor.g:1,y[r+2]/=w.baseColor.b>o?w.baseColor.b:1;const n=t.Color3.FromInts(y[r],y[r+1],y[r+2]).toGammaSpace(a.getEngine().useExactSrgbConversions);y[r]=255*n.r,y[r+1]=255*n.g,y[r+2]=255*n.b,n.equalsWithEpsilon(u,o)||(v=!0),T[r+1]/=w.roughness>o?w.roughness:1,T[r+2]/=w.metallic>o?w.metallic:1,t.Color3.FromInts(255,T[r+1],T[r+2]).equalsWithEpsilon(u,o)||(E=!0)}return E&&i.push(t.EncodeImageAsync(T,d,p).then(e=>{w.metallicRoughnessTextureData=e})),v&&i.push(t.EncodeImageAsync(y,d,p).then(e=>{w.baseColorTextureData=e})),yield Promise.all(i).then(()=>w)}return yield Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")})}_convertSpecularGlossinessToMetallicRoughness(e){const s=this._getPerceivedBrightness(e.diffuseColor),r=this._getPerceivedBrightness(e.specularColor),n=1-this._getMaxComponent(e.specularColor),i=h(s,r,n),u=e.diffuseColor.scale(n/(1-a.r)/Math.max(1-i,o)),l=e.specularColor.subtract(a.scale(1-i)).scale(1/Math.max(i,o));let c=t.Color3.Lerp(u,l,i*i);return c=c.clampToRef(0,1,c),{baseColor:c,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,s,r,n,o,a,u,l,c){return i(this,void 0,void 0,function*(){const h=[],f={baseColor:e,metallic:s,roughness:r};if(c)if(u instanceof t.OpenPBRMaterial){if(u.geometryOpacityTexture){const e=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:0,s=u.geometryOpacityTexture&&u.geometryOpacityTexture.getInternalTexture()?u.geometryOpacityTexture.getInternalTexture().uniqueId:0,r=Number(`${e}${s}`),o=this._textureMap.get(r);o?l.baseColorTexture=o:h.push(t.MergeTexturesAsync("baseColorOpacityTexture",t.CreateRGBAConfiguration(n?t.CreateTextureInput(n,0):t.CreateConstantInput(1),n?t.CreateTextureInput(n,1):t.CreateConstantInput(1),n?t.CreateTextureInput(n,2):t.CreateConstantInput(1),t.CreateTextureInput(u.geometryOpacityTexture,0)),u.getScene()).then(e=>i(this,void 0,void 0,function*(){const t=yield this.exportTextureAsync(e,r);t&&(l.baseColorTexture=t)})))}else n&&h.push(this.exportTextureAsync(n).then(e=>{e&&(l.baseColorTexture=e)}));if(u._useMetallicFromMetallicTextureBlue&&o)h.push(this.exportTextureAsync(o).then(e=>{e&&(l.metallicRoughnessTexture=e)}));else if(a||o){const e=o&&o.getInternalTexture()?o.getInternalTexture().uniqueId:0,s=a&&a.getInternalTexture()?a.getInternalTexture().uniqueId:0,r=Number(`${e}${s}`),n=this._textureMap.get(r);n?l.metallicRoughnessTexture=n:h.push(t.MergeTexturesAsync("MetalRoughTexture",t.CreateRGBAConfiguration(u.ambientOcclusionTexture?t.CreateTextureInput(u.ambientOcclusionTexture,0):t.CreateConstantInput(1),a?t.CreateTextureInput(a,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,0):t.CreateConstantInput(1)),u.getScene()).then(e=>i(this,void 0,void 0,function*(){const t=yield this.exportTextureAsync(e,r);t&&(l.metallicRoughnessTexture=t)})))}}else n&&h.push(this.exportTextureAsync(n).then(e=>{e&&(l.baseColorTexture=e)})),o&&h.push(this.exportTextureAsync(o).then(e=>{e&&(l.metallicRoughnessTexture=e)}));return h.length>0&&(this._exporter._materialNeedsUVsSet.add(u),yield Promise.all(h)),f})}_getTextureSampler(e){const s={};if(!(e&&e instanceof t.Texture))return s;const r=this._getGLTFTextureWrapMode(e.wrapU);10497!==r&&(s.wrapS=r);const n=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==n&&(s.wrapT=n),e.samplingMode){case t.Texture.LINEAR_LINEAR:s.magFilter=9729,s.minFilter=9729;break;case t.Texture.LINEAR_NEAREST:s.magFilter=9729,s.minFilter=9728;break;case t.Texture.NEAREST_LINEAR:s.magFilter=9728,s.minFilter=9729;break;case t.Texture.NEAREST_LINEAR_MIPLINEAR:s.magFilter=9728,s.minFilter=9987;break;case t.Texture.NEAREST_NEAREST:s.magFilter=9728,s.minFilter=9728;break;case t.Texture.NEAREST_LINEAR_MIPNEAREST:s.magFilter=9728,s.minFilter=9985;break;case t.Texture.LINEAR_NEAREST_MIPNEAREST:s.magFilter=9729,s.minFilter=9984;break;case t.Texture.LINEAR_NEAREST_MIPLINEAR:s.magFilter=9729,s.minFilter=9986;break;case t.Texture.NEAREST_NEAREST_MIPLINEAR:s.magFilter=9728,s.minFilter=9986;break;case t.Texture.LINEAR_LINEAR_MIPLINEAR:s.magFilter=9729,s.minFilter=9987;break;case t.Texture.LINEAR_LINEAR_MIPNEAREST:s.magFilter=9729,s.minFilter=9985;break;case t.Texture.NEAREST_NEAREST_MIPNEAREST:s.magFilter=9728,s.minFilter=9984}return s}_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,s){return i(this,void 0,void 0,function*(){const r={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},n=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((n||i)&&s){this._exporter._materialNeedsUVsSet.add(e);const s=this._exportTextureSampler(n||i),o=yield this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(n,i,r),a=this._exporter._textures;if(o.baseColorTextureData){const e=yield this._exportImageAsync(`baseColor${a.length}`,o.baseColorTextureData);t.baseColorTexture=this._exportTextureInfo(e,s,null==n?void 0:n.coordinatesIndex)}if(o.metallicRoughnessTextureData){const e=yield this._exportImageAsync(`metallicRoughness${a.length}`,o.metallicRoughnessTextureData);t.metallicRoughnessTexture=this._exportTextureInfo(e,s,null==i?void 0:i.coordinatesIndex)}return o}return this._convertSpecularGlossinessToMetallicRoughness(r)})}exportPBRMaterialAsync(e,t){return i(this,void 0,void 0,function*(){const s={},r={name:e.name},n=e.isMetallicWorkflow();if(n){const t=e._albedoColor,r=e.alpha;t&&(s.baseColorFactor=[t.r,t.g,t.b,r])}const i=n?yield this._convertMetalRoughFactorsToMetallicRoughnessAsync(e._albedoColor,e._metallic,e._roughness,e._albedoTexture,e._metallicTexture,e._metallicTexture,e,s,t):yield this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,s,t);yield this._setMetallicRoughnessPbrMaterialAsync(i,e,r,s,t),yield this._finishMaterialAsync(r,e);const o=this._exporter._materials;return o.push(r),o.length-1})}_setMetallicRoughnessPbrMaterialAsync(e,s,r,n,a){return i(this,void 0,void 0,function*(){if(d(r,s),e.baseColor.equalsWithEpsilon(u,o)&&t.Scalar.WithinEpsilon(s.alpha,1,o)||(n.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,s.alpha]),null!=e.metallic&&1!==e.metallic&&(n.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(n.roughnessFactor=e.roughness),null==s.backFaceCulling||s.backFaceCulling||(s._twoSidedLighting||t.Tools.Warn(s.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),a){const e=[],o=s instanceof t.PBRBaseMaterial?s._bumpTexture:s.geometryNormalTexture;o&&e.push(this.exportTextureAsync(o).then(e=>{e&&(r.normalTexture=e,1!==o.level&&(r.normalTexture.scale=o.level))}));const a=s instanceof t.PBRBaseMaterial?s._ambientTexture:s.ambientOcclusionTexture;a&&e.push(new Promise(e=>i(this,void 0,void 0,function*(){if(s instanceof t.OpenPBRMaterial&&n.metallicRoughnessTexture){const t=this._exportTextureSampler(a),s=this._exporter._textures[n.metallicRoughnessTexture.index].source,r=this._exportTextureInfo(s,t,a.coordinatesIndex);return this._textureMap.set(a.uniqueId,r),this._exporter._extensionsPostExportTextures("exporter",r,a),e(r)}return e(yield this.exportTextureAsync(a))})).then(e=>i(this,void 0,void 0,function*(){if(e){const n={index:e.index,texCoord:e.texCoord,extensions:e.extensions};r.occlusionTexture=n,s instanceof t.PBRBaseMaterial?n.strength=s._ambientTextureStrength:n.strength=s.ambientOcclusionTexture.level}})));const u=s instanceof t.PBRBaseMaterial?s._emissiveTexture:s.emissionColorTexture;u&&e.push(this.exportTextureAsync(u).then(e=>{e&&(r.emissiveTexture=e)})),e.length>0&&(this._exporter._materialNeedsUVsSet.add(s),yield Promise.all(e))}const c=s instanceof t.PBRBaseMaterial?s._emissiveColor:s.emissionColor;c.equalsWithEpsilon(l,o)||(r.emissiveFactor=c.asArray()),r.pbrMetallicRoughness=n})}exportOpenPBRMaterialAsync(e,t){return i(this,void 0,void 0,function*(){const s={},r={name:e.name},n=e.baseColor,i=e.geometryOpacity;n&&(s.baseColorFactor=[n.r,n.g,n.b,i]);const o=yield this._convertMetalRoughFactorsToMetallicRoughnessAsync(e.baseColor,e.baseMetalness,e.specularRoughness,e.baseColorTexture,e.baseMetalnessTexture,e.specularRoughnessTexture,e,s,t);yield this._setMetallicRoughnessPbrMaterialAsync(o,e,r,s,t),yield this._finishMaterialAsync(r,e);const a=this._exporter._materials;return a.push(r),a.length-1})}exportTextureAsync(e){return i(this,arguments,void 0,function*(e,t=null){let s=this._textureMap.get(null!=t?t:e.uniqueId);if(s)return s;const r=this._exportTextureSampler(e),n=yield this._exportTextureImageAsync(e);return s=this._exportTextureInfo(n,r,e.coordinatesIndex),this._textureMap.set(null!=t?t:e.uniqueId,s),this._exporter._extensionsPostExportTextures("exporter",s,e),s})}_exportTextureImageAsync(e){return i(this,void 0,void 0,function*(){var s;const r=null!==(s=e.mimeType)&&void 0!==s?s:"none",n=this._internalTextureToImage,o=e.getInternalTexture().uniqueId;n[o]=n[o]||{};let a=n[o][r];return void 0===a&&(a=(()=>i(this,void 0,void 0,function*(){const s=yield function(e){return i(this,void 0,void 0,function*(){var s;const r=e.getInternalTexture();if(!r||1!==r.source)return null;if(r.invertY&&!((null===(s=e.getScene())||void 0===s?void 0:s.getEngine())instanceof t.NullEngine))return null;const n=r._buffer;let i,o=e.mimeType;try{n?ArrayBuffer.isView(n)?i=n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength):n instanceof ArrayBuffer?i=n:n instanceof Blob?(i=yield n.arrayBuffer(),o=n.type||o):"string"==typeof n?(i=yield t.Tools.LoadFileAsync(n),o=t.GetMimeType(n)||o):"undefined"!=typeof HTMLImageElement&&n instanceof HTMLImageElement&&(i=yield t.Tools.LoadFileAsync(n.src),o=t.GetMimeType(n.src)||o):(i=yield t.Tools.LoadFileAsync(r.url),o=t.GetMimeType(r.url)||o)}catch(e){return null}if(i&&!o&&r.url){const e=r.url.match(/^data:([^;,]+)/);o=e?e[1]:t.GetMimeType(r.url)}return i&&o?{data:i,mimeType:o}:null})}(e);if(s&&c(s.mimeType)&&("none"===r||s.mimeType===r))return yield this._exportImageAsync(e.name,new Blob([s.data],{type:s.mimeType}));let n="image/png";"none"!==r&&(c(r)?n=r:(n="image/png",t.Tools.Warn(`Unsupported media type: ${r}. Exporting texture as PNG.`)));const o=e.getSize(),a=yield t.GetTextureDataAsync(e),u=yield t.EncodeImageAsync(a,o.width,o.height,n);return yield this._exportImageAsync(e.name,u)}))(),n[o][r]=a),yield a})}_exportImageAsync(e,s){return i(this,void 0,void 0,function*(){const r=this._exporter._images;let n;if(this._exporter._shouldUseGlb){n={name:e,mimeType:s.type,bufferView:void 0};const t=yield s.arrayBuffer(),r=this._exporter._bufferManager.createBufferView(new Uint8Array(t));this._exporter._bufferManager.setBufferView(n,r)}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"}}(s.type);let a=i+o;r.some(e=>e.uri===a)&&(a=`${i}_${t.Tools.RandomId()}${o}`),n={name:e,uri:a},this._exporter._imageData[a]=s}return r.push(n),r.length-1})}_exportTextureInfo(e,t,s){const r=this._exporter._textures;let n=r.findIndex(s=>s.sampler==t&&s.source===e);-1===n&&(n=r.length,r.push({source:e,sampler:t}));const i={index:n};return s&&(i.texCoord=s),i}_exportTextureSampler(e){const t=this._getTextureSampler(e),s=this._exporter._samplers,r=s.findIndex(e=>e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT);return-1!==r?r:(s.push(t),s.length-1)}}const g=t.Matrix.Compose(new t.Vector3(-1,1,1),t.Quaternion.Identity(),t.Vector3.Zero());function m(e,s){if(!(e instanceof t.TransformNode))return!1;if(s){if(!e.getWorldMatrix().equalsWithEpsilon(t.Matrix.IdentityReadOnly,t.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(g,t.TmpVectors.Matrix[0]).equalsWithEpsilon(t.Matrix.IdentityReadOnly,t.Epsilon))return!1;return!(e instanceof t.AbstractMesh&&e.geometry)}const T=t.Vector3.ZeroReadOnly,y=t.Quaternion.Identity(),R=t.Vector3.OneReadOnly,M=new t.Vector3(-1,1,1);function A(e,t){const{byteOffset:s,byteStride:r,type:n,normalized:i}=e,o=e.getSize(),a=t.reduce((e,t)=>t.getTotalVertices()>e?t.getTotalVertices():e,-Number.MAX_VALUE);return{byteOffset:s,byteStride:r,componentCount:o,type:n,count:a*o,normalized:i,totalVertices:a,kind:e.getKind()}}function b(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 w(e){return e.some(e=>e>=256)}function E(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 v(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 C(e){return e.x*=-1,e}function I(e){return g.invertToRef(t.TmpVectors.Matrix[0]).multiplyToRef(e,e).multiplyToRef(g,e),e}function V(e){if(e.x*e.x+e.y*e.y>.5){const t=Math.abs(e.x),s=Math.abs(e.y);if(t>s){const s=Math.sign(e.x);e.x=t,e.y*=-s,e.z*=-s,e.w*=s}else{const t=Math.sign(e.y);e.x*=-t,e.y=s,e.z*=t,e.w*=-t}}else{const t=Math.abs(e.z),s=Math.abs(e.w);if(t>s){const s=Math.sign(e.z);e.x*=-s,e.y*=s,e.z=t,e.w*=-s}else{const t=Math.sign(e.w);e.x*=t,e.y*=-t,e.z*=-t,e.w=s}}return e}function S(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function F(e,s){const r=t.Vector3.FromArrayToRef(s.translation||[0,0,0],0,t.TmpVectors.Vector3[0]),n=t.Quaternion.FromArrayToRef(s.rotation||[0,0,0,1],0,t.TmpVectors.Quaternion[0]),i=t.Matrix.ComposeToRef(R,n,r,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]),u=t.Matrix.ComposeToRef(R,a,o,t.TmpVectors.Matrix[1]);i.multiplyToRef(u,u),u.decompose(void 0,n,r),r.equalsWithEpsilon(T,t.Epsilon)?delete s.translation:s.translation=r.asArray(),n.equalsWithEpsilon(y,t.Epsilon)?delete s.rotation:s.rotation=n.asArray(),s.scale&&delete s.scale}function B(e,s){if(!(s instanceof t.TransformNode))return!1;if(1!==s.getChildren().length||0!==e.getChildren().length||e.parent!==s)return!1;const r=e.getScene(),n=e instanceof t.TargetCamera&&!r.useRightHandedSystem?M:R;return!!s.scaling.equalsWithEpsilon(n,t.Epsilon)||(t.Logger.Warn(`Cannot collapse node ${e.name} into parent node ${s.name} with modified scaling.`),!1)}function N(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 U(e,t){for(const[s,r]of Object.entries(e)){const n=t[s];(Array.isArray(r)&&Array.isArray(n)&&O(r,n)||r===n)&&delete e[s]}return e}function O(e,t){return e.length===t.length&&e.every((e,s)=>e===t[s])}const K=new Map([[Int8Array,(e,t,s)=>e.setInt8(t,s)],[Uint8Array,(e,t,s)=>e.setUint8(t,s)],[Uint8ClampedArray,(e,t,s)=>e.setUint8(t,s)],[Int16Array,(e,t,s)=>e.setInt16(t,s,!0)],[Uint16Array,(e,t,s)=>e.setUint16(t,s,!0)],[Int32Array,(e,t,s)=>e.setInt32(t,s,!0)],[Uint32Array,(e,t,s)=>e.setUint32(t,s,!0)],[Float32Array,(e,t,s)=>e.setFloat32(t,s,!0)],[Float64Array,(e,t,s)=>e.setFloat64(t,s,!0)]]);class P{writeTypedArray(e){this._checkGrowBuffer(e.byteLength);const t=K.get(e.constructor);for(let s=0;s<e.length;s++)t(this._dataView,this._byteOffset,e[s]),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 W(e){return e%4==0?4:e%2==0?2:1}class H{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 s=new P(t),r=Array.from(this._bufferViewToData.keys()).sort((e,t)=>W(t.byteLength)-W(e.byteLength));for(const t of r){t.byteOffset=s.byteOffset,e.push(t);const r=e.length-1,n=this.getPropertiesWithBufferView(t);for(const e of n)e.bufferView=r;s.writeTypedArray(this._bufferViewToData.get(t)),this._bufferViewToData.delete(t)}return s.getOutputData()}createBufferView(e,t){const s={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(s,e),s}createAccessor(e,t,s,r,n,i,o){this._verifyBufferView(e);const a={bufferView:void 0,componentType:s,count:r,type:t,min:null==i?void 0:i.min,max:null==i?void 0:i.max,normalized:o,byteOffset:n};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,s)=>{t===e&&(void 0!==s.byteOffset&&delete s.byteOffset,this._accessorToBufferView.delete(s))})}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 L;!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(L||(L={}));class z{static _IsTransformable(e){return e&&(e instanceof t.TransformNode||e instanceof t.Camera||e instanceof t.Light)}static _CreateNodeAnimation(e,s,r,n,i){if(this._IsTransformable(e)){const o=[],a=[],u=s.getKeys(),l=z._CalculateMinMaxKeyFrames(u),c=z._DeduceInterpolation(u,r,n),h=c.interpolationType,f=c.shouldBakeAnimation;if(f?z._CreateBakedAnimation(e,s,r,l.min,l.max,s.framePerSecond,i,o,a,l,n):"LINEAR"===h||"STEP"===h?z._CreateLinearOrStepAnimation(e,s,r,o,a,n):"CUBICSPLINE"===h?z._CreateCubicSplineAnimation(e,s,r,o,a,n):z._CreateBakedAnimation(e,s,r,l.min,l.max,s.framePerSecond,i,o,a,l,n),o.length&&a.length)return{inputs:o,outputs:a,samplerInterpolation:h,inputsMin:f?l.min:t.Tools.FloatRound(l.min/s.framePerSecond),inputsMax:f?l.max:t.Tools.FloatRound(l.max/s.framePerSecond)}}return null}static _DeduceAnimationInfo(e){let s=null,r="VEC3",n=!1;const i=e.targetProperty.split(".");switch(i[0]){case"scaling":s="scale";break;case"position":s="translation";break;case"rotation":r="VEC4",s="rotation";break;case"rotationQuaternion":r="VEC4",n=!0,s="rotation";break;case"influence":r="SCALAR",s="weights";break;default:t.Tools.Error(`Unsupported animatable property ${i[0]}`)}return s?{animationChannelTargetPath:s,dataAccessorType:r,useQuaternion:n}:(t.Tools.Error("animation channel target path and data accessor type could be deduced"),null)}static _CreateNodeAnimationFromNodeAnimations(e,t,s,r,n,i,o,a,u,l,c){let h;if(z._IsTransformable(e)&&e.animations)for(const n of e.animations){if(c&&!c(n))continue;const f=z._DeduceAnimationInfo(n);f&&(h={name:n.name,samplers:[],channels:[]},z._AddAnimation(`${n.name}`,n.hasRunningRuntimeAnimations?t:h,e,n,f.dataAccessorType,f.animationChannelTargetPath,r,i,o,a,f.useQuaternion,u,l),h.samplers.length&&h.channels.length&&s.push(h))}}static _CreateMorphTargetAnimationFromMorphTargetAnimations(e,s,r,n,i,o,a,u,l,c,h){let f;if(e instanceof t.Mesh){const i=e.morphTargetManager;if(i)for(let d=0;d<i.numTargets;++d){const p=i.getTarget(d);for(const x of p.animations){if(h&&!h(x))continue;const p=new t.Animation(`${x.name}`,"influence",x.framePerSecond,x.dataType,x.loopMode,x.enableBlending),_=[],g=x.getKeys();for(let e=0;e<g.length;++e){const t=g[e];for(let e=0;e<i.numTargets;++e)e==d?_.push(t):_.push({frame:t.frame,value:0})}p.setKeys(_,!0);const m=z._DeduceAnimationInfo(p);m&&(f={name:p.name,samplers:[],channels:[]},z._AddAnimation(x.name,x.hasRunningRuntimeAnimations?s:f,e,p,m.dataAccessorType,m.animationChannelTargetPath,n,o,a,u,m.useQuaternion,l,c,i.numTargets),f.samplers.length&&f.channels.length&&r.push(f))}}}}static _CreateNodeAndMorphAnimationFromAnimationGroups(e,s,r,n,i,o,a,u,l){var c;let h;if(e.animationGroups){const f=e.animationGroups;for(const d of f){const f=new Map,p=new Map,x=new Set,_=d.to-d.from;h={name:d.name,channels:[],samplers:[]};for(let s=0;s<d.targetedAnimations.length;++s){const _=d.targetedAnimations[s],g=_.target,m=_.animation;if(l&&!l(m))continue;const T=u.has(g);if(this._IsTransformable(g)||1===g.length&&this._IsTransformable(g[0])){const e=z._DeduceAnimationInfo(_.animation);if(e){const t=this._IsTransformable(g)?g:this._IsTransformable(g[0])?g[0]:null;t&&z._AddAnimation(`${m.name}`,h,t,m,e.dataAccessorType,e.animationChannelTargetPath,r,n,i,o,e.useQuaternion,a,T)}}else if((g instanceof t.MorphTarget||1===g.length&&g[0]instanceof t.MorphTarget)&&z._DeduceAnimationInfo(_.animation)){const s=g instanceof t.MorphTarget?g:g[0];if(s){const t=e.morphTargetManagers.find(e=>{for(let t=0;t<e.numTargets;++t)if(e.getTarget(t)===s)return!0;return!1});if(t){const r=e.meshes.find(e=>e.morphTargetManager===t);r&&(f.has(r)||f.set(r,new Map),null===(c=f.get(r))||void 0===c||c.set(s,m),x.add(r),p.set(r,m))}}}}x.forEach(e=>{const s=e.morphTargetManager;let u=null;const l=[],c=p.get(e).getKeys(),x=c.length;for(let r=0;r<x;++r)for(let n=0;n<s.numTargets;++n){const i=s.getTarget(n),o=f.get(e);if(o){const s=o.get(i);s?(u||(u=new t.Animation(`${d.name}_${e.name}_MorphWeightAnimation`,"influence",s.framePerSecond,t.Animation.ANIMATIONTYPE_FLOAT,s.loopMode,s.enableBlending)),l.push(s.getKeys()[r])):l.push({frame:d.from+_/x*r,value:i.influence,inTangent:c[0].inTangent?0:void 0,outTangent:c[0].outTangent?0:void 0})}}u.setKeys(l,!0);const g=z._DeduceAnimationInfo(u);g&&z._AddAnimation(`${d.name}_${e.name}_MorphWeightAnimation`,h,e,u,g.dataAccessorType,g.animationChannelTargetPath,r,n,i,o,g.useQuaternion,a,!1,null==s?void 0:s.numTargets)}),h.channels.length&&h.samplers.length&&s.push(h)}}}static _AddAnimation(e,s,r,n,i,o,a,u,l,c,h,f,d,p){const x=z._CreateNodeAnimation(r,n,o,h,f);let _,g,m,T,y,R;if(x){if(p){let e,t=0;const s=[];for(;x.inputs.length>0;)e=x.inputs.shift(),t%p==0&&s.push(e),t++;x.inputs=s}const e=a.get(r),n=new Float32Array(x.inputs);_=u.createBufferView(n),g=u.createAccessor(_,"SCALAR",5126,x.inputs.length,void 0,{min:[x.inputsMin],max:[x.inputsMax]}),c.push(g),m=c.length-1;const l=new t.Quaternion,h=new t.Vector3,f=new t.Vector3,M=r instanceof t.Camera,A=b(i),w=new Float32Array(x.outputs.length*A);x.outputs.forEach(function(e,s){let r=e;switch(o){case"translation":d&&(t.Vector3.FromArrayToRef(e,0,f),C(f),f.toArray(r));break;case"rotation":4===e.length?t.Quaternion.FromArrayToRef(e,0,l):(r=new Array(4),t.Vector3.FromArrayToRef(e,0,h),t.Quaternion.FromEulerVectorToRef(h,l)),d&&(V(l),M&&S(l)),l.toArray(r)}w.set(r,s*A)}),_=u.createBufferView(w),g=u.createAccessor(_,i,5126,x.outputs.length),c.push(g),T=c.length-1,y={interpolation:x.samplerInterpolation,input:m,output:T},s.samplers.push(y),R={sampler:s.samplers.length-1,target:{node:e,path:o}},s.channels.push(R)}}static _CreateBakedAnimation(e,s,r,n,i,o,a,u,l,c,h){let f;const d=t.Quaternion.Identity();let p,x,_,g,m,T=null,y=null;c.min=t.Tools.FloatRound(n/o);const R=s.getKeys();for(let n=0,c=R.length;n<c;++n){if(x=R[n],n+1<c)if(_=R[n+1],x.value.equals&&x.value.equals(_.value)||x.value===_.value){if(0!==n)continue;m=x.frame}else m=_.frame;else{if(g=R[n-1],x.value.equals&&x.value.equals(g.value)||x.value===g.value)continue;m=i}if(m)for(let n=x.frame;n<=m;n+=a){if(p=t.Tools.FloatRound(n/o),p===T)continue;T=p,y=p;const i={key:0,repeatCount:0,loopMode:s.loopMode};f=s._interpolate(n,i),z._SetInterpolatedValue(e,f,p,s,r,d,u,l,h)}}y&&(c.max=y)}static _ConvertFactorToVector3OrQuaternion(e,s,r,n,i){const o=z._GetBasePositionRotationOrScale(s,n,i),a=r.targetProperty.split("."),u=a?a[1]:"",l=i?t.Quaternion.FromArray(o).normalize():t.Vector3.FromArray(o);switch(u){case"x":case"y":case"z":l[u]=e;break;case"w":l.w=e;break;default:t.Tools.Error(`glTFAnimation: Unsupported component name "${u}"!`)}return l}static _SetInterpolatedValue(e,s,r,n,i,o,a,u,l){let c;a.push(r),"weights"!==i?(n.dataType===t.Animation.ANIMATIONTYPE_FLOAT&&(s=this._ConvertFactorToVector3OrQuaternion(s,e,n,i,l)),"rotation"===i?(l?o=s:(c=s,t.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,o)),u.push(o.asArray())):(c=s,u.push(c.asArray()))):u.push([s])}static _CreateLinearOrStepAnimation(e,t,s,r,n,i){for(const o of t.getKeys())r.push(o.frame/t.framePerSecond),z._AddKeyframeValue(o,t,n,s,e,i)}static _CreateCubicSplineAnimation(e,t,s,r,n,i){t.getKeys().forEach(function(o){r.push(o.frame/t.framePerSecond),z._AddSplineTangent(L.INTANGENT,n,s,"CUBICSPLINE",o,i),z._AddKeyframeValue(o,t,n,s,e,i),z._AddSplineTangent(L.OUTTANGENT,n,s,"CUBICSPLINE",o,i)})}static _GetBasePositionRotationOrScale(e,s,r){let n;if("rotation"===s)if(r){const s=e.rotationQuaternion;n=(null!=s?s:t.Quaternion.Identity()).asArray()}else{const s=e.rotation;n=(null!=s?s:t.Vector3.Zero()).asArray()}else if("translation"===s){const s=e.position;n=(null!=s?s:t.Vector3.Zero()).asArray()}else{const s=e.scaling;n=(null!=s?s:t.Vector3.One()).asArray()}return n}static _AddKeyframeValue(e,s,r,n,i,o){let a;const u=s.dataType;if(u===t.Animation.ANIMATIONTYPE_VECTOR3){let s=e.value.asArray();if("rotation"===n){const e=t.Vector3.FromArray(s);s=t.Quaternion.RotationYawPitchRoll(e.y,e.x,e.z).asArray()}r.push(s)}else if(u===t.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(a=this._ConvertFactorToVector3OrQuaternion(e.value,i,s,n,o),a){if("rotation"===n){const e=o?a:t.Quaternion.RotationYawPitchRoll(a.y,a.x,a.z).normalize();r.push(e.asArray())}r.push(a.asArray())}}else u===t.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):t.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")}static _DeduceInterpolation(e,t,s){let r,n,i=!1;if("rotation"===t&&!s)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(let t=0,s=e.length;t<s;++t)if(n=e[t],n.inTangent||n.outTangent)if(r){if("CUBICSPLINE"!==r){r="LINEAR",i=!0;break}}else r="CUBICSPLINE";else if(r){if("CUBICSPLINE"===r||n.interpolation&&1===n.interpolation&&"STEP"!==r){r="LINEAR",i=!0;break}}else r=n.interpolation&&1===n.interpolation?"STEP":"LINEAR";return r||(r="LINEAR"),{interpolationType:r,shouldBakeAnimation:i}}static _AddSplineTangent(e,s,r,n,i,o){let a;const u=e===L.INTANGENT?i.inTangent:i.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(u)if(o)a=u.asArray();else{const e=u;a=t.Quaternion.RotationYawPitchRoll(e.y,e.x,e.z).asArray()}else a=[0,0,0,0];else a="weights"===r?u?[u]:[0]:u?u.asArray():[0,0,0];s.push(a)}}static _CalculateMinMaxKeyFrames(e){let t=1/0,s=-1/0;return e.forEach(function(e){t=Math.min(t,e.frame),s=Math.max(s,e.frame)}),{min:t,max:s}}}function k(e,s,r,n,i,o){const a={attributes:{},influence:e.influence,name:e.name},u=s.geometry;if(!u)return t.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),a;const l=o?-1:1,c=t.Vector3.Zero();let h,f;if(e.hasPositions){const n=e.getPositions(),o=u.getVerticesData(t.VertexBuffer.PositionKind);if(o){const e=new Float32Array(o.length),s=[1/0,1/0,1/0],u=[-1/0,-1/0,-1/0];f=o.length/3,h=0;for(let r=h;r<f;++r){const i=t.Vector3.FromArray(o,3*r);t.Vector3.FromArray(n,3*r).subtractToRef(i,c),c.x*=l,s[0]=Math.min(s[0],c.x),u[0]=Math.max(u[0],c.x),s[1]=Math.min(s[1],c.y),u[1]=Math.max(u[1],c.y),s[2]=Math.min(s[2],c.z),u[2]=Math.max(u[2],c.z),e[3*r]=c.x,e[3*r+1]=c.y,e[3*r+2]=c.z}const d=r.createBufferView(e,12),p=r.createAccessor(d,"VEC3",5126,n.length/3,0,{min:s,max:u});i.push(p),a.attributes.POSITION=i.length-1}else t.Tools.Warn(`Morph target positions for mesh ${s.name} were not exported. Mesh does not have position vertex data`)}if(e.hasNormals){const n=e.getNormals(),o=u.getVerticesData(t.VertexBuffer.NormalKind);if(o){const e=new Float32Array(o.length);f=o.length/3,h=0;for(let s=h;s<f;++s){const r=t.Vector3.FromArray(o,3*s).normalize();t.Vector3.FromArray(n,3*s).normalize().subtractToRef(r,c),e[3*s]=c.x*l,e[3*s+1]=c.y,e[3*s+2]=c.z}const s=r.createBufferView(e,12),u=r.createAccessor(s,"VEC3",5126,n.length/3,0);i.push(u),a.attributes.NORMAL=i.length-1}else t.Tools.Warn(`Morph target normals for mesh ${s.name} were not exported. Mesh does not have normals vertex data`)}if(e.hasTangents){const n=e.getTangents(),o=u.getVerticesData(t.VertexBuffer.TangentKind);if(o){f=o.length/4;const e=new Float32Array(3*f);h=0;for(let s=h;s<f;++s){const r=t.Vector3.FromArray(o,4*s);v(r);const i=t.Vector3.FromArray(n,3*s);v(i),i.subtractToRef(r,c),e[3*s]=c.x*l,e[3*s+1]=c.y,e[3*s+2]=c.z}const s=r.createBufferView(e,12),u=r.createAccessor(s,"VEC3",5126,f,0);i.push(u),a.attributes.TANGENT=i.length-1}else t.Tools.Warn(`Morph target tangents for mesh ${s.name} were not exported. Mesh does not have tangents vertex data`)}if(e.hasColors){const n=e.getColors(),o=u.getVerticesData(t.VertexBuffer.ColorKind),l=u.getVertexBuffer(t.VertexBuffer.ColorKind);if(o&&l){const e=l.getSize();f=o.length/e;const s=new Float32Array(f*e);h=0;for(let r=h;r<f;++r)if(3===e){const i=t.Vector3.FromArray(o,r*e);t.Vector3.FromArray(n,r*e).subtractToRef(i,c),s[3*r]=c.x,s[3*r+1]=c.y,s[3*r+2]=c.z}else if(4===e){const i=new t.Vector4,a=t.Vector4.FromArray(o,r*e);t.Vector4.FromArray(n,r*e).subtractToRef(a,i),s[4*r]=i.x,s[4*r+1]=i.y,s[4*r+2]=i.z,s[4*r+3]=i.w}else t.Tools.Warn(`Unsupported number of components for color attribute: ${e}`);const u=r.createBufferView(s,4*e),d=r.createAccessor(u,3===e?"VEC3":"VEC4",5126,f,0);i.push(d),a.attributes.COLOR_0=i.length-1}else t.Tools.Warn(`Morph target colors for mesh ${s.name} were not exported. Mesh does not have colors vertex data`)}return a}class G{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,s,r,n){var i,o,a,u;return null===(u=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(s))||void 0===a?void 0:a.get(r))||void 0===u?void 0:u.get(n)}setIndicesAccessor(e,t,s,r,n,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 u=a.get(s);u||(u=new Map,a.set(s,u));let l=u.get(r);l||(l=new Map,u.set(r,l)),l.set(n,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,s){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,s)}getRemappedBufferView(e,t){var s;return null===(s=this._remappedBufferView.get(e))||void 0===s?void 0:s.get(t)}getVertexAccessor(e,t,s){var r,n;return null===(n=null===(r=this._vertexAccessorMap.get(e))||void 0===r?void 0:r.get(t))||void 0===n?void 0:n.get(s)}setVertexAccessor(e,t,s,r){let n=this._vertexAccessorMap.get(e);n||(n=new Map,this._vertexAccessorMap.set(e,n));let i=n.get(t);i||(i=new Map,n.set(t,i)),i.set(s,r)}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 s=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,s),-1===s.indexOf(t)&&s.push(t)}getMorphTargetsFromMesh(e){return this._meshMorphTargetMap.get(e)}}class D{_ApplyExtension(e,t,s,r){if(s>=t.length)return Promise.resolve(e);const n=r(t[s],e);return n?n.then(e=>i(this,void 0,void 0,function*(){return e?yield this._ApplyExtension(e,t,s+1,r):null})):this._ApplyExtension(e,t,s+1,r)}_ApplyExtensions(e,t){const s=[];for(const e of D._ExtensionNames)s.push(this._extensions[e]);return this._ApplyExtension(e,s,0,t)}_extensionsPostExportNodeAsync(e,t,s,r,n){return this._ApplyExtensions(t,(t,i)=>t.postExportNodeAsync&&t.postExportNodeAsync(e,i,s,r,n,this._bufferManager))}_extensionsPostExportMaterialAsync(e,t,s){return this._ApplyExtensions(t,(t,r)=>t.postExportMaterialAsync&&t.postExportMaterialAsync(e,r,s))}_extensionsPostExportMaterialAdditionalTexturesAsync(e,t,s){return i(this,void 0,void 0,function*(){const r=[];return yield Promise.all(D._ExtensionNames.map(n=>i(this,void 0,void 0,function*(){const i=this._extensions[n];if(i.postExportMaterialAdditionalTexturesAsync){const n=yield i.postExportMaterialAdditionalTexturesAsync(e,t,s);r.push(...n)}}))),r})}_extensionsPostExportTextures(e,t,s){for(const r of D._ExtensionNames){const n=this._extensions[r];n.postExportTexture&&n.postExportTexture(e,t,s)}}_extensionsPostExportMeshPrimitive(e){for(const t of D._ExtensionNames){const s=this._extensions[t];s.postExportMeshPrimitive&&s.postExportMeshPrimitive(e,this._bufferManager,this._accessors)}}_extensionsPreGenerateBinaryAsync(){return i(this,void 0,void 0,function*(){for(const e of D._ExtensionNames){const t=this._extensions[e];t.preGenerateBinaryAsync&&(yield t.preGenerateBinaryAsync(this._bufferManager))}})}_forEachExtensions(e){for(const t of D._ExtensionNames){const s=this._extensions[t];s.enabled&&e(s)}}_extensionsOnExporting(){this._forEachExtensions(e=>{var t,s,r;e.wasUsed&&((t=this._glTF).extensionsUsed||(t.extensionsUsed=[]),-1===this._glTF.extensionsUsed.indexOf(e.name)&&this._glTF.extensionsUsed.push(e.name),e.required&&((s=this._glTF).extensionsRequired||(s.extensionsRequired=[]),-1===this._glTF.extensionsRequired.indexOf(e.name)&&this._glTF.extensionsRequired.push(e.name)),(r=this._glTF).extensions||(r.extensions={}),e.onExporting&&e.onExporting())})}_loadExtensions(){for(const e of D._ExtensionNames){const t=D._ExtensionFactories[e](this);this._extensions[e]=t}}constructor(e=t.EngineStore.LastCreatedScene,s){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 _(this),this._extensions={},this._bufferManager=new H,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"},s),this._loadExtensions()}dispose(){for(const e in this._extensions)this._extensions[e].dispose()}get options(){return this._options}static RegisterExtension(e,s,r=100){D.UnregisterExtension(e)&&t.Tools.Warn(`Extension with the name ${e} already exists`),D._ExtensionFactories[e]=s;const n=null!=r?r:0;D._ExtensionOrders[e]=n;let i=D._ExtensionNames.length;for(let e=0;e<D._ExtensionNames.length;e++){const t=D._ExtensionNames[e];if(n<D._ExtensionOrders[t]){i=e;break}}D._ExtensionNames.splice(i,0,e)}static UnregisterExtension(e){if(!D._ExtensionFactories[e])return!1;delete D._ExtensionFactories[e],delete D._ExtensionOrders[e];const t=D._ExtensionNames.indexOf(e);return-1!==t&&D._ExtensionNames.splice(t,1),!0}_generateJSON(e,t,s){const r={byteLength:e};return r.byteLength&&(this._glTF.buffers=[r]),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||(r.uri=t+".bin"),s?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)}generateGLTFAsync(e){return i(this,void 0,void 0,function*(){const t=yield this._generateBinaryAsync();this._extensionsOnExporting();const s=this._generateJSON(t.byteLength,e,!0),n=new Blob([t],{type:"application/octet-stream"}),i=e+".gltf",o=e+".bin",a=new r;if(a.files[i]=s,a.files[o]=n,this._imageData)for(const e in this._imageData)a.files[e]=this._imageData[e];return a})}_generateBinaryAsync(){return i(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 i(this,void 0,void 0,function*(){this._shouldUseGlb=!0;const t=yield this._generateBinaryAsync();this._extensionsOnExporting();const s=this._generateJSON(t.byteLength),n=e+".glb";let i,o=s.length;"undefined"!=typeof TextEncoder&&(i=(new TextEncoder).encode(s),o=i.length);const a=this._getPadding(o),u=this._getPadding(t.byteLength),l=28+o+a+t.byteLength+u,c=new P(l);if(c.writeUInt32(1179937895),c.writeUInt32(2),c.writeUInt32(l),c.writeUInt32(o+a),c.writeUInt32(1313821514),i)c.writeTypedArray(i);else{const e="_".charCodeAt(0);for(let t=0;t<o;++t){const r=s.charCodeAt(t);r!=s.codePointAt(t)?c.writeUInt8(e):c.writeUInt8(r)}}for(let e=0;e<a;++e)c.writeUInt8(32);c.writeUInt32(t.byteLength+u),c.writeUInt32(5130562),c.writeTypedArray(t);for(let e=0;e<u;++e)c.writeUInt8(0);const h=new r;return h.files[n]=new Blob([c.getOutputData()],{type:"application/octet-stream"}),h})}_setNodeTransformation(e,s,r){var n;if(s.getPivotPoint().equalsWithEpsilon(T,t.Epsilon)||t.Tools.Warn("Pivot points are not supported in the glTF serializer"),!s.position.equalsWithEpsilon(T,t.Epsilon)){const n=t.TmpVectors.Vector3[0].copyFrom(s.position);r&&C(n),e.translation=n.asArray()}s.scaling.equalsWithEpsilon(R,t.Epsilon)||(e.scale=s.scaling.asArray());const i=(null===(n=s.rotationQuaternion)||void 0===n?void 0:n.clone())||t.Quaternion.FromEulerAngles(s.rotation.x,s.rotation.y,s.rotation.z);i.equalsWithEpsilon(y,t.Epsilon)||(r&&V(i),e.rotation=i.normalize().asArray())}_setCameraTransformation(e,s,r){const n=t.TmpVectors.Vector3[0],i=t.TmpVectors.Quaternion[0],o=s.getWorldMatrix();if(s.parent){const e=s.parent.getWorldMatrix().invertToRef(t.TmpVectors.Matrix[0]);o.multiplyToRef(e,t.TmpVectors.Matrix[1]).decompose(void 0,i,n)}else o.decompose(void 0,i,n);n.equalsWithEpsilon(T,t.Epsilon)||(r&&C(n),e.translation=n.asArray()),r&&V(i),this._babylonScene.useRightHandedSystem||S(i),i.equalsWithEpsilon(y,t.Epsilon)||(e.rotation=i.asArray())}_listAvailableCameras(){for(const e of this._babylonScene.cameras){const s={type:e.mode===t.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(e.name&&(s.name=e.name),"perspective"===s.type)s.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"===s.type){const t=e.orthoLeft&&e.orthoRight?.5*(e.orthoRight-e.orthoLeft):.5*e.getEngine().getRenderWidth(),r=e.orthoBottom&&e.orthoTop?.5*(e.orthoTop-e.orthoBottom):.5*e.getEngine().getRenderHeight();s.orthographic={xmag:t,ymag:r,znear:e.minZ,zfar:e.maxZ}}this._camerasMap.set(e,s)}}_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 s;for(const r of this._babylonScene.skeletons){if(r.bones.length<=0)continue;const n=this._skinMap.get(r);if(null==n)continue;const i={};let o=-1;for(let e=0;e<r.bones.length;++e){const t=r.bones[e],n=null!==(s=t.getIndex())&&void 0!==s?s:e;-1!==n&&(i[n]=t,n>o&&(o=n))}const a=[];for(let s=0;s<=o;++s){const r=i[s],o=r.getTransformNode(),u=o?this._nodeMap.get(o):void 0;if(void 0===u){t.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.");continue}n.joints.push(u);const l=r.getAbsoluteInverseBindMatrix().clone();e.has(o)&&I(l),a.push(l)}const u=this._nodesSkinMap.get(n);if(n.joints.length>0&&void 0!==u){const e=new Float32Array(16*a.length);a.forEach((t,s)=>{e.set(t.m,16*s)});const t=this._bufferManager.createBufferView(e);this._accessors.push(this._bufferManager.createAccessor(t,"MAT4",5126,a.length)),n.inverseBindMatrices=this._accessors.length-1,this._skins.push(n);const s=this._skins.length-1;for(const e of u)e.skin=s}}}_exportSceneAsync(){return i(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 s=new Array,r=new Array,n=new Array;let i;if(this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes)for(const e of this._babylonScene.animationGroups)for(const s of e.targetedAnimations){const e=s.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&&m(e,this._babylonScene.useRightHandedSystem)&&!o?n.push(...e.getChildren()):this._babylonScene.useRightHandedSystem?s.push(e):r.push(e)}this._listAvailableCameras(),this._listAvailableSkeletons();const o=new G(!0,!1);e.nodes.push(...yield this._exportNodesAsync(r,o));const a=new G(!1,!1);e.nodes.push(...yield this._exportNodesAsync(s,a));const u=new G(!1,!0);e.nodes.push(...yield this._exportNodesAsync(n,u)),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(o.getNodesSet()),this._babylonScene.animationGroups.length&&z._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 i(this,void 0,void 0,function*(){const s=new Array;this._exportBuffers(e,t);for(const r of e)yield this._exportNodeAsync(r,s,t);return s})}_collectBuffers(e,s,r,n,i){if(this._shouldExportNode(e)&&e instanceof t.AbstractMesh&&e.geometry){const t=e.geometry.getVertexBuffers();if(t)for(const n in t){if(!E(n))continue;const o=t[n];i.setHasVertexColorAlpha(o,e.hasVertexAlpha);const a=o._buffer,u=s.get(a)||[];s.set(a,u),-1===u.indexOf(o)&&u.push(o);const l=r.get(o)||[];r.set(o,l),-1===l.indexOf(e)&&l.push(e)}const o=e.morphTargetManager;if(o)for(let t=0;t<o.numTargets;t++){const s=o.getTarget(t),r=n.get(s)||[];n.set(s,r),-1===r.indexOf(e)&&r.push(e)}}for(const t of e.getChildren())this._collectBuffers(t,s,r,n,i)}_exportBuffers(e,s){const r=new Map,n=new Map,i=new Map;for(const t of e)this._collectBuffers(t,r,n,i,s);const o=Array.from(r.keys());for(const e of o){const i=e.getData();if(!i)throw new Error("Buffer data is not available");const o=r.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 u=N(i).slice();for(const e of o){const s=n.get(e),{byteOffset:r,byteStride:i,componentCount:o,type:a,count:l,normalized:c,kind:h}=A(e,s);switch(h){case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:t.EnumerateFloatValues(u,r,i,o,a,l,c,e=>{const t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){const s=1/t;e[0]*=s,e[1]*=s,e[2]*=s}});break;case t.VertexBuffer.ColorKind:{const e=s.filter(e=>e.material instanceof t.StandardMaterial||null==e.material).length;if(0==e)break;if(e!=s.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 n=new t.Color3,h=new t.Color4,f=this._babylonScene.getEngine().useExactSrgbConversions;t.EnumerateFloatValues(u,r,i,o,a,l,c,e=>{3===e.length?(n.fromArray(e,0),n.toLinearSpaceToRef(n,f),n.toArray(e,0)):(h.fromArray(e,0),h.toLinearSpaceToRef(h,f),h.toArray(e,0))})}}}if(s.convertToRightHanded){for(const e of o){const s=n.get(e),{byteOffset:r,byteStride:i,componentCount:o,type:a,count:l,normalized:c,kind:h}=A(e,s);switch(h){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:t.EnumerateFloatValues(u,r,i,o,a,l,c,e=>{e[0]=-e[0]})}}s.convertedToRightHandedBuffers.set(e,u)}const l=this._bufferManager.createBufferView(u,a);s.setVertexBufferView(e,l);const c=new Map;for(const e of o){const s=n.get(e),{kind:r,totalVertices:i}=A(e,s);switch(r){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 r=c.get(t);if(!r)continue;const n=w(r),i=new(n?Uint16Array:Uint8Array)(r.length);for(let e=0;e<r.length;e++)i[e]=r[e];const o=this._bufferManager.createBufferView(i,4*(n?2:1));s.setRemappedBufferView(e,t,o)}}const a=Array.from(i.keys());for(const e of a){const t=i.get(e);if(!t)continue;const r=k(e,t[0],this._bufferManager,this._bufferViews,this._accessors,s.convertToRightHanded);for(const e of t)s.bindMorphDataToMesh(e,r)}}_exportNodeAsync(e,t,s){return i(this,void 0,void 0,function*(){let r=this._nodeMap.get(e);if(void 0!==r)return void(t.includes(r)||t.push(r));const n=yield this._createNodeAsync(e,s);if(n){r=this._nodes.length,this._nodes.push(n),this._nodeMap.set(e,r),s.pushExportedNode(e),t.push(r);const i={name:"runtime animations",channels:[],samplers:[]},o=[];this._babylonScene.animationGroups.length||(z._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,o,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,s.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&z._CreateNodeAnimationFromNodeAnimations(e,i,o,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,s.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=n?[]:t;for(const t of e.getChildren())yield this._exportNodeAsync(t,i,s);n&&i.length&&(n.children=i)})}_createNodeAsync(e,s){return i(this,void 0,void 0,function*(){var r,n,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,s.convertToRightHanded),e instanceof t.AbstractMesh)){const n=e instanceof t.InstancedMesh?e.sourceMesh:e;if(n.subMeshes&&n.subMeshes.length>0&&(o.mesh=yield this._exportMeshAsync(n,s)),e.skeleton){const t=this._skinMap.get(e.skeleton);void 0!==t&&(void 0===this._nodesSkinMap.get(t)&&this._nodesSkinMap.set(t,[]),null===(r=this._nodesSkinMap.get(t))||void 0===r||r.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,s.convertToRightHanded);const r=e.parent;if(null!==r&&B(e,r)){const e=this._nodeMap.get(r);if(void 0!==e){const s=this._nodes[e];return F(o,s),null===(n=this._nodesCameraMap.get(t))||void 0===n||n.push(s),null}}null===(i=this._nodesCameraMap.get(t))||void 0===i||i.push(o)}}return(yield this._extensionsPostExportNodeAsync("exportNodeAsync",o,e,this._nodeMap,s.convertToRightHanded))?o:(t.Logger.Warn(`Not exporting node ${e.name}`),null)})}_exportIndices(e,s,r,n,i,o,a,u,l){let c=null;l.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=s?new Uint32Array(n):new Uint16Array(n);if(e)for(let t=0;t+2<n;t+=3)a[t]=e[r+t]+i,a[t+1]=e[r+t+2]+i,a[t+2]=e[r+t+1]+i;else for(let e=0;e+2<n;e+=3)a[e]=e,a[e+1]=e+2,a[e+2]=e+1;c=a}else if(e&&0!==i){const t=s?new Uint32Array(n):new Uint16Array(n);for(let s=0;s<n;s++)t[s]=e[r+s]+i;c=t}else e&&(c=function(e,t,s,r){let n=e;return 0===t&&s===e.length||(n=Array.isArray(e)?e.slice(t,t+s):e.subarray(t,t+s)),n instanceof Int32Array?new Uint32Array(n.buffer,n.byteOffset,n.length):Array.isArray(n)?r?new Uint32Array(n):new Uint16Array(n):n}(e,r,n,s));if(c){let t=u.getIndicesAccessor(e,r,n,i,h);if(void 0===t){const o=this._bufferManager.createBufferView(c),a=s?5125:5123;this._accessors.push(this._bufferManager.createAccessor(o,"SCALAR",a,n,0)),t=this._accessors.length-1,u.setIndicesAccessor(e,r,n,i,h,t)}l.indices=t}}_exportVertexBuffer(e,s,r,n,i,o){const a=e.getKind();if(!E(a))return;if(a.startsWith("uv")&&!this._options.exportUnusedUVs&&(!s||!this._materialNeedsUVsSet.has(s)))return;let u=i.getVertexAccessor(e,r,n);if(void 0===u){const s=i.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),o=a===t.VertexBuffer.PositionKind?function(e,s,r,n){const{byteOffset:i,byteStride:o,type:a,normalized:u}=s,l=s.getSize(),c=new Array(l).fill(1/0),h=new Array(l).fill(-1/0);return t.EnumerateFloatValues(e,i+r*o,o,l,a,n*l,u,e=>{for(let t=0;t<l;t++)c[t]=Math.min(c[t],e[t]),h[t]=Math.max(h[t],e[t])}),{min:c,max:h}}(s,e,r,n):void 0,l=(a===t.VertexBuffer.MatricesIndicesKind||a===t.VertexBuffer.MatricesIndicesExtraKind)&&e.type===t.VertexBuffer.FLOAT,c=l?t.VertexBuffer.UNSIGNED_BYTE:e.type,h=l?void 0:e.normalized,f=l?i.getRemappedBufferView(e._buffer,e):i.getVertexBufferView(e._buffer),d=e.byteOffset+r*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(f,function(e,s){if(e==t.VertexBuffer.ColorKind)return s?"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,n,d,o,h)),u=this._accessors.length-1,i.setVertexAccessor(e,r,n,u)}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)]=u}_exportMaterialAsync(e,s,r,n){return i(this,void 0,void 0,function*(){let i=this._materialMap.get(e);if(void 0===i){const n=s&&Object.keys(s).some(e=>e.startsWith("uv"));if((e=e instanceof t.MultiMaterial?e.subMaterials[r.materialIndex]:e)instanceof t.PBRBaseMaterial)i=yield this._materialExporter.exportPBRMaterialAsync(e,n);else if(e instanceof t.StandardMaterial)i=yield this._materialExporter.exportStandardMaterialAsync(e,n);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,n)}this._materialMap.set(e,i)}n.material=i})}_exportMeshAsync(e,s){return i(this,void 0,void 0,function*(){var r,n,i,o,a,u;let l=s.getMesh(e);if(void 0!==l)return l;const c={primitives:[]};l=this._meshes.length,this._meshes.push(c),s.setMesh(e,l);const h=e.isUnIndexed?null:e.getIndices(),f=null===(r=e.geometry)||void 0===r?void 0:r.getVertexBuffers(),d=s.getMorphTargetsFromMesh(e),p=e instanceof t.LinesMesh,x=e instanceof t.GreasedLineBaseMesh,_=e.subMeshes;if(f&&_&&_.length>0)for(const r of _){const l={attributes:{}},_=r.getMaterial()||this._babylonScene.defaultMaterial;if(x){const s={name:_.name},r=e,u=t.Color3.White(),c=null!==(i=null===(n=r.material)||void 0===n?void 0:n.alpha)&&void 0!==i?i:1,h=null!==(a=null===(o=r.greasedLineMaterial)||void 0===o?void 0:o.color)&&void 0!==a?a:u;(!h.equalsWithEpsilon(u,t.Epsilon)||c<1)&&(s.pbrMetallicRoughness={baseColorFactor:[...h.asArray(),c]}),this._materials.push(s),l.material=this._materials.length-1}else if(p){const s={name:_.name},r=e;(!r.color.equalsWithEpsilon(t.Color3.White(),t.Epsilon)||r.alpha<1)&&(s.pbrMetallicRoughness={baseColorFactor:[...r.color.asArray(),r.alpha]}),this._materials.push(s),l.material=this._materials.length-1}else yield this._exportMaterialAsync(_,f,r,l);const g=p||x?t.Material.LineListDrawMode:null!==(u=e.overrideRenderingFillMode)&&void 0!==u?u:_.fillMode;let m=_._getEffectiveOrientation(e);s.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(m=m===t.Material.ClockWiseSideOrientation?t.Material.CounterClockWiseSideOrientation:t.Material.ClockWiseSideOrientation),this._exportIndices(h,h?t.AreIndices32Bits(h,r.indexCount,r.indexStart,r.verticesStart):r.verticesCount>65535,h?r.indexStart:r.verticesStart,h?r.indexCount:r.verticesCount,-r.verticesStart,g,m,s,l);for(const e of Object.values(f))this._exportVertexBuffer(e,_,r.verticesStart,r.verticesCount,s,l);if(d){l.targets=[];for(const e of d)l.targets.push(e.attributes)}c.primitives.push(l),this._extensionsPostExportMeshPrimitive(l)}if(d){c.weights=[],c.extras||(c.extras={}),c.extras.targetNames=[];for(const e of d)c.weights.push(e.influence),c.extras.targetNames.push(e.name)}return l})}}D._ExtensionNames=new Array,D._ExtensionFactories={},D._ExtensionOrders={};class q{static GLTFAsync(e,t,s){return i(this,void 0,void 0,function*(){s&&s.exportWithoutWaitingForScene||(yield e.whenReadyAsync());const r=new D(e,s),n=yield r.generateGLTFAsync(t.replace(/\.[^/.]+$/,""));return r.dispose(),n})}static GLBAsync(e,t,s){return i(this,void 0,void 0,function*(){s&&s.exportWithoutWaitingForScene||(yield e.whenReadyAsync());const r=new D(e,s),n=yield r.generateGLBAsync(t.replace(/\.[^/.]+$/,""));return r.dispose(),n})}}var $={__proto__:null,GLTF2Export:q};const X="EXT_mesh_gpu_instancing";function Q(e,t){const s=new Float32Array(3*t);for(let r=0;r<t;r++)s[3*r+0]=e[4*r+0],s[3*r+1]=e[4*r+1],s[3*r+2]=e[4*r+2];return s}class j{constructor(e){this.name=X,this.enabled=!0,this.required=!1,this._instanceColorWarned=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportNodeAsync(e,s,r,n,o,a){return i(this,void 0,void 0,function*(){return yield new Promise(e=>{var n,i;if(s&&r instanceof t.Mesh&&r.hasThinInstances&&this._exporter){this._wasUsed=!0;const e=t.Vector3.Zero(),u=t.Quaternion.Identity(),l=t.Vector3.One(),c=r.thinInstanceGetWorldMatrices(),h=t.TmpVectors.Vector3[2],f=t.TmpVectors.Quaternion[1],d=t.TmpVectors.Vector3[3];let p=!1,x=!1,_=!1;const g=new Float32Array(3*r.thinInstanceCount),m=new Float32Array(4*r.thinInstanceCount),T=new Float32Array(3*r.thinInstanceCount);let y=0;for(const t of c)t.decompose(d,f,h),o&&(C(h),V(f)),g.set(h.asArray(),3*y),m.set(f.normalize().asArray(),4*y),T.set(d.asArray(),3*y),p=p||!h.equalsWithEpsilon(e),x=x||!f.equalsWithEpsilon(u),_=_||!d.equalsWithEpsilon(l),y++;const R={attributes:{}};p&&(R.attributes.TRANSLATION=this._buildAccessor(g,"VEC3",r.thinInstanceCount,a)),x&&(R.attributes.ROTATION=this._buildAccessor(m,"VEC4",r.thinInstanceCount,a)),_&&(R.attributes.SCALE=this._buildAccessor(T,"VEC3",r.thinInstanceCount,a));let M=null===(i=null===(n=r._userThinInstanceBuffersStorage)||void 0===n?void 0:n.data)||void 0===i?void 0:i.instanceColor;if(M){const e=r.thinInstanceCount,s="VEC3";r.hasVertexAlpha&&M.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),M=Q(M,e)):M.length===4*e&&(M=Q(M,e)),M.length===3*e&&(R.attributes._COLOR_0=this._buildAccessor(M,s,e,a))}s.extensions=s.extensions||{},s.extensions[X]=R}e(s)})})}_buildAccessor(e,t,s,r){const n=r.createBufferView(e),i=r.createAccessor(n,t,5126,s);return this._exporter._accessors.push(i),this._exporter._accessors.length-1}}let Y=!1;function Z(){Y||(Y=!0,D.RegisterExtension(X,e=>new j(e)))}Z();const J="KHR_draco_mesh_compression";function ee(e){return"POSITION"===e?"POSITION":"NORMAL"===e?"NORMAL":e.startsWith("COLOR")?"COLOR":e.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"}class te{get wasUsed(){return this._wasUsed}constructor(e){this.name=J,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,s,r){if(!this.enabled)return;if(4!==e.mode&&5!==e.mode)return void t.Logger.Warn("Cannot compress primitive with mode "+e.mode+".");const n=[],i=[];let o=null;if(void 0!==e.indices){const t=r[e.indices],a=s.getBufferView(t);o=s.getData(a).slice(),n.push(a),i.push(t)}const a=[];for(const[o,u]of Object.entries(e.attributes)){const e=r[u],l=s.getBufferView(e),c=b(e.type),h=t.GetTypedArrayData(s.getData(l),c,e.componentType,e.byteOffset||0,l.byteStride||t.GetTypeByteLength(e.componentType)*c,e.count,!0);a.push({kind:o,dracoName:ee(o),size:b(e.type),data:h}),n.push(l),i.push(e)}const u={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},l=t.DracoEncoder.Default._encodeAsync(a,o,u).then(t=>{const r={bufferView:-1,attributes:t.attributeIds},o=s.createBufferView(t.data);s.setBufferView(r,o);for(const e of n)this._bufferViewsUsed.add(e);for(const e of i)this._accessorsUsed.add(e);e.extensions||(e.extensions={}),e.extensions[J]=r}).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(l),this._wasUsed=!0}preGenerateBinaryAsync(e){return i(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 se=!1;function re(){se||(se=!0,D.RegisterExtension(J,e=>new te(e)))}re();const ne="KHR_lights_punctual",ie={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},oe={innerConeAngle:0,outerConeAngle:Math.PI/4},ae=t.Vector3.Backward();class ue{constructor(e){this.name=ne,this.enabled=!0,this.required=!1,this._exporter=e}dispose(){this._lights=null}get wasUsed(){return!!this._lights}onExporting(){this._exporter._glTF.extensions[ne]=this._lights}postExportNodeAsync(e,s,r,n,o){return i(this,void 0,void 0,function*(){return yield new Promise(i=>{if(!(r instanceof t.Light))return void i(s);const a=r.getTypeID()==t.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==t.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==t.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(a&&r instanceof t.ShadowLight))return t.Logger.Warn(`${e}: Light ${r.name} is not supported in ${ne}`),void i(s);if(r.falloffType!==t.Light.FALLOFF_GLTF&&t.Logger.Warn(`${e}: Light falloff for ${r.name} does not match the ${ne} specification!`),!r.position.equalsToFloats(0,0,0)){const e=t.TmpVectors.Vector3[0].copyFrom(r.position);o&&C(e),s.translation=e.asArray()}if("point"!==a){const e=r.direction.normalizeToRef(t.TmpVectors.Vector3[0]);o&&C(e);const n=t.Quaternion.FromUnitVectorsToRef(ae,e,t.TmpVectors.Quaternion[0]);t.Quaternion.IsIdentity(n)||(s.rotation=n.asArray())}const u={type:a,name:r.name,color:r.diffuse.asArray(),intensity:r.intensity,range:r.range};if(U(u,ie),"spot"===a){const e=r;u.spot={innerConeAngle:e.innerAngle/2,outerConeAngle:e.angle/2},U(u.spot,oe)}this._lights||(this._lights={lights:[]}),this._lights.lights.push(u);const l={light:this._lights.lights.length-1},c=r.parent;if(c&&B(r,c)){const e=n.get(c);if(e){const t=this._exporter._nodes[e];return F(s,t),t.extensions||(t.extensions={}),t.extensions[ne]=l,void i(null)}}s.extensions||(s.extensions={}),s.extensions[ne]=l,i(s)})})}}let le=!1;function ce(){le||(le=!0,D.RegisterExtension(ne,e=>new ue(e)))}ce();const he="EXT_lights_area",fe={name:"",color:[1,1,1],intensity:1,size:1},de={aspect:1},pe=t.Vector3.Backward();class xe{constructor(e){this.name=he,this.enabled=!0,this.required=!1,this._exporter=e}dispose(){this._lights=null}get wasUsed(){return!!this._lights}onExporting(){this._exporter._glTF.extensions[he]=this._lights}postExportNodeAsync(e,s,r,n,o){return i(this,void 0,void 0,function*(){return yield new Promise(i=>{if(!(r instanceof t.Light))return void i(s);const a=r.getTypeID()==t.Light.LIGHTTYPEID_RECT_AREALIGHT?"rect":null;if(!a)return t.Logger.Warn(`${e}: Light ${r.name} is not supported in ${he}`),void i(s);const u=r;if(u.falloffType!==t.Light.FALLOFF_GLTF&&t.Logger.Warn(`${e}: Light falloff for ${r.name} does not match the ${he} specification!`),!u.position.equalsToFloats(0,0,0)){const e=t.TmpVectors.Vector3[0].copyFrom(u.position);o&&C(e),s.translation=e.asArray()}const l=t.Vector3.Forward();o&&C(l);const c=t.Quaternion.FromUnitVectorsToRef(pe,l,t.TmpVectors.Quaternion[0]);t.Quaternion.IsIdentity(c)||(s.rotation=c.asArray());const h={type:a,name:u.name,color:u.diffuse.asArray(),intensity:u.intensity,size:u.height,rect:{aspect:u.width/u.height}};U(h,fe),h.rect&&U(h.rect,de),this._lights||(this._lights={lights:[]}),this._lights.lights.push(h);const f={light:this._lights.lights.length-1},d=r.parent;if(d&&B(u,d)){const e=n.get(d);if(e){const t=this._exporter._nodes[e];return F(s,t),t.extensions||(t.extensions={}),t.extensions[he]=f,void i(null)}}s.extensions||(s.extensions={}),s.extensions[he]=f,i(s)})})}}let _e=!1;function ge(){_e||(_e=!0,D.RegisterExtension(he,e=>new xe(e)))}ge();const me="KHR_materials_anisotropy";class Te{constructor(e){this.name=me,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._anisoTexturesMap={},this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRBaseMaterial){if(r.anisotropy.isEnabled&&!r.anisotropy.legacy)return r.anisotropy.texture&&e.push(r.anisotropy.texture),e}else if(r instanceof t.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0){const s=function(e){const t=e.specularRoughnessAnisotropyTexture,s=e.geometryTangentTexture;return`${t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength"}_${s&&s.getInternalTexture()?s.getInternalTexture().uniqueId:"NoTangent"}`}(r);if(this._anisoTexturesMap[s])e.push(this._anisoTexturesMap[s]);else{const n=yield function(e){return i(this,void 0,void 0,function*(){const s=e.getScene(),r=e.specularRoughnessAnisotropyTexture,n=e.geometryTangentTexture;return r||n?yield t.MergeTexturesAsync("AnisotropyTexture",t.CreateRGBAConfiguration(n?t.CreateTextureInput(n,0):t.CreateConstantInput(1),n?t.CreateTextureInput(n,1):t.CreateConstantInput(0),r?t.CreateTextureInput(r,0):t.CreateConstantInput(1)),s):null})}(r);n&&(e.push(n),this._anisoTexturesMap[s]=n)}return e}return[]})}postExportMaterialAsync(e,s,r){return new Promise(e=>{var n;if(r instanceof t.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(s);this._wasUsed=!0,s.extensions=s.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(r.anisotropy.texture),n={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=t?t:void 0};null!==n.anisotropyTexture&&this._exporter._materialNeedsUVsSet.add(r),s.extensions[me]=n}else if(r instanceof t.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0){this._wasUsed=!0,s.extensions=s.extensions||{};let t=r.specularRoughnessTexture;r._useRoughnessFromMetallicTextureGreen&&(t=r.baseMetalnessTexture);const i=this._anisoTexturesMap[r.id];if(!t&&!i){let t=r.specularRoughness,n=r.specularRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){const e=function(e,t){const s=e*e,r=s*Math.sqrt(2/(1+(1-t)*(1-t))),n=(1-t)*r;return{newBaseRoughness:Math.sqrt(n),newAnisotropyStrength:Math.min(Math.sqrt((r-s)/Math.max(1-s,1e-4)),1)}}(r.specularRoughness,r.specularRoughnessAnisotropy);t=e.newBaseRoughness,n=e.newAnisotropyStrength}s.pbrMetallicRoughness&&(s.pbrMetallicRoughness.roughnessFactor=t);const i={anisotropyStrength:n,anisotropyRotation:r.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return s.extensions[me]=i,e(s)}const o=i?this._exporter._materialExporter.getTextureInfo(i):null,a={anisotropyStrength:r.specularRoughnessAnisotropy,anisotropyRotation:r.geometryTangentAngle,anisotropyTexture:o||void 0,extensions:{}};r._useGltfStyleAnisotropy||(s.extensions.KHR_materials_openpbr={},(n=this._exporter._glTF).extensionsUsed||(n.extensionsUsed=[]),-1===this._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&this._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr")),this._exporter._materialNeedsUVsSet.add(r),s.extensions[me]=a}e(s)})}}let ye=!1;function Re(){ye||(ye=!0,D.RegisterExtension(me,e=>new Te(e)))}Re();const Me="KHR_materials_clearcoat";function Ae(e,s){const r=new t.Texture(s.name,s.getScene());return r._texture=e,r.coordinatesIndex=s.coordinatesIndex,s instanceof t.Texture&&(r.uOffset=s.uOffset,r.vOffset=s.vOffset,r.uScale=s.uScale,r.vScale=s.vScale,r.wAng=s.wAng),r.wrapU=s.wrapU,r.wrapV=s.wrapV,r}class be{constructor(e){this.name=Me,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,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRBaseMaterial){if(r.clearCoat.isEnabled)return r.clearCoat.texture&&e.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&e.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&e.push(r.clearCoat.bumpTexture),e}else if(r instanceof t.OpenPBRMaterial&&r.coatWeight>0){let s=!1;if(r.coatWeightTexture?r.coatRoughnessTexture?r._useCoatRoughnessFromGreenChannel&&r.coatWeightTexture.getInternalTexture()===r.coatRoughnessTexture.getInternalTexture()?(e.push(r.coatWeightTexture),e.push(r.coatRoughnessTexture)):s=!0:e.push(r.coatWeightTexture):r.coatRoughnessTexture&&(r._useCoatRoughnessFromGreenChannel?e.push(r.coatRoughnessTexture):s=!0),s){const s=function(e){const t=e.coatWeightTexture,s=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",r=e.coatRoughnessTexture;return`${s}_${r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoRoughness"}`}(r);if(!this._cachedInternalTexturesMap[s]){const e=yield function(e){return i(this,void 0,void 0,function*(){const s=e.getScene(),r=e.coatWeightTexture,n=e.coatRoughnessTexture;return r||n?(yield t.MergeTexturesAsync("CoatTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),n?t.CreateTextureInput(n,e._useCoatRoughnessFromGreenChannel?1:0):t.CreateConstantInput(1)),s)).getInternalTexture():null})}(r);e&&(this._cachedInternalTexturesMap[s]=e)}this._cachedInternalTexturesMap[s]&&(r.coatWeightTexture&&(this._mergedTexturesMap[r.coatWeightTexture.uniqueId]=Ae(this._cachedInternalTexturesMap[s],r.coatWeightTexture),e.push(this._mergedTexturesMap[r.coatWeightTexture.uniqueId])),r.coatRoughnessTexture&&(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]=Ae(this._cachedInternalTexturesMap[s],r.coatRoughnessTexture),e.push(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId])))}return r.geometryCoatNormalTexture&&e.push(r.geometryCoatNormalTexture),e}return[]})}postExportMaterialAsync(e,s,r){return new Promise(e=>{if(r instanceof t.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(s);this._wasUsed=!0,s.extensions=s.extensions||{};const n=this._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);let i;i=r.clearCoat.useRoughnessFromMainTexture?this._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):this._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&t.Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${r.name}`),r.clearCoat.remapF0OnInterfaceChange&&t.Tools.Warn(`Clear Color F0 remapping is not supported for glTF export. Ignoring for: ${r.name}`);const o=this._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture),a={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=n?n:void 0,clearcoatRoughnessFactor:r.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(r),s.extensions[Me]=a}else if(r instanceof t.OpenPBRMaterial){if(0==r.coatWeight)return void e(s);let n,i,o,a;this._wasUsed=!0,s.extensions=s.extensions||{},r.coatWeightTexture&&(n=this._mergedTexturesMap[r.coatWeightTexture.uniqueId],i=this._exporter._materialExporter.getTextureInfo(n)),r.coatRoughnessTexture&&(o=this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId],a=this._exporter._materialExporter.getTextureInfo(o)),r.coatColorTexture&&t.Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${r.name}`);const u=this._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),l={clearcoatFactor:r.coatWeight,clearcoatTexture:null!=i?i:void 0,clearcoatRoughnessFactor:r.coatRoughness,clearcoatRoughnessTexture:null!=a?a:void 0,clearcoatNormalTexture:null!=u?u:void 0};null===l.clearcoatTexture&&null===l.clearcoatRoughnessTexture&&null===l.clearcoatRoughnessTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[Me]=l}e(s)})}}let we=!1;function Ee(){we||(we=!0,D.RegisterExtension(Me,e=>new be(e)))}Ee();const ve="KHR_materials_coat";function Ce(e){const t=e.coatRoughnessAnisotropyTexture,s=e.geometryCoatTangentTexture;return`${t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength"}_${s&&s.getInternalTexture()?s.getInternalTexture().uniqueId:"NoTangent"}`}function Ie(e,s){const r=new t.Texture(s.name,s.getScene());return r._texture=e,r.coordinatesIndex=s.coordinatesIndex,s instanceof t.Texture&&(r.uOffset=s.uOffset,r.vOffset=s.vOffset,r.uScale=s.uScale,r.vScale=s.vScale,r.wAng=s.wAng),r.wrapU=s.wrapU,r.wrapV=s.wrapV,r}class Ve{constructor(e){this.name=ve,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,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRBaseMaterial){if(r.clearCoat.isEnabled)return r.clearCoat.texture&&e.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&e.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&e.push(r.clearCoat.bumpTexture),r.clearCoat.tintTexture&&e.push(r.clearCoat.tintTexture),e}else if(r instanceof t.OpenPBRMaterial&&r.coatWeight>0){let s=!1;if(r.coatWeightTexture?r.coatRoughnessTexture?r._useCoatRoughnessFromGreenChannel&&r.coatWeightTexture.getInternalTexture()===r.coatRoughnessTexture.getInternalTexture()?(e.push(r.coatWeightTexture),e.push(r.coatRoughnessTexture)):s=!0:e.push(r.coatWeightTexture):r.coatRoughnessTexture&&(r._useCoatRoughnessFromGreenChannel?e.push(r.coatRoughnessTexture):s=!0),s){const s=function(e){const t=e.coatWeightTexture,s=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",r=e.coatRoughnessTexture;return`${s}_${r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoRoughness"}`}(r);if(!this._cachedInternalTexturesMap[s]){const e=yield function(e){return i(this,void 0,void 0,function*(){const s=e.getScene(),r=e.coatWeightTexture,n=e.coatRoughnessTexture;return r||n?(yield t.MergeTexturesAsync("CoatTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),n?t.CreateTextureInput(n,e._useCoatRoughnessFromGreenChannel?1:0):t.CreateConstantInput(1)),s)).getInternalTexture():null})}(r);e&&(this._cachedInternalTexturesMap[s]=e)}this._cachedInternalTexturesMap[s]&&(r.coatWeightTexture&&(this._mergedTexturesMap[r.coatWeightTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[s],r.coatWeightTexture),e.push(this._mergedTexturesMap[r.coatWeightTexture.uniqueId])),r.coatRoughnessTexture&&(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[s],r.coatRoughnessTexture),e.push(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId])))}if(r.geometryCoatNormalTexture&&e.push(r.geometryCoatNormalTexture),r.coatColorTexture&&e.push(r.coatColorTexture),r.coatRoughnessAnisotropy>0){const s=Ce(r);if(this._mergedTexturesMap[s])e.push(this._mergedTexturesMap[s]);else{const n=yield function(e){return i(this,void 0,void 0,function*(){const s=e.getScene(),r=e.coatRoughnessAnisotropyTexture,n=e.geometryCoatTangentTexture;return r||n?yield t.MergeTexturesAsync("AnisotropyTexture",t.CreateRGBAConfiguration(n?t.CreateTextureInput(n,0):t.CreateConstantInput(1),n?t.CreateTextureInput(n,1):t.CreateConstantInput(0),r?t.CreateTextureInput(r,0):t.CreateConstantInput(1)),s):null})}(r);n&&(e.push(n),this._mergedTexturesMap[s]=n)}return e}return e}return[]})}postExportMaterialAsync(e,s,r){return new Promise(e=>{var n;if(r instanceof t.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(s);this._wasUsed=!0,s.extensions=s.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);let n,i;n=r.clearCoat.useRoughnessFromMainTexture?this._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):this._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&(i=this._exporter._materialExporter.getTextureInfo(r.clearCoat.tintTexture));const o=this._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture),a=r.clearCoat.indexOfRefraction,u={coatFactor:r.clearCoat.intensity,coatTexture:null!=t?t:void 0,coatRoughnessFactor:r.clearCoat.roughness,coatRoughnessTexture:null!=n?n:void 0,coatNormalTexture:null!=o?o:void 0,coatColorFactor:r.clearCoat.tintColor.asArray(),coatColorTexture:null!=i?i:void 0,coatIor:1.5!==a?a:void 0};null===u.coatTexture&&null===u.coatRoughnessTexture&&null===u.coatRoughnessTexture&&null===u.coatColorTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[ve]=u}else if(r instanceof t.OpenPBRMaterial){if(0==r.coatWeight)return void e(s);let t,i,o,a;this._wasUsed=!0,s.extensions=s.extensions||{},r.coatWeightTexture&&(t=this._mergedTexturesMap[r.coatWeightTexture.uniqueId]?this._mergedTexturesMap[r.coatWeightTexture.uniqueId]:r.coatWeightTexture,i=this._exporter._materialExporter.getTextureInfo(t)),r.coatRoughnessTexture&&(o=this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]?this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]:r.coatRoughnessTexture,a=this._exporter._materialExporter.getTextureInfo(o));const u=this._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),l=this._exporter._materialExporter.getTextureInfo(r.coatColorTexture),c=r.coatIor,h=r.coatDarkening,f=r.coatRoughnessTexture,d=Ce(r),p=this._mergedTexturesMap[d];let x,_=0,g=0;if(r.coatRoughnessAnisotropy>0){if(f||p){const e=p?this._exporter._materialExporter.getTextureInfo(p):null;_=r.coatRoughnessAnisotropy,g=r.geometryCoatTangentAngle,x=e||void 0}else{let e=r.coatRoughness,t=r.coatRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){const s=function(e,t){const s=e*e,r=s*Math.sqrt(2/(1+(1-t)*(1-t))),n=(1-t)*r;return{newBaseRoughness:Math.sqrt(n),newAnisotropyStrength:Math.min(Math.sqrt((r-s)/Math.max(1-s,1e-4)),1)}}(r.coatRoughness,r.coatRoughnessAnisotropy);e=s.newBaseRoughness,t=s.newAnisotropyStrength}s.pbrMetallicRoughness&&(s.pbrMetallicRoughness.roughnessFactor=e),_=t,g=r.geometryCoatTangentAngle+.5*Math.PI,x=void 0}r._useGltfStyleAnisotropy||(s.extensions.KHR_materials_openpbr={},(n=this._exporter._glTF).extensionsUsed||(n.extensionsUsed=[]),-1===this._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&this._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr"))}const m={coatFactor:r.coatWeight,coatTexture:null!=i?i:void 0,coatRoughnessFactor:r.coatRoughness,coatRoughnessTexture:null!=a?a:void 0,coatNormalTexture:null!=u?u:void 0,coatColorFactor:r.coatColor.asArray(),coatColorTexture:null!=l?l:void 0,coatIor:1.5!==c?c:void 0,coatDarkeningFactor:1!==h?h:void 0,coatAnisotropyRotation:g,coatAnisotropyStrength:_,coatAnisotropyTexture:x};null===m.coatTexture&&null===m.coatRoughnessTexture&&null===m.coatRoughnessTexture&&null===m.coatAnisotropyTexture&&null===m.coatColorTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[ve]=m}e(s)})}}let Se=!1;function Fe(){Se||(Se=!0,D.RegisterExtension(ve,e=>new Ve(e)))}Fe();const Be="KHR_materials_diffuse_transmission";function Ne(e,s){const r=s.subSurface;let n=null;return r.translucencyIntensityTexture?n=r.translucencyIntensityTexture:r.thicknessTexture&&r.useMaskFromThicknessTexture&&(n=r.thicknessTexture),n&&!r.useGltfStyleTextures?(t.Logger.Warn(`${e}: Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ${s.name}`,1),null):n}class Ue{constructor(e){this.name=Be,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const s=[];if(r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)){const t=Ne(e,r);return t&&s.push(t),r.subSurface.translucencyColorTexture&&s.push(r.subSurface.translucencyColorTexture),s}return s})}_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,s,r){return new Promise(n=>{var i,o;if(r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0;const t=r.subSurface,n=Ne(e,r),a=0==t.translucencyIntensity?void 0:t.translucencyIntensity,u=null!==(i=this._exporter._materialExporter.getTextureInfo(n))&&void 0!==i?i:void 0,l=!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:u,diffuseTransmissionColorFactor:l,diffuseTransmissionColorTexture:c};(u||c)&&this._exporter._materialNeedsUVsSet.add(r),s.extensions=s.extensions||{},s.extensions[Be]=h}n(s)})}}let Oe=!1;function Ke(){Oe||(Oe=!0,D.RegisterExtension(Be,e=>new Ue(e)))}Ke();const Pe="KHR_materials_dispersion";class We{constructor(){this.name=Pe,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,s,r){return new Promise(e=>{if(r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0;const e={dispersion:r.subSurface.dispersion};s.extensions=s.extensions||{},s.extensions[Pe]=e}e(s)})}}let He=!1;function Le(){He||(He=!0,D.RegisterExtension(Pe,()=>new We))}Le();const ze="KHR_materials_emissive_strength";class ke{constructor(){this.name=ze,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAsync(e,s,r){return i(this,void 0,void 0,function*(){return yield new Promise(e=>{if(!(r instanceof t.PBRMaterial))return e(s);const n=r.emissiveColor.scale(r.emissiveIntensity),i=Math.max(...n.asArray());if(i>1){s.emissiveFactor=n.scale(1/i).asArray(),this._wasUsed=!0;const e={emissiveStrength:i};s.extensions||(s.extensions={}),s.extensions[ze]=e}else s.emissiveFactor=n.asArray();return e(s)})})}}let Ge=!1;function De(){Ge||(Ge=!0,D.RegisterExtension(ze,()=>new ke))}De();const qe="KHR_materials_ior";class $e{constructor(){this.name=qe,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,s,r){return new Promise(e=>{if(r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0;const e={ior:r.indexOfRefraction};s.extensions=s.extensions||{},s.extensions[qe]=e}else if(r instanceof t.OpenPBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0;const e={ior:r.specularIor};s.extensions=s.extensions||{},s.extensions[qe]=e}e(s)})}}let Xe=!1;function Qe(){Xe||(Xe=!0,D.RegisterExtension(qe,()=>new $e))}Qe();const je="KHR_materials_iridescence";class Ye{constructor(e){this.name=je,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRBaseMaterial){if(r.iridescence.isEnabled)return r.iridescence.texture&&e.push(r.iridescence.texture),r.iridescence.thicknessTexture&&r.iridescence.thicknessTexture!==r.iridescence.texture&&e.push(r.iridescence.thicknessTexture),e}else if(r instanceof t.OpenPBRMaterial&&r.thinFilmWeight>0)return r.thinFilmWeightTexture&&e.push(r.thinFilmWeightTexture),r.thinFilmThicknessTexture&&r.thinFilmThicknessTexture!==r.thinFilmWeightTexture&&e.push(r.thinFilmThicknessTexture),e;return[]})}postExportMaterialAsync(e,s,r){return new Promise(e=>{if(r instanceof t.PBRBaseMaterial){if(!r.iridescence.isEnabled)return void e(s);this._wasUsed=!0,s.extensions=s.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(r.iridescence.texture),n=this._exporter._materialExporter.getTextureInfo(r.iridescence.thicknessTexture),i={iridescenceFactor:r.iridescence.intensity,iridescenceIor:r.iridescence.indexOfRefraction,iridescenceThicknessMinimum:r.iridescence.minimumThickness,iridescenceThicknessMaximum:r.iridescence.maximumThickness,iridescenceTexture:null!=t?t:void 0,iridescenceThicknessTexture:null!=n?n:void 0};null===i.iridescenceTexture&&null===i.iridescenceThicknessTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[je]=i}else if(r instanceof t.OpenPBRMaterial){if(r.thinFilmWeight<=0)return void e(s);this._wasUsed=!0,s.extensions=s.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(r.thinFilmWeightTexture),n=this._exporter._materialExporter.getTextureInfo(r.thinFilmThicknessTexture),i={iridescenceFactor:r.thinFilmWeight,iridescenceIor:r.thinFilmIor,iridescenceThicknessMinimum:1e3*r.thinFilmThicknessMin,iridescenceThicknessMaximum:1e3*r.thinFilmThickness,iridescenceTexture:null!=t?t:void 0,iridescenceThicknessTexture:null!=n?n:void 0};null===i.iridescenceTexture&&null===i.iridescenceThicknessTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[je]=i}e(s)})}}let Ze=!1;function Je(){Ze||(Ze=!0,D.RegisterExtension(je,e=>new Ye(e)))}Je();const et="KHR_materials_sheen";class tt{constructor(e){this.name=et,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){return r instanceof t.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[r.sheen.texture]:[]})}postExportMaterialAsync(e,s,r){return i(this,void 0,void 0,function*(){return yield new Promise(e=>{var n,i,o,a;if(r instanceof t.PBRMaterial){if(!r.sheen.isEnabled)return void e(s);this._wasUsed=!0,null==s.extensions&&(s.extensions={});const t={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(n=r.sheen.roughness)&&void 0!==n?n:0};null===t.sheenColorTexture&&null===t.sheenRoughnessTexture||this._exporter._materialNeedsUVsSet.add(r),r.sheen.texture&&(t.sheenColorTexture=null!==(i=this._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==i?i:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?t.sheenRoughnessTexture=null!==(o=this._exporter._materialExporter.getTextureInfo(r.sheen.textureRoughness))&&void 0!==o?o:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(t.sheenRoughnessTexture=null!==(a=this._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==a?a:void 0),s.extensions[et]=t}e(s)})})}}let st=!1;function rt(){st||(st=!0,D.RegisterExtension(et,e=>new tt(e)))}rt();const nt="KHR_materials_fuzz";function it(e,s){const r=new t.Texture(s.name,s.getScene());return r._texture=e,r.coordinatesIndex=s.coordinatesIndex,s instanceof t.Texture&&(r.uOffset=s.uOffset,r.vOffset=s.vOffset,r.uScale=s.uScale,r.vScale=s.vScale,r.wAng=s.wAng),r.wrapU=s.wrapU,r.wrapV=s.wrapV,r}class ot{constructor(e){this.name=nt,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,s,r){return i(this,void 0,void 0,function*(){if(r instanceof t.OpenPBRMaterial){const e=[];if(r.fuzzWeight>0){r.fuzzWeightTexture&&e.push(r.fuzzWeightTexture);let s=!1;if(r.fuzzRoughnessTexture&&(r._useFuzzRoughnessFromTextureAlpha?e.push(r.fuzzRoughnessTexture):s=!0),r.fuzzColorTexture&&!s&&e.push(r.fuzzColorTexture),s){const s=function(e){const t=e.fuzzColorTexture,s=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoFuzzColor",r=e.fuzzRoughnessTexture;return`FuzzColor_${s}_FuzzRoughness_${r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoFuzzRoughness"}`}(r);if(!this._cachedInternalTexturesMap[s]){const e=yield function(e){return i(this,void 0,void 0,function*(){const s=e.getScene(),r=e.fuzzColorTexture,n=e.fuzzRoughnessTexture;return r||n?(yield t.MergeTexturesAsync("FuzzTexture",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),n?t.CreateTextureInput(n,e._useFuzzRoughnessFromTextureAlpha?3:0):t.CreateConstantInput(1)),s)).getInternalTexture():null})}(r);e&&(this._cachedInternalTexturesMap[s]=e)}this._cachedInternalTexturesMap[s]&&(r.fuzzColorTexture&&(this._mergedTexturesMap[r.fuzzColorTexture.uniqueId]=it(this._cachedInternalTexturesMap[s],r.fuzzColorTexture),e.push(this._mergedTexturesMap[r.fuzzColorTexture.uniqueId])),r.fuzzRoughnessTexture&&(this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]=it(this._cachedInternalTexturesMap[s],r.fuzzRoughnessTexture),e.push(this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId])))}}return e}return[]})}postExportMaterialAsync(e,s,r){return i(this,void 0,void 0,function*(){return yield new Promise(e=>{var n,i,o;if(r instanceof t.OpenPBRMaterial){if(0==r.fuzzWeight)return void e(s);this._wasUsed=!0,null==s.extensions&&(s.extensions={});const t={fuzzFactor:r.fuzzWeight,fuzzColorFactor:r.fuzzColor.asArray(),fuzzRoughnessFactor:r.fuzzRoughness};let a,u;r.fuzzWeightTexture&&(t.fuzzTexture=null!==(n=this._exporter._materialExporter.getTextureInfo(r.fuzzWeightTexture))&&void 0!==n?n:void 0),r.fuzzColorTexture&&(a=this._mergedTexturesMap[r.fuzzColorTexture.uniqueId]?this._mergedTexturesMap[r.fuzzColorTexture.uniqueId]:r.fuzzColorTexture,t.fuzzColorTexture=null!==(i=this._exporter._materialExporter.getTextureInfo(a))&&void 0!==i?i:void 0),r.fuzzRoughnessTexture&&(u=this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]?this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]:r.fuzzRoughnessTexture,t.fuzzRoughnessTexture=null!==(o=this._exporter._materialExporter.getTextureInfo(u))&&void 0!==o?o:void 0),null===t.fuzzColorTexture&&null===t.fuzzRoughnessTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[nt]=t}e(s)})})}}let at=!1;function ut(){at||(at=!0,D.RegisterExtension(nt,e=>new ot(e)))}ut();const lt="KHR_materials_specular";class ct{constructor(e){this.name=lt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];return r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)?(r.metallicReflectanceTexture&&e.push(r.metallicReflectanceTexture),r.reflectanceTexture&&e.push(r.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,s,r){return new Promise(e=>{var n,i,o,a,u;if(r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0,s.extensions=s.extensions||{};const e=null!==(n=this._exporter._materialExporter.getTextureInfo(r.metallicReflectanceTexture))&&void 0!==n?n:void 0,t=null!==(i=this._exporter._materialExporter.getTextureInfo(r.reflectanceTexture))&&void 0!==i?i:void 0,o={specularFactor:1==r.metallicF0Factor?void 0:r.metallicF0Factor,specularTexture:e,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:t};this._hasTexturesExtension(r)&&this._exporter._materialNeedsUVsSet.add(r),s.extensions[lt]=o}else if(r instanceof t.OpenPBRMaterial){s.extensions=s.extensions||{};const t=null!==(o=this._exporter._materialExporter.getTextureInfo(r.specularWeightTexture))&&void 0!==o?o:void 0,n=null!==(a=this._exporter._materialExporter.getTextureInfo(r.specularColorTexture))&&void 0!==a?a:void 0,i=1==r.specularWeight?void 0:r.specularWeight,l=r.specularColor.equalsFloats(1,1,1)?void 0:r.specularColor.asArray();if(!n&&!t&&void 0===i&&void 0===l)return e(s);this._wasUsed=!0;const c={specularEdgeColorEnabled:!0},h={specularFactor:i,specularTexture:t,specularColorFactor:l,specularColorTexture:n,extensions:{}};h.extensions.EXT_materials_specular_edge_color=c,(u=this._exporter._glTF).extensionsUsed||(u.extensionsUsed=[]),-1===this._exporter._glTF.extensionsUsed.indexOf("EXT_materials_specular_edge_color")&&this._exporter._glTF.extensionsUsed.push("EXT_materials_specular_edge_color"),(t||n)&&this._exporter._materialNeedsUVsSet.add(r),s.extensions[lt]=h}e(s)})}}let ht=!1;function ft(){ht||(ht=!0,D.RegisterExtension(lt,e=>new ct(e)))}ft();const dt="KHR_materials_transmission";class pt{constructor(e){this.name=dt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRMaterial){if(this._isExtensionEnabled(r))return r.subSurface.refractionIntensityTexture&&r.subSurface.useGltfStyleTextures&&e.push(r.subSurface.refractionIntensityTexture),e}else r instanceof t.OpenPBRMaterial&&(r.transmissionWeight>0&&r.transmissionWeightTexture&&(e.push(r.transmissionWeightTexture),r.transmissionColorTexture&&e.push(r.transmissionColorTexture)),r.subsurfaceWeight>0&&r.subsurfaceWeightTexture&&e.push(r.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,s,r){return i(this,void 0,void 0,function*(){if(!this._isExtensionEnabled(r))return s;if(r instanceof t.PBRMaterial){this._wasUsed=!0;const n=r.subSurface,i={transmissionFactor:0===n.refractionIntensity?void 0:n.refractionIntensity};if(n.refractionIntensityTexture)if(n.useGltfStyleTextures){this._exporter._materialNeedsUVsSet.add(r);const e=this._exporter._materialExporter.getTextureInfo(n.refractionIntensityTexture);e&&(i.transmissionTexture=e)}else t.Logger.Warn(`${e}: Exporting a subsurface refraction intensity texture without \`useGltfStyleTextures\` is not supported`);s.extensions||(s.extensions={}),s.extensions[dt]=i}else if(r instanceof t.OpenPBRMaterial){this._wasUsed=!0;const e={transmissionFactor:(1-r.transmissionWeight)*r.subsurfaceWeight+r.transmissionWeight};if(r.transmissionWeightTexture){this._exporter._materialNeedsUVsSet.add(r);const t=this._exporter._materialExporter.getTextureInfo(r.transmissionWeightTexture);t&&(e.transmissionTexture=t)}else if(r.subsurfaceWeightTexture){this._exporter._materialNeedsUVsSet.add(r);const t=this._exporter._materialExporter.getTextureInfo(r.subsurfaceWeightTexture);t&&(e.transmissionTexture=t)}if(0==r.transmissionDepth&&(!r.transmissionColor.equals(t.Color3.White())||r.transmissionColorTexture)&&s.pbrMetallicRoughness&&(s.pbrMetallicRoughness.baseColorFactor||(s.pbrMetallicRoughness.baseColorFactor=[1,1,1,1]),s.pbrMetallicRoughness.baseColorFactor[0]*=r.transmissionColor.r,s.pbrMetallicRoughness.baseColorFactor[1]*=r.transmissionColor.g,s.pbrMetallicRoughness.baseColorFactor[2]*=r.transmissionColor.b,r.transmissionColorTexture&&!s.pbrMetallicRoughness.baseColorTexture)){const e=this._exporter._materialExporter.getTextureInfo(r.transmissionColorTexture);e&&(s.pbrMetallicRoughness.baseColorTexture=e,this._exporter._materialNeedsUVsSet.add(r))}s.extensions||(s.extensions={}),s.extensions[dt]=e}return s})}}let xt=!1;function _t(){xt||(xt=!0,D.RegisterExtension(dt,e=>new pt(e)))}_t();const gt="KHR_materials_unlit";class mt{constructor(){this.name=gt,this.enabled=!0,this.required=!1,this._wasUsed=!1}get wasUsed(){return this._wasUsed}dispose(){}postExportMaterialAsync(e,s,r){return new Promise(e=>{let n=!1;r instanceof t.PBRMaterial?n=r.unlit:r instanceof t.StandardMaterial&&(n=r.disableLighting),n&&(this._wasUsed=!0,null==s.extensions&&(s.extensions={}),s.extensions[gt]={}),e(s)})}}let Tt=!1;function yt(){Tt||(Tt=!0,D.RegisterExtension(gt,()=>new mt))}yt();const Rt="KHR_materials_volume";class Mt{constructor(e){this.name=Rt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRMaterial){if(this._isExtensionEnabled(r))return r.subSurface.thicknessTexture&&e.push(r.subSurface.thicknessTexture),e}else r instanceof t.OpenPBRMaterial&&(r.transmissionWeight>0||r.subsurfaceWeight>0)&&r.geometryThicknessTexture&&e.push(r.geometryThicknessTexture);return e})}_isExtensionEnabled(e){if(e.unlit)return!1;const s=e.subSurface;return!(!s.isRefractionEnabled&&!s.isTranslucencyEnabled)&&(null!=s.maximumThickness&&0!=s.maximumThickness||null!=s.tintColorAtDistance&&s.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=s.tintColor&&s.tintColor!=t.Color3.White()||this._hasTexturesExtension(e))}_hasTexturesExtension(e){return null!=e.subSurface.thicknessTexture}postExportMaterialAsync(e,s,r){return new Promise(e=>{var n,i;if(r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0;const e=r.subSurface,t={thicknessFactor:0==e.maximumThickness?void 0:e.maximumThickness,thicknessTexture:null!==(n=this._exporter._materialExporter.getTextureInfo(e.thicknessTexture))&&void 0!==n?n: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(r)&&this._exporter._materialNeedsUVsSet.add(r),s.extensions=s.extensions||{},s.extensions[Rt]=t}else if(r instanceof t.OpenPBRMaterial){const e=r.transmissionWeight>0&&!r.geometryThinWalled,n=r.subsurfaceWeight>0&&!r.geometryThinWalled;if(e||n){this._wasUsed=!0;const o=r.geometryThickness,a=null!==(i=this._exporter._materialExporter.getTextureInfo(r.geometryThicknessTexture))&&void 0!==i?i:void 0;let u;a&&this._exporter._materialNeedsUVsSet.add(r);const l=t.Color3.White().asArray();if(e&&r.transmissionDepth>0){const e=1/r.transmissionDepth;let s=new t.Vector3(-Math.log(r.transmissionColor.r)*e,-Math.log(r.transmissionColor.g)*e,-Math.log(r.transmissionColor.b)*e);const n=new t.Vector3(r.transmissionScatter.r*e,r.transmissionScatter.g*e,r.transmissionScatter.b*e),i=s.subtract(n),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),s=i.add(n),u=1/Math.max(s.x,s.y,s.z),l[0]=Math.exp(-s.x*u),l[1]=Math.exp(-s.y*u),l[2]=Math.exp(-s.z*u)}else u=Number.MAX_VALUE,l[0]=1,l[1]=1,l[2]=1;let c=1;const h=t.Color3.White().asArray();if(n){const e=r.subsurfaceRadius,s=r.subsurfaceRadiusScale,n=new t.Vector3(s.r,s.g,s.b).multiplyByFloats(e,e,e),i=new t.Vector3(1/Math.max(n.x,1e-6),1/Math.max(n.y,1e-6),1/Math.max(n.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 f=(1-r.transmissionWeight)*r.subsurfaceWeight,d=f+r.transmissionWeight,p=1/Math.max(d,1e-6),x=r.transmissionWeight*p,_=f*p,g=l.map((e,t)=>e*x+h[t]*_),m={thicknessFactor:o,thicknessTexture:a,attenuationDistance:u*x+c*_,attenuationColor:g};s.extensions=s.extensions||{},s.extensions[Rt]=m}}e(s)})}}let At=!1;function bt(){At||(At=!0,D.RegisterExtension(Rt,e=>new Mt(e)))}bt();const wt="KHR_materials_volume_scatter";class Et{constructor(e){this.name=wt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];return r instanceof t.OpenPBRMaterial&&(r.transmissionWeight>0&&r.transmissionScatterTexture&&e.push(r.transmissionScatterTexture),r.subsurfaceWeight>0&&r.subsurfaceColorTexture&&e.push(r.subsurfaceColorTexture)),e})}_isExtensionEnabled(e){if(e.unlit)return!1;const s=e.transmissionWeight>0&&!e.geometryThinWalled&&e.transmissionDepth>0&&!e.transmissionScatter.equals(t.Color3.Black()),r=e.subsurfaceWeight>0&&!e.geometryThinWalled;return!(!s&&!r)}postExportMaterialAsync(e,s,r){return new Promise(e=>{if(r instanceof t.OpenPBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0;let e=t.Vector3.Zero(),n=0;r.transmissionWeight>0&&(e=function(e){const s=new t.Vector3(Math.sqrt(1-e.x),Math.sqrt(1-e.y),Math.sqrt(1-e.z)),r=new t.Vector3(1,1,1),n=r.subtract(s),i=r.subtract(new t.Vector3(.139,.139,.139).multiplyInPlace(s)),o=r.add(new t.Vector3(1.17,1.17,1.17).multiplyInPlace(s));return n.multiplyInPlace(i).divideInPlace(o)}(new t.Vector3(r.transmissionScatter.r,r.transmissionScatter.g,r.transmissionScatter.b)),n=r.transmissionScatterAnisotropy);const i=t.Vector3.Zero();let o=0;r.subsurfaceWeight>0&&(i.set(r.subsurfaceColor.r,r.subsurfaceColor.g,r.subsurfaceColor.b),o=r.subsurfaceScatterAnisotropy);const a=(1-r.transmissionWeight)*r.subsurfaceWeight,u=a+r.transmissionWeight,l=1/Math.max(u,1e-6),c=r.transmissionWeight*l,h=a*l,f={multiscatterColorFactor:e.multiplyByFloats(c,c,c).addInPlace(i.multiplyByFloats(h,h,h)).asArray(),scatterAnisotropy:n*c+o*h};if(r.subsurfaceWeight>0&&r.subsurfaceColorTexture){this._exporter._materialNeedsUVsSet.add(r);const e=this._exporter._materialExporter.getTextureInfo(r.subsurfaceColorTexture);e&&(f.multiscatterColorTexture=e)}else if(r.transmissionWeight>0&&r.transmissionScatterTexture){this._exporter._materialNeedsUVsSet.add(r);const e=this._exporter._materialExporter.getTextureInfo(r.transmissionScatterTexture);e&&(f.multiscatterColorTexture=e)}s.extensions=s.extensions||{},s.extensions[wt]=f}e(s)})}}let vt=!1;function Ct(){vt||(vt=!0,D.RegisterExtension(wt,e=>new Et(e),101))}Ct();const It="KHR_materials_diffuse_roughness";class Vt{constructor(e){this.name=It,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRBaseMaterial){if(r._baseDiffuseRoughness)return r._baseDiffuseRoughnessTexture&&e.push(r._baseDiffuseRoughnessTexture),e}else if(r instanceof t.OpenPBRMaterial&&r.baseDiffuseRoughness)return r.baseDiffuseRoughnessTexture&&e.push(r.baseDiffuseRoughnessTexture),e;return[]})}postExportMaterialAsync(e,s,r){return new Promise(e=>{let n=null,i=null;if(r instanceof t.PBRBaseMaterial?(n=r._baseDiffuseRoughness,i=r._baseDiffuseRoughnessTexture):r instanceof t.OpenPBRMaterial&&(n=r.baseDiffuseRoughness,i=r.baseDiffuseRoughnessTexture),!n)return void e(s);this._wasUsed=!0,s.extensions=s.extensions||{};const o=this._exporter._materialExporter.getTextureInfo(i),a={diffuseRoughnessFactor:n,diffuseRoughnessTexture:null!=o?o:void 0};null!==a.diffuseRoughnessTexture&&this._exporter._materialNeedsUVsSet.add(r),s.extensions[It]=a,e(s)})}}let St=!1;function Ft(){St||(St=!0,D.RegisterExtension(It,e=>new Vt(e)))}Ft();const Bt="KHR_materials_openpbr";class Nt{constructor(){this.name=Bt,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAsync(e,s,r){return new Promise(e=>{r instanceof t.OpenPBRMaterial&&(this._wasUsed=!0,s.extensions=s.extensions||{},s.extensions[Bt]={}),e(s)})}}let Ut=!1;function Ot(){Ut||(Ut=!0,D.RegisterExtension(Bt,()=>new Nt))}Ot();const Kt="KHR_texture_transform";class Pt{constructor(){this.name=Kt,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}postExportTexture(e,s,r){if(r.getScene()||t.Tools.Warn(`${e}: "scene" is not defined for Babylon texture ${r.name}!`),(0!==r.uAng||0!==r.vAng)&&(t.Tools.Warn(`${e}: Texture ${r.name} with rotation in the u or v axis is not supported in glTF.`),0!==r.uRotationCenter||0!==r.vRotationCenter))return;const n={};let i=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],i=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],i=!0),0!==r.wAng){if(0!==r.uRotationCenter||0!==r.vRotationCenter){if(r.homogeneousRotationInUVTransform&&r.uScale!==r.vScale)return void t.Tools.Warn(`${e}: Texture ${r.name} with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ${Kt}.`);t.Tools.Warn(`${e}: Texture ${r.name} with non-origin rotation center will be exported using an adjusted offset with ${Kt}.`),n.offset=function(e){const{uOffset:t,vOffset:s,uRotationCenter:r,vRotationCenter:n,uScale:i,vScale:o,wAng:a}=e,u=Math.cos(a),l=Math.sin(a),c=r*i,h=n*o;return[t+(c*(1-u)+h*l),s+(h*(1-u)-c*l)]}(r)}n.rotation=-r.wAng,i=!0}0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,i=!0),i&&(this._wasUsed=!0,s.extensions||(s.extensions={}),s.extensions[Kt]=n)}}let Wt=!1;function Ht(){Wt||(Wt=!0,D.RegisterExtension(Kt,()=>new Pt))}Ht();const Lt="KHR_texture_basisu";class zt{get wasUsed(){return this._wasUsed}constructor(e){this.name=Lt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}dispose(){}postExportTexture(e,s){const r=this._exporter._textures[s.index],n=r.source;if(void 0===n)return;const i=this._exporter._images[n];"image/ktx2"===(i.mimeType||t.GetMimeType(i.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[Lt]={source:n},this._wasUsed=!0)}}let kt=!1;function Gt(){kt||(kt=!0,D.RegisterExtension(Lt,e=>new zt(e)))}Gt();const Dt="EXT_texture_webp";class qt{get wasUsed(){return this._wasUsed}constructor(e){this.name=Dt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}dispose(){}postExportTexture(e,s){const r=this._exporter._textures[s.index],n=r.source;if(void 0===n)return;const i=this._exporter._images[n];"image/webp"===(i.mimeType||t.GetMimeType(i.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[Dt]={source:n},this._wasUsed=!0)}}let $t=!1;function Xt(){$t||($t=!0,D.RegisterExtension(Dt,e=>new qt(e)))}Xt();const Qt="EXT_texture_avif";class jt{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,s){const r=this._exporter._textures[s.index],n=r.source;if(void 0===n)return;const i=this._exporter._images[n];"image/avif"===(i.mimeType||t.GetMimeType(i.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[Qt]={source:n},this._wasUsed=!0)}}let Yt=!1;function Zt(){Yt||(Yt=!0,D.RegisterExtension(Qt,e=>new jt(e)))}Zt();var Jt={__proto__:null,EXT_lights_area:xe,EXT_mesh_gpu_instancing:j,EXT_texture_avif:jt,EXT_texture_webp:qt,KHR_draco_mesh_compression:te,KHR_lights_punctual:ue,KHR_materials_anisotropy:Te,KHR_materials_clearcoat:be,KHR_materials_coat:Ve,KHR_materials_diffuse_roughness:Vt,KHR_materials_diffuse_transmission:Ue,KHR_materials_dispersion:We,KHR_materials_emissive_strength:ke,KHR_materials_fuzz:ot,KHR_materials_ior:$e,KHR_materials_iridescence:Ye,KHR_materials_openpbr:Nt,KHR_materials_sheen:tt,KHR_materials_specular:ct,KHR_materials_transmission:pt,KHR_materials_unlit:mt,KHR_materials_volume:Mt,KHR_materials_volume_scatter:Et,KHR_texture_basisu:zt,KHR_texture_transform:Pt,RegisterEXT_lights_area:ge,RegisterEXT_mesh_gpu_instancing:Z,RegisterEXT_texture_avif:Zt,RegisterEXT_texture_webp:Xt,RegisterKHR_draco_mesh_compression:re,RegisterKHR_lights_punctual:ce,RegisterKHR_materials_anisotropy:Re,RegisterKHR_materials_clearcoat:Ee,RegisterKHR_materials_coat:Fe,RegisterKHR_materials_diffuse_roughness:Ft,RegisterKHR_materials_diffuse_transmission:Ke,RegisterKHR_materials_dispersion:Le,RegisterKHR_materials_emissive_strength:De,RegisterKHR_materials_fuzz:ut,RegisterKHR_materials_ior:Qe,RegisterKHR_materials_iridescence:Je,RegisterKHR_materials_openpbr:Ot,RegisterKHR_materials_sheen:rt,RegisterKHR_materials_specular:ft,RegisterKHR_materials_transmission:_t,RegisterKHR_materials_unlit:yt,RegisterKHR_materials_volume:bt,RegisterKHR_materials_volume_scatter:Ct,RegisterKHR_texture_basisu:Gt,RegisterKHR_texture_transform:Ht},es={__proto__:null,EXT_lights_area:xe,EXT_mesh_gpu_instancing:j,EXT_texture_avif:jt,EXT_texture_webp:qt,GLTF2Export:q,GLTFData:r,KHR_draco_mesh_compression:te,KHR_lights_punctual:ue,KHR_materials_anisotropy:Te,KHR_materials_clearcoat:be,KHR_materials_coat:Ve,KHR_materials_diffuse_roughness:Vt,KHR_materials_diffuse_transmission:Ue,KHR_materials_dispersion:We,KHR_materials_emissive_strength:ke,KHR_materials_fuzz:ot,KHR_materials_ior:$e,KHR_materials_iridescence:Ye,KHR_materials_openpbr:Nt,KHR_materials_sheen:tt,KHR_materials_specular:ct,KHR_materials_transmission:pt,KHR_materials_unlit:mt,KHR_materials_volume:Mt,KHR_materials_volume_scatter:Et,KHR_texture_basisu:zt,KHR_texture_transform:Pt,RegisterEXT_lights_area:ge,RegisterEXT_mesh_gpu_instancing:Z,RegisterEXT_texture_avif:Zt,RegisterEXT_texture_webp:Xt,RegisterKHR_draco_mesh_compression:re,RegisterKHR_lights_punctual:ce,RegisterKHR_materials_anisotropy:Re,RegisterKHR_materials_clearcoat:Ee,RegisterKHR_materials_coat:Fe,RegisterKHR_materials_diffuse_roughness:Ft,RegisterKHR_materials_diffuse_transmission:Ke,RegisterKHR_materials_dispersion:Le,RegisterKHR_materials_emissive_strength:De,RegisterKHR_materials_fuzz:ut,RegisterKHR_materials_ior:Qe,RegisterKHR_materials_iridescence:Je,RegisterKHR_materials_openpbr:Ot,RegisterKHR_materials_sheen:rt,RegisterKHR_materials_specular:ft,RegisterKHR_materials_transmission:_t,RegisterKHR_materials_unlit:yt,RegisterKHR_materials_volume:bt,RegisterKHR_materials_volume_scatter:Ct,RegisterKHR_texture_basisu:Gt,RegisterKHR_texture_transform:Ht,_ConvertToGLTFPBRMetallicRoughness:f,_SolveMetallic:h};const ts="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==ts){ts.BABYLON=ts.BABYLON||{};const e=ts.BABYLON;e.GLTF2=e.GLTF2||{},e.GLTF2.Exporter=e.GLTF2.Exporter||{},e.GLTF2.Exporter.Extensions=e.GLTF2.Exporter.Extensions||{};const t=[];for(const r in s)e[r]=s[r],t.push(r);for(const s in n)e[s]=n[s],t.push(s);for(const s in $)e[s]=$[s],t.push(s);for(const s in Jt)e.GLTF2.Exporter.Extensions[s]=Jt[s],t.push(s);for(const s in es)t.indexOf(s)>-1||(e.GLTF2.Exporter[s]=es[s])}e.EXT_lights_area=xe,e.EXT_mesh_gpu_instancing=j,e.EXT_texture_avif=jt,e.EXT_texture_webp=qt,e.GLTF2Export=q,e.GLTFData=r,e.KHR_draco_mesh_compression=te,e.KHR_lights_punctual=ue,e.KHR_materials_anisotropy=Te,e.KHR_materials_clearcoat=be,e.KHR_materials_coat=Ve,e.KHR_materials_diffuse_roughness=Vt,e.KHR_materials_diffuse_transmission=Ue,e.KHR_materials_dispersion=We,e.KHR_materials_emissive_strength=ke,e.KHR_materials_fuzz=ot,e.KHR_materials_ior=$e,e.KHR_materials_iridescence=Ye,e.KHR_materials_openpbr=Nt,e.KHR_materials_sheen=tt,e.KHR_materials_specular=ct,e.KHR_materials_transmission=pt,e.KHR_materials_unlit=mt,e.KHR_materials_volume=Mt,e.KHR_materials_volume_scatter=Et,e.KHR_texture_basisu=zt,e.KHR_texture_transform=Pt,e.RegisterEXT_lights_area=ge,e.RegisterEXT_mesh_gpu_instancing=Z,e.RegisterEXT_texture_avif=Zt,e.RegisterEXT_texture_webp=Xt,e.RegisterKHR_draco_mesh_compression=re,e.RegisterKHR_lights_punctual=ce,e.RegisterKHR_materials_anisotropy=Re,e.RegisterKHR_materials_clearcoat=Ee,e.RegisterKHR_materials_coat=Fe,e.RegisterKHR_materials_diffuse_roughness=Ft,e.RegisterKHR_materials_diffuse_transmission=Ke,e.RegisterKHR_materials_dispersion=Le,e.RegisterKHR_materials_emissive_strength=De,e.RegisterKHR_materials_fuzz=ut,e.RegisterKHR_materials_ior=Qe,e.RegisterKHR_materials_iridescence=Je,e.RegisterKHR_materials_openpbr=Ot,e.RegisterKHR_materials_sheen=rt,e.RegisterKHR_materials_specular=ft,e.RegisterKHR_materials_transmission=_t,e.RegisterKHR_materials_unlit=yt,e.RegisterKHR_materials_volume=bt,e.RegisterKHR_materials_volume_scatter=Ct,e.RegisterKHR_texture_basisu=Gt,e.RegisterKHR_texture_transform=Ht,e._ConvertToGLTFPBRMetallicRoughness=f,e._SolveMetallic=h,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";var s={__proto__:null,__IGLTFExporterExtension:0};class r{constructor(){this.files={}}get glTFFiles(){return this.files}downloadFiles(){for(const e in this.files){const s=this.files[e],r=new Blob([s],{type:t.GetMimeType(e)});t.Tools.Download(r,e)}}}var n={__proto__:null,GLTFData:r};function i(e,t,s,r){return new(s||(s=Promise))(function(n,i){function o(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(o,a)}u((r=r.apply(e,t||[])).next())})}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;const o=1e-6,a=new t.Color3(.04,.04,.04),u=t.Color3.White(),l=t.Color3.BlackReadOnly;function c(e){switch(e){case"image/jpeg":case"image/png":case"image/webp":case"image/avif":case"image/ktx2":return!0;default:return!1}}function h(e,s,r){if(s<a.r)return 0;const n=a.r,i=e*r/(1-a.r)+s-2*a.r,o=i*i-4*n*(a.r-s);return t.Scalar.Clamp((-i+Math.sqrt(o))/(2*n),0,1)}function d(e){const s=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),r=e.alpha,n=t.Scalar.Clamp(e.specularPower,0,1024),i=t.SpecularPowerToRoughness(n);return{baseColorFactor:[s.r,s.g,s.b,r],metallicFactor:0,roughnessFactor:i}}function f(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function x(e,s,r){const n=new Uint8Array(e*s*4);for(let e=0;e<n.length;e+=4)n[e]=n[e+1]=n[e+2]=n[e+3]=255;return t.RawTexture.CreateRGBATexture(n,e,s,r)}function p(e){if(e instanceof Uint8Array){const t=e.length,s=new Float32Array(e.length);for(let r=0;r<t;++r)s[r]=e[r]/255;return s}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")}class _{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,s){return i(this,void 0,void 0,function*(){const r=d(e),n={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."),n.doubleSided=!0),s){const t=[],s=e.diffuseTexture;s&&t.push(this.exportTextureAsync(s).then(e=>{e&&(r.baseColorTexture=e)}));const i=e.bumpTexture;i&&t.push(this.exportTextureAsync(i).then(e=>{e&&(n.normalTexture=e,1!==i.level&&(n.normalTexture.scale=i.level))}));const o=e.emissiveTexture;o&&(n.emissiveFactor=[1,1,1],t.push(this.exportTextureAsync(o).then(e=>{e&&(n.emissiveTexture=e)})));const a=e.ambientTexture;a&&t.push(this.exportTextureAsync(a).then(e=>{if(e){const t={index:e.index};n.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?n.alphaMode="BLEND":t.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(l,o)&&(n.emissiveFactor=e.emissiveColor.asArray()),n.pbrMetallicRoughness=r,f(n,e),yield this._finishMaterialAsync(n,e);const i=this._exporter._materials;return i.push(n),i.length-1})}_finishMaterialAsync(e,t){return i(this,void 0,void 0,function*(){const s=yield this._exporter._extensionsPostExportMaterialAdditionalTexturesAsync("exportMaterial",e,t),r=[];for(const e of s)r.push(this.exportTextureAsync(e));yield Promise.all(r),yield this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)})}_resizeTexturesToSameDimensions(e,s,r){const n=e?e.getSize():{width:0,height:0},i=s?s.getSize():{width:0,height:0};let o,a;return n.width<i.width?(o=e&&e instanceof t.Texture?t.TextureTools.CreateResizedCopy(e,i.width,i.height,!0):x(i.width,i.height,r),a=s):n.width>i.width?(a=s&&s instanceof t.Texture?t.TextureTools.CreateResizedCopy(s,n.width,n.height,!0):x(n.width,n.height,r),o=e):(o=e,a=s),{texture1:o,texture2:a}}_convertSpecularGlossinessTexturesToMetallicRoughnessAsync(e,s,r){return i(this,void 0,void 0,function*(){var n;const i=new Array;if(!e&&!s)return yield Promise.reject("diffuse and specular glossiness textures are not defined!");const a=e?e.getScene():s?s.getScene():null;if(a){const l=this._resizeTexturesToSameDimensions(e,s,a),c=null===(n=l.texture1)||void 0===n?void 0:n.getSize();let h,d;const f=c.width,x=c.height,_=yield l.texture1.readPixels(),g=yield l.texture2.readPixels();if(!_)return yield Promise.reject("Failed to retrieve pixels from diffuse texture!");if(h=p(_),!g)return yield Promise.reject("Failed to retrieve pixels from specular glossiness texture!");d=p(g);const m=d.byteLength,T=new Uint8Array(m),y=new Uint8Array(m),R=4,M=new t.Color3(0,0,0);let A=0,b=0;for(let e=0;e<x;++e)for(let s=0;s<f;++s){const n=(f*e+s)*R,i={diffuseColor:new t.Color3(h[n],h[n+1],h[n+2]).toLinearSpace(a.getEngine().useExactSrgbConversions).multiply(r.diffuseColor),specularColor:new t.Color3(d[n],d[n+1],d[n+2]).toLinearSpace(a.getEngine().useExactSrgbConversions).multiply(r.specularColor),glossiness:d[n+3]*r.glossiness},o=this._convertSpecularGlossinessToMetallicRoughness(i);M.r=Math.max(M.r,o.baseColor.r),M.g=Math.max(M.g,o.baseColor.g),M.b=Math.max(M.b,o.baseColor.b),A=Math.max(A,o.metallic),b=Math.max(b,o.roughness),y[n]=255*o.baseColor.r,y[n+1]=255*o.baseColor.g,y[n+2]=255*o.baseColor.b,y[n+3]=l.texture1.hasAlpha?255*h[n+3]:255,T[n]=0,T[n+1]=255*o.roughness,T[n+2]=255*o.metallic,T[n+3]=255}const v={baseColor:M,metallic:A,roughness:b};let w=!1,E=!1;for(let e=0;e<x;++e)for(let s=0;s<f;++s){const r=(f*e+s)*R;y[r]/=v.baseColor.r>o?v.baseColor.r:1,y[r+1]/=v.baseColor.g>o?v.baseColor.g:1,y[r+2]/=v.baseColor.b>o?v.baseColor.b:1;const n=t.Color3.FromInts(y[r],y[r+1],y[r+2]).toGammaSpace(a.getEngine().useExactSrgbConversions);y[r]=255*n.r,y[r+1]=255*n.g,y[r+2]=255*n.b,n.equalsWithEpsilon(u,o)||(E=!0),T[r+1]/=v.roughness>o?v.roughness:1,T[r+2]/=v.metallic>o?v.metallic:1,t.Color3.FromInts(255,T[r+1],T[r+2]).equalsWithEpsilon(u,o)||(w=!0)}return w&&i.push(t.EncodeImageAsync(T,f,x).then(e=>{v.metallicRoughnessTextureData=e})),E&&i.push(t.EncodeImageAsync(y,f,x).then(e=>{v.baseColorTextureData=e})),yield Promise.all(i).then(()=>v)}return yield Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")})}_convertSpecularGlossinessToMetallicRoughness(e){const s=this._getPerceivedBrightness(e.diffuseColor),r=this._getPerceivedBrightness(e.specularColor),n=1-this._getMaxComponent(e.specularColor),i=h(s,r,n),u=e.diffuseColor.scale(n/(1-a.r)/Math.max(1-i,o)),l=e.specularColor.subtract(a.scale(1-i)).scale(1/Math.max(i,o));let c=t.Color3.Lerp(u,l,i*i);return c=c.clampToRef(0,1,c),{baseColor:c,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,s,r,n,o,a,u,l,c){return i(this,void 0,void 0,function*(){const h=[],d={baseColor:e,metallic:s,roughness:r};if(c)if(u instanceof t.OpenPBRMaterial){if(u.geometryOpacityTexture){const e=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:0,s=u.geometryOpacityTexture&&u.geometryOpacityTexture.getInternalTexture()?u.geometryOpacityTexture.getInternalTexture().uniqueId:0,r=Number(`${e}${s}`),o=this._textureMap.get(r);o?l.baseColorTexture=o:h.push(t.MergeTexturesAsync("baseColorOpacityTexture",t.CreateRGBAConfiguration(n?t.CreateTextureInput(n,0):t.CreateConstantInput(1),n?t.CreateTextureInput(n,1):t.CreateConstantInput(1),n?t.CreateTextureInput(n,2):t.CreateConstantInput(1),t.CreateTextureInput(u.geometryOpacityTexture,0)),u.getScene()).then(e=>i(this,void 0,void 0,function*(){const t=yield this.exportTextureAsync(e,r);t&&(l.baseColorTexture=t)})))}else n&&h.push(this.exportTextureAsync(n).then(e=>{e&&(l.baseColorTexture=e)}));if(u._useMetallicFromMetallicTextureBlue&&o)h.push(this.exportTextureAsync(o).then(e=>{e&&(l.metallicRoughnessTexture=e)}));else if(a||o){const e=o&&o.getInternalTexture()?o.getInternalTexture().uniqueId:0,s=a&&a.getInternalTexture()?a.getInternalTexture().uniqueId:0,r=Number(`${e}${s}`),n=this._textureMap.get(r);n?l.metallicRoughnessTexture=n:h.push(t.MergeTexturesAsync("MetalRoughTexture",t.CreateRGBAConfiguration(u.ambientOcclusionTexture?t.CreateTextureInput(u.ambientOcclusionTexture,0):t.CreateConstantInput(1),a?t.CreateTextureInput(a,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,0):t.CreateConstantInput(1)),u.getScene()).then(e=>i(this,void 0,void 0,function*(){const t=yield this.exportTextureAsync(e,r);t&&(l.metallicRoughnessTexture=t)})))}}else n&&h.push(this.exportTextureAsync(n).then(e=>{e&&(l.baseColorTexture=e)})),o&&h.push(this.exportTextureAsync(o).then(e=>{e&&(l.metallicRoughnessTexture=e)}));return h.length>0&&(this._exporter._materialNeedsUVsSet.add(u),yield Promise.all(h)),d})}_getTextureSampler(e){const s={};if(!(e&&e instanceof t.Texture))return s;const r=this._getGLTFTextureWrapMode(e.wrapU);10497!==r&&(s.wrapS=r);const n=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==n&&(s.wrapT=n),e.samplingMode){case t.Texture.LINEAR_LINEAR:s.magFilter=9729,s.minFilter=9729;break;case t.Texture.LINEAR_NEAREST:s.magFilter=9729,s.minFilter=9728;break;case t.Texture.NEAREST_LINEAR:s.magFilter=9728,s.minFilter=9729;break;case t.Texture.NEAREST_LINEAR_MIPLINEAR:s.magFilter=9728,s.minFilter=9987;break;case t.Texture.NEAREST_NEAREST:s.magFilter=9728,s.minFilter=9728;break;case t.Texture.NEAREST_LINEAR_MIPNEAREST:s.magFilter=9728,s.minFilter=9985;break;case t.Texture.LINEAR_NEAREST_MIPNEAREST:s.magFilter=9729,s.minFilter=9984;break;case t.Texture.LINEAR_NEAREST_MIPLINEAR:s.magFilter=9729,s.minFilter=9986;break;case t.Texture.NEAREST_NEAREST_MIPLINEAR:s.magFilter=9728,s.minFilter=9986;break;case t.Texture.LINEAR_LINEAR_MIPLINEAR:s.magFilter=9729,s.minFilter=9987;break;case t.Texture.LINEAR_LINEAR_MIPNEAREST:s.magFilter=9729,s.minFilter=9985;break;case t.Texture.NEAREST_NEAREST_MIPNEAREST:s.magFilter=9728,s.minFilter=9984}return s}_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,s){return i(this,void 0,void 0,function*(){const r={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},n=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((n||i)&&s){this._exporter._materialNeedsUVsSet.add(e);const s=this._exportTextureSampler(n||i),o=yield this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(n,i,r),a=this._exporter._textures;if(o.baseColorTextureData){const e=yield this._exportImageAsync(`baseColor${a.length}`,o.baseColorTextureData);t.baseColorTexture=this._exportTextureInfo(e,s,null==n?void 0:n.coordinatesIndex)}if(o.metallicRoughnessTextureData){const e=yield this._exportImageAsync(`metallicRoughness${a.length}`,o.metallicRoughnessTextureData);t.metallicRoughnessTexture=this._exportTextureInfo(e,s,null==i?void 0:i.coordinatesIndex)}return o}return this._convertSpecularGlossinessToMetallicRoughness(r)})}exportPBRMaterialAsync(e,t){return i(this,void 0,void 0,function*(){const s={},r={name:e.name},n=e.isMetallicWorkflow();if(n){const t=e._albedoColor,r=e.alpha;t&&(s.baseColorFactor=[t.r,t.g,t.b,r])}const i=n?yield this._convertMetalRoughFactorsToMetallicRoughnessAsync(e._albedoColor,e._metallic,e._roughness,e._albedoTexture,e._metallicTexture,e._metallicTexture,e,s,t):yield this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,s,t);yield this._setMetallicRoughnessPbrMaterialAsync(i,e,r,s,t),yield this._finishMaterialAsync(r,e);const o=this._exporter._materials;return o.push(r),o.length-1})}_setMetallicRoughnessPbrMaterialAsync(e,s,r,n,a){return i(this,void 0,void 0,function*(){if(f(r,s),e.baseColor.equalsWithEpsilon(u,o)&&t.Scalar.WithinEpsilon(s.alpha,1,o)||(n.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,s.alpha]),null!=e.metallic&&1!==e.metallic&&(n.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(n.roughnessFactor=e.roughness),null==s.backFaceCulling||s.backFaceCulling||(s._twoSidedLighting||t.Tools.Warn(s.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),a){const e=[],o=s instanceof t.PBRBaseMaterial?s._bumpTexture:s.geometryNormalTexture;o&&e.push(this.exportTextureAsync(o).then(e=>{e&&(r.normalTexture=e,1!==o.level&&(r.normalTexture.scale=o.level))}));const a=s instanceof t.PBRBaseMaterial?s._ambientTexture:s.ambientOcclusionTexture;a&&e.push(new Promise(e=>i(this,void 0,void 0,function*(){if(s instanceof t.OpenPBRMaterial&&n.metallicRoughnessTexture){const t=this._exportTextureSampler(a),s=this._exporter._textures[n.metallicRoughnessTexture.index].source,r=this._exportTextureInfo(s,t,a.coordinatesIndex);return this._textureMap.set(a.uniqueId,r),this._exporter._extensionsPostExportTextures("exporter",r,a),e(r)}return e(yield this.exportTextureAsync(a))})).then(e=>i(this,void 0,void 0,function*(){if(e){const n={index:e.index,texCoord:e.texCoord,extensions:e.extensions};r.occlusionTexture=n,s instanceof t.PBRBaseMaterial?n.strength=s._ambientTextureStrength:n.strength=s.ambientOcclusionTexture.level}})));const u=s instanceof t.PBRBaseMaterial?s._emissiveTexture:s.emissionColorTexture;u&&e.push(this.exportTextureAsync(u).then(e=>{e&&(r.emissiveTexture=e)})),e.length>0&&(this._exporter._materialNeedsUVsSet.add(s),yield Promise.all(e))}const c=s instanceof t.PBRBaseMaterial?s._emissiveColor:s.emissionColor;c.equalsWithEpsilon(l,o)||(r.emissiveFactor=c.asArray()),r.pbrMetallicRoughness=n})}exportOpenPBRMaterialAsync(e,t){return i(this,void 0,void 0,function*(){const s={},r={name:e.name},n=e.baseColor,i=e.geometryOpacity;n&&(s.baseColorFactor=[n.r,n.g,n.b,i]);const o=yield this._convertMetalRoughFactorsToMetallicRoughnessAsync(e.baseColor,e.baseMetalness,e.specularRoughness,e.baseColorTexture,e.baseMetalnessTexture,e.specularRoughnessTexture,e,s,t);yield this._setMetallicRoughnessPbrMaterialAsync(o,e,r,s,t),yield this._finishMaterialAsync(r,e);const a=this._exporter._materials;return a.push(r),a.length-1})}exportTextureAsync(e){return i(this,arguments,void 0,function*(e,t=null){let s=this._textureMap.get(null!=t?t:e.uniqueId);if(s)return s;const r=this._exportTextureSampler(e),n=yield this._exportTextureImageAsync(e);return s=this._exportTextureInfo(n,r,e.coordinatesIndex),this._textureMap.set(null!=t?t:e.uniqueId,s),this._exporter._extensionsPostExportTextures("exporter",s,e),s})}_exportTextureImageAsync(e){return i(this,void 0,void 0,function*(){var s;const r=null!==(s=e.mimeType)&&void 0!==s?s:"none",n=this._internalTextureToImage,o=e.getInternalTexture().uniqueId;n[o]=n[o]||{};let a=n[o][r];return void 0===a&&(a=(()=>i(this,void 0,void 0,function*(){const s=yield function(e){return i(this,void 0,void 0,function*(){var s;const r=e.getInternalTexture();if(!r||1!==r.source)return null;if(r.invertY&&!((null===(s=e.getScene())||void 0===s?void 0:s.getEngine())instanceof t.NullEngine))return null;const n=r._buffer;let i,o=e.mimeType;try{n?ArrayBuffer.isView(n)?i=n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength):n instanceof ArrayBuffer?i=n:n instanceof Blob?(i=yield n.arrayBuffer(),o=n.type||o):"string"==typeof n?(i=yield t.Tools.LoadFileAsync(n),o=t.GetMimeType(n)||o):"undefined"!=typeof HTMLImageElement&&n instanceof HTMLImageElement&&(i=yield t.Tools.LoadFileAsync(n.src),o=t.GetMimeType(n.src)||o):(i=yield t.Tools.LoadFileAsync(r.url),o=t.GetMimeType(r.url)||o)}catch(e){return null}if(i&&!o&&r.url){const e=r.url.match(/^data:([^;,]+)/);o=e?e[1]:t.GetMimeType(r.url)}return i&&o?{data:i,mimeType:o}:null})}(e);if(s&&c(s.mimeType)&&("none"===r||s.mimeType===r))return yield this._exportImageAsync(e.name,new Blob([s.data],{type:s.mimeType}));let n="image/png";"none"!==r&&(c(r)?n=r:(n="image/png",t.Tools.Warn(`Unsupported media type: ${r}. Exporting texture as PNG.`)));const o=e.getSize(),a=yield t.GetTextureDataAsync(e),u=yield t.EncodeImageAsync(a,o.width,o.height,n);return yield this._exportImageAsync(e.name,u)}))(),n[o][r]=a),yield a})}_exportImageAsync(e,s){return i(this,void 0,void 0,function*(){const r=this._exporter._images;let n;if(this._exporter._shouldUseGlb){n={name:e,mimeType:s.type,bufferView:void 0};const t=yield s.arrayBuffer(),r=this._exporter._bufferManager.createBufferView(new Uint8Array(t));this._exporter._bufferManager.setBufferView(n,r)}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"}}(s.type);let a=i+o;r.some(e=>e.uri===a)&&(a=`${i}_${t.Tools.RandomId()}${o}`),n={name:e,uri:a},this._exporter._imageData[a]=s}return r.push(n),r.length-1})}_exportTextureInfo(e,t,s){const r=this._exporter._textures;let n=r.findIndex(s=>s.sampler==t&&s.source===e);-1===n&&(n=r.length,r.push({source:e,sampler:t}));const i={index:n};return s&&(i.texCoord=s),i}_exportTextureSampler(e){const t=this._getTextureSampler(e),s=this._exporter._samplers,r=s.findIndex(e=>e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT);return-1!==r?r:(s.push(t),s.length-1)}}const g=t.Matrix.Compose(new t.Vector3(-1,1,1),t.Quaternion.Identity(),t.Vector3.Zero());function m(e,s){if(!(e instanceof t.TransformNode))return!1;if(s){if(!e.getWorldMatrix().equalsWithEpsilon(t.Matrix.IdentityReadOnly,t.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(g,t.TmpVectors.Matrix[0]).equalsWithEpsilon(t.Matrix.IdentityReadOnly,t.Epsilon))return!1;return!(e instanceof t.AbstractMesh&&e.geometry)}const T=t.Vector3.ZeroReadOnly,y=t.Quaternion.Identity(),R=t.Vector3.OneReadOnly,M=new t.Vector3(-1,1,1);function A(e,t){const{byteOffset:s,byteStride:r,type:n,normalized:i}=e,o=e.getSize(),a=t.reduce((e,t)=>t.getTotalVertices()>e?t.getTotalVertices():e,-Number.MAX_VALUE);return{byteOffset:s,byteStride:r,componentCount:o,type:n,count:a*o,normalized:i,totalVertices:a,kind:e.getKind()}}function b(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 w(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 E(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 C(e){return e.x*=-1,e}function I(e){return g.invertToRef(t.TmpVectors.Matrix[0]).multiplyToRef(e,e).multiplyToRef(g,e),e}function V(e){if(e.x*e.x+e.y*e.y>.5){const t=Math.abs(e.x),s=Math.abs(e.y);if(t>s){const s=Math.sign(e.x);e.x=t,e.y*=-s,e.z*=-s,e.w*=s}else{const t=Math.sign(e.y);e.x*=-t,e.y=s,e.z*=t,e.w*=-t}}else{const t=Math.abs(e.z),s=Math.abs(e.w);if(t>s){const s=Math.sign(e.z);e.x*=-s,e.y*=s,e.z=t,e.w*=-s}else{const t=Math.sign(e.w);e.x*=t,e.y*=-t,e.z*=-t,e.w=s}}return e}function F(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function S(e,s){const r=t.Vector3.FromArrayToRef(s.translation||[0,0,0],0,t.TmpVectors.Vector3[0]),n=t.Quaternion.FromArrayToRef(s.rotation||[0,0,0,1],0,t.TmpVectors.Quaternion[0]),i=t.Matrix.ComposeToRef(R,n,r,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]),u=t.Matrix.ComposeToRef(R,a,o,t.TmpVectors.Matrix[1]);i.multiplyToRef(u,u),u.decompose(void 0,n,r),r.equalsWithEpsilon(T,t.Epsilon)?delete s.translation:s.translation=r.asArray(),n.equalsWithEpsilon(y,t.Epsilon)?delete s.rotation:s.rotation=n.asArray(),s.scale&&delete s.scale}function B(e,s){if(!(s instanceof t.TransformNode))return!1;if(1!==s.getChildren().length||0!==e.getChildren().length||e.parent!==s)return!1;const r=e.getScene(),n=e instanceof t.TargetCamera&&!r.useRightHandedSystem?M:R;return!!s.scaling.equalsWithEpsilon(n,t.Epsilon)||(t.Logger.Warn(`Cannot collapse node ${e.name} into parent node ${s.name} with modified scaling.`),!1)}function N(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 U(e,t){for(const[s,r]of Object.entries(e)){const n=t[s];(Array.isArray(r)&&Array.isArray(n)&&O(r,n)||r===n)&&delete e[s]}return e}function O(e,t){return e.length===t.length&&e.every((e,s)=>e===t[s])}const K=new Map([[Int8Array,(e,t,s)=>e.setInt8(t,s)],[Uint8Array,(e,t,s)=>e.setUint8(t,s)],[Uint8ClampedArray,(e,t,s)=>e.setUint8(t,s)],[Int16Array,(e,t,s)=>e.setInt16(t,s,!0)],[Uint16Array,(e,t,s)=>e.setUint16(t,s,!0)],[Int32Array,(e,t,s)=>e.setInt32(t,s,!0)],[Uint32Array,(e,t,s)=>e.setUint32(t,s,!0)],[Float32Array,(e,t,s)=>e.setFloat32(t,s,!0)],[Float64Array,(e,t,s)=>e.setFloat64(t,s,!0)]]);class P{writeTypedArray(e){this._checkGrowBuffer(e.byteLength);const t=K.get(e.constructor);for(let s=0;s<e.length;s++)t(this._dataView,this._byteOffset,e[s]),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 W{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 s=new P(t),r=Array.from(this._bufferViewToData.keys()).sort((e,t)=>H(t.byteLength)-H(e.byteLength));for(const t of r){t.byteOffset=s.byteOffset,e.push(t);const r=e.length-1,n=this.getPropertiesWithBufferView(t);for(const e of n)e.bufferView=r;s.writeTypedArray(this._bufferViewToData.get(t)),this._bufferViewToData.delete(t)}return s.getOutputData()}createBufferView(e,t){const s={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(s,e),s}createAccessor(e,t,s,r,n,i,o){this._verifyBufferView(e);const a={bufferView:void 0,componentType:s,count:r,type:t,min:null==i?void 0:i.min,max:null==i?void 0:i.max,normalized:o,byteOffset:n};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,s)=>{t===e&&(void 0!==s.byteOffset&&delete s.byteOffset,this._accessorToBufferView.delete(s))})}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 L;!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(L||(L={}));class z{static _IsTransformable(e){return e&&(e instanceof t.TransformNode||e instanceof t.Camera||e instanceof t.Light)}static _CreateNodeAnimation(e,s,r,n,i){if(this._IsTransformable(e)){const o=[],a=[],u=s.getKeys(),l=z._CalculateMinMaxKeyFrames(u),c=z._DeduceInterpolation(u,r,n),h=c.interpolationType,d=c.shouldBakeAnimation;if(d?z._CreateBakedAnimation(e,s,r,l.min,l.max,s.framePerSecond,i,o,a,l,n):"LINEAR"===h||"STEP"===h?z._CreateLinearOrStepAnimation(e,s,r,o,a,n):"CUBICSPLINE"===h?z._CreateCubicSplineAnimation(e,s,r,o,a,n):z._CreateBakedAnimation(e,s,r,l.min,l.max,s.framePerSecond,i,o,a,l,n),o.length&&a.length)return{inputs:o,outputs:a,samplerInterpolation:h,inputsMin:d?l.min:t.Tools.FloatRound(l.min/s.framePerSecond),inputsMax:d?l.max:t.Tools.FloatRound(l.max/s.framePerSecond)}}return null}static _DeduceAnimationInfo(e){let s=null,r="VEC3",n=!1;const i=e.targetProperty.split(".");switch(i[0]){case"scaling":s="scale";break;case"position":s="translation";break;case"rotation":r="VEC4",s="rotation";break;case"rotationQuaternion":r="VEC4",n=!0,s="rotation";break;case"influence":r="SCALAR",s="weights";break;default:t.Tools.Error(`Unsupported animatable property ${i[0]}`)}return s?{animationChannelTargetPath:s,dataAccessorType:r,useQuaternion:n}:(t.Tools.Error("animation channel target path and data accessor type could be deduced"),null)}static _CreateNodeAnimationFromNodeAnimations(e,t,s,r,n,i,o,a,u,l,c){let h;if(z._IsTransformable(e)&&e.animations)for(const n of e.animations){if(c&&!c(n))continue;const d=z._DeduceAnimationInfo(n);d&&(h={name:n.name,samplers:[],channels:[]},z._AddAnimation(`${n.name}`,n.hasRunningRuntimeAnimations?t:h,e,n,d.dataAccessorType,d.animationChannelTargetPath,r,i,o,a,d.useQuaternion,u,l),h.samplers.length&&h.channels.length&&s.push(h))}}static _CreateMorphTargetAnimationFromMorphTargetAnimations(e,s,r,n,i,o,a,u,l,c,h){let d;if(e instanceof t.Mesh){const i=e.morphTargetManager;if(i)for(let f=0;f<i.numTargets;++f){const x=i.getTarget(f);for(const p of x.animations){if(h&&!h(p))continue;const x=new t.Animation(`${p.name}`,"influence",p.framePerSecond,p.dataType,p.loopMode,p.enableBlending),_=[],g=p.getKeys();for(let e=0;e<g.length;++e){const t=g[e];for(let e=0;e<i.numTargets;++e)e==f?_.push(t):_.push({frame:t.frame,value:0})}x.setKeys(_,!0);const m=z._DeduceAnimationInfo(x);m&&(d={name:x.name,samplers:[],channels:[]},z._AddAnimation(p.name,p.hasRunningRuntimeAnimations?s:d,e,x,m.dataAccessorType,m.animationChannelTargetPath,n,o,a,u,m.useQuaternion,l,c,i.numTargets),d.samplers.length&&d.channels.length&&r.push(d))}}}}static _CreateNodeAndMorphAnimationFromAnimationGroups(e,s,r,n,i,o,a,u,l,c){var h;let d;if(e.animationGroups){const f=e.animationGroups;for(const x of f){const f=new Map,p=new Map,_=new Set,g=x.to-x.from;d={name:x.name,channels:[],samplers:[]};for(let s=0;s<x.targetedAnimations.length;++s){const c=x.targetedAnimations[s],g=c.target,m=c.animation;if(l&&!l(m))continue;const T=u.has(g);if(this._IsTransformable(g)||1===g.length&&this._IsTransformable(g[0])){const e=z._DeduceAnimationInfo(c.animation);if(e){const t=this._IsTransformable(g)?g:this._IsTransformable(g[0])?g[0]:null;t&&z._AddAnimation(`${m.name}`,d,t,m,e.dataAccessorType,e.animationChannelTargetPath,r,n,i,o,e.useQuaternion,a,T)}}else if((g instanceof t.MorphTarget||1===g.length&&g[0]instanceof t.MorphTarget)&&z._DeduceAnimationInfo(c.animation)){const s=g instanceof t.MorphTarget?g:g[0];if(s){const t=e.morphTargetManagers.find(e=>{for(let t=0;t<e.numTargets;++t)if(e.getTarget(t)===s)return!0;return!1});if(t){const r=e.meshes.find(e=>e.morphTargetManager===t);r&&(f.has(r)||f.set(r,new Map),null===(h=f.get(r))||void 0===h||h.set(s,m),_.add(r),p.set(r,m))}}}}_.forEach(e=>{const s=e.morphTargetManager;let u=null;const l=[],c=p.get(e).getKeys(),h=c.length;for(let r=0;r<h;++r)for(let n=0;n<s.numTargets;++n){const i=s.getTarget(n),o=f.get(e);if(o){const s=o.get(i);s?(u||(u=new t.Animation(`${x.name}_${e.name}_MorphWeightAnimation`,"influence",s.framePerSecond,t.Animation.ANIMATIONTYPE_FLOAT,s.loopMode,s.enableBlending)),l.push(s.getKeys()[r])):l.push({frame:x.from+g/h*r,value:i.influence,inTangent:c[0].inTangent?0:void 0,outTangent:c[0].outTangent?0:void 0})}}u.setKeys(l,!0);const _=z._DeduceAnimationInfo(u);_&&z._AddAnimation(`${x.name}_${e.name}_MorphWeightAnimation`,d,e,u,_.dataAccessorType,_.animationChannelTargetPath,r,n,i,o,_.useQuaternion,a,!1,null==s?void 0:s.numTargets)}),d.channels.length&&d.samplers.length&&(null==c||c.set(x,s.length),s.push(d))}}}static _AddAnimation(e,s,r,n,i,o,a,u,l,c,h,d,f,x){const p=z._CreateNodeAnimation(r,n,o,h,d);let _,g,m,T,y,R;if(p){if(x){let e,t=0;const s=[];for(;p.inputs.length>0;)e=p.inputs.shift(),t%x==0&&s.push(e),t++;p.inputs=s}const e=a.get(r),n=new Float32Array(p.inputs);_=u.createBufferView(n),g=u.createAccessor(_,"SCALAR",5126,p.inputs.length,void 0,{min:[p.inputsMin],max:[p.inputsMax]}),c.push(g),m=c.length-1;const l=new t.Quaternion,h=new t.Vector3,d=new t.Vector3,M=r instanceof t.Camera,A=b(i),v=new Float32Array(p.outputs.length*A);p.outputs.forEach(function(e,s){let r=e;switch(o){case"translation":f&&(t.Vector3.FromArrayToRef(e,0,d),C(d),d.toArray(r));break;case"rotation":4===e.length?t.Quaternion.FromArrayToRef(e,0,l):(r=new Array(4),t.Vector3.FromArrayToRef(e,0,h),t.Quaternion.FromEulerVectorToRef(h,l)),f&&(V(l),M&&F(l)),l.toArray(r)}v.set(r,s*A)}),_=u.createBufferView(v),g=u.createAccessor(_,i,5126,p.outputs.length),c.push(g),T=c.length-1,y={interpolation:p.samplerInterpolation,input:m,output:T},s.samplers.push(y),R={sampler:s.samplers.length-1,target:{node:e,path:o}},s.channels.push(R)}}static _CreateBakedAnimation(e,s,r,n,i,o,a,u,l,c,h){let d;const f=t.Quaternion.Identity();let x,p,_,g,m,T=null,y=null;c.min=t.Tools.FloatRound(n/o);const R=s.getKeys();for(let n=0,c=R.length;n<c;++n){if(p=R[n],n+1<c)if(_=R[n+1],p.value.equals&&p.value.equals(_.value)||p.value===_.value){if(0!==n)continue;m=p.frame}else m=_.frame;else{if(g=R[n-1],p.value.equals&&p.value.equals(g.value)||p.value===g.value)continue;m=i}if(m)for(let n=p.frame;n<=m;n+=a){if(x=t.Tools.FloatRound(n/o),x===T)continue;T=x,y=x;const i={key:0,repeatCount:0,loopMode:s.loopMode};d=s._interpolate(n,i),z._SetInterpolatedValue(e,d,x,s,r,f,u,l,h)}}y&&(c.max=y)}static _ConvertFactorToVector3OrQuaternion(e,s,r,n,i){const o=z._GetBasePositionRotationOrScale(s,n,i),a=r.targetProperty.split("."),u=a?a[1]:"",l=i?t.Quaternion.FromArray(o).normalize():t.Vector3.FromArray(o);switch(u){case"x":case"y":case"z":l[u]=e;break;case"w":l.w=e;break;default:t.Tools.Error(`glTFAnimation: Unsupported component name "${u}"!`)}return l}static _SetInterpolatedValue(e,s,r,n,i,o,a,u,l){let c;a.push(r),"weights"!==i?(n.dataType===t.Animation.ANIMATIONTYPE_FLOAT&&(s=this._ConvertFactorToVector3OrQuaternion(s,e,n,i,l)),"rotation"===i?(l?o=s:(c=s,t.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,o)),u.push(o.asArray())):(c=s,u.push(c.asArray()))):u.push([s])}static _CreateLinearOrStepAnimation(e,t,s,r,n,i){for(const o of t.getKeys())r.push(o.frame/t.framePerSecond),z._AddKeyframeValue(o,t,n,s,e,i)}static _CreateCubicSplineAnimation(e,t,s,r,n,i){t.getKeys().forEach(function(o){r.push(o.frame/t.framePerSecond),z._AddSplineTangent(L.INTANGENT,n,s,"CUBICSPLINE",o,i),z._AddKeyframeValue(o,t,n,s,e,i),z._AddSplineTangent(L.OUTTANGENT,n,s,"CUBICSPLINE",o,i)})}static _GetBasePositionRotationOrScale(e,s,r){let n;if("rotation"===s)if(r){const s=e.rotationQuaternion;n=(null!=s?s:t.Quaternion.Identity()).asArray()}else{const s=e.rotation;n=(null!=s?s:t.Vector3.Zero()).asArray()}else if("translation"===s){const s=e.position;n=(null!=s?s:t.Vector3.Zero()).asArray()}else{const s=e.scaling;n=(null!=s?s:t.Vector3.One()).asArray()}return n}static _AddKeyframeValue(e,s,r,n,i,o){let a;const u=s.dataType;if(u===t.Animation.ANIMATIONTYPE_VECTOR3){let s=e.value.asArray();if("rotation"===n){const e=t.Vector3.FromArray(s);s=t.Quaternion.RotationYawPitchRoll(e.y,e.x,e.z).asArray()}r.push(s)}else if(u===t.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(a=this._ConvertFactorToVector3OrQuaternion(e.value,i,s,n,o),a){if("rotation"===n){const e=o?a:t.Quaternion.RotationYawPitchRoll(a.y,a.x,a.z).normalize();r.push(e.asArray())}r.push(a.asArray())}}else u===t.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):t.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")}static _DeduceInterpolation(e,t,s){let r,n,i=!1;if("rotation"===t&&!s)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(let t=0,s=e.length;t<s;++t)if(n=e[t],n.inTangent||n.outTangent)if(r){if("CUBICSPLINE"!==r){r="LINEAR",i=!0;break}}else r="CUBICSPLINE";else if(r){if("CUBICSPLINE"===r||n.interpolation&&1===n.interpolation&&"STEP"!==r){r="LINEAR",i=!0;break}}else r=n.interpolation&&1===n.interpolation?"STEP":"LINEAR";return r||(r="LINEAR"),{interpolationType:r,shouldBakeAnimation:i}}static _AddSplineTangent(e,s,r,n,i,o){let a;const u=e===L.INTANGENT?i.inTangent:i.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(u)if(o)a=u.asArray();else{const e=u;a=t.Quaternion.RotationYawPitchRoll(e.y,e.x,e.z).asArray()}else a=[0,0,0,0];else a="weights"===r?u?[u]:[0]:u?u.asArray():[0,0,0];s.push(a)}}static _CalculateMinMaxKeyFrames(e){let t=1/0,s=-1/0;return e.forEach(function(e){t=Math.min(t,e.frame),s=Math.max(s,e.frame)}),{min:t,max:s}}}function k(e,s,r,n,i,o){const a={attributes:{},influence:e.influence,name:e.name},u=s.geometry;if(!u)return t.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),a;const l=o?-1:1,c=t.Vector3.Zero();let h,d;if(e.hasPositions){const n=e.getPositions(),o=u.getVerticesData(t.VertexBuffer.PositionKind);if(o){const e=new Float32Array(o.length),s=[1/0,1/0,1/0],u=[-1/0,-1/0,-1/0];d=o.length/3,h=0;for(let r=h;r<d;++r){const i=t.Vector3.FromArray(o,3*r);t.Vector3.FromArray(n,3*r).subtractToRef(i,c),c.x*=l,s[0]=Math.min(s[0],c.x),u[0]=Math.max(u[0],c.x),s[1]=Math.min(s[1],c.y),u[1]=Math.max(u[1],c.y),s[2]=Math.min(s[2],c.z),u[2]=Math.max(u[2],c.z),e[3*r]=c.x,e[3*r+1]=c.y,e[3*r+2]=c.z}const f=r.createBufferView(e,12),x=r.createAccessor(f,"VEC3",5126,n.length/3,0,{min:s,max:u});i.push(x),a.attributes.POSITION=i.length-1}else t.Tools.Warn(`Morph target positions for mesh ${s.name} were not exported. Mesh does not have position vertex data`)}if(e.hasNormals){const n=e.getNormals(),o=u.getVerticesData(t.VertexBuffer.NormalKind);if(o){const e=new Float32Array(o.length);d=o.length/3,h=0;for(let s=h;s<d;++s){const r=t.Vector3.FromArray(o,3*s).normalize();t.Vector3.FromArray(n,3*s).normalize().subtractToRef(r,c),e[3*s]=c.x*l,e[3*s+1]=c.y,e[3*s+2]=c.z}const s=r.createBufferView(e,12),u=r.createAccessor(s,"VEC3",5126,n.length/3,0);i.push(u),a.attributes.NORMAL=i.length-1}else t.Tools.Warn(`Morph target normals for mesh ${s.name} were not exported. Mesh does not have normals vertex data`)}if(e.hasTangents){const n=e.getTangents(),o=u.getVerticesData(t.VertexBuffer.TangentKind);if(o){d=o.length/4;const e=new Float32Array(3*d);h=0;for(let s=h;s<d;++s){const r=t.Vector3.FromArray(o,4*s);E(r);const i=t.Vector3.FromArray(n,3*s);E(i),i.subtractToRef(r,c),e[3*s]=c.x*l,e[3*s+1]=c.y,e[3*s+2]=c.z}const s=r.createBufferView(e,12),u=r.createAccessor(s,"VEC3",5126,d,0);i.push(u),a.attributes.TANGENT=i.length-1}else t.Tools.Warn(`Morph target tangents for mesh ${s.name} were not exported. Mesh does not have tangents vertex data`)}if(e.hasColors){const n=e.getColors(),o=u.getVerticesData(t.VertexBuffer.ColorKind),l=u.getVertexBuffer(t.VertexBuffer.ColorKind);if(o&&l){const e=l.getSize();d=o.length/e;const s=new Float32Array(d*e);h=0;for(let r=h;r<d;++r)if(3===e){const i=t.Vector3.FromArray(o,r*e);t.Vector3.FromArray(n,r*e).subtractToRef(i,c),s[3*r]=c.x,s[3*r+1]=c.y,s[3*r+2]=c.z}else if(4===e){const i=new t.Vector4,a=t.Vector4.FromArray(o,r*e);t.Vector4.FromArray(n,r*e).subtractToRef(a,i),s[4*r]=i.x,s[4*r+1]=i.y,s[4*r+2]=i.z,s[4*r+3]=i.w}else t.Tools.Warn(`Unsupported number of components for color attribute: ${e}`);const u=r.createBufferView(s,4*e),f=r.createAccessor(u,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 ${s.name} were not exported. Mesh does not have colors vertex data`)}return a}class G{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,s,r,n){var i,o,a,u;return null===(u=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(s))||void 0===a?void 0:a.get(r))||void 0===u?void 0:u.get(n)}setIndicesAccessor(e,t,s,r,n,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 u=a.get(s);u||(u=new Map,a.set(s,u));let l=u.get(r);l||(l=new Map,u.set(r,l)),l.set(n,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,s){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,s)}getRemappedBufferView(e,t){var s;return null===(s=this._remappedBufferView.get(e))||void 0===s?void 0:s.get(t)}getVertexAccessor(e,t,s){var r,n;return null===(n=null===(r=this._vertexAccessorMap.get(e))||void 0===r?void 0:r.get(t))||void 0===n?void 0:n.get(s)}setVertexAccessor(e,t,s,r){let n=this._vertexAccessorMap.get(e);n||(n=new Map,this._vertexAccessorMap.set(e,n));let i=n.get(t);i||(i=new Map,n.set(t,i)),i.set(s,r)}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 s=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,s),-1===s.indexOf(t)&&s.push(t)}getMorphTargetsFromMesh(e){return this._meshMorphTargetMap.get(e)}}class D{_ApplyExtension(e,t,s,r){if(s>=t.length)return Promise.resolve(e);const n=r(t[s],e);return n?n.then(e=>i(this,void 0,void 0,function*(){return e?yield this._ApplyExtension(e,t,s+1,r):null})):this._ApplyExtension(e,t,s+1,r)}_ApplyExtensions(e,t){const s=[];for(const e of D._ExtensionNames)s.push(this._extensions[e]);return this._ApplyExtension(e,s,0,t)}_extensionsPostExportNodeAsync(e,t,s,r,n){return this._ApplyExtensions(t,(t,i)=>t.postExportNodeAsync&&t.postExportNodeAsync(e,i,s,r,n,this._bufferManager))}_extensionsPostExportMaterialAsync(e,t,s){return this._ApplyExtensions(t,(t,r)=>t.postExportMaterialAsync&&t.postExportMaterialAsync(e,r,s))}_extensionsPostExportMaterialAdditionalTexturesAsync(e,t,s){return i(this,void 0,void 0,function*(){const r=[];return yield Promise.all(D._ExtensionNames.map(n=>i(this,void 0,void 0,function*(){const i=this._extensions[n];if(i.postExportMaterialAdditionalTexturesAsync){const n=yield i.postExportMaterialAdditionalTexturesAsync(e,t,s);r.push(...n)}}))),r})}_extensionsPostExportTextures(e,t,s){for(const r of D._ExtensionNames){const n=this._extensions[r];n.postExportTexture&&n.postExportTexture(e,t,s)}}_extensionsPostExportMeshPrimitive(e){for(const t of D._ExtensionNames){const s=this._extensions[t];s.postExportMeshPrimitive&&s.postExportMeshPrimitive(e,this._bufferManager,this._accessors)}}_extensionsPreGenerateBinaryAsync(){return i(this,void 0,void 0,function*(){for(const e of D._ExtensionNames){const t=this._extensions[e];t.preGenerateBinaryAsync&&(yield t.preGenerateBinaryAsync(this._bufferManager))}})}_forEachExtensions(e){for(const t of D._ExtensionNames){const s=this._extensions[t];s.enabled&&e(s)}}_extensionsOnExporting(){this._forEachExtensions(e=>{var t,s,r;e.wasUsed&&((t=this._glTF).extensionsUsed||(t.extensionsUsed=[]),-1===this._glTF.extensionsUsed.indexOf(e.name)&&this._glTF.extensionsUsed.push(e.name),e.required&&((s=this._glTF).extensionsRequired||(s.extensionsRequired=[]),-1===this._glTF.extensionsRequired.indexOf(e.name)&&this._glTF.extensionsRequired.push(e.name)),(r=this._glTF).extensions||(r.extensions={}),e.onExporting&&e.onExporting())})}_loadExtensions(){for(const e of D._ExtensionNames){const t=D._ExtensionFactories[e](this);this._extensions[e]=t}}constructor(e=t.EngineStore.LastCreatedScene,s){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 _(this),this._extensions={},this._bufferManager=new W,this._shouldExportNodeMap=new Map,this._nodeMap=new Map,this._animationGroupMap=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",khrInteractivity:void 0},s),this._loadExtensions()}dispose(){for(const e in this._extensions)this._extensions[e].dispose()}get options(){return this._options}static RegisterExtension(e,s,r=100){D.UnregisterExtension(e)&&t.Tools.Warn(`Extension with the name ${e} already exists`),D._ExtensionFactories[e]=s;const n=null!=r?r:0;D._ExtensionOrders[e]=n;let i=D._ExtensionNames.length;for(let e=0;e<D._ExtensionNames.length;e++){const t=D._ExtensionNames[e];if(n<D._ExtensionOrders[t]){i=e;break}}D._ExtensionNames.splice(i,0,e)}static UnregisterExtension(e){if(!D._ExtensionFactories[e])return!1;delete D._ExtensionFactories[e],delete D._ExtensionOrders[e];const t=D._ExtensionNames.indexOf(e);return-1!==t&&D._ExtensionNames.splice(t,1),!0}_generateJSON(e,t,s){const r={byteLength:e};return r.byteLength&&(this._glTF.buffers=[r]),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||(r.uri=t+".bin"),s?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)}generateGLTFAsync(e){return i(this,void 0,void 0,function*(){const t=yield this._generateBinaryAsync();this._extensionsOnExporting();const s=this._generateJSON(t.byteLength,e,!0),n=new Blob([t],{type:"application/octet-stream"}),i=e+".gltf",o=e+".bin",a=new r;if(a.files[i]=s,a.files[o]=n,this._imageData)for(const e in this._imageData)a.files[e]=this._imageData[e];return a})}_generateBinaryAsync(){return i(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 i(this,void 0,void 0,function*(){this._shouldUseGlb=!0;const t=yield this._generateBinaryAsync();this._extensionsOnExporting();const s=this._generateJSON(t.byteLength),n=e+".glb";let i,o=s.length;"undefined"!=typeof TextEncoder&&(i=(new TextEncoder).encode(s),o=i.length);const a=this._getPadding(o),u=this._getPadding(t.byteLength),l=28+o+a+t.byteLength+u,c=new P(l);if(c.writeUInt32(1179937895),c.writeUInt32(2),c.writeUInt32(l),c.writeUInt32(o+a),c.writeUInt32(1313821514),i)c.writeTypedArray(i);else{const e="_".charCodeAt(0);for(let t=0;t<o;++t){const r=s.charCodeAt(t);r!=s.codePointAt(t)?c.writeUInt8(e):c.writeUInt8(r)}}for(let e=0;e<a;++e)c.writeUInt8(32);c.writeUInt32(t.byteLength+u),c.writeUInt32(5130562),c.writeTypedArray(t);for(let e=0;e<u;++e)c.writeUInt8(0);const h=new r;return h.files[n]=new Blob([c.getOutputData()],{type:"application/octet-stream"}),h})}_setNodeTransformation(e,s,r){var n;if(s.getPivotPoint().equalsWithEpsilon(T,t.Epsilon)||t.Tools.Warn("Pivot points are not supported in the glTF serializer"),!s.position.equalsWithEpsilon(T,t.Epsilon)){const n=t.TmpVectors.Vector3[0].copyFrom(s.position);r&&C(n),e.translation=n.asArray()}s.scaling.equalsWithEpsilon(R,t.Epsilon)||(e.scale=s.scaling.asArray());const i=(null===(n=s.rotationQuaternion)||void 0===n?void 0:n.clone())||t.Quaternion.FromEulerAngles(s.rotation.x,s.rotation.y,s.rotation.z);i.equalsWithEpsilon(y,t.Epsilon)||(r&&V(i),e.rotation=i.normalize().asArray())}_setCameraTransformation(e,s,r){const n=t.TmpVectors.Vector3[0],i=t.TmpVectors.Quaternion[0],o=s.getWorldMatrix();if(s.parent){const e=s.parent.getWorldMatrix().invertToRef(t.TmpVectors.Matrix[0]);o.multiplyToRef(e,t.TmpVectors.Matrix[1]).decompose(void 0,i,n)}else o.decompose(void 0,i,n);n.equalsWithEpsilon(T,t.Epsilon)||(r&&C(n),e.translation=n.asArray()),r&&V(i),this._babylonScene.useRightHandedSystem||F(i),i.equalsWithEpsilon(y,t.Epsilon)||(e.rotation=i.asArray())}_listAvailableCameras(){for(const e of this._babylonScene.cameras){const s={type:e.mode===t.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(e.name&&(s.name=e.name),"perspective"===s.type)s.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"===s.type){const t=e.orthoLeft&&e.orthoRight?.5*(e.orthoRight-e.orthoLeft):.5*e.getEngine().getRenderWidth(),r=e.orthoBottom&&e.orthoTop?.5*(e.orthoTop-e.orthoBottom):.5*e.getEngine().getRenderHeight();s.orthographic={xmag:t,ymag:r,znear:e.minZ,zfar:e.maxZ}}this._camerasMap.set(e,s)}}_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 s;for(const r of this._babylonScene.skeletons){if(r.bones.length<=0)continue;const n=this._skinMap.get(r);if(null==n)continue;const i={};let o=-1;for(let e=0;e<r.bones.length;++e){const t=r.bones[e],n=null!==(s=t.getIndex())&&void 0!==s?s:e;-1!==n&&(i[n]=t,n>o&&(o=n))}const a=[];for(let s=0;s<=o;++s){const r=i[s],o=r.getTransformNode(),u=o?this._nodeMap.get(o):void 0;if(void 0===u){t.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.");continue}n.joints.push(u);const l=r.getAbsoluteInverseBindMatrix().clone();e.has(o)&&I(l),a.push(l)}const u=this._nodesSkinMap.get(n);if(n.joints.length>0&&void 0!==u){const e=new Float32Array(16*a.length);a.forEach((t,s)=>{e.set(t.m,16*s)});const t=this._bufferManager.createBufferView(e);this._accessors.push(this._bufferManager.createAccessor(t,"MAT4",5126,a.length)),n.inverseBindMatrices=this._accessors.length-1,this._skins.push(n);const s=this._skins.length-1;for(const e of u)e.skin=s}}}_exportSceneAsync(){return i(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 s=new Array,r=new Array,n=new Array,i=this._options.removeNoopRootNodes&&!this._options.khrInteractivity;let o;if(i&&!this._options.includeCoordinateSystemConversionNodes)for(const e of this._babylonScene.animationGroups)for(const s of e.targetedAnimations){const e=s.target;e instanceof t.TransformNode&&!e.parent&&(null!=o?o:o=new Set).add(e)}for(const e of this._babylonScene.rootNodes){const t=e.animations,a=!!t&&t.length>0||(null==o?void 0:o.has(e));i&&!this._options.includeCoordinateSystemConversionNodes&&m(e,this._babylonScene.useRightHandedSystem)&&!a?n.push(...e.getChildren()):this._babylonScene.useRightHandedSystem?s.push(e):r.push(e)}this._listAvailableCameras(),this._listAvailableSkeletons();const a=new G(!0,!1);e.nodes.push(...yield this._exportNodesAsync(r,a));const u=new G(!1,!1);e.nodes.push(...yield this._exportNodesAsync(s,u));const l=new G(!1,!0);e.nodes.push(...yield this._exportNodesAsync(n,l)),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(a.getNodesSet()),this._babylonScene.animationGroups.length&&z._CreateNodeAndMorphAnimationFromAnimationGroups(this._babylonScene,this._animations,this._nodeMap,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,a.getNodesSet(),this._options.shouldExportAnimation,this._animationGroupMap)})}_getNodeIndex(e){return this._nodeMap.get(e)}_getAnimationIndex(e){return this._animationGroupMap.get(e)}_getCameraIndex(e){const t=this._camerasMap.get(e);if(!t)return;const s=this._cameras.indexOf(t);return s>=0?s:void 0}_getMaterialIndex(e){return this._materialMap.get(e)}_getRootIndex(e,t){var s,r,n,i,o,a,u;switch(e){case"nodes":return this._getNodeIndex(t);case"animations":return this._getAnimationIndex(t);case"cameras":return this._getCameraIndex(t);case"materials":return this._getMaterialIndex(t);case"meshes":{const e=this._getNodeIndex(t);return void 0===e||null===(s=this._nodes[e])||void 0===s?void 0:s.mesh}case"textures":return null===(r=this._materialExporter.getTextureInfo(t))||void 0===r?void 0:r.index;case"images":{const e=null===(n=this._materialExporter.getTextureInfo(t))||void 0===n?void 0:n.index;if(void 0===e)return;const s=this._textures[e];for(const e of["KHR_texture_basisu","EXT_texture_webp","EXT_texture_avif"]){const t=null===(o=null===(i=null==s?void 0:s.extensions)||void 0===i?void 0:i[e])||void 0===o?void 0:o.source;if("number"==typeof t)return t}return null==s?void 0:s.source}case"samplers":{const e=null===(a=this._materialExporter.getTextureInfo(t))||void 0===a?void 0:a.index;return void 0===e||null===(u=this._textures[e])||void 0===u?void 0:u.sampler}case"skins":{const e=this._skinMap.get(t),s=e?this._skins.indexOf(e):-1;return s>=0?s:void 0}case"scenes":return t===this._babylonScene&&this._scenes.length>0?0:void 0}}_setNodeExtension(e,t,s){const r=this._nodes[e];if(!r)throw new Error(`Cannot write ${t}: glTF node ${e} does not exist.`);r.extensions||(r.extensions={}),r.extensions[t]=s}_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 i(this,void 0,void 0,function*(){const s=new Array;this._exportBuffers(e,t);for(const r of e)yield this._exportNodeAsync(r,s,t);return s})}_collectBuffers(e,s,r,n,i){if(this._shouldExportNode(e)&&e instanceof t.AbstractMesh&&e.geometry){const t=e.geometry.getVertexBuffers();if(t)for(const n in t){if(!w(n))continue;const o=t[n];i.setHasVertexColorAlpha(o,e.hasVertexAlpha);const a=o._buffer,u=s.get(a)||[];s.set(a,u),-1===u.indexOf(o)&&u.push(o);const l=r.get(o)||[];r.set(o,l),-1===l.indexOf(e)&&l.push(e)}const o=e.morphTargetManager;if(o)for(let t=0;t<o.numTargets;t++){const s=o.getTarget(t),r=n.get(s)||[];n.set(s,r),-1===r.indexOf(e)&&r.push(e)}}for(const t of e.getChildren())this._collectBuffers(t,s,r,n,i)}_exportBuffers(e,s){const r=new Map,n=new Map,i=new Map;for(const t of e)this._collectBuffers(t,r,n,i,s);const o=Array.from(r.keys());for(const e of o){const i=e.getData();if(!i)throw new Error("Buffer data is not available");const o=r.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 u=N(i).slice();for(const e of o){const s=n.get(e),{byteOffset:r,byteStride:i,componentCount:o,type:a,count:l,normalized:c,kind:h}=A(e,s);switch(h){case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:t.EnumerateFloatValues(u,r,i,o,a,l,c,e=>{const t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){const s=1/t;e[0]*=s,e[1]*=s,e[2]*=s}});break;case t.VertexBuffer.ColorKind:{const e=s.filter(e=>e.material instanceof t.StandardMaterial||null==e.material).length;if(0==e)break;if(e!=s.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 n=new t.Color3,h=new t.Color4,d=this._babylonScene.getEngine().useExactSrgbConversions;t.EnumerateFloatValues(u,r,i,o,a,l,c,e=>{3===e.length?(n.fromArray(e,0),n.toLinearSpaceToRef(n,d),n.toArray(e,0)):(h.fromArray(e,0),h.toLinearSpaceToRef(h,d),h.toArray(e,0))})}}}if(s.convertToRightHanded){for(const e of o){const s=n.get(e),{byteOffset:r,byteStride:i,componentCount:o,type:a,count:l,normalized:c,kind:h}=A(e,s);switch(h){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:t.EnumerateFloatValues(u,r,i,o,a,l,c,e=>{e[0]=-e[0]})}}s.convertedToRightHandedBuffers.set(e,u)}const l=this._bufferManager.createBufferView(u,a);s.setVertexBufferView(e,l);const c=new Map;for(const e of o){const s=n.get(e),{kind:r,totalVertices:i}=A(e,s);switch(r){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 r=c.get(t);if(!r)continue;const n=v(r),i=new(n?Uint16Array:Uint8Array)(r.length);for(let e=0;e<r.length;e++)i[e]=r[e];const o=this._bufferManager.createBufferView(i,4*(n?2:1));s.setRemappedBufferView(e,t,o)}}const a=Array.from(i.keys());for(const e of a){const t=i.get(e);if(!t)continue;const r=k(e,t[0],this._bufferManager,this._bufferViews,this._accessors,s.convertToRightHanded);for(const e of t)s.bindMorphDataToMesh(e,r)}}_exportNodeAsync(e,t,s){return i(this,void 0,void 0,function*(){let r=this._nodeMap.get(e);if(void 0!==r)return void(t.includes(r)||t.push(r));const n=yield this._createNodeAsync(e,s);if(n){r=this._nodes.length,this._nodes.push(n),this._nodeMap.set(e,r),s.pushExportedNode(e),t.push(r);const i={name:"runtime animations",channels:[],samplers:[]},o=[];this._babylonScene.animationGroups.length||(z._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,o,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,s.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&z._CreateNodeAnimationFromNodeAnimations(e,i,o,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,s.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=n?[]:t;for(const t of e.getChildren())yield this._exportNodeAsync(t,i,s);n&&i.length&&(n.children=i)})}_createNodeAsync(e,s){return i(this,void 0,void 0,function*(){var r,n,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,s.convertToRightHanded),e instanceof t.AbstractMesh)){const n=e instanceof t.InstancedMesh?e.sourceMesh:e;if(n.subMeshes&&n.subMeshes.length>0&&(o.mesh=yield this._exportMeshAsync(n,s)),e.skeleton){const t=this._skinMap.get(e.skeleton);void 0!==t&&(void 0===this._nodesSkinMap.get(t)&&this._nodesSkinMap.set(t,[]),null===(r=this._nodesSkinMap.get(t))||void 0===r||r.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,s.convertToRightHanded);const r=e.parent;if(null!==r&&B(e,r)){const e=this._nodeMap.get(r);if(void 0!==e){const s=this._nodes[e];return S(o,s),null===(n=this._nodesCameraMap.get(t))||void 0===n||n.push(s),null}}null===(i=this._nodesCameraMap.get(t))||void 0===i||i.push(o)}}return(yield this._extensionsPostExportNodeAsync("exportNodeAsync",o,e,this._nodeMap,s.convertToRightHanded))?o:(t.Logger.Warn(`Not exporting node ${e.name}`),null)})}_exportIndices(e,s,r,n,i,o,a,u,l){let c=null;l.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=s?new Uint32Array(n):new Uint16Array(n);if(e)for(let t=0;t+2<n;t+=3)a[t]=e[r+t]+i,a[t+1]=e[r+t+2]+i,a[t+2]=e[r+t+1]+i;else for(let e=0;e+2<n;e+=3)a[e]=e,a[e+1]=e+2,a[e+2]=e+1;c=a}else if(e&&0!==i){const t=s?new Uint32Array(n):new Uint16Array(n);for(let s=0;s<n;s++)t[s]=e[r+s]+i;c=t}else e&&(c=function(e,t,s,r){let n=e;return 0===t&&s===e.length||(n=Array.isArray(e)?e.slice(t,t+s):e.subarray(t,t+s)),n instanceof Int32Array?new Uint32Array(n.buffer,n.byteOffset,n.length):Array.isArray(n)?r?new Uint32Array(n):new Uint16Array(n):n}(e,r,n,s));if(c){let t=u.getIndicesAccessor(e,r,n,i,h);if(void 0===t){const o=this._bufferManager.createBufferView(c),a=s?5125:5123;this._accessors.push(this._bufferManager.createAccessor(o,"SCALAR",a,n,0)),t=this._accessors.length-1,u.setIndicesAccessor(e,r,n,i,h,t)}l.indices=t}}_exportVertexBuffer(e,s,r,n,i,o){const a=e.getKind();if(!w(a))return;if(a.startsWith("uv")&&!this._options.exportUnusedUVs&&(!s||!this._materialNeedsUVsSet.has(s)))return;let u=i.getVertexAccessor(e,r,n);if(void 0===u){const s=i.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),o=a===t.VertexBuffer.PositionKind?function(e,s,r,n){const{byteOffset:i,byteStride:o,type:a,normalized:u}=s,l=s.getSize(),c=new Array(l).fill(1/0),h=new Array(l).fill(-1/0);return t.EnumerateFloatValues(e,i+r*o,o,l,a,n*l,u,e=>{for(let t=0;t<l;t++)c[t]=Math.min(c[t],e[t]),h[t]=Math.max(h[t],e[t])}),{min:c,max:h}}(s,e,r,n):void 0,l=(a===t.VertexBuffer.MatricesIndicesKind||a===t.VertexBuffer.MatricesIndicesExtraKind)&&e.type===t.VertexBuffer.FLOAT,c=l?t.VertexBuffer.UNSIGNED_BYTE:e.type,h=l?void 0:e.normalized,d=l?i.getRemappedBufferView(e._buffer,e):i.getVertexBufferView(e._buffer),f=e.byteOffset+r*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(d,function(e,s){if(e==t.VertexBuffer.ColorKind)return s?"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,n,f,o,h)),u=this._accessors.length-1,i.setVertexAccessor(e,r,n,u)}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)]=u}_exportMaterialAsync(e,s,r,n){return i(this,void 0,void 0,function*(){let i=this._materialMap.get(e);if(void 0===i){const n=s&&Object.keys(s).some(e=>e.startsWith("uv"));if((e=e instanceof t.MultiMaterial?e.subMaterials[r.materialIndex]:e)instanceof t.PBRBaseMaterial)i=yield this._materialExporter.exportPBRMaterialAsync(e,n);else if(e instanceof t.StandardMaterial)i=yield this._materialExporter.exportStandardMaterialAsync(e,n);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,n)}this._materialMap.set(e,i)}n.material=i})}_exportMeshAsync(e,s){return i(this,void 0,void 0,function*(){var r,n,i,o,a,u;let l=s.getMesh(e);if(void 0!==l)return l;const c={primitives:[]};l=this._meshes.length,this._meshes.push(c),s.setMesh(e,l);const h=e.isUnIndexed?null:e.getIndices(),d=null===(r=e.geometry)||void 0===r?void 0:r.getVertexBuffers(),f=s.getMorphTargetsFromMesh(e),x=e instanceof t.LinesMesh,p=e instanceof t.GreasedLineBaseMesh,_=e.subMeshes;if(d&&_&&_.length>0)for(const r of _){const l={attributes:{}},_=r.getMaterial()||this._babylonScene.defaultMaterial;if(p){const s={name:_.name},r=e,u=t.Color3.White(),c=null!==(i=null===(n=r.material)||void 0===n?void 0:n.alpha)&&void 0!==i?i:1,h=null!==(a=null===(o=r.greasedLineMaterial)||void 0===o?void 0:o.color)&&void 0!==a?a:u;(!h.equalsWithEpsilon(u,t.Epsilon)||c<1)&&(s.pbrMetallicRoughness={baseColorFactor:[...h.asArray(),c]}),this._materials.push(s),l.material=this._materials.length-1}else if(x){const s={name:_.name},r=e;(!r.color.equalsWithEpsilon(t.Color3.White(),t.Epsilon)||r.alpha<1)&&(s.pbrMetallicRoughness={baseColorFactor:[...r.color.asArray(),r.alpha]}),this._materials.push(s),l.material=this._materials.length-1}else yield this._exportMaterialAsync(_,d,r,l);const g=x||p?t.Material.LineListDrawMode:null!==(u=e.overrideRenderingFillMode)&&void 0!==u?u:_.fillMode;let m=_._getEffectiveOrientation(e);s.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(m=m===t.Material.ClockWiseSideOrientation?t.Material.CounterClockWiseSideOrientation:t.Material.ClockWiseSideOrientation),this._exportIndices(h,h?t.AreIndices32Bits(h,r.indexCount,r.indexStart,r.verticesStart):r.verticesCount>65535,h?r.indexStart:r.verticesStart,h?r.indexCount:r.verticesCount,-r.verticesStart,g,m,s,l);for(const e of Object.values(d))this._exportVertexBuffer(e,_,r.verticesStart,r.verticesCount,s,l);if(f){l.targets=[];for(const e of f)l.targets.push(e.attributes)}c.primitives.push(l),this._extensionsPostExportMeshPrimitive(l)}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 l})}}D._ExtensionNames=new Array,D._ExtensionFactories={},D._ExtensionOrders={};class q{static GLTFAsync(e,t,s){return i(this,void 0,void 0,function*(){s&&s.exportWithoutWaitingForScene||(yield e.whenReadyAsync());const r=new D(e,s),n=yield r.generateGLTFAsync(t.replace(/\.[^/.]+$/,""));return r.dispose(),n})}static GLBAsync(e,t,s){return i(this,void 0,void 0,function*(){s&&s.exportWithoutWaitingForScene||(yield e.whenReadyAsync());const r=new D(e,s),n=yield r.generateGLBAsync(t.replace(/\.[^/.]+$/,""));return r.dispose(),n})}}var $={__proto__:null,GLTF2Export:q};const X="EXT_mesh_gpu_instancing";function Q(e,t){const s=new Float32Array(3*t);for(let r=0;r<t;r++)s[3*r+0]=e[4*r+0],s[3*r+1]=e[4*r+1],s[3*r+2]=e[4*r+2];return s}class j{constructor(e){this.name=X,this.enabled=!0,this.required=!1,this._instanceColorWarned=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportNodeAsync(e,s,r,n,o,a){return i(this,void 0,void 0,function*(){return yield new Promise(e=>{var n,i;if(s&&r instanceof t.Mesh&&r.hasThinInstances&&this._exporter){this._wasUsed=!0;const e=t.Vector3.Zero(),u=t.Quaternion.Identity(),l=t.Vector3.One(),c=r.thinInstanceGetWorldMatrices(),h=t.TmpVectors.Vector3[2],d=t.TmpVectors.Quaternion[1],f=t.TmpVectors.Vector3[3];let x=!1,p=!1,_=!1;const g=new Float32Array(3*r.thinInstanceCount),m=new Float32Array(4*r.thinInstanceCount),T=new Float32Array(3*r.thinInstanceCount);let y=0;for(const t of c)t.decompose(f,d,h),o&&(C(h),V(d)),g.set(h.asArray(),3*y),m.set(d.normalize().asArray(),4*y),T.set(f.asArray(),3*y),x=x||!h.equalsWithEpsilon(e),p=p||!d.equalsWithEpsilon(u),_=_||!f.equalsWithEpsilon(l),y++;const R={attributes:{}};x&&(R.attributes.TRANSLATION=this._buildAccessor(g,"VEC3",r.thinInstanceCount,a)),p&&(R.attributes.ROTATION=this._buildAccessor(m,"VEC4",r.thinInstanceCount,a)),_&&(R.attributes.SCALE=this._buildAccessor(T,"VEC3",r.thinInstanceCount,a));let M=null===(i=null===(n=r._userThinInstanceBuffersStorage)||void 0===n?void 0:n.data)||void 0===i?void 0:i.instanceColor;if(M){const e=r.thinInstanceCount,s="VEC3";r.hasVertexAlpha&&M.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),M=Q(M,e)):M.length===4*e&&(M=Q(M,e)),M.length===3*e&&(R.attributes._COLOR_0=this._buildAccessor(M,s,e,a))}s.extensions=s.extensions||{},s.extensions[X]=R}e(s)})})}_buildAccessor(e,t,s,r){const n=r.createBufferView(e),i=r.createAccessor(n,t,5126,s);return this._exporter._accessors.push(i),this._exporter._accessors.length-1}}let Y=!1;function Z(){Y||(Y=!0,D.RegisterExtension(X,e=>new j(e)))}Z();const J="KHR_draco_mesh_compression";function ee(e){return"POSITION"===e?"POSITION":"NORMAL"===e?"NORMAL":e.startsWith("COLOR")?"COLOR":e.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"}class te{get wasUsed(){return this._wasUsed}constructor(e){this.name=J,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,s,r){if(!this.enabled)return;if(4!==e.mode&&5!==e.mode)return void t.Logger.Warn("Cannot compress primitive with mode "+e.mode+".");const n=[],i=[];let o=null;if(void 0!==e.indices){const t=r[e.indices],a=s.getBufferView(t);o=s.getData(a).slice(),n.push(a),i.push(t)}const a=[];for(const[o,u]of Object.entries(e.attributes)){const e=r[u],l=s.getBufferView(e),c=b(e.type),h=t.GetTypedArrayData(s.getData(l),c,e.componentType,e.byteOffset||0,l.byteStride||t.GetTypeByteLength(e.componentType)*c,e.count,!0);a.push({kind:o,dracoName:ee(o),size:b(e.type),data:h}),n.push(l),i.push(e)}const u={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},l=t.DracoEncoder.Default._encodeAsync(a,o,u).then(t=>{const r={bufferView:-1,attributes:t.attributeIds},o=s.createBufferView(t.data);s.setBufferView(r,o);for(const e of n)this._bufferViewsUsed.add(e);for(const e of i)this._accessorsUsed.add(e);e.extensions||(e.extensions={}),e.extensions[J]=r}).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(l),this._wasUsed=!0}preGenerateBinaryAsync(e){return i(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 se=!1;function re(){se||(se=!0,D.RegisterExtension(J,e=>new te(e)))}re();const ne="KHR_lights_punctual",ie={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},oe={innerConeAngle:0,outerConeAngle:Math.PI/4},ae=t.Vector3.Backward();class ue{constructor(e){this.name=ne,this.enabled=!0,this.required=!1,this._exporter=e}dispose(){this._lights=null}get wasUsed(){return!!this._lights}onExporting(){this._exporter._glTF.extensions[ne]=this._lights}postExportNodeAsync(e,s,r,n,o){return i(this,void 0,void 0,function*(){return yield new Promise(i=>{if(!(r instanceof t.Light))return void i(s);const a=r.getTypeID()==t.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==t.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==t.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(a&&r instanceof t.ShadowLight))return t.Logger.Warn(`${e}: Light ${r.name} is not supported in ${ne}`),void i(s);if(r.falloffType!==t.Light.FALLOFF_GLTF&&t.Logger.Warn(`${e}: Light falloff for ${r.name} does not match the ${ne} specification!`),!r.position.equalsToFloats(0,0,0)){const e=t.TmpVectors.Vector3[0].copyFrom(r.position);o&&C(e),s.translation=e.asArray()}if("point"!==a){const e=r.direction.normalizeToRef(t.TmpVectors.Vector3[0]);o&&C(e);const n=t.Quaternion.FromUnitVectorsToRef(ae,e,t.TmpVectors.Quaternion[0]);t.Quaternion.IsIdentity(n)||(s.rotation=n.asArray())}const u={type:a,name:r.name,color:r.diffuse.asArray(),intensity:r.intensity,range:r.range};if(U(u,ie),"spot"===a){const e=r;u.spot={innerConeAngle:e.innerAngle/2,outerConeAngle:e.angle/2},U(u.spot,oe)}this._lights||(this._lights={lights:[]}),this._lights.lights.push(u);const l={light:this._lights.lights.length-1},c=r.parent;if(c&&B(r,c)){const e=n.get(c);if(e){const t=this._exporter._nodes[e];return S(s,t),t.extensions||(t.extensions={}),t.extensions[ne]=l,void i(null)}}s.extensions||(s.extensions={}),s.extensions[ne]=l,i(s)})})}}let le=!1;function ce(){le||(le=!0,D.RegisterExtension(ne,e=>new ue(e)))}ce();const he="KHR_interactivity";class de{constructor(e){var t,s;this._exporter=e,this.name=he,this.enabled=!!e.options.khrInteractivity,this.required=null!==(s=null===(t=e.options.khrInteractivity)||void 0===t?void 0:t.required)&&void 0!==s&&s}dispose(){this._exporter=null}get wasUsed(){return this.enabled}onExporting(){var e,t,s;const r=this._exporter.options.khrInteractivity;if(!r)return;const n=r.build({getNodeCount:()=>this._exporter._nodes.length,getNodeIndex:e=>this._exporter._getNodeIndex(e),getAnimationIndex:e=>this._exporter._getAnimationIndex(e),getCameraIndex:e=>this._exporter._getCameraIndex(e),getMaterialIndex:e=>this._exporter._getMaterialIndex(e),getRootIndex:(e,t)=>this._exporter._getRootIndex(e,t),setNodeExtension:(e,t,s)=>this._exporter._setNodeExtension(e,t,s)});this._exporter._glTF.extensions[he]=n;for(const t of r.additionalExtensionsUsed)(e=this._exporter._glTF).extensionsUsed||(e.extensionsUsed=[]),-1===this._exporter._glTF.extensionsUsed.indexOf(t)&&this._exporter._glTF.extensionsUsed.push(t);for(const e of r.additionalExtensionsRequired)(t=this._exporter._glTF).extensionsUsed||(t.extensionsUsed=[]),-1===this._exporter._glTF.extensionsUsed.indexOf(e)&&this._exporter._glTF.extensionsUsed.push(e),(s=this._exporter._glTF).extensionsRequired||(s.extensionsRequired=[]),-1===this._exporter._glTF.extensionsRequired.indexOf(e)&&this._exporter._glTF.extensionsRequired.push(e)}}let fe=!1;function xe(){fe||(fe=!0,D.RegisterExtension(he,e=>new de(e),200))}xe();const pe="EXT_lights_area",_e={name:"",color:[1,1,1],intensity:1,size:1},ge={aspect:1},me=t.Vector3.Backward();class Te{constructor(e){this.name=pe,this.enabled=!0,this.required=!1,this._exporter=e}dispose(){this._lights=null}get wasUsed(){return!!this._lights}onExporting(){this._exporter._glTF.extensions[pe]=this._lights}postExportNodeAsync(e,s,r,n,o){return i(this,void 0,void 0,function*(){return yield new Promise(i=>{if(!(r instanceof t.Light))return void i(s);const a=r.getTypeID()==t.Light.LIGHTTYPEID_RECT_AREALIGHT?"rect":null;if(!a)return t.Logger.Warn(`${e}: Light ${r.name} is not supported in ${pe}`),void i(s);const u=r;if(u.falloffType!==t.Light.FALLOFF_GLTF&&t.Logger.Warn(`${e}: Light falloff for ${r.name} does not match the ${pe} specification!`),!u.position.equalsToFloats(0,0,0)){const e=t.TmpVectors.Vector3[0].copyFrom(u.position);o&&C(e),s.translation=e.asArray()}const l=t.Vector3.Forward();o&&C(l);const c=t.Quaternion.FromUnitVectorsToRef(me,l,t.TmpVectors.Quaternion[0]);t.Quaternion.IsIdentity(c)||(s.rotation=c.asArray());const h={type:a,name:u.name,color:u.diffuse.asArray(),intensity:u.intensity,size:u.height,rect:{aspect:u.width/u.height}};U(h,_e),h.rect&&U(h.rect,ge),this._lights||(this._lights={lights:[]}),this._lights.lights.push(h);const d={light:this._lights.lights.length-1},f=r.parent;if(f&&B(u,f)){const e=n.get(f);if(e){const t=this._exporter._nodes[e];return S(s,t),t.extensions||(t.extensions={}),t.extensions[pe]=d,void i(null)}}s.extensions||(s.extensions={}),s.extensions[pe]=d,i(s)})})}}let ye=!1;function Re(){ye||(ye=!0,D.RegisterExtension(pe,e=>new Te(e)))}Re();const Me="KHR_materials_anisotropy";class Ae{constructor(e){this.name=Me,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._anisoTexturesMap={},this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRBaseMaterial){if(r.anisotropy.isEnabled&&!r.anisotropy.legacy)return r.anisotropy.texture&&e.push(r.anisotropy.texture),e}else if(r instanceof t.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0){const s=function(e){const t=e.specularRoughnessAnisotropyTexture,s=e.geometryTangentTexture;return`${t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength"}_${s&&s.getInternalTexture()?s.getInternalTexture().uniqueId:"NoTangent"}`}(r);if(this._anisoTexturesMap[s])e.push(this._anisoTexturesMap[s]);else{const n=yield function(e){return i(this,void 0,void 0,function*(){const s=e.getScene(),r=e.specularRoughnessAnisotropyTexture,n=e.geometryTangentTexture;return r||n?yield t.MergeTexturesAsync("AnisotropyTexture",t.CreateRGBAConfiguration(n?t.CreateTextureInput(n,0):t.CreateConstantInput(1),n?t.CreateTextureInput(n,1):t.CreateConstantInput(0),r?t.CreateTextureInput(r,0):t.CreateConstantInput(1)),s):null})}(r);n&&(e.push(n),this._anisoTexturesMap[s]=n)}return e}return[]})}postExportMaterialAsync(e,s,r){return new Promise(e=>{var n;if(r instanceof t.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(s);this._wasUsed=!0,s.extensions=s.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(r.anisotropy.texture),n={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=t?t:void 0};null!==n.anisotropyTexture&&this._exporter._materialNeedsUVsSet.add(r),s.extensions[Me]=n}else if(r instanceof t.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0){this._wasUsed=!0,s.extensions=s.extensions||{};let t=r.specularRoughnessTexture;r._useRoughnessFromMetallicTextureGreen&&(t=r.baseMetalnessTexture);const i=this._anisoTexturesMap[r.id];if(!t&&!i){let t=r.specularRoughness,n=r.specularRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){const e=function(e,t){const s=e*e,r=s*Math.sqrt(2/(1+(1-t)*(1-t))),n=(1-t)*r;return{newBaseRoughness:Math.sqrt(n),newAnisotropyStrength:Math.min(Math.sqrt((r-s)/Math.max(1-s,1e-4)),1)}}(r.specularRoughness,r.specularRoughnessAnisotropy);t=e.newBaseRoughness,n=e.newAnisotropyStrength}s.pbrMetallicRoughness&&(s.pbrMetallicRoughness.roughnessFactor=t);const i={anisotropyStrength:n,anisotropyRotation:r.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return s.extensions[Me]=i,e(s)}const o=i?this._exporter._materialExporter.getTextureInfo(i):null,a={anisotropyStrength:r.specularRoughnessAnisotropy,anisotropyRotation:r.geometryTangentAngle,anisotropyTexture:o||void 0,extensions:{}};r._useGltfStyleAnisotropy||(s.extensions.KHR_materials_openpbr={},(n=this._exporter._glTF).extensionsUsed||(n.extensionsUsed=[]),-1===this._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&this._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr")),this._exporter._materialNeedsUVsSet.add(r),s.extensions[Me]=a}e(s)})}}let be=!1;function ve(){be||(be=!0,D.RegisterExtension(Me,e=>new Ae(e)))}ve();const we="KHR_materials_clearcoat";function Ee(e,s){const r=new t.Texture(s.name,s.getScene());return r._texture=e,r.coordinatesIndex=s.coordinatesIndex,s instanceof t.Texture&&(r.uOffset=s.uOffset,r.vOffset=s.vOffset,r.uScale=s.uScale,r.vScale=s.vScale,r.wAng=s.wAng),r.wrapU=s.wrapU,r.wrapV=s.wrapV,r}class Ce{constructor(e){this.name=we,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,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRBaseMaterial){if(r.clearCoat.isEnabled)return r.clearCoat.texture&&e.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&e.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&e.push(r.clearCoat.bumpTexture),e}else if(r instanceof t.OpenPBRMaterial&&r.coatWeight>0){let s=!1;if(r.coatWeightTexture?r.coatRoughnessTexture?r._useCoatRoughnessFromGreenChannel&&r.coatWeightTexture.getInternalTexture()===r.coatRoughnessTexture.getInternalTexture()?(e.push(r.coatWeightTexture),e.push(r.coatRoughnessTexture)):s=!0:e.push(r.coatWeightTexture):r.coatRoughnessTexture&&(r._useCoatRoughnessFromGreenChannel?e.push(r.coatRoughnessTexture):s=!0),s){const s=function(e){const t=e.coatWeightTexture,s=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",r=e.coatRoughnessTexture;return`${s}_${r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoRoughness"}`}(r);if(!this._cachedInternalTexturesMap[s]){const e=yield function(e){return i(this,void 0,void 0,function*(){const s=e.getScene(),r=e.coatWeightTexture,n=e.coatRoughnessTexture;return r||n?(yield t.MergeTexturesAsync("CoatTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),n?t.CreateTextureInput(n,e._useCoatRoughnessFromGreenChannel?1:0):t.CreateConstantInput(1)),s)).getInternalTexture():null})}(r);e&&(this._cachedInternalTexturesMap[s]=e)}this._cachedInternalTexturesMap[s]&&(r.coatWeightTexture&&(this._mergedTexturesMap[r.coatWeightTexture.uniqueId]=Ee(this._cachedInternalTexturesMap[s],r.coatWeightTexture),e.push(this._mergedTexturesMap[r.coatWeightTexture.uniqueId])),r.coatRoughnessTexture&&(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]=Ee(this._cachedInternalTexturesMap[s],r.coatRoughnessTexture),e.push(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId])))}return r.geometryCoatNormalTexture&&e.push(r.geometryCoatNormalTexture),e}return[]})}postExportMaterialAsync(e,s,r){return new Promise(e=>{if(r instanceof t.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(s);this._wasUsed=!0,s.extensions=s.extensions||{};const n=this._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);let i;i=r.clearCoat.useRoughnessFromMainTexture?this._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):this._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&t.Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${r.name}`),r.clearCoat.remapF0OnInterfaceChange&&t.Tools.Warn(`Clear Color F0 remapping is not supported for glTF export. Ignoring for: ${r.name}`);const o=this._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture),a={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=n?n:void 0,clearcoatRoughnessFactor:r.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(r),s.extensions[we]=a}else if(r instanceof t.OpenPBRMaterial){if(0==r.coatWeight)return void e(s);let n,i,o,a;this._wasUsed=!0,s.extensions=s.extensions||{},r.coatWeightTexture&&(n=this._mergedTexturesMap[r.coatWeightTexture.uniqueId],i=this._exporter._materialExporter.getTextureInfo(n)),r.coatRoughnessTexture&&(o=this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId],a=this._exporter._materialExporter.getTextureInfo(o)),r.coatColorTexture&&t.Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${r.name}`);const u=this._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),l={clearcoatFactor:r.coatWeight,clearcoatTexture:null!=i?i:void 0,clearcoatRoughnessFactor:r.coatRoughness,clearcoatRoughnessTexture:null!=a?a:void 0,clearcoatNormalTexture:null!=u?u:void 0};null===l.clearcoatTexture&&null===l.clearcoatRoughnessTexture&&null===l.clearcoatRoughnessTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[we]=l}e(s)})}}let Ie=!1;function Ve(){Ie||(Ie=!0,D.RegisterExtension(we,e=>new Ce(e)))}Ve();const Fe="KHR_materials_coat";function Se(e){const t=e.coatRoughnessAnisotropyTexture,s=e.geometryCoatTangentTexture;return`${t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength"}_${s&&s.getInternalTexture()?s.getInternalTexture().uniqueId:"NoTangent"}`}function Be(e,s){const r=new t.Texture(s.name,s.getScene());return r._texture=e,r.coordinatesIndex=s.coordinatesIndex,s instanceof t.Texture&&(r.uOffset=s.uOffset,r.vOffset=s.vOffset,r.uScale=s.uScale,r.vScale=s.vScale,r.wAng=s.wAng),r.wrapU=s.wrapU,r.wrapV=s.wrapV,r}class Ne{constructor(e){this.name=Fe,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,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRBaseMaterial){if(r.clearCoat.isEnabled)return r.clearCoat.texture&&e.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&e.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&e.push(r.clearCoat.bumpTexture),r.clearCoat.tintTexture&&e.push(r.clearCoat.tintTexture),e}else if(r instanceof t.OpenPBRMaterial&&r.coatWeight>0){let s=!1;if(r.coatWeightTexture?r.coatRoughnessTexture?r._useCoatRoughnessFromGreenChannel&&r.coatWeightTexture.getInternalTexture()===r.coatRoughnessTexture.getInternalTexture()?(e.push(r.coatWeightTexture),e.push(r.coatRoughnessTexture)):s=!0:e.push(r.coatWeightTexture):r.coatRoughnessTexture&&(r._useCoatRoughnessFromGreenChannel?e.push(r.coatRoughnessTexture):s=!0),s){const s=function(e){const t=e.coatWeightTexture,s=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",r=e.coatRoughnessTexture;return`${s}_${r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoRoughness"}`}(r);if(!this._cachedInternalTexturesMap[s]){const e=yield function(e){return i(this,void 0,void 0,function*(){const s=e.getScene(),r=e.coatWeightTexture,n=e.coatRoughnessTexture;return r||n?(yield t.MergeTexturesAsync("CoatTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),n?t.CreateTextureInput(n,e._useCoatRoughnessFromGreenChannel?1:0):t.CreateConstantInput(1)),s)).getInternalTexture():null})}(r);e&&(this._cachedInternalTexturesMap[s]=e)}this._cachedInternalTexturesMap[s]&&(r.coatWeightTexture&&(this._mergedTexturesMap[r.coatWeightTexture.uniqueId]=Be(this._cachedInternalTexturesMap[s],r.coatWeightTexture),e.push(this._mergedTexturesMap[r.coatWeightTexture.uniqueId])),r.coatRoughnessTexture&&(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]=Be(this._cachedInternalTexturesMap[s],r.coatRoughnessTexture),e.push(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId])))}if(r.geometryCoatNormalTexture&&e.push(r.geometryCoatNormalTexture),r.coatColorTexture&&e.push(r.coatColorTexture),r.coatRoughnessAnisotropy>0){const s=Se(r);if(this._mergedTexturesMap[s])e.push(this._mergedTexturesMap[s]);else{const n=yield function(e){return i(this,void 0,void 0,function*(){const s=e.getScene(),r=e.coatRoughnessAnisotropyTexture,n=e.geometryCoatTangentTexture;return r||n?yield t.MergeTexturesAsync("AnisotropyTexture",t.CreateRGBAConfiguration(n?t.CreateTextureInput(n,0):t.CreateConstantInput(1),n?t.CreateTextureInput(n,1):t.CreateConstantInput(0),r?t.CreateTextureInput(r,0):t.CreateConstantInput(1)),s):null})}(r);n&&(e.push(n),this._mergedTexturesMap[s]=n)}return e}return e}return[]})}postExportMaterialAsync(e,s,r){return new Promise(e=>{var n;if(r instanceof t.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(s);this._wasUsed=!0,s.extensions=s.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);let n,i;n=r.clearCoat.useRoughnessFromMainTexture?this._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):this._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&(i=this._exporter._materialExporter.getTextureInfo(r.clearCoat.tintTexture));const o=this._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture),a=r.clearCoat.indexOfRefraction,u={coatFactor:r.clearCoat.intensity,coatTexture:null!=t?t:void 0,coatRoughnessFactor:r.clearCoat.roughness,coatRoughnessTexture:null!=n?n:void 0,coatNormalTexture:null!=o?o:void 0,coatColorFactor:r.clearCoat.tintColor.asArray(),coatColorTexture:null!=i?i:void 0,coatIor:1.5!==a?a:void 0};null===u.coatTexture&&null===u.coatRoughnessTexture&&null===u.coatRoughnessTexture&&null===u.coatColorTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[Fe]=u}else if(r instanceof t.OpenPBRMaterial){if(0==r.coatWeight)return void e(s);let t,i,o,a;this._wasUsed=!0,s.extensions=s.extensions||{},r.coatWeightTexture&&(t=this._mergedTexturesMap[r.coatWeightTexture.uniqueId]?this._mergedTexturesMap[r.coatWeightTexture.uniqueId]:r.coatWeightTexture,i=this._exporter._materialExporter.getTextureInfo(t)),r.coatRoughnessTexture&&(o=this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]?this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]:r.coatRoughnessTexture,a=this._exporter._materialExporter.getTextureInfo(o));const u=this._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),l=this._exporter._materialExporter.getTextureInfo(r.coatColorTexture),c=r.coatIor,h=r.coatDarkening,d=r.coatRoughnessTexture,f=Se(r),x=this._mergedTexturesMap[f];let p,_=0,g=0;if(r.coatRoughnessAnisotropy>0){if(d||x){const e=x?this._exporter._materialExporter.getTextureInfo(x):null;_=r.coatRoughnessAnisotropy,g=r.geometryCoatTangentAngle,p=e||void 0}else{let e=r.coatRoughness,t=r.coatRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){const s=function(e,t){const s=e*e,r=s*Math.sqrt(2/(1+(1-t)*(1-t))),n=(1-t)*r;return{newBaseRoughness:Math.sqrt(n),newAnisotropyStrength:Math.min(Math.sqrt((r-s)/Math.max(1-s,1e-4)),1)}}(r.coatRoughness,r.coatRoughnessAnisotropy);e=s.newBaseRoughness,t=s.newAnisotropyStrength}s.pbrMetallicRoughness&&(s.pbrMetallicRoughness.roughnessFactor=e),_=t,g=r.geometryCoatTangentAngle+.5*Math.PI,p=void 0}r._useGltfStyleAnisotropy||(s.extensions.KHR_materials_openpbr={},(n=this._exporter._glTF).extensionsUsed||(n.extensionsUsed=[]),-1===this._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&this._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr"))}const m={coatFactor:r.coatWeight,coatTexture:null!=i?i:void 0,coatRoughnessFactor:r.coatRoughness,coatRoughnessTexture:null!=a?a:void 0,coatNormalTexture:null!=u?u:void 0,coatColorFactor:r.coatColor.asArray(),coatColorTexture:null!=l?l:void 0,coatIor:1.5!==c?c:void 0,coatDarkeningFactor:1!==h?h:void 0,coatAnisotropyRotation:g,coatAnisotropyStrength:_,coatAnisotropyTexture:p};null===m.coatTexture&&null===m.coatRoughnessTexture&&null===m.coatRoughnessTexture&&null===m.coatAnisotropyTexture&&null===m.coatColorTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[Fe]=m}e(s)})}}let Ue=!1;function Oe(){Ue||(Ue=!0,D.RegisterExtension(Fe,e=>new Ne(e)))}Oe();const Ke="KHR_materials_diffuse_transmission";function Pe(e,s){const r=s.subSurface;let n=null;return r.translucencyIntensityTexture?n=r.translucencyIntensityTexture:r.thicknessTexture&&r.useMaskFromThicknessTexture&&(n=r.thicknessTexture),n&&!r.useGltfStyleTextures?(t.Logger.Warn(`${e}: Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ${s.name}`,1),null):n}class He{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,s,r){return i(this,void 0,void 0,function*(){const s=[];if(r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)){const t=Pe(e,r);return t&&s.push(t),r.subSurface.translucencyColorTexture&&s.push(r.subSurface.translucencyColorTexture),s}return s})}_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,s,r){return new Promise(n=>{var i,o;if(r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0;const t=r.subSurface,n=Pe(e,r),a=0==t.translucencyIntensity?void 0:t.translucencyIntensity,u=null!==(i=this._exporter._materialExporter.getTextureInfo(n))&&void 0!==i?i:void 0,l=!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:u,diffuseTransmissionColorFactor:l,diffuseTransmissionColorTexture:c};(u||c)&&this._exporter._materialNeedsUVsSet.add(r),s.extensions=s.extensions||{},s.extensions[Ke]=h}n(s)})}}let We=!1;function Le(){We||(We=!0,D.RegisterExtension(Ke,e=>new He(e)))}Le();const ze="KHR_materials_dispersion";class ke{constructor(){this.name=ze,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,s,r){return new Promise(e=>{if(r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0;const e={dispersion:r.subSurface.dispersion};s.extensions=s.extensions||{},s.extensions[ze]=e}e(s)})}}let Ge=!1;function De(){Ge||(Ge=!0,D.RegisterExtension(ze,()=>new ke))}De();const qe="KHR_materials_emissive_strength";class $e{constructor(){this.name=qe,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAsync(e,s,r){return i(this,void 0,void 0,function*(){return yield new Promise(e=>{if(!(r instanceof t.PBRMaterial))return e(s);const n=r.emissiveColor.scale(r.emissiveIntensity),i=Math.max(...n.asArray());if(i>1){s.emissiveFactor=n.scale(1/i).asArray(),this._wasUsed=!0;const e={emissiveStrength:i};s.extensions||(s.extensions={}),s.extensions[qe]=e}else s.emissiveFactor=n.asArray();return e(s)})})}}let Xe=!1;function Qe(){Xe||(Xe=!0,D.RegisterExtension(qe,()=>new $e))}Qe();const je="KHR_materials_ior";class Ye{constructor(){this.name=je,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,s,r){return new Promise(e=>{if(r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0;const e={ior:r.indexOfRefraction};s.extensions=s.extensions||{},s.extensions[je]=e}else if(r instanceof t.OpenPBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0;const e={ior:r.specularIor};s.extensions=s.extensions||{},s.extensions[je]=e}e(s)})}}let Ze=!1;function Je(){Ze||(Ze=!0,D.RegisterExtension(je,()=>new Ye))}Je();const et="KHR_materials_iridescence";class tt{constructor(e){this.name=et,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRBaseMaterial){if(r.iridescence.isEnabled)return r.iridescence.texture&&e.push(r.iridescence.texture),r.iridescence.thicknessTexture&&r.iridescence.thicknessTexture!==r.iridescence.texture&&e.push(r.iridescence.thicknessTexture),e}else if(r instanceof t.OpenPBRMaterial&&r.thinFilmWeight>0)return r.thinFilmWeightTexture&&e.push(r.thinFilmWeightTexture),r.thinFilmThicknessTexture&&r.thinFilmThicknessTexture!==r.thinFilmWeightTexture&&e.push(r.thinFilmThicknessTexture),e;return[]})}postExportMaterialAsync(e,s,r){return new Promise(e=>{if(r instanceof t.PBRBaseMaterial){if(!r.iridescence.isEnabled)return void e(s);this._wasUsed=!0,s.extensions=s.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(r.iridescence.texture),n=this._exporter._materialExporter.getTextureInfo(r.iridescence.thicknessTexture),i={iridescenceFactor:r.iridescence.intensity,iridescenceIor:r.iridescence.indexOfRefraction,iridescenceThicknessMinimum:r.iridescence.minimumThickness,iridescenceThicknessMaximum:r.iridescence.maximumThickness,iridescenceTexture:null!=t?t:void 0,iridescenceThicknessTexture:null!=n?n:void 0};null===i.iridescenceTexture&&null===i.iridescenceThicknessTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[et]=i}else if(r instanceof t.OpenPBRMaterial){if(r.thinFilmWeight<=0)return void e(s);this._wasUsed=!0,s.extensions=s.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(r.thinFilmWeightTexture),n=this._exporter._materialExporter.getTextureInfo(r.thinFilmThicknessTexture),i={iridescenceFactor:r.thinFilmWeight,iridescenceIor:r.thinFilmIor,iridescenceThicknessMinimum:1e3*r.thinFilmThicknessMin,iridescenceThicknessMaximum:1e3*r.thinFilmThickness,iridescenceTexture:null!=t?t:void 0,iridescenceThicknessTexture:null!=n?n:void 0};null===i.iridescenceTexture&&null===i.iridescenceThicknessTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[et]=i}e(s)})}}let st=!1;function rt(){st||(st=!0,D.RegisterExtension(et,e=>new tt(e)))}rt();const nt="KHR_materials_sheen";class it{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,s,r){return i(this,void 0,void 0,function*(){return r instanceof t.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[r.sheen.texture]:[]})}postExportMaterialAsync(e,s,r){return i(this,void 0,void 0,function*(){return yield new Promise(e=>{var n,i,o,a;if(r instanceof t.PBRMaterial){if(!r.sheen.isEnabled)return void e(s);this._wasUsed=!0,null==s.extensions&&(s.extensions={});const t={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(n=r.sheen.roughness)&&void 0!==n?n:0};null===t.sheenColorTexture&&null===t.sheenRoughnessTexture||this._exporter._materialNeedsUVsSet.add(r),r.sheen.texture&&(t.sheenColorTexture=null!==(i=this._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==i?i:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?t.sheenRoughnessTexture=null!==(o=this._exporter._materialExporter.getTextureInfo(r.sheen.textureRoughness))&&void 0!==o?o:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(t.sheenRoughnessTexture=null!==(a=this._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==a?a:void 0),s.extensions[nt]=t}e(s)})})}}let ot=!1;function at(){ot||(ot=!0,D.RegisterExtension(nt,e=>new it(e)))}at();const ut="KHR_materials_fuzz";function lt(e,s){const r=new t.Texture(s.name,s.getScene());return r._texture=e,r.coordinatesIndex=s.coordinatesIndex,s instanceof t.Texture&&(r.uOffset=s.uOffset,r.vOffset=s.vOffset,r.uScale=s.uScale,r.vScale=s.vScale,r.wAng=s.wAng),r.wrapU=s.wrapU,r.wrapV=s.wrapV,r}class ct{constructor(e){this.name=ut,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,s,r){return i(this,void 0,void 0,function*(){if(r instanceof t.OpenPBRMaterial){const e=[];if(r.fuzzWeight>0){r.fuzzWeightTexture&&e.push(r.fuzzWeightTexture);let s=!1;if(r.fuzzRoughnessTexture&&(r._useFuzzRoughnessFromTextureAlpha?e.push(r.fuzzRoughnessTexture):s=!0),r.fuzzColorTexture&&!s&&e.push(r.fuzzColorTexture),s){const s=function(e){const t=e.fuzzColorTexture,s=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoFuzzColor",r=e.fuzzRoughnessTexture;return`FuzzColor_${s}_FuzzRoughness_${r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoFuzzRoughness"}`}(r);if(!this._cachedInternalTexturesMap[s]){const e=yield function(e){return i(this,void 0,void 0,function*(){const s=e.getScene(),r=e.fuzzColorTexture,n=e.fuzzRoughnessTexture;return r||n?(yield t.MergeTexturesAsync("FuzzTexture",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),n?t.CreateTextureInput(n,e._useFuzzRoughnessFromTextureAlpha?3:0):t.CreateConstantInput(1)),s)).getInternalTexture():null})}(r);e&&(this._cachedInternalTexturesMap[s]=e)}this._cachedInternalTexturesMap[s]&&(r.fuzzColorTexture&&(this._mergedTexturesMap[r.fuzzColorTexture.uniqueId]=lt(this._cachedInternalTexturesMap[s],r.fuzzColorTexture),e.push(this._mergedTexturesMap[r.fuzzColorTexture.uniqueId])),r.fuzzRoughnessTexture&&(this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]=lt(this._cachedInternalTexturesMap[s],r.fuzzRoughnessTexture),e.push(this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId])))}}return e}return[]})}postExportMaterialAsync(e,s,r){return i(this,void 0,void 0,function*(){return yield new Promise(e=>{var n,i,o;if(r instanceof t.OpenPBRMaterial){if(0==r.fuzzWeight)return void e(s);this._wasUsed=!0,null==s.extensions&&(s.extensions={});const t={fuzzFactor:r.fuzzWeight,fuzzColorFactor:r.fuzzColor.asArray(),fuzzRoughnessFactor:r.fuzzRoughness};let a,u;r.fuzzWeightTexture&&(t.fuzzTexture=null!==(n=this._exporter._materialExporter.getTextureInfo(r.fuzzWeightTexture))&&void 0!==n?n:void 0),r.fuzzColorTexture&&(a=this._mergedTexturesMap[r.fuzzColorTexture.uniqueId]?this._mergedTexturesMap[r.fuzzColorTexture.uniqueId]:r.fuzzColorTexture,t.fuzzColorTexture=null!==(i=this._exporter._materialExporter.getTextureInfo(a))&&void 0!==i?i:void 0),r.fuzzRoughnessTexture&&(u=this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]?this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]:r.fuzzRoughnessTexture,t.fuzzRoughnessTexture=null!==(o=this._exporter._materialExporter.getTextureInfo(u))&&void 0!==o?o:void 0),null===t.fuzzColorTexture&&null===t.fuzzRoughnessTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[ut]=t}e(s)})})}}let ht=!1;function dt(){ht||(ht=!0,D.RegisterExtension(ut,e=>new ct(e)))}dt();const ft="KHR_materials_specular";class xt{constructor(e){this.name=ft,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];return r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)?(r.metallicReflectanceTexture&&e.push(r.metallicReflectanceTexture),r.reflectanceTexture&&e.push(r.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,s,r){return new Promise(e=>{var n,i,o,a,u;if(r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0,s.extensions=s.extensions||{};const e=null!==(n=this._exporter._materialExporter.getTextureInfo(r.metallicReflectanceTexture))&&void 0!==n?n:void 0,t=null!==(i=this._exporter._materialExporter.getTextureInfo(r.reflectanceTexture))&&void 0!==i?i:void 0,o={specularFactor:1==r.metallicF0Factor?void 0:r.metallicF0Factor,specularTexture:e,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:t};this._hasTexturesExtension(r)&&this._exporter._materialNeedsUVsSet.add(r),s.extensions[ft]=o}else if(r instanceof t.OpenPBRMaterial){s.extensions=s.extensions||{};const t=null!==(o=this._exporter._materialExporter.getTextureInfo(r.specularWeightTexture))&&void 0!==o?o:void 0,n=null!==(a=this._exporter._materialExporter.getTextureInfo(r.specularColorTexture))&&void 0!==a?a:void 0,i=1==r.specularWeight?void 0:r.specularWeight,l=r.specularColor.equalsFloats(1,1,1)?void 0:r.specularColor.asArray();if(!n&&!t&&void 0===i&&void 0===l)return e(s);this._wasUsed=!0;const c={specularEdgeColorEnabled:!0},h={specularFactor:i,specularTexture:t,specularColorFactor:l,specularColorTexture:n,extensions:{}};h.extensions.EXT_materials_specular_edge_color=c,(u=this._exporter._glTF).extensionsUsed||(u.extensionsUsed=[]),-1===this._exporter._glTF.extensionsUsed.indexOf("EXT_materials_specular_edge_color")&&this._exporter._glTF.extensionsUsed.push("EXT_materials_specular_edge_color"),(t||n)&&this._exporter._materialNeedsUVsSet.add(r),s.extensions[ft]=h}e(s)})}}let pt=!1;function _t(){pt||(pt=!0,D.RegisterExtension(ft,e=>new xt(e)))}_t();const gt="KHR_materials_transmission";class mt{constructor(e){this.name=gt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRMaterial){if(this._isExtensionEnabled(r))return r.subSurface.refractionIntensityTexture&&r.subSurface.useGltfStyleTextures&&e.push(r.subSurface.refractionIntensityTexture),e}else r instanceof t.OpenPBRMaterial&&(r.transmissionWeight>0&&r.transmissionWeightTexture&&(e.push(r.transmissionWeightTexture),r.transmissionColorTexture&&e.push(r.transmissionColorTexture)),r.subsurfaceWeight>0&&r.subsurfaceWeightTexture&&e.push(r.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,s,r){return i(this,void 0,void 0,function*(){if(!this._isExtensionEnabled(r))return s;if(r instanceof t.PBRMaterial){this._wasUsed=!0;const n=r.subSurface,i={transmissionFactor:0===n.refractionIntensity?void 0:n.refractionIntensity};if(n.refractionIntensityTexture)if(n.useGltfStyleTextures){this._exporter._materialNeedsUVsSet.add(r);const e=this._exporter._materialExporter.getTextureInfo(n.refractionIntensityTexture);e&&(i.transmissionTexture=e)}else t.Logger.Warn(`${e}: Exporting a subsurface refraction intensity texture without \`useGltfStyleTextures\` is not supported`);s.extensions||(s.extensions={}),s.extensions[gt]=i}else if(r instanceof t.OpenPBRMaterial){this._wasUsed=!0;const e={transmissionFactor:(1-r.transmissionWeight)*r.subsurfaceWeight+r.transmissionWeight};if(r.transmissionWeightTexture){this._exporter._materialNeedsUVsSet.add(r);const t=this._exporter._materialExporter.getTextureInfo(r.transmissionWeightTexture);t&&(e.transmissionTexture=t)}else if(r.subsurfaceWeightTexture){this._exporter._materialNeedsUVsSet.add(r);const t=this._exporter._materialExporter.getTextureInfo(r.subsurfaceWeightTexture);t&&(e.transmissionTexture=t)}if(0==r.transmissionDepth&&(!r.transmissionColor.equals(t.Color3.White())||r.transmissionColorTexture)&&s.pbrMetallicRoughness&&(s.pbrMetallicRoughness.baseColorFactor||(s.pbrMetallicRoughness.baseColorFactor=[1,1,1,1]),s.pbrMetallicRoughness.baseColorFactor[0]*=r.transmissionColor.r,s.pbrMetallicRoughness.baseColorFactor[1]*=r.transmissionColor.g,s.pbrMetallicRoughness.baseColorFactor[2]*=r.transmissionColor.b,r.transmissionColorTexture&&!s.pbrMetallicRoughness.baseColorTexture)){const e=this._exporter._materialExporter.getTextureInfo(r.transmissionColorTexture);e&&(s.pbrMetallicRoughness.baseColorTexture=e,this._exporter._materialNeedsUVsSet.add(r))}s.extensions||(s.extensions={}),s.extensions[gt]=e}return s})}}let Tt=!1;function yt(){Tt||(Tt=!0,D.RegisterExtension(gt,e=>new mt(e)))}yt();const Rt="KHR_materials_unlit";class Mt{constructor(){this.name=Rt,this.enabled=!0,this.required=!1,this._wasUsed=!1}get wasUsed(){return this._wasUsed}dispose(){}postExportMaterialAsync(e,s,r){return new Promise(e=>{let n=!1;r instanceof t.PBRMaterial?n=r.unlit:r instanceof t.StandardMaterial&&(n=r.disableLighting),n&&(this._wasUsed=!0,null==s.extensions&&(s.extensions={}),s.extensions[Rt]={}),e(s)})}}let At=!1;function bt(){At||(At=!0,D.RegisterExtension(Rt,()=>new Mt))}bt();const vt="KHR_materials_volume";class wt{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,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRMaterial){if(this._isExtensionEnabled(r))return r.subSurface.thicknessTexture&&e.push(r.subSurface.thicknessTexture),e}else r instanceof t.OpenPBRMaterial&&(r.transmissionWeight>0||r.subsurfaceWeight>0)&&r.geometryThicknessTexture&&e.push(r.geometryThicknessTexture);return e})}_isExtensionEnabled(e){if(e.unlit)return!1;const s=e.subSurface;return!(!s.isRefractionEnabled&&!s.isTranslucencyEnabled)&&(null!=s.maximumThickness&&0!=s.maximumThickness||null!=s.tintColorAtDistance&&s.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=s.tintColor&&s.tintColor!=t.Color3.White()||this._hasTexturesExtension(e))}_hasTexturesExtension(e){return null!=e.subSurface.thicknessTexture}postExportMaterialAsync(e,s,r){return new Promise(e=>{var n,i;if(r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0;const e=r.subSurface,t={thicknessFactor:0==e.maximumThickness?void 0:e.maximumThickness,thicknessTexture:null!==(n=this._exporter._materialExporter.getTextureInfo(e.thicknessTexture))&&void 0!==n?n: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(r)&&this._exporter._materialNeedsUVsSet.add(r),s.extensions=s.extensions||{},s.extensions[vt]=t}else if(r instanceof t.OpenPBRMaterial){const e=r.transmissionWeight>0&&!r.geometryThinWalled,n=r.subsurfaceWeight>0&&!r.geometryThinWalled;if(e||n){this._wasUsed=!0;const o=r.geometryThickness,a=null!==(i=this._exporter._materialExporter.getTextureInfo(r.geometryThicknessTexture))&&void 0!==i?i:void 0;let u;a&&this._exporter._materialNeedsUVsSet.add(r);const l=t.Color3.White().asArray();if(e&&r.transmissionDepth>0){const e=1/r.transmissionDepth;let s=new t.Vector3(-Math.log(r.transmissionColor.r)*e,-Math.log(r.transmissionColor.g)*e,-Math.log(r.transmissionColor.b)*e);const n=new t.Vector3(r.transmissionScatter.r*e,r.transmissionScatter.g*e,r.transmissionScatter.b*e),i=s.subtract(n),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),s=i.add(n),u=1/Math.max(s.x,s.y,s.z),l[0]=Math.exp(-s.x*u),l[1]=Math.exp(-s.y*u),l[2]=Math.exp(-s.z*u)}else u=Number.MAX_VALUE,l[0]=1,l[1]=1,l[2]=1;let c=1;const h=t.Color3.White().asArray();if(n){const e=r.subsurfaceRadius,s=r.subsurfaceRadiusScale,n=new t.Vector3(s.r,s.g,s.b).multiplyByFloats(e,e,e),i=new t.Vector3(1/Math.max(n.x,1e-6),1/Math.max(n.y,1e-6),1/Math.max(n.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-r.transmissionWeight)*r.subsurfaceWeight,f=d+r.transmissionWeight,x=1/Math.max(f,1e-6),p=r.transmissionWeight*x,_=d*x,g=l.map((e,t)=>e*p+h[t]*_),m={thicknessFactor:o,thicknessTexture:a,attenuationDistance:u*p+c*_,attenuationColor:g};s.extensions=s.extensions||{},s.extensions[vt]=m}}e(s)})}}let Et=!1;function Ct(){Et||(Et=!0,D.RegisterExtension(vt,e=>new wt(e)))}Ct();const It="KHR_materials_volume_scatter";class Vt{constructor(e){this.name=It,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];return r instanceof t.OpenPBRMaterial&&(r.transmissionWeight>0&&r.transmissionScatterTexture&&e.push(r.transmissionScatterTexture),r.subsurfaceWeight>0&&r.subsurfaceColorTexture&&e.push(r.subsurfaceColorTexture)),e})}_isExtensionEnabled(e){if(e.unlit)return!1;const s=e.transmissionWeight>0&&!e.geometryThinWalled&&e.transmissionDepth>0&&!e.transmissionScatter.equals(t.Color3.Black()),r=e.subsurfaceWeight>0&&!e.geometryThinWalled;return!(!s&&!r)}postExportMaterialAsync(e,s,r){return new Promise(e=>{if(r instanceof t.OpenPBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0;let e=t.Vector3.Zero(),n=0;r.transmissionWeight>0&&(e=function(e){const s=new t.Vector3(Math.sqrt(1-e.x),Math.sqrt(1-e.y),Math.sqrt(1-e.z)),r=new t.Vector3(1,1,1),n=r.subtract(s),i=r.subtract(new t.Vector3(.139,.139,.139).multiplyInPlace(s)),o=r.add(new t.Vector3(1.17,1.17,1.17).multiplyInPlace(s));return n.multiplyInPlace(i).divideInPlace(o)}(new t.Vector3(r.transmissionScatter.r,r.transmissionScatter.g,r.transmissionScatter.b)),n=r.transmissionScatterAnisotropy);const i=t.Vector3.Zero();let o=0;r.subsurfaceWeight>0&&(i.set(r.subsurfaceColor.r,r.subsurfaceColor.g,r.subsurfaceColor.b),o=r.subsurfaceScatterAnisotropy);const a=(1-r.transmissionWeight)*r.subsurfaceWeight,u=a+r.transmissionWeight,l=1/Math.max(u,1e-6),c=r.transmissionWeight*l,h=a*l,d={multiscatterColorFactor:e.multiplyByFloats(c,c,c).addInPlace(i.multiplyByFloats(h,h,h)).asArray(),scatterAnisotropy:n*c+o*h};if(r.subsurfaceWeight>0&&r.subsurfaceColorTexture){this._exporter._materialNeedsUVsSet.add(r);const e=this._exporter._materialExporter.getTextureInfo(r.subsurfaceColorTexture);e&&(d.multiscatterColorTexture=e)}else if(r.transmissionWeight>0&&r.transmissionScatterTexture){this._exporter._materialNeedsUVsSet.add(r);const e=this._exporter._materialExporter.getTextureInfo(r.transmissionScatterTexture);e&&(d.multiscatterColorTexture=e)}s.extensions=s.extensions||{},s.extensions[It]=d}e(s)})}}let Ft=!1;function St(){Ft||(Ft=!0,D.RegisterExtension(It,e=>new Vt(e),101))}St();const Bt="KHR_materials_diffuse_roughness";class Nt{constructor(e){this.name=Bt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRBaseMaterial){if(r._baseDiffuseRoughness)return r._baseDiffuseRoughnessTexture&&e.push(r._baseDiffuseRoughnessTexture),e}else if(r instanceof t.OpenPBRMaterial&&r.baseDiffuseRoughness)return r.baseDiffuseRoughnessTexture&&e.push(r.baseDiffuseRoughnessTexture),e;return[]})}postExportMaterialAsync(e,s,r){return new Promise(e=>{let n=null,i=null;if(r instanceof t.PBRBaseMaterial?(n=r._baseDiffuseRoughness,i=r._baseDiffuseRoughnessTexture):r instanceof t.OpenPBRMaterial&&(n=r.baseDiffuseRoughness,i=r.baseDiffuseRoughnessTexture),!n)return void e(s);this._wasUsed=!0,s.extensions=s.extensions||{};const o=this._exporter._materialExporter.getTextureInfo(i),a={diffuseRoughnessFactor:n,diffuseRoughnessTexture:null!=o?o:void 0};null!==a.diffuseRoughnessTexture&&this._exporter._materialNeedsUVsSet.add(r),s.extensions[Bt]=a,e(s)})}}let Ut=!1;function Ot(){Ut||(Ut=!0,D.RegisterExtension(Bt,e=>new Nt(e)))}Ot();const Kt="KHR_materials_openpbr";class Pt{constructor(){this.name=Kt,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAsync(e,s,r){return new Promise(e=>{r instanceof t.OpenPBRMaterial&&(this._wasUsed=!0,s.extensions=s.extensions||{},s.extensions[Kt]={}),e(s)})}}let Ht=!1;function Wt(){Ht||(Ht=!0,D.RegisterExtension(Kt,()=>new Pt))}Wt();const Lt="KHR_texture_transform";class zt{constructor(){this.name=Lt,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}postExportTexture(e,s,r){if(r.getScene()||t.Tools.Warn(`${e}: "scene" is not defined for Babylon texture ${r.name}!`),(0!==r.uAng||0!==r.vAng)&&(t.Tools.Warn(`${e}: Texture ${r.name} with rotation in the u or v axis is not supported in glTF.`),0!==r.uRotationCenter||0!==r.vRotationCenter))return;const n={};let i=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],i=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],i=!0),0!==r.wAng){if(0!==r.uRotationCenter||0!==r.vRotationCenter){if(r.homogeneousRotationInUVTransform&&r.uScale!==r.vScale)return void t.Tools.Warn(`${e}: Texture ${r.name} with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ${Lt}.`);t.Tools.Warn(`${e}: Texture ${r.name} with non-origin rotation center will be exported using an adjusted offset with ${Lt}.`),n.offset=function(e){const{uOffset:t,vOffset:s,uRotationCenter:r,vRotationCenter:n,uScale:i,vScale:o,wAng:a}=e,u=Math.cos(a),l=Math.sin(a),c=r*i,h=n*o;return[t+(c*(1-u)+h*l),s+(h*(1-u)-c*l)]}(r)}n.rotation=-r.wAng,i=!0}0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,i=!0),i&&(this._wasUsed=!0,s.extensions||(s.extensions={}),s.extensions[Lt]=n)}}let kt=!1;function Gt(){kt||(kt=!0,D.RegisterExtension(Lt,()=>new zt))}Gt();const Dt="KHR_texture_basisu";class qt{get wasUsed(){return this._wasUsed}constructor(e){this.name=Dt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}dispose(){}postExportTexture(e,s){const r=this._exporter._textures[s.index],n=r.source;if(void 0===n)return;const i=this._exporter._images[n];"image/ktx2"===(i.mimeType||t.GetMimeType(i.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[Dt]={source:n},this._wasUsed=!0)}}let $t=!1;function Xt(){$t||($t=!0,D.RegisterExtension(Dt,e=>new qt(e)))}Xt();const Qt="EXT_texture_webp";class jt{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,s){const r=this._exporter._textures[s.index],n=r.source;if(void 0===n)return;const i=this._exporter._images[n];"image/webp"===(i.mimeType||t.GetMimeType(i.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[Qt]={source:n},this._wasUsed=!0)}}let Yt=!1;function Zt(){Yt||(Yt=!0,D.RegisterExtension(Qt,e=>new jt(e)))}Zt();const Jt="EXT_texture_avif";class es{get wasUsed(){return this._wasUsed}constructor(e){this.name=Jt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}dispose(){}postExportTexture(e,s){const r=this._exporter._textures[s.index],n=r.source;if(void 0===n)return;const i=this._exporter._images[n];"image/avif"===(i.mimeType||t.GetMimeType(i.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[Jt]={source:n},this._wasUsed=!0)}}let ts=!1;function ss(){ts||(ts=!0,D.RegisterExtension(Jt,e=>new es(e)))}ss();var rs={__proto__:null,EXT_lights_area:Te,EXT_mesh_gpu_instancing:j,EXT_texture_avif:es,EXT_texture_webp:jt,KHR_draco_mesh_compression:te,KHR_interactivity:de,KHR_lights_punctual:ue,KHR_materials_anisotropy:Ae,KHR_materials_clearcoat:Ce,KHR_materials_coat:Ne,KHR_materials_diffuse_roughness:Nt,KHR_materials_diffuse_transmission:He,KHR_materials_dispersion:ke,KHR_materials_emissive_strength:$e,KHR_materials_fuzz:ct,KHR_materials_ior:Ye,KHR_materials_iridescence:tt,KHR_materials_openpbr:Pt,KHR_materials_sheen:it,KHR_materials_specular:xt,KHR_materials_transmission:mt,KHR_materials_unlit:Mt,KHR_materials_volume:wt,KHR_materials_volume_scatter:Vt,KHR_texture_basisu:qt,KHR_texture_transform:zt,RegisterEXT_lights_area:Re,RegisterEXT_mesh_gpu_instancing:Z,RegisterEXT_texture_avif:ss,RegisterEXT_texture_webp:Zt,RegisterKHR_draco_mesh_compression:re,RegisterKHR_interactivity:xe,RegisterKHR_lights_punctual:ce,RegisterKHR_materials_anisotropy:ve,RegisterKHR_materials_clearcoat:Ve,RegisterKHR_materials_coat:Oe,RegisterKHR_materials_diffuse_roughness:Ot,RegisterKHR_materials_diffuse_transmission:Le,RegisterKHR_materials_dispersion:De,RegisterKHR_materials_emissive_strength:Qe,RegisterKHR_materials_fuzz:dt,RegisterKHR_materials_ior:Je,RegisterKHR_materials_iridescence:rt,RegisterKHR_materials_openpbr:Wt,RegisterKHR_materials_sheen:at,RegisterKHR_materials_specular:_t,RegisterKHR_materials_transmission:yt,RegisterKHR_materials_unlit:bt,RegisterKHR_materials_volume:Ct,RegisterKHR_materials_volume_scatter:St,RegisterKHR_texture_basisu:Xt,RegisterKHR_texture_transform:Gt},ns={__proto__:null,EXT_lights_area:Te,EXT_mesh_gpu_instancing:j,EXT_texture_avif:es,EXT_texture_webp:jt,GLTF2Export:q,GLTFData:r,KHR_draco_mesh_compression:te,KHR_interactivity:de,KHR_lights_punctual:ue,KHR_materials_anisotropy:Ae,KHR_materials_clearcoat:Ce,KHR_materials_coat:Ne,KHR_materials_diffuse_roughness:Nt,KHR_materials_diffuse_transmission:He,KHR_materials_dispersion:ke,KHR_materials_emissive_strength:$e,KHR_materials_fuzz:ct,KHR_materials_ior:Ye,KHR_materials_iridescence:tt,KHR_materials_openpbr:Pt,KHR_materials_sheen:it,KHR_materials_specular:xt,KHR_materials_transmission:mt,KHR_materials_unlit:Mt,KHR_materials_volume:wt,KHR_materials_volume_scatter:Vt,KHR_texture_basisu:qt,KHR_texture_transform:zt,RegisterEXT_lights_area:Re,RegisterEXT_mesh_gpu_instancing:Z,RegisterEXT_texture_avif:ss,RegisterEXT_texture_webp:Zt,RegisterKHR_draco_mesh_compression:re,RegisterKHR_interactivity:xe,RegisterKHR_lights_punctual:ce,RegisterKHR_materials_anisotropy:ve,RegisterKHR_materials_clearcoat:Ve,RegisterKHR_materials_coat:Oe,RegisterKHR_materials_diffuse_roughness:Ot,RegisterKHR_materials_diffuse_transmission:Le,RegisterKHR_materials_dispersion:De,RegisterKHR_materials_emissive_strength:Qe,RegisterKHR_materials_fuzz:dt,RegisterKHR_materials_ior:Je,RegisterKHR_materials_iridescence:rt,RegisterKHR_materials_openpbr:Wt,RegisterKHR_materials_sheen:at,RegisterKHR_materials_specular:_t,RegisterKHR_materials_transmission:yt,RegisterKHR_materials_unlit:bt,RegisterKHR_materials_volume:Ct,RegisterKHR_materials_volume_scatter:St,RegisterKHR_texture_basisu:Xt,RegisterKHR_texture_transform:Gt,_ConvertToGLTFPBRMetallicRoughness:d,_SolveMetallic:h};const is="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==is){is.BABYLON=is.BABYLON||{};const e=is.BABYLON;e.GLTF2=e.GLTF2||{},e.GLTF2.Exporter=e.GLTF2.Exporter||{},e.GLTF2.Exporter.Extensions=e.GLTF2.Exporter.Extensions||{};const t=[];for(const r in s)e[r]=s[r],t.push(r);for(const s in n)e[s]=n[s],t.push(s);for(const s in $)e[s]=$[s],t.push(s);for(const s in rs)e.GLTF2.Exporter.Extensions[s]=rs[s],t.push(s);for(const s in ns)t.indexOf(s)>-1||(e.GLTF2.Exporter[s]=ns[s])}e.EXT_lights_area=Te,e.EXT_mesh_gpu_instancing=j,e.EXT_texture_avif=es,e.EXT_texture_webp=jt,e.GLTF2Export=q,e.GLTFData=r,e.KHR_draco_mesh_compression=te,e.KHR_interactivity=de,e.KHR_lights_punctual=ue,e.KHR_materials_anisotropy=Ae,e.KHR_materials_clearcoat=Ce,e.KHR_materials_coat=Ne,e.KHR_materials_diffuse_roughness=Nt,e.KHR_materials_diffuse_transmission=He,e.KHR_materials_dispersion=ke,e.KHR_materials_emissive_strength=$e,e.KHR_materials_fuzz=ct,e.KHR_materials_ior=Ye,e.KHR_materials_iridescence=tt,e.KHR_materials_openpbr=Pt,e.KHR_materials_sheen=it,e.KHR_materials_specular=xt,e.KHR_materials_transmission=mt,e.KHR_materials_unlit=Mt,e.KHR_materials_volume=wt,e.KHR_materials_volume_scatter=Vt,e.KHR_texture_basisu=qt,e.KHR_texture_transform=zt,e.RegisterEXT_lights_area=Re,e.RegisterEXT_mesh_gpu_instancing=Z,e.RegisterEXT_texture_avif=ss,e.RegisterEXT_texture_webp=Zt,e.RegisterKHR_draco_mesh_compression=re,e.RegisterKHR_interactivity=xe,e.RegisterKHR_lights_punctual=ce,e.RegisterKHR_materials_anisotropy=ve,e.RegisterKHR_materials_clearcoat=Ve,e.RegisterKHR_materials_coat=Oe,e.RegisterKHR_materials_diffuse_roughness=Ot,e.RegisterKHR_materials_diffuse_transmission=Le,e.RegisterKHR_materials_dispersion=De,e.RegisterKHR_materials_emissive_strength=Qe,e.RegisterKHR_materials_fuzz=dt,e.RegisterKHR_materials_ior=Je,e.RegisterKHR_materials_iridescence=rt,e.RegisterKHR_materials_openpbr=Wt,e.RegisterKHR_materials_sheen=at,e.RegisterKHR_materials_specular=_t,e.RegisterKHR_materials_transmission=yt,e.RegisterKHR_materials_unlit=bt,e.RegisterKHR_materials_volume=Ct,e.RegisterKHR_materials_volume_scatter=St,e.RegisterKHR_texture_basisu=Xt,e.RegisterKHR_texture_transform=Gt,e._ConvertToGLTFPBRMetallicRoughness=d,e._SolveMetallic=h,e.__IGLTFExporterExtension=0});
2
2
  //# sourceMappingURL=babylon.glTF2Serializer.min.js.map