babylonjs-serializers 8.30.3 → 8.30.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.SERIALIZERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(e=>(()=>{"use strict";var t={597:t=>{t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,r),a.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:()=>Dt});var a={};r.r(a),r.d(a,{OBJExport:()=>m});var i={};r.r(i),r.d(i,{__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_mesh_gpu_instancing:()=>le,EXT_texture_avif:()=>lt,EXT_texture_webp:()=>ut,KHR_draco_mesh_compression:()=>pe,KHR_lights_punctual:()=>xe,KHR_materials_anisotropy:()=>Te,KHR_materials_clearcoat:()=>Ae,KHR_materials_clearcoat_anisotropy:()=>Fe,KHR_materials_clearcoat_color:()=>Se,KHR_materials_clearcoat_darkening:()=>we,KHR_materials_clearcoat_ior:()=>Re,KHR_materials_diffuse_roughness:()=>nt,KHR_materials_diffuse_transmission:()=>Ue,KHR_materials_dispersion:()=>Le,KHR_materials_emissive_strength:()=>Ke,KHR_materials_ior:()=>He,KHR_materials_iridescence:()=>We,KHR_materials_sheen:()=>ze,KHR_materials_specular:()=>Xe,KHR_materials_transmission:()=>Qe,KHR_materials_unlit:()=>Je,KHR_materials_volume:()=>et,KHR_texture_basisu:()=>it,KHR_texture_transform:()=>ot});var l={};r.r(l),r.d(l,{EXT_mesh_gpu_instancing:()=>le,EXT_texture_avif:()=>lt,EXT_texture_webp:()=>ut,GLTF2Export:()=>ue,GLTFData:()=>_,KHR_draco_mesh_compression:()=>pe,KHR_lights_punctual:()=>xe,KHR_materials_anisotropy:()=>Te,KHR_materials_clearcoat:()=>Ae,KHR_materials_clearcoat_anisotropy:()=>Fe,KHR_materials_clearcoat_color:()=>Se,KHR_materials_clearcoat_darkening:()=>we,KHR_materials_clearcoat_ior:()=>Re,KHR_materials_diffuse_roughness:()=>nt,KHR_materials_diffuse_transmission:()=>Ue,KHR_materials_dispersion:()=>Le,KHR_materials_emissive_strength:()=>Ke,KHR_materials_ior:()=>He,KHR_materials_iridescence:()=>We,KHR_materials_sheen:()=>ze,KHR_materials_specular:()=>Xe,KHR_materials_transmission:()=>Qe,KHR_materials_unlit:()=>Je,KHR_materials_volume:()=>et,KHR_texture_basisu:()=>it,KHR_texture_transform:()=>ot,_ConvertToGLTFPBRMetallicRoughness:()=>V,_SolveMetallic:()=>S});var f={};r.r(f),r.d(f,{STLExport:()=>ft});var p={};r.r(p),r.d(p,{USDZExportAsync:()=>wt});var h={};r.r(h),r.d(h,{BVHExporter:()=>Et});var d={};r.r(d),r.d(d,{BVHExporter:()=>Et,EXT_mesh_gpu_instancing:()=>le,EXT_texture_avif:()=>lt,EXT_texture_webp:()=>ut,GLTF2Export:()=>ue,GLTFData:()=>_,KHR_draco_mesh_compression:()=>pe,KHR_lights_punctual:()=>xe,KHR_materials_anisotropy:()=>Te,KHR_materials_clearcoat:()=>Ae,KHR_materials_clearcoat_anisotropy:()=>Fe,KHR_materials_clearcoat_color:()=>Se,KHR_materials_clearcoat_darkening:()=>we,KHR_materials_clearcoat_ior:()=>Re,KHR_materials_diffuse_roughness:()=>nt,KHR_materials_diffuse_transmission:()=>Ue,KHR_materials_dispersion:()=>Le,KHR_materials_emissive_strength:()=>Ke,KHR_materials_ior:()=>He,KHR_materials_iridescence:()=>We,KHR_materials_sheen:()=>ze,KHR_materials_specular:()=>Xe,KHR_materials_transmission:()=>Qe,KHR_materials_unlit:()=>Je,KHR_materials_volume:()=>et,KHR_texture_basisu:()=>it,KHR_texture_transform:()=>ot,OBJExport:()=>m,STLExport:()=>ft,USDZExportAsync:()=>wt,_ConvertToGLTFPBRMetallicRoughness:()=>V,_SolveMetallic:()=>S,__IGLTFExporterExtension:()=>x});var g=r(597),m=function(){function e(){}return e.OBJ=function(e,t,n,r){var o=[],a=1,i=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 g.Matrix,f.invertToRef(l),u.bakeTransformIntoVertices(f)}if(t){var p=u.material;p&&o.push("usemtl "+p.id)}var h=u.geometry;if(h){var d=h.getVerticesData("position"),m=h.getVerticesData("normal"),x=h.getVerticesData("uv"),_=h.getIndices(),v=0,y=0;if(d&&_){for(var T=e[0].getScene().useRightHandedSystem?1:-1,b=0;b<d.length;b+=3)o.push("v "+d[b]*T+" "+d[b+1]+" "+d[b+2]),v++;if(null!=m)for(b=0;b<m.length;b+=3)o.push("vn "+m[b]*T+" "+m[b+1]+" "+m[b+2]);if(null!=x)for(b=0;b<x.length;b+=2)o.push("vt "+x[b]+" "+x[b+1]),y++;var A=["","",""],M=(u.material||u.getScene().defaultMaterial)._getEffectiveOrientation(u)===g.Material.ClockWiseSideOrientation?[2,1]:[1,2],w=M[0],E=M[1];for(b=0;b<_.length;b+=3){var R=[String(_[b]+a),String(_[b+w]+a),String(_[b+E]+a)],C=[String(_[b]+i),String(_[b+w]+i),String(_[b+E]+i)],S=R,V=null!=x?C:A,I=null!=m?R:A;o.push("f "+S[0]+"/"+V[0]+"/"+I[0]+" "+S[1]+"/"+V[1]+"/"+I[1]+" "+S[2]+"/"+V[2]+"/"+I[2])}r&&l&&u.bakeTransformIntoVertices(l),a+=v,i+=y}else g.Tools.Warn("There are no position vertices or indices on the mesh!")}else g.Tools.Warn("No geometry is present on the mesh")}return o.join("\n")},e.MTL=function(e){var t=[],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,g.GetMimeType)(e)});g.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,a){function i(e){try{u(r.next(e))}catch(e){a(e)}}function s(e){try{u(r.throw(e))}catch(e){a(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(i,s)}u((r=r.apply(e,t||[])).next())}))}function T(e,t){var n,r,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=s(0),i.throw=s(1),i.return=s(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)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 a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],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,a=t.length;o<a;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 A=1e-6,M=new g.Color3(.04,.04,.04),w=1024,E=g.Color3.White(),R=g.Color3.Black();function C(e){return y(this,void 0,void 0,(function(){var t,n,r,o;return T(this,(function(a){switch(a.label){case 0:return(t=e.getInternalTexture())&&1===t.source?t.invertY?[2,null]:(n=t._buffer,o=e.mimeType,n?[3,2]:[4,g.Tools.LoadFileAsync(t.url)]):[2,null];case 1:return r=a.sent(),o=(0,g.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=a.sent(),o=n.type||o,[3,10];case 6:return"string"!=typeof n?[3,8]:[4,g.Tools.LoadFileAsync(n)];case 7:return r=a.sent(),o=(0,g.GetMimeType)(n)||o,[3,10];case 8:return"undefined"!=typeof HTMLImageElement&&n instanceof HTMLImageElement?[4,g.Tools.LoadFileAsync(n.src)]:[3,10];case 9:r=a.sent(),o=(0,g.GetMimeType)(n.src)||o,a.label=10;case 10:return r&&o?[2,{data:r,mimeType:o}]:[2,null]}}))}))}function S(e,t,n){if(t<M.r)return 0;var r=M.r,o=e*n/(1-M.r)+t-2*M.r,a=o*o-4*r*(M.r-t);return g.Scalar.Clamp((-o+Math.sqrt(a))/(2*r),0,1)}function V(e){var t=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),n=e.alpha,r=g.Scalar.Clamp(e.specularPower,0,w),o=(0,g.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 g.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,a,i,s,u,c;return T(this,(function(l){switch(l.label){case 0:return n=V(e),r={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||g.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),t?(o=[],(a=e.diffuseTexture)&&o.push(this.exportTextureAsync(a).then((function(e){e&&(n.baseColorTexture=e)}))),(i=e.bumpTexture)&&o.push(this.exportTextureAsync(i).then((function(e){e&&(r.normalTexture=e,1!==i.level&&(r.normalTexture.scale=i.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===g.Constants.ALPHA_COMBINE?r.alphaMode="BLEND":g.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(R,A)&&(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,a,i;return T(this,(function(s){switch(s.label){case 0:return[4,this._exporter._extensionsPostExportMaterialAdditionalTexturesAsync("exportMaterial",e,t)];case 1:for(n=s.sent(),r=[],o=0,a=n;o<a.length;o++)i=a[o],r.push(this.exportTextureAsync(i));return[4,Promise.all(r)];case 2:return s.sent(),[4,this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)];case 3: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,g.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,a=e?e.getSize():{width:0,height:0},i=t?t.getSize():{width:0,height:0};return a.width<i.width?(r=e&&e instanceof g.Texture?g.TextureTools.CreateResizedCopy(e,i.width,i.height,!0):B(i.width,i.height,n),o=t):a.width>i.width?(o=t&&t instanceof g.Texture?g.TextureTools.CreateResizedCopy(t,a.width,a.height,!0):B(a.width,a.height,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,a,i,s,u,c,l,f,p,h,d,m,x,_,v,y,b,M,w,C,S,V,I,B,O,P,U,N,L,D,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(a=e?e.getScene():t?t.getScene():null)?(i=this._resizeTexturesToSameDimensions(e,t,a),s=null===(K=i.texture1)||void 0===K?void 0:K.getSize(),u=void 0,c=void 0,l=s.width,f=s.height,[4,i.texture1.readPixels()]):[3,12];case 3:return p=T.sent(),[4,i.texture2.readPixels()];case 4:return h=T.sent(),p?(u=F(p),[3,7]):[3,5];case 5:return[4,Promise.reject("Failed to retrieve pixels from diffuse texture!")];case 7:return h?(c=F(h),[3,10]):[3,8];case 8:return[4,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];case 10:for(d=c.byteLength,m=new Uint8Array(d),x=new Uint8Array(d),_=R,v=0,y=0,P=0;P<f;++P)for(U=0;U<l;++U)b=4*(l*P+U),M=new g.Color3(u[b],u[b+1],u[b+2]).toLinearSpace(a.getEngine().useExactSrgbConversions).multiply(n.diffuseColor),w=new g.Color3(c[b],c[b+1],c[b+2]).toLinearSpace(a.getEngine().useExactSrgbConversions).multiply(n.specularColor),C=c[b+3]*n.glossiness,S={diffuseColor:M,specularColor:w,glossiness:C},V=this._convertSpecularGlossinessToMetallicRoughness(S),_.r=Math.max(_.r,V.baseColor.r),_.g=Math.max(_.g,V.baseColor.g),_.b=Math.max(_.b,V.baseColor.b),v=Math.max(v,V.metallic),y=Math.max(y,V.roughness),x[b]=255*V.baseColor.r,x[b+1]=255*V.baseColor.g,x[b+2]=255*V.baseColor.b,x[b+3]=i.texture1.hasAlpha?255*u[b+3]:255,m[b]=0,m[b+1]=255*V.roughness,m[b+2]=255*V.metallic,m[b+3]=255;for(I={baseColor:_,metallic:v,roughness:y},B=!1,O=!1,P=0;P<f;++P)for(U=0;U<l;++U)x[N=4*(l*P+U)]/=I.baseColor.r>A?I.baseColor.r:1,x[N+1]/=I.baseColor.g>A?I.baseColor.g:1,x[N+2]/=I.baseColor.b>A?I.baseColor.b:1,L=g.Color3.FromInts(x[N],x[N+1],x[N+2]),D=L.toGammaSpace(a.getEngine().useExactSrgbConversions),x[N]=255*D.r,x[N+1]=255*D.g,x[N+2]=255*D.b,D.equalsWithEpsilon(E,A)||(O=!0),m[N+1]/=I.roughness>A?I.roughness:1,m[N+2]/=I.metallic>A?I.metallic:1,g.Color3.FromInts(255,m[N+1],m[N+2]).equalsWithEpsilon(E,A)||(B=!0);return B&&o.push(this._getImageDataAsync(m,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=S(t,n,r),a=e.diffuseColor.scale(r/(1-M.r)/Math.max(1-o)),i=e.specularColor.subtract(M.scale(1-o)).scale(1/Math.max(o)),s=g.Color3.Lerp(a,i,o*o);return{baseColor:s=s.clampToRef(0,1,s),metallic:o,roughness:1-e.glossiness}},e.prototype._getPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},e.prototype._getMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},e.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,n,r,o,a,i,s,u){return y(this,void 0,void 0,(function(){var a,c;return T(this,(function(l){switch(l.label){case 0:return a=[],c={baseColor:e,metallic:t,roughness:n},u&&(r&&a.push(this.exportTextureAsync(r).then((function(e){e&&(s.baseColorTexture=e)}))),o&&a.push(this.exportTextureAsync(o).then((function(e){e&&(s.metallicRoughnessTexture=e)})))),a.length>0?(this._exporter._materialNeedsUVsSet.add(i),[4,Promise.all(a)]):[3,2];case 1:l.sent(),l.label=2;case 2:return[2,c]}}))}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof g.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 g.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case g.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case g.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case g.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case g.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case g.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case g.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case g.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case g.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case g.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case g.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case g.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case g.Texture.WRAP_ADDRESSMODE:return 10497;case g.Texture.CLAMP_ADDRESSMODE:return 33071;case g.Texture.MIRROR_ADDRESSMODE:return 33648;default:return g.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var r,o,a,i,s,u,c,l,f;return T(this,(function(p){switch(p.label){case 0:return r="image/png",o={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},a=e._albedoTexture,i=e._reflectivityTexture,s=e._useMicroSurfaceFromReflectivityMapAlpha,!i||s?[3,2]:[4,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")];case 1:return[2,p.sent()];case 2:return(a||i)&&n?(this._exporter._materialNeedsUVsSet.add(e),u=this._exportTextureSampler(a||i),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(a,i,o,r)]):[3,4];case 3:return c=p.sent(),l=this._exporter._textures,c.baseColorTextureData&&(f=this._exportImage("baseColor".concat(l.length),r,c.baseColorTextureData),t.baseColorTexture=this._exportTextureInfo(f,u,null==a?void 0:a.coordinatesIndex)),c.metallicRoughnessTextureData&&(f=this._exportImage("metallicRoughness".concat(l.length),r,c.metallicRoughnessTextureData),t.metallicRoughnessTexture=this._exportTextureInfo(f,u,null==i?void 0:i.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,a,i,s,u,c;return T(this,(function(l){switch(l.label){case 0:return n={},r={name:e.name},(o=e.isMetallicWorkflow())&&(a=e._albedoColor,i=e.alpha,a&&(n.baseColorFactor=[a.r,a.g,a.b,i])),o?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e._albedoColor,e._metallic,e._roughness,e._albedoTexture,e._metallicTexture,e._metallicTexture,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 a,i,s,u,c;return T(this,(function(l){switch(l.label){case 0:return I(n,t),e.baseColor.equalsWithEpsilon(E,A)&&g.Scalar.WithinEpsilon(t.alpha,1,A)||(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||g.Tools.Warn(t.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),o?(a=[],(i=t instanceof g.PBRBaseMaterial?t._bumpTexture:t.geometryNormalTexture)&&a.push(this.exportTextureAsync(i).then((function(e){e&&(n.normalTexture=e,1!==i.level&&(n.normalTexture.scale=i.level))}))),(s=t instanceof g.PBRBaseMaterial?t._ambientTexture:t.ambientOcclusionTexture)&&a.push(this.exportTextureAsync(s).then((function(e){if(e){var r={index:e.index,texCoord:e.texCoord,extensions:e.extensions};n.occlusionTexture=r,t instanceof g.PBRBaseMaterial?r.strength=t._ambientTextureStrength:r.strength=t.ambientOcclusionTexture.level}}))),(u=t instanceof g.PBRBaseMaterial?t._emissiveTexture:t.emissionColorTexture)&&a.push(this.exportTextureAsync(u).then((function(e){e&&(n.emissiveTexture=e)}))),a.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(a)]):[3,2]):[3,2];case 1:l.sent(),l.label=2;case 2:return(c=t instanceof g.PBRBaseMaterial?t._emissiveColor:t.emissionColor).equalsWithEpsilon(R,A)||(n.emissiveFactor=c.asArray()),n.pbrMetallicRoughness=r,[2]}}))}))},e.prototype.exportOpenPBRMaterialAsync=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,a,i,s;return T(this,(function(u){switch(u.label){case 0:return n={},r={name:e.name},o=e.baseColor,a=e.geometryOpacity,o&&(n.baseColorFactor=[o.r,o.g,o.b,a]),[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e.baseColor,e.baseMetalness,e.specularRoughness,e.baseColorTexture,e.baseMetalnessTexture,e.specularRoughnessTexture,e,n,t)];case 1:return i=u.sent(),[4,this._setMetallicRoughnessPbrMaterialAsync(i,e,r,n,t)];case 2:return u.sent(),[4,this._finishMaterialAsync(r,e)];case 3:return u.sent(),(s=this._exporter._materials).push(r),[2,s.length-1]}}))}))},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,a,i=this;return T(this,(function(s){switch(s.label){case 0:return t=null!==(a=e.mimeType)&&void 0!==a?a:"none",n=this._internalTextureToImage,r=e.getInternalTexture().uniqueId,n[r]=n[r]||{},void 0===(o=n[r][t])&&(o=y(i,void 0,void 0,(function(){var n,r,o,a,i;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:g.Tools.Warn("Unsupported media type: ".concat(t,". Exporting texture as PNG."))}return o=e.getSize(),[4,(0,g.GetTextureDataAsync)(e)];case 2:return a=s.sent(),[4,this._getImageDataAsync(a,o.width,o.height,r)];case 3:return i=s.sent(),[2,this._exportImage(e.name,r,i)]}}))})),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 a=this._exporter._bufferManager.createBufferView(new Uint8Array(n));this._exporter._bufferManager.setBufferView(r,a)}else{var i=e.replace(/\.\/|\/|\.\\|\\/g,"_"),s=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp";case"image/avif":return".avif";case"image/ktx2":return".ktx2"}}(t),u=i+s;o.some((function(e){return e.uri===u}))&&(u="".concat(i,"_").concat(g.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 a={index:o};return n&&(a.texCoord=n),a},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=g.Matrix.Compose(new g.Vector3(-1,1,1),g.Quaternion.Identity(),g.Vector3.Zero());function U(e,t){if(!(e instanceof g.TransformNode))return!1;if(t){if(!e.getWorldMatrix().equalsWithEpsilon(g.Matrix.IdentityReadOnly,g.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(P,g.TmpVectors.Matrix[0]).equalsWithEpsilon(g.Matrix.IdentityReadOnly,g.Epsilon))return!1;return!(e instanceof g.AbstractMesh&&e.geometry)}var N=g.Vector3.Zero(),L=g.Quaternion.Identity(),D=g.Vector3.One(),K=new g.Vector3(-1,1,1);function k(e,t){var n=e.byteOffset,r=e.byteStride,o=e.type,a=e.normalized,i=e.getSize(),s=t.reduce((function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e}),-Number.MAX_VALUE);return{byteOffset:n,byteStride:r,componentCount:i,type:o,count:s*i,normalized:a,totalVertices:s,kind:e.getKind()}}function H(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 G(e){switch(e){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:case g.VertexBuffer.ColorKind:case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:case g.VertexBuffer.MatricesWeightsKind:case g.VertexBuffer.MatricesWeightsExtraKind:case g.VertexBuffer.UVKind:case g.VertexBuffer.UV2Kind:case g.VertexBuffer.UV3Kind:case g.VertexBuffer.UV4Kind:case g.VertexBuffer.UV5Kind:case g.VertexBuffer.UV6Kind:return!0}return!1}function W(e){switch(e){case g.Material.TriangleFillMode:return 4;case g.Material.TriangleStripDrawMode:return 5;case g.Material.TriangleFanDrawMode:return 6;case g.Material.PointListDrawMode:case g.Material.PointFillMode:return 0;case g.Material.LineLoopDrawMode:return 2;case g.Material.LineListDrawMode:return 1;case g.Material.LineStripDrawMode:return 3}throw new Error("Unknown fill mode: ".concat(e))}function 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 z(e){return e.x*=-1,e}function j(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),a=Math.abs(e.w);o>a?(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=a)}return e}function X(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function Y(e,t){var n=g.Vector3.FromArrayToRef(t.translation||[0,0,0],0,g.TmpVectors.Vector3[0]),r=g.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,g.TmpVectors.Quaternion[0]),o=g.Matrix.ComposeToRef(D,r,n,g.TmpVectors.Matrix[0]),a=g.Vector3.FromArrayToRef(e.translation||[0,0,0],0,g.TmpVectors.Vector3[2]),i=g.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,g.TmpVectors.Quaternion[1]),s=g.Matrix.ComposeToRef(D,i,a,g.TmpVectors.Matrix[1]);o.multiplyToRef(s,s),s.decompose(void 0,r,n),n.equalsWithEpsilon(N,g.Epsilon)?delete t.translation:t.translation=n.asArray(),r.equalsWithEpsilon(L,g.Epsilon)?delete t.rotation:t.rotation=r.asArray(),t.scale&&delete t.scale}function Q(e,t){if(!(t instanceof g.TransformNode))return!1;if(1!==t.getChildren().length||0!==e.getChildren().length||e.parent!==t)return!1;var n=e.getScene(),r=e instanceof g.TargetCamera&&!n.useRightHandedSystem?K:D;return!!t.scaling.equalsWithEpsilon(r,g.Epsilon)||(g.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],a=o[0],i=o[1],s=t[a];(Array.isArray(i)&&Array.isArray(s)&&J(i,s)||i===s)&&delete e[a]}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 a=o[r];a.byteOffset=n.byteOffset,e.push(a);for(var i=e.length-1,s=0,u=this.getPropertiesWithBufferView(a);s<u.length;s++)u[s].bufferView=i;n.writeTypedArray(this._bufferViewToData.get(a)),this._bufferViewToData.delete(a)}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,a,i){this._verifyBufferView(e);var s={bufferView:void 0,componentType:n,count:r,type:t,min:null==a?void 0:a.min,max:null==a?void 0:a.max,normalized:i,byteOffset:o};return this.setBufferView(s,e),this._accessorToBufferView.set(s,e),s},e.prototype.setBufferView=function(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)},e.prototype.removeBufferView=function(e){for(var t=this,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 g.TransformNode||e instanceof g.Camera||e instanceof g.Light)},e._CreateNodeAnimation=function(t,n,r,o,a){if(this._IsTransformable(t)){var i=[],s=[],u=n.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,r,o),f=l.interpolationType,p=l.shouldBakeAnimation;if(p?e._CreateBakedAnimation(t,n,r,c.min,c.max,n.framePerSecond,a,i,s,c,o):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(t,n,r,i,s,o):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(t,n,r,i,s,o):e._CreateBakedAnimation(t,n,r,c.min,c.max,n.framePerSecond,a,i,s,c,o),i.length&&s.length)return{inputs:i,outputs:s,samplerInterpolation:f,inputsMin:p?c.min:g.Tools.FloatRound(c.min/n.framePerSecond),inputsMax:p?c.max:g.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:g.Tools.Error("Unsupported animatable property ".concat(o[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:n,useQuaternion:r}:(g.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,n,r,o,a,i,s,u,c,l,f){var p;if(e._IsTransformable(t)&&t.animations)for(var h=0,d=t.animations;h<d.length;h++){var g=d[h];if(!f||f(g)){var m=e._DeduceAnimationInfo(g);m&&(p={name:g.name,samplers:[],channels:[]},e._AddAnimation("".concat(g.name),g.hasRunningRuntimeAnimations?n:p,t,g,m.dataAccessorType,m.animationChannelTargetPath,o,i,s,u,m.useQuaternion,c,l),p.samplers.length&&p.channels.length&&r.push(p))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,n,r,o,a,i,s,u,c,l,f){var p;if(t instanceof g.Mesh){var h=t.morphTargetManager;if(h)for(var d=0;d<h.numTargets;++d)for(var m=0,x=h.getTarget(d).animations;m<x.length;m++){var _=x[m];if(!f||f(_)){for(var v=new g.Animation("".concat(_.name),"influence",_.framePerSecond,_.dataType,_.loopMode,_.enableBlending),y=[],T=_.getKeys(),b=0;b<T.length;++b)for(var A=T[b],M=0;M<h.numTargets;++M)M==d?y.push(A):y.push({frame:A.frame,value:0});v.setKeys(y);var w=e._DeduceAnimationInfo(v);w&&(p={name:v.name,samplers:[],channels:[]},e._AddAnimation(_.name,_.hasRunningRuntimeAnimations?n:p,t,v,w.dataAccessorType,w.animationChannelTargetPath,o,i,s,u,w.useQuaternion,c,l,h.numTargets),p.samplers.length&&p.channels.length&&r.push(p))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,n,r,o,a,i,s,u,c){var l,f;if(t.animationGroups)for(var p=t.animationGroups,h=function(p){var h=new Map,m=new Map,x=new Set,_=p.to-p.from;f={name:p.name,channels:[],samplers:[]};for(var v=function(n){var _=p.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(A=e._DeduceAnimationInfo(_.animation)){var b=d._IsTransformable(v)?v:d._IsTransformable(v[0])?v[0]:null;b&&e._AddAnimation("".concat(y.name),f,b,y,A.dataAccessorType,A.animationChannelTargetPath,r,o,a,i,A.useQuaternion,s,T)}}else if(v instanceof g.MorphTarget||1===v.length&&v[0]instanceof g.MorphTarget){var A;if(A=e._DeduceAnimationInfo(_.animation)){var M=v instanceof g.MorphTarget?v:v[0];if(M){var w=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===M)return!0;return!1}));if(w){var E=t.meshes.find((function(e){return e.morphTargetManager===w}));E&&(h.has(E)||h.set(E,new Map),null===(l=h.get(E))||void 0===l||l.set(M,y),x.add(E),m.set(E,y))}}}}},y=0;y<p.targetedAnimations.length;++y)v(y);x.forEach((function(t){for(var n=t.morphTargetManager,u=null,c=[],l=m.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=h.get(t);if(T){var b=T.get(y);b?(u||(u=new g.Animation("".concat(p.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,g.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[x])):c.push({frame:p.from+_/d*x,value:y.influence,inTangent:l[0].inTangent?0:void 0,outTangent:l[0].outTangent?0:void 0})}}u.setKeys(c);var A=e._DeduceAnimationInfo(u);A&&e._AddAnimation("".concat(p.name,"_").concat(t.name,"_MorphWeightAnimation"),f,t,u,A.dataAccessorType,A.animationChannelTargetPath,r,o,a,i,A.useQuaternion,s,!1,null==n?void 0:n.numTargets)})),f.channels.length&&f.samplers.length&&n.push(f)},d=this,m=0,x=p;m<x.length;m++)h(x[m])},e._AddAnimation=function(t,n,r,o,a,i,s,u,c,l,f,p,h,d){var m,x,_,v,y,T,b=e._CreateNodeAnimation(r,o,i,f,p);if(b){if(d){for(var A=0,M=0,w=[];b.inputs.length>0;)M=b.inputs.shift(),A%d==0&&w.push(M),A++;b.inputs=w}var E=s.get(r),R=new Float32Array(b.inputs);m=u.createBufferView(R),x=u.createAccessor(m,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(x),_=l.length-1;var C=new g.Quaternion,S=new g.Vector3,V=new g.Vector3,I=r instanceof g.Camera,B=H(a),F=new Float32Array(b.outputs.length*B);b.outputs.forEach((function(e,t){var n=e;switch(i){case"translation":h&&(g.Vector3.FromArrayToRef(e,0,V),z(V),V.toArray(n));break;case"rotation":4===e.length?g.Quaternion.FromArrayToRef(e,0,C):(n=new Array(4),g.Vector3.FromArrayToRef(e,0,S),g.Quaternion.FromEulerVectorToRef(S,C)),h&&(j(C),I&&X(C)),C.toArray(n)}F.set(n,t*B)})),m=u.createBufferView(F),x=u.createAccessor(m,a,5126,b.outputs.length),l.push(x),v=l.length-1,y={interpolation:b.samplerInterpolation,input:_,output:v},n.samplers.push(y),T={sampler:n.samplers.length-1,target:{node:E,path:i}},n.channels.push(T)}},e._CreateBakedAnimation=function(t,n,r,o,a,i,s,u,c,l,f){var p,h,d=g.Quaternion.Identity(),m=null,x=null,_=null,v=null,y=null,T=null;l.min=g.Tools.FloatRound(o/i);for(var b=n.getKeys(),A=0,M=b.length;A<M;++A){if(T=null,_=b[A],A+1<M)if(v=b[A+1],_.value.equals&&_.value.equals(v.value)||_.value===v.value){if(0!==A)continue;T=_.frame}else T=v.frame;else{if(y=b[A-1],_.value.equals&&_.value.equals(y.value)||_.value===y.value)continue;T=a}if(T)for(var w=_.frame;w<=T;w+=s)if((h=g.Tools.FloatRound(w/i))!==m){m=h,x=h;var E={key:0,repeatCount:0,loopMode:n.loopMode};p=n._interpolate(w,E),e._SetInterpolatedValue(t,p,h,n,r,d,u,c,f)}}x&&(l.max=x)},e._ConvertFactorToVector3OrQuaternion=function(t,n,r,o,a){var i=e._GetBasePositionRotationOrScale(n,o,a),s=r.targetProperty.split("."),u=s?s[1]:"",c=a?g.Quaternion.FromArray(i).normalize():g.Vector3.FromArray(i);switch(u){case"x":case"y":case"z":c[u]=t;break;case"w":c.w=t;break;default:g.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return c},e._SetInterpolatedValue=function(e,t,n,r,o,a,i,s,u){var c;i.push(n),"weights"!==o?(r.dataType===g.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,r,o,u)),"rotation"===o?(u?a=t:(c=t,g.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,a)),s.push(a.asArray())):(c=t,s.push(c.asArray()))):s.push([t])},e._CreateLinearOrStepAnimation=function(t,n,r,o,a,i){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,a,r,t,i)}},e._CreateCubicSplineAnimation=function(t,n,r,o,a,i){n.getKeys().forEach((function(s){o.push(s.frame/n.framePerSecond),e._AddSplineTangent(ne.INTANGENT,a,r,"CUBICSPLINE",s,i),e._AddKeyframeValue(s,n,a,r,t,i),e._AddSplineTangent(ne.OUTTANGENT,a,r,"CUBICSPLINE",s,i)}))},e._GetBasePositionRotationOrScale=function(e,t,n){var r;if("rotation"===t)if(n){var o=e.rotationQuaternion;r=(null!=o?o:g.Quaternion.Identity()).asArray()}else{var a=e.rotation;r=(null!=a?a:g.Vector3.Zero()).asArray()}else if("translation"===t){var i=e.position;r=(null!=i?i:g.Vector3.Zero()).asArray()}else{var s=e.scaling;r=(null!=s?s:g.Vector3.One()).asArray()}return r},e._AddKeyframeValue=function(e,t,n,r,o,a){var i,s=t.dataType;if(s===g.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===r){var c=g.Vector3.FromArray(u);u=g.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}n.push(u)}else if(s===g.Animation.ANIMATIONTYPE_FLOAT){if("weights"===r)n.push([e.value]);else if(i=this._ConvertFactorToVector3OrQuaternion(e.value,o,t,r,a)){if("rotation"===r){var l=a?i:g.Quaternion.RotationYawPitchRoll(i.y,i.x,i.z).normalize();n.push(l.asArray())}n.push(i.asArray())}}else s===g.Animation.ANIMATIONTYPE_QUATERNION?n.push(e.value.normalize().asArray()):g.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,n){var r,o,a=!1;if("rotation"===t&&!n)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var i=0,s=e.length;i<s;++i)if((o=e[i]).inTangent||o.outTangent)if(r){if("CUBICSPLINE"!==r){r="LINEAR",a=!0;break}}else r="CUBICSPLINE";else if(r){if("CUBICSPLINE"===r||o.interpolation&&1===o.interpolation&&"STEP"!==r){r="LINEAR",a=!0;break}}else r=o.interpolation&&1===o.interpolation?"STEP":"LINEAR";return r||(r="LINEAR"),{interpolationType:r,shouldBakeAnimation:a}},e._AddSplineTangent=function(e,t,n,r,o,a){var i,s=e===ne.INTANGENT?o.inTangent:o.outTangent;if("CUBICSPLINE"===r){if("rotation"===n)if(s)if(a)i=s.asArray();else{var u=s;i=g.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else i=[0,0,0,0];else i="weights"===n?s?[s]:[0]:s?s.asArray():[0,0,0];t.push(i)}},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 ae(e,t,n,r,o,a){var i={attributes:{},influence:e.influence,name:e.name},s=t.geometry;if(!s)return g.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),i;var u=a?-1:1,c=g.Vector3.Zero(),l=0;if(e.hasPositions){var f=e.getPositions(),p=s.getVerticesData(g.VertexBuffer.PositionKind);if(p){var h=new Float32Array(p.length),d=[1/0,1/0,1/0],m=[-1/0,-1/0,-1/0];l=p.length/3;for(var x=0;x<l;++x){var _=g.Vector3.FromArray(p,3*x);g.Vector3.FromArray(f,3*x).subtractToRef(_,c),c.x*=u,d[0]=Math.min(d[0],c.x),m[0]=Math.max(m[0],c.x),d[1]=Math.min(d[1],c.y),m[1]=Math.max(m[1],c.y),d[2]=Math.min(d[2],c.z),m[2]=Math.max(m[2],c.z),h[3*x]=c.x,h[3*x+1]=c.y,h[3*x+2]=c.z}var v=n.createBufferView(h,12),y=n.createAccessor(v,"VEC3",5126,f.length/3,0,{min:d,max:m});o.push(y),i.attributes.POSITION=o.length-1}else g.Tools.Warn("Morph target positions for mesh ".concat(t.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var T=e.getNormals(),b=s.getVerticesData(g.VertexBuffer.NormalKind);if(b){var A=new Float32Array(b.length);for(l=b.length/3,x=0;x<l;++x){var M=g.Vector3.FromArray(b,3*x).normalize();g.Vector3.FromArray(T,3*x).normalize().subtractToRef(M,c),A[3*x]=c.x*u,A[3*x+1]=c.y,A[3*x+2]=c.z}v=n.createBufferView(A,12),y=n.createAccessor(v,"VEC3",5126,T.length/3,0),o.push(y),i.attributes.NORMAL=o.length-1}else g.Tools.Warn("Morph target normals for mesh ".concat(t.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var w=e.getTangents(),E=s.getVerticesData(g.VertexBuffer.TangentKind);if(E){l=E.length/4;var R=new Float32Array(3*l);for(x=0;x<l;++x){var C=g.Vector3.FromArray(E,4*x);q(C);var S=g.Vector3.FromArray(w,3*x);q(S),S.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),i.attributes.TANGENT=o.length-1}else g.Tools.Warn("Morph target tangents for mesh ".concat(t.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var V=e.getColors(),I=s.getVerticesData(g.VertexBuffer.ColorKind),B=s.getVertexBuffer(g.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=g.Vector3.FromArray(I,x*F);g.Vector3.FromArray(V,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 U=new g.Vector4;P=g.Vector4.FromArray(I,x*F),g.Vector4.FromArray(V,x*F).subtractToRef(P,U),O[4*x]=U.x,O[4*x+1]=U.y,O[4*x+2]=U.z,O[4*x+3]=U.w}else g.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),i.attributes.COLOR_0=o.length-1}else g.Tools.Warn("Morph target colors for mesh ".concat(t.name," were not exported. Mesh does not have colors vertex data"))}return i}var ie=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 a,i,s,u;return null===(u=null===(s=null===(i=null===(a=this._indicesAccessorMap.get(e))||void 0===a?void 0:a.get(t))||void 0===i?void 0:i.get(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,a){var i=this._indicesAccessorMap.get(e);i||(i=new Map,this._indicesAccessorMap.set(e,i));var s=i.get(t);s||(s=new Map,i.set(t,s));var u=s.get(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,a)},e.prototype.pushExportedNode=function(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)},e.prototype.getNodesSet=function(){return this._exportedNodes},e.prototype.getVertexBufferView=function(e){return this._vertexBufferViewMap.get(e)},e.prototype.setVertexBufferView=function(e,t){this._vertexBufferViewMap.set(e,t)},e.prototype.setRemappedBufferView=function(e,t,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 a=o.get(t);a||(a=new Map,o.set(t,a)),a.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=g.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(g.Engine.Version),version:"2.0"}},this._animations=[],this._accessors=[],this._bufferViews=[],this._cameras=[],this._images=[],this._materials=[],this._meshes=[],this._nodes=[],this._samplers=[],this._scenes=[],this._skins=[],this._textures=[],this._imageData={},this._shouldUseGlb=!1,this._materialExporter=new 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 a=r(t[n],e);return a?a.then((function(e){return y(o,void 0,void 0,(function(){var o;return T(this,(function(a){switch(a.label){case 0:return e?[4,this._ApplyExtension(e,t,n+1,r)]:[3,2];case 1:return o=a.sent(),[3,3];case 2:o=null,a.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,a=e._ExtensionNames;o<a.length;o++){var i=a[o];r.push(this._extensions[i])}return this._ApplyExtension(t,r,0,n)},e.prototype._extensionsPostExportNodeAsync=function(e,t,n,r,o){var a=this;return this._ApplyExtensions(t,(function(t,i){return t.postExportNodeAsync&&t.postExportNodeAsync(e,i,n,r,o,a._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._extensionsPostExportMaterialAdditionalTexturesAsync=function(t,n,r){return y(this,void 0,void 0,(function(){var o,a=this;return T(this,(function(i){switch(i.label){case 0:return o=[],[4,Promise.all(e._ExtensionNames.map((function(e){return y(a,void 0,void 0,(function(){var a,i;return T(this,(function(s){switch(s.label){case 0:return(a=this._extensions[e]).postExportMaterialAdditionalTexturesAsync?[4,a.postExportMaterialAdditionalTexturesAsync(t,n,r)]:[3,2];case 1:i=s.sent(),o.push.apply(o,i),s.label=2;case 2:return[2]}}))}))})))];case 1:return i.sent(),[2,o]}}))}))},e.prototype._extensionsPostExportTextures=function(t,n,r){for(var o=0,a=e._ExtensionNames;o<a.length;o++){var i=a[o],s=this._extensions[i];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],a=this._extensions[o];a.postExportMeshPrimitive&&a.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(a){switch(a.label){case 0:t=0,n=e._ExtensionNames,a.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:a.sent(),a.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],a=this._extensions[o];a.enabled&&t(a)}},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,r){void 0===r&&(r=100),e.UnregisterExtension(t)&&g.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=n;var o=null!=r?r:0;e._ExtensionOrders[t]=o;for(var a=e._ExtensionNames.length,i=0;i<e._ExtensionNames.length;i++){var s=e._ExtensionNames[i];if(o<e._ExtensionOrders[s]){a=i;break}}e._ExtensionNames.splice(a,0,t)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t],delete e._ExtensionOrders[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,a,i,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",a=e+".bin",(i=new _).files[o]=n,i.files[a]=r,this._imageData)for(s in this._imageData)i.files[s]=new Blob([this._imageData[s].data],{type:this._imageData[s].mimeType});return[2,i]}}))}))},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,a,i,s,u,c,l,f,p,h,d;return T(this,(function(g){switch(g.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=g.sent(),this._extensionsOnExporting(),n=this._generateJSON(t.byteLength),r=e+".glb",o=n.length,"undefined"!=typeof TextEncoder&&(i=new TextEncoder,a=i.encode(n),o=a.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),a)l.writeTypedArray(a);else for(f="_".charCodeAt(0),h=0;h<o;++h)(p=n.charCodeAt(h))!=n.codePointAt(h)?l.writeUInt8(f):l.writeUInt8(p);for(h=0;h<s;++h)l.writeUInt8(32);for(l.writeUInt32(t.byteLength+u),l.writeUInt32(5130562),l.writeTypedArray(t),h=0;h<u;++h)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(N,g.Epsilon)||g.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsWithEpsilon(N,g.Epsilon)){var o=g.TmpVectors.Vector3[0].copyFrom(t.position);n&&z(o),e.translation=o.asArray()}t.scaling.equalsWithEpsilon(D,g.Epsilon)||(e.scale=t.scaling.asArray());var a=(null===(r=t.rotationQuaternion)||void 0===r?void 0:r.clone())||g.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);a.equalsWithEpsilon(L,g.Epsilon)||(n&&j(a),e.rotation=a.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,n){var r=g.TmpVectors.Vector3[0],o=g.TmpVectors.Quaternion[0],a=t.getWorldMatrix();if(t.parent){var i=t.parent.getWorldMatrix().invertToRef(g.TmpVectors.Matrix[0]);a.multiplyToRef(i,g.TmpVectors.Matrix[1]).decompose(void 0,o,r)}else a.decompose(void 0,o,r);r.equalsWithEpsilon(N,g.Epsilon)||(n&&z(r),e.translation=r.asArray()),n&&j(o),this._babylonScene.useRightHandedSystem||X(o),o.equalsWithEpsilon(L,g.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===g.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===g.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(),a=n.orthoBottom&&n.orthoTop?.5*(n.orthoTop-n.orthoBottom):.5*n.getEngine().getRenderHeight();r.orthographic={xmag:o,ymag:a,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,a=r;o<a.length;o++)a[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 a={},i=-1,s=0;s<n.bones.length;++s){var u=n.bones[s];-1!==(f=null!==(t=u.getIndex())&&void 0!==t?t:s)&&(a[f]=u,f>i&&(i=f))}for(var c,l=[],f=0;f<=i;++f){var p=(u=a[f]).getTransformNode(),h=p?r._nodeMap.get(p):void 0;if(void 0!==h){o.joints.push(h);var d=u.getAbsoluteInverseBindMatrix().clone();e.has(p)&&(c=d,P.invertToRef(g.TmpVectors.Matrix[0]).multiplyToRef(c,c).multiplyToRef(P,c)),l.push(d)}else g.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.")}var m=r._nodesSkinMap.get(o);if(o.joints.length>0&&void 0!==m){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=m;y<T.length;y++)T[y].skin=v}},r=this,o=0,a=this._babylonScene.skeletons;o<a.length;o++)n(a[o])},e.prototype._exportSceneAsync=function(){return y(this,void 0,void 0,(function(){var e,t,n,r,o,a,i,s,u,c,l,f,p,h,d,g,m,x,_,v,y,b,A;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,a=0,i=this._babylonScene.rootNodes;a<i.length;a++)s=i[a],this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&U(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 ie(!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()])),p=new ie(!1,!1),d=(h=(b=e.nodes).push).apply,g=[b],[4,this._exportNodesAsync(n,p)];case 2:return d.apply(h,g.concat([T.sent()])),m=new ie(!1,!0),_=(x=(A=e.nodes).push).apply,v=[A],[4,this._exportNodesAsync(o,m)];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,a;return T(this,(function(i){switch(i.label){case 0:n=new Array,this._exportBuffers(e,t),r=0,o=e,i.label=1;case 1:return r<o.length?(a=o[r],[4,this._exportNodeAsync(a,n,t)]):[3,4];case 2:i.sent(),i.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 g.AbstractMesh&&e.geometry){var a=e.geometry.getVertexBuffers();if(a)for(var i in a)if(G(i)){var s=a[i];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 p=0;p<f.numTargets;p++){var h=f.getTarget(p);l=r.get(h)||[],r.set(h,l),-1===l.indexOf(e)&&l.push(e)}}for(var d=0,m=e.getChildren();d<m.length;d++){var x=m[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,a=0,i=e;a<i.length;a++){var s=i[a];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 a=n.get(e);if(!a)return"continue";var i=a[0].byteStride;if(a.some((function(e){return e.byteStride!==i})))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,a=n.byteStride,i=n.componentCount,u=n.type,c=n.count,f=n.normalized;switch(n.kind){case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:(0,g.EnumerateFloatValues)(s,o,a,i,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 g.VertexBuffer.ColorKind:var p=t.filter((function(e){return e.material instanceof g.StandardMaterial||null==e.material})).length;if(0==p)break;if(p!=t.length){g.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}u==g.VertexBuffer.UNSIGNED_BYTE&&g.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var h=new g.Color3,d=new g.Color4,m=l._babylonScene.getEngine().useExactSrgbConversions;(0,g.EnumerateFloatValues)(s,o,a,i,u,c,f,(function(e){3===e.length?(h.fromArray(e,0),h.toLinearSpaceToRef(h,m),h.toArray(e,0)):(d.fromArray(e,0),d.toLinearSpaceToRef(d,m),d.toArray(e,0))}))}},c=0,f=a;c<f.length;c++)u(B=f[c]);if(t.convertToRightHanded){for(var p=0,h=a;p<h.length;p++){var d=k(B=h[p],r.get(B)),m=d.byteOffset,x=d.byteStride,_=d.componentCount,v=d.type,y=d.count,T=d.normalized;switch(R=d.kind){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:(0,g.EnumerateFloatValues)(s,m,x,_,v,y,T,(function(e){e[0]=-e[0]}))}}t.convertedToRightHandedBuffers.set(e,s)}var b=l._bufferManager.createBufferView(s,i);t.setVertexBufferView(e,b);for(var A=new Map,M=0,w=a;M<w.length;M++){var E=k(B=w[M],r.get(B)),R=E.kind,C=E.totalVertices;switch(R){case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:if(B.type==g.VertexBuffer.FLOAT){var S=B.getFloatData(C);null!==S&&A.set(B,S)}}}0!==A.size&&g.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 V=0,I=Array.from(A.keys());V<I.length;V++){var B=I[V],F=A.get(B);if(F){for(var O=F.some((function(e){return e>=256})),P=new(O?Uint16Array:Uint8Array)(F.length),U=0;U<F.length;U++)P[U]=F[U];var N=l._bufferManager.createBufferView(P,4*(O?2:1));t.setRemappedBufferView(e,B,N)}}},l=this,f=0,p=u;f<p.length;f++)c(p[f]);for(var h=0,d=Array.from(o.keys());h<d.length;h++){var m=d[h],x=o.get(m);if(x)for(var _=ae(m,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,a,i,s,u,c,l,f=this;return T(this,(function(p){switch(p.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=p.sent())&&(r=this._nodes.length,this._nodes.push(o),this._nodeMap.set(e,r),n.pushExportedNode(e),t.push(r),a={name:"runtime animations",channels:[],samplers:[]},i=[],this._babylonScene.animationGroups.length||(oe._CreateMorphTargetAnimationFromMorphTargetAnimations(e,a,i,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&oe._CreateNodeAnimationFromNodeAnimations(e,a,i,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation)),a.channels.length&&a.samplers.length&&this._animations.push(a),i.forEach((function(e){e.channels.length&&e.samplers.length&&f._animations.push(e)}))),s=o?[]:t,u=0,c=e.getChildren(),p.label=2;case 2:return u<c.length?(l=c[u],[4,this._exportNodeAsync(l,s,n)]):[3,5];case 3:p.sent(),p.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,a,i,s,u,c,l,f,p,h;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 g.TransformNode?(this._setNodeTransformation(n,e,t.convertToRightHanded),e instanceof g.AbstractMesh?(o=e instanceof g.InstancedMesh?e.sourceMesh:e).subMeshes&&o.subMeshes.length>0?(a=n,[4,this._exportMeshAsync(o,t)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:a.mesh=d.sent(),d.label=2;case 2:e.skeleton&&void 0!==(i=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(i)&&this._nodesSkinMap.set(i,[]),null===(f=this._nodesSkinMap.get(i))||void 0===f||f.push(n)),d.label=3;case 3:if(e instanceof g.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)&&Q(e,u)&&void 0!==(c=this._nodeMap.get(u)))return l=this._nodes[c],Y(n,l),null===(p=this._nodesCameraMap.get(s))||void 0===p||p.push(l),[2,null];null===(h=this._nodesCameraMap.get(s))||void 0===h||h.push(n)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",n,e,this._nodeMap,t.convertToRightHanded)];case 4:return d.sent()?[2,n]:(g.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}}))}))},e.prototype._exportIndices=function(e,t,n,r,o,a,i,s,u){var c=e;u.mode=W(a);var l=i!==g.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case g.Material.TriangleFillMode:case g.Material.TriangleStripDrawMode:case g.Material.TriangleFanDrawMode:return!0}return!1}(a);if(l){if(a===g.Material.TriangleStripDrawMode||a===g.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");u.mode=W(a);var f=t?new Uint32Array(r):new Uint16Array(r);if(e)for(var p=0;p+2<r;p+=3)f[p]=e[n+p]+o,f[p+1]=e[n+p+2]+o,f[p+2]=e[n+p+1]+o;else for(p=0;p+2<r;p+=3)f[p]=p,f[p+1]=p+2,f[p+2]=p+1;c=f}else if(e&&0!==o){for(f=t?new Uint32Array(r):new Uint16Array(r),p=0;p<r;p++)f[p]=e[n+p]+o;c=f}if(c){var h=s.getIndicesAccessor(e,n,r,o,l);if(void 0===h){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),m=this._bufferManager.createBufferView(d),x=t?5125:5123;this._accessors.push(this._bufferManager.createAccessor(m,"SCALAR",x,r,0)),h=this._accessors.length-1,s.setIndicesAccessor(e,n,r,o,l,h)}u.indices=h}},e.prototype._exportVertexBuffer=function(e,t,n,r,o,a){var i=e.getKind();if(G(i)&&(!i.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=i===g.VertexBuffer.PositionKind?function(e,t,n,r){var o=t.byteOffset,a=t.byteStride,i=t.type,s=t.normalized,u=t.getSize(),c=new Array(u).fill(1/0),l=new Array(u).fill(-1/0);return(0,g.EnumerateFloatValues)(e,o+n*a,a,u,i,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=(i===g.VertexBuffer.MatricesIndicesKind||i===g.VertexBuffer.MatricesIndicesExtraKind)&&e.type===g.VertexBuffer.FLOAT,f=l?g.VertexBuffer.UNSIGNED_BYTE:e.type,p=l?void 0:e.normalized,h=l?o.getRemappedBufferView(e._buffer,e):o.getVertexBufferView(e._buffer),d=e.byteOffset+n*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(h,function(e,t){if(e==g.VertexBuffer.ColorKind)return t?"VEC4":"VEC3";switch(e){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:return"VEC3";case g.VertexBuffer.TangentKind:case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:case g.VertexBuffer.MatricesWeightsKind:case g.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case g.VertexBuffer.UVKind:case g.VertexBuffer.UV2Kind:case g.VertexBuffer.UV3Kind:case g.VertexBuffer.UV4Kind:case g.VertexBuffer.UV5Kind:case g.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(i,o.hasVertexColorAlpha(e)),f,r,d,c,p)),s=this._accessors.length-1,o.setVertexAccessor(e,n,r,s)}a.attributes[function(e){switch(e){case g.VertexBuffer.PositionKind:return"POSITION";case g.VertexBuffer.NormalKind:return"NORMAL";case g.VertexBuffer.TangentKind:return"TANGENT";case g.VertexBuffer.ColorKind:return"COLOR_0";case g.VertexBuffer.UVKind:return"TEXCOORD_0";case g.VertexBuffer.UV2Kind:return"TEXCOORD_1";case g.VertexBuffer.UV3Kind:return"TEXCOORD_2";case g.VertexBuffer.UV4Kind:return"TEXCOORD_3";case g.VertexBuffer.UV5Kind:return"TEXCOORD_4";case g.VertexBuffer.UV6Kind:return"TEXCOORD_5";case g.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case g.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case g.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case g.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(i)]=s}},e.prototype._exportMaterialAsync=function(e,t,n,r){return y(this,void 0,void 0,(function(){var o,a;return T(this,(function(i){switch(i.label){case 0:return void 0!==(o=this._materialMap.get(e))?[3,8]:(a=t&&Object.keys(t).some((function(e){return e.startsWith("uv")})),(e=e instanceof g.MultiMaterial?e.subMaterials[n.materialIndex]:e)instanceof g.PBRBaseMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,a)]:[3,2]);case 1:return o=i.sent(),[3,7];case 2:return e instanceof g.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,a)]:[3,4];case 3:return o=i.sent(),[3,7];case 4:return e instanceof g.OpenPBRMaterial?[4,this._materialExporter.exportOpenPBRMaterialAsync(e,a)]:[3,6];case 5:return o=i.sent(),[3,7];case 6:return g.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 7:this._materialMap.set(e,o),i.label=8;case 8:return r.material=o,[2]}}))}))},e.prototype._exportMeshAsync=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,a,i,s,u,c,l,f,p,h,d,m,x,_,v,y,A,M,w,E,R,C,S,V,I,B,F,O,P,U,N,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(),a=null===(F=e.geometry)||void 0===F?void 0:F.getVertexBuffers(),i=t.getMorphTargetsFromMesh(e),s=e instanceof g.LinesMesh,u=e instanceof g.GreasedLineBaseMesh,c=e.subMeshes,!(a&&c&&c.length>0))return[3,7];l=0,f=c,T.label=1;case 1:return l<f.length?(p=f[l],h={attributes:{}},d=p.getMaterial()||this._babylonScene.defaultMaterial,u?(v={name:d.name},y=e,m=g.Color3.White(),x=null!==(P=null===(O=y.material)||void 0===O?void 0:O.alpha)&&void 0!==P?P:1,(!(_=null!==(N=null===(U=y.greasedLineMaterial)||void 0===U?void 0:U.color)&&void 0!==N?N:m).equalsWithEpsilon(m,g.Epsilon)||x<1)&&(v.pbrMetallicRoughness={baseColorFactor:b(b([],_.asArray(),!0),[x],!1)}),this._materials.push(v),h.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return s?(v={name:d.name},(!(y=e).color.equalsWithEpsilon(g.Color3.White(),g.Epsilon)||y.alpha<1)&&(v.pbrMetallicRoughness={baseColorFactor:b(b([],y.color.asArray(),!0),[y.alpha],!1)}),this._materials.push(v),h.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(d,a,p,h)];case 4:T.sent(),T.label=5;case 5:for(A=s||u?g.Material.LineListDrawMode:null!==(L=e.overrideRenderingFillMode)&&void 0!==L?L:d.fillMode,M=d._getEffectiveOrientation(e),t.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(M=M===g.Material.ClockWiseSideOrientation?g.Material.CounterClockWiseSideOrientation:g.Material.ClockWiseSideOrientation),this._exportIndices(o,o?(0,g.AreIndices32Bits)(o,p.indexCount,p.indexStart,p.verticesStart):p.verticesCount>65535,o?p.indexStart:p.verticesStart,o?p.indexCount:p.verticesCount,-p.verticesStart,A,M,t,h),w=0,E=Object.values(a);w<E.length;w++)R=E[w],this._exportVertexBuffer(R,d,p.verticesStart,p.verticesCount,t,h);if(i)for(h.targets=[],C=0,S=i;C<S.length;C++)B=S[C],h.targets.push(B.attributes);r.primitives.push(h),this._extensionsPostExportMeshPrimitive(h),T.label=6;case 6:return l++,[3,1];case 7:if(i)for(r.weights=[],r.extras||(r.extras={}),r.extras.targetNames=[],V=0,I=i;V<I.length;V++)B=I[V],r.weights.push(B.influence),r.extras.targetNames.push(B.name);return[2,n]}}))}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e._ExtensionOrders={},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(a){switch(a.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:a.sent(),a.label=2;case 2:return[4,(r=new se(e,n)).generateGLTFAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=a.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(a){switch(a.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:a.sent(),a.label=2;case 2:return[4,(r=new se(e,n)).generateGLBAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=a.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,a){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 g.Mesh&&n.hasThinInstances&&e._exporter){e._wasUsed=!0;for(var i=g.Vector3.Zero(),s=g.Quaternion.Identity(),u=g.Vector3.One(),c=n.thinInstanceGetWorldMatrices(),l=g.TmpVectors.Vector3[2],f=g.TmpVectors.Quaternion[1],p=g.TmpVectors.Vector3[3],h=!1,d=!1,m=!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(p,f,l),o&&(z(l),j(f)),x.set(l.asArray(),3*y),_.set(f.normalize().asArray(),4*y),v.set(p.asArray(),3*y),h=h||!l.equalsWithEpsilon(i),d=d||!f.equalsWithEpsilon(s),m=m||!p.equalsWithEpsilon(u),y++;var A={attributes:{}};h&&(A.attributes.TRANSLATION=e._buildAccessor(x,"VEC3",n.thinInstanceCount,a)),d&&(A.attributes.ROTATION=e._buildAccessor(_,"VEC4",n.thinInstanceCount,a)),m&&(A.attributes.SCALE=e._buildAccessor(v,"VEC3",n.thinInstanceCount,a)),t.extensions=t.extensions||{},t.extensions[ce]=A}r(t)}))];case 1:return[2,r.sent()]}}))}))},e.prototype._buildAccessor=function(e,t,n,r){var o=r.createBufferView(e),a=r.createAccessor(o,t,5126,n);return this._exporter._accessors.push(a),this._exporter._accessors.length-1},e}();se.RegisterExtension(ce,(function(e){return new le(e)}));var fe="KHR_draco_mesh_compression",pe=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&&g.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=[],a=[],i=null;if(void 0!==e.indices){var s=n[e.indices],u=t.getBufferView(s);i=t.getData(u).slice(),o.push(u),a.push(s)}for(var c,l=[],f=0,p=Object.entries(e.attributes);f<p.length;f++){var h=p[f],d=h[0],m=(s=n[h[1]],u=t.getBufferView(s),H(s.type)),x=(0,g.GetTypedArrayData)(t.getData(u),m,s.componentType,s.byteOffset||0,u.byteStride||(0,g.GetTypeByteLength)(s.componentType)*m,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:H(s.type),data:x}),o.push(u),a.push(s)}var _={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},v=g.DracoEncoder.Default._encodeAsync(l,i,_).then((function(n){if(n){var i={bufferView:-1,attributes:n.attributeIds},s=t.createBufferView(n.data);t.setBufferView(i,s);for(var u=0,c=o;u<c.length;u++){var l=c[u];r._bufferViewsUsed.add(l)}for(var f=0,p=a;f<p.length;f++){var h=p[f];r._accessorsUsed.add(h)}e.extensions||(e.extensions={}),e.extensions[fe]=i}else g.Logger.Error("Draco encoding failed for primitive.")})).catch((function(e){g.Logger.Error("Draco encoding failed for primitive: "+e)}));this._encodePromises.push(v),this._wasUsed=!0}else g.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 pe(e)}));var he="KHR_lights_punctual",de={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},ge={innerConeAngle:0,outerConeAngle:Math.PI/4},me=g.Vector3.Backward(),xe=function(){function e(e){this.name=he,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[he]=this._lights},e.prototype.postExportNodeAsync=function(e,t,n,r,o){return y(this,void 0,void 0,(function(){var a=this;return T(this,(function(i){switch(i.label){case 0:return[4,new Promise((function(i){if(n instanceof g.Light){var s=n.getTypeID()==g.Light.LIGHTTYPEID_POINTLIGHT?"point":n.getTypeID()==g.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":n.getTypeID()==g.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(s&&n instanceof g.ShadowLight))return g.Logger.Warn("".concat(e,": Light ").concat(n.name," is not supported in ").concat(he)),void i(t);if(n.falloffType!==g.Light.FALLOFF_GLTF&&g.Logger.Warn("".concat(e,": Light falloff for ").concat(n.name," does not match the ").concat(he," specification!")),!n.position.equalsToFloats(0,0,0)){var u=g.TmpVectors.Vector3[0].copyFrom(n.position);o&&z(u),t.translation=u.asArray()}if("point"!==s){var c=n.direction.normalizeToRef(g.TmpVectors.Vector3[0]);o&&z(c);var l=g.Quaternion.FromUnitVectorsToRef(me,c,g.TmpVectors.Quaternion[0]);g.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 p=n;f.spot={innerConeAngle:p.innerAngle/2,outerConeAngle:p.angle/2},Z(f.spot,ge)}a._lights||(a._lights={lights:[]}),a._lights.lights.push(f);var h={light:a._lights.lights.length-1},d=n.parent;if(d&&Q(n,d)){var m=r.get(d);if(m){var x=a._exporter._nodes[m];return Y(t,x),x.extensions||(x.extensions={}),x.extensions[he]=h,void i(null)}}t.extensions||(t.extensions={}),t.extensions[he]=h,i(t)}else i(t)}))];case 1:return[2,i.sent()]}}))}))},e}();se.RegisterExtension(he,(function(e){return new xe(e)}));var _e="KHR_materials_anisotropy";function ve(e,t){t.uOffset=e.uOffset,t.vOffset=e.vOffset,t.uScale=e.uScale,t.vScale=e.vScale,t.uAng=e.uAng,t.vAng=e.vAng,t.wAng=e.wAng,t.uRotationCenter=e.uRotationCenter,t.vRotationCenter=e.vRotationCenter}function ye(e){return y(this,void 0,void 0,(function(){var t,n,r,o,a,i,s,u;return T(this,(function(c){switch(c.label){case 0:return t=e.getScene(),g.Effect.ShadersStore.anisotropyMergeFragmentShader||(g.Effect.ShadersStore.anisotropyMergeFragmentShader="\n precision highp float;\n#ifdef HAS_TANGENT_TEXTURE\n uniform sampler2D tangentTexture;\n#endif\n#ifdef HAS_ANISOTROPY_TEXTURE\n uniform sampler2D anisotropyTexture;\n#endif\n uniform int useRoughnessFromMetallicGreen;\n uniform int useAnisotropyFromTangentBlue;\n\n varying vec2 vUV;\n\n void main() {\n vec2 tangent = vec2(1.0, 0.0);\n float anisotropy = 1.0;\n #ifdef HAS_TANGENT_TEXTURE\n // Tangent texture is present\n vec4 tangentSample = texture2D(tangentTexture, vUV);\n tangent = tangentSample.rg;\n\n if (useAnisotropyFromTangentBlue > 0) {\n anisotropy = tangentSample.b;\n }\n #endif\n #ifdef HAS_ANISOTROPY_TEXTURE\n // Anisotropy texture is present\n vec4 anisotropySample = texture2D(anisotropyTexture, vUV);\n anisotropy = anisotropySample.r;\n #endif\n \n // Output: RG = tangent XY, B = anisotropy strength\n vec4 anisotropyData = vec4(tangent.x, tangent.y, anisotropy, 1.0);\n gl_FragColor = anisotropyData;\n }\n"),n=e.specularRoughnessAnisotropyTexture,r=e.geometryTangentTexture,n||r?(o=Math.max(n?n.getSize().width:1,r?r.getSize().width:1),a=Math.max(n?n.getSize().height:1,r?r.getSize().height:1),i={type:g.Constants.TEXTURETYPE_UNSIGNED_BYTE,format:g.Constants.TEXTUREFORMAT_RGBA,samplingMode:g.Constants.TEXTURE_BILINEAR_SAMPLINGMODE,generateDepthBuffer:!1,generateStencilBuffer:!1,generateMipMaps:!1},(s=new g.ProceduralTexture(e.name+"_anisotropy",{width:o,height:a},"anisotropyMerge",t,i)).refreshRate=-1,u="",r&&(u+="#define HAS_TANGENT_TEXTURE\n",s.setTexture("tangentTexture",r),ve(r,s)),s.setVector2("tangentVector",e.geometryTangent),n&&(u+="#define HAS_ANISOTROPY_TEXTURE\n",s.setTexture("anisotropyTexture",n),ve(n,s)),s.setInt("useAnisotropyFromTangentBlue",e._useSpecularRoughnessAnisotropyFromTangentTexture?1:0),s.defines=u,[4,new Promise((function(e,t){s.executeWhenReady((function(){try{s.render(),e(s)}catch(e){t(e instanceof Error?e:new Error(String(e)))}}))}))]):[2,null];case 1:return[2,c.sent()]}}))}))}var Te=function(){function e(e){this.name=_e,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._anisoTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e,t;return T(this,(function(r){switch(r.label){case 0:return e=[],n instanceof g.PBRBaseMaterial?n.anisotropy.isEnabled&&!n.anisotropy.legacy?(n.anisotropy.texture&&e.push(n.anisotropy.texture),[2,e]):[3,3]:[3,1];case 1:return n instanceof g.OpenPBRMaterial&&n.specularRoughnessAnisotropy>0?[4,ye(n)]:[3,3];case 2:return(t=r.sent())&&(e.push(t),this._anisoTexturesMap[n.id]=t),[2,e];case 3:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){var o,a,i,s,u,c;if(n instanceof g.PBRBaseMaterial){if(!n.anisotropy.isEnabled||n.anisotropy.legacy)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var l=r._exporter._materialExporter.getTextureInfo(n.anisotropy.texture);null!==(v={anisotropyStrength:n.anisotropy.intensity,anisotropyRotation:n.anisotropy.angle,anisotropyTexture:null!=l?l:void 0}).anisotropyTexture&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[_e]=v}else if(n instanceof g.OpenPBRMaterial&&n.specularRoughnessAnisotropy>0){r._wasUsed=!0,t.extensions=t.extensions||{};var f=n.specularRoughnessTexture;n._useRoughnessFromMetallicTextureGreen&&(f=n.baseMetalnessTexture);var p=r._anisoTexturesMap[n.id];if(!f&&!p){var h=n.specularRoughness,d=n.specularRoughnessAnisotropy;if(!n._useGltfStyleAnisotropy){var m=(a=n.specularRoughness,c=(1-(i=n.specularRoughnessAnisotropy))*(u=(s=a*a)*Math.sqrt(2/(1+(1-i)*(1-i)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-s)/Math.max(1-s,1e-4)),1)});h=m.newBaseRoughness,d=m.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=h);var x={anisotropyStrength:d,anisotropyRotation:n.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return t.extensions[_e]=x,e(t)}var _=p?r._exporter._materialExporter.getTextureInfo(p):null,v={anisotropyStrength:n.specularRoughnessAnisotropy,anisotropyRotation:n.geometryTangentAngle,anisotropyTexture:_||void 0,extensions:{}};n._useGltfStyleAnisotropy||(v.extensions.EXT_materials_anisotropy_openpbr={openPbrAnisotropyEnabled:!0},(o=r._exporter._glTF).extensionsUsed||(o.extensionsUsed=[]),-1===r._exporter._glTF.extensionsUsed.indexOf("EXT_materials_anisotropy_openpbr")&&r._exporter._glTF.extensionsUsed.push("EXT_materials_anisotropy_openpbr")),r._exporter._materialNeedsUVsSet.add(n),t.extensions[_e]=v}e(t)}))},e}();se.RegisterExtension(_e,(function(e){return new Te(e)}));var be="KHR_materials_clearcoat",Ae=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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e;return T(this,(function(t){if(e=[],n instanceof g.PBRBaseMaterial){if(n.clearCoat.isEnabled)return n.clearCoat.texture&&e.push(n.clearCoat.texture),!n.clearCoat.useRoughnessFromMainTexture&&n.clearCoat.textureRoughness&&e.push(n.clearCoat.textureRoughness),n.clearCoat.bumpTexture&&e.push(n.clearCoat.bumpTexture),[2,e]}else if(n instanceof g.OpenPBRMaterial&&n.coatWeight>0)return n.coatWeightTexture&&e.push(n.coatWeightTexture),n.geometryCoatNormalTexture&&e.push(n.geometryCoatNormalTexture),n.coatRoughnessTexture&&e.push(n.coatRoughnessTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof g.PBRBaseMaterial){if(!n.clearCoat.isEnabled)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var o=r._exporter._materialExporter.getTextureInfo(n.clearCoat.texture),a=void 0;a=n.clearCoat.useRoughnessFromMainTexture?r._exporter._materialExporter.getTextureInfo(n.clearCoat.texture):r._exporter._materialExporter.getTextureInfo(n.clearCoat.textureRoughness),n.clearCoat.isTintEnabled&&g.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(n.name)),n.clearCoat.remapF0OnInterfaceChange&&g.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(n.name));var i=r._exporter._materialExporter.getTextureInfo(n.clearCoat.bumpTexture);null===(s={clearcoatFactor:n.clearCoat.intensity,clearcoatTexture:null!=o?o:void 0,clearcoatRoughnessFactor:n.clearCoat.roughness,clearcoatRoughnessTexture:null!=a?a:void 0,clearcoatNormalTexture:null!=i?i:void 0}).clearcoatTexture&&null===s.clearcoatRoughnessTexture&&null===s.clearcoatRoughnessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[be]=s}else if(n instanceof g.OpenPBRMaterial){if(0==n.coatWeight)return void e(t);var s;r._wasUsed=!0,t.extensions=t.extensions||{},o=r._exporter._materialExporter.getTextureInfo(n.coatWeightTexture),a=void 0,a=n.useCoatRoughnessFromWeightTexture?r._exporter._materialExporter.getTextureInfo(n.coatWeightTexture):r._exporter._materialExporter.getTextureInfo(n.coatRoughnessTexture),n.coatColorTexture&&g.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(n.name)),i=r._exporter._materialExporter.getTextureInfo(n.geometryCoatNormalTexture),null===(s={clearcoatFactor:n.coatWeight,clearcoatTexture:null!=o?o:void 0,clearcoatRoughnessFactor:n.coatRoughness,clearcoatRoughnessTexture:null!=a?a:void 0,clearcoatNormalTexture:null!=i?i:void 0}).clearcoatTexture&&null===s.clearcoatRoughnessTexture&&null===s.clearcoatRoughnessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[be]=s}e(t)}))},e}();se.RegisterExtension(be,(function(e){return new Ae(e)}));var Me="KHR_materials_clearcoat_darkening",we=function(){function e(e){this.name=Me,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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e;return T(this,(function(t){return e=[],n instanceof g.OpenPBRMaterial&&n.coatDarkening?(n.coatDarkeningTexture&&e.push(n.coatDarkeningTexture),[2,e]):[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){var o=null,a=null;if(n instanceof g.OpenPBRMaterial&&(o=n.coatDarkening,a=n.coatDarkeningTexture),null===o||1===o&&null===a)return e(t);var i=t.extensions?t.extensions.KHR_materials_clearcoat:null;if(!i)return e(t);r._wasUsed=!0;var s=r._exporter._materialExporter.getTextureInfo(a),u={clearcoatDarkeningFactor:o,clearcoatDarkeningTexture:null!=s?s:void 0};return null!==u.clearcoatDarkeningTexture&&r._exporter._materialNeedsUVsSet.add(n),i.extensions=i.extensions||{},i.extensions[Me]=u,e(t)}))},e}();se.RegisterExtension(Me,(function(e){return new we(e)}),105);var Ee="KHR_materials_clearcoat_ior",Re=function(){function e(e){this.name=Ee,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.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){var o=null;if(n instanceof g.OpenPBRMaterial?o=n.coatIor:n instanceof g.PBRMaterial&&(o=n.clearCoat.indexOfRefraction),null===o||1.5===o)return e(t);var a=t.extensions?t.extensions.KHR_materials_clearcoat:null;if(!a)return e(t);r._wasUsed=!0;var i={clearcoatIor:o};return r._exporter,a.extensions=a.extensions||{},a.extensions[Ee]=i,e(t)}))},e}();se.RegisterExtension(Ee,(function(e){return new Re(e)}),105);var Ce="KHR_materials_clearcoat_color",Se=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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e;return T(this,(function(t){if(e=[],n instanceof g.PBRBaseMaterial){if(n.clearCoat.isEnabled)return n.clearCoat.tintTexture&&e.push(n.clearCoat.tintTexture),[2,e]}else if(n instanceof g.OpenPBRMaterial&&n.coatWeight>0)return n.coatColorTexture&&e.push(n.coatColorTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof g.PBRBaseMaterial){if(!n.clearCoat.isEnabled)return void e(t);if(r._wasUsed=!0,!(a=t.extensions?t.extensions.KHR_materials_clearcoat:null))return void e(t);var o=r._exporter._materialExporter.getTextureInfo(n.clearCoat.tintTexture);null!==(i={clearcoatColorFactor:n.clearCoat.tintColor.asArray(),clearcoatColorTexture:null!=o?o:void 0}).clearcoatColorTexture&&r._exporter._materialNeedsUVsSet.add(n),a.extensions=a.extensions||{},a.extensions[Ce]=i}else if(n instanceof g.OpenPBRMaterial){if(0==n.coatWeight)return void e(t);var a,i;if(r._wasUsed=!0,!(a=t.extensions?t.extensions.KHR_materials_clearcoat:null))return void e(t);o=r._exporter._materialExporter.getTextureInfo(n.coatWeightTexture),null!==(i={clearcoatColorFactor:n.coatColor.asArray(),clearcoatColorTexture:null!=o?o:void 0}).clearcoatColorTexture&&r._exporter._materialNeedsUVsSet.add(n),a.extensions=a.extensions||{},a.extensions[Ce]=i}e(t)}))},e}();se.RegisterExtension(Ce,(function(e){return new Se(e)}),105);var Ve="KHR_materials_clearcoat_anisotropy";function Ie(e,t){t.uOffset=e.uOffset,t.vOffset=e.vOffset,t.uScale=e.uScale,t.vScale=e.vScale,t.uAng=e.uAng,t.vAng=e.vAng,t.wAng=e.wAng,t.uRotationCenter=e.uRotationCenter,t.vRotationCenter=e.vRotationCenter}function Be(e){return y(this,void 0,void 0,(function(){var t,n,r,o,a,i,s,u;return T(this,(function(c){switch(c.label){case 0:return t=e.getScene(),g.Effect.ShadersStore.anisotropyMergeFragmentShader||(g.Effect.ShadersStore.anisotropyMergeFragmentShader="\n precision highp float;\n#ifdef HAS_TANGENT_TEXTURE\n uniform sampler2D tangentTexture;\n#endif\n#ifdef HAS_ANISOTROPY_TEXTURE\n uniform sampler2D anisotropyTexture;\n#endif\n uniform int useRoughnessFromMetallicGreen;\n uniform int useAnisotropyFromTangentBlue;\n\n varying vec2 vUV;\n\n void main() {\n vec2 tangent = vec2(1.0, 0.0);\n float anisotropy = 1.0;\n #ifdef HAS_TANGENT_TEXTURE\n // Tangent texture is present\n vec4 tangentSample = texture2D(tangentTexture, vUV);\n tangent = tangentSample.rg;\n\n if (useAnisotropyFromTangentBlue > 0) {\n anisotropy = tangentSample.b;\n }\n #endif\n #ifdef HAS_ANISOTROPY_TEXTURE\n // Anisotropy texture is present\n vec4 anisotropySample = texture2D(anisotropyTexture, vUV);\n anisotropy = anisotropySample.r;\n #endif\n \n // Output: RG = tangent XY, B = anisotropy strength\n vec4 anisotropyData = vec4(tangent.x, tangent.y, anisotropy, 1.0);\n gl_FragColor = anisotropyData;\n }\n"),n=e.coatRoughnessAnisotropyTexture,r=e.geometryCoatTangentTexture,n||r?(o=Math.max(n?n.getSize().width:1,r?r.getSize().width:1),a=Math.max(n?n.getSize().height:1,r?r.getSize().height:1),i={type:g.Constants.TEXTURETYPE_UNSIGNED_BYTE,format:g.Constants.TEXTUREFORMAT_RGBA,samplingMode:g.Constants.TEXTURE_BILINEAR_SAMPLINGMODE,generateDepthBuffer:!1,generateStencilBuffer:!1,generateMipMaps:!1},(s=new g.ProceduralTexture(e.name+"_anisotropy",{width:o,height:a},"anisotropyMerge",t,i)).refreshRate=-1,u="",r&&(u+="#define HAS_TANGENT_TEXTURE\n",s.setTexture("tangentTexture",r),Ie(r,s)),s.setVector2("tangentVector",e.geometryTangent),n&&(u+="#define HAS_ANISOTROPY_TEXTURE\n",s.setTexture("anisotropyTexture",n),Ie(n,s)),s.setInt("useAnisotropyFromTangentBlue",e._useCoatRoughnessAnisotropyFromTangentTexture?1:0),s.defines=u,[4,new Promise((function(e,t){s.executeWhenReady((function(){try{s.render(),e(s)}catch(e){t(e instanceof Error?e:new Error(String(e)))}}))}))]):[2,null];case 1:return[2,c.sent()]}}))}))}var Fe=function(){function e(e){this.name=Ve,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._anisoTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e,t;return T(this,(function(r){switch(r.label){case 0:return e=[],n instanceof g.OpenPBRMaterial&&n.coatRoughnessAnisotropy>0?[4,Be(n)]:[3,2];case 1:return(t=r.sent())&&(e.push(t),this._anisoTexturesMap[n.id]=t),[2,e];case 2:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){var o,a,i,s,u,c;if(n instanceof g.OpenPBRMaterial&&n.coatRoughnessAnisotropy>0){t.extensions=t.extensions||{};var l=t.extensions?t.extensions.KHR_materials_clearcoat:null;if(!l)return e(t);r._wasUsed=!0;var f=n.coatRoughnessTexture,p=r._anisoTexturesMap[n.id];if(!f&&!p){var h=n.coatRoughness,d=n.coatRoughnessAnisotropy;if(!n._useGltfStyleAnisotropy){var m=(a=n.coatRoughness,c=(1-(i=n.coatRoughnessAnisotropy))*(u=(s=a*a)*Math.sqrt(2/(1+(1-i)*(1-i)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-s)/Math.max(1-s,1e-4)),1)});h=m.newBaseRoughness,d=m.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=h);var x={clearcoatAnisotropyStrength:d,clearcoatAnisotropyRotation:n.geometryCoatTangentAngle+.5*Math.PI,clearcoatAnisotropyTexture:void 0};return l.extensions=l.extensions||{},l.extensions[Ve]=x,e(t)}var _=p?r._exporter._materialExporter.getTextureInfo(p):null,v={clearcoatAnisotropyStrength:n.coatRoughnessAnisotropy,clearcoatAnisotropyRotation:n.geometryCoatTangentAngle,clearcoatAnisotropyTexture:_||void 0,extensions:{}};n._useGltfStyleAnisotropy||(v.extensions.EXT_materials_anisotropy_openpbr={openPbrAnisotropyEnabled:!0},(o=r._exporter._glTF).extensionsUsed||(o.extensionsUsed=[]),-1===r._exporter._glTF.extensionsUsed.indexOf("EXT_materials_anisotropy_openpbr")&&r._exporter._glTF.extensionsUsed.push("EXT_materials_anisotropy_openpbr")),r._exporter._materialNeedsUVsSet.add(n),l.extensions=l.extensions||{},l.extensions[Ve]=v}e(t)}))},e}();se.RegisterExtension(Ve,(function(e){return new Fe(e)}),105);var Oe="KHR_materials_diffuse_transmission";function Pe(e,t){var n=t.subSurface,r=null;return n.translucencyIntensityTexture?r=n.translucencyIntensityTexture:n.thicknessTexture&&n.useMaskFromThicknessTexture&&(r=n.thicknessTexture),r&&!n.useGltfStyleTextures?(g.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(t.name),1),null):r}var Ue=function(){function e(e){this.name=Oe,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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var t,r;return T(this,(function(o){return t=[],n instanceof g.PBRMaterial&&this._isExtensionEnabled(n)?((r=Pe(e,n))&&t.push(r),n.subSurface.translucencyColorTexture&&t.push(n.subSurface.translucencyColorTexture),[2,t]):[2,t]}))}))},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 a,i;if(n instanceof g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var s=n.subSurface,u=Pe(e,n),c=0==s.translucencyIntensity?void 0:s.translucencyIntensity,l=null!==(a=r._exporter._materialExporter.getTextureInfo(u))&&void 0!==a?a:void 0,f=!s.translucencyColor||s.translucencyColor.equalsFloats(1,1,1)?void 0:s.translucencyColor.asArray(),p=null!==(i=r._exporter._materialExporter.getTextureInfo(s.translucencyColorTexture))&&void 0!==i?i:void 0,h={diffuseTransmissionFactor:c,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:f,diffuseTransmissionColorTexture:p};(l||p)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions=t.extensions||{},t.extensions[Oe]=h}o(t)}))},e}();se.RegisterExtension(Oe,(function(e){return new Ue(e)}));var Ne="KHR_materials_dispersion",Le=function(){function e(){this.name=Ne,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 g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var o={dispersion:n.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[Ne]=o}e(t)}))},e}();se.RegisterExtension(Ne,(function(){return new Le}));var De="KHR_materials_emissive_strength",Ke=function(){function e(){this.name=De,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 g.PBRMaterial))return r(t);var o=n.emissiveColor.scale(n.emissiveIntensity),a=Math.max.apply(Math,o.asArray());if(a>1){t.emissiveFactor=o.scale(1/a).asArray(),e._wasUsed=!0;var i={emissiveStrength:a};t.extensions||(t.extensions={}),t.extensions[De]=i}else t.emissiveFactor=o.asArray();return r(t)}))];case 1:return[2,r.sent()]}}))}))},e}();se.RegisterExtension(De,(function(){return new Ke}));var ke="KHR_materials_ior",He=function(){function e(){this.name=ke,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 g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var o={ior:n.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[ke]=o}e(t)}))},e}();se.RegisterExtension(ke,(function(e){return new He}));var Ge="KHR_materials_iridescence",We=function(){function e(e){this.name=Ge,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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e;return T(this,(function(t){return e=[],n instanceof g.PBRBaseMaterial&&n.iridescence.isEnabled?(n.iridescence.texture&&e.push(n.iridescence.texture),n.iridescence.thicknessTexture&&n.iridescence.thicknessTexture!==n.iridescence.texture&&e.push(n.iridescence.thicknessTexture),[2,e]):[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof g.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),a=r._exporter._materialExporter.getTextureInfo(n.iridescence.thicknessTexture),i={iridescenceFactor:n.iridescence.intensity,iridescenceIor:n.iridescence.indexOfRefraction,iridescenceThicknessMinimum:n.iridescence.minimumThickness,iridescenceThicknessMaximum:n.iridescence.maximumThickness,iridescenceTexture:null!=o?o:void 0,iridescenceThicknessTexture:null!=a?a:void 0};null===i.iridescenceTexture&&null===i.iridescenceThicknessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[Ge]=i}e(t)}))},e}();se.RegisterExtension(Ge,(function(e){return new We(e)}));var qe="KHR_materials_sheen",ze=function(){function e(e){this.name=qe,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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){return T(this,(function(e){return n instanceof g.PBRMaterial&&n.sheen.isEnabled&&n.sheen.texture?[2,[n.sheen.texture]]:[2,[]]}))}))},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,a,i,s;if(n instanceof g.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!==(a=e._exporter._materialExporter.getTextureInfo(n.sheen.texture))&&void 0!==a?a:void 0),n.sheen.textureRoughness&&!n.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(n.sheen.textureRoughness))&&void 0!==i?i: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[qe]=u}r(t)}))];case 1:return[2,r.sent()]}}))}))},e}();se.RegisterExtension(qe,(function(e){return new ze(e)}));var je="KHR_materials_specular",Xe=function(){function e(e){this.name=je,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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e;return T(this,(function(t){return e=[],n instanceof g.PBRMaterial&&this._isExtensionEnabled(n)?(n.metallicReflectanceTexture&&e.push(n.metallicReflectanceTexture),n.reflectanceTexture&&e.push(n.reflectanceTexture),[2,e]):[2,e]}))}))},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,a,i,s,u;if(n instanceof g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0,t.extensions=t.extensions||{};var c=null!==(o=r._exporter._materialExporter.getTextureInfo(n.metallicReflectanceTexture))&&void 0!==o?o:void 0,l=null!==(a=r._exporter._materialExporter.getTextureInfo(n.reflectanceTexture))&&void 0!==a?a:void 0,f={specularFactor:1==n.metallicF0Factor?void 0:n.metallicF0Factor,specularTexture:c,specularColorFactor:n.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:n.metallicReflectanceColor.asArray(),specularColorTexture:l};r._hasTexturesExtension(n)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[je]=f}else if(n instanceof g.OpenPBRMaterial){t.extensions=t.extensions||{};var p=null!==(i=r._exporter._materialExporter.getTextureInfo(n.specularWeightTexture))&&void 0!==i?i:void 0,h=null!==(s=r._exporter._materialExporter.getTextureInfo(n.specularColorTexture))&&void 0!==s?s:void 0,d=1==n.specularWeight?void 0:n.specularWeight,m=n.specularColor.equalsFloats(1,1,1)?void 0:n.specularColor.asArray();if(!h&&!p&&void 0===d&&void 0===m)return e(t);r._wasUsed=!0,(f={specularFactor:d,specularTexture:p,specularColorFactor:m,specularColorTexture:h,extensions:{}}).extensions.EXT_materials_specular_edge_color={specularEdgeColorEnabled:!0},(u=r._exporter._glTF).extensionsUsed||(u.extensionsUsed=[]),-1===r._exporter._glTF.extensionsUsed.indexOf("EXT_materials_specular_edge_color")&&r._exporter._glTF.extensionsUsed.push("EXT_materials_specular_edge_color"),(p||h)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[je]=f}e(t)}))},e}();se.RegisterExtension(je,(function(e){return new Xe(e)}));var Ye="KHR_materials_transmission",Qe=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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e;return T(this,(function(t){return e=[],n instanceof g.PBRMaterial&&this._isExtensionEnabled(n)?(n.subSurface.thicknessTexture&&e.push(n.subSurface.thicknessTexture),[2,e]):[2,e]}))}))},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,a,i;return T(this,(function(s){switch(s.label){case 0:return n instanceof g.PBRMaterial&&this._isExtensionEnabled(n)?(this._wasUsed=!0,r=n.subSurface,o=0===r.refractionIntensity?void 0:r.refractionIntensity,a={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(i=s.sent())&&(a.transmissionTexture=i),[3,3];case 2:g.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[Ye]=a,s.label=4;case 4:return[2,t]}}))}))},e}();se.RegisterExtension(Ye,(function(e){return new Qe(e)}));var Ze="KHR_materials_unlit",Je=function(){function e(){this.name=Ze,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 g.PBRMaterial?o=n.unlit:n instanceof g.StandardMaterial&&(o=n.disableLighting),o&&(r._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[Ze]={}),e(t)}))},e}();se.RegisterExtension(Ze,(function(){return new Je}));var $e="KHR_materials_volume",et=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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e;return T(this,(function(t){return e=[],n instanceof g.PBRMaterial&&this._isExtensionEnabled(n)?(n.subSurface.thicknessTexture&&e.push(n.subSurface.thicknessTexture),[2,e]):[2,e]}))}))},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!=g.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 g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var a=n.subSurface,i={thicknessFactor:0==a.maximumThickness?void 0:a.maximumThickness,thicknessTexture:null!==(o=r._exporter._materialExporter.getTextureInfo(a.thicknessTexture))&&void 0!==o?o:void 0,attenuationDistance:a.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:a.tintColorAtDistance,attenuationColor:a.tintColor.equalsFloats(1,1,1)?void 0:a.tintColor.asArray()};r._hasTexturesExtension(n)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions=t.extensions||{},t.extensions[$e]=i}e(t)}))},e}();se.RegisterExtension($e,(function(e){return new et(e)}));var tt="KHR_materials_diffuse_roughness",nt=function(){function e(e){this.name=tt,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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e;return T(this,(function(t){if(e=[],n instanceof g.PBRBaseMaterial){if(n._baseDiffuseRoughness)return n._baseDiffuseRoughnessTexture&&e.push(n._baseDiffuseRoughnessTexture),[2,e]}else if(n instanceof g.OpenPBRMaterial&&n.baseDiffuseRoughness)return n.baseDiffuseRoughnessTexture&&e.push(n.baseDiffuseRoughnessTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){var o=null,a=null;if(n instanceof g.PBRBaseMaterial?(o=n._baseDiffuseRoughness,a=n._baseDiffuseRoughnessTexture):n instanceof g.OpenPBRMaterial&&(o=n.baseDiffuseRoughness,a=n.baseDiffuseRoughnessTexture),o){r._wasUsed=!0,t.extensions=t.extensions||{};var i=r._exporter._materialExporter.getTextureInfo(a),s={diffuseRoughnessFactor:o,diffuseRoughnessTexture:null!=i?i:void 0};null!==s.diffuseRoughnessTexture&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[tt]=s,e(t)}else e(t)}))},e}();se.RegisterExtension(tt,(function(e){return new nt(e)}));var rt="KHR_texture_transform",ot=function(){function e(){this.name=rt,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()||g.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(n.name,"!")),0===n.uAng&&0===n.vAng||(g.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 g.Tools.Warn("".concat(e,": Texture ").concat(n.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(rt,"."));g.Tools.Warn("".concat(e,": Texture ").concat(n.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(rt,".")),r.offset=function(e){var t=e.uOffset,n=e.vOffset,r=e.uRotationCenter,o=e.vRotationCenter,a=e.uScale,i=e.vScale,s=e.wAng,u=Math.cos(s),c=Math.sin(s),l=r*a,f=o*i;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[rt]=r)}},e}();se.RegisterExtension(rt,(function(){return new ot}));var at="KHR_texture_basisu",it=function(){function e(e){this.name=at,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,g.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[at]={source:r},this._wasUsed=!0)}},e}();se.RegisterExtension(at,(function(e){return new it(e)}));var st="EXT_texture_webp",ut=function(){function e(e){this.name=st,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,g.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[st]={source:r},this._wasUsed=!0)}},e}();se.RegisterExtension(st,(function(e){return new ut(e)}));var ct="EXT_texture_avif",lt=function(){function e(e){this.name=ct,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,g.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[ct]={source:r},this._wasUsed=!0)}},e}();se.RegisterExtension(ct,(function(e){return new lt(e)}));var ft=function(){function e(){}return e.CreateSTL=function(e,t,n,r,o,a,i,s){void 0===t&&(t=!0),void 0===n&&(n="stlmesh"),void 0===r&&(r=!1),void 0===o&&(o=!0),void 0===a&&(a=!1),void 0===i&&(i=!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 g.Vector3(t[r[0]],t[r[0]+2],t[r[0]+1]),new g.Vector3(t[r[1]],t[r[1]+2],t[r[1]+1]),new g.Vector3(t[r[2]],t[r[2]+2],t[r[2]+1])],a=o[0].subtract(o[1]),i=o[2].subtract(o[1]);return{v:o,n:g.Vector3.Cross(i,a).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(i){var t=e;e instanceof g.InstancedMesh&&(t=e.sourceMesh);var n=t.getVerticesData(g.VertexBuffer.PositionKind,!0,!0);if(!n)return[];var r=g.Vector3.Zero(),o=void 0;for(o=0;o<n.length;o+=3)g.Vector3.TransformCoordinatesFromFloatsToRef(n[o],n[o+1],n[o+2],e.computeWorldMatrix(!0),r).toArray(n,o);return n}return e.getVerticesData(g.VertexBuffer.PositionKind)||[]};i&&(a=!0);var p="",h=0,d=0;if(r){for(var m=0;m<e.length;m++)h+=(y=(_=e[m]).getIndices())?y.length/3:0;var x=new ArrayBuffer(84+50*h);d+=80,(p=new DataView(x)).setUint32(d,h,o),d+=4}else s||(p="solid stlmesh\r\n");for(m=0;m<e.length;m++){var _=e[m];!r&&s&&(p+="solid "+_.name+"\r\n"),!a&&_ instanceof g.Mesh&&_.bakeCurrentTransformIntoVertices();for(var v=f(_),y=_.getIndices()||[],T=0;T<y.length;T+=3){var b=u(y,v,T);r?(d=c(p,d,b.n,o),d=c(p,d,b.v[0],o),d=c(p,d,b.v[1],o),d=c(p,d,b.v[2],o),d+=2):(p+="\tfacet normal "+b.n.x+" "+b.n.y+" "+b.n.z+"\r\n",p+="\t\touter loop\r\n",p+="\t\t\tvertex "+b.v[0].x+" "+b.v[0].y+" "+b.v[0].z+"\r\n",p+="\t\t\tvertex "+b.v[1].x+" "+b.v[1].y+" "+b.v[1].z+"\r\n",p+="\t\t\tvertex "+b.v[2].x+" "+b.v[2].y+" "+b.v[2].z+"\r\n",p+="\t\tendloop\r\n",p+="\tendfacet\r\n")}!r&&s&&(p+="endsolid "+name+"\r\n")}if(r||s||(p+="endsolid stlmesh"),t){var A=document.createElement("a"),M=new Blob([p],{type:"application/octet-stream"});A.href=window.URL.createObjectURL(M),A.download=n+".stl",A.click()}return p},e}();function pt(e,t,n,r){void 0===n&&(n=3),void 0===r&&(r=!1);for(var o=[],a=0;a<e.length/n;a++){var i=e[a*n]*(r?-1:1),s=e[a*n+1],u=e[a*n+2];o.push("(".concat(i.toPrecision(t.precision),", ").concat(s.toPrecision(t.precision),", ").concat(u.toPrecision(t.precision),")"))}return o.join(", ")}function ht(e,t){for(var n=[],r=0;r<e.length/2;r++){var o=e[2*r],a=e[2*r+1];n.push("(".concat(o.toPrecision(t.precision),", ").concat((1-a).toPrecision(t.precision),")"))}return n.join(", ")}function dt(e,t,n,r){var o=function(e,t,n,r){var o=e.getVerticesData(g.VertexBuffer.PositionKind),a=e.getVerticesData(g.VertexBuffer.NormalKind);if(o&&a)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 a=0;a<r;a++)o.push(n[a]);else for(a=0;a<r;a++)o.push(a);return o.join(", ")}(e),"]\n\t\tnormal3f[] normals = [").concat(pt(a,t,void 0,r),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)\n\t\tpoint3f[] points = [').concat(pt(o,t,void 0,r),"]\n ").concat(function(e,t){for(var n="",r=0;r<4;r++){var o=r>0?r:"",a=e.getVerticesData(g.VertexBuffer.UVKind+(o?o+1:""));a&&(n+="\n\t\ttexCoord2f[] primvars:st".concat(o," = [").concat(ht(a,t),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)'))}var i=e.getVerticesData(g.VertexBuffer.ColorKind);return i&&(n+="\n\tcolor3f[] primvars:displayColor = [".concat(pt(i,t,i.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 gt(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 mt(e){var t=e.m;return"( ".concat(xt(t,0),", ").concat(xt(t,4),", ").concat(xt(t,8),", ").concat(xt(t,12)," )")}function xt(e,t){return"(".concat(e[t+0],", ").concat(e[t+1],", ").concat(e[t+2],", ").concat(e[t+3],")")}function _t(e,t){var n="Object_"+e.uniqueId,r=mt(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 vt(e){switch(e){case g.Constants.TEXTURE_CLAMP_ADDRESSMODE:return"clamp";case g.Constants.TEXTURE_MIRROR_ADDRESSMODE:return"mirror";case g.Constants.TEXTURE_WRAP_ADDRESSMODE:default:return"repeat"}}function yt(e){return"(".concat(e.x,", ").concat(e.y,")")}function Tt(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,")")}function bt(e,t,n,r,o,a){var i=e.getInternalTexture().uniqueId+"_"+e.invertY;o[i]=e;var s=e.coordinatesIndex>0?"st"+e.coordinatesIndex:"st",u=new g.Vector2(e.uScale,e.vScale),c=new g.Vector2(e.uOffset,e.vOffset),l=e.wAng,f=Math.sin(l),p=Math.cos(l);return c.y=1-c.y-u.y,c.x+=f*u.x,c.y+=(1-p)*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(a.precision),"\n float2 inputs:scale = ").concat(yt(u),"\n float2 inputs:translation = ").concat(yt(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(i,".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(vt(e.wrapU),'"\n token inputs:wrapT = "').concat(vt(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 At(e,t,n){var r="\t\t\t",o=[],a=[],i=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 g.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 g.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=i.diffuseMap,u=i.diffuse,c=i.alphaCutOff,l=i.emissiveMap,f=i.emissive,p=i.normalMap,h=i.roughnessMap,d=i.roughnessChannel,m=i.roughness,x=i.metalnessMap,_=i.metalnessChannel,y=i.metalness,T=i.aoMap,b=i.aoMapChannel,A=i.aoMapIntensity,M=i.alphaMap,w=i.ior,E=i.clearCoatEnabled,R=i.clearCoat,C=i.clearCoatMap,S=i.clearCoatRoughness,V=i.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))),a.push(bt(s,e,"diffuse",u,t,n))):o.push("".concat(r,"color3f inputs:diffuseColor = ").concat(Tt(u||g.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>")),a.push(bt(l,e,"emissive",f,t,n))):f&&f.toLuminance()>0&&o.push("".concat(r,"color3f inputs:emissiveColor = ").concat(Tt(f))),null!==p&&(o.push("".concat(r,"normal3f inputs:normal.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(p.uniqueId,"_normal.outputs:rgb>")),a.push(bt(p,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,">")),a.push(bt(T,e,"occlusion",new g.Color3(A,A,A),t,n))),null!==h?(o.push("".concat(r,"float inputs:roughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(h.uniqueId,"_roughness.outputs:").concat(d,">")),a.push(bt(h,e,"roughness",new g.Color3(m,m,m),t,n))):o.push("".concat(r,"float inputs:roughness = ").concat(m)),null!==x?(o.push("".concat(r,"float inputs:metallic.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(x.uniqueId,"_metallic.outputs:").concat(_,">")),a.push(bt(x,e,"metallic",new g.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")),a.push(bt(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>")),a.push(bt(C,e,"clearcoat",new g.Color3(R,R,R),t,n))):o.push("".concat(r,"float inputs:clearcoat = ").concat(R)),null!==V?(o.push("".concat(r,"float inputs:clearcoatRoughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(V.uniqueId,"_clearcoatRoughness.outputs:g>")),a.push(bt(V,e,"clearcoatRoughness",new g.Color3(S,S,S),t,n))):o.push("".concat(r,"float inputs:clearcoatRoughness = ").concat(S))),o.push("".concat(r,"float inputs:ior = ").concat(w)),'\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(a.join("\n"),"\n\n\t}\n")}function Mt(e){var t,n;e.computeWorldMatrix(!0);for(var r=e.getWorldMatrix().clone(),o=e.getScene().useRightHandedSystem,a=null!==(n=null===(t=e.material)||void 0===t?void 0:t._getEffectiveOrientation(e))&&void 0!==n?n:e.sideOrientation,i=!o,s=e.parent;s;){if(U(s,o)&&null===s.parent){o||(r.multiplyToRef(s.getWorldMatrix().invert(),r),a=a===g.Material.ClockWiseSideOrientation?g.Material.CounterClockWiseSideOrientation:g.Material.ClockWiseSideOrientation),i=!1;break}s=s.parent}return r.determinant()<0&&g.Tools.Warn("Mesh ".concat(e.name," has a negative scale, which may look incorrect in destinations like QuickLook.")),{matrix:r,windingOrder:a===g.Material.ClockWiseSideOrientation?"leftHanded":"rightHanded",convertToRightHanded:i}}function wt(e,t,n){return y(this,void 0,void 0,(function(){var r,o,a,i,s,u,c,l,f,p,h,d,m,x,_,y,b,A,M,w,E,R,C,S,V,I,B,F,O,P,U,N;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,g.Tools.LoadScriptAsync(r.fflateUrl)];case 1:T.sent(),T.label=2;case 2:for((o={})[r.modelFileName]=null,a='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )',a+=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),i={},s=0,u=e.meshes;s<u.length;s++)0!==(c=u[s]).getTotalVertices()&&(f=(l=c).geometry,(p=l.material)&&f&&(!n||n(l))&&(-1!==["StandardMaterial","PBRMaterial","PBRMetallicRoughnessMaterial"].indexOf(p.getClassName())?(h="geometries/Geometry_"+f.uniqueId+".usda",d=Mt(l),m=d.matrix,x=d.windingOrder,_=d.convertToRightHanded,h in o||(y=dt(f,r,x,_),o[h]=gt(y)),p.uniqueId in i||(i[p.uniqueId]=p),a+=_t(l,m)):g.Tools.Warn("USDZExportAsync does not support this material type: "+p.getClassName())));for(w in e.activeCamera&&r.exportCamera&&(a+=function(e,t){var n="Camera_"+e.uniqueId,r=mt(g.Matrix.RotationY(Math.PI).multiply(e.getWorldMatrix()));if(e.mode===g.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),a=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((a/(2*Math.tan(.5*e.fov))).toPrecision(t.precision),'\n token projection = "perspective"\n\t\t\tfloat horizontalAperture = ').concat((a*o).toPrecision(t.precision),"\n\t\t\tfloat verticalAperture = ").concat((a/o).toPrecision(t.precision)," \n\t\t}\n\t\n\t")}(e.activeCamera,r)),a+="\n }\n }",a+=function(e,t,n){var r=[];for(var o in e){var a=e[o];r.push(At(a,t,n))}return'\n def "Materials"\n{\n'.concat(r.join(""),"\n}\n\n")}(i,b={},r),a+="\n }",o[r.modelFileName]=fflate.strToU8(a),M=[],A=b)M.push(w);E=0,T.label=3;case 3:return E<M.length?(w=M[E])in A?(C=b[R=w],S=C.getSize(),[4,(0,g.GetTextureDataAsync)(C)]):[3,6]:[3,7];case 4:return V=T.sent(),[4,g.DumpTools.DumpDataAsync(S.width,S.height,V,"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!=(U=63&(B+=P))&&(N=new Uint8Array(64-U),o[F]=[O,{extra:{12345:N}}]),B=O.length);return[2,fflate.zipSync(o,{level:0})]}}))}))}var Et=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 a=null,i=0,s=o;i<s.length;i++){var u=s[i],c=e.getAnimationRange(u);c&&(a=a?new g.AnimationRange("animation-range",Math.min(a.from,c.from),Math.max(a.to,c.to)):c)}if(!a&&(e.animations.length>0&&(a=e.getAnimationRange(e.animations[0].name)),!a))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),p=0,h=0,d=f;h<d.length;h++){var m=d[h];m.positionKeys.length>0&&(p=Math.max(p,m.positionKeys.length)),m.rotationKeys.length>0&&(p=Math.max(p,m.rotationKeys.length))}0===p&&(p=Math.floor((a.to-a.from)/l)+1);var x="";return x+="HIERARCHY\n",x+=this._ExportHierarchy(f,0),x+="MOTION\n",x+="Frames: ".concat(p,"\n"),(x+="Frame Time: ".concat(l.toFixed(6),"\n"))+this._ExportMotionData(f,p,0,o)},e._BuildBoneHierarchy=function(e,t){for(var n,r,o=new Map,a=[],i=0,s=e.bones;i<s.length;i++){var u={bone:f=s[i],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 p=0,h=f.animations;p<h.length;p++){var d=h[p];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 g=o.get(f.getParent());g&&g.children.push(u)}else a.push(u)}return a},e._ExportHierarchy=function(e,t){for(var n="",r=" ".repeat(t),o=0,a=e;o<a.length;o++){var i=a[o],s=i.bone;if(this._IsEndSite(i)){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=[];i.hasPositionChannels&&c.push("Xposition","Yposition","Zposition"),i.hasRotationChannels&&c.push("Zrotation","Xrotation","Yrotation"),c.length>0&&(n+="".concat(r," CHANNELS ").concat(c.length," ").concat(c.join(" "),"\n")),i.children.length>0&&(n+=this._ExportHierarchy(i.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 g.Vector3.Zero()}},e._ExportMotionData=function(e,t,n,r){for(var o="",a=0;a<t;a++){var i=[];this._CollectFrameValues(e,a+n,i,r),o+=i.map((function(e){return e.toFixed(6)})).join(" ")+"\n"}return o},e._CollectFrameValues=function(e,t,n,r){for(var o=0,a=e;o<a.length;o++){var i=a[o];if(!this._IsEndSite(i)){if(i.hasPositionChannels){var s=this._GetPositionAtFrameIndex(i.positionKeys,t);n.push(s.x,s.y,s.z)}if(i.hasRotationChannels){var u=this._GetRotationAtFrameIndex(i.rotationKeys,t),c=this._QuaternionToEuler(u);n.push(c.z,c.x,c.y)}i.children.length>0&&this._CollectFrameValues(i.children,t,n,r)}}},e._GetPositionAtFrameIndex=function(e,t){return 0===e.length?g.Vector3.Zero():e[Math.max(0,Math.min(t,e.length-1))].value.clone()},e._GetRotationAtFrameIndex=function(e,t){return 0===e.length?g.Quaternion.Identity():e[Math.max(0,Math.min(t,e.length-1))].value.clone()},e._QuaternionToEuler=function(e){var t=new g.Matrix;e.toRotationMatrix(t);var n,r,o,a=t.m,i=Math.sqrt(a[0]*a[0]+a[1]*a[1]);return i>g.Epsilon?(n=Math.atan2(a[6],a[10]),r=Math.atan2(-a[2],i),o=Math.atan2(a[1],a[0])):(n=Math.atan2(-a[9],a[5]),r=Math.atan2(-a[2],i),o=0),new g.Vector3(g.Tools.ToDegrees(n),g.Tools.ToDegrees(r),g.Tools.ToDegrees(o))},e}(),Rt=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Rt)for(var Ct in h)Rt.BABYLON[Ct]=h[Ct];var St=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==St){St.BABYLON=St.BABYLON||{};var Vt=St.BABYLON;Vt.GLTF2=Vt.GLTF2||{},Vt.GLTF2.Exporter=Vt.GLTF2.Exporter||{},Vt.GLTF2.Exporter.Extensions=Vt.GLTF2.Exporter.Extensions||{};var It=[];for(var Bt in i)Vt[Bt]=i[Bt],It.push(Bt);for(var Bt in s)Vt[Bt]=s[Bt],It.push(Bt);for(var Bt in u)Vt[Bt]=u[Bt],It.push(Bt);for(var Bt in c)Vt.GLTF2.Exporter.Extensions[Bt]=c[Bt],It.push(Bt);for(var Bt in l)It.indexOf(Bt)>-1||(Vt.GLTF2.Exporter[Bt]=l[Bt])}var Ft=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Ft)for(var Ot in a)Ft.BABYLON[Ot]=a[Ot];var Pt=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Pt)for(var Ut in f)Pt.BABYLON[Ut]=f[Ut];var Nt=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Nt)for(var Lt in p)Nt.BABYLON[Lt]=p[Lt];const Dt=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 a=n[e]={exports:{}};return t[e](a,a.exports,r),a.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:()=>Dt});var a={};r.r(a),r.d(a,{OBJExport:()=>m});var i={};r.r(i),r.d(i,{__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_mesh_gpu_instancing:()=>le,EXT_texture_avif:()=>lt,EXT_texture_webp:()=>ut,KHR_draco_mesh_compression:()=>pe,KHR_lights_punctual:()=>xe,KHR_materials_anisotropy:()=>Te,KHR_materials_clearcoat:()=>Ae,KHR_materials_clearcoat_anisotropy:()=>Fe,KHR_materials_clearcoat_color:()=>Se,KHR_materials_clearcoat_darkening:()=>we,KHR_materials_clearcoat_ior:()=>Re,KHR_materials_diffuse_roughness:()=>nt,KHR_materials_diffuse_transmission:()=>Ue,KHR_materials_dispersion:()=>Le,KHR_materials_emissive_strength:()=>Ke,KHR_materials_ior:()=>He,KHR_materials_iridescence:()=>We,KHR_materials_sheen:()=>ze,KHR_materials_specular:()=>Xe,KHR_materials_transmission:()=>Qe,KHR_materials_unlit:()=>Je,KHR_materials_volume:()=>et,KHR_texture_basisu:()=>it,KHR_texture_transform:()=>ot});var l={};r.r(l),r.d(l,{EXT_mesh_gpu_instancing:()=>le,EXT_texture_avif:()=>lt,EXT_texture_webp:()=>ut,GLTF2Export:()=>ue,GLTFData:()=>_,KHR_draco_mesh_compression:()=>pe,KHR_lights_punctual:()=>xe,KHR_materials_anisotropy:()=>Te,KHR_materials_clearcoat:()=>Ae,KHR_materials_clearcoat_anisotropy:()=>Fe,KHR_materials_clearcoat_color:()=>Se,KHR_materials_clearcoat_darkening:()=>we,KHR_materials_clearcoat_ior:()=>Re,KHR_materials_diffuse_roughness:()=>nt,KHR_materials_diffuse_transmission:()=>Ue,KHR_materials_dispersion:()=>Le,KHR_materials_emissive_strength:()=>Ke,KHR_materials_ior:()=>He,KHR_materials_iridescence:()=>We,KHR_materials_sheen:()=>ze,KHR_materials_specular:()=>Xe,KHR_materials_transmission:()=>Qe,KHR_materials_unlit:()=>Je,KHR_materials_volume:()=>et,KHR_texture_basisu:()=>it,KHR_texture_transform:()=>ot,_ConvertToGLTFPBRMetallicRoughness:()=>V,_SolveMetallic:()=>S});var f={};r.r(f),r.d(f,{STLExport:()=>ft});var p={};r.r(p),r.d(p,{USDZExportAsync:()=>wt});var h={};r.r(h),r.d(h,{BVHExporter:()=>Et});var d={};r.r(d),r.d(d,{BVHExporter:()=>Et,EXT_mesh_gpu_instancing:()=>le,EXT_texture_avif:()=>lt,EXT_texture_webp:()=>ut,GLTF2Export:()=>ue,GLTFData:()=>_,KHR_draco_mesh_compression:()=>pe,KHR_lights_punctual:()=>xe,KHR_materials_anisotropy:()=>Te,KHR_materials_clearcoat:()=>Ae,KHR_materials_clearcoat_anisotropy:()=>Fe,KHR_materials_clearcoat_color:()=>Se,KHR_materials_clearcoat_darkening:()=>we,KHR_materials_clearcoat_ior:()=>Re,KHR_materials_diffuse_roughness:()=>nt,KHR_materials_diffuse_transmission:()=>Ue,KHR_materials_dispersion:()=>Le,KHR_materials_emissive_strength:()=>Ke,KHR_materials_ior:()=>He,KHR_materials_iridescence:()=>We,KHR_materials_sheen:()=>ze,KHR_materials_specular:()=>Xe,KHR_materials_transmission:()=>Qe,KHR_materials_unlit:()=>Je,KHR_materials_volume:()=>et,KHR_texture_basisu:()=>it,KHR_texture_transform:()=>ot,OBJExport:()=>m,STLExport:()=>ft,USDZExportAsync:()=>wt,_ConvertToGLTFPBRMetallicRoughness:()=>V,_SolveMetallic:()=>S,__IGLTFExporterExtension:()=>x});var g=r(597),m=function(){function e(){}return e.OBJ=function(e,t,n,r){var o=[],a=1,i=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 g.Matrix,f.invertToRef(l),u.bakeTransformIntoVertices(f)}if(t){var p=u.material;p&&o.push("usemtl "+p.id)}var h=u.geometry;if(h){var d=h.getVerticesData("position"),m=h.getVerticesData("normal"),x=h.getVerticesData("uv"),_=h.getIndices(),v=0,y=0;if(d&&_){for(var T=e[0].getScene().useRightHandedSystem?1:-1,b=0;b<d.length;b+=3)o.push("v "+d[b]*T+" "+d[b+1]+" "+d[b+2]),v++;if(null!=m)for(b=0;b<m.length;b+=3)o.push("vn "+m[b]*T+" "+m[b+1]+" "+m[b+2]);if(null!=x)for(b=0;b<x.length;b+=2)o.push("vt "+x[b]+" "+x[b+1]),y++;var A=["","",""],M=(u.material||u.getScene().defaultMaterial)._getEffectiveOrientation(u)===g.Material.ClockWiseSideOrientation?[2,1]:[1,2],w=M[0],E=M[1];for(b=0;b<_.length;b+=3){var R=[String(_[b]+a),String(_[b+w]+a),String(_[b+E]+a)],C=[String(_[b]+i),String(_[b+w]+i),String(_[b+E]+i)],S=R,V=null!=x?C:A,I=null!=m?R:A;o.push("f "+S[0]+"/"+V[0]+"/"+I[0]+" "+S[1]+"/"+V[1]+"/"+I[1]+" "+S[2]+"/"+V[2]+"/"+I[2])}r&&l&&u.bakeTransformIntoVertices(l),a+=v,i+=y}else g.Tools.Warn("There are no position vertices or indices on the mesh!")}else g.Tools.Warn("No geometry is present on the mesh")}return o.join("\n")},e.MTL=function(e){var t=[],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,g.GetMimeType)(e)});g.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,a){function i(e){try{u(r.next(e))}catch(e){a(e)}}function s(e){try{u(r.throw(e))}catch(e){a(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(i,s)}u((r=r.apply(e,t||[])).next())}))}function T(e,t){var n,r,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=s(0),i.throw=s(1),i.return=s(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)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 a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],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,a=t.length;o<a;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 A=1e-6,M=new g.Color3(.04,.04,.04),w=1024,E=g.Color3.White(),R=g.Color3.BlackReadOnly;function C(e){return y(this,void 0,void 0,(function(){var t,n,r,o;return T(this,(function(a){switch(a.label){case 0:return(t=e.getInternalTexture())&&1===t.source?t.invertY?[2,null]:(n=t._buffer,o=e.mimeType,n?[3,2]:[4,g.Tools.LoadFileAsync(t.url)]):[2,null];case 1:return r=a.sent(),o=(0,g.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=a.sent(),o=n.type||o,[3,10];case 6:return"string"!=typeof n?[3,8]:[4,g.Tools.LoadFileAsync(n)];case 7:return r=a.sent(),o=(0,g.GetMimeType)(n)||o,[3,10];case 8:return"undefined"!=typeof HTMLImageElement&&n instanceof HTMLImageElement?[4,g.Tools.LoadFileAsync(n.src)]:[3,10];case 9:r=a.sent(),o=(0,g.GetMimeType)(n.src)||o,a.label=10;case 10:return r&&o?[2,{data:r,mimeType:o}]:[2,null]}}))}))}function S(e,t,n){if(t<M.r)return 0;var r=M.r,o=e*n/(1-M.r)+t-2*M.r,a=o*o-4*r*(M.r-t);return g.Scalar.Clamp((-o+Math.sqrt(a))/(2*r),0,1)}function V(e){var t=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),n=e.alpha,r=g.Scalar.Clamp(e.specularPower,0,w),o=(0,g.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 g.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,a,i,s,u,c;return T(this,(function(l){switch(l.label){case 0:return n=V(e),r={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||g.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),t?(o=[],(a=e.diffuseTexture)&&o.push(this.exportTextureAsync(a).then((function(e){e&&(n.baseColorTexture=e)}))),(i=e.bumpTexture)&&o.push(this.exportTextureAsync(i).then((function(e){e&&(r.normalTexture=e,1!==i.level&&(r.normalTexture.scale=i.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===g.Constants.ALPHA_COMBINE?r.alphaMode="BLEND":g.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(R,A)&&(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,a,i;return T(this,(function(s){switch(s.label){case 0:return[4,this._exporter._extensionsPostExportMaterialAdditionalTexturesAsync("exportMaterial",e,t)];case 1:for(n=s.sent(),r=[],o=0,a=n;o<a.length;o++)i=a[o],r.push(this.exportTextureAsync(i));return[4,Promise.all(r)];case 2:return s.sent(),[4,this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)];case 3: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,g.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,a=e?e.getSize():{width:0,height:0},i=t?t.getSize():{width:0,height:0};return a.width<i.width?(r=e&&e instanceof g.Texture?g.TextureTools.CreateResizedCopy(e,i.width,i.height,!0):B(i.width,i.height,n),o=t):a.width>i.width?(o=t&&t instanceof g.Texture?g.TextureTools.CreateResizedCopy(t,a.width,a.height,!0):B(a.width,a.height,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,a,i,s,u,c,l,f,p,h,d,m,x,_,v,y,b,M,w,R,C,S,V,I,B,O,P,U,N,L,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(a=e?e.getScene():t?t.getScene():null)?(i=this._resizeTexturesToSameDimensions(e,t,a),s=null===(D=i.texture1)||void 0===D?void 0:D.getSize(),u=void 0,c=void 0,l=s.width,f=s.height,[4,i.texture1.readPixels()]):[3,12];case 3:return p=T.sent(),[4,i.texture2.readPixels()];case 4:return h=T.sent(),p?(u=F(p),[3,7]):[3,5];case 5:return[4,Promise.reject("Failed to retrieve pixels from diffuse texture!")];case 7:return h?(c=F(h),[3,10]):[3,8];case 8:return[4,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];case 10:for(d=c.byteLength,m=new Uint8Array(d),x=new Uint8Array(d),_=new g.Color3(0,0,0),v=0,y=0,O=0;O<f;++O)for(P=0;P<l;++P)b=4*(l*O+P),M=new g.Color3(u[b],u[b+1],u[b+2]).toLinearSpace(a.getEngine().useExactSrgbConversions).multiply(n.diffuseColor),w=new g.Color3(c[b],c[b+1],c[b+2]).toLinearSpace(a.getEngine().useExactSrgbConversions).multiply(n.specularColor),R=c[b+3]*n.glossiness,C={diffuseColor:M,specularColor:w,glossiness:R},S=this._convertSpecularGlossinessToMetallicRoughness(C),_.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]=i.texture1.hasAlpha?255*u[b+3]:255,m[b]=0,m[b+1]=255*S.roughness,m[b+2]=255*S.metallic,m[b+3]=255;for(V={baseColor:_,metallic:v,roughness:y},I=!1,B=!1,O=0;O<f;++O)for(P=0;P<l;++P)x[U=4*(l*O+P)]/=V.baseColor.r>A?V.baseColor.r:1,x[U+1]/=V.baseColor.g>A?V.baseColor.g:1,x[U+2]/=V.baseColor.b>A?V.baseColor.b:1,N=g.Color3.FromInts(x[U],x[U+1],x[U+2]),L=N.toGammaSpace(a.getEngine().useExactSrgbConversions),x[U]=255*L.r,x[U+1]=255*L.g,x[U+2]=255*L.b,L.equalsWithEpsilon(E,A)||(B=!0),m[U+1]/=V.roughness>A?V.roughness:1,m[U+2]/=V.metallic>A?V.metallic:1,g.Color3.FromInts(255,m[U+1],m[U+2]).equalsWithEpsilon(E,A)||(I=!0);return I&&o.push(this._getImageDataAsync(m,l,f,r).then((function(e){V.metallicRoughnessTextureData=e}))),B&&o.push(this._getImageDataAsync(x,l,f,r).then((function(e){V.baseColorTextureData=e}))),[4,Promise.all(o).then((function(){return V}))];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=S(t,n,r),a=e.diffuseColor.scale(r/(1-M.r)/Math.max(1-o,A)),i=e.specularColor.subtract(M.scale(1-o)).scale(1/Math.max(o,A)),s=g.Color3.Lerp(a,i,o*o);return{baseColor:s=s.clampToRef(0,1,s),metallic:o,roughness:1-e.glossiness}},e.prototype._getPerceivedBrightness=function(e){return Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b)},e.prototype._getMaxComponent=function(e){return Math.max(e.r,Math.max(e.g,e.b))},e.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,n,r,o,a,i,s,u){return y(this,void 0,void 0,(function(){var a,c;return T(this,(function(l){switch(l.label){case 0:return a=[],c={baseColor:e,metallic:t,roughness:n},u&&(r&&a.push(this.exportTextureAsync(r).then((function(e){e&&(s.baseColorTexture=e)}))),o&&a.push(this.exportTextureAsync(o).then((function(e){e&&(s.metallicRoughnessTexture=e)})))),a.length>0?(this._exporter._materialNeedsUVsSet.add(i),[4,Promise.all(a)]):[3,2];case 1:l.sent(),l.label=2;case 2:return[2,c]}}))}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof g.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 g.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case g.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case g.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case g.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case g.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case g.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case g.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case g.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case g.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case g.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case g.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case g.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case g.Texture.WRAP_ADDRESSMODE:return 10497;case g.Texture.CLAMP_ADDRESSMODE:return 33071;case g.Texture.MIRROR_ADDRESSMODE:return 33648;default:return g.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var r,o,a,i,s,u,c,l,f;return T(this,(function(p){switch(p.label){case 0:return r="image/png",o={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},a=e._albedoTexture,i=e._reflectivityTexture,s=e._useMicroSurfaceFromReflectivityMapAlpha,!i||s?[3,2]:[4,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")];case 1:return[2,p.sent()];case 2:return(a||i)&&n?(this._exporter._materialNeedsUVsSet.add(e),u=this._exportTextureSampler(a||i),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(a,i,o,r)]):[3,4];case 3:return c=p.sent(),l=this._exporter._textures,c.baseColorTextureData&&(f=this._exportImage("baseColor".concat(l.length),r,c.baseColorTextureData),t.baseColorTexture=this._exportTextureInfo(f,u,null==a?void 0:a.coordinatesIndex)),c.metallicRoughnessTextureData&&(f=this._exportImage("metallicRoughness".concat(l.length),r,c.metallicRoughnessTextureData),t.metallicRoughnessTexture=this._exportTextureInfo(f,u,null==i?void 0:i.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,a,i,s,u,c;return T(this,(function(l){switch(l.label){case 0:return n={},r={name:e.name},(o=e.isMetallicWorkflow())&&(a=e._albedoColor,i=e.alpha,a&&(n.baseColorFactor=[a.r,a.g,a.b,i])),o?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e._albedoColor,e._metallic,e._roughness,e._albedoTexture,e._metallicTexture,e._metallicTexture,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 a,i,s,u,c;return T(this,(function(l){switch(l.label){case 0:return I(n,t),e.baseColor.equalsWithEpsilon(E,A)&&g.Scalar.WithinEpsilon(t.alpha,1,A)||(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||g.Tools.Warn(t.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),o?(a=[],(i=t instanceof g.PBRBaseMaterial?t._bumpTexture:t.geometryNormalTexture)&&a.push(this.exportTextureAsync(i).then((function(e){e&&(n.normalTexture=e,1!==i.level&&(n.normalTexture.scale=i.level))}))),(s=t instanceof g.PBRBaseMaterial?t._ambientTexture:t.ambientOcclusionTexture)&&a.push(this.exportTextureAsync(s).then((function(e){if(e){var r={index:e.index,texCoord:e.texCoord,extensions:e.extensions};n.occlusionTexture=r,t instanceof g.PBRBaseMaterial?r.strength=t._ambientTextureStrength:r.strength=t.ambientOcclusionTexture.level}}))),(u=t instanceof g.PBRBaseMaterial?t._emissiveTexture:t.emissionColorTexture)&&a.push(this.exportTextureAsync(u).then((function(e){e&&(n.emissiveTexture=e)}))),a.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(a)]):[3,2]):[3,2];case 1:l.sent(),l.label=2;case 2:return(c=t instanceof g.PBRBaseMaterial?t._emissiveColor:t.emissionColor).equalsWithEpsilon(R,A)||(n.emissiveFactor=c.asArray()),n.pbrMetallicRoughness=r,[2]}}))}))},e.prototype.exportOpenPBRMaterialAsync=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,a,i,s;return T(this,(function(u){switch(u.label){case 0:return n={},r={name:e.name},o=e.baseColor,a=e.geometryOpacity,o&&(n.baseColorFactor=[o.r,o.g,o.b,a]),[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e.baseColor,e.baseMetalness,e.specularRoughness,e.baseColorTexture,e.baseMetalnessTexture,e.specularRoughnessTexture,e,n,t)];case 1:return i=u.sent(),[4,this._setMetallicRoughnessPbrMaterialAsync(i,e,r,n,t)];case 2:return u.sent(),[4,this._finishMaterialAsync(r,e)];case 3:return u.sent(),(s=this._exporter._materials).push(r),[2,s.length-1]}}))}))},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,a,i=this;return T(this,(function(s){switch(s.label){case 0:return t=null!==(a=e.mimeType)&&void 0!==a?a:"none",n=this._internalTextureToImage,r=e.getInternalTexture().uniqueId,n[r]=n[r]||{},void 0===(o=n[r][t])&&(o=y(i,void 0,void 0,(function(){var n,r,o,a,i;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:g.Tools.Warn("Unsupported media type: ".concat(t,". Exporting texture as PNG."))}return o=e.getSize(),[4,(0,g.GetTextureDataAsync)(e)];case 2:return a=s.sent(),[4,this._getImageDataAsync(a,o.width,o.height,r)];case 3:return i=s.sent(),[2,this._exportImage(e.name,r,i)]}}))})),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 a=this._exporter._bufferManager.createBufferView(new Uint8Array(n));this._exporter._bufferManager.setBufferView(r,a)}else{var i=e.replace(/\.\/|\/|\.\\|\\/g,"_"),s=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp";case"image/avif":return".avif";case"image/ktx2":return".ktx2"}}(t),u=i+s;o.some((function(e){return e.uri===u}))&&(u="".concat(i,"_").concat(g.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 a={index:o};return n&&(a.texCoord=n),a},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=g.Matrix.Compose(new g.Vector3(-1,1,1),g.Quaternion.Identity(),g.Vector3.Zero());function U(e,t){if(!(e instanceof g.TransformNode))return!1;if(t){if(!e.getWorldMatrix().equalsWithEpsilon(g.Matrix.IdentityReadOnly,g.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(P,g.TmpVectors.Matrix[0]).equalsWithEpsilon(g.Matrix.IdentityReadOnly,g.Epsilon))return!1;return!(e instanceof g.AbstractMesh&&e.geometry)}var N=g.Vector3.ZeroReadOnly,L=g.Quaternion.Identity(),D=g.Vector3.OneReadOnly,K=new g.Vector3(-1,1,1);function k(e,t){var n=e.byteOffset,r=e.byteStride,o=e.type,a=e.normalized,i=e.getSize(),s=t.reduce((function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e}),-Number.MAX_VALUE);return{byteOffset:n,byteStride:r,componentCount:i,type:o,count:s*i,normalized:a,totalVertices:s,kind:e.getKind()}}function H(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 G(e){switch(e){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:case g.VertexBuffer.ColorKind:case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:case g.VertexBuffer.MatricesWeightsKind:case g.VertexBuffer.MatricesWeightsExtraKind:case g.VertexBuffer.UVKind:case g.VertexBuffer.UV2Kind:case g.VertexBuffer.UV3Kind:case g.VertexBuffer.UV4Kind:case g.VertexBuffer.UV5Kind:case g.VertexBuffer.UV6Kind:return!0}return!1}function W(e){switch(e){case g.Material.TriangleFillMode:return 4;case g.Material.TriangleStripDrawMode:return 5;case g.Material.TriangleFanDrawMode:return 6;case g.Material.PointListDrawMode:case g.Material.PointFillMode:return 0;case g.Material.LineLoopDrawMode:return 2;case g.Material.LineListDrawMode:return 1;case g.Material.LineStripDrawMode:return 3}throw new Error("Unknown fill mode: ".concat(e))}function 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 z(e){return e.x*=-1,e}function j(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),a=Math.abs(e.w);o>a?(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=a)}return e}function X(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function Y(e,t){var n=g.Vector3.FromArrayToRef(t.translation||[0,0,0],0,g.TmpVectors.Vector3[0]),r=g.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,g.TmpVectors.Quaternion[0]),o=g.Matrix.ComposeToRef(D,r,n,g.TmpVectors.Matrix[0]),a=g.Vector3.FromArrayToRef(e.translation||[0,0,0],0,g.TmpVectors.Vector3[2]),i=g.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,g.TmpVectors.Quaternion[1]),s=g.Matrix.ComposeToRef(D,i,a,g.TmpVectors.Matrix[1]);o.multiplyToRef(s,s),s.decompose(void 0,r,n),n.equalsWithEpsilon(N,g.Epsilon)?delete t.translation:t.translation=n.asArray(),r.equalsWithEpsilon(L,g.Epsilon)?delete t.rotation:t.rotation=r.asArray(),t.scale&&delete t.scale}function Q(e,t){if(!(t instanceof g.TransformNode))return!1;if(1!==t.getChildren().length||0!==e.getChildren().length||e.parent!==t)return!1;var n=e.getScene(),r=e instanceof g.TargetCamera&&!n.useRightHandedSystem?K:D;return!!t.scaling.equalsWithEpsilon(r,g.Epsilon)||(g.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],a=o[0],i=o[1],s=t[a];(Array.isArray(i)&&Array.isArray(s)&&J(i,s)||i===s)&&delete e[a]}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 a=o[r];a.byteOffset=n.byteOffset,e.push(a);for(var i=e.length-1,s=0,u=this.getPropertiesWithBufferView(a);s<u.length;s++)u[s].bufferView=i;n.writeTypedArray(this._bufferViewToData.get(a)),this._bufferViewToData.delete(a)}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,a,i){this._verifyBufferView(e);var s={bufferView:void 0,componentType:n,count:r,type:t,min:null==a?void 0:a.min,max:null==a?void 0:a.max,normalized:i,byteOffset:o};return this.setBufferView(s,e),this._accessorToBufferView.set(s,e),s},e.prototype.setBufferView=function(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)},e.prototype.removeBufferView=function(e){for(var t=this,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 g.TransformNode||e instanceof g.Camera||e instanceof g.Light)},e._CreateNodeAnimation=function(t,n,r,o,a){if(this._IsTransformable(t)){var i=[],s=[],u=n.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,r,o),f=l.interpolationType,p=l.shouldBakeAnimation;if(p?e._CreateBakedAnimation(t,n,r,c.min,c.max,n.framePerSecond,a,i,s,c,o):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(t,n,r,i,s,o):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(t,n,r,i,s,o):e._CreateBakedAnimation(t,n,r,c.min,c.max,n.framePerSecond,a,i,s,c,o),i.length&&s.length)return{inputs:i,outputs:s,samplerInterpolation:f,inputsMin:p?c.min:g.Tools.FloatRound(c.min/n.framePerSecond),inputsMax:p?c.max:g.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:g.Tools.Error("Unsupported animatable property ".concat(o[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:n,useQuaternion:r}:(g.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,n,r,o,a,i,s,u,c,l,f){var p;if(e._IsTransformable(t)&&t.animations)for(var h=0,d=t.animations;h<d.length;h++){var g=d[h];if(!f||f(g)){var m=e._DeduceAnimationInfo(g);m&&(p={name:g.name,samplers:[],channels:[]},e._AddAnimation("".concat(g.name),g.hasRunningRuntimeAnimations?n:p,t,g,m.dataAccessorType,m.animationChannelTargetPath,o,i,s,u,m.useQuaternion,c,l),p.samplers.length&&p.channels.length&&r.push(p))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,n,r,o,a,i,s,u,c,l,f){var p;if(t instanceof g.Mesh){var h=t.morphTargetManager;if(h)for(var d=0;d<h.numTargets;++d)for(var m=0,x=h.getTarget(d).animations;m<x.length;m++){var _=x[m];if(!f||f(_)){for(var v=new g.Animation("".concat(_.name),"influence",_.framePerSecond,_.dataType,_.loopMode,_.enableBlending),y=[],T=_.getKeys(),b=0;b<T.length;++b)for(var A=T[b],M=0;M<h.numTargets;++M)M==d?y.push(A):y.push({frame:A.frame,value:0});v.setKeys(y);var w=e._DeduceAnimationInfo(v);w&&(p={name:v.name,samplers:[],channels:[]},e._AddAnimation(_.name,_.hasRunningRuntimeAnimations?n:p,t,v,w.dataAccessorType,w.animationChannelTargetPath,o,i,s,u,w.useQuaternion,c,l,h.numTargets),p.samplers.length&&p.channels.length&&r.push(p))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,n,r,o,a,i,s,u,c){var l,f;if(t.animationGroups)for(var p=t.animationGroups,h=function(p){var h=new Map,m=new Map,x=new Set,_=p.to-p.from;f={name:p.name,channels:[],samplers:[]};for(var v=function(n){var _=p.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(A=e._DeduceAnimationInfo(_.animation)){var b=d._IsTransformable(v)?v:d._IsTransformable(v[0])?v[0]:null;b&&e._AddAnimation("".concat(y.name),f,b,y,A.dataAccessorType,A.animationChannelTargetPath,r,o,a,i,A.useQuaternion,s,T)}}else if(v instanceof g.MorphTarget||1===v.length&&v[0]instanceof g.MorphTarget){var A;if(A=e._DeduceAnimationInfo(_.animation)){var M=v instanceof g.MorphTarget?v:v[0];if(M){var w=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===M)return!0;return!1}));if(w){var E=t.meshes.find((function(e){return e.morphTargetManager===w}));E&&(h.has(E)||h.set(E,new Map),null===(l=h.get(E))||void 0===l||l.set(M,y),x.add(E),m.set(E,y))}}}}},y=0;y<p.targetedAnimations.length;++y)v(y);x.forEach((function(t){for(var n=t.morphTargetManager,u=null,c=[],l=m.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=h.get(t);if(T){var b=T.get(y);b?(u||(u=new g.Animation("".concat(p.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,g.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[x])):c.push({frame:p.from+_/d*x,value:y.influence,inTangent:l[0].inTangent?0:void 0,outTangent:l[0].outTangent?0:void 0})}}u.setKeys(c);var A=e._DeduceAnimationInfo(u);A&&e._AddAnimation("".concat(p.name,"_").concat(t.name,"_MorphWeightAnimation"),f,t,u,A.dataAccessorType,A.animationChannelTargetPath,r,o,a,i,A.useQuaternion,s,!1,null==n?void 0:n.numTargets)})),f.channels.length&&f.samplers.length&&n.push(f)},d=this,m=0,x=p;m<x.length;m++)h(x[m])},e._AddAnimation=function(t,n,r,o,a,i,s,u,c,l,f,p,h,d){var m,x,_,v,y,T,b=e._CreateNodeAnimation(r,o,i,f,p);if(b){if(d){for(var A=0,M=0,w=[];b.inputs.length>0;)M=b.inputs.shift(),A%d==0&&w.push(M),A++;b.inputs=w}var E=s.get(r),R=new Float32Array(b.inputs);m=u.createBufferView(R),x=u.createAccessor(m,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(x),_=l.length-1;var C=new g.Quaternion,S=new g.Vector3,V=new g.Vector3,I=r instanceof g.Camera,B=H(a),F=new Float32Array(b.outputs.length*B);b.outputs.forEach((function(e,t){var n=e;switch(i){case"translation":h&&(g.Vector3.FromArrayToRef(e,0,V),z(V),V.toArray(n));break;case"rotation":4===e.length?g.Quaternion.FromArrayToRef(e,0,C):(n=new Array(4),g.Vector3.FromArrayToRef(e,0,S),g.Quaternion.FromEulerVectorToRef(S,C)),h&&(j(C),I&&X(C)),C.toArray(n)}F.set(n,t*B)})),m=u.createBufferView(F),x=u.createAccessor(m,a,5126,b.outputs.length),l.push(x),v=l.length-1,y={interpolation:b.samplerInterpolation,input:_,output:v},n.samplers.push(y),T={sampler:n.samplers.length-1,target:{node:E,path:i}},n.channels.push(T)}},e._CreateBakedAnimation=function(t,n,r,o,a,i,s,u,c,l,f){var p,h,d=g.Quaternion.Identity(),m=null,x=null,_=null,v=null,y=null,T=null;l.min=g.Tools.FloatRound(o/i);for(var b=n.getKeys(),A=0,M=b.length;A<M;++A){if(T=null,_=b[A],A+1<M)if(v=b[A+1],_.value.equals&&_.value.equals(v.value)||_.value===v.value){if(0!==A)continue;T=_.frame}else T=v.frame;else{if(y=b[A-1],_.value.equals&&_.value.equals(y.value)||_.value===y.value)continue;T=a}if(T)for(var w=_.frame;w<=T;w+=s)if((h=g.Tools.FloatRound(w/i))!==m){m=h,x=h;var E={key:0,repeatCount:0,loopMode:n.loopMode};p=n._interpolate(w,E),e._SetInterpolatedValue(t,p,h,n,r,d,u,c,f)}}x&&(l.max=x)},e._ConvertFactorToVector3OrQuaternion=function(t,n,r,o,a){var i=e._GetBasePositionRotationOrScale(n,o,a),s=r.targetProperty.split("."),u=s?s[1]:"",c=a?g.Quaternion.FromArray(i).normalize():g.Vector3.FromArray(i);switch(u){case"x":case"y":case"z":c[u]=t;break;case"w":c.w=t;break;default:g.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return c},e._SetInterpolatedValue=function(e,t,n,r,o,a,i,s,u){var c;i.push(n),"weights"!==o?(r.dataType===g.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,r,o,u)),"rotation"===o?(u?a=t:(c=t,g.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,a)),s.push(a.asArray())):(c=t,s.push(c.asArray()))):s.push([t])},e._CreateLinearOrStepAnimation=function(t,n,r,o,a,i){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,a,r,t,i)}},e._CreateCubicSplineAnimation=function(t,n,r,o,a,i){n.getKeys().forEach((function(s){o.push(s.frame/n.framePerSecond),e._AddSplineTangent(ne.INTANGENT,a,r,"CUBICSPLINE",s,i),e._AddKeyframeValue(s,n,a,r,t,i),e._AddSplineTangent(ne.OUTTANGENT,a,r,"CUBICSPLINE",s,i)}))},e._GetBasePositionRotationOrScale=function(e,t,n){var r;if("rotation"===t)if(n){var o=e.rotationQuaternion;r=(null!=o?o:g.Quaternion.Identity()).asArray()}else{var a=e.rotation;r=(null!=a?a:g.Vector3.Zero()).asArray()}else if("translation"===t){var i=e.position;r=(null!=i?i:g.Vector3.Zero()).asArray()}else{var s=e.scaling;r=(null!=s?s:g.Vector3.One()).asArray()}return r},e._AddKeyframeValue=function(e,t,n,r,o,a){var i,s=t.dataType;if(s===g.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===r){var c=g.Vector3.FromArray(u);u=g.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}n.push(u)}else if(s===g.Animation.ANIMATIONTYPE_FLOAT){if("weights"===r)n.push([e.value]);else if(i=this._ConvertFactorToVector3OrQuaternion(e.value,o,t,r,a)){if("rotation"===r){var l=a?i:g.Quaternion.RotationYawPitchRoll(i.y,i.x,i.z).normalize();n.push(l.asArray())}n.push(i.asArray())}}else s===g.Animation.ANIMATIONTYPE_QUATERNION?n.push(e.value.normalize().asArray()):g.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,n){var r,o,a=!1;if("rotation"===t&&!n)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var i=0,s=e.length;i<s;++i)if((o=e[i]).inTangent||o.outTangent)if(r){if("CUBICSPLINE"!==r){r="LINEAR",a=!0;break}}else r="CUBICSPLINE";else if(r){if("CUBICSPLINE"===r||o.interpolation&&1===o.interpolation&&"STEP"!==r){r="LINEAR",a=!0;break}}else r=o.interpolation&&1===o.interpolation?"STEP":"LINEAR";return r||(r="LINEAR"),{interpolationType:r,shouldBakeAnimation:a}},e._AddSplineTangent=function(e,t,n,r,o,a){var i,s=e===ne.INTANGENT?o.inTangent:o.outTangent;if("CUBICSPLINE"===r){if("rotation"===n)if(s)if(a)i=s.asArray();else{var u=s;i=g.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else i=[0,0,0,0];else i="weights"===n?s?[s]:[0]:s?s.asArray():[0,0,0];t.push(i)}},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 ae(e,t,n,r,o,a){var i={attributes:{},influence:e.influence,name:e.name},s=t.geometry;if(!s)return g.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),i;var u=a?-1:1,c=g.Vector3.Zero(),l=0;if(e.hasPositions){var f=e.getPositions(),p=s.getVerticesData(g.VertexBuffer.PositionKind);if(p){var h=new Float32Array(p.length),d=[1/0,1/0,1/0],m=[-1/0,-1/0,-1/0];l=p.length/3;for(var x=0;x<l;++x){var _=g.Vector3.FromArray(p,3*x);g.Vector3.FromArray(f,3*x).subtractToRef(_,c),c.x*=u,d[0]=Math.min(d[0],c.x),m[0]=Math.max(m[0],c.x),d[1]=Math.min(d[1],c.y),m[1]=Math.max(m[1],c.y),d[2]=Math.min(d[2],c.z),m[2]=Math.max(m[2],c.z),h[3*x]=c.x,h[3*x+1]=c.y,h[3*x+2]=c.z}var v=n.createBufferView(h,12),y=n.createAccessor(v,"VEC3",5126,f.length/3,0,{min:d,max:m});o.push(y),i.attributes.POSITION=o.length-1}else g.Tools.Warn("Morph target positions for mesh ".concat(t.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var T=e.getNormals(),b=s.getVerticesData(g.VertexBuffer.NormalKind);if(b){var A=new Float32Array(b.length);for(l=b.length/3,x=0;x<l;++x){var M=g.Vector3.FromArray(b,3*x).normalize();g.Vector3.FromArray(T,3*x).normalize().subtractToRef(M,c),A[3*x]=c.x*u,A[3*x+1]=c.y,A[3*x+2]=c.z}v=n.createBufferView(A,12),y=n.createAccessor(v,"VEC3",5126,T.length/3,0),o.push(y),i.attributes.NORMAL=o.length-1}else g.Tools.Warn("Morph target normals for mesh ".concat(t.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var w=e.getTangents(),E=s.getVerticesData(g.VertexBuffer.TangentKind);if(E){l=E.length/4;var R=new Float32Array(3*l);for(x=0;x<l;++x){var C=g.Vector3.FromArray(E,4*x);q(C);var S=g.Vector3.FromArray(w,3*x);q(S),S.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),i.attributes.TANGENT=o.length-1}else g.Tools.Warn("Morph target tangents for mesh ".concat(t.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var V=e.getColors(),I=s.getVerticesData(g.VertexBuffer.ColorKind),B=s.getVertexBuffer(g.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=g.Vector3.FromArray(I,x*F);g.Vector3.FromArray(V,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 U=new g.Vector4;P=g.Vector4.FromArray(I,x*F),g.Vector4.FromArray(V,x*F).subtractToRef(P,U),O[4*x]=U.x,O[4*x+1]=U.y,O[4*x+2]=U.z,O[4*x+3]=U.w}else g.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),i.attributes.COLOR_0=o.length-1}else g.Tools.Warn("Morph target colors for mesh ".concat(t.name," were not exported. Mesh does not have colors vertex data"))}return i}var ie=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 a,i,s,u;return null===(u=null===(s=null===(i=null===(a=this._indicesAccessorMap.get(e))||void 0===a?void 0:a.get(t))||void 0===i?void 0:i.get(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,a){var i=this._indicesAccessorMap.get(e);i||(i=new Map,this._indicesAccessorMap.set(e,i));var s=i.get(t);s||(s=new Map,i.set(t,s));var u=s.get(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,a)},e.prototype.pushExportedNode=function(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)},e.prototype.getNodesSet=function(){return this._exportedNodes},e.prototype.getVertexBufferView=function(e){return this._vertexBufferViewMap.get(e)},e.prototype.setVertexBufferView=function(e,t){this._vertexBufferViewMap.set(e,t)},e.prototype.setRemappedBufferView=function(e,t,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 a=o.get(t);a||(a=new Map,o.set(t,a)),a.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=g.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(g.Engine.Version),version:"2.0"}},this._animations=[],this._accessors=[],this._bufferViews=[],this._cameras=[],this._images=[],this._materials=[],this._meshes=[],this._nodes=[],this._samplers=[],this._scenes=[],this._skins=[],this._textures=[],this._imageData={},this._shouldUseGlb=!1,this._materialExporter=new 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 a=r(t[n],e);return a?a.then((function(e){return y(o,void 0,void 0,(function(){var o;return T(this,(function(a){switch(a.label){case 0:return e?[4,this._ApplyExtension(e,t,n+1,r)]:[3,2];case 1:return o=a.sent(),[3,3];case 2:o=null,a.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,a=e._ExtensionNames;o<a.length;o++){var i=a[o];r.push(this._extensions[i])}return this._ApplyExtension(t,r,0,n)},e.prototype._extensionsPostExportNodeAsync=function(e,t,n,r,o){var a=this;return this._ApplyExtensions(t,(function(t,i){return t.postExportNodeAsync&&t.postExportNodeAsync(e,i,n,r,o,a._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._extensionsPostExportMaterialAdditionalTexturesAsync=function(t,n,r){return y(this,void 0,void 0,(function(){var o,a=this;return T(this,(function(i){switch(i.label){case 0:return o=[],[4,Promise.all(e._ExtensionNames.map((function(e){return y(a,void 0,void 0,(function(){var a,i;return T(this,(function(s){switch(s.label){case 0:return(a=this._extensions[e]).postExportMaterialAdditionalTexturesAsync?[4,a.postExportMaterialAdditionalTexturesAsync(t,n,r)]:[3,2];case 1:i=s.sent(),o.push.apply(o,i),s.label=2;case 2:return[2]}}))}))})))];case 1:return i.sent(),[2,o]}}))}))},e.prototype._extensionsPostExportTextures=function(t,n,r){for(var o=0,a=e._ExtensionNames;o<a.length;o++){var i=a[o],s=this._extensions[i];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],a=this._extensions[o];a.postExportMeshPrimitive&&a.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(a){switch(a.label){case 0:t=0,n=e._ExtensionNames,a.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:a.sent(),a.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],a=this._extensions[o];a.enabled&&t(a)}},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,r){void 0===r&&(r=100),e.UnregisterExtension(t)&&g.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=n;var o=null!=r?r:0;e._ExtensionOrders[t]=o;for(var a=e._ExtensionNames.length,i=0;i<e._ExtensionNames.length;i++){var s=e._ExtensionNames[i];if(o<e._ExtensionOrders[s]){a=i;break}}e._ExtensionNames.splice(a,0,t)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t],delete e._ExtensionOrders[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,a,i,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",a=e+".bin",(i=new _).files[o]=n,i.files[a]=r,this._imageData)for(s in this._imageData)i.files[s]=new Blob([this._imageData[s].data],{type:this._imageData[s].mimeType});return[2,i]}}))}))},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,a,i,s,u,c,l,f,p,h,d;return T(this,(function(g){switch(g.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=g.sent(),this._extensionsOnExporting(),n=this._generateJSON(t.byteLength),r=e+".glb",o=n.length,"undefined"!=typeof TextEncoder&&(i=new TextEncoder,a=i.encode(n),o=a.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),a)l.writeTypedArray(a);else for(f="_".charCodeAt(0),h=0;h<o;++h)(p=n.charCodeAt(h))!=n.codePointAt(h)?l.writeUInt8(f):l.writeUInt8(p);for(h=0;h<s;++h)l.writeUInt8(32);for(l.writeUInt32(t.byteLength+u),l.writeUInt32(5130562),l.writeTypedArray(t),h=0;h<u;++h)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(N,g.Epsilon)||g.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsWithEpsilon(N,g.Epsilon)){var o=g.TmpVectors.Vector3[0].copyFrom(t.position);n&&z(o),e.translation=o.asArray()}t.scaling.equalsWithEpsilon(D,g.Epsilon)||(e.scale=t.scaling.asArray());var a=(null===(r=t.rotationQuaternion)||void 0===r?void 0:r.clone())||g.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);a.equalsWithEpsilon(L,g.Epsilon)||(n&&j(a),e.rotation=a.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,n){var r=g.TmpVectors.Vector3[0],o=g.TmpVectors.Quaternion[0],a=t.getWorldMatrix();if(t.parent){var i=t.parent.getWorldMatrix().invertToRef(g.TmpVectors.Matrix[0]);a.multiplyToRef(i,g.TmpVectors.Matrix[1]).decompose(void 0,o,r)}else a.decompose(void 0,o,r);r.equalsWithEpsilon(N,g.Epsilon)||(n&&z(r),e.translation=r.asArray()),n&&j(o),this._babylonScene.useRightHandedSystem||X(o),o.equalsWithEpsilon(L,g.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===g.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===g.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(),a=n.orthoBottom&&n.orthoTop?.5*(n.orthoTop-n.orthoBottom):.5*n.getEngine().getRenderHeight();r.orthographic={xmag:o,ymag:a,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,a=r;o<a.length;o++)a[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 a={},i=-1,s=0;s<n.bones.length;++s){var u=n.bones[s];-1!==(f=null!==(t=u.getIndex())&&void 0!==t?t:s)&&(a[f]=u,f>i&&(i=f))}for(var c,l=[],f=0;f<=i;++f){var p=(u=a[f]).getTransformNode(),h=p?r._nodeMap.get(p):void 0;if(void 0!==h){o.joints.push(h);var d=u.getAbsoluteInverseBindMatrix().clone();e.has(p)&&(c=d,P.invertToRef(g.TmpVectors.Matrix[0]).multiplyToRef(c,c).multiplyToRef(P,c)),l.push(d)}else g.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.")}var m=r._nodesSkinMap.get(o);if(o.joints.length>0&&void 0!==m){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=m;y<T.length;y++)T[y].skin=v}},r=this,o=0,a=this._babylonScene.skeletons;o<a.length;o++)n(a[o])},e.prototype._exportSceneAsync=function(){return y(this,void 0,void 0,(function(){var e,t,n,r,o,a,i,s,u,c,l,f,p,h,d,g,m,x,_,v,y,b,A;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,a=0,i=this._babylonScene.rootNodes;a<i.length;a++)s=i[a],this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&U(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 ie(!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()])),p=new ie(!1,!1),d=(h=(b=e.nodes).push).apply,g=[b],[4,this._exportNodesAsync(n,p)];case 2:return d.apply(h,g.concat([T.sent()])),m=new ie(!1,!0),_=(x=(A=e.nodes).push).apply,v=[A],[4,this._exportNodesAsync(o,m)];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,a;return T(this,(function(i){switch(i.label){case 0:n=new Array,this._exportBuffers(e,t),r=0,o=e,i.label=1;case 1:return r<o.length?(a=o[r],[4,this._exportNodeAsync(a,n,t)]):[3,4];case 2:i.sent(),i.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 g.AbstractMesh&&e.geometry){var a=e.geometry.getVertexBuffers();if(a)for(var i in a)if(G(i)){var s=a[i];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 p=0;p<f.numTargets;p++){var h=f.getTarget(p);l=r.get(h)||[],r.set(h,l),-1===l.indexOf(e)&&l.push(e)}}for(var d=0,m=e.getChildren();d<m.length;d++){var x=m[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,a=0,i=e;a<i.length;a++){var s=i[a];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 a=n.get(e);if(!a)return"continue";var i=a[0].byteStride;if(a.some((function(e){return e.byteStride!==i})))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,a=n.byteStride,i=n.componentCount,u=n.type,c=n.count,f=n.normalized;switch(n.kind){case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:(0,g.EnumerateFloatValues)(s,o,a,i,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 g.VertexBuffer.ColorKind:var p=t.filter((function(e){return e.material instanceof g.StandardMaterial||null==e.material})).length;if(0==p)break;if(p!=t.length){g.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}u==g.VertexBuffer.UNSIGNED_BYTE&&g.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var h=new g.Color3,d=new g.Color4,m=l._babylonScene.getEngine().useExactSrgbConversions;(0,g.EnumerateFloatValues)(s,o,a,i,u,c,f,(function(e){3===e.length?(h.fromArray(e,0),h.toLinearSpaceToRef(h,m),h.toArray(e,0)):(d.fromArray(e,0),d.toLinearSpaceToRef(d,m),d.toArray(e,0))}))}},c=0,f=a;c<f.length;c++)u(B=f[c]);if(t.convertToRightHanded){for(var p=0,h=a;p<h.length;p++){var d=k(B=h[p],r.get(B)),m=d.byteOffset,x=d.byteStride,_=d.componentCount,v=d.type,y=d.count,T=d.normalized;switch(R=d.kind){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:(0,g.EnumerateFloatValues)(s,m,x,_,v,y,T,(function(e){e[0]=-e[0]}))}}t.convertedToRightHandedBuffers.set(e,s)}var b=l._bufferManager.createBufferView(s,i);t.setVertexBufferView(e,b);for(var A=new Map,M=0,w=a;M<w.length;M++){var E=k(B=w[M],r.get(B)),R=E.kind,C=E.totalVertices;switch(R){case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:if(B.type==g.VertexBuffer.FLOAT){var S=B.getFloatData(C);null!==S&&A.set(B,S)}}}0!==A.size&&g.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 V=0,I=Array.from(A.keys());V<I.length;V++){var B=I[V],F=A.get(B);if(F){for(var O=F.some((function(e){return e>=256})),P=new(O?Uint16Array:Uint8Array)(F.length),U=0;U<F.length;U++)P[U]=F[U];var N=l._bufferManager.createBufferView(P,4*(O?2:1));t.setRemappedBufferView(e,B,N)}}},l=this,f=0,p=u;f<p.length;f++)c(p[f]);for(var h=0,d=Array.from(o.keys());h<d.length;h++){var m=d[h],x=o.get(m);if(x)for(var _=ae(m,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,a,i,s,u,c,l,f=this;return T(this,(function(p){switch(p.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=p.sent())&&(r=this._nodes.length,this._nodes.push(o),this._nodeMap.set(e,r),n.pushExportedNode(e),t.push(r),a={name:"runtime animations",channels:[],samplers:[]},i=[],this._babylonScene.animationGroups.length||(oe._CreateMorphTargetAnimationFromMorphTargetAnimations(e,a,i,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&oe._CreateNodeAnimationFromNodeAnimations(e,a,i,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation)),a.channels.length&&a.samplers.length&&this._animations.push(a),i.forEach((function(e){e.channels.length&&e.samplers.length&&f._animations.push(e)}))),s=o?[]:t,u=0,c=e.getChildren(),p.label=2;case 2:return u<c.length?(l=c[u],[4,this._exportNodeAsync(l,s,n)]):[3,5];case 3:p.sent(),p.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,a,i,s,u,c,l,f,p,h;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 g.TransformNode?(this._setNodeTransformation(n,e,t.convertToRightHanded),e instanceof g.AbstractMesh?(o=e instanceof g.InstancedMesh?e.sourceMesh:e).subMeshes&&o.subMeshes.length>0?(a=n,[4,this._exportMeshAsync(o,t)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:a.mesh=d.sent(),d.label=2;case 2:e.skeleton&&void 0!==(i=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(i)&&this._nodesSkinMap.set(i,[]),null===(f=this._nodesSkinMap.get(i))||void 0===f||f.push(n)),d.label=3;case 3:if(e instanceof g.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)&&Q(e,u)&&void 0!==(c=this._nodeMap.get(u)))return l=this._nodes[c],Y(n,l),null===(p=this._nodesCameraMap.get(s))||void 0===p||p.push(l),[2,null];null===(h=this._nodesCameraMap.get(s))||void 0===h||h.push(n)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",n,e,this._nodeMap,t.convertToRightHanded)];case 4:return d.sent()?[2,n]:(g.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}}))}))},e.prototype._exportIndices=function(e,t,n,r,o,a,i,s,u){var c=e;u.mode=W(a);var l=i!==g.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case g.Material.TriangleFillMode:case g.Material.TriangleStripDrawMode:case g.Material.TriangleFanDrawMode:return!0}return!1}(a);if(l){if(a===g.Material.TriangleStripDrawMode||a===g.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");u.mode=W(a);var f=t?new Uint32Array(r):new Uint16Array(r);if(e)for(var p=0;p+2<r;p+=3)f[p]=e[n+p]+o,f[p+1]=e[n+p+2]+o,f[p+2]=e[n+p+1]+o;else for(p=0;p+2<r;p+=3)f[p]=p,f[p+1]=p+2,f[p+2]=p+1;c=f}else if(e&&0!==o){for(f=t?new Uint32Array(r):new Uint16Array(r),p=0;p<r;p++)f[p]=e[n+p]+o;c=f}if(c){var h=s.getIndicesAccessor(e,n,r,o,l);if(void 0===h){var d=function(e,t,n,r){var o=e;return 0===t&&n===e.length||(o=Array.isArray(e)?e.slice(t,t+n):e.subarray(t,t+n)),o instanceof Int32Array?new Uint32Array(o.buffer,o.byteOffset,o.length):Array.isArray(o)?r?new Uint32Array(o):new Uint16Array(o):o}(c,n,r,t),m=this._bufferManager.createBufferView(d),x=t?5125:5123;this._accessors.push(this._bufferManager.createAccessor(m,"SCALAR",x,r,0)),h=this._accessors.length-1,s.setIndicesAccessor(e,n,r,o,l,h)}u.indices=h}},e.prototype._exportVertexBuffer=function(e,t,n,r,o,a){var i=e.getKind();if(G(i)&&(!i.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=i===g.VertexBuffer.PositionKind?function(e,t,n,r){var o=t.byteOffset,a=t.byteStride,i=t.type,s=t.normalized,u=t.getSize(),c=new Array(u).fill(1/0),l=new Array(u).fill(-1/0);return(0,g.EnumerateFloatValues)(e,o+n*a,a,u,i,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=(i===g.VertexBuffer.MatricesIndicesKind||i===g.VertexBuffer.MatricesIndicesExtraKind)&&e.type===g.VertexBuffer.FLOAT,f=l?g.VertexBuffer.UNSIGNED_BYTE:e.type,p=l?void 0:e.normalized,h=l?o.getRemappedBufferView(e._buffer,e):o.getVertexBufferView(e._buffer),d=e.byteOffset+n*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(h,function(e,t){if(e==g.VertexBuffer.ColorKind)return t?"VEC4":"VEC3";switch(e){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:return"VEC3";case g.VertexBuffer.TangentKind:case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:case g.VertexBuffer.MatricesWeightsKind:case g.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case g.VertexBuffer.UVKind:case g.VertexBuffer.UV2Kind:case g.VertexBuffer.UV3Kind:case g.VertexBuffer.UV4Kind:case g.VertexBuffer.UV5Kind:case g.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(i,o.hasVertexColorAlpha(e)),f,r,d,c,p)),s=this._accessors.length-1,o.setVertexAccessor(e,n,r,s)}a.attributes[function(e){switch(e){case g.VertexBuffer.PositionKind:return"POSITION";case g.VertexBuffer.NormalKind:return"NORMAL";case g.VertexBuffer.TangentKind:return"TANGENT";case g.VertexBuffer.ColorKind:return"COLOR_0";case g.VertexBuffer.UVKind:return"TEXCOORD_0";case g.VertexBuffer.UV2Kind:return"TEXCOORD_1";case g.VertexBuffer.UV3Kind:return"TEXCOORD_2";case g.VertexBuffer.UV4Kind:return"TEXCOORD_3";case g.VertexBuffer.UV5Kind:return"TEXCOORD_4";case g.VertexBuffer.UV6Kind:return"TEXCOORD_5";case g.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case g.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case g.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case g.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(i)]=s}},e.prototype._exportMaterialAsync=function(e,t,n,r){return y(this,void 0,void 0,(function(){var o,a;return T(this,(function(i){switch(i.label){case 0:return void 0!==(o=this._materialMap.get(e))?[3,8]:(a=t&&Object.keys(t).some((function(e){return e.startsWith("uv")})),(e=e instanceof g.MultiMaterial?e.subMaterials[n.materialIndex]:e)instanceof g.PBRBaseMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,a)]:[3,2]);case 1:return o=i.sent(),[3,7];case 2:return e instanceof g.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,a)]:[3,4];case 3:return o=i.sent(),[3,7];case 4:return e instanceof g.OpenPBRMaterial?[4,this._materialExporter.exportOpenPBRMaterialAsync(e,a)]:[3,6];case 5:return o=i.sent(),[3,7];case 6:return g.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 7:this._materialMap.set(e,o),i.label=8;case 8:return r.material=o,[2]}}))}))},e.prototype._exportMeshAsync=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,a,i,s,u,c,l,f,p,h,d,m,x,_,v,y,A,M,w,E,R,C,S,V,I,B,F,O,P,U,N,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(),a=null===(F=e.geometry)||void 0===F?void 0:F.getVertexBuffers(),i=t.getMorphTargetsFromMesh(e),s=e instanceof g.LinesMesh,u=e instanceof g.GreasedLineBaseMesh,c=e.subMeshes,!(a&&c&&c.length>0))return[3,7];l=0,f=c,T.label=1;case 1:return l<f.length?(p=f[l],h={attributes:{}},d=p.getMaterial()||this._babylonScene.defaultMaterial,u?(v={name:d.name},y=e,m=g.Color3.White(),x=null!==(P=null===(O=y.material)||void 0===O?void 0:O.alpha)&&void 0!==P?P:1,(!(_=null!==(N=null===(U=y.greasedLineMaterial)||void 0===U?void 0:U.color)&&void 0!==N?N:m).equalsWithEpsilon(m,g.Epsilon)||x<1)&&(v.pbrMetallicRoughness={baseColorFactor:b(b([],_.asArray(),!0),[x],!1)}),this._materials.push(v),h.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return s?(v={name:d.name},(!(y=e).color.equalsWithEpsilon(g.Color3.White(),g.Epsilon)||y.alpha<1)&&(v.pbrMetallicRoughness={baseColorFactor:b(b([],y.color.asArray(),!0),[y.alpha],!1)}),this._materials.push(v),h.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(d,a,p,h)];case 4:T.sent(),T.label=5;case 5:for(A=s||u?g.Material.LineListDrawMode:null!==(L=e.overrideRenderingFillMode)&&void 0!==L?L:d.fillMode,M=d._getEffectiveOrientation(e),t.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(M=M===g.Material.ClockWiseSideOrientation?g.Material.CounterClockWiseSideOrientation:g.Material.ClockWiseSideOrientation),this._exportIndices(o,o?(0,g.AreIndices32Bits)(o,p.indexCount,p.indexStart,p.verticesStart):p.verticesCount>65535,o?p.indexStart:p.verticesStart,o?p.indexCount:p.verticesCount,-p.verticesStart,A,M,t,h),w=0,E=Object.values(a);w<E.length;w++)R=E[w],this._exportVertexBuffer(R,d,p.verticesStart,p.verticesCount,t,h);if(i)for(h.targets=[],C=0,S=i;C<S.length;C++)B=S[C],h.targets.push(B.attributes);r.primitives.push(h),this._extensionsPostExportMeshPrimitive(h),T.label=6;case 6:return l++,[3,1];case 7:if(i)for(r.weights=[],r.extras||(r.extras={}),r.extras.targetNames=[],V=0,I=i;V<I.length;V++)B=I[V],r.weights.push(B.influence),r.extras.targetNames.push(B.name);return[2,n]}}))}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e._ExtensionOrders={},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(a){switch(a.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:a.sent(),a.label=2;case 2:return[4,(r=new se(e,n)).generateGLTFAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=a.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(a){switch(a.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:a.sent(),a.label=2;case 2:return[4,(r=new se(e,n)).generateGLBAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=a.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,a){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 g.Mesh&&n.hasThinInstances&&e._exporter){e._wasUsed=!0;for(var i=g.Vector3.Zero(),s=g.Quaternion.Identity(),u=g.Vector3.One(),c=n.thinInstanceGetWorldMatrices(),l=g.TmpVectors.Vector3[2],f=g.TmpVectors.Quaternion[1],p=g.TmpVectors.Vector3[3],h=!1,d=!1,m=!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(p,f,l),o&&(z(l),j(f)),x.set(l.asArray(),3*y),_.set(f.normalize().asArray(),4*y),v.set(p.asArray(),3*y),h=h||!l.equalsWithEpsilon(i),d=d||!f.equalsWithEpsilon(s),m=m||!p.equalsWithEpsilon(u),y++;var A={attributes:{}};h&&(A.attributes.TRANSLATION=e._buildAccessor(x,"VEC3",n.thinInstanceCount,a)),d&&(A.attributes.ROTATION=e._buildAccessor(_,"VEC4",n.thinInstanceCount,a)),m&&(A.attributes.SCALE=e._buildAccessor(v,"VEC3",n.thinInstanceCount,a)),t.extensions=t.extensions||{},t.extensions[ce]=A}r(t)}))];case 1:return[2,r.sent()]}}))}))},e.prototype._buildAccessor=function(e,t,n,r){var o=r.createBufferView(e),a=r.createAccessor(o,t,5126,n);return this._exporter._accessors.push(a),this._exporter._accessors.length-1},e}();se.RegisterExtension(ce,(function(e){return new le(e)}));var fe="KHR_draco_mesh_compression",pe=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&&g.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=[],a=[],i=null;if(void 0!==e.indices){var s=n[e.indices],u=t.getBufferView(s);i=t.getData(u).slice(),o.push(u),a.push(s)}for(var c,l=[],f=0,p=Object.entries(e.attributes);f<p.length;f++){var h=p[f],d=h[0],m=(s=n[h[1]],u=t.getBufferView(s),H(s.type)),x=(0,g.GetTypedArrayData)(t.getData(u),m,s.componentType,s.byteOffset||0,u.byteStride||(0,g.GetTypeByteLength)(s.componentType)*m,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:H(s.type),data:x}),o.push(u),a.push(s)}var _={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},v=g.DracoEncoder.Default._encodeAsync(l,i,_).then((function(n){if(n){var i={bufferView:-1,attributes:n.attributeIds},s=t.createBufferView(n.data);t.setBufferView(i,s);for(var u=0,c=o;u<c.length;u++){var l=c[u];r._bufferViewsUsed.add(l)}for(var f=0,p=a;f<p.length;f++){var h=p[f];r._accessorsUsed.add(h)}e.extensions||(e.extensions={}),e.extensions[fe]=i}else g.Logger.Error("Draco encoding failed for primitive.")})).catch((function(e){g.Logger.Error("Draco encoding failed for primitive: "+e)}));this._encodePromises.push(v),this._wasUsed=!0}else g.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 pe(e)}));var he="KHR_lights_punctual",de={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},ge={innerConeAngle:0,outerConeAngle:Math.PI/4},me=g.Vector3.Backward(),xe=function(){function e(e){this.name=he,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[he]=this._lights},e.prototype.postExportNodeAsync=function(e,t,n,r,o){return y(this,void 0,void 0,(function(){var a=this;return T(this,(function(i){switch(i.label){case 0:return[4,new Promise((function(i){if(n instanceof g.Light){var s=n.getTypeID()==g.Light.LIGHTTYPEID_POINTLIGHT?"point":n.getTypeID()==g.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":n.getTypeID()==g.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(s&&n instanceof g.ShadowLight))return g.Logger.Warn("".concat(e,": Light ").concat(n.name," is not supported in ").concat(he)),void i(t);if(n.falloffType!==g.Light.FALLOFF_GLTF&&g.Logger.Warn("".concat(e,": Light falloff for ").concat(n.name," does not match the ").concat(he," specification!")),!n.position.equalsToFloats(0,0,0)){var u=g.TmpVectors.Vector3[0].copyFrom(n.position);o&&z(u),t.translation=u.asArray()}if("point"!==s){var c=n.direction.normalizeToRef(g.TmpVectors.Vector3[0]);o&&z(c);var l=g.Quaternion.FromUnitVectorsToRef(me,c,g.TmpVectors.Quaternion[0]);g.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 p=n;f.spot={innerConeAngle:p.innerAngle/2,outerConeAngle:p.angle/2},Z(f.spot,ge)}a._lights||(a._lights={lights:[]}),a._lights.lights.push(f);var h={light:a._lights.lights.length-1},d=n.parent;if(d&&Q(n,d)){var m=r.get(d);if(m){var x=a._exporter._nodes[m];return Y(t,x),x.extensions||(x.extensions={}),x.extensions[he]=h,void i(null)}}t.extensions||(t.extensions={}),t.extensions[he]=h,i(t)}else i(t)}))];case 1:return[2,i.sent()]}}))}))},e}();se.RegisterExtension(he,(function(e){return new xe(e)}));var _e="KHR_materials_anisotropy";function ve(e,t){t.uOffset=e.uOffset,t.vOffset=e.vOffset,t.uScale=e.uScale,t.vScale=e.vScale,t.uAng=e.uAng,t.vAng=e.vAng,t.wAng=e.wAng,t.uRotationCenter=e.uRotationCenter,t.vRotationCenter=e.vRotationCenter}function ye(e){return y(this,void 0,void 0,(function(){var t,n,r,o,a,i,s,u;return T(this,(function(c){switch(c.label){case 0:return t=e.getScene(),g.Effect.ShadersStore.anisotropyMergeFragmentShader||(g.Effect.ShadersStore.anisotropyMergeFragmentShader="\n precision highp float;\n#ifdef HAS_TANGENT_TEXTURE\n uniform sampler2D tangentTexture;\n#endif\n#ifdef HAS_ANISOTROPY_TEXTURE\n uniform sampler2D anisotropyTexture;\n#endif\n uniform int useRoughnessFromMetallicGreen;\n uniform int useAnisotropyFromTangentBlue;\n\n varying vec2 vUV;\n\n void main() {\n vec2 tangent = vec2(1.0, 0.0);\n float anisotropy = 1.0;\n #ifdef HAS_TANGENT_TEXTURE\n // Tangent texture is present\n vec4 tangentSample = texture2D(tangentTexture, vUV);\n tangent = tangentSample.rg;\n\n if (useAnisotropyFromTangentBlue > 0) {\n anisotropy = tangentSample.b;\n }\n #endif\n #ifdef HAS_ANISOTROPY_TEXTURE\n // Anisotropy texture is present\n vec4 anisotropySample = texture2D(anisotropyTexture, vUV);\n anisotropy = anisotropySample.r;\n #endif\n \n // Output: RG = tangent XY, B = anisotropy strength\n vec4 anisotropyData = vec4(tangent.x, tangent.y, anisotropy, 1.0);\n gl_FragColor = anisotropyData;\n }\n"),n=e.specularRoughnessAnisotropyTexture,r=e.geometryTangentTexture,n||r?(o=Math.max(n?n.getSize().width:1,r?r.getSize().width:1),a=Math.max(n?n.getSize().height:1,r?r.getSize().height:1),i={type:g.Constants.TEXTURETYPE_UNSIGNED_BYTE,format:g.Constants.TEXTUREFORMAT_RGBA,samplingMode:g.Constants.TEXTURE_BILINEAR_SAMPLINGMODE,generateDepthBuffer:!1,generateStencilBuffer:!1,generateMipMaps:!1},(s=new g.ProceduralTexture(e.name+"_anisotropy",{width:o,height:a},"anisotropyMerge",t,i)).refreshRate=-1,u="",r&&(u+="#define HAS_TANGENT_TEXTURE\n",s.setTexture("tangentTexture",r),ve(r,s)),s.setVector2("tangentVector",e.geometryTangent),n&&(u+="#define HAS_ANISOTROPY_TEXTURE\n",s.setTexture("anisotropyTexture",n),ve(n,s)),s.setInt("useAnisotropyFromTangentBlue",e._useSpecularRoughnessAnisotropyFromTangentTexture?1:0),s.defines=u,[4,new Promise((function(e,t){s.executeWhenReady((function(){try{s.render(),e(s)}catch(e){t(e instanceof Error?e:new Error(String(e)))}}))}))]):[2,null];case 1:return[2,c.sent()]}}))}))}var Te=function(){function e(e){this.name=_e,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._anisoTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e,t;return T(this,(function(r){switch(r.label){case 0:return e=[],n instanceof g.PBRBaseMaterial?n.anisotropy.isEnabled&&!n.anisotropy.legacy?(n.anisotropy.texture&&e.push(n.anisotropy.texture),[2,e]):[3,3]:[3,1];case 1:return n instanceof g.OpenPBRMaterial&&n.specularRoughnessAnisotropy>0?[4,ye(n)]:[3,3];case 2:return(t=r.sent())&&(e.push(t),this._anisoTexturesMap[n.id]=t),[2,e];case 3:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){var o,a,i,s,u,c;if(n instanceof g.PBRBaseMaterial){if(!n.anisotropy.isEnabled||n.anisotropy.legacy)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var l=r._exporter._materialExporter.getTextureInfo(n.anisotropy.texture);null!==(v={anisotropyStrength:n.anisotropy.intensity,anisotropyRotation:n.anisotropy.angle,anisotropyTexture:null!=l?l:void 0}).anisotropyTexture&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[_e]=v}else if(n instanceof g.OpenPBRMaterial&&n.specularRoughnessAnisotropy>0){r._wasUsed=!0,t.extensions=t.extensions||{};var f=n.specularRoughnessTexture;n._useRoughnessFromMetallicTextureGreen&&(f=n.baseMetalnessTexture);var p=r._anisoTexturesMap[n.id];if(!f&&!p){var h=n.specularRoughness,d=n.specularRoughnessAnisotropy;if(!n._useGltfStyleAnisotropy){var m=(a=n.specularRoughness,c=(1-(i=n.specularRoughnessAnisotropy))*(u=(s=a*a)*Math.sqrt(2/(1+(1-i)*(1-i)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-s)/Math.max(1-s,1e-4)),1)});h=m.newBaseRoughness,d=m.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=h);var x={anisotropyStrength:d,anisotropyRotation:n.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return t.extensions[_e]=x,e(t)}var _=p?r._exporter._materialExporter.getTextureInfo(p):null,v={anisotropyStrength:n.specularRoughnessAnisotropy,anisotropyRotation:n.geometryTangentAngle,anisotropyTexture:_||void 0,extensions:{}};n._useGltfStyleAnisotropy||(v.extensions.EXT_materials_anisotropy_openpbr={openPbrAnisotropyEnabled:!0},(o=r._exporter._glTF).extensionsUsed||(o.extensionsUsed=[]),-1===r._exporter._glTF.extensionsUsed.indexOf("EXT_materials_anisotropy_openpbr")&&r._exporter._glTF.extensionsUsed.push("EXT_materials_anisotropy_openpbr")),r._exporter._materialNeedsUVsSet.add(n),t.extensions[_e]=v}e(t)}))},e}();se.RegisterExtension(_e,(function(e){return new Te(e)}));var be="KHR_materials_clearcoat",Ae=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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e;return T(this,(function(t){if(e=[],n instanceof g.PBRBaseMaterial){if(n.clearCoat.isEnabled)return n.clearCoat.texture&&e.push(n.clearCoat.texture),!n.clearCoat.useRoughnessFromMainTexture&&n.clearCoat.textureRoughness&&e.push(n.clearCoat.textureRoughness),n.clearCoat.bumpTexture&&e.push(n.clearCoat.bumpTexture),[2,e]}else if(n instanceof g.OpenPBRMaterial&&n.coatWeight>0)return n.coatWeightTexture&&e.push(n.coatWeightTexture),n.geometryCoatNormalTexture&&e.push(n.geometryCoatNormalTexture),n.coatRoughnessTexture&&e.push(n.coatRoughnessTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof g.PBRBaseMaterial){if(!n.clearCoat.isEnabled)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var o=r._exporter._materialExporter.getTextureInfo(n.clearCoat.texture),a=void 0;a=n.clearCoat.useRoughnessFromMainTexture?r._exporter._materialExporter.getTextureInfo(n.clearCoat.texture):r._exporter._materialExporter.getTextureInfo(n.clearCoat.textureRoughness),n.clearCoat.isTintEnabled&&g.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(n.name)),n.clearCoat.remapF0OnInterfaceChange&&g.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(n.name));var i=r._exporter._materialExporter.getTextureInfo(n.clearCoat.bumpTexture);null===(s={clearcoatFactor:n.clearCoat.intensity,clearcoatTexture:null!=o?o:void 0,clearcoatRoughnessFactor:n.clearCoat.roughness,clearcoatRoughnessTexture:null!=a?a:void 0,clearcoatNormalTexture:null!=i?i:void 0}).clearcoatTexture&&null===s.clearcoatRoughnessTexture&&null===s.clearcoatRoughnessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[be]=s}else if(n instanceof g.OpenPBRMaterial){if(0==n.coatWeight)return void e(t);var s;r._wasUsed=!0,t.extensions=t.extensions||{},o=r._exporter._materialExporter.getTextureInfo(n.coatWeightTexture),a=void 0,a=n.useCoatRoughnessFromWeightTexture?r._exporter._materialExporter.getTextureInfo(n.coatWeightTexture):r._exporter._materialExporter.getTextureInfo(n.coatRoughnessTexture),n.coatColorTexture&&g.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(n.name)),i=r._exporter._materialExporter.getTextureInfo(n.geometryCoatNormalTexture),null===(s={clearcoatFactor:n.coatWeight,clearcoatTexture:null!=o?o:void 0,clearcoatRoughnessFactor:n.coatRoughness,clearcoatRoughnessTexture:null!=a?a:void 0,clearcoatNormalTexture:null!=i?i:void 0}).clearcoatTexture&&null===s.clearcoatRoughnessTexture&&null===s.clearcoatRoughnessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[be]=s}e(t)}))},e}();se.RegisterExtension(be,(function(e){return new Ae(e)}));var Me="KHR_materials_clearcoat_darkening",we=function(){function e(e){this.name=Me,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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e;return T(this,(function(t){return e=[],n instanceof g.OpenPBRMaterial&&n.coatDarkening?(n.coatDarkeningTexture&&e.push(n.coatDarkeningTexture),[2,e]):[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){var o=null,a=null;if(n instanceof g.OpenPBRMaterial&&(o=n.coatDarkening,a=n.coatDarkeningTexture),null===o||1===o&&null===a)return e(t);var i=t.extensions?t.extensions.KHR_materials_clearcoat:null;if(!i)return e(t);r._wasUsed=!0;var s=r._exporter._materialExporter.getTextureInfo(a),u={clearcoatDarkeningFactor:o,clearcoatDarkeningTexture:null!=s?s:void 0};return null!==u.clearcoatDarkeningTexture&&r._exporter._materialNeedsUVsSet.add(n),i.extensions=i.extensions||{},i.extensions[Me]=u,e(t)}))},e}();se.RegisterExtension(Me,(function(e){return new we(e)}),105);var Ee="KHR_materials_clearcoat_ior",Re=function(){function e(e){this.name=Ee,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.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){var o=null;if(n instanceof g.OpenPBRMaterial?o=n.coatIor:n instanceof g.PBRMaterial&&(o=n.clearCoat.indexOfRefraction),null===o||1.5===o)return e(t);var a=t.extensions?t.extensions.KHR_materials_clearcoat:null;if(!a)return e(t);r._wasUsed=!0;var i={clearcoatIor:o};return r._exporter,a.extensions=a.extensions||{},a.extensions[Ee]=i,e(t)}))},e}();se.RegisterExtension(Ee,(function(e){return new Re(e)}),105);var Ce="KHR_materials_clearcoat_color",Se=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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e;return T(this,(function(t){if(e=[],n instanceof g.PBRBaseMaterial){if(n.clearCoat.isEnabled)return n.clearCoat.tintTexture&&e.push(n.clearCoat.tintTexture),[2,e]}else if(n instanceof g.OpenPBRMaterial&&n.coatWeight>0)return n.coatColorTexture&&e.push(n.coatColorTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof g.PBRBaseMaterial){if(!n.clearCoat.isEnabled)return void e(t);if(r._wasUsed=!0,!(a=t.extensions?t.extensions.KHR_materials_clearcoat:null))return void e(t);var o=r._exporter._materialExporter.getTextureInfo(n.clearCoat.tintTexture);null!==(i={clearcoatColorFactor:n.clearCoat.tintColor.asArray(),clearcoatColorTexture:null!=o?o:void 0}).clearcoatColorTexture&&r._exporter._materialNeedsUVsSet.add(n),a.extensions=a.extensions||{},a.extensions[Ce]=i}else if(n instanceof g.OpenPBRMaterial){if(0==n.coatWeight)return void e(t);var a,i;if(r._wasUsed=!0,!(a=t.extensions?t.extensions.KHR_materials_clearcoat:null))return void e(t);o=r._exporter._materialExporter.getTextureInfo(n.coatWeightTexture),null!==(i={clearcoatColorFactor:n.coatColor.asArray(),clearcoatColorTexture:null!=o?o:void 0}).clearcoatColorTexture&&r._exporter._materialNeedsUVsSet.add(n),a.extensions=a.extensions||{},a.extensions[Ce]=i}e(t)}))},e}();se.RegisterExtension(Ce,(function(e){return new Se(e)}),105);var Ve="KHR_materials_clearcoat_anisotropy";function Ie(e,t){t.uOffset=e.uOffset,t.vOffset=e.vOffset,t.uScale=e.uScale,t.vScale=e.vScale,t.uAng=e.uAng,t.vAng=e.vAng,t.wAng=e.wAng,t.uRotationCenter=e.uRotationCenter,t.vRotationCenter=e.vRotationCenter}function Be(e){return y(this,void 0,void 0,(function(){var t,n,r,o,a,i,s,u;return T(this,(function(c){switch(c.label){case 0:return t=e.getScene(),g.Effect.ShadersStore.anisotropyMergeFragmentShader||(g.Effect.ShadersStore.anisotropyMergeFragmentShader="\n precision highp float;\n#ifdef HAS_TANGENT_TEXTURE\n uniform sampler2D tangentTexture;\n#endif\n#ifdef HAS_ANISOTROPY_TEXTURE\n uniform sampler2D anisotropyTexture;\n#endif\n uniform int useRoughnessFromMetallicGreen;\n uniform int useAnisotropyFromTangentBlue;\n\n varying vec2 vUV;\n\n void main() {\n vec2 tangent = vec2(1.0, 0.0);\n float anisotropy = 1.0;\n #ifdef HAS_TANGENT_TEXTURE\n // Tangent texture is present\n vec4 tangentSample = texture2D(tangentTexture, vUV);\n tangent = tangentSample.rg;\n\n if (useAnisotropyFromTangentBlue > 0) {\n anisotropy = tangentSample.b;\n }\n #endif\n #ifdef HAS_ANISOTROPY_TEXTURE\n // Anisotropy texture is present\n vec4 anisotropySample = texture2D(anisotropyTexture, vUV);\n anisotropy = anisotropySample.r;\n #endif\n \n // Output: RG = tangent XY, B = anisotropy strength\n vec4 anisotropyData = vec4(tangent.x, tangent.y, anisotropy, 1.0);\n gl_FragColor = anisotropyData;\n }\n"),n=e.coatRoughnessAnisotropyTexture,r=e.geometryCoatTangentTexture,n||r?(o=Math.max(n?n.getSize().width:1,r?r.getSize().width:1),a=Math.max(n?n.getSize().height:1,r?r.getSize().height:1),i={type:g.Constants.TEXTURETYPE_UNSIGNED_BYTE,format:g.Constants.TEXTUREFORMAT_RGBA,samplingMode:g.Constants.TEXTURE_BILINEAR_SAMPLINGMODE,generateDepthBuffer:!1,generateStencilBuffer:!1,generateMipMaps:!1},(s=new g.ProceduralTexture(e.name+"_anisotropy",{width:o,height:a},"anisotropyMerge",t,i)).refreshRate=-1,u="",r&&(u+="#define HAS_TANGENT_TEXTURE\n",s.setTexture("tangentTexture",r),Ie(r,s)),s.setVector2("tangentVector",e.geometryTangent),n&&(u+="#define HAS_ANISOTROPY_TEXTURE\n",s.setTexture("anisotropyTexture",n),Ie(n,s)),s.setInt("useAnisotropyFromTangentBlue",e._useCoatRoughnessAnisotropyFromTangentTexture?1:0),s.defines=u,[4,new Promise((function(e,t){s.executeWhenReady((function(){try{s.render(),e(s)}catch(e){t(e instanceof Error?e:new Error(String(e)))}}))}))]):[2,null];case 1:return[2,c.sent()]}}))}))}var Fe=function(){function e(e){this.name=Ve,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._anisoTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e,t;return T(this,(function(r){switch(r.label){case 0:return e=[],n instanceof g.OpenPBRMaterial&&n.coatRoughnessAnisotropy>0?[4,Be(n)]:[3,2];case 1:return(t=r.sent())&&(e.push(t),this._anisoTexturesMap[n.id]=t),[2,e];case 2:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){var o,a,i,s,u,c;if(n instanceof g.OpenPBRMaterial&&n.coatRoughnessAnisotropy>0){t.extensions=t.extensions||{};var l=t.extensions?t.extensions.KHR_materials_clearcoat:null;if(!l)return e(t);r._wasUsed=!0;var f=n.coatRoughnessTexture,p=r._anisoTexturesMap[n.id];if(!f&&!p){var h=n.coatRoughness,d=n.coatRoughnessAnisotropy;if(!n._useGltfStyleAnisotropy){var m=(a=n.coatRoughness,c=(1-(i=n.coatRoughnessAnisotropy))*(u=(s=a*a)*Math.sqrt(2/(1+(1-i)*(1-i)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-s)/Math.max(1-s,1e-4)),1)});h=m.newBaseRoughness,d=m.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=h);var x={clearcoatAnisotropyStrength:d,clearcoatAnisotropyRotation:n.geometryCoatTangentAngle+.5*Math.PI,clearcoatAnisotropyTexture:void 0};return l.extensions=l.extensions||{},l.extensions[Ve]=x,e(t)}var _=p?r._exporter._materialExporter.getTextureInfo(p):null,v={clearcoatAnisotropyStrength:n.coatRoughnessAnisotropy,clearcoatAnisotropyRotation:n.geometryCoatTangentAngle,clearcoatAnisotropyTexture:_||void 0,extensions:{}};n._useGltfStyleAnisotropy||(v.extensions.EXT_materials_anisotropy_openpbr={openPbrAnisotropyEnabled:!0},(o=r._exporter._glTF).extensionsUsed||(o.extensionsUsed=[]),-1===r._exporter._glTF.extensionsUsed.indexOf("EXT_materials_anisotropy_openpbr")&&r._exporter._glTF.extensionsUsed.push("EXT_materials_anisotropy_openpbr")),r._exporter._materialNeedsUVsSet.add(n),l.extensions=l.extensions||{},l.extensions[Ve]=v}e(t)}))},e}();se.RegisterExtension(Ve,(function(e){return new Fe(e)}),105);var Oe="KHR_materials_diffuse_transmission";function Pe(e,t){var n=t.subSurface,r=null;return n.translucencyIntensityTexture?r=n.translucencyIntensityTexture:n.thicknessTexture&&n.useMaskFromThicknessTexture&&(r=n.thicknessTexture),r&&!n.useGltfStyleTextures?(g.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(t.name),1),null):r}var Ue=function(){function e(e){this.name=Oe,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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var t,r;return T(this,(function(o){return t=[],n instanceof g.PBRMaterial&&this._isExtensionEnabled(n)?((r=Pe(e,n))&&t.push(r),n.subSurface.translucencyColorTexture&&t.push(n.subSurface.translucencyColorTexture),[2,t]):[2,t]}))}))},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 a,i;if(n instanceof g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var s=n.subSurface,u=Pe(e,n),c=0==s.translucencyIntensity?void 0:s.translucencyIntensity,l=null!==(a=r._exporter._materialExporter.getTextureInfo(u))&&void 0!==a?a:void 0,f=!s.translucencyColor||s.translucencyColor.equalsFloats(1,1,1)?void 0:s.translucencyColor.asArray(),p=null!==(i=r._exporter._materialExporter.getTextureInfo(s.translucencyColorTexture))&&void 0!==i?i:void 0,h={diffuseTransmissionFactor:c,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:f,diffuseTransmissionColorTexture:p};(l||p)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions=t.extensions||{},t.extensions[Oe]=h}o(t)}))},e}();se.RegisterExtension(Oe,(function(e){return new Ue(e)}));var Ne="KHR_materials_dispersion",Le=function(){function e(){this.name=Ne,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 g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var o={dispersion:n.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[Ne]=o}e(t)}))},e}();se.RegisterExtension(Ne,(function(){return new Le}));var De="KHR_materials_emissive_strength",Ke=function(){function e(){this.name=De,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 g.PBRMaterial))return r(t);var o=n.emissiveColor.scale(n.emissiveIntensity),a=Math.max.apply(Math,o.asArray());if(a>1){t.emissiveFactor=o.scale(1/a).asArray(),e._wasUsed=!0;var i={emissiveStrength:a};t.extensions||(t.extensions={}),t.extensions[De]=i}else t.emissiveFactor=o.asArray();return r(t)}))];case 1:return[2,r.sent()]}}))}))},e}();se.RegisterExtension(De,(function(){return new Ke}));var ke="KHR_materials_ior",He=function(){function e(){this.name=ke,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 g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var o={ior:n.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[ke]=o}e(t)}))},e}();se.RegisterExtension(ke,(function(e){return new He}));var Ge="KHR_materials_iridescence",We=function(){function e(e){this.name=Ge,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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e;return T(this,(function(t){return e=[],n instanceof g.PBRBaseMaterial&&n.iridescence.isEnabled?(n.iridescence.texture&&e.push(n.iridescence.texture),n.iridescence.thicknessTexture&&n.iridescence.thicknessTexture!==n.iridescence.texture&&e.push(n.iridescence.thicknessTexture),[2,e]):[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof g.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),a=r._exporter._materialExporter.getTextureInfo(n.iridescence.thicknessTexture),i={iridescenceFactor:n.iridescence.intensity,iridescenceIor:n.iridescence.indexOfRefraction,iridescenceThicknessMinimum:n.iridescence.minimumThickness,iridescenceThicknessMaximum:n.iridescence.maximumThickness,iridescenceTexture:null!=o?o:void 0,iridescenceThicknessTexture:null!=a?a:void 0};null===i.iridescenceTexture&&null===i.iridescenceThicknessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[Ge]=i}e(t)}))},e}();se.RegisterExtension(Ge,(function(e){return new We(e)}));var qe="KHR_materials_sheen",ze=function(){function e(e){this.name=qe,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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){return T(this,(function(e){return n instanceof g.PBRMaterial&&n.sheen.isEnabled&&n.sheen.texture?[2,[n.sheen.texture]]:[2,[]]}))}))},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,a,i,s;if(n instanceof g.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!==(a=e._exporter._materialExporter.getTextureInfo(n.sheen.texture))&&void 0!==a?a:void 0),n.sheen.textureRoughness&&!n.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(n.sheen.textureRoughness))&&void 0!==i?i: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[qe]=u}r(t)}))];case 1:return[2,r.sent()]}}))}))},e}();se.RegisterExtension(qe,(function(e){return new ze(e)}));var je="KHR_materials_specular",Xe=function(){function e(e){this.name=je,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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e;return T(this,(function(t){return e=[],n instanceof g.PBRMaterial&&this._isExtensionEnabled(n)?(n.metallicReflectanceTexture&&e.push(n.metallicReflectanceTexture),n.reflectanceTexture&&e.push(n.reflectanceTexture),[2,e]):[2,e]}))}))},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,a,i,s,u;if(n instanceof g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0,t.extensions=t.extensions||{};var c=null!==(o=r._exporter._materialExporter.getTextureInfo(n.metallicReflectanceTexture))&&void 0!==o?o:void 0,l=null!==(a=r._exporter._materialExporter.getTextureInfo(n.reflectanceTexture))&&void 0!==a?a:void 0,f={specularFactor:1==n.metallicF0Factor?void 0:n.metallicF0Factor,specularTexture:c,specularColorFactor:n.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:n.metallicReflectanceColor.asArray(),specularColorTexture:l};r._hasTexturesExtension(n)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[je]=f}else if(n instanceof g.OpenPBRMaterial){t.extensions=t.extensions||{};var p=null!==(i=r._exporter._materialExporter.getTextureInfo(n.specularWeightTexture))&&void 0!==i?i:void 0,h=null!==(s=r._exporter._materialExporter.getTextureInfo(n.specularColorTexture))&&void 0!==s?s:void 0,d=1==n.specularWeight?void 0:n.specularWeight,m=n.specularColor.equalsFloats(1,1,1)?void 0:n.specularColor.asArray();if(!h&&!p&&void 0===d&&void 0===m)return e(t);r._wasUsed=!0,(f={specularFactor:d,specularTexture:p,specularColorFactor:m,specularColorTexture:h,extensions:{}}).extensions.EXT_materials_specular_edge_color={specularEdgeColorEnabled:!0},(u=r._exporter._glTF).extensionsUsed||(u.extensionsUsed=[]),-1===r._exporter._glTF.extensionsUsed.indexOf("EXT_materials_specular_edge_color")&&r._exporter._glTF.extensionsUsed.push("EXT_materials_specular_edge_color"),(p||h)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[je]=f}e(t)}))},e}();se.RegisterExtension(je,(function(e){return new Xe(e)}));var Ye="KHR_materials_transmission",Qe=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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e;return T(this,(function(t){return e=[],n instanceof g.PBRMaterial&&this._isExtensionEnabled(n)?(n.subSurface.thicknessTexture&&e.push(n.subSurface.thicknessTexture),[2,e]):[2,e]}))}))},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,a,i;return T(this,(function(s){switch(s.label){case 0:return n instanceof g.PBRMaterial&&this._isExtensionEnabled(n)?(this._wasUsed=!0,r=n.subSurface,o=0===r.refractionIntensity?void 0:r.refractionIntensity,a={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(i=s.sent())&&(a.transmissionTexture=i),[3,3];case 2:g.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[Ye]=a,s.label=4;case 4:return[2,t]}}))}))},e}();se.RegisterExtension(Ye,(function(e){return new Qe(e)}));var Ze="KHR_materials_unlit",Je=function(){function e(){this.name=Ze,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 g.PBRMaterial?o=n.unlit:n instanceof g.StandardMaterial&&(o=n.disableLighting),o&&(r._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[Ze]={}),e(t)}))},e}();se.RegisterExtension(Ze,(function(){return new Je}));var $e="KHR_materials_volume",et=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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e;return T(this,(function(t){return e=[],n instanceof g.PBRMaterial&&this._isExtensionEnabled(n)?(n.subSurface.thicknessTexture&&e.push(n.subSurface.thicknessTexture),[2,e]):[2,e]}))}))},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!=g.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 g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var a=n.subSurface,i={thicknessFactor:0==a.maximumThickness?void 0:a.maximumThickness,thicknessTexture:null!==(o=r._exporter._materialExporter.getTextureInfo(a.thicknessTexture))&&void 0!==o?o:void 0,attenuationDistance:a.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:a.tintColorAtDistance,attenuationColor:a.tintColor.equalsFloats(1,1,1)?void 0:a.tintColor.asArray()};r._hasTexturesExtension(n)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions=t.extensions||{},t.extensions[$e]=i}e(t)}))},e}();se.RegisterExtension($e,(function(e){return new et(e)}));var tt="KHR_materials_diffuse_roughness",nt=function(){function e(e){this.name=tt,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.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e;return T(this,(function(t){if(e=[],n instanceof g.PBRBaseMaterial){if(n._baseDiffuseRoughness)return n._baseDiffuseRoughnessTexture&&e.push(n._baseDiffuseRoughnessTexture),[2,e]}else if(n instanceof g.OpenPBRMaterial&&n.baseDiffuseRoughness)return n.baseDiffuseRoughnessTexture&&e.push(n.baseDiffuseRoughnessTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){var o=null,a=null;if(n instanceof g.PBRBaseMaterial?(o=n._baseDiffuseRoughness,a=n._baseDiffuseRoughnessTexture):n instanceof g.OpenPBRMaterial&&(o=n.baseDiffuseRoughness,a=n.baseDiffuseRoughnessTexture),o){r._wasUsed=!0,t.extensions=t.extensions||{};var i=r._exporter._materialExporter.getTextureInfo(a),s={diffuseRoughnessFactor:o,diffuseRoughnessTexture:null!=i?i:void 0};null!==s.diffuseRoughnessTexture&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[tt]=s,e(t)}else e(t)}))},e}();se.RegisterExtension(tt,(function(e){return new nt(e)}));var rt="KHR_texture_transform",ot=function(){function e(){this.name=rt,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()||g.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(n.name,"!")),0===n.uAng&&0===n.vAng||(g.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 g.Tools.Warn("".concat(e,": Texture ").concat(n.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(rt,"."));g.Tools.Warn("".concat(e,": Texture ").concat(n.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(rt,".")),r.offset=function(e){var t=e.uOffset,n=e.vOffset,r=e.uRotationCenter,o=e.vRotationCenter,a=e.uScale,i=e.vScale,s=e.wAng,u=Math.cos(s),c=Math.sin(s),l=r*a,f=o*i;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[rt]=r)}},e}();se.RegisterExtension(rt,(function(){return new ot}));var at="KHR_texture_basisu",it=function(){function e(e){this.name=at,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,g.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[at]={source:r},this._wasUsed=!0)}},e}();se.RegisterExtension(at,(function(e){return new it(e)}));var st="EXT_texture_webp",ut=function(){function e(e){this.name=st,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,g.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[st]={source:r},this._wasUsed=!0)}},e}();se.RegisterExtension(st,(function(e){return new ut(e)}));var ct="EXT_texture_avif",lt=function(){function e(e){this.name=ct,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,g.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[ct]={source:r},this._wasUsed=!0)}},e}();se.RegisterExtension(ct,(function(e){return new lt(e)}));var ft=function(){function e(){}return e.CreateSTL=function(e,t,n,r,o,a,i,s){void 0===t&&(t=!0),void 0===n&&(n="stlmesh"),void 0===r&&(r=!1),void 0===o&&(o=!0),void 0===a&&(a=!1),void 0===i&&(i=!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 g.Vector3(t[r[0]],t[r[0]+2],t[r[0]+1]),new g.Vector3(t[r[1]],t[r[1]+2],t[r[1]+1]),new g.Vector3(t[r[2]],t[r[2]+2],t[r[2]+1])],a=o[0].subtract(o[1]),i=o[2].subtract(o[1]);return{v:o,n:g.Vector3.Cross(i,a).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(i){var t=e;e instanceof g.InstancedMesh&&(t=e.sourceMesh);var n=t.getVerticesData(g.VertexBuffer.PositionKind,!0,!0);if(!n)return[];var r=g.Vector3.Zero(),o=void 0;for(o=0;o<n.length;o+=3)g.Vector3.TransformCoordinatesFromFloatsToRef(n[o],n[o+1],n[o+2],e.computeWorldMatrix(!0),r).toArray(n,o);return n}return e.getVerticesData(g.VertexBuffer.PositionKind)||[]};i&&(a=!0);var p="",h=0,d=0;if(r){for(var m=0;m<e.length;m++)h+=(y=(_=e[m]).getIndices())?y.length/3:0;var x=new ArrayBuffer(84+50*h);d+=80,(p=new DataView(x)).setUint32(d,h,o),d+=4}else s||(p="solid stlmesh\r\n");for(m=0;m<e.length;m++){var _=e[m];!r&&s&&(p+="solid "+_.name+"\r\n"),!a&&_ instanceof g.Mesh&&_.bakeCurrentTransformIntoVertices();for(var v=f(_),y=_.getIndices()||[],T=0;T<y.length;T+=3){var b=u(y,v,T);r?(d=c(p,d,b.n,o),d=c(p,d,b.v[0],o),d=c(p,d,b.v[1],o),d=c(p,d,b.v[2],o),d+=2):(p+="\tfacet normal "+b.n.x+" "+b.n.y+" "+b.n.z+"\r\n",p+="\t\touter loop\r\n",p+="\t\t\tvertex "+b.v[0].x+" "+b.v[0].y+" "+b.v[0].z+"\r\n",p+="\t\t\tvertex "+b.v[1].x+" "+b.v[1].y+" "+b.v[1].z+"\r\n",p+="\t\t\tvertex "+b.v[2].x+" "+b.v[2].y+" "+b.v[2].z+"\r\n",p+="\t\tendloop\r\n",p+="\tendfacet\r\n")}!r&&s&&(p+="endsolid "+name+"\r\n")}if(r||s||(p+="endsolid stlmesh"),t){var A=document.createElement("a"),M=new Blob([p],{type:"application/octet-stream"});A.href=window.URL.createObjectURL(M),A.download=n+".stl",A.click()}return p},e}();function pt(e,t,n,r){void 0===n&&(n=3),void 0===r&&(r=!1);for(var o=[],a=0;a<e.length/n;a++){var i=e[a*n]*(r?-1:1),s=e[a*n+1],u=e[a*n+2];o.push("(".concat(i.toPrecision(t.precision),", ").concat(s.toPrecision(t.precision),", ").concat(u.toPrecision(t.precision),")"))}return o.join(", ")}function ht(e,t){for(var n=[],r=0;r<e.length/2;r++){var o=e[2*r],a=e[2*r+1];n.push("(".concat(o.toPrecision(t.precision),", ").concat((1-a).toPrecision(t.precision),")"))}return n.join(", ")}function dt(e,t,n,r){var o=function(e,t,n,r){var o=e.getVerticesData(g.VertexBuffer.PositionKind),a=e.getVerticesData(g.VertexBuffer.NormalKind);if(o&&a)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 a=0;a<r;a++)o.push(n[a]);else for(a=0;a<r;a++)o.push(a);return o.join(", ")}(e),"]\n\t\tnormal3f[] normals = [").concat(pt(a,t,void 0,r),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)\n\t\tpoint3f[] points = [').concat(pt(o,t,void 0,r),"]\n ").concat(function(e,t){for(var n="",r=0;r<4;r++){var o=r>0?r:"",a=e.getVerticesData(g.VertexBuffer.UVKind+(o?o+1:""));a&&(n+="\n\t\ttexCoord2f[] primvars:st".concat(o," = [").concat(ht(a,t),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)'))}var i=e.getVerticesData(g.VertexBuffer.ColorKind);return i&&(n+="\n\tcolor3f[] primvars:displayColor = [".concat(pt(i,t,i.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 gt(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 mt(e){var t=e.m;return"( ".concat(xt(t,0),", ").concat(xt(t,4),", ").concat(xt(t,8),", ").concat(xt(t,12)," )")}function xt(e,t){return"(".concat(e[t+0],", ").concat(e[t+1],", ").concat(e[t+2],", ").concat(e[t+3],")")}function _t(e,t){var n="Object_"+e.uniqueId,r=mt(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 vt(e){switch(e){case g.Constants.TEXTURE_CLAMP_ADDRESSMODE:return"clamp";case g.Constants.TEXTURE_MIRROR_ADDRESSMODE:return"mirror";case g.Constants.TEXTURE_WRAP_ADDRESSMODE:default:return"repeat"}}function yt(e){return"(".concat(e.x,", ").concat(e.y,")")}function Tt(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,")")}function bt(e,t,n,r,o,a){var i=e.getInternalTexture().uniqueId+"_"+e.invertY;o[i]=e;var s=e.coordinatesIndex>0?"st"+e.coordinatesIndex:"st",u=new g.Vector2(e.uScale,e.vScale),c=new g.Vector2(e.uOffset,e.vOffset),l=e.wAng,f=Math.sin(l),p=Math.cos(l);return c.y=1-c.y-u.y,c.x+=f*u.x,c.y+=(1-p)*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(a.precision),"\n float2 inputs:scale = ").concat(yt(u),"\n float2 inputs:translation = ").concat(yt(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(i,".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(vt(e.wrapU),'"\n token inputs:wrapT = "').concat(vt(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 At(e,t,n){var r="\t\t\t",o=[],a=[],i=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 g.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 g.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=i.diffuseMap,u=i.diffuse,c=i.alphaCutOff,l=i.emissiveMap,f=i.emissive,p=i.normalMap,h=i.roughnessMap,d=i.roughnessChannel,m=i.roughness,x=i.metalnessMap,_=i.metalnessChannel,y=i.metalness,T=i.aoMap,b=i.aoMapChannel,A=i.aoMapIntensity,M=i.alphaMap,w=i.ior,E=i.clearCoatEnabled,R=i.clearCoat,C=i.clearCoatMap,S=i.clearCoatRoughness,V=i.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))),a.push(bt(s,e,"diffuse",u,t,n))):o.push("".concat(r,"color3f inputs:diffuseColor = ").concat(Tt(u||g.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>")),a.push(bt(l,e,"emissive",f,t,n))):f&&f.toLuminance()>0&&o.push("".concat(r,"color3f inputs:emissiveColor = ").concat(Tt(f))),null!==p&&(o.push("".concat(r,"normal3f inputs:normal.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(p.uniqueId,"_normal.outputs:rgb>")),a.push(bt(p,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,">")),a.push(bt(T,e,"occlusion",new g.Color3(A,A,A),t,n))),null!==h?(o.push("".concat(r,"float inputs:roughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(h.uniqueId,"_roughness.outputs:").concat(d,">")),a.push(bt(h,e,"roughness",new g.Color3(m,m,m),t,n))):o.push("".concat(r,"float inputs:roughness = ").concat(m)),null!==x?(o.push("".concat(r,"float inputs:metallic.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(x.uniqueId,"_metallic.outputs:").concat(_,">")),a.push(bt(x,e,"metallic",new g.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")),a.push(bt(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>")),a.push(bt(C,e,"clearcoat",new g.Color3(R,R,R),t,n))):o.push("".concat(r,"float inputs:clearcoat = ").concat(R)),null!==V?(o.push("".concat(r,"float inputs:clearcoatRoughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(V.uniqueId,"_clearcoatRoughness.outputs:g>")),a.push(bt(V,e,"clearcoatRoughness",new g.Color3(S,S,S),t,n))):o.push("".concat(r,"float inputs:clearcoatRoughness = ").concat(S))),o.push("".concat(r,"float inputs:ior = ").concat(w)),'\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(a.join("\n"),"\n\n\t}\n")}function Mt(e){var t,n;e.computeWorldMatrix(!0);for(var r=e.getWorldMatrix().clone(),o=e.getScene().useRightHandedSystem,a=null!==(n=null===(t=e.material)||void 0===t?void 0:t._getEffectiveOrientation(e))&&void 0!==n?n:e.sideOrientation,i=!o,s=e.parent;s;){if(U(s,o)&&null===s.parent){o||(r.multiplyToRef(s.getWorldMatrix().invert(),r),a=a===g.Material.ClockWiseSideOrientation?g.Material.CounterClockWiseSideOrientation:g.Material.ClockWiseSideOrientation),i=!1;break}s=s.parent}return r.determinant()<0&&g.Tools.Warn("Mesh ".concat(e.name," has a negative scale, which may look incorrect in destinations like QuickLook.")),{matrix:r,windingOrder:a===g.Material.ClockWiseSideOrientation?"leftHanded":"rightHanded",convertToRightHanded:i}}function wt(e,t,n){return y(this,void 0,void 0,(function(){var r,o,a,i,s,u,c,l,f,p,h,d,m,x,_,y,b,A,M,w,E,R,C,S,V,I,B,F,O,P,U,N;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,g.Tools.LoadScriptAsync(r.fflateUrl)];case 1:T.sent(),T.label=2;case 2:for((o={})[r.modelFileName]=null,a='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )',a+=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),i={},s=0,u=e.meshes;s<u.length;s++)0!==(c=u[s]).getTotalVertices()&&(f=(l=c).geometry,(p=l.material)&&f&&(!n||n(l))&&(-1!==["StandardMaterial","PBRMaterial","PBRMetallicRoughnessMaterial"].indexOf(p.getClassName())?(h="geometries/Geometry_"+f.uniqueId+".usda",d=Mt(l),m=d.matrix,x=d.windingOrder,_=d.convertToRightHanded,h in o||(y=dt(f,r,x,_),o[h]=gt(y)),p.uniqueId in i||(i[p.uniqueId]=p),a+=_t(l,m)):g.Tools.Warn("USDZExportAsync does not support this material type: "+p.getClassName())));for(w in e.activeCamera&&r.exportCamera&&(a+=function(e,t){var n="Camera_"+e.uniqueId,r=mt(g.Matrix.RotationY(Math.PI).multiply(e.getWorldMatrix()));if(e.mode===g.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),a=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((a/(2*Math.tan(.5*e.fov))).toPrecision(t.precision),'\n token projection = "perspective"\n\t\t\tfloat horizontalAperture = ').concat((a*o).toPrecision(t.precision),"\n\t\t\tfloat verticalAperture = ").concat((a/o).toPrecision(t.precision)," \n\t\t}\n\t\n\t")}(e.activeCamera,r)),a+="\n }\n }",a+=function(e,t,n){var r=[];for(var o in e){var a=e[o];r.push(At(a,t,n))}return'\n def "Materials"\n{\n'.concat(r.join(""),"\n}\n\n")}(i,b={},r),a+="\n }",o[r.modelFileName]=fflate.strToU8(a),M=[],A=b)M.push(w);E=0,T.label=3;case 3:return E<M.length?(w=M[E])in A?(C=b[R=w],S=C.getSize(),[4,(0,g.GetTextureDataAsync)(C)]):[3,6]:[3,7];case 4:return V=T.sent(),[4,g.DumpTools.DumpDataAsync(S.width,S.height,V,"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!=(U=63&(B+=P))&&(N=new Uint8Array(64-U),o[F]=[O,{extra:{12345:N}}]),B=O.length);return[2,fflate.zipSync(o,{level:0})]}}))}))}var Et=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 a=null,i=0,s=o;i<s.length;i++){var u=s[i],c=e.getAnimationRange(u);c&&(a=a?new g.AnimationRange("animation-range",Math.min(a.from,c.from),Math.max(a.to,c.to)):c)}if(!a&&(e.animations.length>0&&(a=e.getAnimationRange(e.animations[0].name)),!a))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),p=0,h=0,d=f;h<d.length;h++){var m=d[h];m.positionKeys.length>0&&(p=Math.max(p,m.positionKeys.length)),m.rotationKeys.length>0&&(p=Math.max(p,m.rotationKeys.length))}0===p&&(p=Math.floor((a.to-a.from)/l)+1);var x="";return x+="HIERARCHY\n",x+=this._ExportHierarchy(f,0),x+="MOTION\n",x+="Frames: ".concat(p,"\n"),(x+="Frame Time: ".concat(l.toFixed(6),"\n"))+this._ExportMotionData(f,p,0,o)},e._BuildBoneHierarchy=function(e,t){for(var n,r,o=new Map,a=[],i=0,s=e.bones;i<s.length;i++){var u={bone:f=s[i],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 p=0,h=f.animations;p<h.length;p++){var d=h[p];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 g=o.get(f.getParent());g&&g.children.push(u)}else a.push(u)}return a},e._ExportHierarchy=function(e,t){for(var n="",r=" ".repeat(t),o=0,a=e;o<a.length;o++){var i=a[o],s=i.bone;if(this._IsEndSite(i)){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=[];i.hasPositionChannels&&c.push("Xposition","Yposition","Zposition"),i.hasRotationChannels&&c.push("Zrotation","Xrotation","Yrotation"),c.length>0&&(n+="".concat(r," CHANNELS ").concat(c.length," ").concat(c.join(" "),"\n")),i.children.length>0&&(n+=this._ExportHierarchy(i.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 g.Vector3.Zero()}},e._ExportMotionData=function(e,t,n,r){for(var o="",a=0;a<t;a++){var i=[];this._CollectFrameValues(e,a+n,i,r),o+=i.map((function(e){return e.toFixed(6)})).join(" ")+"\n"}return o},e._CollectFrameValues=function(e,t,n,r){for(var o=0,a=e;o<a.length;o++){var i=a[o];if(!this._IsEndSite(i)){if(i.hasPositionChannels){var s=this._GetPositionAtFrameIndex(i.positionKeys,t);n.push(s.x,s.y,s.z)}if(i.hasRotationChannels){var u=this._GetRotationAtFrameIndex(i.rotationKeys,t),c=this._QuaternionToEuler(u);n.push(c.z,c.x,c.y)}i.children.length>0&&this._CollectFrameValues(i.children,t,n,r)}}},e._GetPositionAtFrameIndex=function(e,t){return 0===e.length?g.Vector3.Zero():e[Math.max(0,Math.min(t,e.length-1))].value.clone()},e._GetRotationAtFrameIndex=function(e,t){return 0===e.length?g.Quaternion.Identity():e[Math.max(0,Math.min(t,e.length-1))].value.clone()},e._QuaternionToEuler=function(e){var t=new g.Matrix;e.toRotationMatrix(t);var n,r,o,a=t.m,i=Math.sqrt(a[0]*a[0]+a[1]*a[1]);return i>g.Epsilon?(n=Math.atan2(a[6],a[10]),r=Math.atan2(-a[2],i),o=Math.atan2(a[1],a[0])):(n=Math.atan2(-a[9],a[5]),r=Math.atan2(-a[2],i),o=0),new g.Vector3(g.Tools.ToDegrees(n),g.Tools.ToDegrees(r),g.Tools.ToDegrees(o))},e}(),Rt=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Rt)for(var Ct in h)Rt.BABYLON[Ct]=h[Ct];var St=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==St){St.BABYLON=St.BABYLON||{};var Vt=St.BABYLON;Vt.GLTF2=Vt.GLTF2||{},Vt.GLTF2.Exporter=Vt.GLTF2.Exporter||{},Vt.GLTF2.Exporter.Extensions=Vt.GLTF2.Exporter.Extensions||{};var It=[];for(var Bt in i)Vt[Bt]=i[Bt],It.push(Bt);for(var Bt in s)Vt[Bt]=s[Bt],It.push(Bt);for(var Bt in u)Vt[Bt]=u[Bt],It.push(Bt);for(var Bt in c)Vt.GLTF2.Exporter.Extensions[Bt]=c[Bt],It.push(Bt);for(var Bt in l)It.indexOf(Bt)>-1||(Vt.GLTF2.Exporter[Bt]=l[Bt])}var Ft=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Ft)for(var Ot in a)Ft.BABYLON[Ot]=a[Ot];var Pt=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Pt)for(var Ut in f)Pt.BABYLON[Ut]=f[Ut];var Nt=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Nt)for(var Lt in p)Nt.BABYLON[Lt]=p[Lt];const Dt=d;return o.default})()));
2
2
  //# sourceMappingURL=babylonjs.serializers.min.js.map