babylonjs-serializers 8.25.2 → 8.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/babylonjs.serializers.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.SERIALIZERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(e=>(()=>{"use strict";var t={597:t=>{t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};r.d(o,{default:()=>Rt});var i={};r.r(i),r.d(i,{OBJExport:()=>g});var a={};r.r(a),r.d(a,{__IGLTFExporterExtension:()=>x});var s={};r.r(s),r.d(s,{GLTFData:()=>_});var u={};r.r(u),r.d(u,{GLTF2Export:()=>ue});var c={};r.r(c),r.d(c,{EXT_materials_diffuse_roughness:()=>He,EXT_mesh_gpu_instancing:()=>le,EXT_texture_avif:()=>Je,EXT_texture_webp:()=>Ye,KHR_draco_mesh_compression:()=>he,KHR_lights_punctual:()=>xe,KHR_materials_anisotropy:()=>ve,KHR_materials_clearcoat:()=>Te,KHR_materials_diffuse_transmission:()=>Me,KHR_materials_dispersion:()=>Ee,KHR_materials_emissive_strength:()=>Ce,KHR_materials_ior:()=>Se,KHR_materials_iridescence:()=>Be,KHR_materials_sheen:()=>Oe,KHR_materials_specular:()=>Ne,KHR_materials_transmission:()=>Le,KHR_materials_unlit:()=>De,KHR_materials_volume:()=>Ge,KHR_texture_basisu:()=>Qe,KHR_texture_transform:()=>je});var l={};r.r(l),r.d(l,{EXT_materials_diffuse_roughness:()=>He,EXT_mesh_gpu_instancing:()=>le,EXT_texture_avif:()=>Je,EXT_texture_webp:()=>Ye,GLTF2Export:()=>ue,GLTFData:()=>_,KHR_draco_mesh_compression:()=>he,KHR_lights_punctual:()=>xe,KHR_materials_anisotropy:()=>ve,KHR_materials_clearcoat:()=>Te,KHR_materials_diffuse_transmission:()=>Me,KHR_materials_dispersion:()=>Ee,KHR_materials_emissive_strength:()=>Ce,KHR_materials_ior:()=>Se,KHR_materials_iridescence:()=>Be,KHR_materials_sheen:()=>Oe,KHR_materials_specular:()=>Ne,KHR_materials_transmission:()=>Le,KHR_materials_unlit:()=>De,KHR_materials_volume:()=>Ge,KHR_texture_basisu:()=>Qe,KHR_texture_transform:()=>je,_ConvertToGLTFPBRMetallicRoughness:()=>S,_SolveMetallic:()=>V});var f={};r.r(f),r.d(f,{STLExport:()=>$e});var h={};r.r(h),r.d(h,{USDZExportAsync:()=>pt});var p={};r.r(p),r.d(p,{BVHExporter:()=>dt});var d={};r.r(d),r.d(d,{BVHExporter:()=>dt,EXT_materials_diffuse_roughness:()=>He,EXT_mesh_gpu_instancing:()=>le,EXT_texture_avif:()=>Je,EXT_texture_webp:()=>Ye,GLTF2Export:()=>ue,GLTFData:()=>_,KHR_draco_mesh_compression:()=>he,KHR_lights_punctual:()=>xe,KHR_materials_anisotropy:()=>ve,KHR_materials_clearcoat:()=>Te,KHR_materials_diffuse_transmission:()=>Me,KHR_materials_dispersion:()=>Ee,KHR_materials_emissive_strength:()=>Ce,KHR_materials_ior:()=>Se,KHR_materials_iridescence:()=>Be,KHR_materials_sheen:()=>Oe,KHR_materials_specular:()=>Ne,KHR_materials_transmission:()=>Le,KHR_materials_unlit:()=>De,KHR_materials_volume:()=>Ge,KHR_texture_basisu:()=>Qe,KHR_texture_transform:()=>je,OBJExport:()=>g,STLExport:()=>$e,USDZExportAsync:()=>pt,_ConvertToGLTFPBRMetallicRoughness:()=>S,_SolveMetallic:()=>V,__IGLTFExporterExtension:()=>x});var m=r(597),g=function(){function e(){}return e.OBJ=function(e,t,n,r){var o=[],i=1,a=1;t&&(n||(n="mat"),o.push("mtllib "+n+".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(r){var f=u.computeWorldMatrix(!0);l=new m.Matrix,f.invertToRef(l),u.bakeTransformIntoVertices(f)}if(t){var h=u.material;h&&o.push("usemtl "+h.id)}var p=u.geometry;if(p){var d=p.getVerticesData("position"),g=p.getVerticesData("normal"),x=p.getVerticesData("uv"),_=p.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!=g)for(b=0;b<g.length;b+=3)o.push("vn "+g[b]*T+" "+g[b+1]+" "+g[b+2]);if(null!=x)for(b=0;b<x.length;b+=2)o.push("vt "+x[b]+" "+x[b+1]),y++;var w=["","",""],M=(u.material||u.getScene().defaultMaterial)._getEffectiveOrientation(u)===m.Material.ClockWiseSideOrientation?[2,1]:[1,2],A=M[0],E=M[1];for(b=0;b<_.length;b+=3){var R=[String(_[b]+i),String(_[b+A]+i),String(_[b+E]+i)],C=[String(_[b]+a),String(_[b+A]+a),String(_[b+E]+a)],V=R,S=null!=x?C:w,I=null!=g?R:w;o.push("f "+V[0]+"/"+S[0]+"/"+I[0]+" "+V[1]+"/"+S[1]+"/"+I[1]+" "+V[2]+"/"+S[2]+"/"+I[2])}r&&l&&u.bakeTransformIntoVertices(l),i+=v,a+=y}else m.Tools.Warn("There are no position vertices or indices on the mesh!")}else m.Tools.Warn("No geometry is present on the mesh")}return o.join("\n")},e.MTL=function(e){var t=[],n=e.material;return t.push("newmtl mat1"),t.push(" Ns "+n.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+n.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+n.ambientColor.r.toFixed(4)+" "+n.ambientColor.g.toFixed(4)+" "+n.ambientColor.b.toFixed(4)),t.push(" Kd "+n.diffuseColor.r.toFixed(4)+" "+n.diffuseColor.g.toFixed(4)+" "+n.diffuseColor.b.toFixed(4)),t.push(" Ks "+n.specularColor.r.toFixed(4)+" "+n.specularColor.g.toFixed(4)+" "+n.specularColor.b.toFixed(4)),t.push(" Ke "+n.emissiveColor.r.toFixed(4)+" "+n.emissiveColor.g.toFixed(4)+" "+n.emissiveColor.b.toFixed(4)),n.ambientTexture&&t.push(" map_Ka "+n.ambientTexture.name),n.diffuseTexture&&t.push(" map_Kd "+n.diffuseTexture.name),n.specularTexture&&t.push(" map_Ks "+n.specularTexture.name),n.bumpTexture&&t.push(" map_bump -imfchan z "+n.bumpTexture.name),n.opacityTexture&&t.push(" map_d "+n.opacityTexture.name),t.join("\n")},e}(),x=0,_=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],n=new Blob([t],{type:(0,m.GetMimeType)(e)});m.Tools.Download(n,e)}},e}(),v=function(){return v=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},v.apply(this,arguments)};function y(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))}function T(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function b(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var w=1e-6,M=new m.Color3(.04,.04,.04),A=1024,E=m.Color3.White(),R=m.Color3.Black();function C(e){return y(this,void 0,void 0,(function(){var t,n,r,o;return T(this,(function(i){switch(i.label){case 0:return(t=e.getInternalTexture())&&1===t.source?t.invertY?[2,null]:(n=t._buffer,o=e.mimeType,n?[3,2]:[4,m.Tools.LoadFileAsync(t.url)]):[2,null];case 1:return r=i.sent(),o=(0,m.GetMimeType)(t.url)||o,[3,10];case 2:return ArrayBuffer.isView(n)?(r=n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength),[3,10]):[3,3];case 3:return n instanceof ArrayBuffer?(r=n,[3,10]):[3,4];case 4:return n instanceof Blob?[4,n.arrayBuffer()]:[3,6];case 5:return r=i.sent(),o=n.type||o,[3,10];case 6:return"string"!=typeof n?[3,8]:[4,m.Tools.LoadFileAsync(n)];case 7:return r=i.sent(),o=(0,m.GetMimeType)(n)||o,[3,10];case 8:return"undefined"!=typeof HTMLImageElement&&n instanceof HTMLImageElement?[4,m.Tools.LoadFileAsync(n.src)]:[3,10];case 9:r=i.sent(),o=(0,m.GetMimeType)(n.src)||o,i.label=10;case 10:return r&&o?[2,{data:r,mimeType:o}]:[2,null]}}))}))}function V(e,t,n){if(t<M.r)return 0;var r=M.r,o=e*n/(1-M.r)+t-2*M.r,i=o*o-4*r*(M.r-t);return m.Scalar.Clamp((-o+Math.sqrt(i))/(2*r),0,1)}function S(e){var t=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),n=e.alpha,r=m.Scalar.Clamp(e.specularPower,0,A),o=(0,m.SpecularPowerToRoughness)(r);return{baseColorFactor:[t.r,t.g,t.b,n],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,n){for(var r=new Uint8Array(e*t*4),o=0;o<r.length;o+=4)r[o]=r[o+1]=r[o+2]=r[o+3]=255;return m.RawTexture.CreateRGBATexture(r,e,t,n)}function F(e){if(e instanceof Uint8Array){for(var t=e.length,n=new Float32Array(e.length),r=0;r<t;++r)n[r]=e[r]/255;return n}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")}var O=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){return y(this,void 0,void 0,(function(){var n,r,o,i,a,s,u,c;return T(this,(function(l){switch(l.label){case 0:return n=S(e),r={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||m.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),t?(o=[],(i=e.diffuseTexture)&&o.push(this.exportTextureAsync(i).then((function(e){e&&(n.baseColorTexture=e)}))),(a=e.bumpTexture)&&o.push(this.exportTextureAsync(a).then((function(e){e&&(r.normalTexture=e,1!==a.level&&(r.normalTexture.scale=a.level))}))),(s=e.emissiveTexture)&&(r.emissiveFactor=[1,1,1],o.push(this.exportTextureAsync(s).then((function(e){e&&(r.emissiveTexture=e)})))),(u=e.ambientTexture)&&o.push(this.exportTextureAsync(u).then((function(e){if(e){var t={index:e.index};r.occlusionTexture=t}}))),o.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(o)]):[3,2]):[3,2];case 1:l.sent(),l.label=2;case 2:return(e.alpha<1||e.opacityTexture)&&(e.alphaMode===m.Constants.ALPHA_COMBINE?r.alphaMode="BLEND":m.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(R,w)&&(r.emissiveFactor=e.emissiveColor.asArray()),r.pbrMetallicRoughness=n,I(r,e),[4,this._finishMaterialAsync(r,e)];case 3:return l.sent(),(c=this._exporter._materials).push(r),[2,c.length-1]}}))}))},e.prototype._finishMaterialAsync=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,i,a;return T(this,(function(s){switch(s.label){case 0:for(n=this._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",e,t),r=[],o=0,i=n;o<i.length;o++)a=i[o],r.push(this.exportTextureAsync(a));return[4,Promise.all(r)];case 1:return s.sent(),[4,this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)];case 2:return s.sent(),[2]}}))}))},e.prototype._getImageDataAsync=function(e,t,n,r){return y(this,void 0,void 0,(function(){return T(this,(function(o){switch(o.label){case 0:return[4,m.DumpTools.DumpDataAsync(t,n,e,r,void 0,!1,!0)];case 1:return[2,o.sent()]}}))}))},e.prototype._resizeTexturesToSameDimensions=function(e,t,n){var r,o,i=e?e.getSize():{width:0,height:0},a=t?t.getSize():{width:0,height:0};return i.width<a.width?(r=e&&e instanceof m.Texture?m.TextureTools.CreateResizedCopy(e,a.width,a.height,!0):B(a.width,a.height,n),o=t):i.width>a.width?(o=t&&t instanceof m.Texture?m.TextureTools.CreateResizedCopy(t,i.width,i.height,!0):B(i.width,i.height,n),r=e):(r=e,o=t),{texture1:r,texture2:o}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,n,r){return y(this,void 0,void 0,(function(){var o,i,a,s,u,c,l,f,h,p,d,g,x,_,v,y,b,M,A,C,V,S,I,B,O,P,N,U,L,k,D;return T(this,(function(T){switch(T.label){case 0:return o=new Array,e||t?[3,2]:[4,Promise.reject("diffuse and specular glossiness textures are not defined!")];case 1:case 6:case 9:case 11:case 13:return[2,T.sent()];case 2:return(i=e?e.getScene():t?t.getScene():null)?(a=this._resizeTexturesToSameDimensions(e,t,i),s=null===(D=a.texture1)||void 0===D?void 0:D.getSize(),u=void 0,c=void 0,l=s.width,f=s.height,[4,a.texture1.readPixels()]):[3,12];case 3:return h=T.sent(),[4,a.texture2.readPixels()];case 4:return p=T.sent(),h?(u=F(h),[3,7]):[3,5];case 5:return[4,Promise.reject("Failed to retrieve pixels from diffuse texture!")];case 7:return p?(c=F(p),[3,10]):[3,8];case 8:return[4,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];case 10:for(d=c.byteLength,g=new Uint8Array(d),x=new Uint8Array(d),_=R,v=0,y=0,P=0;P<f;++P)for(N=0;N<l;++N)b=4*(l*P+N),M=new m.Color3(u[b],u[b+1],u[b+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(n.diffuseColor),A=new m.Color3(c[b],c[b+1],c[b+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(n.specularColor),C=c[b+3]*n.glossiness,V={diffuseColor:M,specularColor:A,glossiness:C},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[b]=255*S.baseColor.r,x[b+1]=255*S.baseColor.g,x[b+2]=255*S.baseColor.b,x[b+3]=a.texture1.hasAlpha?255*u[b+3]:255,g[b]=0,g[b+1]=255*S.roughness,g[b+2]=255*S.metallic,g[b+3]=255;for(I={baseColor:_,metallic:v,roughness:y},B=!1,O=!1,P=0;P<f;++P)for(N=0;N<l;++N)x[U=4*(l*P+N)]/=I.baseColor.r>w?I.baseColor.r:1,x[U+1]/=I.baseColor.g>w?I.baseColor.g:1,x[U+2]/=I.baseColor.b>w?I.baseColor.b:1,L=m.Color3.FromInts(x[U],x[U+1],x[U+2]),k=L.toGammaSpace(i.getEngine().useExactSrgbConversions),x[U]=255*k.r,x[U+1]=255*k.g,x[U+2]=255*k.b,k.equalsWithEpsilon(E,w)||(O=!0),g[U+1]/=I.roughness>w?I.roughness:1,g[U+2]/=I.metallic>w?I.metallic:1,m.Color3.FromInts(255,g[U+1],g[U+2]).equalsWithEpsilon(E,w)||(B=!0);return B&&o.push(this._getImageDataAsync(g,l,f,r).then((function(e){I.metallicRoughnessTextureData=e}))),O&&o.push(this._getImageDataAsync(x,l,f,r).then((function(e){I.baseColorTextureData=e}))),[4,Promise.all(o).then((function(){return I}))];case 12:return[4,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}}))}))},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var t=this._getPerceivedBrightness(e.diffuseColor),n=this._getPerceivedBrightness(e.specularColor),r=1-this._getMaxComponent(e.specularColor),o=V(t,n,r),i=e.diffuseColor.scale(r/(1-M.r)/Math.max(1-o)),a=e.specularColor.subtract(M.scale(1-o)).scale(1/Math.max(o)),s=m.Color3.Lerp(i,a,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,n){return y(this,void 0,void 0,(function(){var r,o,i,a;return T(this,(function(s){switch(s.label){case 0:return r=[],o={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness},n&&((i=e._albedoTexture)&&r.push(this.exportTextureAsync(i).then((function(e){e&&(t.baseColorTexture=e)}))),(a=e._metallicTexture)&&r.push(this.exportTextureAsync(a).then((function(e){e&&(t.metallicRoughnessTexture=e)})))),r.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(r)]):[3,2];case 1:s.sent(),s.label=2;case 2:return[2,o]}}))}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof m.Texture))return t;var n=this._getGLTFTextureWrapMode(e.wrapU);10497!==n&&(t.wrapS=n);var r=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==r&&(t.wrapT=r),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,n){return y(this,void 0,void 0,(function(){var r,o,i,a,s,u,c,l,f;return T(this,(function(h){switch(h.label){case 0:return r="image/png",o={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},i=e._albedoTexture,a=e._reflectivityTexture,s=e._useMicroSurfaceFromReflectivityMapAlpha,!a||s?[3,2]:[4,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")];case 1:return[2,h.sent()];case 2:return(i||a)&&n?(this._exporter._materialNeedsUVsSet.add(e),u=this._exportTextureSampler(i||a),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(i,a,o,r)]):[3,4];case 3:return c=h.sent(),l=this._exporter._textures,c.baseColorTextureData&&(f=this._exportImage("baseColor".concat(l.length),r,c.baseColorTextureData),t.baseColorTexture=this._exportTextureInfo(f,u,null==i?void 0:i.coordinatesIndex)),c.metallicRoughnessTextureData&&(f=this._exportImage("metallicRoughness".concat(l.length),r,c.metallicRoughnessTextureData),t.metallicRoughnessTexture=this._exportTextureInfo(f,u,null==a?void 0:a.coordinatesIndex)),[2,c];case 4:return[2,this._convertSpecularGlossinessToMetallicRoughness(o)]}}))}))},e.prototype.exportPBRMaterialAsync=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,i,a,s,u,c;return T(this,(function(l){switch(l.label){case 0:return n={},r={name:e.name},(o=e.isMetallicWorkflow())&&(i=e._albedoColor,a=e.alpha,i&&(n.baseColorFactor=[i.r,i.g,i.b,a])),o?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,n,t)]:[3,2];case 1:return u=l.sent(),[3,4];case 2:return[4,this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,n,t)];case 3:u=l.sent(),l.label=4;case 4:return s=u,[4,this._setMetallicRoughnessPbrMaterialAsync(s,e,r,n,t)];case 5:return l.sent(),[4,this._finishMaterialAsync(r,e)];case 6:return l.sent(),(c=this._exporter._materials).push(r),[2,c.length-1]}}))}))},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,t,n,r,o){return y(this,void 0,void 0,(function(){var i,a,s,u,c;return T(this,(function(l){switch(l.label){case 0:return I(n,t),e.baseColor.equalsWithEpsilon(E,w)&&m.Scalar.WithinEpsilon(t.alpha,1,w)||(r.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,t.alpha]),null!=e.metallic&&1!==e.metallic&&(r.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(r.roughnessFactor=e.roughness),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."),n.doubleSided=!0),o?(i=[],(a=t._bumpTexture)&&i.push(this.exportTextureAsync(a).then((function(e){e&&(n.normalTexture=e,1!==a.level&&(n.normalTexture.scale=a.level))}))),(s=t._ambientTexture)&&i.push(this.exportTextureAsync(s).then((function(e){if(e){var r={index:e.index,texCoord:e.texCoord,extensions:e.extensions};n.occlusionTexture=r;var o=t._ambientTextureStrength;o&&(r.strength=o)}}))),(u=t._emissiveTexture)&&i.push(this.exportTextureAsync(u).then((function(e){e&&(n.emissiveTexture=e)}))),i.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(i)]):[3,2]):[3,2];case 1:l.sent(),l.label=2;case 2:return(c=t._emissiveColor).equalsWithEpsilon(R,w)||(n.emissiveFactor=c.asArray()),n.pbrMetallicRoughness=r,[2]}}))}))},e.prototype.exportTextureAsync=function(e){return y(this,void 0,void 0,(function(){var t,n,r;return T(this,(function(o){switch(o.label){case 0:return(t=this._textureMap.get(e))?[2,t]:(n=this._exportTextureSampler(e),[4,this._exportTextureImageAsync(e)]);case 1:return r=o.sent(),t=this._exportTextureInfo(r,n,e.coordinatesIndex),this._textureMap.set(e,t),this._exporter._extensionsPostExportTextures("exporter",t,e),[2,t]}}))}))},e.prototype._exportTextureImageAsync=function(e){return y(this,void 0,void 0,(function(){var t,n,r,o,i,a=this;return T(this,(function(s){switch(s.label){case 0:return t=null!==(i=e.mimeType)&&void 0!==i?i:"none",n=this._internalTextureToImage,r=e.getInternalTexture().uniqueId,n[r]=n[r]||{},void 0===(o=n[r][t])&&(o=y(a,void 0,void 0,(function(){var n,r,o,i,a;return T(this,(function(s){switch(s.label){case 0:return[4,C(e)];case 1:if((n=s.sent())&&("none"===t||n.mimeType===t))return[2,this._exportImage(e.name,n.mimeType,n.data)];if(r="image/png","none"!==t)switch(t){case"image/jpeg":case"image/png":case"image/webp":r=t;break;default:m.Tools.Warn("Unsupported media type: ".concat(t,". Exporting texture as PNG."))}return o=e.getSize(),[4,(0,m.GetTextureDataAsync)(e)];case 2:return i=s.sent(),[4,this._getImageDataAsync(i,o.width,o.height,r)];case 3:return a=s.sent(),[2,this._exportImage(e.name,r,a)]}}))})),n[r][t]=o),[4,o];case 1:return[2,s.sent()]}}))}))},e.prototype._exportImage=function(e,t,n){var r,o=this._exporter._images;if(this._exporter._shouldUseGlb){r={name:e,mimeType:t,bufferView:void 0};var i=this._exporter._bufferManager.createBufferView(new Uint8Array(n));this._exporter._bufferManager.setBufferView(r,i)}else{var a=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";case"image/ktx2":return".ktx2"}}(t),u=a+s;o.some((function(e){return e.uri===u}))&&(u="".concat(a,"_").concat(m.Tools.RandomId()).concat(s)),r={name:e,uri:u},this._exporter._imageData[u]={data:n,mimeType:t}}return o.push(r),o.length-1},e.prototype._exportTextureInfo=function(e,t,n){var r=this._exporter._textures,o=r.findIndex((function(n){return n.sampler==t&&n.source===e}));-1===o&&(o=r.length,r.push({source:e,sampler:t}));var i={index:o};return n&&(i.texCoord=n),i},e.prototype._exportTextureSampler=function(e){var t=this._getTextureSampler(e),n=this._exporter._samplers,r=n.findIndex((function(e){return e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT}));return-1!==r?r:(n.push(t),n.length-1)},e}(),P=m.Matrix.Compose(new m.Vector3(-1,1,1),m.Quaternion.Identity(),m.Vector3.Zero());function N(e,t){if(!(e instanceof m.TransformNode))return!1;if(t){if(!e.getWorldMatrix().equalsWithEpsilon(m.Matrix.IdentityReadOnly,m.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(P,m.TmpVectors.Matrix[0]).equalsWithEpsilon(m.Matrix.IdentityReadOnly,m.Epsilon))return!1;return!(e instanceof m.AbstractMesh&&e.geometry)}var U=m.Vector3.Zero(),L=m.Quaternion.Identity(),k=m.Vector3.One(),D=new m.Vector3(-1,1,1);function K(e,t){var n=e.byteOffset,r=e.byteStride,o=e.type,i=e.normalized,a=e.getSize(),s=t.reduce((function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e}),-Number.MAX_VALUE);return{byteOffset:n,byteStride:r,componentCount:a,type:o,count:s*a,normalized:i,totalVertices:s,kind:e.getKind()}}function G(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 W(e){switch(e){case m.VertexBuffer.PositionKind:case m.VertexBuffer.NormalKind:case m.VertexBuffer.TangentKind:case m.VertexBuffer.ColorKind:case m.VertexBuffer.MatricesIndicesKind:case m.VertexBuffer.MatricesIndicesExtraKind:case m.VertexBuffer.MatricesWeightsKind:case m.VertexBuffer.MatricesWeightsExtraKind:case m.VertexBuffer.UVKind:case m.VertexBuffer.UV2Kind:case m.VertexBuffer.UV3Kind:case m.VertexBuffer.UV4Kind:case m.VertexBuffer.UV5Kind:case m.VertexBuffer.UV6Kind:return!0}return!1}function H(e){switch(e){case m.Material.TriangleFillMode:return 4;case m.Material.TriangleStripDrawMode:return 5;case m.Material.TriangleFanDrawMode:return 6;case m.Material.PointListDrawMode:case m.Material.PointFillMode:return 0;case m.Material.LineLoopDrawMode:return 2;case m.Material.LineListDrawMode:return 1;case m.Material.LineStripDrawMode:return 3}throw new Error("Unknown fill mode: ".concat(e))}function q(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 j(e){return e.x*=-1,e}function z(e){if(e.x*e.x+e.y*e.y>.5){var t=Math.abs(e.x),n=Math.abs(e.y);if(t>n){var r=Math.sign(e.x);e.x=t,e.y*=-r,e.z*=-r,e.w*=r}else r=Math.sign(e.y),e.x*=-r,e.y=n,e.z*=r,e.w*=-r}else{var o=Math.abs(e.z),i=Math.abs(e.w);o>i?(r=Math.sign(e.z),e.x*=-r,e.y*=r,e.z=o,e.w*=-r):(r=Math.sign(e.w),e.x*=r,e.y*=-r,e.z*=-r,e.w=i)}return e}function Q(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function X(e,t){var n=m.Vector3.FromArrayToRef(t.translation||[0,0,0],0,m.TmpVectors.Vector3[0]),r=m.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,m.TmpVectors.Quaternion[0]),o=m.Matrix.ComposeToRef(k,r,n,m.TmpVectors.Matrix[0]),i=m.Vector3.FromArrayToRef(e.translation||[0,0,0],0,m.TmpVectors.Vector3[2]),a=m.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,m.TmpVectors.Quaternion[1]),s=m.Matrix.ComposeToRef(k,a,i,m.TmpVectors.Matrix[1]);o.multiplyToRef(s,s),s.decompose(void 0,r,n),n.equalsWithEpsilon(U,m.Epsilon)?delete t.translation:t.translation=n.asArray(),r.equalsWithEpsilon(L,m.Epsilon)?delete t.rotation:t.rotation=r.asArray(),t.scale&&delete t.scale}function Y(e,t){if(!(t instanceof m.TransformNode))return!1;if(1!==t.getChildren().length||0!==e.getChildren().length||e.parent!==t)return!1;var n=e.getScene(),r=e instanceof m.TargetCamera&&!n.useRightHandedSystem?D:k;return!!t.scaling.equalsWithEpsilon(r,m.Epsilon)||(m.Logger.Warn("Cannot collapse node ".concat(e.name," into parent node ").concat(t.name," with modified scaling.")),!1)}function Z(e,t){for(var n=0,r=Object.entries(e);n<r.length;n++){var o=r[n],i=o[0],a=o[1],s=t[i];(Array.isArray(a)&&Array.isArray(s)&&J(a,s)||a===s)&&delete e[i]}return e}function J(e,t){return e.length===t.length&&e.every((function(e,n){return e===t[n]}))}var $=new Map([[Int8Array,function(e,t,n){return e.setInt8(t,n)}],[Uint8Array,function(e,t,n){return e.setUint8(t,n)}],[Uint8ClampedArray,function(e,t,n){return e.setUint8(t,n)}],[Int16Array,function(e,t,n){return e.setInt16(t,n,!0)}],[Uint16Array,function(e,t,n){return e.setUint16(t,n,!0)}],[Int32Array,function(e,t,n){return e.setInt32(t,n,!0)}],[Uint32Array,function(e,t,n){return e.setUint32(t,n,!0)}],[Float32Array,function(e,t,n){return e.setFloat32(t,n,!0)}],[Float64Array,function(e,t,n){return e.setFloat64(t,n,!0)}]]),ee=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=$.get(e.constructor),n=0;n<e.length;n++)t(this._dataView,this._byteOffset,e[n]),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 n=new Uint8Array(2*t);n.set(this._data),this._data=n,this._dataView=new DataView(this._data.buffer)}},e}();function te(e){return e%4==0?4:e%2==0?2:1}var ne,re=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 n=new ee(t),r=0,o=Array.from(this._bufferViewToData.keys()).sort((function(e,t){return te(t.byteLength)-te(e.byteLength)}));r<o.length;r++){var i=o[r];i.byteOffset=n.byteOffset,e.push(i);for(var a=e.length-1,s=0,u=this.getPropertiesWithBufferView(i);s<u.length;s++)u[s].bufferView=a;n.writeTypedArray(this._bufferViewToData.get(i)),this._bufferViewToData.delete(i)}return n.getOutputData()},e.prototype.createBufferView=function(e,t){var n={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(n,e),n},e.prototype.createAccessor=function(e,t,n,r,o,i,a){this._verifyBufferView(e);var s={bufferView:void 0,componentType:n,count:r,type:t,min:null==i?void 0:i.min,max:null==i?void 0:i.max,normalized:a,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,n=0,r=this.getPropertiesWithBufferView(e);n<r.length;n++){var o=r[n];void 0!==o.bufferView&&delete o.bufferView}this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach((function(n,r){n===e&&(void 0!==r.byteOffset&&delete r.byteOffset,t._accessorToBufferView.delete(r))}))},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"}(ne||(ne={}));var oe=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,n,r,o,i){if(this._IsTransformable(t)){var a=[],s=[],u=n.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,r,o),f=l.interpolationType,h=l.shouldBakeAnimation;if(h?e._CreateBakedAnimation(t,n,r,c.min,c.max,n.framePerSecond,i,a,s,c,o):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(t,n,r,a,s,o):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(t,n,r,a,s,o):e._CreateBakedAnimation(t,n,r,c.min,c.max,n.framePerSecond,i,a,s,c,o),a.length&&s.length)return{inputs:a,outputs:s,samplerInterpolation:f,inputsMin:h?c.min:m.Tools.FloatRound(c.min/n.framePerSecond),inputsMax:h?c.max:m.Tools.FloatRound(c.max/n.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,n="VEC3",r=!1,o=e.targetProperty.split(".");switch(o[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":n="VEC4",t="rotation";break;case"rotationQuaternion":n="VEC4",r=!0,t="rotation";break;case"influence":n="SCALAR",t="weights";break;default:m.Tools.Error("Unsupported animatable property ".concat(o[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:n,useQuaternion:r}:(m.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,n,r,o,i,a,s,u,c,l,f){var h;if(e._IsTransformable(t)&&t.animations)for(var p=0,d=t.animations;p<d.length;p++){var m=d[p];if(!f||f(m)){var g=e._DeduceAnimationInfo(m);g&&(h={name:m.name,samplers:[],channels:[]},e._AddAnimation("".concat(m.name),m.hasRunningRuntimeAnimations?n:h,t,m,g.dataAccessorType,g.animationChannelTargetPath,o,a,s,u,g.useQuaternion,c,l),h.samplers.length&&h.channels.length&&r.push(h))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,n,r,o,i,a,s,u,c,l,f){var h;if(t instanceof m.Mesh){var p=t.morphTargetManager;if(p)for(var d=0;d<p.numTargets;++d)for(var g=0,x=p.getTarget(d).animations;g<x.length;g++){var _=x[g];if(!f||f(_)){for(var v=new m.Animation("".concat(_.name),"influence",_.framePerSecond,_.dataType,_.loopMode,_.enableBlending),y=[],T=_.getKeys(),b=0;b<T.length;++b)for(var w=T[b],M=0;M<p.numTargets;++M)M==d?y.push(w):y.push({frame:w.frame,value:0});v.setKeys(y);var A=e._DeduceAnimationInfo(v);A&&(h={name:v.name,samplers:[],channels:[]},e._AddAnimation(_.name,_.hasRunningRuntimeAnimations?n:h,t,v,A.dataAccessorType,A.animationChannelTargetPath,o,a,s,u,A.useQuaternion,c,l,p.numTargets),h.samplers.length&&h.channels.length&&r.push(h))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,n,r,o,i,a,s,u,c){var l,f;if(t.animationGroups)for(var h=t.animationGroups,p=function(h){var p=new Map,g=new Map,x=new Set,_=h.to-h.from;f={name:h.name,channels:[],samplers:[]};for(var v=function(n){var _=h.targetedAnimations[n],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(w=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,w.dataAccessorType,w.animationChannelTargetPath,r,o,i,a,w.useQuaternion,s,T)}}else if(v instanceof m.MorphTarget||1===v.length&&v[0]instanceof m.MorphTarget){var w;if(w=e._DeduceAnimationInfo(_.animation)){var M=v instanceof m.MorphTarget?v:v[0];if(M){var A=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===M)return!0;return!1}));if(A){var E=t.meshes.find((function(e){return e.morphTargetManager===A}));E&&(p.has(E)||p.set(E,new Map),null===(l=p.get(E))||void 0===l||l.set(M,y),x.add(E),g.set(E,y))}}}}},y=0;y<h.targetedAnimations.length;++y)v(y);x.forEach((function(t){for(var n=t.morphTargetManager,u=null,c=[],l=g.get(t).getKeys(),d=l.length,x=0;x<d;++x)for(var v=0;v<n.numTargets;++v){var y=n.getTarget(v),T=p.get(t);if(T){var b=T.get(y);b?(u||(u=new m.Animation("".concat(h.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,m.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[x])):c.push({frame:h.from+_/d*x,value:y.influence,inTangent:l[0].inTangent?0:void 0,outTangent:l[0].outTangent?0:void 0})}}u.setKeys(c);var w=e._DeduceAnimationInfo(u);w&&e._AddAnimation("".concat(h.name,"_").concat(t.name,"_MorphWeightAnimation"),f,t,u,w.dataAccessorType,w.animationChannelTargetPath,r,o,i,a,w.useQuaternion,s,!1,null==n?void 0:n.numTargets)})),f.channels.length&&f.samplers.length&&n.push(f)},d=this,g=0,x=h;g<x.length;g++)p(x[g])},e._AddAnimation=function(t,n,r,o,i,a,s,u,c,l,f,h,p,d){var g,x,_,v,y,T,b=e._CreateNodeAnimation(r,o,a,f,h);if(b){if(d){for(var w=0,M=0,A=[];b.inputs.length>0;)M=b.inputs.shift(),w%d==0&&A.push(M),w++;b.inputs=A}var E=s.get(r),R=new Float32Array(b.inputs);g=u.createBufferView(R),x=u.createAccessor(g,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(x),_=l.length-1;var C=new m.Quaternion,V=new m.Vector3,S=new m.Vector3,I=r instanceof m.Camera,B=G(i),F=new Float32Array(b.outputs.length*B);b.outputs.forEach((function(e,t){var n=e;switch(a){case"translation":p&&(m.Vector3.FromArrayToRef(e,0,S),j(S),S.toArray(n));break;case"rotation":4===e.length?m.Quaternion.FromArrayToRef(e,0,C):(n=new Array(4),m.Vector3.FromArrayToRef(e,0,V),m.Quaternion.FromEulerVectorToRef(V,C)),p&&(z(C),I&&Q(C)),C.toArray(n)}F.set(n,t*B)})),g=u.createBufferView(F),x=u.createAccessor(g,i,5126,b.outputs.length),l.push(x),v=l.length-1,y={interpolation:b.samplerInterpolation,input:_,output:v},n.samplers.push(y),T={sampler:n.samplers.length-1,target:{node:E,path:a}},n.channels.push(T)}},e._CreateBakedAnimation=function(t,n,r,o,i,a,s,u,c,l,f){var h,p,d=m.Quaternion.Identity(),g=null,x=null,_=null,v=null,y=null,T=null;l.min=m.Tools.FloatRound(o/a);for(var b=n.getKeys(),w=0,M=b.length;w<M;++w){if(T=null,_=b[w],w+1<M)if(v=b[w+1],_.value.equals&&_.value.equals(v.value)||_.value===v.value){if(0!==w)continue;T=_.frame}else T=v.frame;else{if(y=b[w-1],_.value.equals&&_.value.equals(y.value)||_.value===y.value)continue;T=i}if(T)for(var A=_.frame;A<=T;A+=s)if((p=m.Tools.FloatRound(A/a))!==g){g=p,x=p;var E={key:0,repeatCount:0,loopMode:n.loopMode};h=n._interpolate(A,E),e._SetInterpolatedValue(t,h,p,n,r,d,u,c,f)}}x&&(l.max=x)},e._ConvertFactorToVector3OrQuaternion=function(t,n,r,o,i){var a=e._GetBasePositionRotationOrScale(n,o,i),s=r.targetProperty.split("."),u=s?s[1]:"",c=i?m.Quaternion.FromArray(a).normalize():m.Vector3.FromArray(a);switch(u){case"x":case"y":case"z":c[u]=t;break;case"w":c.w=t;break;default:m.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return c},e._SetInterpolatedValue=function(e,t,n,r,o,i,a,s,u){var c;a.push(n),"weights"!==o?(r.dataType===m.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,r,o,u)),"rotation"===o?(u?i=t:(c=t,m.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,i)),s.push(i.asArray())):(c=t,s.push(c.asArray()))):s.push([t])},e._CreateLinearOrStepAnimation=function(t,n,r,o,i,a){for(var s=0,u=n.getKeys();s<u.length;s++){var c=u[s];o.push(c.frame/n.framePerSecond),e._AddKeyframeValue(c,n,i,r,t,a)}},e._CreateCubicSplineAnimation=function(t,n,r,o,i,a){n.getKeys().forEach((function(s){o.push(s.frame/n.framePerSecond),e._AddSplineTangent(ne.INTANGENT,i,r,"CUBICSPLINE",s,a),e._AddKeyframeValue(s,n,i,r,t,a),e._AddSplineTangent(ne.OUTTANGENT,i,r,"CUBICSPLINE",s,a)}))},e._GetBasePositionRotationOrScale=function(e,t,n){var r;if("rotation"===t)if(n){var o=e.rotationQuaternion;r=(null!=o?o:m.Quaternion.Identity()).asArray()}else{var i=e.rotation;r=(null!=i?i:m.Vector3.Zero()).asArray()}else if("translation"===t){var a=e.position;r=(null!=a?a:m.Vector3.Zero()).asArray()}else{var s=e.scaling;r=(null!=s?s:m.Vector3.One()).asArray()}return r},e._AddKeyframeValue=function(e,t,n,r,o,i){var a,s=t.dataType;if(s===m.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===r){var c=m.Vector3.FromArray(u);u=m.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}n.push(u)}else if(s===m.Animation.ANIMATIONTYPE_FLOAT){if("weights"===r)n.push([e.value]);else if(a=this._ConvertFactorToVector3OrQuaternion(e.value,o,t,r,i)){if("rotation"===r){var l=i?a:m.Quaternion.RotationYawPitchRoll(a.y,a.x,a.z).normalize();n.push(l.asArray())}n.push(a.asArray())}}else s===m.Animation.ANIMATIONTYPE_QUATERNION?n.push(e.value.normalize().asArray()):m.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,n){var r,o,i=!1;if("rotation"===t&&!n)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var a=0,s=e.length;a<s;++a)if((o=e[a]).inTangent||o.outTangent)if(r){if("CUBICSPLINE"!==r){r="LINEAR",i=!0;break}}else r="CUBICSPLINE";else if(r){if("CUBICSPLINE"===r||o.interpolation&&1===o.interpolation&&"STEP"!==r){r="LINEAR",i=!0;break}}else r=o.interpolation&&1===o.interpolation?"STEP":"LINEAR";return r||(r="LINEAR"),{interpolationType:r,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,t,n,r,o,i){var a,s=e===ne.INTANGENT?o.inTangent:o.outTangent;if("CUBICSPLINE"===r){if("rotation"===n)if(s)if(i)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"===n?s?[s]:[0]:s?s.asArray():[0,0,0];t.push(a)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,n=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),n=Math.max(n,e.frame)})),{min:t,max:n}},e}();function ie(e,t,n,r,o,i){var a={attributes:{},influence:e.influence,name:e.name},s=t.geometry;if(!s)return m.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),a;var u=i?-1:1,c=m.Vector3.Zero(),l=0;if(e.hasPositions){var f=e.getPositions(),h=s.getVerticesData(m.VertexBuffer.PositionKind);if(h){var p=new Float32Array(h.length),d=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0];l=h.length/3;for(var x=0;x<l;++x){var _=m.Vector3.FromArray(h,3*x);m.Vector3.FromArray(f,3*x).subtractToRef(_,c),c.x*=u,d[0]=Math.min(d[0],c.x),g[0]=Math.max(g[0],c.x),d[1]=Math.min(d[1],c.y),g[1]=Math.max(g[1],c.y),d[2]=Math.min(d[2],c.z),g[2]=Math.max(g[2],c.z),p[3*x]=c.x,p[3*x+1]=c.y,p[3*x+2]=c.z}var v=n.createBufferView(p,12),y=n.createAccessor(v,"VEC3",5126,f.length/3,0,{min:d,max:g});o.push(y),a.attributes.POSITION=o.length-1}else m.Tools.Warn("Morph target positions for mesh ".concat(t.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var T=e.getNormals(),b=s.getVerticesData(m.VertexBuffer.NormalKind);if(b){var w=new Float32Array(b.length);for(l=b.length/3,x=0;x<l;++x){var M=m.Vector3.FromArray(b,3*x).normalize();m.Vector3.FromArray(T,3*x).normalize().subtractToRef(M,c),w[3*x]=c.x*u,w[3*x+1]=c.y,w[3*x+2]=c.z}v=n.createBufferView(w,12),y=n.createAccessor(v,"VEC3",5126,T.length/3,0),o.push(y),a.attributes.NORMAL=o.length-1}else m.Tools.Warn("Morph target normals for mesh ".concat(t.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var A=e.getTangents(),E=s.getVerticesData(m.VertexBuffer.TangentKind);if(E){l=E.length/4;var R=new Float32Array(3*l);for(x=0;x<l;++x){var C=m.Vector3.FromArray(E,4*x);q(C);var V=m.Vector3.FromArray(A,3*x);q(V),V.subtractToRef(C,c),R[3*x]=c.x*u,R[3*x+1]=c.y,R[3*x+2]=c.z}v=n.createBufferView(R,12),y=n.createAccessor(v,"VEC3",5126,l,0),o.push(y),a.attributes.TANGENT=o.length-1}else m.Tools.Warn("Morph target tangents for mesh ".concat(t.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var S=e.getColors(),I=s.getVerticesData(m.VertexBuffer.ColorKind),B=s.getVertexBuffer(m.VertexBuffer.ColorKind);if(I&&B){var F=B.getSize();l=I.length/F;var O=new Float32Array(l*F);for(x=0;x<l;++x)if(3===F){var P=m.Vector3.FromArray(I,x*F);m.Vector3.FromArray(S,x*F).subtractToRef(P,c),O[3*x]=c.x,O[3*x+1]=c.y,O[3*x+2]=c.z}else if(4===F){var N=new m.Vector4;P=m.Vector4.FromArray(I,x*F),m.Vector4.FromArray(S,x*F).subtractToRef(P,N),O[4*x]=N.x,O[4*x+1]=N.y,O[4*x+2]=N.z,O[4*x+3]=N.w}else m.Tools.Warn("Unsupported number of components for color attribute: ".concat(F));v=n.createBufferView(O,4*F),y=n.createAccessor(v,3===F?"VEC3":"VEC4",5126,l,0),o.push(y),a.attributes.COLOR_0=o.length-1}else m.Tools.Warn("Morph target colors for mesh ".concat(t.name," were not exported. Mesh does not have colors vertex data"))}return a}var ae=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,n,r,o){var i,a,s,u;return null===(u=null===(s=null===(a=null===(i=this._indicesAccessorMap.get(e))||void 0===i?void 0:i.get(t))||void 0===a?void 0:a.get(n))||void 0===s?void 0:s.get(r))||void 0===u?void 0:u.get(o)},e.prototype.setIndicesAccessor=function(e,t,n,r,o,i){var a=this._indicesAccessorMap.get(e);a||(a=new Map,this._indicesAccessorMap.set(e,a));var s=a.get(t);s||(s=new Map,a.set(t,s));var u=s.get(n);u||(u=new Map,s.set(n,u));var c=u.get(r);c||(c=new Map,u.set(r,c)),c.set(o,i)},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,n){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,n)},e.prototype.getRemappedBufferView=function(e,t){var n;return null===(n=this._remappedBufferView.get(e))||void 0===n?void 0:n.get(t)},e.prototype.getVertexAccessor=function(e,t,n){var r,o;return null===(o=null===(r=this._vertexAccessorMap.get(e))||void 0===r?void 0:r.get(t))||void 0===o?void 0:o.get(n)},e.prototype.setVertexAccessor=function(e,t,n,r){var o=this._vertexAccessorMap.get(e);o||(o=new Map,this._vertexAccessorMap.set(e,o));var i=o.get(t);i||(i=new Map,o.set(t,i)),i.set(n,r)},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 n=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,n),-1===n.indexOf(t)&&n.push(t)},e.prototype.getMorphTargetsFromMesh=function(e){return this._meshMorphTargetMap.get(e)},e}(),se=function(){function e(e,t){if(void 0===e&&(e=m.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(m.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 O(this),this._extensions={},this._bufferManager=new re,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=v({shouldExportNode:function(){return!0},shouldExportAnimation:function(){return!0},metadataSelector:function(e){var t;return null===(t=null==e?void 0:e.gltf)||void 0===t?void 0:t.extras},animationSampleRate:1/60,exportWithoutWaitingForScene:!1,exportUnusedUVs:!1,removeNoopRootNodes:!0,includeCoordinateSystemConversionNodes:!1,meshCompressionMethod:"None"},t),this._loadExtensions()}return e.prototype._ApplyExtension=function(e,t,n,r){var o=this;if(n>=t.length)return Promise.resolve(e);var i=r(t[n],e);return i?i.then((function(e){return y(o,void 0,void 0,(function(){var o;return T(this,(function(i){switch(i.label){case 0:return e?[4,this._ApplyExtension(e,t,n+1,r)]:[3,2];case 1:return o=i.sent(),[3,3];case 2:o=null,i.label=3;case 3:return[2,o]}}))}))})):this._ApplyExtension(e,t,n+1,r)},e.prototype._ApplyExtensions=function(t,n){for(var r=[],o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o];r.push(this._extensions[a])}return this._ApplyExtension(t,r,0,n)},e.prototype._extensionsPostExportNodeAsync=function(e,t,n,r,o){var i=this;return this._ApplyExtensions(t,(function(t,a){return t.postExportNodeAsync&&t.postExportNodeAsync(e,a,n,r,o,i._bufferManager)}))},e.prototype._extensionsPostExportMaterialAsync=function(e,t,n){return this._ApplyExtensions(t,(function(t,r){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,r,n)}))},e.prototype._extensionsPostExportMaterialAdditionalTextures=function(t,n,r){for(var o=[],i=0,a=e._ExtensionNames;i<a.length;i++){var s=a[i],u=this._extensions[s];u.postExportMaterialAdditionalTextures&&o.push.apply(o,u.postExportMaterialAdditionalTextures(t,n,r))}return o},e.prototype._extensionsPostExportTextures=function(t,n,r){for(var o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o],s=this._extensions[a];s.postExportTexture&&s.postExportTexture(t,n,r)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var n=0,r=e._ExtensionNames;n<r.length;n++){var o=r[n],i=this._extensions[o];i.postExportMeshPrimitive&&i.postExportMeshPrimitive(t,this._bufferManager,this._accessors)}},e.prototype._extensionsPreGenerateBinaryAsync=function(){return y(this,void 0,void 0,(function(){var t,n,r,o;return T(this,(function(i){switch(i.label){case 0:t=0,n=e._ExtensionNames,i.label=1;case 1:return t<n.length?(r=n[t],(o=this._extensions[r]).preGenerateBinaryAsync?[4,o.preGenerateBinaryAsync(this._bufferManager)]:[3,3]):[3,4];case 2:i.sent(),i.label=3;case 3:return t++,[3,1];case 4:return[2]}}))}))},e.prototype._forEachExtensions=function(t){for(var n=0,r=e._ExtensionNames;n<r.length;n++){var o=r[n],i=this._extensions[o];i.enabled&&t(i)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){var n,r,o;t.wasUsed&&((n=e._glTF).extensionsUsed||(n.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&((r=e._glTF).extensionsRequired||(r.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,n=e._ExtensionNames;t<n.length;t++){var r=n[t],o=e._ExtensionFactories[r](this);this._extensions[r]=o}},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,n){e.UnregisterExtension(t)&&m.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=n,e._ExtensionNames.push(t)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t];var n=e._ExtensionNames.indexOf(t);return-1!==n&&e._ExtensionNames.splice(n,1),!0},e.prototype._generateJSON=function(e,t,n){var r={byteLength:e};return r.byteLength&&(this._glTF.buffers=[r]),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&&(this._glTF.images=this._images),this._shouldUseGlb||(r.uri=t+".bin"),n?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)},e.prototype.generateGLTFAsync=function(e){return y(this,void 0,void 0,(function(){var t,n,r,o,i,a,s;return T(this,(function(u){switch(u.label){case 0:return[4,this._generateBinaryAsync()];case 1:if(t=u.sent(),this._extensionsOnExporting(),n=this._generateJSON(t.byteLength,e,!0),r=new Blob([t],{type:"application/octet-stream"}),o=e+".gltf",i=e+".bin",(a=new _).files[o]=n,a.files[i]=r,this._imageData)for(s in this._imageData)a.files[s]=new Blob([this._imageData[s].data],{type:this._imageData[s].mimeType});return[2,a]}}))}))},e.prototype._generateBinaryAsync=function(){return y(this,void 0,void 0,(function(){return T(this,(function(e){switch(e.label){case 0:return[4,this._exportSceneAsync()];case 1:return e.sent(),[4,this._extensionsPreGenerateBinaryAsync()];case 2:return e.sent(),[2,this._bufferManager.generateBinary(this._bufferViews)]}}))}))},e.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},e.prototype.generateGLBAsync=function(e){return y(this,void 0,void 0,(function(){var t,n,r,o,i,a,s,u,c,l,f,h,p,d;return T(this,(function(m){switch(m.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=m.sent(),this._extensionsOnExporting(),n=this._generateJSON(t.byteLength),r=e+".glb",o=n.length,"undefined"!=typeof TextEncoder&&(a=new TextEncoder,i=a.encode(n),o=i.length),s=this._getPadding(o),u=this._getPadding(t.byteLength),c=28+o+s+t.byteLength+u,(l=new ee(c)).writeUInt32(1179937895),l.writeUInt32(2),l.writeUInt32(c),l.writeUInt32(o+s),l.writeUInt32(1313821514),i)l.writeTypedArray(i);else for(f="_".charCodeAt(0),p=0;p<o;++p)(h=n.charCodeAt(p))!=n.codePointAt(p)?l.writeUInt8(f):l.writeUInt8(h);for(p=0;p<s;++p)l.writeUInt8(32);for(l.writeUInt32(t.byteLength+u),l.writeUInt32(5130562),l.writeTypedArray(t),p=0;p<u;++p)l.writeUInt8(0);return(d=new _).files[r]=new Blob([l.getOutputData()],{type:"application/octet-stream"}),[2,d]}}))}))},e.prototype._setNodeTransformation=function(e,t,n){var r;if(t.getPivotPoint().equalsWithEpsilon(U,m.Epsilon)||m.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsWithEpsilon(U,m.Epsilon)){var o=m.TmpVectors.Vector3[0].copyFrom(t.position);n&&j(o),e.translation=o.asArray()}t.scaling.equalsWithEpsilon(k,m.Epsilon)||(e.scale=t.scaling.asArray());var i=(null===(r=t.rotationQuaternion)||void 0===r?void 0:r.clone())||m.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);i.equalsWithEpsilon(L,m.Epsilon)||(n&&z(i),e.rotation=i.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,n){if(!t.position.equalsWithEpsilon(U,m.Epsilon)){var r=m.TmpVectors.Vector3[0].copyFrom(t.position);n&&j(r),e.translation=r.asArray()}var o=t.rotationQuaternion||m.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);n&&z(o),this._babylonScene.useRightHandedSystem||Q(o),o.equalsWithEpsilon(L,m.Epsilon)||(e.rotation=o.asArray())},e.prototype._listAvailableCameras=function(){for(var e=0,t=this._babylonScene.cameras;e<t.length;e++){var n=t[e],r={type:n.mode===m.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(n.name&&(r.name=n.name),"perspective"===r.type)r.perspective={aspectRatio:n.getEngine().getAspectRatio(n),yfov:n.fovMode===m.Camera.FOVMODE_VERTICAL_FIXED?n.fov:n.fov*n.getEngine().getAspectRatio(n),znear:n.minZ,zfar:n.maxZ};else if("orthographic"===r.type){var o=n.orthoLeft&&n.orthoRight?.5*(n.orthoRight-n.orthoLeft):.5*n.getEngine().getRenderWidth(),i=n.orthoBottom&&n.orthoTop?.5*(n.orthoTop-n.orthoBottom):.5*n.getEngine().getRenderHeight();r.orthographic={xmag:o,ymag:i,znear:n.minZ,zfar:n.maxZ}}this._camerasMap.set(n,r)}},e.prototype._exportAndAssignCameras=function(){for(var e=0,t=Array.from(this._camerasMap.values());e<t.length;e++){var n=t[e],r=this._nodesCameraMap.get(n);if(void 0!==r){this._cameras.push(n);for(var o=0,i=r;o<i.length;o++)i[o].camera=this._cameras.length-1}}},e.prototype._listAvailableSkeletons=function(){for(var e=0,t=this._babylonScene.skeletons;e<t.length;e++){var n=t[e];n.bones.length<=0||this._skinMap.set(n,{joints:[]})}},e.prototype._exportAndAssignSkeletons=function(e){for(var t,n=function(n){if(n.bones.length<=0)return"continue";var o=r._skinMap.get(n);if(null==o)return"continue";for(var i={},a=-1,s=0;s<n.bones.length;++s){var u=n.bones[s];-1!==(f=null!==(t=u.getIndex())&&void 0!==t?t:s)&&(i[f]=u,f>a&&(a=f))}for(var c,l=[],f=0;f<=a;++f){var h=(u=i[f]).getTransformNode(),p=h?r._nodeMap.get(h):void 0;if(void 0!==p){o.joints.push(p);var d=u.getAbsoluteInverseBindMatrix().clone();e.has(h)&&(c=d,P.invertToRef(m.TmpVectors.Matrix[0]).multiplyToRef(c,c).multiplyToRef(P,c)),l.push(d)}else m.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.")}var g=r._nodesSkinMap.get(o);if(o.joints.length>0&&void 0!==g){var x=new Float32Array(16*l.length);l.forEach((function(e,t){x.set(e.m,16*t)}));var _=r._bufferManager.createBufferView(x);r._accessors.push(r._bufferManager.createAccessor(_,"MAT4",5126,l.length)),o.inverseBindMatrices=r._accessors.length-1,r._skins.push(o);for(var v=r._skins.length-1,y=0,T=g;y<T.length;y++)T[y].skin=v}},r=this,o=0,i=this._babylonScene.skeletons;o<i.length;o++)n(i[o])},e.prototype._exportSceneAsync=function(){return y(this,void 0,void 0,(function(){var e,t,n,r,o,i,a,s,u,c,l,f,h,p,d,m,g,x,_,v,y,b,w;return T(this,(function(T){switch(T.label){case 0:for(e={nodes:[]},this._babylonScene.metadata&&(t=this._options.metadataSelector(this._babylonScene.metadata))&&(e.extras=t),n=new Array,r=new Array,o=new Array,i=0,a=this._babylonScene.rootNodes;i<a.length;i++)s=a[i],this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&N(s,this._babylonScene.useRightHandedSystem)?o.push.apply(o,s.getChildren()):this._babylonScene.useRightHandedSystem?n.push(s):r.push(s);return this._listAvailableCameras(),this._listAvailableSkeletons(),u=new ae(!0,!1),l=(c=(y=e.nodes).push).apply,f=[y],[4,this._exportNodesAsync(r,u)];case 1:return l.apply(c,f.concat([T.sent()])),h=new ae(!1,!1),d=(p=(b=e.nodes).push).apply,m=[b],[4,this._exportNodesAsync(n,h)];case 2:return d.apply(p,m.concat([T.sent()])),g=new ae(!1,!0),_=(x=(w=e.nodes).push).apply,v=[w],[4,this._exportNodesAsync(o,g)];case 3:return _.apply(x,v.concat([T.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(u.getNodesSet()),this._babylonScene.animationGroups.length&&oe._CreateNodeAndMorphAnimationFromAnimationGroups(this._babylonScene,this._animations,this._nodeMap,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,u.getNodesSet(),this._options.shouldExportAnimation),[2]}}))}))},e.prototype._shouldExportNode=function(e){var t=this._shouldExportNodeMap.get(e);return void 0===t&&(t=this._options.shouldExportNode(e),this._shouldExportNodeMap.set(e,t)),t},e.prototype._exportNodesAsync=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,i;return T(this,(function(a){switch(a.label){case 0:n=new Array,this._exportBuffers(e,t),r=0,o=e,a.label=1;case 1:return r<o.length?(i=o[r],[4,this._exportNodeAsync(i,n,t)]):[3,4];case 2:a.sent(),a.label=3;case 3:return r++,[3,1];case 4:return[2,n]}}))}))},e.prototype._collectBuffers=function(e,t,n,r,o){if(this._shouldExportNode(e)&&e instanceof m.AbstractMesh&&e.geometry){var i=e.geometry.getVertexBuffers();if(i)for(var a in i)if(W(a)){var s=i[a];o.setHasVertexColorAlpha(s,e.hasVertexAlpha);var u=s._buffer,c=t.get(u)||[];t.set(u,c),-1===c.indexOf(s)&&c.push(s);var l=n.get(s)||[];n.set(s,l),-1===l.indexOf(e)&&l.push(e)}var f=e.morphTargetManager;if(f)for(var h=0;h<f.numTargets;h++){var p=f.getTarget(h);l=r.get(p)||[],r.set(p,l),-1===l.indexOf(e)&&l.push(e)}}for(var d=0,g=e.getChildren();d<g.length;d++){var x=g[d];this._collectBuffers(x,t,n,r,o)}},e.prototype._exportBuffers=function(e,t){for(var n=new Map,r=new Map,o=new Map,i=0,a=e;i<a.length;i++){var s=a[i];this._collectBuffers(s,n,r,o,t)}for(var u=Array.from(n.keys()),c=function(e){var o=e.getData();if(!o)throw new Error("Buffer data is not available");var i=n.get(e);if(!i)return"continue";var a=i[0].byteStride;if(i.some((function(e){return e.byteStride!==a})))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");for(var s=function(e){if(e instanceof Array){var t=new Float32Array(e);return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}return ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e)}(o).slice(),u=function(e){var t=r.get(e),n=K(e,t),o=n.byteOffset,i=n.byteStride,a=n.componentCount,u=n.type,c=n.count,f=n.normalized;switch(n.kind){case m.VertexBuffer.NormalKind:case m.VertexBuffer.TangentKind:(0,m.EnumerateFloatValues)(s,o,i,a,u,c,f,(function(e){var t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){var n=1/t;e[0]*=n,e[1]*=n,e[2]*=n}}));break;case m.VertexBuffer.ColorKind:var h=t.filter((function(e){return e.material instanceof m.StandardMaterial||null==e.material})).length;if(0==h)break;if(h!=t.length){m.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}u==m.VertexBuffer.UNSIGNED_BYTE&&m.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var p=new m.Color3,d=new m.Color4,g=l._babylonScene.getEngine().useExactSrgbConversions;(0,m.EnumerateFloatValues)(s,o,i,a,u,c,f,(function(e){3===e.length?(p.fromArray(e,0),p.toLinearSpaceToRef(p,g),p.toArray(e,0)):(d.fromArray(e,0),d.toLinearSpaceToRef(d,g),d.toArray(e,0))}))}},c=0,f=i;c<f.length;c++)u(B=f[c]);if(t.convertToRightHanded){for(var h=0,p=i;h<p.length;h++){var d=K(B=p[h],r.get(B)),g=d.byteOffset,x=d.byteStride,_=d.componentCount,v=d.type,y=d.count,T=d.normalized;switch(R=d.kind){case m.VertexBuffer.PositionKind:case m.VertexBuffer.NormalKind:case m.VertexBuffer.TangentKind:(0,m.EnumerateFloatValues)(s,g,x,_,v,y,T,(function(e){e[0]=-e[0]}))}}t.convertedToRightHandedBuffers.set(e,s)}var b=l._bufferManager.createBufferView(s,a);t.setVertexBufferView(e,b);for(var w=new Map,M=0,A=i;M<A.length;M++){var E=K(B=A[M],r.get(B)),R=E.kind,C=E.totalVertices;switch(R){case m.VertexBuffer.MatricesIndicesKind:case m.VertexBuffer.MatricesIndicesExtraKind:if(B.type==m.VertexBuffer.FLOAT){var V=B.getFloatData(C);null!==V&&w.set(B,V)}}}0!==w.size&&m.Logger.Warn("Joint indices conversion needed: some joint indices are stored as floats in Babylon but GLTF requires UNSIGNED BYTES. We will perform the conversion but this might lead to unused data in the buffer.");for(var S=0,I=Array.from(w.keys());S<I.length;S++){var B=I[S],F=w.get(B);if(F){for(var O=F.some((function(e){return e>=256})),P=new(O?Uint16Array:Uint8Array)(F.length),N=0;N<F.length;N++)P[N]=F[N];var U=l._bufferManager.createBufferView(P,4*(O?2:1));t.setRemappedBufferView(e,B,U)}}},l=this,f=0,h=u;f<h.length;f++)c(h[f]);for(var p=0,d=Array.from(o.keys());p<d.length;p++){var g=d[p],x=o.get(g);if(x)for(var _=ie(g,x[0],this._bufferManager,this._bufferViews,this._accessors,t.convertToRightHanded),v=0,y=x;v<y.length;v++){var T=y[v];t.bindMorphDataToMesh(T,_)}}},e.prototype._exportNodeAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var r,o,i,a,s,u,c,l,f=this;return T(this,(function(h){switch(h.label){case 0:return void 0!==(r=this._nodeMap.get(e))?(t.includes(r)||t.push(r),[2]):[4,this._createNodeAsync(e,n)];case 1:(o=h.sent())&&(r=this._nodes.length,this._nodes.push(o),this._nodeMap.set(e,r),n.pushExportedNode(e),t.push(r),i={name:"runtime animations",channels:[],samplers:[]},a=[],this._babylonScene.animationGroups.length||(oe._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,a,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&oe._CreateNodeAnimationFromNodeAnimations(e,i,a,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation)),i.channels.length&&i.samplers.length&&this._animations.push(i),a.forEach((function(e){e.channels.length&&e.samplers.length&&f._animations.push(e)}))),s=o?[]:t,u=0,c=e.getChildren(),h.label=2;case 2:return u<c.length?(l=c[u],[4,this._exportNodeAsync(l,s,n)]):[3,5];case 3:h.sent(),h.label=4;case 4:return u++,[3,2];case 5:return o&&s.length&&(o.children=s),[2]}}))}))},e.prototype._createNodeAsync=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,i,a,s,u,c,l,f,h,p;return T(this,(function(d){switch(d.label){case 0:return this._shouldExportNode(e)?(n={},e.name&&(n.name=e.name),e.metadata&&(r=this._options.metadataSelector(e.metadata))&&(n.extras=r),e instanceof m.TransformNode?(this._setNodeTransformation(n,e,t.convertToRightHanded),e instanceof m.AbstractMesh?(o=e instanceof m.InstancedMesh?e.sourceMesh:e).subMeshes&&o.subMeshes.length>0?(i=n,[4,this._exportMeshAsync(o,t)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:i.mesh=d.sent(),d.label=2;case 2:e.skeleton&&void 0!==(a=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(a)&&this._nodesSkinMap.set(a,[]),null===(f=this._nodesSkinMap.get(a))||void 0===f||f.push(n)),d.label=3;case 3:if(e instanceof m.TargetCamera&&(s=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(s)&&this._nodesCameraMap.set(s,[]),this._setCameraTransformation(n,e,t.convertToRightHanded),null!==(u=e.parent)&&Y(e,u)&&void 0!==(c=this._nodeMap.get(u)))return l=this._nodes[c],X(n,l),null===(h=this._nodesCameraMap.get(s))||void 0===h||h.push(l),[2,null];null===(p=this._nodesCameraMap.get(s))||void 0===p||p.push(n)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",n,e,this._nodeMap,t.convertToRightHanded)];case 4:return d.sent()?[2,n]:(m.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}}))}))},e.prototype._exportIndices=function(e,t,n,r,o,i,a,s,u){var c=e;u.mode=H(i);var l=a!==m.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case m.Material.TriangleFillMode:case m.Material.TriangleStripDrawMode:case m.Material.TriangleFanDrawMode:return!0}return!1}(i);if(l){if(i===m.Material.TriangleStripDrawMode||i===m.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");u.mode=H(i);var f=t?new Uint32Array(r):new Uint16Array(r);if(e)for(var h=0;h+2<r;h+=3)f[h]=e[n+h]+o,f[h+1]=e[n+h+2]+o,f[h+2]=e[n+h+1]+o;else for(h=0;h+2<r;h+=3)f[h]=h,f[h+1]=h+2,f[h+2]=h+1;c=f}else if(e&&0!==o){for(f=t?new Uint32Array(r):new Uint16Array(r),h=0;h<r;h++)f[h]=e[n+h]+o;c=f}if(c){var p=s.getIndicesAccessor(e,n,r,o,l);if(void 0===p){var d=function(e,t,n,r){if(e instanceof Uint16Array||e instanceof Uint32Array)return e;if(e instanceof Int32Array)return new Uint32Array(e.buffer,e.byteOffset,e.length);var o=e.slice(0,0+n);return r?new Uint32Array(o):new Uint16Array(o)}(c,0,r,t),g=this._bufferManager.createBufferView(d),x=t?5125:5123;this._accessors.push(this._bufferManager.createAccessor(g,"SCALAR",x,r,0)),p=this._accessors.length-1,s.setIndicesAccessor(e,n,r,o,l,p)}u.indices=p}},e.prototype._exportVertexBuffer=function(e,t,n,r,o,i){var a=e.getKind();if(W(a)&&(!a.startsWith("uv")||this._options.exportUnusedUVs||t&&this._materialNeedsUVsSet.has(t))){var s=o.getVertexAccessor(e,n,r);if(void 0===s){var u=o.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),c=a===m.VertexBuffer.PositionKind?function(e,t,n,r){var o=t.byteOffset,i=t.byteStride,a=t.type,s=t.normalized,u=t.getSize(),c=new Array(u).fill(1/0),l=new Array(u).fill(-1/0);return(0,m.EnumerateFloatValues)(e,o+n*i,i,u,a,r*u,s,(function(e){for(var t=0;t<u;t++)c[t]=Math.min(c[t],e[t]),l[t]=Math.max(l[t],e[t])})),{min:c,max:l}}(u,e,n,r):void 0,l=(a===m.VertexBuffer.MatricesIndicesKind||a===m.VertexBuffer.MatricesIndicesExtraKind)&&e.type===m.VertexBuffer.FLOAT,f=l?m.VertexBuffer.UNSIGNED_BYTE:e.type,h=l?void 0:e.normalized,p=l?o.getRemappedBufferView(e._buffer,e):o.getVertexBufferView(e._buffer),d=e.byteOffset+n*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(p,function(e,t){if(e==m.VertexBuffer.ColorKind)return t?"VEC4":"VEC3";switch(e){case m.VertexBuffer.PositionKind:case m.VertexBuffer.NormalKind:return"VEC3";case m.VertexBuffer.TangentKind:case m.VertexBuffer.MatricesIndicesKind:case m.VertexBuffer.MatricesIndicesExtraKind:case m.VertexBuffer.MatricesWeightsKind:case m.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case m.VertexBuffer.UVKind:case m.VertexBuffer.UV2Kind:case m.VertexBuffer.UV3Kind:case m.VertexBuffer.UV4Kind:case m.VertexBuffer.UV5Kind:case m.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(a,o.hasVertexColorAlpha(e)),f,r,d,c,h)),s=this._accessors.length-1,o.setVertexAccessor(e,n,r,s)}i.attributes[function(e){switch(e){case m.VertexBuffer.PositionKind:return"POSITION";case m.VertexBuffer.NormalKind:return"NORMAL";case m.VertexBuffer.TangentKind:return"TANGENT";case m.VertexBuffer.ColorKind:return"COLOR_0";case m.VertexBuffer.UVKind:return"TEXCOORD_0";case m.VertexBuffer.UV2Kind:return"TEXCOORD_1";case m.VertexBuffer.UV3Kind:return"TEXCOORD_2";case m.VertexBuffer.UV4Kind:return"TEXCOORD_3";case m.VertexBuffer.UV5Kind:return"TEXCOORD_4";case m.VertexBuffer.UV6Kind:return"TEXCOORD_5";case m.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case m.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case m.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case m.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(a)]=s}},e.prototype._exportMaterialAsync=function(e,t,n,r){return y(this,void 0,void 0,(function(){var o,i;return T(this,(function(a){switch(a.label){case 0:return void 0!==(o=this._materialMap.get(e))?[3,6]:(i=t&&Object.keys(t).some((function(e){return e.startsWith("uv")})),(e=e instanceof m.MultiMaterial?e.subMaterials[n.materialIndex]:e)instanceof m.PBRBaseMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,i)]:[3,2]);case 1:return o=a.sent(),[3,5];case 2:return e instanceof m.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,i)]:[3,4];case 3:return o=a.sent(),[3,5];case 4:return m.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 5:this._materialMap.set(e,o),a.label=6;case 6:return r.material=o,[2]}}))}))},e.prototype._exportMeshAsync=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,i,a,s,u,c,l,f,h,p,d,g,x,_,v,y,w,M,A,E,R,C,V,S,I,B,F,O,P,N,U,L;return T(this,(function(T){switch(T.label){case 0:if(void 0!==(n=t.getMesh(e)))return[2,n];if(r={primitives:[]},n=this._meshes.length,this._meshes.push(r),t.setMesh(e,n),o=e.isUnIndexed?null:e.getIndices(),i=null===(F=e.geometry)||void 0===F?void 0:F.getVertexBuffers(),a=t.getMorphTargetsFromMesh(e),s=e instanceof m.LinesMesh,u=e instanceof m.GreasedLineBaseMesh,c=e.subMeshes,!(i&&c&&c.length>0))return[3,7];l=0,f=c,T.label=1;case 1:return l<f.length?(h=f[l],p={attributes:{}},d=h.getMaterial()||this._babylonScene.defaultMaterial,u?(v={name:d.name},y=e,g=m.Color3.White(),x=null!==(P=null===(O=y.material)||void 0===O?void 0:O.alpha)&&void 0!==P?P:1,(!(_=null!==(U=null===(N=y.greasedLineMaterial)||void 0===N?void 0:N.color)&&void 0!==U?U:g).equalsWithEpsilon(g,m.Epsilon)||x<1)&&(v.pbrMetallicRoughness={baseColorFactor:b(b([],_.asArray(),!0),[x],!1)}),this._materials.push(v),p.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return s?(v={name:d.name},(!(y=e).color.equalsWithEpsilon(m.Color3.White(),m.Epsilon)||y.alpha<1)&&(v.pbrMetallicRoughness={baseColorFactor:b(b([],y.color.asArray(),!0),[y.alpha],!1)}),this._materials.push(v),p.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(d,i,h,p)];case 4:T.sent(),T.label=5;case 5:for(w=s||u?m.Material.LineListDrawMode:null!==(L=e.overrideRenderingFillMode)&&void 0!==L?L:d.fillMode,M=d._getEffectiveOrientation(e),t.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(M=M===m.Material.ClockWiseSideOrientation?m.Material.CounterClockWiseSideOrientation:m.Material.ClockWiseSideOrientation),this._exportIndices(o,o?(0,m.AreIndices32Bits)(o,h.indexCount,h.indexStart,h.verticesStart):h.verticesCount>65535,o?h.indexStart:h.verticesStart,o?h.indexCount:h.verticesCount,-h.verticesStart,w,M,t,p),A=0,E=Object.values(i);A<E.length;A++)R=E[A],this._exportVertexBuffer(R,d,h.verticesStart,h.verticesCount,t,p);if(a)for(p.targets=[],C=0,V=a;C<V.length;C++)B=V[C],p.targets.push(B.attributes);r.primitives.push(p),this._extensionsPostExportMeshPrimitive(p),T.label=6;case 6:return l++,[3,1];case 7:if(a)for(r.weights=[],r.extras||(r.extras={}),r.extras.targetNames=[],S=0,I=a;S<I.length;S++)B=I[S],r.weights.push(B.influence),r.extras.targetNames.push(B.name);return[2,n]}}))}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),ue=function(){function e(){}return e.GLTFAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var r,o;return T(this,(function(i){switch(i.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(r=new se(e,n)).generateGLTFAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=i.sent(),r.dispose(),[2,o]}}))}))},e.GLBAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var r,o;return T(this,(function(i){switch(i.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(r=new se(e,n)).generateGLBAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=i.sent(),r.dispose(),[2,o]}}))}))},e}(),ce="EXT_mesh_gpu_instancing",le=function(){function e(e){this.name=ce,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportNodeAsync=function(e,t,n,r,o,i){return y(this,void 0,void 0,(function(){var e=this;return T(this,(function(r){switch(r.label){case 0:return[4,new Promise((function(r){if(t&&n instanceof m.Mesh&&n.hasThinInstances&&e._exporter){e._wasUsed=!0;for(var a=m.Vector3.Zero(),s=m.Quaternion.Identity(),u=m.Vector3.One(),c=n.thinInstanceGetWorldMatrices(),l=m.TmpVectors.Vector3[2],f=m.TmpVectors.Quaternion[1],h=m.TmpVectors.Vector3[3],p=!1,d=!1,g=!1,x=new Float32Array(3*n.thinInstanceCount),_=new Float32Array(4*n.thinInstanceCount),v=new Float32Array(3*n.thinInstanceCount),y=0,T=0,b=c;T<b.length;T++)b[T].decompose(h,f,l),o&&(j(l),z(f)),x.set(l.asArray(),3*y),_.set(f.normalize().asArray(),4*y),v.set(h.asArray(),3*y),p=p||!l.equalsWithEpsilon(a),d=d||!f.equalsWithEpsilon(s),g=g||!h.equalsWithEpsilon(u),y++;var w={attributes:{}};p&&(w.attributes.TRANSLATION=e._buildAccessor(x,"VEC3",n.thinInstanceCount,i)),d&&(w.attributes.ROTATION=e._buildAccessor(_,"VEC4",n.thinInstanceCount,i)),g&&(w.attributes.SCALE=e._buildAccessor(v,"VEC3",n.thinInstanceCount,i)),t.extensions=t.extensions||{},t.extensions[ce]=w}r(t)}))];case 1:return[2,r.sent()]}}))}))},e.prototype._buildAccessor=function(e,t,n,r){var o=r.createBufferView(e),i=r.createAccessor(o,t,5126,n);return this._exporter._accessors.push(i),this._exporter._accessors.length-1},e}();se.RegisterExtension(ce,(function(e){return new le(e)}));var fe="KHR_draco_mesh_compression",he=function(){function e(e){this.name=fe,this.required=!0,this._bufferViewsUsed=new Set,this._accessorsUsed=new Set,this._encodePromises=[],this._wasUsed=!1,this.enabled="Draco"===e.options.meshCompressionMethod&&m.DracoEncoder.DefaultAvailable}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMeshPrimitive=function(e,t,n){var r=this;if(this.enabled)if(4===e.mode||5===e.mode){var o=[],i=[],a=null;if(void 0!==e.indices){var s=n[e.indices],u=t.getBufferView(s);a=t.getData(u).slice(),o.push(u),i.push(s)}for(var c,l=[],f=0,h=Object.entries(e.attributes);f<h.length;f++){var p=h[f],d=p[0],g=(s=n[p[1]],u=t.getBufferView(s),G(s.type)),x=(0,m.GetTypedArrayData)(t.getData(u),g,s.componentType,s.byteOffset||0,u.byteStride||(0,m.GetTypeByteLength)(s.componentType)*g,s.normalized||!1,s.count,!0);l.push({kind:d,dracoName:(c=d,"POSITION"===c?"POSITION":"NORMAL"===c?"NORMAL":c.startsWith("COLOR")?"COLOR":c.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"),size:G(s.type),data:x}),o.push(u),i.push(s)}var _={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},v=m.DracoEncoder.Default._encodeAsync(l,a,_).then((function(n){if(n){var a={bufferView:-1,attributes:n.attributeIds},s=t.createBufferView(n.data);t.setBufferView(a,s);for(var u=0,c=o;u<c.length;u++){var l=c[u];r._bufferViewsUsed.add(l)}for(var f=0,h=i;f<h.length;f++){var p=h[f];r._accessorsUsed.add(p)}e.extensions||(e.extensions={}),e.extensions[fe]=a}else m.Logger.Error("Draco encoding failed for primitive.")})).catch((function(e){m.Logger.Error("Draco encoding failed for primitive: "+e)}));this._encodePromises.push(v),this._wasUsed=!0}else m.Logger.Warn("Cannot compress primitive with mode "+e.mode+".")},e.prototype.preGenerateBinaryAsync=function(e){return y(this,void 0,void 0,(function(){var t=this;return T(this,(function(n){switch(n.label){case 0:return this.enabled?[4,Promise.all(this._encodePromises)]:[2];case 1:return n.sent(),this._bufferViewsUsed.forEach((function(n){e.getPropertiesWithBufferView(n).every((function(e){return t._accessorsUsed.has(e)}))&&e.removeBufferView(n)})),this._bufferViewsUsed.clear(),this._accessorsUsed.clear(),[2]}}))}))},e}();se.RegisterExtension(fe,(function(e){return new he(e)}));var pe="KHR_lights_punctual",de={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},me={innerConeAngle:0,outerConeAngle:Math.PI/4},ge=m.Vector3.Backward(),xe=function(){function e(e){this.name=pe,this.enabled=!0,this.required=!1,this._exporter=e}return e.prototype.dispose=function(){this._lights=null},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return!!this._lights},enumerable:!1,configurable:!0}),e.prototype.onExporting=function(){this._exporter._glTF.extensions[pe]=this._lights},e.prototype.postExportNodeAsync=function(e,t,n,r,o){return y(this,void 0,void 0,(function(){var i=this;return T(this,(function(a){switch(a.label){case 0:return[4,new Promise((function(a){if(n instanceof m.Light){var s=n.getTypeID()==m.Light.LIGHTTYPEID_POINTLIGHT?"point":n.getTypeID()==m.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":n.getTypeID()==m.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(s&&n instanceof m.ShadowLight))return m.Logger.Warn("".concat(e,": Light ").concat(n.name," is not supported in ").concat(pe)),void a(t);if(n.falloffType!==m.Light.FALLOFF_GLTF&&m.Logger.Warn("".concat(e,": Light falloff for ").concat(n.name," does not match the ").concat(pe," specification!")),!n.position.equalsToFloats(0,0,0)){var u=m.TmpVectors.Vector3[0].copyFrom(n.position);o&&j(u),t.translation=u.asArray()}if("point"!==s){var c=n.direction.normalizeToRef(m.TmpVectors.Vector3[0]);o&&j(c);var l=m.Quaternion.FromUnitVectorsToRef(ge,c,m.TmpVectors.Quaternion[0]);m.Quaternion.IsIdentity(l)||(t.rotation=l.asArray())}var f={type:s,name:n.name,color:n.diffuse.asArray(),intensity:n.intensity,range:n.range};if(Z(f,de),"spot"===s){var h=n;f.spot={innerConeAngle:h.innerAngle/2,outerConeAngle:h.angle/2},Z(f.spot,me)}i._lights||(i._lights={lights:[]}),i._lights.lights.push(f);var p={light:i._lights.lights.length-1},d=n.parent;if(d&&Y(n,d)){var g=r.get(d);if(g){var x=i._exporter._nodes[g];return X(t,x),x.extensions||(x.extensions={}),x.extensions[pe]=p,void a(null)}}t.extensions||(t.extensions={}),t.extensions[pe]=p,a(t)}else a(t)}))];case 1:return[2,a.sent()]}}))}))},e}();se.RegisterExtension(pe,(function(e){return new xe(e)}));var _e="KHR_materials_anisotropy",ve=function(){function e(e){this.name=_e,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,n){var r=[];return n instanceof m.PBRBaseMaterial&&n.anisotropy.isEnabled&&!n.anisotropy.legacy?(n.anisotropy.texture&&r.push(n.anisotropy.texture),r):[]},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof m.PBRBaseMaterial){if(!n.anisotropy.isEnabled||n.anisotropy.legacy)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var o=r._exporter._materialExporter.getTextureInfo(n.anisotropy.texture),i={anisotropyStrength:n.anisotropy.intensity,anisotropyRotation:n.anisotropy.angle,anisotropyTexture:null!=o?o:void 0};null!==i.anisotropyTexture&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[_e]=i}e(t)}))},e}();se.RegisterExtension(_e,(function(e){return new ve(e)}));var ye="KHR_materials_clearcoat",Te=function(){function e(e){this.name=ye,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,n){var r=[];return n instanceof m.PBRBaseMaterial&&n.clearCoat.isEnabled?(n.clearCoat.texture&&r.push(n.clearCoat.texture),!n.clearCoat.useRoughnessFromMainTexture&&n.clearCoat.textureRoughness&&r.push(n.clearCoat.textureRoughness),n.clearCoat.bumpTexture&&r.push(n.clearCoat.bumpTexture),r):[]},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof m.PBRBaseMaterial){if(!n.clearCoat.isEnabled)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var o,i=r._exporter._materialExporter.getTextureInfo(n.clearCoat.texture);o=n.clearCoat.useRoughnessFromMainTexture?r._exporter._materialExporter.getTextureInfo(n.clearCoat.texture):r._exporter._materialExporter.getTextureInfo(n.clearCoat.textureRoughness),n.clearCoat.isTintEnabled&&m.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(n.name)),n.clearCoat.remapF0OnInterfaceChange&&m.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(n.name));var a=r._exporter._materialExporter.getTextureInfo(n.clearCoat.bumpTexture),s={clearcoatFactor:n.clearCoat.intensity,clearcoatTexture:null!=i?i:void 0,clearcoatRoughnessFactor:n.clearCoat.roughness,clearcoatRoughnessTexture:null!=o?o:void 0,clearcoatNormalTexture:null!=a?a:void 0};null===s.clearcoatTexture&&null===s.clearcoatRoughnessTexture&&null===s.clearcoatRoughnessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[ye]=s}e(t)}))},e}();se.RegisterExtension(ye,(function(e){return new Te(e)}));var be="KHR_materials_diffuse_transmission";function we(e,t){var n=t.subSurface,r=null;return n.translucencyIntensityTexture?r=n.translucencyIntensityTexture:n.thicknessTexture&&n.useMaskFromThicknessTexture&&(r=n.thicknessTexture),r&&!n.useGltfStyleTextures?(m.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(t.name),1),null):r}var Me=function(){function e(e){this.name=be,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,n){var r=[];if(n instanceof m.PBRMaterial&&this._isExtensionEnabled(n)){var o=we(e,n);return o&&r.push(o),n.subSurface.translucencyColorTexture&&r.push(n.subSurface.translucencyColorTexture),r}return r},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!!t.isTranslucencyEnabled&&!e.unlit&&!t.useAlbedoToTintTranslucency&&t.useGltfStyleTextures&&1===t.volumeIndexOfRefraction&&0===t.minimumThickness&&0===t.maximumThickness},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(o){var i,a;if(n instanceof m.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var s=n.subSurface,u=we(e,n),c=0==s.translucencyIntensity?void 0:s.translucencyIntensity,l=null!==(i=r._exporter._materialExporter.getTextureInfo(u))&&void 0!==i?i:void 0,f=!s.translucencyColor||s.translucencyColor.equalsFloats(1,1,1)?void 0:s.translucencyColor.asArray(),h=null!==(a=r._exporter._materialExporter.getTextureInfo(s.translucencyColorTexture))&&void 0!==a?a:void 0,p={diffuseTransmissionFactor:c,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:f,diffuseTransmissionColorTexture:h};(l||h)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions=t.extensions||{},t.extensions[be]=p}o(t)}))},e}();se.RegisterExtension(be,(function(e){return new Me(e)}));var Ae="KHR_materials_dispersion",Ee=function(){function e(){this.name=Ae,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isDispersionEnabled)},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof m.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var o={dispersion:n.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[Ae]=o}e(t)}))},e}();se.RegisterExtension(Ae,(function(){return new Ee}));var Re="KHR_materials_emissive_strength",Ce=function(){function e(){this.name=Re,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e=this;return T(this,(function(r){switch(r.label){case 0:return[4,new Promise((function(r){if(!(n instanceof m.PBRMaterial))return r(t);var o=n.emissiveColor.asArray(),i=Math.max.apply(Math,o);if(i>1){e._wasUsed=!0,t.extensions||(t.extensions={});var a={emissiveStrength:i},s=n.emissiveColor.scale(1/a.emissiveStrength);t.emissiveFactor=s.asArray(),t.extensions[Re]=a}return r(t)}))];case 1:return[2,r.sent()]}}))}))},e}();se.RegisterExtension(Re,(function(e){return new Ce}));var Ve="KHR_materials_ior",Se=function(){function e(){this.name=Ve,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){return!e.unlit&&null!=e.indexOfRefraction&&1.5!=e.indexOfRefraction},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof m.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var o={ior:n.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[Ve]=o}e(t)}))},e}();se.RegisterExtension(Ve,(function(e){return new Se}));var Ie="KHR_materials_iridescence",Be=function(){function e(e){this.name=Ie,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,n){var r=[];return n instanceof m.PBRBaseMaterial&&n.iridescence.isEnabled?(n.iridescence.texture&&r.push(n.iridescence.texture),n.iridescence.thicknessTexture&&n.iridescence.thicknessTexture!==n.iridescence.texture&&r.push(n.iridescence.thicknessTexture),r):[]},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof m.PBRBaseMaterial){if(!n.iridescence.isEnabled)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var o=r._exporter._materialExporter.getTextureInfo(n.iridescence.texture),i=r._exporter._materialExporter.getTextureInfo(n.iridescence.thicknessTexture),a={iridescenceFactor:n.iridescence.intensity,iridescenceIor:n.iridescence.indexOfRefraction,iridescenceThicknessMinimum:n.iridescence.minimumThickness,iridescenceThicknessMaximum:n.iridescence.maximumThickness,iridescenceTexture:null!=o?o:void 0,iridescenceThicknessTexture:null!=i?i:void 0};null===a.iridescenceTexture&&null===a.iridescenceThicknessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[Ie]=a}e(t)}))},e}();se.RegisterExtension(Ie,(function(e){return new Be(e)}));var Fe="KHR_materials_sheen",Oe=function(){function e(e){this.name=Fe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,n){return n instanceof m.PBRMaterial&&n.sheen.isEnabled&&n.sheen.texture?[n.sheen.texture]:[]},e.prototype.postExportMaterialAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e=this;return T(this,(function(r){switch(r.label){case 0:return[4,new Promise((function(r){var o,i,a,s;if(n instanceof m.PBRMaterial){if(!n.sheen.isEnabled)return void r(t);e._wasUsed=!0,null==t.extensions&&(t.extensions={});var u={sheenColorFactor:n.sheen.color.asArray(),sheenRoughnessFactor:null!==(o=n.sheen.roughness)&&void 0!==o?o:0};null===u.sheenColorTexture&&null===u.sheenRoughnessTexture||e._exporter._materialNeedsUVsSet.add(n),n.sheen.texture&&(u.sheenColorTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(n.sheen.texture))&&void 0!==i?i:void 0),n.sheen.textureRoughness&&!n.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(n.sheen.textureRoughness))&&void 0!==a?a:void 0:n.sheen.texture&&n.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(s=e._exporter._materialExporter.getTextureInfo(n.sheen.texture))&&void 0!==s?s:void 0),t.extensions[Fe]=u}r(t)}))];case 1:return[2,r.sent()]}}))}))},e}();se.RegisterExtension(Fe,(function(e){return new Oe(e)}));var Pe="KHR_materials_specular",Ne=function(){function e(e){this.name=Pe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,n){var r=[];return n instanceof m.PBRMaterial&&this._isExtensionEnabled(n)?(n.metallicReflectanceTexture&&r.push(n.metallicReflectanceTexture),n.reflectanceTexture&&r.push(n.reflectanceTexture),r):r},e.prototype._isExtensionEnabled=function(e){return!e.unlit&&(null!=e.metallicF0Factor&&1!=e.metallicF0Factor||null!=e.metallicReflectanceColor&&!e.metallicReflectanceColor.equalsFloats(1,1,1)||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.metallicReflectanceTexture||null!=e.reflectanceTexture},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){var o,i;if(n instanceof m.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0,t.extensions=t.extensions||{};var a=null!==(o=r._exporter._materialExporter.getTextureInfo(n.metallicReflectanceTexture))&&void 0!==o?o:void 0,s=null!==(i=r._exporter._materialExporter.getTextureInfo(n.reflectanceTexture))&&void 0!==i?i:void 0,u={specularFactor:1==n.metallicF0Factor?void 0:n.metallicF0Factor,specularTexture:a,specularColorFactor:n.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:n.metallicReflectanceColor.asArray(),specularColorTexture:s};r._hasTexturesExtension(n)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[Pe]=u}e(t)}))},e}();se.RegisterExtension(Pe,(function(e){return new Ne(e)}));var Ue="KHR_materials_transmission",Le=function(){function e(e){this.name=Ue,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,n){var r=[];return n instanceof m.PBRMaterial&&this._isExtensionEnabled(n)?(n.subSurface.thicknessTexture&&r.push(n.subSurface.thicknessTexture),r):r},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return t.isRefractionEnabled&&null!=t.refractionIntensity&&0!=t.refractionIntensity||this._hasTexturesExtension(e)},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.refractionIntensityTexture},e.prototype.postExportMaterialAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var r,o,i,a;return T(this,(function(s){switch(s.label){case 0:return n instanceof m.PBRMaterial&&this._isExtensionEnabled(n)?(this._wasUsed=!0,r=n.subSurface,o=0===r.refractionIntensity?void 0:r.refractionIntensity,i={transmissionFactor:o},this._hasTexturesExtension(n)&&this._exporter._materialNeedsUVsSet.add(n),r.refractionIntensityTexture?r.useGltfStyleTextures?[4,this._exporter._materialExporter.exportTextureAsync(r.refractionIntensityTexture)]:[3,2]:[3,3]):[3,4];case 1:return(a=s.sent())&&(i.transmissionTexture=a),[3,3];case 2:m.Logger.Warn("".concat(e,": Exporting a subsurface refraction intensity texture without `useGltfStyleTextures` is not supported")),s.label=3;case 3:t.extensions||(t.extensions={}),t.extensions[Ue]=i,s.label=4;case 4:return[2,t]}}))}))},e}();se.RegisterExtension(Ue,(function(e){return new Le(e)}));var ke="KHR_materials_unlit",De=function(){function e(){this.name=ke,this.enabled=!0,this.required=!1,this._wasUsed=!1}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){var o=!1;n instanceof m.PBRMaterial?o=n.unlit:n instanceof m.StandardMaterial&&(o=n.disableLighting),o&&(r._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[ke]={}),e(t)}))},e}();se.RegisterExtension(ke,(function(){return new De}));var Ke="KHR_materials_volume",Ge=function(){function e(e){this.name=Ke,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,n){var r=[];return n instanceof m.PBRMaterial&&this._isExtensionEnabled(n)?(n.subSurface.thicknessTexture&&r.push(n.subSurface.thicknessTexture),r):r},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isTranslucencyEnabled)&&(null!=t.maximumThickness&&0!=t.maximumThickness||null!=t.tintColorAtDistance&&t.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=t.tintColor&&t.tintColor!=m.Color3.White()||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.thicknessTexture},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){var o;if(n instanceof m.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var i=n.subSurface,a={thicknessFactor:0==i.maximumThickness?void 0:i.maximumThickness,thicknessTexture:null!==(o=r._exporter._materialExporter.getTextureInfo(i.thicknessTexture))&&void 0!==o?o:void 0,attenuationDistance:i.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:i.tintColorAtDistance,attenuationColor:i.tintColor.equalsFloats(1,1,1)?void 0:i.tintColor.asArray()};r._hasTexturesExtension(n)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions=t.extensions||{},t.extensions[Ke]=a}e(t)}))},e}();se.RegisterExtension(Ke,(function(e){return new Ge(e)}));var We="EXT_materials_diffuse_roughness",He=function(){function e(e){this.name=We,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,n){var r=[];return n instanceof m.PBRBaseMaterial&&n._baseDiffuseRoughness?(n._baseDiffuseRoughnessTexture&&r.push(n._baseDiffuseRoughnessTexture),r):[]},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof m.PBRBaseMaterial){if(!n._baseDiffuseRoughness)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var o=r._exporter._materialExporter.getTextureInfo(n._baseDiffuseRoughnessTexture),i={diffuseRoughnessFactor:n._baseDiffuseRoughness,diffuseRoughnessTexture:null!=o?o:void 0};null!==i.diffuseRoughnessTexture&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[We]=i}e(t)}))},e}();se.RegisterExtension(We,(function(e){return new He(e)}));var qe="KHR_texture_transform",je=function(){function e(){this.name=qe,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportTexture=function(e,t,n){if(n.getScene()||m.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(n.name,"!")),0===n.uAng&&0===n.vAng||(m.Tools.Warn("".concat(e,": Texture ").concat(n.name," with rotation in the u or v axis is not supported in glTF.")),0===n.uRotationCenter&&0===n.vRotationCenter)){var r={},o=!1;if(0===n.uOffset&&0===n.vOffset||(r.offset=[n.uOffset,n.vOffset],o=!0),1===n.uScale&&1===n.vScale||(r.scale=[n.uScale,n.vScale],o=!0),0!==n.wAng){if(0!==n.uRotationCenter||0!==n.vRotationCenter){if(n.homogeneousRotationInUVTransform&&n.uScale!==n.vScale)return void m.Tools.Warn("".concat(e,": Texture ").concat(n.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(qe,"."));m.Tools.Warn("".concat(e,": Texture ").concat(n.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(qe,".")),r.offset=function(e){var t=e.uOffset,n=e.vOffset,r=e.uRotationCenter,o=e.vRotationCenter,i=e.uScale,a=e.vScale,s=e.wAng,u=Math.cos(s),c=Math.sin(s),l=r*i,f=o*a;return[t+(l*(1-u)+f*c),n+(f*(1-u)-l*c)]}(n)}r.rotation=-n.wAng,o=!0}0!==n.coordinatesIndex&&(r.texCoord=n.coordinatesIndex,o=!0),o&&(this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[qe]=r)}},e}();se.RegisterExtension(qe,(function(){return new je}));var ze="KHR_texture_basisu",Qe=function(){function e(e){this.name=ze,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,t){var n=this._exporter._textures[t.index],r=n.source;if(void 0!==r){var o=this._exporter._images[r];"image/ktx2"===(o.mimeType||(0,m.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[ze]={source:r},this._wasUsed=!0)}},e}();se.RegisterExtension(ze,(function(e){return new Qe(e)}));var Xe="EXT_texture_webp",Ye=function(){function e(e){this.name=Xe,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,t){var n=this._exporter._textures[t.index],r=n.source;if(void 0!==r){var o=this._exporter._images[r];"image/webp"===(o.mimeType||(0,m.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[Xe]={source:r},this._wasUsed=!0)}},e}();se.RegisterExtension(Xe,(function(e){return new Ye(e)}));var Ze="EXT_texture_avif",Je=function(){function e(e){this.name=Ze,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,t){var n=this._exporter._textures[t.index],r=n.source;if(void 0!==r){var o=this._exporter._images[r];"image/avif"===(o.mimeType||(0,m.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[Ze]={source:r},this._wasUsed=!0)}},e}();se.RegisterExtension(Ze,(function(e){return new Je(e)}));var $e=function(){function e(){}return e.CreateSTL=function(e,t,n,r,o,i,a,s){void 0===t&&(t=!0),void 0===n&&(n="stlmesh"),void 0===r&&(r=!1),void 0===o&&(o=!0),void 0===i&&(i=!1),void 0===a&&(a=!1),void 0===s&&(s=!1);var u=function(e,t,n){var r=[3*e[n],3*e[n+1],3*e[n+2]],o=[new m.Vector3(t[r[0]],t[r[0]+2],t[r[0]+1]),new m.Vector3(t[r[1]],t[r[1]+2],t[r[1]+1]),new m.Vector3(t[r[2]],t[r[2]+2],t[r[2]+1])],i=o[0].subtract(o[1]),a=o[2].subtract(o[1]);return{v:o,n:m.Vector3.Cross(a,i).normalize()}},c=function(e,t,n,r){return t=l(e,t,n.x,r),t=l(e,t,n.y,r),l(e,t,n.z,r)},l=function(e,t,n,r){return e.setFloat32(t,n,r),t+4},f=function(e){if(a){var t=e;e instanceof m.InstancedMesh&&(t=e.sourceMesh);var n=t.getVerticesData(m.VertexBuffer.PositionKind,!0,!0);if(!n)return[];var r=m.Vector3.Zero(),o=void 0;for(o=0;o<n.length;o+=3)m.Vector3.TransformCoordinatesFromFloatsToRef(n[o],n[o+1],n[o+2],e.computeWorldMatrix(!0),r).toArray(n,o);return n}return e.getVerticesData(m.VertexBuffer.PositionKind)||[]};a&&(i=!0);var h="",p=0,d=0;if(r){for(var g=0;g<e.length;g++)p+=(y=(_=e[g]).getIndices())?y.length/3:0;var x=new ArrayBuffer(84+50*p);d+=80,(h=new DataView(x)).setUint32(d,p,o),d+=4}else s||(h="solid stlmesh\r\n");for(g=0;g<e.length;g++){var _=e[g];!r&&s&&(h+="solid "+_.name+"\r\n"),!i&&_ instanceof m.Mesh&&_.bakeCurrentTransformIntoVertices();for(var v=f(_),y=_.getIndices()||[],T=0;T<y.length;T+=3){var b=u(y,v,T);r?(d=c(h,d,b.n,o),d=c(h,d,b.v[0],o),d=c(h,d,b.v[1],o),d=c(h,d,b.v[2],o),d+=2):(h+="\tfacet normal "+b.n.x+" "+b.n.y+" "+b.n.z+"\r\n",h+="\t\touter loop\r\n",h+="\t\t\tvertex "+b.v[0].x+" "+b.v[0].y+" "+b.v[0].z+"\r\n",h+="\t\t\tvertex "+b.v[1].x+" "+b.v[1].y+" "+b.v[1].z+"\r\n",h+="\t\t\tvertex "+b.v[2].x+" "+b.v[2].y+" "+b.v[2].z+"\r\n",h+="\t\tendloop\r\n",h+="\tendfacet\r\n")}!r&&s&&(h+="endsolid "+name+"\r\n")}if(r||s||(h+="endsolid stlmesh"),t){var w=document.createElement("a"),M=new Blob([h],{type:"application/octet-stream"});w.href=window.URL.createObjectURL(M),w.download=n+".stl",w.click()}return h},e}();function et(e,t,n,r){void 0===n&&(n=3),void 0===r&&(r=!1);for(var o=[],i=0;i<e.length/n;i++){var a=e[i*n]*(r?-1:1),s=e[i*n+1],u=e[i*n+2];o.push("(".concat(a.toPrecision(t.precision),", ").concat(s.toPrecision(t.precision),", ").concat(u.toPrecision(t.precision),")"))}return o.join(", ")}function tt(e,t){for(var n=[],r=0;r<e.length/2;r++){var o=e[2*r],i=e[2*r+1];n.push("(".concat(o.toPrecision(t.precision),", ").concat((1-i).toPrecision(t.precision),")"))}return n.join(", ")}function nt(e,t,n,r){var o=function(e,t,n,r){var o=e.getVerticesData(m.VertexBuffer.PositionKind),i=e.getVerticesData(m.VertexBuffer.NormalKind);if(o&&i)return'\n\tdef Mesh "'.concat("Geometry",'"\n\t{\n uniform token orientation = "').concat(n,'"\n\t\tint[] faceVertexCounts = [').concat(function(e){var t,n=(null===(t=e.getIndices())||void 0===t?void 0:t.length)?e.getTotalIndices():e.getTotalVertices();return Array(n/3).fill(3).join(", ")}(e),"]\n\t\tint[] faceVertexIndices = [").concat(function(e){var t,n=e.getIndices(),r=null!==(t=null==n?void 0:n.length)&&void 0!==t?t:e.getTotalVertices(),o=[];if(null!==n)for(var i=0;i<r;i++)o.push(n[i]);else for(i=0;i<r;i++)o.push(i);return o.join(", ")}(e),"]\n\t\tnormal3f[] normals = [").concat(et(i,t,void 0,r),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)\n\t\tpoint3f[] points = [').concat(et(o,t,void 0,r),"]\n ").concat(function(e,t){for(var n="",r=0;r<4;r++){var o=r>0?r:"",i=e.getVerticesData(m.VertexBuffer.UVKind+(o?o+1:""));i&&(n+="\n\t\ttexCoord2f[] primvars:st".concat(o," = [").concat(tt(i,t),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)'))}var a=e.getVerticesData(m.VertexBuffer.ColorKind);return a&&(n+="\n\tcolor3f[] primvars:displayColor = [".concat(et(a,t,a.length/e.getTotalVertices()),'] (\n\t\tinterpolation = "vertex"\n\t\t)')),n}(e,t),'\n\t\tuniform token subdivisionScheme = "none"\n\t}\n')}(e,t,n,r);return'\n def "Geometry"\n {\n '.concat(o,"\n }\n ")}function rt(e){var t='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )';return t+=e,fflate.strToU8(t)}function ot(e){var t=e.m;return"( ".concat(it(t,0),", ").concat(it(t,4),", ").concat(it(t,8),", ").concat(it(t,12)," )")}function it(e,t){return"(".concat(e[t+0],", ").concat(e[t+1],", ").concat(e[t+2],", ").concat(e[t+3],")")}function at(e,t){var n="Object_"+e.uniqueId,r=ot(t);return'def Xform "'.concat(n,'" (\n\tprepend references = @./geometries/Geometry_').concat(e.geometry.uniqueId,'.usda@</Geometry>\n\tprepend apiSchemas = ["MaterialBindingAPI"]\n)\n{\n\tmatrix4d xformOp:transform = ').concat(r,'\n\tuniform token[] xformOpOrder = ["xformOp:transform"]\t\n\n rel material:binding = </Root/Materials/Material_').concat(e.material.uniqueId,">\n}\n\n")}function st(e){switch(e){case m.Constants.TEXTURE_CLAMP_ADDRESSMODE:return"clamp";case m.Constants.TEXTURE_MIRROR_ADDRESSMODE:return"mirror";case m.Constants.TEXTURE_WRAP_ADDRESSMODE:default:return"repeat"}}function ut(e){return"(".concat(e.x,", ").concat(e.y,")")}function ct(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,")")}function lt(e,t,n,r,o,i){var a=e.getInternalTexture().uniqueId+"_"+e.invertY;o[a]=e;var s=e.coordinatesIndex>0?"st"+e.coordinatesIndex:"st",u=new m.Vector2(e.uScale,e.vScale),c=new m.Vector2(e.uOffset,e.vOffset),l=e.wAng,f=Math.sin(l),h=Math.cos(l);return c.y=1-c.y-u.y,c.x+=f*u.x,c.y+=(1-h)*u.y,'\n def Shader "PrimvarReader_'.concat(n,'"\n {\n uniform token info:id = "UsdPrimvarReader_float2"\n float2 inputs:fallback = (0.0, 0.0)\n token inputs:varname = "').concat(s,'"\n float2 outputs:result\n }\n\n def Shader "Transform2d_').concat(n,'"\n {\n uniform token info:id = "UsdTransform2d"\n token inputs:in.connect = </Root/Materials/Material_').concat(t.uniqueId,"/PrimvarReader_").concat(n,".outputs:result>\n float inputs:rotation = ").concat((l*(180/Math.PI)).toFixed(i.precision),"\n float2 inputs:scale = ").concat(ut(u),"\n float2 inputs:translation = ").concat(ut(c),'\n float2 outputs:result\n }\n\n def Shader "Texture_').concat(e.uniqueId,"_").concat(n,'"\n {\n uniform token info:id = "UsdUVTexture"\n asset inputs:file = @textures/Texture_').concat(a,".png@\n float2 inputs:st.connect = </Root/Materials/Material_").concat(t.uniqueId,"/Transform2d_").concat(n,".outputs:result>\n ").concat(r?"float4 inputs:scale = "+function(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,", 1.0)")}(r):"",'\n token inputs:sourceColorSpace = "').concat(e.gammaSpace?"sRGB":"raw",'"\n token inputs:wrapS = "').concat(st(e.wrapU),'"\n token inputs:wrapT = "').concat(st(e.wrapV),'"\n float outputs:r\n float outputs:g\n float outputs:b\n float3 outputs:rgb\n ').concat(t.needAlphaBlending()||t.needAlphaTesting()?"float outputs:a":"","\n }")}function ft(e,t,n){var r="\t\t\t",o=[],i=[],a=function(e){var t,n,r={diffuseMap:null,diffuse:null,alphaCutOff:0,emissiveMap:null,emissive:null,normalMap:null,roughnessMap:null,roughnessChannel:"a",roughness:0,metalnessMap:null,metalnessChannel:"r",metalness:0,aoMap:null,aoMapChannel:"rgb",aoMapIntensity:0,alphaMap:null,ior:1,clearCoatEnabled:!1,clearCoat:0,clearCoatMap:null,clearCoatRoughness:0,clearCoatRoughnessMap:null};return e instanceof m.StandardMaterial?v(v({},r),{diffuseMap:e.diffuseTexture,diffuse:e.diffuseColor,alphaCutOff:e.alphaCutOff,emissiveMap:e.emissiveTexture,emissive:e.emissiveColor,roughness:1,alphaMap:e.opacityTexture}):e instanceof m.PBRBaseMaterial?v(v({},r),{diffuseMap:e._albedoTexture,diffuse:e._albedoColor,alphaCutOff:e._alphaCutOff,emissiveMap:e._emissiveTexture,emissive:e._emissiveColor,normalMap:e._bumpTexture,roughnessMap:e._metallicTexture,roughnessChannel:e._useRoughnessFromMetallicTextureAlpha?"a":"g",roughness:null!==(t=e._roughness)&&void 0!==t?t:1,metalnessMap:e._metallicTexture,metalnessChannel:e._useMetallnessFromMetallicTextureBlue?"b":"r",metalness:null!==(n=e._metallic)&&void 0!==n?n:0,aoMap:e._ambientTexture,aoMapChannel:e._useAmbientInGrayScale?"r":"rgb",aoMapIntensity:e._ambientTextureStrength,alphaMap:e._opacityTexture,ior:e.subSurface.indexOfRefraction,clearCoatEnabled:e.clearCoat.isEnabled,clearCoat:e.clearCoat.intensity,clearCoatMap:e.clearCoat.texture,clearCoatRoughness:e.clearCoat.roughness,clearCoatRoughnessMap:e.clearCoat.useRoughnessFromMainTexture?e.clearCoat.texture:e.clearCoat.textureRoughness}):r}(e),s=a.diffuseMap,u=a.diffuse,c=a.alphaCutOff,l=a.emissiveMap,f=a.emissive,h=a.normalMap,p=a.roughnessMap,d=a.roughnessChannel,g=a.roughness,x=a.metalnessMap,_=a.metalnessChannel,y=a.metalness,T=a.aoMap,b=a.aoMapChannel,w=a.aoMapIntensity,M=a.alphaMap,A=a.ior,E=a.clearCoatEnabled,R=a.clearCoat,C=a.clearCoatMap,V=a.clearCoatRoughness,S=a.clearCoatRoughnessMap;return null!==s?(o.push("".concat(r,"color3f inputs:diffuseColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:rgb>")),e.needAlphaBlending()?o.push("".concat(r,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:a>")):e.needAlphaTesting()&&(o.push("".concat(r,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:a>")),o.push("".concat(r,"float inputs:opacityThreshold = ").concat(c))),i.push(lt(s,e,"diffuse",u,t,n))):o.push("".concat(r,"color3f inputs:diffuseColor = ").concat(ct(u||m.Color3.White()))),null!==l?(o.push("".concat(r,"color3f inputs:emissiveColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(l.uniqueId,"_emissive.outputs:rgb>")),i.push(lt(l,e,"emissive",f,t,n))):f&&f.toLuminance()>0&&o.push("".concat(r,"color3f inputs:emissiveColor = ").concat(ct(f))),null!==h&&(o.push("".concat(r,"normal3f inputs:normal.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(h.uniqueId,"_normal.outputs:rgb>")),i.push(lt(h,e,"normal",null,t,n))),null!==T&&(o.push("".concat(r,"float inputs:occlusion.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(T.uniqueId,"_occlusion.outputs:").concat(b,">")),i.push(lt(T,e,"occlusion",new m.Color3(w,w,w),t,n))),null!==p?(o.push("".concat(r,"float inputs:roughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(p.uniqueId,"_roughness.outputs:").concat(d,">")),i.push(lt(p,e,"roughness",new m.Color3(g,g,g),t,n))):o.push("".concat(r,"float inputs:roughness = ").concat(g)),null!==x?(o.push("".concat(r,"float inputs:metallic.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(x.uniqueId,"_metallic.outputs:").concat(_,">")),i.push(lt(x,e,"metallic",new m.Color3(y,y,y),t,n))):o.push("".concat(r,"float inputs:metallic = ").concat(y)),null!==M?(o.push("".concat(r,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(M.uniqueId,"_opacity.outputs:r>")),o.push("".concat(r,"float inputs:opacityThreshold = 0.0001")),i.push(lt(M,e,"opacity",null,t,n))):o.push("".concat(r,"float inputs:opacity = ").concat(e.alpha)),E&&(null!==C?(o.push("".concat(r,"float inputs:clearcoat.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(C.uniqueId,"_clearcoat.outputs:r>")),i.push(lt(C,e,"clearcoat",new m.Color3(R,R,R),t,n))):o.push("".concat(r,"float inputs:clearcoat = ").concat(R)),null!==S?(o.push("".concat(r,"float inputs:clearcoatRoughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(S.uniqueId,"_clearcoatRoughness.outputs:g>")),i.push(lt(S,e,"clearcoatRoughness",new m.Color3(V,V,V),t,n))):o.push("".concat(r,"float inputs:clearcoatRoughness = ").concat(V))),o.push("".concat(r,"float inputs:ior = ").concat(A)),'\n\tdef Material "Material_'.concat(e.uniqueId,'"\n\t{\n\t\tdef Shader "PreviewSurface"\n\t\t{\n\t\t\tuniform token info:id = "UsdPreviewSurface"\n').concat(o.join("\n"),"\n\t\t\tint inputs:useSpecularWorkflow = 0\n\t\t\ttoken outputs:surface\n\t\t}\n\n\t\ttoken outputs:surface.connect = </Root/Materials/Material_").concat(e.uniqueId,"/PreviewSurface.outputs:surface>\n\n").concat(i.join("\n"),"\n\n\t}\n")}function ht(e){var t,n;e.computeWorldMatrix(!0);for(var r=e.getWorldMatrix().clone(),o=e.getScene().useRightHandedSystem,i=null!==(n=null===(t=e.material)||void 0===t?void 0:t._getEffectiveOrientation(e))&&void 0!==n?n:e.sideOrientation,a=!o,s=e.parent;s;){if(N(s,o)&&null===s.parent){o||(r.multiplyToRef(s.getWorldMatrix().invert(),r),i=i===m.Material.ClockWiseSideOrientation?m.Material.CounterClockWiseSideOrientation:m.Material.ClockWiseSideOrientation),a=!1;break}s=s.parent}return r.determinant()<0&&m.Tools.Warn("Mesh ".concat(e.name," has a negative scale, which may look incorrect in destinations like QuickLook.")),{matrix:r,windingOrder:i===m.Material.ClockWiseSideOrientation?"leftHanded":"rightHanded",convertToRightHanded:a}}function pt(e,t,n){return y(this,void 0,void 0,(function(){var r,o,i,a,s,u,c,l,f,h,p,d,g,x,_,y,b,w,M,A,E,R,C,V,S,I,B,F,O,P,N,U;return T(this,(function(T){switch(T.label){case 0:return r=v({fflateUrl:"https://unpkg.com/fflate@0.8.2",includeAnchoringProperties:!0,anchoringType:"plane",planeAnchoringAlignment:"horizontal",modelFileName:"model.usda",precision:5,exportCamera:!1,cameraSensorWidth:35},t),"undefined"!=typeof fflate?[3,2]:[4,m.Tools.LoadScriptAsync(r.fflateUrl)];case 1:T.sent(),T.label=2;case 2:for((o={})[r.modelFileName]=null,i='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )',i+=function(e){var t=!0===e.includeAnchoringProperties?'\n\t\ttoken preliminary:anchoring:type = "'.concat(e.anchoringType,'"\n\t\ttoken preliminary:planeAnchoring:alignment = "').concat(e.planeAnchoringAlignment,'"'):"";return'def Xform "Root"\n {\n def Scope "Scenes" (\n kind = "sceneLibrary"\n )\n {\n def Xform "Scene" (\n customData = {\n bool preliminary_collidesWithEnvironment = 0\n string sceneName = "Scene"\n }\n sceneName = "Scene"\n )\n {'.concat(t,"\n ")}(r),a={},s=0,u=e.meshes;s<u.length;s++)0!==(c=u[s]).getTotalVertices()&&(f=(l=c).geometry,(h=l.material)&&f&&(!n||n(l))&&(-1!==["StandardMaterial","PBRMaterial","PBRMetallicRoughnessMaterial"].indexOf(h.getClassName())?(p="geometries/Geometry_"+f.uniqueId+".usda",d=ht(l),g=d.matrix,x=d.windingOrder,_=d.convertToRightHanded,p in o||(y=nt(f,r,x,_),o[p]=rt(y)),h.uniqueId in a||(a[h.uniqueId]=h),i+=at(l,g)):m.Tools.Warn("USDZExportAsync does not support this material type: "+h.getClassName())));for(A in e.activeCamera&&r.exportCamera&&(i+=function(e,t){var n="Camera_"+e.uniqueId,r=ot(m.Matrix.RotationY(Math.PI).multiply(e.getWorldMatrix()));if(e.mode===m.Constants.ORTHOGRAPHIC_CAMERA)return'def Camera "'.concat(n,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(r,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(t.precision),", ").concat(e.maxZ.toPrecision(t.precision),")\n\t\t\tfloat horizontalAperture = ").concat((10*(Math.abs(e.orthoLeft||1)+Math.abs(e.orthoRight||1))).toPrecision(t.precision),"\n\t\t\tfloat verticalAperture = ").concat((10*(Math.abs(e.orthoTop||1)+Math.abs(e.orthoBottom||1))).toPrecision(t.precision),'\n\t\t\ttoken projection = "orthographic"\n\t\t}\n\t\n\t');var o=e.getEngine().getAspectRatio(e),i=t.cameraSensorWidth||35;return'def Camera "'.concat(n,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(r,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(t.precision),", ").concat(e.maxZ.toPrecision(t.precision),")\n\t\t\tfloat focalLength = ").concat((i/(2*Math.tan(.5*e.fov))).toPrecision(t.precision),'\n token projection = "perspective"\n\t\t\tfloat horizontalAperture = ').concat((i*o).toPrecision(t.precision),"\n\t\t\tfloat verticalAperture = ").concat((i/o).toPrecision(t.precision)," \n\t\t}\n\t\n\t")}(e.activeCamera,r)),i+="\n }\n }",i+=function(e,t,n){var r=[];for(var o in e){var i=e[o];r.push(ft(i,t,n))}return'\n def "Materials"\n{\n'.concat(r.join(""),"\n}\n\n")}(a,b={},r),i+="\n }",o[r.modelFileName]=fflate.strToU8(i),M=[],w=b)M.push(A);E=0,T.label=3;case 3:return E<M.length?(A=M[E])in w?(C=b[R=A],V=C.getSize(),[4,(0,m.GetTextureDataAsync)(C)]):[3,6]:[3,7];case 4:return S=T.sent(),[4,m.DumpTools.DumpDataAsync(V.width,V.height,S,"image/png",void 0,!1,!0)];case 5:I=T.sent(),o["textures/Texture_".concat(R,".png")]=new Uint8Array(I).slice(),T.label=6;case 6:return E++,[3,3];case 7:for(F in B=0,o)(O=o[F])&&(P=34+F.length,4!=(N=63&(B+=P))&&(U=new Uint8Array(64-N),o[F]=[O,{extra:{12345:U}}]),B=O.length);return[2,fflate.zipSync(o,{level:0})]}}))}))}var dt=function(){function e(){}return e.Export=function(e,t,n){void 0===t&&(t=[]),void 0===n&&(n=.03333);var r=t;t&&0!==t.length||(r=e.animations.map((function(e){return e.name})));var o=null;if(r.length>0&&(o=e.getAnimationRange(r[0])),!o&&(e.animations.length>0&&(o=e.getAnimationRange(e.animations[0].name)),!o))throw new Error("No animation range found in skeleton");var i=this._BuildBoneHierarchy(e,r),a=o.to-o.from+1,s="";return s+="HIERARCHY\n",s+=this._ExportHierarchy(i,0),s+="MOTION\n",s+="Frames: ".concat(a,"\n"),s+="Frame Time: ".concat(n,"\n"),(s+="\n")+this._ExportMotionData(i,a,o.from,r)},e._BuildBoneHierarchy=function(e,t){for(var n=new Map,r=[],o=0,i=e.bones;o<i.length;o++){var a={bone:c=i[o],children:[],hasPositionChannels:!1,hasRotationChannels:!1,positionKeys:[],rotationKeys:[]};n.set(c,a)}for(var s=0,u=e.bones;s<u.length;s++){var c=u[s];if(a=n.get(c),c.animations.length>0)for(var l=0,f=c.animations;l<f.length;l++){var h=f[l];t.includes(h.name)&&("position"===h.targetProperty?(a.hasPositionChannels=!0,a.positionKeys=h.getKeys()):"rotationQuaternion"===h.targetProperty&&(a.hasRotationChannels=!0,a.rotationKeys=h.getKeys()))}if(c.getParent()){var p=n.get(c.getParent());p&&p.children.push(a)}else r.push(a)}return r},e._ExportHierarchy=function(e,t){for(var n="",r=" ".repeat(t),o=0,i=e;o<i.length;o++){var a=i[o],s=a.bone;if(0!==a.children.length||a.hasPositionChannels||a.hasRotationChannels){n+="".concat(r,"JOINT ").concat(s.name,"\n"),n+="".concat(r,"{\n"),c=this._GetBoneOffset(s),n+="".concat(r," OFFSET ").concat(c.x.toFixed(6)," ").concat(c.y.toFixed(6)," ").concat(c.z.toFixed(6),"\n");var u=[];a.hasPositionChannels&&u.push("Xposition","Yposition","Zposition"),a.hasRotationChannels&&u.push("Zrotation","Xrotation","Yrotation"),u.length>0&&(n+="".concat(r," CHANNELS ").concat(u.length," ").concat(u.join(" "),"\n")),n+="".concat(r,"}\n")}else{n+="".concat(r,"End Site\n"),n+="".concat(r,"{\n");var c=this._GetBoneOffset(s);n+="".concat(r," OFFSET ").concat(c.x.toFixed(6)," ").concat(c.y.toFixed(6)," ").concat(c.z.toFixed(6),"\n"),n+="".concat(r,"}\n")}a.children.length>0&&(n+=this._ExportHierarchy(a.children,t+1))}return n},e._GetBoneOffset=function(e){var t=e.getParent();if(!t)return m.Vector3.Zero();var n=e.getBindMatrix(),r=t.getBindMatrix(),o=n.getTranslation(),i=r.getTranslation();return o.subtract(i)},e._ExportMotionData=function(e,t,n,r){for(var o="",i=0;i<t;i++){var a=[];this._CollectFrameValues(e,i+n,a,r),o+=a.map((function(e){return e.toFixed(6)})).join(" ")+"\n"}return o},e._CollectFrameValues=function(e,t,n,r){for(var o=0,i=e;o<i.length;o++){var a=i[o];if(0!==a.children.length||a.hasPositionChannels||a.hasRotationChannels){if(a.hasPositionChannels){var s=this._GetPositionAtFrame(a.positionKeys,t);n.push(s.x,s.y,s.z)}if(a.hasRotationChannels){var u=this._GetRotationAtFrame(a.rotationKeys,t),c=this._QuaternionToEuler(u);n.push(c.z,c.x,c.y)}a.children.length>0&&this._CollectFrameValues(a.children,t,n,r)}}},e._GetPositionAtFrame=function(e,t){if(0===e.length)return m.Vector3.Zero();for(var n=e[0],r=e[e.length-1],o=0;o<e.length-1;o++)if(e[o].frame<=t&&e[o+1].frame>=t){n=e[o],r=e[o+1];break}if(n.frame===r.frame)return n.value.clone();var i=(t-n.frame)/(r.frame-n.frame);return m.Vector3.Lerp(n.value,r.value,i)},e._GetRotationAtFrame=function(e,t){if(0===e.length)return m.Quaternion.Identity();for(var n=e[0],r=e[e.length-1],o=0;o<e.length-1;o++)if(e[o].frame<=t&&e[o+1].frame>=t){n=e[o],r=e[o+1];break}if(n.frame===r.frame)return n.value.clone();var i=(t-n.frame)/(r.frame-n.frame);return m.Quaternion.Slerp(n.value,r.value,i)},e._QuaternionToEuler=function(e){var t,n,r,o=e.toRotationMatrix(new m.Matrix);return Math.abs(o.m[6])<1-m.Epsilon?(t=Math.atan2(-o.m[7],o.m[8]),n=Math.asin(o.m[6]),r=Math.atan2(-o.m[3],o.m[0])):(t=Math.atan2(o.m[5],o.m[4]),n=Math.asin(o.m[6]),r=0),new m.Vector3(m.Tools.ToDegrees(t),m.Tools.ToDegrees(n),m.Tools.ToDegrees(r))},e}(),mt=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==mt)for(var gt in p)mt.BABYLON[gt]=p[gt];var xt=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==xt){xt.BABYLON=xt.BABYLON||{};var _t=xt.BABYLON;_t.GLTF2=_t.GLTF2||{},_t.GLTF2.Exporter=_t.GLTF2.Exporter||{},_t.GLTF2.Exporter.Extensions=_t.GLTF2.Exporter.Extensions||{};var vt=[];for(var yt in a)_t[yt]=a[yt],vt.push(yt);for(var yt in s)_t[yt]=s[yt],vt.push(yt);for(var yt in u)_t[yt]=u[yt],vt.push(yt);for(var yt in c)_t.GLTF2.Exporter.Extensions[yt]=c[yt],vt.push(yt);for(var yt in l)vt.indexOf(yt)>-1||(_t.GLTF2.Exporter[yt]=l[yt])}var Tt=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Tt)for(var bt in i)Tt.BABYLON[bt]=i[bt];var wt=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==wt)for(var Mt in f)wt.BABYLON[Mt]=f[Mt];var At=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==At)for(var Et in h)At.BABYLON[Et]=h[Et];const Rt=d;return o.default})()));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.SERIALIZERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(e=>(()=>{"use strict";var t={597:t=>{t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};r.d(o,{default:()=>Rt});var i={};r.r(i),r.d(i,{OBJExport:()=>g});var a={};r.r(a),r.d(a,{__IGLTFExporterExtension:()=>x});var s={};r.r(s),r.d(s,{GLTFData:()=>_});var u={};r.r(u),r.d(u,{GLTF2Export:()=>ue});var c={};r.r(c),r.d(c,{EXT_materials_diffuse_roughness:()=>He,EXT_mesh_gpu_instancing:()=>le,EXT_texture_avif:()=>Je,EXT_texture_webp:()=>Ye,KHR_draco_mesh_compression:()=>he,KHR_lights_punctual:()=>xe,KHR_materials_anisotropy:()=>ve,KHR_materials_clearcoat:()=>Te,KHR_materials_diffuse_transmission:()=>Me,KHR_materials_dispersion:()=>Ee,KHR_materials_emissive_strength:()=>Ce,KHR_materials_ior:()=>Se,KHR_materials_iridescence:()=>Fe,KHR_materials_sheen:()=>Oe,KHR_materials_specular:()=>Ne,KHR_materials_transmission:()=>Le,KHR_materials_unlit:()=>Ke,KHR_materials_volume:()=>Ge,KHR_texture_basisu:()=>Qe,KHR_texture_transform:()=>je});var l={};r.r(l),r.d(l,{EXT_materials_diffuse_roughness:()=>He,EXT_mesh_gpu_instancing:()=>le,EXT_texture_avif:()=>Je,EXT_texture_webp:()=>Ye,GLTF2Export:()=>ue,GLTFData:()=>_,KHR_draco_mesh_compression:()=>he,KHR_lights_punctual:()=>xe,KHR_materials_anisotropy:()=>ve,KHR_materials_clearcoat:()=>Te,KHR_materials_diffuse_transmission:()=>Me,KHR_materials_dispersion:()=>Ee,KHR_materials_emissive_strength:()=>Ce,KHR_materials_ior:()=>Se,KHR_materials_iridescence:()=>Fe,KHR_materials_sheen:()=>Oe,KHR_materials_specular:()=>Ne,KHR_materials_transmission:()=>Le,KHR_materials_unlit:()=>Ke,KHR_materials_volume:()=>Ge,KHR_texture_basisu:()=>Qe,KHR_texture_transform:()=>je,_ConvertToGLTFPBRMetallicRoughness:()=>S,_SolveMetallic:()=>V});var f={};r.r(f),r.d(f,{STLExport:()=>$e});var h={};r.r(h),r.d(h,{USDZExportAsync:()=>pt});var p={};r.r(p),r.d(p,{BVHExporter:()=>dt});var d={};r.r(d),r.d(d,{BVHExporter:()=>dt,EXT_materials_diffuse_roughness:()=>He,EXT_mesh_gpu_instancing:()=>le,EXT_texture_avif:()=>Je,EXT_texture_webp:()=>Ye,GLTF2Export:()=>ue,GLTFData:()=>_,KHR_draco_mesh_compression:()=>he,KHR_lights_punctual:()=>xe,KHR_materials_anisotropy:()=>ve,KHR_materials_clearcoat:()=>Te,KHR_materials_diffuse_transmission:()=>Me,KHR_materials_dispersion:()=>Ee,KHR_materials_emissive_strength:()=>Ce,KHR_materials_ior:()=>Se,KHR_materials_iridescence:()=>Fe,KHR_materials_sheen:()=>Oe,KHR_materials_specular:()=>Ne,KHR_materials_transmission:()=>Le,KHR_materials_unlit:()=>Ke,KHR_materials_volume:()=>Ge,KHR_texture_basisu:()=>Qe,KHR_texture_transform:()=>je,OBJExport:()=>g,STLExport:()=>$e,USDZExportAsync:()=>pt,_ConvertToGLTFPBRMetallicRoughness:()=>S,_SolveMetallic:()=>V,__IGLTFExporterExtension:()=>x});var m=r(597),g=function(){function e(){}return e.OBJ=function(e,t,n,r){var o=[],i=1,a=1;t&&(n||(n="mat"),o.push("mtllib "+n+".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(r){var f=u.computeWorldMatrix(!0);l=new m.Matrix,f.invertToRef(l),u.bakeTransformIntoVertices(f)}if(t){var h=u.material;h&&o.push("usemtl "+h.id)}var p=u.geometry;if(p){var d=p.getVerticesData("position"),g=p.getVerticesData("normal"),x=p.getVerticesData("uv"),_=p.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!=g)for(b=0;b<g.length;b+=3)o.push("vn "+g[b]*T+" "+g[b+1]+" "+g[b+2]);if(null!=x)for(b=0;b<x.length;b+=2)o.push("vt "+x[b]+" "+x[b+1]),y++;var w=["","",""],M=(u.material||u.getScene().defaultMaterial)._getEffectiveOrientation(u)===m.Material.ClockWiseSideOrientation?[2,1]:[1,2],A=M[0],E=M[1];for(b=0;b<_.length;b+=3){var R=[String(_[b]+i),String(_[b+A]+i),String(_[b+E]+i)],C=[String(_[b]+a),String(_[b+A]+a),String(_[b+E]+a)],V=R,S=null!=x?C:w,I=null!=g?R:w;o.push("f "+V[0]+"/"+S[0]+"/"+I[0]+" "+V[1]+"/"+S[1]+"/"+I[1]+" "+V[2]+"/"+S[2]+"/"+I[2])}r&&l&&u.bakeTransformIntoVertices(l),i+=v,a+=y}else m.Tools.Warn("There are no position vertices or indices on the mesh!")}else m.Tools.Warn("No geometry is present on the mesh")}return o.join("\n")},e.MTL=function(e){var t=[],n=e.material;return t.push("newmtl mat1"),t.push(" Ns "+n.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+n.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+n.ambientColor.r.toFixed(4)+" "+n.ambientColor.g.toFixed(4)+" "+n.ambientColor.b.toFixed(4)),t.push(" Kd "+n.diffuseColor.r.toFixed(4)+" "+n.diffuseColor.g.toFixed(4)+" "+n.diffuseColor.b.toFixed(4)),t.push(" Ks "+n.specularColor.r.toFixed(4)+" "+n.specularColor.g.toFixed(4)+" "+n.specularColor.b.toFixed(4)),t.push(" Ke "+n.emissiveColor.r.toFixed(4)+" "+n.emissiveColor.g.toFixed(4)+" "+n.emissiveColor.b.toFixed(4)),n.ambientTexture&&t.push(" map_Ka "+n.ambientTexture.name),n.diffuseTexture&&t.push(" map_Kd "+n.diffuseTexture.name),n.specularTexture&&t.push(" map_Ks "+n.specularTexture.name),n.bumpTexture&&t.push(" map_bump -imfchan z "+n.bumpTexture.name),n.opacityTexture&&t.push(" map_d "+n.opacityTexture.name),t.join("\n")},e}(),x=0,_=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],n=new Blob([t],{type:(0,m.GetMimeType)(e)});m.Tools.Download(n,e)}},e}(),v=function(){return v=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},v.apply(this,arguments)};function y(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))}function T(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function b(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var w=1e-6,M=new m.Color3(.04,.04,.04),A=1024,E=m.Color3.White(),R=m.Color3.Black();function C(e){return y(this,void 0,void 0,(function(){var t,n,r,o;return T(this,(function(i){switch(i.label){case 0:return(t=e.getInternalTexture())&&1===t.source?t.invertY?[2,null]:(n=t._buffer,o=e.mimeType,n?[3,2]:[4,m.Tools.LoadFileAsync(t.url)]):[2,null];case 1:return r=i.sent(),o=(0,m.GetMimeType)(t.url)||o,[3,10];case 2:return ArrayBuffer.isView(n)?(r=n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength),[3,10]):[3,3];case 3:return n instanceof ArrayBuffer?(r=n,[3,10]):[3,4];case 4:return n instanceof Blob?[4,n.arrayBuffer()]:[3,6];case 5:return r=i.sent(),o=n.type||o,[3,10];case 6:return"string"!=typeof n?[3,8]:[4,m.Tools.LoadFileAsync(n)];case 7:return r=i.sent(),o=(0,m.GetMimeType)(n)||o,[3,10];case 8:return"undefined"!=typeof HTMLImageElement&&n instanceof HTMLImageElement?[4,m.Tools.LoadFileAsync(n.src)]:[3,10];case 9:r=i.sent(),o=(0,m.GetMimeType)(n.src)||o,i.label=10;case 10:return r&&o?[2,{data:r,mimeType:o}]:[2,null]}}))}))}function V(e,t,n){if(t<M.r)return 0;var r=M.r,o=e*n/(1-M.r)+t-2*M.r,i=o*o-4*r*(M.r-t);return m.Scalar.Clamp((-o+Math.sqrt(i))/(2*r),0,1)}function S(e){var t=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),n=e.alpha,r=m.Scalar.Clamp(e.specularPower,0,A),o=(0,m.SpecularPowerToRoughness)(r);return{baseColorFactor:[t.r,t.g,t.b,n],metallicFactor:0,roughnessFactor:o}}function I(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function F(e,t,n){for(var r=new Uint8Array(e*t*4),o=0;o<r.length;o+=4)r[o]=r[o+1]=r[o+2]=r[o+3]=255;return m.RawTexture.CreateRGBATexture(r,e,t,n)}function B(e){if(e instanceof Uint8Array){for(var t=e.length,n=new Float32Array(e.length),r=0;r<t;++r)n[r]=e[r]/255;return n}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")}var O=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){return y(this,void 0,void 0,(function(){var n,r,o,i,a,s,u,c;return T(this,(function(l){switch(l.label){case 0:return n=S(e),r={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||m.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),t?(o=[],(i=e.diffuseTexture)&&o.push(this.exportTextureAsync(i).then((function(e){e&&(n.baseColorTexture=e)}))),(a=e.bumpTexture)&&o.push(this.exportTextureAsync(a).then((function(e){e&&(r.normalTexture=e,1!==a.level&&(r.normalTexture.scale=a.level))}))),(s=e.emissiveTexture)&&(r.emissiveFactor=[1,1,1],o.push(this.exportTextureAsync(s).then((function(e){e&&(r.emissiveTexture=e)})))),(u=e.ambientTexture)&&o.push(this.exportTextureAsync(u).then((function(e){if(e){var t={index:e.index};r.occlusionTexture=t}}))),o.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(o)]):[3,2]):[3,2];case 1:l.sent(),l.label=2;case 2:return(e.alpha<1||e.opacityTexture)&&(e.alphaMode===m.Constants.ALPHA_COMBINE?r.alphaMode="BLEND":m.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(R,w)&&(r.emissiveFactor=e.emissiveColor.asArray()),r.pbrMetallicRoughness=n,I(r,e),[4,this._finishMaterialAsync(r,e)];case 3:return l.sent(),(c=this._exporter._materials).push(r),[2,c.length-1]}}))}))},e.prototype._finishMaterialAsync=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,i,a;return T(this,(function(s){switch(s.label){case 0:for(n=this._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",e,t),r=[],o=0,i=n;o<i.length;o++)a=i[o],r.push(this.exportTextureAsync(a));return[4,Promise.all(r)];case 1:return s.sent(),[4,this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)];case 2:return s.sent(),[2]}}))}))},e.prototype._getImageDataAsync=function(e,t,n,r){return y(this,void 0,void 0,(function(){return T(this,(function(o){switch(o.label){case 0:return[4,m.DumpTools.DumpDataAsync(t,n,e,r,void 0,!1,!0)];case 1:return[2,o.sent()]}}))}))},e.prototype._resizeTexturesToSameDimensions=function(e,t,n){var r,o,i=e?e.getSize():{width:0,height:0},a=t?t.getSize():{width:0,height:0};return i.width<a.width?(r=e&&e instanceof m.Texture?m.TextureTools.CreateResizedCopy(e,a.width,a.height,!0):F(a.width,a.height,n),o=t):i.width>a.width?(o=t&&t instanceof m.Texture?m.TextureTools.CreateResizedCopy(t,i.width,i.height,!0):F(i.width,i.height,n),r=e):(r=e,o=t),{texture1:r,texture2:o}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,n,r){return y(this,void 0,void 0,(function(){var o,i,a,s,u,c,l,f,h,p,d,g,x,_,v,y,b,M,A,C,V,S,I,F,O,P,N,U,L,k,K;return T(this,(function(T){switch(T.label){case 0:return o=new Array,e||t?[3,2]:[4,Promise.reject("diffuse and specular glossiness textures are not defined!")];case 1:case 6:case 9:case 11:case 13:return[2,T.sent()];case 2:return(i=e?e.getScene():t?t.getScene():null)?(a=this._resizeTexturesToSameDimensions(e,t,i),s=null===(K=a.texture1)||void 0===K?void 0:K.getSize(),u=void 0,c=void 0,l=s.width,f=s.height,[4,a.texture1.readPixels()]):[3,12];case 3:return h=T.sent(),[4,a.texture2.readPixels()];case 4:return p=T.sent(),h?(u=B(h),[3,7]):[3,5];case 5:return[4,Promise.reject("Failed to retrieve pixels from diffuse texture!")];case 7:return p?(c=B(p),[3,10]):[3,8];case 8:return[4,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];case 10:for(d=c.byteLength,g=new Uint8Array(d),x=new Uint8Array(d),_=R,v=0,y=0,P=0;P<f;++P)for(N=0;N<l;++N)b=4*(l*P+N),M=new m.Color3(u[b],u[b+1],u[b+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(n.diffuseColor),A=new m.Color3(c[b],c[b+1],c[b+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(n.specularColor),C=c[b+3]*n.glossiness,V={diffuseColor:M,specularColor:A,glossiness:C},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[b]=255*S.baseColor.r,x[b+1]=255*S.baseColor.g,x[b+2]=255*S.baseColor.b,x[b+3]=a.texture1.hasAlpha?255*u[b+3]:255,g[b]=0,g[b+1]=255*S.roughness,g[b+2]=255*S.metallic,g[b+3]=255;for(I={baseColor:_,metallic:v,roughness:y},F=!1,O=!1,P=0;P<f;++P)for(N=0;N<l;++N)x[U=4*(l*P+N)]/=I.baseColor.r>w?I.baseColor.r:1,x[U+1]/=I.baseColor.g>w?I.baseColor.g:1,x[U+2]/=I.baseColor.b>w?I.baseColor.b:1,L=m.Color3.FromInts(x[U],x[U+1],x[U+2]),k=L.toGammaSpace(i.getEngine().useExactSrgbConversions),x[U]=255*k.r,x[U+1]=255*k.g,x[U+2]=255*k.b,k.equalsWithEpsilon(E,w)||(O=!0),g[U+1]/=I.roughness>w?I.roughness:1,g[U+2]/=I.metallic>w?I.metallic:1,m.Color3.FromInts(255,g[U+1],g[U+2]).equalsWithEpsilon(E,w)||(F=!0);return F&&o.push(this._getImageDataAsync(g,l,f,r).then((function(e){I.metallicRoughnessTextureData=e}))),O&&o.push(this._getImageDataAsync(x,l,f,r).then((function(e){I.baseColorTextureData=e}))),[4,Promise.all(o).then((function(){return I}))];case 12:return[4,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}}))}))},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var t=this._getPerceivedBrightness(e.diffuseColor),n=this._getPerceivedBrightness(e.specularColor),r=1-this._getMaxComponent(e.specularColor),o=V(t,n,r),i=e.diffuseColor.scale(r/(1-M.r)/Math.max(1-o)),a=e.specularColor.subtract(M.scale(1-o)).scale(1/Math.max(o)),s=m.Color3.Lerp(i,a,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,n){return y(this,void 0,void 0,(function(){var r,o,i,a;return T(this,(function(s){switch(s.label){case 0:return r=[],o={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness},n&&((i=e._albedoTexture)&&r.push(this.exportTextureAsync(i).then((function(e){e&&(t.baseColorTexture=e)}))),(a=e._metallicTexture)&&r.push(this.exportTextureAsync(a).then((function(e){e&&(t.metallicRoughnessTexture=e)})))),r.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(r)]):[3,2];case 1:s.sent(),s.label=2;case 2:return[2,o]}}))}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof m.Texture))return t;var n=this._getGLTFTextureWrapMode(e.wrapU);10497!==n&&(t.wrapS=n);var r=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==r&&(t.wrapT=r),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,n){return y(this,void 0,void 0,(function(){var r,o,i,a,s,u,c,l,f;return T(this,(function(h){switch(h.label){case 0:return r="image/png",o={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},i=e._albedoTexture,a=e._reflectivityTexture,s=e._useMicroSurfaceFromReflectivityMapAlpha,!a||s?[3,2]:[4,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")];case 1:return[2,h.sent()];case 2:return(i||a)&&n?(this._exporter._materialNeedsUVsSet.add(e),u=this._exportTextureSampler(i||a),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(i,a,o,r)]):[3,4];case 3:return c=h.sent(),l=this._exporter._textures,c.baseColorTextureData&&(f=this._exportImage("baseColor".concat(l.length),r,c.baseColorTextureData),t.baseColorTexture=this._exportTextureInfo(f,u,null==i?void 0:i.coordinatesIndex)),c.metallicRoughnessTextureData&&(f=this._exportImage("metallicRoughness".concat(l.length),r,c.metallicRoughnessTextureData),t.metallicRoughnessTexture=this._exportTextureInfo(f,u,null==a?void 0:a.coordinatesIndex)),[2,c];case 4:return[2,this._convertSpecularGlossinessToMetallicRoughness(o)]}}))}))},e.prototype.exportPBRMaterialAsync=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,i,a,s,u,c;return T(this,(function(l){switch(l.label){case 0:return n={},r={name:e.name},(o=e.isMetallicWorkflow())&&(i=e._albedoColor,a=e.alpha,i&&(n.baseColorFactor=[i.r,i.g,i.b,a])),o?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,n,t)]:[3,2];case 1:return u=l.sent(),[3,4];case 2:return[4,this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,n,t)];case 3:u=l.sent(),l.label=4;case 4:return s=u,[4,this._setMetallicRoughnessPbrMaterialAsync(s,e,r,n,t)];case 5:return l.sent(),[4,this._finishMaterialAsync(r,e)];case 6:return l.sent(),(c=this._exporter._materials).push(r),[2,c.length-1]}}))}))},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,t,n,r,o){return y(this,void 0,void 0,(function(){var i,a,s,u,c;return T(this,(function(l){switch(l.label){case 0:return I(n,t),e.baseColor.equalsWithEpsilon(E,w)&&m.Scalar.WithinEpsilon(t.alpha,1,w)||(r.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,t.alpha]),null!=e.metallic&&1!==e.metallic&&(r.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(r.roughnessFactor=e.roughness),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."),n.doubleSided=!0),o?(i=[],(a=t._bumpTexture)&&i.push(this.exportTextureAsync(a).then((function(e){e&&(n.normalTexture=e,1!==a.level&&(n.normalTexture.scale=a.level))}))),(s=t._ambientTexture)&&i.push(this.exportTextureAsync(s).then((function(e){if(e){var r={index:e.index,texCoord:e.texCoord,extensions:e.extensions};n.occlusionTexture=r;var o=t._ambientTextureStrength;o&&(r.strength=o)}}))),(u=t._emissiveTexture)&&i.push(this.exportTextureAsync(u).then((function(e){e&&(n.emissiveTexture=e)}))),i.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(i)]):[3,2]):[3,2];case 1:l.sent(),l.label=2;case 2:return(c=t._emissiveColor).equalsWithEpsilon(R,w)||(n.emissiveFactor=c.asArray()),n.pbrMetallicRoughness=r,[2]}}))}))},e.prototype.exportTextureAsync=function(e){return y(this,void 0,void 0,(function(){var t,n,r;return T(this,(function(o){switch(o.label){case 0:return(t=this._textureMap.get(e))?[2,t]:(n=this._exportTextureSampler(e),[4,this._exportTextureImageAsync(e)]);case 1:return r=o.sent(),t=this._exportTextureInfo(r,n,e.coordinatesIndex),this._textureMap.set(e,t),this._exporter._extensionsPostExportTextures("exporter",t,e),[2,t]}}))}))},e.prototype._exportTextureImageAsync=function(e){return y(this,void 0,void 0,(function(){var t,n,r,o,i,a=this;return T(this,(function(s){switch(s.label){case 0:return t=null!==(i=e.mimeType)&&void 0!==i?i:"none",n=this._internalTextureToImage,r=e.getInternalTexture().uniqueId,n[r]=n[r]||{},void 0===(o=n[r][t])&&(o=y(a,void 0,void 0,(function(){var n,r,o,i,a;return T(this,(function(s){switch(s.label){case 0:return[4,C(e)];case 1:if((n=s.sent())&&("none"===t||n.mimeType===t))return[2,this._exportImage(e.name,n.mimeType,n.data)];if(r="image/png","none"!==t)switch(t){case"image/jpeg":case"image/png":case"image/webp":r=t;break;default:m.Tools.Warn("Unsupported media type: ".concat(t,". Exporting texture as PNG."))}return o=e.getSize(),[4,(0,m.GetTextureDataAsync)(e)];case 2:return i=s.sent(),[4,this._getImageDataAsync(i,o.width,o.height,r)];case 3:return a=s.sent(),[2,this._exportImage(e.name,r,a)]}}))})),n[r][t]=o),[4,o];case 1:return[2,s.sent()]}}))}))},e.prototype._exportImage=function(e,t,n){var r,o=this._exporter._images;if(this._exporter._shouldUseGlb){r={name:e,mimeType:t,bufferView:void 0};var i=this._exporter._bufferManager.createBufferView(new Uint8Array(n));this._exporter._bufferManager.setBufferView(r,i)}else{var a=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";case"image/ktx2":return".ktx2"}}(t),u=a+s;o.some((function(e){return e.uri===u}))&&(u="".concat(a,"_").concat(m.Tools.RandomId()).concat(s)),r={name:e,uri:u},this._exporter._imageData[u]={data:n,mimeType:t}}return o.push(r),o.length-1},e.prototype._exportTextureInfo=function(e,t,n){var r=this._exporter._textures,o=r.findIndex((function(n){return n.sampler==t&&n.source===e}));-1===o&&(o=r.length,r.push({source:e,sampler:t}));var i={index:o};return n&&(i.texCoord=n),i},e.prototype._exportTextureSampler=function(e){var t=this._getTextureSampler(e),n=this._exporter._samplers,r=n.findIndex((function(e){return e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT}));return-1!==r?r:(n.push(t),n.length-1)},e}(),P=m.Matrix.Compose(new m.Vector3(-1,1,1),m.Quaternion.Identity(),m.Vector3.Zero());function N(e,t){if(!(e instanceof m.TransformNode))return!1;if(t){if(!e.getWorldMatrix().equalsWithEpsilon(m.Matrix.IdentityReadOnly,m.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(P,m.TmpVectors.Matrix[0]).equalsWithEpsilon(m.Matrix.IdentityReadOnly,m.Epsilon))return!1;return!(e instanceof m.AbstractMesh&&e.geometry)}var U=m.Vector3.Zero(),L=m.Quaternion.Identity(),k=m.Vector3.One(),K=new m.Vector3(-1,1,1);function D(e,t){var n=e.byteOffset,r=e.byteStride,o=e.type,i=e.normalized,a=e.getSize(),s=t.reduce((function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e}),-Number.MAX_VALUE);return{byteOffset:n,byteStride:r,componentCount:a,type:o,count:s*a,normalized:i,totalVertices:s,kind:e.getKind()}}function G(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 W(e){switch(e){case m.VertexBuffer.PositionKind:case m.VertexBuffer.NormalKind:case m.VertexBuffer.TangentKind:case m.VertexBuffer.ColorKind:case m.VertexBuffer.MatricesIndicesKind:case m.VertexBuffer.MatricesIndicesExtraKind:case m.VertexBuffer.MatricesWeightsKind:case m.VertexBuffer.MatricesWeightsExtraKind:case m.VertexBuffer.UVKind:case m.VertexBuffer.UV2Kind:case m.VertexBuffer.UV3Kind:case m.VertexBuffer.UV4Kind:case m.VertexBuffer.UV5Kind:case m.VertexBuffer.UV6Kind:return!0}return!1}function H(e){switch(e){case m.Material.TriangleFillMode:return 4;case m.Material.TriangleStripDrawMode:return 5;case m.Material.TriangleFanDrawMode:return 6;case m.Material.PointListDrawMode:case m.Material.PointFillMode:return 0;case m.Material.LineLoopDrawMode:return 2;case m.Material.LineListDrawMode:return 1;case m.Material.LineStripDrawMode:return 3}throw new Error("Unknown fill mode: ".concat(e))}function q(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 j(e){return e.x*=-1,e}function z(e){if(e.x*e.x+e.y*e.y>.5){var t=Math.abs(e.x),n=Math.abs(e.y);if(t>n){var r=Math.sign(e.x);e.x=t,e.y*=-r,e.z*=-r,e.w*=r}else r=Math.sign(e.y),e.x*=-r,e.y=n,e.z*=r,e.w*=-r}else{var o=Math.abs(e.z),i=Math.abs(e.w);o>i?(r=Math.sign(e.z),e.x*=-r,e.y*=r,e.z=o,e.w*=-r):(r=Math.sign(e.w),e.x*=r,e.y*=-r,e.z*=-r,e.w=i)}return e}function Q(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function X(e,t){var n=m.Vector3.FromArrayToRef(t.translation||[0,0,0],0,m.TmpVectors.Vector3[0]),r=m.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,m.TmpVectors.Quaternion[0]),o=m.Matrix.ComposeToRef(k,r,n,m.TmpVectors.Matrix[0]),i=m.Vector3.FromArrayToRef(e.translation||[0,0,0],0,m.TmpVectors.Vector3[2]),a=m.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,m.TmpVectors.Quaternion[1]),s=m.Matrix.ComposeToRef(k,a,i,m.TmpVectors.Matrix[1]);o.multiplyToRef(s,s),s.decompose(void 0,r,n),n.equalsWithEpsilon(U,m.Epsilon)?delete t.translation:t.translation=n.asArray(),r.equalsWithEpsilon(L,m.Epsilon)?delete t.rotation:t.rotation=r.asArray(),t.scale&&delete t.scale}function Y(e,t){if(!(t instanceof m.TransformNode))return!1;if(1!==t.getChildren().length||0!==e.getChildren().length||e.parent!==t)return!1;var n=e.getScene(),r=e instanceof m.TargetCamera&&!n.useRightHandedSystem?K:k;return!!t.scaling.equalsWithEpsilon(r,m.Epsilon)||(m.Logger.Warn("Cannot collapse node ".concat(e.name," into parent node ").concat(t.name," with modified scaling.")),!1)}function Z(e,t){for(var n=0,r=Object.entries(e);n<r.length;n++){var o=r[n],i=o[0],a=o[1],s=t[i];(Array.isArray(a)&&Array.isArray(s)&&J(a,s)||a===s)&&delete e[i]}return e}function J(e,t){return e.length===t.length&&e.every((function(e,n){return e===t[n]}))}var $=new Map([[Int8Array,function(e,t,n){return e.setInt8(t,n)}],[Uint8Array,function(e,t,n){return e.setUint8(t,n)}],[Uint8ClampedArray,function(e,t,n){return e.setUint8(t,n)}],[Int16Array,function(e,t,n){return e.setInt16(t,n,!0)}],[Uint16Array,function(e,t,n){return e.setUint16(t,n,!0)}],[Int32Array,function(e,t,n){return e.setInt32(t,n,!0)}],[Uint32Array,function(e,t,n){return e.setUint32(t,n,!0)}],[Float32Array,function(e,t,n){return e.setFloat32(t,n,!0)}],[Float64Array,function(e,t,n){return e.setFloat64(t,n,!0)}]]),ee=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=$.get(e.constructor),n=0;n<e.length;n++)t(this._dataView,this._byteOffset,e[n]),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 n=new Uint8Array(2*t);n.set(this._data),this._data=n,this._dataView=new DataView(this._data.buffer)}},e}();function te(e){return e%4==0?4:e%2==0?2:1}var ne,re=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 n=new ee(t),r=0,o=Array.from(this._bufferViewToData.keys()).sort((function(e,t){return te(t.byteLength)-te(e.byteLength)}));r<o.length;r++){var i=o[r];i.byteOffset=n.byteOffset,e.push(i);for(var a=e.length-1,s=0,u=this.getPropertiesWithBufferView(i);s<u.length;s++)u[s].bufferView=a;n.writeTypedArray(this._bufferViewToData.get(i)),this._bufferViewToData.delete(i)}return n.getOutputData()},e.prototype.createBufferView=function(e,t){var n={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(n,e),n},e.prototype.createAccessor=function(e,t,n,r,o,i,a){this._verifyBufferView(e);var s={bufferView:void 0,componentType:n,count:r,type:t,min:null==i?void 0:i.min,max:null==i?void 0:i.max,normalized:a,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,n=0,r=this.getPropertiesWithBufferView(e);n<r.length;n++){var o=r[n];void 0!==o.bufferView&&delete o.bufferView}this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach((function(n,r){n===e&&(void 0!==r.byteOffset&&delete r.byteOffset,t._accessorToBufferView.delete(r))}))},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"}(ne||(ne={}));var oe=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,n,r,o,i){if(this._IsTransformable(t)){var a=[],s=[],u=n.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,r,o),f=l.interpolationType,h=l.shouldBakeAnimation;if(h?e._CreateBakedAnimation(t,n,r,c.min,c.max,n.framePerSecond,i,a,s,c,o):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(t,n,r,a,s,o):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(t,n,r,a,s,o):e._CreateBakedAnimation(t,n,r,c.min,c.max,n.framePerSecond,i,a,s,c,o),a.length&&s.length)return{inputs:a,outputs:s,samplerInterpolation:f,inputsMin:h?c.min:m.Tools.FloatRound(c.min/n.framePerSecond),inputsMax:h?c.max:m.Tools.FloatRound(c.max/n.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,n="VEC3",r=!1,o=e.targetProperty.split(".");switch(o[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":n="VEC4",t="rotation";break;case"rotationQuaternion":n="VEC4",r=!0,t="rotation";break;case"influence":n="SCALAR",t="weights";break;default:m.Tools.Error("Unsupported animatable property ".concat(o[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:n,useQuaternion:r}:(m.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,n,r,o,i,a,s,u,c,l,f){var h;if(e._IsTransformable(t)&&t.animations)for(var p=0,d=t.animations;p<d.length;p++){var m=d[p];if(!f||f(m)){var g=e._DeduceAnimationInfo(m);g&&(h={name:m.name,samplers:[],channels:[]},e._AddAnimation("".concat(m.name),m.hasRunningRuntimeAnimations?n:h,t,m,g.dataAccessorType,g.animationChannelTargetPath,o,a,s,u,g.useQuaternion,c,l),h.samplers.length&&h.channels.length&&r.push(h))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,n,r,o,i,a,s,u,c,l,f){var h;if(t instanceof m.Mesh){var p=t.morphTargetManager;if(p)for(var d=0;d<p.numTargets;++d)for(var g=0,x=p.getTarget(d).animations;g<x.length;g++){var _=x[g];if(!f||f(_)){for(var v=new m.Animation("".concat(_.name),"influence",_.framePerSecond,_.dataType,_.loopMode,_.enableBlending),y=[],T=_.getKeys(),b=0;b<T.length;++b)for(var w=T[b],M=0;M<p.numTargets;++M)M==d?y.push(w):y.push({frame:w.frame,value:0});v.setKeys(y);var A=e._DeduceAnimationInfo(v);A&&(h={name:v.name,samplers:[],channels:[]},e._AddAnimation(_.name,_.hasRunningRuntimeAnimations?n:h,t,v,A.dataAccessorType,A.animationChannelTargetPath,o,a,s,u,A.useQuaternion,c,l,p.numTargets),h.samplers.length&&h.channels.length&&r.push(h))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,n,r,o,i,a,s,u,c){var l,f;if(t.animationGroups)for(var h=t.animationGroups,p=function(h){var p=new Map,g=new Map,x=new Set,_=h.to-h.from;f={name:h.name,channels:[],samplers:[]};for(var v=function(n){var _=h.targetedAnimations[n],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(w=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,w.dataAccessorType,w.animationChannelTargetPath,r,o,i,a,w.useQuaternion,s,T)}}else if(v instanceof m.MorphTarget||1===v.length&&v[0]instanceof m.MorphTarget){var w;if(w=e._DeduceAnimationInfo(_.animation)){var M=v instanceof m.MorphTarget?v:v[0];if(M){var A=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===M)return!0;return!1}));if(A){var E=t.meshes.find((function(e){return e.morphTargetManager===A}));E&&(p.has(E)||p.set(E,new Map),null===(l=p.get(E))||void 0===l||l.set(M,y),x.add(E),g.set(E,y))}}}}},y=0;y<h.targetedAnimations.length;++y)v(y);x.forEach((function(t){for(var n=t.morphTargetManager,u=null,c=[],l=g.get(t).getKeys(),d=l.length,x=0;x<d;++x)for(var v=0;v<n.numTargets;++v){var y=n.getTarget(v),T=p.get(t);if(T){var b=T.get(y);b?(u||(u=new m.Animation("".concat(h.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,m.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[x])):c.push({frame:h.from+_/d*x,value:y.influence,inTangent:l[0].inTangent?0:void 0,outTangent:l[0].outTangent?0:void 0})}}u.setKeys(c);var w=e._DeduceAnimationInfo(u);w&&e._AddAnimation("".concat(h.name,"_").concat(t.name,"_MorphWeightAnimation"),f,t,u,w.dataAccessorType,w.animationChannelTargetPath,r,o,i,a,w.useQuaternion,s,!1,null==n?void 0:n.numTargets)})),f.channels.length&&f.samplers.length&&n.push(f)},d=this,g=0,x=h;g<x.length;g++)p(x[g])},e._AddAnimation=function(t,n,r,o,i,a,s,u,c,l,f,h,p,d){var g,x,_,v,y,T,b=e._CreateNodeAnimation(r,o,a,f,h);if(b){if(d){for(var w=0,M=0,A=[];b.inputs.length>0;)M=b.inputs.shift(),w%d==0&&A.push(M),w++;b.inputs=A}var E=s.get(r),R=new Float32Array(b.inputs);g=u.createBufferView(R),x=u.createAccessor(g,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(x),_=l.length-1;var C=new m.Quaternion,V=new m.Vector3,S=new m.Vector3,I=r instanceof m.Camera,F=G(i),B=new Float32Array(b.outputs.length*F);b.outputs.forEach((function(e,t){var n=e;switch(a){case"translation":p&&(m.Vector3.FromArrayToRef(e,0,S),j(S),S.toArray(n));break;case"rotation":4===e.length?m.Quaternion.FromArrayToRef(e,0,C):(n=new Array(4),m.Vector3.FromArrayToRef(e,0,V),m.Quaternion.FromEulerVectorToRef(V,C)),p&&(z(C),I&&Q(C)),C.toArray(n)}B.set(n,t*F)})),g=u.createBufferView(B),x=u.createAccessor(g,i,5126,b.outputs.length),l.push(x),v=l.length-1,y={interpolation:b.samplerInterpolation,input:_,output:v},n.samplers.push(y),T={sampler:n.samplers.length-1,target:{node:E,path:a}},n.channels.push(T)}},e._CreateBakedAnimation=function(t,n,r,o,i,a,s,u,c,l,f){var h,p,d=m.Quaternion.Identity(),g=null,x=null,_=null,v=null,y=null,T=null;l.min=m.Tools.FloatRound(o/a);for(var b=n.getKeys(),w=0,M=b.length;w<M;++w){if(T=null,_=b[w],w+1<M)if(v=b[w+1],_.value.equals&&_.value.equals(v.value)||_.value===v.value){if(0!==w)continue;T=_.frame}else T=v.frame;else{if(y=b[w-1],_.value.equals&&_.value.equals(y.value)||_.value===y.value)continue;T=i}if(T)for(var A=_.frame;A<=T;A+=s)if((p=m.Tools.FloatRound(A/a))!==g){g=p,x=p;var E={key:0,repeatCount:0,loopMode:n.loopMode};h=n._interpolate(A,E),e._SetInterpolatedValue(t,h,p,n,r,d,u,c,f)}}x&&(l.max=x)},e._ConvertFactorToVector3OrQuaternion=function(t,n,r,o,i){var a=e._GetBasePositionRotationOrScale(n,o,i),s=r.targetProperty.split("."),u=s?s[1]:"",c=i?m.Quaternion.FromArray(a).normalize():m.Vector3.FromArray(a);switch(u){case"x":case"y":case"z":c[u]=t;break;case"w":c.w=t;break;default:m.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return c},e._SetInterpolatedValue=function(e,t,n,r,o,i,a,s,u){var c;a.push(n),"weights"!==o?(r.dataType===m.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,r,o,u)),"rotation"===o?(u?i=t:(c=t,m.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,i)),s.push(i.asArray())):(c=t,s.push(c.asArray()))):s.push([t])},e._CreateLinearOrStepAnimation=function(t,n,r,o,i,a){for(var s=0,u=n.getKeys();s<u.length;s++){var c=u[s];o.push(c.frame/n.framePerSecond),e._AddKeyframeValue(c,n,i,r,t,a)}},e._CreateCubicSplineAnimation=function(t,n,r,o,i,a){n.getKeys().forEach((function(s){o.push(s.frame/n.framePerSecond),e._AddSplineTangent(ne.INTANGENT,i,r,"CUBICSPLINE",s,a),e._AddKeyframeValue(s,n,i,r,t,a),e._AddSplineTangent(ne.OUTTANGENT,i,r,"CUBICSPLINE",s,a)}))},e._GetBasePositionRotationOrScale=function(e,t,n){var r;if("rotation"===t)if(n){var o=e.rotationQuaternion;r=(null!=o?o:m.Quaternion.Identity()).asArray()}else{var i=e.rotation;r=(null!=i?i:m.Vector3.Zero()).asArray()}else if("translation"===t){var a=e.position;r=(null!=a?a:m.Vector3.Zero()).asArray()}else{var s=e.scaling;r=(null!=s?s:m.Vector3.One()).asArray()}return r},e._AddKeyframeValue=function(e,t,n,r,o,i){var a,s=t.dataType;if(s===m.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===r){var c=m.Vector3.FromArray(u);u=m.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}n.push(u)}else if(s===m.Animation.ANIMATIONTYPE_FLOAT){if("weights"===r)n.push([e.value]);else if(a=this._ConvertFactorToVector3OrQuaternion(e.value,o,t,r,i)){if("rotation"===r){var l=i?a:m.Quaternion.RotationYawPitchRoll(a.y,a.x,a.z).normalize();n.push(l.asArray())}n.push(a.asArray())}}else s===m.Animation.ANIMATIONTYPE_QUATERNION?n.push(e.value.normalize().asArray()):m.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,n){var r,o,i=!1;if("rotation"===t&&!n)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var a=0,s=e.length;a<s;++a)if((o=e[a]).inTangent||o.outTangent)if(r){if("CUBICSPLINE"!==r){r="LINEAR",i=!0;break}}else r="CUBICSPLINE";else if(r){if("CUBICSPLINE"===r||o.interpolation&&1===o.interpolation&&"STEP"!==r){r="LINEAR",i=!0;break}}else r=o.interpolation&&1===o.interpolation?"STEP":"LINEAR";return r||(r="LINEAR"),{interpolationType:r,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,t,n,r,o,i){var a,s=e===ne.INTANGENT?o.inTangent:o.outTangent;if("CUBICSPLINE"===r){if("rotation"===n)if(s)if(i)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"===n?s?[s]:[0]:s?s.asArray():[0,0,0];t.push(a)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,n=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),n=Math.max(n,e.frame)})),{min:t,max:n}},e}();function ie(e,t,n,r,o,i){var a={attributes:{},influence:e.influence,name:e.name},s=t.geometry;if(!s)return m.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),a;var u=i?-1:1,c=m.Vector3.Zero(),l=0;if(e.hasPositions){var f=e.getPositions(),h=s.getVerticesData(m.VertexBuffer.PositionKind);if(h){var p=new Float32Array(h.length),d=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0];l=h.length/3;for(var x=0;x<l;++x){var _=m.Vector3.FromArray(h,3*x);m.Vector3.FromArray(f,3*x).subtractToRef(_,c),c.x*=u,d[0]=Math.min(d[0],c.x),g[0]=Math.max(g[0],c.x),d[1]=Math.min(d[1],c.y),g[1]=Math.max(g[1],c.y),d[2]=Math.min(d[2],c.z),g[2]=Math.max(g[2],c.z),p[3*x]=c.x,p[3*x+1]=c.y,p[3*x+2]=c.z}var v=n.createBufferView(p,12),y=n.createAccessor(v,"VEC3",5126,f.length/3,0,{min:d,max:g});o.push(y),a.attributes.POSITION=o.length-1}else m.Tools.Warn("Morph target positions for mesh ".concat(t.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var T=e.getNormals(),b=s.getVerticesData(m.VertexBuffer.NormalKind);if(b){var w=new Float32Array(b.length);for(l=b.length/3,x=0;x<l;++x){var M=m.Vector3.FromArray(b,3*x).normalize();m.Vector3.FromArray(T,3*x).normalize().subtractToRef(M,c),w[3*x]=c.x*u,w[3*x+1]=c.y,w[3*x+2]=c.z}v=n.createBufferView(w,12),y=n.createAccessor(v,"VEC3",5126,T.length/3,0),o.push(y),a.attributes.NORMAL=o.length-1}else m.Tools.Warn("Morph target normals for mesh ".concat(t.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var A=e.getTangents(),E=s.getVerticesData(m.VertexBuffer.TangentKind);if(E){l=E.length/4;var R=new Float32Array(3*l);for(x=0;x<l;++x){var C=m.Vector3.FromArray(E,4*x);q(C);var V=m.Vector3.FromArray(A,3*x);q(V),V.subtractToRef(C,c),R[3*x]=c.x*u,R[3*x+1]=c.y,R[3*x+2]=c.z}v=n.createBufferView(R,12),y=n.createAccessor(v,"VEC3",5126,l,0),o.push(y),a.attributes.TANGENT=o.length-1}else m.Tools.Warn("Morph target tangents for mesh ".concat(t.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var S=e.getColors(),I=s.getVerticesData(m.VertexBuffer.ColorKind),F=s.getVertexBuffer(m.VertexBuffer.ColorKind);if(I&&F){var B=F.getSize();l=I.length/B;var O=new Float32Array(l*B);for(x=0;x<l;++x)if(3===B){var P=m.Vector3.FromArray(I,x*B);m.Vector3.FromArray(S,x*B).subtractToRef(P,c),O[3*x]=c.x,O[3*x+1]=c.y,O[3*x+2]=c.z}else if(4===B){var N=new m.Vector4;P=m.Vector4.FromArray(I,x*B),m.Vector4.FromArray(S,x*B).subtractToRef(P,N),O[4*x]=N.x,O[4*x+1]=N.y,O[4*x+2]=N.z,O[4*x+3]=N.w}else m.Tools.Warn("Unsupported number of components for color attribute: ".concat(B));v=n.createBufferView(O,4*B),y=n.createAccessor(v,3===B?"VEC3":"VEC4",5126,l,0),o.push(y),a.attributes.COLOR_0=o.length-1}else m.Tools.Warn("Morph target colors for mesh ".concat(t.name," were not exported. Mesh does not have colors vertex data"))}return a}var ae=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,n,r,o){var i,a,s,u;return null===(u=null===(s=null===(a=null===(i=this._indicesAccessorMap.get(e))||void 0===i?void 0:i.get(t))||void 0===a?void 0:a.get(n))||void 0===s?void 0:s.get(r))||void 0===u?void 0:u.get(o)},e.prototype.setIndicesAccessor=function(e,t,n,r,o,i){var a=this._indicesAccessorMap.get(e);a||(a=new Map,this._indicesAccessorMap.set(e,a));var s=a.get(t);s||(s=new Map,a.set(t,s));var u=s.get(n);u||(u=new Map,s.set(n,u));var c=u.get(r);c||(c=new Map,u.set(r,c)),c.set(o,i)},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,n){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,n)},e.prototype.getRemappedBufferView=function(e,t){var n;return null===(n=this._remappedBufferView.get(e))||void 0===n?void 0:n.get(t)},e.prototype.getVertexAccessor=function(e,t,n){var r,o;return null===(o=null===(r=this._vertexAccessorMap.get(e))||void 0===r?void 0:r.get(t))||void 0===o?void 0:o.get(n)},e.prototype.setVertexAccessor=function(e,t,n,r){var o=this._vertexAccessorMap.get(e);o||(o=new Map,this._vertexAccessorMap.set(e,o));var i=o.get(t);i||(i=new Map,o.set(t,i)),i.set(n,r)},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 n=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,n),-1===n.indexOf(t)&&n.push(t)},e.prototype.getMorphTargetsFromMesh=function(e){return this._meshMorphTargetMap.get(e)},e}(),se=function(){function e(e,t){if(void 0===e&&(e=m.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(m.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 O(this),this._extensions={},this._bufferManager=new re,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=v({shouldExportNode:function(){return!0},shouldExportAnimation:function(){return!0},metadataSelector:function(e){var t;return null===(t=null==e?void 0:e.gltf)||void 0===t?void 0:t.extras},animationSampleRate:1/60,exportWithoutWaitingForScene:!1,exportUnusedUVs:!1,removeNoopRootNodes:!0,includeCoordinateSystemConversionNodes:!1,meshCompressionMethod:"None"},t),this._loadExtensions()}return e.prototype._ApplyExtension=function(e,t,n,r){var o=this;if(n>=t.length)return Promise.resolve(e);var i=r(t[n],e);return i?i.then((function(e){return y(o,void 0,void 0,(function(){var o;return T(this,(function(i){switch(i.label){case 0:return e?[4,this._ApplyExtension(e,t,n+1,r)]:[3,2];case 1:return o=i.sent(),[3,3];case 2:o=null,i.label=3;case 3:return[2,o]}}))}))})):this._ApplyExtension(e,t,n+1,r)},e.prototype._ApplyExtensions=function(t,n){for(var r=[],o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o];r.push(this._extensions[a])}return this._ApplyExtension(t,r,0,n)},e.prototype._extensionsPostExportNodeAsync=function(e,t,n,r,o){var i=this;return this._ApplyExtensions(t,(function(t,a){return t.postExportNodeAsync&&t.postExportNodeAsync(e,a,n,r,o,i._bufferManager)}))},e.prototype._extensionsPostExportMaterialAsync=function(e,t,n){return this._ApplyExtensions(t,(function(t,r){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,r,n)}))},e.prototype._extensionsPostExportMaterialAdditionalTextures=function(t,n,r){for(var o=[],i=0,a=e._ExtensionNames;i<a.length;i++){var s=a[i],u=this._extensions[s];u.postExportMaterialAdditionalTextures&&o.push.apply(o,u.postExportMaterialAdditionalTextures(t,n,r))}return o},e.prototype._extensionsPostExportTextures=function(t,n,r){for(var o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o],s=this._extensions[a];s.postExportTexture&&s.postExportTexture(t,n,r)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var n=0,r=e._ExtensionNames;n<r.length;n++){var o=r[n],i=this._extensions[o];i.postExportMeshPrimitive&&i.postExportMeshPrimitive(t,this._bufferManager,this._accessors)}},e.prototype._extensionsPreGenerateBinaryAsync=function(){return y(this,void 0,void 0,(function(){var t,n,r,o;return T(this,(function(i){switch(i.label){case 0:t=0,n=e._ExtensionNames,i.label=1;case 1:return t<n.length?(r=n[t],(o=this._extensions[r]).preGenerateBinaryAsync?[4,o.preGenerateBinaryAsync(this._bufferManager)]:[3,3]):[3,4];case 2:i.sent(),i.label=3;case 3:return t++,[3,1];case 4:return[2]}}))}))},e.prototype._forEachExtensions=function(t){for(var n=0,r=e._ExtensionNames;n<r.length;n++){var o=r[n],i=this._extensions[o];i.enabled&&t(i)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){var n,r,o;t.wasUsed&&((n=e._glTF).extensionsUsed||(n.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&((r=e._glTF).extensionsRequired||(r.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,n=e._ExtensionNames;t<n.length;t++){var r=n[t],o=e._ExtensionFactories[r](this);this._extensions[r]=o}},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,n){e.UnregisterExtension(t)&&m.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=n,e._ExtensionNames.push(t)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t];var n=e._ExtensionNames.indexOf(t);return-1!==n&&e._ExtensionNames.splice(n,1),!0},e.prototype._generateJSON=function(e,t,n){var r={byteLength:e};return r.byteLength&&(this._glTF.buffers=[r]),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&&(this._glTF.images=this._images),this._shouldUseGlb||(r.uri=t+".bin"),n?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)},e.prototype.generateGLTFAsync=function(e){return y(this,void 0,void 0,(function(){var t,n,r,o,i,a,s;return T(this,(function(u){switch(u.label){case 0:return[4,this._generateBinaryAsync()];case 1:if(t=u.sent(),this._extensionsOnExporting(),n=this._generateJSON(t.byteLength,e,!0),r=new Blob([t],{type:"application/octet-stream"}),o=e+".gltf",i=e+".bin",(a=new _).files[o]=n,a.files[i]=r,this._imageData)for(s in this._imageData)a.files[s]=new Blob([this._imageData[s].data],{type:this._imageData[s].mimeType});return[2,a]}}))}))},e.prototype._generateBinaryAsync=function(){return y(this,void 0,void 0,(function(){return T(this,(function(e){switch(e.label){case 0:return[4,this._exportSceneAsync()];case 1:return e.sent(),[4,this._extensionsPreGenerateBinaryAsync()];case 2:return e.sent(),[2,this._bufferManager.generateBinary(this._bufferViews)]}}))}))},e.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},e.prototype.generateGLBAsync=function(e){return y(this,void 0,void 0,(function(){var t,n,r,o,i,a,s,u,c,l,f,h,p,d;return T(this,(function(m){switch(m.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=m.sent(),this._extensionsOnExporting(),n=this._generateJSON(t.byteLength),r=e+".glb",o=n.length,"undefined"!=typeof TextEncoder&&(a=new TextEncoder,i=a.encode(n),o=i.length),s=this._getPadding(o),u=this._getPadding(t.byteLength),c=28+o+s+t.byteLength+u,(l=new ee(c)).writeUInt32(1179937895),l.writeUInt32(2),l.writeUInt32(c),l.writeUInt32(o+s),l.writeUInt32(1313821514),i)l.writeTypedArray(i);else for(f="_".charCodeAt(0),p=0;p<o;++p)(h=n.charCodeAt(p))!=n.codePointAt(p)?l.writeUInt8(f):l.writeUInt8(h);for(p=0;p<s;++p)l.writeUInt8(32);for(l.writeUInt32(t.byteLength+u),l.writeUInt32(5130562),l.writeTypedArray(t),p=0;p<u;++p)l.writeUInt8(0);return(d=new _).files[r]=new Blob([l.getOutputData()],{type:"application/octet-stream"}),[2,d]}}))}))},e.prototype._setNodeTransformation=function(e,t,n){var r;if(t.getPivotPoint().equalsWithEpsilon(U,m.Epsilon)||m.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsWithEpsilon(U,m.Epsilon)){var o=m.TmpVectors.Vector3[0].copyFrom(t.position);n&&j(o),e.translation=o.asArray()}t.scaling.equalsWithEpsilon(k,m.Epsilon)||(e.scale=t.scaling.asArray());var i=(null===(r=t.rotationQuaternion)||void 0===r?void 0:r.clone())||m.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);i.equalsWithEpsilon(L,m.Epsilon)||(n&&z(i),e.rotation=i.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,n){if(!t.position.equalsWithEpsilon(U,m.Epsilon)){var r=m.TmpVectors.Vector3[0].copyFrom(t.position);n&&j(r),e.translation=r.asArray()}var o=t.rotationQuaternion||m.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);n&&z(o),this._babylonScene.useRightHandedSystem||Q(o),o.equalsWithEpsilon(L,m.Epsilon)||(e.rotation=o.asArray())},e.prototype._listAvailableCameras=function(){for(var e=0,t=this._babylonScene.cameras;e<t.length;e++){var n=t[e],r={type:n.mode===m.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(n.name&&(r.name=n.name),"perspective"===r.type)r.perspective={aspectRatio:n.getEngine().getAspectRatio(n),yfov:n.fovMode===m.Camera.FOVMODE_VERTICAL_FIXED?n.fov:n.fov*n.getEngine().getAspectRatio(n),znear:n.minZ,zfar:n.maxZ};else if("orthographic"===r.type){var o=n.orthoLeft&&n.orthoRight?.5*(n.orthoRight-n.orthoLeft):.5*n.getEngine().getRenderWidth(),i=n.orthoBottom&&n.orthoTop?.5*(n.orthoTop-n.orthoBottom):.5*n.getEngine().getRenderHeight();r.orthographic={xmag:o,ymag:i,znear:n.minZ,zfar:n.maxZ}}this._camerasMap.set(n,r)}},e.prototype._exportAndAssignCameras=function(){for(var e=0,t=Array.from(this._camerasMap.values());e<t.length;e++){var n=t[e],r=this._nodesCameraMap.get(n);if(void 0!==r){this._cameras.push(n);for(var o=0,i=r;o<i.length;o++)i[o].camera=this._cameras.length-1}}},e.prototype._listAvailableSkeletons=function(){for(var e=0,t=this._babylonScene.skeletons;e<t.length;e++){var n=t[e];n.bones.length<=0||this._skinMap.set(n,{joints:[]})}},e.prototype._exportAndAssignSkeletons=function(e){for(var t,n=function(n){if(n.bones.length<=0)return"continue";var o=r._skinMap.get(n);if(null==o)return"continue";for(var i={},a=-1,s=0;s<n.bones.length;++s){var u=n.bones[s];-1!==(f=null!==(t=u.getIndex())&&void 0!==t?t:s)&&(i[f]=u,f>a&&(a=f))}for(var c,l=[],f=0;f<=a;++f){var h=(u=i[f]).getTransformNode(),p=h?r._nodeMap.get(h):void 0;if(void 0!==p){o.joints.push(p);var d=u.getAbsoluteInverseBindMatrix().clone();e.has(h)&&(c=d,P.invertToRef(m.TmpVectors.Matrix[0]).multiplyToRef(c,c).multiplyToRef(P,c)),l.push(d)}else m.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.")}var g=r._nodesSkinMap.get(o);if(o.joints.length>0&&void 0!==g){var x=new Float32Array(16*l.length);l.forEach((function(e,t){x.set(e.m,16*t)}));var _=r._bufferManager.createBufferView(x);r._accessors.push(r._bufferManager.createAccessor(_,"MAT4",5126,l.length)),o.inverseBindMatrices=r._accessors.length-1,r._skins.push(o);for(var v=r._skins.length-1,y=0,T=g;y<T.length;y++)T[y].skin=v}},r=this,o=0,i=this._babylonScene.skeletons;o<i.length;o++)n(i[o])},e.prototype._exportSceneAsync=function(){return y(this,void 0,void 0,(function(){var e,t,n,r,o,i,a,s,u,c,l,f,h,p,d,m,g,x,_,v,y,b,w;return T(this,(function(T){switch(T.label){case 0:for(e={nodes:[]},this._babylonScene.metadata&&(t=this._options.metadataSelector(this._babylonScene.metadata))&&(e.extras=t),n=new Array,r=new Array,o=new Array,i=0,a=this._babylonScene.rootNodes;i<a.length;i++)s=a[i],this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&N(s,this._babylonScene.useRightHandedSystem)?o.push.apply(o,s.getChildren()):this._babylonScene.useRightHandedSystem?n.push(s):r.push(s);return this._listAvailableCameras(),this._listAvailableSkeletons(),u=new ae(!0,!1),l=(c=(y=e.nodes).push).apply,f=[y],[4,this._exportNodesAsync(r,u)];case 1:return l.apply(c,f.concat([T.sent()])),h=new ae(!1,!1),d=(p=(b=e.nodes).push).apply,m=[b],[4,this._exportNodesAsync(n,h)];case 2:return d.apply(p,m.concat([T.sent()])),g=new ae(!1,!0),_=(x=(w=e.nodes).push).apply,v=[w],[4,this._exportNodesAsync(o,g)];case 3:return _.apply(x,v.concat([T.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(u.getNodesSet()),this._babylonScene.animationGroups.length&&oe._CreateNodeAndMorphAnimationFromAnimationGroups(this._babylonScene,this._animations,this._nodeMap,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,u.getNodesSet(),this._options.shouldExportAnimation),[2]}}))}))},e.prototype._shouldExportNode=function(e){var t=this._shouldExportNodeMap.get(e);return void 0===t&&(t=this._options.shouldExportNode(e),this._shouldExportNodeMap.set(e,t)),t},e.prototype._exportNodesAsync=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,i;return T(this,(function(a){switch(a.label){case 0:n=new Array,this._exportBuffers(e,t),r=0,o=e,a.label=1;case 1:return r<o.length?(i=o[r],[4,this._exportNodeAsync(i,n,t)]):[3,4];case 2:a.sent(),a.label=3;case 3:return r++,[3,1];case 4:return[2,n]}}))}))},e.prototype._collectBuffers=function(e,t,n,r,o){if(this._shouldExportNode(e)&&e instanceof m.AbstractMesh&&e.geometry){var i=e.geometry.getVertexBuffers();if(i)for(var a in i)if(W(a)){var s=i[a];o.setHasVertexColorAlpha(s,e.hasVertexAlpha);var u=s._buffer,c=t.get(u)||[];t.set(u,c),-1===c.indexOf(s)&&c.push(s);var l=n.get(s)||[];n.set(s,l),-1===l.indexOf(e)&&l.push(e)}var f=e.morphTargetManager;if(f)for(var h=0;h<f.numTargets;h++){var p=f.getTarget(h);l=r.get(p)||[],r.set(p,l),-1===l.indexOf(e)&&l.push(e)}}for(var d=0,g=e.getChildren();d<g.length;d++){var x=g[d];this._collectBuffers(x,t,n,r,o)}},e.prototype._exportBuffers=function(e,t){for(var n=new Map,r=new Map,o=new Map,i=0,a=e;i<a.length;i++){var s=a[i];this._collectBuffers(s,n,r,o,t)}for(var u=Array.from(n.keys()),c=function(e){var o=e.getData();if(!o)throw new Error("Buffer data is not available");var i=n.get(e);if(!i)return"continue";var a=i[0].byteStride;if(i.some((function(e){return e.byteStride!==a})))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");for(var s=function(e){if(e instanceof Array){var t=new Float32Array(e);return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}return ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e)}(o).slice(),u=function(e){var t=r.get(e),n=D(e,t),o=n.byteOffset,i=n.byteStride,a=n.componentCount,u=n.type,c=n.count,f=n.normalized;switch(n.kind){case m.VertexBuffer.NormalKind:case m.VertexBuffer.TangentKind:(0,m.EnumerateFloatValues)(s,o,i,a,u,c,f,(function(e){var t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){var n=1/t;e[0]*=n,e[1]*=n,e[2]*=n}}));break;case m.VertexBuffer.ColorKind:var h=t.filter((function(e){return e.material instanceof m.StandardMaterial||null==e.material})).length;if(0==h)break;if(h!=t.length){m.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}u==m.VertexBuffer.UNSIGNED_BYTE&&m.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var p=new m.Color3,d=new m.Color4,g=l._babylonScene.getEngine().useExactSrgbConversions;(0,m.EnumerateFloatValues)(s,o,i,a,u,c,f,(function(e){3===e.length?(p.fromArray(e,0),p.toLinearSpaceToRef(p,g),p.toArray(e,0)):(d.fromArray(e,0),d.toLinearSpaceToRef(d,g),d.toArray(e,0))}))}},c=0,f=i;c<f.length;c++)u(F=f[c]);if(t.convertToRightHanded){for(var h=0,p=i;h<p.length;h++){var d=D(F=p[h],r.get(F)),g=d.byteOffset,x=d.byteStride,_=d.componentCount,v=d.type,y=d.count,T=d.normalized;switch(R=d.kind){case m.VertexBuffer.PositionKind:case m.VertexBuffer.NormalKind:case m.VertexBuffer.TangentKind:(0,m.EnumerateFloatValues)(s,g,x,_,v,y,T,(function(e){e[0]=-e[0]}))}}t.convertedToRightHandedBuffers.set(e,s)}var b=l._bufferManager.createBufferView(s,a);t.setVertexBufferView(e,b);for(var w=new Map,M=0,A=i;M<A.length;M++){var E=D(F=A[M],r.get(F)),R=E.kind,C=E.totalVertices;switch(R){case m.VertexBuffer.MatricesIndicesKind:case m.VertexBuffer.MatricesIndicesExtraKind:if(F.type==m.VertexBuffer.FLOAT){var V=F.getFloatData(C);null!==V&&w.set(F,V)}}}0!==w.size&&m.Logger.Warn("Joint indices conversion needed: some joint indices are stored as floats in Babylon but GLTF requires UNSIGNED BYTES. We will perform the conversion but this might lead to unused data in the buffer.");for(var S=0,I=Array.from(w.keys());S<I.length;S++){var F=I[S],B=w.get(F);if(B){for(var O=B.some((function(e){return e>=256})),P=new(O?Uint16Array:Uint8Array)(B.length),N=0;N<B.length;N++)P[N]=B[N];var U=l._bufferManager.createBufferView(P,4*(O?2:1));t.setRemappedBufferView(e,F,U)}}},l=this,f=0,h=u;f<h.length;f++)c(h[f]);for(var p=0,d=Array.from(o.keys());p<d.length;p++){var g=d[p],x=o.get(g);if(x)for(var _=ie(g,x[0],this._bufferManager,this._bufferViews,this._accessors,t.convertToRightHanded),v=0,y=x;v<y.length;v++){var T=y[v];t.bindMorphDataToMesh(T,_)}}},e.prototype._exportNodeAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var r,o,i,a,s,u,c,l,f=this;return T(this,(function(h){switch(h.label){case 0:return void 0!==(r=this._nodeMap.get(e))?(t.includes(r)||t.push(r),[2]):[4,this._createNodeAsync(e,n)];case 1:(o=h.sent())&&(r=this._nodes.length,this._nodes.push(o),this._nodeMap.set(e,r),n.pushExportedNode(e),t.push(r),i={name:"runtime animations",channels:[],samplers:[]},a=[],this._babylonScene.animationGroups.length||(oe._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,a,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&oe._CreateNodeAnimationFromNodeAnimations(e,i,a,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation)),i.channels.length&&i.samplers.length&&this._animations.push(i),a.forEach((function(e){e.channels.length&&e.samplers.length&&f._animations.push(e)}))),s=o?[]:t,u=0,c=e.getChildren(),h.label=2;case 2:return u<c.length?(l=c[u],[4,this._exportNodeAsync(l,s,n)]):[3,5];case 3:h.sent(),h.label=4;case 4:return u++,[3,2];case 5:return o&&s.length&&(o.children=s),[2]}}))}))},e.prototype._createNodeAsync=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,i,a,s,u,c,l,f,h,p;return T(this,(function(d){switch(d.label){case 0:return this._shouldExportNode(e)?(n={},e.name&&(n.name=e.name),e.metadata&&(r=this._options.metadataSelector(e.metadata))&&(n.extras=r),e instanceof m.TransformNode?(this._setNodeTransformation(n,e,t.convertToRightHanded),e instanceof m.AbstractMesh?(o=e instanceof m.InstancedMesh?e.sourceMesh:e).subMeshes&&o.subMeshes.length>0?(i=n,[4,this._exportMeshAsync(o,t)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:i.mesh=d.sent(),d.label=2;case 2:e.skeleton&&void 0!==(a=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(a)&&this._nodesSkinMap.set(a,[]),null===(f=this._nodesSkinMap.get(a))||void 0===f||f.push(n)),d.label=3;case 3:if(e instanceof m.TargetCamera&&(s=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(s)&&this._nodesCameraMap.set(s,[]),this._setCameraTransformation(n,e,t.convertToRightHanded),null!==(u=e.parent)&&Y(e,u)&&void 0!==(c=this._nodeMap.get(u)))return l=this._nodes[c],X(n,l),null===(h=this._nodesCameraMap.get(s))||void 0===h||h.push(l),[2,null];null===(p=this._nodesCameraMap.get(s))||void 0===p||p.push(n)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",n,e,this._nodeMap,t.convertToRightHanded)];case 4:return d.sent()?[2,n]:(m.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}}))}))},e.prototype._exportIndices=function(e,t,n,r,o,i,a,s,u){var c=e;u.mode=H(i);var l=a!==m.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case m.Material.TriangleFillMode:case m.Material.TriangleStripDrawMode:case m.Material.TriangleFanDrawMode:return!0}return!1}(i);if(l){if(i===m.Material.TriangleStripDrawMode||i===m.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");u.mode=H(i);var f=t?new Uint32Array(r):new Uint16Array(r);if(e)for(var h=0;h+2<r;h+=3)f[h]=e[n+h]+o,f[h+1]=e[n+h+2]+o,f[h+2]=e[n+h+1]+o;else for(h=0;h+2<r;h+=3)f[h]=h,f[h+1]=h+2,f[h+2]=h+1;c=f}else if(e&&0!==o){for(f=t?new Uint32Array(r):new Uint16Array(r),h=0;h<r;h++)f[h]=e[n+h]+o;c=f}if(c){var p=s.getIndicesAccessor(e,n,r,o,l);if(void 0===p){var d=function(e,t,n,r){if(e instanceof Uint16Array||e instanceof Uint32Array)return e;if(e instanceof Int32Array)return new Uint32Array(e.buffer,e.byteOffset,e.length);var o=e.slice(0,0+n);return r?new Uint32Array(o):new Uint16Array(o)}(c,0,r,t),g=this._bufferManager.createBufferView(d),x=t?5125:5123;this._accessors.push(this._bufferManager.createAccessor(g,"SCALAR",x,r,0)),p=this._accessors.length-1,s.setIndicesAccessor(e,n,r,o,l,p)}u.indices=p}},e.prototype._exportVertexBuffer=function(e,t,n,r,o,i){var a=e.getKind();if(W(a)&&(!a.startsWith("uv")||this._options.exportUnusedUVs||t&&this._materialNeedsUVsSet.has(t))){var s=o.getVertexAccessor(e,n,r);if(void 0===s){var u=o.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),c=a===m.VertexBuffer.PositionKind?function(e,t,n,r){var o=t.byteOffset,i=t.byteStride,a=t.type,s=t.normalized,u=t.getSize(),c=new Array(u).fill(1/0),l=new Array(u).fill(-1/0);return(0,m.EnumerateFloatValues)(e,o+n*i,i,u,a,r*u,s,(function(e){for(var t=0;t<u;t++)c[t]=Math.min(c[t],e[t]),l[t]=Math.max(l[t],e[t])})),{min:c,max:l}}(u,e,n,r):void 0,l=(a===m.VertexBuffer.MatricesIndicesKind||a===m.VertexBuffer.MatricesIndicesExtraKind)&&e.type===m.VertexBuffer.FLOAT,f=l?m.VertexBuffer.UNSIGNED_BYTE:e.type,h=l?void 0:e.normalized,p=l?o.getRemappedBufferView(e._buffer,e):o.getVertexBufferView(e._buffer),d=e.byteOffset+n*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(p,function(e,t){if(e==m.VertexBuffer.ColorKind)return t?"VEC4":"VEC3";switch(e){case m.VertexBuffer.PositionKind:case m.VertexBuffer.NormalKind:return"VEC3";case m.VertexBuffer.TangentKind:case m.VertexBuffer.MatricesIndicesKind:case m.VertexBuffer.MatricesIndicesExtraKind:case m.VertexBuffer.MatricesWeightsKind:case m.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case m.VertexBuffer.UVKind:case m.VertexBuffer.UV2Kind:case m.VertexBuffer.UV3Kind:case m.VertexBuffer.UV4Kind:case m.VertexBuffer.UV5Kind:case m.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(a,o.hasVertexColorAlpha(e)),f,r,d,c,h)),s=this._accessors.length-1,o.setVertexAccessor(e,n,r,s)}i.attributes[function(e){switch(e){case m.VertexBuffer.PositionKind:return"POSITION";case m.VertexBuffer.NormalKind:return"NORMAL";case m.VertexBuffer.TangentKind:return"TANGENT";case m.VertexBuffer.ColorKind:return"COLOR_0";case m.VertexBuffer.UVKind:return"TEXCOORD_0";case m.VertexBuffer.UV2Kind:return"TEXCOORD_1";case m.VertexBuffer.UV3Kind:return"TEXCOORD_2";case m.VertexBuffer.UV4Kind:return"TEXCOORD_3";case m.VertexBuffer.UV5Kind:return"TEXCOORD_4";case m.VertexBuffer.UV6Kind:return"TEXCOORD_5";case m.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case m.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case m.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case m.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(a)]=s}},e.prototype._exportMaterialAsync=function(e,t,n,r){return y(this,void 0,void 0,(function(){var o,i;return T(this,(function(a){switch(a.label){case 0:return void 0!==(o=this._materialMap.get(e))?[3,6]:(i=t&&Object.keys(t).some((function(e){return e.startsWith("uv")})),(e=e instanceof m.MultiMaterial?e.subMaterials[n.materialIndex]:e)instanceof m.PBRBaseMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,i)]:[3,2]);case 1:return o=a.sent(),[3,5];case 2:return e instanceof m.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,i)]:[3,4];case 3:return o=a.sent(),[3,5];case 4:return m.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 5:this._materialMap.set(e,o),a.label=6;case 6:return r.material=o,[2]}}))}))},e.prototype._exportMeshAsync=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,i,a,s,u,c,l,f,h,p,d,g,x,_,v,y,w,M,A,E,R,C,V,S,I,F,B,O,P,N,U,L;return T(this,(function(T){switch(T.label){case 0:if(void 0!==(n=t.getMesh(e)))return[2,n];if(r={primitives:[]},n=this._meshes.length,this._meshes.push(r),t.setMesh(e,n),o=e.isUnIndexed?null:e.getIndices(),i=null===(B=e.geometry)||void 0===B?void 0:B.getVertexBuffers(),a=t.getMorphTargetsFromMesh(e),s=e instanceof m.LinesMesh,u=e instanceof m.GreasedLineBaseMesh,c=e.subMeshes,!(i&&c&&c.length>0))return[3,7];l=0,f=c,T.label=1;case 1:return l<f.length?(h=f[l],p={attributes:{}},d=h.getMaterial()||this._babylonScene.defaultMaterial,u?(v={name:d.name},y=e,g=m.Color3.White(),x=null!==(P=null===(O=y.material)||void 0===O?void 0:O.alpha)&&void 0!==P?P:1,(!(_=null!==(U=null===(N=y.greasedLineMaterial)||void 0===N?void 0:N.color)&&void 0!==U?U:g).equalsWithEpsilon(g,m.Epsilon)||x<1)&&(v.pbrMetallicRoughness={baseColorFactor:b(b([],_.asArray(),!0),[x],!1)}),this._materials.push(v),p.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return s?(v={name:d.name},(!(y=e).color.equalsWithEpsilon(m.Color3.White(),m.Epsilon)||y.alpha<1)&&(v.pbrMetallicRoughness={baseColorFactor:b(b([],y.color.asArray(),!0),[y.alpha],!1)}),this._materials.push(v),p.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(d,i,h,p)];case 4:T.sent(),T.label=5;case 5:for(w=s||u?m.Material.LineListDrawMode:null!==(L=e.overrideRenderingFillMode)&&void 0!==L?L:d.fillMode,M=d._getEffectiveOrientation(e),t.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(M=M===m.Material.ClockWiseSideOrientation?m.Material.CounterClockWiseSideOrientation:m.Material.ClockWiseSideOrientation),this._exportIndices(o,o?(0,m.AreIndices32Bits)(o,h.indexCount,h.indexStart,h.verticesStart):h.verticesCount>65535,o?h.indexStart:h.verticesStart,o?h.indexCount:h.verticesCount,-h.verticesStart,w,M,t,p),A=0,E=Object.values(i);A<E.length;A++)R=E[A],this._exportVertexBuffer(R,d,h.verticesStart,h.verticesCount,t,p);if(a)for(p.targets=[],C=0,V=a;C<V.length;C++)F=V[C],p.targets.push(F.attributes);r.primitives.push(p),this._extensionsPostExportMeshPrimitive(p),T.label=6;case 6:return l++,[3,1];case 7:if(a)for(r.weights=[],r.extras||(r.extras={}),r.extras.targetNames=[],S=0,I=a;S<I.length;S++)F=I[S],r.weights.push(F.influence),r.extras.targetNames.push(F.name);return[2,n]}}))}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),ue=function(){function e(){}return e.GLTFAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var r,o;return T(this,(function(i){switch(i.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(r=new se(e,n)).generateGLTFAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=i.sent(),r.dispose(),[2,o]}}))}))},e.GLBAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var r,o;return T(this,(function(i){switch(i.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(r=new se(e,n)).generateGLBAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=i.sent(),r.dispose(),[2,o]}}))}))},e}(),ce="EXT_mesh_gpu_instancing",le=function(){function e(e){this.name=ce,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportNodeAsync=function(e,t,n,r,o,i){return y(this,void 0,void 0,(function(){var e=this;return T(this,(function(r){switch(r.label){case 0:return[4,new Promise((function(r){if(t&&n instanceof m.Mesh&&n.hasThinInstances&&e._exporter){e._wasUsed=!0;for(var a=m.Vector3.Zero(),s=m.Quaternion.Identity(),u=m.Vector3.One(),c=n.thinInstanceGetWorldMatrices(),l=m.TmpVectors.Vector3[2],f=m.TmpVectors.Quaternion[1],h=m.TmpVectors.Vector3[3],p=!1,d=!1,g=!1,x=new Float32Array(3*n.thinInstanceCount),_=new Float32Array(4*n.thinInstanceCount),v=new Float32Array(3*n.thinInstanceCount),y=0,T=0,b=c;T<b.length;T++)b[T].decompose(h,f,l),o&&(j(l),z(f)),x.set(l.asArray(),3*y),_.set(f.normalize().asArray(),4*y),v.set(h.asArray(),3*y),p=p||!l.equalsWithEpsilon(a),d=d||!f.equalsWithEpsilon(s),g=g||!h.equalsWithEpsilon(u),y++;var w={attributes:{}};p&&(w.attributes.TRANSLATION=e._buildAccessor(x,"VEC3",n.thinInstanceCount,i)),d&&(w.attributes.ROTATION=e._buildAccessor(_,"VEC4",n.thinInstanceCount,i)),g&&(w.attributes.SCALE=e._buildAccessor(v,"VEC3",n.thinInstanceCount,i)),t.extensions=t.extensions||{},t.extensions[ce]=w}r(t)}))];case 1:return[2,r.sent()]}}))}))},e.prototype._buildAccessor=function(e,t,n,r){var o=r.createBufferView(e),i=r.createAccessor(o,t,5126,n);return this._exporter._accessors.push(i),this._exporter._accessors.length-1},e}();se.RegisterExtension(ce,(function(e){return new le(e)}));var fe="KHR_draco_mesh_compression",he=function(){function e(e){this.name=fe,this.required=!0,this._bufferViewsUsed=new Set,this._accessorsUsed=new Set,this._encodePromises=[],this._wasUsed=!1,this.enabled="Draco"===e.options.meshCompressionMethod&&m.DracoEncoder.DefaultAvailable}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMeshPrimitive=function(e,t,n){var r=this;if(this.enabled)if(4===e.mode||5===e.mode){var o=[],i=[],a=null;if(void 0!==e.indices){var s=n[e.indices],u=t.getBufferView(s);a=t.getData(u).slice(),o.push(u),i.push(s)}for(var c,l=[],f=0,h=Object.entries(e.attributes);f<h.length;f++){var p=h[f],d=p[0],g=(s=n[p[1]],u=t.getBufferView(s),G(s.type)),x=(0,m.GetTypedArrayData)(t.getData(u),g,s.componentType,s.byteOffset||0,u.byteStride||(0,m.GetTypeByteLength)(s.componentType)*g,s.normalized||!1,s.count,!0);l.push({kind:d,dracoName:(c=d,"POSITION"===c?"POSITION":"NORMAL"===c?"NORMAL":c.startsWith("COLOR")?"COLOR":c.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"),size:G(s.type),data:x}),o.push(u),i.push(s)}var _={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},v=m.DracoEncoder.Default._encodeAsync(l,a,_).then((function(n){if(n){var a={bufferView:-1,attributes:n.attributeIds},s=t.createBufferView(n.data);t.setBufferView(a,s);for(var u=0,c=o;u<c.length;u++){var l=c[u];r._bufferViewsUsed.add(l)}for(var f=0,h=i;f<h.length;f++){var p=h[f];r._accessorsUsed.add(p)}e.extensions||(e.extensions={}),e.extensions[fe]=a}else m.Logger.Error("Draco encoding failed for primitive.")})).catch((function(e){m.Logger.Error("Draco encoding failed for primitive: "+e)}));this._encodePromises.push(v),this._wasUsed=!0}else m.Logger.Warn("Cannot compress primitive with mode "+e.mode+".")},e.prototype.preGenerateBinaryAsync=function(e){return y(this,void 0,void 0,(function(){var t=this;return T(this,(function(n){switch(n.label){case 0:return this.enabled?[4,Promise.all(this._encodePromises)]:[2];case 1:return n.sent(),this._bufferViewsUsed.forEach((function(n){e.getPropertiesWithBufferView(n).every((function(e){return t._accessorsUsed.has(e)}))&&e.removeBufferView(n)})),this._bufferViewsUsed.clear(),this._accessorsUsed.clear(),[2]}}))}))},e}();se.RegisterExtension(fe,(function(e){return new he(e)}));var pe="KHR_lights_punctual",de={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},me={innerConeAngle:0,outerConeAngle:Math.PI/4},ge=m.Vector3.Backward(),xe=function(){function e(e){this.name=pe,this.enabled=!0,this.required=!1,this._exporter=e}return e.prototype.dispose=function(){this._lights=null},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return!!this._lights},enumerable:!1,configurable:!0}),e.prototype.onExporting=function(){this._exporter._glTF.extensions[pe]=this._lights},e.prototype.postExportNodeAsync=function(e,t,n,r,o){return y(this,void 0,void 0,(function(){var i=this;return T(this,(function(a){switch(a.label){case 0:return[4,new Promise((function(a){if(n instanceof m.Light){var s=n.getTypeID()==m.Light.LIGHTTYPEID_POINTLIGHT?"point":n.getTypeID()==m.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":n.getTypeID()==m.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(s&&n instanceof m.ShadowLight))return m.Logger.Warn("".concat(e,": Light ").concat(n.name," is not supported in ").concat(pe)),void a(t);if(n.falloffType!==m.Light.FALLOFF_GLTF&&m.Logger.Warn("".concat(e,": Light falloff for ").concat(n.name," does not match the ").concat(pe," specification!")),!n.position.equalsToFloats(0,0,0)){var u=m.TmpVectors.Vector3[0].copyFrom(n.position);o&&j(u),t.translation=u.asArray()}if("point"!==s){var c=n.direction.normalizeToRef(m.TmpVectors.Vector3[0]);o&&j(c);var l=m.Quaternion.FromUnitVectorsToRef(ge,c,m.TmpVectors.Quaternion[0]);m.Quaternion.IsIdentity(l)||(t.rotation=l.asArray())}var f={type:s,name:n.name,color:n.diffuse.asArray(),intensity:n.intensity,range:n.range};if(Z(f,de),"spot"===s){var h=n;f.spot={innerConeAngle:h.innerAngle/2,outerConeAngle:h.angle/2},Z(f.spot,me)}i._lights||(i._lights={lights:[]}),i._lights.lights.push(f);var p={light:i._lights.lights.length-1},d=n.parent;if(d&&Y(n,d)){var g=r.get(d);if(g){var x=i._exporter._nodes[g];return X(t,x),x.extensions||(x.extensions={}),x.extensions[pe]=p,void a(null)}}t.extensions||(t.extensions={}),t.extensions[pe]=p,a(t)}else a(t)}))];case 1:return[2,a.sent()]}}))}))},e}();se.RegisterExtension(pe,(function(e){return new xe(e)}));var _e="KHR_materials_anisotropy",ve=function(){function e(e){this.name=_e,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,n){var r=[];return n instanceof m.PBRBaseMaterial&&n.anisotropy.isEnabled&&!n.anisotropy.legacy?(n.anisotropy.texture&&r.push(n.anisotropy.texture),r):[]},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof m.PBRBaseMaterial){if(!n.anisotropy.isEnabled||n.anisotropy.legacy)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var o=r._exporter._materialExporter.getTextureInfo(n.anisotropy.texture),i={anisotropyStrength:n.anisotropy.intensity,anisotropyRotation:n.anisotropy.angle,anisotropyTexture:null!=o?o:void 0};null!==i.anisotropyTexture&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[_e]=i}e(t)}))},e}();se.RegisterExtension(_e,(function(e){return new ve(e)}));var ye="KHR_materials_clearcoat",Te=function(){function e(e){this.name=ye,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,n){var r=[];return n instanceof m.PBRBaseMaterial&&n.clearCoat.isEnabled?(n.clearCoat.texture&&r.push(n.clearCoat.texture),!n.clearCoat.useRoughnessFromMainTexture&&n.clearCoat.textureRoughness&&r.push(n.clearCoat.textureRoughness),n.clearCoat.bumpTexture&&r.push(n.clearCoat.bumpTexture),r):[]},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof m.PBRBaseMaterial){if(!n.clearCoat.isEnabled)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var o,i=r._exporter._materialExporter.getTextureInfo(n.clearCoat.texture);o=n.clearCoat.useRoughnessFromMainTexture?r._exporter._materialExporter.getTextureInfo(n.clearCoat.texture):r._exporter._materialExporter.getTextureInfo(n.clearCoat.textureRoughness),n.clearCoat.isTintEnabled&&m.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(n.name)),n.clearCoat.remapF0OnInterfaceChange&&m.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(n.name));var a=r._exporter._materialExporter.getTextureInfo(n.clearCoat.bumpTexture),s={clearcoatFactor:n.clearCoat.intensity,clearcoatTexture:null!=i?i:void 0,clearcoatRoughnessFactor:n.clearCoat.roughness,clearcoatRoughnessTexture:null!=o?o:void 0,clearcoatNormalTexture:null!=a?a:void 0};null===s.clearcoatTexture&&null===s.clearcoatRoughnessTexture&&null===s.clearcoatRoughnessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[ye]=s}e(t)}))},e}();se.RegisterExtension(ye,(function(e){return new Te(e)}));var be="KHR_materials_diffuse_transmission";function we(e,t){var n=t.subSurface,r=null;return n.translucencyIntensityTexture?r=n.translucencyIntensityTexture:n.thicknessTexture&&n.useMaskFromThicknessTexture&&(r=n.thicknessTexture),r&&!n.useGltfStyleTextures?(m.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(t.name),1),null):r}var Me=function(){function e(e){this.name=be,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,n){var r=[];if(n instanceof m.PBRMaterial&&this._isExtensionEnabled(n)){var o=we(e,n);return o&&r.push(o),n.subSurface.translucencyColorTexture&&r.push(n.subSurface.translucencyColorTexture),r}return r},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!!t.isTranslucencyEnabled&&!e.unlit&&!t.useAlbedoToTintTranslucency&&t.useGltfStyleTextures&&1===t.volumeIndexOfRefraction&&0===t.minimumThickness&&0===t.maximumThickness},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(o){var i,a;if(n instanceof m.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var s=n.subSurface,u=we(e,n),c=0==s.translucencyIntensity?void 0:s.translucencyIntensity,l=null!==(i=r._exporter._materialExporter.getTextureInfo(u))&&void 0!==i?i:void 0,f=!s.translucencyColor||s.translucencyColor.equalsFloats(1,1,1)?void 0:s.translucencyColor.asArray(),h=null!==(a=r._exporter._materialExporter.getTextureInfo(s.translucencyColorTexture))&&void 0!==a?a:void 0,p={diffuseTransmissionFactor:c,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:f,diffuseTransmissionColorTexture:h};(l||h)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions=t.extensions||{},t.extensions[be]=p}o(t)}))},e}();se.RegisterExtension(be,(function(e){return new Me(e)}));var Ae="KHR_materials_dispersion",Ee=function(){function e(){this.name=Ae,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isDispersionEnabled)},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof m.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var o={dispersion:n.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[Ae]=o}e(t)}))},e}();se.RegisterExtension(Ae,(function(){return new Ee}));var Re="KHR_materials_emissive_strength",Ce=function(){function e(){this.name=Re,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e=this;return T(this,(function(r){switch(r.label){case 0:return[4,new Promise((function(r){if(!(n instanceof m.PBRMaterial))return r(t);var o=n.emissiveColor.asArray(),i=Math.max.apply(Math,o);if(i>1){e._wasUsed=!0,t.extensions||(t.extensions={});var a={emissiveStrength:i},s=n.emissiveColor.scale(1/a.emissiveStrength);t.emissiveFactor=s.asArray(),t.extensions[Re]=a}return r(t)}))];case 1:return[2,r.sent()]}}))}))},e}();se.RegisterExtension(Re,(function(e){return new Ce}));var Ve="KHR_materials_ior",Se=function(){function e(){this.name=Ve,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){return!e.unlit&&null!=e.indexOfRefraction&&1.5!=e.indexOfRefraction},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof m.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var o={ior:n.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[Ve]=o}e(t)}))},e}();se.RegisterExtension(Ve,(function(e){return new Se}));var Ie="KHR_materials_iridescence",Fe=function(){function e(e){this.name=Ie,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,n){var r=[];return n instanceof m.PBRBaseMaterial&&n.iridescence.isEnabled?(n.iridescence.texture&&r.push(n.iridescence.texture),n.iridescence.thicknessTexture&&n.iridescence.thicknessTexture!==n.iridescence.texture&&r.push(n.iridescence.thicknessTexture),r):[]},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof m.PBRBaseMaterial){if(!n.iridescence.isEnabled)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var o=r._exporter._materialExporter.getTextureInfo(n.iridescence.texture),i=r._exporter._materialExporter.getTextureInfo(n.iridescence.thicknessTexture),a={iridescenceFactor:n.iridescence.intensity,iridescenceIor:n.iridescence.indexOfRefraction,iridescenceThicknessMinimum:n.iridescence.minimumThickness,iridescenceThicknessMaximum:n.iridescence.maximumThickness,iridescenceTexture:null!=o?o:void 0,iridescenceThicknessTexture:null!=i?i:void 0};null===a.iridescenceTexture&&null===a.iridescenceThicknessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[Ie]=a}e(t)}))},e}();se.RegisterExtension(Ie,(function(e){return new Fe(e)}));var Be="KHR_materials_sheen",Oe=function(){function e(e){this.name=Be,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,n){return n instanceof m.PBRMaterial&&n.sheen.isEnabled&&n.sheen.texture?[n.sheen.texture]:[]},e.prototype.postExportMaterialAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e=this;return T(this,(function(r){switch(r.label){case 0:return[4,new Promise((function(r){var o,i,a,s;if(n instanceof m.PBRMaterial){if(!n.sheen.isEnabled)return void r(t);e._wasUsed=!0,null==t.extensions&&(t.extensions={});var u={sheenColorFactor:n.sheen.color.asArray(),sheenRoughnessFactor:null!==(o=n.sheen.roughness)&&void 0!==o?o:0};null===u.sheenColorTexture&&null===u.sheenRoughnessTexture||e._exporter._materialNeedsUVsSet.add(n),n.sheen.texture&&(u.sheenColorTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(n.sheen.texture))&&void 0!==i?i:void 0),n.sheen.textureRoughness&&!n.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(n.sheen.textureRoughness))&&void 0!==a?a:void 0:n.sheen.texture&&n.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(s=e._exporter._materialExporter.getTextureInfo(n.sheen.texture))&&void 0!==s?s:void 0),t.extensions[Be]=u}r(t)}))];case 1:return[2,r.sent()]}}))}))},e}();se.RegisterExtension(Be,(function(e){return new Oe(e)}));var Pe="KHR_materials_specular",Ne=function(){function e(e){this.name=Pe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,n){var r=[];return n instanceof m.PBRMaterial&&this._isExtensionEnabled(n)?(n.metallicReflectanceTexture&&r.push(n.metallicReflectanceTexture),n.reflectanceTexture&&r.push(n.reflectanceTexture),r):r},e.prototype._isExtensionEnabled=function(e){return!e.unlit&&(null!=e.metallicF0Factor&&1!=e.metallicF0Factor||null!=e.metallicReflectanceColor&&!e.metallicReflectanceColor.equalsFloats(1,1,1)||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.metallicReflectanceTexture||null!=e.reflectanceTexture},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){var o,i;if(n instanceof m.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0,t.extensions=t.extensions||{};var a=null!==(o=r._exporter._materialExporter.getTextureInfo(n.metallicReflectanceTexture))&&void 0!==o?o:void 0,s=null!==(i=r._exporter._materialExporter.getTextureInfo(n.reflectanceTexture))&&void 0!==i?i:void 0,u={specularFactor:1==n.metallicF0Factor?void 0:n.metallicF0Factor,specularTexture:a,specularColorFactor:n.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:n.metallicReflectanceColor.asArray(),specularColorTexture:s};r._hasTexturesExtension(n)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[Pe]=u}e(t)}))},e}();se.RegisterExtension(Pe,(function(e){return new Ne(e)}));var Ue="KHR_materials_transmission",Le=function(){function e(e){this.name=Ue,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,n){var r=[];return n instanceof m.PBRMaterial&&this._isExtensionEnabled(n)?(n.subSurface.thicknessTexture&&r.push(n.subSurface.thicknessTexture),r):r},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return t.isRefractionEnabled&&null!=t.refractionIntensity&&0!=t.refractionIntensity||this._hasTexturesExtension(e)},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.refractionIntensityTexture},e.prototype.postExportMaterialAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var r,o,i,a;return T(this,(function(s){switch(s.label){case 0:return n instanceof m.PBRMaterial&&this._isExtensionEnabled(n)?(this._wasUsed=!0,r=n.subSurface,o=0===r.refractionIntensity?void 0:r.refractionIntensity,i={transmissionFactor:o},this._hasTexturesExtension(n)&&this._exporter._materialNeedsUVsSet.add(n),r.refractionIntensityTexture?r.useGltfStyleTextures?[4,this._exporter._materialExporter.exportTextureAsync(r.refractionIntensityTexture)]:[3,2]:[3,3]):[3,4];case 1:return(a=s.sent())&&(i.transmissionTexture=a),[3,3];case 2:m.Logger.Warn("".concat(e,": Exporting a subsurface refraction intensity texture without `useGltfStyleTextures` is not supported")),s.label=3;case 3:t.extensions||(t.extensions={}),t.extensions[Ue]=i,s.label=4;case 4:return[2,t]}}))}))},e}();se.RegisterExtension(Ue,(function(e){return new Le(e)}));var ke="KHR_materials_unlit",Ke=function(){function e(){this.name=ke,this.enabled=!0,this.required=!1,this._wasUsed=!1}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){var o=!1;n instanceof m.PBRMaterial?o=n.unlit:n instanceof m.StandardMaterial&&(o=n.disableLighting),o&&(r._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[ke]={}),e(t)}))},e}();se.RegisterExtension(ke,(function(){return new Ke}));var De="KHR_materials_volume",Ge=function(){function e(e){this.name=De,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,n){var r=[];return n instanceof m.PBRMaterial&&this._isExtensionEnabled(n)?(n.subSurface.thicknessTexture&&r.push(n.subSurface.thicknessTexture),r):r},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isTranslucencyEnabled)&&(null!=t.maximumThickness&&0!=t.maximumThickness||null!=t.tintColorAtDistance&&t.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=t.tintColor&&t.tintColor!=m.Color3.White()||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.thicknessTexture},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){var o;if(n instanceof m.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var i=n.subSurface,a={thicknessFactor:0==i.maximumThickness?void 0:i.maximumThickness,thicknessTexture:null!==(o=r._exporter._materialExporter.getTextureInfo(i.thicknessTexture))&&void 0!==o?o:void 0,attenuationDistance:i.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:i.tintColorAtDistance,attenuationColor:i.tintColor.equalsFloats(1,1,1)?void 0:i.tintColor.asArray()};r._hasTexturesExtension(n)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions=t.extensions||{},t.extensions[De]=a}e(t)}))},e}();se.RegisterExtension(De,(function(e){return new Ge(e)}));var We="EXT_materials_diffuse_roughness",He=function(){function e(e){this.name=We,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,n){var r=[];return n instanceof m.PBRBaseMaterial&&n._baseDiffuseRoughness?(n._baseDiffuseRoughnessTexture&&r.push(n._baseDiffuseRoughnessTexture),r):[]},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof m.PBRBaseMaterial){if(!n._baseDiffuseRoughness)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var o=r._exporter._materialExporter.getTextureInfo(n._baseDiffuseRoughnessTexture),i={diffuseRoughnessFactor:n._baseDiffuseRoughness,diffuseRoughnessTexture:null!=o?o:void 0};null!==i.diffuseRoughnessTexture&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[We]=i}e(t)}))},e}();se.RegisterExtension(We,(function(e){return new He(e)}));var qe="KHR_texture_transform",je=function(){function e(){this.name=qe,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportTexture=function(e,t,n){if(n.getScene()||m.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(n.name,"!")),0===n.uAng&&0===n.vAng||(m.Tools.Warn("".concat(e,": Texture ").concat(n.name," with rotation in the u or v axis is not supported in glTF.")),0===n.uRotationCenter&&0===n.vRotationCenter)){var r={},o=!1;if(0===n.uOffset&&0===n.vOffset||(r.offset=[n.uOffset,n.vOffset],o=!0),1===n.uScale&&1===n.vScale||(r.scale=[n.uScale,n.vScale],o=!0),0!==n.wAng){if(0!==n.uRotationCenter||0!==n.vRotationCenter){if(n.homogeneousRotationInUVTransform&&n.uScale!==n.vScale)return void m.Tools.Warn("".concat(e,": Texture ").concat(n.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(qe,"."));m.Tools.Warn("".concat(e,": Texture ").concat(n.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(qe,".")),r.offset=function(e){var t=e.uOffset,n=e.vOffset,r=e.uRotationCenter,o=e.vRotationCenter,i=e.uScale,a=e.vScale,s=e.wAng,u=Math.cos(s),c=Math.sin(s),l=r*i,f=o*a;return[t+(l*(1-u)+f*c),n+(f*(1-u)-l*c)]}(n)}r.rotation=-n.wAng,o=!0}0!==n.coordinatesIndex&&(r.texCoord=n.coordinatesIndex,o=!0),o&&(this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[qe]=r)}},e}();se.RegisterExtension(qe,(function(){return new je}));var ze="KHR_texture_basisu",Qe=function(){function e(e){this.name=ze,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,t){var n=this._exporter._textures[t.index],r=n.source;if(void 0!==r){var o=this._exporter._images[r];"image/ktx2"===(o.mimeType||(0,m.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[ze]={source:r},this._wasUsed=!0)}},e}();se.RegisterExtension(ze,(function(e){return new Qe(e)}));var Xe="EXT_texture_webp",Ye=function(){function e(e){this.name=Xe,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,t){var n=this._exporter._textures[t.index],r=n.source;if(void 0!==r){var o=this._exporter._images[r];"image/webp"===(o.mimeType||(0,m.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[Xe]={source:r},this._wasUsed=!0)}},e}();se.RegisterExtension(Xe,(function(e){return new Ye(e)}));var Ze="EXT_texture_avif",Je=function(){function e(e){this.name=Ze,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,t){var n=this._exporter._textures[t.index],r=n.source;if(void 0!==r){var o=this._exporter._images[r];"image/avif"===(o.mimeType||(0,m.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[Ze]={source:r},this._wasUsed=!0)}},e}();se.RegisterExtension(Ze,(function(e){return new Je(e)}));var $e=function(){function e(){}return e.CreateSTL=function(e,t,n,r,o,i,a,s){void 0===t&&(t=!0),void 0===n&&(n="stlmesh"),void 0===r&&(r=!1),void 0===o&&(o=!0),void 0===i&&(i=!1),void 0===a&&(a=!1),void 0===s&&(s=!1);var u=function(e,t,n){var r=[3*e[n],3*e[n+1],3*e[n+2]],o=[new m.Vector3(t[r[0]],t[r[0]+2],t[r[0]+1]),new m.Vector3(t[r[1]],t[r[1]+2],t[r[1]+1]),new m.Vector3(t[r[2]],t[r[2]+2],t[r[2]+1])],i=o[0].subtract(o[1]),a=o[2].subtract(o[1]);return{v:o,n:m.Vector3.Cross(a,i).normalize()}},c=function(e,t,n,r){return t=l(e,t,n.x,r),t=l(e,t,n.y,r),l(e,t,n.z,r)},l=function(e,t,n,r){return e.setFloat32(t,n,r),t+4},f=function(e){if(a){var t=e;e instanceof m.InstancedMesh&&(t=e.sourceMesh);var n=t.getVerticesData(m.VertexBuffer.PositionKind,!0,!0);if(!n)return[];var r=m.Vector3.Zero(),o=void 0;for(o=0;o<n.length;o+=3)m.Vector3.TransformCoordinatesFromFloatsToRef(n[o],n[o+1],n[o+2],e.computeWorldMatrix(!0),r).toArray(n,o);return n}return e.getVerticesData(m.VertexBuffer.PositionKind)||[]};a&&(i=!0);var h="",p=0,d=0;if(r){for(var g=0;g<e.length;g++)p+=(y=(_=e[g]).getIndices())?y.length/3:0;var x=new ArrayBuffer(84+50*p);d+=80,(h=new DataView(x)).setUint32(d,p,o),d+=4}else s||(h="solid stlmesh\r\n");for(g=0;g<e.length;g++){var _=e[g];!r&&s&&(h+="solid "+_.name+"\r\n"),!i&&_ instanceof m.Mesh&&_.bakeCurrentTransformIntoVertices();for(var v=f(_),y=_.getIndices()||[],T=0;T<y.length;T+=3){var b=u(y,v,T);r?(d=c(h,d,b.n,o),d=c(h,d,b.v[0],o),d=c(h,d,b.v[1],o),d=c(h,d,b.v[2],o),d+=2):(h+="\tfacet normal "+b.n.x+" "+b.n.y+" "+b.n.z+"\r\n",h+="\t\touter loop\r\n",h+="\t\t\tvertex "+b.v[0].x+" "+b.v[0].y+" "+b.v[0].z+"\r\n",h+="\t\t\tvertex "+b.v[1].x+" "+b.v[1].y+" "+b.v[1].z+"\r\n",h+="\t\t\tvertex "+b.v[2].x+" "+b.v[2].y+" "+b.v[2].z+"\r\n",h+="\t\tendloop\r\n",h+="\tendfacet\r\n")}!r&&s&&(h+="endsolid "+name+"\r\n")}if(r||s||(h+="endsolid stlmesh"),t){var w=document.createElement("a"),M=new Blob([h],{type:"application/octet-stream"});w.href=window.URL.createObjectURL(M),w.download=n+".stl",w.click()}return h},e}();function et(e,t,n,r){void 0===n&&(n=3),void 0===r&&(r=!1);for(var o=[],i=0;i<e.length/n;i++){var a=e[i*n]*(r?-1:1),s=e[i*n+1],u=e[i*n+2];o.push("(".concat(a.toPrecision(t.precision),", ").concat(s.toPrecision(t.precision),", ").concat(u.toPrecision(t.precision),")"))}return o.join(", ")}function tt(e,t){for(var n=[],r=0;r<e.length/2;r++){var o=e[2*r],i=e[2*r+1];n.push("(".concat(o.toPrecision(t.precision),", ").concat((1-i).toPrecision(t.precision),")"))}return n.join(", ")}function nt(e,t,n,r){var o=function(e,t,n,r){var o=e.getVerticesData(m.VertexBuffer.PositionKind),i=e.getVerticesData(m.VertexBuffer.NormalKind);if(o&&i)return'\n\tdef Mesh "'.concat("Geometry",'"\n\t{\n uniform token orientation = "').concat(n,'"\n\t\tint[] faceVertexCounts = [').concat(function(e){var t,n=(null===(t=e.getIndices())||void 0===t?void 0:t.length)?e.getTotalIndices():e.getTotalVertices();return Array(n/3).fill(3).join(", ")}(e),"]\n\t\tint[] faceVertexIndices = [").concat(function(e){var t,n=e.getIndices(),r=null!==(t=null==n?void 0:n.length)&&void 0!==t?t:e.getTotalVertices(),o=[];if(null!==n)for(var i=0;i<r;i++)o.push(n[i]);else for(i=0;i<r;i++)o.push(i);return o.join(", ")}(e),"]\n\t\tnormal3f[] normals = [").concat(et(i,t,void 0,r),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)\n\t\tpoint3f[] points = [').concat(et(o,t,void 0,r),"]\n ").concat(function(e,t){for(var n="",r=0;r<4;r++){var o=r>0?r:"",i=e.getVerticesData(m.VertexBuffer.UVKind+(o?o+1:""));i&&(n+="\n\t\ttexCoord2f[] primvars:st".concat(o," = [").concat(tt(i,t),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)'))}var a=e.getVerticesData(m.VertexBuffer.ColorKind);return a&&(n+="\n\tcolor3f[] primvars:displayColor = [".concat(et(a,t,a.length/e.getTotalVertices()),'] (\n\t\tinterpolation = "vertex"\n\t\t)')),n}(e,t),'\n\t\tuniform token subdivisionScheme = "none"\n\t}\n')}(e,t,n,r);return'\n def "Geometry"\n {\n '.concat(o,"\n }\n ")}function rt(e){var t='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )';return t+=e,fflate.strToU8(t)}function ot(e){var t=e.m;return"( ".concat(it(t,0),", ").concat(it(t,4),", ").concat(it(t,8),", ").concat(it(t,12)," )")}function it(e,t){return"(".concat(e[t+0],", ").concat(e[t+1],", ").concat(e[t+2],", ").concat(e[t+3],")")}function at(e,t){var n="Object_"+e.uniqueId,r=ot(t);return'def Xform "'.concat(n,'" (\n\tprepend references = @./geometries/Geometry_').concat(e.geometry.uniqueId,'.usda@</Geometry>\n\tprepend apiSchemas = ["MaterialBindingAPI"]\n)\n{\n\tmatrix4d xformOp:transform = ').concat(r,'\n\tuniform token[] xformOpOrder = ["xformOp:transform"]\t\n\n rel material:binding = </Root/Materials/Material_').concat(e.material.uniqueId,">\n}\n\n")}function st(e){switch(e){case m.Constants.TEXTURE_CLAMP_ADDRESSMODE:return"clamp";case m.Constants.TEXTURE_MIRROR_ADDRESSMODE:return"mirror";case m.Constants.TEXTURE_WRAP_ADDRESSMODE:default:return"repeat"}}function ut(e){return"(".concat(e.x,", ").concat(e.y,")")}function ct(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,")")}function lt(e,t,n,r,o,i){var a=e.getInternalTexture().uniqueId+"_"+e.invertY;o[a]=e;var s=e.coordinatesIndex>0?"st"+e.coordinatesIndex:"st",u=new m.Vector2(e.uScale,e.vScale),c=new m.Vector2(e.uOffset,e.vOffset),l=e.wAng,f=Math.sin(l),h=Math.cos(l);return c.y=1-c.y-u.y,c.x+=f*u.x,c.y+=(1-h)*u.y,'\n def Shader "PrimvarReader_'.concat(n,'"\n {\n uniform token info:id = "UsdPrimvarReader_float2"\n float2 inputs:fallback = (0.0, 0.0)\n token inputs:varname = "').concat(s,'"\n float2 outputs:result\n }\n\n def Shader "Transform2d_').concat(n,'"\n {\n uniform token info:id = "UsdTransform2d"\n token inputs:in.connect = </Root/Materials/Material_').concat(t.uniqueId,"/PrimvarReader_").concat(n,".outputs:result>\n float inputs:rotation = ").concat((l*(180/Math.PI)).toFixed(i.precision),"\n float2 inputs:scale = ").concat(ut(u),"\n float2 inputs:translation = ").concat(ut(c),'\n float2 outputs:result\n }\n\n def Shader "Texture_').concat(e.uniqueId,"_").concat(n,'"\n {\n uniform token info:id = "UsdUVTexture"\n asset inputs:file = @textures/Texture_').concat(a,".png@\n float2 inputs:st.connect = </Root/Materials/Material_").concat(t.uniqueId,"/Transform2d_").concat(n,".outputs:result>\n ").concat(r?"float4 inputs:scale = "+function(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,", 1.0)")}(r):"",'\n token inputs:sourceColorSpace = "').concat(e.gammaSpace?"sRGB":"raw",'"\n token inputs:wrapS = "').concat(st(e.wrapU),'"\n token inputs:wrapT = "').concat(st(e.wrapV),'"\n float outputs:r\n float outputs:g\n float outputs:b\n float3 outputs:rgb\n ').concat(t.needAlphaBlending()||t.needAlphaTesting()?"float outputs:a":"","\n }")}function ft(e,t,n){var r="\t\t\t",o=[],i=[],a=function(e){var t,n,r={diffuseMap:null,diffuse:null,alphaCutOff:0,emissiveMap:null,emissive:null,normalMap:null,roughnessMap:null,roughnessChannel:"a",roughness:0,metalnessMap:null,metalnessChannel:"r",metalness:0,aoMap:null,aoMapChannel:"rgb",aoMapIntensity:0,alphaMap:null,ior:1,clearCoatEnabled:!1,clearCoat:0,clearCoatMap:null,clearCoatRoughness:0,clearCoatRoughnessMap:null};return e instanceof m.StandardMaterial?v(v({},r),{diffuseMap:e.diffuseTexture,diffuse:e.diffuseColor,alphaCutOff:e.alphaCutOff,emissiveMap:e.emissiveTexture,emissive:e.emissiveColor,roughness:1,alphaMap:e.opacityTexture}):e instanceof m.PBRBaseMaterial?v(v({},r),{diffuseMap:e._albedoTexture,diffuse:e._albedoColor,alphaCutOff:e._alphaCutOff,emissiveMap:e._emissiveTexture,emissive:e._emissiveColor,normalMap:e._bumpTexture,roughnessMap:e._metallicTexture,roughnessChannel:e._useRoughnessFromMetallicTextureAlpha?"a":"g",roughness:null!==(t=e._roughness)&&void 0!==t?t:1,metalnessMap:e._metallicTexture,metalnessChannel:e._useMetallnessFromMetallicTextureBlue?"b":"r",metalness:null!==(n=e._metallic)&&void 0!==n?n:0,aoMap:e._ambientTexture,aoMapChannel:e._useAmbientInGrayScale?"r":"rgb",aoMapIntensity:e._ambientTextureStrength,alphaMap:e._opacityTexture,ior:e.subSurface.indexOfRefraction,clearCoatEnabled:e.clearCoat.isEnabled,clearCoat:e.clearCoat.intensity,clearCoatMap:e.clearCoat.texture,clearCoatRoughness:e.clearCoat.roughness,clearCoatRoughnessMap:e.clearCoat.useRoughnessFromMainTexture?e.clearCoat.texture:e.clearCoat.textureRoughness}):r}(e),s=a.diffuseMap,u=a.diffuse,c=a.alphaCutOff,l=a.emissiveMap,f=a.emissive,h=a.normalMap,p=a.roughnessMap,d=a.roughnessChannel,g=a.roughness,x=a.metalnessMap,_=a.metalnessChannel,y=a.metalness,T=a.aoMap,b=a.aoMapChannel,w=a.aoMapIntensity,M=a.alphaMap,A=a.ior,E=a.clearCoatEnabled,R=a.clearCoat,C=a.clearCoatMap,V=a.clearCoatRoughness,S=a.clearCoatRoughnessMap;return null!==s?(o.push("".concat(r,"color3f inputs:diffuseColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:rgb>")),e.needAlphaBlending()?o.push("".concat(r,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:a>")):e.needAlphaTesting()&&(o.push("".concat(r,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:a>")),o.push("".concat(r,"float inputs:opacityThreshold = ").concat(c))),i.push(lt(s,e,"diffuse",u,t,n))):o.push("".concat(r,"color3f inputs:diffuseColor = ").concat(ct(u||m.Color3.White()))),null!==l?(o.push("".concat(r,"color3f inputs:emissiveColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(l.uniqueId,"_emissive.outputs:rgb>")),i.push(lt(l,e,"emissive",f,t,n))):f&&f.toLuminance()>0&&o.push("".concat(r,"color3f inputs:emissiveColor = ").concat(ct(f))),null!==h&&(o.push("".concat(r,"normal3f inputs:normal.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(h.uniqueId,"_normal.outputs:rgb>")),i.push(lt(h,e,"normal",null,t,n))),null!==T&&(o.push("".concat(r,"float inputs:occlusion.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(T.uniqueId,"_occlusion.outputs:").concat(b,">")),i.push(lt(T,e,"occlusion",new m.Color3(w,w,w),t,n))),null!==p?(o.push("".concat(r,"float inputs:roughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(p.uniqueId,"_roughness.outputs:").concat(d,">")),i.push(lt(p,e,"roughness",new m.Color3(g,g,g),t,n))):o.push("".concat(r,"float inputs:roughness = ").concat(g)),null!==x?(o.push("".concat(r,"float inputs:metallic.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(x.uniqueId,"_metallic.outputs:").concat(_,">")),i.push(lt(x,e,"metallic",new m.Color3(y,y,y),t,n))):o.push("".concat(r,"float inputs:metallic = ").concat(y)),null!==M?(o.push("".concat(r,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(M.uniqueId,"_opacity.outputs:r>")),o.push("".concat(r,"float inputs:opacityThreshold = 0.0001")),i.push(lt(M,e,"opacity",null,t,n))):o.push("".concat(r,"float inputs:opacity = ").concat(e.alpha)),E&&(null!==C?(o.push("".concat(r,"float inputs:clearcoat.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(C.uniqueId,"_clearcoat.outputs:r>")),i.push(lt(C,e,"clearcoat",new m.Color3(R,R,R),t,n))):o.push("".concat(r,"float inputs:clearcoat = ").concat(R)),null!==S?(o.push("".concat(r,"float inputs:clearcoatRoughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(S.uniqueId,"_clearcoatRoughness.outputs:g>")),i.push(lt(S,e,"clearcoatRoughness",new m.Color3(V,V,V),t,n))):o.push("".concat(r,"float inputs:clearcoatRoughness = ").concat(V))),o.push("".concat(r,"float inputs:ior = ").concat(A)),'\n\tdef Material "Material_'.concat(e.uniqueId,'"\n\t{\n\t\tdef Shader "PreviewSurface"\n\t\t{\n\t\t\tuniform token info:id = "UsdPreviewSurface"\n').concat(o.join("\n"),"\n\t\t\tint inputs:useSpecularWorkflow = 0\n\t\t\ttoken outputs:surface\n\t\t}\n\n\t\ttoken outputs:surface.connect = </Root/Materials/Material_").concat(e.uniqueId,"/PreviewSurface.outputs:surface>\n\n").concat(i.join("\n"),"\n\n\t}\n")}function ht(e){var t,n;e.computeWorldMatrix(!0);for(var r=e.getWorldMatrix().clone(),o=e.getScene().useRightHandedSystem,i=null!==(n=null===(t=e.material)||void 0===t?void 0:t._getEffectiveOrientation(e))&&void 0!==n?n:e.sideOrientation,a=!o,s=e.parent;s;){if(N(s,o)&&null===s.parent){o||(r.multiplyToRef(s.getWorldMatrix().invert(),r),i=i===m.Material.ClockWiseSideOrientation?m.Material.CounterClockWiseSideOrientation:m.Material.ClockWiseSideOrientation),a=!1;break}s=s.parent}return r.determinant()<0&&m.Tools.Warn("Mesh ".concat(e.name," has a negative scale, which may look incorrect in destinations like QuickLook.")),{matrix:r,windingOrder:i===m.Material.ClockWiseSideOrientation?"leftHanded":"rightHanded",convertToRightHanded:a}}function pt(e,t,n){return y(this,void 0,void 0,(function(){var r,o,i,a,s,u,c,l,f,h,p,d,g,x,_,y,b,w,M,A,E,R,C,V,S,I,F,B,O,P,N,U;return T(this,(function(T){switch(T.label){case 0:return r=v({fflateUrl:"https://unpkg.com/fflate@0.8.2",includeAnchoringProperties:!0,anchoringType:"plane",planeAnchoringAlignment:"horizontal",modelFileName:"model.usda",precision:5,exportCamera:!1,cameraSensorWidth:35},t),"undefined"!=typeof fflate?[3,2]:[4,m.Tools.LoadScriptAsync(r.fflateUrl)];case 1:T.sent(),T.label=2;case 2:for((o={})[r.modelFileName]=null,i='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )',i+=function(e){var t=!0===e.includeAnchoringProperties?'\n\t\ttoken preliminary:anchoring:type = "'.concat(e.anchoringType,'"\n\t\ttoken preliminary:planeAnchoring:alignment = "').concat(e.planeAnchoringAlignment,'"'):"";return'def Xform "Root"\n {\n def Scope "Scenes" (\n kind = "sceneLibrary"\n )\n {\n def Xform "Scene" (\n customData = {\n bool preliminary_collidesWithEnvironment = 0\n string sceneName = "Scene"\n }\n sceneName = "Scene"\n )\n {'.concat(t,"\n ")}(r),a={},s=0,u=e.meshes;s<u.length;s++)0!==(c=u[s]).getTotalVertices()&&(f=(l=c).geometry,(h=l.material)&&f&&(!n||n(l))&&(-1!==["StandardMaterial","PBRMaterial","PBRMetallicRoughnessMaterial"].indexOf(h.getClassName())?(p="geometries/Geometry_"+f.uniqueId+".usda",d=ht(l),g=d.matrix,x=d.windingOrder,_=d.convertToRightHanded,p in o||(y=nt(f,r,x,_),o[p]=rt(y)),h.uniqueId in a||(a[h.uniqueId]=h),i+=at(l,g)):m.Tools.Warn("USDZExportAsync does not support this material type: "+h.getClassName())));for(A in e.activeCamera&&r.exportCamera&&(i+=function(e,t){var n="Camera_"+e.uniqueId,r=ot(m.Matrix.RotationY(Math.PI).multiply(e.getWorldMatrix()));if(e.mode===m.Constants.ORTHOGRAPHIC_CAMERA)return'def Camera "'.concat(n,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(r,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(t.precision),", ").concat(e.maxZ.toPrecision(t.precision),")\n\t\t\tfloat horizontalAperture = ").concat((10*(Math.abs(e.orthoLeft||1)+Math.abs(e.orthoRight||1))).toPrecision(t.precision),"\n\t\t\tfloat verticalAperture = ").concat((10*(Math.abs(e.orthoTop||1)+Math.abs(e.orthoBottom||1))).toPrecision(t.precision),'\n\t\t\ttoken projection = "orthographic"\n\t\t}\n\t\n\t');var o=e.getEngine().getAspectRatio(e),i=t.cameraSensorWidth||35;return'def Camera "'.concat(n,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(r,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(t.precision),", ").concat(e.maxZ.toPrecision(t.precision),")\n\t\t\tfloat focalLength = ").concat((i/(2*Math.tan(.5*e.fov))).toPrecision(t.precision),'\n token projection = "perspective"\n\t\t\tfloat horizontalAperture = ').concat((i*o).toPrecision(t.precision),"\n\t\t\tfloat verticalAperture = ").concat((i/o).toPrecision(t.precision)," \n\t\t}\n\t\n\t")}(e.activeCamera,r)),i+="\n }\n }",i+=function(e,t,n){var r=[];for(var o in e){var i=e[o];r.push(ft(i,t,n))}return'\n def "Materials"\n{\n'.concat(r.join(""),"\n}\n\n")}(a,b={},r),i+="\n }",o[r.modelFileName]=fflate.strToU8(i),M=[],w=b)M.push(A);E=0,T.label=3;case 3:return E<M.length?(A=M[E])in w?(C=b[R=A],V=C.getSize(),[4,(0,m.GetTextureDataAsync)(C)]):[3,6]:[3,7];case 4:return S=T.sent(),[4,m.DumpTools.DumpDataAsync(V.width,V.height,S,"image/png",void 0,!1,!0)];case 5:I=T.sent(),o["textures/Texture_".concat(R,".png")]=new Uint8Array(I).slice(),T.label=6;case 6:return E++,[3,3];case 7:for(B in F=0,o)(O=o[B])&&(P=34+B.length,4!=(N=63&(F+=P))&&(U=new Uint8Array(64-N),o[B]=[O,{extra:{12345:U}}]),F=O.length);return[2,fflate.zipSync(o,{level:0})]}}))}))}var dt=function(){function e(){}return e.Export=function(e,t,n){var r;if(void 0===t&&(t=[]),!e||0===e.bones.length)throw new Error("Invalid or empty skeleton provided");var o=t;t&&0!==t.length||(o=e.animations.map((function(e){return e.name})));for(var i=null,a=0,s=o;a<s.length;a++){var u=s[a],c=e.getAnimationRange(u);c&&(i=i?new m.AnimationRange("animation-range",Math.min(i.from,c.from),Math.max(i.to,c.to)):c)}if(!i&&(e.animations.length>0&&(i=e.getAnimationRange(e.animations[0].name)),!i))throw new Error("No animation range found in skeleton");for(var l=n||1/((null===(r=e.animations[0])||void 0===r?void 0:r.framePerSecond)||30),f=this._BuildBoneHierarchy(e,o),h=0,p=0,d=f;p<d.length;p++){var g=d[p];g.positionKeys.length>0&&(h=Math.max(h,g.positionKeys.length)),g.rotationKeys.length>0&&(h=Math.max(h,g.rotationKeys.length))}0===h&&(h=Math.floor((i.to-i.from)/l)+1);var x="";return x+="HIERARCHY\n",x+=this._ExportHierarchy(f,0),x+="MOTION\n",x+="Frames: ".concat(h,"\n"),(x+="Frame Time: ".concat(l.toFixed(6),"\n"))+this._ExportMotionData(f,h,0,o)},e._BuildBoneHierarchy=function(e,t){for(var n,r,o=new Map,i=[],a=0,s=e.bones;a<s.length;a++){var u={bone:f=s[a],children:[],hasPositionChannels:!1,hasRotationChannels:!1,positionKeys:[],rotationKeys:[]};o.set(f,u)}for(var c=0,l=e.bones;c<l.length;c++){var f=l[c];if(u=o.get(f),f.animations.length>0)for(var h=0,p=f.animations;h<p.length;h++){var d=p[h];t.includes(d.name)&&("position"===d.targetProperty?(u.hasPositionChannels=!0,(n=u.positionKeys).push.apply(n,d.getKeys())):"rotationQuaternion"===d.targetProperty&&(u.hasRotationChannels=!0,(r=u.rotationKeys).push.apply(r,d.getKeys())))}if(f.getParent()){var m=o.get(f.getParent());m&&m.children.push(u)}else i.push(u)}return i},e._ExportHierarchy=function(e,t){for(var n="",r=" ".repeat(t),o=0,i=e;o<i.length;o++){var a=i[o],s=a.bone;if(this._IsEndSite(a)){n+="".concat(r,"End Site\n"),n+="".concat(r,"{\n");var u=this._GetBoneOffset(s);n+="".concat(r," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n"),n+="".concat(r,"}\n")}else{n+="".concat(0===t?"ROOT":"".concat(r,"JOINT")," ").concat(s.name,"\n"),n+="".concat(r,"{\n"),u=this._GetBoneOffset(s),n+="".concat(r," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n");var c=[];a.hasPositionChannels&&c.push("Xposition","Yposition","Zposition"),a.hasRotationChannels&&c.push("Zrotation","Xrotation","Yrotation"),c.length>0&&(n+="".concat(r," CHANNELS ").concat(c.length," ").concat(c.join(" "),"\n")),a.children.length>0&&(n+=this._ExportHierarchy(a.children,t+1)),n+="".concat(r,"}\n")}}return n},e._IsEndSite=function(e){return 0===e.children.length},e._GetBoneOffset=function(e){try{return e.getParent()?e.getLocalMatrix().getTranslation():e.getRestMatrix().getTranslation()}catch(e){return m.Vector3.Zero()}},e._ExportMotionData=function(e,t,n,r){for(var o="",i=0;i<t;i++){var a=[];this._CollectFrameValues(e,i+n,a,r),o+=a.map((function(e){return e.toFixed(6)})).join(" ")+"\n"}return o},e._CollectFrameValues=function(e,t,n,r){for(var o=0,i=e;o<i.length;o++){var a=i[o];if(!this._IsEndSite(a)){if(a.hasPositionChannels){var s=this._GetPositionAtFrameIndex(a.positionKeys,t);n.push(s.x,s.y,s.z)}if(a.hasRotationChannels){var u=this._GetRotationAtFrameIndex(a.rotationKeys,t),c=this._QuaternionToEuler(u);n.push(c.z,c.x,c.y)}a.children.length>0&&this._CollectFrameValues(a.children,t,n,r)}}},e._GetPositionAtFrameIndex=function(e,t){return 0===e.length?m.Vector3.Zero():e[Math.max(0,Math.min(t,e.length-1))].value.clone()},e._GetRotationAtFrameIndex=function(e,t){return 0===e.length?m.Quaternion.Identity():e[Math.max(0,Math.min(t,e.length-1))].value.clone()},e._QuaternionToEuler=function(e){var t=new m.Matrix;e.toRotationMatrix(t);var n,r,o,i=t.m,a=Math.sqrt(i[0]*i[0]+i[1]*i[1]);return a>m.Epsilon?(n=Math.atan2(i[6],i[10]),r=Math.atan2(-i[2],a),o=Math.atan2(i[1],i[0])):(n=Math.atan2(-i[9],i[5]),r=Math.atan2(-i[2],a),o=0),new m.Vector3(m.Tools.ToDegrees(n),m.Tools.ToDegrees(r),m.Tools.ToDegrees(o))},e}(),mt=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==mt)for(var gt in p)mt.BABYLON[gt]=p[gt];var xt=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==xt){xt.BABYLON=xt.BABYLON||{};var _t=xt.BABYLON;_t.GLTF2=_t.GLTF2||{},_t.GLTF2.Exporter=_t.GLTF2.Exporter||{},_t.GLTF2.Exporter.Extensions=_t.GLTF2.Exporter.Extensions||{};var vt=[];for(var yt in a)_t[yt]=a[yt],vt.push(yt);for(var yt in s)_t[yt]=s[yt],vt.push(yt);for(var yt in u)_t[yt]=u[yt],vt.push(yt);for(var yt in c)_t.GLTF2.Exporter.Extensions[yt]=c[yt],vt.push(yt);for(var yt in l)vt.indexOf(yt)>-1||(_t.GLTF2.Exporter[yt]=l[yt])}var Tt=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Tt)for(var bt in i)Tt.BABYLON[bt]=i[bt];var wt=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==wt)for(var Mt in f)wt.BABYLON[Mt]=f[Mt];var At=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==At)for(var Et in h)At.BABYLON[Et]=h[Et];const Rt=d;return o.default})()));
|
|
2
2
|
//# sourceMappingURL=babylonjs.serializers.min.js.map
|