babylonjs-serializers 9.5.0 → 9.5.2

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