babylonjs-serializers 6.43.0 → 6.45.0

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:()=>ne});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:()=>A});var i={};n.r(i),n.d(i,{EXT_mesh_gpu_instancing:()=>Y,KHR_lights_punctual:()=>w,KHR_materials_anisotropy:()=>B,KHR_materials_clearcoat:()=>V,KHR_materials_dispersion:()=>q,KHR_materials_emissive_strength:()=>Z,KHR_materials_ior:()=>k,KHR_materials_iridescence:()=>S,KHR_materials_sheen:()=>N,KHR_materials_specular:()=>D,KHR_materials_transmission:()=>j,KHR_materials_unlit:()=>L,KHR_materials_volume:()=>W,KHR_texture_transform:()=>M});var o={};n.r(o),n.d(o,{EXT_mesh_gpu_instancing:()=>Y,GLTF2Export:()=>A,GLTFData:()=>l,KHR_lights_punctual:()=>w,KHR_materials_anisotropy:()=>B,KHR_materials_clearcoat:()=>V,KHR_materials_dispersion:()=>q,KHR_materials_emissive_strength:()=>Z,KHR_materials_ior:()=>k,KHR_materials_iridescence:()=>S,KHR_materials_sheen:()=>N,KHR_materials_specular:()=>D,KHR_materials_transmission:()=>j,KHR_materials_unlit:()=>L,KHR_materials_volume:()=>W,KHR_texture_transform:()=>M,_BinaryWriter:()=>b,_Exporter:()=>v,_GLTFAnimation:()=>m,_GLTFMaterialExporter:()=>_,_GLTFUtilities:()=>g,__IGLTFExporterExtensionV2:()=>J});var s={};n.r(s),n.d(s,{EXT_mesh_gpu_instancing:()=>Y,GLTF2Export:()=>A,GLTFData:()=>l,KHR_lights_punctual:()=>w,KHR_materials_anisotropy:()=>B,KHR_materials_clearcoat:()=>V,KHR_materials_dispersion:()=>q,KHR_materials_emissive_strength:()=>Z,KHR_materials_ior:()=>k,KHR_materials_iridescence:()=>S,KHR_materials_sheen:()=>N,KHR_materials_specular:()=>D,KHR_materials_transmission:()=>j,KHR_materials_unlit:()=>L,KHR_materials_volume:()=>W,KHR_texture_transform:()=>M,_BinaryWriter:()=>b,_Exporter:()=>v,_GLTFAnimation:()=>m,_GLTFMaterialExporter:()=>_,_GLTFUtilities:()=>g,__IGLTFExporterExtension:()=>u,__IGLTFExporterExtensionV2:()=>J});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(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(o=0)),o;)try{if(r=1,n&&(a=2&s[0]?n.return:s[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,s[1])).done)return a;switch(n=0,a&&(s=[2&s[0],a.value]),s[0]){case 0:case 1:a=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,n=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!((a=(a=o.trys).length>0&&a[a.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!a||s[1]>a[0]&&s[1]<a[3])){o.label=s[1];break}if(6===s[0]&&o.label<a[1]){o.label=a[1],a=s;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(s);break}a[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],n=0}finally{r=a=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}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,"function"==typeof SuppressedError&&SuppressedError;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(t.getScene().getEngine().useExactSrgbConversions).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.DumpTools.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,_,g,m,x,y,T,v,b,A,E,M,F,w,C,V,R,S,I,B,P,N,O,L,U;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 g=f.sent(),[4,u.texture2.readPixels()];case 2:if(m=f.sent(),!g)return[2,Promise.reject("Failed to retrieve pixels from diffuse texture!")];if(c=this._convertPixelArrayToFloat32(g),!m)return[2,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];for(h=this._convertPixelArrayToFloat32(m),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),M=new d.Color3(c[E],c[E+1],c[E+2]).toLinearSpace(s.getEngine().useExactSrgbConversions).multiply(n.diffuseColor),F=new d.Color3(h[E],h[E+1],h[E+2]).toLinearSpace(s.getEngine().useExactSrgbConversions).multiply(n.specularColor),w=h[E+3]*n.glossiness,C={diffuseColor:M,specularColor:F,glossiness:w},V=this._convertSpecularGlossinessToMetallicRoughness(C),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(R={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)]/=R.baseColor.r>e._Epsilon?R.baseColor.r:1,T[N+1]/=R.baseColor.g>e._Epsilon?R.baseColor.g:1,T[N+2]/=R.baseColor.b>e._Epsilon?R.baseColor.b:1,O=d.Color3.FromInts(T[N],T[N+1],T[N+2]),L=O.toGammaSpace(s.getEngine().useExactSrgbConversions),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]/=R.roughness>e._Epsilon?R.roughness:1,y[N+2]/=R.metallic>e._Epsilon?R.metallic:1,U=d.Color3.FromInts(255,y[N+1],y[N+2]),e._FuzzyEquals(U,d.Color3.White(),e._Epsilon)||(S=!0);return S&&o.push(this._getImageDataAsync(y,p,_,a).then((function(e){R.metallicRoughnessTextureData=e}))),I&&o.push(this._getImageDataAsync(T,p,_,a).then((function(e){R.baseColorTextureData=e}))),[2,Promise.all(o).then((function(){return R}))];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,extensions:e.extensions};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,h,p,_=this;return f(this,(function(g){switch(g.label){case 0:return(r=e.uid)in this._textureMap?[3,3]:[4,this._getPixelsFromTexture(e)];case 1:if(!(n=g.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: ".concat(i))}return o=this._internalTextureToImage,s=e.getInternalTexture().uniqueId,o[s]||(o[s]={}),void 0===(u=o[s][t])&&(l=e.getSize(),u=c(_,void 0,void 0,(function(){var r;return f(this,(function(a){switch(a.label){case 0:return[4,this._getImageDataAsync(n,l.width,l.height,t)];case 1:return r=a.sent(),[2,this._exportImage(e.name,t,r)]}}))})),o[s][t]=u),p=this._exportTextureInfo,[4,u];case 2:h=p.apply(this,[g.sent(),a,e.coordinatesIndex]),this._textureMap[r]=h,this._exporter._extensionsPostExportTextures("exporter",this._textureMap[r],e),g.label=3;case 3:return[2,this._textureMap[r]]}}))}))},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}(),g=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(e,t,r){var n,a,i=[1/0,1/0,1/0],o=[-1/0,-1/0,-1/0];if(r)for(var s=t,u=t+r;s<u;++s){n=3*s,a=d.Vector3.FromArray(e,n).asArray();for(var l=0;l<3;++l){var c=a[l];c<i[l]&&(i[l]=c),c>o[l]&&(o[l]=c),++n}}return{min:i,max:o}},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 m=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){if(this._IsTransformable(t)){var o=[],s=[],u=r.getKeys(),l=e._CalculateMinMaxKeyFrames(u),c=e._DeduceInterpolation(u,n,a),f=c.interpolationType,h=c.shouldBakeAnimation;if(h?e._CreateBakedAnimation(t,r,n,l.min,l.max,r.framePerSecond,i,o,s,l,a):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(t,r,n,o,s,a):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(t,r,n,o,s,a):e._CreateBakedAnimation(t,r,n,l.min,l.max,r.framePerSecond,i,o,s,l,a),o.length&&s.length)return{inputs:o,outputs:s,samplerInterpolation:f,inputsMin:h?l.min:d.Tools.FloatRound(l.min/r.framePerSecond),inputsMax:h?l.max:d.Tools.FloatRound(l.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];if(!c||c(d)){var _=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,_.useQuaternion,l),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,g=h.getTarget(p).animations;_<g.length;_++){var m=g[_];if(!c||c(m)){for(var x=new d.Animation("".concat(m.name),"influence",m.framePerSecond,m.dataType,m.loopMode,m.enableBlending),y=[],T=m.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(m.name,m.hasRunningRuntimeAnimations?r:f,t,x,E.dataAccessorType,E.animationChannelTargetPath,a,o,s,u,E.useQuaternion,l,h.numTargets),f.samplers.length&&f.channels.length&&n.push(f))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,a,i,o,s,u){var l,c;if(t.animationGroups)for(var f=t.animationGroups,h=function(f){var h=new Map,_=new Map,g=new Set,m=f.to-f.from;c={name:f.name,channels:[],samplers:[]};for(var x=function(r){var m=f.targetedAnimations[r],x=m.target,y=m.animation;if(u&&!u(y))return"continue";if(p._IsTransformable(x)||1===x.length&&p._IsTransformable(x[0])){if(v=e._DeduceAnimationInfo(m.animation)){var T=p._IsTransformable(x)?x:p._IsTransformable(x[0])?x[0]:null;T&&e._AddAnimation("".concat(y.name),c,T,y,v.dataAccessorType,v.animationChannelTargetPath,n,a,i,o,v.useQuaternion,s)}}else if(x instanceof d.MorphTarget||1===x.length&&x[0]instanceof d.MorphTarget){var v;if(v=e._DeduceAnimationInfo(m.animation)){var b=x instanceof d.MorphTarget?x:x[0];if(b){var A=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===b)return!0;return!1}));if(A){var E=t.meshes.find((function(e){return e.morphTargetManager===A}));E&&(h.has(E)||h.set(E,new Map),null===(l=h.get(E))||void 0===l||l.set(b,y),g.add(E),_.set(E,y))}}}}},y=0;y<f.targetedAnimations.length;++y)x(y);g.forEach((function(t){for(var r=t.morphTargetManager,u=null,l=[],p=_.get(t).getKeys(),g=p.length,x=0;x<g;++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(f.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,d.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),l.push(b.getKeys()[x])):l.push({frame:f.from+m/g*x,value:T.influence,inTangent:p[0].inTangent?0:void 0,outTangent:p[0].outTangent?0:void 0})}}u.setKeys(l);var A=e._DeduceAnimationInfo(u);A&&e._AddAnimation("".concat(f.name,"_").concat(t.name,"_MorphWeightAnimation"),c,t,u,A.dataAccessorType,A.animationChannelTargetPath,n,a,i,o,A.useQuaternion,s,null==r?void 0:r.numTargets)})),c.channels.length&&c.samplers.length&&r.push(c)},p=this,_=0,g=f;_<g.length;_++)h(g[_])},e._AddAnimation=function(t,r,n,a,i,o,s,u,l,c,f,h,p){var d,_,m,x,y,T,v,b=e._CreateNodeAnimation(n,a,o,f,h);if(b){if(p){for(var A=0,E=0,M=[];b.inputs.length>0;)E=b.inputs.shift(),A%p==0&&M.push(E),A++;b.inputs=M}var F=s[n.uniqueId],w=4*b.inputs.length;d=g._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," keyframe data view")),l.push(d),b.inputs.forEach((function(e){u.setFloat32(e)})),_=g._CreateAccessor(l.length-1,"".concat(t," keyframes"),"SCALAR",5126,b.inputs.length,null,[b.inputsMin],[b.inputsMax]),c.push(_),m=c.length-1,y=b.outputs.length,w=4*g._GetDataAccessorElementCount(i)*b.outputs.length,d=g._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," data view")),l.push(d),b.outputs.forEach((function(e){e.forEach((function(e){u.setFloat32(e)}))})),_=g._CreateAccessor(l.length-1,"".concat(t," data"),i,5126,y,null,null,null),c.push(_),x=c.length-1,T={interpolation:b.samplerInterpolation,input:m,output:x},r.samplers.push(T),v={sampler:r.samplers.length-1,target:{node:F,path:o}},r.channels.push(v)}},e._CreateBakedAnimation=function(t,r,n,a,i,o,s,u,l,c,f){var h,p,_=d.Quaternion.Identity(),g=null,m=null,x=null,y=null,T=null,v=null;c.min=d.Tools.FloatRound(a/o);for(var b=r.getKeys(),A=0,E=b.length;A<E;++A){if(v=null,x=b[A],A+1<E)if(y=b[A+1],x.value.equals&&x.value.equals(y.value)||x.value===y.value){if(0!==A)continue;v=x.frame}else v=y.frame;else{if(T=b[A-1],x.value.equals&&x.value.equals(T.value)||x.value===T.value)continue;v=i}if(v)for(var M=x.frame;M<=v;M+=s)if((p=d.Tools.FloatRound(M/o))!==g){g=p,m=p;var F={key:0,repeatCount:0,loopMode:r.loopMode};h=r._interpolate(M,F),e._SetInterpolatedValue(t,h,p,r,n,_,u,l,f)}}m&&(c.max=m)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,a,i){var o=e._GetBasePositionRotationOrScale(r,a,i),s=n.targetProperty.split("."),u=s?s[1]:"",l=i?d.Quaternion.FromArray(o).normalize():d.Vector3.FromArray(o);switch(u){case"x":case"y":case"z":l[u]=t;break;case"w":l.w=t;break;default:d.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return l},e._SetInterpolatedValue=function(e,t,r,n,a,i,o,s,u){var l;o.push(r),"weights"!==a?(n.dataType===d.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,a,u)),"rotation"===a?(u?i=t:(l=t,d.Quaternion.RotationYawPitchRollToRef(l.y,l.x,l.z,i)),s.push(i.asArray())):(l=t,s.push(l.asArray()))):s.push([t])},e._CreateLinearOrStepAnimation=function(t,r,n,a,i,o){for(var s=0,u=r.getKeys();s<u.length;s++){var l=u[s];a.push(l.frame/r.framePerSecond),e._AddKeyframeValue(l,r,i,n,t,o)}},e._CreateCubicSplineAnimation=function(t,r,n,a,i,o){r.getKeys().forEach((function(s){a.push(s.frame/r.framePerSecond),e._AddSplineTangent(p.INTANGENT,i,n,"CUBICSPLINE",s,o),e._AddKeyframeValue(s,r,i,n,t,o),e._AddSplineTangent(p.OUTTANGENT,i,n,"CUBICSPLINE",s,o)}))},e._GetBasePositionRotationOrScale=function(e,t,r){var n;if("rotation"===t)if(r){var a=e.rotationQuaternion;n=(null!=a?a:d.Quaternion.Identity()).asArray()}else{var i=e.rotation;n=(null!=i?i:d.Vector3.Zero()).asArray()}else if("translation"===t){var o=e.position;n=(null!=o?o:d.Vector3.Zero()).asArray()}else{var s=e.scaling;n=(null!=s?s:d.Vector3.One()).asArray()}return n},e._AddKeyframeValue=function(e,t,r,n,a,i){var o,s=t.dataType;if(s===d.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===n){var l=d.Vector3.FromArray(u);u=d.Quaternion.RotationYawPitchRoll(l.y,l.x,l.z).asArray()}r.push(u)}else if(s===d.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(o=this._ConvertFactorToVector3OrQuaternion(e.value,a,t,n,i)){if("rotation"===n){var c=i?o:d.Quaternion.RotationYawPitchRoll(o.y,o.x,o.z).normalize();r.push(c.asArray())}r.push(o.asArray())}}else s===d.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):d.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,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){var o,s=e===p.INTANGENT?a.inTangent:a.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(s)if(i)o=s.asArray();else{var u=s;o=d.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else o=[0,0,0,0];else o="weights"===r?s?[s]:[0]:s?s.asArray():[0,0,0];t.push(o)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,r=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),r=Math.max(r,e.frame)})),{min:t,max:r}},e}(),x=d.Matrix.Compose(new d.Vector3(-1,1,1),d.Quaternion.Identity(),d.Vector3.Zero()),y=new d.Quaternion(0,1,0,0);function T(e,t){if(!(e instanceof d.TransformNode))return!1;if(t){if(!e.getWorldMatrix().isIdentity())return!1}else if(!e.getWorldMatrix().multiplyToRef(x,d.TmpVectors.Matrix[0]).isIdentity())return!1;return!(e instanceof d.Mesh&&e.geometry||e instanceof d.InstancedMesh&&e.sourceMesh.geometry)}var v=function(){function e(e,t){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=this._options.animationSampleRate||1/60,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){switch(t){case d.Material.TriangleFillMode:this._reorderTriangleFillMode(e,r,n,a,i);break;case d.Material.TriangleStripDrawMode:this._reorderTriangleStripDrawMode(e,r,n,a,i);break;case d.Material.TriangleFanDrawMode:this._reorderTriangleFanMode(e,r,n,a,i)}},e.prototype._reorderTriangleFillMode=function(e,t,r,n,a){var i=this._getVertexBufferFromMesh(t,e.getMesh());if(i){var o=i.byteStride/d.VertexBuffer.GetTypeByteLength(i.type);if(e.verticesCount%3!=0)d.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var s=[],u=0;switch(t){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:for(var l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=3)u=l*o,s.push(d.Vector3.FromArray(r,u)),s.push(d.Vector3.FromArray(r,u+2*o)),s.push(d.Vector3.FromArray(r,u+o));break;case d.VertexBuffer.TangentKind:for(l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=3)u=l*o,s.push(d.Vector4.FromArray(r,u)),s.push(d.Vector4.FromArray(r,u+2*o)),s.push(d.Vector4.FromArray(r,u+o));break;case d.VertexBuffer.ColorKind:var c=i.getSize();for(l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=c)u=l*o,4===c?(s.push(d.Vector4.FromArray(r,u)),s.push(d.Vector4.FromArray(r,u+2*o)),s.push(d.Vector4.FromArray(r,u+o))):(s.push(d.Vector3.FromArray(r,u)),s.push(d.Vector3.FromArray(r,u+2*o)),s.push(d.Vector3.FromArray(r,u+o)));break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:for(l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=3)u=l*o,s.push(d.Vector2.FromArray(r,u)),s.push(d.Vector2.FromArray(r,u+2*o)),s.push(d.Vector2.FromArray(r,u+o));break;default:d.Tools.Error("Unsupported Vertex Buffer type: ".concat(t))}this._writeVertexAttributeData(s,n,t,a)}}else d.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind ".concat(t," not present!"))},e.prototype._reorderTriangleStripDrawMode=function(e,t,r,n,a){var i=this._getVertexBufferFromMesh(t,e.getMesh());if(i){var o=i.byteStride/d.VertexBuffer.GetTypeByteLength(i.type),s=[],u=0;switch(t){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:u=e.verticesStart,s.push(d.Vector3.FromArray(r,u+2*o)),s.push(d.Vector3.FromArray(r,u+o));break;case d.VertexBuffer.TangentKind:for(var l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,s.push(d.Vector4.FromArray(r,u));break;case d.VertexBuffer.ColorKind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,4===i.getSize()?s.push(d.Vector4.FromArray(r,u)):s.push(d.Vector3.FromArray(r,u));break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,s.push(d.Vector2.FromArray(r,u));break;default:d.Tools.Error("Unsupported Vertex Buffer type: ".concat(t))}this._writeVertexAttributeData(s,n+12,t,a)}else d.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind ".concat(t," not present!"))},e.prototype._reorderTriangleFanMode=function(e,t,r,n,a){var i=this._getVertexBufferFromMesh(t,e.getMesh());if(i){var o=i.byteStride/d.VertexBuffer.GetTypeByteLength(i.type),s=[],u=0;switch(t){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:for(var l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,s.push(d.Vector3.FromArray(r,u));break;case d.VertexBuffer.TangentKind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,s.push(d.Vector4.FromArray(r,u));break;case d.VertexBuffer.ColorKind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,s.push(d.Vector4.FromArray(r,u)),4===i.getSize()?s.push(d.Vector4.FromArray(r,u)):s.push(d.Vector3.FromArray(r,u));break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,s.push(d.Vector2.FromArray(r,u));break;default:d.Tools.Error("Unsupported Vertex Buffer type: ".concat(t))}this._writeVertexAttributeData(s,n,t,a)}else d.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind ".concat(t," not present!"))},e.prototype._writeVertexAttributeData=function(e,t,r,n){for(var a=0,i=e;a<i.length;a++){var o=i[a];r===d.VertexBuffer.NormalKind?o.normalize():r===d.VertexBuffer.TangentKind&&o instanceof d.Vector4&&g._NormalizeTangentFromRef(o);for(var s=0,u=o.asArray();s<u.length;s++){var l=u[s];n.setFloat32(l,t),t+=4}}},e.prototype._writeAttributeData=function(e,t,r,n,a,i){var o,s,u=[];switch(e){case d.VertexBuffer.PositionKind:for(var l=0,c=r.length/n;l<c;++l){o=l*n;var f=d.Vector3.FromArray(r,o);u.push(f.asArray())}break;case d.VertexBuffer.NormalKind:l=0;for(var h=r.length/n;l<h;++l)o=l*n,f=d.Vector3.FromArray(r,o),u.push(f.normalize().asArray());break;case d.VertexBuffer.TangentKind:l=0;for(var p=r.length/n;l<p;++l)o=l*n,f=d.Vector4.FromArray(r,o),g._NormalizeTangentFromRef(f),u.push(f.asArray());break;case d.VertexBuffer.ColorKind:for(var _=i.material,m=!_||"StandardMaterial"===_.getClassName(),x=(f=3===n?new d.Color3:new d.Color4,this._babylonScene.getEngine().useExactSrgbConversions),y=(l=0,r.length/n);l<y;++l)o=l*n,3===n?(d.Color3.FromArrayToRef(r,o,f),m&&f.toLinearSpaceToRef(f,x)):(d.Color4.FromArrayToRef(r,o,f),m&&f.toLinearSpaceToRef(f,x)),u.push(f.asArray());break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:l=0;for(var T=r.length/n;l<T;++l)o=l*n,f=d.Vector2.FromArray(r,o),u.push(f.asArray());break;case d.VertexBuffer.MatricesIndicesKind:case d.VertexBuffer.MatricesIndicesExtraKind:l=0;for(var v=r.length/n;l<v;++l)o=l*n,f=d.Vector4.FromArray(r,o),u.push(f.asArray());break;case d.VertexBuffer.MatricesWeightsKind:case d.VertexBuffer.MatricesWeightsExtraKind:l=0;for(var b=r.length/n;l<b;++l)o=l*n,f=d.Vector4.FromArray(r,o),u.push(f.asArray());break;default:d.Tools.Warn("Unsupported Vertex Buffer Type: "+e),u=[]}switch(t){case 5121:s=a.setUInt8.bind(a);break;case 5123:s=a.setUInt16.bind(a);break;case 5125:s=a.setUInt32.bind(a);break;case 5126:s=a.setFloat32.bind(a);break;default:return void d.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var A=0,E=u;A<E.length;A++)for(var M=0,F=E[A];M<F.length;M++)s(F[M])},e.prototype.writeMorphTargetAttributeData=function(e,t,r,n,a,i,o,s){var u,l,c=[],f=new d.Vector3,h=new d.Vector4(0,0,0,0);switch(e){case d.VertexBuffer.PositionKind:for(var p=r.verticesStart;p<r.verticesCount;++p){u=r.indexStart+p*i;var _=d.Vector3.FromArray(n,u);f=(m=d.Vector3.FromArray(a,u)).subtractToRef(_,f),s&&(s.min.copyFromFloats(Math.min(f.x,s.min.x),Math.min(f.y,s.min.y),Math.min(f.z,s.min.z)),s.max.copyFromFloats(Math.max(f.x,s.max.x),Math.max(f.y,s.max.y),Math.max(f.z,s.max.z))),c.push(f.asArray())}break;case d.VertexBuffer.NormalKind:for(p=r.verticesStart;p<r.verticesCount;++p)u=r.indexStart+p*i,_=d.Vector3.FromArray(n,u).normalize(),f=(m=d.Vector3.FromArray(a,u).normalize()).subtractToRef(_,f),c.push(f.asArray());break;case d.VertexBuffer.TangentKind:for(p=r.verticesStart;p<r.verticesCount;++p){u=r.indexStart+p*(i+1),_=d.Vector4.FromArray(n,u),g._NormalizeTangentFromRef(_);var m=d.Vector4.FromArray(a,u);g._NormalizeTangentFromRef(m),h=m.subtractToRef(_,h),c.push([h.x,h.y,h.z])}break;default:d.Tools.Warn("Unsupported Vertex Buffer Type: "+e),c=[]}switch(t){case 5121:l=o.setUInt8.bind(o);break;case 5123:l=o.setUInt16.bind(o);break;case 5125:l=o.setUInt32.bind(o);break;case 5126:l=o.setFloat32.bind(o);break;default:return void d.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var x=0,y=c;x<y.length;x++)for(var T=0,v=y[x];T<v.length;T++)l(v[T])},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=g._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 b(4);return this._createSceneAsync(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),g=new DataView(_);g.setUint32(0,1179937895,!0),g.setUint32(4,2,!0),g.setUint32(8,d,!0);var m=new ArrayBuffer(8+s+f),x=new DataView(m);x.setUint32(0,s+f,!0),x.setUint32(4,1313821514,!0);var y=new Uint8Array(m,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(m,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 M=new ArrayBuffer(h),F=new Uint8Array(M);for(c=0;c<h;++c)F[c]=0;var w=new ArrayBuffer(p),C=new Uint8Array(w);for(c=0;c<p;++c)C[c]=0;var V=[_,m,A,n];for(c=0;c<r._orderedImageData.length;++c)V.push(r._orderedImageData[c].data);V.push(M),V.push(w);var R=new Blob(V,{type:"application/octet-stream"}),S=new l;return S.glTFFiles[o]=R,null!=r._localEngine&&r._localEngine.dispose(),t&&r.dispose(),S}))},e.prototype._setNodeTransformation=function(e,t){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=t.position.asArray()),t.scaling.equalsToFloats(1,1,1)||(e.scale=t.scaling.asArray());var r=d.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);t.rotationQuaternion&&r.multiplyInPlace(t.rotationQuaternion),d.Quaternion.IsIdentity(r)||(e.rotation=r.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t){var r=d.TmpVectors.Vector3[0],n=d.TmpVectors.Quaternion[0];t.getWorldMatrix().decompose(void 0,n,r),r.equalsToFloats(0,0,0)||(e.translation=r.asArray()),n.multiplyInPlace(y),d.Quaternion.IsIdentity(n)||(e.rotation=n.asArray())},e.prototype._getVertexBufferFromMesh=function(e,t){if(t.isVerticesDataPresent(e,!0)){var r=t.getVertexBuffer(e,!0);if(r)return r}return null},e.prototype._createBufferViewKind=function(e,t,r,n,a){var i=r instanceof d.Mesh?r:r instanceof d.InstancedMesh?r.sourceMesh:null;if(i){var o=i.getVertexBuffer(e,!0),s=i.getVerticesData(e,void 0,void 0,!0);if(o&&s){var u=d.VertexBuffer.GetTypeByteLength(t),l=s.length*u,c=g._CreateBufferView(0,n.getByteOffset(),l,a,e+" - "+i.name);this._bufferViews.push(c),this._writeAttributeData(e,t,s,a/u,n,r)}}},e.prototype._setMorphTargetAttributes=function(e,t,r,n){if(r){t.targets||(t.targets=[]);var a={},i=e.getMesh();if(r.hasNormals){var o=i.getVerticesData(d.VertexBuffer.NormalKind,void 0,void 0,!0),s=r.getNormals(),u=(m=e.verticesCount)*(x=12),l=g._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_NORMAL");this._bufferViews.push(l);var c=this._bufferViews.length-1,f=g._CreateAccessor(c,r.name+" - NORMAL","VEC3",5126,m,0,null,null);this._accessors.push(f),a.NORMAL=this._accessors.length-1,this.writeMorphTargetAttributeData(d.VertexBuffer.NormalKind,5126,e,o,s,x/4,n)}if(r.hasPositions){var h=i.getVerticesData(d.VertexBuffer.PositionKind,void 0,void 0,!0),p=r.getPositions();u=(m=e.verticesCount)*(x=12),l=g._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=g._CreateAccessor(c,r.name+" - POSITION","VEC3",5126,m,0,null,null),this._accessors.push(f),a.POSITION=this._accessors.length-1,this.writeMorphTargetAttributeData(d.VertexBuffer.PositionKind,5126,e,h,p,x/4,n,_),f.min=_.min.asArray(),f.max=_.max.asArray()}if(r.hasTangents){var m,x,y=i.getVerticesData(d.VertexBuffer.TangentKind,void 0,void 0,!0),T=r.getTangents();u=(m=e.verticesCount)*(x=12),l=g._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_NORMAL"),this._bufferViews.push(l),c=this._bufferViews.length-1,f=g._CreateAccessor(c,r.name+" - TANGENT","VEC3",5126,m,0,null,null),this._accessors.push(f),a.TANGENT=this._accessors.length-1,this.writeMorphTargetAttributeData(d.VertexBuffer.TangentKind,5126,e,y,T,x/4,n)}t.targets.push(a)}},e.prototype._getMeshPrimitiveMode=function(e){if(e instanceof d.LinesMesh)return d.Material.LineListDrawMode;if(e instanceof d.InstancedMesh||e instanceof d.Mesh){var t=e instanceof d.Mesh?e:e.sourceMesh;if("number"==typeof t.overrideRenderingFillMode)return t.overrideRenderingFillMode}return 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){var n,a,i=[],o=null;t instanceof d.Mesh?o=t:t instanceof d.InstancedMesh&&(o=t.sourceMesh);var s=[{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(o){for(var u=null,l=this._getMeshPrimitiveMode(o),c={},f=o.morphTargetManager,h=0,p=s;h<p.length;h++){var _=(G=p[h]).kind,m=G.accessorComponentType;if(o.isVerticesDataPresent(_,!0)){var x=this._getVertexBufferFromMesh(_,o);G.byteStride=x?x.getSize()*d.VertexBuffer.GetTypeByteLength(G.accessorComponentType):4*d.VertexBuffer.DeduceStride(_),12===G.byteStride&&(G.accessorType="VEC3"),this._createBufferViewKind(_,m,t,r,G.byteStride),G.bufferViewIndex=this._bufferViews.length-1,c[_]=G.bufferViewIndex}}if(o.getTotalIndices()){var y=o.getIndices();if(y){var T=4*y.length;n=g._CreateBufferView(0,r.getByteOffset(),T,void 0,"Indices - "+o.name),this._bufferViews.push(n),u=this._bufferViews.length-1;for(var v=0,b=y.length;v<b;++v)r.setUInt32(y[v])}}if(o.subMeshes)for(var A=0,E=o.subMeshes;A<E.length;A++){var M=E[A],F=M.getMaterial()||o.getScene().defaultMaterial,w=null;if(F)if(o instanceof d.LinesMesh){var C={name:o.name+" material"};(!o.color.equals(d.Color3.White())||o.alpha<1)&&(C.pbrMetallicRoughness={baseColorFactor:o.color.asArray().concat([o.alpha])}),this._materials.push(C),w=this._materials.length-1}else if(F instanceof d.MultiMaterial){var V=F.subMaterials[M.materialIndex];V&&(F=V,w=this._materialMap[F.uniqueId])}else w=this._materialMap[F.uniqueId];var R=null!=w?this._materials[w]:null,S={attributes:{}};this._setPrimitiveMode(S,l);for(var I=0,B=s;I<B.length;I++)if(((_=(G=B[I]).kind)!==d.VertexBuffer.UVKind&&_!==d.VertexBuffer.UV2Kind||this._options.exportUnusedUVs||R&&this._glTFMaterialExporter._hasTexturesPresent(R))&&(D=o.getVerticesData(_,void 0,void 0,!0))&&(x=this._getVertexBufferFromMesh(_,o))){var P=x.getSize(),N=G.bufferViewIndex;if(null!=N){a={min:null,max:null},_==d.VertexBuffer.PositionKind&&(a=g._CalculateMinMaxPositions(D,0,D.length/P));var O=g._CreateAccessor(N,_+" - "+t.name,G.accessorType,G.accessorComponentType,D.length/P,0,a.min,a.max);this._accessors.push(O),this._setAttributeKind(S,_)}}if(u&&(O=g._CreateAccessor(u,"indices - "+t.name,"SCALAR",5125,M.indexCount,4*M.indexStart,null,null),this._accessors.push(O),S.indices=this._accessors.length-1),Object.keys(S.attributes).length>0){if((null!==o.overrideMaterialSideOrientation?o.overrideMaterialSideOrientation:F.sideOrientation)===(this._babylonScene.useRightHandedSystem?d.Material.ClockWiseSideOrientation:d.Material.CounterClockWiseSideOrientation)){var L=null!=u?this._bufferViews[u].byteOffset:null;null==L&&(L=0);var U=null;if(null!=u&&(U=o.getIndices()),U)this._reorderIndicesBasedOnPrimitiveMode(M,l,U,L,r);else for(var k=0,K=s;k<K.length;k++){var D,G=K[k];if(D=o.getVerticesData(G.kind,void 0,void 0,!0)){var W=this._bufferViews[c[G.kind]].byteOffset||0;this._reorderVertexAttributeDataBasedOnPrimitiveMode(M,l,G.kind,D,W,r)}}}null!=w&&(S.material=w)}if(f){e.extras||(e.extras={}),e.extras.targetNames=[];for(var z=0;z<f.numTargets;++z){var q=f.getTarget(z);this._setMorphTargetAttributes(M,S,q,r),e.extras.targetNames.push(q.name)}}e.primitives.push(S),this._extensionsPostExportMeshPrimitiveAsync("postExport",S,M,r),i.push()}}return Promise.all(i).then((function(){}))},e.prototype._createSceneAsync=function(e){var t,r,n,a,i,o=this,s={nodes:[]},u=h(h(h(h([],this._babylonScene.transformNodes,!0),this._babylonScene.meshes,!0),this._babylonScene.lights,!0),this._babylonScene.cameras,!0),l=new Set;if(this._babylonScene.metadata&&(this._options.metadataSelector?s.extras=this._options.metadataSelector(this._babylonScene.metadata):this._babylonScene.metadata.gltf&&(s.extras=this._babylonScene.metadata.gltf.extras)),(null===(r=this._options.removeNoopRootNodes)||void 0===r||r)&&!this._options.includeCoordinateSystemConversionNodes)for(var c=0,f=this._babylonScene.rootNodes;c<f.length;c++){var p=f[c];T(p,this._babylonScene.useRightHandedSystem)&&(l.add(p),u.splice(u.indexOf(p),1))}var _=new Map;this._babylonScene.cameras.forEach((function(e){if(!o._options.shouldExportNode||o._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}}_.set(e,o._cameras.length),o._cameras.push(t)}}));var g=(t=this._getExportNodes(u))[0],m=t[1];return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(m,"image/png",!0).then((function(){return o._createNodeMapAndAnimationsAsync(g,e).then((function(t){return o._createSkinsAsync(t,e).then((function(r){if(o._nodeMap=t,o._totalByteLength=e.getByteOffset(),null==o._totalByteLength)throw new Error("undefined byte length!");for(var c=0,f=u;c<f.length;c++){var h=f[c];if(void 0!==(n=o._nodeMap[h.uniqueId])&&(a=o._nodes[n],h.metadata&&(o._options.metadataSelector?a.extras=o._options.metadataSelector(h.metadata):h.metadata.gltf&&(a.extras=h.metadata.gltf.extras)),h instanceof d.Camera&&(a.camera=_.get(h)),o._options.shouldExportNode&&!o._options.shouldExportNode(h)?d.Tools.Log("Omitting "+h.name+" from scene."):(h.parent||o._babylonScene.useRightHandedSystem||(T=a,v=void 0,b=void 0,A=void 0,v=d.Vector3.FromArrayToRef(T.translation||[0,0,0],0,d.TmpVectors.Vector3[0]),b=d.Quaternion.FromArrayToRef(T.rotation||[0,0,0,1],0,d.TmpVectors.Quaternion[0]),A=d.Vector3.FromArrayToRef(T.scale||[1,1,1],0,d.TmpVectors.Vector3[1]),d.Matrix.ComposeToRef(A,b,v,d.TmpVectors.Matrix[0]).multiplyToRef(x,d.TmpVectors.Matrix[0]).decompose(A,b,v),v.equalsToFloats(0,0,0)?delete T.translation:T.translation=v.asArray(),d.Quaternion.IsIdentity(b)?delete T.rotation:T.rotation=b.asArray(),A.equalsToFloats(1,1,1)?delete T.scale:T.scale=A.asArray()),h.parent&&!l.has(h.parent)||s.nodes.push(n)),h instanceof d.Mesh&&h.skeleton&&(a.skin=r[h.skeleton.uniqueId]),i=h.getDescendants(!0),!a.children&&i&&i.length)){for(var p=[],g=0,m=i;g<m.length;g++){var y=m[g];null!=o._nodeMap[y.uniqueId]&&p.push(o._nodeMap[y.uniqueId])}p.length&&(a.children=p)}}var T,v,b,A;s.nodes.length&&o._scenes.push(s)}))}))}))},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){for(var r,n=this,a=Promise.resolve(),i={},o={name:"runtime animations",channels:[],samplers:[]},s=[],u=function(e){a=a.then((function(){return n._createNodeAsync(e,t).then((function(a){var u=n._extensionsPostExportNodeAsync("createNodeAsync",a,e,i,t);return null==u?(d.Tools.Warn("Not exporting node ".concat(e.name)),Promise.resolve()):u.then((function(a){a&&(n._nodes.push(a),r=n._nodes.length-1,i[e.uniqueId]=r,n._babylonScene.animationGroups.length||(m._CreateMorphTargetAnimationFromMorphTargetAnimations(e,o,s,i,n._nodes,t,n._bufferViews,n._accessors,n._animationSampleRate,n._options.shouldExportAnimation),e.animations.length&&m._CreateNodeAnimationFromNodeAnimations(e,o,s,i,n._nodes,t,n._bufferViews,n._accessors,n._animationSampleRate,n._options.shouldExportAnimation)))}))}))}))},l=0,c=e;l<c.length;l++)u(c[l]);return a.then((function(){return o.channels.length&&o.samplers.length&&n._animations.push(o),s.forEach((function(e){e.channels.length&&e.samplers.length&&n._animations.push(e)})),n._babylonScene.animationGroups.length&&m._CreateNodeAndMorphAnimationFromAnimationGroups(n._babylonScene,n._animations,i,t,n._bufferViews,n._accessors,n._animationSampleRate,n._options.shouldExportAnimation),i}))},e.prototype._createNodeAsync=function(e,t){var r=this;return Promise.resolve().then((function(){var n={},a={primitives:[]};if(e.name&&(n.name=e.name),e instanceof d.TransformNode){if(r._setNodeTransformation(n,e),e instanceof d.Mesh){var i=e.morphTargetManager;if(i&&i.numTargets>0){a.weights=[];for(var o=0;o<i.numTargets;++o)a.weights.push(i.getTarget(o).influence)}}return r._setPrimitiveAttributesAsync(a,e,t).then((function(){return a.primitives.length&&(r._meshes.push(a),n.mesh=r._meshes.length-1),n}))}return e instanceof d.Camera?(r._setCameraTransformation(n,e),n):n}))},e.prototype._createSkinsAsync=function(e,t){for(var r,n=Promise.resolve(),a={},i=0,o=this._babylonScene.skeletons;i<o.length;i++){var s=o[i];if(!(s.bones.length<=0)){for(var u={joints:[]},l=[],c={},f=-1,h=0;h<s.bones.length;++h)-1!==(p=null!==(r=(_=s.bones[h]).getIndex())&&void 0!==r?r:h)&&(c[p]=_,p>f&&(f=p));for(var p=0;p<=f;++p){var _=c[p];l.push(_.getInvertedAbsoluteTransform());var m=_.getTransformNode();m&&null!==e[m.uniqueId]&&void 0!==e[m.uniqueId]?u.joints.push(e[m.uniqueId]):d.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}if(u.joints.length>0){var x=64*l.length,y=t.getByteOffset(),T=g._CreateBufferView(0,y,x,void 0,"InverseBindMatrices - "+s.name);this._bufferViews.push(T);var v=this._bufferViews.length-1,b=g._CreateAccessor(v,"InverseBindMatrices - "+s.name,"MAT4",5126,l.length,null,null,null),A=this._accessors.push(b)-1;u.inverseBindMatrices=A,this._skins.push(u),a[s.uniqueId]=this._skins.length-1,l.forEach((function(e){e.m.forEach((function(e){t.setFloat32(e)}))}))}}}return n.then((function(){return a}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),b=function(){function e(e){this._arrayBuffer=new ArrayBuffer(e),this._dataView=new DataView(this._arrayBuffer),this._byteOffset=0}return e.prototype._resizeBuffer=function(e){var t=new ArrayBuffer(e),r=Math.min(this._arrayBuffer.byteLength,e),n=new Uint8Array(this._arrayBuffer,0,r);return new Uint8Array(t).set(n,0),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}(),A=function(){function e(){}return e.GLTFAsync=function(e,t,r){return e.whenReadyAsync().then((function(){var n=t.replace(/\.[^/.]+$/,"");return new v(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 v(e,r)._generateGLBAsync(a).then((function(t){return n._PostExportAsync(e,t,r)}))}))},e}(),E="KHR_texture_transform",M=function(){function e(){this.name=E,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[E]=n}},e.prototype.preExportTextureAsync=function(e,t){return new Promise((function(r,n){t.getScene()?0!==t.uAng||0!==t.vAng?(d.Tools.Warn("".concat(e,": Texture ").concat(t.name," with rotation in the u or v axis is not supported in glTF.")),r(null)):0===t.wAng||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(E)),r(null)):n("".concat(e,': "scene" is not defined for Babylon texture ').concat(t.name,"!"))}))},e}();v.RegisterExtension(E,(function(){return new M}));var F="KHR_lights_punctual",w=function(){function e(e){this.name=F,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[F]=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=void 0,s=r.getTypeID()==d.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==d.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==d.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(null==s)d.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(F));else{if(r.position.equalsToFloats(0,0,0)||(t.translation=r.position.asArray()),"point"!==s){var u=r.direction,l=-Math.atan2(u.z,u.x)+Math.PI/2,c=Math.sqrt(u.x*u.x+u.z*u.z),f=-Math.atan2(u.y,c),h=d.Quaternion.RotationYawPitchRoll(l+Math.PI,f,0);d.Quaternion.IsIdentity(h)||(t.rotation=h.asArray())}if(r.falloffType!==d.Light.FALLOFF_GLTF&&d.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(F," specification!")),o={type:s},r.diffuse.equals(d.Color3.White())||(o.color=r.diffuse.asArray()),1!==r.intensity&&(o.intensity=r.intensity),r.range!==Number.MAX_VALUE&&(o.range=r.range),"spot"===s){var p=r;p.angle!==Math.PI/2&&(null==o.spot&&(o.spot={}),o.spot.outerConeAngle=p.angle/2),0!==p.innerAngle&&(null==o.spot&&(o.spot={}),o.spot.innerConeAngle=p.innerAngle/2)}a._lights||(a._lights={lights:[]}),a._lights.lights.push(o);var _={light:a._lights.lights.length-1},g=r.parent;if(g&&1==g.getChildren().length){var m=a._exporter._nodes[n[g.uniqueId]];if(m){var x=d.Vector3.FromArrayToRef(m.translation||[0,0,0],0,d.TmpVectors.Vector3[0]),y=d.Quaternion.FromArrayToRef(m.rotation||[0,0,0,1],0,d.TmpVectors.Quaternion[0]),T=d.Vector3.FromArrayToRef(m.scale||[1,1,1],0,d.TmpVectors.Vector3[1]),v=d.Matrix.ComposeToRef(T,y,x,d.TmpVectors.Matrix[0]),b=d.Vector3.FromArrayToRef(t.translation||[0,0,0],0,d.TmpVectors.Vector3[2]),A=d.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,d.TmpVectors.Quaternion[1]),E=d.Matrix.ComposeToRef(d.Vector3.OneReadOnly,A,b,d.TmpVectors.Matrix[1]);return v.multiplyToRef(E,E),E.decompose(T,y,x),x.equalsToFloats(0,0,0)?delete m.translation:m.translation=x.asArray(),d.Quaternion.IsIdentity(y)?delete m.rotation:m.rotation=y.asArray(),T.equalsToFloats(1,1,1)?delete m.scale:m.scale=T.asArray(),m.extensions||(m.extensions={}),m.extensions[F]=_,void i(null)}}t.extensions||(t.extensions={}),t.extensions[F]=_}}i(t)}))},e}();v.RegisterExtension(F,(function(e){return new w(e)}));var C="KHR_materials_clearcoat",V=function(){function e(e){this.name=C,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[C]=s}e(t)}))},e}();v.RegisterExtension(C,(function(e){return new V(e)}));var R="KHR_materials_iridescence",S=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[R]=o}e(t)}))},e}();v.RegisterExtension(R,(function(e){return new S(e)}));var I="KHR_materials_anisotropy",B=function(){function e(e){this.name=I,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof d.PBRBaseMaterial&&r.anisotropy.isEnabled&&!r.anisotropy.legacy?(r.anisotropy.texture&&n.push(r.anisotropy.texture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof d.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var a=n._exporter._glTFMaterialExporter._getTextureInfo(r.anisotropy.texture),i={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=a?a:void 0,hasTextures:function(){return null!==i.anisotropyTexture}};t.extensions[I]=i}e(t)}))},e}();v.RegisterExtension(I,(function(e){return new B(e)}));var P="KHR_materials_sheen",N=function(){function e(e){this.name=P,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[P]=u}e(t)}))},e}();v.RegisterExtension(P,(function(e){return new N(e)}));var O="KHR_materials_unlit",L=function(){function e(){this.name=O,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[O]={}),e(t)}))},e}();v.RegisterExtension(O,(function(){return new L}));var U="KHR_materials_ior",k=function(){function e(){this.name=U,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[U]=a}e(t)}))},e}();v.RegisterExtension(U,(function(e){return new k}));var K="KHR_materials_specular",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.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[K]=u}e(t)}))},e}();v.RegisterExtension(K,(function(e){return new D(e)}));var G="KHR_materials_volume",W=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.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[G]=o}e(t)}))},e}();v.RegisterExtension(G,(function(e){return new W(e)}));var z="KHR_materials_dispersion",q=function(){function e(){this.name=z,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isDispersionEnabled)},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var a={dispersion:r.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[z]=a}e(t)}))},e}();v.RegisterExtension(z,(function(){return new q}));var H="KHR_materials_transmission",j=function(){function e(e){this.name=H,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[H]=o}e(t)}))},e}();v.RegisterExtension(H,(function(e){return new j(e)}));var Q="EXT_mesh_gpu_instancing",Y=function(){function e(e){this.name=Q,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,g=new Float32Array(3*r.thinInstanceCount),m=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),g.set(l.asArray(),3*y),m.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(g,"VEC3",r.thinInstanceCount,a,5126)),p&&(b.attributes.ROTATION=i._buildAccessor(m,"VEC4",r.thinInstanceCount,a,5126)),_&&(b.attributes.SCALE=i._buildAccessor(x,"VEC3",r.thinInstanceCount,a,5126)),t.extensions=t.extensions||{},t.extensions[Q]=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}();v.RegisterExtension(Q,(function(e){return new Y(e)}));var X="KHR_materials_emissive_strength",Z=function(){function e(){this.name=X,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(!(r instanceof d.PBRMaterial))return e(t);var a=r.emissiveColor.asArray(),i=Math.max.apply(Math,a);if(i>1){n._wasUsed=!0,t.extensions||(t.extensions={});var o={emissiveStrength:i},s=r.emissiveColor.scale(1/o.emissiveStrength);t.emissiveFactor=s.asArray(),t.extensions[X]=o}return e(t)}))},e}();v.RegisterExtension(X,(function(e){return new Z}));var J=0,$=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==$){$.BABYLON=$.BABYLON||{};var ee=$.BABYLON;ee.GLTF2=ee.GLTF2||{},ee.GLTF2.Exporter=ee.GLTF2.Exporter||{},ee.GLTF2.Exporter.Extensions=ee.GLTF2.Exporter.Extensions||{};var te=[];for(var re in e)ee[re]=e[re],te.push(re);for(var re in t)ee[re]=t[re],te.push(re);for(var re in r)ee[re]=r[re],te.push(re);for(var re in i)ee.GLTF2.Exporter.Extensions[re]=i[re],te.push(re);for(var re in o)te.indexOf(re)>-1||(ee.GLTF2.Exporter[re]=o[re])}const ne=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={597: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:()=>ne});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:()=>A});var i={};n.r(i),n.d(i,{EXT_mesh_gpu_instancing:()=>Y,KHR_lights_punctual:()=>w,KHR_materials_anisotropy:()=>B,KHR_materials_clearcoat:()=>V,KHR_materials_dispersion:()=>q,KHR_materials_emissive_strength:()=>Z,KHR_materials_ior:()=>k,KHR_materials_iridescence:()=>S,KHR_materials_sheen:()=>N,KHR_materials_specular:()=>D,KHR_materials_transmission:()=>j,KHR_materials_unlit:()=>L,KHR_materials_volume:()=>W,KHR_texture_transform:()=>M});var o={};n.r(o),n.d(o,{EXT_mesh_gpu_instancing:()=>Y,GLTF2Export:()=>A,GLTFData:()=>l,KHR_lights_punctual:()=>w,KHR_materials_anisotropy:()=>B,KHR_materials_clearcoat:()=>V,KHR_materials_dispersion:()=>q,KHR_materials_emissive_strength:()=>Z,KHR_materials_ior:()=>k,KHR_materials_iridescence:()=>S,KHR_materials_sheen:()=>N,KHR_materials_specular:()=>D,KHR_materials_transmission:()=>j,KHR_materials_unlit:()=>L,KHR_materials_volume:()=>W,KHR_texture_transform:()=>M,_BinaryWriter:()=>b,_Exporter:()=>v,_GLTFAnimation:()=>m,_GLTFMaterialExporter:()=>_,_GLTFUtilities:()=>g,__IGLTFExporterExtensionV2:()=>J});var s={};n.r(s),n.d(s,{EXT_mesh_gpu_instancing:()=>Y,GLTF2Export:()=>A,GLTFData:()=>l,KHR_lights_punctual:()=>w,KHR_materials_anisotropy:()=>B,KHR_materials_clearcoat:()=>V,KHR_materials_dispersion:()=>q,KHR_materials_emissive_strength:()=>Z,KHR_materials_ior:()=>k,KHR_materials_iridescence:()=>S,KHR_materials_sheen:()=>N,KHR_materials_specular:()=>D,KHR_materials_transmission:()=>j,KHR_materials_unlit:()=>L,KHR_materials_volume:()=>W,KHR_texture_transform:()=>M,_BinaryWriter:()=>b,_Exporter:()=>v,_GLTFAnimation:()=>m,_GLTFMaterialExporter:()=>_,_GLTFUtilities:()=>g,__IGLTFExporterExtension:()=>u,__IGLTFExporterExtensionV2:()=>J});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(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(o=0)),o;)try{if(r=1,n&&(a=2&s[0]?n.return:s[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,s[1])).done)return a;switch(n=0,a&&(s=[2&s[0],a.value]),s[0]){case 0:case 1:a=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,n=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!((a=(a=o.trys).length>0&&a[a.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!a||s[1]>a[0]&&s[1]<a[3])){o.label=s[1];break}if(6===s[0]&&o.label<a[1]){o.label=a[1],a=s;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(s);break}a[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],n=0}finally{r=a=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}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,"function"==typeof SuppressedError&&SuppressedError;var p,d=n(597),_=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(t.getScene().getEngine().useExactSrgbConversions).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.DumpTools.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,_,g,m,x,y,T,v,b,A,E,M,F,w,C,V,R,S,I,B,P,N,O,L,U;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 g=f.sent(),[4,u.texture2.readPixels()];case 2:if(m=f.sent(),!g)return[2,Promise.reject("Failed to retrieve pixels from diffuse texture!")];if(c=this._convertPixelArrayToFloat32(g),!m)return[2,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];for(h=this._convertPixelArrayToFloat32(m),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),M=new d.Color3(c[E],c[E+1],c[E+2]).toLinearSpace(s.getEngine().useExactSrgbConversions).multiply(n.diffuseColor),F=new d.Color3(h[E],h[E+1],h[E+2]).toLinearSpace(s.getEngine().useExactSrgbConversions).multiply(n.specularColor),w=h[E+3]*n.glossiness,C={diffuseColor:M,specularColor:F,glossiness:w},V=this._convertSpecularGlossinessToMetallicRoughness(C),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(R={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)]/=R.baseColor.r>e._Epsilon?R.baseColor.r:1,T[N+1]/=R.baseColor.g>e._Epsilon?R.baseColor.g:1,T[N+2]/=R.baseColor.b>e._Epsilon?R.baseColor.b:1,O=d.Color3.FromInts(T[N],T[N+1],T[N+2]),L=O.toGammaSpace(s.getEngine().useExactSrgbConversions),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]/=R.roughness>e._Epsilon?R.roughness:1,y[N+2]/=R.metallic>e._Epsilon?R.metallic:1,U=d.Color3.FromInts(255,y[N+1],y[N+2]),e._FuzzyEquals(U,d.Color3.White(),e._Epsilon)||(S=!0);return S&&o.push(this._getImageDataAsync(y,p,_,a).then((function(e){R.metallicRoughnessTextureData=e}))),I&&o.push(this._getImageDataAsync(T,p,_,a).then((function(e){R.baseColorTextureData=e}))),[2,Promise.all(o).then((function(){return R}))];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,extensions:e.extensions};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,h,p,_=this;return f(this,(function(g){switch(g.label){case 0:return(r=e.uid)in this._textureMap?[3,3]:[4,this._getPixelsFromTexture(e)];case 1:if(!(n=g.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: ".concat(i))}return o=this._internalTextureToImage,s=e.getInternalTexture().uniqueId,o[s]||(o[s]={}),void 0===(u=o[s][t])&&(l=e.getSize(),u=c(_,void 0,void 0,(function(){var r;return f(this,(function(a){switch(a.label){case 0:return[4,this._getImageDataAsync(n,l.width,l.height,t)];case 1:return r=a.sent(),[2,this._exportImage(e.name,t,r)]}}))})),o[s][t]=u),p=this._exportTextureInfo,[4,u];case 2:h=p.apply(this,[g.sent(),a,e.coordinatesIndex]),this._textureMap[r]=h,this._exporter._extensionsPostExportTextures("exporter",this._textureMap[r],e),g.label=3;case 3:return[2,this._textureMap[r]]}}))}))},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}(),g=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(e,t,r){var n,a,i=[1/0,1/0,1/0],o=[-1/0,-1/0,-1/0];if(r)for(var s=t,u=t+r;s<u;++s){n=3*s,a=d.Vector3.FromArray(e,n).asArray();for(var l=0;l<3;++l){var c=a[l];c<i[l]&&(i[l]=c),c>o[l]&&(o[l]=c),++n}}return{min:i,max:o}},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 m=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){if(this._IsTransformable(t)){var o=[],s=[],u=r.getKeys(),l=e._CalculateMinMaxKeyFrames(u),c=e._DeduceInterpolation(u,n,a),f=c.interpolationType,h=c.shouldBakeAnimation;if(h?e._CreateBakedAnimation(t,r,n,l.min,l.max,r.framePerSecond,i,o,s,l,a):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(t,r,n,o,s,a):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(t,r,n,o,s,a):e._CreateBakedAnimation(t,r,n,l.min,l.max,r.framePerSecond,i,o,s,l,a),o.length&&s.length)return{inputs:o,outputs:s,samplerInterpolation:f,inputsMin:h?l.min:d.Tools.FloatRound(l.min/r.framePerSecond),inputsMax:h?l.max:d.Tools.FloatRound(l.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];if(!c||c(d)){var _=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,_.useQuaternion,l),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,g=h.getTarget(p).animations;_<g.length;_++){var m=g[_];if(!c||c(m)){for(var x=new d.Animation("".concat(m.name),"influence",m.framePerSecond,m.dataType,m.loopMode,m.enableBlending),y=[],T=m.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(m.name,m.hasRunningRuntimeAnimations?r:f,t,x,E.dataAccessorType,E.animationChannelTargetPath,a,o,s,u,E.useQuaternion,l,h.numTargets),f.samplers.length&&f.channels.length&&n.push(f))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,a,i,o,s,u){var l,c;if(t.animationGroups)for(var f=t.animationGroups,h=function(f){var h=new Map,_=new Map,g=new Set,m=f.to-f.from;c={name:f.name,channels:[],samplers:[]};for(var x=function(r){var m=f.targetedAnimations[r],x=m.target,y=m.animation;if(u&&!u(y))return"continue";if(p._IsTransformable(x)||1===x.length&&p._IsTransformable(x[0])){if(v=e._DeduceAnimationInfo(m.animation)){var T=p._IsTransformable(x)?x:p._IsTransformable(x[0])?x[0]:null;T&&e._AddAnimation("".concat(y.name),c,T,y,v.dataAccessorType,v.animationChannelTargetPath,n,a,i,o,v.useQuaternion,s)}}else if(x instanceof d.MorphTarget||1===x.length&&x[0]instanceof d.MorphTarget){var v;if(v=e._DeduceAnimationInfo(m.animation)){var b=x instanceof d.MorphTarget?x:x[0];if(b){var A=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===b)return!0;return!1}));if(A){var E=t.meshes.find((function(e){return e.morphTargetManager===A}));E&&(h.has(E)||h.set(E,new Map),null===(l=h.get(E))||void 0===l||l.set(b,y),g.add(E),_.set(E,y))}}}}},y=0;y<f.targetedAnimations.length;++y)x(y);g.forEach((function(t){for(var r=t.morphTargetManager,u=null,l=[],p=_.get(t).getKeys(),g=p.length,x=0;x<g;++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(f.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,d.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),l.push(b.getKeys()[x])):l.push({frame:f.from+m/g*x,value:T.influence,inTangent:p[0].inTangent?0:void 0,outTangent:p[0].outTangent?0:void 0})}}u.setKeys(l);var A=e._DeduceAnimationInfo(u);A&&e._AddAnimation("".concat(f.name,"_").concat(t.name,"_MorphWeightAnimation"),c,t,u,A.dataAccessorType,A.animationChannelTargetPath,n,a,i,o,A.useQuaternion,s,null==r?void 0:r.numTargets)})),c.channels.length&&c.samplers.length&&r.push(c)},p=this,_=0,g=f;_<g.length;_++)h(g[_])},e._AddAnimation=function(t,r,n,a,i,o,s,u,l,c,f,h,p){var d,_,m,x,y,T,v,b=e._CreateNodeAnimation(n,a,o,f,h);if(b){if(p){for(var A=0,E=0,M=[];b.inputs.length>0;)E=b.inputs.shift(),A%p==0&&M.push(E),A++;b.inputs=M}var F=s[n.uniqueId],w=4*b.inputs.length;d=g._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," keyframe data view")),l.push(d),b.inputs.forEach((function(e){u.setFloat32(e)})),_=g._CreateAccessor(l.length-1,"".concat(t," keyframes"),"SCALAR",5126,b.inputs.length,null,[b.inputsMin],[b.inputsMax]),c.push(_),m=c.length-1,y=b.outputs.length,w=4*g._GetDataAccessorElementCount(i)*b.outputs.length,d=g._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," data view")),l.push(d),b.outputs.forEach((function(e){e.forEach((function(e){u.setFloat32(e)}))})),_=g._CreateAccessor(l.length-1,"".concat(t," data"),i,5126,y,null,null,null),c.push(_),x=c.length-1,T={interpolation:b.samplerInterpolation,input:m,output:x},r.samplers.push(T),v={sampler:r.samplers.length-1,target:{node:F,path:o}},r.channels.push(v)}},e._CreateBakedAnimation=function(t,r,n,a,i,o,s,u,l,c,f){var h,p,_=d.Quaternion.Identity(),g=null,m=null,x=null,y=null,T=null,v=null;c.min=d.Tools.FloatRound(a/o);for(var b=r.getKeys(),A=0,E=b.length;A<E;++A){if(v=null,x=b[A],A+1<E)if(y=b[A+1],x.value.equals&&x.value.equals(y.value)||x.value===y.value){if(0!==A)continue;v=x.frame}else v=y.frame;else{if(T=b[A-1],x.value.equals&&x.value.equals(T.value)||x.value===T.value)continue;v=i}if(v)for(var M=x.frame;M<=v;M+=s)if((p=d.Tools.FloatRound(M/o))!==g){g=p,m=p;var F={key:0,repeatCount:0,loopMode:r.loopMode};h=r._interpolate(M,F),e._SetInterpolatedValue(t,h,p,r,n,_,u,l,f)}}m&&(c.max=m)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,a,i){var o=e._GetBasePositionRotationOrScale(r,a,i),s=n.targetProperty.split("."),u=s?s[1]:"",l=i?d.Quaternion.FromArray(o).normalize():d.Vector3.FromArray(o);switch(u){case"x":case"y":case"z":l[u]=t;break;case"w":l.w=t;break;default:d.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return l},e._SetInterpolatedValue=function(e,t,r,n,a,i,o,s,u){var l;o.push(r),"weights"!==a?(n.dataType===d.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,a,u)),"rotation"===a?(u?i=t:(l=t,d.Quaternion.RotationYawPitchRollToRef(l.y,l.x,l.z,i)),s.push(i.asArray())):(l=t,s.push(l.asArray()))):s.push([t])},e._CreateLinearOrStepAnimation=function(t,r,n,a,i,o){for(var s=0,u=r.getKeys();s<u.length;s++){var l=u[s];a.push(l.frame/r.framePerSecond),e._AddKeyframeValue(l,r,i,n,t,o)}},e._CreateCubicSplineAnimation=function(t,r,n,a,i,o){r.getKeys().forEach((function(s){a.push(s.frame/r.framePerSecond),e._AddSplineTangent(p.INTANGENT,i,n,"CUBICSPLINE",s,o),e._AddKeyframeValue(s,r,i,n,t,o),e._AddSplineTangent(p.OUTTANGENT,i,n,"CUBICSPLINE",s,o)}))},e._GetBasePositionRotationOrScale=function(e,t,r){var n;if("rotation"===t)if(r){var a=e.rotationQuaternion;n=(null!=a?a:d.Quaternion.Identity()).asArray()}else{var i=e.rotation;n=(null!=i?i:d.Vector3.Zero()).asArray()}else if("translation"===t){var o=e.position;n=(null!=o?o:d.Vector3.Zero()).asArray()}else{var s=e.scaling;n=(null!=s?s:d.Vector3.One()).asArray()}return n},e._AddKeyframeValue=function(e,t,r,n,a,i){var o,s=t.dataType;if(s===d.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===n){var l=d.Vector3.FromArray(u);u=d.Quaternion.RotationYawPitchRoll(l.y,l.x,l.z).asArray()}r.push(u)}else if(s===d.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(o=this._ConvertFactorToVector3OrQuaternion(e.value,a,t,n,i)){if("rotation"===n){var c=i?o:d.Quaternion.RotationYawPitchRoll(o.y,o.x,o.z).normalize();r.push(c.asArray())}r.push(o.asArray())}}else s===d.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):d.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,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){var o,s=e===p.INTANGENT?a.inTangent:a.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(s)if(i)o=s.asArray();else{var u=s;o=d.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else o=[0,0,0,0];else o="weights"===r?s?[s]:[0]:s?s.asArray():[0,0,0];t.push(o)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,r=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),r=Math.max(r,e.frame)})),{min:t,max:r}},e}(),x=d.Matrix.Compose(new d.Vector3(-1,1,1),d.Quaternion.Identity(),d.Vector3.Zero()),y=new d.Quaternion(0,1,0,0);function T(e,t){if(!(e instanceof d.TransformNode))return!1;if(t){if(!e.getWorldMatrix().isIdentity())return!1}else if(!e.getWorldMatrix().multiplyToRef(x,d.TmpVectors.Matrix[0]).isIdentity())return!1;return!(e instanceof d.Mesh&&e.geometry||e instanceof d.InstancedMesh&&e.sourceMesh.geometry)}var v=function(){function e(e,t){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=this._options.animationSampleRate||1/60,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){switch(t){case d.Material.TriangleFillMode:this._reorderTriangleFillMode(e,r,n,a,i);break;case d.Material.TriangleStripDrawMode:this._reorderTriangleStripDrawMode(e,r,n,a,i);break;case d.Material.TriangleFanDrawMode:this._reorderTriangleFanMode(e,r,n,a,i)}},e.prototype._reorderTriangleFillMode=function(e,t,r,n,a){var i=this._getVertexBufferFromMesh(t,e.getMesh());if(i){var o=i.byteStride/d.VertexBuffer.GetTypeByteLength(i.type);if(e.verticesCount%3!=0)d.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var s=[],u=0;switch(t){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:for(var l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=3)u=l*o,s.push(d.Vector3.FromArray(r,u)),s.push(d.Vector3.FromArray(r,u+2*o)),s.push(d.Vector3.FromArray(r,u+o));break;case d.VertexBuffer.TangentKind:for(l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=3)u=l*o,s.push(d.Vector4.FromArray(r,u)),s.push(d.Vector4.FromArray(r,u+2*o)),s.push(d.Vector4.FromArray(r,u+o));break;case d.VertexBuffer.ColorKind:var c=i.getSize();for(l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=c)u=l*o,4===c?(s.push(d.Vector4.FromArray(r,u)),s.push(d.Vector4.FromArray(r,u+2*o)),s.push(d.Vector4.FromArray(r,u+o))):(s.push(d.Vector3.FromArray(r,u)),s.push(d.Vector3.FromArray(r,u+2*o)),s.push(d.Vector3.FromArray(r,u+o)));break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:for(l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=3)u=l*o,s.push(d.Vector2.FromArray(r,u)),s.push(d.Vector2.FromArray(r,u+2*o)),s.push(d.Vector2.FromArray(r,u+o));break;default:d.Tools.Error("Unsupported Vertex Buffer type: ".concat(t))}this._writeVertexAttributeData(s,n,t,a)}}else d.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind ".concat(t," not present!"))},e.prototype._reorderTriangleStripDrawMode=function(e,t,r,n,a){var i=this._getVertexBufferFromMesh(t,e.getMesh());if(i){var o=i.byteStride/d.VertexBuffer.GetTypeByteLength(i.type),s=[],u=0;switch(t){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:u=e.verticesStart,s.push(d.Vector3.FromArray(r,u+2*o)),s.push(d.Vector3.FromArray(r,u+o));break;case d.VertexBuffer.TangentKind:for(var l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,s.push(d.Vector4.FromArray(r,u));break;case d.VertexBuffer.ColorKind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,4===i.getSize()?s.push(d.Vector4.FromArray(r,u)):s.push(d.Vector3.FromArray(r,u));break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,s.push(d.Vector2.FromArray(r,u));break;default:d.Tools.Error("Unsupported Vertex Buffer type: ".concat(t))}this._writeVertexAttributeData(s,n+12,t,a)}else d.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind ".concat(t," not present!"))},e.prototype._reorderTriangleFanMode=function(e,t,r,n,a){var i=this._getVertexBufferFromMesh(t,e.getMesh());if(i){var o=i.byteStride/d.VertexBuffer.GetTypeByteLength(i.type),s=[],u=0;switch(t){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:for(var l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,s.push(d.Vector3.FromArray(r,u));break;case d.VertexBuffer.TangentKind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,s.push(d.Vector4.FromArray(r,u));break;case d.VertexBuffer.ColorKind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,s.push(d.Vector4.FromArray(r,u)),4===i.getSize()?s.push(d.Vector4.FromArray(r,u)):s.push(d.Vector3.FromArray(r,u));break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,s.push(d.Vector2.FromArray(r,u));break;default:d.Tools.Error("Unsupported Vertex Buffer type: ".concat(t))}this._writeVertexAttributeData(s,n,t,a)}else d.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind ".concat(t," not present!"))},e.prototype._writeVertexAttributeData=function(e,t,r,n){for(var a=0,i=e;a<i.length;a++){var o=i[a];r===d.VertexBuffer.NormalKind?o.normalize():r===d.VertexBuffer.TangentKind&&o instanceof d.Vector4&&g._NormalizeTangentFromRef(o);for(var s=0,u=o.asArray();s<u.length;s++){var l=u[s];n.setFloat32(l,t),t+=4}}},e.prototype._writeAttributeData=function(e,t,r,n,a,i){var o,s,u=[];switch(e){case d.VertexBuffer.PositionKind:for(var l=0,c=r.length/n;l<c;++l){o=l*n;var f=d.Vector3.FromArray(r,o);u.push(f.asArray())}break;case d.VertexBuffer.NormalKind:l=0;for(var h=r.length/n;l<h;++l)o=l*n,f=d.Vector3.FromArray(r,o),u.push(f.normalize().asArray());break;case d.VertexBuffer.TangentKind:l=0;for(var p=r.length/n;l<p;++l)o=l*n,f=d.Vector4.FromArray(r,o),g._NormalizeTangentFromRef(f),u.push(f.asArray());break;case d.VertexBuffer.ColorKind:for(var _=i.material,m=!_||"StandardMaterial"===_.getClassName(),x=(f=3===n?new d.Color3:new d.Color4,this._babylonScene.getEngine().useExactSrgbConversions),y=(l=0,r.length/n);l<y;++l)o=l*n,3===n?(d.Color3.FromArrayToRef(r,o,f),m&&f.toLinearSpaceToRef(f,x)):(d.Color4.FromArrayToRef(r,o,f),m&&f.toLinearSpaceToRef(f,x)),u.push(f.asArray());break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:l=0;for(var T=r.length/n;l<T;++l)o=l*n,f=d.Vector2.FromArray(r,o),u.push(f.asArray());break;case d.VertexBuffer.MatricesIndicesKind:case d.VertexBuffer.MatricesIndicesExtraKind:l=0;for(var v=r.length/n;l<v;++l)o=l*n,f=d.Vector4.FromArray(r,o),u.push(f.asArray());break;case d.VertexBuffer.MatricesWeightsKind:case d.VertexBuffer.MatricesWeightsExtraKind:l=0;for(var b=r.length/n;l<b;++l)o=l*n,f=d.Vector4.FromArray(r,o),u.push(f.asArray());break;default:d.Tools.Warn("Unsupported Vertex Buffer Type: "+e),u=[]}switch(t){case 5121:s=a.setUInt8.bind(a);break;case 5123:s=a.setUInt16.bind(a);break;case 5125:s=a.setUInt32.bind(a);break;case 5126:s=a.setFloat32.bind(a);break;default:return void d.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var A=0,E=u;A<E.length;A++)for(var M=0,F=E[A];M<F.length;M++)s(F[M])},e.prototype.writeMorphTargetAttributeData=function(e,t,r,n,a,i,o,s){var u,l,c=[],f=new d.Vector3,h=new d.Vector4(0,0,0,0);switch(e){case d.VertexBuffer.PositionKind:for(var p=r.verticesStart;p<r.verticesCount;++p){u=r.indexStart+p*i;var _=d.Vector3.FromArray(n,u);f=(m=d.Vector3.FromArray(a,u)).subtractToRef(_,f),s&&(s.min.copyFromFloats(Math.min(f.x,s.min.x),Math.min(f.y,s.min.y),Math.min(f.z,s.min.z)),s.max.copyFromFloats(Math.max(f.x,s.max.x),Math.max(f.y,s.max.y),Math.max(f.z,s.max.z))),c.push(f.asArray())}break;case d.VertexBuffer.NormalKind:for(p=r.verticesStart;p<r.verticesCount;++p)u=r.indexStart+p*i,_=d.Vector3.FromArray(n,u).normalize(),f=(m=d.Vector3.FromArray(a,u).normalize()).subtractToRef(_,f),c.push(f.asArray());break;case d.VertexBuffer.TangentKind:for(p=r.verticesStart;p<r.verticesCount;++p){u=r.indexStart+p*(i+1),_=d.Vector4.FromArray(n,u),g._NormalizeTangentFromRef(_);var m=d.Vector4.FromArray(a,u);g._NormalizeTangentFromRef(m),h=m.subtractToRef(_,h),c.push([h.x,h.y,h.z])}break;default:d.Tools.Warn("Unsupported Vertex Buffer Type: "+e),c=[]}switch(t){case 5121:l=o.setUInt8.bind(o);break;case 5123:l=o.setUInt16.bind(o);break;case 5125:l=o.setUInt32.bind(o);break;case 5126:l=o.setFloat32.bind(o);break;default:return void d.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var x=0,y=c;x<y.length;x++)for(var T=0,v=y[x];T<v.length;T++)l(v[T])},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=g._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 b(4);return this._createSceneAsync(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),g=new DataView(_);g.setUint32(0,1179937895,!0),g.setUint32(4,2,!0),g.setUint32(8,d,!0);var m=new ArrayBuffer(8+s+f),x=new DataView(m);x.setUint32(0,s+f,!0),x.setUint32(4,1313821514,!0);var y=new Uint8Array(m,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(m,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 M=new ArrayBuffer(h),F=new Uint8Array(M);for(c=0;c<h;++c)F[c]=0;var w=new ArrayBuffer(p),C=new Uint8Array(w);for(c=0;c<p;++c)C[c]=0;var V=[_,m,A,n];for(c=0;c<r._orderedImageData.length;++c)V.push(r._orderedImageData[c].data);V.push(M),V.push(w);var R=new Blob(V,{type:"application/octet-stream"}),S=new l;return S.glTFFiles[o]=R,null!=r._localEngine&&r._localEngine.dispose(),t&&r.dispose(),S}))},e.prototype._setNodeTransformation=function(e,t){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=t.position.asArray()),t.scaling.equalsToFloats(1,1,1)||(e.scale=t.scaling.asArray());var r=d.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);t.rotationQuaternion&&r.multiplyInPlace(t.rotationQuaternion),d.Quaternion.IsIdentity(r)||(e.rotation=r.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t){var r=d.TmpVectors.Vector3[0],n=d.TmpVectors.Quaternion[0];t.getWorldMatrix().decompose(void 0,n,r),r.equalsToFloats(0,0,0)||(e.translation=r.asArray()),n.multiplyInPlace(y),d.Quaternion.IsIdentity(n)||(e.rotation=n.asArray())},e.prototype._getVertexBufferFromMesh=function(e,t){if(t.isVerticesDataPresent(e,!0)){var r=t.getVertexBuffer(e,!0);if(r)return r}return null},e.prototype._createBufferViewKind=function(e,t,r,n,a){var i=r instanceof d.Mesh?r:r instanceof d.InstancedMesh?r.sourceMesh:null;if(i){var o=i.getVertexBuffer(e,!0),s=i.getVerticesData(e,void 0,void 0,!0);if(o&&s){var u=d.VertexBuffer.GetTypeByteLength(t),l=s.length*u,c=g._CreateBufferView(0,n.getByteOffset(),l,a,e+" - "+i.name);this._bufferViews.push(c),this._writeAttributeData(e,t,s,a/u,n,r)}}},e.prototype._setMorphTargetAttributes=function(e,t,r,n){if(r){t.targets||(t.targets=[]);var a={},i=e.getMesh();if(r.hasNormals){var o=i.getVerticesData(d.VertexBuffer.NormalKind,void 0,void 0,!0),s=r.getNormals(),u=(m=e.verticesCount)*(x=12),l=g._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_NORMAL");this._bufferViews.push(l);var c=this._bufferViews.length-1,f=g._CreateAccessor(c,r.name+" - NORMAL","VEC3",5126,m,0,null,null);this._accessors.push(f),a.NORMAL=this._accessors.length-1,this.writeMorphTargetAttributeData(d.VertexBuffer.NormalKind,5126,e,o,s,x/4,n)}if(r.hasPositions){var h=i.getVerticesData(d.VertexBuffer.PositionKind,void 0,void 0,!0),p=r.getPositions();u=(m=e.verticesCount)*(x=12),l=g._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=g._CreateAccessor(c,r.name+" - POSITION","VEC3",5126,m,0,null,null),this._accessors.push(f),a.POSITION=this._accessors.length-1,this.writeMorphTargetAttributeData(d.VertexBuffer.PositionKind,5126,e,h,p,x/4,n,_),f.min=_.min.asArray(),f.max=_.max.asArray()}if(r.hasTangents){var m,x,y=i.getVerticesData(d.VertexBuffer.TangentKind,void 0,void 0,!0),T=r.getTangents();u=(m=e.verticesCount)*(x=12),l=g._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_NORMAL"),this._bufferViews.push(l),c=this._bufferViews.length-1,f=g._CreateAccessor(c,r.name+" - TANGENT","VEC3",5126,m,0,null,null),this._accessors.push(f),a.TANGENT=this._accessors.length-1,this.writeMorphTargetAttributeData(d.VertexBuffer.TangentKind,5126,e,y,T,x/4,n)}t.targets.push(a)}},e.prototype._getMeshPrimitiveMode=function(e){if(e instanceof d.LinesMesh)return d.Material.LineListDrawMode;if(e instanceof d.InstancedMesh||e instanceof d.Mesh){var t=e instanceof d.Mesh?e:e.sourceMesh;if("number"==typeof t.overrideRenderingFillMode)return t.overrideRenderingFillMode}return 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){var n,a,i=[],o=null;t instanceof d.Mesh?o=t:t instanceof d.InstancedMesh&&(o=t.sourceMesh);var s=[{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(o){for(var u=null,l=this._getMeshPrimitiveMode(o),c={},f=o.morphTargetManager,h=0,p=s;h<p.length;h++){var _=(G=p[h]).kind,m=G.accessorComponentType;if(o.isVerticesDataPresent(_,!0)){var x=this._getVertexBufferFromMesh(_,o);G.byteStride=x?x.getSize()*d.VertexBuffer.GetTypeByteLength(G.accessorComponentType):4*d.VertexBuffer.DeduceStride(_),12===G.byteStride&&(G.accessorType="VEC3"),this._createBufferViewKind(_,m,t,r,G.byteStride),G.bufferViewIndex=this._bufferViews.length-1,c[_]=G.bufferViewIndex}}if(o.getTotalIndices()){var y=o.getIndices();if(y){var T=4*y.length;n=g._CreateBufferView(0,r.getByteOffset(),T,void 0,"Indices - "+o.name),this._bufferViews.push(n),u=this._bufferViews.length-1;for(var v=0,b=y.length;v<b;++v)r.setUInt32(y[v])}}if(o.subMeshes)for(var A=0,E=o.subMeshes;A<E.length;A++){var M=E[A],F=M.getMaterial()||o.getScene().defaultMaterial,w=null;if(F)if(o instanceof d.LinesMesh){var C={name:o.name+" material"};(!o.color.equals(d.Color3.White())||o.alpha<1)&&(C.pbrMetallicRoughness={baseColorFactor:o.color.asArray().concat([o.alpha])}),this._materials.push(C),w=this._materials.length-1}else if(F instanceof d.MultiMaterial){var V=F.subMaterials[M.materialIndex];V&&(F=V,w=this._materialMap[F.uniqueId])}else w=this._materialMap[F.uniqueId];var R=null!=w?this._materials[w]:null,S={attributes:{}};this._setPrimitiveMode(S,l);for(var I=0,B=s;I<B.length;I++)if(((_=(G=B[I]).kind)!==d.VertexBuffer.UVKind&&_!==d.VertexBuffer.UV2Kind||this._options.exportUnusedUVs||R&&this._glTFMaterialExporter._hasTexturesPresent(R))&&(D=o.getVerticesData(_,void 0,void 0,!0))&&(x=this._getVertexBufferFromMesh(_,o))){var P=x.getSize(),N=G.bufferViewIndex;if(null!=N){a={min:null,max:null},_==d.VertexBuffer.PositionKind&&(a=g._CalculateMinMaxPositions(D,0,D.length/P));var O=g._CreateAccessor(N,_+" - "+t.name,G.accessorType,G.accessorComponentType,D.length/P,0,a.min,a.max);this._accessors.push(O),this._setAttributeKind(S,_)}}if(u&&(O=g._CreateAccessor(u,"indices - "+t.name,"SCALAR",5125,M.indexCount,4*M.indexStart,null,null),this._accessors.push(O),S.indices=this._accessors.length-1),Object.keys(S.attributes).length>0){if((null!==o.overrideMaterialSideOrientation?o.overrideMaterialSideOrientation:F.sideOrientation)===(this._babylonScene.useRightHandedSystem?d.Material.ClockWiseSideOrientation:d.Material.CounterClockWiseSideOrientation)){var L=null!=u?this._bufferViews[u].byteOffset:null;null==L&&(L=0);var U=null;if(null!=u&&(U=o.getIndices()),U)this._reorderIndicesBasedOnPrimitiveMode(M,l,U,L,r);else for(var k=0,K=s;k<K.length;k++){var D,G=K[k];if(D=o.getVerticesData(G.kind,void 0,void 0,!0)){var W=this._bufferViews[c[G.kind]].byteOffset||0;this._reorderVertexAttributeDataBasedOnPrimitiveMode(M,l,G.kind,D,W,r)}}}null!=w&&(S.material=w)}if(f){e.extras||(e.extras={}),e.extras.targetNames=[];for(var z=0;z<f.numTargets;++z){var q=f.getTarget(z);this._setMorphTargetAttributes(M,S,q,r),e.extras.targetNames.push(q.name)}}e.primitives.push(S),this._extensionsPostExportMeshPrimitiveAsync("postExport",S,M,r),i.push()}}return Promise.all(i).then((function(){}))},e.prototype._createSceneAsync=function(e){var t,r,n,a,i,o=this,s={nodes:[]},u=h(h(h(h([],this._babylonScene.transformNodes,!0),this._babylonScene.meshes,!0),this._babylonScene.lights,!0),this._babylonScene.cameras,!0),l=new Set;if(this._babylonScene.metadata&&(this._options.metadataSelector?s.extras=this._options.metadataSelector(this._babylonScene.metadata):this._babylonScene.metadata.gltf&&(s.extras=this._babylonScene.metadata.gltf.extras)),(null===(r=this._options.removeNoopRootNodes)||void 0===r||r)&&!this._options.includeCoordinateSystemConversionNodes)for(var c=0,f=this._babylonScene.rootNodes;c<f.length;c++){var p=f[c];T(p,this._babylonScene.useRightHandedSystem)&&(l.add(p),u.splice(u.indexOf(p),1))}var _=new Map;this._babylonScene.cameras.forEach((function(e){if(!o._options.shouldExportNode||o._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}}_.set(e,o._cameras.length),o._cameras.push(t)}}));var g=(t=this._getExportNodes(u))[0],m=t[1];return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(m,"image/png",!0).then((function(){return o._createNodeMapAndAnimationsAsync(g,e).then((function(t){return o._createSkinsAsync(t,e).then((function(r){if(o._nodeMap=t,o._totalByteLength=e.getByteOffset(),null==o._totalByteLength)throw new Error("undefined byte length!");for(var c=0,f=u;c<f.length;c++){var h=f[c];if(void 0!==(n=o._nodeMap[h.uniqueId])&&(a=o._nodes[n],h.metadata&&(o._options.metadataSelector?a.extras=o._options.metadataSelector(h.metadata):h.metadata.gltf&&(a.extras=h.metadata.gltf.extras)),h instanceof d.Camera&&(a.camera=_.get(h)),o._options.shouldExportNode&&!o._options.shouldExportNode(h)?d.Tools.Log("Omitting "+h.name+" from scene."):(h.parent||o._babylonScene.useRightHandedSystem||(T=a,v=void 0,b=void 0,A=void 0,v=d.Vector3.FromArrayToRef(T.translation||[0,0,0],0,d.TmpVectors.Vector3[0]),b=d.Quaternion.FromArrayToRef(T.rotation||[0,0,0,1],0,d.TmpVectors.Quaternion[0]),A=d.Vector3.FromArrayToRef(T.scale||[1,1,1],0,d.TmpVectors.Vector3[1]),d.Matrix.ComposeToRef(A,b,v,d.TmpVectors.Matrix[0]).multiplyToRef(x,d.TmpVectors.Matrix[0]).decompose(A,b,v),v.equalsToFloats(0,0,0)?delete T.translation:T.translation=v.asArray(),d.Quaternion.IsIdentity(b)?delete T.rotation:T.rotation=b.asArray(),A.equalsToFloats(1,1,1)?delete T.scale:T.scale=A.asArray()),h.parent&&!l.has(h.parent)||s.nodes.push(n)),h instanceof d.Mesh&&h.skeleton&&(a.skin=r[h.skeleton.uniqueId]),i=h.getDescendants(!0),!a.children&&i&&i.length)){for(var p=[],g=0,m=i;g<m.length;g++){var y=m[g];null!=o._nodeMap[y.uniqueId]&&p.push(o._nodeMap[y.uniqueId])}p.length&&(a.children=p)}}var T,v,b,A;s.nodes.length&&o._scenes.push(s)}))}))}))},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){for(var r,n=this,a=Promise.resolve(),i={},o={name:"runtime animations",channels:[],samplers:[]},s=[],u=function(e){a=a.then((function(){return n._createNodeAsync(e,t).then((function(a){var u=n._extensionsPostExportNodeAsync("createNodeAsync",a,e,i,t);return null==u?(d.Tools.Warn("Not exporting node ".concat(e.name)),Promise.resolve()):u.then((function(a){a&&(n._nodes.push(a),r=n._nodes.length-1,i[e.uniqueId]=r,n._babylonScene.animationGroups.length||(m._CreateMorphTargetAnimationFromMorphTargetAnimations(e,o,s,i,n._nodes,t,n._bufferViews,n._accessors,n._animationSampleRate,n._options.shouldExportAnimation),e.animations.length&&m._CreateNodeAnimationFromNodeAnimations(e,o,s,i,n._nodes,t,n._bufferViews,n._accessors,n._animationSampleRate,n._options.shouldExportAnimation)))}))}))}))},l=0,c=e;l<c.length;l++)u(c[l]);return a.then((function(){return o.channels.length&&o.samplers.length&&n._animations.push(o),s.forEach((function(e){e.channels.length&&e.samplers.length&&n._animations.push(e)})),n._babylonScene.animationGroups.length&&m._CreateNodeAndMorphAnimationFromAnimationGroups(n._babylonScene,n._animations,i,t,n._bufferViews,n._accessors,n._animationSampleRate,n._options.shouldExportAnimation),i}))},e.prototype._createNodeAsync=function(e,t){var r=this;return Promise.resolve().then((function(){var n={},a={primitives:[]};if(e.name&&(n.name=e.name),e instanceof d.TransformNode){if(r._setNodeTransformation(n,e),e instanceof d.Mesh){var i=e.morphTargetManager;if(i&&i.numTargets>0){a.weights=[];for(var o=0;o<i.numTargets;++o)a.weights.push(i.getTarget(o).influence)}}return r._setPrimitiveAttributesAsync(a,e,t).then((function(){return a.primitives.length&&(r._meshes.push(a),n.mesh=r._meshes.length-1),n}))}return e instanceof d.Camera?(r._setCameraTransformation(n,e),n):n}))},e.prototype._createSkinsAsync=function(e,t){for(var r,n=Promise.resolve(),a={},i=0,o=this._babylonScene.skeletons;i<o.length;i++){var s=o[i];if(!(s.bones.length<=0)){for(var u={joints:[]},l=[],c={},f=-1,h=0;h<s.bones.length;++h)-1!==(p=null!==(r=(_=s.bones[h]).getIndex())&&void 0!==r?r:h)&&(c[p]=_,p>f&&(f=p));for(var p=0;p<=f;++p){var _=c[p];l.push(_.getInvertedAbsoluteTransform());var m=_.getTransformNode();m&&null!==e[m.uniqueId]&&void 0!==e[m.uniqueId]?u.joints.push(e[m.uniqueId]):d.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}if(u.joints.length>0){var x=64*l.length,y=t.getByteOffset(),T=g._CreateBufferView(0,y,x,void 0,"InverseBindMatrices - "+s.name);this._bufferViews.push(T);var v=this._bufferViews.length-1,b=g._CreateAccessor(v,"InverseBindMatrices - "+s.name,"MAT4",5126,l.length,null,null,null),A=this._accessors.push(b)-1;u.inverseBindMatrices=A,this._skins.push(u),a[s.uniqueId]=this._skins.length-1,l.forEach((function(e){e.m.forEach((function(e){t.setFloat32(e)}))}))}}}return n.then((function(){return a}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),b=function(){function e(e){this._arrayBuffer=new ArrayBuffer(e),this._dataView=new DataView(this._arrayBuffer),this._byteOffset=0}return e.prototype._resizeBuffer=function(e){var t=new ArrayBuffer(e),r=Math.min(this._arrayBuffer.byteLength,e),n=new Uint8Array(this._arrayBuffer,0,r);return new Uint8Array(t).set(n,0),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}(),A=function(){function e(){}return e.GLTFAsync=function(e,t,r){return e.whenReadyAsync().then((function(){var n=t.replace(/\.[^/.]+$/,"");return new v(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 v(e,r)._generateGLBAsync(a).then((function(t){return n._PostExportAsync(e,t,r)}))}))},e}(),E="KHR_texture_transform",M=function(){function e(){this.name=E,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[E]=n}},e.prototype.preExportTextureAsync=function(e,t){return new Promise((function(r,n){t.getScene()?0!==t.uAng||0!==t.vAng?(d.Tools.Warn("".concat(e,": Texture ").concat(t.name," with rotation in the u or v axis is not supported in glTF.")),r(null)):0===t.wAng||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(E)),r(null)):n("".concat(e,': "scene" is not defined for Babylon texture ').concat(t.name,"!"))}))},e}();v.RegisterExtension(E,(function(){return new M}));var F="KHR_lights_punctual",w=function(){function e(e){this.name=F,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[F]=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=void 0,s=r.getTypeID()==d.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==d.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==d.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(null==s)d.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(F));else{if(r.position.equalsToFloats(0,0,0)||(t.translation=r.position.asArray()),"point"!==s){var u=r.direction,l=-Math.atan2(u.z,u.x)+Math.PI/2,c=Math.sqrt(u.x*u.x+u.z*u.z),f=-Math.atan2(u.y,c),h=d.Quaternion.RotationYawPitchRoll(l+Math.PI,f,0);d.Quaternion.IsIdentity(h)||(t.rotation=h.asArray())}if(r.falloffType!==d.Light.FALLOFF_GLTF&&d.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(F," specification!")),o={type:s},r.diffuse.equals(d.Color3.White())||(o.color=r.diffuse.asArray()),1!==r.intensity&&(o.intensity=r.intensity),r.range!==Number.MAX_VALUE&&(o.range=r.range),"spot"===s){var p=r;p.angle!==Math.PI/2&&(null==o.spot&&(o.spot={}),o.spot.outerConeAngle=p.angle/2),0!==p.innerAngle&&(null==o.spot&&(o.spot={}),o.spot.innerConeAngle=p.innerAngle/2)}a._lights||(a._lights={lights:[]}),a._lights.lights.push(o);var _={light:a._lights.lights.length-1},g=r.parent;if(g&&1==g.getChildren().length){var m=a._exporter._nodes[n[g.uniqueId]];if(m){var x=d.Vector3.FromArrayToRef(m.translation||[0,0,0],0,d.TmpVectors.Vector3[0]),y=d.Quaternion.FromArrayToRef(m.rotation||[0,0,0,1],0,d.TmpVectors.Quaternion[0]),T=d.Vector3.FromArrayToRef(m.scale||[1,1,1],0,d.TmpVectors.Vector3[1]),v=d.Matrix.ComposeToRef(T,y,x,d.TmpVectors.Matrix[0]),b=d.Vector3.FromArrayToRef(t.translation||[0,0,0],0,d.TmpVectors.Vector3[2]),A=d.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,d.TmpVectors.Quaternion[1]),E=d.Matrix.ComposeToRef(d.Vector3.OneReadOnly,A,b,d.TmpVectors.Matrix[1]);return v.multiplyToRef(E,E),E.decompose(T,y,x),x.equalsToFloats(0,0,0)?delete m.translation:m.translation=x.asArray(),d.Quaternion.IsIdentity(y)?delete m.rotation:m.rotation=y.asArray(),T.equalsToFloats(1,1,1)?delete m.scale:m.scale=T.asArray(),m.extensions||(m.extensions={}),m.extensions[F]=_,void i(null)}}t.extensions||(t.extensions={}),t.extensions[F]=_}}i(t)}))},e}();v.RegisterExtension(F,(function(e){return new w(e)}));var C="KHR_materials_clearcoat",V=function(){function e(e){this.name=C,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[C]=s}e(t)}))},e}();v.RegisterExtension(C,(function(e){return new V(e)}));var R="KHR_materials_iridescence",S=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[R]=o}e(t)}))},e}();v.RegisterExtension(R,(function(e){return new S(e)}));var I="KHR_materials_anisotropy",B=function(){function e(e){this.name=I,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof d.PBRBaseMaterial&&r.anisotropy.isEnabled&&!r.anisotropy.legacy?(r.anisotropy.texture&&n.push(r.anisotropy.texture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof d.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var a=n._exporter._glTFMaterialExporter._getTextureInfo(r.anisotropy.texture),i={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=a?a:void 0,hasTextures:function(){return null!==i.anisotropyTexture}};t.extensions[I]=i}e(t)}))},e}();v.RegisterExtension(I,(function(e){return new B(e)}));var P="KHR_materials_sheen",N=function(){function e(e){this.name=P,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[P]=u}e(t)}))},e}();v.RegisterExtension(P,(function(e){return new N(e)}));var O="KHR_materials_unlit",L=function(){function e(){this.name=O,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[O]={}),e(t)}))},e}();v.RegisterExtension(O,(function(){return new L}));var U="KHR_materials_ior",k=function(){function e(){this.name=U,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[U]=a}e(t)}))},e}();v.RegisterExtension(U,(function(e){return new k}));var K="KHR_materials_specular",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.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[K]=u}e(t)}))},e}();v.RegisterExtension(K,(function(e){return new D(e)}));var G="KHR_materials_volume",W=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.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[G]=o}e(t)}))},e}();v.RegisterExtension(G,(function(e){return new W(e)}));var z="KHR_materials_dispersion",q=function(){function e(){this.name=z,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isDispersionEnabled)},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof d.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var a={dispersion:r.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[z]=a}e(t)}))},e}();v.RegisterExtension(z,(function(){return new q}));var H="KHR_materials_transmission",j=function(){function e(e){this.name=H,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[H]=o}e(t)}))},e}();v.RegisterExtension(H,(function(e){return new j(e)}));var Q="EXT_mesh_gpu_instancing",Y=function(){function e(e){this.name=Q,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,g=new Float32Array(3*r.thinInstanceCount),m=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),g.set(l.asArray(),3*y),m.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(g,"VEC3",r.thinInstanceCount,a,5126)),p&&(b.attributes.ROTATION=i._buildAccessor(m,"VEC4",r.thinInstanceCount,a,5126)),_&&(b.attributes.SCALE=i._buildAccessor(x,"VEC3",r.thinInstanceCount,a,5126)),t.extensions=t.extensions||{},t.extensions[Q]=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}();v.RegisterExtension(Q,(function(e){return new Y(e)}));var X="KHR_materials_emissive_strength",Z=function(){function e(){this.name=X,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(!(r instanceof d.PBRMaterial))return e(t);var a=r.emissiveColor.asArray(),i=Math.max.apply(Math,a);if(i>1){n._wasUsed=!0,t.extensions||(t.extensions={});var o={emissiveStrength:i},s=r.emissiveColor.scale(1/o.emissiveStrength);t.emissiveFactor=s.asArray(),t.extensions[X]=o}return e(t)}))},e}();v.RegisterExtension(X,(function(e){return new Z}));var J=0,$=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==$){$.BABYLON=$.BABYLON||{};var ee=$.BABYLON;ee.GLTF2=ee.GLTF2||{},ee.GLTF2.Exporter=ee.GLTF2.Exporter||{},ee.GLTF2.Exporter.Extensions=ee.GLTF2.Exporter.Extensions||{};var te=[];for(var re in e)ee[re]=e[re],te.push(re);for(var re in t)ee[re]=t[re],te.push(re);for(var re in r)ee[re]=r[re],te.push(re);for(var re in i)ee.GLTF2.Exporter.Extensions[re]=i[re],te.push(re);for(var re in o)te.indexOf(re)>-1||(ee.GLTF2.Exporter[re]=o[re])}const ne=s})(),a.default})()));
2
2
  //# sourceMappingURL=babylon.glTF2Serializer.min.js.map