babylonjs-serializers 6.6.0 → 6.7.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:()=>$});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:()=>v});var i={};n.r(i),n.d(i,{EXT_mesh_gpu_instancing:()=>W,KHR_lights_punctual:()=>M,KHR_materials_anisotropy:()=>S,KHR_materials_clearcoat:()=>R,KHR_materials_emissive_strength:()=>Q,KHR_materials_ior:()=>L,KHR_materials_iridescence:()=>V,KHR_materials_sheen:()=>B,KHR_materials_specular:()=>U,KHR_materials_transmission:()=>H,KHR_materials_unlit:()=>N,KHR_materials_volume:()=>G,KHR_texture_transform:()=>A});var o={};n.r(o),n.d(o,{EXT_mesh_gpu_instancing:()=>W,GLTF2Export:()=>v,GLTFData:()=>l,KHR_lights_punctual:()=>M,KHR_materials_anisotropy:()=>S,KHR_materials_clearcoat:()=>R,KHR_materials_emissive_strength:()=>Q,KHR_materials_ior:()=>L,KHR_materials_iridescence:()=>V,KHR_materials_sheen:()=>B,KHR_materials_specular:()=>U,KHR_materials_transmission:()=>H,KHR_materials_unlit:()=>N,KHR_materials_volume:()=>G,KHR_texture_transform:()=>A,_BinaryWriter:()=>T,_Exporter:()=>y,_GLTFAnimation:()=>m,_GLTFMaterialExporter:()=>_,_GLTFUtilities:()=>g,__IGLTFExporterExtensionV2:()=>j});var s={};n.r(s),n.d(s,{EXT_mesh_gpu_instancing:()=>W,GLTF2Export:()=>v,GLTFData:()=>l,KHR_lights_punctual:()=>M,KHR_materials_anisotropy:()=>S,KHR_materials_clearcoat:()=>R,KHR_materials_emissive_strength:()=>Q,KHR_materials_ior:()=>L,KHR_materials_iridescence:()=>V,KHR_materials_sheen:()=>B,KHR_materials_specular:()=>U,KHR_materials_transmission:()=>H,KHR_materials_unlit:()=>N,KHR_materials_volume:()=>G,KHR_texture_transform:()=>A,_BinaryWriter:()=>T,_Exporter:()=>y,_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;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,R,w,V,C,S,I,B,P,N,O,L,k;return f(this,(function(f){switch(f.label){case 0:return o=new Array,t||r?(s=t?t.getScene():r?r.getScene():null)?(u=this._resizeTexturesToSameDimensions(t,r,s),l=null===(i=u.texture1)||void 0===i?void 0:i.getSize(),c=void 0,h=void 0,p=l.width,_=l.height,[4,u.texture1.readPixels()]):[3,3]:[2,Promise.reject("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!")];case 1:return 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),R=h[E+3]*n.glossiness,w={diffuseColor:M,specularColor:F,glossiness:R},V=this._convertSpecularGlossinessToMetallicRoughness(w),v.r=Math.max(v.r,V.baseColor.r),v.g=Math.max(v.g,V.baseColor.g),v.b=Math.max(v.b,V.baseColor.b),b=Math.max(b,V.metallic),A=Math.max(A,V.roughness),T[E]=255*V.baseColor.r,T[E+1]=255*V.baseColor.g,T[E+2]=255*V.baseColor.b,T[E+3]=u.texture1.hasAlpha?255*c[E+3]:255,y[E]=0,y[E+1]=255*V.roughness,y[E+2]=255*V.metallic,y[E+3]=255;for(C={baseColor:v,metallic:b,roughness:A},S=!1,I=!1,B=0;B<_;++B)for(P=0;P<p;++P)T[N=4*(p*B+P)]/=C.baseColor.r>e._Epsilon?C.baseColor.r:1,T[N+1]/=C.baseColor.g>e._Epsilon?C.baseColor.g:1,T[N+2]/=C.baseColor.b>e._Epsilon?C.baseColor.b:1,O=d.Color3.FromInts(T[N],T[N+1],T[N+2]),L=O.toGammaSpace(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]/=C.roughness>e._Epsilon?C.roughness:1,y[N+2]/=C.metallic>e._Epsilon?C.metallic:1,k=d.Color3.FromInts(255,y[N+1],y[N+2]),e._FuzzyEquals(k,d.Color3.White(),e._Epsilon)||(S=!0);return S&&o.push(this._getImageDataAsync(y,p,_,a).then((function(e){C.metallicRoughnessTextureData=e}))),I&&o.push(this._getImageDataAsync(T,p,_,a).then((function(e){C.baseColorTextureData=e}))),[2,Promise.all(o).then((function(){return C}))];case 3:return[2,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}}))}))},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(t){var r=this._getPerceivedBrightness(t.diffuseColor),n=this._getPerceivedBrightness(t.specularColor),a=1-this._getMaxComponent(t.specularColor),i=e._SolveMetallic(r,n,a),o=t.diffuseColor.scale(a/(1-e._DielectricSpecular.r)/Math.max(1-i,e._Epsilon)),s=t.specularColor.subtract(e._DielectricSpecular.scale(1-i)).scale(1/Math.max(i,e._Epsilon)),u=d.Color3.Lerp(o,s,i*i);return{baseColor:u=u.clampToRef(0,1,u),metallic:i,roughness:1-t.glossiness}},e.prototype._getPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},e.prototype._getMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},e.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,r,n){var a=[],i={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness};if(n){e._albedoTexture&&a.push(this._exportTextureAsync(e._albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)})));var o=e._metallicTexture;o&&a.push(this._exportTextureAsync(o,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))}return Promise.all(a).then((function(){return i}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof d.Texture))return t;var r=this._getGLTFTextureWrapMode(e.wrapU);10497!==r&&(t.wrapS=r);var n=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==n&&(t.wrapT=n),e.samplingMode){case d.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case d.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case d.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case d.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case d.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case d.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case d.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case d.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case d.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case d.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case d.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case d.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case d.Texture.WRAP_ADDRESSMODE:return 10497;case d.Texture.CLAMP_ADDRESSMODE:return 33071;case d.Texture.MIRROR_ADDRESSMODE:return 33648;default:return d.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r,n){var a=this;return Promise.resolve().then((function(){var i={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},o=e._albedoTexture,s=e._reflectivityTexture,u=e._useMicroSurfaceFromReflectivityMapAlpha;if(s&&!u)return Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported");if((o||s)&&n){var l=a._exportTextureSampler(o||s);return a._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(o,s,i,t).then((function(e){var n=a._exporter._textures;if(e.baseColorTextureData){var i=a._exportImage("baseColor".concat(n.length),t,e.baseColorTextureData);r.baseColorTexture=a._exportTextureInfo(i,l,null==o?void 0:o.coordinatesIndex)}return e.metallicRoughnessTextureData&&(i=a._exportImage("metallicRoughness".concat(n.length),t,e.metallicRoughnessTextureData),r.metallicRoughnessTexture=a._exportTextureInfo(i,l,null==s?void 0:s.coordinatesIndex)),e}))}return a._convertSpecularGlossinessToMetallicRoughness(i)}))},e.prototype._convertPBRMaterialAsync=function(e,t,r){var n=this,a={},i={name:e.name};if(e.isMetallicWorkflow()){var o=e._albedoColor,s=e.alpha;return o&&(a.baseColorFactor=[o.r,o.g,o.b,s]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,a,r).then((function(o){return n._setMetallicRoughnessPbrMaterial(o,e,i,a,t,r)}))}return this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,a,r).then((function(o){return n._setMetallicRoughnessPbrMaterial(o,e,i,a,t,r)}))},e.prototype._setMetallicRoughnessPbrMaterial=function(t,r,n,a,i,o){var s=this._exporter._materialMap,u=this._exporter._materials,l=[];if(t){if(e._SetAlphaMode(n,r),e._FuzzyEquals(t.baseColor,d.Color3.White(),e._Epsilon)&&r.alpha>=e._Epsilon||(a.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,r.alpha]),null!=t.metallic&&1!==t.metallic&&(a.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(a.roughnessFactor=t.roughness),null==r.backFaceCulling||r.backFaceCulling||(r._twoSidedLighting||d.Tools.Warn(r.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),o){var c=r._bumpTexture;if(c){var f=this._exportTextureAsync(c,i).then((function(e){e&&(n.normalTexture=e,1!==c.level&&(n.normalTexture.scale=c.level))}));l.push(f)}var h=r._ambientTexture;h&&(f=this._exportTextureAsync(h,i).then((function(e){if(e){var t={index:e.index,texCoord:e.texCoord,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(t,r,n,a){var i,o,s,u=[1/0,1/0,1/0],l=[-1/0,-1/0,-1/0];if(n)for(var c=r,f=r+n;c<f;++c){i=3*c,o=d.Vector3.FromArray(t,i),a&&e._GetRightHandedPositionVector3FromRef(o),s=o.asArray();for(var h=0;h<3;++h){var p=s[h];p<u[h]&&(u[h]=p),p>l[h]&&(l[h]=p),++i}}return{min:u,max:l}},e._GetRightHandedPositionVector3=function(e){return new d.Vector3(e.x,e.y,-e.z)},e._GetRightHandedPositionVector3FromRef=function(e){e.z*=-1},e._GetRightHandedPositionArray3FromRef=function(e){e[2]*=-1},e._GetRightHandedNormalVector3=function(e){return new d.Vector3(e.x,e.y,-e.z)},e._GetRightHandedNormalVector3FromRef=function(e){e.z*=-1},e._GetRightHandedNormalArray3FromRef=function(e){e[2]*=-1},e._GetRightHandedVector4FromRef=function(e){e.z*=-1,e.w*=-1},e._GetRightHandedArray4FromRef=function(e){e[2]*=-1,e[3]*=-1},e._GetRightHandedQuaternionFromRef=function(e){e.x*=-1,e.y*=-1},e._GetRightHandedQuaternionArrayFromRef=function(e){e[0]*=-1,e[1]*=-1},e._NormalizeTangentFromRef=function(e){var t=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);t>0&&(e.x/=t,e.y/=t,e.z/=t)},e._GetDataAccessorElementCount=function(e){switch(e){case"MAT2":case"VEC4":return 4;case"MAT3":return 9;case"MAT4":return 16;case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3}},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(p||(p={}));var 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,o){if(this._IsTransformable(t)){var s=[],u=[],l=r.getKeys(),c=e._CalculateMinMaxKeyFrames(l),f=e._DeduceInterpolation(l,n,i),h=c.max-c.min,p=f.interpolationType,_=f.shouldBakeAnimation;if(_?e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,o,s,u,c,a,i):"LINEAR"===p||"STEP"===p?e._CreateLinearOrStepAnimation(t,r,n,h,s,u,a,i):"CUBICSPLINE"===p?e._CreateCubicSplineAnimation(t,r,n,h,s,u,a,i):e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,o,s,u,c,a,i),s.length&&u.length)return{inputs:s,outputs:u,samplerInterpolation:p,inputsMin:_?c.min:d.Tools.FloatRound(c.min/r.framePerSecond),inputsMax:_?c.max:d.Tools.FloatRound(c.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,a=e.targetProperty.split(".");switch(a[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":r="VEC4",t="rotation";break;case"rotationQuaternion":r="VEC4",n=!0,t="rotation";break;case"influence":r="SCALAR",t="weights";break;default:d.Tools.Error("Unsupported animatable property ".concat(a[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(d.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,r,n,a,i,o,s,u,l,c,f){var h;if(e._IsTransformable(t)&&t.animations)for(var p=0,d=t.animations;p<d.length;p++){var _=d[p];if(!f||f(_)){var g=e._DeduceAnimationInfo(_);g&&(h={name:_.name,samplers:[],channels:[]},e._AddAnimation("".concat(_.name),_.hasRunningRuntimeAnimations?r:h,t,_,g.dataAccessorType,g.animationChannelTargetPath,a,o,s,u,l,g.useQuaternion,c),h.samplers.length&&h.channels.length&&n.push(h))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,a,i,o,s,u,l,c,f){var h;if(t instanceof d.Mesh){var p=t.morphTargetManager;if(p)for(var _=0;_<p.numTargets;++_)for(var g=0,m=p.getTarget(_).animations;g<m.length;g++){var x=m[g];if(!f||f(x)){for(var y=new d.Animation("".concat(x.name),"influence",x.framePerSecond,x.dataType,x.loopMode,x.enableBlending),T=[],v=x.getKeys(),b=0;b<v.length;++b)for(var A=v[b],E=0;E<p.numTargets;++E)E==_?T.push(A):T.push({frame:A.frame,value:0});y.setKeys(T);var M=e._DeduceAnimationInfo(y);M&&(h={name:y.name,samplers:[],channels:[]},e._AddAnimation(x.name,x.hasRunningRuntimeAnimations?r:h,t,y,M.dataAccessorType,M.animationChannelTargetPath,a,o,s,u,l,M.useQuaternion,c,p.numTargets),h.samplers.length&&h.channels.length&&n.push(h))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,a,i,o,s,u,l,c){var f,h;if(t.animationGroups)for(var p=t.animationGroups,_=function(a){var p=new Map,_=new Map,m=new Set,x=a.to-a.from;h={name:a.name,channels:[],samplers:[]};for(var y=function(r){var x=a.targetedAnimations[r],y=x.target,T=x.animation;if(c&&!c(T))return"continue";if(g._IsTransformable(y)||1===y.length&&g._IsTransformable(y[0])){if(A=e._DeduceAnimationInfo(x.animation)){var v=g._IsTransformable(y)?y:g._IsTransformable(y[0])?y[0]:null;if(v){var b=u[v.uniqueId];e._AddAnimation("".concat(T.name),h,v,T,A.dataAccessorType,A.animationChannelTargetPath,n,i,o,s,b,A.useQuaternion,l)}}}else if(y instanceof d.MorphTarget||1===y.length&&y[0]instanceof d.MorphTarget){var A;if(A=e._DeduceAnimationInfo(x.animation)){var E=y instanceof d.MorphTarget?y:y[0];if(E){var M=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===E)return!0;return!1}));if(M){var F=t.meshes.find((function(e){return e.morphTargetManager===M}));F&&(p.has(F)||p.set(F,new Map),null===(f=p.get(F))||void 0===f||f.set(E,T),m.add(F),_.set(F,T))}}}}},T=0;T<a.targetedAnimations.length;++T)y(T);m.forEach((function(t){for(var r=t.morphTargetManager,u=null,c=[],f=_.get(t).getKeys(),g=f.length,m=0;m<g;++m)for(var y=0;y<r.numTargets;++y){var T=r.getTarget(y),v=p.get(t);if(v){var b=v.get(T);b?(u||(u=new d.Animation("".concat(a.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,d.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[m])):c.push({frame:a.from+x/g*m,value:T.influence,inTangent:f[0].inTangent?0:void 0,outTangent:f[0].outTangent?0:void 0})}}u.setKeys(c);var A=e._DeduceAnimationInfo(u);A&&e._AddAnimation("".concat(a.name,"_").concat(t.name,"_MorphWeightAnimation"),h,t,u,A.dataAccessorType,A.animationChannelTargetPath,n,i,o,s,!1,A.useQuaternion,l,null==r?void 0:r.numTargets)})),h.channels.length&&h.samplers.length&&r.push(h)},g=this,m=0,x=p;m<x.length;m++)_(x[m])},e._AddAnimation=function(t,r,n,a,i,o,s,u,l,c,f,h,p,d){var _,m,x,y,T,v,b,A=e._CreateNodeAnimation(n,a,o,f,h,p);if(A){if(d){for(var E=0,M=0,F=[];A.inputs.length>0;)M=A.inputs.shift(),E%d==0&&F.push(M),E++;A.inputs=F}var R=s[n.uniqueId],w=4*A.inputs.length;_=g._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," keyframe data view")),l.push(_),A.inputs.forEach((function(e){u.setFloat32(e)})),m=g._CreateAccessor(l.length-1,"".concat(t," keyframes"),"SCALAR",5126,A.inputs.length,null,[A.inputsMin],[A.inputsMax]),c.push(m),x=c.length-1,T=A.outputs.length,w=4*g._GetDataAccessorElementCount(i)*A.outputs.length,_=g._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," data view")),l.push(_),A.outputs.forEach((function(e){e.forEach((function(e){u.setFloat32(e)}))})),m=g._CreateAccessor(l.length-1,"".concat(t," data"),i,5126,T,null,null,null),c.push(m),y=c.length-1,v={interpolation:A.samplerInterpolation,input:x,output:y},r.samplers.push(v),b={sampler:r.samplers.length-1,target:{node:R,path:o}},r.channels.push(b)}},e._CreateBakedAnimation=function(t,r,n,a,i,o,s,u,l,c,f,h){var p,_,g=d.Quaternion.Identity(),m=null,x=null,y=null,T=null,v=null,b=null;c.min=d.Tools.FloatRound(a/o);for(var A=r.getKeys(),E=0,M=A.length;E<M;++E){if(b=null,y=A[E],E+1<M)if(T=A[E+1],y.value.equals&&y.value.equals(T.value)||y.value===T.value){if(0!==E)continue;b=y.frame}else b=T.frame;else{if(v=A[E-1],y.value.equals&&y.value.equals(v.value)||y.value===v.value)continue;b=i}if(b)for(var F=y.frame;F<=b;F+=s)if((_=d.Tools.FloatRound(F/o))!==m){m=_,x=_;var R={key:0,repeatCount:0,loopMode:r.loopMode};p=r._interpolate(F,R),e._SetInterpolatedValue(t,p,_,r,n,g,u,l,f,h)}}x&&(c.max=x)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,a,i,o){var s=e._GetBasePositionRotationOrScale(r,a,i,o),u=n.targetProperty.split("."),l=u?u[1]:"",c=o?d.Quaternion.FromArray(s).normalize():d.Vector3.FromArray(s);switch(l){case"x":case"y":c[l]=i&&o&&"scale"!==a?-t:t;break;case"z":c[l]=i&&!o&&"scale"!==a?-t:t;break;case"w":c.w=t;break;default:d.Tools.Error('glTFAnimation: Unsupported component name "'.concat(l,'"!'))}return c},e._SetInterpolatedValue=function(e,t,r,n,a,i,o,s,u,l){var c;o.push(r),"weights"!==a?(n.dataType===d.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,a,u,l)),"rotation"===a?(l?i=t:(c=t,d.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,i)),u&&(g._GetRightHandedQuaternionFromRef(i),e.parent||(i=d.Quaternion.FromArray([0,1,0,0]).multiply(i))),s.push(i.asArray())):(c=t,u&&"scale"!==a&&(g._GetRightHandedPositionVector3FromRef(c),e.parent||(c.x*=-1,c.z*=-1)),s.push(c.asArray()))):s.push([t])},e._CreateLinearOrStepAnimation=function(t,r,n,a,i,o,s,u){for(var l=0,c=r.getKeys();l<c.length;l++){var f=c[l];i.push(f.frame/r.framePerSecond),e._AddKeyframeValue(f,r,o,n,t,s,u)}},e._CreateCubicSplineAnimation=function(t,r,n,a,i,o,s,u){r.getKeys().forEach((function(l){i.push(l.frame/r.framePerSecond),e._AddSplineTangent(t,p.INTANGENT,o,n,"CUBICSPLINE",l,a,u,s),e._AddKeyframeValue(l,r,o,n,t,s,u),e._AddSplineTangent(t,p.OUTTANGENT,o,n,"CUBICSPLINE",l,a,u,s)}))},e._GetBasePositionRotationOrScale=function(e,t,r,n){var a;if("rotation"===t)if(n){var i=e.rotationQuaternion;a=(null!=i?i:d.Quaternion.Identity()).asArray(),r&&(g._GetRightHandedQuaternionArrayFromRef(a),e.parent||(a=d.Quaternion.FromArray([0,1,0,0]).multiply(d.Quaternion.FromArray(a)).asArray()))}else{var o=e.rotation;a=(null!=o?o:d.Vector3.Zero()).asArray(),g._GetRightHandedNormalArray3FromRef(a)}else if("translation"===t){var s=e.position;a=(null!=s?s:d.Vector3.Zero()).asArray(),r&&g._GetRightHandedPositionArray3FromRef(a)}else{var u=e.scaling;a=(null!=u?u:d.Vector3.One()).asArray()}return a},e._AddKeyframeValue=function(e,t,r,n,a,i,o){var s,u,l=t.dataType;if(l===d.Animation.ANIMATIONTYPE_VECTOR3){if(s=e.value.asArray(),"rotation"===n){var c=d.Vector3.FromArray(s),f=d.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z);i&&(g._GetRightHandedQuaternionFromRef(f),a.parent||(f=d.Quaternion.FromArray([0,1,0,0]).multiply(f))),s=f.asArray()}else"translation"===n&&i&&(g._GetRightHandedNormalArray3FromRef(s),a.parent||(s[0]*=-1,s[2]*=-1));r.push(s)}else if(l===d.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(u=this._ConvertFactorToVector3OrQuaternion(e.value,a,t,n,i,o)){if("rotation"===n){var h=o?u:d.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).normalize();i&&(g._GetRightHandedQuaternionFromRef(h),a.parent||(h=d.Quaternion.FromArray([0,1,0,0]).multiply(h))),r.push(h.asArray())}else"translation"===n&&i&&(g._GetRightHandedNormalVector3FromRef(u),a.parent||(u.x*=-1,u.z*=-1));r.push(u.asArray())}}else l===d.Animation.ANIMATIONTYPE_QUATERNION?(s=e.value.normalize().asArray(),i&&(g._GetRightHandedQuaternionArrayFromRef(s),a.parent||(s=d.Quaternion.FromArray([0,1,0,0]).multiply(d.Quaternion.FromArray(s)).asArray())),r.push(s)):d.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,a,i=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var o=0,s=e.length;o<s;++o)if((a=e[o]).inTangent||a.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",i=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||a.interpolation&&a.interpolation===d.AnimationKeyInterpolation.STEP&&"STEP"!==n){n="LINEAR",i=!0;break}}else n=a.interpolation&&a.interpolation===d.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,t,r,n,a,i,o,s,u){var l,c=t===p.INTANGENT?i.inTangent:i.outTangent;if("CUBICSPLINE"===a){if("rotation"===n)if(c){if(s)l=c.asArray();else{var f=c;l=d.Quaternion.RotationYawPitchRoll(f.y,f.x,f.z).asArray()}u&&(g._GetRightHandedQuaternionArrayFromRef(l),e.parent||(l=d.Quaternion.FromArray([0,1,0,0]).multiply(d.Quaternion.FromArray(l)).asArray()))}else l=[0,0,0,0];else"weights"===n?l=c?[c]:[0]:c?(l=c.asArray(),u&&"translation"===n&&(g._GetRightHandedPositionArray3FromRef(l),e.parent||(l[0]*=-1,l[2]*=-1))):l=[0,0,0];r.push(l)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,r=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),r=Math.max(r,e.frame)})),{min:t,max:r}},e}(),x=d.Matrix.Compose(new d.Vector3(-1,1,1),d.Quaternion.Identity(),d.Vector3.Zero()),y=function(){function e(e,t){this._includeCoordinateSystemConversionNodes=!1,this._extensions={},this._glTF={asset:{generator:"Babylon.js v".concat(d.Engine.Version),version:"2.0"}},(e=e||d.EngineStore.LastCreatedScene)&&(this._babylonScene=e,this._bufferViews=[],this._accessors=[],this._meshes=[],this._scenes=[],this._cameras=[],this._nodes=[],this._images=[],this._materials=[],this._materialMap=[],this._textures=[],this._samplers=[],this._skins=[],this._animations=[],this._imageData={},this._orderedImageData=[],this._options=t||{},this._animationSampleRate=t&&t.animationSampleRate?t.animationSampleRate:1/60,this._includeCoordinateSystemConversionNodes=!(!t||!t.includeCoordinateSystemConversionNodes),this._glTFMaterialExporter=new _(this),this._loadExtensions())}return e.prototype._applyExtension=function(e,t,r,n){var a=this;if(r>=t.length)return Promise.resolve(e);var i=n(t[r],e);return i?i.then((function(e){return a._applyExtension(e,t,r+1,n)})):this._applyExtension(e,t,r+1,n)},e.prototype._applyExtensions=function(t,r){for(var n=[],a=0,i=e._ExtensionNames;a<i.length;a++){var o=i[a];n.push(this._extensions[o])}return this._applyExtension(t,n,0,r)},e.prototype._extensionsPreExportTextureAsync=function(e,t,r){return this._applyExtensions(t,(function(t,n){return t.preExportTextureAsync&&t.preExportTextureAsync(e,n,r)}))},e.prototype._extensionsPostExportMeshPrimitiveAsync=function(e,t,r,n){return this._applyExtensions(t,(function(t,a){return t.postExportMeshPrimitiveAsync&&t.postExportMeshPrimitiveAsync(e,a,r,n)}))},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n,a){return this._applyExtensions(t,(function(t,i){return t.postExportNodeAsync&&t.postExportNodeAsync(e,i,r,n,a)}))},e.prototype._extensionsPostExportMaterialAsync=function(e,t,r){return this._applyExtensions(t,(function(t,n){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,n,r)}))},e.prototype._extensionsPostExportMaterialAdditionalTextures=function(t,r,n){for(var a=[],i=0,o=e._ExtensionNames;i<o.length;i++){var s=o[i],u=this._extensions[s];u.postExportMaterialAdditionalTextures&&a.push.apply(a,u.postExportMaterialAdditionalTextures(t,r,n))}return a},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var a=0,i=e._ExtensionNames;a<i.length;a++){var o=i[a],s=this._extensions[o];s.postExportTexture&&s.postExportTexture(t,r,n)}},e.prototype._forEachExtensions=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var a=n[r],i=this._extensions[a];i.enabled&&t(i)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){t.wasUsed&&(null==e._glTF.extensionsUsed&&(e._glTF.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&(null==e._glTF.extensionsRequired&&(e._glTF.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),null==e._glTF.extensions&&(e._glTF.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],a=e._ExtensionFactories[n](this);this._extensions[n]=a}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e.RegisterExtension=function(t,r){e.UnregisterExtension(t)&&d.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=r,e._ExtensionNames.push(t)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t];var r=e._ExtensionNames.indexOf(t);return-1!==r&&e._ExtensionNames.splice(r,1),!0},e.prototype._reorderIndicesBasedOnPrimitiveMode=function(e,t,r,n,a){switch(t){case d.Material.TriangleFillMode:n||(n=0);for(var i=e.indexStart,o=e.indexStart+e.indexCount;i<o;i+=3){var s=n+4*i,u=a.getUInt32(s+4),l=a.getUInt32(s+8);a.setUInt32(l,s+4),a.setUInt32(u,s+8)}break;case d.Material.TriangleFanDrawMode:i=e.indexStart+e.indexCount-1;for(var c=e.indexStart;i>=c;--i)a.setUInt32(r[i],n),n+=4;break;case d.Material.TriangleStripDrawMode:e.indexCount>=3&&(a.setUInt32(r[e.indexStart+2],n+4),a.setUInt32(r[e.indexStart+1],n+8))}},e.prototype._reorderVertexAttributeDataBasedOnPrimitiveMode=function(e,t,r,n,a,i,o,s){if(s&&r===d.Material.ClockWiseSideOrientation)switch(t){case d.Material.TriangleFillMode:this._reorderTriangleFillMode(e,t,r,n,a,i,o,s);break;case d.Material.TriangleStripDrawMode:this._reorderTriangleStripDrawMode(e,t,r,n,a,i,o,s);break;case d.Material.TriangleFanDrawMode:this._reorderTriangleFanMode(e,t,r,n,a,i,o,s)}},e.prototype._reorderTriangleFillMode=function(e,t,r,n,a,i,o,s){var u=this._getVertexBufferFromMesh(n,e.getMesh());if(u){var l=u.byteStride/d.VertexBuffer.GetTypeByteLength(u.type);if(e.verticesCount%3!=0)d.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var c=[],f=0;switch(n){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:for(var h=e.verticesStart;h<e.verticesStart+e.verticesCount;h+=3)f=h*l,c.push(d.Vector3.FromArray(a,f)),c.push(d.Vector3.FromArray(a,f+2*l)),c.push(d.Vector3.FromArray(a,f+l));break;case d.VertexBuffer.TangentKind:for(h=e.verticesStart;h<e.verticesStart+e.verticesCount;h+=3)f=h*l,c.push(d.Vector4.FromArray(a,f)),c.push(d.Vector4.FromArray(a,f+2*l)),c.push(d.Vector4.FromArray(a,f+l));break;case d.VertexBuffer.ColorKind:var p=u.getSize();for(h=e.verticesStart;h<e.verticesStart+e.verticesCount;h+=p)f=h*l,4===p?(c.push(d.Vector4.FromArray(a,f)),c.push(d.Vector4.FromArray(a,f+2*l)),c.push(d.Vector4.FromArray(a,f+l))):(c.push(d.Vector3.FromArray(a,f)),c.push(d.Vector3.FromArray(a,f+2*l)),c.push(d.Vector3.FromArray(a,f+l)));break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:for(h=e.verticesStart;h<e.verticesStart+e.verticesCount;h+=3)f=h*l,c.push(d.Vector2.FromArray(a,f)),c.push(d.Vector2.FromArray(a,f+2*l)),c.push(d.Vector2.FromArray(a,f+l));break;default:d.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this._writeVertexAttributeData(c,i,n,a,o,s)}}else d.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind ".concat(n," not present!"))},e.prototype._reorderTriangleStripDrawMode=function(e,t,r,n,a,i,o,s){var u=this._getVertexBufferFromMesh(n,e.getMesh());if(u){var l=u.byteStride/d.VertexBuffer.GetTypeByteLength(u.type),c=[],f=0;switch(n){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:f=e.verticesStart,c.push(d.Vector3.FromArray(a,f+2*l)),c.push(d.Vector3.FromArray(a,f+l));break;case d.VertexBuffer.TangentKind:for(var h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,c.push(d.Vector4.FromArray(a,f));break;case d.VertexBuffer.ColorKind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,4===u.getSize()?c.push(d.Vector4.FromArray(a,f)):c.push(d.Vector3.FromArray(a,f));break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,c.push(d.Vector2.FromArray(a,f));break;default:d.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this._writeVertexAttributeData(c,i+12,n,a,o,s)}else d.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind ".concat(n," not present!"))},e.prototype._reorderTriangleFanMode=function(e,t,r,n,a,i,o,s){var u=this._getVertexBufferFromMesh(n,e.getMesh());if(u){var l=u.byteStride/d.VertexBuffer.GetTypeByteLength(u.type),c=[],f=0;switch(n){case d.VertexBuffer.PositionKind:case d.VertexBuffer.NormalKind:for(var h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,c.push(d.Vector3.FromArray(a,f));break;case d.VertexBuffer.TangentKind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,c.push(d.Vector4.FromArray(a,f));break;case d.VertexBuffer.ColorKind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,c.push(d.Vector4.FromArray(a,f)),4===u.getSize()?c.push(d.Vector4.FromArray(a,f)):c.push(d.Vector3.FromArray(a,f));break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*l,c.push(d.Vector2.FromArray(a,f));break;default:d.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this._writeVertexAttributeData(c,i,n,a,o,s)}else d.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind ".concat(n," not present!"))},e.prototype._writeVertexAttributeData=function(e,t,r,n,a,i){for(var o=0,s=e;o<s.length;o++){var u=s[o];!i||r===d.VertexBuffer.ColorKind||u instanceof d.Vector2||(u instanceof d.Vector3?r===d.VertexBuffer.NormalKind?g._GetRightHandedNormalVector3FromRef(u):r===d.VertexBuffer.PositionKind?g._GetRightHandedPositionVector3FromRef(u):d.Tools.Error("Unsupported vertex attribute kind!"):g._GetRightHandedVector4FromRef(u)),r===d.VertexBuffer.NormalKind?u.normalize():r===d.VertexBuffer.TangentKind&&u instanceof d.Vector4&&g._NormalizeTangentFromRef(u);for(var l=0,c=u.asArray();l<c.length;l++){var f=c[l];a.setFloat32(f,t),t+=4}}},e.prototype._writeAttributeData=function(e,t,r,n,a,i,o){var s,u,l=[];switch(e){case d.VertexBuffer.PositionKind:for(var c=0,f=r.length/n;c<f;++c){s=c*n;var h=d.Vector3.FromArray(r,s);i&&g._GetRightHandedPositionVector3FromRef(h),l.push(h.asArray())}break;case d.VertexBuffer.NormalKind:c=0;for(var p=r.length/n;c<p;++c)s=c*n,h=d.Vector3.FromArray(r,s),i&&g._GetRightHandedNormalVector3FromRef(h),h.normalize(),l.push(h.asArray());break;case d.VertexBuffer.TangentKind:c=0;for(var _=r.length/n;c<_;++c)s=c*n,h=d.Vector4.FromArray(r,s),i&&g._GetRightHandedVector4FromRef(h),g._NormalizeTangentFromRef(h),l.push(h.asArray());break;case d.VertexBuffer.ColorKind:for(var m=o.material,x=!m||"StandardMaterial"===m.getClassName(),y=(h=3===n?new d.Color3:new d.Color4,this._babylonScene.getEngine().useExactSrgbConversions),T=(c=0,r.length/n);c<T;++c)s=c*n,3===n?(d.Color3.FromArrayToRef(r,s,h),x&&h.toLinearSpaceToRef(h,y)):(d.Color4.FromArrayToRef(r,s,h),x&&h.toLinearSpaceToRef(h,y)),l.push(h.asArray());break;case d.VertexBuffer.UVKind:case d.VertexBuffer.UV2Kind:c=0;for(var v=r.length/n;c<v;++c)s=c*n,l.push([r[s],r[s+1]]);break;case d.VertexBuffer.MatricesIndicesKind:case d.VertexBuffer.MatricesIndicesExtraKind:c=0;for(var b=r.length/n;c<b;++c)s=c*n,h=d.Vector4.FromArray(r,s),l.push(h.asArray());break;case d.VertexBuffer.MatricesWeightsKind:case d.VertexBuffer.MatricesWeightsExtraKind:c=0;for(var A=r.length/n;c<A;++c)s=c*n,h=d.Vector4.FromArray(r,s),l.push(h.asArray());break;default:d.Tools.Warn("Unsupported Vertex Buffer Type: "+e),l=[]}switch(t){case 5121:u=a.setUInt8.bind(a);break;case 5123:u=a.setUInt16.bind(a);break;case 5125:u=a.setUInt32.bind(a);break;case 5126:u=a.setFloat32.bind(a);break;default:return void d.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var E=0,M=l;E<M.length;E++)for(var F=0,R=M[E];F<R.length;F++)u(R[F])},e.prototype.writeMorphTargetAttributeData=function(e,t,r,n,a,i,o,s,u,l){var c,f,h=[],p=new d.Vector3,_=new d.Vector4(0,0,0,0);switch(e){case d.VertexBuffer.PositionKind:for(var m=r.verticesStart;m<r.verticesCount;++m){c=r.indexStart+m*o;var x=d.Vector3.FromArray(a,c);p=(y=d.Vector3.FromArray(i,c)).subtractToRef(x,p),u&&g._GetRightHandedPositionVector3FromRef(p),l&&(l.min.copyFromFloats(Math.min(p.x,l.min.x),Math.min(p.y,l.min.y),Math.min(p.z,l.min.z)),l.max.copyFromFloats(Math.max(p.x,l.max.x),Math.max(p.y,l.max.y),Math.max(p.z,l.max.z))),h.push(p.asArray())}break;case d.VertexBuffer.NormalKind:for(m=r.verticesStart;m<r.verticesCount;++m)c=r.indexStart+m*o,(x=d.Vector3.FromArray(a,c)).normalize(),(y=d.Vector3.FromArray(i,c)).normalize(),p=y.subtractToRef(x,p),u&&g._GetRightHandedNormalVector3FromRef(p),h.push(p.asArray());break;case d.VertexBuffer.TangentKind:for(m=r.verticesStart;m<r.verticesCount;++m){c=r.indexStart+m*(o+1),x=d.Vector4.FromArray(a,c),g._NormalizeTangentFromRef(x);var y=d.Vector4.FromArray(i,c);g._NormalizeTangentFromRef(y),_=y.subtractToRef(x,_),u&&g._GetRightHandedVector4FromRef(_),h.push([_.x,_.y,_.z])}break;default:d.Tools.Warn("Unsupported Vertex Buffer Type: "+e),h=[]}switch(t){case 5121:f=s.setUInt8.bind(s);break;case 5123:f=s.setUInt16.bind(s);break;case 5125:f=s.setUInt32.bind(s);break;case 5126:f=s.setFloat32.bind(s);break;default:return void d.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var T=0,v=h;T<v.length;T++)for(var b=0,A=v[T];b<A.length;b++)f(A[b])},e.prototype._generateJSON=function(e,t,r){var n,a,i,o=this,s={byteLength:this._totalByteLength},u=this._totalByteLength;return s.byteLength&&(this._glTF.buffers=[s]),this._nodes&&this._nodes.length&&(this._glTF.nodes=this._nodes),this._meshes&&this._meshes.length&&(this._glTF.meshes=this._meshes),this._scenes&&this._scenes.length&&(this._glTF.scenes=this._scenes,this._glTF.scene=0),this._cameras&&this._cameras.length&&(this._glTF.cameras=this._cameras),this._bufferViews&&this._bufferViews.length&&(this._glTF.bufferViews=this._bufferViews),this._accessors&&this._accessors.length&&(this._glTF.accessors=this._accessors),this._animations&&this._animations.length&&(this._glTF.animations=this._animations),this._materials&&this._materials.length&&(this._glTF.materials=this._materials),this._textures&&this._textures.length&&(this._glTF.textures=this._textures),this._samplers&&this._samplers.length&&(this._glTF.samplers=this._samplers),this._skins&&this._skins.length&&(this._glTF.skins=this._skins),this._images&&this._images.length&&(e?(this._glTF.images=[],this._images.forEach((function(e){e.uri&&(a=o._imageData[e.uri],o._orderedImageData.push(a),n=e.uri.split(".")[0]+" image",i=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 T(4);return this._createSceneAsync(this._babylonScene,t).then((function(){return e._localEngine&&e._localEngine.dispose(),t.getArrayBuffer()}))},e.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},e.prototype._generateGLBAsync=function(e,t){var r=this;return void 0===t&&(t=!0),this._generateBinaryAsync().then((function(n){r._extensionsOnExporting();var a,i=r._generateJSON(!0),o=e+".glb",s=i.length,u=0;"undefined"!=typeof TextEncoder&&(s=(a=(new TextEncoder).encode(i)).length);for(var c=0;c<r._orderedImageData.length;++c)u+=r._orderedImageData[c].data.byteLength;var f=r._getPadding(s),h=r._getPadding(n.byteLength),p=r._getPadding(u),d=28+s+f+n.byteLength+h+u+p,_=new ArrayBuffer(12),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 R=new ArrayBuffer(p),w=new Uint8Array(R);for(c=0;c<p;++c)w[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(R);var C=new Blob(V,{type:"application/octet-stream"}),S=new l;return S.glTFFiles[o]=C,null!=r._localEngine&&r._localEngine.dispose(),t&&r.dispose(),S}))},e.prototype._setNodeTransformation=function(e,t,r){t.getPivotPoint().equalsToFloats(0,0,0)||d.Tools.Warn("Pivot points are not supported in the glTF serializer"),t.position.equalsToFloats(0,0,0)||(e.translation=r?g._GetRightHandedPositionVector3(t.position).asArray():t.position.asArray()),t.scaling.equalsToFloats(1,1,1)||(e.scale=t.scaling.asArray());var n=d.Quaternion.RotationYawPitchRoll(t.rotation.y,t.rotation.x,t.rotation.z);t.rotationQuaternion&&n.multiplyInPlace(t.rotationQuaternion),d.Quaternion.IsIdentity(n)||(r&&g._GetRightHandedQuaternionFromRef(n),e.rotation=n.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,r){t.position.equalsToFloats(0,0,0)||(e.translation=r?g._GetRightHandedPositionVector3(t.position).asArray():t.position.asArray());var n=t.rotationQuaternion;n&&!d.Quaternion.IsIdentity(n)&&(r&&g._GetRightHandedQuaternionFromRef(n),e.rotation=n.normalize().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,i){var o=r instanceof d.Mesh?r:r instanceof d.InstancedMesh?r.sourceMesh:null;if(o){var s=o.getVertexBuffer(e,!0),u=o.getVerticesData(e,void 0,void 0,!0);if(s&&u){var l=d.VertexBuffer.GetTypeByteLength(t),c=u.length*l,f=g._CreateBufferView(0,n.getByteOffset(),c,a,e+" - "+o.name);this._bufferViews.push(f),this._writeAttributeData(e,t,u,a/l,n,i,r)}}},e.prototype._setMorphTargetAttributes=function(e,t,r,n,a){if(r){t.targets||(t.targets=[]);var i={},o=e.getMesh();if(r.hasNormals){var s=o.getVerticesData(d.VertexBuffer.NormalKind,void 0,void 0,!0),u=r.getNormals(),l=(x=e.verticesCount)*(y=12),c=g._CreateBufferView(0,n.getByteOffset(),l,y,r.name+"_NORMAL");this._bufferViews.push(c);var f=this._bufferViews.length-1,h=g._CreateAccessor(f,r.name+" - NORMAL","VEC3",5126,x,0,null,null);this._accessors.push(h),i.NORMAL=this._accessors.length-1,this.writeMorphTargetAttributeData(d.VertexBuffer.NormalKind,5126,e,r,s,u,y/4,n,a)}if(r.hasPositions){var p=o.getVerticesData(d.VertexBuffer.PositionKind,void 0,void 0,!0),_=r.getPositions();l=(x=e.verticesCount)*(y=12),c=g._CreateBufferView(0,n.getByteOffset(),l,y,r.name+"_POSITION"),this._bufferViews.push(c),f=this._bufferViews.length-1;var m={min:new d.Vector3(1/0,1/0,1/0),max:new d.Vector3(-1/0,-1/0,-1/0)};h=g._CreateAccessor(f,r.name+" - POSITION","VEC3",5126,x,0,null,null),this._accessors.push(h),i.POSITION=this._accessors.length-1,this.writeMorphTargetAttributeData(d.VertexBuffer.PositionKind,5126,e,r,p,_,y/4,n,a,m),h.min=m.min.asArray(),h.max=m.max.asArray()}if(r.hasTangents){var x,y,T=o.getVerticesData(d.VertexBuffer.TangentKind,void 0,void 0,!0),v=r.getTangents();l=(x=e.verticesCount)*(y=12),c=g._CreateBufferView(0,n.getByteOffset(),l,y,r.name+"_NORMAL"),this._bufferViews.push(c),f=this._bufferViews.length-1,h=g._CreateAccessor(f,r.name+" - TANGENT","VEC3",5126,x,0,null,null),this._accessors.push(h),i.TANGENT=this._accessors.length-1,this.writeMorphTargetAttributeData(d.VertexBuffer.TangentKind,5126,e,r,T,v,y/4,n,a)}t.targets.push(i)}},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,n){var a,i,o,s=[],u=null;t instanceof d.Mesh?u=t:t instanceof d.InstancedMesh&&(u=t.sourceMesh);var l=[{kind:d.VertexBuffer.PositionKind,accessorType:"VEC3",accessorComponentType:5126,byteStride:12},{kind:d.VertexBuffer.NormalKind,accessorType:"VEC3",accessorComponentType:5126,byteStride:12},{kind:d.VertexBuffer.ColorKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:d.VertexBuffer.TangentKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:d.VertexBuffer.UVKind,accessorType:"VEC2",accessorComponentType:5126,byteStride:8},{kind:d.VertexBuffer.UV2Kind,accessorType:"VEC2",accessorComponentType:5126,byteStride:8},{kind:d.VertexBuffer.MatricesIndicesKind,accessorType:"VEC4",accessorComponentType:5123,byteStride:8},{kind:d.VertexBuffer.MatricesIndicesExtraKind,accessorType:"VEC4",accessorComponentType:5123,byteStride:8},{kind:d.VertexBuffer.MatricesWeightsKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:d.VertexBuffer.MatricesWeightsExtraKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16}];if(u){for(var c=null,f=this._getMeshPrimitiveMode(u),h={},p=u.morphTargetManager,_=0,m=l;_<m.length;_++){var x=(W=m[_]).kind,y=W.accessorComponentType;if(u.isVerticesDataPresent(x,!0)){var T=this._getVertexBufferFromMesh(x,u);W.byteStride=T?T.getSize()*d.VertexBuffer.GetTypeByteLength(W.accessorComponentType):4*d.VertexBuffer.DeduceStride(x),12===W.byteStride&&(W.accessorType="VEC3"),this._createBufferViewKind(x,y,t,r,W.byteStride,n),W.bufferViewIndex=this._bufferViews.length-1,h[x]=W.bufferViewIndex}}if(u.getTotalIndices()){var v=u.getIndices();if(v){var b=4*v.length;i=g._CreateBufferView(0,r.getByteOffset(),b,void 0,"Indices - "+u.name),this._bufferViews.push(i),c=this._bufferViews.length-1;for(var A=0,E=v.length;A<E;++A)r.setUInt32(v[A])}}if(u.subMeshes)for(var M=0,F=u.subMeshes;M<F.length;M++){var R=F[M],w=R.getMaterial()||u.getScene().defaultMaterial,V=null;if(w)if(u instanceof d.LinesMesh){var C={name:u.name+" material"};(!u.color.equals(d.Color3.White())||u.alpha<1)&&(C.pbrMetallicRoughness={baseColorFactor:u.color.asArray().concat([u.alpha])}),this._materials.push(C),V=this._materials.length-1}else if(w instanceof d.MultiMaterial){var S=w.subMaterials[R.materialIndex];S&&(w=S,V=this._materialMap[w.uniqueId])}else V=this._materialMap[w.uniqueId];var I=null!=V?this._materials[V]:null,B={attributes:{}};this._setPrimitiveMode(B,f);for(var P=0,N=l;P<N.length;P++)if(((x=(W=N[P]).kind)!==d.VertexBuffer.UVKind&&x!==d.VertexBuffer.UV2Kind||this._options.exportUnusedUVs||I&&this._glTFMaterialExporter._hasTexturesPresent(I))&&(z=u.getVerticesData(x,void 0,void 0,!0))&&(T=this._getVertexBufferFromMesh(x,u))){var O=T.getSize(),L=W.bufferViewIndex;if(null!=L){o={min:null,max:null},x==d.VertexBuffer.PositionKind&&(o=g._CalculateMinMaxPositions(z,0,z.length/O,n));var k=g._CreateAccessor(L,x+" - "+t.name,W.accessorType,W.accessorComponentType,z.length/O,0,o.min,o.max);this._accessors.push(k),this._setAttributeKind(B,x)}}if(c&&(k=g._CreateAccessor(c,"indices - "+t.name,"SCALAR",5125,R.indexCount,4*R.indexStart,null,null),this._accessors.push(k),B.indices=this._accessors.length-1),null!=V&&Object.keys(B.attributes).length>0){var U=null!==u.overrideMaterialSideOrientation?u.overrideMaterialSideOrientation:w.sideOrientation;if(U==d.Material.ClockWiseSideOrientation&&this._babylonScene.useRightHandedSystem||U==d.Material.ClockWiseSideOrientation&&n&&u.overrideMaterialSideOrientation!==(null===(a=u.material)||void 0===a?void 0:a.sideOrientation)){var K=null!=c?this._bufferViews[c].byteOffset:null;null==K&&(K=0);var G=null;if(null!=c&&(G=u.getIndices()),G)this._reorderIndicesBasedOnPrimitiveMode(R,f,G,K,r);else for(var D=0,H=l;D<H.length;D++){var z,W=H[D];if(z=u.getVerticesData(W.kind,void 0,void 0,!0)){var q=this._bufferViews[h[W.kind]].byteOffset;q||(q=0),this._reorderVertexAttributeDataBasedOnPrimitiveMode(R,f,U,W.kind,z,q,r,n)}}}B.material=V}if(p)for(var Q=void 0,j=0;j<p.numTargets;++j)Q=p.getTarget(j),this._setMorphTargetAttributes(R,B,Q,r,n);e.primitives.push(B),this._extensionsPostExportMeshPrimitiveAsync("postExport",B,R,r),s.push()}}return Promise.all(s).then((function(){}))},e.prototype._isBabylonCoordinateSystemConvertingNode=function(e){return e instanceof d.TransformNode&&!!e.getWorldMatrix().multiplyToRef(x,d.TmpVectors.Matrix[0]).isIdentity()&&!(e instanceof d.Mesh&&null!==e.geometry||e instanceof d.InstancedMesh&&null!==e.sourceMesh.geometry)},e.prototype._createSceneAsync=function(e,t){var r,n,a,i=this,o={nodes:[]},s=h(h(h(h([],e.transformNodes,!0),e.meshes,!0),e.lights,!0),e.cameras,!0),u=[];this._convertToRightHandedSystem=!e.useRightHandedSystem,this._convertToRightHandedSystemMap={},e.metadata&&(this._options.metadataSelector?o.extras=this._options.metadataSelector(e.metadata):e.metadata.gltf&&(o.extras=e.metadata.gltf.extras)),e.rootNodes.forEach((function(e){i._convertToRightHandedSystemMap[e.uniqueId]=i._convertToRightHandedSystem,e.getDescendants(!1).forEach((function(e){i._convertToRightHandedSystemMap[e.uniqueId]=i._convertToRightHandedSystem}))})),e.rootNodes.forEach((function(e){if(!i._includeCoordinateSystemConversionNodes&&i._isBabylonCoordinateSystemConvertingNode(e)){u.push(e);var t=s.indexOf(e);-1!==t&&s.splice(t,1),e.getDescendants(!1).forEach((function(e){i._convertToRightHandedSystemMap[e.uniqueId]=!1}))}}));var l=new Map;e.cameras.forEach((function(e){if(!i._options.shouldExportNode||i._options.shouldExportNode(e)){var t={type:e.mode===d.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(e.name&&(t.name=e.name),"perspective"===t.type)t.perspective={aspectRatio:e.getEngine().getAspectRatio(e),yfov:e.fovMode===d.Camera.FOVMODE_VERTICAL_FIXED?e.fov:e.fov*e.getEngine().getAspectRatio(e),znear:e.minZ,zfar:e.maxZ};else if("orthographic"===t.type){var r=e.orthoLeft&&e.orthoRight?.5*(e.orthoRight-e.orthoLeft):.5*e.getEngine().getRenderWidth(),n=e.orthoBottom&&e.orthoTop?.5*(e.orthoTop-e.orthoBottom):.5*e.getEngine().getRenderHeight();t.orthographic={xmag:r,ymag:n,znear:e.minZ,zfar:e.maxZ}}l.set(e,i._cameras.length),i._cameras.push(t)}}));var c=this._getExportNodes(s),f=c[0],p=c[1];return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(p,"image/png",!0).then((function(){return i._createNodeMapAndAnimationsAsync(e,f,t).then((function(c){return i._createSkinsAsync(e,c,t).then((function(e){if(i._nodeMap=c,i._totalByteLength=t.getByteOffset(),null==i._totalByteLength)throw new Error("undefined byte length!");for(var f=0,h=s;f<h.length;f++){var p=h[f];if(void 0!==(r=i._nodeMap[p.uniqueId])){if(n=i._nodes[r],p.metadata&&(i._options.metadataSelector?n.extras=i._options.metadataSelector(p.metadata):p.metadata.gltf&&(n.extras=p.metadata.gltf.extras)),p instanceof d.Camera&&(n.camera=l.get(p)),p.parent&&-1===u.indexOf(p.parent)||(i._options.shouldExportNode&&!i._options.shouldExportNode(p)?d.Tools.Log("Omitting "+p.name+" from scene."):(i._convertToRightHandedSystemMap[p.uniqueId]&&(n.translation&&(n.translation[2]*=-1,n.translation[0]*=-1),n.rotation=n.rotation?d.Quaternion.FromArray([0,1,0,0]).multiply(d.Quaternion.FromArray(n.rotation)).asArray():d.Quaternion.FromArray([0,1,0,0]).asArray()),o.nodes.push(r))),p instanceof d.Mesh){var _=p;_.skeleton&&(n.skin=e[_.skeleton.uniqueId])}if(a=p.getDescendants(!0),!n.children&&a&&a.length){for(var g=[],m=0,x=a;m<x.length;m++){var y=x[m];null!=i._nodeMap[y.uniqueId]&&g.push(i._nodeMap[y.uniqueId])}g.length&&(n.children=g)}}}o.nodes.length&&i._scenes.push(o)}))}))}))},e.prototype._getExportNodes=function(e){for(var t=[],r=new Set,n=0,a=e;n<a.length;n++){var i=a[n];if(!this._options.shouldExportNode||this._options.shouldExportNode(i)){t.push(i);var o=i;if(o.subMeshes&&o.subMeshes.length>0){var s=o.material||o.getScene().defaultMaterial;if(s instanceof d.MultiMaterial)for(var u=0,l=s.subMaterials;u<l.length;u++){var c=l[u];c&&r.add(c)}else r.add(s)}}else"Excluding node ".concat(i.name)}return[t,r]},e.prototype._createNodeMapAndAnimationsAsync=function(e,t,r){for(var n,a=this,i=Promise.resolve(),o={},s={name:"runtime animations",channels:[],samplers:[]},u=[],l=function(t){i=i.then((function(){var i=a._convertToRightHandedSystemMap[t.uniqueId];return a._createNodeAsync(t,r,i).then((function(l){var c=a._extensionsPostExportNodeAsync("createNodeAsync",l,t,o,r);return null==c?(d.Tools.Warn("Not exporting node ".concat(t.name)),Promise.resolve()):c.then((function(l){l&&(a._nodes.push(l),n=a._nodes.length-1,o[t.uniqueId]=n,e.animationGroups.length||(m._CreateMorphTargetAnimationFromMorphTargetAnimations(t,s,u,o,a._nodes,r,a._bufferViews,a._accessors,i,a._animationSampleRate,a._options.shouldExportAnimation),t.animations.length&&m._CreateNodeAnimationFromNodeAnimations(t,s,u,o,a._nodes,r,a._bufferViews,a._accessors,i,a._animationSampleRate,a._options.shouldExportAnimation)))}))}))}))},c=0,f=t;c<f.length;c++)l(f[c]);return i.then((function(){return s.channels.length&&s.samplers.length&&a._animations.push(s),u.forEach((function(e){e.channels.length&&e.samplers.length&&a._animations.push(e)})),e.animationGroups.length&&m._CreateNodeAndMorphAnimationFromAnimationGroups(e,a._animations,o,a._nodes,r,a._bufferViews,a._accessors,a._convertToRightHandedSystemMap,a._animationSampleRate,a._options.shouldExportAnimation),o}))},e.prototype._createNodeAsync=function(e,t,r){var n=this;return Promise.resolve().then((function(){var a={},i={primitives:[]};if(e.name&&(a.name=e.name),e instanceof d.TransformNode){if(n._setNodeTransformation(a,e,r),e instanceof d.Mesh){var o=e.morphTargetManager;if(o&&o.numTargets>0){i.weights=[];for(var s=0;s<o.numTargets;++s)i.weights.push(o.getTarget(s).influence)}}return n._setPrimitiveAttributesAsync(i,e,t,r).then((function(){return i.primitives.length&&(n._meshes.push(i),a.mesh=n._meshes.length-1),a}))}return e instanceof d.Camera?(n._setCameraTransformation(a,e,r),a):a}))},e.prototype._createSkinsAsync=function(e,t,r){for(var n,a=Promise.resolve(),i={},o=0,s=e.skeletons;o<s.length;o++){var u=s[o];if(!(u.bones.length<=0)){for(var l={joints:[]},c=[],f={},h=-1,p=0;p<u.bones.length;++p)-1!==(_=null!==(n=(m=u.bones[p]).getIndex())&&void 0!==n?n:p)&&(f[_]=m,_>h&&(h=_));for(var _=0;_<=h;++_){var m=f[_];c.push(m.getInvertedAbsoluteTransform());var x=m.getTransformNode();x&&null!==t[x.uniqueId]&&void 0!==t[x.uniqueId]?l.joints.push(t[x.uniqueId]):d.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}if(l.joints.length>0){var y=64*c.length,T=r.getByteOffset(),v=g._CreateBufferView(0,T,y,void 0,"InverseBindMatrices - "+u.name);this._bufferViews.push(v);var b=this._bufferViews.length-1,A=g._CreateAccessor(b,"InverseBindMatrices - "+u.name,"MAT4",5126,c.length,null,null,null),E=this._accessors.push(A)-1;l.inverseBindMatrices=E,this._skins.push(l),i[u.uniqueId]=this._skins.length-1,c.forEach((function(e){e.m.forEach((function(e){r.setFloat32(e)}))}))}}}return a.then((function(){return i}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),T=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}(),v=function(){function e(){}return e.GLTFAsync=function(e,t,r){return e.whenReadyAsync().then((function(){var n=t.replace(/\.[^/.]+$/,"");return new y(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 y(e,r)._generateGLBAsync(a).then((function(t){return n._PostExportAsync(e,t,r)}))}))},e}(),b="KHR_texture_transform",A=function(){function e(){this.name=b,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.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[b]=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(b)),r(null)):n("".concat(e,': "scene" is not defined for Babylon texture ').concat(t.name,"!"))}))},e}();y.RegisterExtension(b,(function(){return new A}));var E="KHR_lights_punctual",M=function(){function e(e){this.name=E,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[E]=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,n){var a=this;return new Promise((function(i){if(t&&r instanceof d.ShadowLight){var o=r,s=void 0,u=o.getTypeID()==d.Light.LIGHTTYPEID_POINTLIGHT?"point":o.getTypeID()==d.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":o.getTypeID()==d.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(null==u)d.Logger.Warn("".concat(e,": Light ").concat(o.name," is not supported in ").concat(E));else{var l=o.position.clone(),c=a._exporter._convertToRightHandedSystemMap[r.uniqueId];if(l.equals(d.Vector3.Zero())||(c&&g._GetRightHandedPositionVector3FromRef(l),t.translation=l.asArray()),"point"!==u){var f=o.direction,h=-Math.atan2(f.z*(a._exporter._babylonScene.useRightHandedSystem?-1:1),f.x)+Math.PI/2,p=Math.sqrt(f.x*f.x+f.z*f.z),_=-Math.atan2(f.y,p),m=d.Quaternion.RotationYawPitchRoll(h,_,0);c&&g._GetRightHandedQuaternionFromRef(m),m.equals(d.Quaternion.Identity())||(t.rotation=m.asArray())}if(o.falloffType!==d.Light.FALLOFF_GLTF&&d.Logger.Warn("".concat(e,": Light falloff for ").concat(o.name," does not match the ").concat(E," specification!")),s={type:u},o.diffuse.equals(d.Color3.White())||(s.color=o.diffuse.asArray()),1!==o.intensity&&(s.intensity=o.intensity),o.range!==Number.MAX_VALUE&&(s.range=o.range),"spot"===u){var x=o;x.angle!==Math.PI/2&&(null==s.spot&&(s.spot={}),s.spot.outerConeAngle=x.angle/2),0!==x.innerAngle&&(null==s.spot&&(s.spot={}),s.spot.innerConeAngle=x.innerAngle/2)}null==a._lights&&(a._lights={lights:[]}),a._lights.lights.push(s);var y={light:a._lights.lights.length-1},T=r.parent;if(T&&1==T.getChildren().length){var v=a._exporter._nodes[n[T.uniqueId]];if(v){var b=d.TmpVectors.Matrix[0],A=d.TmpVectors.Matrix[1],M=v.translation?new d.Vector3(v.translation[0],v.translation[1],v.translation[2]):d.Vector3.Zero(),F=v.rotation?new d.Quaternion(v.rotation[0],v.rotation[1],v.rotation[2],v.rotation[3]):d.Quaternion.Identity(),R=v.scale?new d.Vector3(v.scale[0],v.scale[1],v.scale[2]):d.Vector3.One();d.Matrix.ComposeToRef(R,F,M,b),b.invertToRef(A);var w=d.TmpVectors.Matrix[2],V=t.translation?new d.Vector3(t.translation[0],t.translation[1],t.translation[2]):d.Vector3.Zero();o instanceof d.DirectionalLight&&V.subtractInPlace(a._exporter._babylonScene.useRightHandedSystem?o.direction:g._GetRightHandedPositionVector3(o.direction));var C=a._exporter._babylonScene.useRightHandedSystem?d.Quaternion.Identity():new d.Quaternion(0,1,0,0);t.rotation&&C.multiplyInPlace(new d.Quaternion(t.rotation[0],t.rotation[1],t.rotation[2],t.rotation[3]));var S=t.scale?new d.Vector3(t.scale[0],t.scale[1],t.scale[2]):d.Vector3.One();d.Matrix.ComposeToRef(S,C,V,w),w.multiplyToRef(A,w);var I=d.TmpVectors.Vector3[0],B=d.TmpVectors.Quaternion[0],P=d.TmpVectors.Vector3[1];return w.decompose(I,B,P),v.scale=I.asArray(),v.rotation=B.asArray(),v.translation=P.asArray(),null==v.extensions&&(v.extensions={}),v.extensions[E]=y,void i(null)}}null==t.extensions&&(t.extensions={}),t.extensions[E]=y}}i(t)}))},e}();y.RegisterExtension(E,(function(e){return new M(e)}));var F="KHR_materials_clearcoat",R=function(){function e(e){this.name=F,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof d.PBRBaseMaterial&&r.clearCoat.isEnabled?(r.clearCoat.texture&&n.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&n.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&n.push(r.clearCoat.bumpTexture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof d.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var a,i=n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.texture);a=r.clearCoat.useRoughnessFromMainTexture?n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.texture):n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&d.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),r.clearCoat.remapF0OnInterfaceChange&&d.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(r.name));var o=n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.bumpTexture),s={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=i?i:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=a?a:void 0,clearcoatNormalTexture:null!=o?o:void 0,hasTextures:function(){return null!==s.clearcoatTexture||null!==s.clearcoatRoughnessTexture||null!==s.clearcoatRoughnessTexture}};t.extensions[F]=s}e(t)}))},e}();y.RegisterExtension(F,(function(e){return new R(e)}));var w="KHR_materials_iridescence",V=function(){function e(e){this.name=w,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[w]=o}e(t)}))},e}();y.RegisterExtension(w,(function(e){return new V(e)}));var C="KHR_materials_anisotropy",S=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.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[C]=i}e(t)}))},e}();y.RegisterExtension(C,(function(e){return new S(e)}));var I="KHR_materials_sheen",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){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[I]=u}e(t)}))},e}();y.RegisterExtension(I,(function(e){return new B(e)}));var P="KHR_materials_unlit",N=function(){function e(){this.name=P,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[P]={}),e(t)}))},e}();y.RegisterExtension(P,(function(){return new N}));var O="KHR_materials_ior",L=function(){function e(){this.name=O,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[O]=a}e(t)}))},e}();y.RegisterExtension(O,(function(e){return new L}));var k="KHR_materials_specular",U=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}();y.RegisterExtension(k,(function(e){return new U(e)}));var K="KHR_materials_volume",G=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.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[K]=o}e(t)}))},e}();y.RegisterExtension(K,(function(e){return new G(e)}));var D="KHR_materials_transmission",H=function(){function e(e){this.name=D,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[D]=o}e(t)}))},e}();y.RegisterExtension(D,(function(e){return new H(e)}));var z="EXT_mesh_gpu_instancing",W=function(){function e(e){this.name=z,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[z]=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}();y.RegisterExtension(z,(function(e){return new W(e)}));var q="KHR_materials_emissive_strength",Q=function(){function e(){this.name=q,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[q]=o}return e(t)}))},e}();y.RegisterExtension(q,(function(e){return new Q}));var j=0,Y=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==Y){Y.BABYLON=Y.BABYLON||{};var X=Y.BABYLON;X.GLTF2=X.GLTF2||{},X.GLTF2.Exporter=X.GLTF2.Exporter||{},X.GLTF2.Exporter.Extensions=X.GLTF2.Exporter.Extensions||{};var Z=[];for(var J in e)X[J]=e[J],Z.push(J);for(var J in t)X[J]=t[J],Z.push(J);for(var J in r)X[J]=r[J],Z.push(J);for(var J in i)X.GLTF2.Exporter.Extensions[J]=i[J],Z.push(J);for(var J in o)Z.indexOf(J)>-1||(X.GLTF2.Exporter[J]=o[J])}const $=s})(),a.default})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.SERIALIZERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(e=>(()=>{"use strict";var t={520:t=>{t.exports=e}},r={};function n(e){var a=r[e];if(void 0!==a)return a.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return(()=>{n.d(a,{default:()=>ee});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:()=>b});var i={};n.r(i),n.d(i,{EXT_mesh_gpu_instancing:()=>H,KHR_lights_punctual:()=>F,KHR_materials_anisotropy:()=>I,KHR_materials_clearcoat:()=>C,KHR_materials_emissive_strength:()=>Q,KHR_materials_ior:()=>k,KHR_materials_iridescence:()=>R,KHR_materials_sheen:()=>P,KHR_materials_specular:()=>K,KHR_materials_transmission:()=>z,KHR_materials_unlit:()=>L,KHR_materials_volume:()=>G,KHR_texture_transform:()=>E});var o={};n.r(o),n.d(o,{EXT_mesh_gpu_instancing:()=>H,GLTF2Export:()=>b,GLTFData:()=>l,KHR_lights_punctual:()=>F,KHR_materials_anisotropy:()=>I,KHR_materials_clearcoat:()=>C,KHR_materials_emissive_strength:()=>Q,KHR_materials_ior:()=>k,KHR_materials_iridescence:()=>R,KHR_materials_sheen:()=>P,KHR_materials_specular:()=>K,KHR_materials_transmission:()=>z,KHR_materials_unlit:()=>L,KHR_materials_volume:()=>G,KHR_texture_transform:()=>E,_BinaryWriter:()=>v,_Exporter:()=>T,_GLTFAnimation:()=>m,_GLTFMaterialExporter:()=>_,_GLTFUtilities:()=>g,__IGLTFExporterExtensionV2:()=>Y});var s={};n.r(s),n.d(s,{EXT_mesh_gpu_instancing:()=>H,GLTF2Export:()=>b,GLTFData:()=>l,KHR_lights_punctual:()=>F,KHR_materials_anisotropy:()=>I,KHR_materials_clearcoat:()=>C,KHR_materials_emissive_strength:()=>Q,KHR_materials_ior:()=>k,KHR_materials_iridescence:()=>R,KHR_materials_sheen:()=>P,KHR_materials_specular:()=>K,KHR_materials_transmission:()=>z,KHR_materials_unlit:()=>L,KHR_materials_volume:()=>G,KHR_texture_transform:()=>E,_BinaryWriter:()=>v,_Exporter:()=>T,_GLTFAnimation:()=>m,_GLTFMaterialExporter:()=>_,_GLTFUtilities:()=>g,__IGLTFExporterExtension:()=>u,__IGLTFExporterExtensionV2:()=>Y});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;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,L,O,k;return f(this,(function(f){switch(f.label){case 0:return o=new Array,t||r?(s=t?t.getScene():r?r.getScene():null)?(u=this._resizeTexturesToSameDimensions(t,r,s),l=null===(i=u.texture1)||void 0===i?void 0:i.getSize(),c=void 0,h=void 0,p=l.width,_=l.height,[4,u.texture1.readPixels()]):[3,3]:[2,Promise.reject("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!")];case 1:return 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,L=d.Color3.FromInts(T[N],T[N+1],T[N+2]),O=L.toGammaSpace(s.getEngine().useExactSrgbConversions),T[N]=255*O.r,T[N+1]=255*O.g,T[N+2]=255*O.b,e._FuzzyEquals(O,d.Color3.White(),e._Epsilon)||(I=!0),y[N+1]/=R.roughness>e._Epsilon?R.roughness:1,y[N+2]/=R.metallic>e._Epsilon?R.metallic:1,k=d.Color3.FromInts(255,y[N+1],y[N+2]),e._FuzzyEquals(k,d.Color3.White(),e._Epsilon)||(S=!0);return S&&o.push(this._getImageDataAsync(y,p,_,a).then((function(e){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());function y(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 T=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 v(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.RotationYawPitchRoll(t.rotation.y,t.rotation.x,t.rotation.z);t.rotationQuaternion&&r.multiplyInPlace(t.rotationQuaternion),d.Quaternion.IsIdentity(r)||(e.rotation=r.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t){t.position.equalsToFloats(0,0,0)||(e.translation=t.position.asArray());var r=t.rotationQuaternion;r&&!d.Quaternion.IsIdentity(r)&&(e.rotation=r.normalize().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 L=g._CreateAccessor(N,_+" - "+t.name,G.accessorType,G.accessorComponentType,D.length/P,0,a.min,a.max);this._accessors.push(L),this._setAttributeKind(S,_)}}if(u&&(L=g._CreateAccessor(u,"indices - "+t.name,"SCALAR",5125,M.indexCount,4*M.indexStart,null,null),this._accessors.push(L),S.indices=this._accessors.length-1),null!=w&&Object.keys(S.attributes).length>0){if((null!==o.overrideMaterialSideOrientation?o.overrideMaterialSideOrientation:F.sideOrientation)===(this._babylonScene.useRightHandedSystem?d.Material.ClockWiseSideOrientation:d.Material.CounterClockWiseSideOrientation)){var O=null!=u?this._bufferViews[u].byteOffset:null;null==O&&(O=0);var k=null;if(null!=u&&(k=o.getIndices()),k)this._reorderIndicesBasedOnPrimitiveMode(M,l,k,O,r);else for(var U=0,K=s;U<K.length;U++){var D,G=K[U];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)}}}S.material=w}if(f)for(var z=void 0,q=0;q<f.numTargets;++q)z=f.getTarget(q),this._setMorphTargetAttributes(M,S,z,r);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=this,o={nodes:[]},s=h(h(h(h([],this._babylonScene.transformNodes,!0),this._babylonScene.meshes,!0),this._babylonScene.lights,!0),this._babylonScene.cameras,!0),u=new Set;if(this._babylonScene.metadata&&(this._options.metadataSelector?o.extras=this._options.metadataSelector(this._babylonScene.metadata):this._babylonScene.metadata.gltf&&(o.extras=this._babylonScene.metadata.gltf.extras)),(null===(t=this._options.removeNoopRootNodes)||void 0===t||t)&&!this._options.includeCoordinateSystemConversionNodes)for(var l=0,c=this._babylonScene.rootNodes;l<c.length;l++){var f=c[l];y(f,this._babylonScene.useRightHandedSystem)&&(u.add(f),s.splice(s.indexOf(f),1))}var p=new Map;this._babylonScene.cameras.forEach((function(e){if(!i._options.shouldExportNode||i._options.shouldExportNode(e)){var t={type:e.mode===d.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(e.name&&(t.name=e.name),"perspective"===t.type)t.perspective={aspectRatio:e.getEngine().getAspectRatio(e),yfov:e.fovMode===d.Camera.FOVMODE_VERTICAL_FIXED?e.fov:e.fov*e.getEngine().getAspectRatio(e),znear:e.minZ,zfar:e.maxZ};else if("orthographic"===t.type){var r=e.orthoLeft&&e.orthoRight?.5*(e.orthoRight-e.orthoLeft):.5*e.getEngine().getRenderWidth(),n=e.orthoBottom&&e.orthoTop?.5*(e.orthoTop-e.orthoBottom):.5*e.getEngine().getRenderHeight();t.orthographic={xmag:r,ymag:n,znear:e.minZ,zfar:e.maxZ}}p.set(e,i._cameras.length),i._cameras.push(t)}}));var _=this._getExportNodes(s),g=_[0],m=_[1];return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(m,"image/png",!0).then((function(){return i._createNodeMapAndAnimationsAsync(g,e).then((function(t){return i._createSkinsAsync(t,e).then((function(l){if(i._nodeMap=t,i._totalByteLength=e.getByteOffset(),null==i._totalByteLength)throw new Error("undefined byte length!");for(var c=0,f=s;c<f.length;c++){var h=f[c];if(void 0!==(r=i._nodeMap[h.uniqueId])&&(n=i._nodes[r],h.metadata&&(i._options.metadataSelector?n.extras=i._options.metadataSelector(h.metadata):h.metadata.gltf&&(n.extras=h.metadata.gltf.extras)),h instanceof d.Camera&&(n.camera=p.get(h)),i._options.shouldExportNode&&!i._options.shouldExportNode(h)?d.Tools.Log("Omitting "+h.name+" from scene."):(h.parent||i._babylonScene.useRightHandedSystem||(T=n,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&&!u.has(h.parent)||o.nodes.push(r)),h instanceof d.Mesh&&h.skeleton&&(n.skin=l[h.skeleton.uniqueId]),a=h.getDescendants(!0),!n.children&&a&&a.length)){for(var _=[],g=0,m=a;g<m.length;g++){var y=m[g];null!=i._nodeMap[y.uniqueId]&&_.push(i._nodeMap[y.uniqueId])}_.length&&(n.children=_)}}var T,v,b,A;o.nodes.length&&i._scenes.push(o)}))}))}))},e.prototype._getExportNodes=function(e){for(var t=[],r=new Set,n=0,a=e;n<a.length;n++){var i=a[n];if(!this._options.shouldExportNode||this._options.shouldExportNode(i)){t.push(i);var o=i;if(o.subMeshes&&o.subMeshes.length>0){var s=o.material||o.getScene().defaultMaterial;if(s instanceof d.MultiMaterial)for(var u=0,l=s.subMaterials;u<l.length;u++){var c=l[u];c&&r.add(c)}else r.add(s)}}else"Excluding node ".concat(i.name)}return[t,r]},e.prototype._createNodeMapAndAnimationsAsync=function(e,t){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}(),v=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}(),b=function(){function e(){}return e.GLTFAsync=function(e,t,r){return e.whenReadyAsync().then((function(){var n=t.replace(/\.[^/.]+$/,"");return new T(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 T(e,r)._generateGLBAsync(a).then((function(t){return n._PostExportAsync(e,t,r)}))}))},e}(),A="KHR_texture_transform",E=function(){function e(){this.name=A,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[A]=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(A)),r(null)):n("".concat(e,': "scene" is not defined for Babylon texture ').concat(t.name,"!"))}))},e}();T.RegisterExtension(A,(function(){return new E}));var M="KHR_lights_punctual",F=function(){function e(e){this.name=M,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[M]=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(M));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(M," 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[M]=_,void i(null)}}t.extensions||(t.extensions={}),t.extensions[M]=_}}i(t)}))},e}();T.RegisterExtension(M,(function(e){return new F(e)}));var w="KHR_materials_clearcoat",C=function(){function e(e){this.name=w,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[w]=s}e(t)}))},e}();T.RegisterExtension(w,(function(e){return new C(e)}));var V="KHR_materials_iridescence",R=function(){function e(e){this.name=V,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){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[V]=o}e(t)}))},e}();T.RegisterExtension(V,(function(e){return new R(e)}));var S="KHR_materials_anisotropy",I=function(){function e(e){this.name=S,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[S]=i}e(t)}))},e}();T.RegisterExtension(S,(function(e){return new I(e)}));var B="KHR_materials_sheen",P=function(){function e(e){this.name=B,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[B]=u}e(t)}))},e}();T.RegisterExtension(B,(function(e){return new P(e)}));var N="KHR_materials_unlit",L=function(){function e(){this.name=N,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[N]={}),e(t)}))},e}();T.RegisterExtension(N,(function(){return new L}));var O="KHR_materials_ior",k=function(){function e(){this.name=O,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[O]=a}e(t)}))},e}();T.RegisterExtension(O,(function(e){return new k}));var U="KHR_materials_specular",K=function(){function e(e){this.name=U,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof d.PBRMaterial&&this._isExtensionEnabled(r)?(r.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[U]=u}e(t)}))},e}();T.RegisterExtension(U,(function(e){return new K(e)}));var D="KHR_materials_volume",G=function(){function e(e){this.name=D,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[D]=o}e(t)}))},e}();T.RegisterExtension(D,(function(e){return new G(e)}));var W="KHR_materials_transmission",z=function(){function e(e){this.name=W,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[W]=o}e(t)}))},e}();T.RegisterExtension(W,(function(e){return new z(e)}));var q="EXT_mesh_gpu_instancing",H=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}();T.RegisterExtension(q,(function(e){return new H(e)}));var j="KHR_materials_emissive_strength",Q=function(){function e(){this.name=j,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[j]=o}return e(t)}))},e}();T.RegisterExtension(j,(function(e){return new Q}));var Y=0,X=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==X){X.BABYLON=X.BABYLON||{};var Z=X.BABYLON;Z.GLTF2=Z.GLTF2||{},Z.GLTF2.Exporter=Z.GLTF2.Exporter||{},Z.GLTF2.Exporter.Extensions=Z.GLTF2.Exporter.Extensions||{};var J=[];for(var $ in e)Z[$]=e[$],J.push($);for(var $ in t)Z[$]=t[$],J.push($);for(var $ in r)Z[$]=r[$],J.push($);for(var $ in i)Z.GLTF2.Exporter.Extensions[$]=i[$],J.push($);for(var $ in o)J.indexOf($)>-1||(Z.GLTF2.Exporter[$]=o[$])}const ee=s})(),a.default})()));
2
2
  //# sourceMappingURL=babylon.glTF2Serializer.min.js.map