babylonjs-serializers 8.31.0 → 8.31.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&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.SERIALIZERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(e=>(()=>{"use strict";var t={597:t=>{t.exports=e}},r={};function n(e){var s=r[e];if(void 0!==s)return s.exports;var o=r[e]={exports:{}};return t[e](o,o.exports,n),o.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};n.d(s,{default:()=>lt});var o={};n.r(o),n.d(o,{__IGLTFExporterExtension:()=>f});var i={};n.r(i),n.d(i,{GLTFData:()=>h});var a={};n.r(a),n.d(a,{GLTF2Export:()=>ne});var u={};n.r(u),n.d(u,{EXT_mesh_gpu_instancing:()=>oe,EXT_texture_avif:()=>ot,EXT_texture_webp:()=>nt,KHR_draco_mesh_compression:()=>ae,KHR_lights_punctual:()=>pe,KHR_materials_anisotropy:()=>_e,KHR_materials_clearcoat:()=>me,KHR_materials_clearcoat_anisotropy:()=>Ce,KHR_materials_clearcoat_color:()=>we,KHR_materials_clearcoat_darkening:()=>ve,KHR_materials_clearcoat_ior:()=>be,KHR_materials_diffuse_roughness:()=>Ze,KHR_materials_diffuse_transmission:()=>Be,KHR_materials_dispersion:()=>Fe,KHR_materials_emissive_strength:()=>Ne,KHR_materials_ior:()=>Pe,KHR_materials_iridescence:()=>Ke,KHR_materials_sheen:()=>ke,KHR_materials_specular:()=>Ge,KHR_materials_transmission:()=>qe,KHR_materials_unlit:()=>je,KHR_materials_volume:()=>Qe,KHR_texture_basisu:()=>tt,KHR_texture_transform:()=>$e});var c={};n.r(c),n.d(c,{EXT_mesh_gpu_instancing:()=>oe,EXT_texture_avif:()=>ot,EXT_texture_webp:()=>nt,GLTF2Export:()=>ne,GLTFData:()=>h,KHR_draco_mesh_compression:()=>ae,KHR_lights_punctual:()=>pe,KHR_materials_anisotropy:()=>_e,KHR_materials_clearcoat:()=>me,KHR_materials_clearcoat_anisotropy:()=>Ce,KHR_materials_clearcoat_color:()=>we,KHR_materials_clearcoat_darkening:()=>ve,KHR_materials_clearcoat_ior:()=>be,KHR_materials_diffuse_roughness:()=>Ze,KHR_materials_diffuse_transmission:()=>Be,KHR_materials_dispersion:()=>Fe,KHR_materials_emissive_strength:()=>Ne,KHR_materials_ior:()=>Pe,KHR_materials_iridescence:()=>Ke,KHR_materials_sheen:()=>ke,KHR_materials_specular:()=>Ge,KHR_materials_transmission:()=>qe,KHR_materials_unlit:()=>je,KHR_materials_volume:()=>Qe,KHR_texture_basisu:()=>tt,KHR_texture_transform:()=>$e,_ConvertToGLTFPBRMetallicRoughness:()=>E,_SolveMetallic:()=>w});var l={};n.r(l),n.d(l,{EXT_mesh_gpu_instancing:()=>oe,EXT_texture_avif:()=>ot,EXT_texture_webp:()=>nt,GLTF2Export:()=>ne,GLTFData:()=>h,KHR_draco_mesh_compression:()=>ae,KHR_lights_punctual:()=>pe,KHR_materials_anisotropy:()=>_e,KHR_materials_clearcoat:()=>me,KHR_materials_clearcoat_anisotropy:()=>Ce,KHR_materials_clearcoat_color:()=>we,KHR_materials_clearcoat_darkening:()=>ve,KHR_materials_clearcoat_ior:()=>be,KHR_materials_diffuse_roughness:()=>Ze,KHR_materials_diffuse_transmission:()=>Be,KHR_materials_dispersion:()=>Fe,KHR_materials_emissive_strength:()=>Ne,KHR_materials_ior:()=>Pe,KHR_materials_iridescence:()=>Ke,KHR_materials_sheen:()=>ke,KHR_materials_specular:()=>Ge,KHR_materials_transmission:()=>qe,KHR_materials_unlit:()=>je,KHR_materials_volume:()=>Qe,KHR_texture_basisu:()=>tt,KHR_texture_transform:()=>$e,_ConvertToGLTFPBRMetallicRoughness:()=>E,_SolveMetallic:()=>w,__IGLTFExporterExtension:()=>f});var f=0,p=n(597),h=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 t=this.files[e],r=new Blob([t],{type:(0,p.GetMimeType)(e)});p.Tools.Download(r,e)}},e}(),d=function(){return d=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},d.apply(this,arguments)};function g(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 _(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 x(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 m=1e-6,y=new p.Color3(.04,.04,.04),v=1024,T=p.Color3.White(),b=p.Color3.BlackReadOnly;function A(e){return g(this,void 0,void 0,(function(){var t,r,n,s;return _(this,(function(o){switch(o.label){case 0:return(t=e.getInternalTexture())&&1===t.source?t.invertY?[2,null]:(r=t._buffer,s=e.mimeType,r?[3,2]:[4,p.Tools.LoadFileAsync(t.url)]):[2,null];case 1:return n=o.sent(),s=(0,p.GetMimeType)(t.url)||s,[3,10];case 2:return ArrayBuffer.isView(r)?(n=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),[3,10]):[3,3];case 3:return r instanceof ArrayBuffer?(n=r,[3,10]):[3,4];case 4:return r instanceof Blob?[4,r.arrayBuffer()]:[3,6];case 5:return n=o.sent(),s=r.type||s,[3,10];case 6:return"string"!=typeof r?[3,8]:[4,p.Tools.LoadFileAsync(r)];case 7:return n=o.sent(),s=(0,p.GetMimeType)(r)||s,[3,10];case 8:return"undefined"!=typeof HTMLImageElement&&r instanceof HTMLImageElement?[4,p.Tools.LoadFileAsync(r.src)]:[3,10];case 9:n=o.sent(),s=(0,p.GetMimeType)(r.src)||s,o.label=10;case 10:return n&&s?[2,{data:n,mimeType:s}]:[2,null]}}))}))}function w(e,t,r){if(t<y.r)return 0;var n=y.r,s=e*r/(1-y.r)+t-2*y.r,o=s*s-4*n*(y.r-t);return p.Scalar.Clamp((-s+Math.sqrt(o))/(2*n),0,1)}function E(e){var t=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),r=e.alpha,n=p.Scalar.Clamp(e.specularPower,0,v),s=(0,p.SpecularPowerToRoughness)(n);return{baseColorFactor:[t.r,t.g,t.b,r],metallicFactor:0,roughnessFactor:s}}function M(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function R(e,t,r){for(var n=new Uint8Array(e*t*4),s=0;s<n.length;s+=4)n[s]=n[s+1]=n[s+2]=n[s+3]=255;return p.RawTexture.CreateRGBATexture(n,e,t,r)}function C(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 S=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))&&void 0!==t?t:null},e.prototype.exportStandardMaterialAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,s,o,i,a,u,c;return _(this,(function(l){switch(l.label){case 0:return r=E(e),n={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||p.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),t?(s=[],(o=e.diffuseTexture)&&s.push(this.exportTextureAsync(o).then((function(e){e&&(r.baseColorTexture=e)}))),(i=e.bumpTexture)&&s.push(this.exportTextureAsync(i).then((function(e){e&&(n.normalTexture=e,1!==i.level&&(n.normalTexture.scale=i.level))}))),(a=e.emissiveTexture)&&(n.emissiveFactor=[1,1,1],s.push(this.exportTextureAsync(a).then((function(e){e&&(n.emissiveTexture=e)})))),(u=e.ambientTexture)&&s.push(this.exportTextureAsync(u).then((function(e){if(e){var t={index:e.index};n.occlusionTexture=t}}))),s.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(s)]):[3,2]):[3,2];case 1:l.sent(),l.label=2;case 2:return(e.alpha<1||e.opacityTexture)&&(e.alphaMode===p.Constants.ALPHA_COMBINE?n.alphaMode="BLEND":p.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(b,m)&&(n.emissiveFactor=e.emissiveColor.asArray()),n.pbrMetallicRoughness=r,M(n,e),[4,this._finishMaterialAsync(n,e)];case 3:return l.sent(),(c=this._exporter._materials).push(n),[2,c.length-1]}}))}))},e.prototype._finishMaterialAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,s,o,i;return _(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._getImageDataAsync=function(e,t,r,n){return g(this,void 0,void 0,(function(){return _(this,(function(s){switch(s.label){case 0:return[4,p.DumpTools.DumpDataAsync(t,r,e,n,void 0,!1,!0)];case 1:return[2,s.sent()]}}))}))},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,s,o=e?e.getSize():{width:0,height:0},i=t?t.getSize():{width:0,height:0};return o.width<i.width?(n=e&&e instanceof p.Texture?p.TextureTools.CreateResizedCopy(e,i.width,i.height,!0):R(i.width,i.height,r),s=t):o.width>i.width?(s=t&&t instanceof p.Texture?p.TextureTools.CreateResizedCopy(t,o.width,o.height,!0):R(o.width,o.height,r),n=e):(n=e,s=t),{texture1:n,texture2:s}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,r,n){return g(this,void 0,void 0,(function(){var s,o,i,a,u,c,l,f,h,d,g,x,y,v,b,A,w,E,M,R,S,V,B,I,F,U,N,O,P,L,K;return _(this,(function(_){switch(_.label){case 0:return s=new Array,e||t?[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,_.sent()];case 2:return(o=e?e.getScene():t?t.getScene():null)?(i=this._resizeTexturesToSameDimensions(e,t,o),a=null===(K=i.texture1)||void 0===K?void 0:K.getSize(),u=void 0,c=void 0,l=a.width,f=a.height,[4,i.texture1.readPixels()]):[3,12];case 3:return h=_.sent(),[4,i.texture2.readPixels()];case 4:return d=_.sent(),h?(u=C(h),[3,7]):[3,5];case 5:return[4,Promise.reject("Failed to retrieve pixels from diffuse texture!")];case 7:return d?(c=C(d),[3,10]):[3,8];case 8:return[4,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];case 10:for(g=c.byteLength,x=new Uint8Array(g),y=new Uint8Array(g),v=new p.Color3(0,0,0),b=0,A=0,U=0;U<f;++U)for(N=0;N<l;++N)w=4*(l*U+N),E=new p.Color3(u[w],u[w+1],u[w+2]).toLinearSpace(o.getEngine().useExactSrgbConversions).multiply(r.diffuseColor),M=new p.Color3(c[w],c[w+1],c[w+2]).toLinearSpace(o.getEngine().useExactSrgbConversions).multiply(r.specularColor),R=c[w+3]*r.glossiness,S={diffuseColor:E,specularColor:M,glossiness:R},V=this._convertSpecularGlossinessToMetallicRoughness(S),v.r=Math.max(v.r,V.baseColor.r),v.g=Math.max(v.g,V.baseColor.g),v.b=Math.max(v.b,V.baseColor.b),b=Math.max(b,V.metallic),A=Math.max(A,V.roughness),y[w]=255*V.baseColor.r,y[w+1]=255*V.baseColor.g,y[w+2]=255*V.baseColor.b,y[w+3]=i.texture1.hasAlpha?255*u[w+3]:255,x[w]=0,x[w+1]=255*V.roughness,x[w+2]=255*V.metallic,x[w+3]=255;for(B={baseColor:v,metallic:b,roughness:A},I=!1,F=!1,U=0;U<f;++U)for(N=0;N<l;++N)y[O=4*(l*U+N)]/=B.baseColor.r>m?B.baseColor.r:1,y[O+1]/=B.baseColor.g>m?B.baseColor.g:1,y[O+2]/=B.baseColor.b>m?B.baseColor.b:1,P=p.Color3.FromInts(y[O],y[O+1],y[O+2]),L=P.toGammaSpace(o.getEngine().useExactSrgbConversions),y[O]=255*L.r,y[O+1]=255*L.g,y[O+2]=255*L.b,L.equalsWithEpsilon(T,m)||(F=!0),x[O+1]/=B.roughness>m?B.roughness:1,x[O+2]/=B.metallic>m?B.metallic:1,p.Color3.FromInts(255,x[O+1],x[O+2]).equalsWithEpsilon(T,m)||(I=!0);return I&&s.push(this._getImageDataAsync(x,l,f,n).then((function(e){B.metallicRoughnessTextureData=e}))),F&&s.push(this._getImageDataAsync(y,l,f,n).then((function(e){B.baseColorTextureData=e}))),[4,Promise.all(s).then((function(){return B}))];case 12:return[4,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}}))}))},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var t=this._getPerceivedBrightness(e.diffuseColor),r=this._getPerceivedBrightness(e.specularColor),n=1-this._getMaxComponent(e.specularColor),s=w(t,r,n),o=e.diffuseColor.scale(n/(1-y.r)/Math.max(1-s,m)),i=e.specularColor.subtract(y.scale(1-s)).scale(1/Math.max(s,m)),a=p.Color3.Lerp(o,i,s*s);return{baseColor:a=a.clampToRef(0,1,a),metallic:s,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,t,r,n,s,o,i,a,u){return g(this,void 0,void 0,(function(){var o,c;return _(this,(function(l){switch(l.label){case 0:return o=[],c={baseColor:e,metallic:t,roughness:r},u&&(n&&o.push(this.exportTextureAsync(n).then((function(e){e&&(a.baseColorTexture=e)}))),s&&o.push(this.exportTextureAsync(s).then((function(e){e&&(a.metallicRoughnessTexture=e)})))),o.length>0?(this._exporter._materialNeedsUVsSet.add(i),[4,Promise.all(o)]):[3,2];case 1:l.sent(),l.label=2;case 2:return[2,c]}}))}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof p.Texture))return t;var r=this._getGLTFTextureWrapMode(e.wrapU);10497!==r&&(t.wrapS=r);var n=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==n&&(t.wrapT=n),e.samplingMode){case p.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case p.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case p.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case p.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case p.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case p.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case p.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case p.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case p.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case p.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case p.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case p.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case p.Texture.WRAP_ADDRESSMODE:return 10497;case p.Texture.CLAMP_ADDRESSMODE:return 33071;case p.Texture.MIRROR_ADDRESSMODE:return 33648;default:return p.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,s,o,i,a,u,c,l,f;return _(this,(function(p){switch(p.label){case 0:return n="image/png",s={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},o=e._albedoTexture,i=e._reflectivityTexture,a=e._useMicroSurfaceFromReflectivityMapAlpha,!i||a?[3,2]:[4,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")];case 1:return[2,p.sent()];case 2:return(o||i)&&r?(this._exporter._materialNeedsUVsSet.add(e),u=this._exportTextureSampler(o||i),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(o,i,s,n)]):[3,4];case 3:return c=p.sent(),l=this._exporter._textures,c.baseColorTextureData&&(f=this._exportImage("baseColor".concat(l.length),n,c.baseColorTextureData),t.baseColorTexture=this._exportTextureInfo(f,u,null==o?void 0:o.coordinatesIndex)),c.metallicRoughnessTextureData&&(f=this._exportImage("metallicRoughness".concat(l.length),n,c.metallicRoughnessTextureData),t.metallicRoughnessTexture=this._exportTextureInfo(f,u,null==i?void 0:i.coordinatesIndex)),[2,c];case 4:return[2,this._convertSpecularGlossinessToMetallicRoughness(s)]}}))}))},e.prototype.exportPBRMaterialAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,s,o,i,a,u,c;return _(this,(function(l){switch(l.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 u=l.sent(),[3,4];case 2:return[4,this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,r,t)];case 3:u=l.sent(),l.label=4;case 4:return a=u,[4,this._setMetallicRoughnessPbrMaterialAsync(a,e,n,r,t)];case 5:return l.sent(),[4,this._finishMaterialAsync(n,e)];case 6:return l.sent(),(c=this._exporter._materials).push(n),[2,c.length-1]}}))}))},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,t,r,n,s){return g(this,void 0,void 0,(function(){var o,i,a,u,c;return _(this,(function(l){switch(l.label){case 0:return M(r,t),e.baseColor.equalsWithEpsilon(T,m)&&p.Scalar.WithinEpsilon(t.alpha,1,m)||(n.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,t.alpha]),null!=e.metallic&&1!==e.metallic&&(n.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(n.roughnessFactor=e.roughness),null==t.backFaceCulling||t.backFaceCulling||(t._twoSidedLighting||p.Tools.Warn(t.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),s?(o=[],(i=t instanceof p.PBRBaseMaterial?t._bumpTexture:t.geometryNormalTexture)&&o.push(this.exportTextureAsync(i).then((function(e){e&&(r.normalTexture=e,1!==i.level&&(r.normalTexture.scale=i.level))}))),(a=t instanceof p.PBRBaseMaterial?t._ambientTexture:t.ambientOcclusionTexture)&&o.push(this.exportTextureAsync(a).then((function(e){if(e){var n={index:e.index,texCoord:e.texCoord,extensions:e.extensions};r.occlusionTexture=n,t instanceof p.PBRBaseMaterial?n.strength=t._ambientTextureStrength:n.strength=t.ambientOcclusionTexture.level}}))),(u=t instanceof p.PBRBaseMaterial?t._emissiveTexture:t.emissionColorTexture)&&o.push(this.exportTextureAsync(u).then((function(e){e&&(r.emissiveTexture=e)}))),o.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(o)]):[3,2]):[3,2];case 1:l.sent(),l.label=2;case 2:return(c=t instanceof p.PBRBaseMaterial?t._emissiveColor:t.emissionColor).equalsWithEpsilon(b,m)||(r.emissiveFactor=c.asArray()),r.pbrMetallicRoughness=n,[2]}}))}))},e.prototype.exportOpenPBRMaterialAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,s,o,i,a;return _(this,(function(u){switch(u.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=u.sent(),[4,this._setMetallicRoughnessPbrMaterialAsync(i,e,n,r,t)];case 2:return u.sent(),[4,this._finishMaterialAsync(n,e)];case 3:return u.sent(),(a=this._exporter._materials).push(n),[2,a.length-1]}}))}))},e.prototype.exportTextureAsync=function(e){return g(this,void 0,void 0,(function(){var t,r,n;return _(this,(function(s){switch(s.label){case 0:return(t=this._textureMap.get(e))?[2,t]:(r=this._exportTextureSampler(e),[4,this._exportTextureImageAsync(e)]);case 1:return n=s.sent(),t=this._exportTextureInfo(n,r,e.coordinatesIndex),this._textureMap.set(e,t),this._exporter._extensionsPostExportTextures("exporter",t,e),[2,t]}}))}))},e.prototype._exportTextureImageAsync=function(e){return g(this,void 0,void 0,(function(){var t,r,n,s,o,i=this;return _(this,(function(a){switch(a.label){case 0:return t=null!==(o=e.mimeType)&&void 0!==o?o:"none",r=this._internalTextureToImage,n=e.getInternalTexture().uniqueId,r[n]=r[n]||{},void 0===(s=r[n][t])&&(s=g(i,void 0,void 0,(function(){var r,n,s,o,i;return _(this,(function(a){switch(a.label){case 0:return[4,A(e)];case 1:if((r=a.sent())&&("none"===t||r.mimeType===t))return[2,this._exportImage(e.name,r.mimeType,r.data)];if(n="image/png","none"!==t)switch(t){case"image/jpeg":case"image/png":case"image/webp":n=t;break;default:p.Tools.Warn("Unsupported media type: ".concat(t,". Exporting texture as PNG."))}return s=e.getSize(),[4,(0,p.GetTextureDataAsync)(e)];case 2:return o=a.sent(),[4,this._getImageDataAsync(o,s.width,s.height,n)];case 3:return i=a.sent(),[2,this._exportImage(e.name,n,i)]}}))})),r[n][t]=s),[4,s];case 1:return[2,a.sent()]}}))}))},e.prototype._exportImage=function(e,t,r){var n,s=this._exporter._images;if(this._exporter._shouldUseGlb){n={name:e,mimeType:t,bufferView:void 0};var o=this._exporter._bufferManager.createBufferView(new Uint8Array(r));this._exporter._bufferManager.setBufferView(n,o)}else{var i=e.replace(/\.\/|\/|\.\\|\\/g,"_"),a=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"}}(t),u=i+a;s.some((function(e){return e.uri===u}))&&(u="".concat(i,"_").concat(p.Tools.RandomId()).concat(a)),n={name:e,uri:u},this._exporter._imageData[u]={data:r,mimeType:t}}return s.push(n),s.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=p.Matrix.Compose(new p.Vector3(-1,1,1),p.Quaternion.Identity(),p.Vector3.Zero());function B(e,t){if(!(e instanceof p.TransformNode))return!1;if(t){if(!e.getWorldMatrix().equalsWithEpsilon(p.Matrix.IdentityReadOnly,p.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(V,p.TmpVectors.Matrix[0]).equalsWithEpsilon(p.Matrix.IdentityReadOnly,p.Epsilon))return!1;return!(e instanceof p.AbstractMesh&&e.geometry)}var I=p.Vector3.ZeroReadOnly,F=p.Quaternion.Identity(),U=p.Vector3.OneReadOnly,N=new p.Vector3(-1,1,1);function O(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 P(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 L(e){switch(e){case p.VertexBuffer.PositionKind:case p.VertexBuffer.NormalKind:case p.VertexBuffer.TangentKind:case p.VertexBuffer.ColorKind:case p.VertexBuffer.MatricesIndicesKind:case p.VertexBuffer.MatricesIndicesExtraKind:case p.VertexBuffer.MatricesWeightsKind:case p.VertexBuffer.MatricesWeightsExtraKind:case p.VertexBuffer.UVKind:case p.VertexBuffer.UV2Kind:case p.VertexBuffer.UV3Kind:case p.VertexBuffer.UV4Kind:case p.VertexBuffer.UV5Kind:case p.VertexBuffer.UV6Kind:return!0}return!1}function K(e){switch(e){case p.Material.TriangleFillMode:return 4;case p.Material.TriangleStripDrawMode:return 5;case p.Material.TriangleFanDrawMode:return 6;case p.Material.PointListDrawMode:case p.Material.PointFillMode:return 0;case p.Material.LineLoopDrawMode:return 2;case p.Material.LineListDrawMode:return 1;case p.Material.LineStripDrawMode:return 3}throw new Error("Unknown fill mode: ".concat(e))}function D(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 k(e){return e.x*=-1,e}function H(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 G(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function W(e,t){var r=p.Vector3.FromArrayToRef(t.translation||[0,0,0],0,p.TmpVectors.Vector3[0]),n=p.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,p.TmpVectors.Quaternion[0]),s=p.Matrix.ComposeToRef(U,n,r,p.TmpVectors.Matrix[0]),o=p.Vector3.FromArrayToRef(e.translation||[0,0,0],0,p.TmpVectors.Vector3[2]),i=p.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,p.TmpVectors.Quaternion[1]),a=p.Matrix.ComposeToRef(U,i,o,p.TmpVectors.Matrix[1]);s.multiplyToRef(a,a),a.decompose(void 0,n,r),r.equalsWithEpsilon(I,p.Epsilon)?delete t.translation:t.translation=r.asArray(),n.equalsWithEpsilon(F,p.Epsilon)?delete t.rotation:t.rotation=n.asArray(),t.scale&&delete t.scale}function q(e,t){if(!(t instanceof p.TransformNode))return!1;if(1!==t.getChildren().length||0!==e.getChildren().length||e.parent!==t)return!1;var r=e.getScene(),n=e instanceof p.TargetCamera&&!r.useRightHandedSystem?N:U;return!!t.scaling.equalsWithEpsilon(n,p.Epsilon)||(p.Logger.Warn("Cannot collapse node ".concat(e.name," into parent node ").concat(t.name," with modified scaling.")),!1)}function z(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)&&j(i,a)||i===a)&&delete e[o]}return e}function j(e,t){return e.length===t.length&&e.every((function(e,r){return e===t[r]}))}var X=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)}]]),Q=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=X.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 Y(e){return e%4==0?4:e%2==0?2:1}var Z,J=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 Q(t),n=0,s=Array.from(this._bufferViewToData.keys()).sort((function(e,t){return Y(t.byteLength)-Y(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"}(Z||(Z={}));var $=function(){function e(){}return e._IsTransformable=function(e){return e&&(e instanceof p.TransformNode||e instanceof p.Camera||e instanceof p.Light)},e._CreateNodeAnimation=function(t,r,n,s,o){if(this._IsTransformable(t)){var i=[],a=[],u=r.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,n,s),f=l.interpolationType,h=l.shouldBakeAnimation;if(h?e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,o,i,a,c,s):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(t,r,n,i,a,s):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(t,r,n,i,a,s):e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,o,i,a,c,s),i.length&&a.length)return{inputs:i,outputs:a,samplerInterpolation:f,inputsMin:h?c.min:p.Tools.FloatRound(c.min/r.framePerSecond),inputsMax:h?c.max:p.Tools.FloatRound(c.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,s=e.targetProperty.split(".");switch(s[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":r="VEC4",t="rotation";break;case"rotationQuaternion":r="VEC4",n=!0,t="rotation";break;case"influence":r="SCALAR",t="weights";break;default:p.Tools.Error("Unsupported animatable property ".concat(s[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(p.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,f){var p;if(e._IsTransformable(t)&&t.animations)for(var h=0,d=t.animations;h<d.length;h++){var g=d[h];if(!f||f(g)){var _=e._DeduceAnimationInfo(g);_&&(p={name:g.name,samplers:[],channels:[]},e._AddAnimation("".concat(g.name),g.hasRunningRuntimeAnimations?r:p,t,g,_.dataAccessorType,_.animationChannelTargetPath,s,i,a,u,_.useQuaternion,c,l),p.samplers.length&&p.channels.length&&n.push(p))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,s,o,i,a,u,c,l,f){var h;if(t instanceof p.Mesh){var d=t.morphTargetManager;if(d)for(var g=0;g<d.numTargets;++g)for(var _=0,x=d.getTarget(g).animations;_<x.length;_++){var m=x[_];if(!f||f(m)){for(var y=new p.Animation("".concat(m.name),"influence",m.framePerSecond,m.dataType,m.loopMode,m.enableBlending),v=[],T=m.getKeys(),b=0;b<T.length;++b)for(var A=T[b],w=0;w<d.numTargets;++w)w==g?v.push(A):v.push({frame:A.frame,value:0});y.setKeys(v);var E=e._DeduceAnimationInfo(y);E&&(h={name:y.name,samplers:[],channels:[]},e._AddAnimation(m.name,m.hasRunningRuntimeAnimations?r:h,t,y,E.dataAccessorType,E.animationChannelTargetPath,s,i,a,u,E.useQuaternion,c,l,d.numTargets),h.samplers.length&&h.channels.length&&n.push(h))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,s,o,i,a,u,c){var l,f;if(t.animationGroups)for(var h=t.animationGroups,d=function(h){var d=new Map,_=new Map,x=new Set,m=h.to-h.from;f={name:h.name,channels:[],samplers:[]};for(var y=function(r){var m=h.targetedAnimations[r],y=m.target,v=m.animation;if(c&&!c(v))return"continue";var T=u.has(y);if(g._IsTransformable(y)||1===y.length&&g._IsTransformable(y[0])){if(A=e._DeduceAnimationInfo(m.animation)){var b=g._IsTransformable(y)?y:g._IsTransformable(y[0])?y[0]:null;b&&e._AddAnimation("".concat(v.name),f,b,v,A.dataAccessorType,A.animationChannelTargetPath,n,s,o,i,A.useQuaternion,a,T)}}else if(y instanceof p.MorphTarget||1===y.length&&y[0]instanceof p.MorphTarget){var A;if(A=e._DeduceAnimationInfo(m.animation)){var w=y instanceof p.MorphTarget?y:y[0];if(w){var E=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===w)return!0;return!1}));if(E){var M=t.meshes.find((function(e){return e.morphTargetManager===E}));M&&(d.has(M)||d.set(M,new Map),null===(l=d.get(M))||void 0===l||l.set(w,v),x.add(M),_.set(M,v))}}}}},v=0;v<h.targetedAnimations.length;++v)y(v);x.forEach((function(t){for(var r=t.morphTargetManager,u=null,c=[],l=_.get(t).getKeys(),g=l.length,x=0;x<g;++x)for(var y=0;y<r.numTargets;++y){var v=r.getTarget(y),T=d.get(t);if(T){var b=T.get(v);b?(u||(u=new p.Animation("".concat(h.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,p.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[x])):c.push({frame:h.from+m/g*x,value:v.influence,inTangent:l[0].inTangent?0:void 0,outTangent:l[0].outTangent?0:void 0})}}u.setKeys(c);var A=e._DeduceAnimationInfo(u);A&&e._AddAnimation("".concat(h.name,"_").concat(t.name,"_MorphWeightAnimation"),f,t,u,A.dataAccessorType,A.animationChannelTargetPath,n,s,o,i,A.useQuaternion,a,!1,null==r?void 0:r.numTargets)})),f.channels.length&&f.samplers.length&&r.push(f)},g=this,_=0,x=h;_<x.length;_++)d(x[_])},e._AddAnimation=function(t,r,n,s,o,i,a,u,c,l,f,h,d,g){var _,x,m,y,v,T,b=e._CreateNodeAnimation(n,s,i,f,h);if(b){if(g){for(var A=0,w=0,E=[];b.inputs.length>0;)w=b.inputs.shift(),A%g==0&&E.push(w),A++;b.inputs=E}var M=a.get(n),R=new Float32Array(b.inputs);_=u.createBufferView(R),x=u.createAccessor(_,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(x),m=l.length-1;var C=new p.Quaternion,S=new p.Vector3,V=new p.Vector3,B=n instanceof p.Camera,I=P(o),F=new Float32Array(b.outputs.length*I);b.outputs.forEach((function(e,t){var r=e;switch(i){case"translation":d&&(p.Vector3.FromArrayToRef(e,0,V),k(V),V.toArray(r));break;case"rotation":4===e.length?p.Quaternion.FromArrayToRef(e,0,C):(r=new Array(4),p.Vector3.FromArrayToRef(e,0,S),p.Quaternion.FromEulerVectorToRef(S,C)),d&&(H(C),B&&G(C)),C.toArray(r)}F.set(r,t*I)})),_=u.createBufferView(F),x=u.createAccessor(_,o,5126,b.outputs.length),l.push(x),y=l.length-1,v={interpolation:b.samplerInterpolation,input:m,output:y},r.samplers.push(v),T={sampler:r.samplers.length-1,target:{node:M,path:i}},r.channels.push(T)}},e._CreateBakedAnimation=function(t,r,n,s,o,i,a,u,c,l,f){var h,d,g=p.Quaternion.Identity(),_=null,x=null,m=null,y=null,v=null,T=null;l.min=p.Tools.FloatRound(s/i);for(var b=r.getKeys(),A=0,w=b.length;A<w;++A){if(T=null,m=b[A],A+1<w)if(y=b[A+1],m.value.equals&&m.value.equals(y.value)||m.value===y.value){if(0!==A)continue;T=m.frame}else T=y.frame;else{if(v=b[A-1],m.value.equals&&m.value.equals(v.value)||m.value===v.value)continue;T=o}if(T)for(var E=m.frame;E<=T;E+=a)if((d=p.Tools.FloatRound(E/i))!==_){_=d,x=d;var M={key:0,repeatCount:0,loopMode:r.loopMode};h=r._interpolate(E,M),e._SetInterpolatedValue(t,h,d,r,n,g,u,c,f)}}x&&(l.max=x)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,s,o){var i=e._GetBasePositionRotationOrScale(r,s,o),a=n.targetProperty.split("."),u=a?a[1]:"",c=o?p.Quaternion.FromArray(i).normalize():p.Vector3.FromArray(i);switch(u){case"x":case"y":case"z":c[u]=t;break;case"w":c.w=t;break;default:p.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return c},e._SetInterpolatedValue=function(e,t,r,n,s,o,i,a,u){var c;i.push(r),"weights"!==s?(n.dataType===p.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,s,u)),"rotation"===s?(u?o=t:(c=t,p.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,o)),a.push(o.asArray())):(c=t,a.push(c.asArray()))):a.push([t])},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(Z.INTANGENT,o,n,"CUBICSPLINE",a,i),e._AddKeyframeValue(a,r,o,n,t,i),e._AddSplineTangent(Z.OUTTANGENT,o,n,"CUBICSPLINE",a,i)}))},e._GetBasePositionRotationOrScale=function(e,t,r){var n;if("rotation"===t)if(r){var s=e.rotationQuaternion;n=(null!=s?s:p.Quaternion.Identity()).asArray()}else{var o=e.rotation;n=(null!=o?o:p.Vector3.Zero()).asArray()}else if("translation"===t){var i=e.position;n=(null!=i?i:p.Vector3.Zero()).asArray()}else{var a=e.scaling;n=(null!=a?a:p.Vector3.One()).asArray()}return n},e._AddKeyframeValue=function(e,t,r,n,s,o){var i,a=t.dataType;if(a===p.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===n){var c=p.Vector3.FromArray(u);u=p.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}r.push(u)}else if(a===p.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(i=this._ConvertFactorToVector3OrQuaternion(e.value,s,t,n,o)){if("rotation"===n){var l=o?i:p.Quaternion.RotationYawPitchRoll(i.y,i.x,i.z).normalize();r.push(l.asArray())}r.push(i.asArray())}}else a===p.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):p.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,t,r,n,s,o){var i,a=e===Z.INTANGENT?s.inTangent:s.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(a)if(o)i=a.asArray();else{var u=a;i=p.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else i=[0,0,0,0];else i="weights"===r?a?[a]:[0]:a?a.asArray():[0,0,0];t.push(i)}},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 ee(e,t,r,n,s,o){var i={attributes:{},influence:e.influence,name:e.name},a=t.geometry;if(!a)return p.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),i;var u=o?-1:1,c=p.Vector3.Zero(),l=0;if(e.hasPositions){var f=e.getPositions(),h=a.getVerticesData(p.VertexBuffer.PositionKind);if(h){var d=new Float32Array(h.length),g=[1/0,1/0,1/0],_=[-1/0,-1/0,-1/0];l=h.length/3;for(var x=0;x<l;++x){var m=p.Vector3.FromArray(h,3*x);p.Vector3.FromArray(f,3*x).subtractToRef(m,c),c.x*=u,g[0]=Math.min(g[0],c.x),_[0]=Math.max(_[0],c.x),g[1]=Math.min(g[1],c.y),_[1]=Math.max(_[1],c.y),g[2]=Math.min(g[2],c.z),_[2]=Math.max(_[2],c.z),d[3*x]=c.x,d[3*x+1]=c.y,d[3*x+2]=c.z}var y=r.createBufferView(d,12),v=r.createAccessor(y,"VEC3",5126,f.length/3,0,{min:g,max:_});s.push(v),i.attributes.POSITION=s.length-1}else p.Tools.Warn("Morph target positions for mesh ".concat(t.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var T=e.getNormals(),b=a.getVerticesData(p.VertexBuffer.NormalKind);if(b){var A=new Float32Array(b.length);for(l=b.length/3,x=0;x<l;++x){var w=p.Vector3.FromArray(b,3*x).normalize();p.Vector3.FromArray(T,3*x).normalize().subtractToRef(w,c),A[3*x]=c.x*u,A[3*x+1]=c.y,A[3*x+2]=c.z}y=r.createBufferView(A,12),v=r.createAccessor(y,"VEC3",5126,T.length/3,0),s.push(v),i.attributes.NORMAL=s.length-1}else p.Tools.Warn("Morph target normals for mesh ".concat(t.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var E=e.getTangents(),M=a.getVerticesData(p.VertexBuffer.TangentKind);if(M){l=M.length/4;var R=new Float32Array(3*l);for(x=0;x<l;++x){var C=p.Vector3.FromArray(M,4*x);D(C);var S=p.Vector3.FromArray(E,3*x);D(S),S.subtractToRef(C,c),R[3*x]=c.x*u,R[3*x+1]=c.y,R[3*x+2]=c.z}y=r.createBufferView(R,12),v=r.createAccessor(y,"VEC3",5126,l,0),s.push(v),i.attributes.TANGENT=s.length-1}else p.Tools.Warn("Morph target tangents for mesh ".concat(t.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var V=e.getColors(),B=a.getVerticesData(p.VertexBuffer.ColorKind),I=a.getVertexBuffer(p.VertexBuffer.ColorKind);if(B&&I){var F=I.getSize();l=B.length/F;var U=new Float32Array(l*F);for(x=0;x<l;++x)if(3===F){var N=p.Vector3.FromArray(B,x*F);p.Vector3.FromArray(V,x*F).subtractToRef(N,c),U[3*x]=c.x,U[3*x+1]=c.y,U[3*x+2]=c.z}else if(4===F){var O=new p.Vector4;N=p.Vector4.FromArray(B,x*F),p.Vector4.FromArray(V,x*F).subtractToRef(N,O),U[4*x]=O.x,U[4*x+1]=O.y,U[4*x+2]=O.z,U[4*x+3]=O.w}else p.Tools.Warn("Unsupported number of components for color attribute: ".concat(F));y=r.createBufferView(U,4*F),v=r.createAccessor(y,3===F?"VEC3":"VEC4",5126,l,0),s.push(v),i.attributes.COLOR_0=s.length-1}else p.Tools.Warn("Morph target colors for mesh ".concat(t.name," were not exported. Mesh does not have colors vertex data"))}return i}var te=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}(),re=function(){function e(e,t){if(void 0===e&&(e=p.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(p.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 S(this),this._extensions={},this._bufferManager=new J,this._shouldExportNodeMap=new Map,this._nodeMap=new Map,this._materialMap=new Map,this._camerasMap=new Map,this._nodesCameraMap=new Map,this._skinMap=new Map,this._nodesSkinMap=new Map,this._materialNeedsUVsSet=new Set,!e)throw new Error("No scene available to export");this._babylonScene=e,this._options=d({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"},t),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 g(s,void 0,void 0,(function(){var s;return _(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 g(this,void 0,void 0,(function(){var s,o=this;return _(this,(function(i){switch(i.label){case 0:return s=[],[4,Promise.all(e._ExtensionNames.map((function(e){return g(o,void 0,void 0,(function(){var o,i;return _(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 i.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 g(this,void 0,void 0,(function(){var t,r,n,s;return _(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(t,r,n){void 0===n&&(n=100),e.UnregisterExtension(t)&&p.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=r;var s=null!=n?n:0;e._ExtensionOrders[t]=s;for(var o=e._ExtensionNames.length,i=0;i<e._ExtensionNames.length;i++){var a=e._ExtensionNames[i];if(s<e._ExtensionOrders[a]){o=i;break}}e._ExtensionNames.splice(o,0,t)},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 g(this,void 0,void 0,(function(){var t,r,n,s,o,i,a;return _(this,(function(u){switch(u.label){case 0:return[4,this._generateBinaryAsync()];case 1:if(t=u.sent(),this._extensionsOnExporting(),r=this._generateJSON(t.byteLength,e,!0),n=new Blob([t],{type:"application/octet-stream"}),s=e+".gltf",o=e+".bin",(i=new h).files[s]=r,i.files[o]=n,this._imageData)for(a in this._imageData)i.files[a]=new Blob([this._imageData[a].data],{type:this._imageData[a].mimeType});return[2,i]}}))}))},e.prototype._generateBinaryAsync=function(){return g(this,void 0,void 0,(function(){return _(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 g(this,void 0,void 0,(function(){var t,r,n,s,o,i,a,u,c,l,f,p,d,g;return _(this,(function(_){switch(_.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=_.sent(),this._extensionsOnExporting(),r=this._generateJSON(t.byteLength),n=e+".glb",s=r.length,"undefined"!=typeof TextEncoder&&(i=new TextEncoder,o=i.encode(r),s=o.length),a=this._getPadding(s),u=this._getPadding(t.byteLength),c=28+s+a+t.byteLength+u,(l=new Q(c)).writeUInt32(1179937895),l.writeUInt32(2),l.writeUInt32(c),l.writeUInt32(s+a),l.writeUInt32(1313821514),o)l.writeTypedArray(o);else for(f="_".charCodeAt(0),d=0;d<s;++d)(p=r.charCodeAt(d))!=r.codePointAt(d)?l.writeUInt8(f):l.writeUInt8(p);for(d=0;d<a;++d)l.writeUInt8(32);for(l.writeUInt32(t.byteLength+u),l.writeUInt32(5130562),l.writeTypedArray(t),d=0;d<u;++d)l.writeUInt8(0);return(g=new h).files[n]=new Blob([l.getOutputData()],{type:"application/octet-stream"}),[2,g]}}))}))},e.prototype._setNodeTransformation=function(e,t,r){var n;if(t.getPivotPoint().equalsWithEpsilon(I,p.Epsilon)||p.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsWithEpsilon(I,p.Epsilon)){var s=p.TmpVectors.Vector3[0].copyFrom(t.position);r&&k(s),e.translation=s.asArray()}t.scaling.equalsWithEpsilon(U,p.Epsilon)||(e.scale=t.scaling.asArray());var o=(null===(n=t.rotationQuaternion)||void 0===n?void 0:n.clone())||p.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);o.equalsWithEpsilon(F,p.Epsilon)||(r&&H(o),e.rotation=o.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,r){var n=p.TmpVectors.Vector3[0],s=p.TmpVectors.Quaternion[0],o=t.getWorldMatrix();if(t.parent){var i=t.parent.getWorldMatrix().invertToRef(p.TmpVectors.Matrix[0]);o.multiplyToRef(i,p.TmpVectors.Matrix[1]).decompose(void 0,s,n)}else o.decompose(void 0,s,n);n.equalsWithEpsilon(I,p.Epsilon)||(r&&k(n),e.translation=n.asArray()),r&&H(s),this._babylonScene.useRightHandedSystem||G(s),s.equalsWithEpsilon(F,p.Epsilon)||(e.rotation=s.asArray())},e.prototype._listAvailableCameras=function(){for(var e=0,t=this._babylonScene.cameras;e<t.length;e++){var r=t[e],n={type:r.mode===p.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(r.name&&(n.name=r.name),"perspective"===n.type)n.perspective={aspectRatio:r.getEngine().getAspectRatio(r),yfov:r.fovMode===p.Camera.FOVMODE_VERTICAL_FIXED?r.fov:r.fov*r.getEngine().getAspectRatio(r),znear:r.minZ,zfar:r.maxZ};else if("orthographic"===n.type){var s=r.orthoLeft&&r.orthoRight?.5*(r.orthoRight-r.orthoLeft):.5*r.getEngine().getRenderWidth(),o=r.orthoBottom&&r.orthoTop?.5*(r.orthoTop-r.orthoBottom):.5*r.getEngine().getRenderHeight();n.orthographic={xmag:s,ymag:o,znear:r.minZ,zfar:r.maxZ}}this._camerasMap.set(r,n)}},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 t,r=function(r){if(r.bones.length<=0)return"continue";var s=n._skinMap.get(r);if(null==s)return"continue";for(var o={},i=-1,a=0;a<r.bones.length;++a){var u=r.bones[a];-1!==(f=null!==(t=u.getIndex())&&void 0!==t?t:a)&&(o[f]=u,f>i&&(i=f))}for(var c,l=[],f=0;f<=i;++f){var h=(u=o[f]).getTransformNode(),d=h?n._nodeMap.get(h):void 0;if(void 0!==d){s.joints.push(d);var g=u.getAbsoluteInverseBindMatrix().clone();e.has(h)&&(c=g,V.invertToRef(p.TmpVectors.Matrix[0]).multiplyToRef(c,c).multiplyToRef(V,c)),l.push(g)}else p.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.")}var _=n._nodesSkinMap.get(s);if(s.joints.length>0&&void 0!==_){var x=new Float32Array(16*l.length);l.forEach((function(e,t){x.set(e.m,16*t)}));var m=n._bufferManager.createBufferView(x);n._accessors.push(n._bufferManager.createAccessor(m,"MAT4",5126,l.length)),s.inverseBindMatrices=n._accessors.length-1,n._skins.push(s);for(var y=n._skins.length-1,v=0,T=_;v<T.length;v++)T[v].skin=y}},n=this,s=0,o=this._babylonScene.skeletons;s<o.length;s++)r(o[s])},e.prototype._exportSceneAsync=function(){return g(this,void 0,void 0,(function(){var e,t,r,n,s,o,i,a,u,c,l,f,p,h,d,g,x,m,y,v,T,b,A;return _(this,(function(_){switch(_.label){case 0:for(e={nodes:[]},this._babylonScene.metadata&&(t=this._options.metadataSelector(this._babylonScene.metadata))&&(e.extras=t),r=new Array,n=new Array,s=new Array,o=0,i=this._babylonScene.rootNodes;o<i.length;o++)a=i[o],this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&B(a,this._babylonScene.useRightHandedSystem)?s.push.apply(s,a.getChildren()):this._babylonScene.useRightHandedSystem?r.push(a):n.push(a);return this._listAvailableCameras(),this._listAvailableSkeletons(),u=new te(!0,!1),l=(c=(T=e.nodes).push).apply,f=[T],[4,this._exportNodesAsync(n,u)];case 1:return l.apply(c,f.concat([_.sent()])),p=new te(!1,!1),d=(h=(b=e.nodes).push).apply,g=[b],[4,this._exportNodesAsync(r,p)];case 2:return d.apply(h,g.concat([_.sent()])),x=new te(!1,!0),y=(m=(A=e.nodes).push).apply,v=[A],[4,this._exportNodesAsync(s,x)];case 3:return y.apply(m,v.concat([_.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(u.getNodesSet()),this._babylonScene.animationGroups.length&&$._CreateNodeAndMorphAnimationFromAnimationGroups(this._babylonScene,this._animations,this._nodeMap,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,u.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 g(this,void 0,void 0,(function(){var r,n,s,o;return _(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,t,r,n,s){if(this._shouldExportNode(e)&&e instanceof p.AbstractMesh&&e.geometry){var o=e.geometry.getVertexBuffers();if(o)for(var i in o)if(L(i)){var a=o[i];s.setHasVertexColorAlpha(a,e.hasVertexAlpha);var u=a._buffer,c=t.get(u)||[];t.set(u,c),-1===c.indexOf(a)&&c.push(a);var l=r.get(a)||[];r.set(a,l),-1===l.indexOf(e)&&l.push(e)}var f=e.morphTargetManager;if(f)for(var h=0;h<f.numTargets;h++){var d=f.getTarget(h);l=n.get(d)||[],n.set(d,l),-1===l.indexOf(e)&&l.push(e)}}for(var g=0,_=e.getChildren();g<_.length;g++){var x=_[g];this._collectBuffers(x,t,r,n,s)}},e.prototype._exportBuffers=function(e,t){for(var r=new Map,n=new Map,s=new Map,o=0,i=e;o<i.length;o++){var a=i[o];this._collectBuffers(a,r,n,s,t)}for(var u=Array.from(r.keys()),c=function(e){var s=e.getData();if(!s)throw new Error("Buffer data is not available");var o=r.get(e);if(!o)return"continue";var i=o[0].byteStride;if(o.some((function(e){return e.byteStride!==i})))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");for(var a=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)}(s).slice(),u=function(e){var t=n.get(e),r=O(e,t),s=r.byteOffset,o=r.byteStride,i=r.componentCount,u=r.type,c=r.count,f=r.normalized;switch(r.kind){case p.VertexBuffer.NormalKind:case p.VertexBuffer.TangentKind:(0,p.EnumerateFloatValues)(a,s,o,i,u,c,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 p.VertexBuffer.ColorKind:var h=t.filter((function(e){return e.material instanceof p.StandardMaterial||null==e.material})).length;if(0==h)break;if(h!=t.length){p.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}u==p.VertexBuffer.UNSIGNED_BYTE&&p.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var d=new p.Color3,g=new p.Color4,_=l._babylonScene.getEngine().useExactSrgbConversions;(0,p.EnumerateFloatValues)(a,s,o,i,u,c,f,(function(e){3===e.length?(d.fromArray(e,0),d.toLinearSpaceToRef(d,_),d.toArray(e,0)):(g.fromArray(e,0),g.toLinearSpaceToRef(g,_),g.toArray(e,0))}))}},c=0,f=o;c<f.length;c++)u(I=f[c]);if(t.convertToRightHanded){for(var h=0,d=o;h<d.length;h++){var g=O(I=d[h],n.get(I)),_=g.byteOffset,x=g.byteStride,m=g.componentCount,y=g.type,v=g.count,T=g.normalized;switch(R=g.kind){case p.VertexBuffer.PositionKind:case p.VertexBuffer.NormalKind:case p.VertexBuffer.TangentKind:(0,p.EnumerateFloatValues)(a,_,x,m,y,v,T,(function(e){e[0]=-e[0]}))}}t.convertedToRightHandedBuffers.set(e,a)}var b=l._bufferManager.createBufferView(a,i);t.setVertexBufferView(e,b);for(var A=new Map,w=0,E=o;w<E.length;w++){var M=O(I=E[w],n.get(I)),R=M.kind,C=M.totalVertices;switch(R){case p.VertexBuffer.MatricesIndicesKind:case p.VertexBuffer.MatricesIndicesExtraKind:if(I.type==p.VertexBuffer.FLOAT){var S=I.getFloatData(C);null!==S&&A.set(I,S)}}}0!==A.size&&p.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 V=0,B=Array.from(A.keys());V<B.length;V++){var I=B[V],F=A.get(I);if(F){for(var U=F.some((function(e){return e>=256})),N=new(U?Uint16Array:Uint8Array)(F.length),P=0;P<F.length;P++)N[P]=F[P];var L=l._bufferManager.createBufferView(N,4*(U?2:1));t.setRemappedBufferView(e,I,L)}}},l=this,f=0,h=u;f<h.length;f++)c(h[f]);for(var d=0,g=Array.from(s.keys());d<g.length;d++){var _=g[d],x=s.get(_);if(x)for(var m=ee(_,x[0],this._bufferManager,this._bufferViews,this._accessors,t.convertToRightHanded),y=0,v=x;y<v.length;y++){var T=v[y];t.bindMorphDataToMesh(T,m)}}},e.prototype._exportNodeAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,s,o,i,a,u,c,l,f=this;return _(this,(function(p){switch(p.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=p.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||($._CreateMorphTargetAnimationFromMorphTargetAnimations(e,o,i,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&$._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)}))),a=s?[]:t,u=0,c=e.getChildren(),p.label=2;case 2:return u<c.length?(l=c[u],[4,this._exportNodeAsync(l,a,r)]):[3,5];case 3:p.sent(),p.label=4;case 4:return u++,[3,2];case 5:return s&&a.length&&(s.children=a),[2]}}))}))},e.prototype._createNodeAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,s,o,i,a,u,c,l,f,h,d;return _(this,(function(g){switch(g.label){case 0:return this._shouldExportNode(e)?(r={},e.name&&(r.name=e.name),e.metadata&&(n=this._options.metadataSelector(e.metadata))&&(r.extras=n),e instanceof p.TransformNode?(this._setNodeTransformation(r,e,t.convertToRightHanded),e instanceof p.AbstractMesh?(s=e instanceof p.InstancedMesh?e.sourceMesh:e).subMeshes&&s.subMeshes.length>0?(o=r,[4,this._exportMeshAsync(s,t)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:o.mesh=g.sent(),g.label=2;case 2:e.skeleton&&void 0!==(i=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(i)&&this._nodesSkinMap.set(i,[]),null===(f=this._nodesSkinMap.get(i))||void 0===f||f.push(r)),g.label=3;case 3:if(e instanceof p.TargetCamera&&(a=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(a)&&this._nodesCameraMap.set(a,[]),this._setCameraTransformation(r,e,t.convertToRightHanded),null!==(u=e.parent)&&q(e,u)&&void 0!==(c=this._nodeMap.get(u)))return l=this._nodes[c],W(r,l),null===(h=this._nodesCameraMap.get(a))||void 0===h||h.push(l),[2,null];null===(d=this._nodesCameraMap.get(a))||void 0===d||d.push(r)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",r,e,this._nodeMap,t.convertToRightHanded)];case 4:return g.sent()?[2,r]:(p.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}}))}))},e.prototype._exportIndices=function(e,t,r,n,s,o,i,a,u){var c=e;u.mode=K(o);var l=i!==p.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case p.Material.TriangleFillMode:case p.Material.TriangleStripDrawMode:case p.Material.TriangleFanDrawMode:return!0}return!1}(o);if(l){if(o===p.Material.TriangleStripDrawMode||o===p.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");u.mode=K(o);var f=t?new Uint32Array(n):new Uint16Array(n);if(e)for(var h=0;h+2<n;h+=3)f[h]=e[r+h]+s,f[h+1]=e[r+h+2]+s,f[h+2]=e[r+h+1]+s;else for(h=0;h+2<n;h+=3)f[h]=h,f[h+1]=h+2,f[h+2]=h+1;c=f}else if(e&&0!==s){for(f=t?new Uint32Array(n):new Uint16Array(n),h=0;h<n;h++)f[h]=e[r+h]+s;c=f}if(c){var d=a.getIndicesAccessor(e,r,n,s,l);if(void 0===d){var g=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}(c,r,n,t),_=this._bufferManager.createBufferView(g),x=t?5125:5123;this._accessors.push(this._bufferManager.createAccessor(_,"SCALAR",x,n,0)),d=this._accessors.length-1,a.setIndicesAccessor(e,r,n,s,l,d)}u.indices=d}},e.prototype._exportVertexBuffer=function(e,t,r,n,s,o){var i=e.getKind();if(L(i)&&(!i.startsWith("uv")||this._options.exportUnusedUVs||t&&this._materialNeedsUVsSet.has(t))){var a=s.getVertexAccessor(e,r,n);if(void 0===a){var u=s.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),c=i===p.VertexBuffer.PositionKind?function(e,t,r,n){var s=t.byteOffset,o=t.byteStride,i=t.type,a=t.normalized,u=t.getSize(),c=new Array(u).fill(1/0),l=new Array(u).fill(-1/0);return(0,p.EnumerateFloatValues)(e,s+r*o,o,u,i,n*u,a,(function(e){for(var t=0;t<u;t++)c[t]=Math.min(c[t],e[t]),l[t]=Math.max(l[t],e[t])})),{min:c,max:l}}(u,e,r,n):void 0,l=(i===p.VertexBuffer.MatricesIndicesKind||i===p.VertexBuffer.MatricesIndicesExtraKind)&&e.type===p.VertexBuffer.FLOAT,f=l?p.VertexBuffer.UNSIGNED_BYTE:e.type,h=l?void 0:e.normalized,d=l?s.getRemappedBufferView(e._buffer,e):s.getVertexBufferView(e._buffer),g=e.byteOffset+r*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(d,function(e,t){if(e==p.VertexBuffer.ColorKind)return t?"VEC4":"VEC3";switch(e){case p.VertexBuffer.PositionKind:case p.VertexBuffer.NormalKind:return"VEC3";case p.VertexBuffer.TangentKind:case p.VertexBuffer.MatricesIndicesKind:case p.VertexBuffer.MatricesIndicesExtraKind:case p.VertexBuffer.MatricesWeightsKind:case p.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case p.VertexBuffer.UVKind:case p.VertexBuffer.UV2Kind:case p.VertexBuffer.UV3Kind:case p.VertexBuffer.UV4Kind:case p.VertexBuffer.UV5Kind:case p.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(i,s.hasVertexColorAlpha(e)),f,n,g,c,h)),a=this._accessors.length-1,s.setVertexAccessor(e,r,n,a)}o.attributes[function(e){switch(e){case p.VertexBuffer.PositionKind:return"POSITION";case p.VertexBuffer.NormalKind:return"NORMAL";case p.VertexBuffer.TangentKind:return"TANGENT";case p.VertexBuffer.ColorKind:return"COLOR_0";case p.VertexBuffer.UVKind:return"TEXCOORD_0";case p.VertexBuffer.UV2Kind:return"TEXCOORD_1";case p.VertexBuffer.UV3Kind:return"TEXCOORD_2";case p.VertexBuffer.UV4Kind:return"TEXCOORD_3";case p.VertexBuffer.UV5Kind:return"TEXCOORD_4";case p.VertexBuffer.UV6Kind:return"TEXCOORD_5";case p.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case p.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case p.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case p.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(i)]=a}},e.prototype._exportMaterialAsync=function(e,t,r,n){return g(this,void 0,void 0,(function(){var s,o;return _(this,(function(i){switch(i.label){case 0:return void 0!==(s=this._materialMap.get(e))?[3,8]:(o=t&&Object.keys(t).some((function(e){return e.startsWith("uv")})),(e=e instanceof p.MultiMaterial?e.subMaterials[r.materialIndex]:e)instanceof p.PBRBaseMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,o)]:[3,2]);case 1:return s=i.sent(),[3,7];case 2:return e instanceof p.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,o)]:[3,4];case 3:return s=i.sent(),[3,7];case 4:return e instanceof p.OpenPBRMaterial?[4,this._materialExporter.exportOpenPBRMaterialAsync(e,o)]:[3,6];case 5:return s=i.sent(),[3,7];case 6:return p.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 7:this._materialMap.set(e,s),i.label=8;case 8:return n.material=s,[2]}}))}))},e.prototype._exportMeshAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,s,o,i,a,u,c,l,f,h,d,g,m,y,v,T,b,A,w,E,M,R,C,S,V,B,I,F,U,N,O,P,L;return _(this,(function(_){switch(_.label){case 0:if(void 0!==(r=t.getMesh(e)))return[2,r];if(n={primitives:[]},r=this._meshes.length,this._meshes.push(n),t.setMesh(e,r),s=e.isUnIndexed?null:e.getIndices(),o=null===(F=e.geometry)||void 0===F?void 0:F.getVertexBuffers(),i=t.getMorphTargetsFromMesh(e),a=e instanceof p.LinesMesh,u=e instanceof p.GreasedLineBaseMesh,c=e.subMeshes,!(o&&c&&c.length>0))return[3,7];l=0,f=c,_.label=1;case 1:return l<f.length?(h=f[l],d={attributes:{}},g=h.getMaterial()||this._babylonScene.defaultMaterial,u?(T={name:g.name},b=e,m=p.Color3.White(),y=null!==(N=null===(U=b.material)||void 0===U?void 0:U.alpha)&&void 0!==N?N:1,(!(v=null!==(P=null===(O=b.greasedLineMaterial)||void 0===O?void 0:O.color)&&void 0!==P?P:m).equalsWithEpsilon(m,p.Epsilon)||y<1)&&(T.pbrMetallicRoughness={baseColorFactor:x(x([],v.asArray(),!0),[y],!1)}),this._materials.push(T),d.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return a?(T={name:g.name},(!(b=e).color.equalsWithEpsilon(p.Color3.White(),p.Epsilon)||b.alpha<1)&&(T.pbrMetallicRoughness={baseColorFactor:x(x([],b.color.asArray(),!0),[b.alpha],!1)}),this._materials.push(T),d.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(g,o,h,d)];case 4:_.sent(),_.label=5;case 5:for(A=a||u?p.Material.LineListDrawMode:null!==(L=e.overrideRenderingFillMode)&&void 0!==L?L:g.fillMode,w=g._getEffectiveOrientation(e),t.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(w=w===p.Material.ClockWiseSideOrientation?p.Material.CounterClockWiseSideOrientation:p.Material.ClockWiseSideOrientation),this._exportIndices(s,s?(0,p.AreIndices32Bits)(s,h.indexCount,h.indexStart,h.verticesStart):h.verticesCount>65535,s?h.indexStart:h.verticesStart,s?h.indexCount:h.verticesCount,-h.verticesStart,A,w,t,d),E=0,M=Object.values(o);E<M.length;E++)R=M[E],this._exportVertexBuffer(R,g,h.verticesStart,h.verticesCount,t,d);if(i)for(d.targets=[],C=0,S=i;C<S.length;C++)I=S[C],d.targets.push(I.attributes);n.primitives.push(d),this._extensionsPostExportMeshPrimitive(d),_.label=6;case 6:return l++,[3,1];case 7:if(i)for(n.weights=[],n.extras||(n.extras={}),n.extras.targetNames=[],V=0,B=i;V<B.length;V++)I=B[V],n.weights.push(I.influence),n.extras.targetNames.push(I.name);return[2,r]}}))}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e._ExtensionOrders={},e}(),ne=function(){function e(){}return e.GLTFAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,s;return _(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 re(e,r)).generateGLTFAsync(t.replace(/\.[^/.]+$/,""))];case 3:return s=o.sent(),n.dispose(),[2,s]}}))}))},e.GLBAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,s;return _(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 re(e,r)).generateGLBAsync(t.replace(/\.[^/.]+$/,""))];case 3:return s=o.sent(),n.dispose(),[2,s]}}))}))},e}(),se="EXT_mesh_gpu_instancing",oe=function(){function e(e){this.name=se,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.postExportNodeAsync=function(e,t,r,n,s,o){return g(this,void 0,void 0,(function(){var e=this;return _(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){if(t&&r instanceof p.Mesh&&r.hasThinInstances&&e._exporter){e._wasUsed=!0;for(var i=p.Vector3.Zero(),a=p.Quaternion.Identity(),u=p.Vector3.One(),c=r.thinInstanceGetWorldMatrices(),l=p.TmpVectors.Vector3[2],f=p.TmpVectors.Quaternion[1],h=p.TmpVectors.Vector3[3],d=!1,g=!1,_=!1,x=new Float32Array(3*r.thinInstanceCount),m=new Float32Array(4*r.thinInstanceCount),y=new Float32Array(3*r.thinInstanceCount),v=0,T=0,b=c;T<b.length;T++)b[T].decompose(h,f,l),s&&(k(l),H(f)),x.set(l.asArray(),3*v),m.set(f.normalize().asArray(),4*v),y.set(h.asArray(),3*v),d=d||!l.equalsWithEpsilon(i),g=g||!f.equalsWithEpsilon(a),_=_||!h.equalsWithEpsilon(u),v++;var A={attributes:{}};d&&(A.attributes.TRANSLATION=e._buildAccessor(x,"VEC3",r.thinInstanceCount,o)),g&&(A.attributes.ROTATION=e._buildAccessor(m,"VEC4",r.thinInstanceCount,o)),_&&(A.attributes.SCALE=e._buildAccessor(y,"VEC3",r.thinInstanceCount,o)),t.extensions=t.extensions||{},t.extensions[se]=A}n(t)}))];case 1:return[2,n.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}();re.RegisterExtension(se,(function(e){return new oe(e)}));var ie="KHR_draco_mesh_compression",ae=function(){function e(e){this.name=ie,this.required=!0,this._bufferViewsUsed=new Set,this._accessorsUsed=new Set,this._encodePromises=[],this._wasUsed=!1,this.enabled="Draco"===e.options.meshCompressionMethod&&p.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,t,r){var n=this;if(this.enabled)if(4===e.mode||5===e.mode){var s=[],o=[],i=null;if(void 0!==e.indices){var a=r[e.indices],u=t.getBufferView(a);i=t.getData(u).slice(),s.push(u),o.push(a)}for(var c,l=[],f=0,h=Object.entries(e.attributes);f<h.length;f++){var d=h[f],g=d[0],_=(a=r[d[1]],u=t.getBufferView(a),P(a.type)),x=(0,p.GetTypedArrayData)(t.getData(u),_,a.componentType,a.byteOffset||0,u.byteStride||(0,p.GetTypeByteLength)(a.componentType)*_,a.normalized||!1,a.count,!0);l.push({kind:g,dracoName:(c=g,"POSITION"===c?"POSITION":"NORMAL"===c?"NORMAL":c.startsWith("COLOR")?"COLOR":c.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"),size:P(a.type),data:x}),s.push(u),o.push(a)}var m={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},y=p.DracoEncoder.Default._encodeAsync(l,i,m).then((function(r){if(r){var i={bufferView:-1,attributes:r.attributeIds},a=t.createBufferView(r.data);t.setBufferView(i,a);for(var u=0,c=s;u<c.length;u++){var l=c[u];n._bufferViewsUsed.add(l)}for(var f=0,h=o;f<h.length;f++){var d=h[f];n._accessorsUsed.add(d)}e.extensions||(e.extensions={}),e.extensions[ie]=i}else p.Logger.Error("Draco encoding failed for primitive.")})).catch((function(e){p.Logger.Error("Draco encoding failed for primitive: "+e)}));this._encodePromises.push(y),this._wasUsed=!0}else p.Logger.Warn("Cannot compress primitive with mode "+e.mode+".")},e.prototype.preGenerateBinaryAsync=function(e){return g(this,void 0,void 0,(function(){var t=this;return _(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}();re.RegisterExtension(ie,(function(e){return new ae(e)}));var ue="KHR_lights_punctual",ce={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},le={innerConeAngle:0,outerConeAngle:Math.PI/4},fe=p.Vector3.Backward(),pe=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,t,r,n,s){return g(this,void 0,void 0,(function(){var o=this;return _(this,(function(i){switch(i.label){case 0:return[4,new Promise((function(i){if(r instanceof p.Light){var a=r.getTypeID()==p.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==p.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==p.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(a&&r instanceof p.ShadowLight))return p.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(ue)),void i(t);if(r.falloffType!==p.Light.FALLOFF_GLTF&&p.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(ue," specification!")),!r.position.equalsToFloats(0,0,0)){var u=p.TmpVectors.Vector3[0].copyFrom(r.position);s&&k(u),t.translation=u.asArray()}if("point"!==a){var c=r.direction.normalizeToRef(p.TmpVectors.Vector3[0]);s&&k(c);var l=p.Quaternion.FromUnitVectorsToRef(fe,c,p.TmpVectors.Quaternion[0]);p.Quaternion.IsIdentity(l)||(t.rotation=l.asArray())}var f={type:a,name:r.name,color:r.diffuse.asArray(),intensity:r.intensity,range:r.range};if(z(f,ce),"spot"===a){var h=r;f.spot={innerConeAngle:h.innerAngle/2,outerConeAngle:h.angle/2},z(f.spot,le)}o._lights||(o._lights={lights:[]}),o._lights.lights.push(f);var d={light:o._lights.lights.length-1},g=r.parent;if(g&&q(r,g)){var _=n.get(g);if(_){var x=o._exporter._nodes[_];return W(t,x),x.extensions||(x.extensions={}),x.extensions[ue]=d,void i(null)}}t.extensions||(t.extensions={}),t.extensions[ue]=d,i(t)}else i(t)}))];case 1:return[2,i.sent()]}}))}))},e}();re.RegisterExtension(ue,(function(e){return new pe(e)}));var he="KHR_materials_anisotropy";function de(e,t){t.uOffset=e.uOffset,t.vOffset=e.vOffset,t.uScale=e.uScale,t.vScale=e.vScale,t.uAng=e.uAng,t.vAng=e.vAng,t.wAng=e.wAng,t.uRotationCenter=e.uRotationCenter,t.vRotationCenter=e.vRotationCenter}function ge(e){return g(this,void 0,void 0,(function(){var t,r,n,s,o,i,a,u;return _(this,(function(c){switch(c.label){case 0:return t=e.getScene(),p.Effect.ShadersStore.anisotropyMergeFragmentShader||(p.Effect.ShadersStore.anisotropyMergeFragmentShader="\n precision highp float;\n#ifdef HAS_TANGENT_TEXTURE\n uniform sampler2D tangentTexture;\n#endif\n#ifdef HAS_ANISOTROPY_TEXTURE\n uniform sampler2D anisotropyTexture;\n#endif\n uniform int useRoughnessFromMetallicGreen;\n uniform int useAnisotropyFromTangentBlue;\n\n varying vec2 vUV;\n\n void main() {\n vec2 tangent = vec2(1.0, 0.0);\n float anisotropy = 1.0;\n #ifdef HAS_TANGENT_TEXTURE\n // Tangent texture is present\n vec4 tangentSample = texture2D(tangentTexture, vUV);\n tangent = tangentSample.rg;\n\n if (useAnisotropyFromTangentBlue > 0) {\n anisotropy = tangentSample.b;\n }\n #endif\n #ifdef HAS_ANISOTROPY_TEXTURE\n // Anisotropy texture is present\n vec4 anisotropySample = texture2D(anisotropyTexture, vUV);\n anisotropy = anisotropySample.r;\n #endif\n \n // Output: RG = tangent XY, B = anisotropy strength\n vec4 anisotropyData = vec4(tangent.x, tangent.y, anisotropy, 1.0);\n gl_FragColor = anisotropyData;\n }\n"),r=e.specularRoughnessAnisotropyTexture,n=e.geometryTangentTexture,r||n?(s=Math.max(r?r.getSize().width:1,n?n.getSize().width:1),o=Math.max(r?r.getSize().height:1,n?n.getSize().height:1),i={type:p.Constants.TEXTURETYPE_UNSIGNED_BYTE,format:p.Constants.TEXTUREFORMAT_RGBA,samplingMode:p.Constants.TEXTURE_BILINEAR_SAMPLINGMODE,generateDepthBuffer:!1,generateStencilBuffer:!1,generateMipMaps:!1},(a=new p.ProceduralTexture(e.name+"_anisotropy",{width:s,height:o},"anisotropyMerge",t,i)).refreshRate=-1,u="",n&&(u+="#define HAS_TANGENT_TEXTURE\n",a.setTexture("tangentTexture",n),de(n,a)),a.setVector2("tangentVector",e.geometryTangent),r&&(u+="#define HAS_ANISOTROPY_TEXTURE\n",a.setTexture("anisotropyTexture",r),de(r,a)),a.setInt("useAnisotropyFromTangentBlue",e._useSpecularRoughnessAnisotropyFromTangentTexture?1:0),a.defines=u,[4,new Promise((function(e,t){a.executeWhenReady((function(){try{a.render(),e(a)}catch(e){t(e instanceof Error?e:new Error(String(e)))}}))}))]):[2,null];case 1:return[2,c.sent()]}}))}))}var _e=function(){function e(e){this.name=he,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,t,r){return g(this,void 0,void 0,(function(){var e,t;return _(this,(function(n){switch(n.label){case 0:return e=[],r instanceof p.PBRBaseMaterial?r.anisotropy.isEnabled&&!r.anisotropy.legacy?(r.anisotropy.texture&&e.push(r.anisotropy.texture),[2,e]):[3,3]:[3,1];case 1:return r instanceof p.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0?[4,ge(r)]:[3,3];case 2:return(t=n.sent())&&(e.push(t),this._anisoTexturesMap[r.id]=t),[2,e];case 3:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var s,o,i,a,u,c;if(r instanceof p.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var l=n._exporter._materialExporter.getTextureInfo(r.anisotropy.texture);null!==(y={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=l?l:void 0}).anisotropyTexture&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[he]=y}else if(r instanceof p.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0){n._wasUsed=!0,t.extensions=t.extensions||{};var f=r.specularRoughnessTexture;r._useRoughnessFromMetallicTextureGreen&&(f=r.baseMetalnessTexture);var h=n._anisoTexturesMap[r.id];if(!f&&!h){var d=r.specularRoughness,g=r.specularRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){var _=(o=r.specularRoughness,c=(1-(i=r.specularRoughnessAnisotropy))*(u=(a=o*o)*Math.sqrt(2/(1+(1-i)*(1-i)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-a)/Math.max(1-a,1e-4)),1)});d=_.newBaseRoughness,g=_.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=d);var x={anisotropyStrength:g,anisotropyRotation:r.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return t.extensions[he]=x,e(t)}var m=h?n._exporter._materialExporter.getTextureInfo(h):null,y={anisotropyStrength:r.specularRoughnessAnisotropy,anisotropyRotation:r.geometryTangentAngle,anisotropyTexture:m||void 0,extensions:{}};r._useGltfStyleAnisotropy||(y.extensions.EXT_materials_anisotropy_openpbr={openPbrAnisotropyEnabled:!0},(s=n._exporter._glTF).extensionsUsed||(s.extensionsUsed=[]),-1===n._exporter._glTF.extensionsUsed.indexOf("EXT_materials_anisotropy_openpbr")&&n._exporter._glTF.extensionsUsed.push("EXT_materials_anisotropy_openpbr")),n._exporter._materialNeedsUVsSet.add(r),t.extensions[he]=y}e(t)}))},e}();re.RegisterExtension(he,(function(e){return new _e(e)}));var xe="KHR_materials_clearcoat",me=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,t,r){return g(this,void 0,void 0,(function(){var e;return _(this,(function(t){if(e=[],r instanceof p.PBRBaseMaterial){if(r.clearCoat.isEnabled)return r.clearCoat.texture&&e.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&e.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&e.push(r.clearCoat.bumpTexture),[2,e]}else if(r instanceof p.OpenPBRMaterial&&r.coatWeight>0)return r.coatWeightTexture&&e.push(r.coatWeightTexture),r.geometryCoatNormalTexture&&e.push(r.geometryCoatNormalTexture),r.coatRoughnessTexture&&e.push(r.coatRoughnessTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof p.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var s=n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture),o=void 0;o=r.clearCoat.useRoughnessFromMainTexture?n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):n._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&p.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),r.clearCoat.remapF0OnInterfaceChange&&p.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(r.name));var i=n._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture);null===(a={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=s?s:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=o?o:void 0,clearcoatNormalTexture:null!=i?i:void 0}).clearcoatTexture&&null===a.clearcoatRoughnessTexture&&null===a.clearcoatRoughnessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[xe]=a}else if(r instanceof p.OpenPBRMaterial){if(0==r.coatWeight)return void e(t);var a;n._wasUsed=!0,t.extensions=t.extensions||{},s=n._exporter._materialExporter.getTextureInfo(r.coatWeightTexture),o=void 0,o=r.useCoatRoughnessFromWeightTexture?n._exporter._materialExporter.getTextureInfo(r.coatWeightTexture):n._exporter._materialExporter.getTextureInfo(r.coatRoughnessTexture),r.coatColorTexture&&p.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),i=n._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),null===(a={clearcoatFactor:r.coatWeight,clearcoatTexture:null!=s?s:void 0,clearcoatRoughnessFactor:r.coatRoughness,clearcoatRoughnessTexture:null!=o?o:void 0,clearcoatNormalTexture:null!=i?i:void 0}).clearcoatTexture&&null===a.clearcoatRoughnessTexture&&null===a.clearcoatRoughnessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[xe]=a}e(t)}))},e}();re.RegisterExtension(xe,(function(e){return new me(e)}));var ye="KHR_materials_clearcoat_darkening",ve=function(){function e(e){this.name=ye,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,t,r){return g(this,void 0,void 0,(function(){var e;return _(this,(function(t){return e=[],r instanceof p.OpenPBRMaterial&&r.coatDarkening?(r.coatDarkeningTexture&&e.push(r.coatDarkeningTexture),[2,e]):[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var s=null,o=null;if(r instanceof p.OpenPBRMaterial&&(s=r.coatDarkening,o=r.coatDarkeningTexture),null===s||1===s&&null===o)return e(t);var i=t.extensions?t.extensions.KHR_materials_clearcoat:null;if(!i)return e(t);n._wasUsed=!0;var a=n._exporter._materialExporter.getTextureInfo(o),u={clearcoatDarkeningFactor:s,clearcoatDarkeningTexture:null!=a?a:void 0};return null!==u.clearcoatDarkeningTexture&&n._exporter._materialNeedsUVsSet.add(r),i.extensions=i.extensions||{},i.extensions[ye]=u,e(t)}))},e}();re.RegisterExtension(ye,(function(e){return new ve(e)}),105);var Te="KHR_materials_clearcoat_ior",be=function(){function e(e){this.name=Te,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.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var s=null;if(r instanceof p.OpenPBRMaterial?s=r.coatIor:r instanceof p.PBRMaterial&&(s=r.clearCoat.indexOfRefraction),null===s||1.5===s)return e(t);var o=t.extensions?t.extensions.KHR_materials_clearcoat:null;if(!o)return e(t);n._wasUsed=!0;var i={clearcoatIor:s};return n._exporter,o.extensions=o.extensions||{},o.extensions[Te]=i,e(t)}))},e}();re.RegisterExtension(Te,(function(e){return new be(e)}),105);var Ae="KHR_materials_clearcoat_color",we=function(){function e(e){this.name=Ae,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,t,r){return g(this,void 0,void 0,(function(){var e;return _(this,(function(t){if(e=[],r instanceof p.PBRBaseMaterial){if(r.clearCoat.isEnabled)return r.clearCoat.tintTexture&&e.push(r.clearCoat.tintTexture),[2,e]}else if(r instanceof p.OpenPBRMaterial&&r.coatWeight>0)return r.coatColorTexture&&e.push(r.coatColorTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof p.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(t);if(n._wasUsed=!0,!(o=t.extensions?t.extensions.KHR_materials_clearcoat:null))return void e(t);var s=n._exporter._materialExporter.getTextureInfo(r.clearCoat.tintTexture);null!==(i={clearcoatColorFactor:r.clearCoat.tintColor.asArray(),clearcoatColorTexture:null!=s?s:void 0}).clearcoatColorTexture&&n._exporter._materialNeedsUVsSet.add(r),o.extensions=o.extensions||{},o.extensions[Ae]=i}else if(r instanceof p.OpenPBRMaterial){if(0==r.coatWeight)return void e(t);var o,i;if(n._wasUsed=!0,!(o=t.extensions?t.extensions.KHR_materials_clearcoat:null))return void e(t);s=n._exporter._materialExporter.getTextureInfo(r.coatWeightTexture),null!==(i={clearcoatColorFactor:r.coatColor.asArray(),clearcoatColorTexture:null!=s?s:void 0}).clearcoatColorTexture&&n._exporter._materialNeedsUVsSet.add(r),o.extensions=o.extensions||{},o.extensions[Ae]=i}e(t)}))},e}();re.RegisterExtension(Ae,(function(e){return new we(e)}),105);var Ee="KHR_materials_clearcoat_anisotropy";function Me(e,t){t.uOffset=e.uOffset,t.vOffset=e.vOffset,t.uScale=e.uScale,t.vScale=e.vScale,t.uAng=e.uAng,t.vAng=e.vAng,t.wAng=e.wAng,t.uRotationCenter=e.uRotationCenter,t.vRotationCenter=e.vRotationCenter}function Re(e){return g(this,void 0,void 0,(function(){var t,r,n,s,o,i,a,u;return _(this,(function(c){switch(c.label){case 0:return t=e.getScene(),p.Effect.ShadersStore.anisotropyMergeFragmentShader||(p.Effect.ShadersStore.anisotropyMergeFragmentShader="\n precision highp float;\n#ifdef HAS_TANGENT_TEXTURE\n uniform sampler2D tangentTexture;\n#endif\n#ifdef HAS_ANISOTROPY_TEXTURE\n uniform sampler2D anisotropyTexture;\n#endif\n uniform int useRoughnessFromMetallicGreen;\n uniform int useAnisotropyFromTangentBlue;\n\n varying vec2 vUV;\n\n void main() {\n vec2 tangent = vec2(1.0, 0.0);\n float anisotropy = 1.0;\n #ifdef HAS_TANGENT_TEXTURE\n // Tangent texture is present\n vec4 tangentSample = texture2D(tangentTexture, vUV);\n tangent = tangentSample.rg;\n\n if (useAnisotropyFromTangentBlue > 0) {\n anisotropy = tangentSample.b;\n }\n #endif\n #ifdef HAS_ANISOTROPY_TEXTURE\n // Anisotropy texture is present\n vec4 anisotropySample = texture2D(anisotropyTexture, vUV);\n anisotropy = anisotropySample.r;\n #endif\n \n // Output: RG = tangent XY, B = anisotropy strength\n vec4 anisotropyData = vec4(tangent.x, tangent.y, anisotropy, 1.0);\n gl_FragColor = anisotropyData;\n }\n"),r=e.coatRoughnessAnisotropyTexture,n=e.geometryCoatTangentTexture,r||n?(s=Math.max(r?r.getSize().width:1,n?n.getSize().width:1),o=Math.max(r?r.getSize().height:1,n?n.getSize().height:1),i={type:p.Constants.TEXTURETYPE_UNSIGNED_BYTE,format:p.Constants.TEXTUREFORMAT_RGBA,samplingMode:p.Constants.TEXTURE_BILINEAR_SAMPLINGMODE,generateDepthBuffer:!1,generateStencilBuffer:!1,generateMipMaps:!1},(a=new p.ProceduralTexture(e.name+"_anisotropy",{width:s,height:o},"anisotropyMerge",t,i)).refreshRate=-1,u="",n&&(u+="#define HAS_TANGENT_TEXTURE\n",a.setTexture("tangentTexture",n),Me(n,a)),a.setVector2("tangentVector",e.geometryTangent),r&&(u+="#define HAS_ANISOTROPY_TEXTURE\n",a.setTexture("anisotropyTexture",r),Me(r,a)),a.setInt("useAnisotropyFromTangentBlue",e._useCoatRoughnessAnisotropyFromTangentTexture?1:0),a.defines=u,[4,new Promise((function(e,t){a.executeWhenReady((function(){try{a.render(),e(a)}catch(e){t(e instanceof Error?e:new Error(String(e)))}}))}))]):[2,null];case 1:return[2,c.sent()]}}))}))}var Ce=function(){function e(e){this.name=Ee,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,t,r){return g(this,void 0,void 0,(function(){var e,t;return _(this,(function(n){switch(n.label){case 0:return e=[],r instanceof p.OpenPBRMaterial&&r.coatRoughnessAnisotropy>0?[4,Re(r)]:[3,2];case 1:return(t=n.sent())&&(e.push(t),this._anisoTexturesMap[r.id]=t),[2,e];case 2:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var s,o,i,a,u,c;if(r instanceof p.OpenPBRMaterial&&r.coatRoughnessAnisotropy>0){t.extensions=t.extensions||{};var l=t.extensions?t.extensions.KHR_materials_clearcoat:null;if(!l)return e(t);n._wasUsed=!0;var f=r.coatRoughnessTexture,h=n._anisoTexturesMap[r.id];if(!f&&!h){var d=r.coatRoughness,g=r.coatRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){var _=(o=r.coatRoughness,c=(1-(i=r.coatRoughnessAnisotropy))*(u=(a=o*o)*Math.sqrt(2/(1+(1-i)*(1-i)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-a)/Math.max(1-a,1e-4)),1)});d=_.newBaseRoughness,g=_.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=d);var x={clearcoatAnisotropyStrength:g,clearcoatAnisotropyRotation:r.geometryCoatTangentAngle+.5*Math.PI,clearcoatAnisotropyTexture:void 0};return l.extensions=l.extensions||{},l.extensions[Ee]=x,e(t)}var m=h?n._exporter._materialExporter.getTextureInfo(h):null,y={clearcoatAnisotropyStrength:r.coatRoughnessAnisotropy,clearcoatAnisotropyRotation:r.geometryCoatTangentAngle,clearcoatAnisotropyTexture:m||void 0,extensions:{}};r._useGltfStyleAnisotropy||(y.extensions.EXT_materials_anisotropy_openpbr={openPbrAnisotropyEnabled:!0},(s=n._exporter._glTF).extensionsUsed||(s.extensionsUsed=[]),-1===n._exporter._glTF.extensionsUsed.indexOf("EXT_materials_anisotropy_openpbr")&&n._exporter._glTF.extensionsUsed.push("EXT_materials_anisotropy_openpbr")),n._exporter._materialNeedsUVsSet.add(r),l.extensions=l.extensions||{},l.extensions[Ee]=y}e(t)}))},e}();re.RegisterExtension(Ee,(function(e){return new Ce(e)}),105);var Se="KHR_materials_diffuse_transmission";function Ve(e,t){var r=t.subSurface,n=null;return r.translucencyIntensityTexture?n=r.translucencyIntensityTexture:r.thicknessTexture&&r.useMaskFromThicknessTexture&&(n=r.thicknessTexture),n&&!r.useGltfStyleTextures?(p.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(t.name),1),null):n}var Be=function(){function e(e){this.name=Se,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,t,r){return g(this,void 0,void 0,(function(){var t,n;return _(this,(function(s){return t=[],r instanceof p.PBRMaterial&&this._isExtensionEnabled(r)?((n=Ve(e,r))&&t.push(n),r.subSurface.translucencyColorTexture&&t.push(r.subSurface.translucencyColorTexture),[2,t]):[2,t]}))}))},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,t,r){var n=this;return new Promise((function(s){var o,i;if(r instanceof p.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var a=r.subSurface,u=Ve(e,r),c=0==a.translucencyIntensity?void 0:a.translucencyIntensity,l=null!==(o=n._exporter._materialExporter.getTextureInfo(u))&&void 0!==o?o:void 0,f=!a.translucencyColor||a.translucencyColor.equalsFloats(1,1,1)?void 0:a.translucencyColor.asArray(),h=null!==(i=n._exporter._materialExporter.getTextureInfo(a.translucencyColorTexture))&&void 0!==i?i:void 0,d={diffuseTransmissionFactor:c,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:f,diffuseTransmissionColorTexture:h};(l||h)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions=t.extensions||{},t.extensions[Se]=d}s(t)}))},e}();re.RegisterExtension(Se,(function(e){return new Be(e)}));var Ie="KHR_materials_dispersion",Fe=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,t,r){var n=this;return new Promise((function(e){if(r instanceof p.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var s={dispersion:r.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[Ie]=s}e(t)}))},e}();re.RegisterExtension(Ie,(function(){return new Fe}));var Ue="KHR_materials_emissive_strength",Ne=function(){function e(){this.name=Ue,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,t,r){return g(this,void 0,void 0,(function(){var e=this;return _(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){if(!(r instanceof p.PBRMaterial))return n(t);var s=r.emissiveColor.scale(r.emissiveIntensity),o=Math.max.apply(Math,s.asArray());if(o>1){t.emissiveFactor=s.scale(1/o).asArray(),e._wasUsed=!0;var i={emissiveStrength:o};t.extensions||(t.extensions={}),t.extensions[Ue]=i}else t.emissiveFactor=s.asArray();return n(t)}))];case 1:return[2,n.sent()]}}))}))},e}();re.RegisterExtension(Ue,(function(){return new Ne}));var Oe="KHR_materials_ior",Pe=function(){function e(){this.name=Oe,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&&null!=e.indexOfRefraction&&1.5!=e.indexOfRefraction},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof p.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var s={ior:r.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[Oe]=s}e(t)}))},e}();re.RegisterExtension(Oe,(function(e){return new Pe}));var Le="KHR_materials_iridescence",Ke=function(){function e(e){this.name=Le,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,t,r){return g(this,void 0,void 0,(function(){var e;return _(this,(function(t){return e=[],r instanceof p.PBRBaseMaterial&&r.iridescence.isEnabled?(r.iridescence.texture&&e.push(r.iridescence.texture),r.iridescence.thicknessTexture&&r.iridescence.thicknessTexture!==r.iridescence.texture&&e.push(r.iridescence.thicknessTexture),[2,e]):[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof p.PBRBaseMaterial){if(!r.iridescence.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var s=n._exporter._materialExporter.getTextureInfo(r.iridescence.texture),o=n._exporter._materialExporter.getTextureInfo(r.iridescence.thicknessTexture),i={iridescenceFactor:r.iridescence.intensity,iridescenceIor:r.iridescence.indexOfRefraction,iridescenceThicknessMinimum:r.iridescence.minimumThickness,iridescenceThicknessMaximum:r.iridescence.maximumThickness,iridescenceTexture:null!=s?s:void 0,iridescenceThicknessTexture:null!=o?o:void 0};null===i.iridescenceTexture&&null===i.iridescenceThicknessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Le]=i}e(t)}))},e}();re.RegisterExtension(Le,(function(e){return new Ke(e)}));var De="KHR_materials_sheen",ke=function(){function e(e){this.name=De,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,t,r){return g(this,void 0,void 0,(function(){return _(this,(function(e){return r instanceof p.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[2,[r.sheen.texture]]:[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var e=this;return _(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){var s,o,i,a;if(r instanceof p.PBRMaterial){if(!r.sheen.isEnabled)return void n(t);e._wasUsed=!0,null==t.extensions&&(t.extensions={});var u={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(s=r.sheen.roughness)&&void 0!==s?s:0};null===u.sheenColorTexture&&null===u.sheenRoughnessTexture||e._exporter._materialNeedsUVsSet.add(r),r.sheen.texture&&(u.sheenColorTexture=null!==(o=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==o?o:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(r.sheen.textureRoughness))&&void 0!==i?i:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==a?a:void 0),t.extensions[De]=u}n(t)}))];case 1:return[2,n.sent()]}}))}))},e}();re.RegisterExtension(De,(function(e){return new ke(e)}));var He="KHR_materials_specular",Ge=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,t,r){return g(this,void 0,void 0,(function(){var e;return _(this,(function(t){return e=[],r instanceof p.PBRMaterial&&this._isExtensionEnabled(r)?(r.metallicReflectanceTexture&&e.push(r.metallicReflectanceTexture),r.reflectanceTexture&&e.push(r.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,t,r){var n=this;return new Promise((function(e){var s,o,i,a,u;if(r instanceof p.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0,t.extensions=t.extensions||{};var c=null!==(s=n._exporter._materialExporter.getTextureInfo(r.metallicReflectanceTexture))&&void 0!==s?s:void 0,l=null!==(o=n._exporter._materialExporter.getTextureInfo(r.reflectanceTexture))&&void 0!==o?o:void 0,f={specularFactor:1==r.metallicF0Factor?void 0:r.metallicF0Factor,specularTexture:c,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:l};n._hasTexturesExtension(r)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[He]=f}else if(r instanceof p.OpenPBRMaterial){t.extensions=t.extensions||{};var h=null!==(i=n._exporter._materialExporter.getTextureInfo(r.specularWeightTexture))&&void 0!==i?i:void 0,d=null!==(a=n._exporter._materialExporter.getTextureInfo(r.specularColorTexture))&&void 0!==a?a:void 0,g=1==r.specularWeight?void 0:r.specularWeight,_=r.specularColor.equalsFloats(1,1,1)?void 0:r.specularColor.asArray();if(!d&&!h&&void 0===g&&void 0===_)return e(t);n._wasUsed=!0,(f={specularFactor:g,specularTexture:h,specularColorFactor:_,specularColorTexture:d,extensions:{}}).extensions.EXT_materials_specular_edge_color={specularEdgeColorEnabled:!0},(u=n._exporter._glTF).extensionsUsed||(u.extensionsUsed=[]),-1===n._exporter._glTF.extensionsUsed.indexOf("EXT_materials_specular_edge_color")&&n._exporter._glTF.extensionsUsed.push("EXT_materials_specular_edge_color"),(h||d)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[He]=f}e(t)}))},e}();re.RegisterExtension(He,(function(e){return new Ge(e)}));var We="KHR_materials_transmission",qe=function(){function e(e){this.name=We,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,t,r){return g(this,void 0,void 0,(function(){var e;return _(this,(function(t){return e=[],r instanceof p.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&e.push(r.subSurface.thicknessTexture),[2,e]):[2,e]}))}))},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return t.isRefractionEnabled&&null!=t.refractionIntensity&&0!=t.refractionIntensity||this._hasTexturesExtension(e)},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.refractionIntensityTexture},e.prototype.postExportMaterialAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,s,o,i;return _(this,(function(a){switch(a.label){case 0:return r instanceof p.PBRMaterial&&this._isExtensionEnabled(r)?(this._wasUsed=!0,n=r.subSurface,s=0===n.refractionIntensity?void 0:n.refractionIntensity,o={transmissionFactor:s},this._hasTexturesExtension(r)&&this._exporter._materialNeedsUVsSet.add(r),n.refractionIntensityTexture?n.useGltfStyleTextures?[4,this._exporter._materialExporter.exportTextureAsync(n.refractionIntensityTexture)]:[3,2]:[3,3]):[3,4];case 1:return(i=a.sent())&&(o.transmissionTexture=i),[3,3];case 2:p.Logger.Warn("".concat(e,": Exporting a subsurface refraction intensity texture without `useGltfStyleTextures` is not supported")),a.label=3;case 3:t.extensions||(t.extensions={}),t.extensions[We]=o,a.label=4;case 4:return[2,t]}}))}))},e}();re.RegisterExtension(We,(function(e){return new qe(e)}));var ze="KHR_materials_unlit",je=function(){function e(){this.name=ze,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,t,r){var n=this;return new Promise((function(e){var s=!1;r instanceof p.PBRMaterial?s=r.unlit:r instanceof p.StandardMaterial&&(s=r.disableLighting),s&&(n._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[ze]={}),e(t)}))},e}();re.RegisterExtension(ze,(function(){return new je}));var Xe="KHR_materials_volume",Qe=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,t,r){return g(this,void 0,void 0,(function(){var e;return _(this,(function(t){return e=[],r instanceof p.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&e.push(r.subSurface.thicknessTexture),[2,e]):[2,e]}))}))},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isTranslucencyEnabled)&&(null!=t.maximumThickness&&0!=t.maximumThickness||null!=t.tintColorAtDistance&&t.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=t.tintColor&&t.tintColor!=p.Color3.White()||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.thicknessTexture},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var s;if(r instanceof p.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var o=r.subSurface,i={thicknessFactor:0==o.maximumThickness?void 0:o.maximumThickness,thicknessTexture:null!==(s=n._exporter._materialExporter.getTextureInfo(o.thicknessTexture))&&void 0!==s?s:void 0,attenuationDistance:o.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:o.tintColorAtDistance,attenuationColor:o.tintColor.equalsFloats(1,1,1)?void 0:o.tintColor.asArray()};n._hasTexturesExtension(r)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions=t.extensions||{},t.extensions[Xe]=i}e(t)}))},e}();re.RegisterExtension(Xe,(function(e){return new Qe(e)}));var Ye="KHR_materials_diffuse_roughness",Ze=function(){function e(e){this.name=Ye,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,t,r){return g(this,void 0,void 0,(function(){var e;return _(this,(function(t){if(e=[],r instanceof p.PBRBaseMaterial){if(r._baseDiffuseRoughness)return r._baseDiffuseRoughnessTexture&&e.push(r._baseDiffuseRoughnessTexture),[2,e]}else if(r instanceof p.OpenPBRMaterial&&r.baseDiffuseRoughness)return r.baseDiffuseRoughnessTexture&&e.push(r.baseDiffuseRoughnessTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var s=null,o=null;if(r instanceof p.PBRBaseMaterial?(s=r._baseDiffuseRoughness,o=r._baseDiffuseRoughnessTexture):r instanceof p.OpenPBRMaterial&&(s=r.baseDiffuseRoughness,o=r.baseDiffuseRoughnessTexture),s){n._wasUsed=!0,t.extensions=t.extensions||{};var i=n._exporter._materialExporter.getTextureInfo(o),a={diffuseRoughnessFactor:s,diffuseRoughnessTexture:null!=i?i:void 0};null!==a.diffuseRoughnessTexture&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[Ye]=a,e(t)}else e(t)}))},e}();re.RegisterExtension(Ye,(function(e){return new Ze(e)}));var Je="KHR_texture_transform",$e=function(){function e(){this.name=Je,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,t,r){if(r.getScene()||p.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(r.name,"!")),0===r.uAng&&0===r.vAng||(p.Tools.Warn("".concat(e,": Texture ").concat(r.name," with rotation in the u or v axis is not supported in glTF.")),0===r.uRotationCenter&&0===r.vRotationCenter)){var n={},s=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],s=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],s=!0),0!==r.wAng){if(0!==r.uRotationCenter||0!==r.vRotationCenter){if(r.homogeneousRotationInUVTransform&&r.uScale!==r.vScale)return void p.Tools.Warn("".concat(e,": Texture ").concat(r.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(Je,"."));p.Tools.Warn("".concat(e,": Texture ").concat(r.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(Je,".")),n.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,f=s*i;return[t+(l*(1-u)+f*c),r+(f*(1-u)-l*c)]}(r)}n.rotation=-r.wAng,s=!0}0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,s=!0),s&&(this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[Je]=n)}},e}();re.RegisterExtension(Je,(function(){return new $e}));var et="KHR_texture_basisu",tt=function(){function e(e){this.name=et,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,t){var r=this._exporter._textures[t.index],n=r.source;if(void 0!==n){var s=this._exporter._images[n];"image/ktx2"===(s.mimeType||(0,p.GetMimeType)(s.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[et]={source:n},this._wasUsed=!0)}},e}();re.RegisterExtension(et,(function(e){return new tt(e)}));var rt="EXT_texture_webp",nt=function(){function e(e){this.name=rt,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,t){var r=this._exporter._textures[t.index],n=r.source;if(void 0!==n){var s=this._exporter._images[n];"image/webp"===(s.mimeType||(0,p.GetMimeType)(s.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[rt]={source:n},this._wasUsed=!0)}},e}();re.RegisterExtension(rt,(function(e){return new nt(e)}));var st="EXT_texture_avif",ot=function(){function e(e){this.name=st,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,t){var r=this._exporter._textures[t.index],n=r.source;if(void 0!==n){var s=this._exporter._images[n];"image/avif"===(s.mimeType||(0,p.GetMimeType)(s.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[st]={source:n},this._wasUsed=!0)}},e}();re.RegisterExtension(st,(function(e){return new ot(e)}));var it=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==it){it.BABYLON=it.BABYLON||{};var at=it.BABYLON;at.GLTF2=at.GLTF2||{},at.GLTF2.Exporter=at.GLTF2.Exporter||{},at.GLTF2.Exporter.Extensions=at.GLTF2.Exporter.Extensions||{};var ut=[];for(var ct in o)at[ct]=o[ct],ut.push(ct);for(var ct in i)at[ct]=i[ct],ut.push(ct);for(var ct in a)at[ct]=a[ct],ut.push(ct);for(var ct in u)at.GLTF2.Exporter.Extensions[ct]=u[ct],ut.push(ct);for(var ct in c)ut.indexOf(ct)>-1||(at.GLTF2.Exporter[ct]=c[ct])}const lt=l;return s.default})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.SERIALIZERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(e=>(()=>{"use strict";var t={597:t=>{t.exports=e}},r={};function n(e){var s=r[e];if(void 0!==s)return s.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};n.d(s,{default:()=>lt});var i={};n.r(i),n.d(i,{__IGLTFExporterExtension:()=>f});var o={};n.r(o),n.d(o,{GLTFData:()=>h});var a={};n.r(a),n.d(a,{GLTF2Export:()=>ne});var u={};n.r(u),n.d(u,{EXT_mesh_gpu_instancing:()=>ie,EXT_texture_avif:()=>it,EXT_texture_webp:()=>nt,KHR_draco_mesh_compression:()=>ae,KHR_lights_punctual:()=>pe,KHR_materials_anisotropy:()=>_e,KHR_materials_clearcoat:()=>me,KHR_materials_clearcoat_anisotropy:()=>Ce,KHR_materials_clearcoat_color:()=>we,KHR_materials_clearcoat_darkening:()=>ve,KHR_materials_clearcoat_ior:()=>be,KHR_materials_diffuse_roughness:()=>Ze,KHR_materials_diffuse_transmission:()=>Be,KHR_materials_dispersion:()=>Fe,KHR_materials_emissive_strength:()=>Ne,KHR_materials_ior:()=>Pe,KHR_materials_iridescence:()=>Ke,KHR_materials_sheen:()=>De,KHR_materials_specular:()=>Ge,KHR_materials_transmission:()=>qe,KHR_materials_unlit:()=>je,KHR_materials_volume:()=>Qe,KHR_texture_basisu:()=>tt,KHR_texture_transform:()=>$e});var c={};n.r(c),n.d(c,{EXT_mesh_gpu_instancing:()=>ie,EXT_texture_avif:()=>it,EXT_texture_webp:()=>nt,GLTF2Export:()=>ne,GLTFData:()=>h,KHR_draco_mesh_compression:()=>ae,KHR_lights_punctual:()=>pe,KHR_materials_anisotropy:()=>_e,KHR_materials_clearcoat:()=>me,KHR_materials_clearcoat_anisotropy:()=>Ce,KHR_materials_clearcoat_color:()=>we,KHR_materials_clearcoat_darkening:()=>ve,KHR_materials_clearcoat_ior:()=>be,KHR_materials_diffuse_roughness:()=>Ze,KHR_materials_diffuse_transmission:()=>Be,KHR_materials_dispersion:()=>Fe,KHR_materials_emissive_strength:()=>Ne,KHR_materials_ior:()=>Pe,KHR_materials_iridescence:()=>Ke,KHR_materials_sheen:()=>De,KHR_materials_specular:()=>Ge,KHR_materials_transmission:()=>qe,KHR_materials_unlit:()=>je,KHR_materials_volume:()=>Qe,KHR_texture_basisu:()=>tt,KHR_texture_transform:()=>$e,_ConvertToGLTFPBRMetallicRoughness:()=>E,_SolveMetallic:()=>w});var l={};n.r(l),n.d(l,{EXT_mesh_gpu_instancing:()=>ie,EXT_texture_avif:()=>it,EXT_texture_webp:()=>nt,GLTF2Export:()=>ne,GLTFData:()=>h,KHR_draco_mesh_compression:()=>ae,KHR_lights_punctual:()=>pe,KHR_materials_anisotropy:()=>_e,KHR_materials_clearcoat:()=>me,KHR_materials_clearcoat_anisotropy:()=>Ce,KHR_materials_clearcoat_color:()=>we,KHR_materials_clearcoat_darkening:()=>ve,KHR_materials_clearcoat_ior:()=>be,KHR_materials_diffuse_roughness:()=>Ze,KHR_materials_diffuse_transmission:()=>Be,KHR_materials_dispersion:()=>Fe,KHR_materials_emissive_strength:()=>Ne,KHR_materials_ior:()=>Pe,KHR_materials_iridescence:()=>Ke,KHR_materials_sheen:()=>De,KHR_materials_specular:()=>Ge,KHR_materials_transmission:()=>qe,KHR_materials_unlit:()=>je,KHR_materials_volume:()=>Qe,KHR_texture_basisu:()=>tt,KHR_texture_transform:()=>$e,_ConvertToGLTFPBRMetallicRoughness:()=>E,_SolveMetallic:()=>w,__IGLTFExporterExtension:()=>f});var f=0,p=n(597),h=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 t=this.files[e],r=new Blob([t],{type:(0,p.GetMimeType)(e)});p.Tools.Download(r,e)}},e}(),d=function(){return d=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},d.apply(this,arguments)};function g(e,t,r,n){return new(r||(r=Promise))((function(s,i){function o(e){try{u(n.next(e))}catch(e){i(e)}}function a(e){try{u(n.throw(e))}catch(e){i(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(o,a)}u((n=n.apply(e,t||[])).next())}))}function _(e,t){var r,n,s,i={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(i=0)),i;)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 i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((s=(s=i.trys).length>0&&s[s.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!s||a[1]>s[0]&&a[1]<s[3])){i.label=a[1];break}if(6===a[0]&&i.label<s[1]){i.label=s[1],s=a;break}if(s&&i.label<s[2]){i.label=s[2],i.ops.push(a);break}s[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}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 x(e,t,r){if(r||2===arguments.length)for(var n,s=0,i=t.length;s<i;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 m=1e-6,y=new p.Color3(.04,.04,.04),v=1024,T=p.Color3.White(),b=p.Color3.BlackReadOnly;function A(e){return g(this,void 0,void 0,(function(){var t,r,n,s;return _(this,(function(i){switch(i.label){case 0:return(t=e.getInternalTexture())&&1===t.source?t.invertY?[2,null]:(r=t._buffer,s=e.mimeType,r?[3,2]:[4,p.Tools.LoadFileAsync(t.url)]):[2,null];case 1:return n=i.sent(),s=(0,p.GetMimeType)(t.url)||s,[3,10];case 2:return ArrayBuffer.isView(r)?(n=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),[3,10]):[3,3];case 3:return r instanceof ArrayBuffer?(n=r,[3,10]):[3,4];case 4:return r instanceof Blob?[4,r.arrayBuffer()]:[3,6];case 5:return n=i.sent(),s=r.type||s,[3,10];case 6:return"string"!=typeof r?[3,8]:[4,p.Tools.LoadFileAsync(r)];case 7:return n=i.sent(),s=(0,p.GetMimeType)(r)||s,[3,10];case 8:return"undefined"!=typeof HTMLImageElement&&r instanceof HTMLImageElement?[4,p.Tools.LoadFileAsync(r.src)]:[3,10];case 9:n=i.sent(),s=(0,p.GetMimeType)(r.src)||s,i.label=10;case 10:return n&&s?[2,{data:n,mimeType:s}]:[2,null]}}))}))}function w(e,t,r){if(t<y.r)return 0;var n=y.r,s=e*r/(1-y.r)+t-2*y.r,i=s*s-4*n*(y.r-t);return p.Scalar.Clamp((-s+Math.sqrt(i))/(2*n),0,1)}function E(e){var t=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),r=e.alpha,n=p.Scalar.Clamp(e.specularPower,0,v),s=(0,p.SpecularPowerToRoughness)(n);return{baseColorFactor:[t.r,t.g,t.b,r],metallicFactor:0,roughnessFactor:s}}function M(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function R(e,t,r){for(var n=new Uint8Array(e*t*4),s=0;s<n.length;s+=4)n[s]=n[s+1]=n[s+2]=n[s+3]=255;return p.RawTexture.CreateRGBATexture(n,e,t,r)}function C(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 S=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))&&void 0!==t?t:null},e.prototype.exportStandardMaterialAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,s,i,o,a,u,c;return _(this,(function(l){switch(l.label){case 0:return r=E(e),n={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||p.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),t?(s=[],(i=e.diffuseTexture)&&s.push(this.exportTextureAsync(i).then((function(e){e&&(r.baseColorTexture=e)}))),(o=e.bumpTexture)&&s.push(this.exportTextureAsync(o).then((function(e){e&&(n.normalTexture=e,1!==o.level&&(n.normalTexture.scale=o.level))}))),(a=e.emissiveTexture)&&(n.emissiveFactor=[1,1,1],s.push(this.exportTextureAsync(a).then((function(e){e&&(n.emissiveTexture=e)})))),(u=e.ambientTexture)&&s.push(this.exportTextureAsync(u).then((function(e){if(e){var t={index:e.index};n.occlusionTexture=t}}))),s.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(s)]):[3,2]):[3,2];case 1:l.sent(),l.label=2;case 2:return(e.alpha<1||e.opacityTexture)&&(e.alphaMode===p.Constants.ALPHA_COMBINE?n.alphaMode="BLEND":p.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(b,m)&&(n.emissiveFactor=e.emissiveColor.asArray()),n.pbrMetallicRoughness=r,M(n,e),[4,this._finishMaterialAsync(n,e)];case 3:return l.sent(),(c=this._exporter._materials).push(n),[2,c.length-1]}}))}))},e.prototype._finishMaterialAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,s,i,o;return _(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,i=r;s<i.length;s++)o=i[s],n.push(this.exportTextureAsync(o));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._getImageDataAsync=function(e,t,r,n){return g(this,void 0,void 0,(function(){return _(this,(function(s){switch(s.label){case 0:return[4,p.DumpTools.DumpDataAsync(t,r,e,n,void 0,!1,!0)];case 1:return[2,s.sent()]}}))}))},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,s,i=e?e.getSize():{width:0,height:0},o=t?t.getSize():{width:0,height:0};return i.width<o.width?(n=e&&e instanceof p.Texture?p.TextureTools.CreateResizedCopy(e,o.width,o.height,!0):R(o.width,o.height,r),s=t):i.width>o.width?(s=t&&t instanceof p.Texture?p.TextureTools.CreateResizedCopy(t,i.width,i.height,!0):R(i.width,i.height,r),n=e):(n=e,s=t),{texture1:n,texture2:s}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,r,n){return g(this,void 0,void 0,(function(){var s,i,o,a,u,c,l,f,h,d,g,x,y,v,b,A,w,E,M,R,S,V,B,I,F,U,N,O,P,L,K;return _(this,(function(_){switch(_.label){case 0:return s=new Array,e||t?[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,_.sent()];case 2:return(i=e?e.getScene():t?t.getScene():null)?(o=this._resizeTexturesToSameDimensions(e,t,i),a=null===(K=o.texture1)||void 0===K?void 0:K.getSize(),u=void 0,c=void 0,l=a.width,f=a.height,[4,o.texture1.readPixels()]):[3,12];case 3:return h=_.sent(),[4,o.texture2.readPixels()];case 4:return d=_.sent(),h?(u=C(h),[3,7]):[3,5];case 5:return[4,Promise.reject("Failed to retrieve pixels from diffuse texture!")];case 7:return d?(c=C(d),[3,10]):[3,8];case 8:return[4,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];case 10:for(g=c.byteLength,x=new Uint8Array(g),y=new Uint8Array(g),v=new p.Color3(0,0,0),b=0,A=0,U=0;U<f;++U)for(N=0;N<l;++N)w=4*(l*U+N),E=new p.Color3(u[w],u[w+1],u[w+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(r.diffuseColor),M=new p.Color3(c[w],c[w+1],c[w+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(r.specularColor),R=c[w+3]*r.glossiness,S={diffuseColor:E,specularColor:M,glossiness:R},V=this._convertSpecularGlossinessToMetallicRoughness(S),v.r=Math.max(v.r,V.baseColor.r),v.g=Math.max(v.g,V.baseColor.g),v.b=Math.max(v.b,V.baseColor.b),b=Math.max(b,V.metallic),A=Math.max(A,V.roughness),y[w]=255*V.baseColor.r,y[w+1]=255*V.baseColor.g,y[w+2]=255*V.baseColor.b,y[w+3]=o.texture1.hasAlpha?255*u[w+3]:255,x[w]=0,x[w+1]=255*V.roughness,x[w+2]=255*V.metallic,x[w+3]=255;for(B={baseColor:v,metallic:b,roughness:A},I=!1,F=!1,U=0;U<f;++U)for(N=0;N<l;++N)y[O=4*(l*U+N)]/=B.baseColor.r>m?B.baseColor.r:1,y[O+1]/=B.baseColor.g>m?B.baseColor.g:1,y[O+2]/=B.baseColor.b>m?B.baseColor.b:1,P=p.Color3.FromInts(y[O],y[O+1],y[O+2]),L=P.toGammaSpace(i.getEngine().useExactSrgbConversions),y[O]=255*L.r,y[O+1]=255*L.g,y[O+2]=255*L.b,L.equalsWithEpsilon(T,m)||(F=!0),x[O+1]/=B.roughness>m?B.roughness:1,x[O+2]/=B.metallic>m?B.metallic:1,p.Color3.FromInts(255,x[O+1],x[O+2]).equalsWithEpsilon(T,m)||(I=!0);return I&&s.push(this._getImageDataAsync(x,l,f,n).then((function(e){B.metallicRoughnessTextureData=e}))),F&&s.push(this._getImageDataAsync(y,l,f,n).then((function(e){B.baseColorTextureData=e}))),[4,Promise.all(s).then((function(){return B}))];case 12:return[4,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}}))}))},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var t=this._getPerceivedBrightness(e.diffuseColor),r=this._getPerceivedBrightness(e.specularColor),n=1-this._getMaxComponent(e.specularColor),s=w(t,r,n),i=e.diffuseColor.scale(n/(1-y.r)/Math.max(1-s,m)),o=e.specularColor.subtract(y.scale(1-s)).scale(1/Math.max(s,m)),a=p.Color3.Lerp(i,o,s*s);return{baseColor:a=a.clampToRef(0,1,a),metallic:s,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,t,r,n,s,i,o,a,u){return g(this,void 0,void 0,(function(){var i,c;return _(this,(function(l){switch(l.label){case 0:return i=[],c={baseColor:e,metallic:t,roughness:r},u&&(n&&i.push(this.exportTextureAsync(n).then((function(e){e&&(a.baseColorTexture=e)}))),s&&i.push(this.exportTextureAsync(s).then((function(e){e&&(a.metallicRoughnessTexture=e)})))),i.length>0?(this._exporter._materialNeedsUVsSet.add(o),[4,Promise.all(i)]):[3,2];case 1:l.sent(),l.label=2;case 2:return[2,c]}}))}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof p.Texture))return t;var r=this._getGLTFTextureWrapMode(e.wrapU);10497!==r&&(t.wrapS=r);var n=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==n&&(t.wrapT=n),e.samplingMode){case p.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case p.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case p.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case p.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case p.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case p.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case p.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case p.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case p.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case p.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case p.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case p.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case p.Texture.WRAP_ADDRESSMODE:return 10497;case p.Texture.CLAMP_ADDRESSMODE:return 33071;case p.Texture.MIRROR_ADDRESSMODE:return 33648;default:return p.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,s,i,o,a,u,c,l,f;return _(this,(function(p){switch(p.label){case 0:return n="image/png",s={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},i=e._albedoTexture,o=e._reflectivityTexture,a=e._useMicroSurfaceFromReflectivityMapAlpha,!o||a?[3,2]:[4,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")];case 1:return[2,p.sent()];case 2:return(i||o)&&r?(this._exporter._materialNeedsUVsSet.add(e),u=this._exportTextureSampler(i||o),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(i,o,s,n)]):[3,4];case 3:return c=p.sent(),l=this._exporter._textures,c.baseColorTextureData&&(f=this._exportImage("baseColor".concat(l.length),n,c.baseColorTextureData),t.baseColorTexture=this._exportTextureInfo(f,u,null==i?void 0:i.coordinatesIndex)),c.metallicRoughnessTextureData&&(f=this._exportImage("metallicRoughness".concat(l.length),n,c.metallicRoughnessTextureData),t.metallicRoughnessTexture=this._exportTextureInfo(f,u,null==o?void 0:o.coordinatesIndex)),[2,c];case 4:return[2,this._convertSpecularGlossinessToMetallicRoughness(s)]}}))}))},e.prototype.exportPBRMaterialAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,s,i,o,a,u,c;return _(this,(function(l){switch(l.label){case 0:return r={},n={name:e.name},(s=e.isMetallicWorkflow())&&(i=e._albedoColor,o=e.alpha,i&&(r.baseColorFactor=[i.r,i.g,i.b,o])),s?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e._albedoColor,e._metallic,e._roughness,e._albedoTexture,e._metallicTexture,e._metallicTexture,e,r,t)]:[3,2];case 1:return u=l.sent(),[3,4];case 2:return[4,this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,r,t)];case 3:u=l.sent(),l.label=4;case 4:return a=u,[4,this._setMetallicRoughnessPbrMaterialAsync(a,e,n,r,t)];case 5:return l.sent(),[4,this._finishMaterialAsync(n,e)];case 6:return l.sent(),(c=this._exporter._materials).push(n),[2,c.length-1]}}))}))},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,t,r,n,s){return g(this,void 0,void 0,(function(){var i,o,a,u,c;return _(this,(function(l){switch(l.label){case 0:return M(r,t),e.baseColor.equalsWithEpsilon(T,m)&&p.Scalar.WithinEpsilon(t.alpha,1,m)||(n.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,t.alpha]),null!=e.metallic&&1!==e.metallic&&(n.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(n.roughnessFactor=e.roughness),null==t.backFaceCulling||t.backFaceCulling||(t._twoSidedLighting||p.Tools.Warn(t.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),s?(i=[],(o=t instanceof p.PBRBaseMaterial?t._bumpTexture:t.geometryNormalTexture)&&i.push(this.exportTextureAsync(o).then((function(e){e&&(r.normalTexture=e,1!==o.level&&(r.normalTexture.scale=o.level))}))),(a=t instanceof p.PBRBaseMaterial?t._ambientTexture:t.ambientOcclusionTexture)&&i.push(this.exportTextureAsync(a).then((function(e){if(e){var n={index:e.index,texCoord:e.texCoord,extensions:e.extensions};r.occlusionTexture=n,t instanceof p.PBRBaseMaterial?n.strength=t._ambientTextureStrength:n.strength=t.ambientOcclusionTexture.level}}))),(u=t instanceof p.PBRBaseMaterial?t._emissiveTexture:t.emissionColorTexture)&&i.push(this.exportTextureAsync(u).then((function(e){e&&(r.emissiveTexture=e)}))),i.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(i)]):[3,2]):[3,2];case 1:l.sent(),l.label=2;case 2:return(c=t instanceof p.PBRBaseMaterial?t._emissiveColor:t.emissionColor).equalsWithEpsilon(b,m)||(r.emissiveFactor=c.asArray()),r.pbrMetallicRoughness=n,[2]}}))}))},e.prototype.exportOpenPBRMaterialAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,s,i,o,a;return _(this,(function(u){switch(u.label){case 0:return r={},n={name:e.name},s=e.baseColor,i=e.geometryOpacity,s&&(r.baseColorFactor=[s.r,s.g,s.b,i]),[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e.baseColor,e.baseMetalness,e.specularRoughness,e.baseColorTexture,e.baseMetalnessTexture,e.specularRoughnessTexture,e,r,t)];case 1:return o=u.sent(),[4,this._setMetallicRoughnessPbrMaterialAsync(o,e,n,r,t)];case 2:return u.sent(),[4,this._finishMaterialAsync(n,e)];case 3:return u.sent(),(a=this._exporter._materials).push(n),[2,a.length-1]}}))}))},e.prototype.exportTextureAsync=function(e){return g(this,void 0,void 0,(function(){var t,r,n;return _(this,(function(s){switch(s.label){case 0:return(t=this._textureMap.get(e))?[2,t]:(r=this._exportTextureSampler(e),[4,this._exportTextureImageAsync(e)]);case 1:return n=s.sent(),t=this._exportTextureInfo(n,r,e.coordinatesIndex),this._textureMap.set(e,t),this._exporter._extensionsPostExportTextures("exporter",t,e),[2,t]}}))}))},e.prototype._exportTextureImageAsync=function(e){return g(this,void 0,void 0,(function(){var t,r,n,s,i,o=this;return _(this,(function(a){switch(a.label){case 0:return t=null!==(i=e.mimeType)&&void 0!==i?i:"none",r=this._internalTextureToImage,n=e.getInternalTexture().uniqueId,r[n]=r[n]||{},void 0===(s=r[n][t])&&(s=g(o,void 0,void 0,(function(){var r,n,s,i,o;return _(this,(function(a){switch(a.label){case 0:return[4,A(e)];case 1:if((r=a.sent())&&("none"===t||r.mimeType===t))return[2,this._exportImage(e.name,r.mimeType,r.data)];if(n="image/png","none"!==t)switch(t){case"image/jpeg":case"image/png":case"image/webp":n=t;break;default:p.Tools.Warn("Unsupported media type: ".concat(t,". Exporting texture as PNG."))}return s=e.getSize(),[4,(0,p.GetTextureDataAsync)(e)];case 2:return i=a.sent(),[4,this._getImageDataAsync(i,s.width,s.height,n)];case 3:return o=a.sent(),[2,this._exportImage(e.name,n,o)]}}))})),r[n][t]=s),[4,s];case 1:return[2,a.sent()]}}))}))},e.prototype._exportImage=function(e,t,r){var n,s=this._exporter._images;if(this._exporter._shouldUseGlb){n={name:e,mimeType:t,bufferView:void 0};var i=this._exporter._bufferManager.createBufferView(new Uint8Array(r));this._exporter._bufferManager.setBufferView(n,i)}else{var o=e.replace(/\.\/|\/|\.\\|\\/g,"_"),a=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"}}(t),u=o+a;s.some((function(e){return e.uri===u}))&&(u="".concat(o,"_").concat(p.Tools.RandomId()).concat(a)),n={name:e,uri:u},this._exporter._imageData[u]={data:r,mimeType:t}}return s.push(n),s.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 i={index:s};return r&&(i.texCoord=r),i},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=p.Matrix.Compose(new p.Vector3(-1,1,1),p.Quaternion.Identity(),p.Vector3.Zero());function B(e,t){if(!(e instanceof p.TransformNode))return!1;if(t){if(!e.getWorldMatrix().equalsWithEpsilon(p.Matrix.IdentityReadOnly,p.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(V,p.TmpVectors.Matrix[0]).equalsWithEpsilon(p.Matrix.IdentityReadOnly,p.Epsilon))return!1;return!(e instanceof p.AbstractMesh&&e.geometry)}var I=p.Vector3.ZeroReadOnly,F=p.Quaternion.Identity(),U=p.Vector3.OneReadOnly,N=new p.Vector3(-1,1,1);function O(e,t){var r=e.byteOffset,n=e.byteStride,s=e.type,i=e.normalized,o=e.getSize(),a=t.reduce((function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e}),-Number.MAX_VALUE);return{byteOffset:r,byteStride:n,componentCount:o,type:s,count:a*o,normalized:i,totalVertices:a,kind:e.getKind()}}function P(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 L(e){switch(e){case p.VertexBuffer.PositionKind:case p.VertexBuffer.NormalKind:case p.VertexBuffer.TangentKind:case p.VertexBuffer.ColorKind:case p.VertexBuffer.MatricesIndicesKind:case p.VertexBuffer.MatricesIndicesExtraKind:case p.VertexBuffer.MatricesWeightsKind:case p.VertexBuffer.MatricesWeightsExtraKind:case p.VertexBuffer.UVKind:case p.VertexBuffer.UV2Kind:case p.VertexBuffer.UV3Kind:case p.VertexBuffer.UV4Kind:case p.VertexBuffer.UV5Kind:case p.VertexBuffer.UV6Kind:return!0}return!1}function K(e){switch(e){case p.Material.TriangleFillMode:return 4;case p.Material.TriangleStripDrawMode:return 5;case p.Material.TriangleFanDrawMode:return 6;case p.Material.PointListDrawMode:case p.Material.PointFillMode:return 0;case p.Material.LineLoopDrawMode:return 2;case p.Material.LineListDrawMode:return 1;case p.Material.LineStripDrawMode:return 3}throw new Error("Unknown fill mode: ".concat(e))}function k(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 D(e){return e.x*=-1,e}function H(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),i=Math.abs(e.w);s>i?(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=i)}return e}function G(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function W(e,t){var r=p.Vector3.FromArrayToRef(t.translation||[0,0,0],0,p.TmpVectors.Vector3[0]),n=p.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,p.TmpVectors.Quaternion[0]),s=p.Matrix.ComposeToRef(U,n,r,p.TmpVectors.Matrix[0]),i=p.Vector3.FromArrayToRef(e.translation||[0,0,0],0,p.TmpVectors.Vector3[2]),o=p.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,p.TmpVectors.Quaternion[1]),a=p.Matrix.ComposeToRef(U,o,i,p.TmpVectors.Matrix[1]);s.multiplyToRef(a,a),a.decompose(void 0,n,r),r.equalsWithEpsilon(I,p.Epsilon)?delete t.translation:t.translation=r.asArray(),n.equalsWithEpsilon(F,p.Epsilon)?delete t.rotation:t.rotation=n.asArray(),t.scale&&delete t.scale}function q(e,t){if(!(t instanceof p.TransformNode))return!1;if(1!==t.getChildren().length||0!==e.getChildren().length||e.parent!==t)return!1;var r=e.getScene(),n=e instanceof p.TargetCamera&&!r.useRightHandedSystem?N:U;return!!t.scaling.equalsWithEpsilon(n,p.Epsilon)||(p.Logger.Warn("Cannot collapse node ".concat(e.name," into parent node ").concat(t.name," with modified scaling.")),!1)}function z(e,t){for(var r=0,n=Object.entries(e);r<n.length;r++){var s=n[r],i=s[0],o=s[1],a=t[i];(Array.isArray(o)&&Array.isArray(a)&&j(o,a)||o===a)&&delete e[i]}return e}function j(e,t){return e.length===t.length&&e.every((function(e,r){return e===t[r]}))}var X=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)}]]),Q=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=X.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 Y(e){return e%4==0?4:e%2==0?2:1}var Z,J=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 Q(t),n=0,s=Array.from(this._bufferViewToData.keys()).sort((function(e,t){return Y(t.byteLength)-Y(e.byteLength)}));n<s.length;n++){var i=s[n];i.byteOffset=r.byteOffset,e.push(i);for(var o=e.length-1,a=0,u=this.getPropertiesWithBufferView(i);a<u.length;a++)u[a].bufferView=o;r.writeTypedArray(this._bufferViewToData.get(i)),this._bufferViewToData.delete(i)}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,i,o){this._verifyBufferView(e);var a={bufferView:void 0,componentType:r,count:n,type:t,min:null==i?void 0:i.min,max:null==i?void 0:i.max,normalized:o,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"}(Z||(Z={}));var $=function(){function e(){}return e._IsTransformable=function(e){return e&&(e instanceof p.TransformNode||e instanceof p.Camera||e instanceof p.Light)},e._CreateNodeAnimation=function(t,r,n,s,i){if(this._IsTransformable(t)){var o=[],a=[],u=r.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,n,s),f=l.interpolationType,h=l.shouldBakeAnimation;if(h?e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,i,o,a,c,s):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(t,r,n,o,a,s):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(t,r,n,o,a,s):e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,i,o,a,c,s),o.length&&a.length)return{inputs:o,outputs:a,samplerInterpolation:f,inputsMin:h?c.min:p.Tools.FloatRound(c.min/r.framePerSecond),inputsMax:h?c.max:p.Tools.FloatRound(c.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,s=e.targetProperty.split(".");switch(s[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":r="VEC4",t="rotation";break;case"rotationQuaternion":r="VEC4",n=!0,t="rotation";break;case"influence":r="SCALAR",t="weights";break;default:p.Tools.Error("Unsupported animatable property ".concat(s[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(p.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,r,n,s,i,o,a,u,c,l,f){var p;if(e._IsTransformable(t)&&t.animations)for(var h=0,d=t.animations;h<d.length;h++){var g=d[h];if(!f||f(g)){var _=e._DeduceAnimationInfo(g);_&&(p={name:g.name,samplers:[],channels:[]},e._AddAnimation("".concat(g.name),g.hasRunningRuntimeAnimations?r:p,t,g,_.dataAccessorType,_.animationChannelTargetPath,s,o,a,u,_.useQuaternion,c,l),p.samplers.length&&p.channels.length&&n.push(p))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,s,i,o,a,u,c,l,f){var h;if(t instanceof p.Mesh){var d=t.morphTargetManager;if(d)for(var g=0;g<d.numTargets;++g)for(var _=0,x=d.getTarget(g).animations;_<x.length;_++){var m=x[_];if(!f||f(m)){for(var y=new p.Animation("".concat(m.name),"influence",m.framePerSecond,m.dataType,m.loopMode,m.enableBlending),v=[],T=m.getKeys(),b=0;b<T.length;++b)for(var A=T[b],w=0;w<d.numTargets;++w)w==g?v.push(A):v.push({frame:A.frame,value:0});y.setKeys(v);var E=e._DeduceAnimationInfo(y);E&&(h={name:y.name,samplers:[],channels:[]},e._AddAnimation(m.name,m.hasRunningRuntimeAnimations?r:h,t,y,E.dataAccessorType,E.animationChannelTargetPath,s,o,a,u,E.useQuaternion,c,l,d.numTargets),h.samplers.length&&h.channels.length&&n.push(h))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,s,i,o,a,u,c){var l,f;if(t.animationGroups)for(var h=t.animationGroups,d=function(h){var d=new Map,_=new Map,x=new Set,m=h.to-h.from;f={name:h.name,channels:[],samplers:[]};for(var y=function(r){var m=h.targetedAnimations[r],y=m.target,v=m.animation;if(c&&!c(v))return"continue";var T=u.has(y);if(g._IsTransformable(y)||1===y.length&&g._IsTransformable(y[0])){if(A=e._DeduceAnimationInfo(m.animation)){var b=g._IsTransformable(y)?y:g._IsTransformable(y[0])?y[0]:null;b&&e._AddAnimation("".concat(v.name),f,b,v,A.dataAccessorType,A.animationChannelTargetPath,n,s,i,o,A.useQuaternion,a,T)}}else if(y instanceof p.MorphTarget||1===y.length&&y[0]instanceof p.MorphTarget){var A;if(A=e._DeduceAnimationInfo(m.animation)){var w=y instanceof p.MorphTarget?y:y[0];if(w){var E=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===w)return!0;return!1}));if(E){var M=t.meshes.find((function(e){return e.morphTargetManager===E}));M&&(d.has(M)||d.set(M,new Map),null===(l=d.get(M))||void 0===l||l.set(w,v),x.add(M),_.set(M,v))}}}}},v=0;v<h.targetedAnimations.length;++v)y(v);x.forEach((function(t){for(var r=t.morphTargetManager,u=null,c=[],l=_.get(t).getKeys(),g=l.length,x=0;x<g;++x)for(var y=0;y<r.numTargets;++y){var v=r.getTarget(y),T=d.get(t);if(T){var b=T.get(v);b?(u||(u=new p.Animation("".concat(h.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,p.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[x])):c.push({frame:h.from+m/g*x,value:v.influence,inTangent:l[0].inTangent?0:void 0,outTangent:l[0].outTangent?0:void 0})}}u.setKeys(c);var A=e._DeduceAnimationInfo(u);A&&e._AddAnimation("".concat(h.name,"_").concat(t.name,"_MorphWeightAnimation"),f,t,u,A.dataAccessorType,A.animationChannelTargetPath,n,s,i,o,A.useQuaternion,a,!1,null==r?void 0:r.numTargets)})),f.channels.length&&f.samplers.length&&r.push(f)},g=this,_=0,x=h;_<x.length;_++)d(x[_])},e._AddAnimation=function(t,r,n,s,i,o,a,u,c,l,f,h,d,g){var _,x,m,y,v,T,b=e._CreateNodeAnimation(n,s,o,f,h);if(b){if(g){for(var A=0,w=0,E=[];b.inputs.length>0;)w=b.inputs.shift(),A%g==0&&E.push(w),A++;b.inputs=E}var M=a.get(n),R=new Float32Array(b.inputs);_=u.createBufferView(R),x=u.createAccessor(_,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(x),m=l.length-1;var C=new p.Quaternion,S=new p.Vector3,V=new p.Vector3,B=n instanceof p.Camera,I=P(i),F=new Float32Array(b.outputs.length*I);b.outputs.forEach((function(e,t){var r=e;switch(o){case"translation":d&&(p.Vector3.FromArrayToRef(e,0,V),D(V),V.toArray(r));break;case"rotation":4===e.length?p.Quaternion.FromArrayToRef(e,0,C):(r=new Array(4),p.Vector3.FromArrayToRef(e,0,S),p.Quaternion.FromEulerVectorToRef(S,C)),d&&(H(C),B&&G(C)),C.toArray(r)}F.set(r,t*I)})),_=u.createBufferView(F),x=u.createAccessor(_,i,5126,b.outputs.length),l.push(x),y=l.length-1,v={interpolation:b.samplerInterpolation,input:m,output:y},r.samplers.push(v),T={sampler:r.samplers.length-1,target:{node:M,path:o}},r.channels.push(T)}},e._CreateBakedAnimation=function(t,r,n,s,i,o,a,u,c,l,f){var h,d,g=p.Quaternion.Identity(),_=null,x=null,m=null,y=null,v=null,T=null;l.min=p.Tools.FloatRound(s/o);for(var b=r.getKeys(),A=0,w=b.length;A<w;++A){if(T=null,m=b[A],A+1<w)if(y=b[A+1],m.value.equals&&m.value.equals(y.value)||m.value===y.value){if(0!==A)continue;T=m.frame}else T=y.frame;else{if(v=b[A-1],m.value.equals&&m.value.equals(v.value)||m.value===v.value)continue;T=i}if(T)for(var E=m.frame;E<=T;E+=a)if((d=p.Tools.FloatRound(E/o))!==_){_=d,x=d;var M={key:0,repeatCount:0,loopMode:r.loopMode};h=r._interpolate(E,M),e._SetInterpolatedValue(t,h,d,r,n,g,u,c,f)}}x&&(l.max=x)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,s,i){var o=e._GetBasePositionRotationOrScale(r,s,i),a=n.targetProperty.split("."),u=a?a[1]:"",c=i?p.Quaternion.FromArray(o).normalize():p.Vector3.FromArray(o);switch(u){case"x":case"y":case"z":c[u]=t;break;case"w":c.w=t;break;default:p.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return c},e._SetInterpolatedValue=function(e,t,r,n,s,i,o,a,u){var c;o.push(r),"weights"!==s?(n.dataType===p.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,s,u)),"rotation"===s?(u?i=t:(c=t,p.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,i)),a.push(i.asArray())):(c=t,a.push(c.asArray()))):a.push([t])},e._CreateLinearOrStepAnimation=function(t,r,n,s,i,o){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,i,n,t,o)}},e._CreateCubicSplineAnimation=function(t,r,n,s,i,o){r.getKeys().forEach((function(a){s.push(a.frame/r.framePerSecond),e._AddSplineTangent(Z.INTANGENT,i,n,"CUBICSPLINE",a,o),e._AddKeyframeValue(a,r,i,n,t,o),e._AddSplineTangent(Z.OUTTANGENT,i,n,"CUBICSPLINE",a,o)}))},e._GetBasePositionRotationOrScale=function(e,t,r){var n;if("rotation"===t)if(r){var s=e.rotationQuaternion;n=(null!=s?s:p.Quaternion.Identity()).asArray()}else{var i=e.rotation;n=(null!=i?i:p.Vector3.Zero()).asArray()}else if("translation"===t){var o=e.position;n=(null!=o?o:p.Vector3.Zero()).asArray()}else{var a=e.scaling;n=(null!=a?a:p.Vector3.One()).asArray()}return n},e._AddKeyframeValue=function(e,t,r,n,s,i){var o,a=t.dataType;if(a===p.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===n){var c=p.Vector3.FromArray(u);u=p.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}r.push(u)}else if(a===p.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(o=this._ConvertFactorToVector3OrQuaternion(e.value,s,t,n,i)){if("rotation"===n){var l=i?o:p.Quaternion.RotationYawPitchRoll(o.y,o.x,o.z).normalize();r.push(l.asArray())}r.push(o.asArray())}}else a===p.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):p.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,s,i=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var o=0,a=e.length;o<a;++o)if((s=e[o]).inTangent||s.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",i=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||s.interpolation&&1===s.interpolation&&"STEP"!==n){n="LINEAR",i=!0;break}}else n=s.interpolation&&1===s.interpolation?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,t,r,n,s,i){var o,a=e===Z.INTANGENT?s.inTangent:s.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(a)if(i)o=a.asArray();else{var u=a;o=p.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else o=[0,0,0,0];else o="weights"===r?a?[a]:[0]:a?a.asArray():[0,0,0];t.push(o)}},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 ee(e,t,r,n,s,i){var o={attributes:{},influence:e.influence,name:e.name},a=t.geometry;if(!a)return p.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),o;var u=i?-1:1,c=p.Vector3.Zero(),l=0;if(e.hasPositions){var f=e.getPositions(),h=a.getVerticesData(p.VertexBuffer.PositionKind);if(h){var d=new Float32Array(h.length),g=[1/0,1/0,1/0],_=[-1/0,-1/0,-1/0];l=h.length/3;for(var x=0;x<l;++x){var m=p.Vector3.FromArray(h,3*x);p.Vector3.FromArray(f,3*x).subtractToRef(m,c),c.x*=u,g[0]=Math.min(g[0],c.x),_[0]=Math.max(_[0],c.x),g[1]=Math.min(g[1],c.y),_[1]=Math.max(_[1],c.y),g[2]=Math.min(g[2],c.z),_[2]=Math.max(_[2],c.z),d[3*x]=c.x,d[3*x+1]=c.y,d[3*x+2]=c.z}var y=r.createBufferView(d,12),v=r.createAccessor(y,"VEC3",5126,f.length/3,0,{min:g,max:_});s.push(v),o.attributes.POSITION=s.length-1}else p.Tools.Warn("Morph target positions for mesh ".concat(t.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var T=e.getNormals(),b=a.getVerticesData(p.VertexBuffer.NormalKind);if(b){var A=new Float32Array(b.length);for(l=b.length/3,x=0;x<l;++x){var w=p.Vector3.FromArray(b,3*x).normalize();p.Vector3.FromArray(T,3*x).normalize().subtractToRef(w,c),A[3*x]=c.x*u,A[3*x+1]=c.y,A[3*x+2]=c.z}y=r.createBufferView(A,12),v=r.createAccessor(y,"VEC3",5126,T.length/3,0),s.push(v),o.attributes.NORMAL=s.length-1}else p.Tools.Warn("Morph target normals for mesh ".concat(t.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var E=e.getTangents(),M=a.getVerticesData(p.VertexBuffer.TangentKind);if(M){l=M.length/4;var R=new Float32Array(3*l);for(x=0;x<l;++x){var C=p.Vector3.FromArray(M,4*x);k(C);var S=p.Vector3.FromArray(E,3*x);k(S),S.subtractToRef(C,c),R[3*x]=c.x*u,R[3*x+1]=c.y,R[3*x+2]=c.z}y=r.createBufferView(R,12),v=r.createAccessor(y,"VEC3",5126,l,0),s.push(v),o.attributes.TANGENT=s.length-1}else p.Tools.Warn("Morph target tangents for mesh ".concat(t.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var V=e.getColors(),B=a.getVerticesData(p.VertexBuffer.ColorKind),I=a.getVertexBuffer(p.VertexBuffer.ColorKind);if(B&&I){var F=I.getSize();l=B.length/F;var U=new Float32Array(l*F);for(x=0;x<l;++x)if(3===F){var N=p.Vector3.FromArray(B,x*F);p.Vector3.FromArray(V,x*F).subtractToRef(N,c),U[3*x]=c.x,U[3*x+1]=c.y,U[3*x+2]=c.z}else if(4===F){var O=new p.Vector4;N=p.Vector4.FromArray(B,x*F),p.Vector4.FromArray(V,x*F).subtractToRef(N,O),U[4*x]=O.x,U[4*x+1]=O.y,U[4*x+2]=O.z,U[4*x+3]=O.w}else p.Tools.Warn("Unsupported number of components for color attribute: ".concat(F));y=r.createBufferView(U,4*F),v=r.createAccessor(y,3===F?"VEC3":"VEC4",5126,l,0),s.push(v),o.attributes.COLOR_0=s.length-1}else p.Tools.Warn("Morph target colors for mesh ".concat(t.name," were not exported. Mesh does not have colors vertex data"))}return o}var te=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 i,o,a,u;return null===(u=null===(a=null===(o=null===(i=this._indicesAccessorMap.get(e))||void 0===i?void 0:i.get(t))||void 0===o?void 0:o.get(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,i){var o=this._indicesAccessorMap.get(e);o||(o=new Map,this._indicesAccessorMap.set(e,o));var a=o.get(t);a||(a=new Map,o.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,i)},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 i=s.get(t);i||(i=new Map,s.set(t,i)),i.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}(),re=function(){function e(e,t){if(void 0===e&&(e=p.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(p.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 S(this),this._extensions={},this._bufferManager=new J,this._shouldExportNodeMap=new Map,this._nodeMap=new Map,this._materialMap=new Map,this._camerasMap=new Map,this._nodesCameraMap=new Map,this._skinMap=new Map,this._nodesSkinMap=new Map,this._materialNeedsUVsSet=new Set,!e)throw new Error("No scene available to export");this._babylonScene=e,this._options=d({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"},t),this._loadExtensions()}return e.prototype._ApplyExtension=function(e,t,r,n){var s=this;if(r>=t.length)return Promise.resolve(e);var i=n(t[r],e);return i?i.then((function(e){return g(s,void 0,void 0,(function(){var s;return _(this,(function(i){switch(i.label){case 0:return e?[4,this._ApplyExtension(e,t,r+1,n)]:[3,2];case 1:return s=i.sent(),[3,3];case 2:s=null,i.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,i=e._ExtensionNames;s<i.length;s++){var o=i[s];n.push(this._extensions[o])}return this._ApplyExtension(t,n,0,r)},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n,s){var i=this;return this._ApplyExtensions(t,(function(t,o){return t.postExportNodeAsync&&t.postExportNodeAsync(e,o,r,n,s,i._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 g(this,void 0,void 0,(function(){var s,i=this;return _(this,(function(o){switch(o.label){case 0:return s=[],[4,Promise.all(e._ExtensionNames.map((function(e){return g(i,void 0,void 0,(function(){var i,o;return _(this,(function(a){switch(a.label){case 0:return(i=this._extensions[e]).postExportMaterialAdditionalTexturesAsync?[4,i.postExportMaterialAdditionalTexturesAsync(t,r,n)]:[3,2];case 1:o=a.sent(),s.push.apply(s,o),a.label=2;case 2:return[2]}}))}))})))];case 1:return o.sent(),[2,s]}}))}))},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var s=0,i=e._ExtensionNames;s<i.length;s++){var o=i[s],a=this._extensions[o];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],i=this._extensions[s];i.postExportMeshPrimitive&&i.postExportMeshPrimitive(t,this._bufferManager,this._accessors)}},e.prototype._extensionsPreGenerateBinaryAsync=function(){return g(this,void 0,void 0,(function(){var t,r,n,s;return _(this,(function(i){switch(i.label){case 0:t=0,r=e._ExtensionNames,i.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:i.sent(),i.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],i=this._extensions[s];i.enabled&&t(i)}},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(t,r,n){void 0===n&&(n=100),e.UnregisterExtension(t)&&p.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=r;var s=null!=n?n:0;e._ExtensionOrders[t]=s;for(var i=e._ExtensionNames.length,o=0;o<e._ExtensionNames.length;o++){var a=e._ExtensionNames[o];if(s<e._ExtensionOrders[a]){i=o;break}}e._ExtensionNames.splice(i,0,t)},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 g(this,void 0,void 0,(function(){var t,r,n,s,i,o,a;return _(this,(function(u){switch(u.label){case 0:return[4,this._generateBinaryAsync()];case 1:if(t=u.sent(),this._extensionsOnExporting(),r=this._generateJSON(t.byteLength,e,!0),n=new Blob([t],{type:"application/octet-stream"}),s=e+".gltf",i=e+".bin",(o=new h).files[s]=r,o.files[i]=n,this._imageData)for(a in this._imageData)o.files[a]=new Blob([this._imageData[a].data],{type:this._imageData[a].mimeType});return[2,o]}}))}))},e.prototype._generateBinaryAsync=function(){return g(this,void 0,void 0,(function(){return _(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 g(this,void 0,void 0,(function(){var t,r,n,s,i,o,a,u,c,l,f,p,d,g;return _(this,(function(_){switch(_.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=_.sent(),this._extensionsOnExporting(),r=this._generateJSON(t.byteLength),n=e+".glb",s=r.length,"undefined"!=typeof TextEncoder&&(o=new TextEncoder,i=o.encode(r),s=i.length),a=this._getPadding(s),u=this._getPadding(t.byteLength),c=28+s+a+t.byteLength+u,(l=new Q(c)).writeUInt32(1179937895),l.writeUInt32(2),l.writeUInt32(c),l.writeUInt32(s+a),l.writeUInt32(1313821514),i)l.writeTypedArray(i);else for(f="_".charCodeAt(0),d=0;d<s;++d)(p=r.charCodeAt(d))!=r.codePointAt(d)?l.writeUInt8(f):l.writeUInt8(p);for(d=0;d<a;++d)l.writeUInt8(32);for(l.writeUInt32(t.byteLength+u),l.writeUInt32(5130562),l.writeTypedArray(t),d=0;d<u;++d)l.writeUInt8(0);return(g=new h).files[n]=new Blob([l.getOutputData()],{type:"application/octet-stream"}),[2,g]}}))}))},e.prototype._setNodeTransformation=function(e,t,r){var n;if(t.getPivotPoint().equalsWithEpsilon(I,p.Epsilon)||p.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsWithEpsilon(I,p.Epsilon)){var s=p.TmpVectors.Vector3[0].copyFrom(t.position);r&&D(s),e.translation=s.asArray()}t.scaling.equalsWithEpsilon(U,p.Epsilon)||(e.scale=t.scaling.asArray());var i=(null===(n=t.rotationQuaternion)||void 0===n?void 0:n.clone())||p.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);i.equalsWithEpsilon(F,p.Epsilon)||(r&&H(i),e.rotation=i.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,r){var n=p.TmpVectors.Vector3[0],s=p.TmpVectors.Quaternion[0],i=t.getWorldMatrix();if(t.parent){var o=t.parent.getWorldMatrix().invertToRef(p.TmpVectors.Matrix[0]);i.multiplyToRef(o,p.TmpVectors.Matrix[1]).decompose(void 0,s,n)}else i.decompose(void 0,s,n);n.equalsWithEpsilon(I,p.Epsilon)||(r&&D(n),e.translation=n.asArray()),r&&H(s),this._babylonScene.useRightHandedSystem||G(s),s.equalsWithEpsilon(F,p.Epsilon)||(e.rotation=s.asArray())},e.prototype._listAvailableCameras=function(){for(var e=0,t=this._babylonScene.cameras;e<t.length;e++){var r=t[e],n={type:r.mode===p.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(r.name&&(n.name=r.name),"perspective"===n.type)n.perspective={aspectRatio:r.getEngine().getAspectRatio(r),yfov:r.fovMode===p.Camera.FOVMODE_VERTICAL_FIXED?r.fov:r.fov*r.getEngine().getAspectRatio(r),znear:r.minZ,zfar:r.maxZ};else if("orthographic"===n.type){var s=r.orthoLeft&&r.orthoRight?.5*(r.orthoRight-r.orthoLeft):.5*r.getEngine().getRenderWidth(),i=r.orthoBottom&&r.orthoTop?.5*(r.orthoTop-r.orthoBottom):.5*r.getEngine().getRenderHeight();n.orthographic={xmag:s,ymag:i,znear:r.minZ,zfar:r.maxZ}}this._camerasMap.set(r,n)}},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,i=n;s<i.length;s++)i[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 t,r=function(r){if(r.bones.length<=0)return"continue";var s=n._skinMap.get(r);if(null==s)return"continue";for(var i={},o=-1,a=0;a<r.bones.length;++a){var u=r.bones[a];-1!==(f=null!==(t=u.getIndex())&&void 0!==t?t:a)&&(i[f]=u,f>o&&(o=f))}for(var c,l=[],f=0;f<=o;++f){var h=(u=i[f]).getTransformNode(),d=h?n._nodeMap.get(h):void 0;if(void 0!==d){s.joints.push(d);var g=u.getAbsoluteInverseBindMatrix().clone();e.has(h)&&(c=g,V.invertToRef(p.TmpVectors.Matrix[0]).multiplyToRef(c,c).multiplyToRef(V,c)),l.push(g)}else p.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.")}var _=n._nodesSkinMap.get(s);if(s.joints.length>0&&void 0!==_){var x=new Float32Array(16*l.length);l.forEach((function(e,t){x.set(e.m,16*t)}));var m=n._bufferManager.createBufferView(x);n._accessors.push(n._bufferManager.createAccessor(m,"MAT4",5126,l.length)),s.inverseBindMatrices=n._accessors.length-1,n._skins.push(s);for(var y=n._skins.length-1,v=0,T=_;v<T.length;v++)T[v].skin=y}},n=this,s=0,i=this._babylonScene.skeletons;s<i.length;s++)r(i[s])},e.prototype._exportSceneAsync=function(){return g(this,void 0,void 0,(function(){var e,t,r,n,s,i,o,a,u,c,l,f,p,h,d,g,x,m,y,v,T,b,A;return _(this,(function(_){switch(_.label){case 0:for(e={nodes:[]},this._babylonScene.metadata&&(t=this._options.metadataSelector(this._babylonScene.metadata))&&(e.extras=t),r=new Array,n=new Array,s=new Array,i=0,o=this._babylonScene.rootNodes;i<o.length;i++)a=o[i],this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&B(a,this._babylonScene.useRightHandedSystem)?s.push.apply(s,a.getChildren()):this._babylonScene.useRightHandedSystem?r.push(a):n.push(a);return this._listAvailableCameras(),this._listAvailableSkeletons(),u=new te(!0,!1),l=(c=(T=e.nodes).push).apply,f=[T],[4,this._exportNodesAsync(n,u)];case 1:return l.apply(c,f.concat([_.sent()])),p=new te(!1,!1),d=(h=(b=e.nodes).push).apply,g=[b],[4,this._exportNodesAsync(r,p)];case 2:return d.apply(h,g.concat([_.sent()])),x=new te(!1,!0),y=(m=(A=e.nodes).push).apply,v=[A],[4,this._exportNodesAsync(s,x)];case 3:return y.apply(m,v.concat([_.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(u.getNodesSet()),this._babylonScene.animationGroups.length&&$._CreateNodeAndMorphAnimationFromAnimationGroups(this._babylonScene,this._animations,this._nodeMap,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,u.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 g(this,void 0,void 0,(function(){var r,n,s,i;return _(this,(function(o){switch(o.label){case 0:r=new Array,this._exportBuffers(e,t),n=0,s=e,o.label=1;case 1:return n<s.length?(i=s[n],[4,this._exportNodeAsync(i,r,t)]):[3,4];case 2:o.sent(),o.label=3;case 3:return n++,[3,1];case 4:return[2,r]}}))}))},e.prototype._collectBuffers=function(e,t,r,n,s){if(this._shouldExportNode(e)&&e instanceof p.AbstractMesh&&e.geometry){var i=e.geometry.getVertexBuffers();if(i)for(var o in i)if(L(o)){var a=i[o];s.setHasVertexColorAlpha(a,e.hasVertexAlpha);var u=a._buffer,c=t.get(u)||[];t.set(u,c),-1===c.indexOf(a)&&c.push(a);var l=r.get(a)||[];r.set(a,l),-1===l.indexOf(e)&&l.push(e)}var f=e.morphTargetManager;if(f)for(var h=0;h<f.numTargets;h++){var d=f.getTarget(h);l=n.get(d)||[],n.set(d,l),-1===l.indexOf(e)&&l.push(e)}}for(var g=0,_=e.getChildren();g<_.length;g++){var x=_[g];this._collectBuffers(x,t,r,n,s)}},e.prototype._exportBuffers=function(e,t){for(var r=new Map,n=new Map,s=new Map,i=0,o=e;i<o.length;i++){var a=o[i];this._collectBuffers(a,r,n,s,t)}for(var u=Array.from(r.keys()),c=function(e){var s=e.getData();if(!s)throw new Error("Buffer data is not available");var i=r.get(e);if(!i)return"continue";var o=i[0].byteStride;if(i.some((function(e){return e.byteStride!==o})))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");for(var a=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)}(s).slice(),u=function(e){var t=n.get(e),r=O(e,t),s=r.byteOffset,i=r.byteStride,o=r.componentCount,u=r.type,c=r.count,f=r.normalized;switch(r.kind){case p.VertexBuffer.NormalKind:case p.VertexBuffer.TangentKind:(0,p.EnumerateFloatValues)(a,s,i,o,u,c,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 p.VertexBuffer.ColorKind:var h=t.filter((function(e){return e.material instanceof p.StandardMaterial||null==e.material})).length;if(0==h)break;if(h!=t.length){p.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}u==p.VertexBuffer.UNSIGNED_BYTE&&p.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var d=new p.Color3,g=new p.Color4,_=l._babylonScene.getEngine().useExactSrgbConversions;(0,p.EnumerateFloatValues)(a,s,i,o,u,c,f,(function(e){3===e.length?(d.fromArray(e,0),d.toLinearSpaceToRef(d,_),d.toArray(e,0)):(g.fromArray(e,0),g.toLinearSpaceToRef(g,_),g.toArray(e,0))}))}},c=0,f=i;c<f.length;c++)u(I=f[c]);if(t.convertToRightHanded){for(var h=0,d=i;h<d.length;h++){var g=O(I=d[h],n.get(I)),_=g.byteOffset,x=g.byteStride,m=g.componentCount,y=g.type,v=g.count,T=g.normalized;switch(R=g.kind){case p.VertexBuffer.PositionKind:case p.VertexBuffer.NormalKind:case p.VertexBuffer.TangentKind:(0,p.EnumerateFloatValues)(a,_,x,m,y,v,T,(function(e){e[0]=-e[0]}))}}t.convertedToRightHandedBuffers.set(e,a)}var b=l._bufferManager.createBufferView(a,o);t.setVertexBufferView(e,b);for(var A=new Map,w=0,E=i;w<E.length;w++){var M=O(I=E[w],n.get(I)),R=M.kind,C=M.totalVertices;switch(R){case p.VertexBuffer.MatricesIndicesKind:case p.VertexBuffer.MatricesIndicesExtraKind:if(I.type==p.VertexBuffer.FLOAT){var S=I.getFloatData(C);null!==S&&A.set(I,S)}}}0!==A.size&&p.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 V=0,B=Array.from(A.keys());V<B.length;V++){var I=B[V],F=A.get(I);if(F){for(var U=F.some((function(e){return e>=256})),N=new(U?Uint16Array:Uint8Array)(F.length),P=0;P<F.length;P++)N[P]=F[P];var L=l._bufferManager.createBufferView(N,4*(U?2:1));t.setRemappedBufferView(e,I,L)}}},l=this,f=0,h=u;f<h.length;f++)c(h[f]);for(var d=0,g=Array.from(s.keys());d<g.length;d++){var _=g[d],x=s.get(_);if(x)for(var m=ee(_,x[0],this._bufferManager,this._bufferViews,this._accessors,t.convertToRightHanded),y=0,v=x;y<v.length;y++){var T=v[y];t.bindMorphDataToMesh(T,m)}}},e.prototype._exportNodeAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,s,i,o,a,u,c,l,f=this;return _(this,(function(p){switch(p.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=p.sent())&&(n=this._nodes.length,this._nodes.push(s),this._nodeMap.set(e,n),r.pushExportedNode(e),t.push(n),i={name:"runtime animations",channels:[],samplers:[]},o=[],this._babylonScene.animationGroups.length||($._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,o,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&$._CreateNodeAnimationFromNodeAnimations(e,i,o,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation)),i.channels.length&&i.samplers.length&&this._animations.push(i),o.forEach((function(e){e.channels.length&&e.samplers.length&&f._animations.push(e)}))),a=s?[]:t,u=0,c=e.getChildren(),p.label=2;case 2:return u<c.length?(l=c[u],[4,this._exportNodeAsync(l,a,r)]):[3,5];case 3:p.sent(),p.label=4;case 4:return u++,[3,2];case 5:return s&&a.length&&(s.children=a),[2]}}))}))},e.prototype._createNodeAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,s,i,o,a,u,c,l,f,h,d;return _(this,(function(g){switch(g.label){case 0:return this._shouldExportNode(e)?(r={},e.name&&(r.name=e.name),e.metadata&&(n=this._options.metadataSelector(e.metadata))&&(r.extras=n),e instanceof p.TransformNode?(this._setNodeTransformation(r,e,t.convertToRightHanded),e instanceof p.AbstractMesh?(s=e instanceof p.InstancedMesh?e.sourceMesh:e).subMeshes&&s.subMeshes.length>0?(i=r,[4,this._exportMeshAsync(s,t)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:i.mesh=g.sent(),g.label=2;case 2:e.skeleton&&void 0!==(o=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(o)&&this._nodesSkinMap.set(o,[]),null===(f=this._nodesSkinMap.get(o))||void 0===f||f.push(r)),g.label=3;case 3:if(e instanceof p.TargetCamera&&(a=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(a)&&this._nodesCameraMap.set(a,[]),this._setCameraTransformation(r,e,t.convertToRightHanded),null!==(u=e.parent)&&q(e,u)&&void 0!==(c=this._nodeMap.get(u)))return l=this._nodes[c],W(r,l),null===(h=this._nodesCameraMap.get(a))||void 0===h||h.push(l),[2,null];null===(d=this._nodesCameraMap.get(a))||void 0===d||d.push(r)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",r,e,this._nodeMap,t.convertToRightHanded)];case 4:return g.sent()?[2,r]:(p.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}}))}))},e.prototype._exportIndices=function(e,t,r,n,s,i,o,a,u){var c=e;u.mode=K(i);var l=o!==p.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case p.Material.TriangleFillMode:case p.Material.TriangleStripDrawMode:case p.Material.TriangleFanDrawMode:return!0}return!1}(i);if(l){if(i===p.Material.TriangleStripDrawMode||i===p.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");u.mode=K(i);var f=t?new Uint32Array(n):new Uint16Array(n);if(e)for(var h=0;h+2<n;h+=3)f[h]=e[r+h]+s,f[h+1]=e[r+h+2]+s,f[h+2]=e[r+h+1]+s;else for(h=0;h+2<n;h+=3)f[h]=h,f[h+1]=h+2,f[h+2]=h+1;c=f}else if(e&&0!==s){for(f=t?new Uint32Array(n):new Uint16Array(n),h=0;h<n;h++)f[h]=e[r+h]+s;c=f}if(c){var d=a.getIndicesAccessor(e,r,n,s,l);if(void 0===d){var g=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}(c,r,n,t),_=this._bufferManager.createBufferView(g),x=t?5125:5123;this._accessors.push(this._bufferManager.createAccessor(_,"SCALAR",x,n,0)),d=this._accessors.length-1,a.setIndicesAccessor(e,r,n,s,l,d)}u.indices=d}},e.prototype._exportVertexBuffer=function(e,t,r,n,s,i){var o=e.getKind();if(L(o)&&(!o.startsWith("uv")||this._options.exportUnusedUVs||t&&this._materialNeedsUVsSet.has(t))){var a=s.getVertexAccessor(e,r,n);if(void 0===a){var u=s.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),c=o===p.VertexBuffer.PositionKind?function(e,t,r,n){var s=t.byteOffset,i=t.byteStride,o=t.type,a=t.normalized,u=t.getSize(),c=new Array(u).fill(1/0),l=new Array(u).fill(-1/0);return(0,p.EnumerateFloatValues)(e,s+r*i,i,u,o,n*u,a,(function(e){for(var t=0;t<u;t++)c[t]=Math.min(c[t],e[t]),l[t]=Math.max(l[t],e[t])})),{min:c,max:l}}(u,e,r,n):void 0,l=(o===p.VertexBuffer.MatricesIndicesKind||o===p.VertexBuffer.MatricesIndicesExtraKind)&&e.type===p.VertexBuffer.FLOAT,f=l?p.VertexBuffer.UNSIGNED_BYTE:e.type,h=l?void 0:e.normalized,d=l?s.getRemappedBufferView(e._buffer,e):s.getVertexBufferView(e._buffer),g=e.byteOffset+r*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(d,function(e,t){if(e==p.VertexBuffer.ColorKind)return t?"VEC4":"VEC3";switch(e){case p.VertexBuffer.PositionKind:case p.VertexBuffer.NormalKind:return"VEC3";case p.VertexBuffer.TangentKind:case p.VertexBuffer.MatricesIndicesKind:case p.VertexBuffer.MatricesIndicesExtraKind:case p.VertexBuffer.MatricesWeightsKind:case p.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case p.VertexBuffer.UVKind:case p.VertexBuffer.UV2Kind:case p.VertexBuffer.UV3Kind:case p.VertexBuffer.UV4Kind:case p.VertexBuffer.UV5Kind:case p.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(o,s.hasVertexColorAlpha(e)),f,n,g,c,h)),a=this._accessors.length-1,s.setVertexAccessor(e,r,n,a)}i.attributes[function(e){switch(e){case p.VertexBuffer.PositionKind:return"POSITION";case p.VertexBuffer.NormalKind:return"NORMAL";case p.VertexBuffer.TangentKind:return"TANGENT";case p.VertexBuffer.ColorKind:return"COLOR_0";case p.VertexBuffer.UVKind:return"TEXCOORD_0";case p.VertexBuffer.UV2Kind:return"TEXCOORD_1";case p.VertexBuffer.UV3Kind:return"TEXCOORD_2";case p.VertexBuffer.UV4Kind:return"TEXCOORD_3";case p.VertexBuffer.UV5Kind:return"TEXCOORD_4";case p.VertexBuffer.UV6Kind:return"TEXCOORD_5";case p.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case p.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case p.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case p.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(o)]=a}},e.prototype._exportMaterialAsync=function(e,t,r,n){return g(this,void 0,void 0,(function(){var s,i;return _(this,(function(o){switch(o.label){case 0:return void 0!==(s=this._materialMap.get(e))?[3,8]:(i=t&&Object.keys(t).some((function(e){return e.startsWith("uv")})),(e=e instanceof p.MultiMaterial?e.subMaterials[r.materialIndex]:e)instanceof p.PBRBaseMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,i)]:[3,2]);case 1:return s=o.sent(),[3,7];case 2:return e instanceof p.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,i)]:[3,4];case 3:return s=o.sent(),[3,7];case 4:return e instanceof p.OpenPBRMaterial?[4,this._materialExporter.exportOpenPBRMaterialAsync(e,i)]:[3,6];case 5:return s=o.sent(),[3,7];case 6:return p.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 7:this._materialMap.set(e,s),o.label=8;case 8:return n.material=s,[2]}}))}))},e.prototype._exportMeshAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,s,i,o,a,u,c,l,f,h,d,g,m,y,v,T,b,A,w,E,M,R,C,S,V,B,I,F,U,N,O,P,L;return _(this,(function(_){switch(_.label){case 0:if(void 0!==(r=t.getMesh(e)))return[2,r];if(n={primitives:[]},r=this._meshes.length,this._meshes.push(n),t.setMesh(e,r),s=e.isUnIndexed?null:e.getIndices(),i=null===(F=e.geometry)||void 0===F?void 0:F.getVertexBuffers(),o=t.getMorphTargetsFromMesh(e),a=e instanceof p.LinesMesh,u=e instanceof p.GreasedLineBaseMesh,c=e.subMeshes,!(i&&c&&c.length>0))return[3,7];l=0,f=c,_.label=1;case 1:return l<f.length?(h=f[l],d={attributes:{}},g=h.getMaterial()||this._babylonScene.defaultMaterial,u?(T={name:g.name},b=e,m=p.Color3.White(),y=null!==(N=null===(U=b.material)||void 0===U?void 0:U.alpha)&&void 0!==N?N:1,(!(v=null!==(P=null===(O=b.greasedLineMaterial)||void 0===O?void 0:O.color)&&void 0!==P?P:m).equalsWithEpsilon(m,p.Epsilon)||y<1)&&(T.pbrMetallicRoughness={baseColorFactor:x(x([],v.asArray(),!0),[y],!1)}),this._materials.push(T),d.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return a?(T={name:g.name},(!(b=e).color.equalsWithEpsilon(p.Color3.White(),p.Epsilon)||b.alpha<1)&&(T.pbrMetallicRoughness={baseColorFactor:x(x([],b.color.asArray(),!0),[b.alpha],!1)}),this._materials.push(T),d.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(g,i,h,d)];case 4:_.sent(),_.label=5;case 5:for(A=a||u?p.Material.LineListDrawMode:null!==(L=e.overrideRenderingFillMode)&&void 0!==L?L:g.fillMode,w=g._getEffectiveOrientation(e),t.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(w=w===p.Material.ClockWiseSideOrientation?p.Material.CounterClockWiseSideOrientation:p.Material.ClockWiseSideOrientation),this._exportIndices(s,s?(0,p.AreIndices32Bits)(s,h.indexCount,h.indexStart,h.verticesStart):h.verticesCount>65535,s?h.indexStart:h.verticesStart,s?h.indexCount:h.verticesCount,-h.verticesStart,A,w,t,d),E=0,M=Object.values(i);E<M.length;E++)R=M[E],this._exportVertexBuffer(R,g,h.verticesStart,h.verticesCount,t,d);if(o)for(d.targets=[],C=0,S=o;C<S.length;C++)I=S[C],d.targets.push(I.attributes);n.primitives.push(d),this._extensionsPostExportMeshPrimitive(d),_.label=6;case 6:return l++,[3,1];case 7:if(o)for(n.weights=[],n.extras||(n.extras={}),n.extras.targetNames=[],V=0,B=o;V<B.length;V++)I=B[V],n.weights.push(I.influence),n.extras.targetNames.push(I.name);return[2,r]}}))}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e._ExtensionOrders={},e}(),ne=function(){function e(){}return e.GLTFAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,s;return _(this,(function(i){switch(i.label){case 0:return r&&r.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(n=new re(e,r)).generateGLTFAsync(t.replace(/\.[^/.]+$/,""))];case 3:return s=i.sent(),n.dispose(),[2,s]}}))}))},e.GLBAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,s;return _(this,(function(i){switch(i.label){case 0:return r&&r.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(n=new re(e,r)).generateGLBAsync(t.replace(/\.[^/.]+$/,""))];case 3:return s=i.sent(),n.dispose(),[2,s]}}))}))},e}(),se="EXT_mesh_gpu_instancing",ie=function(){function e(e){this.name=se,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.postExportNodeAsync=function(e,t,r,n,s,i){return g(this,void 0,void 0,(function(){var e=this;return _(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){if(t&&r instanceof p.Mesh&&r.hasThinInstances&&e._exporter){e._wasUsed=!0;for(var o=p.Vector3.Zero(),a=p.Quaternion.Identity(),u=p.Vector3.One(),c=r.thinInstanceGetWorldMatrices(),l=p.TmpVectors.Vector3[2],f=p.TmpVectors.Quaternion[1],h=p.TmpVectors.Vector3[3],d=!1,g=!1,_=!1,x=new Float32Array(3*r.thinInstanceCount),m=new Float32Array(4*r.thinInstanceCount),y=new Float32Array(3*r.thinInstanceCount),v=0,T=0,b=c;T<b.length;T++)b[T].decompose(h,f,l),s&&(D(l),H(f)),x.set(l.asArray(),3*v),m.set(f.normalize().asArray(),4*v),y.set(h.asArray(),3*v),d=d||!l.equalsWithEpsilon(o),g=g||!f.equalsWithEpsilon(a),_=_||!h.equalsWithEpsilon(u),v++;var A={attributes:{}};d&&(A.attributes.TRANSLATION=e._buildAccessor(x,"VEC3",r.thinInstanceCount,i)),g&&(A.attributes.ROTATION=e._buildAccessor(m,"VEC4",r.thinInstanceCount,i)),_&&(A.attributes.SCALE=e._buildAccessor(y,"VEC3",r.thinInstanceCount,i)),t.extensions=t.extensions||{},t.extensions[se]=A}n(t)}))];case 1:return[2,n.sent()]}}))}))},e.prototype._buildAccessor=function(e,t,r,n){var s=n.createBufferView(e),i=n.createAccessor(s,t,5126,r);return this._exporter._accessors.push(i),this._exporter._accessors.length-1},e}();re.RegisterExtension(se,(function(e){return new ie(e)}));var oe="KHR_draco_mesh_compression",ae=function(){function e(e){this.name=oe,this.required=!0,this._bufferViewsUsed=new Set,this._accessorsUsed=new Set,this._encodePromises=[],this._wasUsed=!1,this.enabled="Draco"===e.options.meshCompressionMethod&&p.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,t,r){var n=this;if(this.enabled)if(4===e.mode||5===e.mode){var s=[],i=[],o=null;if(void 0!==e.indices){var a=r[e.indices],u=t.getBufferView(a);o=t.getData(u).slice(),s.push(u),i.push(a)}for(var c,l=[],f=0,h=Object.entries(e.attributes);f<h.length;f++){var d=h[f],g=d[0],_=(a=r[d[1]],u=t.getBufferView(a),P(a.type)),x=(0,p.GetTypedArrayData)(t.getData(u),_,a.componentType,a.byteOffset||0,u.byteStride||(0,p.GetTypeByteLength)(a.componentType)*_,a.count,!0);l.push({kind:g,dracoName:(c=g,"POSITION"===c?"POSITION":"NORMAL"===c?"NORMAL":c.startsWith("COLOR")?"COLOR":c.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"),size:P(a.type),data:x}),s.push(u),i.push(a)}var m={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},y=p.DracoEncoder.Default._encodeAsync(l,o,m).then((function(r){if(r){var o={bufferView:-1,attributes:r.attributeIds},a=t.createBufferView(r.data);t.setBufferView(o,a);for(var u=0,c=s;u<c.length;u++){var l=c[u];n._bufferViewsUsed.add(l)}for(var f=0,h=i;f<h.length;f++){var d=h[f];n._accessorsUsed.add(d)}e.extensions||(e.extensions={}),e.extensions[oe]=o}else p.Logger.Error("Draco encoding failed for primitive.")})).catch((function(e){p.Logger.Error("Draco encoding failed for primitive: "+e)}));this._encodePromises.push(y),this._wasUsed=!0}else p.Logger.Warn("Cannot compress primitive with mode "+e.mode+".")},e.prototype.preGenerateBinaryAsync=function(e){return g(this,void 0,void 0,(function(){var t=this;return _(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}();re.RegisterExtension(oe,(function(e){return new ae(e)}));var ue="KHR_lights_punctual",ce={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},le={innerConeAngle:0,outerConeAngle:Math.PI/4},fe=p.Vector3.Backward(),pe=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,t,r,n,s){return g(this,void 0,void 0,(function(){var i=this;return _(this,(function(o){switch(o.label){case 0:return[4,new Promise((function(o){if(r instanceof p.Light){var a=r.getTypeID()==p.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==p.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==p.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(a&&r instanceof p.ShadowLight))return p.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(ue)),void o(t);if(r.falloffType!==p.Light.FALLOFF_GLTF&&p.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(ue," specification!")),!r.position.equalsToFloats(0,0,0)){var u=p.TmpVectors.Vector3[0].copyFrom(r.position);s&&D(u),t.translation=u.asArray()}if("point"!==a){var c=r.direction.normalizeToRef(p.TmpVectors.Vector3[0]);s&&D(c);var l=p.Quaternion.FromUnitVectorsToRef(fe,c,p.TmpVectors.Quaternion[0]);p.Quaternion.IsIdentity(l)||(t.rotation=l.asArray())}var f={type:a,name:r.name,color:r.diffuse.asArray(),intensity:r.intensity,range:r.range};if(z(f,ce),"spot"===a){var h=r;f.spot={innerConeAngle:h.innerAngle/2,outerConeAngle:h.angle/2},z(f.spot,le)}i._lights||(i._lights={lights:[]}),i._lights.lights.push(f);var d={light:i._lights.lights.length-1},g=r.parent;if(g&&q(r,g)){var _=n.get(g);if(_){var x=i._exporter._nodes[_];return W(t,x),x.extensions||(x.extensions={}),x.extensions[ue]=d,void o(null)}}t.extensions||(t.extensions={}),t.extensions[ue]=d,o(t)}else o(t)}))];case 1:return[2,o.sent()]}}))}))},e}();re.RegisterExtension(ue,(function(e){return new pe(e)}));var he="KHR_materials_anisotropy";function de(e,t){t.uOffset=e.uOffset,t.vOffset=e.vOffset,t.uScale=e.uScale,t.vScale=e.vScale,t.uAng=e.uAng,t.vAng=e.vAng,t.wAng=e.wAng,t.uRotationCenter=e.uRotationCenter,t.vRotationCenter=e.vRotationCenter}function ge(e){return g(this,void 0,void 0,(function(){var t,r,n,s,i,o,a,u;return _(this,(function(c){switch(c.label){case 0:return t=e.getScene(),p.Effect.ShadersStore.anisotropyMergeFragmentShader||(p.Effect.ShadersStore.anisotropyMergeFragmentShader="\n precision highp float;\n#ifdef HAS_TANGENT_TEXTURE\n uniform sampler2D tangentTexture;\n#endif\n#ifdef HAS_ANISOTROPY_TEXTURE\n uniform sampler2D anisotropyTexture;\n#endif\n uniform int useRoughnessFromMetallicGreen;\n uniform int useAnisotropyFromTangentBlue;\n\n varying vec2 vUV;\n\n void main() {\n vec2 tangent = vec2(1.0, 0.0);\n float anisotropy = 1.0;\n #ifdef HAS_TANGENT_TEXTURE\n // Tangent texture is present\n vec4 tangentSample = texture2D(tangentTexture, vUV);\n tangent = tangentSample.rg;\n\n if (useAnisotropyFromTangentBlue > 0) {\n anisotropy = tangentSample.b;\n }\n #endif\n #ifdef HAS_ANISOTROPY_TEXTURE\n // Anisotropy texture is present\n vec4 anisotropySample = texture2D(anisotropyTexture, vUV);\n anisotropy = anisotropySample.r;\n #endif\n \n // Output: RG = tangent XY, B = anisotropy strength\n vec4 anisotropyData = vec4(tangent.x, tangent.y, anisotropy, 1.0);\n gl_FragColor = anisotropyData;\n }\n"),r=e.specularRoughnessAnisotropyTexture,n=e.geometryTangentTexture,r||n?(s=Math.max(r?r.getSize().width:1,n?n.getSize().width:1),i=Math.max(r?r.getSize().height:1,n?n.getSize().height:1),o={type:p.Constants.TEXTURETYPE_UNSIGNED_BYTE,format:p.Constants.TEXTUREFORMAT_RGBA,samplingMode:p.Constants.TEXTURE_BILINEAR_SAMPLINGMODE,generateDepthBuffer:!1,generateStencilBuffer:!1,generateMipMaps:!1},(a=new p.ProceduralTexture(e.name+"_anisotropy",{width:s,height:i},"anisotropyMerge",t,o)).refreshRate=-1,u="",n&&(u+="#define HAS_TANGENT_TEXTURE\n",a.setTexture("tangentTexture",n),de(n,a)),a.setVector2("tangentVector",e.geometryTangent),r&&(u+="#define HAS_ANISOTROPY_TEXTURE\n",a.setTexture("anisotropyTexture",r),de(r,a)),a.setInt("useAnisotropyFromTangentBlue",e._useSpecularRoughnessAnisotropyFromTangentTexture?1:0),a.defines=u,[4,new Promise((function(e,t){a.executeWhenReady((function(){try{a.render(),e(a)}catch(e){t(e instanceof Error?e:new Error(String(e)))}}))}))]):[2,null];case 1:return[2,c.sent()]}}))}))}var _e=function(){function e(e){this.name=he,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,t,r){return g(this,void 0,void 0,(function(){var e,t;return _(this,(function(n){switch(n.label){case 0:return e=[],r instanceof p.PBRBaseMaterial?r.anisotropy.isEnabled&&!r.anisotropy.legacy?(r.anisotropy.texture&&e.push(r.anisotropy.texture),[2,e]):[3,3]:[3,1];case 1:return r instanceof p.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0?[4,ge(r)]:[3,3];case 2:return(t=n.sent())&&(e.push(t),this._anisoTexturesMap[r.id]=t),[2,e];case 3:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var s,i,o,a,u,c;if(r instanceof p.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var l=n._exporter._materialExporter.getTextureInfo(r.anisotropy.texture);null!==(y={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=l?l:void 0}).anisotropyTexture&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[he]=y}else if(r instanceof p.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0){n._wasUsed=!0,t.extensions=t.extensions||{};var f=r.specularRoughnessTexture;r._useRoughnessFromMetallicTextureGreen&&(f=r.baseMetalnessTexture);var h=n._anisoTexturesMap[r.id];if(!f&&!h){var d=r.specularRoughness,g=r.specularRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){var _=(i=r.specularRoughness,c=(1-(o=r.specularRoughnessAnisotropy))*(u=(a=i*i)*Math.sqrt(2/(1+(1-o)*(1-o)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-a)/Math.max(1-a,1e-4)),1)});d=_.newBaseRoughness,g=_.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=d);var x={anisotropyStrength:g,anisotropyRotation:r.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return t.extensions[he]=x,e(t)}var m=h?n._exporter._materialExporter.getTextureInfo(h):null,y={anisotropyStrength:r.specularRoughnessAnisotropy,anisotropyRotation:r.geometryTangentAngle,anisotropyTexture:m||void 0,extensions:{}};r._useGltfStyleAnisotropy||(y.extensions.EXT_materials_anisotropy_openpbr={openPbrAnisotropyEnabled:!0},(s=n._exporter._glTF).extensionsUsed||(s.extensionsUsed=[]),-1===n._exporter._glTF.extensionsUsed.indexOf("EXT_materials_anisotropy_openpbr")&&n._exporter._glTF.extensionsUsed.push("EXT_materials_anisotropy_openpbr")),n._exporter._materialNeedsUVsSet.add(r),t.extensions[he]=y}e(t)}))},e}();re.RegisterExtension(he,(function(e){return new _e(e)}));var xe="KHR_materials_clearcoat",me=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,t,r){return g(this,void 0,void 0,(function(){var e;return _(this,(function(t){if(e=[],r instanceof p.PBRBaseMaterial){if(r.clearCoat.isEnabled)return r.clearCoat.texture&&e.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&e.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&e.push(r.clearCoat.bumpTexture),[2,e]}else if(r instanceof p.OpenPBRMaterial&&r.coatWeight>0)return r.coatWeightTexture&&e.push(r.coatWeightTexture),r.geometryCoatNormalTexture&&e.push(r.geometryCoatNormalTexture),r.coatRoughnessTexture&&e.push(r.coatRoughnessTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof p.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var s=n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture),i=void 0;i=r.clearCoat.useRoughnessFromMainTexture?n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):n._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&p.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),r.clearCoat.remapF0OnInterfaceChange&&p.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(r.name));var o=n._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture);null===(a={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=s?s:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=i?i:void 0,clearcoatNormalTexture:null!=o?o:void 0}).clearcoatTexture&&null===a.clearcoatRoughnessTexture&&null===a.clearcoatRoughnessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[xe]=a}else if(r instanceof p.OpenPBRMaterial){if(0==r.coatWeight)return void e(t);var a;n._wasUsed=!0,t.extensions=t.extensions||{},s=n._exporter._materialExporter.getTextureInfo(r.coatWeightTexture),i=void 0,i=r.useCoatRoughnessFromWeightTexture?n._exporter._materialExporter.getTextureInfo(r.coatWeightTexture):n._exporter._materialExporter.getTextureInfo(r.coatRoughnessTexture),r.coatColorTexture&&p.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),o=n._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),null===(a={clearcoatFactor:r.coatWeight,clearcoatTexture:null!=s?s:void 0,clearcoatRoughnessFactor:r.coatRoughness,clearcoatRoughnessTexture:null!=i?i:void 0,clearcoatNormalTexture:null!=o?o:void 0}).clearcoatTexture&&null===a.clearcoatRoughnessTexture&&null===a.clearcoatRoughnessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[xe]=a}e(t)}))},e}();re.RegisterExtension(xe,(function(e){return new me(e)}));var ye="KHR_materials_clearcoat_darkening",ve=function(){function e(e){this.name=ye,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,t,r){return g(this,void 0,void 0,(function(){var e;return _(this,(function(t){return e=[],r instanceof p.OpenPBRMaterial&&r.coatDarkening?(r.coatDarkeningTexture&&e.push(r.coatDarkeningTexture),[2,e]):[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var s=null,i=null;if(r instanceof p.OpenPBRMaterial&&(s=r.coatDarkening,i=r.coatDarkeningTexture),null===s||1===s&&null===i)return e(t);var o=t.extensions?t.extensions.KHR_materials_clearcoat:null;if(!o)return e(t);n._wasUsed=!0;var a=n._exporter._materialExporter.getTextureInfo(i),u={clearcoatDarkeningFactor:s,clearcoatDarkeningTexture:null!=a?a:void 0};return null!==u.clearcoatDarkeningTexture&&n._exporter._materialNeedsUVsSet.add(r),o.extensions=o.extensions||{},o.extensions[ye]=u,e(t)}))},e}();re.RegisterExtension(ye,(function(e){return new ve(e)}),105);var Te="KHR_materials_clearcoat_ior",be=function(){function e(e){this.name=Te,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.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var s=null;if(r instanceof p.OpenPBRMaterial?s=r.coatIor:r instanceof p.PBRMaterial&&(s=r.clearCoat.indexOfRefraction),null===s||1.5===s)return e(t);var i=t.extensions?t.extensions.KHR_materials_clearcoat:null;if(!i)return e(t);n._wasUsed=!0;var o={clearcoatIor:s};return n._exporter,i.extensions=i.extensions||{},i.extensions[Te]=o,e(t)}))},e}();re.RegisterExtension(Te,(function(e){return new be(e)}),105);var Ae="KHR_materials_clearcoat_color",we=function(){function e(e){this.name=Ae,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,t,r){return g(this,void 0,void 0,(function(){var e;return _(this,(function(t){if(e=[],r instanceof p.PBRBaseMaterial){if(r.clearCoat.isEnabled)return r.clearCoat.tintTexture&&e.push(r.clearCoat.tintTexture),[2,e]}else if(r instanceof p.OpenPBRMaterial&&r.coatWeight>0)return r.coatColorTexture&&e.push(r.coatColorTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof p.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(t);if(n._wasUsed=!0,!(i=t.extensions?t.extensions.KHR_materials_clearcoat:null))return void e(t);var s=n._exporter._materialExporter.getTextureInfo(r.clearCoat.tintTexture);null!==(o={clearcoatColorFactor:r.clearCoat.tintColor.asArray(),clearcoatColorTexture:null!=s?s:void 0}).clearcoatColorTexture&&n._exporter._materialNeedsUVsSet.add(r),i.extensions=i.extensions||{},i.extensions[Ae]=o}else if(r instanceof p.OpenPBRMaterial){if(0==r.coatWeight)return void e(t);var i,o;if(n._wasUsed=!0,!(i=t.extensions?t.extensions.KHR_materials_clearcoat:null))return void e(t);s=n._exporter._materialExporter.getTextureInfo(r.coatWeightTexture),null!==(o={clearcoatColorFactor:r.coatColor.asArray(),clearcoatColorTexture:null!=s?s:void 0}).clearcoatColorTexture&&n._exporter._materialNeedsUVsSet.add(r),i.extensions=i.extensions||{},i.extensions[Ae]=o}e(t)}))},e}();re.RegisterExtension(Ae,(function(e){return new we(e)}),105);var Ee="KHR_materials_clearcoat_anisotropy";function Me(e,t){t.uOffset=e.uOffset,t.vOffset=e.vOffset,t.uScale=e.uScale,t.vScale=e.vScale,t.uAng=e.uAng,t.vAng=e.vAng,t.wAng=e.wAng,t.uRotationCenter=e.uRotationCenter,t.vRotationCenter=e.vRotationCenter}function Re(e){return g(this,void 0,void 0,(function(){var t,r,n,s,i,o,a,u;return _(this,(function(c){switch(c.label){case 0:return t=e.getScene(),p.Effect.ShadersStore.anisotropyMergeFragmentShader||(p.Effect.ShadersStore.anisotropyMergeFragmentShader="\n precision highp float;\n#ifdef HAS_TANGENT_TEXTURE\n uniform sampler2D tangentTexture;\n#endif\n#ifdef HAS_ANISOTROPY_TEXTURE\n uniform sampler2D anisotropyTexture;\n#endif\n uniform int useRoughnessFromMetallicGreen;\n uniform int useAnisotropyFromTangentBlue;\n\n varying vec2 vUV;\n\n void main() {\n vec2 tangent = vec2(1.0, 0.0);\n float anisotropy = 1.0;\n #ifdef HAS_TANGENT_TEXTURE\n // Tangent texture is present\n vec4 tangentSample = texture2D(tangentTexture, vUV);\n tangent = tangentSample.rg;\n\n if (useAnisotropyFromTangentBlue > 0) {\n anisotropy = tangentSample.b;\n }\n #endif\n #ifdef HAS_ANISOTROPY_TEXTURE\n // Anisotropy texture is present\n vec4 anisotropySample = texture2D(anisotropyTexture, vUV);\n anisotropy = anisotropySample.r;\n #endif\n \n // Output: RG = tangent XY, B = anisotropy strength\n vec4 anisotropyData = vec4(tangent.x, tangent.y, anisotropy, 1.0);\n gl_FragColor = anisotropyData;\n }\n"),r=e.coatRoughnessAnisotropyTexture,n=e.geometryCoatTangentTexture,r||n?(s=Math.max(r?r.getSize().width:1,n?n.getSize().width:1),i=Math.max(r?r.getSize().height:1,n?n.getSize().height:1),o={type:p.Constants.TEXTURETYPE_UNSIGNED_BYTE,format:p.Constants.TEXTUREFORMAT_RGBA,samplingMode:p.Constants.TEXTURE_BILINEAR_SAMPLINGMODE,generateDepthBuffer:!1,generateStencilBuffer:!1,generateMipMaps:!1},(a=new p.ProceduralTexture(e.name+"_anisotropy",{width:s,height:i},"anisotropyMerge",t,o)).refreshRate=-1,u="",n&&(u+="#define HAS_TANGENT_TEXTURE\n",a.setTexture("tangentTexture",n),Me(n,a)),a.setVector2("tangentVector",e.geometryTangent),r&&(u+="#define HAS_ANISOTROPY_TEXTURE\n",a.setTexture("anisotropyTexture",r),Me(r,a)),a.setInt("useAnisotropyFromTangentBlue",e._useCoatRoughnessAnisotropyFromTangentTexture?1:0),a.defines=u,[4,new Promise((function(e,t){a.executeWhenReady((function(){try{a.render(),e(a)}catch(e){t(e instanceof Error?e:new Error(String(e)))}}))}))]):[2,null];case 1:return[2,c.sent()]}}))}))}var Ce=function(){function e(e){this.name=Ee,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,t,r){return g(this,void 0,void 0,(function(){var e,t;return _(this,(function(n){switch(n.label){case 0:return e=[],r instanceof p.OpenPBRMaterial&&r.coatRoughnessAnisotropy>0?[4,Re(r)]:[3,2];case 1:return(t=n.sent())&&(e.push(t),this._anisoTexturesMap[r.id]=t),[2,e];case 2:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var s,i,o,a,u,c;if(r instanceof p.OpenPBRMaterial&&r.coatRoughnessAnisotropy>0){t.extensions=t.extensions||{};var l=t.extensions?t.extensions.KHR_materials_clearcoat:null;if(!l)return e(t);n._wasUsed=!0;var f=r.coatRoughnessTexture,h=n._anisoTexturesMap[r.id];if(!f&&!h){var d=r.coatRoughness,g=r.coatRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){var _=(i=r.coatRoughness,c=(1-(o=r.coatRoughnessAnisotropy))*(u=(a=i*i)*Math.sqrt(2/(1+(1-o)*(1-o)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-a)/Math.max(1-a,1e-4)),1)});d=_.newBaseRoughness,g=_.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=d);var x={clearcoatAnisotropyStrength:g,clearcoatAnisotropyRotation:r.geometryCoatTangentAngle+.5*Math.PI,clearcoatAnisotropyTexture:void 0};return l.extensions=l.extensions||{},l.extensions[Ee]=x,e(t)}var m=h?n._exporter._materialExporter.getTextureInfo(h):null,y={clearcoatAnisotropyStrength:r.coatRoughnessAnisotropy,clearcoatAnisotropyRotation:r.geometryCoatTangentAngle,clearcoatAnisotropyTexture:m||void 0,extensions:{}};r._useGltfStyleAnisotropy||(y.extensions.EXT_materials_anisotropy_openpbr={openPbrAnisotropyEnabled:!0},(s=n._exporter._glTF).extensionsUsed||(s.extensionsUsed=[]),-1===n._exporter._glTF.extensionsUsed.indexOf("EXT_materials_anisotropy_openpbr")&&n._exporter._glTF.extensionsUsed.push("EXT_materials_anisotropy_openpbr")),n._exporter._materialNeedsUVsSet.add(r),l.extensions=l.extensions||{},l.extensions[Ee]=y}e(t)}))},e}();re.RegisterExtension(Ee,(function(e){return new Ce(e)}),105);var Se="KHR_materials_diffuse_transmission";function Ve(e,t){var r=t.subSurface,n=null;return r.translucencyIntensityTexture?n=r.translucencyIntensityTexture:r.thicknessTexture&&r.useMaskFromThicknessTexture&&(n=r.thicknessTexture),n&&!r.useGltfStyleTextures?(p.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(t.name),1),null):n}var Be=function(){function e(e){this.name=Se,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,t,r){return g(this,void 0,void 0,(function(){var t,n;return _(this,(function(s){return t=[],r instanceof p.PBRMaterial&&this._isExtensionEnabled(r)?((n=Ve(e,r))&&t.push(n),r.subSurface.translucencyColorTexture&&t.push(r.subSurface.translucencyColorTexture),[2,t]):[2,t]}))}))},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,t,r){var n=this;return new Promise((function(s){var i,o;if(r instanceof p.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var a=r.subSurface,u=Ve(e,r),c=0==a.translucencyIntensity?void 0:a.translucencyIntensity,l=null!==(i=n._exporter._materialExporter.getTextureInfo(u))&&void 0!==i?i:void 0,f=!a.translucencyColor||a.translucencyColor.equalsFloats(1,1,1)?void 0:a.translucencyColor.asArray(),h=null!==(o=n._exporter._materialExporter.getTextureInfo(a.translucencyColorTexture))&&void 0!==o?o:void 0,d={diffuseTransmissionFactor:c,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:f,diffuseTransmissionColorTexture:h};(l||h)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions=t.extensions||{},t.extensions[Se]=d}s(t)}))},e}();re.RegisterExtension(Se,(function(e){return new Be(e)}));var Ie="KHR_materials_dispersion",Fe=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,t,r){var n=this;return new Promise((function(e){if(r instanceof p.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var s={dispersion:r.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[Ie]=s}e(t)}))},e}();re.RegisterExtension(Ie,(function(){return new Fe}));var Ue="KHR_materials_emissive_strength",Ne=function(){function e(){this.name=Ue,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,t,r){return g(this,void 0,void 0,(function(){var e=this;return _(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){if(!(r instanceof p.PBRMaterial))return n(t);var s=r.emissiveColor.scale(r.emissiveIntensity),i=Math.max.apply(Math,s.asArray());if(i>1){t.emissiveFactor=s.scale(1/i).asArray(),e._wasUsed=!0;var o={emissiveStrength:i};t.extensions||(t.extensions={}),t.extensions[Ue]=o}else t.emissiveFactor=s.asArray();return n(t)}))];case 1:return[2,n.sent()]}}))}))},e}();re.RegisterExtension(Ue,(function(){return new Ne}));var Oe="KHR_materials_ior",Pe=function(){function e(){this.name=Oe,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&&null!=e.indexOfRefraction&&1.5!=e.indexOfRefraction},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof p.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var s={ior:r.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[Oe]=s}e(t)}))},e}();re.RegisterExtension(Oe,(function(e){return new Pe}));var Le="KHR_materials_iridescence",Ke=function(){function e(e){this.name=Le,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,t,r){return g(this,void 0,void 0,(function(){var e;return _(this,(function(t){if(e=[],r instanceof p.PBRBaseMaterial){if(r.iridescence.isEnabled)return r.iridescence.texture&&e.push(r.iridescence.texture),r.iridescence.thicknessTexture&&r.iridescence.thicknessTexture!==r.iridescence.texture&&e.push(r.iridescence.thicknessTexture),[2,e]}else if(r instanceof p.OpenPBRMaterial&&r.thinFilmWeight>0)return r.thinFilmWeightTexture&&e.push(r.thinFilmWeightTexture),r.thinFilmThicknessTexture&&r.thinFilmThicknessTexture!==r.thinFilmWeightTexture&&e.push(r.thinFilmThicknessTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof p.PBRBaseMaterial){if(!r.iridescence.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var s=n._exporter._materialExporter.getTextureInfo(r.iridescence.texture),i=n._exporter._materialExporter.getTextureInfo(r.iridescence.thicknessTexture);null===(o={iridescenceFactor:r.iridescence.intensity,iridescenceIor:r.iridescence.indexOfRefraction,iridescenceThicknessMinimum:r.iridescence.minimumThickness,iridescenceThicknessMaximum:r.iridescence.maximumThickness,iridescenceTexture:null!=s?s:void 0,iridescenceThicknessTexture:null!=i?i:void 0}).iridescenceTexture&&null===o.iridescenceThicknessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Le]=o}else if(r instanceof p.OpenPBRMaterial){if(r.thinFilmWeight<=0)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var o,a=n._exporter._materialExporter.getTextureInfo(r.thinFilmWeightTexture),u=n._exporter._materialExporter.getTextureInfo(r.thinFilmThicknessTexture);null===(o={iridescenceFactor:r.thinFilmWeight,iridescenceIor:r.thinFilmIor,iridescenceThicknessMinimum:1e3*r.thinFilmThicknessMin,iridescenceThicknessMaximum:1e3*r.thinFilmThickness,iridescenceTexture:null!=a?a:void 0,iridescenceThicknessTexture:null!=u?u:void 0}).iridescenceTexture&&null===o.iridescenceThicknessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Le]=o}e(t)}))},e}();re.RegisterExtension(Le,(function(e){return new Ke(e)}));var ke="KHR_materials_sheen",De=function(){function e(e){this.name=ke,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,t,r){return g(this,void 0,void 0,(function(){return _(this,(function(e){return r instanceof p.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[2,[r.sheen.texture]]:[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var e=this;return _(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){var s,i,o,a;if(r instanceof p.PBRMaterial){if(!r.sheen.isEnabled)return void n(t);e._wasUsed=!0,null==t.extensions&&(t.extensions={});var u={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(s=r.sheen.roughness)&&void 0!==s?s:0};null===u.sheenColorTexture&&null===u.sheenRoughnessTexture||e._exporter._materialNeedsUVsSet.add(r),r.sheen.texture&&(u.sheenColorTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==i?i:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(o=e._exporter._materialExporter.getTextureInfo(r.sheen.textureRoughness))&&void 0!==o?o:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==a?a:void 0),t.extensions[ke]=u}n(t)}))];case 1:return[2,n.sent()]}}))}))},e}();re.RegisterExtension(ke,(function(e){return new De(e)}));var He="KHR_materials_specular",Ge=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,t,r){return g(this,void 0,void 0,(function(){var e;return _(this,(function(t){return e=[],r instanceof p.PBRMaterial&&this._isExtensionEnabled(r)?(r.metallicReflectanceTexture&&e.push(r.metallicReflectanceTexture),r.reflectanceTexture&&e.push(r.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,t,r){var n=this;return new Promise((function(e){var s,i,o,a,u;if(r instanceof p.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0,t.extensions=t.extensions||{};var c=null!==(s=n._exporter._materialExporter.getTextureInfo(r.metallicReflectanceTexture))&&void 0!==s?s:void 0,l=null!==(i=n._exporter._materialExporter.getTextureInfo(r.reflectanceTexture))&&void 0!==i?i:void 0,f={specularFactor:1==r.metallicF0Factor?void 0:r.metallicF0Factor,specularTexture:c,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:l};n._hasTexturesExtension(r)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[He]=f}else if(r instanceof p.OpenPBRMaterial){t.extensions=t.extensions||{};var h=null!==(o=n._exporter._materialExporter.getTextureInfo(r.specularWeightTexture))&&void 0!==o?o:void 0,d=null!==(a=n._exporter._materialExporter.getTextureInfo(r.specularColorTexture))&&void 0!==a?a:void 0,g=1==r.specularWeight?void 0:r.specularWeight,_=r.specularColor.equalsFloats(1,1,1)?void 0:r.specularColor.asArray();if(!d&&!h&&void 0===g&&void 0===_)return e(t);n._wasUsed=!0,(f={specularFactor:g,specularTexture:h,specularColorFactor:_,specularColorTexture:d,extensions:{}}).extensions.EXT_materials_specular_edge_color={specularEdgeColorEnabled:!0},(u=n._exporter._glTF).extensionsUsed||(u.extensionsUsed=[]),-1===n._exporter._glTF.extensionsUsed.indexOf("EXT_materials_specular_edge_color")&&n._exporter._glTF.extensionsUsed.push("EXT_materials_specular_edge_color"),(h||d)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[He]=f}e(t)}))},e}();re.RegisterExtension(He,(function(e){return new Ge(e)}));var We="KHR_materials_transmission",qe=function(){function e(e){this.name=We,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,t,r){return g(this,void 0,void 0,(function(){var e;return _(this,(function(t){return e=[],r instanceof p.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&e.push(r.subSurface.thicknessTexture),[2,e]):[2,e]}))}))},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return t.isRefractionEnabled&&null!=t.refractionIntensity&&0!=t.refractionIntensity||this._hasTexturesExtension(e)},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.refractionIntensityTexture},e.prototype.postExportMaterialAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,s,i,o;return _(this,(function(a){switch(a.label){case 0:return r instanceof p.PBRMaterial&&this._isExtensionEnabled(r)?(this._wasUsed=!0,n=r.subSurface,s=0===n.refractionIntensity?void 0:n.refractionIntensity,i={transmissionFactor:s},this._hasTexturesExtension(r)&&this._exporter._materialNeedsUVsSet.add(r),n.refractionIntensityTexture?n.useGltfStyleTextures?[4,this._exporter._materialExporter.exportTextureAsync(n.refractionIntensityTexture)]:[3,2]:[3,3]):[3,4];case 1:return(o=a.sent())&&(i.transmissionTexture=o),[3,3];case 2:p.Logger.Warn("".concat(e,": Exporting a subsurface refraction intensity texture without `useGltfStyleTextures` is not supported")),a.label=3;case 3:t.extensions||(t.extensions={}),t.extensions[We]=i,a.label=4;case 4:return[2,t]}}))}))},e}();re.RegisterExtension(We,(function(e){return new qe(e)}));var ze="KHR_materials_unlit",je=function(){function e(){this.name=ze,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,t,r){var n=this;return new Promise((function(e){var s=!1;r instanceof p.PBRMaterial?s=r.unlit:r instanceof p.StandardMaterial&&(s=r.disableLighting),s&&(n._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[ze]={}),e(t)}))},e}();re.RegisterExtension(ze,(function(){return new je}));var Xe="KHR_materials_volume",Qe=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,t,r){return g(this,void 0,void 0,(function(){var e;return _(this,(function(t){return e=[],r instanceof p.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&e.push(r.subSurface.thicknessTexture),[2,e]):[2,e]}))}))},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isTranslucencyEnabled)&&(null!=t.maximumThickness&&0!=t.maximumThickness||null!=t.tintColorAtDistance&&t.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=t.tintColor&&t.tintColor!=p.Color3.White()||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.thicknessTexture},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var s;if(r instanceof p.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var i=r.subSurface,o={thicknessFactor:0==i.maximumThickness?void 0:i.maximumThickness,thicknessTexture:null!==(s=n._exporter._materialExporter.getTextureInfo(i.thicknessTexture))&&void 0!==s?s:void 0,attenuationDistance:i.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:i.tintColorAtDistance,attenuationColor:i.tintColor.equalsFloats(1,1,1)?void 0:i.tintColor.asArray()};n._hasTexturesExtension(r)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions=t.extensions||{},t.extensions[Xe]=o}e(t)}))},e}();re.RegisterExtension(Xe,(function(e){return new Qe(e)}));var Ye="KHR_materials_diffuse_roughness",Ze=function(){function e(e){this.name=Ye,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,t,r){return g(this,void 0,void 0,(function(){var e;return _(this,(function(t){if(e=[],r instanceof p.PBRBaseMaterial){if(r._baseDiffuseRoughness)return r._baseDiffuseRoughnessTexture&&e.push(r._baseDiffuseRoughnessTexture),[2,e]}else if(r instanceof p.OpenPBRMaterial&&r.baseDiffuseRoughness)return r.baseDiffuseRoughnessTexture&&e.push(r.baseDiffuseRoughnessTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var s=null,i=null;if(r instanceof p.PBRBaseMaterial?(s=r._baseDiffuseRoughness,i=r._baseDiffuseRoughnessTexture):r instanceof p.OpenPBRMaterial&&(s=r.baseDiffuseRoughness,i=r.baseDiffuseRoughnessTexture),s){n._wasUsed=!0,t.extensions=t.extensions||{};var o=n._exporter._materialExporter.getTextureInfo(i),a={diffuseRoughnessFactor:s,diffuseRoughnessTexture:null!=o?o:void 0};null!==a.diffuseRoughnessTexture&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[Ye]=a,e(t)}else e(t)}))},e}();re.RegisterExtension(Ye,(function(e){return new Ze(e)}));var Je="KHR_texture_transform",$e=function(){function e(){this.name=Je,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,t,r){if(r.getScene()||p.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(r.name,"!")),0===r.uAng&&0===r.vAng||(p.Tools.Warn("".concat(e,": Texture ").concat(r.name," with rotation in the u or v axis is not supported in glTF.")),0===r.uRotationCenter&&0===r.vRotationCenter)){var n={},s=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],s=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],s=!0),0!==r.wAng){if(0!==r.uRotationCenter||0!==r.vRotationCenter){if(r.homogeneousRotationInUVTransform&&r.uScale!==r.vScale)return void p.Tools.Warn("".concat(e,": Texture ").concat(r.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(Je,"."));p.Tools.Warn("".concat(e,": Texture ").concat(r.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(Je,".")),n.offset=function(e){var t=e.uOffset,r=e.vOffset,n=e.uRotationCenter,s=e.vRotationCenter,i=e.uScale,o=e.vScale,a=e.wAng,u=Math.cos(a),c=Math.sin(a),l=n*i,f=s*o;return[t+(l*(1-u)+f*c),r+(f*(1-u)-l*c)]}(r)}n.rotation=-r.wAng,s=!0}0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,s=!0),s&&(this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[Je]=n)}},e}();re.RegisterExtension(Je,(function(){return new $e}));var et="KHR_texture_basisu",tt=function(){function e(e){this.name=et,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,t){var r=this._exporter._textures[t.index],n=r.source;if(void 0!==n){var s=this._exporter._images[n];"image/ktx2"===(s.mimeType||(0,p.GetMimeType)(s.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[et]={source:n},this._wasUsed=!0)}},e}();re.RegisterExtension(et,(function(e){return new tt(e)}));var rt="EXT_texture_webp",nt=function(){function e(e){this.name=rt,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,t){var r=this._exporter._textures[t.index],n=r.source;if(void 0!==n){var s=this._exporter._images[n];"image/webp"===(s.mimeType||(0,p.GetMimeType)(s.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[rt]={source:n},this._wasUsed=!0)}},e}();re.RegisterExtension(rt,(function(e){return new nt(e)}));var st="EXT_texture_avif",it=function(){function e(e){this.name=st,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,t){var r=this._exporter._textures[t.index],n=r.source;if(void 0!==n){var s=this._exporter._images[n];"image/avif"===(s.mimeType||(0,p.GetMimeType)(s.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[st]={source:n},this._wasUsed=!0)}},e}();re.RegisterExtension(st,(function(e){return new it(e)}));var ot=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==ot){ot.BABYLON=ot.BABYLON||{};var at=ot.BABYLON;at.GLTF2=at.GLTF2||{},at.GLTF2.Exporter=at.GLTF2.Exporter||{},at.GLTF2.Exporter.Extensions=at.GLTF2.Exporter.Extensions||{};var ut=[];for(var ct in i)at[ct]=i[ct],ut.push(ct);for(var ct in o)at[ct]=o[ct],ut.push(ct);for(var ct in a)at[ct]=a[ct],ut.push(ct);for(var ct in u)at.GLTF2.Exporter.Extensions[ct]=u[ct],ut.push(ct);for(var ct in c)ut.indexOf(ct)>-1||(at.GLTF2.Exporter[ct]=c[ct])}const lt=l;return s.default})()));
2
2
  //# sourceMappingURL=babylon.glTF2Serializer.min.js.map