babylonjs-serializers 8.2.0 → 8.2.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,r,n={597:t=>{t.exports=e}},o={};function i(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return n[e](r,r.exports,i),r.exports}r=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,i.t=function(e,n){if(1&n&&(e=this(e)),8&n)return e;if("object"==typeof e&&e){if(4&n&&e.__esModule)return e;if(16&n&&"function"==typeof e.then)return e}var o=Object.create(null);i.r(o);var s={};t=t||[null,r({}),r([]),r(r)];for(var a=2&n&&e;"object"==typeof a&&!~t.indexOf(a);a=r(a))Object.getOwnPropertyNames(a).forEach((t=>s[t]=()=>e[t]));return s.default=()=>e,i.d(o,s),o},i.d=(e,t)=>{for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};i.d(s,{default:()=>We});var a={};i.r(a),i.d(a,{__IGLTFExporterExtension:()=>p});var u={};i.r(u),i.d(u,{GLTFData:()=>m});var c={};i.r(c),i.d(c,{GLTF2Export:()=>ne});var l={};i.r(l),i.d(l,{EXT_mesh_gpu_instancing:()=>ie,KHR_draco_mesh_compression:()=>ae,KHR_lights_punctual:()=>he,KHR_materials_anisotropy:()=>de,KHR_materials_clearcoat:()=>_e,KHR_materials_diffuse_transmission:()=>ye,KHR_materials_dispersion:()=>Te,KHR_materials_emissive_strength:()=>Ae,KHR_materials_ior:()=>Ee,KHR_materials_iridescence:()=>Re,KHR_materials_sheen:()=>Ce,KHR_materials_specular:()=>Ie,KHR_materials_transmission:()=>Be,KHR_materials_unlit:()=>Pe,KHR_materials_volume:()=>Ue,KHR_texture_transform:()=>Ke});var f={};i.r(f),i.d(f,{EXT_mesh_gpu_instancing:()=>ie,GLTF2Export:()=>ne,GLTFData:()=>m,KHR_draco_mesh_compression:()=>ae,KHR_lights_punctual:()=>he,KHR_materials_anisotropy:()=>de,KHR_materials_clearcoat:()=>_e,KHR_materials_diffuse_transmission:()=>ye,KHR_materials_dispersion:()=>Te,KHR_materials_emissive_strength:()=>Ae,KHR_materials_ior:()=>Ee,KHR_materials_iridescence:()=>Re,KHR_materials_sheen:()=>Ce,KHR_materials_specular:()=>Ie,KHR_materials_transmission:()=>Be,KHR_materials_unlit:()=>Pe,KHR_materials_volume:()=>Ue,KHR_texture_transform:()=>Ke,_ConvertToGLTFPBRMetallicRoughness:()=>M,_SolveMetallic:()=>E});var h={};i.r(h),i.d(h,{EXT_mesh_gpu_instancing:()=>ie,GLTF2Export:()=>ne,GLTFData:()=>m,KHR_draco_mesh_compression:()=>ae,KHR_lights_punctual:()=>he,KHR_materials_anisotropy:()=>de,KHR_materials_clearcoat:()=>_e,KHR_materials_diffuse_transmission:()=>ye,KHR_materials_dispersion:()=>Te,KHR_materials_emissive_strength:()=>Ae,KHR_materials_ior:()=>Ee,KHR_materials_iridescence:()=>Re,KHR_materials_sheen:()=>Ce,KHR_materials_specular:()=>Ie,KHR_materials_transmission:()=>Be,KHR_materials_unlit:()=>Pe,KHR_materials_volume:()=>Ue,KHR_texture_transform:()=>Ke,_ConvertToGLTFPBRMetallicRoughness:()=>M,_SolveMetallic:()=>E,__IGLTFExporterExtension:()=>p});var p=0,d=i(597),m=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,d.GetMimeType)(e)});d.Tools.Download(r,e)}},e}(),_=function(){return _=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},_.apply(this,arguments)};function g(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(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?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((n=n.apply(e,t||[])).next())}))}function x(e,t){var r,n,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=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(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function y(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var v=1e-6,T=new d.Color3(.04,.04,.04),b=1024,A=d.Color3.White(),w=d.Color3.Black();function E(e,t,r){if(t<T.r)return 0;var n=T.r,o=e*r/(1-T.r)+t-2*T.r,i=o*o-4*n*(T.r-t);return d.Scalar.Clamp((-o+Math.sqrt(i))/(2*n),0,1)}function M(e){var t=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),r=e.alpha,n=d.Scalar.Clamp(e.specularPower,0,b),o=(0,d.SpecularPowerToRoughness)(n);return{baseColorFactor:[t.r,t.g,t.b,r],metallicFactor:0,roughnessFactor:o}}function R(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function V(e,t,r){for(var n=new Uint8Array(e*t*4),o=0;o<n.length;o+=4)n[o]=n[o+1]=n[o+2]=n[o+3]=255;return d.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,r){return g(this,void 0,void 0,(function(){var n,o,i,s,a,u,c,l;return x(this,(function(f){switch(f.label){case 0:return n=M(e),o={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||d.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),o.doubleSided=!0),r?(i=[],(s=e.diffuseTexture)&&i.push(this.exportTextureAsync(s,t).then((function(e){e&&(n.baseColorTexture=e)}))),(a=e.bumpTexture)&&i.push(this.exportTextureAsync(a,t).then((function(e){e&&(o.normalTexture=e,1!==a.level&&(o.normalTexture.scale=a.level))}))),(u=e.emissiveTexture)&&(o.emissiveFactor=[1,1,1],i.push(this.exportTextureAsync(u,t).then((function(e){e&&(o.emissiveTexture=e)})))),(c=e.ambientTexture)&&i.push(this.exportTextureAsync(c,t).then((function(e){if(e){var t={index:e.index};o.occlusionTexture=t}}))),i.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(i)]):[3,2]):[3,2];case 1:f.sent(),f.label=2;case 2:return(e.alpha<1||e.opacityTexture)&&(e.alphaMode===d.Constants.ALPHA_COMBINE?o.alphaMode="BLEND":d.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(w,v)&&(o.emissiveFactor=e.emissiveColor.asArray()),o.pbrMetallicRoughness=n,R(o,e),[4,this._finishMaterialAsync(o,e,t)];case 3:return f.sent(),(l=this._exporter._materials).push(o),[2,l.length-1]}}))}))},e.prototype._finishMaterialAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,o,i,s,a;return x(this,(function(u){switch(u.label){case 0:for(n=this._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",e,t),o=[],i=0,s=n;i<s.length;i++)a=s[i],o.push(this.exportTextureAsync(a,r));return[4,Promise.all(o)];case 1:return u.sent(),[4,this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)];case 2:return u.sent(),[2]}}))}))},e.prototype._getImageDataAsync=function(e,t,r,n){return g(this,void 0,void 0,(function(){var o,s,a,u,c;return x(this,(function(l){switch(l.label){case 0:return o=d.Constants.TEXTURETYPE_UNSIGNED_BYTE,s=this._exporter._babylonScene,a=s.getEngine(),u=a.createRawTexture(e,t,r,d.Constants.TEXTUREFORMAT_RGBA,!1,!0,d.Texture.NEAREST_SAMPLINGMODE,null,o),a.isWebGPU?[4,Promise.resolve().then(i.t.bind(i,597,23))]:[3,2];case 1:return l.sent(),[3,4];case 2:return[4,Promise.resolve().then(i.t.bind(i,597,23))];case 3:l.sent(),l.label=4;case 4:return[4,d.TextureTools.ApplyPostProcess("pass",u,s,o,d.Constants.TEXTURE_NEAREST_SAMPLINGMODE,d.Constants.TEXTUREFORMAT_RGBA)];case 5:return l.sent(),[4,a._readTexturePixels(u,t,r)];case 6:return c=l.sent(),[4,d.DumpTools.DumpDataAsync(t,r,c,n,void 0,!0,!0)];case 7:return[2,l.sent()]}}))}))},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,o,i=e?e.getSize():{width:0,height:0},s=t?t.getSize():{width:0,height:0};return i.width<s.width?(n=e&&e instanceof d.Texture?d.TextureTools.CreateResizedCopy(e,s.width,s.height,!0):V(s.width,s.height,r),o=t):i.width>s.width?(o=t&&t instanceof d.Texture?d.TextureTools.CreateResizedCopy(t,i.width,i.height,!0):V(i.width,i.height,r),n=e):(n=e,o=t),{texture1:n,texture2:o}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,r,n){return g(this,void 0,void 0,(function(){var o,i,s,a,u,c,l,f,h,p,m,_,g,y,T,b,E,M,R,V,S,I,F,B,N,P,O,U,L,K,k;return x(this,(function(x){switch(x.label){case 0:return o=new Array,e||t?(i=e?e.getScene():t?t.getScene():null)?(s=this._resizeTexturesToSameDimensions(e,t,i),a=null===(k=s.texture1)||void 0===k?void 0:k.getSize(),u=void 0,c=void 0,l=a.width,f=a.height,[4,s.texture1.readPixels()]):[3,3]:[2,Promise.reject("diffuse and specular glossiness textures are not defined!")];case 1:return h=x.sent(),[4,s.texture2.readPixels()];case 2:if(p=x.sent(),!h)return[2,Promise.reject("Failed to retrieve pixels from diffuse texture!")];if(u=C(h),!p)return[2,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];for(c=C(p),m=c.byteLength,_=new Uint8Array(m),g=new Uint8Array(m),y=w,T=0,b=0,P=0;P<f;++P)for(O=0;O<l;++O)E=4*(l*P+O),M=new d.Color3(u[E],u[E+1],u[E+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(r.diffuseColor),R=new d.Color3(c[E],c[E+1],c[E+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(r.specularColor),V=c[E+3]*r.glossiness,S={diffuseColor:M,specularColor:R,glossiness:V},I=this._convertSpecularGlossinessToMetallicRoughness(S),y.r=Math.max(y.r,I.baseColor.r),y.g=Math.max(y.g,I.baseColor.g),y.b=Math.max(y.b,I.baseColor.b),T=Math.max(T,I.metallic),b=Math.max(b,I.roughness),g[E]=255*I.baseColor.r,g[E+1]=255*I.baseColor.g,g[E+2]=255*I.baseColor.b,g[E+3]=s.texture1.hasAlpha?255*u[E+3]:255,_[E]=0,_[E+1]=255*I.roughness,_[E+2]=255*I.metallic,_[E+3]=255;for(F={baseColor:y,metallic:T,roughness:b},B=!1,N=!1,P=0;P<f;++P)for(O=0;O<l;++O)g[U=4*(l*P+O)]/=F.baseColor.r>v?F.baseColor.r:1,g[U+1]/=F.baseColor.g>v?F.baseColor.g:1,g[U+2]/=F.baseColor.b>v?F.baseColor.b:1,L=d.Color3.FromInts(g[U],g[U+1],g[U+2]),K=L.toGammaSpace(i.getEngine().useExactSrgbConversions),g[U]=255*K.r,g[U+1]=255*K.g,g[U+2]=255*K.b,K.equalsWithEpsilon(A,v)||(N=!0),_[U+1]/=F.roughness>v?F.roughness:1,_[U+2]/=F.metallic>v?F.metallic:1,d.Color3.FromInts(255,_[U+1],_[U+2]).equalsWithEpsilon(A,v)||(B=!0);return B&&o.push(this._getImageDataAsync(_,l,f,n).then((function(e){F.metallicRoughnessTextureData=e}))),N&&o.push(this._getImageDataAsync(g,l,f,n).then((function(e){F.baseColorTextureData=e}))),[2,Promise.all(o).then((function(){return F}))];case 3:return[2,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),o=E(t,r,n),i=e.diffuseColor.scale(n/(1-T.r)/Math.max(1-o)),s=e.specularColor.subtract(T.scale(1-o)).scale(1/Math.max(o)),a=d.Color3.Lerp(i,s,o*o);return{baseColor:a=a.clampToRef(0,1,a),metallic:o,roughness:1-e.glossiness}},e.prototype._getPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},e.prototype._getMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},e.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,r,n){return g(this,void 0,void 0,(function(){var o,i,s;return x(this,(function(a){switch(a.label){case 0:return o=[],i={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness},n&&(e._albedoTexture&&o.push(this.exportTextureAsync(e._albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)}))),(s=e._metallicTexture)&&o.push(this.exportTextureAsync(s,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))),o.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(o)]):[3,2];case 1:a.sent(),a.label=2;case 2:return[2,i]}}))}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof d.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 d.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case d.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case d.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case d.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case d.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case d.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case d.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case d.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case d.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case d.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case d.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case d.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case d.Texture.WRAP_ADDRESSMODE:return 10497;case d.Texture.CLAMP_ADDRESSMODE:return 33071;case d.Texture.MIRROR_ADDRESSMODE:return 33648;default:return d.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r,n){return g(this,void 0,void 0,(function(){var o,i,s,a,u,c,l,f;return x(this,(function(h){switch(h.label){case 0:return o={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},i=e._albedoTexture,s=e._reflectivityTexture,a=e._useMicroSurfaceFromReflectivityMapAlpha,s&&!a?[2,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")]:(i||s)&&n?(this._exporter._materialNeedsUVsSet.add(e),u=this._exportTextureSampler(i||s),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(i,s,o,t)]):[3,2];case 1:return c=h.sent(),l=this._exporter._textures,c.baseColorTextureData&&(f=this._exportImage("baseColor".concat(l.length),t,c.baseColorTextureData),r.baseColorTexture=this._exportTextureInfo(f,u,null==i?void 0:i.coordinatesIndex)),c.metallicRoughnessTextureData&&(f=this._exportImage("metallicRoughness".concat(l.length),t,c.metallicRoughnessTextureData),r.metallicRoughnessTexture=this._exportTextureInfo(f,u,null==s?void 0:s.coordinatesIndex)),[2,c];case 2:return[2,this._convertSpecularGlossinessToMetallicRoughness(o)]}}))}))},e.prototype.exportPBRMaterialAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,o,i,s,a,u,c,l;return x(this,(function(f){switch(f.label){case 0:return n={},o={name:e.name},(i=e.isMetallicWorkflow())&&(s=e._albedoColor,a=e.alpha,s&&(n.baseColorFactor=[s.r,s.g,s.b,a])),i?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,n,r)]:[3,2];case 1:return c=f.sent(),[3,4];case 2:return[4,this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,n,r)];case 3:c=f.sent(),f.label=4;case 4:return u=c,[4,this._setMetallicRoughnessPbrMaterialAsync(u,e,o,n,t,r)];case 5:return f.sent(),[4,this._finishMaterialAsync(o,e,t)];case 6:return f.sent(),(l=this._exporter._materials).push(o),[2,l.length-1]}}))}))},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,t,r,n,o,i){return g(this,void 0,void 0,(function(){var s,a,u,c,l;return x(this,(function(f){switch(f.label){case 0:return R(r,t),e.baseColor.equalsWithEpsilon(A,v)&&d.Scalar.WithinEpsilon(t.alpha,1,v)||(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||d.Tools.Warn(t.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),i?(s=[],(a=t._bumpTexture)&&s.push(this.exportTextureAsync(a,o).then((function(e){e&&(r.normalTexture=e,1!==a.level&&(r.normalTexture.scale=a.level))}))),(u=t._ambientTexture)&&s.push(this.exportTextureAsync(u,o).then((function(e){if(e){var n={index:e.index,texCoord:e.texCoord,extensions:e.extensions};r.occlusionTexture=n;var o=t._ambientTextureStrength;o&&(n.strength=o)}}))),(c=t._emissiveTexture)&&s.push(this.exportTextureAsync(c,o).then((function(e){e&&(r.emissiveTexture=e)}))),s.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(s)]):[3,2]):[3,2];case 1:f.sent(),f.label=2;case 2:return(l=t._emissiveColor).equalsWithEpsilon(w,v)||(r.emissiveFactor=l.asArray()),r.pbrMetallicRoughness=n,[2]}}))}))},e.prototype._getPixelsFromTexture=function(e){return e.textureType,d.Constants.TEXTURETYPE_UNSIGNED_BYTE,e.readPixels()},e.prototype.exportTextureAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n=this;return x(this,(function(o){return(r=this._exporter._extensionsPreExportTextureAsync("exporter",e,t))?[2,r.then((function(r){return r?n._exportTextureInfoAsync(r,t):n._exportTextureInfoAsync(e,t)}))]:[2,this._exportTextureInfoAsync(e,t)]}))}))},e.prototype._exportTextureInfoAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,o,i,s,a,u,c,l,f=this;return x(this,(function(h){switch(h.label){case 0:return(r=this._textureMap.get(e))?[3,3]:[4,this._getPixelsFromTexture(e)];case 1:if(!(n=h.sent()))return[2,null];if(o=this._exportTextureSampler(e),i=e.mimeType)switch(i){case"image/jpeg":case"image/png":case"image/webp":t=i;break;default:d.Tools.Warn("Unsupported media type: ".concat(i))}return s=this._internalTextureToImage,a=e.getInternalTexture().uniqueId,s[a]||(s[a]={}),void 0===(u=s[a][t])&&(c=e.getSize(),u=g(f,void 0,void 0,(function(){var r;return x(this,(function(o){switch(o.label){case 0:return[4,this._getImageDataAsync(n,c.width,c.height,t)];case 1:return r=o.sent(),[2,this._exportImage(e.name,t,r)]}}))})),s[a][t]=u),l=this._exportTextureInfo,[4,u];case 2:r=l.apply(this,[h.sent(),o,e.coordinatesIndex]),this._textureMap.set(e,r),this._exporter._extensionsPostExportTextures("exporter",r,e),h.label=3;case 3:return[2,r]}}))}))},e.prototype._exportImage=function(e,t,r){var n,o=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 s=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"}}(t),u=s+a;o.some((function(e){return e.uri===u}))&&(u="".concat(s,"_").concat(d.Tools.RandomId()).concat(a)),n={name:e,uri:u},this._exporter._imageData[u]={data:r,mimeType:t}}return o.push(n),o.length-1},e.prototype._exportTextureInfo=function(e,t,r){var n=this._exporter._textures,o=n.findIndex((function(r){return r.sampler==t&&r.source===e}));-1===o&&(o=n.length,n.push({source:e,sampler:t}));var i={index:o};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}(),I=d.Matrix.Compose(new d.Vector3(-1,1,1),d.Quaternion.Identity(),d.Vector3.Zero()),F=new d.Quaternion(0,1,0,0),B=1e-6,N=d.Vector3.Zero(),P=d.Vector3.One();function O(e,t){var r=e.byteOffset,n=e.byteStride,o=e.type,i=e.normalized,s=e.getSize(),a=t.reduce((function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e}),-Number.MAX_VALUE);return{byteOffset:r,byteStride:n,componentCount:s,type:o,count:a*s,normalized:i,totalVertices:a,kind:e.getKind()}}function U(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 d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:case d.VertexBuffer.TangentKind:case d.VertexBuffer.ColorKind:case d.VertexBuffer.MatricesIndicesKind:case d.VertexBuffer.MatricesIndicesExtraKind:case d.VertexBuffer.MatricesWeightsKind:case d.VertexBuffer.MatricesWeightsExtraKind:case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:case d.VertexBuffer.UV3Kind:case d.VertexBuffer.UV4Kind:case d.VertexBuffer.UV5Kind:case d.VertexBuffer.UV6Kind:return!0}return!1}function K(e){switch(e){case d.Material.TriangleFillMode:return 4;case d.Material.TriangleStripDrawMode:return 5;case d.Material.TriangleFanDrawMode:return 6;case d.Material.PointListDrawMode:case d.Material.PointFillMode:return 0;case d.Material.LineLoopDrawMode:return 2;case d.Material.LineListDrawMode:return 1;case d.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 G(e){return e.x*=-1,e.y*=-1,e}function H(e){return e.multiplyInPlace(F)}function W(e,t){return t instanceof d.TransformNode&&1==t.getChildren().length&&0==e.getChildren().length}function j(e,t){if(!(e instanceof d.TransformNode))return!1;if(t){if(!e.getWorldMatrix().isIdentity())return!1}else if(!e.getWorldMatrix().multiplyToRef(I,d.TmpVectors.Matrix[0]).isIdentity())return!1;return!(e instanceof d.Mesh&&e.geometry||e instanceof d.InstancedMesh&&e.sourceMesh.geometry)}function q(e,t){for(var r=0,n=Object.entries(e);r<n.length;r++){var o=n[r],i=o[0],s=o[1],a=t[i];(Array.isArray(s)&&Array.isArray(a)&&z(s,a)||s===a)&&delete e[i]}return e}function z(e,t){return e.length===t.length&&e.every((function(e,r){return e===t[r]}))}var Q=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)}]]),Y=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=Q.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 X(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 Y(t),n=0,o=Array.from(this._bufferViewToData.keys()).sort((function(e,t){return X(t.byteLength)-X(e.byteLength)}));n<o.length;n++){var i=o[n];i.byteOffset=r.byteOffset,e.push(i);for(var s=e.length-1,a=0,u=this.getPropertiesWithBufferView(i);a<u.length;a++)u[a].bufferView=s;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,o,i,s){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:s,byteOffset:o};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 o=n[r];void 0!==o.bufferView&&delete o.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 d.TransformNode||e instanceof d.Camera||e instanceof d.Light)},e._CreateNodeAnimation=function(t,r,n,o,i){if(this._IsTransformable(t)){var s=[],a=[],u=r.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,n,o),f=l.interpolationType,h=l.shouldBakeAnimation;if(h?e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,i,s,a,c,o):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(t,r,n,s,a,o):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(t,r,n,s,a,o):e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,i,s,a,c,o),s.length&&a.length)return{inputs:s,outputs:a,samplerInterpolation:f,inputsMin:h?c.min:d.Tools.FloatRound(c.min/r.framePerSecond),inputsMax:h?c.max:d.Tools.FloatRound(c.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,o=e.targetProperty.split(".");switch(o[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:d.Tools.Error("Unsupported animatable property ".concat(o[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(d.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,r,n,o,i,s,a,u,c,l,f){var h;if(e._IsTransformable(t)&&t.animations)for(var p=0,d=t.animations;p<d.length;p++){var m=d[p];if(!f||f(m)){var _=e._DeduceAnimationInfo(m);_&&(h={name:m.name,samplers:[],channels:[]},e._AddAnimation("".concat(m.name),m.hasRunningRuntimeAnimations?r:h,t,m,_.dataAccessorType,_.animationChannelTargetPath,o,s,a,u,_.useQuaternion,c,l),h.samplers.length&&h.channels.length&&n.push(h))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,o,i,s,a,u,c,l,f){var h;if(t instanceof d.Mesh){var p=t.morphTargetManager;if(p)for(var m=0;m<p.numTargets;++m)for(var _=0,g=p.getTarget(m).animations;_<g.length;_++){var x=g[_];if(!f||f(x)){for(var y=new d.Animation("".concat(x.name),"influence",x.framePerSecond,x.dataType,x.loopMode,x.enableBlending),v=[],T=x.getKeys(),b=0;b<T.length;++b)for(var A=T[b],w=0;w<p.numTargets;++w)w==m?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(x.name,x.hasRunningRuntimeAnimations?r:h,t,y,E.dataAccessorType,E.animationChannelTargetPath,o,s,a,u,E.useQuaternion,c,l,p.numTargets),h.samplers.length&&h.channels.length&&n.push(h))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,o,i,s,a,u,c){var l,f;if(t.animationGroups)for(var h=t.animationGroups,p=function(h){var p=new Map,_=new Map,g=new Set,x=h.to-h.from;f={name:h.name,channels:[],samplers:[]};for(var y=function(r){var x=h.targetedAnimations[r],y=x.target,v=x.animation;if(c&&!c(v))return"continue";var T=u.has(y);if(m._IsTransformable(y)||1===y.length&&m._IsTransformable(y[0])){if(A=e._DeduceAnimationInfo(x.animation)){var b=m._IsTransformable(y)?y:m._IsTransformable(y[0])?y[0]:null;b&&e._AddAnimation("".concat(v.name),f,b,v,A.dataAccessorType,A.animationChannelTargetPath,n,o,i,s,A.useQuaternion,a,T)}}else if(y instanceof d.MorphTarget||1===y.length&&y[0]instanceof d.MorphTarget){var A;if(A=e._DeduceAnimationInfo(x.animation)){var w=y instanceof d.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&&(p.has(M)||p.set(M,new Map),null===(l=p.get(M))||void 0===l||l.set(w,v),g.add(M),_.set(M,v))}}}}},v=0;v<h.targetedAnimations.length;++v)y(v);g.forEach((function(t){for(var r=t.morphTargetManager,u=null,c=[],l=_.get(t).getKeys(),m=l.length,g=0;g<m;++g)for(var y=0;y<r.numTargets;++y){var v=r.getTarget(y),T=p.get(t);if(T){var b=T.get(v);b?(u||(u=new d.Animation("".concat(h.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,d.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[g])):c.push({frame:h.from+x/m*g,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,o,i,s,A.useQuaternion,a,!1,null==r?void 0:r.numTargets)})),f.channels.length&&f.samplers.length&&r.push(f)},m=this,_=0,g=h;_<g.length;_++)p(g[_])},e._AddAnimation=function(t,r,n,o,i,s,a,u,c,l,f,h,p,m){var _,g,x,y,v,T,b=e._CreateNodeAnimation(n,o,s,f,h);if(b){if(m){for(var A=0,w=0,E=[];b.inputs.length>0;)w=b.inputs.shift(),A%m==0&&E.push(w),A++;b.inputs=E}var M=a.get(n),R=new Float32Array(b.inputs);_=u.createBufferView(R),g=u.createAccessor(_,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(g),x=l.length-1;var V=new d.Quaternion,C=new d.Vector3,S=new d.Vector3,I=n instanceof d.Camera,F=U(i),B=new Float32Array(b.outputs.length*F);b.outputs.forEach((function(e,t){var r=e;if(p)switch(s){case"translation":d.Vector3.FromArrayToRef(e,0,S),D(S),S.toArray(r);break;case"rotation":4===e.length?d.Quaternion.FromArrayToRef(e,0,V):(r=new Array(4),d.Vector3.FromArrayToRef(e,0,C),d.Quaternion.FromEulerVectorToRef(C,V)),I?H(V):d.Quaternion.IsIdentity(V)||G(V),V.toArray(r)}else"rotation"===s&&(4===e.length?d.Quaternion.FromArrayToRef(e,0,V):(r=new Array(4),d.Vector3.FromArrayToRef(e,0,C),d.Quaternion.FromEulerVectorToRef(C,V)),I&&H(V),V.toArray(r));B.set(r,t*F)})),_=u.createBufferView(B),g=u.createAccessor(_,i,5126,b.outputs.length),l.push(g),y=l.length-1,v={interpolation:b.samplerInterpolation,input:x,output:y},r.samplers.push(v),T={sampler:r.samplers.length-1,target:{node:M,path:s}},r.channels.push(T)}},e._CreateBakedAnimation=function(t,r,n,o,i,s,a,u,c,l,f){var h,p,m=d.Quaternion.Identity(),_=null,g=null,x=null,y=null,v=null,T=null;l.min=d.Tools.FloatRound(o/s);for(var b=r.getKeys(),A=0,w=b.length;A<w;++A){if(T=null,x=b[A],A+1<w)if(y=b[A+1],x.value.equals&&x.value.equals(y.value)||x.value===y.value){if(0!==A)continue;T=x.frame}else T=y.frame;else{if(v=b[A-1],x.value.equals&&x.value.equals(v.value)||x.value===v.value)continue;T=i}if(T)for(var E=x.frame;E<=T;E+=a)if((p=d.Tools.FloatRound(E/s))!==_){_=p,g=p;var M={key:0,repeatCount:0,loopMode:r.loopMode};h=r._interpolate(E,M),e._SetInterpolatedValue(t,h,p,r,n,m,u,c,f)}}g&&(l.max=g)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,o,i){var s=e._GetBasePositionRotationOrScale(r,o,i),a=n.targetProperty.split("."),u=a?a[1]:"",c=i?d.Quaternion.FromArray(s).normalize():d.Vector3.FromArray(s);switch(u){case"x":case"y":case"z":c[u]=t;break;case"w":c.w=t;break;default:d.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return c},e._SetInterpolatedValue=function(e,t,r,n,o,i,s,a,u){var c;s.push(r),"weights"!==o?(n.dataType===d.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,o,u)),"rotation"===o?(u?i=t:(c=t,d.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,o,i,s){for(var a=0,u=r.getKeys();a<u.length;a++){var c=u[a];o.push(c.frame/r.framePerSecond),e._AddKeyframeValue(c,r,i,n,t,s)}},e._CreateCubicSplineAnimation=function(t,r,n,o,i,s){r.getKeys().forEach((function(a){o.push(a.frame/r.framePerSecond),e._AddSplineTangent(Z.INTANGENT,i,n,"CUBICSPLINE",a,s),e._AddKeyframeValue(a,r,i,n,t,s),e._AddSplineTangent(Z.OUTTANGENT,i,n,"CUBICSPLINE",a,s)}))},e._GetBasePositionRotationOrScale=function(e,t,r){var n;if("rotation"===t)if(r){var o=e.rotationQuaternion;n=(null!=o?o:d.Quaternion.Identity()).asArray()}else{var i=e.rotation;n=(null!=i?i:d.Vector3.Zero()).asArray()}else if("translation"===t){var s=e.position;n=(null!=s?s:d.Vector3.Zero()).asArray()}else{var a=e.scaling;n=(null!=a?a:d.Vector3.One()).asArray()}return n},e._AddKeyframeValue=function(e,t,r,n,o,i){var s,a=t.dataType;if(a===d.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===n){var c=d.Vector3.FromArray(u);u=d.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}r.push(u)}else if(a===d.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(s=this._ConvertFactorToVector3OrQuaternion(e.value,o,t,n,i)){if("rotation"===n){var l=i?s:d.Quaternion.RotationYawPitchRoll(s.y,s.x,s.z).normalize();r.push(l.asArray())}r.push(s.asArray())}}else a===d.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):d.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,o,i=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var s=0,a=e.length;s<a;++s)if((o=e[s]).inTangent||o.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",i=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||o.interpolation&&1===o.interpolation&&"STEP"!==n){n="LINEAR",i=!0;break}}else n=o.interpolation&&1===o.interpolation?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,t,r,n,o,i){var s,a=e===Z.INTANGENT?o.inTangent:o.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(a)if(i)s=a.asArray();else{var u=a;s=d.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else s=[0,0,0,0];else s="weights"===r?a?[a]:[0]:a?a.asArray():[0,0,0];t.push(s)}},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,o,i){var s={attributes:{},influence:e.influence,name:e.name},a=i?-1:1,u=d.Vector3.Zero(),c=0;if(e.hasPositions){var l=e.getPositions(),f=t.getVerticesData(d.VertexBuffer.PositionKind,void 0,void 0,!0);if(f){var h=new Float32Array(f.length),p=[1/0,1/0,1/0],m=[-1/0,-1/0,-1/0];c=f.length/3;for(var _=0;_<c;++_){var g=d.Vector3.FromArray(f,3*_);d.Vector3.FromArray(l,3*_).subtractToRef(g,u),u.x*=a,p[0]=Math.min(p[0],u.x),m[0]=Math.max(m[0],u.x),p[1]=Math.min(p[1],u.y),m[1]=Math.max(m[1],u.y),p[2]=Math.min(p[2],u.z),m[2]=Math.max(m[2],u.z),h[3*_]=u.x,h[3*_+1]=u.y,h[3*_+2]=u.z}var x=r.createBufferView(h,12),y=r.createAccessor(x,"VEC3",5126,l.length/3,0,{min:p,max:m});o.push(y),s.attributes.POSITION=o.length-1}else d.Tools.Warn("Morph target positions for mesh ".concat(t.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var v=e.getNormals(),T=t.getVerticesData(d.VertexBuffer.NormalKind,void 0,void 0,!0);if(T){var b=new Float32Array(T.length);for(c=T.length/3,_=0;_<c;++_){var A=d.Vector3.FromArray(T,3*_).normalize();d.Vector3.FromArray(v,3*_).normalize().subtractToRef(A,u),b[3*_]=u.x*a,b[3*_+1]=u.y,b[3*_+2]=u.z}x=r.createBufferView(b,12),y=r.createAccessor(x,"VEC3",5126,v.length/3,0),o.push(y),s.attributes.NORMAL=o.length-1}else d.Tools.Warn("Morph target normals for mesh ".concat(t.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var w=e.getTangents(),E=t.getVerticesData(d.VertexBuffer.TangentKind,void 0,void 0,!0);if(E){c=E.length/4;var M=new Float32Array(3*c);for(_=0;_<c;++_){var R=d.Vector3.FromArray(E,4*_);k(R);var V=d.Vector3.FromArray(w,3*_);k(V),V.subtractToRef(R,u),M[3*_]=u.x*a,M[3*_+1]=u.y,M[3*_+2]=u.z}x=r.createBufferView(M,12),y=r.createAccessor(x,"VEC3",5126,c,0),o.push(y),s.attributes.TANGENT=o.length-1}else d.Tools.Warn("Morph target tangents for mesh ".concat(t.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var C=e.getColors(),S=t.getVerticesData(d.VertexBuffer.ColorKind,void 0,void 0,!0),I=t.getVertexBuffer(d.VertexBuffer.ColorKind,!0);if(S&&I){var F=I.getSize();c=S.length/F;var B=new Float32Array(c*F);for(_=0;_<c;++_)if(3===F){var N=d.Vector3.FromArray(S,_*F);d.Vector3.FromArray(C,_*F).subtractToRef(N,u),B[3*_]=u.x,B[3*_+1]=u.y,B[3*_+2]=u.z}else if(4===F){var P=new d.Vector4;N=d.Vector4.FromArray(S,_*F),d.Vector4.FromArray(C,_*F).subtractToRef(N,P),B[4*_]=P.x,B[4*_+1]=P.y,B[4*_+2]=P.z,B[4*_+3]=P.w}else d.Tools.Warn("Unsupported number of components for color attribute: ".concat(F));x=r.createBufferView(B,4*F),y=r.createAccessor(x,3===F?"VEC3":"VEC4",5126,c,0),o.push(y),s.attributes.COLOR_0=o.length-1}else d.Tools.Warn("Morph target colors for mesh ".concat(t.name," were not exported. Mesh does not have colors vertex data"))}return s}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,o){var i,s,a,u;return null===(u=null===(a=null===(s=null===(i=this._indicesAccessorMap.get(e))||void 0===i?void 0:i.get(t))||void 0===s?void 0:s.get(r))||void 0===a?void 0:a.get(n))||void 0===u?void 0:u.get(o)},e.prototype.setIndicesAccessor=function(e,t,r,n,o,i){var s=this._indicesAccessorMap.get(e);s||(s=new Map,this._indicesAccessorMap.set(e,s));var a=s.get(t);a||(a=new Map,s.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(o,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,o;return null===(o=null===(n=this._vertexAccessorMap.get(e))||void 0===n?void 0:n.get(t))||void 0===o?void 0:o.get(r)},e.prototype.setVertexAccessor=function(e,t,r,n){var o=this._vertexAccessorMap.get(e);o||(o=new Map,this._vertexAccessorMap.set(e,o));var i=o.get(t);i||(i=new Map,o.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=d.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(d.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=_({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 o=this;if(r>=t.length)return Promise.resolve(e);var i=n(t[r],e);return i?i.then((function(e){return e?o._applyExtension(e,t,r+1,n):null})):this._applyExtension(e,t,r+1,n)},e.prototype._applyExtensions=function(t,r){for(var n=[],o=0,i=e._ExtensionNames;o<i.length;o++){var s=i[o];n.push(this._extensions[s])}return this._applyExtension(t,n,0,r)},e.prototype._extensionsPreExportTextureAsync=function(e,t,r){return this._applyExtensions(t,(function(t,n){return t.preExportTextureAsync&&t.preExportTextureAsync(e,n,r)}))},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n,o){var i=this;return this._applyExtensions(t,(function(t,s){return t.postExportNodeAsync&&t.postExportNodeAsync(e,s,r,n,o,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._extensionsPostExportMaterialAdditionalTextures=function(t,r,n){for(var o=[],i=0,s=e._ExtensionNames;i<s.length;i++){var a=s[i],u=this._extensions[a];u.postExportMaterialAdditionalTextures&&o.push.apply(o,u.postExportMaterialAdditionalTextures(t,r,n))}return o},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var o=0,i=e._ExtensionNames;o<i.length;o++){var s=i[o],a=this._extensions[s];a.postExportTexture&&a.postExportTexture(t,r,n)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var o=n[r],i=this._extensions[o];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,o;return x(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],(o=this._extensions[n]).preGenerateBinaryAsync?[4,o.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 o=n[r],i=this._extensions[o];i.enabled&&t(i)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){var r,n,o;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)),(o=e._glTF).extensions||(o.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],o=e._ExtensionFactories[n](this);this._extensions[n]=o}},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){e.UnregisterExtension(t)&&d.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=r,e._ExtensionNames.push(t)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[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,o,i,s,a;return x(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"}),o=e+".gltf",i=e+".bin",(s=new m).files[o]=r,s.files[i]=n,this._imageData)for(a in this._imageData)s.files[a]=new Blob([this._imageData[a].data],{type:this._imageData[a].mimeType});return[2,s]}}))}))},e.prototype._generateBinaryAsync=function(){return g(this,void 0,void 0,(function(){return x(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,o,i,s,a,u,c,l,f,h,p,d,_,g,y,v,T,b,A,w,E,M;return x(this,(function(x){switch(x.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=x.sent(),this._extensionsOnExporting(),r=this._generateJSON(t.byteLength),n=e+".glb",o=r.length,"undefined"!=typeof TextEncoder&&(s=new TextEncoder,i=s.encode(r),o=i.length),a=this._getPadding(o),u=this._getPadding(t.byteLength),c=28+o+a+t.byteLength+u,l=new ArrayBuffer(12),(f=new DataView(l)).setUint32(0,1179937895,!0),f.setUint32(4,2,!0),f.setUint32(8,c,!0),h=new ArrayBuffer(8+o+a),(p=new DataView(h)).setUint32(0,o+a,!0),p.setUint32(4,1313821514,!0),d=new Uint8Array(h,8),i)d.set(i);else for(_="_".charCodeAt(0),w=0;w<o;++w)(g=r.charCodeAt(w))!=r.codePointAt(w)?d[w]=_:d[w]=g;for(y=new Uint8Array(h,8+o),w=0;w<a;++w)y[w]=32;for(v=new ArrayBuffer(8),(T=new DataView(v)).setUint32(0,t.byteLength+u,!0),T.setUint32(4,5130562,!0),b=new ArrayBuffer(u),A=new Uint8Array(b),w=0;w<u;++w)A[w]=0;return E=new Blob([l,h,v,t,b],{type:"application/octet-stream"}),(M=new m).files[n]=E,[2,M]}}))}))},e.prototype._setNodeTransformation=function(e,t,r){if(t.getPivotPoint().equalsToFloats(0,0,0)||d.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsToFloats(0,0,0)){var n=d.TmpVectors.Vector3[0].copyFrom(t.position);r&&D(n),e.translation=n.asArray()}t.scaling.equalsToFloats(1,1,1)||(e.scale=t.scaling.asArray());var o=d.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);t.rotationQuaternion&&o.multiplyInPlace(t.rotationQuaternion),d.Quaternion.IsIdentity(o)||(r&&G(o),e.rotation=o.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,r,n){var o=d.TmpVectors.Vector3[0],i=d.TmpVectors.Quaternion[0];if(null!==n){var s=d.Matrix.Invert(n.getWorldMatrix());t.getWorldMatrix().multiply(s).decompose(void 0,i,o)}else t.getWorldMatrix().decompose(void 0,i,o);o.equalsToFloats(0,0,0)||(e.translation=o.asArray()),d.Quaternion.IsIdentity(i)||(e.rotation=i.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===d.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===d.Camera.FOVMODE_VERTICAL_FIXED?r.fov:r.fov*r.getEngine().getAspectRatio(r),znear:r.minZ,zfar:r.maxZ};else if("orthographic"===n.type){var o=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:o,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 o=0,i=n;o<i.length;o++)i[o].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(){for(var e,t=function(t){if(t.bones.length<=0)return"continue";var n=r._skinMap.get(t);if(null==n)return"continue";for(var o={},i=[],s=-1,a=0;a<t.bones.length;++a){var u=t.bones[a];-1!==(c=null!==(e=u.getIndex())&&void 0!==e?e:a)&&(o[c]=u,c>s&&(s=c))}for(var c=0;c<=s;++c){u=o[c],i.push(u.getAbsoluteInverseBindMatrix());var l=u.getTransformNode();if(null!==l){var f=r._nodeMap.get(l);l&&null!=f?n.joints.push(f):d.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}else d.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}var h=r._nodesSkinMap.get(n);if(n.joints.length>0&&void 0!==h){var p=64*i.length,m=new Float32Array(p/4);i.forEach((function(e,t){m.set(e.m,16*t)}));var _=r._bufferManager.createBufferView(m);r._accessors.push(r._bufferManager.createAccessor(_,"MAT4",5126,i.length)),n.inverseBindMatrices=r._accessors.length-1,r._skins.push(n);for(var g=0,x=h;g<x.length;g++)x[g].skin=r._skins.length-1}},r=this,n=0,o=this._babylonScene.skeletons;n<o.length;n++)t(o[n])},e.prototype._exportSceneAsync=function(){return g(this,void 0,void 0,(function(){var e,t,r,n,o,i,s,a,u,c,l,f,h,p,d,m,_,g,y,v,T,b,A;return x(this,(function(x){switch(x.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,o=new Array,i=0,s=this._babylonScene.rootNodes;i<s.length;i++)a=s[i],this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&j(a,this._babylonScene.useRightHandedSystem)?o.push.apply(o,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([x.sent()])),h=new te(!1,!1),d=(p=(b=e.nodes).push).apply,m=[b],[4,this._exportNodesAsync(r,h)];case 2:return d.apply(p,m.concat([x.sent()])),_=new te(!1,!0),y=(g=(A=e.nodes).push).apply,v=[A],[4,this._exportNodesAsync(o,_)];case 3:return y.apply(g,v.concat([x.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(),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,o,i;return x(this,(function(s){switch(s.label){case 0:r=new Array,this._exportBuffers(e,t),n=0,o=e,s.label=1;case 1:return n<o.length?(i=o[n],[4,this._exportNodeAsync(i,r,t)]):[3,4];case 2:s.sent(),s.label=3;case 3:return n++,[3,1];case 4:return[2,r]}}))}))},e.prototype._collectBuffers=function(e,t,r,n,o){if(this._shouldExportNode(e)&&e instanceof d.Mesh&&e.geometry){var i=e.geometry.getVertexBuffers();if(i)for(var s in i)if(L(s)){var a=i[s];o.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 p=f.getTarget(h);l=n.get(p)||[],n.set(p,l),-1===l.indexOf(e)&&l.push(e)}}for(var m=0,_=e.getChildren();m<_.length;m++){var g=_[m];this._collectBuffers(g,t,r,n,o)}},e.prototype._exportBuffers=function(e,t){for(var r=new Map,n=new Map,o=new Map,i=0,s=e;i<s.length;i++){var a=s[i];this._collectBuffers(a,r,n,o,t)}for(var u=Array.from(r.keys()),c=function(e){var o=e.getData();if(!o)throw new Error("Buffer data is not available");var i=r.get(e);if(!i)return"continue";var s=i[0].byteStride;if(i.some((function(e){return e.byteStride!==s})))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)}(o).slice(),u=function(e){var t=n.get(e),r=O(e,t),o=r.byteOffset,i=r.byteStride,s=r.componentCount,u=r.type,c=r.count,f=r.normalized;switch(r.kind){case d.VertexBuffer.NormalKind:case d.VertexBuffer.TangentKind:(0,d.EnumerateFloatValues)(a,o,i,s,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 d.VertexBuffer.ColorKind:var h=t.filter((function(e){return e.material instanceof d.StandardMaterial||null==e.material})).length;if(0==h)break;if(h!=t.length){d.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}u==d.VertexBuffer.UNSIGNED_BYTE&&d.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var p=new d.Color3,m=new d.Color4,_=l._babylonScene.getEngine().useExactSrgbConversions;(0,d.EnumerateFloatValues)(a,o,i,s,u,c,f,(function(e){3===e.length?(p.fromArray(e,0),p.toLinearSpaceToRef(p,_),p.toArray(e,0)):(m.fromArray(e,0),m.toLinearSpaceToRef(m,_),m.toArray(e,0))}))}},c=0,f=i;c<f.length;c++)u(F=f[c]);if(t.convertToRightHanded){for(var h=0,p=i;h<p.length;h++){var m=O(F=p[h],n.get(F)),_=m.byteOffset,g=m.byteStride,x=m.componentCount,y=m.type,v=m.count,T=m.normalized;switch(R=m.kind){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:case d.VertexBuffer.TangentKind:(0,d.EnumerateFloatValues)(a,_,g,x,y,v,T,(function(e){e[0]=-e[0]}))}}t.convertedToRightHandedBuffers.set(e,a)}var b=l._bufferManager.createBufferView(a,s);t.setVertexBufferView(e,b);for(var A=new Map,w=0,E=i;w<E.length;w++){var M=O(F=E[w],n.get(F)),R=M.kind,V=M.totalVertices;switch(R){case d.VertexBuffer.MatricesIndicesKind:case d.VertexBuffer.MatricesIndicesExtraKind:if(F.type==d.VertexBuffer.FLOAT){var C=F.getFloatData(V);null!==C&&A.set(F,C)}}}0!==A.size&&d.Logger.Warn("Joints conversion needed: some joints 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 S=0,I=Array.from(A.keys());S<I.length;S++){var F=I[S],B=A.get(F);if(B){for(var N=B.some((function(e){return e>=256})),P=new(N?Uint16Array:Uint8Array)(B.length),U=0;U<B.length;U++)P[U]=B[U];var L=l._bufferManager.createBufferView(P,4*(N?2:1));t.setRemappedBufferView(e,F,L)}}},l=this,f=0,h=u;f<h.length;f++)c(h[f]);for(var p=0,m=Array.from(o.keys());p<m.length;p++){var _=m[p],g=o.get(_);if(g)for(var x=ee(_,g[0],this._bufferManager,this._bufferViews,this._accessors,t.convertToRightHanded),y=0,v=g;y<v.length;y++){var T=v[y];t.bindMorphDataToMesh(T,x)}}},e.prototype._exportNodeAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,o,i,s,a,u,c,l,f=this;return x(this,(function(h){switch(h.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:(o=h.sent())&&(n=this._nodes.length,this._nodes.push(o),this._nodeMap.set(e,n),r.pushExportedNode(e),t.push(n),i={name:"runtime animations",channels:[],samplers:[]},s=[],this._babylonScene.animationGroups.length||($._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,s,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&$._CreateNodeAnimationFromNodeAnimations(e,i,s,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),s.forEach((function(e){e.channels.length&&e.samplers.length&&f._animations.push(e)}))),a=o?[]:t,u=0,c=e.getChildren(),h.label=2;case 2:return u<c.length?(l=c[u],[4,this._exportNodeAsync(l,a,r)]):[3,5];case 3:h.sent(),h.label=4;case 4:return u++,[3,2];case 5:return o&&a.length&&(o.children=a),[2]}}))}))},e.prototype._createNodeAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,o,i,s,a,u,c,l,f,h,p;return x(this,(function(m){switch(m.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 d.TransformNode?(this._setNodeTransformation(r,e,t.convertToRightHanded),e instanceof d.Mesh||e instanceof d.InstancedMesh?(o=e instanceof d.Mesh?e:e.sourceMesh).subMeshes&&o.subMeshes.length>0?(i=r,[4,this._exportMeshAsync(o,t)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:i.mesh=m.sent(),m.label=2;case 2:e.skeleton&&void 0!==(s=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(s)&&this._nodesSkinMap.set(s,[]),null===(f=this._nodesSkinMap.get(s))||void 0===f||f.push(r)),m.label=3;case 3:if(e instanceof d.Camera&&(a=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(a)&&this._nodesCameraMap.set(a,[]),u=e.parent,this._setCameraTransformation(r,e,t.convertToRightHanded,u),u&&W(e,u)&&(c=this._nodeMap.get(u)))return l=this._nodes[c],null===(h=this._nodesCameraMap.get(a))||void 0===h||h.push(l),[2,null];t.convertToRightHanded&&(_=r,g=d.Vector3.FromArrayToRef(_.translation||[0,0,0],0,d.TmpVectors.Vector3[0]),x=d.Quaternion.FromArrayToRef(_.rotation||[0,0,0,1],0,d.TmpVectors.Quaternion[0]),g=D(g),x=G(x),g.equalsWithEpsilon(N,B)?delete _.translation:_.translation=g.asArray(),d.Quaternion.IsIdentity(x)?delete _.rotation:_.rotation=x.asArray(),function(e){var t=d.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,d.TmpVectors.Quaternion[1]);F.multiplyToRef(t,t),e.rotation=t.asArray()}(r)),null===(p=this._nodesCameraMap.get(a))||void 0===p||p.push(r)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",r,e,this._nodeMap,t.convertToRightHanded)];case 4:return m.sent()?[2,r]:(d.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}var _,g,x}))}))},e.prototype._exportIndices=function(e,t,r,n,o,i,s,a,u){var c=e;u.mode=K(i);var l=s!==d.Material.CounterClockWiseSideOrientation,f=!a.wasAddedByNoopNode&&l,h=function(e){switch(e){case d.Material.TriangleFillMode:case d.Material.TriangleStripDrawMode:case d.Material.TriangleFanDrawMode:return!0}return!1}(i)&&f;if(h){if(i===d.Material.TriangleStripDrawMode||i===d.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");u.mode=K(i);var p=t?new Uint32Array(n):new Uint16Array(n);if(e)for(var m=0;m+2<n;m+=3)p[m]=e[r+m]+o,p[m+1]=e[r+m+2]+o,p[m+2]=e[r+m+1]+o;else for(m=0;m+2<n;m+=3)p[m]=m,p[m+1]=m+2,p[m+2]=m+1;c=p}else if(e&&0!==o){for(p=t?new Uint32Array(n):new Uint16Array(n),m=0;m<n;m++)p[m]=e[r+m]+o;c=p}if(c){var _=a.getIndicesAccessor(e,r,n,o,h);if(void 0===_){var g=function(e,t,r,n){if(e instanceof Uint16Array||e instanceof Uint32Array)return e;if(e instanceof Int32Array)return new Uint32Array(e.buffer,e.byteOffset,e.length);var o=e.slice(0,0+r);return n?new Uint32Array(o):new Uint16Array(o)}(c,0,n,t),x=this._bufferManager.createBufferView(g),y=t?5125:5123;this._accessors.push(this._bufferManager.createAccessor(x,"SCALAR",y,n,0)),_=this._accessors.length-1,a.setIndicesAccessor(e,r,n,o,h,_)}u.indices=_}},e.prototype._exportVertexBuffer=function(e,t,r,n,o,i){var s=e.getKind();if(L(s)&&(!s.startsWith("uv")||this._options.exportUnusedUVs||t&&this._materialNeedsUVsSet.has(t))){var a=o.getVertexAccessor(e,r,n);if(void 0===a){var u=o.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),c=s===d.VertexBuffer.PositionKind?function(e,t,r,n){var o=t.byteOffset,i=t.byteStride,s=t.type,a=t.normalized,u=t.getSize(),c=new Array(u).fill(1/0),l=new Array(u).fill(-1/0);return(0,d.EnumerateFloatValues)(e,o+r*i,i,u,s,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=(s===d.VertexBuffer.MatricesIndicesKind||s===d.VertexBuffer.MatricesIndicesExtraKind)&&e.type===d.VertexBuffer.FLOAT,f=l?d.VertexBuffer.UNSIGNED_BYTE:e.type,h=l?void 0:e.normalized,p=l?o.getRemappedBufferView(e._buffer,e):o.getVertexBufferView(e._buffer),m=e.byteOffset+r*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(p,function(e,t){if(e==d.VertexBuffer.ColorKind)return t?"VEC4":"VEC3";switch(e){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:return"VEC3";case d.VertexBuffer.TangentKind:case d.VertexBuffer.MatricesIndicesKind:case d.VertexBuffer.MatricesIndicesExtraKind:case d.VertexBuffer.MatricesWeightsKind:case d.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:case d.VertexBuffer.UV3Kind:case d.VertexBuffer.UV4Kind:case d.VertexBuffer.UV5Kind:case d.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(s,o.hasVertexColorAlpha(e)),f,n,m,c,h)),a=this._accessors.length-1,o.setVertexAccessor(e,r,n,a)}i.attributes[function(e){switch(e){case d.VertexBuffer.PositionKind:return"POSITION";case d.VertexBuffer.NormalKind:return"NORMAL";case d.VertexBuffer.TangentKind:return"TANGENT";case d.VertexBuffer.ColorKind:return"COLOR_0";case d.VertexBuffer.UVKind:return"TEXCOORD_0";case d.VertexBuffer.UV2Kind:return"TEXCOORD_1";case d.VertexBuffer.UV3Kind:return"TEXCOORD_2";case d.VertexBuffer.UV4Kind:return"TEXCOORD_3";case d.VertexBuffer.UV5Kind:return"TEXCOORD_4";case d.VertexBuffer.UV6Kind:return"TEXCOORD_5";case d.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case d.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case d.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case d.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(s)]=a}},e.prototype._exportMaterialAsync=function(e,t,r,n){return g(this,void 0,void 0,(function(){var o,i;return x(this,(function(s){switch(s.label){case 0:return void 0!==(o=this._materialMap.get(e))?[3,6]:(i=t&&Object.keys(t).some((function(e){return e.startsWith("uv")})),(e=e instanceof d.MultiMaterial?e.subMaterials[r.materialIndex]:e)instanceof d.PBRMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,"image/png",i)]:[3,2]);case 1:return o=s.sent(),[3,5];case 2:return e instanceof d.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,"image/png",i)]:[3,4];case 3:return o=s.sent(),[3,5];case 4:return d.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 5:this._materialMap.set(e,o),s.label=6;case 6:return n.material=o,[2]}}))}))},e.prototype._exportMeshAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,o,i,s,a,u,c,l,f,h,p,m,_,g,v,T,b,A,w,E,M,R,V,C,S,I,F,B,N,P,O,U,L;return x(this,(function(x){switch(x.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),o=e.isUnIndexed?null:e.getIndices(),i=null===(B=e.geometry)||void 0===B?void 0:B.getVertexBuffers(),s=t.getMorphTargetsFromMesh(e),a=e instanceof d.LinesMesh,u=e instanceof d.GreasedLineBaseMesh,c=e.subMeshes,!(i&&c&&c.length>0))return[3,7];l=0,f=c,x.label=1;case 1:return l<f.length?(h=f[l],p={attributes:{}},m=h.getMaterial()||this._babylonScene.defaultMaterial,u?(T={name:m.name},b=e,_=d.Color3.White(),g=null!==(P=null===(N=b.material)||void 0===N?void 0:N.alpha)&&void 0!==P?P:1,(!(v=null!==(U=null===(O=b.greasedLineMaterial)||void 0===O?void 0:O.color)&&void 0!==U?U:_).equals(_)||g<1)&&(T.pbrMetallicRoughness={baseColorFactor:y(y([],v.asArray(),!0),[g],!1)}),this._materials.push(T),p.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return a?(T={name:m.name},(!(b=e).color.equals(d.Color3.White())||b.alpha<1)&&(T.pbrMetallicRoughness={baseColorFactor:y(y([],b.color.asArray(),!0),[b.alpha],!1)}),this._materials.push(T),p.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(m,i,h,p)];case 4:x.sent(),x.label=5;case 5:for(A=a||u?d.Material.LineListDrawMode:null!==(L=e.overrideRenderingFillMode)&&void 0!==L?L:m.fillMode,w=m._getEffectiveOrientation(e),this._exportIndices(o,o?(0,d.AreIndices32Bits)(o,h.indexCount,h.indexStart,h.verticesStart):h.verticesCount>65535,o?h.indexStart:h.verticesStart,o?h.indexCount:h.verticesCount,-h.verticesStart,A,w,t,p),E=0,M=Object.values(i);E<M.length;E++)R=M[E],this._exportVertexBuffer(R,m,h.verticesStart,h.verticesCount,t,p);if(s)for(p.targets=[],V=0,C=s;V<C.length;V++)F=C[V],p.targets.push(F.attributes);n.primitives.push(p),this._extensionsPostExportMeshPrimitive(p),x.label=6;case 6:return l++,[3,1];case 7:if(s)for(n.weights=[],n.extras||(n.extras={}),n.extras.targetNames=[],S=0,I=s;S<I.length;S++)F=I[S],n.weights.push(F.influence),n.extras.targetNames.push(F.name);return[2,r]}}))}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),ne=function(){function e(){}return e.GLTFAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,o;return x(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 o=i.sent(),n.dispose(),[2,o]}}))}))},e.GLBAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,o;return x(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 o=i.sent(),n.dispose(),[2,o]}}))}))},e}(),oe="EXT_mesh_gpu_instancing",ie=function(){function e(e){this.name=oe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportNodeAsync=function(e,t,r,n,o,i){var s=this;return new Promise((function(e){if(t&&r instanceof d.Mesh&&r.hasThinInstances&&s._exporter){s._wasUsed=!0;for(var n=d.Vector3.Zero(),a=d.Quaternion.Identity(),u=d.Vector3.One(),c=r.thinInstanceGetWorldMatrices(),l=d.TmpVectors.Vector3[2],f=d.TmpVectors.Quaternion[1],h=d.TmpVectors.Vector3[3],p=!1,m=!1,_=!1,g=new Float32Array(3*r.thinInstanceCount),x=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),o&&(D(l),G(f)),g.set(l.asArray(),3*v),x.set(f.normalize().asArray(),4*v),y.set(h.asArray(),3*v),p=p||!l.equalsWithEpsilon(n),m=m||!f.equalsWithEpsilon(a),_=_||!h.equalsWithEpsilon(u),v++;var A={attributes:{}};p&&(A.attributes.TRANSLATION=s._buildAccessor(g,"VEC3",r.thinInstanceCount,i)),m&&(A.attributes.ROTATION=s._buildAccessor(x,"VEC4",r.thinInstanceCount,i)),_&&(A.attributes.SCALE=s._buildAccessor(y,"VEC3",r.thinInstanceCount,i)),t.extensions=t.extensions||{},t.extensions[oe]=A}e(t)}))},e.prototype._buildAccessor=function(e,t,r,n){var o=n.createBufferView(e),i=n.createAccessor(o,t,5126,r);return this._exporter._accessors.push(i),this._exporter._accessors.length-1},e}();re.RegisterExtension(oe,(function(e){return new ie(e)}));var se="KHR_draco_mesh_compression",ae=function(){function e(e){this.name=se,this.required=!0,this._bufferViewsUsed=new Set,this._accessorsUsed=new Set,this._encodePromises=[],this._wasUsed=!1,this.enabled="Draco"===e.options.meshCompressionMethod&&d.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 o=[],i=[],s=null;if(void 0!==e.indices){var a=r[e.indices],u=t.getBufferView(a);s=t.getData(u).slice(),o.push(u),i.push(a)}for(var c,l=[],f=0,h=Object.entries(e.attributes);f<h.length;f++){var p=h[f],m=p[0],_=(a=r[p[1]],u=t.getBufferView(a),U(a.type)),g=(0,d.GetTypedArrayData)(t.getData(u),_,a.componentType,a.byteOffset||0,u.byteStride||(0,d.GetTypeByteLength)(a.componentType)*_,a.normalized||!1,a.count,!0);l.push({kind:m,dracoName:(c=m,"POSITION"===c?"POSITION":"NORMAL"===c?"NORMAL":c.startsWith("COLOR")?"COLOR":c.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"),size:U(a.type),data:g}),o.push(u),i.push(a)}var x={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},y=d.DracoEncoder.Default._encodeAsync(l,s,x).then((function(r){if(r){var s={bufferView:-1,attributes:r.attributeIDs},a=t.createBufferView(r.data);t.setBufferView(s,a);for(var u=0,c=o;u<c.length;u++){var l=c[u];n._bufferViewsUsed.add(l)}for(var f=0,h=i;f<h.length;f++){var p=h[f];n._accessorsUsed.add(p)}e.extensions||(e.extensions={}),e.extensions[se]=s}else d.Logger.Error("Draco encoding failed for primitive.")})).catch((function(e){d.Logger.Error("Draco encoding failed for primitive: "+e)}));this._encodePromises.push(y),this._wasUsed=!0}else d.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 x(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(se,(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=d.Vector3.Backward(),he=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,o){var i=this;return new Promise((function(s){if(r instanceof d.ShadowLight){var a=r.getTypeID()==d.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==d.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==d.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!a)return d.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(ue)),void s(t);if(r.falloffType!==d.Light.FALLOFF_GLTF&&d.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=d.TmpVectors.Vector3[0].copyFrom(r.position);o&&D(u),t.translation=u.asArray()}if("point"!==a){var c=r.direction.normalizeToRef(d.TmpVectors.Vector3[0]);o&&D(c);var l=Math.acos(d.Vector3.Dot(fe,c)),f=d.Vector3.Cross(fe,c),h=d.Quaternion.RotationAxisToRef(f,l,d.TmpVectors.Quaternion[0]);d.Quaternion.IsIdentity(h)||(t.rotation=h.asArray())}var p={type:a,name:r.name,color:r.diffuse.asArray(),intensity:r.intensity,range:r.range};if(q(p,ce),"spot"===a){var m=r;p.spot={innerConeAngle:m.innerAngle/2,outerConeAngle:m.angle/2},q(p.spot,le)}i._lights||(i._lights={lights:[]}),i._lights.lights.push(p);var _={light:i._lights.lights.length-1},g=r.parent;if(g&&W(r,g)){var x=n.get(g);if(x){var y=i._exporter._nodes[x];return function(e,t){var r=d.Vector3.FromArrayToRef(t.translation||[0,0,0],0,d.TmpVectors.Vector3[0]),n=d.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,d.TmpVectors.Quaternion[0]),o=d.Vector3.FromArrayToRef(t.scale||[1,1,1],0,d.TmpVectors.Vector3[1]),i=d.Matrix.ComposeToRef(o,n,r,d.TmpVectors.Matrix[0]),s=d.Vector3.FromArrayToRef(e.translation||[0,0,0],0,d.TmpVectors.Vector3[2]),a=d.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,d.TmpVectors.Quaternion[1]),u=d.Vector3.FromArrayToRef(e.scale||[1,1,1],0,d.TmpVectors.Vector3[1]),c=d.Matrix.ComposeToRef(u,a,s,d.TmpVectors.Matrix[1]);i.multiplyToRef(c,c),c.decompose(o,n,r),r.equalsWithEpsilon(N,B)?delete t.translation:t.translation=r.asArray(),d.Quaternion.IsIdentity(n)?delete t.rotation:t.rotation=n.asArray(),o.equalsWithEpsilon(P,B)?delete t.scale:t.scale=o.asArray()}(t,y),y.extensions||(y.extensions={}),y.extensions[ue]=_,void s(null)}}t.extensions||(t.extensions={}),t.extensions[ue]=_,s(t)}else s(t)}))},e}();re.RegisterExtension(ue,(function(e){return new he(e)}));var pe="KHR_materials_anisotropy",de=function(){function e(e){this.name=pe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof d.PBRBaseMaterial&&r.anisotropy.isEnabled&&!r.anisotropy.legacy?(r.anisotropy.texture&&n.push(r.anisotropy.texture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof d.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var o=n._exporter._materialExporter.getTextureInfo(r.anisotropy.texture),i={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=o?o:void 0};null!==i.anisotropyTexture&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[pe]=i}e(t)}))},e}();re.RegisterExtension(pe,(function(e){return new de(e)}));var me="KHR_materials_clearcoat",_e=function(){function e(e){this.name=me,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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof d.PBRBaseMaterial&&r.clearCoat.isEnabled?(r.clearCoat.texture&&n.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&n.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&n.push(r.clearCoat.bumpTexture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof d.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var o,i=n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);o=r.clearCoat.useRoughnessFromMainTexture?n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):n._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&d.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),r.clearCoat.remapF0OnInterfaceChange&&d.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(r.name));var s=n._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture),a={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=i?i:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=o?o:void 0,clearcoatNormalTexture:null!=s?s:void 0};null===a.clearcoatTexture&&null===a.clearcoatRoughnessTexture&&null===a.clearcoatRoughnessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[me]=a}e(t)}))},e}();re.RegisterExtension(me,(function(e){return new _e(e)}));var ge="KHR_materials_diffuse_transmission";function xe(e,t){var r=t.subSurface,n=null;return r.translucencyIntensityTexture?n=r.translucencyIntensityTexture:r.thicknessTexture&&r.useMaskFromThicknessTexture&&(n=r.thicknessTexture),n&&!r.useGltfStyleTextures?(d.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(t.name),1),null):n}var ye=function(){function e(e){this.name=ge,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];if(r instanceof d.PBRMaterial&&this._isExtensionEnabled(r)){var o=xe(e,r);return o&&n.push(o),r.subSurface.translucencyColorTexture&&n.push(r.subSurface.translucencyColorTexture),n}return n},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(o){var i,s;if(r instanceof d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var a=r.subSurface,u=xe(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!==(s=n._exporter._materialExporter.getTextureInfo(a.translucencyColorTexture))&&void 0!==s?s:void 0,p={diffuseTransmissionFactor:c,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:f,diffuseTransmissionColorTexture:h};(l||h)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions=t.extensions||{},t.extensions[ge]=p}o(t)}))},e}();re.RegisterExtension(ge,(function(e){return new ye(e)}));var ve="KHR_materials_dispersion",Te=function(){function e(){this.name=ve,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 d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var o={dispersion:r.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[ve]=o}e(t)}))},e}();re.RegisterExtension(ve,(function(){return new Te}));var be="KHR_materials_emissive_strength",Ae=function(){function e(){this.name=be,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(!(r instanceof d.PBRMaterial))return e(t);var o=r.emissiveColor.asArray(),i=Math.max.apply(Math,o);if(i>1){n._wasUsed=!0,t.extensions||(t.extensions={});var s={emissiveStrength:i},a=r.emissiveColor.scale(1/s.emissiveStrength);t.emissiveFactor=a.asArray(),t.extensions[be]=s}return e(t)}))},e}();re.RegisterExtension(be,(function(e){return new Ae}));var we="KHR_materials_ior",Ee=function(){function e(){this.name=we,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 d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var o={ior:r.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[we]=o}e(t)}))},e}();re.RegisterExtension(we,(function(e){return new Ee}));var Me="KHR_materials_iridescence",Re=function(){function e(e){this.name=Me,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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof d.PBRBaseMaterial&&r.iridescence.isEnabled?(r.iridescence.texture&&n.push(r.iridescence.texture),r.iridescence.thicknessTexture&&r.iridescence.thicknessTexture!==r.iridescence.texture&&n.push(r.iridescence.thicknessTexture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof d.PBRBaseMaterial){if(!r.iridescence.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var o=n._exporter._materialExporter.getTextureInfo(r.iridescence.texture),i=n._exporter._materialExporter.getTextureInfo(r.iridescence.thicknessTexture),s={iridescenceFactor:r.iridescence.intensity,iridescenceIor:r.iridescence.indexOfRefraction,iridescenceThicknessMinimum:r.iridescence.minimumThickness,iridescenceThicknessMaximum:r.iridescence.maximumThickness,iridescenceTexture:null!=o?o:void 0,iridescenceThicknessTexture:null!=i?i:void 0};null===s.iridescenceTexture&&null===s.iridescenceThicknessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Me]=s}e(t)}))},e}();re.RegisterExtension(Me,(function(e){return new Re(e)}));var Ve="KHR_materials_sheen",Ce=function(){function e(e){this.name=Ve,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.postExportMaterialAdditionalTextures=function(e,t,r){return r instanceof d.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[r.sheen.texture]:[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o,i,s,a;if(r instanceof d.PBRMaterial){if(!r.sheen.isEnabled)return void e(t);n._wasUsed=!0,null==t.extensions&&(t.extensions={});var u={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(o=r.sheen.roughness)&&void 0!==o?o:0};null===u.sheenColorTexture&&null===u.sheenRoughnessTexture||n._exporter._materialNeedsUVsSet.add(r),r.sheen.texture&&(u.sheenColorTexture=null!==(i=n._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==i?i:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(s=n._exporter._materialExporter.getTextureInfo(r.sheen.textureRoughness))&&void 0!==s?s:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(a=n._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==a?a:void 0),t.extensions[Ve]=u}e(t)}))},e}();re.RegisterExtension(Ve,(function(e){return new Ce(e)}));var Se="KHR_materials_specular",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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof d.PBRMaterial&&this._isExtensionEnabled(r)?(r.metallicReflectanceTexture&&n.push(r.metallicReflectanceTexture),r.reflectanceTexture&&n.push(r.reflectanceTexture),n):n},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 o,i;if(r instanceof d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0,t.extensions=t.extensions||{};var s=null!==(o=n._exporter._materialExporter.getTextureInfo(r.metallicReflectanceTexture))&&void 0!==o?o:void 0,a=null!==(i=n._exporter._materialExporter.getTextureInfo(r.reflectanceTexture))&&void 0!==i?i:void 0,u={specularFactor:1==r.metallicF0Factor?void 0:r.metallicF0Factor,specularTexture:s,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:a};n._hasTexturesExtension(r)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[Se]=u}e(t)}))},e}();re.RegisterExtension(Se,(function(e){return new Ie(e)}));var Fe="KHR_materials_transmission",Be=function(){function e(e){this.name=Fe,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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof d.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&n.push(r.subSurface.thicknessTexture),n):n},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,o,i,s;return x(this,(function(a){switch(a.label){case 0:return r instanceof d.PBRMaterial&&this._isExtensionEnabled(r)?(this._wasUsed=!0,n=r.subSurface,o=0===n.refractionIntensity?void 0:n.refractionIntensity,i={transmissionFactor:o},this._hasTexturesExtension(r)&&this._exporter._materialNeedsUVsSet.add(r),n.refractionIntensityTexture?n.useGltfStyleTextures?[4,this._exporter._materialExporter.exportTextureAsync(n.refractionIntensityTexture,"image/png")]:[3,2]:[3,3]):[3,4];case 1:return(s=a.sent())&&(i.transmissionTexture=s),[3,3];case 2:d.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[Fe]=i,a.label=4;case 4:return[2,t]}}))}))},e}();re.RegisterExtension(Fe,(function(e){return new Be(e)}));var Ne="KHR_materials_unlit",Pe=function(){function e(){this.name=Ne,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 o=!1;r instanceof d.PBRMaterial?o=r.unlit:r instanceof d.StandardMaterial&&(o=r.disableLighting),o&&(n._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[Ne]={}),e(t)}))},e}();re.RegisterExtension(Ne,(function(){return new Pe}));var Oe="KHR_materials_volume",Ue=function(){function e(e){this.name=Oe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof d.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&n.push(r.subSurface.thicknessTexture),n):n},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!=d.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 o;if(r instanceof d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var i=r.subSurface,s={thicknessFactor:0==i.maximumThickness?void 0:i.maximumThickness,thicknessTexture:null!==(o=n._exporter._materialExporter.getTextureInfo(i.thicknessTexture))&&void 0!==o?o: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[Oe]=s}e(t)}))},e}();re.RegisterExtension(Oe,(function(e){return new Ue(e)}));var Le="KHR_texture_transform",Ke=function(){function e(){this.name=Le,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()||d.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(r.name,"!")),0===r.uAng&&0===r.vAng||(d.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={},o=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],o=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],o=!0),0!==r.wAng){if(0!==r.uRotationCenter||0!==r.vRotationCenter){if(r.homogeneousRotationInUVTransform&&r.uScale!==r.vScale)return void d.Tools.Warn("".concat(e,": Texture ").concat(r.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(Le,"."));d.Tools.Warn("".concat(e,": Texture ").concat(r.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(Le,".")),n.offset=function(e){var t=e.uOffset,r=e.vOffset,n=e.uRotationCenter,o=e.vRotationCenter,i=e.uScale,s=e.vScale,a=e.wAng,u=Math.cos(a),c=Math.sin(a),l=n*i,f=o*s;return[t+(l*(1-u)+f*c),r+(f*(1-u)-l*c)]}(r)}n.rotation=-r.wAng,o=!0}0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,o=!0),o&&(this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[Le]=n)}},e}();re.RegisterExtension(Le,(function(){return new Ke}));var ke=void 0!==i.g?i.g:"undefined"!=typeof window?window:void 0;if(void 0!==ke){ke.BABYLON=ke.BABYLON||{};var De=ke.BABYLON;De.GLTF2=De.GLTF2||{},De.GLTF2.Exporter=De.GLTF2.Exporter||{},De.GLTF2.Exporter.Extensions=De.GLTF2.Exporter.Extensions||{};var Ge=[];for(var He in a)De[He]=a[He],Ge.push(He);for(var He in u)De[He]=u[He],Ge.push(He);for(var He in c)De[He]=c[He],Ge.push(He);for(var He in l)De.GLTF2.Exporter.Extensions[He]=l[He],Ge.push(He);for(var He in f)Ge.indexOf(He)>-1||(De.GLTF2.Exporter[He]=f[He])}const We=h;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,r,n={597:t=>{t.exports=e}},o={};function i(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return n[e](r,r.exports,i),r.exports}r=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,i.t=function(e,n){if(1&n&&(e=this(e)),8&n)return e;if("object"==typeof e&&e){if(4&n&&e.__esModule)return e;if(16&n&&"function"==typeof e.then)return e}var o=Object.create(null);i.r(o);var s={};t=t||[null,r({}),r([]),r(r)];for(var a=2&n&&e;"object"==typeof a&&!~t.indexOf(a);a=r(a))Object.getOwnPropertyNames(a).forEach((t=>s[t]=()=>e[t]));return s.default=()=>e,i.d(o,s),o},i.d=(e,t)=>{for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};i.d(s,{default:()=>We});var a={};i.r(a),i.d(a,{__IGLTFExporterExtension:()=>p});var u={};i.r(u),i.d(u,{GLTFData:()=>m});var c={};i.r(c),i.d(c,{GLTF2Export:()=>ne});var l={};i.r(l),i.d(l,{EXT_mesh_gpu_instancing:()=>ie,KHR_draco_mesh_compression:()=>ae,KHR_lights_punctual:()=>he,KHR_materials_anisotropy:()=>de,KHR_materials_clearcoat:()=>_e,KHR_materials_diffuse_transmission:()=>ye,KHR_materials_dispersion:()=>Te,KHR_materials_emissive_strength:()=>Ae,KHR_materials_ior:()=>Ee,KHR_materials_iridescence:()=>Re,KHR_materials_sheen:()=>Ce,KHR_materials_specular:()=>Ie,KHR_materials_transmission:()=>Be,KHR_materials_unlit:()=>Pe,KHR_materials_volume:()=>Ue,KHR_texture_transform:()=>Ke});var f={};i.r(f),i.d(f,{EXT_mesh_gpu_instancing:()=>ie,GLTF2Export:()=>ne,GLTFData:()=>m,KHR_draco_mesh_compression:()=>ae,KHR_lights_punctual:()=>he,KHR_materials_anisotropy:()=>de,KHR_materials_clearcoat:()=>_e,KHR_materials_diffuse_transmission:()=>ye,KHR_materials_dispersion:()=>Te,KHR_materials_emissive_strength:()=>Ae,KHR_materials_ior:()=>Ee,KHR_materials_iridescence:()=>Re,KHR_materials_sheen:()=>Ce,KHR_materials_specular:()=>Ie,KHR_materials_transmission:()=>Be,KHR_materials_unlit:()=>Pe,KHR_materials_volume:()=>Ue,KHR_texture_transform:()=>Ke,_ConvertToGLTFPBRMetallicRoughness:()=>M,_SolveMetallic:()=>E});var h={};i.r(h),i.d(h,{EXT_mesh_gpu_instancing:()=>ie,GLTF2Export:()=>ne,GLTFData:()=>m,KHR_draco_mesh_compression:()=>ae,KHR_lights_punctual:()=>he,KHR_materials_anisotropy:()=>de,KHR_materials_clearcoat:()=>_e,KHR_materials_diffuse_transmission:()=>ye,KHR_materials_dispersion:()=>Te,KHR_materials_emissive_strength:()=>Ae,KHR_materials_ior:()=>Ee,KHR_materials_iridescence:()=>Re,KHR_materials_sheen:()=>Ce,KHR_materials_specular:()=>Ie,KHR_materials_transmission:()=>Be,KHR_materials_unlit:()=>Pe,KHR_materials_volume:()=>Ue,KHR_texture_transform:()=>Ke,_ConvertToGLTFPBRMetallicRoughness:()=>M,_SolveMetallic:()=>E,__IGLTFExporterExtension:()=>p});var p=0,d=i(597),m=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,d.GetMimeType)(e)});d.Tools.Download(r,e)}},e}(),_=function(){return _=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},_.apply(this,arguments)};function g(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(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?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((n=n.apply(e,t||[])).next())}))}function x(e,t){var r,n,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=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(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function y(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var v=1e-6,T=new d.Color3(.04,.04,.04),b=1024,A=d.Color3.White(),w=d.Color3.Black();function E(e,t,r){if(t<T.r)return 0;var n=T.r,o=e*r/(1-T.r)+t-2*T.r,i=o*o-4*n*(T.r-t);return d.Scalar.Clamp((-o+Math.sqrt(i))/(2*n),0,1)}function M(e){var t=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),r=e.alpha,n=d.Scalar.Clamp(e.specularPower,0,b),o=(0,d.SpecularPowerToRoughness)(n);return{baseColorFactor:[t.r,t.g,t.b,r],metallicFactor:0,roughnessFactor:o}}function R(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function V(e,t,r){for(var n=new Uint8Array(e*t*4),o=0;o<n.length;o+=4)n[o]=n[o+1]=n[o+2]=n[o+3]=255;return d.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,r){return g(this,void 0,void 0,(function(){var n,o,i,s,a,u,c,l;return x(this,(function(f){switch(f.label){case 0:return n=M(e),o={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||d.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),o.doubleSided=!0),r?(i=[],(s=e.diffuseTexture)&&i.push(this.exportTextureAsync(s,t).then((function(e){e&&(n.baseColorTexture=e)}))),(a=e.bumpTexture)&&i.push(this.exportTextureAsync(a,t).then((function(e){e&&(o.normalTexture=e,1!==a.level&&(o.normalTexture.scale=a.level))}))),(u=e.emissiveTexture)&&(o.emissiveFactor=[1,1,1],i.push(this.exportTextureAsync(u,t).then((function(e){e&&(o.emissiveTexture=e)})))),(c=e.ambientTexture)&&i.push(this.exportTextureAsync(c,t).then((function(e){if(e){var t={index:e.index};o.occlusionTexture=t}}))),i.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(i)]):[3,2]):[3,2];case 1:f.sent(),f.label=2;case 2:return(e.alpha<1||e.opacityTexture)&&(e.alphaMode===d.Constants.ALPHA_COMBINE?o.alphaMode="BLEND":d.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(w,v)&&(o.emissiveFactor=e.emissiveColor.asArray()),o.pbrMetallicRoughness=n,R(o,e),[4,this._finishMaterialAsync(o,e,t)];case 3:return f.sent(),(l=this._exporter._materials).push(o),[2,l.length-1]}}))}))},e.prototype._finishMaterialAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,o,i,s,a;return x(this,(function(u){switch(u.label){case 0:for(n=this._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",e,t),o=[],i=0,s=n;i<s.length;i++)a=s[i],o.push(this.exportTextureAsync(a,r));return[4,Promise.all(o)];case 1:return u.sent(),[4,this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)];case 2:return u.sent(),[2]}}))}))},e.prototype._getImageDataAsync=function(e,t,r,n){return g(this,void 0,void 0,(function(){var o,s,a,u,c;return x(this,(function(l){switch(l.label){case 0:return o=d.Constants.TEXTURETYPE_UNSIGNED_BYTE,s=this._exporter._babylonScene,a=s.getEngine(),u=a.createRawTexture(e,t,r,d.Constants.TEXTUREFORMAT_RGBA,!1,!0,d.Texture.NEAREST_SAMPLINGMODE,null,o),a.isWebGPU?[4,Promise.resolve().then(i.t.bind(i,597,23))]:[3,2];case 1:return l.sent(),[3,4];case 2:return[4,Promise.resolve().then(i.t.bind(i,597,23))];case 3:l.sent(),l.label=4;case 4:return[4,d.TextureTools.ApplyPostProcess("pass",u,s,o,d.Constants.TEXTURE_NEAREST_SAMPLINGMODE,d.Constants.TEXTUREFORMAT_RGBA)];case 5:return l.sent(),[4,a._readTexturePixels(u,t,r)];case 6:return c=l.sent(),[4,d.DumpTools.DumpDataAsync(t,r,c,n,void 0,!0,!0)];case 7:return[2,l.sent()]}}))}))},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,o,i=e?e.getSize():{width:0,height:0},s=t?t.getSize():{width:0,height:0};return i.width<s.width?(n=e&&e instanceof d.Texture?d.TextureTools.CreateResizedCopy(e,s.width,s.height,!0):V(s.width,s.height,r),o=t):i.width>s.width?(o=t&&t instanceof d.Texture?d.TextureTools.CreateResizedCopy(t,i.width,i.height,!0):V(i.width,i.height,r),n=e):(n=e,o=t),{texture1:n,texture2:o}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,r,n){return g(this,void 0,void 0,(function(){var o,i,s,a,u,c,l,f,h,p,m,_,g,y,T,b,E,M,R,V,S,I,F,B,N,P,O,U,L,K,k;return x(this,(function(x){switch(x.label){case 0:return o=new Array,e||t?(i=e?e.getScene():t?t.getScene():null)?(s=this._resizeTexturesToSameDimensions(e,t,i),a=null===(k=s.texture1)||void 0===k?void 0:k.getSize(),u=void 0,c=void 0,l=a.width,f=a.height,[4,s.texture1.readPixels()]):[3,3]:[2,Promise.reject("diffuse and specular glossiness textures are not defined!")];case 1:return h=x.sent(),[4,s.texture2.readPixels()];case 2:if(p=x.sent(),!h)return[2,Promise.reject("Failed to retrieve pixels from diffuse texture!")];if(u=C(h),!p)return[2,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];for(c=C(p),m=c.byteLength,_=new Uint8Array(m),g=new Uint8Array(m),y=w,T=0,b=0,P=0;P<f;++P)for(O=0;O<l;++O)E=4*(l*P+O),M=new d.Color3(u[E],u[E+1],u[E+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(r.diffuseColor),R=new d.Color3(c[E],c[E+1],c[E+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(r.specularColor),V=c[E+3]*r.glossiness,S={diffuseColor:M,specularColor:R,glossiness:V},I=this._convertSpecularGlossinessToMetallicRoughness(S),y.r=Math.max(y.r,I.baseColor.r),y.g=Math.max(y.g,I.baseColor.g),y.b=Math.max(y.b,I.baseColor.b),T=Math.max(T,I.metallic),b=Math.max(b,I.roughness),g[E]=255*I.baseColor.r,g[E+1]=255*I.baseColor.g,g[E+2]=255*I.baseColor.b,g[E+3]=s.texture1.hasAlpha?255*u[E+3]:255,_[E]=0,_[E+1]=255*I.roughness,_[E+2]=255*I.metallic,_[E+3]=255;for(F={baseColor:y,metallic:T,roughness:b},B=!1,N=!1,P=0;P<f;++P)for(O=0;O<l;++O)g[U=4*(l*P+O)]/=F.baseColor.r>v?F.baseColor.r:1,g[U+1]/=F.baseColor.g>v?F.baseColor.g:1,g[U+2]/=F.baseColor.b>v?F.baseColor.b:1,L=d.Color3.FromInts(g[U],g[U+1],g[U+2]),K=L.toGammaSpace(i.getEngine().useExactSrgbConversions),g[U]=255*K.r,g[U+1]=255*K.g,g[U+2]=255*K.b,K.equalsWithEpsilon(A,v)||(N=!0),_[U+1]/=F.roughness>v?F.roughness:1,_[U+2]/=F.metallic>v?F.metallic:1,d.Color3.FromInts(255,_[U+1],_[U+2]).equalsWithEpsilon(A,v)||(B=!0);return B&&o.push(this._getImageDataAsync(_,l,f,n).then((function(e){F.metallicRoughnessTextureData=e}))),N&&o.push(this._getImageDataAsync(g,l,f,n).then((function(e){F.baseColorTextureData=e}))),[2,Promise.all(o).then((function(){return F}))];case 3:return[2,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),o=E(t,r,n),i=e.diffuseColor.scale(n/(1-T.r)/Math.max(1-o)),s=e.specularColor.subtract(T.scale(1-o)).scale(1/Math.max(o)),a=d.Color3.Lerp(i,s,o*o);return{baseColor:a=a.clampToRef(0,1,a),metallic:o,roughness:1-e.glossiness}},e.prototype._getPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},e.prototype._getMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},e.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,r,n){return g(this,void 0,void 0,(function(){var o,i,s;return x(this,(function(a){switch(a.label){case 0:return o=[],i={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness},n&&(e._albedoTexture&&o.push(this.exportTextureAsync(e._albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)}))),(s=e._metallicTexture)&&o.push(this.exportTextureAsync(s,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))),o.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(o)]):[3,2];case 1:a.sent(),a.label=2;case 2:return[2,i]}}))}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof d.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 d.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case d.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case d.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case d.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case d.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case d.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case d.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case d.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case d.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case d.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case d.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case d.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case d.Texture.WRAP_ADDRESSMODE:return 10497;case d.Texture.CLAMP_ADDRESSMODE:return 33071;case d.Texture.MIRROR_ADDRESSMODE:return 33648;default:return d.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r,n){return g(this,void 0,void 0,(function(){var o,i,s,a,u,c,l,f;return x(this,(function(h){switch(h.label){case 0:return o={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},i=e._albedoTexture,s=e._reflectivityTexture,a=e._useMicroSurfaceFromReflectivityMapAlpha,s&&!a?[2,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")]:(i||s)&&n?(this._exporter._materialNeedsUVsSet.add(e),u=this._exportTextureSampler(i||s),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(i,s,o,t)]):[3,2];case 1:return c=h.sent(),l=this._exporter._textures,c.baseColorTextureData&&(f=this._exportImage("baseColor".concat(l.length),t,c.baseColorTextureData),r.baseColorTexture=this._exportTextureInfo(f,u,null==i?void 0:i.coordinatesIndex)),c.metallicRoughnessTextureData&&(f=this._exportImage("metallicRoughness".concat(l.length),t,c.metallicRoughnessTextureData),r.metallicRoughnessTexture=this._exportTextureInfo(f,u,null==s?void 0:s.coordinatesIndex)),[2,c];case 2:return[2,this._convertSpecularGlossinessToMetallicRoughness(o)]}}))}))},e.prototype.exportPBRMaterialAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,o,i,s,a,u,c,l;return x(this,(function(f){switch(f.label){case 0:return n={},o={name:e.name},(i=e.isMetallicWorkflow())&&(s=e._albedoColor,a=e.alpha,s&&(n.baseColorFactor=[s.r,s.g,s.b,a])),i?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,n,r)]:[3,2];case 1:return c=f.sent(),[3,4];case 2:return[4,this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,n,r)];case 3:c=f.sent(),f.label=4;case 4:return u=c,[4,this._setMetallicRoughnessPbrMaterialAsync(u,e,o,n,t,r)];case 5:return f.sent(),[4,this._finishMaterialAsync(o,e,t)];case 6:return f.sent(),(l=this._exporter._materials).push(o),[2,l.length-1]}}))}))},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,t,r,n,o,i){return g(this,void 0,void 0,(function(){var s,a,u,c,l;return x(this,(function(f){switch(f.label){case 0:return R(r,t),e.baseColor.equalsWithEpsilon(A,v)&&d.Scalar.WithinEpsilon(t.alpha,1,v)||(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||d.Tools.Warn(t.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),i?(s=[],(a=t._bumpTexture)&&s.push(this.exportTextureAsync(a,o).then((function(e){e&&(r.normalTexture=e,1!==a.level&&(r.normalTexture.scale=a.level))}))),(u=t._ambientTexture)&&s.push(this.exportTextureAsync(u,o).then((function(e){if(e){var n={index:e.index,texCoord:e.texCoord,extensions:e.extensions};r.occlusionTexture=n;var o=t._ambientTextureStrength;o&&(n.strength=o)}}))),(c=t._emissiveTexture)&&s.push(this.exportTextureAsync(c,o).then((function(e){e&&(r.emissiveTexture=e)}))),s.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(s)]):[3,2]):[3,2];case 1:f.sent(),f.label=2;case 2:return(l=t._emissiveColor).equalsWithEpsilon(w,v)||(r.emissiveFactor=l.asArray()),r.pbrMetallicRoughness=n,[2]}}))}))},e.prototype._getPixelsFromTexture=function(e){return e.textureType,d.Constants.TEXTURETYPE_UNSIGNED_BYTE,e.readPixels()},e.prototype.exportTextureAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n=this;return x(this,(function(o){return(r=this._exporter._extensionsPreExportTextureAsync("exporter",e,t))?[2,r.then((function(r){return r?n._exportTextureInfoAsync(r,t):n._exportTextureInfoAsync(e,t)}))]:[2,this._exportTextureInfoAsync(e,t)]}))}))},e.prototype._exportTextureInfoAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,o,i,s,a,u,c,l,f=this;return x(this,(function(h){switch(h.label){case 0:return(r=this._textureMap.get(e))?[3,3]:[4,this._getPixelsFromTexture(e)];case 1:if(!(n=h.sent()))return[2,null];if(o=this._exportTextureSampler(e),i=e.mimeType)switch(i){case"image/jpeg":case"image/png":case"image/webp":t=i;break;default:d.Tools.Warn("Unsupported media type: ".concat(i))}return s=this._internalTextureToImage,a=e.getInternalTexture().uniqueId,s[a]||(s[a]={}),void 0===(u=s[a][t])&&(c=e.getSize(),u=g(f,void 0,void 0,(function(){var r;return x(this,(function(o){switch(o.label){case 0:return[4,this._getImageDataAsync(n,c.width,c.height,t)];case 1:return r=o.sent(),[2,this._exportImage(e.name,t,r)]}}))})),s[a][t]=u),l=this._exportTextureInfo,[4,u];case 2:r=l.apply(this,[h.sent(),o,e.coordinatesIndex]),this._textureMap.set(e,r),this._exporter._extensionsPostExportTextures("exporter",r,e),h.label=3;case 3:return[2,r]}}))}))},e.prototype._exportImage=function(e,t,r){var n,o=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 s=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"}}(t),u=s+a;o.some((function(e){return e.uri===u}))&&(u="".concat(s,"_").concat(d.Tools.RandomId()).concat(a)),n={name:e,uri:u},this._exporter._imageData[u]={data:r,mimeType:t}}return o.push(n),o.length-1},e.prototype._exportTextureInfo=function(e,t,r){var n=this._exporter._textures,o=n.findIndex((function(r){return r.sampler==t&&r.source===e}));-1===o&&(o=n.length,n.push({source:e,sampler:t}));var i={index:o};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}(),I=d.Matrix.Compose(new d.Vector3(-1,1,1),d.Quaternion.Identity(),d.Vector3.Zero()),F=new d.Quaternion(0,1,0,0),B=1e-6,N=d.Vector3.Zero(),P=d.Vector3.One();function O(e,t){var r=e.byteOffset,n=e.byteStride,o=e.type,i=e.normalized,s=e.getSize(),a=t.reduce((function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e}),-Number.MAX_VALUE);return{byteOffset:r,byteStride:n,componentCount:s,type:o,count:a*s,normalized:i,totalVertices:a,kind:e.getKind()}}function U(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 d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:case d.VertexBuffer.TangentKind:case d.VertexBuffer.ColorKind:case d.VertexBuffer.MatricesIndicesKind:case d.VertexBuffer.MatricesIndicesExtraKind:case d.VertexBuffer.MatricesWeightsKind:case d.VertexBuffer.MatricesWeightsExtraKind:case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:case d.VertexBuffer.UV3Kind:case d.VertexBuffer.UV4Kind:case d.VertexBuffer.UV5Kind:case d.VertexBuffer.UV6Kind:return!0}return!1}function K(e){switch(e){case d.Material.TriangleFillMode:return 4;case d.Material.TriangleStripDrawMode:return 5;case d.Material.TriangleFanDrawMode:return 6;case d.Material.PointListDrawMode:case d.Material.PointFillMode:return 0;case d.Material.LineLoopDrawMode:return 2;case d.Material.LineListDrawMode:return 1;case d.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 G(e){return e.x*=-1,e.y*=-1,e}function H(e){return e.multiplyInPlace(F)}function W(e,t){return t instanceof d.TransformNode&&1==t.getChildren().length&&0==e.getChildren().length}function j(e,t){if(!(e instanceof d.TransformNode))return!1;if(t){if(!e.getWorldMatrix().isIdentity())return!1}else if(!e.getWorldMatrix().multiplyToRef(I,d.TmpVectors.Matrix[0]).isIdentity())return!1;return!(e instanceof d.AbstractMesh&&e.geometry)}function q(e,t){for(var r=0,n=Object.entries(e);r<n.length;r++){var o=n[r],i=o[0],s=o[1],a=t[i];(Array.isArray(s)&&Array.isArray(a)&&z(s,a)||s===a)&&delete e[i]}return e}function z(e,t){return e.length===t.length&&e.every((function(e,r){return e===t[r]}))}var Q=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)}]]),Y=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=Q.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 X(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 Y(t),n=0,o=Array.from(this._bufferViewToData.keys()).sort((function(e,t){return X(t.byteLength)-X(e.byteLength)}));n<o.length;n++){var i=o[n];i.byteOffset=r.byteOffset,e.push(i);for(var s=e.length-1,a=0,u=this.getPropertiesWithBufferView(i);a<u.length;a++)u[a].bufferView=s;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,o,i,s){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:s,byteOffset:o};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 o=n[r];void 0!==o.bufferView&&delete o.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 d.TransformNode||e instanceof d.Camera||e instanceof d.Light)},e._CreateNodeAnimation=function(t,r,n,o,i){if(this._IsTransformable(t)){var s=[],a=[],u=r.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,n,o),f=l.interpolationType,h=l.shouldBakeAnimation;if(h?e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,i,s,a,c,o):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(t,r,n,s,a,o):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(t,r,n,s,a,o):e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,i,s,a,c,o),s.length&&a.length)return{inputs:s,outputs:a,samplerInterpolation:f,inputsMin:h?c.min:d.Tools.FloatRound(c.min/r.framePerSecond),inputsMax:h?c.max:d.Tools.FloatRound(c.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,o=e.targetProperty.split(".");switch(o[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:d.Tools.Error("Unsupported animatable property ".concat(o[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(d.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,r,n,o,i,s,a,u,c,l,f){var h;if(e._IsTransformable(t)&&t.animations)for(var p=0,d=t.animations;p<d.length;p++){var m=d[p];if(!f||f(m)){var _=e._DeduceAnimationInfo(m);_&&(h={name:m.name,samplers:[],channels:[]},e._AddAnimation("".concat(m.name),m.hasRunningRuntimeAnimations?r:h,t,m,_.dataAccessorType,_.animationChannelTargetPath,o,s,a,u,_.useQuaternion,c,l),h.samplers.length&&h.channels.length&&n.push(h))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,o,i,s,a,u,c,l,f){var h;if(t instanceof d.Mesh){var p=t.morphTargetManager;if(p)for(var m=0;m<p.numTargets;++m)for(var _=0,g=p.getTarget(m).animations;_<g.length;_++){var x=g[_];if(!f||f(x)){for(var y=new d.Animation("".concat(x.name),"influence",x.framePerSecond,x.dataType,x.loopMode,x.enableBlending),v=[],T=x.getKeys(),b=0;b<T.length;++b)for(var A=T[b],w=0;w<p.numTargets;++w)w==m?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(x.name,x.hasRunningRuntimeAnimations?r:h,t,y,E.dataAccessorType,E.animationChannelTargetPath,o,s,a,u,E.useQuaternion,c,l,p.numTargets),h.samplers.length&&h.channels.length&&n.push(h))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,o,i,s,a,u,c){var l,f;if(t.animationGroups)for(var h=t.animationGroups,p=function(h){var p=new Map,_=new Map,g=new Set,x=h.to-h.from;f={name:h.name,channels:[],samplers:[]};for(var y=function(r){var x=h.targetedAnimations[r],y=x.target,v=x.animation;if(c&&!c(v))return"continue";var T=u.has(y);if(m._IsTransformable(y)||1===y.length&&m._IsTransformable(y[0])){if(A=e._DeduceAnimationInfo(x.animation)){var b=m._IsTransformable(y)?y:m._IsTransformable(y[0])?y[0]:null;b&&e._AddAnimation("".concat(v.name),f,b,v,A.dataAccessorType,A.animationChannelTargetPath,n,o,i,s,A.useQuaternion,a,T)}}else if(y instanceof d.MorphTarget||1===y.length&&y[0]instanceof d.MorphTarget){var A;if(A=e._DeduceAnimationInfo(x.animation)){var w=y instanceof d.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&&(p.has(M)||p.set(M,new Map),null===(l=p.get(M))||void 0===l||l.set(w,v),g.add(M),_.set(M,v))}}}}},v=0;v<h.targetedAnimations.length;++v)y(v);g.forEach((function(t){for(var r=t.morphTargetManager,u=null,c=[],l=_.get(t).getKeys(),m=l.length,g=0;g<m;++g)for(var y=0;y<r.numTargets;++y){var v=r.getTarget(y),T=p.get(t);if(T){var b=T.get(v);b?(u||(u=new d.Animation("".concat(h.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,d.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[g])):c.push({frame:h.from+x/m*g,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,o,i,s,A.useQuaternion,a,!1,null==r?void 0:r.numTargets)})),f.channels.length&&f.samplers.length&&r.push(f)},m=this,_=0,g=h;_<g.length;_++)p(g[_])},e._AddAnimation=function(t,r,n,o,i,s,a,u,c,l,f,h,p,m){var _,g,x,y,v,T,b=e._CreateNodeAnimation(n,o,s,f,h);if(b){if(m){for(var A=0,w=0,E=[];b.inputs.length>0;)w=b.inputs.shift(),A%m==0&&E.push(w),A++;b.inputs=E}var M=a.get(n),R=new Float32Array(b.inputs);_=u.createBufferView(R),g=u.createAccessor(_,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(g),x=l.length-1;var V=new d.Quaternion,C=new d.Vector3,S=new d.Vector3,I=n instanceof d.Camera,F=U(i),B=new Float32Array(b.outputs.length*F);b.outputs.forEach((function(e,t){var r=e;if(p)switch(s){case"translation":d.Vector3.FromArrayToRef(e,0,S),D(S),S.toArray(r);break;case"rotation":4===e.length?d.Quaternion.FromArrayToRef(e,0,V):(r=new Array(4),d.Vector3.FromArrayToRef(e,0,C),d.Quaternion.FromEulerVectorToRef(C,V)),I?H(V):d.Quaternion.IsIdentity(V)||G(V),V.toArray(r)}else"rotation"===s&&(4===e.length?d.Quaternion.FromArrayToRef(e,0,V):(r=new Array(4),d.Vector3.FromArrayToRef(e,0,C),d.Quaternion.FromEulerVectorToRef(C,V)),I&&H(V),V.toArray(r));B.set(r,t*F)})),_=u.createBufferView(B),g=u.createAccessor(_,i,5126,b.outputs.length),l.push(g),y=l.length-1,v={interpolation:b.samplerInterpolation,input:x,output:y},r.samplers.push(v),T={sampler:r.samplers.length-1,target:{node:M,path:s}},r.channels.push(T)}},e._CreateBakedAnimation=function(t,r,n,o,i,s,a,u,c,l,f){var h,p,m=d.Quaternion.Identity(),_=null,g=null,x=null,y=null,v=null,T=null;l.min=d.Tools.FloatRound(o/s);for(var b=r.getKeys(),A=0,w=b.length;A<w;++A){if(T=null,x=b[A],A+1<w)if(y=b[A+1],x.value.equals&&x.value.equals(y.value)||x.value===y.value){if(0!==A)continue;T=x.frame}else T=y.frame;else{if(v=b[A-1],x.value.equals&&x.value.equals(v.value)||x.value===v.value)continue;T=i}if(T)for(var E=x.frame;E<=T;E+=a)if((p=d.Tools.FloatRound(E/s))!==_){_=p,g=p;var M={key:0,repeatCount:0,loopMode:r.loopMode};h=r._interpolate(E,M),e._SetInterpolatedValue(t,h,p,r,n,m,u,c,f)}}g&&(l.max=g)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,o,i){var s=e._GetBasePositionRotationOrScale(r,o,i),a=n.targetProperty.split("."),u=a?a[1]:"",c=i?d.Quaternion.FromArray(s).normalize():d.Vector3.FromArray(s);switch(u){case"x":case"y":case"z":c[u]=t;break;case"w":c.w=t;break;default:d.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return c},e._SetInterpolatedValue=function(e,t,r,n,o,i,s,a,u){var c;s.push(r),"weights"!==o?(n.dataType===d.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,o,u)),"rotation"===o?(u?i=t:(c=t,d.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,o,i,s){for(var a=0,u=r.getKeys();a<u.length;a++){var c=u[a];o.push(c.frame/r.framePerSecond),e._AddKeyframeValue(c,r,i,n,t,s)}},e._CreateCubicSplineAnimation=function(t,r,n,o,i,s){r.getKeys().forEach((function(a){o.push(a.frame/r.framePerSecond),e._AddSplineTangent(Z.INTANGENT,i,n,"CUBICSPLINE",a,s),e._AddKeyframeValue(a,r,i,n,t,s),e._AddSplineTangent(Z.OUTTANGENT,i,n,"CUBICSPLINE",a,s)}))},e._GetBasePositionRotationOrScale=function(e,t,r){var n;if("rotation"===t)if(r){var o=e.rotationQuaternion;n=(null!=o?o:d.Quaternion.Identity()).asArray()}else{var i=e.rotation;n=(null!=i?i:d.Vector3.Zero()).asArray()}else if("translation"===t){var s=e.position;n=(null!=s?s:d.Vector3.Zero()).asArray()}else{var a=e.scaling;n=(null!=a?a:d.Vector3.One()).asArray()}return n},e._AddKeyframeValue=function(e,t,r,n,o,i){var s,a=t.dataType;if(a===d.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===n){var c=d.Vector3.FromArray(u);u=d.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}r.push(u)}else if(a===d.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(s=this._ConvertFactorToVector3OrQuaternion(e.value,o,t,n,i)){if("rotation"===n){var l=i?s:d.Quaternion.RotationYawPitchRoll(s.y,s.x,s.z).normalize();r.push(l.asArray())}r.push(s.asArray())}}else a===d.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):d.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,o,i=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var s=0,a=e.length;s<a;++s)if((o=e[s]).inTangent||o.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",i=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||o.interpolation&&1===o.interpolation&&"STEP"!==n){n="LINEAR",i=!0;break}}else n=o.interpolation&&1===o.interpolation?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,t,r,n,o,i){var s,a=e===Z.INTANGENT?o.inTangent:o.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(a)if(i)s=a.asArray();else{var u=a;s=d.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else s=[0,0,0,0];else s="weights"===r?a?[a]:[0]:a?a.asArray():[0,0,0];t.push(s)}},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,o,i){var s={attributes:{},influence:e.influence,name:e.name},a=t.geometry;if(!a)return d.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),s;var u=i?-1:1,c=d.Vector3.Zero(),l=0;if(e.hasPositions){var f=e.getPositions(),h=a.getVerticesData(d.VertexBuffer.PositionKind);if(h){var p=new Float32Array(h.length),m=[1/0,1/0,1/0],_=[-1/0,-1/0,-1/0];l=h.length/3;for(var g=0;g<l;++g){var x=d.Vector3.FromArray(h,3*g);d.Vector3.FromArray(f,3*g).subtractToRef(x,c),c.x*=u,m[0]=Math.min(m[0],c.x),_[0]=Math.max(_[0],c.x),m[1]=Math.min(m[1],c.y),_[1]=Math.max(_[1],c.y),m[2]=Math.min(m[2],c.z),_[2]=Math.max(_[2],c.z),p[3*g]=c.x,p[3*g+1]=c.y,p[3*g+2]=c.z}var y=r.createBufferView(p,12),v=r.createAccessor(y,"VEC3",5126,f.length/3,0,{min:m,max:_});o.push(v),s.attributes.POSITION=o.length-1}else d.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(d.VertexBuffer.NormalKind);if(b){var A=new Float32Array(b.length);for(l=b.length/3,g=0;g<l;++g){var w=d.Vector3.FromArray(b,3*g).normalize();d.Vector3.FromArray(T,3*g).normalize().subtractToRef(w,c),A[3*g]=c.x*u,A[3*g+1]=c.y,A[3*g+2]=c.z}y=r.createBufferView(A,12),v=r.createAccessor(y,"VEC3",5126,T.length/3,0),o.push(v),s.attributes.NORMAL=o.length-1}else d.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(d.VertexBuffer.TangentKind);if(M){l=M.length/4;var R=new Float32Array(3*l);for(g=0;g<l;++g){var V=d.Vector3.FromArray(M,4*g);k(V);var C=d.Vector3.FromArray(E,3*g);k(C),C.subtractToRef(V,c),R[3*g]=c.x*u,R[3*g+1]=c.y,R[3*g+2]=c.z}y=r.createBufferView(R,12),v=r.createAccessor(y,"VEC3",5126,l,0),o.push(v),s.attributes.TANGENT=o.length-1}else d.Tools.Warn("Morph target tangents for mesh ".concat(t.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var S=e.getColors(),I=a.getVerticesData(d.VertexBuffer.ColorKind),F=a.getVertexBuffer(d.VertexBuffer.ColorKind);if(I&&F){var B=F.getSize();l=I.length/B;var N=new Float32Array(l*B);for(g=0;g<l;++g)if(3===B){var P=d.Vector3.FromArray(I,g*B);d.Vector3.FromArray(S,g*B).subtractToRef(P,c),N[3*g]=c.x,N[3*g+1]=c.y,N[3*g+2]=c.z}else if(4===B){var O=new d.Vector4;P=d.Vector4.FromArray(I,g*B),d.Vector4.FromArray(S,g*B).subtractToRef(P,O),N[4*g]=O.x,N[4*g+1]=O.y,N[4*g+2]=O.z,N[4*g+3]=O.w}else d.Tools.Warn("Unsupported number of components for color attribute: ".concat(B));y=r.createBufferView(N,4*B),v=r.createAccessor(y,3===B?"VEC3":"VEC4",5126,l,0),o.push(v),s.attributes.COLOR_0=o.length-1}else d.Tools.Warn("Morph target colors for mesh ".concat(t.name," were not exported. Mesh does not have colors vertex data"))}return s}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,o){var i,s,a,u;return null===(u=null===(a=null===(s=null===(i=this._indicesAccessorMap.get(e))||void 0===i?void 0:i.get(t))||void 0===s?void 0:s.get(r))||void 0===a?void 0:a.get(n))||void 0===u?void 0:u.get(o)},e.prototype.setIndicesAccessor=function(e,t,r,n,o,i){var s=this._indicesAccessorMap.get(e);s||(s=new Map,this._indicesAccessorMap.set(e,s));var a=s.get(t);a||(a=new Map,s.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(o,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,o;return null===(o=null===(n=this._vertexAccessorMap.get(e))||void 0===n?void 0:n.get(t))||void 0===o?void 0:o.get(r)},e.prototype.setVertexAccessor=function(e,t,r,n){var o=this._vertexAccessorMap.get(e);o||(o=new Map,this._vertexAccessorMap.set(e,o));var i=o.get(t);i||(i=new Map,o.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=d.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(d.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=_({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 o=this;if(r>=t.length)return Promise.resolve(e);var i=n(t[r],e);return i?i.then((function(e){return e?o._applyExtension(e,t,r+1,n):null})):this._applyExtension(e,t,r+1,n)},e.prototype._applyExtensions=function(t,r){for(var n=[],o=0,i=e._ExtensionNames;o<i.length;o++){var s=i[o];n.push(this._extensions[s])}return this._applyExtension(t,n,0,r)},e.prototype._extensionsPreExportTextureAsync=function(e,t,r){return this._applyExtensions(t,(function(t,n){return t.preExportTextureAsync&&t.preExportTextureAsync(e,n,r)}))},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n,o){var i=this;return this._applyExtensions(t,(function(t,s){return t.postExportNodeAsync&&t.postExportNodeAsync(e,s,r,n,o,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._extensionsPostExportMaterialAdditionalTextures=function(t,r,n){for(var o=[],i=0,s=e._ExtensionNames;i<s.length;i++){var a=s[i],u=this._extensions[a];u.postExportMaterialAdditionalTextures&&o.push.apply(o,u.postExportMaterialAdditionalTextures(t,r,n))}return o},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var o=0,i=e._ExtensionNames;o<i.length;o++){var s=i[o],a=this._extensions[s];a.postExportTexture&&a.postExportTexture(t,r,n)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var o=n[r],i=this._extensions[o];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,o;return x(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],(o=this._extensions[n]).preGenerateBinaryAsync?[4,o.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 o=n[r],i=this._extensions[o];i.enabled&&t(i)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){var r,n,o;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)),(o=e._glTF).extensions||(o.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],o=e._ExtensionFactories[n](this);this._extensions[n]=o}},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){e.UnregisterExtension(t)&&d.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=r,e._ExtensionNames.push(t)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[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,o,i,s,a;return x(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"}),o=e+".gltf",i=e+".bin",(s=new m).files[o]=r,s.files[i]=n,this._imageData)for(a in this._imageData)s.files[a]=new Blob([this._imageData[a].data],{type:this._imageData[a].mimeType});return[2,s]}}))}))},e.prototype._generateBinaryAsync=function(){return g(this,void 0,void 0,(function(){return x(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,o,i,s,a,u,c,l,f,h,p,d,_,g,y,v,T,b,A,w,E,M;return x(this,(function(x){switch(x.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=x.sent(),this._extensionsOnExporting(),r=this._generateJSON(t.byteLength),n=e+".glb",o=r.length,"undefined"!=typeof TextEncoder&&(s=new TextEncoder,i=s.encode(r),o=i.length),a=this._getPadding(o),u=this._getPadding(t.byteLength),c=28+o+a+t.byteLength+u,l=new ArrayBuffer(12),(f=new DataView(l)).setUint32(0,1179937895,!0),f.setUint32(4,2,!0),f.setUint32(8,c,!0),h=new ArrayBuffer(8+o+a),(p=new DataView(h)).setUint32(0,o+a,!0),p.setUint32(4,1313821514,!0),d=new Uint8Array(h,8),i)d.set(i);else for(_="_".charCodeAt(0),w=0;w<o;++w)(g=r.charCodeAt(w))!=r.codePointAt(w)?d[w]=_:d[w]=g;for(y=new Uint8Array(h,8+o),w=0;w<a;++w)y[w]=32;for(v=new ArrayBuffer(8),(T=new DataView(v)).setUint32(0,t.byteLength+u,!0),T.setUint32(4,5130562,!0),b=new ArrayBuffer(u),A=new Uint8Array(b),w=0;w<u;++w)A[w]=0;return E=new Blob([l,h,v,t,b],{type:"application/octet-stream"}),(M=new m).files[n]=E,[2,M]}}))}))},e.prototype._setNodeTransformation=function(e,t,r){if(t.getPivotPoint().equalsToFloats(0,0,0)||d.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsToFloats(0,0,0)){var n=d.TmpVectors.Vector3[0].copyFrom(t.position);r&&D(n),e.translation=n.asArray()}t.scaling.equalsToFloats(1,1,1)||(e.scale=t.scaling.asArray());var o=d.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);t.rotationQuaternion&&o.multiplyInPlace(t.rotationQuaternion),d.Quaternion.IsIdentity(o)||(r&&G(o),e.rotation=o.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,r,n){var o=d.TmpVectors.Vector3[0],i=d.TmpVectors.Quaternion[0];if(null!==n){var s=d.Matrix.Invert(n.getWorldMatrix());t.getWorldMatrix().multiply(s).decompose(void 0,i,o)}else t.getWorldMatrix().decompose(void 0,i,o);o.equalsToFloats(0,0,0)||(e.translation=o.asArray()),d.Quaternion.IsIdentity(i)||(e.rotation=i.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===d.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===d.Camera.FOVMODE_VERTICAL_FIXED?r.fov:r.fov*r.getEngine().getAspectRatio(r),znear:r.minZ,zfar:r.maxZ};else if("orthographic"===n.type){var o=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:o,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 o=0,i=n;o<i.length;o++)i[o].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(){for(var e,t=function(t){if(t.bones.length<=0)return"continue";var n=r._skinMap.get(t);if(null==n)return"continue";for(var o={},i=[],s=-1,a=0;a<t.bones.length;++a){var u=t.bones[a];-1!==(c=null!==(e=u.getIndex())&&void 0!==e?e:a)&&(o[c]=u,c>s&&(s=c))}for(var c=0;c<=s;++c){u=o[c],i.push(u.getAbsoluteInverseBindMatrix());var l=u.getTransformNode();if(null!==l){var f=r._nodeMap.get(l);l&&null!=f?n.joints.push(f):d.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}else d.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}var h=r._nodesSkinMap.get(n);if(n.joints.length>0&&void 0!==h){var p=64*i.length,m=new Float32Array(p/4);i.forEach((function(e,t){m.set(e.m,16*t)}));var _=r._bufferManager.createBufferView(m);r._accessors.push(r._bufferManager.createAccessor(_,"MAT4",5126,i.length)),n.inverseBindMatrices=r._accessors.length-1,r._skins.push(n);for(var g=0,x=h;g<x.length;g++)x[g].skin=r._skins.length-1}},r=this,n=0,o=this._babylonScene.skeletons;n<o.length;n++)t(o[n])},e.prototype._exportSceneAsync=function(){return g(this,void 0,void 0,(function(){var e,t,r,n,o,i,s,a,u,c,l,f,h,p,d,m,_,g,y,v,T,b,A;return x(this,(function(x){switch(x.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,o=new Array,i=0,s=this._babylonScene.rootNodes;i<s.length;i++)a=s[i],this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&j(a,this._babylonScene.useRightHandedSystem)?o.push.apply(o,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([x.sent()])),h=new te(!1,!1),d=(p=(b=e.nodes).push).apply,m=[b],[4,this._exportNodesAsync(r,h)];case 2:return d.apply(p,m.concat([x.sent()])),_=new te(!1,!0),y=(g=(A=e.nodes).push).apply,v=[A],[4,this._exportNodesAsync(o,_)];case 3:return y.apply(g,v.concat([x.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(),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,o,i;return x(this,(function(s){switch(s.label){case 0:r=new Array,this._exportBuffers(e,t),n=0,o=e,s.label=1;case 1:return n<o.length?(i=o[n],[4,this._exportNodeAsync(i,r,t)]):[3,4];case 2:s.sent(),s.label=3;case 3:return n++,[3,1];case 4:return[2,r]}}))}))},e.prototype._collectBuffers=function(e,t,r,n,o){if(this._shouldExportNode(e)&&e instanceof d.AbstractMesh&&e.geometry){var i=e.geometry.getVertexBuffers();if(i)for(var s in i)if(L(s)){var a=i[s];o.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 p=f.getTarget(h);l=n.get(p)||[],n.set(p,l),-1===l.indexOf(e)&&l.push(e)}}for(var m=0,_=e.getChildren();m<_.length;m++){var g=_[m];this._collectBuffers(g,t,r,n,o)}},e.prototype._exportBuffers=function(e,t){for(var r=new Map,n=new Map,o=new Map,i=0,s=e;i<s.length;i++){var a=s[i];this._collectBuffers(a,r,n,o,t)}for(var u=Array.from(r.keys()),c=function(e){var o=e.getData();if(!o)throw new Error("Buffer data is not available");var i=r.get(e);if(!i)return"continue";var s=i[0].byteStride;if(i.some((function(e){return e.byteStride!==s})))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)}(o).slice(),u=function(e){var t=n.get(e),r=O(e,t),o=r.byteOffset,i=r.byteStride,s=r.componentCount,u=r.type,c=r.count,f=r.normalized;switch(r.kind){case d.VertexBuffer.NormalKind:case d.VertexBuffer.TangentKind:(0,d.EnumerateFloatValues)(a,o,i,s,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 d.VertexBuffer.ColorKind:var h=t.filter((function(e){return e.material instanceof d.StandardMaterial||null==e.material})).length;if(0==h)break;if(h!=t.length){d.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}u==d.VertexBuffer.UNSIGNED_BYTE&&d.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var p=new d.Color3,m=new d.Color4,_=l._babylonScene.getEngine().useExactSrgbConversions;(0,d.EnumerateFloatValues)(a,o,i,s,u,c,f,(function(e){3===e.length?(p.fromArray(e,0),p.toLinearSpaceToRef(p,_),p.toArray(e,0)):(m.fromArray(e,0),m.toLinearSpaceToRef(m,_),m.toArray(e,0))}))}},c=0,f=i;c<f.length;c++)u(F=f[c]);if(t.convertToRightHanded){for(var h=0,p=i;h<p.length;h++){var m=O(F=p[h],n.get(F)),_=m.byteOffset,g=m.byteStride,x=m.componentCount,y=m.type,v=m.count,T=m.normalized;switch(R=m.kind){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:case d.VertexBuffer.TangentKind:(0,d.EnumerateFloatValues)(a,_,g,x,y,v,T,(function(e){e[0]=-e[0]}))}}t.convertedToRightHandedBuffers.set(e,a)}var b=l._bufferManager.createBufferView(a,s);t.setVertexBufferView(e,b);for(var A=new Map,w=0,E=i;w<E.length;w++){var M=O(F=E[w],n.get(F)),R=M.kind,V=M.totalVertices;switch(R){case d.VertexBuffer.MatricesIndicesKind:case d.VertexBuffer.MatricesIndicesExtraKind:if(F.type==d.VertexBuffer.FLOAT){var C=F.getFloatData(V);null!==C&&A.set(F,C)}}}0!==A.size&&d.Logger.Warn("Joints conversion needed: some joints 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 S=0,I=Array.from(A.keys());S<I.length;S++){var F=I[S],B=A.get(F);if(B){for(var N=B.some((function(e){return e>=256})),P=new(N?Uint16Array:Uint8Array)(B.length),U=0;U<B.length;U++)P[U]=B[U];var L=l._bufferManager.createBufferView(P,4*(N?2:1));t.setRemappedBufferView(e,F,L)}}},l=this,f=0,h=u;f<h.length;f++)c(h[f]);for(var p=0,m=Array.from(o.keys());p<m.length;p++){var _=m[p],g=o.get(_);if(g)for(var x=ee(_,g[0],this._bufferManager,this._bufferViews,this._accessors,t.convertToRightHanded),y=0,v=g;y<v.length;y++){var T=v[y];t.bindMorphDataToMesh(T,x)}}},e.prototype._exportNodeAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,o,i,s,a,u,c,l,f=this;return x(this,(function(h){switch(h.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:(o=h.sent())&&(n=this._nodes.length,this._nodes.push(o),this._nodeMap.set(e,n),r.pushExportedNode(e),t.push(n),i={name:"runtime animations",channels:[],samplers:[]},s=[],this._babylonScene.animationGroups.length||($._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,s,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&$._CreateNodeAnimationFromNodeAnimations(e,i,s,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),s.forEach((function(e){e.channels.length&&e.samplers.length&&f._animations.push(e)}))),a=o?[]:t,u=0,c=e.getChildren(),h.label=2;case 2:return u<c.length?(l=c[u],[4,this._exportNodeAsync(l,a,r)]):[3,5];case 3:h.sent(),h.label=4;case 4:return u++,[3,2];case 5:return o&&a.length&&(o.children=a),[2]}}))}))},e.prototype._createNodeAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,o,i,s,a,u,c,l,f,h,p;return x(this,(function(m){switch(m.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 d.TransformNode?(this._setNodeTransformation(r,e,t.convertToRightHanded),e instanceof d.AbstractMesh?(o=e instanceof d.InstancedMesh?e.sourceMesh:e).subMeshes&&o.subMeshes.length>0?(i=r,[4,this._exportMeshAsync(o,t)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:i.mesh=m.sent(),m.label=2;case 2:e.skeleton&&void 0!==(s=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(s)&&this._nodesSkinMap.set(s,[]),null===(f=this._nodesSkinMap.get(s))||void 0===f||f.push(r)),m.label=3;case 3:if(e instanceof d.Camera&&(a=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(a)&&this._nodesCameraMap.set(a,[]),u=e.parent,this._setCameraTransformation(r,e,t.convertToRightHanded,u),u&&W(e,u)&&(c=this._nodeMap.get(u)))return l=this._nodes[c],null===(h=this._nodesCameraMap.get(a))||void 0===h||h.push(l),[2,null];t.convertToRightHanded&&(_=r,g=d.Vector3.FromArrayToRef(_.translation||[0,0,0],0,d.TmpVectors.Vector3[0]),x=d.Quaternion.FromArrayToRef(_.rotation||[0,0,0,1],0,d.TmpVectors.Quaternion[0]),g=D(g),x=G(x),g.equalsWithEpsilon(N,B)?delete _.translation:_.translation=g.asArray(),d.Quaternion.IsIdentity(x)?delete _.rotation:_.rotation=x.asArray(),function(e){var t=d.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,d.TmpVectors.Quaternion[1]);F.multiplyToRef(t,t),e.rotation=t.asArray()}(r)),null===(p=this._nodesCameraMap.get(a))||void 0===p||p.push(r)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",r,e,this._nodeMap,t.convertToRightHanded)];case 4:return m.sent()?[2,r]:(d.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}var _,g,x}))}))},e.prototype._exportIndices=function(e,t,r,n,o,i,s,a,u){var c=e;u.mode=K(i);var l=s!==d.Material.CounterClockWiseSideOrientation,f=!a.wasAddedByNoopNode&&l,h=function(e){switch(e){case d.Material.TriangleFillMode:case d.Material.TriangleStripDrawMode:case d.Material.TriangleFanDrawMode:return!0}return!1}(i)&&f;if(h){if(i===d.Material.TriangleStripDrawMode||i===d.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");u.mode=K(i);var p=t?new Uint32Array(n):new Uint16Array(n);if(e)for(var m=0;m+2<n;m+=3)p[m]=e[r+m]+o,p[m+1]=e[r+m+2]+o,p[m+2]=e[r+m+1]+o;else for(m=0;m+2<n;m+=3)p[m]=m,p[m+1]=m+2,p[m+2]=m+1;c=p}else if(e&&0!==o){for(p=t?new Uint32Array(n):new Uint16Array(n),m=0;m<n;m++)p[m]=e[r+m]+o;c=p}if(c){var _=a.getIndicesAccessor(e,r,n,o,h);if(void 0===_){var g=function(e,t,r,n){if(e instanceof Uint16Array||e instanceof Uint32Array)return e;if(e instanceof Int32Array)return new Uint32Array(e.buffer,e.byteOffset,e.length);var o=e.slice(0,0+r);return n?new Uint32Array(o):new Uint16Array(o)}(c,0,n,t),x=this._bufferManager.createBufferView(g),y=t?5125:5123;this._accessors.push(this._bufferManager.createAccessor(x,"SCALAR",y,n,0)),_=this._accessors.length-1,a.setIndicesAccessor(e,r,n,o,h,_)}u.indices=_}},e.prototype._exportVertexBuffer=function(e,t,r,n,o,i){var s=e.getKind();if(L(s)&&(!s.startsWith("uv")||this._options.exportUnusedUVs||t&&this._materialNeedsUVsSet.has(t))){var a=o.getVertexAccessor(e,r,n);if(void 0===a){var u=o.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),c=s===d.VertexBuffer.PositionKind?function(e,t,r,n){var o=t.byteOffset,i=t.byteStride,s=t.type,a=t.normalized,u=t.getSize(),c=new Array(u).fill(1/0),l=new Array(u).fill(-1/0);return(0,d.EnumerateFloatValues)(e,o+r*i,i,u,s,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=(s===d.VertexBuffer.MatricesIndicesKind||s===d.VertexBuffer.MatricesIndicesExtraKind)&&e.type===d.VertexBuffer.FLOAT,f=l?d.VertexBuffer.UNSIGNED_BYTE:e.type,h=l?void 0:e.normalized,p=l?o.getRemappedBufferView(e._buffer,e):o.getVertexBufferView(e._buffer),m=e.byteOffset+r*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(p,function(e,t){if(e==d.VertexBuffer.ColorKind)return t?"VEC4":"VEC3";switch(e){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:return"VEC3";case d.VertexBuffer.TangentKind:case d.VertexBuffer.MatricesIndicesKind:case d.VertexBuffer.MatricesIndicesExtraKind:case d.VertexBuffer.MatricesWeightsKind:case d.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:case d.VertexBuffer.UV3Kind:case d.VertexBuffer.UV4Kind:case d.VertexBuffer.UV5Kind:case d.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(s,o.hasVertexColorAlpha(e)),f,n,m,c,h)),a=this._accessors.length-1,o.setVertexAccessor(e,r,n,a)}i.attributes[function(e){switch(e){case d.VertexBuffer.PositionKind:return"POSITION";case d.VertexBuffer.NormalKind:return"NORMAL";case d.VertexBuffer.TangentKind:return"TANGENT";case d.VertexBuffer.ColorKind:return"COLOR_0";case d.VertexBuffer.UVKind:return"TEXCOORD_0";case d.VertexBuffer.UV2Kind:return"TEXCOORD_1";case d.VertexBuffer.UV3Kind:return"TEXCOORD_2";case d.VertexBuffer.UV4Kind:return"TEXCOORD_3";case d.VertexBuffer.UV5Kind:return"TEXCOORD_4";case d.VertexBuffer.UV6Kind:return"TEXCOORD_5";case d.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case d.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case d.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case d.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(s)]=a}},e.prototype._exportMaterialAsync=function(e,t,r,n){return g(this,void 0,void 0,(function(){var o,i;return x(this,(function(s){switch(s.label){case 0:return void 0!==(o=this._materialMap.get(e))?[3,6]:(i=t&&Object.keys(t).some((function(e){return e.startsWith("uv")})),(e=e instanceof d.MultiMaterial?e.subMaterials[r.materialIndex]:e)instanceof d.PBRMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,"image/png",i)]:[3,2]);case 1:return o=s.sent(),[3,5];case 2:return e instanceof d.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,"image/png",i)]:[3,4];case 3:return o=s.sent(),[3,5];case 4:return d.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 5:this._materialMap.set(e,o),s.label=6;case 6:return n.material=o,[2]}}))}))},e.prototype._exportMeshAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,o,i,s,a,u,c,l,f,h,p,m,_,g,v,T,b,A,w,E,M,R,V,C,S,I,F,B,N,P,O,U,L;return x(this,(function(x){switch(x.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),o=e.isUnIndexed?null:e.getIndices(),i=null===(B=e.geometry)||void 0===B?void 0:B.getVertexBuffers(),s=t.getMorphTargetsFromMesh(e),a=e instanceof d.LinesMesh,u=e instanceof d.GreasedLineBaseMesh,c=e.subMeshes,!(i&&c&&c.length>0))return[3,7];l=0,f=c,x.label=1;case 1:return l<f.length?(h=f[l],p={attributes:{}},m=h.getMaterial()||this._babylonScene.defaultMaterial,u?(T={name:m.name},b=e,_=d.Color3.White(),g=null!==(P=null===(N=b.material)||void 0===N?void 0:N.alpha)&&void 0!==P?P:1,(!(v=null!==(U=null===(O=b.greasedLineMaterial)||void 0===O?void 0:O.color)&&void 0!==U?U:_).equals(_)||g<1)&&(T.pbrMetallicRoughness={baseColorFactor:y(y([],v.asArray(),!0),[g],!1)}),this._materials.push(T),p.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return a?(T={name:m.name},(!(b=e).color.equals(d.Color3.White())||b.alpha<1)&&(T.pbrMetallicRoughness={baseColorFactor:y(y([],b.color.asArray(),!0),[b.alpha],!1)}),this._materials.push(T),p.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(m,i,h,p)];case 4:x.sent(),x.label=5;case 5:for(A=a||u?d.Material.LineListDrawMode:null!==(L=e.overrideRenderingFillMode)&&void 0!==L?L:m.fillMode,w=m._getEffectiveOrientation(e),this._exportIndices(o,o?(0,d.AreIndices32Bits)(o,h.indexCount,h.indexStart,h.verticesStart):h.verticesCount>65535,o?h.indexStart:h.verticesStart,o?h.indexCount:h.verticesCount,-h.verticesStart,A,w,t,p),E=0,M=Object.values(i);E<M.length;E++)R=M[E],this._exportVertexBuffer(R,m,h.verticesStart,h.verticesCount,t,p);if(s)for(p.targets=[],V=0,C=s;V<C.length;V++)F=C[V],p.targets.push(F.attributes);n.primitives.push(p),this._extensionsPostExportMeshPrimitive(p),x.label=6;case 6:return l++,[3,1];case 7:if(s)for(n.weights=[],n.extras||(n.extras={}),n.extras.targetNames=[],S=0,I=s;S<I.length;S++)F=I[S],n.weights.push(F.influence),n.extras.targetNames.push(F.name);return[2,r]}}))}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),ne=function(){function e(){}return e.GLTFAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,o;return x(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 o=i.sent(),n.dispose(),[2,o]}}))}))},e.GLBAsync=function(e,t,r){return g(this,void 0,void 0,(function(){var n,o;return x(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 o=i.sent(),n.dispose(),[2,o]}}))}))},e}(),oe="EXT_mesh_gpu_instancing",ie=function(){function e(e){this.name=oe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportNodeAsync=function(e,t,r,n,o,i){var s=this;return new Promise((function(e){if(t&&r instanceof d.Mesh&&r.hasThinInstances&&s._exporter){s._wasUsed=!0;for(var n=d.Vector3.Zero(),a=d.Quaternion.Identity(),u=d.Vector3.One(),c=r.thinInstanceGetWorldMatrices(),l=d.TmpVectors.Vector3[2],f=d.TmpVectors.Quaternion[1],h=d.TmpVectors.Vector3[3],p=!1,m=!1,_=!1,g=new Float32Array(3*r.thinInstanceCount),x=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),o&&(D(l),G(f)),g.set(l.asArray(),3*v),x.set(f.normalize().asArray(),4*v),y.set(h.asArray(),3*v),p=p||!l.equalsWithEpsilon(n),m=m||!f.equalsWithEpsilon(a),_=_||!h.equalsWithEpsilon(u),v++;var A={attributes:{}};p&&(A.attributes.TRANSLATION=s._buildAccessor(g,"VEC3",r.thinInstanceCount,i)),m&&(A.attributes.ROTATION=s._buildAccessor(x,"VEC4",r.thinInstanceCount,i)),_&&(A.attributes.SCALE=s._buildAccessor(y,"VEC3",r.thinInstanceCount,i)),t.extensions=t.extensions||{},t.extensions[oe]=A}e(t)}))},e.prototype._buildAccessor=function(e,t,r,n){var o=n.createBufferView(e),i=n.createAccessor(o,t,5126,r);return this._exporter._accessors.push(i),this._exporter._accessors.length-1},e}();re.RegisterExtension(oe,(function(e){return new ie(e)}));var se="KHR_draco_mesh_compression",ae=function(){function e(e){this.name=se,this.required=!0,this._bufferViewsUsed=new Set,this._accessorsUsed=new Set,this._encodePromises=[],this._wasUsed=!1,this.enabled="Draco"===e.options.meshCompressionMethod&&d.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 o=[],i=[],s=null;if(void 0!==e.indices){var a=r[e.indices],u=t.getBufferView(a);s=t.getData(u).slice(),o.push(u),i.push(a)}for(var c,l=[],f=0,h=Object.entries(e.attributes);f<h.length;f++){var p=h[f],m=p[0],_=(a=r[p[1]],u=t.getBufferView(a),U(a.type)),g=(0,d.GetTypedArrayData)(t.getData(u),_,a.componentType,a.byteOffset||0,u.byteStride||(0,d.GetTypeByteLength)(a.componentType)*_,a.normalized||!1,a.count,!0);l.push({kind:m,dracoName:(c=m,"POSITION"===c?"POSITION":"NORMAL"===c?"NORMAL":c.startsWith("COLOR")?"COLOR":c.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"),size:U(a.type),data:g}),o.push(u),i.push(a)}var x={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},y=d.DracoEncoder.Default._encodeAsync(l,s,x).then((function(r){if(r){var s={bufferView:-1,attributes:r.attributeIDs},a=t.createBufferView(r.data);t.setBufferView(s,a);for(var u=0,c=o;u<c.length;u++){var l=c[u];n._bufferViewsUsed.add(l)}for(var f=0,h=i;f<h.length;f++){var p=h[f];n._accessorsUsed.add(p)}e.extensions||(e.extensions={}),e.extensions[se]=s}else d.Logger.Error("Draco encoding failed for primitive.")})).catch((function(e){d.Logger.Error("Draco encoding failed for primitive: "+e)}));this._encodePromises.push(y),this._wasUsed=!0}else d.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 x(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(se,(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=d.Vector3.Backward(),he=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,o){var i=this;return new Promise((function(s){if(r instanceof d.ShadowLight){var a=r.getTypeID()==d.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==d.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==d.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!a)return d.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(ue)),void s(t);if(r.falloffType!==d.Light.FALLOFF_GLTF&&d.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=d.TmpVectors.Vector3[0].copyFrom(r.position);o&&D(u),t.translation=u.asArray()}if("point"!==a){var c=r.direction.normalizeToRef(d.TmpVectors.Vector3[0]);o&&D(c);var l=Math.acos(d.Vector3.Dot(fe,c)),f=d.Vector3.Cross(fe,c),h=d.Quaternion.RotationAxisToRef(f,l,d.TmpVectors.Quaternion[0]);d.Quaternion.IsIdentity(h)||(t.rotation=h.asArray())}var p={type:a,name:r.name,color:r.diffuse.asArray(),intensity:r.intensity,range:r.range};if(q(p,ce),"spot"===a){var m=r;p.spot={innerConeAngle:m.innerAngle/2,outerConeAngle:m.angle/2},q(p.spot,le)}i._lights||(i._lights={lights:[]}),i._lights.lights.push(p);var _={light:i._lights.lights.length-1},g=r.parent;if(g&&W(r,g)){var x=n.get(g);if(x){var y=i._exporter._nodes[x];return function(e,t){var r=d.Vector3.FromArrayToRef(t.translation||[0,0,0],0,d.TmpVectors.Vector3[0]),n=d.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,d.TmpVectors.Quaternion[0]),o=d.Vector3.FromArrayToRef(t.scale||[1,1,1],0,d.TmpVectors.Vector3[1]),i=d.Matrix.ComposeToRef(o,n,r,d.TmpVectors.Matrix[0]),s=d.Vector3.FromArrayToRef(e.translation||[0,0,0],0,d.TmpVectors.Vector3[2]),a=d.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,d.TmpVectors.Quaternion[1]),u=d.Vector3.FromArrayToRef(e.scale||[1,1,1],0,d.TmpVectors.Vector3[1]),c=d.Matrix.ComposeToRef(u,a,s,d.TmpVectors.Matrix[1]);i.multiplyToRef(c,c),c.decompose(o,n,r),r.equalsWithEpsilon(N,B)?delete t.translation:t.translation=r.asArray(),d.Quaternion.IsIdentity(n)?delete t.rotation:t.rotation=n.asArray(),o.equalsWithEpsilon(P,B)?delete t.scale:t.scale=o.asArray()}(t,y),y.extensions||(y.extensions={}),y.extensions[ue]=_,void s(null)}}t.extensions||(t.extensions={}),t.extensions[ue]=_,s(t)}else s(t)}))},e}();re.RegisterExtension(ue,(function(e){return new he(e)}));var pe="KHR_materials_anisotropy",de=function(){function e(e){this.name=pe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof d.PBRBaseMaterial&&r.anisotropy.isEnabled&&!r.anisotropy.legacy?(r.anisotropy.texture&&n.push(r.anisotropy.texture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof d.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var o=n._exporter._materialExporter.getTextureInfo(r.anisotropy.texture),i={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=o?o:void 0};null!==i.anisotropyTexture&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[pe]=i}e(t)}))},e}();re.RegisterExtension(pe,(function(e){return new de(e)}));var me="KHR_materials_clearcoat",_e=function(){function e(e){this.name=me,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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof d.PBRBaseMaterial&&r.clearCoat.isEnabled?(r.clearCoat.texture&&n.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&n.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&n.push(r.clearCoat.bumpTexture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof d.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var o,i=n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);o=r.clearCoat.useRoughnessFromMainTexture?n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):n._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&d.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),r.clearCoat.remapF0OnInterfaceChange&&d.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(r.name));var s=n._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture),a={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=i?i:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=o?o:void 0,clearcoatNormalTexture:null!=s?s:void 0};null===a.clearcoatTexture&&null===a.clearcoatRoughnessTexture&&null===a.clearcoatRoughnessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[me]=a}e(t)}))},e}();re.RegisterExtension(me,(function(e){return new _e(e)}));var ge="KHR_materials_diffuse_transmission";function xe(e,t){var r=t.subSurface,n=null;return r.translucencyIntensityTexture?n=r.translucencyIntensityTexture:r.thicknessTexture&&r.useMaskFromThicknessTexture&&(n=r.thicknessTexture),n&&!r.useGltfStyleTextures?(d.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(t.name),1),null):n}var ye=function(){function e(e){this.name=ge,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];if(r instanceof d.PBRMaterial&&this._isExtensionEnabled(r)){var o=xe(e,r);return o&&n.push(o),r.subSurface.translucencyColorTexture&&n.push(r.subSurface.translucencyColorTexture),n}return n},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(o){var i,s;if(r instanceof d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var a=r.subSurface,u=xe(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!==(s=n._exporter._materialExporter.getTextureInfo(a.translucencyColorTexture))&&void 0!==s?s:void 0,p={diffuseTransmissionFactor:c,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:f,diffuseTransmissionColorTexture:h};(l||h)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions=t.extensions||{},t.extensions[ge]=p}o(t)}))},e}();re.RegisterExtension(ge,(function(e){return new ye(e)}));var ve="KHR_materials_dispersion",Te=function(){function e(){this.name=ve,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 d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var o={dispersion:r.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[ve]=o}e(t)}))},e}();re.RegisterExtension(ve,(function(){return new Te}));var be="KHR_materials_emissive_strength",Ae=function(){function e(){this.name=be,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(!(r instanceof d.PBRMaterial))return e(t);var o=r.emissiveColor.asArray(),i=Math.max.apply(Math,o);if(i>1){n._wasUsed=!0,t.extensions||(t.extensions={});var s={emissiveStrength:i},a=r.emissiveColor.scale(1/s.emissiveStrength);t.emissiveFactor=a.asArray(),t.extensions[be]=s}return e(t)}))},e}();re.RegisterExtension(be,(function(e){return new Ae}));var we="KHR_materials_ior",Ee=function(){function e(){this.name=we,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 d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var o={ior:r.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[we]=o}e(t)}))},e}();re.RegisterExtension(we,(function(e){return new Ee}));var Me="KHR_materials_iridescence",Re=function(){function e(e){this.name=Me,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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof d.PBRBaseMaterial&&r.iridescence.isEnabled?(r.iridescence.texture&&n.push(r.iridescence.texture),r.iridescence.thicknessTexture&&r.iridescence.thicknessTexture!==r.iridescence.texture&&n.push(r.iridescence.thicknessTexture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof d.PBRBaseMaterial){if(!r.iridescence.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var o=n._exporter._materialExporter.getTextureInfo(r.iridescence.texture),i=n._exporter._materialExporter.getTextureInfo(r.iridescence.thicknessTexture),s={iridescenceFactor:r.iridescence.intensity,iridescenceIor:r.iridescence.indexOfRefraction,iridescenceThicknessMinimum:r.iridescence.minimumThickness,iridescenceThicknessMaximum:r.iridescence.maximumThickness,iridescenceTexture:null!=o?o:void 0,iridescenceThicknessTexture:null!=i?i:void 0};null===s.iridescenceTexture&&null===s.iridescenceThicknessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Me]=s}e(t)}))},e}();re.RegisterExtension(Me,(function(e){return new Re(e)}));var Ve="KHR_materials_sheen",Ce=function(){function e(e){this.name=Ve,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.postExportMaterialAdditionalTextures=function(e,t,r){return r instanceof d.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[r.sheen.texture]:[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o,i,s,a;if(r instanceof d.PBRMaterial){if(!r.sheen.isEnabled)return void e(t);n._wasUsed=!0,null==t.extensions&&(t.extensions={});var u={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(o=r.sheen.roughness)&&void 0!==o?o:0};null===u.sheenColorTexture&&null===u.sheenRoughnessTexture||n._exporter._materialNeedsUVsSet.add(r),r.sheen.texture&&(u.sheenColorTexture=null!==(i=n._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==i?i:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(s=n._exporter._materialExporter.getTextureInfo(r.sheen.textureRoughness))&&void 0!==s?s:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(a=n._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==a?a:void 0),t.extensions[Ve]=u}e(t)}))},e}();re.RegisterExtension(Ve,(function(e){return new Ce(e)}));var Se="KHR_materials_specular",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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof d.PBRMaterial&&this._isExtensionEnabled(r)?(r.metallicReflectanceTexture&&n.push(r.metallicReflectanceTexture),r.reflectanceTexture&&n.push(r.reflectanceTexture),n):n},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 o,i;if(r instanceof d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0,t.extensions=t.extensions||{};var s=null!==(o=n._exporter._materialExporter.getTextureInfo(r.metallicReflectanceTexture))&&void 0!==o?o:void 0,a=null!==(i=n._exporter._materialExporter.getTextureInfo(r.reflectanceTexture))&&void 0!==i?i:void 0,u={specularFactor:1==r.metallicF0Factor?void 0:r.metallicF0Factor,specularTexture:s,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:a};n._hasTexturesExtension(r)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[Se]=u}e(t)}))},e}();re.RegisterExtension(Se,(function(e){return new Ie(e)}));var Fe="KHR_materials_transmission",Be=function(){function e(e){this.name=Fe,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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof d.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&n.push(r.subSurface.thicknessTexture),n):n},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,o,i,s;return x(this,(function(a){switch(a.label){case 0:return r instanceof d.PBRMaterial&&this._isExtensionEnabled(r)?(this._wasUsed=!0,n=r.subSurface,o=0===n.refractionIntensity?void 0:n.refractionIntensity,i={transmissionFactor:o},this._hasTexturesExtension(r)&&this._exporter._materialNeedsUVsSet.add(r),n.refractionIntensityTexture?n.useGltfStyleTextures?[4,this._exporter._materialExporter.exportTextureAsync(n.refractionIntensityTexture,"image/png")]:[3,2]:[3,3]):[3,4];case 1:return(s=a.sent())&&(i.transmissionTexture=s),[3,3];case 2:d.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[Fe]=i,a.label=4;case 4:return[2,t]}}))}))},e}();re.RegisterExtension(Fe,(function(e){return new Be(e)}));var Ne="KHR_materials_unlit",Pe=function(){function e(){this.name=Ne,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 o=!1;r instanceof d.PBRMaterial?o=r.unlit:r instanceof d.StandardMaterial&&(o=r.disableLighting),o&&(n._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[Ne]={}),e(t)}))},e}();re.RegisterExtension(Ne,(function(){return new Pe}));var Oe="KHR_materials_volume",Ue=function(){function e(e){this.name=Oe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof d.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&n.push(r.subSurface.thicknessTexture),n):n},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!=d.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 o;if(r instanceof d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var i=r.subSurface,s={thicknessFactor:0==i.maximumThickness?void 0:i.maximumThickness,thicknessTexture:null!==(o=n._exporter._materialExporter.getTextureInfo(i.thicknessTexture))&&void 0!==o?o: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[Oe]=s}e(t)}))},e}();re.RegisterExtension(Oe,(function(e){return new Ue(e)}));var Le="KHR_texture_transform",Ke=function(){function e(){this.name=Le,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()||d.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(r.name,"!")),0===r.uAng&&0===r.vAng||(d.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={},o=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],o=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],o=!0),0!==r.wAng){if(0!==r.uRotationCenter||0!==r.vRotationCenter){if(r.homogeneousRotationInUVTransform&&r.uScale!==r.vScale)return void d.Tools.Warn("".concat(e,": Texture ").concat(r.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(Le,"."));d.Tools.Warn("".concat(e,": Texture ").concat(r.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(Le,".")),n.offset=function(e){var t=e.uOffset,r=e.vOffset,n=e.uRotationCenter,o=e.vRotationCenter,i=e.uScale,s=e.vScale,a=e.wAng,u=Math.cos(a),c=Math.sin(a),l=n*i,f=o*s;return[t+(l*(1-u)+f*c),r+(f*(1-u)-l*c)]}(r)}n.rotation=-r.wAng,o=!0}0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,o=!0),o&&(this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[Le]=n)}},e}();re.RegisterExtension(Le,(function(){return new Ke}));var ke=void 0!==i.g?i.g:"undefined"!=typeof window?window:void 0;if(void 0!==ke){ke.BABYLON=ke.BABYLON||{};var De=ke.BABYLON;De.GLTF2=De.GLTF2||{},De.GLTF2.Exporter=De.GLTF2.Exporter||{},De.GLTF2.Exporter.Extensions=De.GLTF2.Exporter.Extensions||{};var Ge=[];for(var He in a)De[He]=a[He],Ge.push(He);for(var He in u)De[He]=u[He],Ge.push(He);for(var He in c)De[He]=c[He],Ge.push(He);for(var He in l)De.GLTF2.Exporter.Extensions[He]=l[He],Ge.push(He);for(var He in f)Ge.indexOf(He)>-1||(De.GLTF2.Exporter[He]=f[He])}const We=h;return s.default})()));
2
2
  //# sourceMappingURL=babylon.glTF2Serializer.min.js.map