@vrspace/babylonjs
Version:
vrspace.org babylonjs client
1 lines • 115 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,r,n={597:t=>{t.exports=e}},o={};function a(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return n[e](r,r.exports,a),r.exports}r=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,a.t=function(e,n){if(1&n&&(e=this(e)),8&n)return e;if("object"==typeof e&&e){if(4&n&&e.__esModule)return e;if(16&n&&"function"==typeof e.then)return e}var o=Object.create(null);a.r(o);var i={};t=t||[null,r({}),r([]),r(r)];for(var s=2&n&&e;"object"==typeof s&&!~t.indexOf(s);s=r(s))Object.getOwnPropertyNames(s).forEach((t=>i[t]=()=>e[t]));return i.default=()=>e,a.d(o,i),o},a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),a.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};a.d(i,{default:()=>ht});var s={};a.r(s),a.d(s,{OBJExport:()=>x});var u={};a.r(u),a.d(u,{__IGLTFExporterExtension:()=>_});var c={};a.r(c),a.d(c,{GLTFData:()=>v});var l={};a.r(l),a.d(l,{GLTF2Export:()=>ie});var f={};a.r(f),a.d(f,{EXT_mesh_gpu_instancing:()=>ue,KHR_draco_mesh_compression:()=>le,KHR_lights_punctual:()=>me,KHR_materials_anisotropy:()=>xe,KHR_materials_clearcoat:()=>ve,KHR_materials_diffuse_transmission:()=>be,KHR_materials_dispersion:()=>Me,KHR_materials_emissive_strength:()=>Ee,KHR_materials_ior:()=>Ce,KHR_materials_iridescence:()=>Se,KHR_materials_sheen:()=>Be,KHR_materials_specular:()=>Pe,KHR_materials_transmission:()=>Oe,KHR_materials_unlit:()=>Le,KHR_materials_volume:()=>ke,KHR_texture_transform:()=>Ge});var p={};a.r(p),a.d(p,{EXT_mesh_gpu_instancing:()=>ue,GLTF2Export:()=>ie,GLTFData:()=>v,KHR_draco_mesh_compression:()=>le,KHR_lights_punctual:()=>me,KHR_materials_anisotropy:()=>xe,KHR_materials_clearcoat:()=>ve,KHR_materials_diffuse_transmission:()=>be,KHR_materials_dispersion:()=>Me,KHR_materials_emissive_strength:()=>Ee,KHR_materials_ior:()=>Ce,KHR_materials_iridescence:()=>Se,KHR_materials_sheen:()=>Be,KHR_materials_specular:()=>Pe,KHR_materials_transmission:()=>Oe,KHR_materials_unlit:()=>Le,KHR_materials_volume:()=>ke,KHR_texture_transform:()=>Ge,_ConvertToGLTFPBRMetallicRoughness:()=>S,_SolveMetallic:()=>V});var h={};a.r(h),a.d(h,{STLExport:()=>We});var d={};a.r(d),a.d(d,{USDZExportAsync:()=>rt});var m={};a.r(m),a.d(m,{EXT_mesh_gpu_instancing:()=>ue,GLTF2Export:()=>ie,GLTFData:()=>v,KHR_draco_mesh_compression:()=>le,KHR_lights_punctual:()=>me,KHR_materials_anisotropy:()=>xe,KHR_materials_clearcoat:()=>ve,KHR_materials_diffuse_transmission:()=>be,KHR_materials_dispersion:()=>Me,KHR_materials_emissive_strength:()=>Ee,KHR_materials_ior:()=>Ce,KHR_materials_iridescence:()=>Se,KHR_materials_sheen:()=>Be,KHR_materials_specular:()=>Pe,KHR_materials_transmission:()=>Oe,KHR_materials_unlit:()=>Le,KHR_materials_volume:()=>ke,KHR_texture_transform:()=>Ge,OBJExport:()=>x,STLExport:()=>We,USDZExportAsync:()=>rt,_ConvertToGLTFPBRMetallicRoughness:()=>S,_SolveMetallic:()=>V,__IGLTFExporterExtension:()=>_});var g=a(597),x=function(){function e(){}return e.OBJ=function(e,t,r,n){var o=[],a=1,i=1;t&&(r||(r="mat"),o.push("mtllib "+r+".mtl"));for(var s=0;s<e.length;s++){var u=e[s],c=u.name||"mesh".concat(s,"}");o.push("o ".concat(c));var l=null;if(n){var f=u.computeWorldMatrix(!0);l=new g.Matrix,f.invertToRef(l),u.bakeTransformIntoVertices(f)}if(t){var p=u.material;p&&o.push("usemtl "+p.id)}var h=u.geometry;if(h){var d=h.getVerticesData("position"),m=h.getVerticesData("normal"),x=h.getVerticesData("uv"),_=h.getIndices(),v=0,y=0;if(d&&_){for(var T=e[0].getScene().useRightHandedSystem?1:-1,b=0;b<d.length;b+=3)o.push("v "+d[b]*T+" "+d[b+1]+" "+d[b+2]),v++;if(null!=m)for(b=0;b<m.length;b+=3)o.push("vn "+m[b]*T+" "+m[b+1]+" "+m[b+2]);if(null!=x)for(b=0;b<x.length;b+=2)o.push("vt "+x[b]+" "+x[b+1]),y++;var A=["","",""],M=(u.material||u.getScene().defaultMaterial)._getEffectiveOrientation(u)===g.Material.ClockWiseSideOrientation?[2,1]:[1,2],w=M[0],E=M[1];for(b=0;b<_.length;b+=3){var R=[String(_[b]+a),String(_[b+w]+a),String(_[b+E]+a)],C=[String(_[b]+i),String(_[b+w]+i),String(_[b+E]+i)],V=R,S=null!=x?C:A,I=null!=m?R:A;o.push("f "+V[0]+"/"+S[0]+"/"+I[0]+" "+V[1]+"/"+S[1]+"/"+I[1]+" "+V[2]+"/"+S[2]+"/"+I[2])}n&&l&&u.bakeTransformIntoVertices(l),a+=v,i+=y}else g.Tools.Warn("There are no position vertices or indices on the mesh!")}else g.Tools.Warn("No geometry is present on the mesh")}return o.join("\n")},e.MTL=function(e){var t=[],r=e.material;return t.push("newmtl mat1"),t.push(" Ns "+r.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+r.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+r.ambientColor.r.toFixed(4)+" "+r.ambientColor.g.toFixed(4)+" "+r.ambientColor.b.toFixed(4)),t.push(" Kd "+r.diffuseColor.r.toFixed(4)+" "+r.diffuseColor.g.toFixed(4)+" "+r.diffuseColor.b.toFixed(4)),t.push(" Ks "+r.specularColor.r.toFixed(4)+" "+r.specularColor.g.toFixed(4)+" "+r.specularColor.b.toFixed(4)),t.push(" Ke "+r.emissiveColor.r.toFixed(4)+" "+r.emissiveColor.g.toFixed(4)+" "+r.emissiveColor.b.toFixed(4)),r.ambientTexture&&t.push(" map_Ka "+r.ambientTexture.name),r.diffuseTexture&&t.push(" map_Kd "+r.diffuseTexture.name),r.specularTexture&&t.push(" map_Ks "+r.specularTexture.name),r.bumpTexture&&t.push(" map_bump -imfchan z "+r.bumpTexture.name),r.opacityTexture&&t.push(" map_d "+r.opacityTexture.name),t.join("\n")},e}(),_=0,v=function(){function e(){this.files={}}return Object.defineProperty(e.prototype,"glTFFiles",{get:function(){return this.files},enumerable:!1,configurable:!0}),e.prototype.downloadFiles=function(){for(var e in this.files){var t=this.files[e],r=new Blob([t],{type:(n=e,n.endsWith(".glb")?"model/gltf-binary":n.endsWith(".bin")?"application/octet-stream":n.endsWith(".gltf")?"model/gltf+json":n.endsWith(".jpeg")||n.endsWith(".jpg")?"image/jpeg":n.endsWith(".png")?"image/png":n.endsWith(".webp")?"image/webp":void 0)});g.Tools.Download(r,e)}var n},e}(),y=function(){return y=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},y.apply(this,arguments)};function T(e,t,r,n){return new(r||(r=Promise))((function(o,a){function i(e){try{u(n.next(e))}catch(e){a(e)}}function s(e){try{u(n.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}u((n=n.apply(e,t||[])).next())}))}function b(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=s(0),i.throw=s(1),i.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]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function A(e,t,r){if(r||2===arguments.length)for(var n,o=0,a=t.length;o<a;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var M=1e-6,w=new g.Color3(.04,.04,.04),E=1024,R=g.Color3.White(),C=g.Color3.Black();function V(e,t,r){if(t<w.r)return 0;var n=w.r,o=e*r/(1-w.r)+t-2*w.r,a=o*o-4*n*(w.r-t);return g.Scalar.Clamp((-o+Math.sqrt(a))/(2*n),0,1)}function S(e){var t=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),r=e.alpha,n=g.Scalar.Clamp(e.specularPower,0,E),o=(0,g.SpecularPowerToRoughness)(n);return{baseColorFactor:[t.r,t.g,t.b,r],metallicFactor:0,roughnessFactor:o}}function I(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function B(e,t,r){for(var n=new Uint8Array(e*t*4),o=0;o<n.length;o+=4)n[o]=n[o+1]=n[o+2]=n[o+3]=255;return g.RawTexture.CreateRGBATexture(n,e,t,r)}function F(e){if(e instanceof Uint8Array){for(var t=e.length,r=new Float32Array(e.length),n=0;n<t;++n)r[n]=e[n]/255;return r}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")}var P=function(){function e(e){this._exporter=e,this._textureMap=new Map,this._internalTextureToImage={}}return e.prototype.getTextureInfo=function(e){var t;return e&&null!==(t=this._textureMap.get(e))&&void 0!==t?t:null},e.prototype.exportStandardMaterialAsync=function(e,t,r){return T(this,void 0,void 0,(function(){var n,o,a,i,s,u,c,l;return b(this,(function(f){switch(f.label){case 0:return n=S(e),o={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||g.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),o.doubleSided=!0),r?(a=[],(i=e.diffuseTexture)&&a.push(this.exportTextureAsync(i,t).then((function(e){e&&(n.baseColorTexture=e)}))),(s=e.bumpTexture)&&a.push(this.exportTextureAsync(s,t).then((function(e){e&&(o.normalTexture=e,1!==s.level&&(o.normalTexture.scale=s.level))}))),(u=e.emissiveTexture)&&(o.emissiveFactor=[1,1,1],a.push(this.exportTextureAsync(u,t).then((function(e){e&&(o.emissiveTexture=e)})))),(c=e.ambientTexture)&&a.push(this.exportTextureAsync(c,t).then((function(e){if(e){var t={index:e.index};o.occlusionTexture=t}}))),a.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(a)]):[3,2]):[3,2];case 1:f.sent(),f.label=2;case 2:return(e.alpha<1||e.opacityTexture)&&(e.alphaMode===g.Constants.ALPHA_COMBINE?o.alphaMode="BLEND":g.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(C,M)&&(o.emissiveFactor=e.emissiveColor.asArray()),o.pbrMetallicRoughness=n,I(o,e),[4,this._finishMaterialAsync(o,e,t)];case 3:return f.sent(),(l=this._exporter._materials).push(o),[2,l.length-1]}}))}))},e.prototype._finishMaterialAsync=function(e,t,r){return T(this,void 0,void 0,(function(){var n,o,a,i,s;return b(this,(function(u){switch(u.label){case 0:for(n=this._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",e,t),o=[],a=0,i=n;a<i.length;a++)s=i[a],o.push(this.exportTextureAsync(s,r));return[4,Promise.all(o)];case 1:return u.sent(),[4,this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)];case 2:return u.sent(),[2]}}))}))},e.prototype._getImageDataAsync=function(e,t,r,n){return T(this,void 0,void 0,(function(){var o,i,s,u,c;return b(this,(function(l){switch(l.label){case 0:return o=g.Constants.TEXTURETYPE_UNSIGNED_BYTE,i=this._exporter._babylonScene,s=i.getEngine(),u=s.createRawTexture(e,t,r,g.Constants.TEXTUREFORMAT_RGBA,!1,!0,g.Texture.NEAREST_SAMPLINGMODE,null,o),s.isWebGPU?[4,Promise.resolve().then(a.t.bind(a,597,23))]:[3,2];case 1:return l.sent(),[3,4];case 2:return[4,Promise.resolve().then(a.t.bind(a,597,23))];case 3:l.sent(),l.label=4;case 4:return[4,g.TextureTools.ApplyPostProcess("pass",u,i,o,g.Constants.TEXTURE_NEAREST_SAMPLINGMODE,g.Constants.TEXTUREFORMAT_RGBA)];case 5:return l.sent(),[4,s._readTexturePixels(u,t,r)];case 6:return c=l.sent(),[4,g.DumpTools.DumpDataAsync(t,r,c,n,void 0,!0,!0)];case 7:return[2,l.sent()]}}))}))},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,o,a=e?e.getSize():{width:0,height:0},i=t?t.getSize():{width:0,height:0};return a.width<i.width?(n=e&&e instanceof g.Texture?g.TextureTools.CreateResizedCopy(e,i.width,i.height,!0):B(i.width,i.height,r),o=t):a.width>i.width?(o=t&&t instanceof g.Texture?g.TextureTools.CreateResizedCopy(t,a.width,a.height,!0):B(a.width,a.height,r),n=e):(n=e,o=t),{texture1:n,texture2:o}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,r,n){return T(this,void 0,void 0,(function(){var o,a,i,s,u,c,l,f,p,h,d,m,x,_,v,y,T,A,w,E,V,S,I,B,P,N,O,U,L,D,k;return b(this,(function(b){switch(b.label){case 0:return o=new Array,e||t?(a=e?e.getScene():t?t.getScene():null)?(i=this._resizeTexturesToSameDimensions(e,t,a),s=null===(k=i.texture1)||void 0===k?void 0:k.getSize(),u=void 0,c=void 0,l=s.width,f=s.height,[4,i.texture1.readPixels()]):[3,3]:[2,Promise.reject("diffuse and specular glossiness textures are not defined!")];case 1:return p=b.sent(),[4,i.texture2.readPixels()];case 2:if(h=b.sent(),!p)return[2,Promise.reject("Failed to retrieve pixels from diffuse texture!")];if(u=F(p),!h)return[2,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];for(c=F(h),d=c.byteLength,m=new Uint8Array(d),x=new Uint8Array(d),_=C,v=0,y=0,N=0;N<f;++N)for(O=0;O<l;++O)T=4*(l*N+O),A=new g.Color3(u[T],u[T+1],u[T+2]).toLinearSpace(a.getEngine().useExactSrgbConversions).multiply(r.diffuseColor),w=new g.Color3(c[T],c[T+1],c[T+2]).toLinearSpace(a.getEngine().useExactSrgbConversions).multiply(r.specularColor),E=c[T+3]*r.glossiness,V={diffuseColor:A,specularColor:w,glossiness:E},S=this._convertSpecularGlossinessToMetallicRoughness(V),_.r=Math.max(_.r,S.baseColor.r),_.g=Math.max(_.g,S.baseColor.g),_.b=Math.max(_.b,S.baseColor.b),v=Math.max(v,S.metallic),y=Math.max(y,S.roughness),x[T]=255*S.baseColor.r,x[T+1]=255*S.baseColor.g,x[T+2]=255*S.baseColor.b,x[T+3]=i.texture1.hasAlpha?255*u[T+3]:255,m[T]=0,m[T+1]=255*S.roughness,m[T+2]=255*S.metallic,m[T+3]=255;for(I={baseColor:_,metallic:v,roughness:y},B=!1,P=!1,N=0;N<f;++N)for(O=0;O<l;++O)x[U=4*(l*N+O)]/=I.baseColor.r>M?I.baseColor.r:1,x[U+1]/=I.baseColor.g>M?I.baseColor.g:1,x[U+2]/=I.baseColor.b>M?I.baseColor.b:1,L=g.Color3.FromInts(x[U],x[U+1],x[U+2]),D=L.toGammaSpace(a.getEngine().useExactSrgbConversions),x[U]=255*D.r,x[U+1]=255*D.g,x[U+2]=255*D.b,D.equalsWithEpsilon(R,M)||(P=!0),m[U+1]/=I.roughness>M?I.roughness:1,m[U+2]/=I.metallic>M?I.metallic:1,g.Color3.FromInts(255,m[U+1],m[U+2]).equalsWithEpsilon(R,M)||(B=!0);return B&&o.push(this._getImageDataAsync(m,l,f,n).then((function(e){I.metallicRoughnessTextureData=e}))),P&&o.push(this._getImageDataAsync(x,l,f,n).then((function(e){I.baseColorTextureData=e}))),[2,Promise.all(o).then((function(){return I}))];case 3:return[2,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}}))}))},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var t=this._getPerceivedBrightness(e.diffuseColor),r=this._getPerceivedBrightness(e.specularColor),n=1-this._getMaxComponent(e.specularColor),o=V(t,r,n),a=e.diffuseColor.scale(n/(1-w.r)/Math.max(1-o)),i=e.specularColor.subtract(w.scale(1-o)).scale(1/Math.max(o)),s=g.Color3.Lerp(a,i,o*o);return{baseColor:s=s.clampToRef(0,1,s),metallic:o,roughness:1-e.glossiness}},e.prototype._getPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},e.prototype._getMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},e.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,r,n){return T(this,void 0,void 0,(function(){var o,a,i;return b(this,(function(s){switch(s.label){case 0:return o=[],a={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness},n&&(e._albedoTexture&&o.push(this.exportTextureAsync(e._albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)}))),(i=e._metallicTexture)&&o.push(this.exportTextureAsync(i,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))),o.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(o)]):[3,2];case 1:s.sent(),s.label=2;case 2:return[2,a]}}))}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof g.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 g.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case g.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case g.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case g.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case g.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case g.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case g.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case g.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case g.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case g.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case g.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case g.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case g.Texture.WRAP_ADDRESSMODE:return 10497;case g.Texture.CLAMP_ADDRESSMODE:return 33071;case g.Texture.MIRROR_ADDRESSMODE:return 33648;default:return g.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r,n){return T(this,void 0,void 0,(function(){var o,a,i,s,u,c,l,f;return b(this,(function(p){switch(p.label){case 0:return o={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},a=e._albedoTexture,i=e._reflectivityTexture,s=e._useMicroSurfaceFromReflectivityMapAlpha,i&&!s?[2,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")]:(a||i)&&n?(this._exporter._materialNeedsUVsSet.add(e),u=this._exportTextureSampler(a||i),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(a,i,o,t)]):[3,2];case 1:return c=p.sent(),l=this._exporter._textures,c.baseColorTextureData&&(f=this._exportImage("baseColor".concat(l.length),t,c.baseColorTextureData),r.baseColorTexture=this._exportTextureInfo(f,u,null==a?void 0:a.coordinatesIndex)),c.metallicRoughnessTextureData&&(f=this._exportImage("metallicRoughness".concat(l.length),t,c.metallicRoughnessTextureData),r.metallicRoughnessTexture=this._exportTextureInfo(f,u,null==i?void 0:i.coordinatesIndex)),[2,c];case 2:return[2,this._convertSpecularGlossinessToMetallicRoughness(o)]}}))}))},e.prototype.exportPBRMaterialAsync=function(e,t,r){return T(this,void 0,void 0,(function(){var n,o,a,i,s,u,c,l;return b(this,(function(f){switch(f.label){case 0:return n={},o={name:e.name},(a=e.isMetallicWorkflow())&&(i=e._albedoColor,s=e.alpha,i&&(n.baseColorFactor=[i.r,i.g,i.b,s])),a?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,n,r)]:[3,2];case 1:return c=f.sent(),[3,4];case 2:return[4,this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,n,r)];case 3:c=f.sent(),f.label=4;case 4:return u=c,[4,this._setMetallicRoughnessPbrMaterialAsync(u,e,o,n,t,r)];case 5:return f.sent(),[4,this._finishMaterialAsync(o,e,t)];case 6:return f.sent(),(l=this._exporter._materials).push(o),[2,l.length-1]}}))}))},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,t,r,n,o,a){return T(this,void 0,void 0,(function(){var i,s,u,c,l;return b(this,(function(f){switch(f.label){case 0:return I(r,t),e.baseColor.equalsWithEpsilon(R,M)&&g.Scalar.WithinEpsilon(t.alpha,1,M)||(n.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,t.alpha]),null!=e.metallic&&1!==e.metallic&&(n.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(n.roughnessFactor=e.roughness),null==t.backFaceCulling||t.backFaceCulling||(t._twoSidedLighting||g.Tools.Warn(t.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),a?(i=[],(s=t._bumpTexture)&&i.push(this.exportTextureAsync(s,o).then((function(e){e&&(r.normalTexture=e,1!==s.level&&(r.normalTexture.scale=s.level))}))),(u=t._ambientTexture)&&i.push(this.exportTextureAsync(u,o).then((function(e){if(e){var n={index:e.index,texCoord:e.texCoord,extensions:e.extensions};r.occlusionTexture=n;var o=t._ambientTextureStrength;o&&(n.strength=o)}}))),(c=t._emissiveTexture)&&i.push(this.exportTextureAsync(c,o).then((function(e){e&&(r.emissiveTexture=e)}))),i.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(i)]):[3,2]):[3,2];case 1:f.sent(),f.label=2;case 2:return(l=t._emissiveColor).equalsWithEpsilon(C,M)||(r.emissiveFactor=l.asArray()),r.pbrMetallicRoughness=n,[2]}}))}))},e.prototype._getPixelsFromTexture=function(e){return e.textureType,g.Constants.TEXTURETYPE_UNSIGNED_BYTE,e.readPixels()},e.prototype.exportTextureAsync=function(e,t){return T(this,void 0,void 0,(function(){var r,n=this;return b(this,(function(o){return(r=this._exporter._extensionsPreExportTextureAsync("exporter",e,t))?[2,r.then((function(r){return r?n._exportTextureInfoAsync(r,t):n._exportTextureInfoAsync(e,t)}))]:[2,this._exportTextureInfoAsync(e,t)]}))}))},e.prototype._exportTextureInfoAsync=function(e,t){return T(this,void 0,void 0,(function(){var r,n,o,a,i,s,u,c,l,f=this;return b(this,(function(p){switch(p.label){case 0:return(r=this._textureMap.get(e))?[3,3]:[4,this._getPixelsFromTexture(e)];case 1:if(!(n=p.sent()))return[2,null];if(o=this._exportTextureSampler(e),a=e.mimeType)switch(a){case"image/jpeg":case"image/png":case"image/webp":t=a;break;default:g.Tools.Warn("Unsupported media type: ".concat(a))}return i=this._internalTextureToImage,s=e.getInternalTexture().uniqueId,i[s]||(i[s]={}),void 0===(u=i[s][t])&&(c=e.getSize(),u=T(f,void 0,void 0,(function(){var r;return b(this,(function(o){switch(o.label){case 0:return[4,this._getImageDataAsync(n,c.width,c.height,t)];case 1:return r=o.sent(),[2,this._exportImage(e.name,t,r)]}}))})),i[s][t]=u),l=this._exportTextureInfo,[4,u];case 2:r=l.apply(this,[p.sent(),o,e.coordinatesIndex]),this._textureMap.set(e,r),this._exporter._extensionsPostExportTextures("exporter",r,e),p.label=3;case 3:return[2,r]}}))}))},e.prototype._exportImage=function(e,t,r){var n,o=this._exporter._images;if(this._exporter._shouldUseGlb){n={name:e,mimeType:t,bufferView:void 0};var a=this._exporter._bufferManager.createBufferView(new Uint8Array(r));this._exporter._bufferManager.setBufferView(n,a)}else{var i=e.replace(/\.\/|\/|\.\\|\\/g,"_"),s=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp";case"image/avif":return".avif"}}(t),u=i+s;o.some((function(e){return e.uri===u}))&&(u="".concat(i,"_").concat(g.Tools.RandomId()).concat(s)),n={name:e,uri:u},this._exporter._imageData[u]={data:r,mimeType:t}}return o.push(n),o.length-1},e.prototype._exportTextureInfo=function(e,t,r){var n=this._exporter._textures,o=n.findIndex((function(r){return r.sampler==t&&r.source===e}));-1===o&&(o=n.length,n.push({source:e,sampler:t}));var a={index:o};return r&&(a.texCoord=r),a},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}(),N=g.Matrix.Compose(new g.Vector3(-1,1,1),g.Quaternion.Identity(),g.Vector3.Zero()),O=new g.Quaternion(0,1,0,0),U=1e-6,L=g.Vector3.Zero(),D=g.Vector3.One();function k(e){switch(e){case"MAT2":case"VEC4":return 4;case"MAT3":return 9;case"MAT4":return 16;case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3}}function K(e){switch(e){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:case g.VertexBuffer.ColorKind:case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:case g.VertexBuffer.MatricesWeightsKind:case g.VertexBuffer.MatricesWeightsExtraKind:case g.VertexBuffer.UVKind:case g.VertexBuffer.UV2Kind:case g.VertexBuffer.UV3Kind:case g.VertexBuffer.UV4Kind:case g.VertexBuffer.UV5Kind:case g.VertexBuffer.UV6Kind:return!0}return!1}function G(e){switch(e){case g.Material.TriangleFillMode:return 4;case g.Material.TriangleStripDrawMode:return 5;case g.Material.TriangleFanDrawMode:return 6;case g.Material.PointListDrawMode:case g.Material.PointFillMode:return 0;case g.Material.LineLoopDrawMode:return 2;case g.Material.LineListDrawMode:return 1;case g.Material.LineStripDrawMode:return 3}throw new Error("Unknown fill mode: ".concat(e))}function W(e){var t=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);t>0&&(e.x/=t,e.y/=t,e.z/=t)}function H(e){return e.x*=-1,e}function q(e){return e.x*=-1,e.y*=-1,e}function j(e){return e.multiplyInPlace(O)}function z(e,t){return t instanceof g.TransformNode&&1==t.getChildren().length&&0==e.getChildren().length}function Q(e,t){if(!(e instanceof g.TransformNode))return!1;if(t){if(!e.getWorldMatrix().isIdentity())return!1}else if(!e.getWorldMatrix().multiplyToRef(N,g.TmpVectors.Matrix[0]).isIdentity())return!1;return!(e instanceof g.Mesh&&e.geometry||e instanceof g.InstancedMesh&&e.sourceMesh.geometry)}function Y(e,t){for(var r=0,n=Object.entries(e);r<n.length;r++){var o=n[r],a=o[0],i=o[1],s=t[a];(Array.isArray(i)&&Array.isArray(s)&&X(i,s)||i===s)&&delete e[a]}return e}function X(e,t){return e.length===t.length&&e.every((function(e,r){return e===t[r]}))}var Z=new Map([[Int8Array,function(e,t,r){return e.setInt8(t,r)}],[Uint8Array,function(e,t,r){return e.setUint8(t,r)}],[Uint8ClampedArray,function(e,t,r){return e.setUint8(t,r)}],[Int16Array,function(e,t,r){return e.setInt16(t,r,!0)}],[Uint16Array,function(e,t,r){return e.setUint16(t,r,!0)}],[Int32Array,function(e,t,r){return e.setInt32(t,r,!0)}],[Uint32Array,function(e,t,r){return e.setUint32(t,r,!0)}],[Float32Array,function(e,t,r){return e.setFloat32(t,r,!0)}],[Float64Array,function(e,t,r){return e.setFloat64(t,r,!0)}]]),J=function(){function e(e){this._data=new Uint8Array(e),this._dataView=new DataView(this._data.buffer),this._byteOffset=0}return e.prototype.writeTypedArray=function(e){this._checkGrowBuffer(e.byteLength);for(var t=Z.get(e.constructor),r=0;r<e.length;r++)t(this._dataView,this._byteOffset,e[r]),this._byteOffset+=e.BYTES_PER_ELEMENT},Object.defineProperty(e.prototype,"byteOffset",{get:function(){return this._byteOffset},enumerable:!1,configurable:!0}),e.prototype.getOutputData=function(){return new Uint8Array(this._data.buffer,0,this._byteOffset)},e.prototype.writeUInt8=function(e){this._checkGrowBuffer(1),this._dataView.setUint8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt8=function(e){this._checkGrowBuffer(1),this._dataView.setInt8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt16=function(e){this._checkGrowBuffer(2),this._dataView.setInt16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeUInt16=function(e){this._checkGrowBuffer(2),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeInt32=function(e){this._checkGrowBuffer(4),this._dataView.setInt32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeUInt32=function(e){this._checkGrowBuffer(4),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat32=function(e){this._checkGrowBuffer(4),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat64=function(e){this._checkGrowBuffer(8),this._dataView.setFloat64(this._byteOffset,e,!0),this._byteOffset+=8},e.prototype._checkGrowBuffer=function(e){var t=this.byteOffset+e;if(t>this._data.byteLength){var r=new Uint8Array(2*t);r.set(this._data),this._data=r,this._dataView=new DataView(this._data.buffer)}},e}();function $(e){return e%4==0?4:e%2==0?2:1}var ee,te=function(){function e(){this._bufferViewToData=new Map,this._bufferViewToProperties=new Map,this._accessorToBufferView=new Map}return e.prototype.generateBinary=function(e){var t=0;this._bufferViewToData.forEach((function(e){t+=e.byteLength}));for(var r=new J(t),n=0,o=Array.from(this._bufferViewToData.keys()).sort((function(e,t){return $(t.byteLength)-$(e.byteLength)}));n<o.length;n++){var a=o[n];a.byteOffset=r.byteOffset,e.push(a);for(var i=e.length-1,s=0,u=this.getPropertiesWithBufferView(a);s<u.length;s++)u[s].bufferView=i;r.writeTypedArray(this._bufferViewToData.get(a)),this._bufferViewToData.delete(a)}return r.getOutputData()},e.prototype.createBufferView=function(e,t){var r={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(r,e),r},e.prototype.createAccessor=function(e,t,r,n,o,a,i){this._verifyBufferView(e);var s={bufferView:void 0,componentType:r,count:n,type:t,min:null==a?void 0:a.min,max:null==a?void 0:a.max,normalized:i,byteOffset:o};return this.setBufferView(s,e),this._accessorToBufferView.set(s,e),s},e.prototype.setBufferView=function(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)},e.prototype.removeBufferView=function(e){for(var t=this,r=0,n=this.getPropertiesWithBufferView(e);r<n.length;r++){var o=n[r];void 0!==o.bufferView&&delete o.bufferView}this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach((function(r,n){r===e&&(void 0!==n.byteOffset&&delete n.byteOffset,t._accessorToBufferView.delete(n))}))},e.prototype.getBufferView=function(e){var t=this._accessorToBufferView.get(e);return this._verifyBufferView(t),t},e.prototype.getPropertiesWithBufferView=function(e){var t;return this._verifyBufferView(e),this._bufferViewToProperties.set(e,null!==(t=this._bufferViewToProperties.get(e))&&void 0!==t?t:[]),this._bufferViewToProperties.get(e)},e.prototype.getData=function(e){return this._verifyBufferView(e),this._bufferViewToData.get(e)},e.prototype._verifyBufferView=function(e){if(void 0===e||!this._bufferViewToData.has(e))throw new Error("BufferView ".concat(e," not found in BufferManager."))},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(ee||(ee={}));var re=function(){function e(){}return e._IsTransformable=function(e){return e&&(e instanceof g.TransformNode||e instanceof g.Camera||e instanceof g.Light)},e._CreateNodeAnimation=function(t,r,n,o,a){if(this._IsTransformable(t)){var i=[],s=[],u=r.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,n,o),f=l.interpolationType,p=l.shouldBakeAnimation;if(p?e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,a,i,s,c,o):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(t,r,n,i,s,o):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(t,r,n,i,s,o):e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,a,i,s,c,o),i.length&&s.length)return{inputs:i,outputs:s,samplerInterpolation:f,inputsMin:p?c.min:g.Tools.FloatRound(c.min/r.framePerSecond),inputsMax:p?c.max:g.Tools.FloatRound(c.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,o=e.targetProperty.split(".");switch(o[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:g.Tools.Error("Unsupported animatable property ".concat(o[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(g.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,r,n,o,a,i,s,u,c,l,f){var p;if(e._IsTransformable(t)&&t.animations)for(var h=0,d=t.animations;h<d.length;h++){var m=d[h];if(!f||f(m)){var g=e._DeduceAnimationInfo(m);g&&(p={name:m.name,samplers:[],channels:[]},e._AddAnimation("".concat(m.name),m.hasRunningRuntimeAnimations?r:p,t,m,g.dataAccessorType,g.animationChannelTargetPath,o,i,s,u,g.useQuaternion,c,l),p.samplers.length&&p.channels.length&&n.push(p))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,o,a,i,s,u,c,l,f){var p;if(t instanceof g.Mesh){var h=t.morphTargetManager;if(h)for(var d=0;d<h.numTargets;++d)for(var m=0,x=h.getTarget(d).animations;m<x.length;m++){var _=x[m];if(!f||f(_)){for(var v=new g.Animation("".concat(_.name),"influence",_.framePerSecond,_.dataType,_.loopMode,_.enableBlending),y=[],T=_.getKeys(),b=0;b<T.length;++b)for(var A=T[b],M=0;M<h.numTargets;++M)M==d?y.push(A):y.push({frame:A.frame,value:0});v.setKeys(y);var w=e._DeduceAnimationInfo(v);w&&(p={name:v.name,samplers:[],channels:[]},e._AddAnimation(_.name,_.hasRunningRuntimeAnimations?r:p,t,v,w.dataAccessorType,w.animationChannelTargetPath,o,i,s,u,w.useQuaternion,c,l,h.numTargets),p.samplers.length&&p.channels.length&&n.push(p))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,o,a,i,s,u,c){var l,f;if(t.animationGroups)for(var p=t.animationGroups,h=function(p){var h=new Map,m=new Map,x=new Set,_=p.to-p.from;f={name:p.name,channels:[],samplers:[]};for(var v=function(r){var _=p.targetedAnimations[r],v=_.target,y=_.animation;if(c&&!c(y))return"continue";var T=u.has(v);if(d._IsTransformable(v)||1===v.length&&d._IsTransformable(v[0])){if(A=e._DeduceAnimationInfo(_.animation)){var b=d._IsTransformable(v)?v:d._IsTransformable(v[0])?v[0]:null;b&&e._AddAnimation("".concat(y.name),f,b,y,A.dataAccessorType,A.animationChannelTargetPath,n,o,a,i,A.useQuaternion,s,T)}}else if(v instanceof g.MorphTarget||1===v.length&&v[0]instanceof g.MorphTarget){var A;if(A=e._DeduceAnimationInfo(_.animation)){var M=v instanceof g.MorphTarget?v:v[0];if(M){var w=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===M)return!0;return!1}));if(w){var E=t.meshes.find((function(e){return e.morphTargetManager===w}));E&&(h.has(E)||h.set(E,new Map),null===(l=h.get(E))||void 0===l||l.set(M,y),x.add(E),m.set(E,y))}}}}},y=0;y<p.targetedAnimations.length;++y)v(y);x.forEach((function(t){for(var r=t.morphTargetManager,u=null,c=[],l=m.get(t).getKeys(),d=l.length,x=0;x<d;++x)for(var v=0;v<r.numTargets;++v){var y=r.getTarget(v),T=h.get(t);if(T){var b=T.get(y);b?(u||(u=new g.Animation("".concat(p.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,g.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[x])):c.push({frame:p.from+_/d*x,value:y.influence,inTangent:l[0].inTangent?0:void 0,outTangent:l[0].outTangent?0:void 0})}}u.setKeys(c);var A=e._DeduceAnimationInfo(u);A&&e._AddAnimation("".concat(p.name,"_").concat(t.name,"_MorphWeightAnimation"),f,t,u,A.dataAccessorType,A.animationChannelTargetPath,n,o,a,i,A.useQuaternion,s,!1,null==r?void 0:r.numTargets)})),f.channels.length&&f.samplers.length&&r.push(f)},d=this,m=0,x=p;m<x.length;m++)h(x[m])},e._AddAnimation=function(t,r,n,o,a,i,s,u,c,l,f,p,h,d){var m,x,_,v,y,T,b=e._CreateNodeAnimation(n,o,i,f,p);if(b){if(d){for(var A=0,M=0,w=[];b.inputs.length>0;)M=b.inputs.shift(),A%d==0&&w.push(M),A++;b.inputs=w}var E=s.get(n),R=new Float32Array(b.inputs);m=u.createBufferView(R),x=u.createAccessor(m,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(x),_=l.length-1;var C=new g.Quaternion,V=new g.Vector3,S=new g.Vector3,I=n instanceof g.Camera,B=k(a),F=new Float32Array(b.outputs.length*B);b.outputs.forEach((function(e,t){var r=e;if(h)switch(i){case"translation":g.Vector3.FromArrayToRef(e,0,S),H(S),S.toArray(r);break;case"rotation":4===e.length?g.Quaternion.FromArrayToRef(e,0,C):(r=new Array(4),g.Vector3.FromArrayToRef(e,0,V),g.Quaternion.FromEulerVectorToRef(V,C)),I?j(C):g.Quaternion.IsIdentity(C)||q(C),C.toArray(r)}else"rotation"===i&&(4===e.length?g.Quaternion.FromArrayToRef(e,0,C):(r=new Array(4),g.Vector3.FromArrayToRef(e,0,V),g.Quaternion.FromEulerVectorToRef(V,C)),I&&j(C),C.toArray(r));F.set(r,t*B)})),m=u.createBufferView(F),x=u.createAccessor(m,a,5126,b.outputs.length),l.push(x),v=l.length-1,y={interpolation:b.samplerInterpolation,input:_,output:v},r.samplers.push(y),T={sampler:r.samplers.length-1,target:{node:E,path:i}},r.channels.push(T)}},e._CreateBakedAnimation=function(t,r,n,o,a,i,s,u,c,l,f){var p,h,d=g.Quaternion.Identity(),m=null,x=null,_=null,v=null,y=null,T=null;l.min=g.Tools.FloatRound(o/i);for(var b=r.getKeys(),A=0,M=b.length;A<M;++A){if(T=null,_=b[A],A+1<M)if(v=b[A+1],_.value.equals&&_.value.equals(v.value)||_.value===v.value){if(0!==A)continue;T=_.frame}else T=v.frame;else{if(y=b[A-1],_.value.equals&&_.value.equals(y.value)||_.value===y.value)continue;T=a}if(T)for(var w=_.frame;w<=T;w+=s)if((h=g.Tools.FloatRound(w/i))!==m){m=h,x=h;var E={key:0,repeatCount:0,loopMode:r.loopMode};p=r._interpolate(w,E),e._SetInterpolatedValue(t,p,h,r,n,d,u,c,f)}}x&&(l.max=x)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,o,a){var i=e._GetBasePositionRotationOrScale(r,o,a),s=n.targetProperty.split("."),u=s?s[1]:"",c=a?g.Quaternion.FromArray(i).normalize():g.Vector3.FromArray(i);switch(u){case"x":case"y":case"z":c[u]=t;break;case"w":c.w=t;break;default:g.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return c},e._SetInterpolatedValue=function(e,t,r,n,o,a,i,s,u){var c;i.push(r),"weights"!==o?(n.dataType===g.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,o,u)),"rotation"===o?(u?a=t:(c=t,g.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,a)),s.push(a.asArray())):(c=t,s.push(c.asArray()))):s.push([t])},e._CreateLinearOrStepAnimation=function(t,r,n,o,a,i){for(var s=0,u=r.getKeys();s<u.length;s++){var c=u[s];o.push(c.frame/r.framePerSecond),e._AddKeyframeValue(c,r,a,n,t,i)}},e._CreateCubicSplineAnimation=function(t,r,n,o,a,i){r.getKeys().forEach((function(s){o.push(s.frame/r.framePerSecond),e._AddSplineTangent(ee.INTANGENT,a,n,"CUBICSPLINE",s,i),e._AddKeyframeValue(s,r,a,n,t,i),e._AddSplineTangent(ee.OUTTANGENT,a,n,"CUBICSPLINE",s,i)}))},e._GetBasePositionRotationOrScale=function(e,t,r){var n;if("rotation"===t)if(r){var o=e.rotationQuaternion;n=(null!=o?o:g.Quaternion.Identity()).asArray()}else{var a=e.rotation;n=(null!=a?a:g.Vector3.Zero()).asArray()}else if("translation"===t){var i=e.position;n=(null!=i?i:g.Vector3.Zero()).asArray()}else{var s=e.scaling;n=(null!=s?s:g.Vector3.One()).asArray()}return n},e._AddKeyframeValue=function(e,t,r,n,o,a){var i,s=t.dataType;if(s===g.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===n){var c=g.Vector3.FromArray(u);u=g.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}r.push(u)}else if(s===g.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(i=this._ConvertFactorToVector3OrQuaternion(e.value,o,t,n,a)){if("rotation"===n){var l=a?i:g.Quaternion.RotationYawPitchRoll(i.y,i.x,i.z).normalize();r.push(l.asArray())}r.push(i.asArray())}}else s===g.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):g.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,o,a=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var i=0,s=e.length;i<s;++i)if((o=e[i]).inTangent||o.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",a=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||o.interpolation&&1===o.interpolation&&"STEP"!==n){n="LINEAR",a=!0;break}}else n=o.interpolation&&1===o.interpolation?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:a}},e._AddSplineTangent=function(e,t,r,n,o,a){var i,s=e===ee.INTANGENT?o.inTangent:o.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(s)if(a)i=s.asArray();else{var u=s;i=g.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else i=[0,0,0,0];else i="weights"===r?s?[s]:[0]:s?s.asArray():[0,0,0];t.push(i)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,r=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),r=Math.max(r,e.frame)})),{min:t,max:r}},e}();function ne(e,t,r,n,o,a){var i={attributes:{},influence:e.influence,name:e.name},s=a?-1:1,u=g.Vector3.Zero(),c=0;if(e.hasPositions){var l=e.getPositions(),f=t.getVerticesData(g.VertexBuffer.PositionKind,void 0,void 0,!0);if(f){var p=new Float32Array(f.length),h=[1/0,1/0,1/0],d=[-1/0,-1/0,-1/0];c=f.length/3;for(var m=0;m<c;++m){var x=g.Vector3.FromArray(f,3*m);g.Vector3.FromArray(l,3*m).subtractToRef(x,u),u.x*=s,h[0]=Math.min(h[0],u.x),d[0]=Math.max(d[0],u.x),h[1]=Math.min(h[1],u.y),d[1]=Math.max(d[1],u.y),h[2]=Math.min(h[2],u.z),d[2]=Math.max(d[2],u.z),p[3*m]=u.x,p[3*m+1]=u.y,p[3*m+2]=u.z}var _=r.createBufferView(p,12),v=r.createAccessor(_,"VEC3",5126,l.length/3,0,{min:h,max:d});o.push(v),i.attributes.POSITION=o.length-1}else g.Tools.Warn("Morph target positions for mesh ".concat(t.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var y=e.getNormals(),T=t.getVerticesData(g.VertexBuffer.NormalKind,void 0,void 0,!0);if(T){var b=new Float32Array(T.length);for(c=T.length/3,m=0;m<c;++m){var A=g.Vector3.FromArray(T,3*m).normalize();g.Vector3.FromArray(y,3*m).normalize().subtractToRef(A,u),b[3*m]=u.x*s,b[3*m+1]=u.y,b[3*m+2]=u.z}_=r.createBufferView(b,12),v=r.createAccessor(_,"VEC3",5126,y.length/3,0),o.push(v),i.attributes.NORMAL=o.length-1}else g.Tools.Warn("Morph target normals for mesh ".concat(t.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var M=e.getTangents(),w=t.getVerticesData(g.VertexBuffer.TangentKind,void 0,void 0,!0);if(w){c=w.length/4;var E=new Float32Array(3*c);for(m=0;m<c;++m){var R=g.Vector3.FromArray(w,4*m);W(R);var C=g.Vector3.FromArray(M,3*m);W(C),C.subtractToRef(R,u),E[3*m]=u.x*s,E[3*m+1]=u.y,E[3*m+2]=u.z}_=r.createBufferView(E,12),v=r.createAccessor(_,"VEC3",5126,c,0),o.push(v),i.attributes.TANGENT=o.length-1}else g.Tools.Warn("Morph target tangents for mesh ".concat(t.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var V=e.getColors(),S=t.getVerticesData(g.VertexBuffer.ColorKind,void 0,void 0,!0),I=t.getVertexBuffer(g.VertexBuffer.ColorKind,!0);if(S&&I){var B=I.getSize();c=S.length/B;var F=new Float32Array(c*B);for(m=0;m<c;++m)if(3===B){var P=g.Vector3.FromArray(S,m*B);g.Vector3.FromArray(V,m*B).subtractToRef(P,u),F[3*m]=u.x,F[3*m+1]=u.y,F[3*m+2]=u.z}else if(4===B){var N=new g.Vector4;P=g.Vector4.FromArray(S,m*B),g.Vector4.FromArray(V,m*B).subtractToRef(P,N),F[4*m]=N.x,F[4*m+1]=N.y,F[4*m+2]=N.z,F[4*m+3]=N.w}else g.Tools.Warn("Unsupported number of components for color attribute: ".concat(B));_=r.createBufferView(F,4*B),v=r.createAccessor(_,3===B?"VEC3":"VEC4",5126,c,0),o.push(v),i.attributes.COLOR_0=o.length-1}else g.Tools.Warn("Morph target colors for mesh ".concat(t.name," were not exported. Mesh does not have colors vertex data"))}return i}var oe=function(){function e(e,t){this._indicesAccessorMap=new Map,this._vertexBufferViewMap=new Map,this._vertexAccessorMap=new Map,this._remappedBufferView=new Map,this._meshMorphTargetMap=new Map,this._vertexMapColorAlpha=new Map,this._exportedNodes=new Set,this._meshMap=new Map,this.convertedToRightHandedBuffers=new Map,this.convertToRightHanded=e,this.wasAddedByNoopNode=t}return e.prototype.getIndicesAccessor=function(e,t,r,n,o){var a,i,s,u;return null===(u=null===(s=null===(i=null===(a=this._indicesAccessorMap.get(e))||void 0===a?void 0:a.get(t))||void 0===i?void 0:i.get(r))||void 0===s?void 0:s.get(n))||void 0===u?void 0:u.get(o)},e.prototype.setIndicesAccessor=function(e,t,r,n,o,a){var i=this._indicesAccessorMap.get(e);i||(i=new Map,this._indicesAccessorMap.set(e,i));var s=i.get(t);s||(s=new Map,i.set(t,s));var u=s.get(r);u||(u=new Map,s.set(r,u));var c=u.get(n);c||(c=new Map,u.set(n,c)),c.set(o,a)},e.prototype.pushExportedNode=function(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)},e.prototype.getNodesSet=function(){return this._exportedNodes},e.prototype.getVertexBufferView=function(e){return this._vertexBufferViewMap.get(e)},e.prototype.setVertexBufferView=function(e,t){this._vertexBufferViewMap.set(e,t)},e.prototype.setRemappedBufferView=function(e,t,r){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,r)},e.prototype.getRemappedBufferView=function(e,t){var r;return null===(r=this._remappedBufferView.get(e))||void 0===r?void 0:r.get(t)},e.prototype.getVertexAccessor=function(e,t,r){var n,o;return null===(o=null===(n=this._vertexAccessorMap.get(e))||void 0===n?void 0:n.get(t))||void 0===o?void 0:o.get(r)},e.prototype.setVertexAccessor=function(e,t,r,n){var o=this._vertexAccessorMap.get(e);o||(o=new Map,this._vertexAccessorMap.set(e,o));var a=o.get(t);a||(a=new Map,o.set(t,a)),a.set(r,n)},e.prototype.hasVertexColorAlpha=function(e){return this._vertexMapColorAlpha.get(e)||!1},e.prototype.setHasVertexColorAlpha=function(e,t){return this._vertexMapColorAlpha.set(e,t)},e.prototype.getMesh=function(e){return this._meshMap.get(e)},e.prototype.setMesh=function(e,t){this._meshMap.set(e,t)},e.prototype.bindMorphDataToMesh=function(e,t){var r=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,r),-1===r.indexOf(t)&&r.push(t)},e.prototype.getMorphTargetsFromMesh=function(e){return this._meshMorphTargetMap.get(e)},e}(),ae=function(){function e(e,t){if(void 0===e&&(e=g.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(g.Engine.Version),version:"2.0"}},this._animations=[],this._accessors=[],this._bufferViews=[],this._cameras=[],this._images=[],this._materials=[],this._meshes=[],this._nodes=[],this._samplers=[],this._scenes=[],this._skins=[],this._textures=[],this._imageData={},this._shouldUseGlb=!1,this._materialExporter=new P(this),this._extensions={},this._bufferManager=new te,this._shouldExportNodeMap=new Map,this._nodeMap=new Map,this._materialMap=new Map,this._camerasMap=new Map,this._nodesCameraMap=new Map,this._skinMap=new Map,this._nodesSkinMap=new Map,this._materialNeedsUVsSet=new Set,!e)throw new Error("No scene available to export");this._babylonScene=e,this._options=y({shouldExportNode:function(){return!0},shouldExportAnimation:function(){return!0},metadataSelector:function(e){return e},animationSampleRate:1/60,exportWithoutWaitingForScene:!1,exportUnusedUVs:!1,removeNoopRootNodes:!0,includeCoordinateSystemConversionNodes:!1,meshCompressionMethod:"None"},t),this._loadExtensions()}return e.prototype._applyExtension=function(e,t,r,n){var o=this;if(r>=t.length)return Promise.resolve(e);var a=n(t[r],e);return a?a.then((function(e){return e?o._applyExtension(e,t,r+1,n):null})):this._applyExtension(e,t,r+1,n)},e.prototype._applyExtensions=function(t,r){for(var n=[],o=0,a=e._ExtensionNames;o<a.length;o++){var i=a[o];n.push(this._extensions[i])}return this._applyExtension(t,n,0,r)},e.prototype._extensionsPreExportTextureAsync=function(e,t,r){return this._applyExtensions(t,(function(t,n){return t.preExportTextureAsync&&t.preExportTextureAsync(e,n,r)}))},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n,o){var a=this;return this._applyExtensions(t,(function(t,i){return t.postExportNodeAsync&&t.postExportNodeAsync(e,i,r,n,o,a._bufferManager)}))},e.prototype._extensionsPostExportMaterialAsync=function(e,t,r){return this._applyExtensions(t,(function(t,n){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,n,r)}))},e.prototype._extensionsPostExportMaterialAdditionalTextures=function(t,r,n){for(var o=[],a=0,i=e._ExtensionNames;a<i.length;a++){var s=i[a],u=this._extensions[s];u.postExportMaterialAdditionalTextures&&o.push.apply(o,u.postExportMaterialAdditionalTextures(t,r,n))}return o},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var o=0,a=e._ExtensionNames;o<a.length;o++){var i=a[o],s=this._extensions[i];s.postExportTexture&&s.postExportTexture(t,r,n)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var o=n[r],a=this._extensions[o];a.postExportMeshPrimitive&&a.postExportMeshPrimitive(t,this._bufferManager,this._accessors)}},e.prototype._extensionsPreGenerateBinaryAsync=function(){return T(this,void 0,void 0,(function(){var t,r,n,o;return b(this,(function(a){switch(a.label){case 0:t=0,r=e._ExtensionNames,a.label=1;case 1:return t<r.length?(n=r[t],(o=this._extensions[n]).preGenerateBinaryAsync?[4,o.preGenerateBinaryAsync(this._bufferManager)]:[3,3]):[3,4];case 2:a.sent(),a.label=3;case 3:return t++,[3,1];case 4:return[2]}}))}))},e.prototype._forEachExtensions=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var o=n[r],a=this._extensions[o];a.enabled&&t(a)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){var r,n,o;t.wasUsed&&((r=e._glTF).extensionsUsed||(r.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&((n=e._glTF).extensionsRequired||(n.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),(o=e._glTF).extensions||(o.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],o=e._ExtensionFactories[n](this);this._extensions[n]=o}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){r