babylonjs-serializers 8.16.2 → 8.16.3

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}},s={};function i(e){var t=s[e];if(void 0!==t)return t.exports;var r=s[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 s=Object.create(null);i.r(s);var o={};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=>o[t]=()=>e[t]));return o.default=()=>e,i.d(s,o),s},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 o={};i.d(o,{default:()=>qe});var a={};i.r(a),i.d(a,{__IGLTFExporterExtension:()=>p});var u={};i.r(u),i.d(u,{GLTFData:()=>_});var c={};i.r(c),i.d(c,{GLTF2Export:()=>se});var l={};i.r(l),i.d(l,{EXT_materials_diffuse_roughness:()=>Ge,EXT_mesh_gpu_instancing:()=>oe,KHR_draco_mesh_compression:()=>ue,KHR_lights_punctual:()=>pe,KHR_materials_anisotropy:()=>_e,KHR_materials_clearcoat:()=>me,KHR_materials_diffuse_transmission:()=>Te,KHR_materials_dispersion:()=>be,KHR_materials_emissive_strength:()=>Ae,KHR_materials_ior:()=>Me,KHR_materials_iridescence:()=>Ce,KHR_materials_sheen:()=>Ve,KHR_materials_specular:()=>Fe,KHR_materials_transmission:()=>Oe,KHR_materials_unlit:()=>Ne,KHR_materials_volume:()=>Le,KHR_texture_transform:()=>ke});var f={};i.r(f),i.d(f,{EXT_materials_diffuse_roughness:()=>Ge,EXT_mesh_gpu_instancing:()=>oe,GLTF2Export:()=>se,GLTFData:()=>_,KHR_draco_mesh_compression:()=>ue,KHR_lights_punctual:()=>pe,KHR_materials_anisotropy:()=>_e,KHR_materials_clearcoat:()=>me,KHR_materials_diffuse_transmission:()=>Te,KHR_materials_dispersion:()=>be,KHR_materials_emissive_strength:()=>Ae,KHR_materials_ior:()=>Me,KHR_materials_iridescence:()=>Ce,KHR_materials_sheen:()=>Ve,KHR_materials_specular:()=>Fe,KHR_materials_transmission:()=>Oe,KHR_materials_unlit:()=>Ne,KHR_materials_volume:()=>Le,KHR_texture_transform:()=>ke,_ConvertToGLTFPBRMetallicRoughness:()=>M,_SolveMetallic:()=>w});var h={};i.r(h),i.d(h,{EXT_materials_diffuse_roughness:()=>Ge,EXT_mesh_gpu_instancing:()=>oe,GLTF2Export:()=>se,GLTFData:()=>_,KHR_draco_mesh_compression:()=>ue,KHR_lights_punctual:()=>pe,KHR_materials_anisotropy:()=>_e,KHR_materials_clearcoat:()=>me,KHR_materials_diffuse_transmission:()=>Te,KHR_materials_dispersion:()=>be,KHR_materials_emissive_strength:()=>Ae,KHR_materials_ior:()=>Me,KHR_materials_iridescence:()=>Ce,KHR_materials_sheen:()=>Ve,KHR_materials_specular:()=>Fe,KHR_materials_transmission:()=>Oe,KHR_materials_unlit:()=>Ne,KHR_materials_volume:()=>Le,KHR_texture_transform:()=>ke,_ConvertToGLTFPBRMetallicRoughness:()=>M,_SolveMetallic:()=>w,__IGLTFExporterExtension:()=>p});var p=0,d=i(597),_=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}(),g=function(){return g=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var s in t=arguments[r])Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s]);return e},g.apply(this,arguments)};function m(e,t,r,n){return new(r||(r=Promise))((function(s,i){function o(e){try{u(n.next(e))}catch(e){i(e)}}function a(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,a)}u((n=n.apply(e,t||[])).next())}))}function x(e,t){var r,n,s,i={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(i=0)),i;)try{if(r=1,n&&(s=2&a[0]?n.return:a[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,a[1])).done)return s;switch(n=0,s&&(a=[2&a[0],s.value]),a[0]){case 0:case 1:s=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((s=(s=i.trys).length>0&&s[s.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!s||a[1]>s[0]&&a[1]<s[3])){i.label=a[1];break}if(6===a[0]&&i.label<s[1]){i.label=s[1],s=a;break}if(s&&i.label<s[2]){i.label=s[2],i.ops.push(a);break}s[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],n=0}finally{r=s=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function y(e,t,r){if(r||2===arguments.length)for(var n,s=0,i=t.length;s<i;s++)!n&&s in t||(n||(n=Array.prototype.slice.call(t,0,s)),n[s]=t[s]);return e.concat(n||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var T=1e-6,v=new d.Color3(.04,.04,.04),b=1024,E=d.Color3.White(),A=d.Color3.Black();function w(e,t,r){if(t<v.r)return 0;var n=v.r,s=e*r/(1-v.r)+t-2*v.r,i=s*s-4*n*(v.r-t);return d.Scalar.Clamp((-s+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),s=(0,d.SpecularPowerToRoughness)(n);return{baseColorFactor:[t.r,t.g,t.b,r],metallicFactor:0,roughnessFactor:s}}function R(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function C(e,t,r){for(var n=new Uint8Array(e*t*4),s=0;s<n.length;s+=4)n[s]=n[s+1]=n[s+2]=n[s+3]=255;return d.RawTexture.CreateRGBATexture(n,e,t,r)}function S(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 V=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 m(this,void 0,void 0,(function(){var n,s,i,o,a,u,c,l;return x(this,(function(f){switch(f.label){case 0:return n=M(e),s={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."),s.doubleSided=!0),r?(i=[],(o=e.diffuseTexture)&&i.push(this.exportTextureAsync(o,t).then((function(e){e&&(n.baseColorTexture=e)}))),(a=e.bumpTexture)&&i.push(this.exportTextureAsync(a,t).then((function(e){e&&(s.normalTexture=e,1!==a.level&&(s.normalTexture.scale=a.level))}))),(u=e.emissiveTexture)&&(s.emissiveFactor=[1,1,1],i.push(this.exportTextureAsync(u,t).then((function(e){e&&(s.emissiveTexture=e)})))),(c=e.ambientTexture)&&i.push(this.exportTextureAsync(c,t).then((function(e){if(e){var t={index:e.index};s.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?s.alphaMode="BLEND":d.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(A,T)&&(s.emissiveFactor=e.emissiveColor.asArray()),s.pbrMetallicRoughness=n,R(s,e),[4,this._finishMaterialAsync(s,e,t)];case 3:return f.sent(),(l=this._exporter._materials).push(s),[2,l.length-1]}}))}))},e.prototype._finishMaterialAsync=function(e,t,r){return m(this,void 0,void 0,(function(){var n,s,i,o,a;return x(this,(function(u){switch(u.label){case 0:for(n=this._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",e,t),s=[],i=0,o=n;i<o.length;i++)a=o[i],s.push(this.exportTextureAsync(a,r));return[4,Promise.all(s)];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 m(this,void 0,void 0,(function(){var s,o,a,u,c;return x(this,(function(l){switch(l.label){case 0:return s=d.Constants.TEXTURETYPE_UNSIGNED_BYTE,o=this._exporter._babylonScene,a=o.getEngine(),u=a.createRawTexture(e,t,r,d.Constants.TEXTUREFORMAT_RGBA,!1,!0,d.Texture.NEAREST_SAMPLINGMODE,null,s),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,o,s,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,s,i=e?e.getSize():{width:0,height:0},o=t?t.getSize():{width:0,height:0};return i.width<o.width?(n=e&&e instanceof d.Texture?d.TextureTools.CreateResizedCopy(e,o.width,o.height,!0):C(o.width,o.height,r),s=t):i.width>o.width?(s=t&&t instanceof d.Texture?d.TextureTools.CreateResizedCopy(t,i.width,i.height,!0):C(i.width,i.height,r),n=e):(n=e,s=t),{texture1:n,texture2:s}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,r,n){return m(this,void 0,void 0,(function(){var s,i,o,a,u,c,l,f,h,p,_,g,m,y,v,b,w,M,R,C,V,B,F,I,O,P,N,U,L,D,G;return x(this,(function(x){switch(x.label){case 0:return s=new Array,e||t?[3,2]:[4,Promise.reject("diffuse and specular glossiness textures are not defined!")];case 1:case 6:case 9:case 11:case 13:return[2,x.sent()];case 2:return(i=e?e.getScene():t?t.getScene():null)?(o=this._resizeTexturesToSameDimensions(e,t,i),a=null===(G=o.texture1)||void 0===G?void 0:G.getSize(),u=void 0,c=void 0,l=a.width,f=a.height,[4,o.texture1.readPixels()]):[3,12];case 3:return h=x.sent(),[4,o.texture2.readPixels()];case 4:return p=x.sent(),h?(u=S(h),[3,7]):[3,5];case 5:return[4,Promise.reject("Failed to retrieve pixels from diffuse texture!")];case 7:return p?(c=S(p),[3,10]):[3,8];case 8:return[4,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];case 10:for(_=c.byteLength,g=new Uint8Array(_),m=new Uint8Array(_),y=A,v=0,b=0,P=0;P<f;++P)for(N=0;N<l;++N)w=4*(l*P+N),M=new d.Color3(u[w],u[w+1],u[w+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(r.diffuseColor),R=new d.Color3(c[w],c[w+1],c[w+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(r.specularColor),C=c[w+3]*r.glossiness,V={diffuseColor:M,specularColor:R,glossiness:C},B=this._convertSpecularGlossinessToMetallicRoughness(V),y.r=Math.max(y.r,B.baseColor.r),y.g=Math.max(y.g,B.baseColor.g),y.b=Math.max(y.b,B.baseColor.b),v=Math.max(v,B.metallic),b=Math.max(b,B.roughness),m[w]=255*B.baseColor.r,m[w+1]=255*B.baseColor.g,m[w+2]=255*B.baseColor.b,m[w+3]=o.texture1.hasAlpha?255*u[w+3]:255,g[w]=0,g[w+1]=255*B.roughness,g[w+2]=255*B.metallic,g[w+3]=255;for(F={baseColor:y,metallic:v,roughness:b},I=!1,O=!1,P=0;P<f;++P)for(N=0;N<l;++N)m[U=4*(l*P+N)]/=F.baseColor.r>T?F.baseColor.r:1,m[U+1]/=F.baseColor.g>T?F.baseColor.g:1,m[U+2]/=F.baseColor.b>T?F.baseColor.b:1,L=d.Color3.FromInts(m[U],m[U+1],m[U+2]),D=L.toGammaSpace(i.getEngine().useExactSrgbConversions),m[U]=255*D.r,m[U+1]=255*D.g,m[U+2]=255*D.b,D.equalsWithEpsilon(E,T)||(O=!0),g[U+1]/=F.roughness>T?F.roughness:1,g[U+2]/=F.metallic>T?F.metallic:1,d.Color3.FromInts(255,g[U+1],g[U+2]).equalsWithEpsilon(E,T)||(I=!0);return I&&s.push(this._getImageDataAsync(g,l,f,n).then((function(e){F.metallicRoughnessTextureData=e}))),O&&s.push(this._getImageDataAsync(m,l,f,n).then((function(e){F.baseColorTextureData=e}))),[4,Promise.all(s).then((function(){return F}))];case 12:return[4,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}}))}))},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var t=this._getPerceivedBrightness(e.diffuseColor),r=this._getPerceivedBrightness(e.specularColor),n=1-this._getMaxComponent(e.specularColor),s=w(t,r,n),i=e.diffuseColor.scale(n/(1-v.r)/Math.max(1-s)),o=e.specularColor.subtract(v.scale(1-s)).scale(1/Math.max(s)),a=d.Color3.Lerp(i,o,s*s);return{baseColor:a=a.clampToRef(0,1,a),metallic:s,roughness:1-e.glossiness}},e.prototype._getPerceivedBrightness=function(e){return 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 m(this,void 0,void 0,(function(){var s,i,o;return x(this,(function(a){switch(a.label){case 0:return s=[],i={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness},n&&(e._albedoTexture&&s.push(this.exportTextureAsync(e._albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)}))),(o=e._metallicTexture)&&s.push(this.exportTextureAsync(o,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))),s.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(s)]):[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 m(this,void 0,void 0,(function(){var s,i,o,a,u,c,l,f;return x(this,(function(h){switch(h.label){case 0:return s={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},i=e._albedoTexture,o=e._reflectivityTexture,a=e._useMicroSurfaceFromReflectivityMapAlpha,!o||a?[3,2]:[4,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")];case 1:return[2,h.sent()];case 2:return(i||o)&&n?(this._exporter._materialNeedsUVsSet.add(e),u=this._exportTextureSampler(i||o),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(i,o,s,t)]):[3,4];case 3: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==o?void 0:o.coordinatesIndex)),[2,c];case 4:return[2,this._convertSpecularGlossinessToMetallicRoughness(s)]}}))}))},e.prototype.exportPBRMaterialAsync=function(e,t,r){return m(this,void 0,void 0,(function(){var n,s,i,o,a,u,c,l;return x(this,(function(f){switch(f.label){case 0:return n={},s={name:e.name},(i=e.isMetallicWorkflow())&&(o=e._albedoColor,a=e.alpha,o&&(n.baseColorFactor=[o.r,o.g,o.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,s,n,t,r)];case 5:return f.sent(),[4,this._finishMaterialAsync(s,e,t)];case 6:return f.sent(),(l=this._exporter._materials).push(s),[2,l.length-1]}}))}))},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,t,r,n,s,i){return m(this,void 0,void 0,(function(){var o,a,u,c,l;return x(this,(function(f){switch(f.label){case 0:return R(r,t),e.baseColor.equalsWithEpsilon(E,T)&&d.Scalar.WithinEpsilon(t.alpha,1,T)||(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?(o=[],(a=t._bumpTexture)&&o.push(this.exportTextureAsync(a,s).then((function(e){e&&(r.normalTexture=e,1!==a.level&&(r.normalTexture.scale=a.level))}))),(u=t._ambientTexture)&&o.push(this.exportTextureAsync(u,s).then((function(e){if(e){var n={index:e.index,texCoord:e.texCoord,extensions:e.extensions};r.occlusionTexture=n;var s=t._ambientTextureStrength;s&&(n.strength=s)}}))),(c=t._emissiveTexture)&&o.push(this.exportTextureAsync(c,s).then((function(e){e&&(r.emissiveTexture=e)}))),o.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(o)]):[3,2]):[3,2];case 1:f.sent(),f.label=2;case 2:return(l=t._emissiveColor).equalsWithEpsilon(A,T)||(r.emissiveFactor=l.asArray()),r.pbrMetallicRoughness=n,[2]}}))}))},e.prototype._getPixelsFromTextureAsync=function(e){return function(e){switch(e){case d.Constants.TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM:case d.Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT5:case d.Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT3:case d.Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT1:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGB_S3TC_DXT1:case d.Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:case d.Constants.TEXTUREFORMAT_COMPRESSED_SRGB_S3TC_DXT1_EXT:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGBA_ASTC_4x4:case d.Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGB_ETC1_WEBGL:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGB8_ETC2:case d.Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_ETC2:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:case d.Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGBA8_ETC2_EAC:case d.Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:return!0;default:return!1}}(e.textureFormat)?(0,d.GetTextureDataAsync)(e,e._texture.width,e._texture.height):(e.textureType,d.Constants.TEXTURETYPE_UNSIGNED_BYTE,e.readPixels())},e.prototype.exportTextureAsync=function(e,t){return m(this,void 0,void 0,(function(){var r,n=this;return x(this,(function(s){switch(s.label){case 0:return(r=this._exporter._extensionsPreExportTextureAsync("exporter",e,t))?[3,2]:[4,this._exportTextureInfoAsync(e,t)];case 1:case 3:return[2,s.sent()];case 2:return[4,r.then((function(r){return m(n,void 0,void 0,(function(){return x(this,(function(n){switch(n.label){case 0:return r?[3,2]:[4,this._exportTextureInfoAsync(e,t)];case 1:case 3:return[2,n.sent()];case 2:return[4,this._exportTextureInfoAsync(r,t)]}}))}))}))]}}))}))},e.prototype._exportTextureInfoAsync=function(e,t){return m(this,void 0,void 0,(function(){var r,n,s,i,o,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._getPixelsFromTextureAsync(e)];case 1:if(!(n=h.sent()))return[2,null];if(s=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,". Exporting texture as PNG."))}return o=this._internalTextureToImage,a=e.getInternalTexture().uniqueId,o[a]||(o[a]={}),void 0===(u=o[a][t])&&(c=e.getSize(),u=m(f,void 0,void 0,(function(){var r;return x(this,(function(s){switch(s.label){case 0:return[4,this._getImageDataAsync(n,c.width,c.height,t)];case 1:return r=s.sent(),[2,this._exportImage(e.name,t,r)]}}))})),o[a][t]=u),l=this._exportTextureInfo,[4,u];case 2:r=l.apply(this,[h.sent(),s,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,s=this._exporter._images;if(this._exporter._shouldUseGlb){n={name:e,mimeType:t,bufferView:void 0};var i=this._exporter._bufferManager.createBufferView(new Uint8Array(r));this._exporter._bufferManager.setBufferView(n,i)}else{var o=e.replace(/\.\/|\/|\.\\|\\/g,"_"),a=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp";case"image/avif":return".avif"}}(t),u=o+a;s.some((function(e){return e.uri===u}))&&(u="".concat(o,"_").concat(d.Tools.RandomId()).concat(a)),n={name:e,uri:u},this._exporter._imageData[u]={data:r,mimeType:t}}return s.push(n),s.length-1},e.prototype._exportTextureInfo=function(e,t,r){var n=this._exporter._textures,s=n.findIndex((function(r){return r.sampler==t&&r.source===e}));-1===s&&(s=n.length,n.push({source:e,sampler:t}));var i={index:s};return r&&(i.texCoord=r),i},e.prototype._exportTextureSampler=function(e){var t=this._getTextureSampler(e),r=this._exporter._samplers,n=r.findIndex((function(e){return e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT}));return-1!==n?n:(r.push(t),r.length-1)},e}(),B=d.Vector3.Zero(),F=d.Quaternion.Identity(),I=d.Vector3.One(),O=new d.Vector3(-1,1,1);function P(e,t){var r=e.byteOffset,n=e.byteStride,s=e.type,i=e.normalized,o=e.getSize(),a=t.reduce((function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e}),-Number.MAX_VALUE);return{byteOffset:r,byteStride:n,componentCount:o,type:s,count:a*o,normalized:i,totalVertices:a,kind:e.getKind()}}function N(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 U(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 L(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 D(e){var t=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);t>0&&(e.x/=t,e.y/=t,e.z/=t)}function G(e){return e.x*=-1,e}function K(e){if(e.x*e.x+e.y*e.y>.5){var t=Math.abs(e.x),r=Math.abs(e.y);if(t>r){var n=Math.sign(e.x);e.x=t,e.y*=-n,e.z*=-n,e.w*=n}else n=Math.sign(e.y),e.x*=-n,e.y=r,e.z*=n,e.w*=-n}else{var s=Math.abs(e.z),i=Math.abs(e.w);s>i?(n=Math.sign(e.z),e.x*=-n,e.y*=n,e.z=s,e.w*=-n):(n=Math.sign(e.w),e.x*=n,e.y*=-n,e.z*=-n,e.w=i)}return e}function k(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function H(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]),s=d.Matrix.ComposeToRef(I,n,r,d.TmpVectors.Matrix[0]),i=d.Vector3.FromArrayToRef(e.translation||[0,0,0],0,d.TmpVectors.Vector3[2]),o=d.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,d.TmpVectors.Quaternion[1]),a=d.Matrix.ComposeToRef(I,o,i,d.TmpVectors.Matrix[1]);s.multiplyToRef(a,a),a.decompose(void 0,n,r),r.equalsWithEpsilon(B,d.Epsilon)?delete t.translation:t.translation=r.asArray(),n.equalsWithEpsilon(F,d.Epsilon)?delete t.rotation:t.rotation=n.asArray(),t.scale&&delete t.scale}function W(e,t){if(!(t instanceof d.TransformNode))return!1;if(1!==t.getChildren().length||0!==e.getChildren().length||e.parent!==t)return!1;var r=e.getScene(),n=e instanceof d.TargetCamera&&!r.useRightHandedSystem?O:I;return!!t.scaling.equalsWithEpsilon(n,d.Epsilon)||(d.Logger.Warn("Cannot collapse node ".concat(e.name," into parent node ").concat(t.name," with modified scaling.")),!1)}function j(e,t){for(var r=0,n=Object.entries(e);r<n.length;r++){var s=n[r],i=s[0],o=s[1],a=t[i];(Array.isArray(o)&&Array.isArray(a)&&z(o,a)||o===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=d.Matrix.Compose(new d.Vector3(-1,1,1),d.Quaternion.Identity(),d.Vector3.Zero());function X(e,t){if(!(e instanceof d.TransformNode))return!1;if(t){if(!e.getWorldMatrix().equalsWithEpsilon(d.Matrix.IdentityReadOnly,d.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(q,d.TmpVectors.Matrix[0]).equalsWithEpsilon(d.Matrix.IdentityReadOnly,d.Epsilon))return!1;return!(e instanceof d.AbstractMesh&&e.geometry)}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 Z(e){return e%4==0?4:e%2==0?2:1}var 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,s=Array.from(this._bufferViewToData.keys()).sort((function(e,t){return Z(t.byteLength)-Z(e.byteLength)}));n<s.length;n++){var i=s[n];i.byteOffset=r.byteOffset,e.push(i);for(var o=e.length-1,a=0,u=this.getPropertiesWithBufferView(i);a<u.length;a++)u[a].bufferView=o;r.writeTypedArray(this._bufferViewToData.get(i)),this._bufferViewToData.delete(i)}return r.getOutputData()},e.prototype.createBufferView=function(e,t){var r={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(r,e),r},e.prototype.createAccessor=function(e,t,r,n,s,i,o){this._verifyBufferView(e);var a={bufferView:void 0,componentType:r,count:n,type:t,min:null==i?void 0:i.min,max:null==i?void 0:i.max,normalized:o,byteOffset:s};return this.setBufferView(a,e),this._accessorToBufferView.set(a,e),a},e.prototype.setBufferView=function(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)},e.prototype.removeBufferView=function(e){for(var t=this,r=0,n=this.getPropertiesWithBufferView(e);r<n.length;r++){var s=n[r];void 0!==s.bufferView&&delete s.bufferView}this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach((function(r,n){r===e&&(void 0!==n.byteOffset&&delete n.byteOffset,t._accessorToBufferView.delete(n))}))},e.prototype.getBufferView=function(e){var t=this._accessorToBufferView.get(e);return this._verifyBufferView(t),t},e.prototype.getPropertiesWithBufferView=function(e){var t;return this._verifyBufferView(e),this._bufferViewToProperties.set(e,null!==(t=this._bufferViewToProperties.get(e))&&void 0!==t?t:[]),this._bufferViewToProperties.get(e)},e.prototype.getData=function(e){return this._verifyBufferView(e),this._bufferViewToData.get(e)},e.prototype._verifyBufferView=function(e){if(void 0===e||!this._bufferViewToData.has(e))throw new Error("BufferView ".concat(e," not found in BufferManager."))},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(J||(J={}));var ee=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,s,i){if(this._IsTransformable(t)){var o=[],a=[],u=r.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,n,s),f=l.interpolationType,h=l.shouldBakeAnimation;if(h?e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,i,o,a,c,s):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(t,r,n,o,a,s):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(t,r,n,o,a,s):e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,i,o,a,c,s),o.length&&a.length)return{inputs:o,outputs:a,samplerInterpolation:f,inputsMin:h?c.min: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,s=e.targetProperty.split(".");switch(s[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":r="VEC4",t="rotation";break;case"rotationQuaternion":r="VEC4",n=!0,t="rotation";break;case"influence":r="SCALAR",t="weights";break;default:d.Tools.Error("Unsupported animatable property ".concat(s[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,s,i,o,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 _=d[p];if(!f||f(_)){var g=e._DeduceAnimationInfo(_);g&&(h={name:_.name,samplers:[],channels:[]},e._AddAnimation("".concat(_.name),_.hasRunningRuntimeAnimations?r:h,t,_,g.dataAccessorType,g.animationChannelTargetPath,s,o,a,u,g.useQuaternion,c,l),h.samplers.length&&h.channels.length&&n.push(h))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,s,i,o,a,u,c,l,f){var h;if(t instanceof d.Mesh){var p=t.morphTargetManager;if(p)for(var _=0;_<p.numTargets;++_)for(var g=0,m=p.getTarget(_).animations;g<m.length;g++){var x=m[g];if(!f||f(x)){for(var y=new d.Animation("".concat(x.name),"influence",x.framePerSecond,x.dataType,x.loopMode,x.enableBlending),T=[],v=x.getKeys(),b=0;b<v.length;++b)for(var E=v[b],A=0;A<p.numTargets;++A)A==_?T.push(E):T.push({frame:E.frame,value:0});y.setKeys(T);var w=e._DeduceAnimationInfo(y);w&&(h={name:y.name,samplers:[],channels:[]},e._AddAnimation(x.name,x.hasRunningRuntimeAnimations?r:h,t,y,w.dataAccessorType,w.animationChannelTargetPath,s,o,a,u,w.useQuaternion,c,l,p.numTargets),h.samplers.length&&h.channels.length&&n.push(h))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,s,i,o,a,u,c){var l,f;if(t.animationGroups)for(var h=t.animationGroups,p=function(h){var p=new Map,g=new Map,m=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,T=x.animation;if(c&&!c(T))return"continue";var v=u.has(y);if(_._IsTransformable(y)||1===y.length&&_._IsTransformable(y[0])){if(E=e._DeduceAnimationInfo(x.animation)){var b=_._IsTransformable(y)?y:_._IsTransformable(y[0])?y[0]:null;b&&e._AddAnimation("".concat(T.name),f,b,T,E.dataAccessorType,E.animationChannelTargetPath,n,s,i,o,E.useQuaternion,a,v)}}else if(y instanceof d.MorphTarget||1===y.length&&y[0]instanceof d.MorphTarget){var E;if(E=e._DeduceAnimationInfo(x.animation)){var A=y instanceof d.MorphTarget?y:y[0];if(A){var w=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===A)return!0;return!1}));if(w){var M=t.meshes.find((function(e){return e.morphTargetManager===w}));M&&(p.has(M)||p.set(M,new Map),null===(l=p.get(M))||void 0===l||l.set(A,T),m.add(M),g.set(M,T))}}}}},T=0;T<h.targetedAnimations.length;++T)y(T);m.forEach((function(t){for(var r=t.morphTargetManager,u=null,c=[],l=g.get(t).getKeys(),_=l.length,m=0;m<_;++m)for(var y=0;y<r.numTargets;++y){var T=r.getTarget(y),v=p.get(t);if(v){var b=v.get(T);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()[m])):c.push({frame:h.from+x/_*m,value:T.influence,inTangent:l[0].inTangent?0:void 0,outTangent:l[0].outTangent?0:void 0})}}u.setKeys(c);var E=e._DeduceAnimationInfo(u);E&&e._AddAnimation("".concat(h.name,"_").concat(t.name,"_MorphWeightAnimation"),f,t,u,E.dataAccessorType,E.animationChannelTargetPath,n,s,i,o,E.useQuaternion,a,!1,null==r?void 0:r.numTargets)})),f.channels.length&&f.samplers.length&&r.push(f)},_=this,g=0,m=h;g<m.length;g++)p(m[g])},e._AddAnimation=function(t,r,n,s,i,o,a,u,c,l,f,h,p,_){var g,m,x,y,T,v,b=e._CreateNodeAnimation(n,s,o,f,h);if(b){if(_){for(var E=0,A=0,w=[];b.inputs.length>0;)A=b.inputs.shift(),E%_==0&&w.push(A),E++;b.inputs=w}var M=a.get(n),R=new Float32Array(b.inputs);g=u.createBufferView(R),m=u.createAccessor(g,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(m),x=l.length-1;var C=new d.Quaternion,S=new d.Vector3,V=new d.Vector3,B=n instanceof d.Camera,F=N(i),I=new Float32Array(b.outputs.length*F);b.outputs.forEach((function(e,t){var r=e;switch(o){case"translation":p&&(d.Vector3.FromArrayToRef(e,0,V),G(V),V.toArray(r));break;case"rotation":4===e.length?d.Quaternion.FromArrayToRef(e,0,C):(r=new Array(4),d.Vector3.FromArrayToRef(e,0,S),d.Quaternion.FromEulerVectorToRef(S,C)),p&&(K(C),B&&k(C)),C.toArray(r)}I.set(r,t*F)})),g=u.createBufferView(I),m=u.createAccessor(g,i,5126,b.outputs.length),l.push(m),y=l.length-1,T={interpolation:b.samplerInterpolation,input:x,output:y},r.samplers.push(T),v={sampler:r.samplers.length-1,target:{node:M,path:o}},r.channels.push(v)}},e._CreateBakedAnimation=function(t,r,n,s,i,o,a,u,c,l,f){var h,p,_=d.Quaternion.Identity(),g=null,m=null,x=null,y=null,T=null,v=null;l.min=d.Tools.FloatRound(s/o);for(var b=r.getKeys(),E=0,A=b.length;E<A;++E){if(v=null,x=b[E],E+1<A)if(y=b[E+1],x.value.equals&&x.value.equals(y.value)||x.value===y.value){if(0!==E)continue;v=x.frame}else v=y.frame;else{if(T=b[E-1],x.value.equals&&x.value.equals(T.value)||x.value===T.value)continue;v=i}if(v)for(var w=x.frame;w<=v;w+=a)if((p=d.Tools.FloatRound(w/o))!==g){g=p,m=p;var M={key:0,repeatCount:0,loopMode:r.loopMode};h=r._interpolate(w,M),e._SetInterpolatedValue(t,h,p,r,n,_,u,c,f)}}m&&(l.max=m)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,s,i){var o=e._GetBasePositionRotationOrScale(r,s,i),a=n.targetProperty.split("."),u=a?a[1]:"",c=i?d.Quaternion.FromArray(o).normalize():d.Vector3.FromArray(o);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,s,i,o,a,u){var c;o.push(r),"weights"!==s?(n.dataType===d.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,s,u)),"rotation"===s?(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,s,i,o){for(var a=0,u=r.getKeys();a<u.length;a++){var c=u[a];s.push(c.frame/r.framePerSecond),e._AddKeyframeValue(c,r,i,n,t,o)}},e._CreateCubicSplineAnimation=function(t,r,n,s,i,o){r.getKeys().forEach((function(a){s.push(a.frame/r.framePerSecond),e._AddSplineTangent(J.INTANGENT,i,n,"CUBICSPLINE",a,o),e._AddKeyframeValue(a,r,i,n,t,o),e._AddSplineTangent(J.OUTTANGENT,i,n,"CUBICSPLINE",a,o)}))},e._GetBasePositionRotationOrScale=function(e,t,r){var n;if("rotation"===t)if(r){var s=e.rotationQuaternion;n=(null!=s?s:d.Quaternion.Identity()).asArray()}else{var i=e.rotation;n=(null!=i?i:d.Vector3.Zero()).asArray()}else if("translation"===t){var o=e.position;n=(null!=o?o: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,s,i){var o,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(o=this._ConvertFactorToVector3OrQuaternion(e.value,s,t,n,i)){if("rotation"===n){var l=i?o:d.Quaternion.RotationYawPitchRoll(o.y,o.x,o.z).normalize();r.push(l.asArray())}r.push(o.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,s,i=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var o=0,a=e.length;o<a;++o)if((s=e[o]).inTangent||s.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",i=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||s.interpolation&&1===s.interpolation&&"STEP"!==n){n="LINEAR",i=!0;break}}else n=s.interpolation&&1===s.interpolation?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,t,r,n,s,i){var o,a=e===J.INTANGENT?s.inTangent:s.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(a)if(i)o=a.asArray();else{var u=a;o=d.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else o=[0,0,0,0];else o="weights"===r?a?[a]:[0]:a?a.asArray():[0,0,0];t.push(o)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,r=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),r=Math.max(r,e.frame)})),{min:t,max:r}},e}();function te(e,t,r,n,s,i){var o={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."),o;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),_=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0];l=h.length/3;for(var m=0;m<l;++m){var x=d.Vector3.FromArray(h,3*m);d.Vector3.FromArray(f,3*m).subtractToRef(x,c),c.x*=u,_[0]=Math.min(_[0],c.x),g[0]=Math.max(g[0],c.x),_[1]=Math.min(_[1],c.y),g[1]=Math.max(g[1],c.y),_[2]=Math.min(_[2],c.z),g[2]=Math.max(g[2],c.z),p[3*m]=c.x,p[3*m+1]=c.y,p[3*m+2]=c.z}var y=r.createBufferView(p,12),T=r.createAccessor(y,"VEC3",5126,f.length/3,0,{min:_,max:g});s.push(T),o.attributes.POSITION=s.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(),b=a.getVerticesData(d.VertexBuffer.NormalKind);if(b){var E=new Float32Array(b.length);for(l=b.length/3,m=0;m<l;++m){var A=d.Vector3.FromArray(b,3*m).normalize();d.Vector3.FromArray(v,3*m).normalize().subtractToRef(A,c),E[3*m]=c.x*u,E[3*m+1]=c.y,E[3*m+2]=c.z}y=r.createBufferView(E,12),T=r.createAccessor(y,"VEC3",5126,v.length/3,0),s.push(T),o.attributes.NORMAL=s.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(),M=a.getVerticesData(d.VertexBuffer.TangentKind);if(M){l=M.length/4;var R=new Float32Array(3*l);for(m=0;m<l;++m){var C=d.Vector3.FromArray(M,4*m);D(C);var S=d.Vector3.FromArray(w,3*m);D(S),S.subtractToRef(C,c),R[3*m]=c.x*u,R[3*m+1]=c.y,R[3*m+2]=c.z}y=r.createBufferView(R,12),T=r.createAccessor(y,"VEC3",5126,l,0),s.push(T),o.attributes.TANGENT=s.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 V=e.getColors(),B=a.getVerticesData(d.VertexBuffer.ColorKind),F=a.getVertexBuffer(d.VertexBuffer.ColorKind);if(B&&F){var I=F.getSize();l=B.length/I;var O=new Float32Array(l*I);for(m=0;m<l;++m)if(3===I){var P=d.Vector3.FromArray(B,m*I);d.Vector3.FromArray(V,m*I).subtractToRef(P,c),O[3*m]=c.x,O[3*m+1]=c.y,O[3*m+2]=c.z}else if(4===I){var N=new d.Vector4;P=d.Vector4.FromArray(B,m*I),d.Vector4.FromArray(V,m*I).subtractToRef(P,N),O[4*m]=N.x,O[4*m+1]=N.y,O[4*m+2]=N.z,O[4*m+3]=N.w}else d.Tools.Warn("Unsupported number of components for color attribute: ".concat(I));y=r.createBufferView(O,4*I),T=r.createAccessor(y,3===I?"VEC3":"VEC4",5126,l,0),s.push(T),o.attributes.COLOR_0=s.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 o}var re=function(){function e(e,t){this._indicesAccessorMap=new Map,this._vertexBufferViewMap=new Map,this._vertexAccessorMap=new Map,this._remappedBufferView=new Map,this._meshMorphTargetMap=new Map,this._vertexMapColorAlpha=new Map,this._exportedNodes=new Set,this._meshMap=new Map,this.convertedToRightHandedBuffers=new Map,this.convertToRightHanded=e,this.wasAddedByNoopNode=t}return e.prototype.getIndicesAccessor=function(e,t,r,n,s){var i,o,a,u;return null===(u=null===(a=null===(o=null===(i=this._indicesAccessorMap.get(e))||void 0===i?void 0:i.get(t))||void 0===o?void 0:o.get(r))||void 0===a?void 0:a.get(n))||void 0===u?void 0:u.get(s)},e.prototype.setIndicesAccessor=function(e,t,r,n,s,i){var o=this._indicesAccessorMap.get(e);o||(o=new Map,this._indicesAccessorMap.set(e,o));var a=o.get(t);a||(a=new Map,o.set(t,a));var u=a.get(r);u||(u=new Map,a.set(r,u));var c=u.get(n);c||(c=new Map,u.set(n,c)),c.set(s,i)},e.prototype.pushExportedNode=function(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)},e.prototype.getNodesSet=function(){return this._exportedNodes},e.prototype.getVertexBufferView=function(e){return this._vertexBufferViewMap.get(e)},e.prototype.setVertexBufferView=function(e,t){this._vertexBufferViewMap.set(e,t)},e.prototype.setRemappedBufferView=function(e,t,r){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,r)},e.prototype.getRemappedBufferView=function(e,t){var r;return null===(r=this._remappedBufferView.get(e))||void 0===r?void 0:r.get(t)},e.prototype.getVertexAccessor=function(e,t,r){var n,s;return null===(s=null===(n=this._vertexAccessorMap.get(e))||void 0===n?void 0:n.get(t))||void 0===s?void 0:s.get(r)},e.prototype.setVertexAccessor=function(e,t,r,n){var s=this._vertexAccessorMap.get(e);s||(s=new Map,this._vertexAccessorMap.set(e,s));var i=s.get(t);i||(i=new Map,s.set(t,i)),i.set(r,n)},e.prototype.hasVertexColorAlpha=function(e){return this._vertexMapColorAlpha.get(e)||!1},e.prototype.setHasVertexColorAlpha=function(e,t){return this._vertexMapColorAlpha.set(e,t)},e.prototype.getMesh=function(e){return this._meshMap.get(e)},e.prototype.setMesh=function(e,t){this._meshMap.set(e,t)},e.prototype.bindMorphDataToMesh=function(e,t){var r=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,r),-1===r.indexOf(t)&&r.push(t)},e.prototype.getMorphTargetsFromMesh=function(e){return this._meshMorphTargetMap.get(e)},e}(),ne=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 V(this),this._extensions={},this._bufferManager=new $,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=g({shouldExportNode:function(){return!0},shouldExportAnimation:function(){return!0},metadataSelector:function(e){var t;return null===(t=null==e?void 0:e.gltf)||void 0===t?void 0:t.extras},animationSampleRate:1/60,exportWithoutWaitingForScene:!1,exportUnusedUVs:!1,removeNoopRootNodes:!0,includeCoordinateSystemConversionNodes:!1,meshCompressionMethod:"None"},t),this._loadExtensions()}return e.prototype._ApplyExtension=function(e,t,r,n){var s=this;if(r>=t.length)return Promise.resolve(e);var i=n(t[r],e);return i?i.then((function(e){return m(s,void 0,void 0,(function(){var s;return x(this,(function(i){switch(i.label){case 0:return e?[4,this._ApplyExtension(e,t,r+1,n)]:[3,2];case 1:return s=i.sent(),[3,3];case 2:s=null,i.label=3;case 3:return[2,s]}}))}))})):this._ApplyExtension(e,t,r+1,n)},e.prototype._ApplyExtensions=function(t,r){for(var n=[],s=0,i=e._ExtensionNames;s<i.length;s++){var o=i[s];n.push(this._extensions[o])}return this._ApplyExtension(t,n,0,r)},e.prototype._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,s){var i=this;return this._ApplyExtensions(t,(function(t,o){return t.postExportNodeAsync&&t.postExportNodeAsync(e,o,r,n,s,i._bufferManager)}))},e.prototype._extensionsPostExportMaterialAsync=function(e,t,r){return this._ApplyExtensions(t,(function(t,n){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,n,r)}))},e.prototype._extensionsPostExportMaterialAdditionalTextures=function(t,r,n){for(var s=[],i=0,o=e._ExtensionNames;i<o.length;i++){var a=o[i],u=this._extensions[a];u.postExportMaterialAdditionalTextures&&s.push.apply(s,u.postExportMaterialAdditionalTextures(t,r,n))}return s},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var s=0,i=e._ExtensionNames;s<i.length;s++){var o=i[s],a=this._extensions[o];a.postExportTexture&&a.postExportTexture(t,r,n)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var s=n[r],i=this._extensions[s];i.postExportMeshPrimitive&&i.postExportMeshPrimitive(t,this._bufferManager,this._accessors)}},e.prototype._extensionsPreGenerateBinaryAsync=function(){return m(this,void 0,void 0,(function(){var t,r,n,s;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],(s=this._extensions[n]).preGenerateBinaryAsync?[4,s.preGenerateBinaryAsync(this._bufferManager)]:[3,3]):[3,4];case 2:i.sent(),i.label=3;case 3:return t++,[3,1];case 4:return[2]}}))}))},e.prototype._forEachExtensions=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var s=n[r],i=this._extensions[s];i.enabled&&t(i)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){var r,n,s;t.wasUsed&&((r=e._glTF).extensionsUsed||(r.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&((n=e._glTF).extensionsRequired||(n.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),(s=e._glTF).extensions||(s.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],s=e._ExtensionFactories[n](this);this._extensions[n]=s}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e.RegisterExtension=function(t,r){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 m(this,void 0,void 0,(function(){var t,r,n,s,i,o,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"}),s=e+".gltf",i=e+".bin",(o=new _).files[s]=r,o.files[i]=n,this._imageData)for(a in this._imageData)o.files[a]=new Blob([this._imageData[a].data],{type:this._imageData[a].mimeType});return[2,o]}}))}))},e.prototype._generateBinaryAsync=function(){return m(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 m(this,void 0,void 0,(function(){var t,r,n,s,i,o,a,u,c,l,f,h,p,d;return x(this,(function(g){switch(g.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=g.sent(),this._extensionsOnExporting(),r=this._generateJSON(t.byteLength),n=e+".glb",s=r.length,"undefined"!=typeof TextEncoder&&(o=new TextEncoder,i=o.encode(r),s=i.length),a=this._getPadding(s),u=this._getPadding(t.byteLength),c=28+s+a+t.byteLength+u,(l=new Y(c)).writeUInt32(1179937895),l.writeUInt32(2),l.writeUInt32(c),l.writeUInt32(s+a),l.writeUInt32(1313821514),i)l.writeTypedArray(i);else for(f="_".charCodeAt(0),p=0;p<s;++p)(h=r.charCodeAt(p))!=r.codePointAt(p)?l.writeUInt8(f):l.writeUInt8(h);for(p=0;p<a;++p)l.writeUInt8(32);for(l.writeUInt32(t.byteLength+u),l.writeUInt32(5130562),l.writeTypedArray(t),p=0;p<u;++p)l.writeUInt8(0);return(d=new _).files[n]=new Blob([l.getOutputData()],{type:"application/octet-stream"}),[2,d]}}))}))},e.prototype._setNodeTransformation=function(e,t,r){var n;if(t.getPivotPoint().equalsWithEpsilon(B,d.Epsilon)||d.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsWithEpsilon(B,d.Epsilon)){var s=d.TmpVectors.Vector3[0].copyFrom(t.position);r&&G(s),e.translation=s.asArray()}t.scaling.equalsWithEpsilon(I,d.Epsilon)||(e.scale=t.scaling.asArray());var i=(null===(n=t.rotationQuaternion)||void 0===n?void 0:n.clone())||d.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);i.equalsWithEpsilon(F,d.Epsilon)||(r&&K(i),e.rotation=i.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,r){if(!t.position.equalsWithEpsilon(B,d.Epsilon)){var n=d.TmpVectors.Vector3[0].copyFrom(t.position);r&&G(n),e.translation=n.asArray()}var s=t.rotationQuaternion||d.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);r&&K(s),this._babylonScene.useRightHandedSystem||k(s),s.equalsWithEpsilon(F,d.Epsilon)||(e.rotation=s.asArray())},e.prototype._listAvailableCameras=function(){for(var e=0,t=this._babylonScene.cameras;e<t.length;e++){var r=t[e],n={type:r.mode===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 s=r.orthoLeft&&r.orthoRight?.5*(r.orthoRight-r.orthoLeft):.5*r.getEngine().getRenderWidth(),i=r.orthoBottom&&r.orthoTop?.5*(r.orthoTop-r.orthoBottom):.5*r.getEngine().getRenderHeight();n.orthographic={xmag:s,ymag:i,znear:r.minZ,zfar:r.maxZ}}this._camerasMap.set(r,n)}},e.prototype._exportAndAssignCameras=function(){for(var e=0,t=Array.from(this._camerasMap.values());e<t.length;e++){var r=t[e],n=this._nodesCameraMap.get(r);if(void 0!==n){this._cameras.push(r);for(var s=0,i=n;s<i.length;s++)i[s].camera=this._cameras.length-1}}},e.prototype._listAvailableSkeletons=function(){for(var e=0,t=this._babylonScene.skeletons;e<t.length;e++){var r=t[e];r.bones.length<=0||this._skinMap.set(r,{joints:[]})}},e.prototype._exportAndAssignSkeletons=function(){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 s={},i=[],o=-1,a=0;a<t.bones.length;++a){var u=t.bones[a];-1!==(c=null!==(e=u.getIndex())&&void 0!==e?e:a)&&(s[c]=u,c>o&&(o=c))}for(var c=0;c<=o;++c){u=s[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,_=new Float32Array(p/4);i.forEach((function(e,t){_.set(e.m,16*t)}));var g=r._bufferManager.createBufferView(_);r._accessors.push(r._bufferManager.createAccessor(g,"MAT4",5126,i.length)),n.inverseBindMatrices=r._accessors.length-1,r._skins.push(n);for(var m=0,x=h;m<x.length;m++)x[m].skin=r._skins.length-1}},r=this,n=0,s=this._babylonScene.skeletons;n<s.length;n++)t(s[n])},e.prototype._exportSceneAsync=function(){return m(this,void 0,void 0,(function(){var e,t,r,n,s,i,o,a,u,c,l,f,h,p,d,_,g,m,y,T,v,b,E;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,s=new Array,i=0,o=this._babylonScene.rootNodes;i<o.length;i++)a=o[i],this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&X(a,this._babylonScene.useRightHandedSystem)?s.push.apply(s,a.getChildren()):this._babylonScene.useRightHandedSystem?r.push(a):n.push(a);return this._listAvailableCameras(),this._listAvailableSkeletons(),u=new re(!0,!1),l=(c=(v=e.nodes).push).apply,f=[v],[4,this._exportNodesAsync(n,u)];case 1:return l.apply(c,f.concat([x.sent()])),h=new re(!1,!1),d=(p=(b=e.nodes).push).apply,_=[b],[4,this._exportNodesAsync(r,h)];case 2:return d.apply(p,_.concat([x.sent()])),g=new re(!1,!0),y=(m=(E=e.nodes).push).apply,T=[E],[4,this._exportNodesAsync(s,g)];case 3:return y.apply(m,T.concat([x.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(),this._babylonScene.animationGroups.length&&ee._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 m(this,void 0,void 0,(function(){var r,n,s,i;return x(this,(function(o){switch(o.label){case 0:r=new Array,this._exportBuffers(e,t),n=0,s=e,o.label=1;case 1:return n<s.length?(i=s[n],[4,this._exportNodeAsync(i,r,t)]):[3,4];case 2:o.sent(),o.label=3;case 3:return n++,[3,1];case 4:return[2,r]}}))}))},e.prototype._collectBuffers=function(e,t,r,n,s){if(this._shouldExportNode(e)&&e instanceof d.AbstractMesh&&e.geometry){var i=e.geometry.getVertexBuffers();if(i)for(var o in i)if(U(o)){var a=i[o];s.setHasVertexColorAlpha(a,e.hasVertexAlpha);var u=a._buffer,c=t.get(u)||[];t.set(u,c),-1===c.indexOf(a)&&c.push(a);var l=r.get(a)||[];r.set(a,l),-1===l.indexOf(e)&&l.push(e)}var f=e.morphTargetManager;if(f)for(var h=0;h<f.numTargets;h++){var p=f.getTarget(h);l=n.get(p)||[],n.set(p,l),-1===l.indexOf(e)&&l.push(e)}}for(var _=0,g=e.getChildren();_<g.length;_++){var m=g[_];this._collectBuffers(m,t,r,n,s)}},e.prototype._exportBuffers=function(e,t){for(var r=new Map,n=new Map,s=new Map,i=0,o=e;i<o.length;i++){var a=o[i];this._collectBuffers(a,r,n,s,t)}for(var u=Array.from(r.keys()),c=function(e){var s=e.getData();if(!s)throw new Error("Buffer data is not available");var i=r.get(e);if(!i)return"continue";var o=i[0].byteStride;if(i.some((function(e){return e.byteStride!==o})))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");for(var a=function(e){if(e instanceof Array){var t=new Float32Array(e);return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}return ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e)}(s).slice(),u=function(e){var t=n.get(e),r=P(e,t),s=r.byteOffset,i=r.byteStride,o=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,s,i,o,u,c,f,(function(e){var t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){var r=1/t;e[0]*=r,e[1]*=r,e[2]*=r}}));break;case 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,_=new d.Color4,g=l._babylonScene.getEngine().useExactSrgbConversions;(0,d.EnumerateFloatValues)(a,s,i,o,u,c,f,(function(e){3===e.length?(p.fromArray(e,0),p.toLinearSpaceToRef(p,g),p.toArray(e,0)):(_.fromArray(e,0),_.toLinearSpaceToRef(_,g),_.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 _=P(F=p[h],n.get(F)),g=_.byteOffset,m=_.byteStride,x=_.componentCount,y=_.type,T=_.count,v=_.normalized;switch(R=_.kind){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:case d.VertexBuffer.TangentKind:(0,d.EnumerateFloatValues)(a,g,m,x,y,T,v,(function(e){e[0]=-e[0]}))}}t.convertedToRightHandedBuffers.set(e,a)}var b=l._bufferManager.createBufferView(a,o);t.setVertexBufferView(e,b);for(var E=new Map,A=0,w=i;A<w.length;A++){var M=P(F=w[A],n.get(F)),R=M.kind,C=M.totalVertices;switch(R){case d.VertexBuffer.MatricesIndicesKind:case d.VertexBuffer.MatricesIndicesExtraKind:if(F.type==d.VertexBuffer.FLOAT){var S=F.getFloatData(C);null!==S&&E.set(F,S)}}}0!==E.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 V=0,B=Array.from(E.keys());V<B.length;V++){var F=B[V],I=E.get(F);if(I){for(var O=I.some((function(e){return e>=256})),N=new(O?Uint16Array:Uint8Array)(I.length),U=0;U<I.length;U++)N[U]=I[U];var L=l._bufferManager.createBufferView(N,4*(O?2:1));t.setRemappedBufferView(e,F,L)}}},l=this,f=0,h=u;f<h.length;f++)c(h[f]);for(var p=0,_=Array.from(s.keys());p<_.length;p++){var g=_[p],m=s.get(g);if(m)for(var x=te(g,m[0],this._bufferManager,this._bufferViews,this._accessors,t.convertToRightHanded),y=0,T=m;y<T.length;y++){var v=T[y];t.bindMorphDataToMesh(v,x)}}},e.prototype._exportNodeAsync=function(e,t,r){return m(this,void 0,void 0,(function(){var n,s,i,o,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:(s=h.sent())&&(n=this._nodes.length,this._nodes.push(s),this._nodeMap.set(e,n),r.pushExportedNode(e),t.push(n),i={name:"runtime animations",channels:[],samplers:[]},o=[],this._babylonScene.animationGroups.length||(ee._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,o,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&ee._CreateNodeAnimationFromNodeAnimations(e,i,o,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation)),i.channels.length&&i.samplers.length&&this._animations.push(i),o.forEach((function(e){e.channels.length&&e.samplers.length&&f._animations.push(e)}))),a=s?[]:t,u=0,c=e.getChildren(),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 s&&a.length&&(s.children=a),[2]}}))}))},e.prototype._createNodeAsync=function(e,t){return m(this,void 0,void 0,(function(){var r,n,s,i,o,a,u,c,l,f,h,p;return x(this,(function(_){switch(_.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?(s=e instanceof d.InstancedMesh?e.sourceMesh:e).subMeshes&&s.subMeshes.length>0?(i=r,[4,this._exportMeshAsync(s,t)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:i.mesh=_.sent(),_.label=2;case 2:e.skeleton&&void 0!==(o=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(o)&&this._nodesSkinMap.set(o,[]),null===(f=this._nodesSkinMap.get(o))||void 0===f||f.push(r)),_.label=3;case 3:if(e instanceof d.TargetCamera&&(a=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(a)&&this._nodesCameraMap.set(a,[]),this._setCameraTransformation(r,e,t.convertToRightHanded),null!==(u=e.parent)&&W(e,u)&&void 0!==(c=this._nodeMap.get(u)))return l=this._nodes[c],H(r,l),null===(h=this._nodesCameraMap.get(a))||void 0===h||h.push(l),[2,null];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 _.sent()?[2,r]:(d.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}}))}))},e.prototype._exportIndices=function(e,t,r,n,s,i,o,a,u){var c=e;u.mode=L(i);var l=o!==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=L(i);var p=t?new Uint32Array(n):new Uint16Array(n);if(e)for(var _=0;_+2<n;_+=3)p[_]=e[r+_]+s,p[_+1]=e[r+_+2]+s,p[_+2]=e[r+_+1]+s;else for(_=0;_+2<n;_+=3)p[_]=_,p[_+1]=_+2,p[_+2]=_+1;c=p}else if(e&&0!==s){for(p=t?new Uint32Array(n):new Uint16Array(n),_=0;_<n;_++)p[_]=e[r+_]+s;c=p}if(c){var g=a.getIndicesAccessor(e,r,n,s,h);if(void 0===g){var m=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 s=e.slice(0,0+r);return n?new Uint32Array(s):new Uint16Array(s)}(c,0,n,t),x=this._bufferManager.createBufferView(m),y=t?5125:5123;this._accessors.push(this._bufferManager.createAccessor(x,"SCALAR",y,n,0)),g=this._accessors.length-1,a.setIndicesAccessor(e,r,n,s,h,g)}u.indices=g}},e.prototype._exportVertexBuffer=function(e,t,r,n,s,i){var o=e.getKind();if(U(o)&&(!o.startsWith("uv")||this._options.exportUnusedUVs||t&&this._materialNeedsUVsSet.has(t))){var a=s.getVertexAccessor(e,r,n);if(void 0===a){var u=s.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),c=o===d.VertexBuffer.PositionKind?function(e,t,r,n){var s=t.byteOffset,i=t.byteStride,o=t.type,a=t.normalized,u=t.getSize(),c=new Array(u).fill(1/0),l=new Array(u).fill(-1/0);return(0,d.EnumerateFloatValues)(e,s+r*i,i,u,o,n*u,a,(function(e){for(var t=0;t<u;t++)c[t]=Math.min(c[t],e[t]),l[t]=Math.max(l[t],e[t])})),{min:c,max:l}}(u,e,r,n):void 0,l=(o===d.VertexBuffer.MatricesIndicesKind||o===d.VertexBuffer.MatricesIndicesExtraKind)&&e.type===d.VertexBuffer.FLOAT,f=l?d.VertexBuffer.UNSIGNED_BYTE:e.type,h=l?void 0:e.normalized,p=l?s.getRemappedBufferView(e._buffer,e):s.getVertexBufferView(e._buffer),_=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))}(o,s.hasVertexColorAlpha(e)),f,n,_,c,h)),a=this._accessors.length-1,s.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))}(o)]=a}},e.prototype._exportMaterialAsync=function(e,t,r,n){return m(this,void 0,void 0,(function(){var s,i;return x(this,(function(o){switch(o.label){case 0:return void 0!==(s=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.PBRBaseMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,"image/png",i)]:[3,2]);case 1:return s=o.sent(),[3,5];case 2:return e instanceof d.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,"image/png",i)]:[3,4];case 3:return s=o.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,s),o.label=6;case 6:return n.material=s,[2]}}))}))},e.prototype._exportMeshAsync=function(e,t){return m(this,void 0,void 0,(function(){var r,n,s,i,o,a,u,c,l,f,h,p,_,g,m,T,v,b,E,A,w,M,R,C,S,V,B,F,I,O,P,N,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),s=e.isUnIndexed?null:e.getIndices(),i=null===(I=e.geometry)||void 0===I?void 0:I.getVertexBuffers(),o=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:{}},_=h.getMaterial()||this._babylonScene.defaultMaterial,u?(v={name:_.name},b=e,g=d.Color3.White(),m=null!==(P=null===(O=b.material)||void 0===O?void 0:O.alpha)&&void 0!==P?P:1,(!(T=null!==(U=null===(N=b.greasedLineMaterial)||void 0===N?void 0:N.color)&&void 0!==U?U:g).equalsWithEpsilon(g,d.Epsilon)||m<1)&&(v.pbrMetallicRoughness={baseColorFactor:y(y([],T.asArray(),!0),[m],!1)}),this._materials.push(v),p.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return a?(v={name:_.name},(!(b=e).color.equalsWithEpsilon(d.Color3.White(),d.Epsilon)||b.alpha<1)&&(v.pbrMetallicRoughness={baseColorFactor:y(y([],b.color.asArray(),!0),[b.alpha],!1)}),this._materials.push(v),p.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(_,i,h,p)];case 4:x.sent(),x.label=5;case 5:for(E=a||u?d.Material.LineListDrawMode:null!==(L=e.overrideRenderingFillMode)&&void 0!==L?L:_.fillMode,A=_._getEffectiveOrientation(e),this._exportIndices(s,s?(0,d.AreIndices32Bits)(s,h.indexCount,h.indexStart,h.verticesStart):h.verticesCount>65535,s?h.indexStart:h.verticesStart,s?h.indexCount:h.verticesCount,-h.verticesStart,E,A,t,p),w=0,M=Object.values(i);w<M.length;w++)R=M[w],this._exportVertexBuffer(R,_,h.verticesStart,h.verticesCount,t,p);if(o)for(p.targets=[],C=0,S=o;C<S.length;C++)F=S[C],p.targets.push(F.attributes);n.primitives.push(p),this._extensionsPostExportMeshPrimitive(p),x.label=6;case 6:return l++,[3,1];case 7:if(o)for(n.weights=[],n.extras||(n.extras={}),n.extras.targetNames=[],V=0,B=o;V<B.length;V++)F=B[V],n.weights.push(F.influence),n.extras.targetNames.push(F.name);return[2,r]}}))}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),se=function(){function e(){}return e.GLTFAsync=function(e,t,r){return m(this,void 0,void 0,(function(){var n,s;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 ne(e,r)).generateGLTFAsync(t.replace(/\.[^/.]+$/,""))];case 3:return s=i.sent(),n.dispose(),[2,s]}}))}))},e.GLBAsync=function(e,t,r){return m(this,void 0,void 0,(function(){var n,s;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 ne(e,r)).generateGLBAsync(t.replace(/\.[^/.]+$/,""))];case 3:return s=i.sent(),n.dispose(),[2,s]}}))}))},e}(),ie="EXT_mesh_gpu_instancing",oe=function(){function e(e){this.name=ie,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportNodeAsync=function(e,t,r,n,s,i){return m(this,void 0,void 0,(function(){var e=this;return x(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){if(t&&r instanceof d.Mesh&&r.hasThinInstances&&e._exporter){e._wasUsed=!0;for(var o=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,_=!1,g=!1,m=new Float32Array(3*r.thinInstanceCount),x=new Float32Array(4*r.thinInstanceCount),y=new Float32Array(3*r.thinInstanceCount),T=0,v=0,b=c;v<b.length;v++)b[v].decompose(h,f,l),s&&(G(l),K(f)),m.set(l.asArray(),3*T),x.set(f.normalize().asArray(),4*T),y.set(h.asArray(),3*T),p=p||!l.equalsWithEpsilon(o),_=_||!f.equalsWithEpsilon(a),g=g||!h.equalsWithEpsilon(u),T++;var E={attributes:{}};p&&(E.attributes.TRANSLATION=e._buildAccessor(m,"VEC3",r.thinInstanceCount,i)),_&&(E.attributes.ROTATION=e._buildAccessor(x,"VEC4",r.thinInstanceCount,i)),g&&(E.attributes.SCALE=e._buildAccessor(y,"VEC3",r.thinInstanceCount,i)),t.extensions=t.extensions||{},t.extensions[ie]=E}n(t)}))];case 1:return[2,n.sent()]}}))}))},e.prototype._buildAccessor=function(e,t,r,n){var s=n.createBufferView(e),i=n.createAccessor(s,t,5126,r);return this._exporter._accessors.push(i),this._exporter._accessors.length-1},e}();ne.RegisterExtension(ie,(function(e){return new oe(e)}));var ae="KHR_draco_mesh_compression",ue=function(){function e(e){this.name=ae,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 s=[],i=[],o=null;if(void 0!==e.indices){var a=r[e.indices],u=t.getBufferView(a);o=t.getData(u).slice(),s.push(u),i.push(a)}for(var c,l=[],f=0,h=Object.entries(e.attributes);f<h.length;f++){var p=h[f],_=p[0],g=(a=r[p[1]],u=t.getBufferView(a),N(a.type)),m=(0,d.GetTypedArrayData)(t.getData(u),g,a.componentType,a.byteOffset||0,u.byteStride||(0,d.GetTypeByteLength)(a.componentType)*g,a.normalized||!1,a.count,!0);l.push({kind:_,dracoName:(c=_,"POSITION"===c?"POSITION":"NORMAL"===c?"NORMAL":c.startsWith("COLOR")?"COLOR":c.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"),size:N(a.type),data:m}),s.push(u),i.push(a)}var x={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},y=d.DracoEncoder.Default._encodeAsync(l,o,x).then((function(r){if(r){var o={bufferView:-1,attributes:r.attributeIds},a=t.createBufferView(r.data);t.setBufferView(o,a);for(var u=0,c=s;u<c.length;u++){var l=c[u];n._bufferViewsUsed.add(l)}for(var f=0,h=i;f<h.length;f++){var p=h[f];n._accessorsUsed.add(p)}e.extensions||(e.extensions={}),e.extensions[ae]=o}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 m(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}();ne.RegisterExtension(ae,(function(e){return new ue(e)}));var ce="KHR_lights_punctual",le={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},fe={innerConeAngle:0,outerConeAngle:Math.PI/4},he=d.Vector3.Backward(),pe=function(){function e(e){this.name=ce,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[ce]=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,n,s){return m(this,void 0,void 0,(function(){var i=this;return x(this,(function(o){switch(o.label){case 0:return[4,new Promise((function(o){if(r instanceof d.Light){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&&r instanceof d.ShadowLight))return d.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(ce)),void o(t);if(r.falloffType!==d.Light.FALLOFF_GLTF&&d.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(ce," specification!")),!r.position.equalsToFloats(0,0,0)){var u=d.TmpVectors.Vector3[0].copyFrom(r.position);s&&G(u),t.translation=u.asArray()}if("point"!==a){var c=r.direction.normalizeToRef(d.TmpVectors.Vector3[0]);s&&G(c);var l=d.Quaternion.FromUnitVectorsToRef(he,c,d.TmpVectors.Quaternion[0]);d.Quaternion.IsIdentity(l)||(t.rotation=l.asArray())}var f={type:a,name:r.name,color:r.diffuse.asArray(),intensity:r.intensity,range:r.range};if(j(f,le),"spot"===a){var h=r;f.spot={innerConeAngle:h.innerAngle/2,outerConeAngle:h.angle/2},j(f.spot,fe)}i._lights||(i._lights={lights:[]}),i._lights.lights.push(f);var p={light:i._lights.lights.length-1},_=r.parent;if(_&&W(r,_)){var g=n.get(_);if(g){var m=i._exporter._nodes[g];return H(t,m),m.extensions||(m.extensions={}),m.extensions[ce]=p,void o(null)}}t.extensions||(t.extensions={}),t.extensions[ce]=p,o(t)}else o(t)}))];case 1:return[2,o.sent()]}}))}))},e}();ne.RegisterExtension(ce,(function(e){return new pe(e)}));var de="KHR_materials_anisotropy",_e=function(){function e(e){this.name=de,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.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 s=n._exporter._materialExporter.getTextureInfo(r.anisotropy.texture),i={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=s?s:void 0};null!==i.anisotropyTexture&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[de]=i}e(t)}))},e}();ne.RegisterExtension(de,(function(e){return new _e(e)}));var ge="KHR_materials_clearcoat",me=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=[];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 s,i=n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);s=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 o=n._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture),a={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=i?i:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=s?s:void 0,clearcoatNormalTexture:null!=o?o:void 0};null===a.clearcoatTexture&&null===a.clearcoatRoughnessTexture&&null===a.clearcoatRoughnessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[ge]=a}e(t)}))},e}();ne.RegisterExtension(ge,(function(e){return new me(e)}));var xe="KHR_materials_diffuse_transmission";function ye(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 Te=function(){function e(e){this.name=xe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];if(r instanceof d.PBRMaterial&&this._isExtensionEnabled(r)){var s=ye(e,r);return s&&n.push(s),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(s){var i,o;if(r instanceof d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var a=r.subSurface,u=ye(e,r),c=0==a.translucencyIntensity?void 0:a.translucencyIntensity,l=null!==(i=n._exporter._materialExporter.getTextureInfo(u))&&void 0!==i?i:void 0,f=!a.translucencyColor||a.translucencyColor.equalsFloats(1,1,1)?void 0:a.translucencyColor.asArray(),h=null!==(o=n._exporter._materialExporter.getTextureInfo(a.translucencyColorTexture))&&void 0!==o?o:void 0,p={diffuseTransmissionFactor:c,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:f,diffuseTransmissionColorTexture:h};(l||h)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions=t.extensions||{},t.extensions[xe]=p}s(t)}))},e}();ne.RegisterExtension(xe,(function(e){return new Te(e)}));var ve="KHR_materials_dispersion",be=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 s={dispersion:r.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[ve]=s}e(t)}))},e}();ne.RegisterExtension(ve,(function(){return new be}));var Ee="KHR_materials_emissive_strength",Ae=function(){function e(){this.name=Ee,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,t,r){return m(this,void 0,void 0,(function(){var e=this;return x(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){if(!(r instanceof d.PBRMaterial))return n(t);var s=r.emissiveColor.asArray(),i=Math.max.apply(Math,s);if(i>1){e._wasUsed=!0,t.extensions||(t.extensions={});var o={emissiveStrength:i},a=r.emissiveColor.scale(1/o.emissiveStrength);t.emissiveFactor=a.asArray(),t.extensions[Ee]=o}return n(t)}))];case 1:return[2,n.sent()]}}))}))},e}();ne.RegisterExtension(Ee,(function(e){return new Ae}));var we="KHR_materials_ior",Me=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 s={ior:r.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[we]=s}e(t)}))},e}();ne.RegisterExtension(we,(function(e){return new Me}));var Re="KHR_materials_iridescence",Ce=function(){function e(e){this.name=Re,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.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 s=n._exporter._materialExporter.getTextureInfo(r.iridescence.texture),i=n._exporter._materialExporter.getTextureInfo(r.iridescence.thicknessTexture),o={iridescenceFactor:r.iridescence.intensity,iridescenceIor:r.iridescence.indexOfRefraction,iridescenceThicknessMinimum:r.iridescence.minimumThickness,iridescenceThicknessMaximum:r.iridescence.maximumThickness,iridescenceTexture:null!=s?s:void 0,iridescenceThicknessTexture:null!=i?i:void 0};null===o.iridescenceTexture&&null===o.iridescenceThicknessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Re]=o}e(t)}))},e}();ne.RegisterExtension(Re,(function(e){return new Ce(e)}));var Se="KHR_materials_sheen",Ve=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){return r instanceof d.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[r.sheen.texture]:[]},e.prototype.postExportMaterialAsync=function(e,t,r){return m(this,void 0,void 0,(function(){var e=this;return x(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){var s,i,o,a;if(r instanceof d.PBRMaterial){if(!r.sheen.isEnabled)return void n(t);e._wasUsed=!0,null==t.extensions&&(t.extensions={});var u={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(s=r.sheen.roughness)&&void 0!==s?s:0};null===u.sheenColorTexture&&null===u.sheenRoughnessTexture||e._exporter._materialNeedsUVsSet.add(r),r.sheen.texture&&(u.sheenColorTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==i?i:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(o=e._exporter._materialExporter.getTextureInfo(r.sheen.textureRoughness))&&void 0!==o?o:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==a?a:void 0),t.extensions[Se]=u}n(t)}))];case 1:return[2,n.sent()]}}))}))},e}();ne.RegisterExtension(Se,(function(e){return new Ve(e)}));var Be="KHR_materials_specular",Fe=function(){function e(e){this.name=Be,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 s,i;if(r instanceof d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0,t.extensions=t.extensions||{};var o=null!==(s=n._exporter._materialExporter.getTextureInfo(r.metallicReflectanceTexture))&&void 0!==s?s: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:o,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:a};n._hasTexturesExtension(r)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[Be]=u}e(t)}))},e}();ne.RegisterExtension(Be,(function(e){return new Fe(e)}));var Ie="KHR_materials_transmission",Oe=function(){function e(e){this.name=Ie,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 m(this,void 0,void 0,(function(){var n,s,i,o;return x(this,(function(a){switch(a.label){case 0:return r instanceof d.PBRMaterial&&this._isExtensionEnabled(r)?(this._wasUsed=!0,n=r.subSurface,s=0===n.refractionIntensity?void 0:n.refractionIntensity,i={transmissionFactor:s},this._hasTexturesExtension(r)&&this._exporter._materialNeedsUVsSet.add(r),n.refractionIntensityTexture?n.useGltfStyleTextures?[4,this._exporter._materialExporter.exportTextureAsync(n.refractionIntensityTexture,"image/png")]:[3,2]:[3,3]):[3,4];case 1:return(o=a.sent())&&(i.transmissionTexture=o),[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[Ie]=i,a.label=4;case 4:return[2,t]}}))}))},e}();ne.RegisterExtension(Ie,(function(e){return new Oe(e)}));var Pe="KHR_materials_unlit",Ne=function(){function e(){this.name=Pe,this.enabled=!0,this.required=!1,this._wasUsed=!1}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var s=!1;r instanceof d.PBRMaterial?s=r.unlit:r instanceof d.StandardMaterial&&(s=r.disableLighting),s&&(n._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[Pe]={}),e(t)}))},e}();ne.RegisterExtension(Pe,(function(){return new Ne}));var Ue="KHR_materials_volume",Le=function(){function e(e){this.name=Ue,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 s;if(r instanceof d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var i=r.subSurface,o={thicknessFactor:0==i.maximumThickness?void 0:i.maximumThickness,thicknessTexture:null!==(s=n._exporter._materialExporter.getTextureInfo(i.thicknessTexture))&&void 0!==s?s:void 0,attenuationDistance:i.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:i.tintColorAtDistance,attenuationColor:i.tintColor.equalsFloats(1,1,1)?void 0:i.tintColor.asArray()};n._hasTexturesExtension(r)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions=t.extensions||{},t.extensions[Ue]=o}e(t)}))},e}();ne.RegisterExtension(Ue,(function(e){return new Le(e)}));var De="EXT_materials_diffuse_roughness",Ge=function(){function e(e){this.name=De,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof d.PBRBaseMaterial&&r._baseDiffuseRoughness?(r._baseDiffuseRoughnessTexture&&n.push(r._baseDiffuseRoughnessTexture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof d.PBRBaseMaterial){if(!r._baseDiffuseRoughness)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var s=n._exporter._materialExporter.getTextureInfo(r._baseDiffuseRoughnessTexture),i={diffuseRoughnessFactor:r._baseDiffuseRoughness,diffuseRoughnessTexture:null!=s?s:void 0};null!==i.diffuseRoughnessTexture&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[De]=i}e(t)}))},e}();ne.RegisterExtension(De,(function(e){return new Ge(e)}));var Ke="KHR_texture_transform",ke=function(){function e(){this.name=Ke,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={},s=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],s=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],s=!0),0!==r.wAng){if(0!==r.uRotationCenter||0!==r.vRotationCenter){if(r.homogeneousRotationInUVTransform&&r.uScale!==r.vScale)return void d.Tools.Warn("".concat(e,": Texture ").concat(r.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(Ke,"."));d.Tools.Warn("".concat(e,": Texture ").concat(r.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(Ke,".")),n.offset=function(e){var t=e.uOffset,r=e.vOffset,n=e.uRotationCenter,s=e.vRotationCenter,i=e.uScale,o=e.vScale,a=e.wAng,u=Math.cos(a),c=Math.sin(a),l=n*i,f=s*o;return[t+(l*(1-u)+f*c),r+(f*(1-u)-l*c)]}(r)}n.rotation=-r.wAng,s=!0}0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,s=!0),s&&(this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[Ke]=n)}},e}();ne.RegisterExtension(Ke,(function(){return new ke}));var He=void 0!==i.g?i.g:"undefined"!=typeof window?window:void 0;if(void 0!==He){He.BABYLON=He.BABYLON||{};var We=He.BABYLON;We.GLTF2=We.GLTF2||{},We.GLTF2.Exporter=We.GLTF2.Exporter||{},We.GLTF2.Exporter.Extensions=We.GLTF2.Exporter.Extensions||{};var je=[];for(var ze in a)We[ze]=a[ze],je.push(ze);for(var ze in u)We[ze]=u[ze],je.push(ze);for(var ze in c)We[ze]=c[ze],je.push(ze);for(var ze in l)We.GLTF2.Exporter.Extensions[ze]=l[ze],je.push(ze);for(var ze in f)je.indexOf(ze)>-1||(We.GLTF2.Exporter[ze]=f[ze])}const qe=h;return o.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}},s={};function i(e){var t=s[e];if(void 0!==t)return t.exports;var r=s[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 s=Object.create(null);i.r(s);var o={};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=>o[t]=()=>e[t]));return o.default=()=>e,i.d(s,o),s},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 o={};i.d(o,{default:()=>qe});var a={};i.r(a),i.d(a,{__IGLTFExporterExtension:()=>p});var u={};i.r(u),i.d(u,{GLTFData:()=>_});var c={};i.r(c),i.d(c,{GLTF2Export:()=>se});var l={};i.r(l),i.d(l,{EXT_materials_diffuse_roughness:()=>Ge,EXT_mesh_gpu_instancing:()=>oe,KHR_draco_mesh_compression:()=>ue,KHR_lights_punctual:()=>pe,KHR_materials_anisotropy:()=>_e,KHR_materials_clearcoat:()=>me,KHR_materials_diffuse_transmission:()=>Te,KHR_materials_dispersion:()=>be,KHR_materials_emissive_strength:()=>Ae,KHR_materials_ior:()=>Me,KHR_materials_iridescence:()=>Ce,KHR_materials_sheen:()=>Ve,KHR_materials_specular:()=>Fe,KHR_materials_transmission:()=>Oe,KHR_materials_unlit:()=>Ne,KHR_materials_volume:()=>Le,KHR_texture_transform:()=>ke});var f={};i.r(f),i.d(f,{EXT_materials_diffuse_roughness:()=>Ge,EXT_mesh_gpu_instancing:()=>oe,GLTF2Export:()=>se,GLTFData:()=>_,KHR_draco_mesh_compression:()=>ue,KHR_lights_punctual:()=>pe,KHR_materials_anisotropy:()=>_e,KHR_materials_clearcoat:()=>me,KHR_materials_diffuse_transmission:()=>Te,KHR_materials_dispersion:()=>be,KHR_materials_emissive_strength:()=>Ae,KHR_materials_ior:()=>Me,KHR_materials_iridescence:()=>Ce,KHR_materials_sheen:()=>Ve,KHR_materials_specular:()=>Fe,KHR_materials_transmission:()=>Oe,KHR_materials_unlit:()=>Ne,KHR_materials_volume:()=>Le,KHR_texture_transform:()=>ke,_ConvertToGLTFPBRMetallicRoughness:()=>M,_SolveMetallic:()=>w});var h={};i.r(h),i.d(h,{EXT_materials_diffuse_roughness:()=>Ge,EXT_mesh_gpu_instancing:()=>oe,GLTF2Export:()=>se,GLTFData:()=>_,KHR_draco_mesh_compression:()=>ue,KHR_lights_punctual:()=>pe,KHR_materials_anisotropy:()=>_e,KHR_materials_clearcoat:()=>me,KHR_materials_diffuse_transmission:()=>Te,KHR_materials_dispersion:()=>be,KHR_materials_emissive_strength:()=>Ae,KHR_materials_ior:()=>Me,KHR_materials_iridescence:()=>Ce,KHR_materials_sheen:()=>Ve,KHR_materials_specular:()=>Fe,KHR_materials_transmission:()=>Oe,KHR_materials_unlit:()=>Ne,KHR_materials_volume:()=>Le,KHR_texture_transform:()=>ke,_ConvertToGLTFPBRMetallicRoughness:()=>M,_SolveMetallic:()=>w,__IGLTFExporterExtension:()=>p});var p=0,d=i(597),_=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}(),g=function(){return g=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var s in t=arguments[r])Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s]);return e},g.apply(this,arguments)};function m(e,t,r,n){return new(r||(r=Promise))((function(s,i){function o(e){try{u(n.next(e))}catch(e){i(e)}}function a(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,a)}u((n=n.apply(e,t||[])).next())}))}function x(e,t){var r,n,s,i={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(i=0)),i;)try{if(r=1,n&&(s=2&a[0]?n.return:a[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,a[1])).done)return s;switch(n=0,s&&(a=[2&a[0],s.value]),a[0]){case 0:case 1:s=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((s=(s=i.trys).length>0&&s[s.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!s||a[1]>s[0]&&a[1]<s[3])){i.label=a[1];break}if(6===a[0]&&i.label<s[1]){i.label=s[1],s=a;break}if(s&&i.label<s[2]){i.label=s[2],i.ops.push(a);break}s[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],n=0}finally{r=s=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function y(e,t,r){if(r||2===arguments.length)for(var n,s=0,i=t.length;s<i;s++)!n&&s in t||(n||(n=Array.prototype.slice.call(t,0,s)),n[s]=t[s]);return e.concat(n||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var T=1e-6,v=new d.Color3(.04,.04,.04),b=1024,E=d.Color3.White(),A=d.Color3.Black();function w(e,t,r){if(t<v.r)return 0;var n=v.r,s=e*r/(1-v.r)+t-2*v.r,i=s*s-4*n*(v.r-t);return d.Scalar.Clamp((-s+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),s=(0,d.SpecularPowerToRoughness)(n);return{baseColorFactor:[t.r,t.g,t.b,r],metallicFactor:0,roughnessFactor:s}}function R(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function C(e,t,r){for(var n=new Uint8Array(e*t*4),s=0;s<n.length;s+=4)n[s]=n[s+1]=n[s+2]=n[s+3]=255;return d.RawTexture.CreateRGBATexture(n,e,t,r)}function S(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 V=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 m(this,void 0,void 0,(function(){var n,s,i,o,a,u,c,l;return x(this,(function(f){switch(f.label){case 0:return n=M(e),s={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."),s.doubleSided=!0),r?(i=[],(o=e.diffuseTexture)&&i.push(this.exportTextureAsync(o,t).then((function(e){e&&(n.baseColorTexture=e)}))),(a=e.bumpTexture)&&i.push(this.exportTextureAsync(a,t).then((function(e){e&&(s.normalTexture=e,1!==a.level&&(s.normalTexture.scale=a.level))}))),(u=e.emissiveTexture)&&(s.emissiveFactor=[1,1,1],i.push(this.exportTextureAsync(u,t).then((function(e){e&&(s.emissiveTexture=e)})))),(c=e.ambientTexture)&&i.push(this.exportTextureAsync(c,t).then((function(e){if(e){var t={index:e.index};s.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?s.alphaMode="BLEND":d.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(A,T)&&(s.emissiveFactor=e.emissiveColor.asArray()),s.pbrMetallicRoughness=n,R(s,e),[4,this._finishMaterialAsync(s,e,t)];case 3:return f.sent(),(l=this._exporter._materials).push(s),[2,l.length-1]}}))}))},e.prototype._finishMaterialAsync=function(e,t,r){return m(this,void 0,void 0,(function(){var n,s,i,o,a;return x(this,(function(u){switch(u.label){case 0:for(n=this._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",e,t),s=[],i=0,o=n;i<o.length;i++)a=o[i],s.push(this.exportTextureAsync(a,r));return[4,Promise.all(s)];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 m(this,void 0,void 0,(function(){var s,o,a,u,c;return x(this,(function(l){switch(l.label){case 0:return s=d.Constants.TEXTURETYPE_UNSIGNED_BYTE,o=this._exporter._babylonScene,a=o.getEngine(),u=a.createRawTexture(e,t,r,d.Constants.TEXTUREFORMAT_RGBA,!1,!0,d.Texture.NEAREST_SAMPLINGMODE,null,s),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,o,s,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,s,i=e?e.getSize():{width:0,height:0},o=t?t.getSize():{width:0,height:0};return i.width<o.width?(n=e&&e instanceof d.Texture?d.TextureTools.CreateResizedCopy(e,o.width,o.height,!0):C(o.width,o.height,r),s=t):i.width>o.width?(s=t&&t instanceof d.Texture?d.TextureTools.CreateResizedCopy(t,i.width,i.height,!0):C(i.width,i.height,r),n=e):(n=e,s=t),{texture1:n,texture2:s}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,r,n){return m(this,void 0,void 0,(function(){var s,i,o,a,u,c,l,f,h,p,_,g,m,y,v,b,w,M,R,C,V,B,F,I,O,P,N,U,L,D,G;return x(this,(function(x){switch(x.label){case 0:return s=new Array,e||t?[3,2]:[4,Promise.reject("diffuse and specular glossiness textures are not defined!")];case 1:case 6:case 9:case 11:case 13:return[2,x.sent()];case 2:return(i=e?e.getScene():t?t.getScene():null)?(o=this._resizeTexturesToSameDimensions(e,t,i),a=null===(G=o.texture1)||void 0===G?void 0:G.getSize(),u=void 0,c=void 0,l=a.width,f=a.height,[4,o.texture1.readPixels()]):[3,12];case 3:return h=x.sent(),[4,o.texture2.readPixels()];case 4:return p=x.sent(),h?(u=S(h),[3,7]):[3,5];case 5:return[4,Promise.reject("Failed to retrieve pixels from diffuse texture!")];case 7:return p?(c=S(p),[3,10]):[3,8];case 8:return[4,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];case 10:for(_=c.byteLength,g=new Uint8Array(_),m=new Uint8Array(_),y=A,v=0,b=0,P=0;P<f;++P)for(N=0;N<l;++N)w=4*(l*P+N),M=new d.Color3(u[w],u[w+1],u[w+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(r.diffuseColor),R=new d.Color3(c[w],c[w+1],c[w+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(r.specularColor),C=c[w+3]*r.glossiness,V={diffuseColor:M,specularColor:R,glossiness:C},B=this._convertSpecularGlossinessToMetallicRoughness(V),y.r=Math.max(y.r,B.baseColor.r),y.g=Math.max(y.g,B.baseColor.g),y.b=Math.max(y.b,B.baseColor.b),v=Math.max(v,B.metallic),b=Math.max(b,B.roughness),m[w]=255*B.baseColor.r,m[w+1]=255*B.baseColor.g,m[w+2]=255*B.baseColor.b,m[w+3]=o.texture1.hasAlpha?255*u[w+3]:255,g[w]=0,g[w+1]=255*B.roughness,g[w+2]=255*B.metallic,g[w+3]=255;for(F={baseColor:y,metallic:v,roughness:b},I=!1,O=!1,P=0;P<f;++P)for(N=0;N<l;++N)m[U=4*(l*P+N)]/=F.baseColor.r>T?F.baseColor.r:1,m[U+1]/=F.baseColor.g>T?F.baseColor.g:1,m[U+2]/=F.baseColor.b>T?F.baseColor.b:1,L=d.Color3.FromInts(m[U],m[U+1],m[U+2]),D=L.toGammaSpace(i.getEngine().useExactSrgbConversions),m[U]=255*D.r,m[U+1]=255*D.g,m[U+2]=255*D.b,D.equalsWithEpsilon(E,T)||(O=!0),g[U+1]/=F.roughness>T?F.roughness:1,g[U+2]/=F.metallic>T?F.metallic:1,d.Color3.FromInts(255,g[U+1],g[U+2]).equalsWithEpsilon(E,T)||(I=!0);return I&&s.push(this._getImageDataAsync(g,l,f,n).then((function(e){F.metallicRoughnessTextureData=e}))),O&&s.push(this._getImageDataAsync(m,l,f,n).then((function(e){F.baseColorTextureData=e}))),[4,Promise.all(s).then((function(){return F}))];case 12:return[4,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}}))}))},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var t=this._getPerceivedBrightness(e.diffuseColor),r=this._getPerceivedBrightness(e.specularColor),n=1-this._getMaxComponent(e.specularColor),s=w(t,r,n),i=e.diffuseColor.scale(n/(1-v.r)/Math.max(1-s)),o=e.specularColor.subtract(v.scale(1-s)).scale(1/Math.max(s)),a=d.Color3.Lerp(i,o,s*s);return{baseColor:a=a.clampToRef(0,1,a),metallic:s,roughness:1-e.glossiness}},e.prototype._getPerceivedBrightness=function(e){return 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 m(this,void 0,void 0,(function(){var s,i,o;return x(this,(function(a){switch(a.label){case 0:return s=[],i={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness},n&&(e._albedoTexture&&s.push(this.exportTextureAsync(e._albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)}))),(o=e._metallicTexture)&&s.push(this.exportTextureAsync(o,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))),s.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(s)]):[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 m(this,void 0,void 0,(function(){var s,i,o,a,u,c,l,f;return x(this,(function(h){switch(h.label){case 0:return s={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},i=e._albedoTexture,o=e._reflectivityTexture,a=e._useMicroSurfaceFromReflectivityMapAlpha,!o||a?[3,2]:[4,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")];case 1:return[2,h.sent()];case 2:return(i||o)&&n?(this._exporter._materialNeedsUVsSet.add(e),u=this._exportTextureSampler(i||o),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(i,o,s,t)]):[3,4];case 3: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==o?void 0:o.coordinatesIndex)),[2,c];case 4:return[2,this._convertSpecularGlossinessToMetallicRoughness(s)]}}))}))},e.prototype.exportPBRMaterialAsync=function(e,t,r){return m(this,void 0,void 0,(function(){var n,s,i,o,a,u,c,l;return x(this,(function(f){switch(f.label){case 0:return n={},s={name:e.name},(i=e.isMetallicWorkflow())&&(o=e._albedoColor,a=e.alpha,o&&(n.baseColorFactor=[o.r,o.g,o.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,s,n,t,r)];case 5:return f.sent(),[4,this._finishMaterialAsync(s,e,t)];case 6:return f.sent(),(l=this._exporter._materials).push(s),[2,l.length-1]}}))}))},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,t,r,n,s,i){return m(this,void 0,void 0,(function(){var o,a,u,c,l;return x(this,(function(f){switch(f.label){case 0:return R(r,t),e.baseColor.equalsWithEpsilon(E,T)&&d.Scalar.WithinEpsilon(t.alpha,1,T)||(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?(o=[],(a=t._bumpTexture)&&o.push(this.exportTextureAsync(a,s).then((function(e){e&&(r.normalTexture=e,1!==a.level&&(r.normalTexture.scale=a.level))}))),(u=t._ambientTexture)&&o.push(this.exportTextureAsync(u,s).then((function(e){if(e){var n={index:e.index,texCoord:e.texCoord,extensions:e.extensions};r.occlusionTexture=n;var s=t._ambientTextureStrength;s&&(n.strength=s)}}))),(c=t._emissiveTexture)&&o.push(this.exportTextureAsync(c,s).then((function(e){e&&(r.emissiveTexture=e)}))),o.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(o)]):[3,2]):[3,2];case 1:f.sent(),f.label=2;case 2:return(l=t._emissiveColor).equalsWithEpsilon(A,T)||(r.emissiveFactor=l.asArray()),r.pbrMetallicRoughness=n,[2]}}))}))},e.prototype._getPixelsFromTextureAsync=function(e){return function(e){switch(e){case d.Constants.TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM:case d.Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT5:case d.Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT3:case d.Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT1:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGB_S3TC_DXT1:case d.Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:case d.Constants.TEXTUREFORMAT_COMPRESSED_SRGB_S3TC_DXT1_EXT:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGBA_ASTC_4x4:case d.Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGB_ETC1_WEBGL:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGB8_ETC2:case d.Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_ETC2:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:case d.Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:case d.Constants.TEXTUREFORMAT_COMPRESSED_RGBA8_ETC2_EAC:case d.Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:return!0;default:return!1}}(e.textureFormat)?(0,d.GetTextureDataAsync)(e,e._texture.width,e._texture.height):(e.textureType,d.Constants.TEXTURETYPE_UNSIGNED_BYTE,e.readPixels())},e.prototype.exportTextureAsync=function(e,t){return m(this,void 0,void 0,(function(){var r,n=this;return x(this,(function(s){switch(s.label){case 0:return(r=this._exporter._extensionsPreExportTextureAsync("exporter",e,t))?[3,2]:[4,this._exportTextureInfoAsync(e,t)];case 1:case 3:return[2,s.sent()];case 2:return[4,r.then((function(r){return m(n,void 0,void 0,(function(){return x(this,(function(n){switch(n.label){case 0:return r?[3,2]:[4,this._exportTextureInfoAsync(e,t)];case 1:case 3:return[2,n.sent()];case 2:return[4,this._exportTextureInfoAsync(r,t)]}}))}))}))]}}))}))},e.prototype._exportTextureInfoAsync=function(e,t){return m(this,void 0,void 0,(function(){var r,n,s,i,o,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._getPixelsFromTextureAsync(e)];case 1:if(!(n=h.sent()))return[2,null];if(s=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,". Exporting texture as PNG."))}return o=this._internalTextureToImage,a=e.getInternalTexture().uniqueId,o[a]||(o[a]={}),void 0===(u=o[a][t])&&(c=e.getSize(),u=m(f,void 0,void 0,(function(){var r;return x(this,(function(s){switch(s.label){case 0:return[4,this._getImageDataAsync(n,c.width,c.height,t)];case 1:return r=s.sent(),[2,this._exportImage(e.name,t,r)]}}))})),o[a][t]=u),l=this._exportTextureInfo,[4,u];case 2:r=l.apply(this,[h.sent(),s,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,s=this._exporter._images;if(this._exporter._shouldUseGlb){n={name:e,mimeType:t,bufferView:void 0};var i=this._exporter._bufferManager.createBufferView(new Uint8Array(r));this._exporter._bufferManager.setBufferView(n,i)}else{var o=e.replace(/\.\/|\/|\.\\|\\/g,"_"),a=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp";case"image/avif":return".avif"}}(t),u=o+a;s.some((function(e){return e.uri===u}))&&(u="".concat(o,"_").concat(d.Tools.RandomId()).concat(a)),n={name:e,uri:u},this._exporter._imageData[u]={data:r,mimeType:t}}return s.push(n),s.length-1},e.prototype._exportTextureInfo=function(e,t,r){var n=this._exporter._textures,s=n.findIndex((function(r){return r.sampler==t&&r.source===e}));-1===s&&(s=n.length,n.push({source:e,sampler:t}));var i={index:s};return r&&(i.texCoord=r),i},e.prototype._exportTextureSampler=function(e){var t=this._getTextureSampler(e),r=this._exporter._samplers,n=r.findIndex((function(e){return e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT}));return-1!==n?n:(r.push(t),r.length-1)},e}(),B=d.Matrix.Compose(new d.Vector3(-1,1,1),d.Quaternion.Identity(),d.Vector3.Zero());function F(e,t){if(!(e instanceof d.TransformNode))return!1;if(t){if(!e.getWorldMatrix().equalsWithEpsilon(d.Matrix.IdentityReadOnly,d.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(B,d.TmpVectors.Matrix[0]).equalsWithEpsilon(d.Matrix.IdentityReadOnly,d.Epsilon))return!1;return!(e instanceof d.AbstractMesh&&e.geometry)}var I=d.Vector3.Zero(),O=d.Quaternion.Identity(),P=d.Vector3.One(),N=new d.Vector3(-1,1,1);function U(e,t){var r=e.byteOffset,n=e.byteStride,s=e.type,i=e.normalized,o=e.getSize(),a=t.reduce((function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e}),-Number.MAX_VALUE);return{byteOffset:r,byteStride:n,componentCount:o,type:s,count:a*o,normalized:i,totalVertices:a,kind:e.getKind()}}function L(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 D(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 G(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 k(e){return e.x*=-1,e}function H(e){if(e.x*e.x+e.y*e.y>.5){var t=Math.abs(e.x),r=Math.abs(e.y);if(t>r){var n=Math.sign(e.x);e.x=t,e.y*=-n,e.z*=-n,e.w*=n}else n=Math.sign(e.y),e.x*=-n,e.y=r,e.z*=n,e.w*=-n}else{var s=Math.abs(e.z),i=Math.abs(e.w);s>i?(n=Math.sign(e.z),e.x*=-n,e.y*=n,e.z=s,e.w*=-n):(n=Math.sign(e.w),e.x*=n,e.y*=-n,e.z*=-n,e.w=i)}return e}function W(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function j(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]),s=d.Matrix.ComposeToRef(P,n,r,d.TmpVectors.Matrix[0]),i=d.Vector3.FromArrayToRef(e.translation||[0,0,0],0,d.TmpVectors.Vector3[2]),o=d.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,d.TmpVectors.Quaternion[1]),a=d.Matrix.ComposeToRef(P,o,i,d.TmpVectors.Matrix[1]);s.multiplyToRef(a,a),a.decompose(void 0,n,r),r.equalsWithEpsilon(I,d.Epsilon)?delete t.translation:t.translation=r.asArray(),n.equalsWithEpsilon(O,d.Epsilon)?delete t.rotation:t.rotation=n.asArray(),t.scale&&delete t.scale}function z(e,t){if(!(t instanceof d.TransformNode))return!1;if(1!==t.getChildren().length||0!==e.getChildren().length||e.parent!==t)return!1;var r=e.getScene(),n=e instanceof d.TargetCamera&&!r.useRightHandedSystem?N:P;return!!t.scaling.equalsWithEpsilon(n,d.Epsilon)||(d.Logger.Warn("Cannot collapse node ".concat(e.name," into parent node ").concat(t.name," with modified scaling.")),!1)}function q(e,t){for(var r=0,n=Object.entries(e);r<n.length;r++){var s=n[r],i=s[0],o=s[1],a=t[i];(Array.isArray(o)&&Array.isArray(a)&&X(o,a)||o===a)&&delete e[i]}return e}function X(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 Z(e){return e%4==0?4:e%2==0?2:1}var 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,s=Array.from(this._bufferViewToData.keys()).sort((function(e,t){return Z(t.byteLength)-Z(e.byteLength)}));n<s.length;n++){var i=s[n];i.byteOffset=r.byteOffset,e.push(i);for(var o=e.length-1,a=0,u=this.getPropertiesWithBufferView(i);a<u.length;a++)u[a].bufferView=o;r.writeTypedArray(this._bufferViewToData.get(i)),this._bufferViewToData.delete(i)}return r.getOutputData()},e.prototype.createBufferView=function(e,t){var r={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(r,e),r},e.prototype.createAccessor=function(e,t,r,n,s,i,o){this._verifyBufferView(e);var a={bufferView:void 0,componentType:r,count:n,type:t,min:null==i?void 0:i.min,max:null==i?void 0:i.max,normalized:o,byteOffset:s};return this.setBufferView(a,e),this._accessorToBufferView.set(a,e),a},e.prototype.setBufferView=function(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)},e.prototype.removeBufferView=function(e){for(var t=this,r=0,n=this.getPropertiesWithBufferView(e);r<n.length;r++){var s=n[r];void 0!==s.bufferView&&delete s.bufferView}this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach((function(r,n){r===e&&(void 0!==n.byteOffset&&delete n.byteOffset,t._accessorToBufferView.delete(n))}))},e.prototype.getBufferView=function(e){var t=this._accessorToBufferView.get(e);return this._verifyBufferView(t),t},e.prototype.getPropertiesWithBufferView=function(e){var t;return this._verifyBufferView(e),this._bufferViewToProperties.set(e,null!==(t=this._bufferViewToProperties.get(e))&&void 0!==t?t:[]),this._bufferViewToProperties.get(e)},e.prototype.getData=function(e){return this._verifyBufferView(e),this._bufferViewToData.get(e)},e.prototype._verifyBufferView=function(e){if(void 0===e||!this._bufferViewToData.has(e))throw new Error("BufferView ".concat(e," not found in BufferManager."))},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(J||(J={}));var ee=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,s,i){if(this._IsTransformable(t)){var o=[],a=[],u=r.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,n,s),f=l.interpolationType,h=l.shouldBakeAnimation;if(h?e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,i,o,a,c,s):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(t,r,n,o,a,s):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(t,r,n,o,a,s):e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,i,o,a,c,s),o.length&&a.length)return{inputs:o,outputs:a,samplerInterpolation:f,inputsMin:h?c.min: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,s=e.targetProperty.split(".");switch(s[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":r="VEC4",t="rotation";break;case"rotationQuaternion":r="VEC4",n=!0,t="rotation";break;case"influence":r="SCALAR",t="weights";break;default:d.Tools.Error("Unsupported animatable property ".concat(s[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,s,i,o,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 _=d[p];if(!f||f(_)){var g=e._DeduceAnimationInfo(_);g&&(h={name:_.name,samplers:[],channels:[]},e._AddAnimation("".concat(_.name),_.hasRunningRuntimeAnimations?r:h,t,_,g.dataAccessorType,g.animationChannelTargetPath,s,o,a,u,g.useQuaternion,c,l),h.samplers.length&&h.channels.length&&n.push(h))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,s,i,o,a,u,c,l,f){var h;if(t instanceof d.Mesh){var p=t.morphTargetManager;if(p)for(var _=0;_<p.numTargets;++_)for(var g=0,m=p.getTarget(_).animations;g<m.length;g++){var x=m[g];if(!f||f(x)){for(var y=new d.Animation("".concat(x.name),"influence",x.framePerSecond,x.dataType,x.loopMode,x.enableBlending),T=[],v=x.getKeys(),b=0;b<v.length;++b)for(var E=v[b],A=0;A<p.numTargets;++A)A==_?T.push(E):T.push({frame:E.frame,value:0});y.setKeys(T);var w=e._DeduceAnimationInfo(y);w&&(h={name:y.name,samplers:[],channels:[]},e._AddAnimation(x.name,x.hasRunningRuntimeAnimations?r:h,t,y,w.dataAccessorType,w.animationChannelTargetPath,s,o,a,u,w.useQuaternion,c,l,p.numTargets),h.samplers.length&&h.channels.length&&n.push(h))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,s,i,o,a,u,c){var l,f;if(t.animationGroups)for(var h=t.animationGroups,p=function(h){var p=new Map,g=new Map,m=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,T=x.animation;if(c&&!c(T))return"continue";var v=u.has(y);if(_._IsTransformable(y)||1===y.length&&_._IsTransformable(y[0])){if(E=e._DeduceAnimationInfo(x.animation)){var b=_._IsTransformable(y)?y:_._IsTransformable(y[0])?y[0]:null;b&&e._AddAnimation("".concat(T.name),f,b,T,E.dataAccessorType,E.animationChannelTargetPath,n,s,i,o,E.useQuaternion,a,v)}}else if(y instanceof d.MorphTarget||1===y.length&&y[0]instanceof d.MorphTarget){var E;if(E=e._DeduceAnimationInfo(x.animation)){var A=y instanceof d.MorphTarget?y:y[0];if(A){var w=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===A)return!0;return!1}));if(w){var M=t.meshes.find((function(e){return e.morphTargetManager===w}));M&&(p.has(M)||p.set(M,new Map),null===(l=p.get(M))||void 0===l||l.set(A,T),m.add(M),g.set(M,T))}}}}},T=0;T<h.targetedAnimations.length;++T)y(T);m.forEach((function(t){for(var r=t.morphTargetManager,u=null,c=[],l=g.get(t).getKeys(),_=l.length,m=0;m<_;++m)for(var y=0;y<r.numTargets;++y){var T=r.getTarget(y),v=p.get(t);if(v){var b=v.get(T);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()[m])):c.push({frame:h.from+x/_*m,value:T.influence,inTangent:l[0].inTangent?0:void 0,outTangent:l[0].outTangent?0:void 0})}}u.setKeys(c);var E=e._DeduceAnimationInfo(u);E&&e._AddAnimation("".concat(h.name,"_").concat(t.name,"_MorphWeightAnimation"),f,t,u,E.dataAccessorType,E.animationChannelTargetPath,n,s,i,o,E.useQuaternion,a,!1,null==r?void 0:r.numTargets)})),f.channels.length&&f.samplers.length&&r.push(f)},_=this,g=0,m=h;g<m.length;g++)p(m[g])},e._AddAnimation=function(t,r,n,s,i,o,a,u,c,l,f,h,p,_){var g,m,x,y,T,v,b=e._CreateNodeAnimation(n,s,o,f,h);if(b){if(_){for(var E=0,A=0,w=[];b.inputs.length>0;)A=b.inputs.shift(),E%_==0&&w.push(A),E++;b.inputs=w}var M=a.get(n),R=new Float32Array(b.inputs);g=u.createBufferView(R),m=u.createAccessor(g,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(m),x=l.length-1;var C=new d.Quaternion,S=new d.Vector3,V=new d.Vector3,B=n instanceof d.Camera,F=L(i),I=new Float32Array(b.outputs.length*F);b.outputs.forEach((function(e,t){var r=e;switch(o){case"translation":p&&(d.Vector3.FromArrayToRef(e,0,V),k(V),V.toArray(r));break;case"rotation":4===e.length?d.Quaternion.FromArrayToRef(e,0,C):(r=new Array(4),d.Vector3.FromArrayToRef(e,0,S),d.Quaternion.FromEulerVectorToRef(S,C)),p&&(H(C),B&&W(C)),C.toArray(r)}I.set(r,t*F)})),g=u.createBufferView(I),m=u.createAccessor(g,i,5126,b.outputs.length),l.push(m),y=l.length-1,T={interpolation:b.samplerInterpolation,input:x,output:y},r.samplers.push(T),v={sampler:r.samplers.length-1,target:{node:M,path:o}},r.channels.push(v)}},e._CreateBakedAnimation=function(t,r,n,s,i,o,a,u,c,l,f){var h,p,_=d.Quaternion.Identity(),g=null,m=null,x=null,y=null,T=null,v=null;l.min=d.Tools.FloatRound(s/o);for(var b=r.getKeys(),E=0,A=b.length;E<A;++E){if(v=null,x=b[E],E+1<A)if(y=b[E+1],x.value.equals&&x.value.equals(y.value)||x.value===y.value){if(0!==E)continue;v=x.frame}else v=y.frame;else{if(T=b[E-1],x.value.equals&&x.value.equals(T.value)||x.value===T.value)continue;v=i}if(v)for(var w=x.frame;w<=v;w+=a)if((p=d.Tools.FloatRound(w/o))!==g){g=p,m=p;var M={key:0,repeatCount:0,loopMode:r.loopMode};h=r._interpolate(w,M),e._SetInterpolatedValue(t,h,p,r,n,_,u,c,f)}}m&&(l.max=m)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,s,i){var o=e._GetBasePositionRotationOrScale(r,s,i),a=n.targetProperty.split("."),u=a?a[1]:"",c=i?d.Quaternion.FromArray(o).normalize():d.Vector3.FromArray(o);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,s,i,o,a,u){var c;o.push(r),"weights"!==s?(n.dataType===d.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,s,u)),"rotation"===s?(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,s,i,o){for(var a=0,u=r.getKeys();a<u.length;a++){var c=u[a];s.push(c.frame/r.framePerSecond),e._AddKeyframeValue(c,r,i,n,t,o)}},e._CreateCubicSplineAnimation=function(t,r,n,s,i,o){r.getKeys().forEach((function(a){s.push(a.frame/r.framePerSecond),e._AddSplineTangent(J.INTANGENT,i,n,"CUBICSPLINE",a,o),e._AddKeyframeValue(a,r,i,n,t,o),e._AddSplineTangent(J.OUTTANGENT,i,n,"CUBICSPLINE",a,o)}))},e._GetBasePositionRotationOrScale=function(e,t,r){var n;if("rotation"===t)if(r){var s=e.rotationQuaternion;n=(null!=s?s:d.Quaternion.Identity()).asArray()}else{var i=e.rotation;n=(null!=i?i:d.Vector3.Zero()).asArray()}else if("translation"===t){var o=e.position;n=(null!=o?o: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,s,i){var o,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(o=this._ConvertFactorToVector3OrQuaternion(e.value,s,t,n,i)){if("rotation"===n){var l=i?o:d.Quaternion.RotationYawPitchRoll(o.y,o.x,o.z).normalize();r.push(l.asArray())}r.push(o.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,s,i=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var o=0,a=e.length;o<a;++o)if((s=e[o]).inTangent||s.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",i=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||s.interpolation&&1===s.interpolation&&"STEP"!==n){n="LINEAR",i=!0;break}}else n=s.interpolation&&1===s.interpolation?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,t,r,n,s,i){var o,a=e===J.INTANGENT?s.inTangent:s.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(a)if(i)o=a.asArray();else{var u=a;o=d.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else o=[0,0,0,0];else o="weights"===r?a?[a]:[0]:a?a.asArray():[0,0,0];t.push(o)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,r=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),r=Math.max(r,e.frame)})),{min:t,max:r}},e}();function te(e,t,r,n,s,i){var o={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."),o;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),_=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0];l=h.length/3;for(var m=0;m<l;++m){var x=d.Vector3.FromArray(h,3*m);d.Vector3.FromArray(f,3*m).subtractToRef(x,c),c.x*=u,_[0]=Math.min(_[0],c.x),g[0]=Math.max(g[0],c.x),_[1]=Math.min(_[1],c.y),g[1]=Math.max(g[1],c.y),_[2]=Math.min(_[2],c.z),g[2]=Math.max(g[2],c.z),p[3*m]=c.x,p[3*m+1]=c.y,p[3*m+2]=c.z}var y=r.createBufferView(p,12),T=r.createAccessor(y,"VEC3",5126,f.length/3,0,{min:_,max:g});s.push(T),o.attributes.POSITION=s.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(),b=a.getVerticesData(d.VertexBuffer.NormalKind);if(b){var E=new Float32Array(b.length);for(l=b.length/3,m=0;m<l;++m){var A=d.Vector3.FromArray(b,3*m).normalize();d.Vector3.FromArray(v,3*m).normalize().subtractToRef(A,c),E[3*m]=c.x*u,E[3*m+1]=c.y,E[3*m+2]=c.z}y=r.createBufferView(E,12),T=r.createAccessor(y,"VEC3",5126,v.length/3,0),s.push(T),o.attributes.NORMAL=s.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(),M=a.getVerticesData(d.VertexBuffer.TangentKind);if(M){l=M.length/4;var R=new Float32Array(3*l);for(m=0;m<l;++m){var C=d.Vector3.FromArray(M,4*m);K(C);var S=d.Vector3.FromArray(w,3*m);K(S),S.subtractToRef(C,c),R[3*m]=c.x*u,R[3*m+1]=c.y,R[3*m+2]=c.z}y=r.createBufferView(R,12),T=r.createAccessor(y,"VEC3",5126,l,0),s.push(T),o.attributes.TANGENT=s.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 V=e.getColors(),B=a.getVerticesData(d.VertexBuffer.ColorKind),F=a.getVertexBuffer(d.VertexBuffer.ColorKind);if(B&&F){var I=F.getSize();l=B.length/I;var O=new Float32Array(l*I);for(m=0;m<l;++m)if(3===I){var P=d.Vector3.FromArray(B,m*I);d.Vector3.FromArray(V,m*I).subtractToRef(P,c),O[3*m]=c.x,O[3*m+1]=c.y,O[3*m+2]=c.z}else if(4===I){var N=new d.Vector4;P=d.Vector4.FromArray(B,m*I),d.Vector4.FromArray(V,m*I).subtractToRef(P,N),O[4*m]=N.x,O[4*m+1]=N.y,O[4*m+2]=N.z,O[4*m+3]=N.w}else d.Tools.Warn("Unsupported number of components for color attribute: ".concat(I));y=r.createBufferView(O,4*I),T=r.createAccessor(y,3===I?"VEC3":"VEC4",5126,l,0),s.push(T),o.attributes.COLOR_0=s.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 o}var re=function(){function e(e,t){this._indicesAccessorMap=new Map,this._vertexBufferViewMap=new Map,this._vertexAccessorMap=new Map,this._remappedBufferView=new Map,this._meshMorphTargetMap=new Map,this._vertexMapColorAlpha=new Map,this._exportedNodes=new Set,this._meshMap=new Map,this.convertedToRightHandedBuffers=new Map,this.convertToRightHanded=e,this.wasAddedByNoopNode=t}return e.prototype.getIndicesAccessor=function(e,t,r,n,s){var i,o,a,u;return null===(u=null===(a=null===(o=null===(i=this._indicesAccessorMap.get(e))||void 0===i?void 0:i.get(t))||void 0===o?void 0:o.get(r))||void 0===a?void 0:a.get(n))||void 0===u?void 0:u.get(s)},e.prototype.setIndicesAccessor=function(e,t,r,n,s,i){var o=this._indicesAccessorMap.get(e);o||(o=new Map,this._indicesAccessorMap.set(e,o));var a=o.get(t);a||(a=new Map,o.set(t,a));var u=a.get(r);u||(u=new Map,a.set(r,u));var c=u.get(n);c||(c=new Map,u.set(n,c)),c.set(s,i)},e.prototype.pushExportedNode=function(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)},e.prototype.getNodesSet=function(){return this._exportedNodes},e.prototype.getVertexBufferView=function(e){return this._vertexBufferViewMap.get(e)},e.prototype.setVertexBufferView=function(e,t){this._vertexBufferViewMap.set(e,t)},e.prototype.setRemappedBufferView=function(e,t,r){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,r)},e.prototype.getRemappedBufferView=function(e,t){var r;return null===(r=this._remappedBufferView.get(e))||void 0===r?void 0:r.get(t)},e.prototype.getVertexAccessor=function(e,t,r){var n,s;return null===(s=null===(n=this._vertexAccessorMap.get(e))||void 0===n?void 0:n.get(t))||void 0===s?void 0:s.get(r)},e.prototype.setVertexAccessor=function(e,t,r,n){var s=this._vertexAccessorMap.get(e);s||(s=new Map,this._vertexAccessorMap.set(e,s));var i=s.get(t);i||(i=new Map,s.set(t,i)),i.set(r,n)},e.prototype.hasVertexColorAlpha=function(e){return this._vertexMapColorAlpha.get(e)||!1},e.prototype.setHasVertexColorAlpha=function(e,t){return this._vertexMapColorAlpha.set(e,t)},e.prototype.getMesh=function(e){return this._meshMap.get(e)},e.prototype.setMesh=function(e,t){this._meshMap.set(e,t)},e.prototype.bindMorphDataToMesh=function(e,t){var r=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,r),-1===r.indexOf(t)&&r.push(t)},e.prototype.getMorphTargetsFromMesh=function(e){return this._meshMorphTargetMap.get(e)},e}(),ne=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 V(this),this._extensions={},this._bufferManager=new $,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=g({shouldExportNode:function(){return!0},shouldExportAnimation:function(){return!0},metadataSelector:function(e){var t;return null===(t=null==e?void 0:e.gltf)||void 0===t?void 0:t.extras},animationSampleRate:1/60,exportWithoutWaitingForScene:!1,exportUnusedUVs:!1,removeNoopRootNodes:!0,includeCoordinateSystemConversionNodes:!1,meshCompressionMethod:"None"},t),this._loadExtensions()}return e.prototype._ApplyExtension=function(e,t,r,n){var s=this;if(r>=t.length)return Promise.resolve(e);var i=n(t[r],e);return i?i.then((function(e){return m(s,void 0,void 0,(function(){var s;return x(this,(function(i){switch(i.label){case 0:return e?[4,this._ApplyExtension(e,t,r+1,n)]:[3,2];case 1:return s=i.sent(),[3,3];case 2:s=null,i.label=3;case 3:return[2,s]}}))}))})):this._ApplyExtension(e,t,r+1,n)},e.prototype._ApplyExtensions=function(t,r){for(var n=[],s=0,i=e._ExtensionNames;s<i.length;s++){var o=i[s];n.push(this._extensions[o])}return this._ApplyExtension(t,n,0,r)},e.prototype._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,s){var i=this;return this._ApplyExtensions(t,(function(t,o){return t.postExportNodeAsync&&t.postExportNodeAsync(e,o,r,n,s,i._bufferManager)}))},e.prototype._extensionsPostExportMaterialAsync=function(e,t,r){return this._ApplyExtensions(t,(function(t,n){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,n,r)}))},e.prototype._extensionsPostExportMaterialAdditionalTextures=function(t,r,n){for(var s=[],i=0,o=e._ExtensionNames;i<o.length;i++){var a=o[i],u=this._extensions[a];u.postExportMaterialAdditionalTextures&&s.push.apply(s,u.postExportMaterialAdditionalTextures(t,r,n))}return s},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var s=0,i=e._ExtensionNames;s<i.length;s++){var o=i[s],a=this._extensions[o];a.postExportTexture&&a.postExportTexture(t,r,n)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var s=n[r],i=this._extensions[s];i.postExportMeshPrimitive&&i.postExportMeshPrimitive(t,this._bufferManager,this._accessors)}},e.prototype._extensionsPreGenerateBinaryAsync=function(){return m(this,void 0,void 0,(function(){var t,r,n,s;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],(s=this._extensions[n]).preGenerateBinaryAsync?[4,s.preGenerateBinaryAsync(this._bufferManager)]:[3,3]):[3,4];case 2:i.sent(),i.label=3;case 3:return t++,[3,1];case 4:return[2]}}))}))},e.prototype._forEachExtensions=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var s=n[r],i=this._extensions[s];i.enabled&&t(i)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){var r,n,s;t.wasUsed&&((r=e._glTF).extensionsUsed||(r.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&((n=e._glTF).extensionsRequired||(n.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),(s=e._glTF).extensions||(s.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],s=e._ExtensionFactories[n](this);this._extensions[n]=s}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e.RegisterExtension=function(t,r){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 m(this,void 0,void 0,(function(){var t,r,n,s,i,o,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"}),s=e+".gltf",i=e+".bin",(o=new _).files[s]=r,o.files[i]=n,this._imageData)for(a in this._imageData)o.files[a]=new Blob([this._imageData[a].data],{type:this._imageData[a].mimeType});return[2,o]}}))}))},e.prototype._generateBinaryAsync=function(){return m(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 m(this,void 0,void 0,(function(){var t,r,n,s,i,o,a,u,c,l,f,h,p,d;return x(this,(function(g){switch(g.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=g.sent(),this._extensionsOnExporting(),r=this._generateJSON(t.byteLength),n=e+".glb",s=r.length,"undefined"!=typeof TextEncoder&&(o=new TextEncoder,i=o.encode(r),s=i.length),a=this._getPadding(s),u=this._getPadding(t.byteLength),c=28+s+a+t.byteLength+u,(l=new Y(c)).writeUInt32(1179937895),l.writeUInt32(2),l.writeUInt32(c),l.writeUInt32(s+a),l.writeUInt32(1313821514),i)l.writeTypedArray(i);else for(f="_".charCodeAt(0),p=0;p<s;++p)(h=r.charCodeAt(p))!=r.codePointAt(p)?l.writeUInt8(f):l.writeUInt8(h);for(p=0;p<a;++p)l.writeUInt8(32);for(l.writeUInt32(t.byteLength+u),l.writeUInt32(5130562),l.writeTypedArray(t),p=0;p<u;++p)l.writeUInt8(0);return(d=new _).files[n]=new Blob([l.getOutputData()],{type:"application/octet-stream"}),[2,d]}}))}))},e.prototype._setNodeTransformation=function(e,t,r){var n;if(t.getPivotPoint().equalsWithEpsilon(I,d.Epsilon)||d.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsWithEpsilon(I,d.Epsilon)){var s=d.TmpVectors.Vector3[0].copyFrom(t.position);r&&k(s),e.translation=s.asArray()}t.scaling.equalsWithEpsilon(P,d.Epsilon)||(e.scale=t.scaling.asArray());var i=(null===(n=t.rotationQuaternion)||void 0===n?void 0:n.clone())||d.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);i.equalsWithEpsilon(O,d.Epsilon)||(r&&H(i),e.rotation=i.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,r){if(!t.position.equalsWithEpsilon(I,d.Epsilon)){var n=d.TmpVectors.Vector3[0].copyFrom(t.position);r&&k(n),e.translation=n.asArray()}var s=t.rotationQuaternion||d.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);r&&H(s),this._babylonScene.useRightHandedSystem||W(s),s.equalsWithEpsilon(O,d.Epsilon)||(e.rotation=s.asArray())},e.prototype._listAvailableCameras=function(){for(var e=0,t=this._babylonScene.cameras;e<t.length;e++){var r=t[e],n={type:r.mode===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 s=r.orthoLeft&&r.orthoRight?.5*(r.orthoRight-r.orthoLeft):.5*r.getEngine().getRenderWidth(),i=r.orthoBottom&&r.orthoTop?.5*(r.orthoTop-r.orthoBottom):.5*r.getEngine().getRenderHeight();n.orthographic={xmag:s,ymag:i,znear:r.minZ,zfar:r.maxZ}}this._camerasMap.set(r,n)}},e.prototype._exportAndAssignCameras=function(){for(var e=0,t=Array.from(this._camerasMap.values());e<t.length;e++){var r=t[e],n=this._nodesCameraMap.get(r);if(void 0!==n){this._cameras.push(r);for(var s=0,i=n;s<i.length;s++)i[s].camera=this._cameras.length-1}}},e.prototype._listAvailableSkeletons=function(){for(var e=0,t=this._babylonScene.skeletons;e<t.length;e++){var r=t[e];r.bones.length<=0||this._skinMap.set(r,{joints:[]})}},e.prototype._exportAndAssignSkeletons=function(e){for(var t,r=function(r){if(r.bones.length<=0)return"continue";var s=n._skinMap.get(r);if(null==s)return"continue";for(var i={},o=-1,a=0;a<r.bones.length;++a){var u=r.bones[a];-1!==(f=null!==(t=u.getIndex())&&void 0!==t?t:a)&&(i[f]=u,f>o&&(o=f))}for(var c,l=[],f=0;f<=o;++f){var h=(u=i[f]).getTransformNode(),p=h?n._nodeMap.get(h):void 0;if(void 0!==p){s.joints.push(p);var _=u.getAbsoluteInverseBindMatrix().clone();e.has(h)&&(c=_,B.invertToRef(d.TmpVectors.Matrix[0]).multiplyToRef(c,c).multiplyToRef(B,c)),l.push(_)}else d.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.")}var g=n._nodesSkinMap.get(s);if(s.joints.length>0&&void 0!==g){var m=new Float32Array(16*l.length);l.forEach((function(e,t){m.set(e.m,16*t)}));var x=n._bufferManager.createBufferView(m);n._accessors.push(n._bufferManager.createAccessor(x,"MAT4",5126,l.length)),s.inverseBindMatrices=n._accessors.length-1,n._skins.push(s);for(var y=n._skins.length-1,T=0,v=g;T<v.length;T++)v[T].skin=y}},n=this,s=0,i=this._babylonScene.skeletons;s<i.length;s++)r(i[s])},e.prototype._exportSceneAsync=function(){return m(this,void 0,void 0,(function(){var e,t,r,n,s,i,o,a,u,c,l,f,h,p,d,_,g,m,y,T,v,b,E;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,s=new Array,i=0,o=this._babylonScene.rootNodes;i<o.length;i++)a=o[i],this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&F(a,this._babylonScene.useRightHandedSystem)?s.push.apply(s,a.getChildren()):this._babylonScene.useRightHandedSystem?r.push(a):n.push(a);return this._listAvailableCameras(),this._listAvailableSkeletons(),u=new re(!0,!1),l=(c=(v=e.nodes).push).apply,f=[v],[4,this._exportNodesAsync(n,u)];case 1:return l.apply(c,f.concat([x.sent()])),h=new re(!1,!1),d=(p=(b=e.nodes).push).apply,_=[b],[4,this._exportNodesAsync(r,h)];case 2:return d.apply(p,_.concat([x.sent()])),g=new re(!1,!0),y=(m=(E=e.nodes).push).apply,T=[E],[4,this._exportNodesAsync(s,g)];case 3:return y.apply(m,T.concat([x.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(u.getNodesSet()),this._babylonScene.animationGroups.length&&ee._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 m(this,void 0,void 0,(function(){var r,n,s,i;return x(this,(function(o){switch(o.label){case 0:r=new Array,this._exportBuffers(e,t),n=0,s=e,o.label=1;case 1:return n<s.length?(i=s[n],[4,this._exportNodeAsync(i,r,t)]):[3,4];case 2:o.sent(),o.label=3;case 3:return n++,[3,1];case 4:return[2,r]}}))}))},e.prototype._collectBuffers=function(e,t,r,n,s){if(this._shouldExportNode(e)&&e instanceof d.AbstractMesh&&e.geometry){var i=e.geometry.getVertexBuffers();if(i)for(var o in i)if(D(o)){var a=i[o];s.setHasVertexColorAlpha(a,e.hasVertexAlpha);var u=a._buffer,c=t.get(u)||[];t.set(u,c),-1===c.indexOf(a)&&c.push(a);var l=r.get(a)||[];r.set(a,l),-1===l.indexOf(e)&&l.push(e)}var f=e.morphTargetManager;if(f)for(var h=0;h<f.numTargets;h++){var p=f.getTarget(h);l=n.get(p)||[],n.set(p,l),-1===l.indexOf(e)&&l.push(e)}}for(var _=0,g=e.getChildren();_<g.length;_++){var m=g[_];this._collectBuffers(m,t,r,n,s)}},e.prototype._exportBuffers=function(e,t){for(var r=new Map,n=new Map,s=new Map,i=0,o=e;i<o.length;i++){var a=o[i];this._collectBuffers(a,r,n,s,t)}for(var u=Array.from(r.keys()),c=function(e){var s=e.getData();if(!s)throw new Error("Buffer data is not available");var i=r.get(e);if(!i)return"continue";var o=i[0].byteStride;if(i.some((function(e){return e.byteStride!==o})))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");for(var a=function(e){if(e instanceof Array){var t=new Float32Array(e);return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}return ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e)}(s).slice(),u=function(e){var t=n.get(e),r=U(e,t),s=r.byteOffset,i=r.byteStride,o=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,s,i,o,u,c,f,(function(e){var t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){var r=1/t;e[0]*=r,e[1]*=r,e[2]*=r}}));break;case 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,_=new d.Color4,g=l._babylonScene.getEngine().useExactSrgbConversions;(0,d.EnumerateFloatValues)(a,s,i,o,u,c,f,(function(e){3===e.length?(p.fromArray(e,0),p.toLinearSpaceToRef(p,g),p.toArray(e,0)):(_.fromArray(e,0),_.toLinearSpaceToRef(_,g),_.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 _=U(F=p[h],n.get(F)),g=_.byteOffset,m=_.byteStride,x=_.componentCount,y=_.type,T=_.count,v=_.normalized;switch(R=_.kind){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:case d.VertexBuffer.TangentKind:(0,d.EnumerateFloatValues)(a,g,m,x,y,T,v,(function(e){e[0]=-e[0]}))}}t.convertedToRightHandedBuffers.set(e,a)}var b=l._bufferManager.createBufferView(a,o);t.setVertexBufferView(e,b);for(var E=new Map,A=0,w=i;A<w.length;A++){var M=U(F=w[A],n.get(F)),R=M.kind,C=M.totalVertices;switch(R){case d.VertexBuffer.MatricesIndicesKind:case d.VertexBuffer.MatricesIndicesExtraKind:if(F.type==d.VertexBuffer.FLOAT){var S=F.getFloatData(C);null!==S&&E.set(F,S)}}}0!==E.size&&d.Logger.Warn("Joint indices conversion needed: some joint indices are stored as floats in Babylon but GLTF requires UNSIGNED BYTES. We will perform the conversion but this might lead to unused data in the buffer.");for(var V=0,B=Array.from(E.keys());V<B.length;V++){var F=B[V],I=E.get(F);if(I){for(var O=I.some((function(e){return e>=256})),P=new(O?Uint16Array:Uint8Array)(I.length),N=0;N<I.length;N++)P[N]=I[N];var L=l._bufferManager.createBufferView(P,4*(O?2:1));t.setRemappedBufferView(e,F,L)}}},l=this,f=0,h=u;f<h.length;f++)c(h[f]);for(var p=0,_=Array.from(s.keys());p<_.length;p++){var g=_[p],m=s.get(g);if(m)for(var x=te(g,m[0],this._bufferManager,this._bufferViews,this._accessors,t.convertToRightHanded),y=0,T=m;y<T.length;y++){var v=T[y];t.bindMorphDataToMesh(v,x)}}},e.prototype._exportNodeAsync=function(e,t,r){return m(this,void 0,void 0,(function(){var n,s,i,o,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:(s=h.sent())&&(n=this._nodes.length,this._nodes.push(s),this._nodeMap.set(e,n),r.pushExportedNode(e),t.push(n),i={name:"runtime animations",channels:[],samplers:[]},o=[],this._babylonScene.animationGroups.length||(ee._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,o,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&ee._CreateNodeAnimationFromNodeAnimations(e,i,o,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation)),i.channels.length&&i.samplers.length&&this._animations.push(i),o.forEach((function(e){e.channels.length&&e.samplers.length&&f._animations.push(e)}))),a=s?[]:t,u=0,c=e.getChildren(),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 s&&a.length&&(s.children=a),[2]}}))}))},e.prototype._createNodeAsync=function(e,t){return m(this,void 0,void 0,(function(){var r,n,s,i,o,a,u,c,l,f,h,p;return x(this,(function(_){switch(_.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?(s=e instanceof d.InstancedMesh?e.sourceMesh:e).subMeshes&&s.subMeshes.length>0?(i=r,[4,this._exportMeshAsync(s,t)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:i.mesh=_.sent(),_.label=2;case 2:e.skeleton&&void 0!==(o=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(o)&&this._nodesSkinMap.set(o,[]),null===(f=this._nodesSkinMap.get(o))||void 0===f||f.push(r)),_.label=3;case 3:if(e instanceof d.TargetCamera&&(a=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(a)&&this._nodesCameraMap.set(a,[]),this._setCameraTransformation(r,e,t.convertToRightHanded),null!==(u=e.parent)&&z(e,u)&&void 0!==(c=this._nodeMap.get(u)))return l=this._nodes[c],j(r,l),null===(h=this._nodesCameraMap.get(a))||void 0===h||h.push(l),[2,null];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 _.sent()?[2,r]:(d.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}}))}))},e.prototype._exportIndices=function(e,t,r,n,s,i,o,a,u){var c=e;u.mode=G(i);var l=o!==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=G(i);var p=t?new Uint32Array(n):new Uint16Array(n);if(e)for(var _=0;_+2<n;_+=3)p[_]=e[r+_]+s,p[_+1]=e[r+_+2]+s,p[_+2]=e[r+_+1]+s;else for(_=0;_+2<n;_+=3)p[_]=_,p[_+1]=_+2,p[_+2]=_+1;c=p}else if(e&&0!==s){for(p=t?new Uint32Array(n):new Uint16Array(n),_=0;_<n;_++)p[_]=e[r+_]+s;c=p}if(c){var g=a.getIndicesAccessor(e,r,n,s,h);if(void 0===g){var m=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 s=e.slice(0,0+r);return n?new Uint32Array(s):new Uint16Array(s)}(c,0,n,t),x=this._bufferManager.createBufferView(m),y=t?5125:5123;this._accessors.push(this._bufferManager.createAccessor(x,"SCALAR",y,n,0)),g=this._accessors.length-1,a.setIndicesAccessor(e,r,n,s,h,g)}u.indices=g}},e.prototype._exportVertexBuffer=function(e,t,r,n,s,i){var o=e.getKind();if(D(o)&&(!o.startsWith("uv")||this._options.exportUnusedUVs||t&&this._materialNeedsUVsSet.has(t))){var a=s.getVertexAccessor(e,r,n);if(void 0===a){var u=s.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),c=o===d.VertexBuffer.PositionKind?function(e,t,r,n){var s=t.byteOffset,i=t.byteStride,o=t.type,a=t.normalized,u=t.getSize(),c=new Array(u).fill(1/0),l=new Array(u).fill(-1/0);return(0,d.EnumerateFloatValues)(e,s+r*i,i,u,o,n*u,a,(function(e){for(var t=0;t<u;t++)c[t]=Math.min(c[t],e[t]),l[t]=Math.max(l[t],e[t])})),{min:c,max:l}}(u,e,r,n):void 0,l=(o===d.VertexBuffer.MatricesIndicesKind||o===d.VertexBuffer.MatricesIndicesExtraKind)&&e.type===d.VertexBuffer.FLOAT,f=l?d.VertexBuffer.UNSIGNED_BYTE:e.type,h=l?void 0:e.normalized,p=l?s.getRemappedBufferView(e._buffer,e):s.getVertexBufferView(e._buffer),_=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))}(o,s.hasVertexColorAlpha(e)),f,n,_,c,h)),a=this._accessors.length-1,s.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))}(o)]=a}},e.prototype._exportMaterialAsync=function(e,t,r,n){return m(this,void 0,void 0,(function(){var s,i;return x(this,(function(o){switch(o.label){case 0:return void 0!==(s=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.PBRBaseMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,"image/png",i)]:[3,2]);case 1:return s=o.sent(),[3,5];case 2:return e instanceof d.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,"image/png",i)]:[3,4];case 3:return s=o.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,s),o.label=6;case 6:return n.material=s,[2]}}))}))},e.prototype._exportMeshAsync=function(e,t){return m(this,void 0,void 0,(function(){var r,n,s,i,o,a,u,c,l,f,h,p,_,g,m,T,v,b,E,A,w,M,R,C,S,V,B,F,I,O,P,N,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),s=e.isUnIndexed?null:e.getIndices(),i=null===(I=e.geometry)||void 0===I?void 0:I.getVertexBuffers(),o=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:{}},_=h.getMaterial()||this._babylonScene.defaultMaterial,u?(v={name:_.name},b=e,g=d.Color3.White(),m=null!==(P=null===(O=b.material)||void 0===O?void 0:O.alpha)&&void 0!==P?P:1,(!(T=null!==(U=null===(N=b.greasedLineMaterial)||void 0===N?void 0:N.color)&&void 0!==U?U:g).equalsWithEpsilon(g,d.Epsilon)||m<1)&&(v.pbrMetallicRoughness={baseColorFactor:y(y([],T.asArray(),!0),[m],!1)}),this._materials.push(v),p.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return a?(v={name:_.name},(!(b=e).color.equalsWithEpsilon(d.Color3.White(),d.Epsilon)||b.alpha<1)&&(v.pbrMetallicRoughness={baseColorFactor:y(y([],b.color.asArray(),!0),[b.alpha],!1)}),this._materials.push(v),p.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(_,i,h,p)];case 4:x.sent(),x.label=5;case 5:for(E=a||u?d.Material.LineListDrawMode:null!==(L=e.overrideRenderingFillMode)&&void 0!==L?L:_.fillMode,A=_._getEffectiveOrientation(e),this._exportIndices(s,s?(0,d.AreIndices32Bits)(s,h.indexCount,h.indexStart,h.verticesStart):h.verticesCount>65535,s?h.indexStart:h.verticesStart,s?h.indexCount:h.verticesCount,-h.verticesStart,E,A,t,p),w=0,M=Object.values(i);w<M.length;w++)R=M[w],this._exportVertexBuffer(R,_,h.verticesStart,h.verticesCount,t,p);if(o)for(p.targets=[],C=0,S=o;C<S.length;C++)F=S[C],p.targets.push(F.attributes);n.primitives.push(p),this._extensionsPostExportMeshPrimitive(p),x.label=6;case 6:return l++,[3,1];case 7:if(o)for(n.weights=[],n.extras||(n.extras={}),n.extras.targetNames=[],V=0,B=o;V<B.length;V++)F=B[V],n.weights.push(F.influence),n.extras.targetNames.push(F.name);return[2,r]}}))}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),se=function(){function e(){}return e.GLTFAsync=function(e,t,r){return m(this,void 0,void 0,(function(){var n,s;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 ne(e,r)).generateGLTFAsync(t.replace(/\.[^/.]+$/,""))];case 3:return s=i.sent(),n.dispose(),[2,s]}}))}))},e.GLBAsync=function(e,t,r){return m(this,void 0,void 0,(function(){var n,s;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 ne(e,r)).generateGLBAsync(t.replace(/\.[^/.]+$/,""))];case 3:return s=i.sent(),n.dispose(),[2,s]}}))}))},e}(),ie="EXT_mesh_gpu_instancing",oe=function(){function e(e){this.name=ie,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportNodeAsync=function(e,t,r,n,s,i){return m(this,void 0,void 0,(function(){var e=this;return x(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){if(t&&r instanceof d.Mesh&&r.hasThinInstances&&e._exporter){e._wasUsed=!0;for(var o=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,_=!1,g=!1,m=new Float32Array(3*r.thinInstanceCount),x=new Float32Array(4*r.thinInstanceCount),y=new Float32Array(3*r.thinInstanceCount),T=0,v=0,b=c;v<b.length;v++)b[v].decompose(h,f,l),s&&(k(l),H(f)),m.set(l.asArray(),3*T),x.set(f.normalize().asArray(),4*T),y.set(h.asArray(),3*T),p=p||!l.equalsWithEpsilon(o),_=_||!f.equalsWithEpsilon(a),g=g||!h.equalsWithEpsilon(u),T++;var E={attributes:{}};p&&(E.attributes.TRANSLATION=e._buildAccessor(m,"VEC3",r.thinInstanceCount,i)),_&&(E.attributes.ROTATION=e._buildAccessor(x,"VEC4",r.thinInstanceCount,i)),g&&(E.attributes.SCALE=e._buildAccessor(y,"VEC3",r.thinInstanceCount,i)),t.extensions=t.extensions||{},t.extensions[ie]=E}n(t)}))];case 1:return[2,n.sent()]}}))}))},e.prototype._buildAccessor=function(e,t,r,n){var s=n.createBufferView(e),i=n.createAccessor(s,t,5126,r);return this._exporter._accessors.push(i),this._exporter._accessors.length-1},e}();ne.RegisterExtension(ie,(function(e){return new oe(e)}));var ae="KHR_draco_mesh_compression",ue=function(){function e(e){this.name=ae,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 s=[],i=[],o=null;if(void 0!==e.indices){var a=r[e.indices],u=t.getBufferView(a);o=t.getData(u).slice(),s.push(u),i.push(a)}for(var c,l=[],f=0,h=Object.entries(e.attributes);f<h.length;f++){var p=h[f],_=p[0],g=(a=r[p[1]],u=t.getBufferView(a),L(a.type)),m=(0,d.GetTypedArrayData)(t.getData(u),g,a.componentType,a.byteOffset||0,u.byteStride||(0,d.GetTypeByteLength)(a.componentType)*g,a.normalized||!1,a.count,!0);l.push({kind:_,dracoName:(c=_,"POSITION"===c?"POSITION":"NORMAL"===c?"NORMAL":c.startsWith("COLOR")?"COLOR":c.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"),size:L(a.type),data:m}),s.push(u),i.push(a)}var x={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},y=d.DracoEncoder.Default._encodeAsync(l,o,x).then((function(r){if(r){var o={bufferView:-1,attributes:r.attributeIds},a=t.createBufferView(r.data);t.setBufferView(o,a);for(var u=0,c=s;u<c.length;u++){var l=c[u];n._bufferViewsUsed.add(l)}for(var f=0,h=i;f<h.length;f++){var p=h[f];n._accessorsUsed.add(p)}e.extensions||(e.extensions={}),e.extensions[ae]=o}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 m(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}();ne.RegisterExtension(ae,(function(e){return new ue(e)}));var ce="KHR_lights_punctual",le={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},fe={innerConeAngle:0,outerConeAngle:Math.PI/4},he=d.Vector3.Backward(),pe=function(){function e(e){this.name=ce,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[ce]=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,n,s){return m(this,void 0,void 0,(function(){var i=this;return x(this,(function(o){switch(o.label){case 0:return[4,new Promise((function(o){if(r instanceof d.Light){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&&r instanceof d.ShadowLight))return d.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(ce)),void o(t);if(r.falloffType!==d.Light.FALLOFF_GLTF&&d.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(ce," specification!")),!r.position.equalsToFloats(0,0,0)){var u=d.TmpVectors.Vector3[0].copyFrom(r.position);s&&k(u),t.translation=u.asArray()}if("point"!==a){var c=r.direction.normalizeToRef(d.TmpVectors.Vector3[0]);s&&k(c);var l=d.Quaternion.FromUnitVectorsToRef(he,c,d.TmpVectors.Quaternion[0]);d.Quaternion.IsIdentity(l)||(t.rotation=l.asArray())}var f={type:a,name:r.name,color:r.diffuse.asArray(),intensity:r.intensity,range:r.range};if(q(f,le),"spot"===a){var h=r;f.spot={innerConeAngle:h.innerAngle/2,outerConeAngle:h.angle/2},q(f.spot,fe)}i._lights||(i._lights={lights:[]}),i._lights.lights.push(f);var p={light:i._lights.lights.length-1},_=r.parent;if(_&&z(r,_)){var g=n.get(_);if(g){var m=i._exporter._nodes[g];return j(t,m),m.extensions||(m.extensions={}),m.extensions[ce]=p,void o(null)}}t.extensions||(t.extensions={}),t.extensions[ce]=p,o(t)}else o(t)}))];case 1:return[2,o.sent()]}}))}))},e}();ne.RegisterExtension(ce,(function(e){return new pe(e)}));var de="KHR_materials_anisotropy",_e=function(){function e(e){this.name=de,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.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 s=n._exporter._materialExporter.getTextureInfo(r.anisotropy.texture),i={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=s?s:void 0};null!==i.anisotropyTexture&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[de]=i}e(t)}))},e}();ne.RegisterExtension(de,(function(e){return new _e(e)}));var ge="KHR_materials_clearcoat",me=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=[];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 s,i=n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);s=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 o=n._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture),a={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=i?i:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=s?s:void 0,clearcoatNormalTexture:null!=o?o:void 0};null===a.clearcoatTexture&&null===a.clearcoatRoughnessTexture&&null===a.clearcoatRoughnessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[ge]=a}e(t)}))},e}();ne.RegisterExtension(ge,(function(e){return new me(e)}));var xe="KHR_materials_diffuse_transmission";function ye(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 Te=function(){function e(e){this.name=xe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];if(r instanceof d.PBRMaterial&&this._isExtensionEnabled(r)){var s=ye(e,r);return s&&n.push(s),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(s){var i,o;if(r instanceof d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var a=r.subSurface,u=ye(e,r),c=0==a.translucencyIntensity?void 0:a.translucencyIntensity,l=null!==(i=n._exporter._materialExporter.getTextureInfo(u))&&void 0!==i?i:void 0,f=!a.translucencyColor||a.translucencyColor.equalsFloats(1,1,1)?void 0:a.translucencyColor.asArray(),h=null!==(o=n._exporter._materialExporter.getTextureInfo(a.translucencyColorTexture))&&void 0!==o?o:void 0,p={diffuseTransmissionFactor:c,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:f,diffuseTransmissionColorTexture:h};(l||h)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions=t.extensions||{},t.extensions[xe]=p}s(t)}))},e}();ne.RegisterExtension(xe,(function(e){return new Te(e)}));var ve="KHR_materials_dispersion",be=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 s={dispersion:r.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[ve]=s}e(t)}))},e}();ne.RegisterExtension(ve,(function(){return new be}));var Ee="KHR_materials_emissive_strength",Ae=function(){function e(){this.name=Ee,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,t,r){return m(this,void 0,void 0,(function(){var e=this;return x(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){if(!(r instanceof d.PBRMaterial))return n(t);var s=r.emissiveColor.asArray(),i=Math.max.apply(Math,s);if(i>1){e._wasUsed=!0,t.extensions||(t.extensions={});var o={emissiveStrength:i},a=r.emissiveColor.scale(1/o.emissiveStrength);t.emissiveFactor=a.asArray(),t.extensions[Ee]=o}return n(t)}))];case 1:return[2,n.sent()]}}))}))},e}();ne.RegisterExtension(Ee,(function(e){return new Ae}));var we="KHR_materials_ior",Me=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 s={ior:r.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[we]=s}e(t)}))},e}();ne.RegisterExtension(we,(function(e){return new Me}));var Re="KHR_materials_iridescence",Ce=function(){function e(e){this.name=Re,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.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 s=n._exporter._materialExporter.getTextureInfo(r.iridescence.texture),i=n._exporter._materialExporter.getTextureInfo(r.iridescence.thicknessTexture),o={iridescenceFactor:r.iridescence.intensity,iridescenceIor:r.iridescence.indexOfRefraction,iridescenceThicknessMinimum:r.iridescence.minimumThickness,iridescenceThicknessMaximum:r.iridescence.maximumThickness,iridescenceTexture:null!=s?s:void 0,iridescenceThicknessTexture:null!=i?i:void 0};null===o.iridescenceTexture&&null===o.iridescenceThicknessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Re]=o}e(t)}))},e}();ne.RegisterExtension(Re,(function(e){return new Ce(e)}));var Se="KHR_materials_sheen",Ve=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){return r instanceof d.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[r.sheen.texture]:[]},e.prototype.postExportMaterialAsync=function(e,t,r){return m(this,void 0,void 0,(function(){var e=this;return x(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){var s,i,o,a;if(r instanceof d.PBRMaterial){if(!r.sheen.isEnabled)return void n(t);e._wasUsed=!0,null==t.extensions&&(t.extensions={});var u={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(s=r.sheen.roughness)&&void 0!==s?s:0};null===u.sheenColorTexture&&null===u.sheenRoughnessTexture||e._exporter._materialNeedsUVsSet.add(r),r.sheen.texture&&(u.sheenColorTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==i?i:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(o=e._exporter._materialExporter.getTextureInfo(r.sheen.textureRoughness))&&void 0!==o?o:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==a?a:void 0),t.extensions[Se]=u}n(t)}))];case 1:return[2,n.sent()]}}))}))},e}();ne.RegisterExtension(Se,(function(e){return new Ve(e)}));var Be="KHR_materials_specular",Fe=function(){function e(e){this.name=Be,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 s,i;if(r instanceof d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0,t.extensions=t.extensions||{};var o=null!==(s=n._exporter._materialExporter.getTextureInfo(r.metallicReflectanceTexture))&&void 0!==s?s: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:o,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:a};n._hasTexturesExtension(r)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[Be]=u}e(t)}))},e}();ne.RegisterExtension(Be,(function(e){return new Fe(e)}));var Ie="KHR_materials_transmission",Oe=function(){function e(e){this.name=Ie,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 m(this,void 0,void 0,(function(){var n,s,i,o;return x(this,(function(a){switch(a.label){case 0:return r instanceof d.PBRMaterial&&this._isExtensionEnabled(r)?(this._wasUsed=!0,n=r.subSurface,s=0===n.refractionIntensity?void 0:n.refractionIntensity,i={transmissionFactor:s},this._hasTexturesExtension(r)&&this._exporter._materialNeedsUVsSet.add(r),n.refractionIntensityTexture?n.useGltfStyleTextures?[4,this._exporter._materialExporter.exportTextureAsync(n.refractionIntensityTexture,"image/png")]:[3,2]:[3,3]):[3,4];case 1:return(o=a.sent())&&(i.transmissionTexture=o),[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[Ie]=i,a.label=4;case 4:return[2,t]}}))}))},e}();ne.RegisterExtension(Ie,(function(e){return new Oe(e)}));var Pe="KHR_materials_unlit",Ne=function(){function e(){this.name=Pe,this.enabled=!0,this.required=!1,this._wasUsed=!1}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var s=!1;r instanceof d.PBRMaterial?s=r.unlit:r instanceof d.StandardMaterial&&(s=r.disableLighting),s&&(n._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[Pe]={}),e(t)}))},e}();ne.RegisterExtension(Pe,(function(){return new Ne}));var Ue="KHR_materials_volume",Le=function(){function e(e){this.name=Ue,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 s;if(r instanceof d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var i=r.subSurface,o={thicknessFactor:0==i.maximumThickness?void 0:i.maximumThickness,thicknessTexture:null!==(s=n._exporter._materialExporter.getTextureInfo(i.thicknessTexture))&&void 0!==s?s:void 0,attenuationDistance:i.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:i.tintColorAtDistance,attenuationColor:i.tintColor.equalsFloats(1,1,1)?void 0:i.tintColor.asArray()};n._hasTexturesExtension(r)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions=t.extensions||{},t.extensions[Ue]=o}e(t)}))},e}();ne.RegisterExtension(Ue,(function(e){return new Le(e)}));var De="EXT_materials_diffuse_roughness",Ge=function(){function e(e){this.name=De,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof d.PBRBaseMaterial&&r._baseDiffuseRoughness?(r._baseDiffuseRoughnessTexture&&n.push(r._baseDiffuseRoughnessTexture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof d.PBRBaseMaterial){if(!r._baseDiffuseRoughness)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var s=n._exporter._materialExporter.getTextureInfo(r._baseDiffuseRoughnessTexture),i={diffuseRoughnessFactor:r._baseDiffuseRoughness,diffuseRoughnessTexture:null!=s?s:void 0};null!==i.diffuseRoughnessTexture&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[De]=i}e(t)}))},e}();ne.RegisterExtension(De,(function(e){return new Ge(e)}));var Ke="KHR_texture_transform",ke=function(){function e(){this.name=Ke,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={},s=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],s=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],s=!0),0!==r.wAng){if(0!==r.uRotationCenter||0!==r.vRotationCenter){if(r.homogeneousRotationInUVTransform&&r.uScale!==r.vScale)return void d.Tools.Warn("".concat(e,": Texture ").concat(r.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(Ke,"."));d.Tools.Warn("".concat(e,": Texture ").concat(r.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(Ke,".")),n.offset=function(e){var t=e.uOffset,r=e.vOffset,n=e.uRotationCenter,s=e.vRotationCenter,i=e.uScale,o=e.vScale,a=e.wAng,u=Math.cos(a),c=Math.sin(a),l=n*i,f=s*o;return[t+(l*(1-u)+f*c),r+(f*(1-u)-l*c)]}(r)}n.rotation=-r.wAng,s=!0}0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,s=!0),s&&(this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[Ke]=n)}},e}();ne.RegisterExtension(Ke,(function(){return new ke}));var He=void 0!==i.g?i.g:"undefined"!=typeof window?window:void 0;if(void 0!==He){He.BABYLON=He.BABYLON||{};var We=He.BABYLON;We.GLTF2=We.GLTF2||{},We.GLTF2.Exporter=We.GLTF2.Exporter||{},We.GLTF2.Exporter.Extensions=We.GLTF2.Exporter.Extensions||{};var je=[];for(var ze in a)We[ze]=a[ze],je.push(ze);for(var ze in u)We[ze]=u[ze],je.push(ze);for(var ze in c)We[ze]=c[ze],je.push(ze);for(var ze in l)We.GLTF2.Exporter.Extensions[ze]=l[ze],je.push(ze);for(var ze in f)je.indexOf(ze)>-1||(We.GLTF2.Exporter[ze]=f[ze])}const qe=h;return o.default})()));
2
2
  //# sourceMappingURL=babylon.glTF2Serializer.min.js.map