@aladas-org/cryptoshape
Version:
Generates a representation of a Bip39 seed phrase as a 3D scene
1 lines • 90.2 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.SERIALIZERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(e=>(()=>{"use strict";var t={597:t=>{t.exports=e}},r={};function n(e){var i=r[e];if(void 0!==i)return i.exports;var o=r[e]={exports:{}};return t[e](o,o.exports,n),o.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 i={};n.d(i,{default:()=>le});var o={};n.r(o),n.d(o,{__IGLTFExporterExtension:()=>f});var a={};n.r(a),n.d(a,{GLTFData:()=>h});var s={};n.r(s),n.d(s,{GLTF2Export:()=>w});var u={};n.r(u),n.d(u,{EXT_mesh_gpu_instancing:()=>$,KHR_lights_punctual:()=>S,KHR_materials_anisotropy:()=>O,KHR_materials_clearcoat:()=>B,KHR_materials_diffuse_transmission:()=>ne,KHR_materials_dispersion:()=>Y,KHR_materials_emissive_strength:()=>te,KHR_materials_ior:()=>z,KHR_materials_iridescence:()=>N,KHR_materials_sheen:()=>k,KHR_materials_specular:()=>q,KHR_materials_transmission:()=>Z,KHR_materials_unlit:()=>D,KHR_materials_volume:()=>j,KHR_texture_transform:()=>C});var l={};n.r(l),n.d(l,{EXT_mesh_gpu_instancing:()=>$,GLTF2Export:()=>w,GLTFData:()=>h,KHR_lights_punctual:()=>S,KHR_materials_anisotropy:()=>O,KHR_materials_clearcoat:()=>B,KHR_materials_diffuse_transmission:()=>ne,KHR_materials_dispersion:()=>Y,KHR_materials_emissive_strength:()=>te,KHR_materials_ior:()=>z,KHR_materials_iridescence:()=>N,KHR_materials_sheen:()=>k,KHR_materials_specular:()=>q,KHR_materials_transmission:()=>Z,KHR_materials_unlit:()=>D,KHR_materials_volume:()=>j,KHR_texture_transform:()=>C,_BinaryWriter:()=>F,_Exporter:()=>M,_GLTFAnimation:()=>T,_GLTFMaterialExporter:()=>x,_GLTFUtilities:()=>y,__IGLTFExporterExtensionV2:()=>ie});var c={};n.r(c),n.d(c,{EXT_mesh_gpu_instancing:()=>$,GLTF2Export:()=>w,GLTFData:()=>h,KHR_lights_punctual:()=>S,KHR_materials_anisotropy:()=>O,KHR_materials_clearcoat:()=>B,KHR_materials_diffuse_transmission:()=>ne,KHR_materials_dispersion:()=>Y,KHR_materials_emissive_strength:()=>te,KHR_materials_ior:()=>z,KHR_materials_iridescence:()=>N,KHR_materials_sheen:()=>k,KHR_materials_specular:()=>q,KHR_materials_transmission:()=>Z,KHR_materials_unlit:()=>D,KHR_materials_volume:()=>j,KHR_texture_transform:()=>C,_BinaryWriter:()=>F,_Exporter:()=>M,_GLTFAnimation:()=>T,_GLTFMaterialExporter:()=>x,_GLTFUtilities:()=>y,__IGLTFExporterExtension:()=>f,__IGLTFExporterExtensionV2:()=>ie});var f=0,h=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],i=void 0;e(t,".glb")?i={type:"model/gltf-binary"}:e(t,".bin")?i={type:"application/octet-stream"}:e(t,".gltf")?i={type:"model/gltf+json"}:e(t,".jpeg")||e(t,".jpg")?i={type:"image/jpeg"}:e(t,".png")&&(i={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([n],i)),r.click()}},e}();function p(e,t,r,n){return new(r||(r=Promise))((function(i,o){function a(e){try{u(n.next(e))}catch(e){o(e)}}function s(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))}function d(e,t){var r,n,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(o=0)),o;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=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(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function _(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var g,m=n(597),x=function(){function e(e){this._textureMap={},this._internalTextureToImage={},this._textureMap={},this._exporter=e}return e._FuzzyEquals=function(e,t,r){return m.Scalar.WithinEpsilon(e.r,t.r,r)&&m.Scalar.WithinEpsilon(e.g,t.g,r)&&m.Scalar.WithinEpsilon(e.b,t.b,r)},e.prototype._convertMaterialsToGLTFAsync=function(e,t,r){var n=this,i=[];return e.forEach((function(e){"StandardMaterial"===e.getClassName()?i.push(n._convertStandardMaterialAsync(e,t,r)):-1!==e.getClassName().indexOf("PBR")?i.push(n._convertPBRMaterialAsync(e,t,r)):m.Tools.Warn("Unsupported material type: ".concat(e.name))})),Promise.all(i).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 i=e.extensions[n];if(i)return null===(t=i.hasTextures)||void 0===t?void 0:t.call(i)}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,i,o,a,s,u=new m.Vector2(0,1),l=new m.Vector2(0,.1),c=new m.Vector2(0,.1),f=new m.Vector2(1300,.1),h=t.diffuseColor.toLinearSpace(t.getScene().getEngine().useExactSrgbConversions).scale(.5),p=t.alpha,d=(r=m.Scalar.Clamp(t.specularPower,0,e._MaxSpecularPower),n=Math.pow(r/f.x,.333333),i=u.y,o=l.y,a=c.y,s=f.y,(1-n)*(1-n)*(1-n)*i+3*(1-n)*(1-n)*n*o+3*(1-n)*n*n*a+n*n*n*s);return{baseColorFactor:[h.r,h.g,h.b,p],metallicFactor:0,roughnessFactor:d}},e._SolveMetallic=function(e,t,r){if(t<this._DielectricSpecular.r)return this._DielectricSpecular,0;var n=this._DielectricSpecular.r,i=e*r/(1-this._DielectricSpecular.r)+t-2*this._DielectricSpecular.r,o=i*i-4*n*(this._DielectricSpecular.r-t);return m.Scalar.Clamp((-i+Math.sqrt(o))/(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 i=this._exporter._materialMap,o=this._exporter._materials,a=[],s=this._convertToGLTFPBRMetallicRoughness(t),u={name:t.name};if(null==t.backFaceCulling||t.backFaceCulling||(t.twoSidedLighting||m.Tools.Warn(t.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),u.doubleSided=!0),n){t.diffuseTexture&&a.push(this._exportTextureAsync(t.diffuseTexture,r).then((function(e){e&&(s.baseColorTexture=e)})));var l=t.bumpTexture;l&&a.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],a.push(this._exportTextureAsync(t.emissiveTexture,r).then((function(e){e&&(u.emissiveTexture=e)})))),t.ambientTexture&&a.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===m.Constants.ALPHA_COMBINE?u.alphaMode="BLEND":m.Tools.Warn(t.name+": glTF 2.0 does not support alpha mode: "+t.alphaMode.toString())),t.emissiveColor&&!e._FuzzyEquals(t.emissiveColor,m.Color3.Black(),e._Epsilon)&&(u.emissiveFactor=t.emissiveColor.asArray()),u.pbrMetallicRoughness=s,e._SetAlphaMode(u,t),o.push(u),i[t.uniqueId]=o.length-1,this._finishMaterial(a,u,t,r)},e.prototype._finishMaterial=function(e,t,r,n){var i=this;return Promise.all(e).then((function(){for(var e=null,o=0,a=i._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",t,r);o<a.length;o++){var s=a[o];e||(e=[]),e.push(i._exportTextureAsync(s,n))}return e||(e=[Promise.resolve(null)]),Promise.all(e).then((function(){var e=i._exporter._extensionsPostExportMaterialAsync("exportMaterial",t,r);return e?e.then((function(){return t})):t}))}))},e.prototype._getImageDataAsync=function(e,t,r,n){return p(this,void 0,void 0,(function(){var i,o,a,s,u;return d(this,(function(l){switch(l.label){case 0:return i=m.Constants.TEXTURETYPE_UNSIGNED_INT,o=this._exporter._babylonScene,a=o.getEngine(),s=a.createRawTexture(e,t,r,m.Constants.TEXTUREFORMAT_RGBA,!1,!0,m.Texture.NEAREST_SAMPLINGMODE,null,i),[4,m.TextureTools.ApplyPostProcess("pass",s,o,i,m.Constants.TEXTURE_NEAREST_SAMPLINGMODE,m.Constants.TEXTUREFORMAT_RGBA)];case 1:return l.sent(),[4,a._readTexturePixels(s,t,r)];case 2:return u=l.sent(),[4,m.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),i=0;i<n.length;i+=4)n[i]=n[i+1]=n[i+2]=n[i+3]=255;return m.RawTexture.CreateRGBATexture(n,e,t,r)},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,i,o=e?e.getSize():{width:0,height:0},a=t?t.getSize():{width:0,height:0};return o.width<a.width?(n=e&&e instanceof m.Texture?m.TextureTools.CreateResizedCopy(e,a.width,a.height,!0):this._createWhiteTexture(a.width,a.height,r),i=t):o.width>a.width?(i=t&&t instanceof m.Texture?m.TextureTools.CreateResizedCopy(t,o.width,o.height,!0):this._createWhiteTexture(o.width,o.height,r),n=e):(n=e,i=t),{texture1:n,texture2:i}},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,i){var o;return p(this,void 0,void 0,(function(){var a,s,u,l,c,f,h,p,_,g,x,y,T,v,b,A,E,M,F,w,R,C,V,S,I,B,P,N,L,O,U;return d(this,(function(d){switch(d.label){case 0:return a=new Array,t||r?(s=t?t.getScene():r?r.getScene():null)?(u=this._resizeTexturesToSameDimensions(t,r,s),l=null===(o=u.texture1)||void 0===o?void 0:o.getSize(),c=void 0,f=void 0,h=l.width,p=l.height,[4,u.texture1.readPixels()]):[3,3]:[2,Promise.reject("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!")];case 1:return _=d.sent(),[4,u.texture2.readPixels()];case 2:if(g=d.sent(),!_)return[2,Promise.reject("Failed to retrieve pixels from diffuse texture!")];if(c=this._convertPixelArrayToFloat32(_),!g)return[2,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];for(f=this._convertPixelArrayToFloat32(g),x=f.byteLength,y=new Uint8Array(x),T=new Uint8Array(x),v=m.Color3.Black(),b=0,A=0,B=0;B<p;++B)for(P=0;P<h;++P)E=4*(h*B+P),M=new m.Color3(c[E],c[E+1],c[E+2]).toLinearSpace(s.getEngine().useExactSrgbConversions).multiply(n.diffuseColor),F=new m.Color3(f[E],f[E+1],f[E+2]).toLinearSpace(s.getEngine().useExactSrgbConversions).multiply(n.specularColor),w=f[E+3]*n.glossiness,R={diffuseColor:M,specularColor:F,glossiness:w},C=this._convertSpecularGlossinessToMetallicRoughness(R),v.r=Math.max(v.r,C.baseColor.r),v.g=Math.max(v.g,C.baseColor.g),v.b=Math.max(v.b,C.baseColor.b),b=Math.max(b,C.metallic),A=Math.max(A,C.roughness),T[E]=255*C.baseColor.r,T[E+1]=255*C.baseColor.g,T[E+2]=255*C.baseColor.b,T[E+3]=u.texture1.hasAlpha?255*c[E+3]:255,y[E]=0,y[E+1]=255*C.roughness,y[E+2]=255*C.metallic,y[E+3]=255;for(V={baseColor:v,metallic:b,roughness:A},S=!1,I=!1,B=0;B<p;++B)for(P=0;P<h;++P)T[N=4*(h*B+P)]/=V.baseColor.r>e._Epsilon?V.baseColor.r:1,T[N+1]/=V.baseColor.g>e._Epsilon?V.baseColor.g:1,T[N+2]/=V.baseColor.b>e._Epsilon?V.baseColor.b:1,L=m.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,m.Color3.White(),e._Epsilon)||(I=!0),y[N+1]/=V.roughness>e._Epsilon?V.roughness:1,y[N+2]/=V.metallic>e._Epsilon?V.metallic:1,U=m.Color3.FromInts(255,y[N+1],y[N+2]),e._FuzzyEquals(U,m.Color3.White(),e._Epsilon)||(S=!0);return S&&a.push(this._getImageDataAsync(y,h,p,i).then((function(e){V.metallicRoughnessTextureData=e}))),I&&a.push(this._getImageDataAsync(T,h,p,i).then((function(e){V.baseColorTextureData=e}))),[2,Promise.all(a).then((function(){return V}))];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),i=1-this._getMaxComponent(t.specularColor),o=e._SolveMetallic(r,n,i),a=t.diffuseColor.scale(i/(1-e._DielectricSpecular.r)/Math.max(1-o,e._Epsilon)),s=t.specularColor.subtract(e._DielectricSpecular.scale(1-o)).scale(1/Math.max(o,e._Epsilon)),u=m.Color3.Lerp(a,s,o*o);return{baseColor:u=u.clampToRef(0,1,u),metallic:o,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 i=[],o={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness};if(n){e._albedoTexture&&i.push(this._exportTextureAsync(e._albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)})));var a=e._metallicTexture;a&&i.push(this._exportTextureAsync(a,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))}return Promise.all(i).then((function(){return o}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof m.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 m.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case m.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case m.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case m.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case m.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case m.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case m.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case m.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case m.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case m.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case m.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case m.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case m.Texture.WRAP_ADDRESSMODE:return 10497;case m.Texture.CLAMP_ADDRESSMODE:return 33071;case m.Texture.MIRROR_ADDRESSMODE:return 33648;default:return m.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r,n){var i=this;return Promise.resolve().then((function(){var o={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},a=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((a||s)&&n){var l=i._exportTextureSampler(a||s);return i._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(a,s,o,t).then((function(e){var n=i._exporter._textures;if(e.baseColorTextureData){var o=i._exportImage("baseColor".concat(n.length),t,e.baseColorTextureData);r.baseColorTexture=i._exportTextureInfo(o,l,null==a?void 0:a.coordinatesIndex)}return e.metallicRoughnessTextureData&&(o=i._exportImage("metallicRoughness".concat(n.length),t,e.metallicRoughnessTextureData),r.metallicRoughnessTexture=i._exportTextureInfo(o,l,null==s?void 0:s.coordinatesIndex)),e}))}return i._convertSpecularGlossinessToMetallicRoughness(o)}))},e.prototype._convertPBRMaterialAsync=function(e,t,r){var n=this,i={},o={name:e.name};if(e.isMetallicWorkflow()){var a=e._albedoColor,s=e.alpha;return a&&(i.baseColorFactor=[a.r,a.g,a.b,s]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,i,r).then((function(a){return n._setMetallicRoughnessPbrMaterial(a,e,o,i,t,r)}))}return this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,i,r).then((function(a){return n._setMetallicRoughnessPbrMaterial(a,e,o,i,t,r)}))},e.prototype._setMetallicRoughnessPbrMaterial=function(t,r,n,i,o,a){var s=this._exporter._materialMap,u=this._exporter._materials,l=[];if(t){if(e._SetAlphaMode(n,r),e._FuzzyEquals(t.baseColor,m.Color3.White(),e._Epsilon)&&r.alpha>=e._Epsilon||(i.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,r.alpha]),null!=t.metallic&&1!==t.metallic&&(i.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(i.roughnessFactor=t.roughness),null==r.backFaceCulling||r.backFaceCulling||(r._twoSidedLighting||m.Tools.Warn(r.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),a){var c=r._bumpTexture;if(c){var f=this._exportTextureAsync(c,o).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,o).then((function(e){if(e){var t={index:e.index,texCoord:e.texCoord,extensions:e.extensions};n.occlusionTexture=t;var i=r._ambientTextureStrength;i&&(t.strength=i)}})),l.push(f));var p=r._emissiveTexture;p&&(f=this._exportTextureAsync(p,o).then((function(e){e&&(n.emissiveTexture=e)})),l.push(f))}var d=r._emissiveColor;e._FuzzyEquals(d,m.Color3.Black(),e._Epsilon)||(n.emissiveFactor=d.asArray()),n.pbrMetallicRoughness=i,u.push(n),s[r.uniqueId]=u.length-1}return this._finishMaterial(l,n,r,o)},e.prototype._getPixelsFromTexture=function(e){return e.textureType,m.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 p(this,void 0,void 0,(function(){var r,n,i,o,a,s,u,l,c,f,h=this;return d(this,(function(_){switch(_.label){case 0:return(r=e.uid)in this._textureMap?[3,3]:[4,this._getPixelsFromTexture(e)];case 1:if(!(n=_.sent()))return[2,null];if(i=this._exportTextureSampler(e),o=e.mimeType)switch(o){case"image/jpeg":case"image/png":case"image/webp":t=o;break;default:m.Tools.Warn("Unsupported media type: ".concat(o))}return a=this._internalTextureToImage,s=e.getInternalTexture().uniqueId,a[s]||(a[s]={}),void 0===(u=a[s][t])&&(l=e.getSize(),u=p(h,void 0,void 0,(function(){var r;return d(this,(function(i){switch(i.label){case 0:return[4,this._getImageDataAsync(n,l.width,l.height,t)];case 1:return r=i.sent(),[2,this._exportImage(e.name,t,r)]}}))})),a[s][t]=u),f=this._exportTextureInfo,[4,u];case 2:c=f.apply(this,[_.sent(),i,e.coordinatesIndex]),this._textureMap[r]=c,this._exporter._extensionsPostExportTextures("exporter",this._textureMap[r],e),_.label=3;case 3:return[2,this._textureMap[r]]}}))}))},e.prototype._exportImage=function(e,t,r){var n=this._exporter._imageData,i=e.replace(/\.\/|\/|\.\\|\\/g,"_"),o=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp";case"image/avif":return".avif"}}(t),a=i+o;a in n&&(a="".concat(i,"_").concat(m.Tools.RandomId()).concat(o)),n[a]={data:r,mimeType:t};var s=this._exporter._images;return s.push({name:e,uri:a}),s.length-1},e.prototype._exportTextureInfo=function(e,t,r){var n=this._exporter._textures,i=n.findIndex((function(r){return r.sampler==t&&r.source===e}));-1===i&&(i=n.length,n.push({source:e,sampler:t}));var o={index:i};return r&&(o.texCoord=r),o},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 m.Color3(.04,.04,.04),e._MaxSpecularPower=1024,e._Epsilon=1e-6,e}(),y=function(){function e(){}return e._CreateBufferView=function(e,t,r,n,i){var o={buffer:e,byteLength:r};return t&&(o.byteOffset=t),i&&(o.name=i),n&&(o.byteStride=n),o},e._CreateAccessor=function(e,t,r,n,i,o,a,s){var u={name:t,bufferView:e,componentType:n,count:i,type:r};return null!=a&&(u.min=a),null!=s&&(u.max=s),null!=o&&(u.byteOffset=o),u},e._CalculateMinMaxPositions=function(e,t,r){var n,i,o=[1/0,1/0,1/0],a=[-1/0,-1/0,-1/0];if(r)for(var s=t,u=t+r;s<u;++s){n=3*s,i=m.Vector3.FromArray(e,n).asArray();for(var l=0;l<3;++l){var c=i[l];c<o[l]&&(o[l]=c),c>a[l]&&(a[l]=c),++n}}return{min:o,max:a}},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"}(g||(g={}));var T=function(){function e(){}return e._IsTransformable=function(e){return e&&(e instanceof m.TransformNode||e instanceof m.Camera||e instanceof m.Light)},e._CreateNodeAnimation=function(t,r,n,i,o){if(this._IsTransformable(t)){var a=[],s=[],u=r.getKeys(),l=e._CalculateMinMaxKeyFrames(u),c=e._DeduceInterpolation(u,n,i),f=c.interpolationType,h=c.shouldBakeAnimation;if(h?e._CreateBakedAnimation(t,r,n,l.min,l.max,r.framePerSecond,o,a,s,l,i):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(t,r,n,a,s,i):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(t,r,n,a,s,i):e._CreateBakedAnimation(t,r,n,l.min,l.max,r.framePerSecond,o,a,s,l,i),a.length&&s.length)return{inputs:a,outputs:s,samplerInterpolation:f,inputsMin:h?l.min:m.Tools.FloatRound(l.min/r.framePerSecond),inputsMax:h?l.max:m.Tools.FloatRound(l.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,i=e.targetProperty.split(".");switch(i[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:m.Tools.Error("Unsupported animatable property ".concat(i[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(m.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,r,n,i,o,a,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,i,a,s,u,_.useQuaternion,l),f.samplers.length&&f.channels.length&&n.push(f))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,i,o,a,s,u,l,c){var f;if(t instanceof m.Mesh){var h=t.morphTargetManager;if(h)for(var p=0;p<h.numTargets;++p)for(var d=0,_=h.getTarget(p).animations;d<_.length;d++){var g=_[d];if(!c||c(g)){for(var x=new m.Animation("".concat(g.name),"influence",g.framePerSecond,g.dataType,g.loopMode,g.enableBlending),y=[],T=g.getKeys(),v=0;v<T.length;++v)for(var b=T[v],A=0;A<h.numTargets;++A)A==p?y.push(b):y.push({frame:b.frame,value:0});x.setKeys(y);var E=e._DeduceAnimationInfo(x);E&&(f={name:x.name,samplers:[],channels:[]},e._AddAnimation(g.name,g.hasRunningRuntimeAnimations?r:f,t,x,E.dataAccessorType,E.animationChannelTargetPath,i,a,s,u,E.useQuaternion,l,h.numTargets),f.samplers.length&&f.channels.length&&n.push(f))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,i,o,a,s,u){var l,c;if(t.animationGroups)for(var f=t.animationGroups,h=function(f){var h=new Map,d=new Map,_=new Set,g=f.to-f.from;c={name:f.name,channels:[],samplers:[]};for(var x=function(r){var g=f.targetedAnimations[r],x=g.target,y=g.animation;if(u&&!u(y))return"continue";if(p._IsTransformable(x)||1===x.length&&p._IsTransformable(x[0])){if(v=e._DeduceAnimationInfo(g.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,i,o,a,v.useQuaternion,s)}}else if(x instanceof m.MorphTarget||1===x.length&&x[0]instanceof m.MorphTarget){var v;if(v=e._DeduceAnimationInfo(g.animation)){var b=x instanceof m.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),_.add(E),d.set(E,y))}}}}},y=0;y<f.targetedAnimations.length;++y)x(y);_.forEach((function(t){for(var r=t.morphTargetManager,u=null,l=[],p=d.get(t).getKeys(),_=p.length,x=0;x<_;++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 m.Animation("".concat(f.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,m.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),l.push(b.getKeys()[x])):l.push({frame:f.from+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,i,o,a,A.useQuaternion,s,null==r?void 0:r.numTargets)})),c.channels.length&&c.samplers.length&&r.push(c)},p=this,d=0,_=f;d<_.length;d++)h(_[d])},e._AddAnimation=function(t,r,n,i,o,a,s,u,l,c,f,h,p){var d,_,g,m,x,T,v,b=e._CreateNodeAnimation(n,i,a,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=y._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," keyframe data view")),l.push(d),b.inputs.forEach((function(e){u.setFloat32(e)})),_=y._CreateAccessor(l.length-1,"".concat(t," keyframes"),"SCALAR",5126,b.inputs.length,null,[b.inputsMin],[b.inputsMax]),c.push(_),g=c.length-1,x=b.outputs.length,w=4*y._GetDataAccessorElementCount(o)*b.outputs.length,d=y._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)}))})),_=y._CreateAccessor(l.length-1,"".concat(t," data"),o,5126,x,null,null,null),c.push(_),m=c.length-1,T={interpolation:b.samplerInterpolation,input:g,output:m},r.samplers.push(T),v={sampler:r.samplers.length-1,target:{node:F,path:a}},r.channels.push(v)}},e._CreateBakedAnimation=function(t,r,n,i,o,a,s,u,l,c,f){var h,p,d=m.Quaternion.Identity(),_=null,g=null,x=null,y=null,T=null,v=null;c.min=m.Tools.FloatRound(i/a);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=o}if(v)for(var M=x.frame;M<=v;M+=s)if((p=m.Tools.FloatRound(M/a))!==_){_=p,g=p;var F={key:0,repeatCount:0,loopMode:r.loopMode};h=r._interpolate(M,F),e._SetInterpolatedValue(t,h,p,r,n,d,u,l,f)}}g&&(c.max=g)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,i,o){var a=e._GetBasePositionRotationOrScale(r,i,o),s=n.targetProperty.split("."),u=s?s[1]:"",l=o?m.Quaternion.FromArray(a).normalize():m.Vector3.FromArray(a);switch(u){case"x":case"y":case"z":l[u]=t;break;case"w":l.w=t;break;default:m.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return l},e._SetInterpolatedValue=function(e,t,r,n,i,o,a,s,u){var l;a.push(r),"weights"!==i?(n.dataType===m.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,i,u)),"rotation"===i?(u?o=t:(l=t,m.Quaternion.RotationYawPitchRollToRef(l.y,l.x,l.z,o)),s.push(o.asArray())):(l=t,s.push(l.asArray()))):s.push([t])},e._CreateLinearOrStepAnimation=function(t,r,n,i,o,a){for(var s=0,u=r.getKeys();s<u.length;s++){var l=u[s];i.push(l.frame/r.framePerSecond),e._AddKeyframeValue(l,r,o,n,t,a)}},e._CreateCubicSplineAnimation=function(t,r,n,i,o,a){r.getKeys().forEach((function(s){i.push(s.frame/r.framePerSecond),e._AddSplineTangent(g.INTANGENT,o,n,"CUBICSPLINE",s,a),e._AddKeyframeValue(s,r,o,n,t,a),e._AddSplineTangent(g.OUTTANGENT,o,n,"CUBICSPLINE",s,a)}))},e._GetBasePositionRotationOrScale=function(e,t,r){var n;if("rotation"===t)if(r){var i=e.rotationQuaternion;n=(null!=i?i:m.Quaternion.Identity()).asArray()}else{var o=e.rotation;n=(null!=o?o:m.Vector3.Zero()).asArray()}else if("translation"===t){var a=e.position;n=(null!=a?a:m.Vector3.Zero()).asArray()}else{var s=e.scaling;n=(null!=s?s:m.Vector3.One()).asArray()}return n},e._AddKeyframeValue=function(e,t,r,n,i,o){var a,s=t.dataType;if(s===m.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===n){var l=m.Vector3.FromArray(u);u=m.Quaternion.RotationYawPitchRoll(l.y,l.x,l.z).asArray()}r.push(u)}else if(s===m.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(a=this._ConvertFactorToVector3OrQuaternion(e.value,i,t,n,o)){if("rotation"===n){var c=o?a:m.Quaternion.RotationYawPitchRoll(a.y,a.x,a.z).normalize();r.push(c.asArray())}r.push(a.asArray())}}else s===m.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):m.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,i,o=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var a=0,s=e.length;a<s;++a)if((i=e[a]).inTangent||i.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",o=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||i.interpolation&&1===i.interpolation&&"STEP"!==n){n="LINEAR",o=!0;break}}else n=i.interpolation&&1===i.interpolation?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:o}},e._AddSplineTangent=function(e,t,r,n,i,o){var a,s=e===g.INTANGENT?i.inTangent:i.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(s)if(o)a=s.asArray();else{var u=s;a=m.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else a=[0,0,0,0];else a="weights"===r?s?[s]:[0]:s?s.asArray():[0,0,0];t.push(a)}},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}(),v=m.Matrix.Compose(new m.Vector3(-1,1,1),m.Quaternion.Identity(),m.Vector3.Zero()),b=new m.Quaternion(0,1,0,0);function A(e,t){if(!(e instanceof m.TransformNode))return!1;if(t){if(!e.getWorldMatrix().isIdentity())return!1}else if(!e.getWorldMatrix().multiplyToRef(v,m.TmpVectors.Matrix[0]).isIdentity())return!1;return!(e instanceof m.Mesh&&e.geometry||e instanceof m.InstancedMesh&&e.sourceMesh.geometry)}function E(e,t){switch(t){case 5121:return e.setUInt8.bind(e);case 5123:return e.setUInt16.bind(e);case 5125:return e.setUInt32.bind(e);case 5126:return e.setFloat32.bind(e);default:return m.Tools.Warn("Unsupported Attribute Component kind: "+t),null}}var M=function(){function e(e,t){this._extensions={},this._glTF={asset:{generator:"Babylon.js v".concat(m.Engine.Version),version:"2.0"}},(e=e||m.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 x(this),this._loadExtensions())}return e.prototype._applyExtension=function(e,t,r,n){var i=this;if(r>=t.length)return Promise.resolve(e);var o=n(t[r],e);return o?o.then((function(e){return i._applyExtension(e,t,r+1,n)})):this._applyExtension(e,t,r+1,n)},e.prototype._applyExtensions=function(t,r){for(var n=[],i=0,o=e._ExtensionNames;i<o.length;i++){var a=o[i];n.push(this._extensions[a])}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,i){return t.postExportMeshPrimitiveAsync&&t.postExportMeshPrimitiveAsync(e,i,r,n)}))},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n,i){return this._applyExtensions(t,(function(t,o){return t.postExportNodeAsync&&t.postExportNodeAsync(e,o,r,n,i)}))},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 i=[],o=0,a=e._ExtensionNames;o<a.length;o++){var s=a[o],u=this._extensions[s];u.postExportMaterialAdditionalTextures&&i.push.apply(i,u.postExportMaterialAdditionalTextures(t,r,n))}return i},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var i=0,o=e._ExtensionNames;i<o.length;i++){var a=o[i],s=this._extensions[a];s.postExportTexture&&s.postExportTexture(t,r,n)}},e.prototype._forEachExtensions=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var i=n[r],o=this._extensions[i];o.enabled&&t(o)}},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],i=e._ExtensionFactories[n](this);this._extensions[n]=i}},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)&&m.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,i){switch(t){case m.Material.TriangleFillMode:n||(n=0);for(var o=e.indexStart,a=e.indexStart+e.indexCount;o<a;o+=3){var s=n+4*o,u=i.getUInt32(s+4),l=i.getUInt32(s+8);i.setUInt32(l,s+4),i.setUInt32(u,s+8)}break;case m.Material.TriangleFanDrawMode:o=e.indexStart+e.indexCount-1;for(var c=e.indexStart;o>=c;--o)i.setUInt32(r[o],n),n+=4;break;case m.Material.TriangleStripDrawMode:e.indexCount>=3&&(i.setUInt32(r[e.indexStart+2],n+4),i.setUInt32(r[e.indexStart+1],n+8))}},e.prototype._reorderVertexAttributeDataBasedOnPrimitiveMode=function(e,t,r,n,i,o){switch(t){case m.Material.TriangleFillMode:this._reorderTriangleFillMode(e,r,n,i,o);break;case m.Material.TriangleStripDrawMode:this._reorderTriangleStripDrawMode(e,r,n,i,o);break;case m.Material.TriangleFanDrawMode:this._reorderTriangleFanMode(e,r,n,i,o)}},e.prototype._reorderTriangleFillMode=function(e,t,r,n,i){var o=this._getVertexBufferFromMesh(t,e.getMesh());if(o){var a=o.byteStride/m.VertexBuffer.GetTypeByteLength(o.type);if(e.verticesCount%3!=0)m.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var s=[],u=0;switch(t){case m.VertexBuffer.PositionKind:case m.VertexBuffer.NormalKind:for(var l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=3)u=l*a,s.push(m.Vector3.FromArray(r,u)),s.push(m.Vector3.FromArray(r,u+2*a)),s.push(m.Vector3.FromArray(r,u+a));break;case m.VertexBuffer.TangentKind:for(l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=3)u=l*a,s.push(m.Vector4.FromArray(r,u)),s.push(m.Vector4.FromArray(r,u+2*a)),s.push(m.Vector4.FromArray(r,u+a));break;case m.VertexBuffer.ColorKind:var c=o.getSize();for(l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=c)u=l*a,4===c?(s.push(m.Vector4.FromArray(r,u)),s.push(m.Vector4.FromArray(r,u+2*a)),s.push(m.Vector4.FromArray(r,u+a))):(s.push(m.Vector3.FromArray(r,u)),s.push(m.Vector3.FromArray(r,u+2*a)),s.push(m.Vector3.FromArray(r,u+a)));break;case m.VertexBuffer.UVKind:case m.VertexBuffer.UV2Kind:for(l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=3)u=l*a,s.push(m.Vector2.FromArray(r,u)),s.push(m.Vector2.FromArray(r,u+2*a)),s.push(m.Vector2.FromArray(r,u+a));break;default:m.Tools.Error("Unsupported Vertex Buffer type: ".concat(t))}this._writeVertexAttributeData(s,n,t,i)}}else m.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind ".concat(t," not present!"))},e.prototype._reorderTriangleStripDrawMode=function(e,t,r,n,i){var o=this._getVertexBufferFromMesh(t,e.getMesh());if(o){var a=o.byteStride/m.VertexBuffer.GetTypeByteLength(o.type),s=[],u=0;switch(t){case m.VertexBuffer.PositionKind:case m.VertexBuffer.NormalKind:u=e.verticesStart,s.push(m.Vector3.FromArray(r,u+2*a)),s.push(m.Vector3.FromArray(r,u+a));break;case m.VertexBuffer.TangentKind:for(var l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*a,s.push(m.Vector4.FromArray(r,u));break;case m.VertexBuffer.ColorKind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*a,4===o.getSize()?s.push(m.Vector4.FromArray(r,u)):s.push(m.Vector3.FromArray(r,u));break;case m.VertexBuffer.UVKind:case m.VertexBuffer.UV2Kind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*a,s.push(m.Vector2.FromArray(r,u));break;default:m.Tools.Error("Unsupported Vertex Buffer type: ".concat(t))}this._writeVertexAttributeData(s,n+12,t,i)}else m.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind ".concat(t," not present!"))},e.prototype._reorderTriangleFanMode=function(e,t,r,n,i){var o=this._getVertexBufferFromMesh(t,e.getMesh());if(o){var a=o.byteStride/m.VertexBuffer.GetTypeByteLength(o.type),s=[],u=0;switch(t){case m.VertexBuffer.PositionKind:case m.VertexBuffer.NormalKind:for(var l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*a,s.push(m.Vector3.FromArray(r,u));break;case m.VertexBuffer.TangentKind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*a,s.push(m.Vector4.FromArray(r,u));break;case m.VertexBuffer.ColorKind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*a,s.push(m.Vector4.FromArray(r,u)),4===o.getSize()?s.push(m.Vector4.FromArray(r,u)):s.push(m.Vector3.FromArray(r,u));break;case m.VertexBuffer.UVKind:case m.VertexBuffer.UV2Kind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*a,s.push(m.Vector2.FromArray(r,u));break;default:m.Tools.Error("Unsupported Vertex Buffer type: ".concat(t))}this._writeVertexAttributeData(s,n,t,i)}else m.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind ".concat(t," not present!"))},e.prototype._writeVertexAttributeData=function(e,t,r,n){for(var i=0,o=e;i<o.length;i++){var a=o[i];r===m.VertexBuffer.NormalKind?a.normalize():r===m.VertexBuffer.TangentKind&&a instanceof m.Vector4&&y._NormalizeTangentFromRef(a);for(var s=0,u=a.asArray();s<u.length;s++){var l=u[s];n.setFloat32(l,t),t+=4}}},e.prototype._writeAttributeData=function(e,t,r,n,i,o){var a,s=[];switch(e){case m.VertexBuffer.PositionKind:for(var u=0,l=r.length/n;u<l;++u){a=u*n;var c=m.Vector3.FromArray(r,a);s.push(c.asArray())}break;case m.VertexBuffer.NormalKind:u=0;for(var f=r.length/n;u<f;++u)a=u*n,c=m.Vector3.FromArray(r,a),s.push(c.normalize().asArray());break;case m.VertexBuffer.TangentKind:u=0;for(var h=r.length/n;u<h;++u)a=u*n,c=m.Vector4.FromArray(r,a),y._NormalizeTangentFromRef(c),s.push(c.asArray());break;case m.VertexBuffer.ColorKind:for(var p=o.material,d=!p||"StandardMaterial"===p.getClassName(),_=(c=3===n?new m.Color3:new m.Color4,this._babylonScene.getEngine().useExactSrgbConversions),g=(u=0,r.length/n);u<g;++u)a=u*n,3===n?(m.Color3.FromArrayToRef(r,a,c),d&&c.toLinearSpaceToRef(c,_)):(m.Color4.FromArrayToRef(r,a,c),d&&c.toLinearSpaceToRef(c,_)),s.push(c.asArray());break;case m.VertexBuffer.UVKind:case m.VertexBuffer.UV2Kind:u=0;for(var x=r.length/n;u<x;++u)a=u*n,c=m.Vector2.FromArray(r,a),s.push(c.asArray());break;case m.VertexBuffer.MatricesIndicesKind:case m.VertexBuffer.MatricesIndicesExtraKind:u=0;for(var T=r.length/n;u<T;++u)a=u*n,c=m.Vector4.FromArray(r,a),s.push(c.asArray());break;case m.VertexBuffer.MatricesWeightsKind:case m.VertexBuffer.MatricesWeightsExtraKind:u=0;for(var v=r.length/n;u<v;++u)a=u*n,c=m.Vector4.FromArray(r,a),s.push(c.asArray());break;default:m.Tools.Warn("Unsupported Vertex Buffer Type: "+e),s=[]}var b=E(i,t);if(b)for(var A=0,M=s;A<M.length;A++)for(var F=0,w=M[A];F<w.length;F++)b(w[F])},e.prototype._createMorphTargetBufferViewKind=function(e,t,r,n,i,o,a){var s,u,l=[],c=m.TmpVectors.Vector3[0];switch(e){case m.VertexBuffer.PositionKind:var f=i.getPositions();if(!f)return null;var h=n.getVerticesData(m.VertexBuffer.PositionKind,void 0,void 0,!0),p=0,d=new m.Vector3(1/0,1/0,1/0),_=new m.Vector3(-1/0,-1/0,-1/0);s=h.length/3;for(var g=p;g<s;++g){var x=m.Vector3.FromArray(h,3*g);m.Vector3.FromArray(f,3*g).subtractToRef(x,c),d.copyFromFloats(Math.min(c.x,d.x),Math.min(c.y,d.y),Math.min(c.z,d.z)),_.copyFromFloats(Math.max(c.x,_.x),Math.max(c.y,_.y),Math.max(c.z,_.z)),l.push(c.x,c.y,c.z)}u={min:d,max:_};break;case m.VertexBuffer.NormalKind:var T=i.getNormals();if(!T)return null;var v=n.getVerticesData(m.VertexBuffer.NormalKind,void 0,void 0,!0);for(p=0,s=v.length/3,g=p;g<s;++g){var b=m.Vector3.FromArray(v,3*g).normalize();m.Vector3.FromArray(T,3*g).normalize().subtractToRef(b,c),l.push(c.x,c.y,c.z)}break;case m.VertexBuffer.TangentKind:var A=i.getTangents();if(!A)return null;t="VEC3",a=12;var M=n.getVerticesData(m.VertexBuffer.TangentKind,void 0,void 0,!0);for(p=0,s=M.length/4,g=p;g<s;++g){var F=m.Vector3.FromArray(M,4*g);y._NormalizeTangentFromRef(F);var w=m.Vector3.FromArray(A,3*g);y._NormalizeTangentFromRef(w),w.subtractToRef(F,c),l.push(c.x,c.y,c.z)}break;default:return null}var R=E(o,r);if(!R)return null;var C=m.VertexBuffer.GetTypeByteLength(r),V=l.length*C,S=y._CreateBufferView(0,o.getByteOffset(),V,a,"".concat(e," - ").concat(i.name," (Morph Target)"));this._bufferViews.push(S);for(var I=this._bufferViews.length-1,B=0,P=l;B<P.length;B++)R(P[B]);return{bufferViewIndex:I,vertexCount:s,accessorType:t,minMax:u}},e.prototype._generateJSON=function(e,t,r){var n,i,o,a=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&&(i=a._imageData[e.uri],a._orderedImageData.push(i),n=e.uri.split(".")[0]+" image",o=y._CreateBufferView(0,u,i.data.byteLength,void 0,n),u+=i.data.byteLength,a._bufferViews.push(o),e.bufferView=a._bufferViews.length-1,e.name=n,e.mimeType=i.mimeType,e.uri=void 0,a._glTF.images||(a._glTF.images=[]),a._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 i=r._generateJSON(!1,e,!0),o=new Blob([n],{type:"application/octet-stream"}),a=e+".gltf",s=e+".bin",u=new h;if(u.glTFFiles[a]=i,u.glTFFiles[s]=o,r._imageData)for(var l in r._imageData)u.glTFFiles[l]=new Blob([r._imageData[l].data],{type:r._imageData[l].mimeType});return t&&r.dispose(),u}))},e.prototype._generateBinaryAsync=function(){var e=this,t=new F(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 i,o=r._generateJSON(!0),a=e+".glb",s=o.length,u=0;"undefined"!=typeof TextEncoder&&(s=(i=(new TextEncoder).encode(o)).length);for(var l=0;l<r._orderedImageData.length;++l)u+=r._orderedImageData[l].data.byteLength;var c=r._getPadding(s),f=r._getPadding(n.byteLength),p=r._getPadding(u),d=28+s+c+n.byteLength+f+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+c),x=new DataView(m);x.setUint32(0,s+c,!0),x.setUint32(4,1313821514,!0);var y=new Uint8Array(m,8);if(i)y.set(i);else{var T="_".charCodeAt(0);for(l=0;l<s;++l){var v=o.charCodeAt(l);v!=o.codePointAt(l)?y[l]=T:y[l]=v}}var b=new Uint8Array(m,8+s);for(l=0;l<c;++l)b[l]=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(f),F=new Uint8Array(M);for(l=0;l<f;++l)F[l]=0;var w=new ArrayBuffer(p),R=new Uint8Array(w);for(l=0;l<p;++l)R[l]=0;var C=[_,m,A,n];for(l=0;l<r._orderedImageData.length;++l)C.push(r._orderedImageData[l].data);C.push(M),C.push(w);var V=new Blob(C,{type:"application/octet-stream"}),S=new h;return S.glTFFiles[a]=V,null!=r._localEngine&&r._localEngine.dispose(),t&&r.dispose(),S}))},e.prototype._setNodeTransformation=function(e,t){t.getPivotPoint().equalsToFloats(0,0,0)||m.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=m.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);t.rotationQuaternion&&r.multiplyInPlace(t.rotationQuaternion),m.Quaternion.IsIdentity(r)||(e.rotation=r.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t){var r=m.TmpVectors.Vector3[0],n=m.TmpVectors.Quaternion[0];t.getWorldMatrix().decompose(void 0,n,r),r.equalsToFloats(0,0,0)||(e.translation=r.asArray()),n.multiplyInPlace(b),m.Quaternion.IsIdentity(n)||(e.rotation=n.asArray())},e.prototype._getVertexBufferFromMesh=function(e,t){if(t.isVerticesDataPresent(e,!0)){var r=t.getVertexBuffer(e,!0);if(r)return r}return null},e.prototype._createBufferViewKind=function(e,t,r,n,i){var o=r instanceof m.Mesh?r:r instanceof m.InstancedMesh?r.sourceMesh:null;if(o){var a=o.getVertexBuffer(e,!0),s=o.getVerticesData(e,void 0,void 0,!0);if(a&&s){var u=m.VertexBuffer.GetTypeByteLength(t),l=s.length*u,c=y._CreateBufferView(0,n.getByteOffset(),l,i,e+" - "+o.name);this._bufferViews.push(c),this._writeAttributeData(e,t,s,i/u,n,r)}}},e.prototype._getMeshPrimitiveMode=function(e){if(e instanceof m.LinesMesh)return m.Material.LineListDrawMode;if(e instanceof m.InstancedMesh||e instanceof m.Mesh){var t=e instanceof m.Mesh?e:e.sourceMesh;if("number"==typeof t.overrideRenderingFillMode)return t.overrideRenderingFillMode}return e.material?e.