babylonjs-serializers 5.32.1 → 5.32.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.SERIALIZERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(e=>(()=>{"use strict";var t={520:t=>{t.exports=e}},r={};function n(e){var a=r[e];if(void 0!==a)return a.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return(()=>{n.d(a,{default:()=>j});var e={};n.r(e),n.d(e,{__IGLTFExporterExtension:()=>u});var t={};n.r(t),n.d(t,{GLTFData:()=>l});var r={};n.r(r),n.d(r,{GLTF2Export:()=>T});var i={};n.r(i),n.d(i,{EXT_mesh_gpu_instancing:()=>D,KHR_lights_punctual:()=>E,KHR_materials_clearcoat:()=>M,KHR_materials_ior:()=>P,KHR_materials_iridescence:()=>w,KHR_materials_sheen:()=>C,KHR_materials_specular:()=>L,KHR_materials_transmission:()=>G,KHR_materials_unlit:()=>I,KHR_materials_volume:()=>k,KHR_texture_transform:()=>b});var o={};n.r(o),n.d(o,{EXT_mesh_gpu_instancing:()=>D,GLTF2Export:()=>T,GLTFData:()=>l,KHR_lights_punctual:()=>E,KHR_materials_clearcoat:()=>M,KHR_materials_ior:()=>P,KHR_materials_iridescence:()=>w,KHR_materials_sheen:()=>C,KHR_materials_specular:()=>L,KHR_materials_transmission:()=>G,KHR_materials_unlit:()=>I,KHR_materials_volume:()=>k,KHR_texture_transform:()=>b,_BinaryWriter:()=>y,_Exporter:()=>x,_GLTFAnimation:()=>g,_GLTFMaterialExporter:()=>_,_GLTFUtilities:()=>m,__IGLTFExporterExtensionV2:()=>H});var s={};n.r(s),n.d(s,{EXT_mesh_gpu_instancing:()=>D,GLTF2Export:()=>T,GLTFData:()=>l,KHR_lights_punctual:()=>E,KHR_materials_clearcoat:()=>M,KHR_materials_ior:()=>P,KHR_materials_iridescence:()=>w,KHR_materials_sheen:()=>C,KHR_materials_specular:()=>L,KHR_materials_transmission:()=>G,KHR_materials_unlit:()=>I,KHR_materials_volume:()=>k,KHR_texture_transform:()=>b,_BinaryWriter:()=>y,_Exporter:()=>x,_GLTFAnimation:()=>g,_GLTFMaterialExporter:()=>_,_GLTFUtilities:()=>m,__IGLTFExporterExtension:()=>u,__IGLTFExporterExtensionV2:()=>H});var u=0,l=function(){function e(){this.glTFFiles={}}return e.prototype.downloadFiles=function(){function e(e,t){return-1!==e.indexOf(t,e.length-t.length)}for(var t in this.glTFFiles){var r=document.createElement("a");document.body.appendChild(r),r.setAttribute("type","hidden"),r.download=t;var n=this.glTFFiles[t],a=void 0;e(t,".glb")?a={type:"model/gltf-binary"}:e(t,".bin")?a={type:"application/octet-stream"}:e(t,".gltf")?a={type:"model/gltf+json"}:e(t,".jpeg")||e(t,".jpg")?a={type:"image/jpeg"}:e(t,".png")&&(a={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([n],a)),r.click()}},e}();function c(e,t,r,n){return new(r||(r=Promise))((function(a,i){function o(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,s)}u((n=n.apply(e,t||[])).next())}))}function f(e,t){var r,n,a,i,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(a=2&i[0]?n.return:i[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,i[1])).done)return a;switch(n=0,a&&(i=[2&i[0],a.value]),i[0]){case 0:case 1:a=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,n=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!((a=(a=o.trys).length>0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]<a[3])){o.label=i[1];break}if(6===i[0]&&o.label<a[1]){o.label=a[1],a=i;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(i);break}a[2]&&o.ops.pop(),o.trys.pop();continue}i=t.call(e,o)}catch(e){i=[6,e],n=0}finally{r=a=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function h(e,t,r){if(r||2===arguments.length)for(var n,a=0,i=t.length;a<i;a++)!n&&a in t||(n||(n=Array.prototype.slice.call(t,0,a)),n[a]=t[a]);return e.concat(n||Array.prototype.slice.call(t))}Object.create,Object.create;var p,d=n(520),_=function(){function e(e){this._textureMap={},this._textureMap={},this._exporter=e}return e._FuzzyEquals=function(e,t,r){return d.Scalar.WithinEpsilon(e.r,t.r,r)&&d.Scalar.WithinEpsilon(e.g,t.g,r)&&d.Scalar.WithinEpsilon(e.b,t.b,r)},e.prototype._convertMaterialsToGLTFAsync=function(e,t,r){var n=this,a=[];return e.forEach((function(e){"StandardMaterial"===e.getClassName()?a.push(n._convertStandardMaterialAsync(e,t,r)):-1!==e.getClassName().indexOf("PBR")?a.push(n._convertPBRMaterialAsync(e,t,r)):d.Tools.Warn("Unsupported material type: ".concat(e.name))})),Promise.all(a).then((function(){}))},e.prototype._stripTexturesFromMaterial=function(e){var t={};if(e){t.name=e.name,t.doubleSided=e.doubleSided,t.alphaMode=e.alphaMode,t.alphaCutoff=e.alphaCutoff,t.emissiveFactor=e.emissiveFactor;var r=e.pbrMetallicRoughness;r&&(t.pbrMetallicRoughness={},t.pbrMetallicRoughness.baseColorFactor=r.baseColorFactor,t.pbrMetallicRoughness.metallicFactor=r.metallicFactor,t.pbrMetallicRoughness.roughnessFactor=r.roughnessFactor)}return t},e.prototype._hasTexturesPresent=function(e){var t;if(e.emissiveTexture||e.normalTexture||e.occlusionTexture)return!0;var r=e.pbrMetallicRoughness;if(r&&(r.baseColorTexture||r.metallicRoughnessTexture))return!0;if(e.extensions)for(var n in e.extensions){var a=e.extensions[n];if(a)return null===(t=a.hasTextures)||void 0===t?void 0:t.call(a)}return!1},e.prototype._getTextureInfo=function(e){if(e){var t=e.uid;if(t in this._textureMap)return this._textureMap[t]}return null},e.prototype._convertToGLTFPBRMetallicRoughness=function(t){var r,n,a,i,o,s,u=new d.Vector2(0,1),l=new d.Vector2(0,.1),c=new d.Vector2(0,.1),f=new d.Vector2(1300,.1),h=t.diffuseColor.toLinearSpace().scale(.5),p=t.alpha,_=(r=d.Scalar.Clamp(t.specularPower,0,e._MaxSpecularPower),n=Math.pow(r/f.x,.333333),a=u.y,i=l.y,o=c.y,s=f.y,(1-n)*(1-n)*(1-n)*a+3*(1-n)*(1-n)*n*i+3*(1-n)*n*n*o+n*n*n*s);return{baseColorFactor:[h.r,h.g,h.b,p],metallicFactor:0,roughnessFactor:_}},e._SolveMetallic=function(e,t,r){if(t<this._DielectricSpecular.r)return this._DielectricSpecular,0;var n=this._DielectricSpecular.r,a=e*r/(1-this._DielectricSpecular.r)+t-2*this._DielectricSpecular.r,i=a*a-4*n*(this._DielectricSpecular.r-t);return d.Scalar.Clamp((-a+Math.sqrt(i))/(2*n),0,1)},e._SetAlphaMode=function(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)},e.prototype._convertStandardMaterialAsync=function(t,r,n){var a=this._exporter._materialMap,i=this._exporter._materials,o=[],s=this._convertToGLTFPBRMetallicRoughness(t),u={name:t.name};return 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."),u.doubleSided=!0),n&&(t.diffuseTexture&&o.push(this._exportTextureAsync(t.diffuseTexture,r).then((function(e){e&&(s.baseColorTexture=e)}))),t.bumpTexture&&o.push(this._exportTextureAsync(t.bumpTexture,r).then((function(e){e&&(u.normalTexture=e,null!=t.bumpTexture&&1!==t.bumpTexture.level&&(u.normalTexture.scale=t.bumpTexture.level))}))),t.emissiveTexture&&(u.emissiveFactor=[1,1,1],o.push(this._exportTextureAsync(t.emissiveTexture,r).then((function(e){e&&(u.emissiveTexture=e)})))),t.ambientTexture&&o.push(this._exportTextureAsync(t.ambientTexture,r).then((function(e){if(e){var t={index:e.index};u.occlusionTexture=t,t.strength=1}})))),(t.alpha<1||t.opacityTexture)&&(t.alphaMode===d.Constants.ALPHA_COMBINE?u.alphaMode="BLEND":d.Tools.Warn(t.name+": glTF 2.0 does not support alpha mode: "+t.alphaMode.toString())),t.emissiveColor&&!e._FuzzyEquals(t.emissiveColor,d.Color3.Black(),e._Epsilon)&&(u.emissiveFactor=t.emissiveColor.asArray()),u.pbrMetallicRoughness=s,e._SetAlphaMode(u,t),i.push(u),a[t.uniqueId]=i.length-1,this._finishMaterial(o,u,t,r)},e.prototype._finishMaterial=function(e,t,r,n){var a=this;return Promise.all(e).then((function(){for(var e=null,i=0,o=a._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",t,r);i<o.length;i++){var s=o[i];e||(e=[]),e.push(a._exportTextureAsync(s,n))}return e||(e=[Promise.resolve(null)]),Promise.all(e).then((function(){var e=a._exporter._extensionsPostExportMaterialAsync("exportMaterial",t,r);return e?e.then((function(){return t})):t}))}))},e.prototype._createBase64FromCanvasAsync=function(e,t,r,n){var a=this;return new Promise((function(i){return c(a,void 0,void 0,(function(){var a,o,s,u,l,c;return f(this,(function(f){switch(f.label){case 0:return a=d.Constants.TEXTURETYPE_UNSIGNED_INT,o=this._exporter._babylonScene,s=o.getEngine(),u=s.createRawTexture(e,t,r,d.Constants.TEXTUREFORMAT_RGBA,!1,!0,d.Texture.NEAREST_SAMPLINGMODE,null,a),[4,d.TextureTools.ApplyPostProcess("pass",u,o,a,d.Constants.TEXTURE_NEAREST_SAMPLINGMODE,d.Constants.TEXTUREFORMAT_RGBA)];case 1:return f.sent(),[4,s._readTexturePixels(u,t,r)];case 2:return l=f.sent(),[4,d.Tools.DumpDataAsync(t,r,l,n,void 0,!0,!1)];case 3:return c=f.sent(),i(c),[2]}}))}))}))},e.prototype._createWhiteTexture=function(e,t,r){for(var n=new Uint8Array(e*t*4),a=0;a<n.length;a+=4)n[a]=n[a+1]=n[a+2]=n[a+3]=255;return d.RawTexture.CreateRGBATexture(n,e,t,r)},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,a,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):this._createWhiteTexture(o.width,o.height,r),a=t):i.width>o.width?(a=t&&t instanceof d.Texture?d.TextureTools.CreateResizedCopy(t,i.width,i.height,!0):this._createWhiteTexture(i.width,i.height,r),n=e):(n=e,a=t),{texture1:n,texture2:a}},e.prototype._convertPixelArrayToFloat32=function(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!")},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(t,r,n,a){var i;return c(this,void 0,void 0,(function(){var o,s,u,l,c,h,p,_,m,g,x,y,T,v,b,A,E,F,M,R,w,V,C,S,I,B,P,N,L,O,k,U;return f(this,(function(f){switch(f.label){case 0:return o=[],t||r?(s=t?t.getScene():r?r.getScene():null)?(u=this._resizeTexturesToSameDimensions(t,r,s),l=null===(i=u.texture1)||void 0===i?void 0:i.getSize(),c=void 0,h=void 0,p=l.width,_=l.height,[4,u.texture1.readPixels()]):[3,3]:[2,Promise.reject("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!")];case 1:return m=f.sent(),[4,u.texture2.readPixels()];case 2:if(g=f.sent(),!m)return[2,Promise.reject("Failed to retrieve pixels from diffuse texture!")];if(c=this._convertPixelArrayToFloat32(m),!g)return[2,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];for(h=this._convertPixelArrayToFloat32(g),x=h.byteLength,y=new Uint8Array(x),T=new Uint8Array(x),v=d.Color3.Black(),b=0,A=0,B=0;B<_;++B)for(P=0;P<p;++P)E=4*(p*B+P),F=new d.Color3(c[E],c[E+1],c[E+2]).toLinearSpace().multiply(n.diffuseColor),M=new d.Color3(h[E],h[E+1],h[E+2]).toLinearSpace().multiply(n.specularColor),R=h[E+3]*n.glossiness,w={diffuseColor:F,specularColor:M,glossiness:R},V=this._convertSpecularGlossinessToMetallicRoughness(w),v.r=Math.max(v.r,V.baseColor.r),v.g=Math.max(v.g,V.baseColor.g),v.b=Math.max(v.b,V.baseColor.b),b=Math.max(b,V.metallic),A=Math.max(A,V.roughness),T[E]=255*V.baseColor.r,T[E+1]=255*V.baseColor.g,T[E+2]=255*V.baseColor.b,T[E+3]=u.texture1.hasAlpha?255*c[E+3]:255,y[E]=0,y[E+1]=255*V.roughness,y[E+2]=255*V.metallic,y[E+3]=255;for(C={baseColor:v,metallic:b,roughness:A},S=!1,I=!1,B=0;B<_;++B)for(P=0;P<p;++P)T[N=4*(p*B+P)]/=C.baseColor.r>e._Epsilon?C.baseColor.r:1,T[N+1]/=C.baseColor.g>e._Epsilon?C.baseColor.g:1,T[N+2]/=C.baseColor.b>e._Epsilon?C.baseColor.b:1,L=d.Color3.FromInts(T[N],T[N+1],T[N+2]),O=L.toGammaSpace(),T[N]=255*O.r,T[N+1]=255*O.g,T[N+2]=255*O.b,e._FuzzyEquals(O,d.Color3.White(),e._Epsilon)||(I=!0),y[N+1]/=C.roughness>e._Epsilon?C.roughness:1,y[N+2]/=C.metallic>e._Epsilon?C.metallic:1,k=d.Color3.FromInts(255,y[N+1],y[N+2]),e._FuzzyEquals(k,d.Color3.White(),e._Epsilon)||(S=!0);return S&&(U=this._createBase64FromCanvasAsync(y,p,_,a).then((function(e){C.metallicRoughnessTextureBase64=e})),o.push(U)),I&&(U=this._createBase64FromCanvasAsync(T,p,_,a).then((function(e){C.baseColorTextureBase64=e})),o.push(U)),[2,Promise.all(o).then((function(){return C}))];case 3:return[2,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}}))}))},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(t){var r=this._getPerceivedBrightness(t.diffuseColor),n=this._getPerceivedBrightness(t.specularColor),a=1-this._getMaxComponent(t.specularColor),i=e._SolveMetallic(r,n,a),o=t.diffuseColor.scale(a/(1-e._DielectricSpecular.r)/Math.max(1-i,e._Epsilon)),s=t.specularColor.subtract(e._DielectricSpecular.scale(1-i)).scale(1/Math.max(i,e._Epsilon)),u=d.Color3.Lerp(o,s,i*i);return{baseColor:u=u.clampToRef(0,1,u),metallic:i,roughness:1-t.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){var a=[],i={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness};if(n){e._albedoTexture&&a.push(this._exportTextureAsync(e._albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)})));var o=e._metallicTexture;o&&a.push(this._exportTextureAsync(o,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))}return Promise.all(a).then((function(){return i}))},e.prototype._getGLTFTextureSampler=function(e){var t=this._getGLTFTextureWrapModesSampler(e),r=e instanceof d.Texture?e.samplingMode:null;if(null!=r)switch(r){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._getGLTFTextureWrapModesSampler=function(e){var t=this._getGLTFTextureWrapMode(e instanceof d.Texture?e.wrapU:d.Texture.WRAP_ADDRESSMODE),r=this._getGLTFTextureWrapMode(e instanceof d.Texture?e.wrapV:d.Texture.WRAP_ADDRESSMODE);return 10497===t&&10497===r?{}:{wrapS:t,wrapT:r}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r,n){var a=this;return Promise.resolve().then((function(){var i=a._exporter._samplers,o=a._exporter._textures,s={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},u=null,l=e._albedoTexture,c=e._reflectivityTexture;if(l){var f=a._getGLTFTextureSampler(l);null!=f.magFilter&&null!=f.minFilter&&null!=f.wrapS&&null!=f.wrapT&&(i.push(f),u=i.length-1)}var h=e._useMicroSurfaceFromReflectivityMapAlpha;return c&&!h?Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported"):(l||c)&&n?a._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(l,c,s,t).then((function(e){if(e.baseColorTextureBase64){var n=a._getTextureInfoFromBase64(e.baseColorTextureBase64,"bjsBaseColorTexture_"+o.length+".png",t,l?l.coordinatesIndex:null,u);n&&(r.baseColorTexture=n)}if(e.metallicRoughnessTextureBase64){var i=a._getTextureInfoFromBase64(e.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+o.length+".png",t,c?c.coordinatesIndex:null,u);i&&(r.metallicRoughnessTexture=i)}return e})):a._convertSpecularGlossinessToMetallicRoughness(s)}))},e.prototype._convertPBRMaterialAsync=function(e,t,r){var n=this,a={},i={name:e.name};if(e.isMetallicWorkflow()){var o=e._albedoColor,s=e.alpha;return o&&(a.baseColorFactor=[o.r,o.g,o.b,s]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,a,r).then((function(o){return n._setMetallicRoughnessPbrMaterial(o,e,i,a,t,r)}))}return this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,a,r).then((function(o){return n._setMetallicRoughnessPbrMaterial(o,e,i,a,t,r)}))},e.prototype._setMetallicRoughnessPbrMaterial=function(t,r,n,a,i,o){var s=this._exporter._materialMap,u=this._exporter._materials,l=[];if(t){if(e._SetAlphaMode(n,r),e._FuzzyEquals(t.baseColor,d.Color3.White(),e._Epsilon)&&r.alpha>=e._Epsilon||(a.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,r.alpha]),null!=t.metallic&&1!==t.metallic&&(a.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(a.roughnessFactor=t.roughness),null==r.backFaceCulling||r.backFaceCulling||(r._twoSidedLighting||d.Tools.Warn(r.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),o){var c=r._bumpTexture;if(c){var f=this._exportTextureAsync(c,i).then((function(e){e&&(n.normalTexture=e,1!==c.level&&(n.normalTexture.scale=c.level))}));l.push(f)}var h=r._ambientTexture;h&&(f=this._exportTextureAsync(h,i).then((function(e){if(e){var t={index:e.index,texCoord:e.texCoord};n.occlusionTexture=t;var a=r._ambientTextureStrength;a&&(t.strength=a)}})),l.push(f));var p=r._emissiveTexture;p&&(f=this._exportTextureAsync(p,i).then((function(e){e&&(n.emissiveTexture=e)})),l.push(f))}var _=r._emissiveColor;e._FuzzyEquals(_,d.Color3.Black(),e._Epsilon)||(n.emissiveFactor=_.asArray()),n.pbrMetallicRoughness=a,u.push(n),s[r.uniqueId]=u.length-1}return this._finishMaterial(l,n,r,i)},e.prototype._getPixelsFromTexture=function(e){return e.textureType,d.Constants.TEXTURETYPE_UNSIGNED_INT,e.readPixels()},e.prototype._exportTextureAsync=function(e,t){var r=this,n=this._exporter._extensionsPreExportTextureAsync("exporter",e,t);return n?n.then((function(n){return n?r._exportTextureInfoAsync(n,t):r._exportTextureInfoAsync(e,t)})):this._exportTextureInfoAsync(e,t)},e.prototype._exportTextureInfoAsync=function(e,t){var r=this;return Promise.resolve().then((function(){return c(r,void 0,void 0,(function(){var r,n,a,i,o,s,u,l,c,h=this;return f(this,(function(f){switch(f.label){case 0:return(r=e.uid)in this._textureMap?[2,this._textureMap[r]]:[3,1];case 1:return[4,this._getPixelsFromTexture(e)];case 2:if(!(n=f.sent()))return[2,null];for(a=this._exporter._samplers,i=this._getGLTFTextureSampler(e),o=null,s=null,u=0;u<a.length;++u)if((l=a[u]).minFilter===i.minFilter&&l.magFilter===i.magFilter&&l.wrapS===i.wrapS&&l.wrapT===i.wrapT){s=u;break}if(null==s?(a.push(i),o=a.length-1):o=s,c=e.getSize(),e.mimeType)switch(e.mimeType){case"image/jpeg":t="image/jpeg";break;case"image/png":t="image/png";break;case"image/webp":t="image/webp"}return[2,this._createBase64FromCanvasAsync(n,c.width,c.height,t).then((function(n){var a=h._getTextureInfoFromBase64(n,e.name.replace(/\.\/|\/|\.\\|\\/g,"_"),t,e.coordinatesIndex,o);return a&&(h._textureMap[r]=a,h._exporter._extensionsPostExportTextures("linkTextureInfo",a,e)),a}))]}}))}))}))},e.prototype._getTextureInfoFromBase64=function(e,t,r,n,a){var i=this._exporter._textures,o=this._exporter._images,s=this._exporter._imageData,u=null,l={source:o.length,name:t};null!=a&&(l.sampler=a);for(var c=atob(e.split(",")[1]),f=new ArrayBuffer(c.length),h=new Uint8Array(f),p=0,_=c.length;p<_;++p)h[p]=c.charCodeAt(p);var m={data:h,mimeType:r},g="image/jpeg"===r?".jpeg":".png",x=t+g,y=x;if(x in s&&(x="".concat(t,"_").concat(d.Tools.RandomId()).concat(g)),s[x]=m,"image/jpeg"===r||"image/png"===r||"image/webp"===r){var T={name:t,uri:x},v=null;for(p=0;p<o.length;++p)if(o[p].uri===y){v=p;break}null==v?(o.push(T),l.source=o.length-1):l.source=v,i.push(l),u={index:i.length-1},null!=n&&(u.texCoord=n)}else d.Tools.Error("Unsupported texture mime type ".concat(r));return u},e._DielectricSpecular=new d.Color3(.04,.04,.04),e._MaxSpecularPower=1024,e._Epsilon=1e-6,e}(),m=function(){function e(){}return e._CreateBufferView=function(e,t,r,n,a){var i={buffer:e,byteLength:r};return t&&(i.byteOffset=t),a&&(i.name=a),n&&(i.byteStride=n),i},e._CreateAccessor=function(e,t,r,n,a,i,o,s){var u={name:t,bufferView:e,componentType:n,count:a,type:r};return null!=o&&(u.min=o),null!=s&&(u.max=s),null!=i&&(u.byteOffset=i),u},e._CalculateMinMaxPositions=function(t,r,n,a){var i,o,s,u=[1/0,1/0,1/0],l=[-1/0,-1/0,-1/0];if(n)for(var c=r,f=r+n;c<f;++c){i=3*c,o=d.Vector3.FromArray(t,i),a&&e._GetRightHandedPositionVector3FromRef(o),s=o.asArray();for(var h=0;h<3;++h){var p=s[h];p<u[h]&&(u[h]=p),p>l[h]&&(l[h]=p),++i}}return{min:u,max:l}},e._GetRightHandedPositionVector3=function(e){return new d.Vector3(e.x,e.y,-e.z)},e._GetRightHandedPositionVector3FromRef=function(e){e.z*=-1},e._GetRightHandedPositionArray3FromRef=function(e){e[2]*=-1},e._GetRightHandedNormalVector3=function(e){return new d.Vector3(e.x,e.y,-e.z)},e._GetRightHandedNormalVector3FromRef=function(e){e.z*=-1},e._GetRightHandedNormalArray3FromRef=function(e){e[2]*=-1},e._GetRightHandedVector4FromRef=function(e){e.z*=-1,e.w*=-1},e._GetRightHandedArray4FromRef=function(e){e[2]*=-1,e[3]*=-1},e._GetRightHandedQuaternionFromRef=function(e){e.x*=-1,e.y*=-1},e._GetRightHandedQuaternionArrayFromRef=function(e){e[0]*=-1,e[1]*=-1},e._NormalizeTangentFromRef=function(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)},e._GetDataAccessorElementCount=function(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}},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(p||(p={}));var g=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,a,i,o){if(this._IsTransformable(t)){var s=[],u=[],l=r.getKeys(),c=e._CalculateMinMaxKeyFrames(l),f=e._DeduceInterpolation(l,n,i),h=c.max-c.min,p=f.interpolationType,_=f.shouldBakeAnimation;if(_?e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,o,s,u,c,a,i):"LINEAR"===p||"STEP"===p?e._CreateLinearOrStepAnimation(t,r,n,h,s,u,a,i):"CUBICSPLINE"===p?e._CreateCubicSplineAnimation(t,r,n,h,s,u,a,i):e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,o,s,u,c,a,i),s.length&&u.length)return{inputs:s,outputs:u,samplerInterpolation:p,inputsMin:_?c.min:d.Tools.FloatRound(c.min/r.framePerSecond),inputsMax:_?c.max:d.Tools.FloatRound(c.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,a=e.targetProperty.split(".");switch(a[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(a[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,a,i,o,s,u,l,c){var f;if(e._IsTransformable(t)&&t.animations)for(var h=0,p=t.animations;h<p.length;h++){var d=p[h],_=e._DeduceAnimationInfo(d);_&&(f={name:d.name,samplers:[],channels:[]},e._AddAnimation("".concat(d.name),d.hasRunningRuntimeAnimations?r:f,t,d,_.dataAccessorType,_.animationChannelTargetPath,a,o,s,u,l,_.useQuaternion,c),f.samplers.length&&f.channels.length&&n.push(f))}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,a,i,o,s,u,l,c){var f;if(t instanceof d.Mesh){var h=t.morphTargetManager;if(h)for(var p=0;p<h.numTargets;++p)for(var _=0,m=h.getTarget(p).animations;_<m.length;_++){for(var g=m[_],x=new d.Animation("".concat(g.name),"influence",g.framePerSecond,g.dataType,g.loopMode,g.enableBlending),y=[],T=g.getKeys(),v=0;v<T.length;++v)for(var b=T[v],A=0;A<h.numTargets;++A)A==p?y.push(b):y.push({frame:b.frame,value:0});x.setKeys(y);var E=e._DeduceAnimationInfo(x);E&&(f={name:x.name,samplers:[],channels:[]},e._AddAnimation(g.name,g.hasRunningRuntimeAnimations?r:f,t,x,E.dataAccessorType,E.animationChannelTargetPath,a,o,s,u,l,E.useQuaternion,c,h.numTargets),f.samplers.length&&f.channels.length&&n.push(f))}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,a,i,o,s,u,l){var c,f;if(t.animationGroups)for(var h=t.animationGroups,p=function(a){var h=new Map,p=new Map,m=new Set,g=a.to-a.from;f={name:a.name,channels:[],samplers:[]};for(var x=function(r){var g=a.targetedAnimations[r],x=g.target,y=g.animation;if(_._IsTransformable(x)||1===x.length&&_._IsTransformable(x[0])){if(b=e._DeduceAnimationInfo(g.animation)){var T=_._IsTransformable(x)?x:_._IsTransformable(x[0])?x[0]:null;if(T){var v=u[T.uniqueId];e._AddAnimation("".concat(y.name),f,T,y,b.dataAccessorType,b.animationChannelTargetPath,n,i,o,s,v,b.useQuaternion,l)}}}else if(x instanceof d.MorphTarget||1===x.length&&x[0]instanceof d.MorphTarget){var b;if(b=e._DeduceAnimationInfo(g.animation)){var A=x instanceof d.MorphTarget?x:x[0];if(A){var E=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===A)return!0;return!1}));if(E){var F=t.meshes.find((function(e){return e.morphTargetManager===E}));F&&(h.has(F)||h.set(F,new Map),null===(c=h.get(F))||void 0===c||c.set(A,y),m.add(F),p.set(F,y))}}}}},y=0;y<a.targetedAnimations.length;++y)x(y);m.forEach((function(t){for(var r=t.morphTargetManager,u=null,c=[],_=p.get(t).getKeys(),m=_.length,x=0;x<m;++x)for(var y=0;y<r.numTargets;++y){var T=r.getTarget(y),v=h.get(t);if(v){var b=v.get(T);b?(u||(u=new d.Animation("".concat(a.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,d.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[x])):c.push({frame:a.from+g/m*x,value:T.influence,inTangent:_[0].inTangent?0:void 0,outTangent:_[0].outTangent?0:void 0})}}u.setKeys(c);var A=e._DeduceAnimationInfo(u);A&&e._AddAnimation("".concat(a.name,"_").concat(t.name,"_MorphWeightAnimation"),f,t,u,A.dataAccessorType,A.animationChannelTargetPath,n,i,o,s,!1,A.useQuaternion,l,null==r?void 0:r.numTargets)})),f.channels.length&&f.samplers.length&&r.push(f)},_=this,m=0,g=h;m<g.length;m++)p(g[m])},e._AddAnimation=function(t,r,n,a,i,o,s,u,l,c,f,h,p,d){var _,g,x,y,T,v,b,A=e._CreateNodeAnimation(n,a,o,f,h,p);if(A){if(d){for(var E=0,F=0,M=[];A.inputs.length>0;)F=A.inputs.shift(),E%d==0&&M.push(F),E++;A.inputs=M}var R=s[n.uniqueId],w=4*A.inputs.length;_=m._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," keyframe data view")),l.push(_),A.inputs.forEach((function(e){u.setFloat32(e)})),g=m._CreateAccessor(l.length-1,"".concat(t," keyframes"),"SCALAR",5126,A.inputs.length,null,[A.inputsMin],[A.inputsMax]),c.push(g),x=c.length-1,T=A.outputs.length,w=4*m._GetDataAccessorElementCount(i)*A.outputs.length,_=m._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," data view")),l.push(_),A.outputs.forEach((function(e){e.forEach((function(e){u.setFloat32(e)}))})),g=m._CreateAccessor(l.length-1,"".concat(t," data"),i,5126,T,null,null,null),c.push(g),y=c.length-1,v={interpolation:A.samplerInterpolation,input:x,output:y},r.samplers.push(v),b={sampler:r.samplers.length-1,target:{node:R,path:o}},r.channels.push(b)}},e._CreateBakedAnimation=function(t,r,n,a,i,o,s,u,l,c,f,h){var p,_,m=d.Quaternion.Identity(),g=null,x=null,y=null,T=null,v=null,b=null;c.min=d.Tools.FloatRound(a/o);for(var A=r.getKeys(),E=0,F=A.length;E<F;++E){if(b=null,y=A[E],E+1<F)if(T=A[E+1],y.value.equals&&y.value.equals(T.value)||y.value===T.value){if(0!==E)continue;b=y.frame}else b=T.frame;else{if(v=A[E-1],y.value.equals&&y.value.equals(v.value)||y.value===v.value)continue;b=i}if(b)for(var M=y.frame;M<=b;M+=s)if((_=d.Tools.FloatRound(M/o))!==g){g=_,x=_;var R={key:0,repeatCount:0,loopMode:r.loopMode};p=r._interpolate(M,R),e._SetInterpolatedValue(t,p,_,r,n,m,u,l,f,h)}}x&&(c.max=x)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,a,i,o,s){var u,l,c=null,f=e._GetBasePositionRotationOrScale(r,i,o,s);if(a===d.Animation.ANIMATIONTYPE_FLOAT)switch(l=(u=n.targetProperty.split("."))?u[1]:"",c=s?d.Quaternion.FromArray(f).normalize():d.Vector3.FromArray(f),l){case"x":case"y":c[l]=o&&s&&"scale"!==i?-t:t;break;case"z":c[l]=o&&!s&&"scale"!==i?-t:t;break;case"w":c.w=t;break;default:d.Tools.Error('glTFAnimation: Unsupported component type "'.concat(l,'" for scale animation!'))}return c},e._SetInterpolatedValue=function(e,t,r,n,a,i,o,s,u,l){var c,f=n.dataType;if(o.push(r),t){if("weights"===a)return void s.push([t]);"number"==typeof t&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,f,a,u,l)),"rotation"===a?(l?i=t:(c=t,d.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,i)),u&&(m._GetRightHandedQuaternionFromRef(i),e.parent||(i=d.Quaternion.FromArray([0,1,0,0]).multiply(i))),s.push(i.asArray())):(c=t,u&&"scale"!==a&&(m._GetRightHandedPositionVector3FromRef(c),e.parent||(c.x*=-1,c.z*=-1)),s.push(c.asArray()))}},e._CreateLinearOrStepAnimation=function(t,r,n,a,i,o,s,u){for(var l=0,c=r.getKeys();l<c.length;l++){var f=c[l];i.push(f.frame/r.framePerSecond),e._AddKeyframeValue(f,r,o,n,t,s,u)}},e._CreateCubicSplineAnimation=function(t,r,n,a,i,o,s,u){r.getKeys().forEach((function(l){i.push(l.frame/r.framePerSecond),e._AddSplineTangent(t,p.INTANGENT,o,n,"CUBICSPLINE",l,a,u,s),e._AddKeyframeValue(l,r,o,n,t,s,u),e._AddSplineTangent(t,p.OUTTANGENT,o,n,"CUBICSPLINE",l,a,u,s)}))},e._GetBasePositionRotationOrScale=function(e,t,r,n){var a;if("rotation"===t)if(n){var i=e.rotationQuaternion;a=(null!=i?i:d.Quaternion.Identity()).asArray(),r&&(m._GetRightHandedQuaternionArrayFromRef(a),e.parent||(a=d.Quaternion.FromArray([0,1,0,0]).multiply(d.Quaternion.FromArray(a)).asArray()))}else{var o=e.rotation;a=(null!=o?o:d.Vector3.Zero()).asArray(),m._GetRightHandedNormalArray3FromRef(a)}else if("translation"===t){var s=e.position;a=(null!=s?s:d.Vector3.Zero()).asArray(),r&&m._GetRightHandedPositionArray3FromRef(a)}else{var u=e.scaling;a=(null!=u?u:d.Vector3.One()).asArray()}return a},e._AddKeyframeValue=function(e,t,r,n,a,i,o){var s,u,l=t.dataType;if(l===d.Animation.ANIMATIONTYPE_VECTOR3){if(s=e.value.asArray(),"rotation"===n){var c=d.Vector3.FromArray(s),f=d.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z);i&&(m._GetRightHandedQuaternionFromRef(f),a.parent||(f=d.Quaternion.FromArray([0,1,0,0]).multiply(f))),s=f.asArray()}else"translation"===n&&i&&(m._GetRightHandedNormalArray3FromRef(s),a.parent||(s[0]*=-1,s[2]*=-1));r.push(s)}else if(l===d.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(u=this._ConvertFactorToVector3OrQuaternion(e.value,a,t,l,n,i,o)){if("rotation"===n){var h=o?u:d.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).normalize();i&&(m._GetRightHandedQuaternionFromRef(h),a.parent||(h=d.Quaternion.FromArray([0,1,0,0]).multiply(h))),r.push(h.asArray())}else"translation"===n&&i&&(m._GetRightHandedNormalVector3FromRef(u),a.parent||(u.x*=-1,u.z*=-1));r.push(u.asArray())}}else l===d.Animation.ANIMATIONTYPE_QUATERNION?(s=e.value.normalize().asArray(),i&&(m._GetRightHandedQuaternionArrayFromRef(s),a.parent||(s=d.Quaternion.FromArray([0,1,0,0]).multiply(d.Quaternion.FromArray(s)).asArray())),r.push(s)):d.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,a,i=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var o=0,s=e.length;o<s;++o)if((a=e[o]).inTangent||a.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",i=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||a.interpolation&&a.interpolation===d.AnimationKeyInterpolation.STEP&&"STEP"!==n){n="LINEAR",i=!0;break}}else n=a.interpolation&&a.interpolation===d.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,t,r,n,a,i,o,s,u){var l,c=t===p.INTANGENT?i.inTangent:i.outTangent;if("CUBICSPLINE"===a){if("rotation"===n)if(c){if(s)l=c.asArray();else{var f=c;l=d.Quaternion.RotationYawPitchRoll(f.y,f.x,f.z).asArray()}u&&(m._GetRightHandedQuaternionArrayFromRef(l),e.parent||(l=d.Quaternion.FromArray([0,1,0,0]).multiply(d.Quaternion.FromArray(l)).asArray()))}else l=[0,0,0,0];else"weights"===n?l=c?[c]:[0]:c?(l=c.asArray(),u&&"translation"===n&&(m._GetRightHandedPositionArray3FromRef(l),e.parent||(l[0]*=-1,l[2]*=-1))):l=[0,0,0];r.push(l)}},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}(),x=function(){function e(e,t){this._includeCoordinateSystemConversionNodes=!1,this._extensions={},this._glTF={asset:{generator:"Babylon.js v".concat(d.Engine.Version),version:"2.0"}},(e=e||d.EngineStore.LastCreatedScene)&&(this._babylonScene=e,this._bufferViews=[],this._accessors=[],this._meshes=[],this._scenes=[],this._cameras=[],this._nodes=[],this._images=[],this._materials=[],this._materialMap=[],this._textures=[],this._samplers=[],this._skins=[],this._animations=[],this._imageData={},this._orderedImageData=[],this._options=t||{},this._animationSampleRate=t&&t.animationSampleRate?t.animationSampleRate:1/60,this._includeCoordinateSystemConversionNodes=!(!t||!t.includeCoordinateSystemConversionNodes),this._glTFMaterialExporter=new _(this),this._loadExtensions())}return e.prototype._applyExtension=function(e,t,r,n){var a=this;if(r>=t.length)return Promise.resolve(e);var i=n(t[r],e);return i?i.then((function(e){return a._applyExtension(e,t,r+1,n)})):this._applyExtension(e,t,r+1,n)},e.prototype._applyExtensions=function(t,r){for(var n=[],a=0,i=e._ExtensionNames;a<i.length;a++){var o=i[a];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._extensionsPostExportMeshPrimitiveAsync=function(e,t,r,n){return this._applyExtensions(t,(function(t,a){return t.postExportMeshPrimitiveAsync&&t.postExportMeshPrimitiveAsync(e,a,r,n)}))},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n,a){return this._applyExtensions(t,(function(t,i){return t.postExportNodeAsync&&t.postExportNodeAsync(e,i,r,n,a)}))},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 a=[],i=0,o=e._ExtensionNames;i<o.length;i++){var s=o[i],u=this._extensions[s];u.postExportMaterialAdditionalTextures&&a.push.apply(a,u.postExportMaterialAdditionalTextures(t,r,n))}return a},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var a=0,i=e._ExtensionNames;a<i.length;a++){var o=i[a],s=this._extensions[o];s.postExportTexture&&s.postExportTexture(t,r,n)}},e.prototype._forEachExtensions=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var a=n[r],i=this._extensions[a];i.enabled&&t(i)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){t.wasUsed&&(null==e._glTF.extensionsUsed&&(e._glTF.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&(null==e._glTF.extensionsRequired&&(e._glTF.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),null==e._glTF.extensions&&(e._glTF.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],a=e._ExtensionFactories[n](this);this._extensions[n]=a}},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._reorderIndicesBasedOnPrimitiveMode=function(e,t,r,n,a){switch(t){case d.Material.TriangleFillMode:n||(n=0);for(var i=e.indexStart,o=e.indexStart+e.indexCount;i<o;i+=3){var s=n+4*i,u=a.getUInt32(s+4),l=a.getUInt32(s+8);a.setUInt32(l,s+4),a.setUInt32(u,s+8)}break;case d.Material.TriangleFanDrawMode:i=e.indexStart+e.indexCount-1;for(var c=e.indexStart;i>=c;--i)a.setUInt32(r[i],n),n+=4;break;case d.Material.TriangleStripDrawMode:e.indexCount>=3&&(a.setUInt32(r[e.indexStart+2],n+4),a.setUInt32(r[e.indexStart+1],n+8))}},e.prototype._reorderVertexAttributeDataBasedOnPrimitiveMode=function(e,t,r,n,a,i,o,s){if(s&&r===d.Material.ClockWiseSideOrientation)switch(t){case d.Material.TriangleFillMode:this._reorderTriangleFillMode(e,t,r,n,a,i,o,s);break;case d.Material.TriangleStripDrawMode:this._reorderTriangleStripDrawMode(e,t,r,n,a,i,o,s);break;case d.Material.TriangleFanDrawMode:this._reorderTriangleFanMode(e,t,r,n,a,i,o,s)}},e.prototype._reorderTriangleFillMode=function(e,t,r,n,a,i,o,s){var u=this._getVertexBufferFromMesh(n,e.getMesh());if(u){var l=u.byteStride/d.VertexBuffer.GetTypeByteLength(u.type);if(e.verticesCount%3!=0)d.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var c=[],f=0;switch(n){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:for(var h=e.verticesStart;h<e.verticesStart+e.verticesCount;h+=3)f=h*l,c.push(d.Vector3.FromArray(a,f)),c.push(d.Vector3.FromArray(a,f+2*l)),c.push(d.Vector3.FromArray(a,f+l));break;case d.VertexBuffer.TangentKind:for(h=e.verticesStart;h<e.verticesStart+e.verticesCount;h+=3)f=h*l,c.push(d.Vector4.FromArray(a,f)),c.push(d.Vector4.FromArray(a,f+2*l)),c.push(d.Vector4.FromArray(a,f+l));break;case d.VertexBuffer.ColorKind:var p=u.getSize();for(h=e.verticesStart;h<e.verticesStart+e.verticesCount;h+=p)f=h*l,4===p?(c.push(d.Vector4.FromArray(a,f)),c.push(d.Vector4.FromArray(a,f+2*l)),c.push(d.Vector4.FromArray(a,f+l))):(c.push(d.Vector3.FromArray(a,f)),c.push(d.Vector3.FromArray(a,f+2*l)),c.push(d.Vector3.FromArray(a,f+l)));break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:for(h=e.verticesStart;h<e.verticesStart+e.verticesCount;h+=3)f=h*l,c.push(d.Vector2.FromArray(a,f)),c.push(d.Vector2.FromArray(a,f+2*l)),c.push(d.Vector2.FromArray(a,f+l));break;default:d.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this._writeVertexAttributeData(c,i,n,a,o,s)}}else d.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind ".concat(n," not present!"))},e.prototype._reorderTriangleStripDrawMode=function(e,t,r,n,a,i,o,s){var u=this._getVertexBufferFromMesh(n,e.getMesh());if(u){var l=u.byteStride/d.VertexBuffer.GetTypeByteLength(u.type),c=[],f=0;switch(n){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:f=e.verticesStart,c.push(d.Vector3.FromArray(a,f+2*l)),c.push(d.Vector3.FromArray(a,f+l));break;case d.VertexBuffer.TangentKind:for(var h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,c.push(d.Vector4.FromArray(a,f));break;case d.VertexBuffer.ColorKind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,4===u.getSize()?c.push(d.Vector4.FromArray(a,f)):c.push(d.Vector3.FromArray(a,f));break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,c.push(d.Vector2.FromArray(a,f));break;default:d.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this._writeVertexAttributeData(c,i+12,n,a,o,s)}else d.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind ".concat(n," not present!"))},e.prototype._reorderTriangleFanMode=function(e,t,r,n,a,i,o,s){var u=this._getVertexBufferFromMesh(n,e.getMesh());if(u){var l=u.byteStride/d.VertexBuffer.GetTypeByteLength(u.type),c=[],f=0;switch(n){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:for(var h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,c.push(d.Vector3.FromArray(a,f));break;case d.VertexBuffer.TangentKind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,c.push(d.Vector4.FromArray(a,f));break;case d.VertexBuffer.ColorKind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,c.push(d.Vector4.FromArray(a,f)),4===u.getSize()?c.push(d.Vector4.FromArray(a,f)):c.push(d.Vector3.FromArray(a,f));break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,c.push(d.Vector2.FromArray(a,f));break;default:d.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this._writeVertexAttributeData(c,i,n,a,o,s)}else d.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind ".concat(n," not present!"))},e.prototype._writeVertexAttributeData=function(e,t,r,n,a,i){for(var o=0,s=e;o<s.length;o++){var u=s[o];!i||r===d.VertexBuffer.ColorKind||u instanceof d.Vector2||(u instanceof d.Vector3?r===d.VertexBuffer.NormalKind?m._GetRightHandedNormalVector3FromRef(u):r===d.VertexBuffer.PositionKind?m._GetRightHandedPositionVector3FromRef(u):d.Tools.Error("Unsupported vertex attribute kind!"):m._GetRightHandedVector4FromRef(u)),r===d.VertexBuffer.NormalKind?u.normalize():r===d.VertexBuffer.TangentKind&&u instanceof d.Vector4&&m._NormalizeTangentFromRef(u);for(var l=0,c=u.asArray();l<c.length;l++){var f=c[l];a.setFloat32(f,t),t+=4}}},e.prototype._writeAttributeData=function(e,t,r,n,a,i,o){var s,u,l=[];switch(e){case d.VertexBuffer.PositionKind:for(var c=0,f=r.length/n;c<f;++c){s=c*n;var h=d.Vector3.FromArray(r,s);i&&m._GetRightHandedPositionVector3FromRef(h),l.push(h.asArray())}break;case d.VertexBuffer.NormalKind:c=0;for(var p=r.length/n;c<p;++c)s=c*n,h=d.Vector3.FromArray(r,s),i&&m._GetRightHandedNormalVector3FromRef(h),h.normalize(),l.push(h.asArray());break;case d.VertexBuffer.TangentKind:c=0;for(var _=r.length/n;c<_;++c)s=c*n,h=d.Vector4.FromArray(r,s),i&&m._GetRightHandedVector4FromRef(h),m._NormalizeTangentFromRef(h),l.push(h.asArray());break;case d.VertexBuffer.ColorKind:for(var g=o.material,x=!g||"StandardMaterial"===g.getClassName(),y=(h=3===n?new d.Color3:new d.Color4,c=0,r.length/n);c<y;++c)s=c*n,3===n?(d.Color3.FromArrayToRef(r,s,h),x&&h.toLinearSpaceToRef(h)):(d.Color4.FromArrayToRef(r,s,h),x&&h.toLinearSpaceToRef(h)),l.push(h.asArray());break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:c=0;for(var T=r.length/n;c<T;++c)s=c*n,l.push([r[s],r[s+1]]);break;case d.VertexBuffer.MatricesIndicesKind:case d.VertexBuffer.MatricesIndicesExtraKind:c=0;for(var v=r.length/n;c<v;++c)s=c*n,h=d.Vector4.FromArray(r,s),l.push(h.asArray());break;case d.VertexBuffer.MatricesWeightsKind:case d.VertexBuffer.MatricesWeightsExtraKind:c=0;for(var b=r.length/n;c<b;++c)s=c*n,h=d.Vector4.FromArray(r,s),l.push(h.asArray());break;default:d.Tools.Warn("Unsupported Vertex Buffer Type: "+e),l=[]}switch(t){case 5121:u=a.setUInt8.bind(a);break;case 5123:u=a.setUInt16.bind(a);break;case 5125:u=a.setUInt32.bind(a);break;case 5126:u=a.setFloat32.bind(a);break;default:return void d.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var A=0,E=l;A<E.length;A++)for(var F=0,M=E[A];F<M.length;F++)u(M[F])},e.prototype.writeMorphTargetAttributeData=function(e,t,r,n,a,i,o,s,u,l){var c,f,h=[],p=new d.Vector3,_=new d.Vector4(0,0,0,0);switch(e){case d.VertexBuffer.PositionKind:for(var g=r.verticesStart;g<r.verticesCount;++g){c=r.indexStart+g*o;var x=d.Vector3.FromArray(a,c);p=(y=d.Vector3.FromArray(i,c)).subtractToRef(x,p),u&&m._GetRightHandedPositionVector3FromRef(p),l&&(l.min.copyFromFloats(Math.min(p.x,l.min.x),Math.min(p.y,l.min.y),Math.min(p.z,l.min.z)),l.max.copyFromFloats(Math.max(p.x,l.max.x),Math.max(p.y,l.max.y),Math.max(p.z,l.max.z))),h.push(p.asArray())}break;case d.VertexBuffer.NormalKind:for(g=r.verticesStart;g<r.verticesCount;++g)c=r.indexStart+g*o,(x=d.Vector3.FromArray(a,c)).normalize(),(y=d.Vector3.FromArray(i,c)).normalize(),p=y.subtractToRef(x,p),u&&m._GetRightHandedNormalVector3FromRef(p),h.push(p.asArray());break;case d.VertexBuffer.TangentKind:for(g=r.verticesStart;g<r.verticesCount;++g){c=r.indexStart+g*(o+1),x=d.Vector4.FromArray(a,c),m._NormalizeTangentFromRef(x);var y=d.Vector4.FromArray(i,c);m._NormalizeTangentFromRef(y),_=y.subtractToRef(x,_),u&&m._GetRightHandedVector4FromRef(_),h.push([_.x,_.y,_.z])}break;default:d.Tools.Warn("Unsupported Vertex Buffer Type: "+e),h=[]}switch(t){case 5121:f=s.setUInt8.bind(s);break;case 5123:f=s.setUInt16.bind(s);break;case 5125:f=s.setUInt32.bind(s);break;case 5126:f=s.setFloat32.bind(s);break;default:return void d.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var T=0,v=h;T<v.length;T++)for(var b=0,A=v[T];b<A.length;b++)f(A[b])},e.prototype._generateJSON=function(e,t,r){var n,a,i,o=this,s={byteLength:this._totalByteLength},u=this._totalByteLength;return s.byteLength&&(this._glTF.buffers=[s]),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&&(e?(this._glTF.images=[],this._images.forEach((function(e){e.uri&&(a=o._imageData[e.uri],o._orderedImageData.push(a),n=e.uri.split(".")[0]+" image",i=m._CreateBufferView(0,u,a.data.length,void 0,n),u+=a.data.buffer.byteLength,o._bufferViews.push(i),e.bufferView=o._bufferViews.length-1,e.name=n,e.mimeType=a.mimeType,e.uri=void 0,o._glTF.images||(o._glTF.images=[]),o._glTF.images.push(e))})),s.byteLength=u):this._glTF.images=this._images),e||(s.uri=t+".bin"),r?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)},e.prototype._generateGLTFAsync=function(e,t){var r=this;return void 0===t&&(t=!0),this._generateBinaryAsync().then((function(n){r._extensionsOnExporting();var a=r._generateJSON(!1,e,!0),i=new Blob([n],{type:"application/octet-stream"}),o=e+".gltf",s=e+".bin",u=new l;if(u.glTFFiles[o]=a,u.glTFFiles[s]=i,r._imageData)for(var c in r._imageData)u.glTFFiles[c]=new Blob([r._imageData[c].data],{type:r._imageData[c].mimeType});return t&&r.dispose(),u}))},e.prototype._generateBinaryAsync=function(){var e=this,t=new y(4);return this._createSceneAsync(this._babylonScene,t).then((function(){return e._localEngine&&e._localEngine.dispose(),t.getArrayBuffer()}))},e.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},e.prototype._generateGLBAsync=function(e,t){var r=this;return void 0===t&&(t=!0),this._generateBinaryAsync().then((function(n){r._extensionsOnExporting();var a,i=r._generateJSON(!0),o=e+".glb",s=i.length,u=0;"undefined"!=typeof TextEncoder&&(s=(a=(new TextEncoder).encode(i)).length);for(var c=0;c<r._orderedImageData.length;++c)u+=r._orderedImageData[c].data.byteLength;var f=r._getPadding(s),h=r._getPadding(n.byteLength),p=r._getPadding(u),d=28+s+f+n.byteLength+h+u+p,_=new ArrayBuffer(12),m=new DataView(_);m.setUint32(0,1179937895,!0),m.setUint32(4,2,!0),m.setUint32(8,d,!0);var g=new ArrayBuffer(8+s+f),x=new DataView(g);x.setUint32(0,s+f,!0),x.setUint32(4,1313821514,!0);var y=new Uint8Array(g,8);if(a)y.set(a);else{var T="_".charCodeAt(0);for(c=0;c<s;++c){var v=i.charCodeAt(c);v!=i.codePointAt(c)?y[c]=T:y[c]=v}}var b=new Uint8Array(g,8+s);for(c=0;c<f;++c)b[c]=32;var A=new ArrayBuffer(8),E=new DataView(A);E.setUint32(0,n.byteLength+u+p,!0),E.setUint32(4,5130562,!0);var F=new ArrayBuffer(h),M=new Uint8Array(F);for(c=0;c<h;++c)M[c]=0;var R=new ArrayBuffer(p),w=new Uint8Array(R);for(c=0;c<p;++c)w[c]=0;var V=[_,g,A,n];for(c=0;c<r._orderedImageData.length;++c)V.push(r._orderedImageData[c].data.buffer);V.push(F),V.push(R);var C=new Blob(V,{type:"application/octet-stream"}),S=new l;return S.glTFFiles[o]=C,null!=r._localEngine&&r._localEngine.dispose(),t&&r.dispose(),S}))},e.prototype._setNodeTransformation=function(e,t,r){t.getPivotPoint().equalsToFloats(0,0,0)||d.Tools.Warn("Pivot points are not supported in the glTF serializer"),t.position.equalsToFloats(0,0,0)||(e.translation=r?m._GetRightHandedPositionVector3(t.position).asArray():t.position.asArray()),t.scaling.equalsToFloats(1,1,1)||(e.scale=t.scaling.asArray());var n=d.Quaternion.RotationYawPitchRoll(t.rotation.y,t.rotation.x,t.rotation.z);t.rotationQuaternion&&n.multiplyInPlace(t.rotationQuaternion),d.Quaternion.IsIdentity(n)||(r&&m._GetRightHandedQuaternionFromRef(n),e.rotation=n.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,r){t.position.equalsToFloats(0,0,0)||(e.translation=r?m._GetRightHandedPositionVector3(t.position).asArray():t.position.asArray());var n=t.rotationQuaternion;n&&!d.Quaternion.IsIdentity(n)&&(r&&m._GetRightHandedQuaternionFromRef(n),e.rotation=n.normalize().asArray())},e.prototype._getVertexBufferFromMesh=function(e,t){if(t.isVerticesDataPresent(e)){var r=t.getVertexBuffer(e);if(r)return r}return null},e.prototype._createBufferViewKind=function(e,t,r,n,a,i){var o=r instanceof d.Mesh?r:r instanceof d.InstancedMesh?r.sourceMesh:null;if(o){var s=o.getVertexBuffer(e),u=o.getVerticesData(e);if(s&&u){var l=d.VertexBuffer.GetTypeByteLength(t),c=u.length*l,f=m._CreateBufferView(0,n.getByteOffset(),c,a,e+" - "+o.name);this._bufferViews.push(f),this._writeAttributeData(e,t,u,a/l,n,i,r)}}},e.prototype._setMorphTargetAttributes=function(e,t,r,n,a){if(r){t.targets||(t.targets=[]);var i={};if(r.hasNormals){var o=e.getMesh().getVerticesData(d.VertexBuffer.NormalKind),s=r.getNormals(),u=(g=e.verticesCount)*(x=12),l=m._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_NORMAL");this._bufferViews.push(l);var c=this._bufferViews.length-1,f=m._CreateAccessor(c,r.name+" - NORMAL","VEC3",5126,g,0,null,null);this._accessors.push(f),i.NORMAL=this._accessors.length-1,this.writeMorphTargetAttributeData(d.VertexBuffer.NormalKind,5126,e,r,o,s,x/4,n,a)}if(r.hasPositions){var h=e.getMesh().getVerticesData(d.VertexBuffer.PositionKind),p=r.getPositions();u=(g=e.verticesCount)*(x=12),l=m._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_POSITION"),this._bufferViews.push(l),c=this._bufferViews.length-1;var _={min:new d.Vector3(1/0,1/0,1/0),max:new d.Vector3(-1/0,-1/0,-1/0)};f=m._CreateAccessor(c,r.name+" - POSITION","VEC3",5126,g,0,null,null),this._accessors.push(f),i.POSITION=this._accessors.length-1,this.writeMorphTargetAttributeData(d.VertexBuffer.PositionKind,5126,e,r,h,p,x/4,n,a,_),f.min=_.min.asArray(),f.max=_.max.asArray()}if(r.hasTangents){var g,x,y=e.getMesh().getVerticesData(d.VertexBuffer.TangentKind),T=r.getTangents();u=(g=e.verticesCount)*(x=12),l=m._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_NORMAL"),this._bufferViews.push(l),c=this._bufferViews.length-1,f=m._CreateAccessor(c,r.name+" - TANGENT","VEC3",5126,g,0,null,null),this._accessors.push(f),i.TANGENT=this._accessors.length-1,this.writeMorphTargetAttributeData(d.VertexBuffer.TangentKind,5126,e,r,y,T,x/4,n,a)}t.targets.push(i)}},e.prototype._getMeshPrimitiveMode=function(e){return e instanceof d.LinesMesh?d.Material.LineListDrawMode:e.material?e.material.fillMode:d.Material.TriangleFillMode},e.prototype._setPrimitiveMode=function(e,t){switch(t){case d.Material.TriangleFillMode:break;case d.Material.TriangleStripDrawMode:e.mode=5;break;case d.Material.TriangleFanDrawMode:e.mode=6;break;case d.Material.PointListDrawMode:case d.Material.PointFillMode:e.mode=0;break;case d.Material.LineLoopDrawMode:e.mode=2;break;case d.Material.LineListDrawMode:e.mode=1;break;case d.Material.LineStripDrawMode:e.mode=3}},e.prototype._setAttributeKind=function(e,t){switch(t){case d.VertexBuffer.PositionKind:e.attributes.POSITION=this._accessors.length-1;break;case d.VertexBuffer.NormalKind:e.attributes.NORMAL=this._accessors.length-1;break;case d.VertexBuffer.ColorKind:e.attributes.COLOR_0=this._accessors.length-1;break;case d.VertexBuffer.TangentKind:e.attributes.TANGENT=this._accessors.length-1;break;case d.VertexBuffer.UVKind:e.attributes.TEXCOORD_0=this._accessors.length-1;break;case d.VertexBuffer.UV2Kind:e.attributes.TEXCOORD_1=this._accessors.length-1;break;case d.VertexBuffer.MatricesIndicesKind:e.attributes.JOINTS_0=this._accessors.length-1;break;case d.VertexBuffer.MatricesIndicesExtraKind:e.attributes.JOINTS_1=this._accessors.length-1;break;case d.VertexBuffer.MatricesWeightsKind:e.attributes.WEIGHTS_0=this._accessors.length-1;break;case d.VertexBuffer.MatricesWeightsExtraKind:e.attributes.WEIGHTS_1=this._accessors.length-1;break;default:d.Tools.Warn("Unsupported Vertex Buffer Type: "+t)}},e.prototype._setPrimitiveAttributesAsync=function(e,t,r,n){var a,i,o,s=[],u=null;t instanceof d.Mesh?u=t:t instanceof d.InstancedMesh&&(u=t.sourceMesh);var l=[{kind:d.VertexBuffer.PositionKind,accessorType:"VEC3",accessorComponentType:5126,byteStride:12},{kind:d.VertexBuffer.NormalKind,accessorType:"VEC3",accessorComponentType:5126,byteStride:12},{kind:d.VertexBuffer.ColorKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:d.VertexBuffer.TangentKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:d.VertexBuffer.UVKind,accessorType:"VEC2",accessorComponentType:5126,byteStride:8},{kind:d.VertexBuffer.UV2Kind,accessorType:"VEC2",accessorComponentType:5126,byteStride:8},{kind:d.VertexBuffer.MatricesIndicesKind,accessorType:"VEC4",accessorComponentType:5123,byteStride:8},{kind:d.VertexBuffer.MatricesIndicesExtraKind,accessorType:"VEC4",accessorComponentType:5123,byteStride:8},{kind:d.VertexBuffer.MatricesWeightsKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:d.VertexBuffer.MatricesWeightsExtraKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16}];if(u){for(var c=null,f=this._getMeshPrimitiveMode(u),h={},p=u.morphTargetManager,_=0,g=l;_<g.length;_++){var x=(W=g[_]).kind,y=W.accessorComponentType;if(u.isVerticesDataPresent(x)){var T=this._getVertexBufferFromMesh(x,u);W.byteStride=T?T.getSize()*d.VertexBuffer.GetTypeByteLength(W.accessorComponentType):4*d.VertexBuffer.DeduceStride(x),12===W.byteStride&&(W.accessorType="VEC3"),this._createBufferViewKind(x,y,t,r,W.byteStride,n),W.bufferViewIndex=this._bufferViews.length-1,h[x]=W.bufferViewIndex}}if(u.getTotalIndices()){var v=u.getIndices();if(v){var b=4*v.length;i=m._CreateBufferView(0,r.getByteOffset(),b,void 0,"Indices - "+u.name),this._bufferViews.push(i),c=this._bufferViews.length-1;for(var A=0,E=v.length;A<E;++A)r.setUInt32(v[A])}}if(u.subMeshes)for(var F=0,M=u.subMeshes;F<M.length;F++){var R=M[F],w=R.getMaterial()||u.getScene().defaultMaterial,V=null;if(w)if(u instanceof d.LinesMesh){var C={name:u.name+" material"};(!u.color.equals(d.Color3.White())||u.alpha<1)&&(C.pbrMetallicRoughness={baseColorFactor:u.color.asArray().concat([u.alpha])}),this._materials.push(C),V=this._materials.length-1}else if(w instanceof d.MultiMaterial){var S=w.subMaterials[R.materialIndex];S&&(w=S,V=this._materialMap[w.uniqueId])}else V=this._materialMap[w.uniqueId];var I=null!=V?this._materials[V]:null,B={attributes:{}};this._setPrimitiveMode(B,f);for(var P=0,N=l;P<N.length;P++)if(((x=(W=N[P]).kind)!==d.VertexBuffer.UVKind&&x!==d.VertexBuffer.UV2Kind||this._options.exportUnusedUVs||I&&this._glTFMaterialExporter._hasTexturesPresent(I))&&(z=u.getVerticesData(x))&&(T=this._getVertexBufferFromMesh(x,u))){var L=T.getSize(),O=W.bufferViewIndex;if(null!=O){o={min:null,max:null},x==d.VertexBuffer.PositionKind&&(o=m._CalculateMinMaxPositions(z,0,z.length/L,n));var k=m._CreateAccessor(O,x+" - "+t.name,W.accessorType,W.accessorComponentType,z.length/L,0,o.min,o.max);this._accessors.push(k),this._setAttributeKind(B,x)}}if(c&&(k=m._CreateAccessor(c,"indices - "+t.name,"SCALAR",5125,R.indexCount,4*R.indexStart,null,null),this._accessors.push(k),B.indices=this._accessors.length-1),null!=V&&Object.keys(B.attributes).length>0){var U=null!==u.overrideMaterialSideOrientation?u.overrideMaterialSideOrientation:w.sideOrientation;if(U==d.Material.ClockWiseSideOrientation&&this._babylonScene.useRightHandedSystem||U==d.Material.ClockWiseSideOrientation&&n&&u.overrideMaterialSideOrientation!==(null===(a=u.material)||void 0===a?void 0:a.sideOrientation)){var G=null!=c?this._bufferViews[c].byteOffset:null;null==G&&(G=0);var K=null;if(null!=c&&(K=u.getIndices()),K)this._reorderIndicesBasedOnPrimitiveMode(R,f,K,G,r);else for(var D=0,H=l;D<H.length;D++){var z,W=H[D];if(z=u.getVerticesData(W.kind)){var q=this._bufferViews[h[W.kind]].byteOffset;q||(q=0),this._reorderVertexAttributeDataBasedOnPrimitiveMode(R,f,U,W.kind,z,q,r,n)}}}B.material=V}if(p)for(var Q=void 0,j=0;j<p.numTargets;++j)Q=p.getTarget(j),this._setMorphTargetAttributes(R,B,Q,r,n);e.primitives.push(B),this._extensionsPostExportMeshPrimitiveAsync("postExport",B,R,r),s.push()}}return Promise.all(s).then((function(){}))},e.prototype._isBabylonCoordinateSystemConvertingNode=function(e){return e instanceof d.TransformNode&&"__root__"===e.name&&1!==e.getWorldMatrix().determinant()&&!(e instanceof d.Mesh&&null!==e.geometry||e instanceof d.InstancedMesh&&null!==e.sourceMesh.geometry)&&!this._includeCoordinateSystemConversionNodes},e.prototype._createSceneAsync=function(e,t){var r,n,a,i=this,o={nodes:[]},s=h(h(h(h([],e.transformNodes,!0),e.meshes,!0),e.lights,!0),e.cameras,!0),u=[];this._convertToRightHandedSystem=!e.useRightHandedSystem,this._convertToRightHandedSystemMap={},e.rootNodes.forEach((function(e){i._convertToRightHandedSystemMap[e.uniqueId]=i._convertToRightHandedSystem,e.getDescendants(!1).forEach((function(e){i._convertToRightHandedSystemMap[e.uniqueId]=i._convertToRightHandedSystem}))})),e.rootNodes.forEach((function(e){if(i._isBabylonCoordinateSystemConvertingNode(e)){u.push(e);var t=s.indexOf(e);-1!==t&&s.splice(t,1),e.getDescendants(!1).forEach((function(e){i._convertToRightHandedSystemMap[e.uniqueId]=!1}))}}));var l=new Map;e.cameras.forEach((function(e){if(!i._options.shouldExportNode||i._options.shouldExportNode(e)){var t={type:e.mode===d.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(e.name&&(t.name=e.name),"perspective"===t.type)t.perspective={aspectRatio:e.getEngine().getAspectRatio(e),yfov:e.fovMode===d.Camera.FOVMODE_VERTICAL_FIXED?e.fov:e.fov*e.getEngine().getAspectRatio(e),znear:e.minZ,zfar:e.maxZ};else if("orthographic"===t.type){var r=e.orthoLeft&&e.orthoRight?.5*(e.orthoRight-e.orthoLeft):.5*e.getEngine().getRenderWidth(),n=e.orthoBottom&&e.orthoTop?.5*(e.orthoTop-e.orthoBottom):.5*e.getEngine().getRenderHeight();t.orthographic={xmag:r,ymag:n,znear:e.minZ,zfar:e.maxZ}}l.set(e,i._cameras.length),i._cameras.push(t)}}));var c=this._getExportNodes(s),f=c[0],p=c[1];return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(p,"image/png",!0).then((function(){return i._createNodeMapAndAnimationsAsync(e,f,t).then((function(c){return i._createSkinsAsync(e,c,t).then((function(e){if(i._nodeMap=c,i._totalByteLength=t.getByteOffset(),null==i._totalByteLength)throw new Error("undefined byte length!");for(var f=0,h=s;f<h.length;f++){var p=h[f];if(void 0!==(r=i._nodeMap[p.uniqueId])){if(n=i._nodes[r],p.metadata&&(i._options.metadataSelector?n.extras=i._options.metadataSelector(p.metadata):p.metadata.gltf&&(n.extras=p.metadata.gltf.extras)),p instanceof d.Camera&&(n.camera=l.get(p)),p.parent&&-1===u.indexOf(p.parent)||(i._options.shouldExportNode&&!i._options.shouldExportNode(p)?d.Tools.Log("Omitting "+p.name+" from scene."):(i._convertToRightHandedSystemMap[p.uniqueId]&&(n.translation&&(n.translation[2]*=-1,n.translation[0]*=-1),n.rotation=n.rotation?d.Quaternion.FromArray([0,1,0,0]).multiply(d.Quaternion.FromArray(n.rotation)).asArray():d.Quaternion.FromArray([0,1,0,0]).asArray()),o.nodes.push(r))),p instanceof d.Mesh){var _=p;_.skeleton&&(n.skin=e[_.skeleton.uniqueId])}if(a=p.getDescendants(!0),!n.children&&a&&a.length){for(var m=[],g=0,x=a;g<x.length;g++){var y=x[g];null!=i._nodeMap[y.uniqueId]&&m.push(i._nodeMap[y.uniqueId])}m.length&&(n.children=m)}}}o.nodes.length&&i._scenes.push(o)}))}))}))},e.prototype._getExportNodes=function(e){for(var t=[],r=new Set,n=0,a=e;n<a.length;n++){var i=a[n];if(!this._options.shouldExportNode||this._options.shouldExportNode(i)){t.push(i);var o=i;if(o.subMeshes&&o.subMeshes.length>0){var s=o.material||o.getScene().defaultMaterial;if(s instanceof d.MultiMaterial)for(var u=0,l=s.subMaterials;u<l.length;u++){var c=l[u];c&&r.add(c)}else r.add(s)}}else"Excluding node ".concat(i.name)}return[t,r]},e.prototype._createNodeMapAndAnimationsAsync=function(e,t,r){for(var n,a=this,i=Promise.resolve(),o={},s={name:"runtime animations",channels:[],samplers:[]},u=[],l=function(t){i=i.then((function(){var i=a._convertToRightHandedSystemMap[t.uniqueId];return a._createNodeAsync(t,r,i).then((function(l){var c=a._extensionsPostExportNodeAsync("createNodeAsync",l,t,o,r);return null==c?(d.Tools.Warn("Not exporting node ".concat(t.name)),Promise.resolve()):c.then((function(l){l&&(a._nodes.push(l),n=a._nodes.length-1,o[t.uniqueId]=n,e.animationGroups.length||(g._CreateMorphTargetAnimationFromMorphTargetAnimations(t,s,u,o,a._nodes,r,a._bufferViews,a._accessors,i,a._animationSampleRate),t.animations.length&&g._CreateNodeAnimationFromNodeAnimations(t,s,u,o,a._nodes,r,a._bufferViews,a._accessors,i,a._animationSampleRate)))}))}))}))},c=0,f=t;c<f.length;c++)l(f[c]);return i.then((function(){return s.channels.length&&s.samplers.length&&a._animations.push(s),u.forEach((function(e){e.channels.length&&e.samplers.length&&a._animations.push(e)})),e.animationGroups.length&&g._CreateNodeAndMorphAnimationFromAnimationGroups(e,a._animations,o,a._nodes,r,a._bufferViews,a._accessors,a._convertToRightHandedSystemMap,a._animationSampleRate),o}))},e.prototype._createNodeAsync=function(e,t,r){var n=this;return Promise.resolve().then((function(){var a={},i={primitives:[]};if(e.name&&(a.name=e.name),e instanceof d.TransformNode){if(n._setNodeTransformation(a,e,r),e instanceof d.Mesh){var o=e.morphTargetManager;if(o&&o.numTargets>0){i.weights=[];for(var s=0;s<o.numTargets;++s)i.weights.push(o.getTarget(s).influence)}}return n._setPrimitiveAttributesAsync(i,e,t,r).then((function(){return i.primitives.length&&(n._meshes.push(i),a.mesh=n._meshes.length-1),a}))}return e instanceof d.Camera?(n._setCameraTransformation(a,e,r),a):a}))},e.prototype._createSkinsAsync=function(e,t,r){for(var n,a=Promise.resolve(),i={},o=0,s=e.skeletons;o<s.length;o++){var u=s[o];if(!(u.bones.length<=0)){for(var l={joints:[]},c=[],f={},h=-1,p=0;p<u.bones.length;++p)-1!==(_=null!==(n=(g=u.bones[p]).getIndex())&&void 0!==n?n:p)&&(f[_]=g,_>h&&(h=_));for(var _=0;_<=h;++_){var g=f[_];c.push(g.getInvertedAbsoluteTransform());var x=g.getTransformNode();x?l.joints.push(t[x.uniqueId]):d.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}var y=64*c.length,T=r.getByteOffset(),v=m._CreateBufferView(0,T,y,void 0,"InverseBindMatrices - "+u.name);this._bufferViews.push(v);var b=this._bufferViews.length-1,A=m._CreateAccessor(b,"InverseBindMatrices - "+u.name,"MAT4",5126,c.length,null,null,null),E=this._accessors.push(A)-1;l.inverseBindMatrices=E,this._skins.push(l),i[u.uniqueId]=this._skins.length-1,c.forEach((function(e){e.m.forEach((function(e){r.setFloat32(e)}))}))}}return a.then((function(){return i}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),y=function(){function e(e){this._arrayBuffer=new ArrayBuffer(e),this._dataView=new DataView(this._arrayBuffer),this._byteOffset=0}return e.prototype._resizeBuffer=function(e){for(var t=new ArrayBuffer(e),r=new Uint8Array(this._arrayBuffer),n=new Uint8Array(t),a=0,i=n.byteLength;a<i;++a)n[a]=r[a];return this._arrayBuffer=t,this._dataView=new DataView(this._arrayBuffer),t},e.prototype.getArrayBuffer=function(){return this._resizeBuffer(this.getByteOffset())},e.prototype.getByteOffset=function(){if(null==this._byteOffset)throw new Error("Byte offset is undefined!");return this._byteOffset},e.prototype.setUInt8=function(e,t){null!=t?t<this._byteOffset?this._dataView.setUint8(t,e):d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+1>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint8(this._byteOffset,e),this._byteOffset+=1)},e.prototype.setUInt16=function(e,t){null!=t?t<this._byteOffset?this._dataView.setUint16(t,e,!0):d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+2>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2)},e.prototype.getUInt32=function(e){if(e<this._byteOffset)return this._dataView.getUint32(e,!0);throw d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"),new Error("BinaryWriter: byteoffset is greater than the current binary buffer length!")},e.prototype.getVector3Float32FromRef=function(e,t){t+8>this._byteOffset?d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(e.x=this._dataView.getFloat32(t,!0),e.y=this._dataView.getFloat32(t+4,!0),e.z=this._dataView.getFloat32(t+8,!0))},e.prototype.setVector3Float32FromRef=function(e,t){t+8>this._byteOffset?d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(t,e.x,!0),this._dataView.setFloat32(t+4,e.y,!0),this._dataView.setFloat32(t+8,e.z,!0))},e.prototype.getVector4Float32FromRef=function(e,t){t+12>this._byteOffset?d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(e.x=this._dataView.getFloat32(t,!0),e.y=this._dataView.getFloat32(t+4,!0),e.z=this._dataView.getFloat32(t+8,!0),e.w=this._dataView.getFloat32(t+12,!0))},e.prototype.setVector4Float32FromRef=function(e,t){t+12>this._byteOffset?d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(t,e.x,!0),this._dataView.setFloat32(t+4,e.y,!0),this._dataView.setFloat32(t+8,e.z,!0),this._dataView.setFloat32(t+12,e.w,!0))},e.prototype.setFloat32=function(e,t){isNaN(e)&&d.Tools.Error("Invalid data being written!"),null!=t&&(t<this._byteOffset?this._dataView.setFloat32(t,e,!0):d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary length!")),this._byteOffset+4>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.setUInt32=function(e,t){null!=t?t<this._byteOffset?this._dataView.setUint32(t,e,!0):d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+4>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4)},e.prototype.setInt16=function(e,t){null!=t?t<this._byteOffset?this._dataView.setInt16(t,e,!0):d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+2>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setInt16(this._byteOffset,e,!0),this._byteOffset+=2)},e.prototype.setByte=function(e,t){null!=t?t<this._byteOffset?this._dataView.setInt8(t,e):d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+1>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setInt8(this._byteOffset,e),this._byteOffset++)},e}(),T=function(){function e(){}return e.GLTFAsync=function(e,t,r){return e.whenReadyAsync().then((function(){var n=t.replace(/\.[^/.]+$/,"");return new x(e,r)._generateGLTFAsync(n)}))},e._PreExportAsync=function(e,t){return Promise.resolve().then((function(){return t&&t.exportWithoutWaitingForScene?Promise.resolve():e.whenReadyAsync()}))},e._PostExportAsync=function(e,t,r){return Promise.resolve().then((function(){return r&&r.exportWithoutWaitingForScene,t}))},e.GLBAsync=function(e,t,r){var n=this;return this._PreExportAsync(e,r).then((function(){var a=t.replace(/\.[^/.]+$/,"");return new x(e,r)._generateGLBAsync(a).then((function(t){return n._PostExportAsync(e,t,r)}))}))},e}();d.ShaderStore.ShadersStore.textureTransformPixelShader="precision highp float;varying vec2 vUV;uniform sampler2D textureSampler;uniform mat4 textureTransformMat;void main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\nvec2 uvTransformed=(textureTransformMat*vec4(vUV.xy,1,1)).xy;gl_FragColor=texture2D(textureSampler,uvTransformed);\n#define CUSTOM_FRAGMENT_MAIN_END\n}";var v="KHR_texture_transform",b=function(){function e(){this._recordedTextures=[],this.name=v,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){for(var e=0,t=this._recordedTextures;e<t.length;e++)t[e].dispose()},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportTexture=function(e,t,r){if(r&&(0===r.uAng&&0===r.wAng&&0===r.vAng||0===r.uRotationCenter&&0===r.vRotationCenter)){var n={},a=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],a=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],a=!0),0!==r.wAng&&(n.rotation=r.wAng,a=!0),0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,a=!0),!a)return;this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[v]=n}},e.prototype.preExportTextureAsync=function(e,t){var r=this;return new Promise((function(n,a){var i=t.getScene();if(i){var o=!1;if(0===t.uAng&&0===t.wAng&&0===t.vAng||0===t.uRotationCenter&&0===t.vRotationCenter||(o=!0),o)return r._textureTransformTextureAsync(t,i).then((function(e){n(e)})).catch((function(e){a(e)}));n(t)}else a("".concat(e,': "scene" is not defined for Babylon texture ').concat(t.name,"!"))}))},e.prototype._textureTransformTextureAsync=function(e,t){var r=this;return new Promise((function(n){var a=new d.ProceduralTexture("".concat(e.name),e.getSize(),"textureTransform",t);a||(d.Tools.Log("Cannot create procedural texture for ".concat(e.name,"!")),n(e)),a.reservedDataStore={hidden:!0,source:e},r._recordedTextures.push(a),a.coordinatesIndex=e.coordinatesIndex,a.setTexture("textureSampler",e),a.setMatrix("textureTransformMat",e.getTextureMatrix()),a.isReady()?(a.render(),n(a)):a.getEffect().executeWhenCompiled((function(){a.render(),n(a)}))}))},e}();x.RegisterExtension(v,(function(){return new b}));var A="KHR_lights_punctual",E=function(){function e(e){this.name=A,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.KHR_lights_punctual=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,n){var a=this;return new Promise((function(i){if(t&&r instanceof d.ShadowLight){var o=r,s=void 0,u=o.getTypeID()==d.Light.LIGHTTYPEID_POINTLIGHT?"point":o.getTypeID()==d.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":o.getTypeID()==d.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(null==u)d.Logger.Warn("".concat(e,": Light ").concat(o.name," is not supported in ").concat(A));else{var l=o.position.clone(),c=a._exporter._convertToRightHandedSystemMap[r.uniqueId];if(l.equals(d.Vector3.Zero())||(c&&m._GetRightHandedPositionVector3FromRef(l),t.translation=l.asArray()),"point"!==u){var f=o.direction,h=-Math.atan2(f.z*(a._exporter._babylonScene.useRightHandedSystem?-1:1),f.x)+Math.PI/2,p=Math.sqrt(f.x*f.x+f.z*f.z),_=-Math.atan2(f.y,p),g=d.Quaternion.RotationYawPitchRoll(h,_,0);c&&m._GetRightHandedQuaternionFromRef(g),g.equals(d.Quaternion.Identity())||(t.rotation=g.asArray())}if(o.falloffType!==d.Light.FALLOFF_GLTF&&d.Logger.Warn("".concat(e,": Light falloff for ").concat(o.name," does not match the ").concat(A," specification!")),s={type:u},o.diffuse.equals(d.Color3.White())||(s.color=o.diffuse.asArray()),1!==o.intensity&&(s.intensity=o.intensity),o.range!==Number.MAX_VALUE&&(s.range=o.range),"spot"===u){var x=o;x.angle!==Math.PI/2&&(null==s.spot&&(s.spot={}),s.spot.outerConeAngle=x.angle/2),0!==x.innerAngle&&(null==s.spot&&(s.spot={}),s.spot.innerConeAngle=x.innerAngle/2)}null==a._lights&&(a._lights={lights:[]}),a._lights.lights.push(s);var y={light:a._lights.lights.length-1},T=r.parent;if(T&&1==T.getChildren().length){var v=a._exporter._nodes[n[T.uniqueId]];if(v){var b=d.TmpVectors.Matrix[0],E=d.TmpVectors.Matrix[1],F=v.translation?new d.Vector3(v.translation[0],v.translation[1],v.translation[2]):d.Vector3.Zero(),M=v.rotation?new d.Quaternion(v.rotation[0],v.rotation[1],v.rotation[2],v.rotation[3]):d.Quaternion.Identity(),R=v.scale?new d.Vector3(v.scale[0],v.scale[1],v.scale[2]):d.Vector3.One();d.Matrix.ComposeToRef(R,M,F,b),b.invertToRef(E);var w=d.TmpVectors.Matrix[2],V=t.translation?new d.Vector3(t.translation[0],t.translation[1],t.translation[2]):d.Vector3.Zero();o instanceof d.DirectionalLight&&V.subtractInPlace(a._exporter._babylonScene.useRightHandedSystem?o.direction:m._GetRightHandedPositionVector3(o.direction));var C=a._exporter._babylonScene.useRightHandedSystem?d.Quaternion.Identity():new d.Quaternion(0,1,0,0);t.rotation&&C.multiplyInPlace(new d.Quaternion(t.rotation[0],t.rotation[1],t.rotation[2],t.rotation[3]));var S=t.scale?new d.Vector3(t.scale[0],t.scale[1],t.scale[2]):d.Vector3.One();d.Matrix.ComposeToRef(S,C,V,w),w.multiplyToRef(E,w);var I=d.TmpVectors.Vector3[0],B=d.TmpVectors.Quaternion[0],P=d.TmpVectors.Vector3[1];return w.decompose(I,B,P),v.scale=I.asArray(),v.rotation=B.asArray(),v.translation=P.asArray(),null==v.extensions&&(v.extensions={}),v.extensions.KHR_lights_punctual=y,void i(null)}}null==t.extensions&&(t.extensions={}),t.extensions.KHR_lights_punctual=y}}i(t)}))},e}();x.RegisterExtension(A,(function(e){return new E(e)}));var F="KHR_materials_clearcoat",M=function(){function e(e){this.name=F,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 a,i=n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.texture);a=r.clearCoat.useRoughnessFromMainTexture?n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.texture):n._exporter._glTFMaterialExporter._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._glTFMaterialExporter._getTextureInfo(r.clearCoat.bumpTexture),s={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=i?i:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=a?a:void 0,clearcoatNormalTexture:null!=o?o:void 0,hasTextures:function(){return null!==s.clearcoatTexture||null!==s.clearcoatRoughnessTexture||null!==s.clearcoatRoughnessTexture}};t.extensions.KHR_materials_clearcoat=s}e(t)}))},e}();x.RegisterExtension(F,(function(e){return new M(e)}));var R="KHR_materials_iridescence",w=function(){function e(e){this.name=R,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 a=n._exporter._glTFMaterialExporter._getTextureInfo(r.iridescence.texture),i=n._exporter._glTFMaterialExporter._getTextureInfo(r.iridescence.thicknessTexture),o={iridescenceFactor:r.iridescence.intensity,iridescenceIor:r.iridescence.indexOfRefraction,iridescenceThicknessMinimum:r.iridescence.minimumThickness,iridescenceThicknessMaximum:r.iridescence.maximumThickness,iridescenceTexture:null!=a?a:void 0,iridescenceThicknessTexture:null!=i?i:void 0,hasTextures:function(){return null!==o.iridescenceTexture||null!==o.iridescenceThicknessTexture}};t.extensions.KHR_materials_iridescence=o}e(t)}))},e}();x.RegisterExtension(R,(function(e){return new w(e)}));var V="KHR_materials_sheen",C=function(){function e(e){this.name=V,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){return r instanceof d.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[r.sheen.texture]:[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var a,i,o,s;if(r instanceof d.PBRMaterial){if(!r.sheen.isEnabled)return void e(t);n._wasUsed=!0,null==t.extensions&&(t.extensions={});var u={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(a=r.sheen.roughness)&&void 0!==a?a:0,hasTextures:function(){return null!==u.sheenColorTexture||null!==u.sheenRoughnessTexture}};r.sheen.texture&&(u.sheenColorTexture=null!==(i=n._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.texture))&&void 0!==i?i:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(o=n._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.textureRoughness))&&void 0!==o?o:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(s=n._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.texture))&&void 0!==s?s:void 0),t.extensions.KHR_materials_sheen=u}e(t)}))},e}();x.RegisterExtension(V,(function(e){return new C(e)}));var S="KHR_materials_unlit",I=function(){function e(){this.name=S,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 a=!1;r instanceof d.PBRMaterial?a=r.unlit:r instanceof d.StandardMaterial&&(a=r.disableLighting),a&&(n._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions.KHR_materials_unlit={}),e(t)}))},e}();x.RegisterExtension(S,(function(){return new I}));var B="KHR_materials_ior",P=function(){function e(){this.name=B,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 a={ior:r.indexOfRefraction};t.extensions=t.extensions||{},t.extensions.KHR_materials_ior=a}e(t)}))},e}();x.RegisterExtension(B,(function(e){return new P}));var N="KHR_materials_specular",L=function(){function e(e){this.name=N,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 a,i;if(r instanceof d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0,t.extensions=t.extensions||{};var o=null!==(a=n._exporter._glTFMaterialExporter._getTextureInfo(r.metallicReflectanceTexture))&&void 0!==a?a:void 0,s=null!==(i=n._exporter._glTFMaterialExporter._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:s,hasTextures:function(){return n._hasTexturesExtension(r)}};t.extensions.KHR_materials_specular=u}e(t)}))},e}();x.RegisterExtension(N,(function(e){return new L(e)}));var O="KHR_materials_volume",k=function(){function e(e){this.name=O,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 a;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!==(a=n._exporter._glTFMaterialExporter._getTextureInfo(i.thicknessTexture))&&void 0!==a?a:void 0,attenuationDistance:i.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:i.tintColorAtDistance,attenuationColor:i.tintColor.equalsFloats(1,1,1)?void 0:i.tintColor.asArray(),hasTextures:function(){return n._hasTexturesExtension(r)}};t.extensions=t.extensions||{},t.extensions.KHR_materials_volume=o}e(t)}))},e}();x.RegisterExtension(O,(function(e){return new k(e)}));var U="KHR_materials_transmission",G=function(){function e(e){this.name=U,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){var n=this;return new Promise((function(e){var a;if(r instanceof d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var i=r.subSurface,o={transmissionFactor:0===i.refractionIntensity?void 0:i.refractionIntensity,transmissionTexture:null!==(a=n._exporter._glTFMaterialExporter._getTextureInfo(i.refractionIntensityTexture))&&void 0!==a?a:void 0,hasTextures:function(){return n._hasTexturesExtension(r)}};t.extensions=t.extensions||{},t.extensions.KHR_materials_transmission=o}e(t)}))},e}();x.RegisterExtension(U,(function(e){return new G(e)}));var K="EXT_mesh_gpu_instancing",D=function(){function e(e){this.name=K,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,a){var i=this;return new Promise((function(e){if(t&&r instanceof d.Mesh&&r.hasThinInstances&&a){i._wasUsed=!0;for(var n=d.Vector3.Zero(),o=d.Quaternion.Identity(),s=d.Vector3.One(),u=r.thinInstanceGetWorldMatrices(),l=d.TmpVectors.Vector3[2],c=d.TmpVectors.Quaternion[1],f=d.TmpVectors.Vector3[3],h=!1,p=!1,_=!1,m=new Float32Array(3*r.thinInstanceCount),g=new Float32Array(4*r.thinInstanceCount),x=new Float32Array(3*r.thinInstanceCount),y=0,T=0,v=u;T<v.length;T++)v[T].decompose(f,c,l),m.set(l.asArray(),3*y),g.set(c.normalize().asArray(),4*y),x.set(f.asArray(),3*y),h=h||!l.equalsWithEpsilon(n),p=p||!c.equalsWithEpsilon(o),_=_||!f.equalsWithEpsilon(s),y++;var b={attributes:{}};h&&(b.attributes.TRANSLATION=i._buildAccessor(m,"VEC3",r.thinInstanceCount,a,5126)),p&&(b.attributes.ROTATION=i._buildAccessor(g,"VEC4",r.thinInstanceCount,a,5126)),_&&(b.attributes.SCALE=i._buildAccessor(x,"VEC3",r.thinInstanceCount,a,5126)),t.extensions=t.extensions||{},t.extensions.EXT_mesh_gpu_instancing=b}e(t)}))},e.prototype._buildAccessor=function(e,t,r,n,a){var i=n.getByteOffset();switch(a){case 5126:for(var o=0;o!=e.length;o++)n.setFloat32(e[o]);break;case 5120:for(o=0;o!=e.length;o++)n.setByte(127*e[o]);break;case 5122:for(o=0;o!=e.length;o++)n.setInt16(32767*e[o])}var s={buffer:0,byteOffset:i,byteLength:e.length*d.VertexBuffer.GetTypeByteLength(a)},u=this._exporter._bufferViews.length;this._exporter._bufferViews.push(s);var l=this._exporter._accessors.length,c={bufferView:u,componentType:a,count:r,type:t,normalized:5120==a||5122==a};return this._exporter._accessors.push(c),l},e}();x.RegisterExtension(K,(function(e){return new D(e)}));var H=0,z=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==z){z.BABYLON=z.BABYLON||{};var W=z.BABYLON;W.GLTF2=W.GLTF2||{},W.GLTF2.Exporter=W.GLTF2.Exporter||{},W.GLTF2.Exporter.Extensions=W.GLTF2.Exporter.Extensions||{};var q=[];for(var Q in e)W[Q]=e[Q],q.push(Q);for(var Q in t)W[Q]=t[Q],q.push(Q);for(var Q in r)W[Q]=r[Q],q.push(Q);for(var Q in i)W.GLTF2.Exporter.Extensions[Q]=i[Q],q.push(Q);for(var Q in o)q.indexOf(Q)>-1||(W.GLTF2.Exporter[Q]=o[Q])}const j=s})(),a.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={520:t=>{t.exports=e}},r={};function n(e){var a=r[e];if(void 0!==a)return a.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return(()=>{n.d(a,{default:()=>j});var e={};n.r(e),n.d(e,{__IGLTFExporterExtension:()=>u});var t={};n.r(t),n.d(t,{GLTFData:()=>l});var r={};n.r(r),n.d(r,{GLTF2Export:()=>T});var i={};n.r(i),n.d(i,{EXT_mesh_gpu_instancing:()=>D,KHR_lights_punctual:()=>E,KHR_materials_clearcoat:()=>M,KHR_materials_ior:()=>P,KHR_materials_iridescence:()=>w,KHR_materials_sheen:()=>C,KHR_materials_specular:()=>O,KHR_materials_transmission:()=>K,KHR_materials_unlit:()=>I,KHR_materials_volume:()=>k,KHR_texture_transform:()=>b});var o={};n.r(o),n.d(o,{EXT_mesh_gpu_instancing:()=>D,GLTF2Export:()=>T,GLTFData:()=>l,KHR_lights_punctual:()=>E,KHR_materials_clearcoat:()=>M,KHR_materials_ior:()=>P,KHR_materials_iridescence:()=>w,KHR_materials_sheen:()=>C,KHR_materials_specular:()=>O,KHR_materials_transmission:()=>K,KHR_materials_unlit:()=>I,KHR_materials_volume:()=>k,KHR_texture_transform:()=>b,_BinaryWriter:()=>y,_Exporter:()=>x,_GLTFAnimation:()=>g,_GLTFMaterialExporter:()=>_,_GLTFUtilities:()=>m,__IGLTFExporterExtensionV2:()=>H});var s={};n.r(s),n.d(s,{EXT_mesh_gpu_instancing:()=>D,GLTF2Export:()=>T,GLTFData:()=>l,KHR_lights_punctual:()=>E,KHR_materials_clearcoat:()=>M,KHR_materials_ior:()=>P,KHR_materials_iridescence:()=>w,KHR_materials_sheen:()=>C,KHR_materials_specular:()=>O,KHR_materials_transmission:()=>K,KHR_materials_unlit:()=>I,KHR_materials_volume:()=>k,KHR_texture_transform:()=>b,_BinaryWriter:()=>y,_Exporter:()=>x,_GLTFAnimation:()=>g,_GLTFMaterialExporter:()=>_,_GLTFUtilities:()=>m,__IGLTFExporterExtension:()=>u,__IGLTFExporterExtensionV2:()=>H});var u=0,l=function(){function e(){this.glTFFiles={}}return e.prototype.downloadFiles=function(){function e(e,t){return-1!==e.indexOf(t,e.length-t.length)}for(var t in this.glTFFiles){var r=document.createElement("a");document.body.appendChild(r),r.setAttribute("type","hidden"),r.download=t;var n=this.glTFFiles[t],a=void 0;e(t,".glb")?a={type:"model/gltf-binary"}:e(t,".bin")?a={type:"application/octet-stream"}:e(t,".gltf")?a={type:"model/gltf+json"}:e(t,".jpeg")||e(t,".jpg")?a={type:"image/jpeg"}:e(t,".png")&&(a={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([n],a)),r.click()}},e}();function c(e,t,r,n){return new(r||(r=Promise))((function(a,i){function o(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,s)}u((n=n.apply(e,t||[])).next())}))}function f(e,t){var r,n,a,i,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(a=2&i[0]?n.return:i[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,i[1])).done)return a;switch(n=0,a&&(i=[2&i[0],a.value]),i[0]){case 0:case 1:a=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,n=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!((a=(a=o.trys).length>0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]<a[3])){o.label=i[1];break}if(6===i[0]&&o.label<a[1]){o.label=a[1],a=i;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(i);break}a[2]&&o.ops.pop(),o.trys.pop();continue}i=t.call(e,o)}catch(e){i=[6,e],n=0}finally{r=a=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function h(e,t,r){if(r||2===arguments.length)for(var n,a=0,i=t.length;a<i;a++)!n&&a in t||(n||(n=Array.prototype.slice.call(t,0,a)),n[a]=t[a]);return e.concat(n||Array.prototype.slice.call(t))}Object.create,Object.create;var p,d=n(520),_=function(){function e(e){this._textureMap={},this._internalTextureToImage={},this._textureMap={},this._exporter=e}return e._FuzzyEquals=function(e,t,r){return d.Scalar.WithinEpsilon(e.r,t.r,r)&&d.Scalar.WithinEpsilon(e.g,t.g,r)&&d.Scalar.WithinEpsilon(e.b,t.b,r)},e.prototype._convertMaterialsToGLTFAsync=function(e,t,r){var n=this,a=[];return e.forEach((function(e){"StandardMaterial"===e.getClassName()?a.push(n._convertStandardMaterialAsync(e,t,r)):-1!==e.getClassName().indexOf("PBR")?a.push(n._convertPBRMaterialAsync(e,t,r)):d.Tools.Warn("Unsupported material type: ".concat(e.name))})),Promise.all(a).then((function(){}))},e.prototype._stripTexturesFromMaterial=function(e){var t={};if(e){t.name=e.name,t.doubleSided=e.doubleSided,t.alphaMode=e.alphaMode,t.alphaCutoff=e.alphaCutoff,t.emissiveFactor=e.emissiveFactor;var r=e.pbrMetallicRoughness;r&&(t.pbrMetallicRoughness={},t.pbrMetallicRoughness.baseColorFactor=r.baseColorFactor,t.pbrMetallicRoughness.metallicFactor=r.metallicFactor,t.pbrMetallicRoughness.roughnessFactor=r.roughnessFactor)}return t},e.prototype._hasTexturesPresent=function(e){var t;if(e.emissiveTexture||e.normalTexture||e.occlusionTexture)return!0;var r=e.pbrMetallicRoughness;if(r&&(r.baseColorTexture||r.metallicRoughnessTexture))return!0;if(e.extensions)for(var n in e.extensions){var a=e.extensions[n];if(a)return null===(t=a.hasTextures)||void 0===t?void 0:t.call(a)}return!1},e.prototype._getTextureInfo=function(e){if(e){var t=e.uid;if(t in this._textureMap)return this._textureMap[t]}return null},e.prototype._convertToGLTFPBRMetallicRoughness=function(t){var r,n,a,i,o,s,u=new d.Vector2(0,1),l=new d.Vector2(0,.1),c=new d.Vector2(0,.1),f=new d.Vector2(1300,.1),h=t.diffuseColor.toLinearSpace().scale(.5),p=t.alpha,_=(r=d.Scalar.Clamp(t.specularPower,0,e._MaxSpecularPower),n=Math.pow(r/f.x,.333333),a=u.y,i=l.y,o=c.y,s=f.y,(1-n)*(1-n)*(1-n)*a+3*(1-n)*(1-n)*n*i+3*(1-n)*n*n*o+n*n*n*s);return{baseColorFactor:[h.r,h.g,h.b,p],metallicFactor:0,roughnessFactor:_}},e._SolveMetallic=function(e,t,r){if(t<this._DielectricSpecular.r)return this._DielectricSpecular,0;var n=this._DielectricSpecular.r,a=e*r/(1-this._DielectricSpecular.r)+t-2*this._DielectricSpecular.r,i=a*a-4*n*(this._DielectricSpecular.r-t);return d.Scalar.Clamp((-a+Math.sqrt(i))/(2*n),0,1)},e._SetAlphaMode=function(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)},e.prototype._convertStandardMaterialAsync=function(t,r,n){var a=this._exporter._materialMap,i=this._exporter._materials,o=[],s=this._convertToGLTFPBRMetallicRoughness(t),u={name:t.name};if(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."),u.doubleSided=!0),n){t.diffuseTexture&&o.push(this._exportTextureAsync(t.diffuseTexture,r).then((function(e){e&&(s.baseColorTexture=e)})));var l=t.bumpTexture;l&&o.push(this._exportTextureAsync(l,r).then((function(e){e&&(u.normalTexture=e,1!==l.level&&(u.normalTexture.scale=l.level))}))),t.emissiveTexture&&(u.emissiveFactor=[1,1,1],o.push(this._exportTextureAsync(t.emissiveTexture,r).then((function(e){e&&(u.emissiveTexture=e)})))),t.ambientTexture&&o.push(this._exportTextureAsync(t.ambientTexture,r).then((function(e){if(e){var t={index:e.index};u.occlusionTexture=t}})))}return(t.alpha<1||t.opacityTexture)&&(t.alphaMode===d.Constants.ALPHA_COMBINE?u.alphaMode="BLEND":d.Tools.Warn(t.name+": glTF 2.0 does not support alpha mode: "+t.alphaMode.toString())),t.emissiveColor&&!e._FuzzyEquals(t.emissiveColor,d.Color3.Black(),e._Epsilon)&&(u.emissiveFactor=t.emissiveColor.asArray()),u.pbrMetallicRoughness=s,e._SetAlphaMode(u,t),i.push(u),a[t.uniqueId]=i.length-1,this._finishMaterial(o,u,t,r)},e.prototype._finishMaterial=function(e,t,r,n){var a=this;return Promise.all(e).then((function(){for(var e=null,i=0,o=a._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",t,r);i<o.length;i++){var s=o[i];e||(e=[]),e.push(a._exportTextureAsync(s,n))}return e||(e=[Promise.resolve(null)]),Promise.all(e).then((function(){var e=a._exporter._extensionsPostExportMaterialAsync("exportMaterial",t,r);return e?e.then((function(){return t})):t}))}))},e.prototype._getImageDataAsync=function(e,t,r,n){return c(this,void 0,void 0,(function(){var a,i,o,s,u;return f(this,(function(l){switch(l.label){case 0:return a=d.Constants.TEXTURETYPE_UNSIGNED_INT,i=this._exporter._babylonScene,o=i.getEngine(),s=o.createRawTexture(e,t,r,d.Constants.TEXTUREFORMAT_RGBA,!1,!0,d.Texture.NEAREST_SAMPLINGMODE,null,a),[4,d.TextureTools.ApplyPostProcess("pass",s,i,a,d.Constants.TEXTURE_NEAREST_SAMPLINGMODE,d.Constants.TEXTUREFORMAT_RGBA)];case 1:return l.sent(),[4,o._readTexturePixels(s,t,r)];case 2:return u=l.sent(),[4,d.Tools.DumpDataAsync(t,r,u,n,void 0,!0,!0)];case 3:return[2,l.sent()]}}))}))},e.prototype._createWhiteTexture=function(e,t,r){for(var n=new Uint8Array(e*t*4),a=0;a<n.length;a+=4)n[a]=n[a+1]=n[a+2]=n[a+3]=255;return d.RawTexture.CreateRGBATexture(n,e,t,r)},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,a,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):this._createWhiteTexture(o.width,o.height,r),a=t):i.width>o.width?(a=t&&t instanceof d.Texture?d.TextureTools.CreateResizedCopy(t,i.width,i.height,!0):this._createWhiteTexture(i.width,i.height,r),n=e):(n=e,a=t),{texture1:n,texture2:a}},e.prototype._convertPixelArrayToFloat32=function(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!")},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(t,r,n,a){var i;return c(this,void 0,void 0,(function(){var o,s,u,l,c,h,p,_,m,g,x,y,T,v,b,A,E,F,M,R,w,V,C,S,I,B,P,N,O,L,k;return f(this,(function(f){switch(f.label){case 0:return o=new Array,t||r?(s=t?t.getScene():r?r.getScene():null)?(u=this._resizeTexturesToSameDimensions(t,r,s),l=null===(i=u.texture1)||void 0===i?void 0:i.getSize(),c=void 0,h=void 0,p=l.width,_=l.height,[4,u.texture1.readPixels()]):[3,3]:[2,Promise.reject("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!")];case 1:return m=f.sent(),[4,u.texture2.readPixels()];case 2:if(g=f.sent(),!m)return[2,Promise.reject("Failed to retrieve pixels from diffuse texture!")];if(c=this._convertPixelArrayToFloat32(m),!g)return[2,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];for(h=this._convertPixelArrayToFloat32(g),x=h.byteLength,y=new Uint8Array(x),T=new Uint8Array(x),v=d.Color3.Black(),b=0,A=0,B=0;B<_;++B)for(P=0;P<p;++P)E=4*(p*B+P),F=new d.Color3(c[E],c[E+1],c[E+2]).toLinearSpace().multiply(n.diffuseColor),M=new d.Color3(h[E],h[E+1],h[E+2]).toLinearSpace().multiply(n.specularColor),R=h[E+3]*n.glossiness,w={diffuseColor:F,specularColor:M,glossiness:R},V=this._convertSpecularGlossinessToMetallicRoughness(w),v.r=Math.max(v.r,V.baseColor.r),v.g=Math.max(v.g,V.baseColor.g),v.b=Math.max(v.b,V.baseColor.b),b=Math.max(b,V.metallic),A=Math.max(A,V.roughness),T[E]=255*V.baseColor.r,T[E+1]=255*V.baseColor.g,T[E+2]=255*V.baseColor.b,T[E+3]=u.texture1.hasAlpha?255*c[E+3]:255,y[E]=0,y[E+1]=255*V.roughness,y[E+2]=255*V.metallic,y[E+3]=255;for(C={baseColor:v,metallic:b,roughness:A},S=!1,I=!1,B=0;B<_;++B)for(P=0;P<p;++P)T[N=4*(p*B+P)]/=C.baseColor.r>e._Epsilon?C.baseColor.r:1,T[N+1]/=C.baseColor.g>e._Epsilon?C.baseColor.g:1,T[N+2]/=C.baseColor.b>e._Epsilon?C.baseColor.b:1,O=d.Color3.FromInts(T[N],T[N+1],T[N+2]),L=O.toGammaSpace(),T[N]=255*L.r,T[N+1]=255*L.g,T[N+2]=255*L.b,e._FuzzyEquals(L,d.Color3.White(),e._Epsilon)||(I=!0),y[N+1]/=C.roughness>e._Epsilon?C.roughness:1,y[N+2]/=C.metallic>e._Epsilon?C.metallic:1,k=d.Color3.FromInts(255,y[N+1],y[N+2]),e._FuzzyEquals(k,d.Color3.White(),e._Epsilon)||(S=!0);return S&&o.push(this._getImageDataAsync(y,p,_,a).then((function(e){C.metallicRoughnessTextureData=e}))),I&&o.push(this._getImageDataAsync(T,p,_,a).then((function(e){C.baseColorTextureData=e}))),[2,Promise.all(o).then((function(){return C}))];case 3:return[2,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}}))}))},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(t){var r=this._getPerceivedBrightness(t.diffuseColor),n=this._getPerceivedBrightness(t.specularColor),a=1-this._getMaxComponent(t.specularColor),i=e._SolveMetallic(r,n,a),o=t.diffuseColor.scale(a/(1-e._DielectricSpecular.r)/Math.max(1-i,e._Epsilon)),s=t.specularColor.subtract(e._DielectricSpecular.scale(1-i)).scale(1/Math.max(i,e._Epsilon)),u=d.Color3.Lerp(o,s,i*i);return{baseColor:u=u.clampToRef(0,1,u),metallic:i,roughness:1-t.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){var a=[],i={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness};if(n){e._albedoTexture&&a.push(this._exportTextureAsync(e._albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)})));var o=e._metallicTexture;o&&a.push(this._exportTextureAsync(o,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))}return Promise.all(a).then((function(){return 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){var a=this;return Promise.resolve().then((function(){var i={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},o=e._albedoTexture,s=e._reflectivityTexture,u=e._useMicroSurfaceFromReflectivityMapAlpha;if(s&&!u)return Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported");if((o||s)&&n){var l=a._exportTextureSampler(o||s);return a._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(o,s,i,t).then((function(e){var n=a._exporter._textures;if(e.baseColorTextureData){var i=a._exportImage("baseColor".concat(n.length),t,e.baseColorTextureData);r.baseColorTexture=a._exportTextureInfo(i,l,null==o?void 0:o.coordinatesIndex)}return e.metallicRoughnessTextureData&&(i=a._exportImage("metallicRoughness".concat(n.length),t,e.metallicRoughnessTextureData),r.metallicRoughnessTexture=a._exportTextureInfo(i,l,null==s?void 0:s.coordinatesIndex)),e}))}return a._convertSpecularGlossinessToMetallicRoughness(i)}))},e.prototype._convertPBRMaterialAsync=function(e,t,r){var n=this,a={},i={name:e.name};if(e.isMetallicWorkflow()){var o=e._albedoColor,s=e.alpha;return o&&(a.baseColorFactor=[o.r,o.g,o.b,s]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,a,r).then((function(o){return n._setMetallicRoughnessPbrMaterial(o,e,i,a,t,r)}))}return this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,a,r).then((function(o){return n._setMetallicRoughnessPbrMaterial(o,e,i,a,t,r)}))},e.prototype._setMetallicRoughnessPbrMaterial=function(t,r,n,a,i,o){var s=this._exporter._materialMap,u=this._exporter._materials,l=[];if(t){if(e._SetAlphaMode(n,r),e._FuzzyEquals(t.baseColor,d.Color3.White(),e._Epsilon)&&r.alpha>=e._Epsilon||(a.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,r.alpha]),null!=t.metallic&&1!==t.metallic&&(a.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(a.roughnessFactor=t.roughness),null==r.backFaceCulling||r.backFaceCulling||(r._twoSidedLighting||d.Tools.Warn(r.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),o){var c=r._bumpTexture;if(c){var f=this._exportTextureAsync(c,i).then((function(e){e&&(n.normalTexture=e,1!==c.level&&(n.normalTexture.scale=c.level))}));l.push(f)}var h=r._ambientTexture;h&&(f=this._exportTextureAsync(h,i).then((function(e){if(e){var t={index:e.index,texCoord:e.texCoord};n.occlusionTexture=t;var a=r._ambientTextureStrength;a&&(t.strength=a)}})),l.push(f));var p=r._emissiveTexture;p&&(f=this._exportTextureAsync(p,i).then((function(e){e&&(n.emissiveTexture=e)})),l.push(f))}var _=r._emissiveColor;e._FuzzyEquals(_,d.Color3.Black(),e._Epsilon)||(n.emissiveFactor=_.asArray()),n.pbrMetallicRoughness=a,u.push(n),s[r.uniqueId]=u.length-1}return this._finishMaterial(l,n,r,i)},e.prototype._getPixelsFromTexture=function(e){return e.textureType,d.Constants.TEXTURETYPE_UNSIGNED_INT,e.readPixels()},e.prototype._exportTextureAsync=function(e,t){var r=this,n=this._exporter._extensionsPreExportTextureAsync("exporter",e,t);return n?n.then((function(n){return n?r._exportTextureInfoAsync(n,t):r._exportTextureInfoAsync(e,t)})):this._exportTextureInfoAsync(e,t)},e.prototype._exportTextureInfoAsync=function(e,t){return c(this,void 0,void 0,(function(){var r,n,a,i,o,s,u,l,c,h;return f(this,(function(f){switch(f.label){case 0:return(r=e.uid)in this._textureMap?[2,this._textureMap[r]]:[3,1];case 1:return[4,this._getPixelsFromTexture(e)];case 2:if(!(n=f.sent()))return[2,null];if(a=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: ${textureMimeType}")}return o=this._internalTextureToImage,s=e.getInternalTexture().uniqueId,o[s]||(o[s]={}),void 0!==(u=o[s][t])?[3,4]:(l=e.getSize(),[4,this._getImageDataAsync(n,l.width,l.height,t)]);case 3:c=f.sent(),u=this._exportImage(e.name,t,c),o[s][t]=u,f.label=4;case 4:return h=this._exportTextureInfo(u,a,e.coordinatesIndex),this._textureMap[r]=h,[2,h]}}))}))},e.prototype._exportImage=function(e,t,r){var n=this._exporter._imageData,a=e.replace(/\.\/|\/|\.\\|\\/g,"_"),i=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp"}}(t),o=a+i;o in n&&(o="".concat(a,"_").concat(d.Tools.RandomId()).concat(i)),n[o]={data:r,mimeType:t};var s=this._exporter._images;return s.push({name:e,uri:o}),s.length-1},e.prototype._exportTextureInfo=function(e,t,r){var n=this._exporter._textures,a=n.findIndex((function(r){return r.sampler==t&&r.source===e}));-1===a&&(a=n.length,n.push({source:e,sampler:t}));var i={index:a};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._DielectricSpecular=new d.Color3(.04,.04,.04),e._MaxSpecularPower=1024,e._Epsilon=1e-6,e}(),m=function(){function e(){}return e._CreateBufferView=function(e,t,r,n,a){var i={buffer:e,byteLength:r};return t&&(i.byteOffset=t),a&&(i.name=a),n&&(i.byteStride=n),i},e._CreateAccessor=function(e,t,r,n,a,i,o,s){var u={name:t,bufferView:e,componentType:n,count:a,type:r};return null!=o&&(u.min=o),null!=s&&(u.max=s),null!=i&&(u.byteOffset=i),u},e._CalculateMinMaxPositions=function(t,r,n,a){var i,o,s,u=[1/0,1/0,1/0],l=[-1/0,-1/0,-1/0];if(n)for(var c=r,f=r+n;c<f;++c){i=3*c,o=d.Vector3.FromArray(t,i),a&&e._GetRightHandedPositionVector3FromRef(o),s=o.asArray();for(var h=0;h<3;++h){var p=s[h];p<u[h]&&(u[h]=p),p>l[h]&&(l[h]=p),++i}}return{min:u,max:l}},e._GetRightHandedPositionVector3=function(e){return new d.Vector3(e.x,e.y,-e.z)},e._GetRightHandedPositionVector3FromRef=function(e){e.z*=-1},e._GetRightHandedPositionArray3FromRef=function(e){e[2]*=-1},e._GetRightHandedNormalVector3=function(e){return new d.Vector3(e.x,e.y,-e.z)},e._GetRightHandedNormalVector3FromRef=function(e){e.z*=-1},e._GetRightHandedNormalArray3FromRef=function(e){e[2]*=-1},e._GetRightHandedVector4FromRef=function(e){e.z*=-1,e.w*=-1},e._GetRightHandedArray4FromRef=function(e){e[2]*=-1,e[3]*=-1},e._GetRightHandedQuaternionFromRef=function(e){e.x*=-1,e.y*=-1},e._GetRightHandedQuaternionArrayFromRef=function(e){e[0]*=-1,e[1]*=-1},e._NormalizeTangentFromRef=function(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)},e._GetDataAccessorElementCount=function(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}},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(p||(p={}));var g=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,a,i,o){if(this._IsTransformable(t)){var s=[],u=[],l=r.getKeys(),c=e._CalculateMinMaxKeyFrames(l),f=e._DeduceInterpolation(l,n,i),h=c.max-c.min,p=f.interpolationType,_=f.shouldBakeAnimation;if(_?e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,o,s,u,c,a,i):"LINEAR"===p||"STEP"===p?e._CreateLinearOrStepAnimation(t,r,n,h,s,u,a,i):"CUBICSPLINE"===p?e._CreateCubicSplineAnimation(t,r,n,h,s,u,a,i):e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,o,s,u,c,a,i),s.length&&u.length)return{inputs:s,outputs:u,samplerInterpolation:p,inputsMin:_?c.min:d.Tools.FloatRound(c.min/r.framePerSecond),inputsMax:_?c.max:d.Tools.FloatRound(c.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,a=e.targetProperty.split(".");switch(a[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(a[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,a,i,o,s,u,l,c){var f;if(e._IsTransformable(t)&&t.animations)for(var h=0,p=t.animations;h<p.length;h++){var d=p[h],_=e._DeduceAnimationInfo(d);_&&(f={name:d.name,samplers:[],channels:[]},e._AddAnimation("".concat(d.name),d.hasRunningRuntimeAnimations?r:f,t,d,_.dataAccessorType,_.animationChannelTargetPath,a,o,s,u,l,_.useQuaternion,c),f.samplers.length&&f.channels.length&&n.push(f))}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,a,i,o,s,u,l,c){var f;if(t instanceof d.Mesh){var h=t.morphTargetManager;if(h)for(var p=0;p<h.numTargets;++p)for(var _=0,m=h.getTarget(p).animations;_<m.length;_++){for(var g=m[_],x=new d.Animation("".concat(g.name),"influence",g.framePerSecond,g.dataType,g.loopMode,g.enableBlending),y=[],T=g.getKeys(),v=0;v<T.length;++v)for(var b=T[v],A=0;A<h.numTargets;++A)A==p?y.push(b):y.push({frame:b.frame,value:0});x.setKeys(y);var E=e._DeduceAnimationInfo(x);E&&(f={name:x.name,samplers:[],channels:[]},e._AddAnimation(g.name,g.hasRunningRuntimeAnimations?r:f,t,x,E.dataAccessorType,E.animationChannelTargetPath,a,o,s,u,l,E.useQuaternion,c,h.numTargets),f.samplers.length&&f.channels.length&&n.push(f))}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,a,i,o,s,u,l){var c,f;if(t.animationGroups)for(var h=t.animationGroups,p=function(a){var h=new Map,p=new Map,m=new Set,g=a.to-a.from;f={name:a.name,channels:[],samplers:[]};for(var x=function(r){var g=a.targetedAnimations[r],x=g.target,y=g.animation;if(_._IsTransformable(x)||1===x.length&&_._IsTransformable(x[0])){if(b=e._DeduceAnimationInfo(g.animation)){var T=_._IsTransformable(x)?x:_._IsTransformable(x[0])?x[0]:null;if(T){var v=u[T.uniqueId];e._AddAnimation("".concat(y.name),f,T,y,b.dataAccessorType,b.animationChannelTargetPath,n,i,o,s,v,b.useQuaternion,l)}}}else if(x instanceof d.MorphTarget||1===x.length&&x[0]instanceof d.MorphTarget){var b;if(b=e._DeduceAnimationInfo(g.animation)){var A=x instanceof d.MorphTarget?x:x[0];if(A){var E=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===A)return!0;return!1}));if(E){var F=t.meshes.find((function(e){return e.morphTargetManager===E}));F&&(h.has(F)||h.set(F,new Map),null===(c=h.get(F))||void 0===c||c.set(A,y),m.add(F),p.set(F,y))}}}}},y=0;y<a.targetedAnimations.length;++y)x(y);m.forEach((function(t){for(var r=t.morphTargetManager,u=null,c=[],_=p.get(t).getKeys(),m=_.length,x=0;x<m;++x)for(var y=0;y<r.numTargets;++y){var T=r.getTarget(y),v=h.get(t);if(v){var b=v.get(T);b?(u||(u=new d.Animation("".concat(a.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,d.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[x])):c.push({frame:a.from+g/m*x,value:T.influence,inTangent:_[0].inTangent?0:void 0,outTangent:_[0].outTangent?0:void 0})}}u.setKeys(c);var A=e._DeduceAnimationInfo(u);A&&e._AddAnimation("".concat(a.name,"_").concat(t.name,"_MorphWeightAnimation"),f,t,u,A.dataAccessorType,A.animationChannelTargetPath,n,i,o,s,!1,A.useQuaternion,l,null==r?void 0:r.numTargets)})),f.channels.length&&f.samplers.length&&r.push(f)},_=this,m=0,g=h;m<g.length;m++)p(g[m])},e._AddAnimation=function(t,r,n,a,i,o,s,u,l,c,f,h,p,d){var _,g,x,y,T,v,b,A=e._CreateNodeAnimation(n,a,o,f,h,p);if(A){if(d){for(var E=0,F=0,M=[];A.inputs.length>0;)F=A.inputs.shift(),E%d==0&&M.push(F),E++;A.inputs=M}var R=s[n.uniqueId],w=4*A.inputs.length;_=m._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," keyframe data view")),l.push(_),A.inputs.forEach((function(e){u.setFloat32(e)})),g=m._CreateAccessor(l.length-1,"".concat(t," keyframes"),"SCALAR",5126,A.inputs.length,null,[A.inputsMin],[A.inputsMax]),c.push(g),x=c.length-1,T=A.outputs.length,w=4*m._GetDataAccessorElementCount(i)*A.outputs.length,_=m._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," data view")),l.push(_),A.outputs.forEach((function(e){e.forEach((function(e){u.setFloat32(e)}))})),g=m._CreateAccessor(l.length-1,"".concat(t," data"),i,5126,T,null,null,null),c.push(g),y=c.length-1,v={interpolation:A.samplerInterpolation,input:x,output:y},r.samplers.push(v),b={sampler:r.samplers.length-1,target:{node:R,path:o}},r.channels.push(b)}},e._CreateBakedAnimation=function(t,r,n,a,i,o,s,u,l,c,f,h){var p,_,m=d.Quaternion.Identity(),g=null,x=null,y=null,T=null,v=null,b=null;c.min=d.Tools.FloatRound(a/o);for(var A=r.getKeys(),E=0,F=A.length;E<F;++E){if(b=null,y=A[E],E+1<F)if(T=A[E+1],y.value.equals&&y.value.equals(T.value)||y.value===T.value){if(0!==E)continue;b=y.frame}else b=T.frame;else{if(v=A[E-1],y.value.equals&&y.value.equals(v.value)||y.value===v.value)continue;b=i}if(b)for(var M=y.frame;M<=b;M+=s)if((_=d.Tools.FloatRound(M/o))!==g){g=_,x=_;var R={key:0,repeatCount:0,loopMode:r.loopMode};p=r._interpolate(M,R),e._SetInterpolatedValue(t,p,_,r,n,m,u,l,f,h)}}x&&(c.max=x)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,a,i,o,s){var u,l,c=null,f=e._GetBasePositionRotationOrScale(r,i,o,s);if(a===d.Animation.ANIMATIONTYPE_FLOAT)switch(l=(u=n.targetProperty.split("."))?u[1]:"",c=s?d.Quaternion.FromArray(f).normalize():d.Vector3.FromArray(f),l){case"x":case"y":c[l]=o&&s&&"scale"!==i?-t:t;break;case"z":c[l]=o&&!s&&"scale"!==i?-t:t;break;case"w":c.w=t;break;default:d.Tools.Error('glTFAnimation: Unsupported component type "'.concat(l,'" for scale animation!'))}return c},e._SetInterpolatedValue=function(e,t,r,n,a,i,o,s,u,l){var c,f=n.dataType;if(o.push(r),t){if("weights"===a)return void s.push([t]);"number"==typeof t&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,f,a,u,l)),"rotation"===a?(l?i=t:(c=t,d.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,i)),u&&(m._GetRightHandedQuaternionFromRef(i),e.parent||(i=d.Quaternion.FromArray([0,1,0,0]).multiply(i))),s.push(i.asArray())):(c=t,u&&"scale"!==a&&(m._GetRightHandedPositionVector3FromRef(c),e.parent||(c.x*=-1,c.z*=-1)),s.push(c.asArray()))}},e._CreateLinearOrStepAnimation=function(t,r,n,a,i,o,s,u){for(var l=0,c=r.getKeys();l<c.length;l++){var f=c[l];i.push(f.frame/r.framePerSecond),e._AddKeyframeValue(f,r,o,n,t,s,u)}},e._CreateCubicSplineAnimation=function(t,r,n,a,i,o,s,u){r.getKeys().forEach((function(l){i.push(l.frame/r.framePerSecond),e._AddSplineTangent(t,p.INTANGENT,o,n,"CUBICSPLINE",l,a,u,s),e._AddKeyframeValue(l,r,o,n,t,s,u),e._AddSplineTangent(t,p.OUTTANGENT,o,n,"CUBICSPLINE",l,a,u,s)}))},e._GetBasePositionRotationOrScale=function(e,t,r,n){var a;if("rotation"===t)if(n){var i=e.rotationQuaternion;a=(null!=i?i:d.Quaternion.Identity()).asArray(),r&&(m._GetRightHandedQuaternionArrayFromRef(a),e.parent||(a=d.Quaternion.FromArray([0,1,0,0]).multiply(d.Quaternion.FromArray(a)).asArray()))}else{var o=e.rotation;a=(null!=o?o:d.Vector3.Zero()).asArray(),m._GetRightHandedNormalArray3FromRef(a)}else if("translation"===t){var s=e.position;a=(null!=s?s:d.Vector3.Zero()).asArray(),r&&m._GetRightHandedPositionArray3FromRef(a)}else{var u=e.scaling;a=(null!=u?u:d.Vector3.One()).asArray()}return a},e._AddKeyframeValue=function(e,t,r,n,a,i,o){var s,u,l=t.dataType;if(l===d.Animation.ANIMATIONTYPE_VECTOR3){if(s=e.value.asArray(),"rotation"===n){var c=d.Vector3.FromArray(s),f=d.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z);i&&(m._GetRightHandedQuaternionFromRef(f),a.parent||(f=d.Quaternion.FromArray([0,1,0,0]).multiply(f))),s=f.asArray()}else"translation"===n&&i&&(m._GetRightHandedNormalArray3FromRef(s),a.parent||(s[0]*=-1,s[2]*=-1));r.push(s)}else if(l===d.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(u=this._ConvertFactorToVector3OrQuaternion(e.value,a,t,l,n,i,o)){if("rotation"===n){var h=o?u:d.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).normalize();i&&(m._GetRightHandedQuaternionFromRef(h),a.parent||(h=d.Quaternion.FromArray([0,1,0,0]).multiply(h))),r.push(h.asArray())}else"translation"===n&&i&&(m._GetRightHandedNormalVector3FromRef(u),a.parent||(u.x*=-1,u.z*=-1));r.push(u.asArray())}}else l===d.Animation.ANIMATIONTYPE_QUATERNION?(s=e.value.normalize().asArray(),i&&(m._GetRightHandedQuaternionArrayFromRef(s),a.parent||(s=d.Quaternion.FromArray([0,1,0,0]).multiply(d.Quaternion.FromArray(s)).asArray())),r.push(s)):d.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,a,i=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var o=0,s=e.length;o<s;++o)if((a=e[o]).inTangent||a.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",i=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||a.interpolation&&a.interpolation===d.AnimationKeyInterpolation.STEP&&"STEP"!==n){n="LINEAR",i=!0;break}}else n=a.interpolation&&a.interpolation===d.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,t,r,n,a,i,o,s,u){var l,c=t===p.INTANGENT?i.inTangent:i.outTangent;if("CUBICSPLINE"===a){if("rotation"===n)if(c){if(s)l=c.asArray();else{var f=c;l=d.Quaternion.RotationYawPitchRoll(f.y,f.x,f.z).asArray()}u&&(m._GetRightHandedQuaternionArrayFromRef(l),e.parent||(l=d.Quaternion.FromArray([0,1,0,0]).multiply(d.Quaternion.FromArray(l)).asArray()))}else l=[0,0,0,0];else"weights"===n?l=c?[c]:[0]:c?(l=c.asArray(),u&&"translation"===n&&(m._GetRightHandedPositionArray3FromRef(l),e.parent||(l[0]*=-1,l[2]*=-1))):l=[0,0,0];r.push(l)}},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}(),x=function(){function e(e,t){this._includeCoordinateSystemConversionNodes=!1,this._extensions={},this._glTF={asset:{generator:"Babylon.js v".concat(d.Engine.Version),version:"2.0"}},(e=e||d.EngineStore.LastCreatedScene)&&(this._babylonScene=e,this._bufferViews=[],this._accessors=[],this._meshes=[],this._scenes=[],this._cameras=[],this._nodes=[],this._images=[],this._materials=[],this._materialMap=[],this._textures=[],this._samplers=[],this._skins=[],this._animations=[],this._imageData={},this._orderedImageData=[],this._options=t||{},this._animationSampleRate=t&&t.animationSampleRate?t.animationSampleRate:1/60,this._includeCoordinateSystemConversionNodes=!(!t||!t.includeCoordinateSystemConversionNodes),this._glTFMaterialExporter=new _(this),this._loadExtensions())}return e.prototype._applyExtension=function(e,t,r,n){var a=this;if(r>=t.length)return Promise.resolve(e);var i=n(t[r],e);return i?i.then((function(e){return a._applyExtension(e,t,r+1,n)})):this._applyExtension(e,t,r+1,n)},e.prototype._applyExtensions=function(t,r){for(var n=[],a=0,i=e._ExtensionNames;a<i.length;a++){var o=i[a];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._extensionsPostExportMeshPrimitiveAsync=function(e,t,r,n){return this._applyExtensions(t,(function(t,a){return t.postExportMeshPrimitiveAsync&&t.postExportMeshPrimitiveAsync(e,a,r,n)}))},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n,a){return this._applyExtensions(t,(function(t,i){return t.postExportNodeAsync&&t.postExportNodeAsync(e,i,r,n,a)}))},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 a=[],i=0,o=e._ExtensionNames;i<o.length;i++){var s=o[i],u=this._extensions[s];u.postExportMaterialAdditionalTextures&&a.push.apply(a,u.postExportMaterialAdditionalTextures(t,r,n))}return a},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var a=0,i=e._ExtensionNames;a<i.length;a++){var o=i[a],s=this._extensions[o];s.postExportTexture&&s.postExportTexture(t,r,n)}},e.prototype._forEachExtensions=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var a=n[r],i=this._extensions[a];i.enabled&&t(i)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){t.wasUsed&&(null==e._glTF.extensionsUsed&&(e._glTF.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&(null==e._glTF.extensionsRequired&&(e._glTF.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),null==e._glTF.extensions&&(e._glTF.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],a=e._ExtensionFactories[n](this);this._extensions[n]=a}},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._reorderIndicesBasedOnPrimitiveMode=function(e,t,r,n,a){switch(t){case d.Material.TriangleFillMode:n||(n=0);for(var i=e.indexStart,o=e.indexStart+e.indexCount;i<o;i+=3){var s=n+4*i,u=a.getUInt32(s+4),l=a.getUInt32(s+8);a.setUInt32(l,s+4),a.setUInt32(u,s+8)}break;case d.Material.TriangleFanDrawMode:i=e.indexStart+e.indexCount-1;for(var c=e.indexStart;i>=c;--i)a.setUInt32(r[i],n),n+=4;break;case d.Material.TriangleStripDrawMode:e.indexCount>=3&&(a.setUInt32(r[e.indexStart+2],n+4),a.setUInt32(r[e.indexStart+1],n+8))}},e.prototype._reorderVertexAttributeDataBasedOnPrimitiveMode=function(e,t,r,n,a,i,o,s){if(s&&r===d.Material.ClockWiseSideOrientation)switch(t){case d.Material.TriangleFillMode:this._reorderTriangleFillMode(e,t,r,n,a,i,o,s);break;case d.Material.TriangleStripDrawMode:this._reorderTriangleStripDrawMode(e,t,r,n,a,i,o,s);break;case d.Material.TriangleFanDrawMode:this._reorderTriangleFanMode(e,t,r,n,a,i,o,s)}},e.prototype._reorderTriangleFillMode=function(e,t,r,n,a,i,o,s){var u=this._getVertexBufferFromMesh(n,e.getMesh());if(u){var l=u.byteStride/d.VertexBuffer.GetTypeByteLength(u.type);if(e.verticesCount%3!=0)d.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var c=[],f=0;switch(n){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:for(var h=e.verticesStart;h<e.verticesStart+e.verticesCount;h+=3)f=h*l,c.push(d.Vector3.FromArray(a,f)),c.push(d.Vector3.FromArray(a,f+2*l)),c.push(d.Vector3.FromArray(a,f+l));break;case d.VertexBuffer.TangentKind:for(h=e.verticesStart;h<e.verticesStart+e.verticesCount;h+=3)f=h*l,c.push(d.Vector4.FromArray(a,f)),c.push(d.Vector4.FromArray(a,f+2*l)),c.push(d.Vector4.FromArray(a,f+l));break;case d.VertexBuffer.ColorKind:var p=u.getSize();for(h=e.verticesStart;h<e.verticesStart+e.verticesCount;h+=p)f=h*l,4===p?(c.push(d.Vector4.FromArray(a,f)),c.push(d.Vector4.FromArray(a,f+2*l)),c.push(d.Vector4.FromArray(a,f+l))):(c.push(d.Vector3.FromArray(a,f)),c.push(d.Vector3.FromArray(a,f+2*l)),c.push(d.Vector3.FromArray(a,f+l)));break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:for(h=e.verticesStart;h<e.verticesStart+e.verticesCount;h+=3)f=h*l,c.push(d.Vector2.FromArray(a,f)),c.push(d.Vector2.FromArray(a,f+2*l)),c.push(d.Vector2.FromArray(a,f+l));break;default:d.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this._writeVertexAttributeData(c,i,n,a,o,s)}}else d.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind ".concat(n," not present!"))},e.prototype._reorderTriangleStripDrawMode=function(e,t,r,n,a,i,o,s){var u=this._getVertexBufferFromMesh(n,e.getMesh());if(u){var l=u.byteStride/d.VertexBuffer.GetTypeByteLength(u.type),c=[],f=0;switch(n){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:f=e.verticesStart,c.push(d.Vector3.FromArray(a,f+2*l)),c.push(d.Vector3.FromArray(a,f+l));break;case d.VertexBuffer.TangentKind:for(var h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,c.push(d.Vector4.FromArray(a,f));break;case d.VertexBuffer.ColorKind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,4===u.getSize()?c.push(d.Vector4.FromArray(a,f)):c.push(d.Vector3.FromArray(a,f));break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,c.push(d.Vector2.FromArray(a,f));break;default:d.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this._writeVertexAttributeData(c,i+12,n,a,o,s)}else d.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind ".concat(n," not present!"))},e.prototype._reorderTriangleFanMode=function(e,t,r,n,a,i,o,s){var u=this._getVertexBufferFromMesh(n,e.getMesh());if(u){var l=u.byteStride/d.VertexBuffer.GetTypeByteLength(u.type),c=[],f=0;switch(n){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:for(var h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,c.push(d.Vector3.FromArray(a,f));break;case d.VertexBuffer.TangentKind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,c.push(d.Vector4.FromArray(a,f));break;case d.VertexBuffer.ColorKind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,c.push(d.Vector4.FromArray(a,f)),4===u.getSize()?c.push(d.Vector4.FromArray(a,f)):c.push(d.Vector3.FromArray(a,f));break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,c.push(d.Vector2.FromArray(a,f));break;default:d.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this._writeVertexAttributeData(c,i,n,a,o,s)}else d.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind ".concat(n," not present!"))},e.prototype._writeVertexAttributeData=function(e,t,r,n,a,i){for(var o=0,s=e;o<s.length;o++){var u=s[o];!i||r===d.VertexBuffer.ColorKind||u instanceof d.Vector2||(u instanceof d.Vector3?r===d.VertexBuffer.NormalKind?m._GetRightHandedNormalVector3FromRef(u):r===d.VertexBuffer.PositionKind?m._GetRightHandedPositionVector3FromRef(u):d.Tools.Error("Unsupported vertex attribute kind!"):m._GetRightHandedVector4FromRef(u)),r===d.VertexBuffer.NormalKind?u.normalize():r===d.VertexBuffer.TangentKind&&u instanceof d.Vector4&&m._NormalizeTangentFromRef(u);for(var l=0,c=u.asArray();l<c.length;l++){var f=c[l];a.setFloat32(f,t),t+=4}}},e.prototype._writeAttributeData=function(e,t,r,n,a,i,o){var s,u,l=[];switch(e){case d.VertexBuffer.PositionKind:for(var c=0,f=r.length/n;c<f;++c){s=c*n;var h=d.Vector3.FromArray(r,s);i&&m._GetRightHandedPositionVector3FromRef(h),l.push(h.asArray())}break;case d.VertexBuffer.NormalKind:c=0;for(var p=r.length/n;c<p;++c)s=c*n,h=d.Vector3.FromArray(r,s),i&&m._GetRightHandedNormalVector3FromRef(h),h.normalize(),l.push(h.asArray());break;case d.VertexBuffer.TangentKind:c=0;for(var _=r.length/n;c<_;++c)s=c*n,h=d.Vector4.FromArray(r,s),i&&m._GetRightHandedVector4FromRef(h),m._NormalizeTangentFromRef(h),l.push(h.asArray());break;case d.VertexBuffer.ColorKind:for(var g=o.material,x=!g||"StandardMaterial"===g.getClassName(),y=(h=3===n?new d.Color3:new d.Color4,c=0,r.length/n);c<y;++c)s=c*n,3===n?(d.Color3.FromArrayToRef(r,s,h),x&&h.toLinearSpaceToRef(h)):(d.Color4.FromArrayToRef(r,s,h),x&&h.toLinearSpaceToRef(h)),l.push(h.asArray());break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:c=0;for(var T=r.length/n;c<T;++c)s=c*n,l.push([r[s],r[s+1]]);break;case d.VertexBuffer.MatricesIndicesKind:case d.VertexBuffer.MatricesIndicesExtraKind:c=0;for(var v=r.length/n;c<v;++c)s=c*n,h=d.Vector4.FromArray(r,s),l.push(h.asArray());break;case d.VertexBuffer.MatricesWeightsKind:case d.VertexBuffer.MatricesWeightsExtraKind:c=0;for(var b=r.length/n;c<b;++c)s=c*n,h=d.Vector4.FromArray(r,s),l.push(h.asArray());break;default:d.Tools.Warn("Unsupported Vertex Buffer Type: "+e),l=[]}switch(t){case 5121:u=a.setUInt8.bind(a);break;case 5123:u=a.setUInt16.bind(a);break;case 5125:u=a.setUInt32.bind(a);break;case 5126:u=a.setFloat32.bind(a);break;default:return void d.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var A=0,E=l;A<E.length;A++)for(var F=0,M=E[A];F<M.length;F++)u(M[F])},e.prototype.writeMorphTargetAttributeData=function(e,t,r,n,a,i,o,s,u,l){var c,f,h=[],p=new d.Vector3,_=new d.Vector4(0,0,0,0);switch(e){case d.VertexBuffer.PositionKind:for(var g=r.verticesStart;g<r.verticesCount;++g){c=r.indexStart+g*o;var x=d.Vector3.FromArray(a,c);p=(y=d.Vector3.FromArray(i,c)).subtractToRef(x,p),u&&m._GetRightHandedPositionVector3FromRef(p),l&&(l.min.copyFromFloats(Math.min(p.x,l.min.x),Math.min(p.y,l.min.y),Math.min(p.z,l.min.z)),l.max.copyFromFloats(Math.max(p.x,l.max.x),Math.max(p.y,l.max.y),Math.max(p.z,l.max.z))),h.push(p.asArray())}break;case d.VertexBuffer.NormalKind:for(g=r.verticesStart;g<r.verticesCount;++g)c=r.indexStart+g*o,(x=d.Vector3.FromArray(a,c)).normalize(),(y=d.Vector3.FromArray(i,c)).normalize(),p=y.subtractToRef(x,p),u&&m._GetRightHandedNormalVector3FromRef(p),h.push(p.asArray());break;case d.VertexBuffer.TangentKind:for(g=r.verticesStart;g<r.verticesCount;++g){c=r.indexStart+g*(o+1),x=d.Vector4.FromArray(a,c),m._NormalizeTangentFromRef(x);var y=d.Vector4.FromArray(i,c);m._NormalizeTangentFromRef(y),_=y.subtractToRef(x,_),u&&m._GetRightHandedVector4FromRef(_),h.push([_.x,_.y,_.z])}break;default:d.Tools.Warn("Unsupported Vertex Buffer Type: "+e),h=[]}switch(t){case 5121:f=s.setUInt8.bind(s);break;case 5123:f=s.setUInt16.bind(s);break;case 5125:f=s.setUInt32.bind(s);break;case 5126:f=s.setFloat32.bind(s);break;default:return void d.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var T=0,v=h;T<v.length;T++)for(var b=0,A=v[T];b<A.length;b++)f(A[b])},e.prototype._generateJSON=function(e,t,r){var n,a,i,o=this,s={byteLength:this._totalByteLength},u=this._totalByteLength;return s.byteLength&&(this._glTF.buffers=[s]),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&&(e?(this._glTF.images=[],this._images.forEach((function(e){e.uri&&(a=o._imageData[e.uri],o._orderedImageData.push(a),n=e.uri.split(".")[0]+" image",i=m._CreateBufferView(0,u,a.data.byteLength,void 0,n),u+=a.data.byteLength,o._bufferViews.push(i),e.bufferView=o._bufferViews.length-1,e.name=n,e.mimeType=a.mimeType,e.uri=void 0,o._glTF.images||(o._glTF.images=[]),o._glTF.images.push(e))})),s.byteLength=u):this._glTF.images=this._images),e||(s.uri=t+".bin"),r?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)},e.prototype._generateGLTFAsync=function(e,t){var r=this;return void 0===t&&(t=!0),this._generateBinaryAsync().then((function(n){r._extensionsOnExporting();var a=r._generateJSON(!1,e,!0),i=new Blob([n],{type:"application/octet-stream"}),o=e+".gltf",s=e+".bin",u=new l;if(u.glTFFiles[o]=a,u.glTFFiles[s]=i,r._imageData)for(var c in r._imageData)u.glTFFiles[c]=new Blob([r._imageData[c].data],{type:r._imageData[c].mimeType});return t&&r.dispose(),u}))},e.prototype._generateBinaryAsync=function(){var e=this,t=new y(4);return this._createSceneAsync(this._babylonScene,t).then((function(){return e._localEngine&&e._localEngine.dispose(),t.getArrayBuffer()}))},e.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},e.prototype._generateGLBAsync=function(e,t){var r=this;return void 0===t&&(t=!0),this._generateBinaryAsync().then((function(n){r._extensionsOnExporting();var a,i=r._generateJSON(!0),o=e+".glb",s=i.length,u=0;"undefined"!=typeof TextEncoder&&(s=(a=(new TextEncoder).encode(i)).length);for(var c=0;c<r._orderedImageData.length;++c)u+=r._orderedImageData[c].data.byteLength;var f=r._getPadding(s),h=r._getPadding(n.byteLength),p=r._getPadding(u),d=28+s+f+n.byteLength+h+u+p,_=new ArrayBuffer(12),m=new DataView(_);m.setUint32(0,1179937895,!0),m.setUint32(4,2,!0),m.setUint32(8,d,!0);var g=new ArrayBuffer(8+s+f),x=new DataView(g);x.setUint32(0,s+f,!0),x.setUint32(4,1313821514,!0);var y=new Uint8Array(g,8);if(a)y.set(a);else{var T="_".charCodeAt(0);for(c=0;c<s;++c){var v=i.charCodeAt(c);v!=i.codePointAt(c)?y[c]=T:y[c]=v}}var b=new Uint8Array(g,8+s);for(c=0;c<f;++c)b[c]=32;var A=new ArrayBuffer(8),E=new DataView(A);E.setUint32(0,n.byteLength+u+p,!0),E.setUint32(4,5130562,!0);var F=new ArrayBuffer(h),M=new Uint8Array(F);for(c=0;c<h;++c)M[c]=0;var R=new ArrayBuffer(p),w=new Uint8Array(R);for(c=0;c<p;++c)w[c]=0;var V=[_,g,A,n];for(c=0;c<r._orderedImageData.length;++c)V.push(r._orderedImageData[c].data);V.push(F),V.push(R);var C=new Blob(V,{type:"application/octet-stream"}),S=new l;return S.glTFFiles[o]=C,null!=r._localEngine&&r._localEngine.dispose(),t&&r.dispose(),S}))},e.prototype._setNodeTransformation=function(e,t,r){t.getPivotPoint().equalsToFloats(0,0,0)||d.Tools.Warn("Pivot points are not supported in the glTF serializer"),t.position.equalsToFloats(0,0,0)||(e.translation=r?m._GetRightHandedPositionVector3(t.position).asArray():t.position.asArray()),t.scaling.equalsToFloats(1,1,1)||(e.scale=t.scaling.asArray());var n=d.Quaternion.RotationYawPitchRoll(t.rotation.y,t.rotation.x,t.rotation.z);t.rotationQuaternion&&n.multiplyInPlace(t.rotationQuaternion),d.Quaternion.IsIdentity(n)||(r&&m._GetRightHandedQuaternionFromRef(n),e.rotation=n.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,r){t.position.equalsToFloats(0,0,0)||(e.translation=r?m._GetRightHandedPositionVector3(t.position).asArray():t.position.asArray());var n=t.rotationQuaternion;n&&!d.Quaternion.IsIdentity(n)&&(r&&m._GetRightHandedQuaternionFromRef(n),e.rotation=n.normalize().asArray())},e.prototype._getVertexBufferFromMesh=function(e,t){if(t.isVerticesDataPresent(e)){var r=t.getVertexBuffer(e);if(r)return r}return null},e.prototype._createBufferViewKind=function(e,t,r,n,a,i){var o=r instanceof d.Mesh?r:r instanceof d.InstancedMesh?r.sourceMesh:null;if(o){var s=o.getVertexBuffer(e),u=o.getVerticesData(e);if(s&&u){var l=d.VertexBuffer.GetTypeByteLength(t),c=u.length*l,f=m._CreateBufferView(0,n.getByteOffset(),c,a,e+" - "+o.name);this._bufferViews.push(f),this._writeAttributeData(e,t,u,a/l,n,i,r)}}},e.prototype._setMorphTargetAttributes=function(e,t,r,n,a){if(r){t.targets||(t.targets=[]);var i={};if(r.hasNormals){var o=e.getMesh().getVerticesData(d.VertexBuffer.NormalKind),s=r.getNormals(),u=(g=e.verticesCount)*(x=12),l=m._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_NORMAL");this._bufferViews.push(l);var c=this._bufferViews.length-1,f=m._CreateAccessor(c,r.name+" - NORMAL","VEC3",5126,g,0,null,null);this._accessors.push(f),i.NORMAL=this._accessors.length-1,this.writeMorphTargetAttributeData(d.VertexBuffer.NormalKind,5126,e,r,o,s,x/4,n,a)}if(r.hasPositions){var h=e.getMesh().getVerticesData(d.VertexBuffer.PositionKind),p=r.getPositions();u=(g=e.verticesCount)*(x=12),l=m._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_POSITION"),this._bufferViews.push(l),c=this._bufferViews.length-1;var _={min:new d.Vector3(1/0,1/0,1/0),max:new d.Vector3(-1/0,-1/0,-1/0)};f=m._CreateAccessor(c,r.name+" - POSITION","VEC3",5126,g,0,null,null),this._accessors.push(f),i.POSITION=this._accessors.length-1,this.writeMorphTargetAttributeData(d.VertexBuffer.PositionKind,5126,e,r,h,p,x/4,n,a,_),f.min=_.min.asArray(),f.max=_.max.asArray()}if(r.hasTangents){var g,x,y=e.getMesh().getVerticesData(d.VertexBuffer.TangentKind),T=r.getTangents();u=(g=e.verticesCount)*(x=12),l=m._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_NORMAL"),this._bufferViews.push(l),c=this._bufferViews.length-1,f=m._CreateAccessor(c,r.name+" - TANGENT","VEC3",5126,g,0,null,null),this._accessors.push(f),i.TANGENT=this._accessors.length-1,this.writeMorphTargetAttributeData(d.VertexBuffer.TangentKind,5126,e,r,y,T,x/4,n,a)}t.targets.push(i)}},e.prototype._getMeshPrimitiveMode=function(e){return e instanceof d.LinesMesh?d.Material.LineListDrawMode:e.material?e.material.fillMode:d.Material.TriangleFillMode},e.prototype._setPrimitiveMode=function(e,t){switch(t){case d.Material.TriangleFillMode:break;case d.Material.TriangleStripDrawMode:e.mode=5;break;case d.Material.TriangleFanDrawMode:e.mode=6;break;case d.Material.PointListDrawMode:case d.Material.PointFillMode:e.mode=0;break;case d.Material.LineLoopDrawMode:e.mode=2;break;case d.Material.LineListDrawMode:e.mode=1;break;case d.Material.LineStripDrawMode:e.mode=3}},e.prototype._setAttributeKind=function(e,t){switch(t){case d.VertexBuffer.PositionKind:e.attributes.POSITION=this._accessors.length-1;break;case d.VertexBuffer.NormalKind:e.attributes.NORMAL=this._accessors.length-1;break;case d.VertexBuffer.ColorKind:e.attributes.COLOR_0=this._accessors.length-1;break;case d.VertexBuffer.TangentKind:e.attributes.TANGENT=this._accessors.length-1;break;case d.VertexBuffer.UVKind:e.attributes.TEXCOORD_0=this._accessors.length-1;break;case d.VertexBuffer.UV2Kind:e.attributes.TEXCOORD_1=this._accessors.length-1;break;case d.VertexBuffer.MatricesIndicesKind:e.attributes.JOINTS_0=this._accessors.length-1;break;case d.VertexBuffer.MatricesIndicesExtraKind:e.attributes.JOINTS_1=this._accessors.length-1;break;case d.VertexBuffer.MatricesWeightsKind:e.attributes.WEIGHTS_0=this._accessors.length-1;break;case d.VertexBuffer.MatricesWeightsExtraKind:e.attributes.WEIGHTS_1=this._accessors.length-1;break;default:d.Tools.Warn("Unsupported Vertex Buffer Type: "+t)}},e.prototype._setPrimitiveAttributesAsync=function(e,t,r,n){var a,i,o,s=[],u=null;t instanceof d.Mesh?u=t:t instanceof d.InstancedMesh&&(u=t.sourceMesh);var l=[{kind:d.VertexBuffer.PositionKind,accessorType:"VEC3",accessorComponentType:5126,byteStride:12},{kind:d.VertexBuffer.NormalKind,accessorType:"VEC3",accessorComponentType:5126,byteStride:12},{kind:d.VertexBuffer.ColorKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:d.VertexBuffer.TangentKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:d.VertexBuffer.UVKind,accessorType:"VEC2",accessorComponentType:5126,byteStride:8},{kind:d.VertexBuffer.UV2Kind,accessorType:"VEC2",accessorComponentType:5126,byteStride:8},{kind:d.VertexBuffer.MatricesIndicesKind,accessorType:"VEC4",accessorComponentType:5123,byteStride:8},{kind:d.VertexBuffer.MatricesIndicesExtraKind,accessorType:"VEC4",accessorComponentType:5123,byteStride:8},{kind:d.VertexBuffer.MatricesWeightsKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:d.VertexBuffer.MatricesWeightsExtraKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16}];if(u){for(var c=null,f=this._getMeshPrimitiveMode(u),h={},p=u.morphTargetManager,_=0,g=l;_<g.length;_++){var x=(W=g[_]).kind,y=W.accessorComponentType;if(u.isVerticesDataPresent(x)){var T=this._getVertexBufferFromMesh(x,u);W.byteStride=T?T.getSize()*d.VertexBuffer.GetTypeByteLength(W.accessorComponentType):4*d.VertexBuffer.DeduceStride(x),12===W.byteStride&&(W.accessorType="VEC3"),this._createBufferViewKind(x,y,t,r,W.byteStride,n),W.bufferViewIndex=this._bufferViews.length-1,h[x]=W.bufferViewIndex}}if(u.getTotalIndices()){var v=u.getIndices();if(v){var b=4*v.length;i=m._CreateBufferView(0,r.getByteOffset(),b,void 0,"Indices - "+u.name),this._bufferViews.push(i),c=this._bufferViews.length-1;for(var A=0,E=v.length;A<E;++A)r.setUInt32(v[A])}}if(u.subMeshes)for(var F=0,M=u.subMeshes;F<M.length;F++){var R=M[F],w=R.getMaterial()||u.getScene().defaultMaterial,V=null;if(w)if(u instanceof d.LinesMesh){var C={name:u.name+" material"};(!u.color.equals(d.Color3.White())||u.alpha<1)&&(C.pbrMetallicRoughness={baseColorFactor:u.color.asArray().concat([u.alpha])}),this._materials.push(C),V=this._materials.length-1}else if(w instanceof d.MultiMaterial){var S=w.subMaterials[R.materialIndex];S&&(w=S,V=this._materialMap[w.uniqueId])}else V=this._materialMap[w.uniqueId];var I=null!=V?this._materials[V]:null,B={attributes:{}};this._setPrimitiveMode(B,f);for(var P=0,N=l;P<N.length;P++)if(((x=(W=N[P]).kind)!==d.VertexBuffer.UVKind&&x!==d.VertexBuffer.UV2Kind||this._options.exportUnusedUVs||I&&this._glTFMaterialExporter._hasTexturesPresent(I))&&(z=u.getVerticesData(x))&&(T=this._getVertexBufferFromMesh(x,u))){var O=T.getSize(),L=W.bufferViewIndex;if(null!=L){o={min:null,max:null},x==d.VertexBuffer.PositionKind&&(o=m._CalculateMinMaxPositions(z,0,z.length/O,n));var k=m._CreateAccessor(L,x+" - "+t.name,W.accessorType,W.accessorComponentType,z.length/O,0,o.min,o.max);this._accessors.push(k),this._setAttributeKind(B,x)}}if(c&&(k=m._CreateAccessor(c,"indices - "+t.name,"SCALAR",5125,R.indexCount,4*R.indexStart,null,null),this._accessors.push(k),B.indices=this._accessors.length-1),null!=V&&Object.keys(B.attributes).length>0){var U=null!==u.overrideMaterialSideOrientation?u.overrideMaterialSideOrientation:w.sideOrientation;if(U==d.Material.ClockWiseSideOrientation&&this._babylonScene.useRightHandedSystem||U==d.Material.ClockWiseSideOrientation&&n&&u.overrideMaterialSideOrientation!==(null===(a=u.material)||void 0===a?void 0:a.sideOrientation)){var K=null!=c?this._bufferViews[c].byteOffset:null;null==K&&(K=0);var G=null;if(null!=c&&(G=u.getIndices()),G)this._reorderIndicesBasedOnPrimitiveMode(R,f,G,K,r);else for(var D=0,H=l;D<H.length;D++){var z,W=H[D];if(z=u.getVerticesData(W.kind)){var q=this._bufferViews[h[W.kind]].byteOffset;q||(q=0),this._reorderVertexAttributeDataBasedOnPrimitiveMode(R,f,U,W.kind,z,q,r,n)}}}B.material=V}if(p)for(var Q=void 0,j=0;j<p.numTargets;++j)Q=p.getTarget(j),this._setMorphTargetAttributes(R,B,Q,r,n);e.primitives.push(B),this._extensionsPostExportMeshPrimitiveAsync("postExport",B,R,r),s.push()}}return Promise.all(s).then((function(){}))},e.prototype._isBabylonCoordinateSystemConvertingNode=function(e){return e instanceof d.TransformNode&&"__root__"===e.name&&1!==e.getWorldMatrix().determinant()&&!(e instanceof d.Mesh&&null!==e.geometry||e instanceof d.InstancedMesh&&null!==e.sourceMesh.geometry)&&!this._includeCoordinateSystemConversionNodes},e.prototype._createSceneAsync=function(e,t){var r,n,a,i=this,o={nodes:[]},s=h(h(h(h([],e.transformNodes,!0),e.meshes,!0),e.lights,!0),e.cameras,!0),u=[];this._convertToRightHandedSystem=!e.useRightHandedSystem,this._convertToRightHandedSystemMap={},e.rootNodes.forEach((function(e){i._convertToRightHandedSystemMap[e.uniqueId]=i._convertToRightHandedSystem,e.getDescendants(!1).forEach((function(e){i._convertToRightHandedSystemMap[e.uniqueId]=i._convertToRightHandedSystem}))})),e.rootNodes.forEach((function(e){if(i._isBabylonCoordinateSystemConvertingNode(e)){u.push(e);var t=s.indexOf(e);-1!==t&&s.splice(t,1),e.getDescendants(!1).forEach((function(e){i._convertToRightHandedSystemMap[e.uniqueId]=!1}))}}));var l=new Map;e.cameras.forEach((function(e){if(!i._options.shouldExportNode||i._options.shouldExportNode(e)){var t={type:e.mode===d.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(e.name&&(t.name=e.name),"perspective"===t.type)t.perspective={aspectRatio:e.getEngine().getAspectRatio(e),yfov:e.fovMode===d.Camera.FOVMODE_VERTICAL_FIXED?e.fov:e.fov*e.getEngine().getAspectRatio(e),znear:e.minZ,zfar:e.maxZ};else if("orthographic"===t.type){var r=e.orthoLeft&&e.orthoRight?.5*(e.orthoRight-e.orthoLeft):.5*e.getEngine().getRenderWidth(),n=e.orthoBottom&&e.orthoTop?.5*(e.orthoTop-e.orthoBottom):.5*e.getEngine().getRenderHeight();t.orthographic={xmag:r,ymag:n,znear:e.minZ,zfar:e.maxZ}}l.set(e,i._cameras.length),i._cameras.push(t)}}));var c=this._getExportNodes(s),f=c[0],p=c[1];return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(p,"image/png",!0).then((function(){return i._createNodeMapAndAnimationsAsync(e,f,t).then((function(c){return i._createSkinsAsync(e,c,t).then((function(e){if(i._nodeMap=c,i._totalByteLength=t.getByteOffset(),null==i._totalByteLength)throw new Error("undefined byte length!");for(var f=0,h=s;f<h.length;f++){var p=h[f];if(void 0!==(r=i._nodeMap[p.uniqueId])){if(n=i._nodes[r],p.metadata&&(i._options.metadataSelector?n.extras=i._options.metadataSelector(p.metadata):p.metadata.gltf&&(n.extras=p.metadata.gltf.extras)),p instanceof d.Camera&&(n.camera=l.get(p)),p.parent&&-1===u.indexOf(p.parent)||(i._options.shouldExportNode&&!i._options.shouldExportNode(p)?d.Tools.Log("Omitting "+p.name+" from scene."):(i._convertToRightHandedSystemMap[p.uniqueId]&&(n.translation&&(n.translation[2]*=-1,n.translation[0]*=-1),n.rotation=n.rotation?d.Quaternion.FromArray([0,1,0,0]).multiply(d.Quaternion.FromArray(n.rotation)).asArray():d.Quaternion.FromArray([0,1,0,0]).asArray()),o.nodes.push(r))),p instanceof d.Mesh){var _=p;_.skeleton&&(n.skin=e[_.skeleton.uniqueId])}if(a=p.getDescendants(!0),!n.children&&a&&a.length){for(var m=[],g=0,x=a;g<x.length;g++){var y=x[g];null!=i._nodeMap[y.uniqueId]&&m.push(i._nodeMap[y.uniqueId])}m.length&&(n.children=m)}}}o.nodes.length&&i._scenes.push(o)}))}))}))},e.prototype._getExportNodes=function(e){for(var t=[],r=new Set,n=0,a=e;n<a.length;n++){var i=a[n];if(!this._options.shouldExportNode||this._options.shouldExportNode(i)){t.push(i);var o=i;if(o.subMeshes&&o.subMeshes.length>0){var s=o.material||o.getScene().defaultMaterial;if(s instanceof d.MultiMaterial)for(var u=0,l=s.subMaterials;u<l.length;u++){var c=l[u];c&&r.add(c)}else r.add(s)}}else"Excluding node ".concat(i.name)}return[t,r]},e.prototype._createNodeMapAndAnimationsAsync=function(e,t,r){for(var n,a=this,i=Promise.resolve(),o={},s={name:"runtime animations",channels:[],samplers:[]},u=[],l=function(t){i=i.then((function(){var i=a._convertToRightHandedSystemMap[t.uniqueId];return a._createNodeAsync(t,r,i).then((function(l){var c=a._extensionsPostExportNodeAsync("createNodeAsync",l,t,o,r);return null==c?(d.Tools.Warn("Not exporting node ".concat(t.name)),Promise.resolve()):c.then((function(l){l&&(a._nodes.push(l),n=a._nodes.length-1,o[t.uniqueId]=n,e.animationGroups.length||(g._CreateMorphTargetAnimationFromMorphTargetAnimations(t,s,u,o,a._nodes,r,a._bufferViews,a._accessors,i,a._animationSampleRate),t.animations.length&&g._CreateNodeAnimationFromNodeAnimations(t,s,u,o,a._nodes,r,a._bufferViews,a._accessors,i,a._animationSampleRate)))}))}))}))},c=0,f=t;c<f.length;c++)l(f[c]);return i.then((function(){return s.channels.length&&s.samplers.length&&a._animations.push(s),u.forEach((function(e){e.channels.length&&e.samplers.length&&a._animations.push(e)})),e.animationGroups.length&&g._CreateNodeAndMorphAnimationFromAnimationGroups(e,a._animations,o,a._nodes,r,a._bufferViews,a._accessors,a._convertToRightHandedSystemMap,a._animationSampleRate),o}))},e.prototype._createNodeAsync=function(e,t,r){var n=this;return Promise.resolve().then((function(){var a={},i={primitives:[]};if(e.name&&(a.name=e.name),e instanceof d.TransformNode){if(n._setNodeTransformation(a,e,r),e instanceof d.Mesh){var o=e.morphTargetManager;if(o&&o.numTargets>0){i.weights=[];for(var s=0;s<o.numTargets;++s)i.weights.push(o.getTarget(s).influence)}}return n._setPrimitiveAttributesAsync(i,e,t,r).then((function(){return i.primitives.length&&(n._meshes.push(i),a.mesh=n._meshes.length-1),a}))}return e instanceof d.Camera?(n._setCameraTransformation(a,e,r),a):a}))},e.prototype._createSkinsAsync=function(e,t,r){for(var n,a=Promise.resolve(),i={},o=0,s=e.skeletons;o<s.length;o++){var u=s[o];if(!(u.bones.length<=0)){for(var l={joints:[]},c=[],f={},h=-1,p=0;p<u.bones.length;++p)-1!==(_=null!==(n=(g=u.bones[p]).getIndex())&&void 0!==n?n:p)&&(f[_]=g,_>h&&(h=_));for(var _=0;_<=h;++_){var g=f[_];c.push(g.getInvertedAbsoluteTransform());var x=g.getTransformNode();x?l.joints.push(t[x.uniqueId]):d.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}var y=64*c.length,T=r.getByteOffset(),v=m._CreateBufferView(0,T,y,void 0,"InverseBindMatrices - "+u.name);this._bufferViews.push(v);var b=this._bufferViews.length-1,A=m._CreateAccessor(b,"InverseBindMatrices - "+u.name,"MAT4",5126,c.length,null,null,null),E=this._accessors.push(A)-1;l.inverseBindMatrices=E,this._skins.push(l),i[u.uniqueId]=this._skins.length-1,c.forEach((function(e){e.m.forEach((function(e){r.setFloat32(e)}))}))}}return a.then((function(){return i}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),y=function(){function e(e){this._arrayBuffer=new ArrayBuffer(e),this._dataView=new DataView(this._arrayBuffer),this._byteOffset=0}return e.prototype._resizeBuffer=function(e){for(var t=new ArrayBuffer(e),r=new Uint8Array(this._arrayBuffer),n=new Uint8Array(t),a=0,i=n.byteLength;a<i;++a)n[a]=r[a];return this._arrayBuffer=t,this._dataView=new DataView(this._arrayBuffer),t},e.prototype.getArrayBuffer=function(){return this._resizeBuffer(this.getByteOffset())},e.prototype.getByteOffset=function(){if(null==this._byteOffset)throw new Error("Byte offset is undefined!");return this._byteOffset},e.prototype.setUInt8=function(e,t){null!=t?t<this._byteOffset?this._dataView.setUint8(t,e):d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+1>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint8(this._byteOffset,e),this._byteOffset+=1)},e.prototype.setUInt16=function(e,t){null!=t?t<this._byteOffset?this._dataView.setUint16(t,e,!0):d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+2>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2)},e.prototype.getUInt32=function(e){if(e<this._byteOffset)return this._dataView.getUint32(e,!0);throw d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"),new Error("BinaryWriter: byteoffset is greater than the current binary buffer length!")},e.prototype.getVector3Float32FromRef=function(e,t){t+8>this._byteOffset?d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(e.x=this._dataView.getFloat32(t,!0),e.y=this._dataView.getFloat32(t+4,!0),e.z=this._dataView.getFloat32(t+8,!0))},e.prototype.setVector3Float32FromRef=function(e,t){t+8>this._byteOffset?d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(t,e.x,!0),this._dataView.setFloat32(t+4,e.y,!0),this._dataView.setFloat32(t+8,e.z,!0))},e.prototype.getVector4Float32FromRef=function(e,t){t+12>this._byteOffset?d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(e.x=this._dataView.getFloat32(t,!0),e.y=this._dataView.getFloat32(t+4,!0),e.z=this._dataView.getFloat32(t+8,!0),e.w=this._dataView.getFloat32(t+12,!0))},e.prototype.setVector4Float32FromRef=function(e,t){t+12>this._byteOffset?d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(t,e.x,!0),this._dataView.setFloat32(t+4,e.y,!0),this._dataView.setFloat32(t+8,e.z,!0),this._dataView.setFloat32(t+12,e.w,!0))},e.prototype.setFloat32=function(e,t){isNaN(e)&&d.Tools.Error("Invalid data being written!"),null!=t&&(t<this._byteOffset?this._dataView.setFloat32(t,e,!0):d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary length!")),this._byteOffset+4>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.setUInt32=function(e,t){null!=t?t<this._byteOffset?this._dataView.setUint32(t,e,!0):d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+4>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4)},e.prototype.setInt16=function(e,t){null!=t?t<this._byteOffset?this._dataView.setInt16(t,e,!0):d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+2>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setInt16(this._byteOffset,e,!0),this._byteOffset+=2)},e.prototype.setByte=function(e,t){null!=t?t<this._byteOffset?this._dataView.setInt8(t,e):d.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+1>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setInt8(this._byteOffset,e),this._byteOffset++)},e}(),T=function(){function e(){}return e.GLTFAsync=function(e,t,r){return e.whenReadyAsync().then((function(){var n=t.replace(/\.[^/.]+$/,"");return new x(e,r)._generateGLTFAsync(n)}))},e._PreExportAsync=function(e,t){return Promise.resolve().then((function(){return t&&t.exportWithoutWaitingForScene?Promise.resolve():e.whenReadyAsync()}))},e._PostExportAsync=function(e,t,r){return Promise.resolve().then((function(){return r&&r.exportWithoutWaitingForScene,t}))},e.GLBAsync=function(e,t,r){var n=this;return this._PreExportAsync(e,r).then((function(){var a=t.replace(/\.[^/.]+$/,"");return new x(e,r)._generateGLBAsync(a).then((function(t){return n._PostExportAsync(e,t,r)}))}))},e}(),v="KHR_texture_transform",b=function(){function e(){this.name=v,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&&(0===r.uAng&&0===r.wAng&&0===r.vAng||0===r.uRotationCenter&&0===r.vRotationCenter)){var n={},a=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],a=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],a=!0),0!==r.wAng&&(n.rotation=r.wAng,a=!0),0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,a=!0),!a)return;this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[v]=n}},e.prototype.preExportTextureAsync=function(e,t){return new Promise((function(r,n){t.getScene()?0===t.uAng&&0===t.wAng&&0===t.vAng||0===t.uRotationCenter&&0===t.vRotationCenter?r(t):(d.Tools.Warn("".concat(e,": Texture ").concat(t.name," with rotation not centered at the origin cannot be exported with ").concat(v)),r(null)):n("".concat(e,': "scene" is not defined for Babylon texture ').concat(t.name,"!"))}))},e}();x.RegisterExtension(v,(function(){return new b}));var A="KHR_lights_punctual",E=function(){function e(e){this.name=A,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.KHR_lights_punctual=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,n){var a=this;return new Promise((function(i){if(t&&r instanceof d.ShadowLight){var o=r,s=void 0,u=o.getTypeID()==d.Light.LIGHTTYPEID_POINTLIGHT?"point":o.getTypeID()==d.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":o.getTypeID()==d.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(null==u)d.Logger.Warn("".concat(e,": Light ").concat(o.name," is not supported in ").concat(A));else{var l=o.position.clone(),c=a._exporter._convertToRightHandedSystemMap[r.uniqueId];if(l.equals(d.Vector3.Zero())||(c&&m._GetRightHandedPositionVector3FromRef(l),t.translation=l.asArray()),"point"!==u){var f=o.direction,h=-Math.atan2(f.z*(a._exporter._babylonScene.useRightHandedSystem?-1:1),f.x)+Math.PI/2,p=Math.sqrt(f.x*f.x+f.z*f.z),_=-Math.atan2(f.y,p),g=d.Quaternion.RotationYawPitchRoll(h,_,0);c&&m._GetRightHandedQuaternionFromRef(g),g.equals(d.Quaternion.Identity())||(t.rotation=g.asArray())}if(o.falloffType!==d.Light.FALLOFF_GLTF&&d.Logger.Warn("".concat(e,": Light falloff for ").concat(o.name," does not match the ").concat(A," specification!")),s={type:u},o.diffuse.equals(d.Color3.White())||(s.color=o.diffuse.asArray()),1!==o.intensity&&(s.intensity=o.intensity),o.range!==Number.MAX_VALUE&&(s.range=o.range),"spot"===u){var x=o;x.angle!==Math.PI/2&&(null==s.spot&&(s.spot={}),s.spot.outerConeAngle=x.angle/2),0!==x.innerAngle&&(null==s.spot&&(s.spot={}),s.spot.innerConeAngle=x.innerAngle/2)}null==a._lights&&(a._lights={lights:[]}),a._lights.lights.push(s);var y={light:a._lights.lights.length-1},T=r.parent;if(T&&1==T.getChildren().length){var v=a._exporter._nodes[n[T.uniqueId]];if(v){var b=d.TmpVectors.Matrix[0],E=d.TmpVectors.Matrix[1],F=v.translation?new d.Vector3(v.translation[0],v.translation[1],v.translation[2]):d.Vector3.Zero(),M=v.rotation?new d.Quaternion(v.rotation[0],v.rotation[1],v.rotation[2],v.rotation[3]):d.Quaternion.Identity(),R=v.scale?new d.Vector3(v.scale[0],v.scale[1],v.scale[2]):d.Vector3.One();d.Matrix.ComposeToRef(R,M,F,b),b.invertToRef(E);var w=d.TmpVectors.Matrix[2],V=t.translation?new d.Vector3(t.translation[0],t.translation[1],t.translation[2]):d.Vector3.Zero();o instanceof d.DirectionalLight&&V.subtractInPlace(a._exporter._babylonScene.useRightHandedSystem?o.direction:m._GetRightHandedPositionVector3(o.direction));var C=a._exporter._babylonScene.useRightHandedSystem?d.Quaternion.Identity():new d.Quaternion(0,1,0,0);t.rotation&&C.multiplyInPlace(new d.Quaternion(t.rotation[0],t.rotation[1],t.rotation[2],t.rotation[3]));var S=t.scale?new d.Vector3(t.scale[0],t.scale[1],t.scale[2]):d.Vector3.One();d.Matrix.ComposeToRef(S,C,V,w),w.multiplyToRef(E,w);var I=d.TmpVectors.Vector3[0],B=d.TmpVectors.Quaternion[0],P=d.TmpVectors.Vector3[1];return w.decompose(I,B,P),v.scale=I.asArray(),v.rotation=B.asArray(),v.translation=P.asArray(),null==v.extensions&&(v.extensions={}),v.extensions.KHR_lights_punctual=y,void i(null)}}null==t.extensions&&(t.extensions={}),t.extensions.KHR_lights_punctual=y}}i(t)}))},e}();x.RegisterExtension(A,(function(e){return new E(e)}));var F="KHR_materials_clearcoat",M=function(){function e(e){this.name=F,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 a,i=n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.texture);a=r.clearCoat.useRoughnessFromMainTexture?n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.texture):n._exporter._glTFMaterialExporter._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._glTFMaterialExporter._getTextureInfo(r.clearCoat.bumpTexture),s={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=i?i:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=a?a:void 0,clearcoatNormalTexture:null!=o?o:void 0,hasTextures:function(){return null!==s.clearcoatTexture||null!==s.clearcoatRoughnessTexture||null!==s.clearcoatRoughnessTexture}};t.extensions.KHR_materials_clearcoat=s}e(t)}))},e}();x.RegisterExtension(F,(function(e){return new M(e)}));var R="KHR_materials_iridescence",w=function(){function e(e){this.name=R,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 a=n._exporter._glTFMaterialExporter._getTextureInfo(r.iridescence.texture),i=n._exporter._glTFMaterialExporter._getTextureInfo(r.iridescence.thicknessTexture),o={iridescenceFactor:r.iridescence.intensity,iridescenceIor:r.iridescence.indexOfRefraction,iridescenceThicknessMinimum:r.iridescence.minimumThickness,iridescenceThicknessMaximum:r.iridescence.maximumThickness,iridescenceTexture:null!=a?a:void 0,iridescenceThicknessTexture:null!=i?i:void 0,hasTextures:function(){return null!==o.iridescenceTexture||null!==o.iridescenceThicknessTexture}};t.extensions.KHR_materials_iridescence=o}e(t)}))},e}();x.RegisterExtension(R,(function(e){return new w(e)}));var V="KHR_materials_sheen",C=function(){function e(e){this.name=V,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){return r instanceof d.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[r.sheen.texture]:[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var a,i,o,s;if(r instanceof d.PBRMaterial){if(!r.sheen.isEnabled)return void e(t);n._wasUsed=!0,null==t.extensions&&(t.extensions={});var u={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(a=r.sheen.roughness)&&void 0!==a?a:0,hasTextures:function(){return null!==u.sheenColorTexture||null!==u.sheenRoughnessTexture}};r.sheen.texture&&(u.sheenColorTexture=null!==(i=n._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.texture))&&void 0!==i?i:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(o=n._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.textureRoughness))&&void 0!==o?o:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(s=n._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.texture))&&void 0!==s?s:void 0),t.extensions.KHR_materials_sheen=u}e(t)}))},e}();x.RegisterExtension(V,(function(e){return new C(e)}));var S="KHR_materials_unlit",I=function(){function e(){this.name=S,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 a=!1;r instanceof d.PBRMaterial?a=r.unlit:r instanceof d.StandardMaterial&&(a=r.disableLighting),a&&(n._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions.KHR_materials_unlit={}),e(t)}))},e}();x.RegisterExtension(S,(function(){return new I}));var B="KHR_materials_ior",P=function(){function e(){this.name=B,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 a={ior:r.indexOfRefraction};t.extensions=t.extensions||{},t.extensions.KHR_materials_ior=a}e(t)}))},e}();x.RegisterExtension(B,(function(e){return new P}));var N="KHR_materials_specular",O=function(){function e(e){this.name=N,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 a,i;if(r instanceof d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0,t.extensions=t.extensions||{};var o=null!==(a=n._exporter._glTFMaterialExporter._getTextureInfo(r.metallicReflectanceTexture))&&void 0!==a?a:void 0,s=null!==(i=n._exporter._glTFMaterialExporter._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:s,hasTextures:function(){return n._hasTexturesExtension(r)}};t.extensions.KHR_materials_specular=u}e(t)}))},e}();x.RegisterExtension(N,(function(e){return new O(e)}));var L="KHR_materials_volume",k=function(){function e(e){this.name=L,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 a;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!==(a=n._exporter._glTFMaterialExporter._getTextureInfo(i.thicknessTexture))&&void 0!==a?a:void 0,attenuationDistance:i.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:i.tintColorAtDistance,attenuationColor:i.tintColor.equalsFloats(1,1,1)?void 0:i.tintColor.asArray(),hasTextures:function(){return n._hasTexturesExtension(r)}};t.extensions=t.extensions||{},t.extensions.KHR_materials_volume=o}e(t)}))},e}();x.RegisterExtension(L,(function(e){return new k(e)}));var U="KHR_materials_transmission",K=function(){function e(e){this.name=U,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){var n=this;return new Promise((function(e){var a;if(r instanceof d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var i=r.subSurface,o={transmissionFactor:0===i.refractionIntensity?void 0:i.refractionIntensity,transmissionTexture:null!==(a=n._exporter._glTFMaterialExporter._getTextureInfo(i.refractionIntensityTexture))&&void 0!==a?a:void 0,hasTextures:function(){return n._hasTexturesExtension(r)}};t.extensions=t.extensions||{},t.extensions.KHR_materials_transmission=o}e(t)}))},e}();x.RegisterExtension(U,(function(e){return new K(e)}));var G="EXT_mesh_gpu_instancing",D=function(){function e(e){this.name=G,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,a){var i=this;return new Promise((function(e){if(t&&r instanceof d.Mesh&&r.hasThinInstances&&a){i._wasUsed=!0;for(var n=d.Vector3.Zero(),o=d.Quaternion.Identity(),s=d.Vector3.One(),u=r.thinInstanceGetWorldMatrices(),l=d.TmpVectors.Vector3[2],c=d.TmpVectors.Quaternion[1],f=d.TmpVectors.Vector3[3],h=!1,p=!1,_=!1,m=new Float32Array(3*r.thinInstanceCount),g=new Float32Array(4*r.thinInstanceCount),x=new Float32Array(3*r.thinInstanceCount),y=0,T=0,v=u;T<v.length;T++)v[T].decompose(f,c,l),m.set(l.asArray(),3*y),g.set(c.normalize().asArray(),4*y),x.set(f.asArray(),3*y),h=h||!l.equalsWithEpsilon(n),p=p||!c.equalsWithEpsilon(o),_=_||!f.equalsWithEpsilon(s),y++;var b={attributes:{}};h&&(b.attributes.TRANSLATION=i._buildAccessor(m,"VEC3",r.thinInstanceCount,a,5126)),p&&(b.attributes.ROTATION=i._buildAccessor(g,"VEC4",r.thinInstanceCount,a,5126)),_&&(b.attributes.SCALE=i._buildAccessor(x,"VEC3",r.thinInstanceCount,a,5126)),t.extensions=t.extensions||{},t.extensions.EXT_mesh_gpu_instancing=b}e(t)}))},e.prototype._buildAccessor=function(e,t,r,n,a){var i=n.getByteOffset();switch(a){case 5126:for(var o=0;o!=e.length;o++)n.setFloat32(e[o]);break;case 5120:for(o=0;o!=e.length;o++)n.setByte(127*e[o]);break;case 5122:for(o=0;o!=e.length;o++)n.setInt16(32767*e[o])}var s={buffer:0,byteOffset:i,byteLength:e.length*d.VertexBuffer.GetTypeByteLength(a)},u=this._exporter._bufferViews.length;this._exporter._bufferViews.push(s);var l=this._exporter._accessors.length,c={bufferView:u,componentType:a,count:r,type:t,normalized:5120==a||5122==a};return this._exporter._accessors.push(c),l},e}();x.RegisterExtension(G,(function(e){return new D(e)}));var H=0,z=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==z){z.BABYLON=z.BABYLON||{};var W=z.BABYLON;W.GLTF2=W.GLTF2||{},W.GLTF2.Exporter=W.GLTF2.Exporter||{},W.GLTF2.Exporter.Extensions=W.GLTF2.Exporter.Extensions||{};var q=[];for(var Q in e)W[Q]=e[Q],q.push(Q);for(var Q in t)W[Q]=t[Q],q.push(Q);for(var Q in r)W[Q]=r[Q],q.push(Q);for(var Q in i)W.GLTF2.Exporter.Extensions[Q]=i[Q],q.push(Q);for(var Q in o)q.indexOf(Q)>-1||(W.GLTF2.Exporter[Q]=o[Q])}const j=s})(),a.default})()));
2
2
  //# sourceMappingURL=babylon.glTF2Serializer.min.js.map